Merge branch 'dev' into 'master'

Cron Fix and Minor Updates

See merge request Shinobi-Systems/Shinobi!2
merge-requests/5/head
Moe 2018-06-13 01:05:53 +00:00
commit 930d5873d6
5 changed files with 44 additions and 15 deletions

View File

@ -12,7 +12,7 @@ Defintions.
"Licenser" shall mean SHINOBI SYSTEMS "Licenser" shall mean SHINOBI SYSTEMS
"Licensee" shall mean YOU, or the organisation (if any) on whose behalf YOU are taking the EULA. "Licensee" shall mean YOU, or the organisation (if any) on whose behalf YOU are taking the EULA.
"SOFTWARE PRODUCTS" or "SOFTWARE" or "PRODUCTS" shall mean GMASTER and any additional modules or add-ons delivered by Shinobi Systems. The term "SOFTWARE" includes, to the extent provided by SHINOBI SYSTEMS: 1) any revisions, updates and/or upgrades thereto; 2) any data, image or executable files, databases, data engines, computer software, or similar items customarily used or distributed with computer software products; 3) anything in any form whatsoever intended to be used with or in conjunction with the SOFTWARE; and 4) any associated media, documentation (including physical, electronic and on-line) and printed materials (the "Documentation"). "SOFTWARE PRODUCTS" or "SOFTWARE" or "PRODUCTS" shall mean the Software Product this License is included with and any additional modules or add-ons delivered by Shinobi Systems. The term "SOFTWARE" includes, to the extent provided by SHINOBI SYSTEMS: 1) any revisions, updates and/or upgrades thereto; 2) any data, image or executable files, databases, data engines, computer software, or similar items customarily used or distributed with computer software products; 3) anything in any form whatsoever intended to be used with or in conjunction with the SOFTWARE; and 4) any associated media, documentation (including physical, electronic and on-line) and printed materials (the "Documentation").
Purpose of the Agreement. Purpose of the Agreement.

View File

@ -12,7 +12,7 @@ Defintions.
"Licenser" shall mean SHINOBI SYSTEMS "Licenser" shall mean SHINOBI SYSTEMS
"Licensee" shall mean YOU, or the organisation (if any) on whose behalf YOU are taking the EULA. "Licensee" shall mean YOU, or the organisation (if any) on whose behalf YOU are taking the EULA.
"SOFTWARE PRODUCTS" or "SOFTWARE" or "PRODUCTS" shall mean GMASTER and any additional modules or add-ons delivered by Shinobi Systems. The term "SOFTWARE" includes, to the extent provided by SHINOBI SYSTEMS: 1) any revisions, updates and/or upgrades thereto; 2) any data, image or executable files, databases, data engines, computer software, or similar items customarily used or distributed with computer software products; 3) anything in any form whatsoever intended to be used with or in conjunction with the SOFTWARE; and 4) any associated media, documentation (including physical, electronic and on-line) and printed materials (the "Documentation"). "SOFTWARE PRODUCTS" or "SOFTWARE" or "PRODUCTS" shall mean the Software Product this License is included with and any additional modules or add-ons delivered by Shinobi Systems. The term "SOFTWARE" includes, to the extent provided by SHINOBI SYSTEMS: 1) any revisions, updates and/or upgrades thereto; 2) any data, image or executable files, databases, data engines, computer software, or similar items customarily used or distributed with computer software products; 3) anything in any form whatsoever intended to be used with or in conjunction with the SOFTWARE; and 4) any associated media, documentation (including physical, electronic and on-line) and printed materials (the "Documentation").
Purpose of the Agreement. Purpose of the Agreement.

View File

