Files
docker-traefik-labels/rootfs/labels/nsupdate.js
T
2024-01-22 16:50:56 +01:00

33 lines
1.1 KiB
JavaScript

const { spawn } = require('node:child_process');
const { elevenLogJSON } = require('/labels/lib/util.js');
exports.nsupdate = async(server, key, commands) => {
commands.unshift(`server ${server}`);
commands.push('send');
commands.push('quit');
return(new Promise((resolve, reject) => {
elevenLogJSON('debug', {method:'nsupdate()', params:{server:server, key:'******', commands:commands}});
const nsupdate = spawn('/usr/bin/nsupdate', ['-y', key]);
const io = {stdout:'', stderr:''};
nsupdate.stderr.on('data', data => {io.stderr += data.toString()});
nsupdate.stdout.on('data', data => {io.stdout += (data.toString()).replace(/[\r\n]*$/ig, '')});
nsupdate.on('error', error => {reject(error)});
nsupdate.on('close', code =>{
if(code === 0){
if(io.stderr.length > 0){
reject(io.stderr);
}else{
resolve(io.stdout);
}
}else{
reject(io.stderr);
}
});
for(const command of commands){
nsupdate.stdin.write(`${command}\n`);
}
nsupdate.stdin.end();
}));
}