diff --git a/beacon.js b/beacon.js index a9cabdc..8b202e0 100644 --- a/beacon.js +++ b/beacon.js @@ -13,6 +13,7 @@ var Beacon = function(options) { this.interval = options.interval || 1*60*60*1000; this._timer = null; this.running = false; + this.consent_for_beacon = "false"; } function setURL(url) { this.set('url', url); } @@ -20,9 +21,9 @@ function setInterval(interval) { this.set('interval', interval); } // Changing any of the options provokes a new beacon report Beacon.prototype.set = function(key, value) { + this[key] = value; var wasRunning = this.running; this.stop(); - this[key] = value; if(wasRunning) { this.run('config'); } } @@ -34,13 +35,17 @@ Beacon.prototype.start = function(reason) { // Function called at intervals to report to the beacon Beacon.prototype.run = function(reason) { - this.report(reason) - .catch(function(err) { - log.warn('Could not send a beacon message: ' + err); - }) - .finally(function() { - this._timer = setTimeout(this.run.bind(this), this.interval); - }.bind(this)); + if (this.consent_for_beacon === "true"){ + this.report(reason) + .catch(function(err) { + log.warn('Could not send a beacon message: ' + err); + }) + .finally(function() { + this._timer = setTimeout(this.run.bind(this), this.interval); + }.bind(this)); + } else { + log.warn('Beacon is not enabled'); + } } // Stops further beacon reports. Reports can be restarted with start() diff --git a/static/index.html b/static/index.html index 37d9832..0df2321 100644 --- a/static/index.html +++ b/static/index.html @@ -204,7 +204,6 @@

Configuration

  • diff --git a/updater.js b/updater.js index c40a596..cbd572e 100644 --- a/updater.js +++ b/updater.js @@ -589,15 +589,20 @@ Updater.prototype.start = function(callback) { function setup_config_events(callback) { config.updater.on('change', function(evt) { + if(evt.packages_url) { this.runAllPackageChecks(); } if(evt.beacon_url) { - this.beacon.set(config.updater.get('beacon_url')); + this.beacon.set('url', config.updater.get('beacon_url')); } if(evt.name) { this.beacon.once('config'); } + if (evt.consent_for_beacon) { + this.beacon.set("consent_for_beacon", evt.consent_for_beacon); + log.info("Consent for beacon is " + evt.consent_for_beacon); + } }.bind(this)); callback(); }.bind(this), @@ -628,7 +633,7 @@ Updater.prototype.start = function(callback) { } }.bind(this), - function start_beacon(callback) { + function start_beacon(callback) { var url = config.updater.get('beacon_url'); var consent = config.updater.get('consent_for_beacon'); @@ -639,10 +644,13 @@ Updater.prototype.start = function(callback) { }); if (consent === "true"){ - this.beacon.start(); + this.beacon.set("consent_for_beacon", consent); + log.info("Beacon is enabled"); } else if (consent === "false"){ - log.error("Beacon is not consented to"); + this.beacon.set("consent_for_beacon", consent); + log.info("Beacon is disabled"); } + this.beacon.start(); }.bind(this) ], function(err, results) {