From 79f60848a40766f53cb0a3944cecedaa0e0b0cbc Mon Sep 17 00:00:00 2001 From: Moe Date: Sun, 11 Jul 2021 11:03:22 -0700 Subject: [PATCH 1/5] Keep Activation box visible --- web/pages/blocks/heyActivate.ejs | 7 ++++--- web/pages/super.ejs | 4 +--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/web/pages/blocks/heyActivate.ejs b/web/pages/blocks/heyActivate.ejs index 024f2c81..cc57cd1d 100644 --- a/web/pages/blocks/heyActivate.ejs +++ b/web/pages/blocks/heyActivate.ejs @@ -1,10 +1,10 @@
- <%- lang['Not Activated'] %> + <%- config.hasSubcribed ? lang['Activated'] : lang['Not Activated'] %>
- +
@@ -42,10 +42,11 @@ noticeTitle = lang.Activated noticeText = lang.activatedText noticeType = 'success' - heyActivateCard.remove() + heyActivateCard.find('[name="subscriptionId"]').val('') }else{ heyActivateCardSubmit.html(lang.Save) } + heyActivateCard.find('.card-header').html(noticeTitle) new PNotify({ title: noticeTitle, text: noticeText, diff --git a/web/pages/super.ejs b/web/pages/super.ejs index 519fb272..74236557 100644 --- a/web/pages/super.ejs +++ b/web/pages/super.ejs @@ -103,9 +103,7 @@
- <% if(!config.userHasSubscribed){ %> - <% include blocks/heyActivate.ejs %> - <% } %> + <% include blocks/heyActivate.ejs %>
 

From 916fb7b8cf534ba8a883d1ef370831f2d64443b9 Mon Sep 17 00:00:00 2001
From: Moe 
Date: Mon, 2 Aug 2021 09:31:02 -0700
Subject: [PATCH 2/5] Fix Zombie Processes

---
 libs/monitor.js       |  5 +--
 libs/monitor/utils.js | 79 +++++++++++++++++++++++--------------------
 2 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/libs/monitor.js b/libs/monitor.js
index 8c5d249a..93ad6354 100644
--- a/libs/monitor.js
+++ b/libs/monitor.js
@@ -24,6 +24,7 @@ module.exports = function(s,config,lang){
         splitForFFPMEG,
     } = require('./ffmpeg/utils.js')(s,config,lang)
     const {
+        processKill,
         cameraDestroy,
         monitorConfigurationMigrator,
     } = require('./monitor/utils.js')(s,config,lang)
@@ -202,14 +203,14 @@ module.exports = function(s,config,lang){
                         })
                         snapProcess.on('error', (data) => {
                             console.log(data)
-                            snapProcess.terminate()
+                            processKill(snapProcess)
                         })
                         snapProcess.on('exit', (code) => {
                             clearTimeout(snapProcessTimeout)
                             sendTempImage()
                         })
                         var snapProcessTimeout = setTimeout(function(){
-                            snapProcess.terminate()
+                            processKill(snapProcess)
                         },dynamicTimeout)
                     }catch(err){
                         console.log(err)
diff --git a/libs/monitor/utils.js b/libs/monitor/utils.js
index 7205340c..bb40d1a9 100644
--- a/libs/monitor/utils.js
+++ b/libs/monitor/utils.js
@@ -6,6 +6,40 @@ module.exports = (s,config,lang) => {
         splitForFFPMEG,
     } = require('../ffmpeg/utils.js')(s,config,lang)
     const getUpdateableFields = require('./updatedFields.js')
+    const processKill = (proc) => {
+        const response = {ok: true}
+        return new Promise((resolve,reject) => {
+            function sendError(err){
+                response.ok = false
+                response.err = err
+                resolve(response)
+            }
+            try{
+                proc.stdin.write("q\r\n")
+                setTimeout(() => {
+                    if(proc && proc.kill){
+                        if(s.isWin){
+                            spawn("taskkill", ["/pid", proc.pid, '/t'])
+                        }else{
+                            proc.kill('SIGTERM')
+                        }
+                        setTimeout(function(){
+                            try{
+                                proc.kill()
+                                resolve(response)
+                            }catch(err){
+                                s.debugLog(err)
+                                sendError(err)
+                            }
+                        },1000)
+                    }
+                },1000)
+            }catch(err){
+                s.debugLog(err)
+                sendError(err)
+            }
+        })
+    }
     const cameraDestroy = function(e,p){
         if(
             s.group[e.ke] &&
@@ -72,27 +106,9 @@ module.exports = (s,config,lang) => {
             if(activeMonitor.childNode){
                 s.cx({f:'kill',d:s.cleanMonitorObject(e)},activeMonitor.childNodeId)
             }else{
-                try{
-                    proc.stdin.write("q\r\n")
-                    setTimeout(() => {
-                        if(proc && proc.kill){
-                            if(s.isWin){
-                                spawn("taskkill", ["/pid", proc.pid, '/t'])
-                            }else{
-                                proc.kill('SIGTERM')
-                            }
-                            setTimeout(function(){
-                                try{
-                                    proc.kill()
-                                }catch(err){
-                                    s.debugLog(err)
-                                }
-                            },1000)
-                        }
-                    },1000)
-                }catch(err){
-                    s.debugLog(err)
-                }
+                processKill(proc).then((response) => {
+                    s.debugLog(`cameraDestroy`,response)
+                })
             }
         }
     }
@@ -126,25 +142,15 @@ module.exports = (s,config,lang) => {
                 // s.debugLog(data.toString())
             })
             snapProcess.on('close',async function(data){
-                clearTimeout(snapProcessTimeout)
+                // clearTimeout(snapProcessTimeout)
                 completeRequest()
             })
             var snapProcessTimeout = setTimeout(function(){
-                var pid = snapProcess.pid
-                if(s.isWin){
-                    spawn("taskkill", ["/pid", pid, '/t'])
-                }else{
-                    process.kill(-pid, 'SIGTERM')
-                }
-                setTimeout(function(){
-                    if(s.isWin === false){
-                        treekill(pid)
-                    }else{
-                        snapProcess.kill()
-                    }
+                processKill(snapProcess).then((response) => {
+                    s.debugLog(`createSnapshot-snapProcessTimeout`,response)
                     completeRequest()
-                },10000)
-            },30000)
+                })
+            },5000)
         })
     }
     const addCredentialsToStreamLink = (options) => {
@@ -192,6 +198,7 @@ module.exports = (s,config,lang) => {
     return {
         cameraDestroy: cameraDestroy,
         createSnapshot: createSnapshot,
+        processKill: processKill,
         addCredentialsToStreamLink: addCredentialsToStreamLink,
         monitorConfigurationMigrator: monitorConfigurationMigrator,
     }

From 4ec40919242e06a5e61c980f80fe5348976ec6b6 Mon Sep 17 00:00:00 2001
From: Moe 
Date: Mon, 2 Aug 2021 10:04:24 -0700
Subject: [PATCH 3/5] Fix Zombie Processes+

---
 libs/monitor/utils.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/monitor/utils.js b/libs/monitor/utils.js
index bb40d1a9..ea2b5698 100644
--- a/libs/monitor/utils.js
+++ b/libs/monitor/utils.js
@@ -142,7 +142,7 @@ module.exports = (s,config,lang) => {
                 // s.debugLog(data.toString())
             })
             snapProcess.on('close',async function(data){
-                // clearTimeout(snapProcessTimeout)
+                clearTimeout(snapProcessTimeout)
                 completeRequest()
             })
             var snapProcessTimeout = setTimeout(function(){

From c951a1b20fe377e20fc766e047ef4bedc96ad287 Mon Sep 17 00:00:00 2001
From: Moe 
Date: Mon, 2 Aug 2021 10:16:01 -0700
Subject: [PATCH 4/5] update platerecognizer

---
 plugins/platerecognizer/README.md    | 78 ++++++++++++++++++++++++++++
 plugins/platerecognizer/package.json |  2 +-
 2 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 plugins/platerecognizer/README.md

diff --git a/plugins/platerecognizer/README.md b/plugins/platerecognizer/README.md
new file mode 100644
index 00000000..8cba2fc8
--- /dev/null
+++ b/plugins/platerecognizer/README.md
@@ -0,0 +1,78 @@
+# PlateRecognizer
+
+> PlateRecognizer is a cloud-based service. You must sign up at http://platerecognizer.com to use this plugin. **In your purchase notes to http://platerecognizer.com be sure to indicate it will be used with Shinobi.**
+
+1. Go to the Shinobi directory. **/home/Shinobi** is the default directory.
+
+```
+cd /home/Shinobi/plugins/platerecognizer
+```
+
+2. Install
+
+```
+sh INSTALL.sh
+```
+
+3. Start the plugin.
+
+```
+pm2 start shinobi-platerecognizer.js
+```
+
+4. Save to startup list. **OPTIONAL**
+
+```
+pm2 save
+```
+
+Doing this will reveal options in the monitor configuration. Shinobi does not need to be restarted when a plugin is initiated or stopped.
+
+## Run the plugin as a Host
+> The main app (Shinobi) will be the client and the plugin will be the host. The purpose of allowing this method is so that you can use one plugin for multiple Shinobi instances. Allowing you to easily manage connections without starting multiple processes.
+
+Edit your plugins configuration file. Set the `hostPort` **to be different** than the `listening port for camera.js`.
+
+```
+nano conf.json
+```
+
+Here is a sample of a Host configuration for the plugin.
+ - `platerecognizerApiKey` is your API Key given by http://platerecognizer.com.
+ - `plug` is the name of the plugin corresponding in the main configuration file.
+ - `https` choose if you want to use SSL or not. Default is `false`.
+ - `hostPort` can be any available port number. **Don't make this the same port number as Shinobi.** Default is `8082`.
+ - `type` tells the main application (Shinobi) what kind of plugin it is. In this case it is a detector.
+
+```
+{
+  "plug":"PlateRecognizer",
+  "platerecognizerApiKey": "11111111111111111",
+  "hostPort":8082,
+  "key":"1234567890",
+  "mode":"host",
+  "type":"detector"
+}
+```
+
+Now modify the **main configuration file** located in the main directory of Shinobi.
+
+```
+nano conf.json
+```
+
+Add the `plugins` array if you don't already have it. Add the following *object inside the array*.
+
+```
+  "plugins":[
+      {
+          "id" : "PlateRecognizer",
+          "https" : false,
+          "host" : "localhost",
+          "port" : 8082,
+          "key" : "1234567890",
+          "mode" : "host",
+          "type" : "detector"
+      }
+  ],
+```
diff --git a/plugins/platerecognizer/package.json b/plugins/platerecognizer/package.json
index e1ffe3e7..4b5298d2 100644
--- a/plugins/platerecognizer/package.json
+++ b/plugins/platerecognizer/package.json
@@ -1,6 +1,6 @@
 {
    "name": "shinobi-platerecognizer",
-   "author": "Elad Bar",
+   "author": "Moe Alam",
    "version": "1.0.0",
    "description": "Object Detection plugin for DeepStack",
    "main": "shinobi-platerecognizer.js",

From c8009a0538f6ede460fd4711744d95ce7694a7f5 Mon Sep 17 00:00:00 2001
From: Mike Hurley 
Date: Tue, 3 Aug 2021 00:33:39 +0000
Subject: [PATCH 5/5] Update package.json to include node-pushover

---
 package.json | 1 +
 1 file changed, 1 insertion(+)

diff --git a/package.json b/package.json
index 0e59bbe4..d830627d 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
     "node-ssh": "^11.1.1",
     "node-telegram-bot-api": "^0.52.0",
     "nodemailer": "^6.4.11",
+    "node-pushover": "^1.0.0",
     "pam-diff": "^1.0.0",
     "path": "^0.12.7",
     "pipe2pam": "^0.6.2",