add renew dns

This commit is contained in:
monoid 2024-02-07 22:42:33 +09:00
parent 9cdd088ad7
commit b6bf8e2367
2 changed files with 65 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
.vscode .vscode
services.json services.json
.vscode/**/* .vscode/**/*
.env

64
renew_dns.ts Executable file
View File

@ -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("<text>")
.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);
}