thsq-agent
Advanced tools
Comparing version 1.0.33 to 1.0.34
{ | ||
"name": "thsq-agent", | ||
"version": "1.0.33", | ||
"version": "1.0.34", | ||
"description": "Thingsquare agent for Linux gateways", | ||
@@ -5,0 +5,0 @@ "main": "thsq-agent.js", |
62
PPP.js
@@ -11,4 +11,2 @@ /*jslint nomen: true, node: true */ | ||
var dnsserver = '8.8.8.8'; | ||
function cmd(c, options, cb) { | ||
@@ -23,13 +21,12 @@ if (typeof options === 'function') { | ||
function PPP(agent, options) { | ||
var _this = this; | ||
var lastDNS; | ||
function getCurrentDNS() { | ||
var currentDns = '8.8.8.8'; | ||
var logmsg = 'getCurrentDNS(): default: ' + currentDns; | ||
this.agent = agent; | ||
this.d = agent.virtualdevice(); | ||
/* Try to replace default dns server 8.8.8.8 with one found in /etc/resolv.conf */ | ||
/* Try to replace default dns 8.8.8.8 with one found in /etc/resolv.conf */ | ||
try { | ||
if (process.env.THSQ_AGENT_DNS) { | ||
dnsserver = process.env.THSQ_AGENT_DNS; | ||
console.log('read DNS server configuration env THSQ_AGENT_DNS:', dnsserver); | ||
currentDns = process.env.THSQ_AGENT_DNS; | ||
logmsg = 'getCurrentDNS(): env THSQ_AGENT_DNS: ' + currentDns; | ||
} else if (fs.existsSync('/etc/resolv.conf')) { | ||
@@ -40,7 +37,4 @@ var data = fs.readFileSync('/etc/resolv.conf', 'utf8'); | ||
if (line.indexOf('nameserver ') == 0) { | ||
var newdnsserver = line.split(' ')[1]; | ||
if (newdnsserver !== dnsserver) { | ||
dnsserver = newdnsserver; | ||
console.log('read DNS server configuration from /etc/resolv.conf:', dnsserver); | ||
} | ||
currentDns = line.split(' ')[1]; | ||
logmsg = 'getCurrentDNS(): /etc/resolv.conf: ' + currentDns; | ||
} | ||
@@ -51,6 +45,22 @@ }); | ||
} catch(e) { | ||
console.log('error reading DNS server configuration:', e); | ||
console.log('getCurrentDNS(): error:', e); | ||
} | ||
console.log('DNS server configuration:', dnsserver); | ||
if (currentDns != lastDNS) { | ||
lastDNS = currentDns; | ||
console.log(currentDns); | ||
} | ||
return currentDns; | ||
} | ||
function PPP(agent, options) { | ||
var _this = this; | ||
this.agent = agent; | ||
this.d = agent.virtualdevice(); | ||
getCurrentDNS(); | ||
console.log('DNS configuration:', lastDNS); | ||
var active = {}; /* active ppp sessions */ | ||
@@ -112,3 +122,3 @@ setInterval(function() { | ||
var c = 'stty -F ' + file + ' 115200 raw; sleep 1; ' + PPPD_PATH + ' ' + file + ' 115200 ' + netid + '.1:' + netid + '.2 nodefaultroute local nodetach noauth ms-dns ' + dnsserver; | ||
var c = 'stty -F ' + file + ' 115200 raw; sleep 1; ' + PPPD_PATH + ' ' + file + ' 115200 ' + netid + '.1:' + netid + '.2 nodefaultroute local nodetach noauth ms-dns ' + getCurrentDNS(); | ||
console.log('starting pppd for ' + file + ' on subnet ' + netid + '.0...'); | ||
@@ -186,2 +196,10 @@ | ||
cmd('echo \'thsq * "thsq" *\' > /etc/ppp/pap-secrets', function() { | ||
/* Monitor for DNS changes */ | ||
setInterval(function() { | ||
if (lastDNS != getCurrentDNS()) { | ||
console.log('Detected changed DNS configuration, restarting pppd processes:', lastDNS); | ||
cmd('killall pppd'); | ||
} | ||
}, 10 * 1000); | ||
/* Start monitoring serial ports */ | ||
@@ -193,2 +211,10 @@ setInterval(scantty, 10000); | ||
} else { | ||
/* Monitor for DNS changes */ | ||
setInterval(function() { | ||
if (lastDNS != getCurrentDNS()) { | ||
console.log('Detected changed DNS configuration, restarting pppd processes:', lastDNS); | ||
cmd('killall pppd'); | ||
} | ||
}, 10 * 1000); | ||
/* Start monitoring serial ports */ | ||
@@ -195,0 +221,0 @@ setInterval(scantty, 10000); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50948
1180