diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6642cf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/dist +/conf + +/.idea diff --git a/build.js b/build.js new file mode 100644 index 0000000..c92c63e --- /dev/null +++ b/build.js @@ -0,0 +1,31 @@ +import { mkdir, readdir, readFile, writeFile } from 'fs/promises'; + +async function main() { + + const args = process.argv.slice(2); + + if (args.length != 4) { + console.log('Usage: node build.js base_host ip4_host ip6_host root_dir'); + return; + } + + const [BASE_HOST, IP4_HOST, IP6_HOST, DIST_DIR] = args; + const vars = { BASE_HOST, IP4_HOST, IP6_HOST, DIST_DIR }; + console.log(vars); + + await mkdir('dist', { recursive: true }); + await mkdir('conf', { recursive: true }); + + const files = await readdir('template'); + for (const fn of files) { + let src = await readFile(`template/${fn}`, 'utf-8'); + for (const [key, val] of Object.entries(vars)) { + src = src.replaceAll(key, val); + } + const out = fn.match(/\.conf$/) ? 'conf' : 'dist'; + await writeFile(`${out}/${fn}`, src); + } + +} + +await main(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..c5124bf --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "@virtulis/this-computer", + "private": true, + "type": "module" +} diff --git a/template/index.html b/template/index.html new file mode 100644 index 0000000..bc8bc94 --- /dev/null +++ b/template/index.html @@ -0,0 +1,73 @@ + + + + BASE_HOST + + + + + + + + + +
+

This Computer:

+
+
IPv4:
+
...
+
IPv6:
+
...
+
+ + + +
+ + + + + + + + \ No newline at end of file diff --git a/template/this-computer-certbot.conf b/template/this-computer-certbot.conf new file mode 100644 index 0000000..279c948 --- /dev/null +++ b/template/this-computer-certbot.conf @@ -0,0 +1,7 @@ +server { + listen 80; + server_name BASE_HOST IP4_HOST IP6_HOST; + location /.well-known { + root /srv/tmp; + } +} diff --git a/template/this-computer.conf b/template/this-computer.conf new file mode 100644 index 0000000..391c1f6 --- /dev/null +++ b/template/this-computer.conf @@ -0,0 +1,43 @@ +map $http_accept $respond_with { + default /text; + ~text/html /index; +} + +server { + + listen 443 ssl http2; + server_name BASE_HOST; + #ssl_certificate /etc/letsencrypt/live/BASE_HOST/fullchain.pem; + #ssl_certificate_key /etc/letsencrypt/live/BASE_HOST/privkey.pem; + + root DIST_DIR; + location = / { + rewrite . $respond_with; + } + location /text { + add_header Cache-Control "no-cache"; + return 200 "$remote_addr\n\nSee also:\nhttps://IP4_HOST\nhttps://IP6_HOST\n"; + } + location / { + add_header Cache-Control "no-cache"; + index index.html; + try_files $uri $uri.html =404; + } + +} + +server { + + listen 443 ssl http2; + server_name IP4_HOST IP6_HOST; + #ssl_certificate /etc/letsencrypt/live/BASE_HOST/fullchain.pem; + #ssl_certificate_key /etc/letsencrypt/live/BASE_HOST/privkey.pem; + + location / { + add_header Content-Type text/plain; + add_header Cache-Control "no-cache"; + add_header Access-Control-Allow-Origin "https://BASE_HOST"; + return 200 "$remote_addr\n"; + } + +}