1 parent
952587df4f
commit
efcb19aa2f
19 files changed
+276
-189
No files matched your search
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
@charset "UTF-8";/*!
|
||||
* Bootstrap v5.3.5 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2025 The Bootstrap Authors
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/:root,[data-bs-theme=light]{--bs-blue:#0d6efd;--bs-indigo:#6610f2;--bs-purple:#6f42c1;--bs-pink:#d63384;--bs-red:#dc3545;--bs-orange:#fd7e14;--bs-yellow:#ffc107;--bs-green:#198754;--bs-teal:#20c997;--bs-cyan:#0dcaf0;--bs-black:#000;--bs-white:#fff;--bs-gray:#6c757d;--bs-gray-dark:#343a40;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#adb5bd;--bs-gray-600:#6c757d;--bs-gray-700:#495057;--bs-gray-800:#343a40;--bs-gray-900:#212529;--bs-primary:#0d6efd;--bs-secondary:#6c757d;--bs-success:#198754;--bs-info:#0dcaf0;--bs-warning:#ffc107;--bs-danger:#dc3545;--bs-light:#f8f9fa;--bs-dark:#212529;--bs-primary-rgb:13,110,253;--bs-secondary-rgb:108,117,125;--bs-success-rgb:25,135,84;--bs-info-rgb:13,202,240;--bs-warning-rgb:255,193,7;--bs-danger-rgb:220,53,69;--bs-light-rgb:248,249,250;--bs-dark-rgb:33,37,41;--bs-primary-text-emphasis:#052c65;--bs-secondary-text-emphasis:#2b2f32;--bs-success-text-emphasis:#0a3622;--bs-info-text-emphasis:#055160;--bs-warning-text-emphasis:#664d03;--bs-danger-text-emphasis:#58151c;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#cfe2ff;--bs-secondary-bg-subtle:#e2e3e5;--bs-success-bg-subtle:#d1e7dd;--bs-info-bg-subtle:#cff4fc;--bs-warning-bg-subtle:#fff3cd;--bs-danger-bg-subtle:#f8d7da;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#9ec5fe;--bs-secondary-border-subtle:#c4c8cb;--bs-success-border-subtle:#a3cfbb;--bs-info-border-subtle:#9eeaf9;--bs-warning-border-subtle:#ffe69c;--bs-danger-border-subtle:#f1aeb5;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#adb5bd;--bs-white-rgb:255,255,255;--bs-black-rgb:0,0,0;--bs-font-sans-serif:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--bs-font-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#212529;--bs-body-color-rgb:33,37,41;--bs-body-bg:#fff;--bs-body-bg-rgb:255,255,255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0,0,0;--bs-secondary-color:rgba(33, 37, 41, 0.75);--bs-secondary-color-rgb:33,37,41;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233,236,239;--bs-tertiary-color:rgba(33, 37, 41, 0.5);--bs-tertiary-color-rgb:33,37,41;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248,249,250;--bs-heading-color:inherit;--bs-link-color:#0d6efd;--bs-link-color-rgb:13,110,253;--bs-link-decoration:underline;--bs-link-hover-color:#0a58ca;--bs-link-hover-color-rgb:10,88,202;--bs-code-color:#d63384;--bs-highlight-color:#212529;--bs-highlight-bg:#fff3cd;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, 0.175);--bs-border-radius:0.375rem;--bs-border-radius-sm:0.25rem;--bs-border-radius-lg:0.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.15);--bs-box-shadow-sm:0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, 0.175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, 0.075);--bs-focus-ring-width:0.25rem;--bs-focus-ring-opacity:0.25;--bs-focus-ring-color:rgba(13, 110, 253, 0.25);--bs-form-valid-color:#198754;--bs-form-valid-border-color:#198754;--bs-form-invalid-color:#dc3545;--bs-form-invalid-border-color:#dc3545}[data-bs-theme=dark]{color-scheme:dark;--bs-body-color:#dee2e6;--bs-body-color-rgb:222,226,230;--bs-body-bg:#212529;--bs-body-bg-rgb:33,37,41;--bs-emphasis-color:#fff;--bs-emphasis-color-rgb:255,255,255;--bs-secondary-color:rgba(222, 226, 230, 0.75);--bs-secondary-color-rgb:222,226,230;--bs-secondary-bg:#343a40;--bs-secondary-bg-rgb:52,58,64;--bs-tertiary-color:rgba(222, 226, 230, 0.5);--bs-tertiary-color-rgb:222,226,230;--bs-tertiary-bg:#2b3035;--bs-tertiary-bg-rgb:43,48,53;--bs-primary-text-emphasis:#6ea8fe;--bs-secondary-text-emphasis:#a7acb1;--bs-success-text-emphasis:#75b798;--bs-info-text-emphasis:#6edff6;--bs-warning-text-emphasis:#ffda6a;--bs-danger-text-emphasis:#ea868f;--bs-light-text-emphasis:#f8f9fa;--bs-dark-text-emphasis:#dee2e6;--bs-primary-bg-subtle:#031633;--bs-secondary-bg-subtle:#161719;--bs-success-bg-subtle:#051b11;--bs-info-bg-subtle:#032830;--bs-warning-bg-subtle:#332701;--bs-danger-bg-subtle:#2c0b0e;--bs-light-bg-subtle:#343a40;--bs-dark-bg-subtle:#1a1d20;--bs-primary-border-subtle:#084298;--bs-secondary-border-subtle:#41464b;--bs-success-border-subtle:#0f5132;--bs-info-border-subtle:#087990;--bs-warning-border-subtle:#997404;--bs-danger-border-subtle:#842029;--bs-light-border-subtle:#495057;--bs-dark-border-subtle:#343a40;--bs-heading-color:inherLine truncated
|
||||
/*# sourceMappingURL=bootstrap.min.css.map */
|
||||
@@ -0,0 +1,70 @@
|
||||
.checkbox-wrapper-2 {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC {
|
||||
appearance: none;
|
||||
background-color: #dfe1e4;
|
||||
border-radius: 72px;
|
||||
border-style: none;
|
||||
flex-shrink: 0;
|
||||
height: 20px;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
width: 30px;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC::before {
|
||||
bottom: -6px;
|
||||
content: "";
|
||||
left: -6px;
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
top: -6px;
|
||||
transition: 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC,
|
||||
.checkbox-wrapper-2 .ikxBAC::after {
|
||||
transition: 300ms;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC::after {
|
||||
background-color: #fff;
|
||||
border-radius: 50%;
|
||||
content: "";
|
||||
height: 14px;
|
||||
left: 3px;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
width: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 input[type="checkbox"] {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC:hover {
|
||||
background-color: #c9cbcd;
|
||||
transition-duration: 0s;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC:checked {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC:checked::after {
|
||||
background-color: #fff;
|
||||
left: 13px;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 :focus:not(.focus-visible) {
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.checkbox-wrapper-2 .ikxBAC:checked:hover {
|
||||
background-color: hsl(from green h s 20%);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
* {
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
transform: scale(0);
|
||||
height: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
#save-settings-button {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 10px;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width"/>
|
||||
<link rel="stylesheet" href="css/index.css" />
|
||||
<link rel="stylesheet" href="css/checkbox.css" />
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<title>Dns Service</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<a href="/" class="navbar-brand">Dns Service</a>
|
||||
<p style="margin-bottom: 0;">Dark theme</p>
|
||||
<div class="checkbox-wrapper-2"><input type="checkbox" class="sc-gJwTLC ikxBAC" id="dark_theme"/></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<section class="settings-section d-grid gap-2 justify-content-center p-3">
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">Upstream Dns Servers</h3></div>
|
||||
<div class="card-body">
|
||||
<table id="upstream-dns-servers-table" class="table">
|
||||
<thead><tr><th>Upstream Dns Servers</th></tr></thead>
|
||||
<tbody id="upstream-dns-servers-table-body"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
style="width: 100%"
|
||||
id="add_dns_server_button"
|
||||
>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">Local Domains</h3></div>
|
||||
<div class="card-body">
|
||||
<table class="local-domains-table table">
|
||||
<thead><tr><th>IP</th><th>Domain</th><th>Delete</th></tr></thead>
|
||||
<tbody id="local-domains-table-body">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
style="width: 100%"
|
||||
id="add_local_domain_button"
|
||||
>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header d-flex align-items-center gap-3 justify-content-between">
|
||||
<h3>DHCP</h3>
|
||||
<div class="checkbox-wrapper-2"><input type="checkbox" class="sc-gJwTLC ikxBAC" id="dhcp_enabled"/></div>
|
||||
</div>
|
||||
<div class="card-body hidden" id="dhcp_rect_body">
|
||||
<h3 class="card-title">DHCP range</h3>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<input placeholder="192.168.0.2" type="text" id="start-dhcp-range" class="form-control"/>
|
||||
-
|
||||
<input placeholder="192.168.0.254" type="text" id="stop-dhcp-range" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header d-flex align-items-center gap3 justify-content-between">
|
||||
<h3>Cache size</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<input type="number" name="" id="cache-size-input" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" style="margin-bottom: 50px;">
|
||||
<div class="card-header d-flex align-items-center gap3 justify-content-between">
|
||||
<h3>Edit config file</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<textarea id="edit_file_input" style="width: 100%;height: 200px;"></textarea>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button class="btn btn-primary" id="save_config_file_button" style="width: 100%">Save config file</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<button class="btn btn-primary" id="save-settings-button">Save</button>
|
||||
<script src="js/checkbox.js"></script>
|
||||
<script src="js/bootstrap.min.js"></script>
|
||||
<script src="js/theme.js"></script>
|
||||
<script src="js/settings/settings.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* Bootstrap v5.3.5 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2025 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@popperjs/core")):"function"==typeof define&&define.amd?define(["@popperjs/core"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).bootstrap=e(t.Popper)}(this,(function(t){"use strict";function e(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const i in t)if("default"!==i){const s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>t[i]})}return e.default=t,Object.freeze(e)}const i=e(t),s=new Map,n={set(t,e,i){s.has(t)||s.set(t,new Map);const n=s.get(t);n.has(e)||0===n.size?n.set(e,i):console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(n.keys())[0]}.`)},get:(t,e)=>s.has(t)&&s.get(t).get(e)||null,remove(t,e){if(!s.has(t))return;const i=s.get(t);i.delete(e),0===i.size&&s.delete(t)}},o="transitionend",r=t=>(t&&window.CSS&&window.CSS.escape&&(t=t.replace(/#([^\s"#']+)/g,((t,e)=>`#${CSS.escape(e)}`))),t),a=t=>{t.dispatchEvent(new Event(o))},l=t=>!(!t||"object"!=typeof t)&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType),c=t=>l(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(r(t)):null,h=t=>{if(!l(t)||0===t.getClientRects().length)return!1;const e="visible"===getComputedStyle(t).getPropertyValue("visibility"),i=t.closest("details:not([open])");if(!i)return e;if(i!==t){const e=t.closest("summary");if(e&&e.parentNode!==i)return!1;if(null===e)return!1}return e},d=t=>!t||t.nodeType!==Node.ELEMENT_NODE||!!t.classList.contains("disabled")||(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")),u=t=>{if(!document.documentElement.attachShadow)return null;if("function"==typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?u(t.parentNode):null},_=()=>{},g=t=>{t.offsetHeight},f=()=>window.jQuery&&!document.body.hasAttribute("data-bs-no-jquery")?window.jQuery:null,m=[],p=()=>"rtl"===document.documentElement.dir,b=t=>{var e;e=()=>{const e=f();if(e){const i=t.NAME,s=e.fn[i];e.fn[i]=t.jQueryInterface,e.fn[i].Constructor=t,e.fn[i].noConflict=()=>(e.fn[i]=s,t.jQueryInterface)}},"loading"===document.readyState?(m.length||document.addEventListener("DOMContentLoaded",(()=>{for(const t of m)t()})),m.push(e)):e()},v=(t,e=[],i=t)=>"function"==typeof t?t.call(...e):i,y=(t,e,i=!0)=>{if(!i)return void v(t);const s=(t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:i}=window.getComputedStyle(t);const s=Number.parseFloat(e),n=Number.parseFloat(i);return s||n?(e=e.split(",")[0],i=i.split(",")[0],1e3*(Number.parseFloat(e)+Number.parseFloat(i))):0})(e)+5;let n=!1;const r=({target:i})=>{i===e&&(n=!0,e.removeEventListener(o,r),v(t))};e.addEventListener(o,r),setTimeout((()=>{n||a(e)}),s)},w=(t,e,i,s)=>{const n=t.length;let o=t.indexOf(e);return-1===o?!i&&s?t[n-1]:t[0]:(o+=i?1:-1,s&&(o=(o+n)%n),t[Math.max(0,Math.min(o,n-1))])},A=/[^.]*(?=\..*)\.|.*/,E=/\..*/,C=/::\d+$/,T={};let k=1;const $={mouseenter:"mouseover",mouseleave:"mouseout"},S=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function L(t,e){return e&&`${e}::${k++}`||t.uidEvent||k++}function O(t){const e=L(t);return t.uidEvent=e,T[e]=T[e]||{},T[e]}function I(t,e,i=null){return Object.values(t).find((t=>t.callable===e&&t.delegationSelector===i))}function D(t,e,i){const s="string"==typeof e,n=s?i:e||i;let o=M(t);return S.has(o)||(o=t),[s,n,o]}function N(t,e,i,s,n){if("string"!=typeof e||!t)return;let[o,r,a]=D(e,i,s);if(e in $){const t=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};r=t(r)}const l=O(t),c=l[a]||(l[a]={}),h=I(c,r,o?i:null);if(h)return void(h.oneOff=h.oneOff&&n);const d=L(r,e.replace(A,"")),u=o?function(t,e,i){return function s(n){const o=t.querySelectorAll(e);for(let{target:r}=n;r&&r!==this;r=r.parentNode)for(const a of o)if(a===r)return F(n,{delegateTarget:r}),s.oneOff&&j.off(t,n.type,e,i),i.apply(r,[n])}}(t,i,r):function(t,e){return function i(s){return F(s,{delegateTarget:t}),i.oneOff&&j.off(t,s.type,e),e.apply(t,[s])}}(t,r);u.delegationSelector=o?i:null,u.callable=r,u.oneOff=n,u.uidEvent=d,c[d]=u,t.addEventListener(a,u,o)}function P(t,e,i,s,n){const o=I(e[i],s,n);o&&(t.removeEventListener(i,o,Boolean(n)),delete e[i][o.uidEvent])}function x(t,e,i,s){const n=e[i]||{};for(const[o,r]of Object.entries(n))o.includes(Line truncated
|
||||
//# sourceMappingURL=bootstrap.min.js.map
|
||||
@@ -0,0 +1,8 @@
|
||||
const dhcp_enabled = document.querySelector("#dhcp_enabled");
|
||||
const dhcp_rect_body = document.querySelector("#dhcp_rect_body");
|
||||
|
||||
dhcp_enabled.addEventListener("click", () => {
|
||||
!dhcp_enabled.checked
|
||||
? dhcp_rect_body.classList.add("hidden")
|
||||
: dhcp_rect_body.classList.remove("hidden");
|
||||
});
|
||||
@@ -0,0 +1,183 @@
|
||||
const upstream_dns_servers_table_body = document.querySelector('#upstream-dns-servers-table-body')
|
||||
const local_domains_table_body = document.querySelector('#local-domains-table-body')
|
||||
const cache_size_input = document.querySelector('#cache-size-input')
|
||||
const save_settings_button = document.querySelector('#save-settings-button')
|
||||
const add_dns_server_button = document.querySelector('#add_dns_server_button')
|
||||
const add_local_domain_button = document.querySelector('#add_local_domain_button')
|
||||
const edit_file_input = document.querySelector('#edit_file_input')
|
||||
const save_config_file_button = document.querySelector('#save_config_file_button')
|
||||
|
||||
var settings = {}
|
||||
var configFile = ""
|
||||
|
||||
const updateDnsServersTable = () => {
|
||||
upstream_dns_servers_table_body.innerHTML = ""
|
||||
for (var i = 0; i < settings.resolv.length; i++) {
|
||||
upstream_dns_servers_table_body.innerHTML += `<tr>
|
||||
<th class="d-flex align-items-center justify-content-between">
|
||||
${settings.resolv[i]}
|
||||
<button id="${i}" class="delete-table-button btn btn-danger">Del</button>
|
||||
</th>
|
||||
</tr>`
|
||||
}
|
||||
}
|
||||
|
||||
const updateLocalDomainsTable = () => {
|
||||
local_domains_table_body.innerHTML = ""
|
||||
for (const [key, value] of Object.entries(settings.hosts)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
local_domains_table_body.innerHTML += `<tr>
|
||||
<th>${key}</th>
|
||||
<th>${value[i]}</th>
|
||||
<th><button class="deldomain btn btn-danger" id="${key}|${value[i]}">Del</button>
|
||||
</th>
|
||||
</tr>`
|
||||
}
|
||||
} else {
|
||||
local_domains_table_body.innerHTML += `<tr>
|
||||
<th>${key}</th>
|
||||
<th>${value}</th>
|
||||
<th><button class="deldomain btn btn-danger" id="${key}|${value}">Del</button>
|
||||
</th>
|
||||
</tr>`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const updateInterface = () => {
|
||||
updateDnsServersTable()
|
||||
updateLocalDomainsTable()
|
||||
cache_size_input.value = settings.cache_size
|
||||
}
|
||||
|
||||
const getSettings = () => {
|
||||
fetch(window.location.origin + "/api/settings")
|
||||
.then(data => data.json())
|
||||
.then(jsondata => {
|
||||
settings = jsondata
|
||||
updateInterface()
|
||||
})
|
||||
}
|
||||
|
||||
const setSettings = () => {
|
||||
fetch(window.location.origin + "/api/settings", {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(settings)
|
||||
}).then(data => data.json())
|
||||
.then(jsondata => {
|
||||
settings = jsondata
|
||||
updateInterface()
|
||||
})
|
||||
}
|
||||
|
||||
save_settings_button.addEventListener('click', () => {
|
||||
setSettings()
|
||||
})
|
||||
|
||||
const write_cache_size = (value) => {
|
||||
settings.cache_size = value
|
||||
}
|
||||
|
||||
cache_size_input.addEventListener('change', (e) => {
|
||||
write_cache_size(e.target.value)
|
||||
})
|
||||
|
||||
cache_size_input.addEventListener('input', (e) => {
|
||||
write_cache_size(e.target.value)
|
||||
})
|
||||
|
||||
getSettings()
|
||||
|
||||
add_dns_server_button.addEventListener('click', () => {
|
||||
const dns_server = prompt("Input your DNS server:")
|
||||
if (dns_server === null) return
|
||||
if (confirm("Confirm DNS settings? (add DNS server)")) {
|
||||
if (Array.isArray(settings.resolv)) {
|
||||
if (!settings.resolv.includes(dns_server)) {
|
||||
settings.resolv.push(dns_server)
|
||||
updateDnsServersTable()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
upstream_dns_servers_table_body.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains("delete-table-button")) {
|
||||
if (confirm(`Confirm DNS settings? (delete DNS server: ${e.target.id})`)) {
|
||||
if (Array.isArray(settings.resolv)) {
|
||||
settings.resolv.splice(e.target.id, 1)
|
||||
updateDnsServersTable()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
add_local_domain_button.addEventListener('click', () => {
|
||||
const domainip = prompt('Input localdomain IP:')
|
||||
if (domainip === null) return
|
||||
const domain = prompt('Input domain:')
|
||||
if (domainip === null || domain === null) return
|
||||
if (confirm(`Confirm DNS settings? (Add Local Domain: ${domainip} ${domain})`)) {
|
||||
for (const [key, value] of Object.entries(settings.hosts)) {
|
||||
if (key === domainip) {
|
||||
if (Array.isArray(value)) {
|
||||
if (!value.includes(domain)) {
|
||||
value.push(domain)
|
||||
updateLocalDomainsTable()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
const domainsarray = [value, domain]
|
||||
settings.hosts[key] = domainsarray
|
||||
updateLocalDomainsTable()
|
||||
return
|
||||
}
|
||||
}
|
||||
settings.hosts[domainip] = domain
|
||||
updateLocalDomainsTable()
|
||||
}
|
||||
})
|
||||
|
||||
local_domains_table_body.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('deldomain')) {
|
||||
if (confirm(`Confirm DNS settings? (delete domain: ${e.target.id})`)) {
|
||||
const domainip = e.target.id.split("|")[0]
|
||||
const domain = e.target.id.split("|")[1]
|
||||
for (const [key, value] of Object.entries(settings.hosts)) {
|
||||
if (key === domainip) {
|
||||
if (Array.isArray(value)) {
|
||||
if (value.includes(domain)) {
|
||||
value.splice(value.indexOf(domain), 1)
|
||||
updateLocalDomainsTable()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
delete settings.hosts[key]
|
||||
updateLocalDomainsTable()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const getConfigFile = () => {
|
||||
fetch(window.location.origin + "/api/settings/file")
|
||||
.then(data => data.text())
|
||||
.then(textdata => edit_file_input.value = textdata)
|
||||
}
|
||||
|
||||
getConfigFile()
|
||||
|
||||
save_config_file_button.addEventListener('click', () => {
|
||||
if (confirm("Save Config file?")) {
|
||||
fetch(window.location.origin + "/api/settings/file", {
|
||||
method: 'POST',
|
||||
body: edit_file_input.value
|
||||
}).then(data => data.text())
|
||||
.then(textdata => edit_file_input.value = textdata)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
const dark_theme = document.querySelector('#dark_theme')
|
||||
|
||||
dark_theme.addEventListener('click', () => {
|
||||
if (dark_theme.checked) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'dark')
|
||||
localStorage.setItem('data-bs-theme', 'dark')
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'light')
|
||||
localStorage.setItem('data-bs-theme', 'light')
|
||||
}
|
||||
})
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
var theme = localStorage.getItem('data-bs-theme')
|
||||
if (theme) {
|
||||
document.documentElement.setAttribute('data-bs-theme', theme)
|
||||
if (theme === 'dark') {
|
||||
dark_theme.checked = true
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"dns_service/settings"
|
||||
"dns_service/utils"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Settings(w http.ResponseWriter, req *http.Request) {
|
||||
switch req.Method {
|
||||
case "GET":
|
||||
respSettings, err := settings.GetSettings()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
utils.RespondWithJSON(w, respSettings, http.StatusOK)
|
||||
case "POST":
|
||||
var newSettings map[string]any
|
||||
if err := json.NewDecoder(req.Body).Decode(&newSettings); err != nil {
|
||||
http.Error(w, "invalid JSON format", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
respSettings, err := settings.SetSettings(newSettings)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
utils.RespondWithJSON(w, respSettings, http.StatusOK)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"dns_service/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func SettingsFile(w http.ResponseWriter, req *http.Request) {
|
||||
configPath := os.Getenv("DNSMASQ_CONFIG")
|
||||
if configPath == "" {
|
||||
http.Error(w, "DNSMASQ_CONFIG environment variable not set", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
switch req.Method {
|
||||
case "GET":
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
http.Error(w, "failed to read dnsmasq config file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write(data)
|
||||
case "POST":
|
||||
bodyBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "failed to read request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(configPath, bodyBytes, 0644); err != nil {
|
||||
http.Error(w, "failed to write dnsmasq config file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err := utils.RestartDnsmasq(); err != nil {
|
||||
http.Error(w, "failed to restart dnsmasq", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write(bodyBytes)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
)
|
||||
|
||||
//go:embed frontend/*
|
||||
var Frontend embed.FS
|
||||
|
||||
func SpaHandler(fs http.FileSystem) http.Handler {
|
||||
fileServer := http.FileServer(fs)
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("/frontend" + r.URL.Path)
|
||||
r.URL.Path = "/frontend" + path.Clean(r.URL.Path)
|
||||
if _, err := fs.Open(path.Clean(r.URL.Path)); err != nil {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user