소스 검색

feat(www): expose dyndns status check script on dedyn host, see #193

Peter Thomassen 6 년 전
부모
커밋
5a31a8514a
2개의 변경된 파일113개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      www/conf/sites-available/05-dedyn.conf.var
  2. 106 0
      www/html/check.html

+ 7 - 1
www/conf/sites-available/05-dedyn.conf.var

@@ -27,6 +27,12 @@ server {
 		add_header Strict-Transport-Security "max-age=31536000" always;
 		return 301 https://desec.$DESECSTACK_DOMAIN$request_uri;
 	}
+
+        location =/check {
+		add_header Strict-Transport-Security "max-age=31536000" always;
+		root /usr/share/nginx/html;
+		try_files /check.html =404;
+        }
 }
 server {
 	listen 443 ssl http2;
@@ -40,6 +46,6 @@ server {
 
 	location / {
 		add_header Strict-Transport-Security "max-age=31536000" always;
-		return 301 https://desec.$DESECSTACK_DOMAIN$request_uri;
+		return 301 https://dedyn.$DESECSTACK_DOMAIN$request_uri;
 	}
 }

+ 106 - 0
www/html/check.html

@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>dynDNS Check</title>
+<style>
+body {
+    background: #F8F8F8;
+    font-family: sans-serif;
+}
+h1, h2 {
+    text-align: center;
+}
+#results > div {
+    margin-left: auto;
+    margin-right: auto;
+    max-width: 40em;
+    padding: 1em;
+}
+#footer {
+    font-style: italic;
+    text-align: center;
+}
+#footer a {
+    color: inherit;
+}
+
+.waiting {
+    background: #CCCCCC;
+}
+.success {
+    background: #AAFFAA;
+}
+.warning {
+    background: #FFDDAA;
+}
+.error {
+    background: #FFAAAA;
+}
+</style>
+</head>
+
+<body>
+<h1>dynDNS Check</h1>
+<h2 id="domain">Domain: </h2>
+<div id="results">
+    <div class="waiting" id="ipv4_records"><b>IPv4:</b> <span>checking ...<span></div>
+    <div class="waiting" id="ipv6_records"><b>IPv6:</b> <span>checking ...<span></div>
+</div>
+<p id="footer">dedyn.io is a dynDNS service provided by <a href="https://desec.io/">deSEC</a>.</pre>
+</body>
+
+<script>
+function getRecords(token, domain, type, callback) {
+    var req = new XMLHttpRequest();
+    req.addEventListener("load", callback);
+    req.open("GET", "https://desec.io/api/v1/domains/" + domain + "/rrsets/?subname=&type=" + type);
+    req.setRequestHeader("Authorization", "Token " + token);
+    req.send();
+}
+
+function setRecordsElement(elementId, status, data) {
+    className = "error";
+    if (status == 401) {
+        textContent = "(unauthorized)";
+    } else if (status == 404) {
+        textContent = "[Domain not found]";
+    } else if (status == 200) {
+        if (data.length) {
+            className = "success";
+            textContent = data[0]["records"].join(", ");
+        } else {
+            className = "warning";
+            textContent = "(none)";
+        }
+    } else {
+        textContent = "(check failed)";
+    }
+    element = document.getElementById(elementId)
+    element.className = className;
+    element.lastElementChild.textContent = textContent;
+}
+
+domain = location.search.substr(1)
+token = location.hash.substr(1);
+
+if (domain.length) {
+    document.getElementById("domain").textContent = "Domain: " + domain;
+} else {
+    document.getElementById("domain").textContent = "Domain: (none)";
+}
+
+if (!token.length || !domain.length) {
+    document.getElementById("ipv4_records").lastElementChild.textContent = "(unauthorized)";
+    document.getElementById("ipv6_records").lastElementChild.textContent = "(unauthorized)";
+} else {
+    getRecords(token, domain, "A", function() {
+        setRecordsElement("ipv4_records", this.status, JSON.parse(this.responseText));
+    });
+    getRecords(token, domain, "AAAA", function() {
+        setRecordsElement("ipv6_records", this.status, JSON.parse(this.responseText));
+    });
+}
+</script>
+
+</html>