Add IP service
This commit is contained in:
parent
6d26621417
commit
3dc4f456cc
2 changed files with 65 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
|||
./forgejo.nix
|
||||
./gitlab-runner.nix
|
||||
./hedgedoc.nix
|
||||
./ip.nix
|
||||
./it-tools.nix
|
||||
./mealie.nix
|
||||
./ntfy.nix
|
||||
|
|
|
|||
64
hosts/magnesium/services/ip.nix
Normal file
64
hosts/magnesium/services/ip.nix
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
baseDomain = "jalr.de";
|
||||
webDomain = "ip.${baseDomain}";
|
||||
ip4Domain = "ip4.${baseDomain}";
|
||||
ip6Domain = "ip6.${baseDomain}";
|
||||
in
|
||||
{
|
||||
services.nginx.virtualHosts = lib.attrsets.genAttrs [ ip4Domain ip6Domain ]
|
||||
(_: {
|
||||
enableACME = true;
|
||||
addSSL = true;
|
||||
locations."/" = {
|
||||
return = ''200 "$remote_addr\n"'';
|
||||
extraConfig = ''
|
||||
types { } default_type "text/plain; charset=utf-8";
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
'';
|
||||
};
|
||||
}) // {
|
||||
"${webDomain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
root = pkgs.writeTextDir "index.html" ''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${webDomain}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${webDomain}</h1>
|
||||
<ul>
|
||||
<li><b>IPv6:</b> <span id="ip6" data-url="https://${ip6Domain}/">Loading...</span></li>
|
||||
<li><b>IPv4:</b> <span id="ip4" data-url="https://${ip4Domain}/">Loading...</span></li>
|
||||
</ul>
|
||||
<script>
|
||||
function httpGet(url, loaded, error) {
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("GET", url + "?" + (new Date()).getTime(), true);
|
||||
r.onload = () => {
|
||||
if(r.status == 200) {
|
||||
loaded(r.responseText);
|
||||
}
|
||||
else {
|
||||
error();
|
||||
}
|
||||
};
|
||||
r.onerror = () => {error();};
|
||||
r.send(null);
|
||||
}
|
||||
document.querySelectorAll("span").forEach(el => {
|
||||
httpGet(el.dataset.url,
|
||||
(response) => {el.innerText = response;},
|
||||
() => {el.innerText = "Error";}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue