small fix
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Relay Admin Panel</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
max-width: 600px;
|
||||
margin: 40px auto;
|
||||
}
|
||||
h1 {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
input, button {
|
||||
padding: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
li {
|
||||
margin: 6px 0;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Relay Admin Panel</h1>
|
||||
|
||||
<label>
|
||||
API Key:
|
||||
<input id="apiKey" type="password" style="width: 100%" />
|
||||
</label>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Registered domains</h3>
|
||||
<button onclick="loadDomains()">Refresh</button>
|
||||
<ul id="domains"></ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Add domain</h3>
|
||||
<input id="newDomain" placeholder="example.phone.local" />
|
||||
<button onclick="addDomain()">Add</button>
|
||||
|
||||
<p id="status" class="error"></p>
|
||||
|
||||
<script>
|
||||
const apiBase = "/domains";
|
||||
|
||||
function headers() {
|
||||
return {
|
||||
"apikey": document.getElementById("apiKey").value
|
||||
};
|
||||
}
|
||||
|
||||
async function loadDomains() {
|
||||
const res = await fetch(apiBase, { headers: headers() });
|
||||
if (!res.ok) {
|
||||
showError(res);
|
||||
return;
|
||||
}
|
||||
|
||||
const text = await res.text();
|
||||
const list = document.getElementById("domains");
|
||||
list.innerHTML = "";
|
||||
|
||||
text.trim().split("\n").forEach(domain => {
|
||||
if (!domain) return;
|
||||
|
||||
const li = document.createElement("li");
|
||||
li.textContent = domain + " ";
|
||||
|
||||
const btn = document.createElement("button");
|
||||
btn.textContent = "Delete";
|
||||
btn.onclick = () => deleteDomain(domain);
|
||||
|
||||
li.appendChild(btn);
|
||||
list.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
async function addDomain() {
|
||||
const domain = document.getElementById("newDomain").value;
|
||||
if (!domain) return;
|
||||
|
||||
const res = await fetch(`${apiBase}?domain=${encodeURIComponent(domain)}`, {
|
||||
method: "POST",
|
||||
headers: headers()
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
showError(res);
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById("newDomain").value = "";
|
||||
loadDomains();
|
||||
}
|
||||
|
||||
async function deleteDomain(domain) {
|
||||
const res = await fetch(`${apiBase}?domain=${encodeURIComponent(domain)}`, {
|
||||
method: "DELETE",
|
||||
headers: headers()
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
showError(res);
|
||||
return;
|
||||
}
|
||||
|
||||
loadDomains();
|
||||
}
|
||||
|
||||
function showError(res) {
|
||||
document.getElementById("status").textContent =
|
||||
`Error: ${res.status} ${res.statusText}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+15
-7
@@ -4,6 +4,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"relay/device"
|
||||
tunnelpb "relay/proto/tunnel"
|
||||
"relay/registry"
|
||||
)
|
||||
|
||||
@@ -40,19 +42,25 @@ func domainsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
case "DELETE":
|
||||
domain := strings.ToLower(r.URL.Query().Get("domain"))
|
||||
|
||||
var dev *device.Device
|
||||
var existed bool
|
||||
|
||||
registry.Global.Mu.Lock()
|
||||
if _, exists := registry.Global.Domains[domain]; exists {
|
||||
if d, ok := registry.Global.Domains[domain]; ok {
|
||||
existed = true
|
||||
dev = d
|
||||
delete(registry.Global.Domains, domain)
|
||||
adminLogger.Printf(
|
||||
"ADMIN DELETE domain=%s ip=%s",
|
||||
domain, r.RemoteAddr,
|
||||
)
|
||||
}
|
||||
registry.Global.Mu.Unlock()
|
||||
|
||||
w.Write([]byte("deleted\n"))
|
||||
if existed && dev != nil {
|
||||
dev.SendFrame(&tunnelpb.Frame{
|
||||
Type: tunnelpb.FrameType_FRAME_BIND_REJECTED,
|
||||
Payload: []byte(domain),
|
||||
})
|
||||
}
|
||||
|
||||
default:
|
||||
http.Error(w, "method not allowed", 405)
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user