From 5f4f580c41c1215b8dea74cbae0434c1f48e831c Mon Sep 17 00:00:00 2001 From: Moe Date: Wed, 14 Nov 2018 19:24:34 -0800 Subject: [PATCH 1/7] API call for getting Monitor State Presets --- libs/webServerAdminPaths.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libs/webServerAdminPaths.js b/libs/webServerAdminPaths.js index 7cebd975..7d4809ba 100644 --- a/libs/webServerAdminPaths.js +++ b/libs/webServerAdminPaths.js @@ -364,6 +364,36 @@ module.exports = function(s,config,lang,app){ },res,req) }) /** + * API : Administrator : Get Monitor State Presets List + */ + app.get([ + config.webPaths.apiPrefix+':auth/monitorStates/:ke', + config.webPaths.adminApiPrefix+':auth/monitorStates/:ke' + ],function (req,res){ + s.auth(req.params,function(user){ + var endData = { + ok : false + } + if(user.details.sub){ + endData.msg = user.lang['Not Permitted'] + s.closeJsonResponse(res,endData) + return + } + s.sqlQuery("SELECT * FROM Presets WHERE ke=? AND type=?",[req.params.ke,'monitorStates'],function(err,presets){ + if(presets && presets[0]){ + endData.ok = true + presets.forEach(function(preset){ + preset.details = JSON.parse(preset.details) + }) + endData.presets = presets + }else{ + endData.msg = user.lang['State Configuration Not Found'] + } + s.closeJsonResponse(res,endData) + }) + }) + }) + /** * API : Administrator : Change Group Preset. Currently affects Monitors only. */ app.all([ From 219fdd1139c4b09c43b70295c0a89e72ca04800a Mon Sep 17 00:00:00 2001 From: Moe Date: Wed, 14 Nov 2018 19:24:50 -0800 Subject: [PATCH 2/7] Fix 2-Factor Authentication --- libs/webServerPaths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/webServerPaths.js b/libs/webServerPaths.js index c01f26fd..77b03000 100644 --- a/libs/webServerPaths.js +++ b/libs/webServerPaths.js @@ -18,6 +18,7 @@ module.exports = function(s,config,lang,app,io){ s.renderPage = function(req,res,paths,passables,callback){ passables.window = {} passables.originalURL = s.getOriginalUrl(req) + passables.config = config res.render(paths,passables,callback) } //child node proxy check From 950dd9bf3706bf34557cc67673084a6b9b338bf4 Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 15 Nov 2018 10:29:23 -0800 Subject: [PATCH 3/7] Make Built-In Motion Detector Matrix optional --- languages/en_CA.json | 2 + libs/detector.js | 6 ++- libs/detectorPamDiff.js | 74 +++++++++++++++++++++++++++++++- web/pages/blocks/monitoredit.ejs | 8 ++++ 4 files changed, 87 insertions(+), 3 deletions(-) diff --git a/languages/en_CA.json b/languages/en_CA.json index e72d9525..896b7793 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -649,6 +649,8 @@ "Thumbnail": "Thumbnail", "Host Type": "Host Type", "Edit": "Edit", + "Show Matrices": "Show Matrices", + "Show Matrix": "Show Matrix", "No Monitor ID Present in Form": "No Monitor ID Present in Form", "State Configuration has no monitors associated": "State Configuration has no monitors associated", "State Configuration Not Found": "State Configuration Not Found", diff --git a/libs/detector.js b/libs/detector.js index 2ea40344..eac722fa 100644 --- a/libs/detector.js +++ b/libs/detector.js @@ -53,7 +53,11 @@ module.exports = function(s,config){ var regions = s.createPamDiffRegionArray(regionJson,globalColorThreshold,globalSensitivity,fullFrame) - s.group[e.ke].mon[e.id].pamDiff = new PamDiff({grayscale: 'luminosity', regions : regions.forPam}); + s.group[e.ke].mon[e.id].pamDiff = new PamDiff({ + grayscale: 'luminosity', + regions : regions.forPam, + drawMatrix : e.details.detector_show_matrix + }); s.group[e.ke].mon[e.id].p2p = new P2P(); var sendTrigger = function(trigger){ var detectorObject = { diff --git a/libs/detectorPamDiff.js b/libs/detectorPamDiff.js index a24ef3b8..690adcc5 100644 --- a/libs/detectorPamDiff.js +++ b/libs/detectorPamDiff.js @@ -44,6 +44,7 @@ class PamDiff extends Transform { this.difference = PamDiff._parseOptions('difference', options);//global option, can be overridden per region this.percent = PamDiff._parseOptions('percent', options);//global option, can be overridden per region this.regions = PamDiff._parseOptions('regions', options);//can be no regions or a single region or multiple regions. if no regions, all pixels will be compared. + this.drawMatrix = PamDiff._parseOptions('drawMatrix', options);//can be no regions or a single region or multiple regions. if no regions, all pixels will be compared. this.callback = callback;//callback function to be called when pixel difference is detected this._parseChunk = this._parseFirstChunk;//first parsing will be reading settings and configuring internal pixel reading } @@ -331,7 +332,7 @@ class PamDiff extends Transform { * @param chunk * @private */ - _grayScalePixelDiff(chunk) { + _grayScalePixelDiffWithMatrices(chunk) { this._newPix = chunk.pixels; for (let j = 0; j < this._regionsLength; j++) { this._regions[j].topLeft = { @@ -430,6 +431,71 @@ class PamDiff extends Transform { this._oldPix = this._newPix; } + /** + * + * @param chunk + * @private + */ + _grayScalePixelDiff(chunk) { + this._newPix = chunk.pixels; + for (let y = 0, i = 0; y < this._height; y++) { + for (let x = 0; x < this._width; x++, i++) { + if (this._oldPix[i] !== this._newPix[i]) { + const diff = Math.abs(this._oldPix[i] - this._newPix[i]); + if (this._regions && diff >= this._minDiff) { + for (let j = 0; j < this._regionsLength; j++) { + if (this._pointsInPolygons[j][i] && diff >= this._regions[j].difference) { + this._regions[j].diffs++; + } + } + } else { + if (diff >= this._difference) { + this._diffs++; + } + } + } + } + } + if (this._regions) { + const regionDiffArray = []; + for (let i = 0; i < this._regionsLength; i++) { + const percent = Math.floor(100 * this._regions[i].diffs / this._regions[i].pointsLength); + if (percent >= this._regions[i].percent) { + regionDiffArray.push({name: this._regions[i].name, percent: percent}); + } + this._regions[i].diffs = 0; + } + if (regionDiffArray.length > 0) { + const data = {trigger: regionDiffArray, pam: chunk.pam}; + if (this._callback) { + this._callback(data); + } + if (this._readableState.pipesCount > 0) { + this.push(data); + } + if (this.listenerCount('diff') > 0) { + this.emit('diff', data); + } + } + } else { + const percent = Math.floor(100 * this._diffs / this._length); + if (percent >= this._percent) { + const data = {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}; + if (this._callback) { + this._callback(data); + } + if (this._readableState.pipesCount > 0) { + this.push(data); + } + if (this.listenerCount('diff') > 0) { + this.emit('diff', data); + } + } + this._diffs = 0; + } + this._oldPix = this._newPix; + } + /** * * @param chunk @@ -576,7 +642,11 @@ class PamDiff extends Transform { this._parseChunk = this._blackAndWhitePixelDiff; break; case 'grayscale' : - this._parseChunk = this._grayScalePixelDiff; + if(this.drawMatrix === "1"){ + this._parseChunk = this._grayScalePixelDiffWithMatrices; + }else{ + this._parseChunk = this._grayScalePixelDiff; + } break; case 'rgb' : this._parseChunk = this._rgbPixelDiff; diff --git a/web/pages/blocks/monitoredit.ejs b/web/pages/blocks/monitoredit.ejs index d112d56e..c83a5fda 100644 --- a/web/pages/blocks/monitoredit.ejs +++ b/web/pages/blocks/monitoredit.ejs @@ -1065,6 +1065,14 @@ +
+ +