Skip to content

Instantly share code, notes, and snippets.

@makotom
Created September 11, 2014 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makotom/8810f1a7ca20fc3f2732 to your computer and use it in GitHub Desktop.
Save makotom/8810f1a7ca20fc3f2732 to your computer and use it in GitHub Desktop.
Zone file updator for LuaDNS. No longer maintained.
(function(){
var DIRNAME = "/tmp/ddns",
REPORTS_DIR = DIRNAME + "/reports",
ZONEFILE = DIRNAME + "/ddns.makotom.net.lua",
fs = require("fs");
(function(){
var reports = fs.readdirSync(REPORTS_DIR),
table = [],
zone = "";
reports.forEach(function(fileName){
var name = fileName.replace(/\.html$/, ""),
ip6Catch = /REMOTE_ADDR<dd>([0-9a-f:]+)$/m.exec(fs.readFileSync(REPORTS_DIR + "/" + fileName).toString()),
ip6 = (ip6Catch !== null && typeof ip6Catch[1] === typeof "") ? ip6Catch[1] : "::1";
table.push({
name : name,
addr : ip6
});
});
table.forEach(function(record){
zone += "aaaa(\"" + record.name + "\", \"" + record.addr + "\", 300)\n";
});
fs.writeFileSync(ZONEFILE, zone);
})();
})();
#!/usr/bin/bash
WD=$(dirname $(realpath $0))
cd $WD
node buildZone.js
git commit -a -m "Auto update: `date`"
GIT_SSH=$WD/ssh git push -u
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment