add renew dns
This commit is contained in:
parent
9cdd088ad7
commit
b6bf8e2367
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.vscode
|
||||
services.json
|
||||
.vscode/**/*
|
||||
|
||||
.env
|
64
renew_dns.ts
Executable file
64
renew_dns.ts
Executable 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);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user