Add option for automatic private backup of monitors to ShinobiHub
- This feature is for Subscribers only.build-default-monitor-config-from-definitions
parent
410a6de983
commit
3f0efd3c5c
|
@ -80,6 +80,8 @@ require('./libs/ffmpeg.js')(s,config,lang,function(ffmpeg){
|
|||
//custom module loader
|
||||
require('./libs/customAutoLoad.js')(s,config,lang,app,io)
|
||||
//scheduling engine
|
||||
require('./libs/shinobiHub.js')(s,config,lang,app,io)
|
||||
//scheduling engine
|
||||
require('./libs/scheduler.js')(s,config,lang,app,io)
|
||||
//on-start actions, daemon(s) starter
|
||||
require('./libs/startup.js')(s,config,lang)
|
||||
|
|
|
@ -3927,6 +3927,43 @@ module.exports = function(s,config,lang){
|
|||
"Account Settings": {
|
||||
"section": "Account Settings",
|
||||
"blocks": {
|
||||
"ShinobiHub": {
|
||||
"evaluation": "!details.sub && details.use_shinobihub !== '0'",
|
||||
"name": lang["ShinobiHub"],
|
||||
"color": "purple",
|
||||
"info": [
|
||||
{
|
||||
"name": "detail=shinobihub",
|
||||
"selector":"autosave_shinobihub",
|
||||
"field": lang.Autosave,
|
||||
"description": "",
|
||||
"default": "0",
|
||||
"example": "",
|
||||
"fieldType": "select",
|
||||
"possible": [
|
||||
{
|
||||
"name": lang.No,
|
||||
"value": "0"
|
||||
},
|
||||
{
|
||||
"name": lang.Yes,
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hidden": true,
|
||||
"field": lang['API Key'],
|
||||
"name": "detail=shinobihub_key",
|
||||
"placeholder": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||
"form-group-class": "autosave_shinobihub_input autosave_shinobihub_1",
|
||||
"description": "",
|
||||
"default": "",
|
||||
"example": "",
|
||||
"possible": ""
|
||||
},
|
||||
]
|
||||
},
|
||||
"2-Factor Authentication": {
|
||||
"name": lang['2-Factor Authentication'],
|
||||
"color": "grey",
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
"Remember Me": "Remember Me",
|
||||
"Process Already Running": "Process Already Running",
|
||||
"Process Not Running": "Process Not Running",
|
||||
"ShinobiHub": "ShinobiHub",
|
||||
"Play": "Play",
|
||||
"Pause": "Pause",
|
||||
"RAM": "RAM",
|
||||
|
|
|
@ -251,7 +251,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
var split = address.address.split('@')
|
||||
var monitorId = split[0]
|
||||
var ke = session.user
|
||||
if(s.group[ke].rawMonitorConfigurations[monitorId] && s.group[ke].activeMonitors[monitorId].isStarted === true){
|
||||
if(s.group[ke] && s.group[ke].rawMonitorConfigurations[monitorId] && s.group[ke].activeMonitors[monitorId].isStarted === true){
|
||||
session.monitorId = monitorId
|
||||
}else{
|
||||
return callback(new Error(lang['No Monitor Exists with this ID.']))
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
var fs = require('fs')
|
||||
var request = require('request')
|
||||
module.exports = function(s,config,lang,app,io){
|
||||
if(config.shinobiHubEndpoint === undefined){config.shinobiHubEndpoint = `https://hub.shinobi.video/`}else{config.shinobiHubEndpoint = s.checkCorrectPathEnding(config.shinobiHubEndpoint)}
|
||||
var stripUsernameAndPassword = function(string,username,password){
|
||||
if(username)string = string.split(username).join('_USERNAME_')
|
||||
if(password)string = string.split(password).join('_PASSWORD_')
|
||||
return string
|
||||
}
|
||||
var validatePostConfiguration = function(fields){
|
||||
var response = {ok: true}
|
||||
var fieldsJson
|
||||
if(!fields.json)fields.json = '{}'
|
||||
try{
|
||||
fieldsJson = JSON.parse(fields.json)
|
||||
}catch(err){
|
||||
response.ok = false
|
||||
response.msg = ('Configuration is not JSON format.')
|
||||
}
|
||||
if(!fields.details)fields.details = '{}'
|
||||
try{
|
||||
fieldsDetails = JSON.parse(fields.details)
|
||||
}catch(err){
|
||||
fieldsDetails = {}
|
||||
}
|
||||
if(
|
||||
fields.name === '' ||
|
||||
fields.brand === '' ||
|
||||
fields.json === ''
|
||||
){
|
||||
response.ok = false
|
||||
response.msg = ('The form is incomplete.')
|
||||
}
|
||||
if(!fields.description)fields.description = ''
|
||||
if(!fieldsJson.mid){
|
||||
response.ok = false
|
||||
response.msg = ('The monitor configuration is incomplete.')
|
||||
}
|
||||
var monitorDetails = s.parseJSON(fieldsJson.details)
|
||||
fieldsJson.details = monitorDetails || {}
|
||||
|
||||
fieldsJson.details.auto_host = stripUsernameAndPassword(fieldsJson.details.auto_host,fieldsJson.details.muser,fieldsJson.details.mpass)
|
||||
fieldsJson.path = stripUsernameAndPassword(fieldsJson.path,fieldsJson.details.muser,fieldsJson.details.mpass)
|
||||
fieldsJson.details.muser = '_USERNAME_'
|
||||
fieldsJson.details.mpass = '_PASSWORD_'
|
||||
|
||||
response.json = JSON.stringify(fieldsJson)
|
||||
response.details = JSON.stringify(fieldsDetails)
|
||||
return response
|
||||
}
|
||||
const uploadConfiguration = (shinobiHubApiKey,type,monitorConfig,callback) => {
|
||||
var validated = validatePostConfiguration({
|
||||
json: JSON.stringify(monitorConfig)
|
||||
})
|
||||
if(validated.ok === true){
|
||||
request.post({
|
||||
url: `${config.shinobiHubEndpoint}api/${shinobiHubApiKey}/postConfiguration`,
|
||||
form: {
|
||||
"type": type,
|
||||
"brand": monitorConfig.ke,
|
||||
"name": monitorConfig.mid,
|
||||
"description": "Backup at " + (new Date()),
|
||||
"json": validated.json,
|
||||
"details": JSON.stringify({
|
||||
// maybe ip address?
|
||||
})
|
||||
}
|
||||
}, function(err,httpResponse,body){
|
||||
callback(err,s.parseJSON(body) || {ok: false})
|
||||
})
|
||||
}else{
|
||||
callback(new Error(validated.msg),{ok: false})
|
||||
}
|
||||
}
|
||||
const onMonitorSave = async (monitorConfig,form) => {
|
||||
if(config.shinobiHubAutoBackup === true && config.shinobiHubApiKey){
|
||||
uploadConfiguration(config.shinobiHubApiKey,'cam',monitorConfig,() => {
|
||||
// s.userLog({ke:monitorConfig.ke,mid:'$USER'},{type:lang['Websocket Connected'],msg:{for:lang['Superuser'],id:cn.mail,ip:cn.ip}})
|
||||
})
|
||||
}
|
||||
if(s.group[monitorConfig.ke] && s.group[monitorConfig.ke].init.shinobihub === '1'){
|
||||
uploadConfiguration(s.group[monitorConfig.ke].init.shinobihub_key,'cam',monitorConfig,() => {
|
||||
// s.userLog({ke:monitorConfig.ke,mid:'$USER'},{type:lang['Websocket Connected'],msg:{for:lang['Superuser'],id:cn.mail,ip:cn.ip}})
|
||||
})
|
||||
}
|
||||
}
|
||||
s.onMonitorSave(onMonitorSave)
|
||||
}
|
Loading…
Reference in New Issue