@ -100,7 +100,7 @@ http://shinobi.video/why
2. Download and run the installer. 2. Download and run the installer.
``` ```
bash <(curl -s https://raw.githubusercontent.com/ShinobiCCTV/Shinobi-Installer/master/shinobi-install.sh) bash <(curl -s https://gitlab.com/Shinobi-Systems/Shinobi-Installer/raw/master/shinobi-install.sh)
``` ```
#### Elaborate Installs #### Elaborate Installs

48
cron.js
View File

@ -10,7 +10,9 @@ var spawn = require('child_process').spawn;
var config=require('./conf.json'); var config=require('./conf.json');
//set option defaults //set option defaults
s={}; s={
utcOffset : moment().utcOffset()
};
if(config.cron===undefined)config.cron={}; if(config.cron===undefined)config.cron={};
if(config.cron.deleteOld===undefined)config.cron.deleteOld=true; if(config.cron.deleteOld===undefined)config.cron.deleteOld=true;
if(config.cron.deleteOrphans===undefined)config.cron.deleteOrphans=false; if(config.cron.deleteOrphans===undefined)config.cron.deleteOrphans=false;
@ -23,6 +25,8 @@ if(config.cron.deleteFileBins===undefined)config.cron.deleteFileBins=true;
if(config.cron.interval===undefined)config.cron.interval=1; if(config.cron.interval===undefined)config.cron.interval=1;
if(config.databaseType===undefined){config.databaseType='mysql'} if(config.databaseType===undefined){config.databaseType='mysql'}
if(config.databaseLogs===undefined){config.databaseLogs=false} if(config.databaseLogs===undefined){config.databaseLogs=false}
if(config.useUTC===undefined){config.useUTC=false}
if(config.debugLog===undefined){config.debugLog=false}
if(!config.ip||config.ip===''||config.ip.indexOf('0.0.0.0')>-1)config.ip='localhost'; if(!config.ip||config.ip===''||config.ip.indexOf('0.0.0.0')>-1)config.ip='localhost';
if(!config.videosDir)config.videosDir=__dirname+'/videos/'; if(!config.videosDir)config.videosDir=__dirname+'/videos/';
@ -102,11 +106,18 @@ s.sqlQuery = function(query,values,onMoveOn,hideLog){
} }
onMoveOn(err,r) onMoveOn(err,r)
}else{ }else{
console.log(onMoveOn) s.debugLog('onMoveOn',onMoveOn)
} }
}) })
} }
s.debugLog = function(arg1,arg2){
if(config.debugLog === true){
if(!arg2)arg2 = ''
console.log(arg1,arg2)
}
}
//containers //containers
s.overlapLock={}; s.overlapLock={};
s.alreadyDeletedRowsWithNoVideosOnStart={}; s.alreadyDeletedRowsWithNoVideosOnStart={};
@ -127,6 +138,12 @@ s.moment=function(e,x){
if(!e){e=new Date};if(!x){x='YYYY-MM-DDTHH-mm-ss'}; if(!e){e=new Date};if(!x){x='YYYY-MM-DDTHH-mm-ss'};
return moment(e).format(x); return moment(e).format(x);
} }
s.utcToLocal = function(time){
return moment.utc(time).utcOffset(s.utcOffset).format()
}
s.localToUtc = function(time){
return moment(time).utc()
}
s.nameToTime=function(x){x=x.replace('.webm','').replace('.mp4','').split('T'),x[1]=x[1].replace(/-/g,':');x=x.join(' ');return x;} s.nameToTime=function(x){x=x.replace('.webm','').replace('.mp4','').split('T'),x[1]=x[1].replace(/-/g,':');x=x.join(' ');return x;}
io = require('socket.io-client')('ws://'+config.ip+':'+config.port);//connect to master io = require('socket.io-client')('ws://'+config.ip+':'+config.port);//connect to master
s.cx=function(x){x.cronKey=config.cron.key;return io.emit('cron',x)} s.cx=function(x){x.cronKey=config.cron.key;return io.emit('cron',x)}
@ -260,12 +277,18 @@ s.deleteRowsWithNoVideo=function(v,callback){
if(evs&&evs[0]){ if(evs&&evs[0]){
es.del=[];es.ar=[v.ke]; es.del=[];es.ar=[v.ke];
evs.forEach(function(ev){ evs.forEach(function(ev){
ev.dir=s.getVideoDirectory(ev)+s.moment(ev.time)+'.'+ev.ext; var details = JSON.parse(ev.details)
if(fs.existsSync(ev.dir)!==true){ var filename = ev.time
var dir = s.getVideoDirectory(ev)+s.moment(filename)+'.'+ev.ext;
var fileExists = fs.existsSync(dir)
if(details.isUTC === true){
filename = s.localToUtc(filename).format('YYYY-MM-DDTHH-mm-ss')
dir = s.getVideoDirectory(ev)+filename+'.'+ev.ext;
fileExists = fs.existsSync(dir)
}
if(fileExists !== true){
s.video('delete',ev) s.video('delete',ev)
es.del.push('(mid=? AND time=?)'); s.tx({f:'video_delete',filename:filename+'.'+ev.ext,mid:ev.mid,ke:ev.ke,time:ev.time,end:s.moment(new Date,'YYYY-MM-DD HH:mm:ss')},'GRP_'+ev.ke);
es.ar.push(ev.mid),es.ar.push(ev.time);
s.tx({f:'video_delete',filename:s.moment(ev.time)+'.'+ev.ext,mid:ev.mid,ke:ev.ke,time:ev.time,end:s.moment(new Date,'YYYY-MM-DD HH:mm:ss')},'GRP_'+ev.ke);
} }
}); });
if(es.del.length>0){ if(es.del.length>0){
@ -402,6 +425,7 @@ s.processUser = function(number,rows){
//no user object given //no user object given
return return
} }
s.debugLog(v)
if(!s.alreadyDeletedRowsWithNoVideosOnStart[v.ke]){ if(!s.alreadyDeletedRowsWithNoVideosOnStart[v.ke]){
s.alreadyDeletedRowsWithNoVideosOnStart[v.ke]=false; s.alreadyDeletedRowsWithNoVideosOnStart[v.ke]=false;
} }
@ -415,6 +439,9 @@ s.processUser = function(number,rows){
//days to keep videos //days to keep videos
if(!v.d.days||v.d.days==''){v.d.days=5}else{v.d.days=parseFloat(v.d.days)}; if(!v.d.days||v.d.days==''){v.d.days=5}else{v.d.days=parseFloat(v.d.days)};
s.sqlQuery('SELECT * FROM Monitors WHERE ke=?', [v.ke], function(err,rr) { s.sqlQuery('SELECT * FROM Monitors WHERE ke=?', [v.ke], function(err,rr) {
if(!v.d.filters||v.d.filters==''){
v.d.filters={};
}
rr.forEach(function(b,m){ rr.forEach(function(b,m){
b.details=JSON.parse(b.details); b.details=JSON.parse(b.details);
if(b.details.max_keep_days&&b.details.max_keep_days!==''){ if(b.details.max_keep_days&&b.details.max_keep_days!==''){
@ -443,10 +470,15 @@ s.processUser = function(number,rows){
} }
}) })
s.deleteOldLogs(v,function(){ s.deleteOldLogs(v,function(){
s.debugLog('deleteOldLogs')
s.deleteOldFileBins(v,function(){ s.deleteOldFileBins(v,function(){
s.debugLog('deleteOldFileBins')
s.deleteOldEvents(v,function(){ s.deleteOldEvents(v,function(){
s.debugLog('deleteOldEvents')
s.checkFilterRules(v,function(){ s.checkFilterRules(v,function(){
s.debugLog('checkFilterRules')
s.deleteRowsWithNoVideo(v,function(){ s.deleteRowsWithNoVideo(v,function(){
s.debugLog('deleteRowsWithNoVideo')
s.checkForOrphanedFiles(v,function(){ s.checkForOrphanedFiles(v,function(){
//done user, unlock current, and do next //done user, unlock current, and do next
s.overlapLock[v.ke]=false; s.overlapLock[v.ke]=false;
@ -458,6 +490,8 @@ s.processUser = function(number,rows){
}) })
}) })
}) })
}else{
s.processUser(number+1,rows)
} }
} }
//recursive function //recursive function

View File

@ -46,11 +46,6 @@
<div><input class="form-control" name="name"></div> <div><input class="form-control" name="name"></div>
</label> </label>
</div> </div>
<div class="form-group">
<label><div><span><%-lang['Retry Connection']%></span></div>
<div><input class="form-control" detail="fatal_max" placeholder="10"></div>
</label>
</div>
<div class="form-group"> <div class="form-group">
<label><div><span><%-lang["Number of Days to keep"]%> <%-lang["Videos"]%></span></div> <label><div><span><%-lang["Number of Days to keep"]%> <%-lang["Videos"]%></span></div>
<div><input class="form-control" detail="max_keep_days" placeholder="Default is global value"></div> <div><input class="form-control" detail="max_keep_days" placeholder="Default is global value"></div>