From b6bf8e23679eb5ee491079f2661d720f67545276 Mon Sep 17 00:00:00 2001 From: monoid Date: Wed, 7 Feb 2024 22:42:33 +0900 Subject: [PATCH] add renew dns --- .gitignore | 2 +- renew_dns.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 renew_dns.ts diff --git a/.gitignore b/.gitignore index b57b2b2..df6e15e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .vscode services.json .vscode/**/* - +.env \ No newline at end of file diff --git a/renew_dns.ts b/renew_dns.ts new file mode 100755 index 0000000..97d8a69 --- /dev/null +++ b/renew_dns.ts @@ -0,0 +1,64 @@ +#!/usr/bin/env -S /root/.deno/bin/deno run --allow-env --allow-read --unstable --allow-sys --allow-run --allow-write +import {load} from "https://deno.land/std@0.214.0/dotenv/mod.ts"; +import { Command } from "https://deno.land/x/cliffy@v0.25.7/mod.ts"; + +async function changeTextRecord(domain: string, token:string, text: string){ + const url = `https://www.duckdns.org/update?domains=${domain}&token=${token}&txt=${text}` + const res = await fetch(url); + const c = await res.text() + return c === "OK" +} + + +const env = await load(); +const domain = env.DUCKDNS_DOMAIN; +const token = env.DUCKDNS_TOKEN; +/* +sudo certbot certonly --manual --preferred-challenges dns --renew-by-default -d "*.pages.prelude.duckdns.org" +*/ +if(import.meta.main){ + if (!domain || !token){ + console.log("Env not found!"); + Deno.exit(1); + } + + //const cmd = new Deno.Command("certbot",{ + // args:[ + // "certonly", + // "--manual", + // "--preferred-challenges", + // "dns", + // "--renew-by-default", + // "-d", "*.pages.prelude.duckdns.org" + // ], + // stdin: "piped", + // stdout: "piped", + //}); +// + //const proc = cmd.spawn(); + //await proc.stdout.pipeTo(Deno.stdout.writable); + + await new Command() + .name("renew_dns") + .description("Duckdns TXT Record renewer") + .version("v1.0.0") + .option("-q, --quiet", "disable output.") + .arguments("") + .action(async ({quiet},text)=>{ + const s = await changeTextRecord(domain, token, text); + if (s) { + if (!quiet){ + console.log("success!"); + } + Deno.exit(0); + } + else { + if(!quiet){ + console.log("failed!"); + } + Deno.exit(1); + } + }) + .parse(Deno.args); + +}