-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/dist | ||
/conf | ||
|
||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@virtulis/this-computer", | ||
"private": true, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>BASE_HOST</title> | ||
<meta charset="utf8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=yes" /> | ||
<style> | ||
body { | ||
font-family: sans-serif; | ||
padding: 16px; | ||
} | ||
footer { | ||
margin: 16px 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<noscript> | ||
This page requires JavaScript to work. Or use the <a href="https://BASE_HOST/text">text version</a>. | ||
</noscript> | ||
|
||
<main> | ||
<h2>This Computer:</h2> | ||
<dl> | ||
<dt>IPv4:</dt> | ||
<dd id="public4">...</dd> | ||
<dt>IPv6:</dt> | ||
<dd id="public6">...</dd> | ||
</dl> | ||
<button id="copy">Copy</button> | ||
<button id="copy4" disabled>IPv4</button> | ||
<button id="copy6" disabled>IPv6</button> | ||
</main> | ||
|
||
<footer> | ||
100% <a href="https://kludge.guru">kludges</a>. | ||
<a href="https://github.com/virtulis/this-computer">Github</a>. | ||
<a href="https://ko-fi.com/kludge_guru">Ko-fi</a>. | ||
</footer> | ||
|
||
<script type="application/javascript"> | ||
|
||
const timeout = new Promise(resolve => setTimeout(() => resolve(null), 30_000)); | ||
|
||
const ips = {}; | ||
const promises = { | ||
4: Promise.race([timeout, fetch('https://IP4_HOST/').then(res => res.text()).catch(() => null)]), | ||
6: Promise.race([timeout, fetch('https://IP6_HOST/').then(res => res.text()).catch(() => null)]), | ||
}; | ||
Object.entries(promises).forEach(([v, p]) => p.then(str => { | ||
ips[v] = str?.trim(); | ||
document.getElementById(`public${v}`).textContent = str ?? '—'; | ||
document.getElementById(`copy${v}`).disabled = !str; | ||
})); | ||
|
||
document.getElementById('copy').addEventListener('click', async e => { | ||
const lines = Object.values(ips).filter(s => !!s); | ||
if (!lines.length) return; | ||
await navigator.clipboard.writeText(lines.join('\n')); | ||
e.target.textContent = 'Copied'; | ||
}); | ||
[4, 6].forEach(v => document.getElementById(`copy${v}`).addEventListener('click', async e => { | ||
await navigator.clipboard.writeText(ips[v]); | ||
e.target.textContent = 'Copied'; | ||
})); | ||
|
||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
server { | ||
listen 80; | ||
server_name BASE_HOST IP4_HOST IP6_HOST; | ||
location /.well-known { | ||
root /srv/tmp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
|
||
} |