mirror of
https://gitlab.com/Shinobi-Systems/ShinobiCE.git
synced 2025-03-09 15:40:15 +00:00
Solar Plexus
- New Plugin structure with pluginBase.js - New plugins : Object Detection with YoloV3 and Face Detection with Dlib - Fix 2-Factor Authentication
This commit is contained in:
parent
e0f7c135af
commit
24de55e45a
22 changed files with 1268 additions and 899 deletions
50
plugins/dlib/INSTALL.sh
Normal file
50
plugins/dlib/INSTALL.sh
Normal file
|
@ -0,0 +1,50 @@
|
|||
#!/bin/bash
|
||||
THE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
sudo apt update -y
|
||||
sudo apt-get install libx11-dev -y
|
||||
sudo apt-get install libpng-dev -y
|
||||
sudo apt-get install libopenblas-dev -y
|
||||
echo "----------------------------------------"
|
||||
echo "-- Installing Dlib Plugin for Shinobi --"
|
||||
echo "----------------------------------------"
|
||||
if ! [ -x "$(command -v nvidia-smi)" ]; then
|
||||
echo "You need to install NVIDIA Drivers to use this."
|
||||
echo "inside the Shinobi directory run the following :"
|
||||
echo "sh INSTALL/cuda.sh"
|
||||
exit 1
|
||||
else
|
||||
echo "NVIDIA Drivers found..."
|
||||
echo "$(nvidia-smi |grep 'Driver Version')"
|
||||
fi
|
||||
echo "-----------------------------------"
|
||||
if [ ! -d "/usr/local/cuda" ]; then
|
||||
echo "You need to install CUDA Toolkit to use this."
|
||||
echo "inside the Shinobi directory run the following :"
|
||||
echo "sh INSTALL/cuda.sh"
|
||||
exit 1
|
||||
else
|
||||
echo "CUDA Toolkit found..."
|
||||
fi
|
||||
echo "-----------------------------------"
|
||||
if [ ! -e "./conf.json" ]; then
|
||||
echo "Creating conf.json"
|
||||
sudo cp conf.sample.json conf.json
|
||||
else
|
||||
echo "conf.json already exists..."
|
||||
fi
|
||||
npm i npm -g
|
||||
echo "-----------------------------------"
|
||||
echo "Getting node-gyp to build C++ modules"
|
||||
npm install node-gyp -g --unsafe-perm
|
||||
echo "-----------------------------------"
|
||||
echo "Getting C++ module : face-recognition"
|
||||
echo "https://gitlab.com/Shinobi-Systems/face-recognition-js-cuda"
|
||||
npm install --unsafe-perm
|
||||
npm audit fix --force
|
||||
cd $THE_DIR
|
||||
echo "-----------------------------------"
|
||||
echo "Start the plugin with pm2 like so :"
|
||||
echo "pm2 start shinobi-dlib.js"
|
||||
echo "-----------------------------------"
|
||||
echo "Start the plugin without pm2 :"
|
||||
echo "node shinobi-dlib.js"
|
71
plugins/dlib/README.md
Normal file
71
plugins/dlib/README.md
Normal file
|
@ -0,0 +1,71 @@
|
|||
#Dlib Plugin for Shinobi
|
||||
|
||||
**Ubuntu and CentOS only**
|
||||
|
||||
Go to the Shinobi directory. **/home/Shinobi** is the default directory.
|
||||
|
||||
```
|
||||
cd /home/Shinobi/plugins/dlib
|
||||
```
|
||||
|
||||
Copy the config file.
|
||||
|
||||
```
|
||||
sh INSTALL.sh
|
||||
```
|
||||
|
||||
Start the plugin.
|
||||
|
||||
```
|
||||
pm2 start shinobi-dlib.js
|
||||
```
|
||||
|
||||
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.
|
||||
- `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":"Dlib",
|
||||
"hostPort":8082,
|
||||
"key":"Dlib123123",
|
||||
"mode":"host",
|
||||
"type":"detector",
|
||||
"conectionType":"websocket"
|
||||
}
|
||||
```
|
||||
|
||||
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" : "Dlib",
|
||||
"https" : false,
|
||||
"host" : "localhost",
|
||||
"port" : 8082,
|
||||
"key" : "Dlib123123",
|
||||
"mode" : "host",
|
||||
"type" : "detector"
|
||||
}
|
||||
],
|
||||
```
|
9
plugins/dlib/conf.sample.json
Normal file
9
plugins/dlib/conf.sample.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"plug":"Dlib",
|
||||
"host":"localhost",
|
||||
"port":8080,
|
||||
"key":"Dlib123123",
|
||||
"mode":"client",
|
||||
"type":"detector",
|
||||
"connectionType":"websocket"
|
||||
}
|
19
plugins/dlib/package.json
Normal file
19
plugins/dlib/package.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "shinobi-dlib",
|
||||
"version": "1.0.0",
|
||||
"description": "Dlib plugin for Shinobi that uses C++ functions for detection.",
|
||||
"main": "shinobi-dlib.js",
|
||||
"dependencies": {
|
||||
"socket.io-client": "^1.7.4",
|
||||
"express": "^4.16.2",
|
||||
"moment": "^2.19.2",
|
||||
"socket.io": "^2.0.4",
|
||||
"face-recognition-cuda": "0.9.3"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Moe Alam",
|
||||
"license": "ISC"
|
||||
}
|
97
plugins/dlib/shinobi-dlib.js
Normal file
97
plugins/dlib/shinobi-dlib.js
Normal file
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// Shinobi - Dlib Plugin
|
||||
// Copyright (C) 2016-2025 Moe Alam, moeiscool
|
||||
//
|
||||
// # Donate
|
||||
//
|
||||
// If you like what I am doing here and want me to continue please consider donating :)
|
||||
// PayPal : paypal@m03.ca
|
||||
//
|
||||
// Base Init >>
|
||||
var fs = require('fs');
|
||||
var config = require('./conf.json')
|
||||
var s
|
||||
try{
|
||||
s = require('../pluginBase.js')(__dirname,config)
|
||||
}catch(err){
|
||||
console.log(err)
|
||||
try{
|
||||
s = require('./pluginBase.js')(__dirname,config)
|
||||
}catch(err){
|
||||
console.log(err)
|
||||
return console.log(config.plug,'Plugin start has failed. pluginBase.js was not found.')
|
||||
}
|
||||
}
|
||||
// Base Init />>
|
||||
var fr = require('face-recognition-cuda');//modified "binding.gyp" file for "face-recognition" to build dlib with cuda
|
||||
const detector = fr.FaceDetector()
|
||||
s.detectObject=function(buffer,d,tx,frameLocation){
|
||||
var detectStuff = function(frame){
|
||||
try{
|
||||
var buffer = fr.loadImage(frame)
|
||||
var faceRectangles = detector.locateFaces(buffer)
|
||||
var matrices = []
|
||||
faceRectangles.forEach(function(v){
|
||||
var coordinates = [
|
||||
{"x" : v.rect.left, "y" : v.rect.top},
|
||||
{"x" : v.rect.right, "y" : v.rect.top},
|
||||
{"x" : v.rect.right, "y" : v.rect.bottom}
|
||||
]
|
||||
var width = Math.sqrt( Math.pow(coordinates[1].x - coordinates[0].x, 2) + Math.pow(coordinates[1].y - coordinates[0].y, 2));
|
||||
var height = Math.sqrt( Math.pow(coordinates[2].x - coordinates[1].x, 2) + Math.pow(coordinates[2].y - coordinates[1].y, 2))
|
||||
matrices.push({
|
||||
x: coordinates[0].x,
|
||||
y: coordinates[0].y,
|
||||
width: width,
|
||||
height: height,
|
||||
tag: 'UNKNOWN FACE',
|
||||
confidence: v.confidence,
|
||||
})
|
||||
})
|
||||
if(matrices.length > 0){
|
||||
tx({
|
||||
f: 'trigger',
|
||||
id: d.id,
|
||||
ke: d.ke,
|
||||
details:{
|
||||
plug: config.plug,
|
||||
name: 'dlib',
|
||||
reason: 'object',
|
||||
matrices: matrices,
|
||||
imgHeight: parseFloat(d.mon.detector_scale_y),
|
||||
imgWidth: parseFloat(d.mon.detector_scale_x)
|
||||
}
|
||||
})
|
||||
}
|
||||
fs.unlink(frame,function(){
|
||||
|
||||
})
|
||||
}catch(err){
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
if(frameLocation){
|
||||
detectStuff(frameLocation)
|
||||
}else{
|
||||
d.tmpFile=s.gid(5)+'.jpg'
|
||||
if(!fs.existsSync(s.dir.streams)){
|
||||
fs.mkdirSync(s.dir.streams);
|
||||
}
|
||||
d.dir=s.dir.streams+d.ke+'/'
|
||||
if(!fs.existsSync(d.dir)){
|
||||
fs.mkdirSync(d.dir);
|
||||
}
|
||||
d.dir=s.dir.streams+d.ke+'/'+d.id+'/'
|
||||
if(!fs.existsSync(d.dir)){
|
||||
fs.mkdirSync(d.dir);
|
||||
}
|
||||
fs.writeFile(d.dir+d.tmpFile,buffer,function(err){
|
||||
if(err) return s.systemLog(err);
|
||||
try{
|
||||
detectStuff(d.dir+d.tmpFile)
|
||||
}catch(error){
|
||||
console.error('Catch: ' + error);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue