Merge branch 'dev' into 'master'

Blue Turtle - Minor Additions and Bug Fixes

See merge request Shinobi-Systems/Shinobi!35
merge-requests/39/head
Moe 2018-10-29 16:02:01 +00:00
commit 4304fa9a47
6 changed files with 66 additions and 59 deletions

View File

@ -328,9 +328,15 @@ module.exports = function(s,config,lang){
}else{
detector_timeout = parseFloat(currentConfig.detector_timeout)
}
s.group[d.ke].mon[d.id].eventBasedRecording.timeout = setTimeout(function(){
s.group[d.ke].mon[d.id].eventBasedRecording.allowEnd=true;
},detector_timeout * 950 * 60)
if(currentConfig.watchdog_reset !== '1' || !s.group[d.ke].mon[d.id].eventBasedRecording.timeout){
clearTimeout(s.group[d.ke].mon[d.id].eventBasedRecording.timeout)
s.group[d.ke].mon[d.id].eventBasedRecording.timeout = setTimeout(function(){
s.group[d.ke].mon[d.id].eventBasedRecording.allowEnd = true
s.group[d.ke].mon[d.id].eventBasedRecording.process.stdin.setEncoding('utf8')
s.group[d.ke].mon[d.id].eventBasedRecording.process.stdin.write('q')
delete(s.group[d.ke].mon[d.id].eventBasedRecording.timeout)
},detector_timeout * 1000 * 60)
}
if(!s.group[d.ke].mon[d.id].eventBasedRecording.process){
if(!d.auth){
d.auth = s.gid(60)
@ -348,7 +354,7 @@ module.exports = function(s,config,lang){
var filename = s.formattedTime()+'.mp4'
s.userLog(d,{type:"Traditional Recording",msg:"Started"})
//-t 00:'+s.timeObject(new Date(detector_timeout * 1000 * 60)).format('mm:ss')+'
s.group[d.ke].mon[d.id].eventBasedRecording.process = spawn(config.ffmpegDir,s.splitForFFPMEG(('-loglevel warning -analyzeduration 1000000 -probesize 1000000 -re -i http://'+config.ip+':'+config.port+'/'+d.auth+'/hls/'+d.ke+'/'+d.id+'/detectorStream.m3u8 -t 00:'+s.timeObject(new Date(detector_timeout * 1000 * 60)).format('mm:ss')+' -c:v copy -strftime 1 "'+s.getVideoDirectory(d.mon) + filename + '"')))
s.group[d.ke].mon[d.id].eventBasedRecording.process = spawn(config.ffmpegDir,s.splitForFFPMEG(('-loglevel warning -analyzeduration 1000000 -probesize 1000000 -re -i http://'+config.ip+':'+config.port+'/'+d.auth+'/hls/'+d.ke+'/'+d.id+'/detectorStream.m3u8 -c:v copy -strftime 1 "'+s.getVideoDirectory(d.mon) + filename + '"')))
var ffmpegError='';
var error
s.group[d.ke].mon[d.id].eventBasedRecording.process.stderr.on('data',function(data){

View File

@ -198,7 +198,8 @@ module.exports = function(s,config,onFinish){
//`e` is the monitor object
//`x` is an object used to contain temporary values.
var x = {
pipe:''
pipe: '',
cust_stream: ''
}
if(!number||number==''){
x.channel_sdir = e.sdir;
@ -245,7 +246,7 @@ module.exports = function(s,config,onFinish){
//hls list size
if(channel.hls_list_size&&channel.hls_list_size!==''){x.hls_list_size=channel.hls_list_size}else{x.hls_list_size=2}
//stream - custom flags
if(channel.cust_stream&&channel.cust_stream!==''){x.cust_stream=' '+channel.cust_stream}else{x.cust_stream=''}
if(channel.cust_stream&&channel.cust_stream!==''){x.cust_stream=' '+channel.cust_stream}
//stream - preset
if(channel.stream_type !== 'h265' && channel.preset_stream && channel.preset_stream!==''){x.preset_stream=' -preset '+channel.preset_stream;}else{x.preset_stream=''}
//hardware acceleration
@ -441,6 +442,7 @@ module.exports = function(s,config,onFinish){
//x = temporary values
x.stream_video_filters = []
x.pipe = ''
x.cust_stream = ''
//stream - timestamp
if(e.details.stream_timestamp&&e.details.stream_timestamp=="1"&&e.details.vcodec!=='copy'){
//font
@ -496,7 +498,7 @@ module.exports = function(s,config,onFinish){
if(e.details.hls_time&&e.details.hls_time!==''){x.hls_time=e.details.hls_time}else{x.hls_time="2"} //hls list size
if(e.details.hls_list_size&&e.details.hls_list_size!==''){x.hls_list_size=e.details.hls_list_size}else{x.hls_list_size=2}
//stream - custom flags
if(e.details.cust_stream&&e.details.cust_stream!==''){x.cust_stream=' '+e.details.cust_stream}else{x.cust_stream=''}
if(e.details.cust_stream&&e.details.cust_stream!==''){x.cust_stream=' '+e.details.cust_stream}
//stream - preset
if(e.details.stream_type !== 'h265' && e.details.preset_stream && e.details.preset_stream !== ''){x.preset_stream=' -preset '+e.details.preset_stream;}else{x.preset_stream=''}
@ -524,9 +526,12 @@ module.exports = function(s,config,onFinish){
//add input feed map
x.pipe += s.createFFmpegMap(e,e.details.input_map_choices.stream)
}
if(e.details.stream_vcodec !== 'copy' || e.details.stream_type === 'mjpeg' || e.details.stream_type === 'b64'){
console.log('x.cust_stream',x.cust_stream)
if(x.stream_fps && (e.details.stream_vcodec !== 'copy' || e.details.stream_type === 'mjpeg' || e.details.stream_type === 'b64')){
x.cust_stream += x.stream_fps
}
console.log('x.cust_stream',x.cust_stream)
switch(e.details.stream_type){
case'mp4':
x.cust_stream+=' -movflags +frag_keyframe+empty_moov+default_base_moof -metadata title="Poseidon Stream" -reset_timestamps 1'
@ -660,7 +665,7 @@ module.exports = function(s,config,onFinish){
//record - frames per second (fps)
if(e.fps&&e.fps!==''&&e.details.vcodec!=='copy'){x.record_fps=' -r '+e.fps}else{x.record_fps=''}
//stream - frames per second (fps)
if(e.details.stream_fps&&e.details.stream_fps!==''){x.stream_fps=' -r '+e.details.stream_fps}else{x.stream_fps=''}
if(e.details.stream_fps&&e.details.stream_fps!==''){x.stream_fps=' -r '+e.details.stream_fps}else{x.stream_fps = ''}
//record - timestamp options for -vf
if(e.details.timestamp&&e.details.timestamp=="1"&&e.details.vcodec!=='copy'){
//font

View File

@ -1004,7 +1004,11 @@ module.exports = function(s,config,lang){
s.group[e.ke].mon[e.id].fswatch = fs.watch(e.dir, {encoding : 'utf8'}, (event, filename) => {
switch(event){
case'rename':
try{
s.group[e.ke].mon[e.id].open = filename.split('.')[0]
}catch(err){
s.debugLog('Failed to split filename : ',filename)
}
break;
case'change':
s.resetRecordingCheck(e)

View File

@ -165,71 +165,59 @@ module.exports = function(s,config,lang,app){
s.auth(req.params,function(user){
var hasRestrictions = user.details.sub && user.details.allmonitors !== '1'
if(req.params.f !== 'delete'){
if(!req.body.data&&!req.query.data){
req.ret.msg='No Monitor Data found.'
var form = s.getPostData(req)
if(!form){
req.ret.msg = user.lang.monitorEditText1;
res.end(s.prettyPrint(req.ret))
return
}
try{
if(req.query.data){
req.monitor=JSON.parse(req.query.data)
}else{
req.monitor=JSON.parse(req.body.data)
}
}catch(er){
if(!req.monitor){
req.ret.msg=user.lang.monitorEditText1;
res.end(s.prettyPrint(req.ret))
}
return
}
if(!user.details.sub ||
user.details.allmonitors === '1' ||
hasRestrictions && user.details.monitor_edit.indexOf(req.monitor.mid) >- 1 ||
hasRestrictions && user.details.monitor_edit.indexOf(form.mid) >- 1 ||
hasRestrictions && user.details.monitor_create === '1'){
if(req.monitor&&req.monitor.mid&&req.monitor.name){
if(form&&form.mid&&form.name){
req.set=[],req.ar=[];
req.monitor.mid=req.params.id.replace(/[^\w\s]/gi,'').replace(/ /g,'');
form.mid=req.params.id.replace(/[^\w\s]/gi,'').replace(/ /g,'');
try{
JSON.parse(req.monitor.details)
JSON.parse(form.details)
}catch(er){
if(!req.monitor.details||!req.monitor.details.stream_type){
if(!form.details||!form.details.stream_type){
req.ret.msg=user.lang.monitorEditText2;
res.end(s.prettyPrint(req.ret))
return
}else{
req.monitor.details=JSON.stringify(req.monitor.details)
form.details=JSON.stringify(form.details)
}
}
req.monitor.ke=req.params.ke
req.logObject={details:JSON.parse(req.monitor.details),ke:req.params.ke,mid:req.params.id}
s.sqlQuery('SELECT * FROM Monitors WHERE ke=? AND mid=?',[req.monitor.ke,req.monitor.mid],function(er,r){
req.tx={f:'monitor_edit',mid:req.monitor.mid,ke:req.monitor.ke,mon:req.monitor};
form.ke=req.params.ke
req.logObject={details:JSON.parse(form.details),ke:req.params.ke,mid:req.params.id}
s.sqlQuery('SELECT * FROM Monitors WHERE ke=? AND mid=?',[form.ke,form.mid],function(er,r){
req.tx={f:'monitor_edit',mid:form.mid,ke:form.ke,mon:form};
if(r&&r[0]){
req.tx.new=false;
Object.keys(req.monitor).forEach(function(v){
if(req.monitor[v]&&req.monitor[v]!==''){
req.set.push(v+'=?'),req.ar.push(req.monitor[v]);
Object.keys(form).forEach(function(v){
if(form[v]&&form[v]!==''){
req.set.push(v+'=?'),req.ar.push(form[v]);
}
})
req.set=req.set.join(',');
req.ar.push(req.monitor.ke),req.ar.push(req.monitor.mid);
s.userLog(req.monitor,{type:'Monitor Updated',msg:'by user : '+user.uid});
req.ar.push(form.ke),req.ar.push(form.mid);
s.userLog(form,{type:'Monitor Updated',msg:'by user : '+user.uid});
req.ret.msg=user.lang['Monitor Updated by user']+' : '+user.uid;
s.sqlQuery('UPDATE Monitors SET '+req.set+' WHERE ke=? AND mid=?',req.ar)
req.finish=1;
}else{
if(!s.group[req.monitor.ke].init.max_camera||s.group[req.monitor.ke].init.max_camera==''||Object.keys(s.group[req.monitor.ke].mon).length <= parseInt(s.group[req.monitor.ke].init.max_camera)){
if(!s.group[form.ke].init.max_camera||s.group[form.ke].init.max_camera==''||Object.keys(s.group[form.ke].mon).length <= parseInt(s.group[form.ke].init.max_camera)){
req.tx.new=true;
req.st=[];
Object.keys(req.monitor).forEach(function(v){
if(req.monitor[v]&&req.monitor[v]!==''){
req.set.push(v),req.st.push('?'),req.ar.push(req.monitor[v]);
Object.keys(form).forEach(function(v){
if(form[v]&&form[v]!==''){
req.set.push(v),req.st.push('?'),req.ar.push(form[v]);
}
})
// req.set.push('ke'),req.st.push('?'),req.ar.push(req.monitor.ke);
// req.set.push('ke'),req.st.push('?'),req.ar.push(form.ke);
req.set=req.set.join(','),req.st=req.st.join(',');
s.userLog(req.monitor,{type:'Monitor Added',msg:'by user : '+user.uid});
s.userLog(form,{type:'Monitor Added',msg:'by user : '+user.uid});
req.ret.msg=user.lang['Monitor Added by user']+' : '+user.uid;
s.sqlQuery('INSERT INTO Monitors ('+req.set+') VALUES ('+req.st+')',req.ar)
req.finish=1;
@ -240,18 +228,18 @@ module.exports = function(s,config,lang,app){
}
}
if(req.finish===1){
req.monitor.details=JSON.parse(req.monitor.details)
form.details=JSON.parse(form.details)
req.ret.ok=true;
s.initiateMonitorObject({mid:req.monitor.mid,ke:req.monitor.ke});
s.group[req.monitor.ke].mon_conf[req.monitor.mid]=s.cleanMonitorObject(req.monitor);
if(req.monitor.mode==='stop'){
s.camera('stop',req.monitor);
s.initiateMonitorObject({mid:form.mid,ke:form.ke});
s.group[form.ke].mon_conf[form.mid]=s.cleanMonitorObject(form);
if(form.mode==='stop'){
s.camera('stop',form);
}else{
s.camera('stop',req.monitor);setTimeout(function(){s.camera(req.monitor.mode,req.monitor);},5000)
s.camera('stop',form);setTimeout(function(){s.camera(form.mode,form);},5000)
};
s.tx(req.tx,'STR_'+req.monitor.ke);
s.tx(req.tx,'STR_'+form.ke);
};
s.tx(req.tx,'GRP_'+req.monitor.ke);
s.tx(req.tx,'GRP_'+form.ke);
res.end(s.prettyPrint(req.ret))
})
}else{

View File

@ -377,11 +377,15 @@ module.exports = function(s,config,lang,app){
}
if(r.details.sub){
s.sqlQuery('SELECT details FROM Users WHERE ke=? AND details NOT LIKE ?',[r.ke,'%"sub"%'],function(err,rr) {
rr=rr[0];
rr.details=JSON.parse(rr.details);
r.details.mon_groups=rr.details.mon_groups;
req.resp.details=JSON.stringify(r.details);
req.factorAuth()
if(rr && rr[0]){
rr=rr[0];
rr.details=JSON.parse(rr.details);
r.details.mon_groups=rr.details.mon_groups;
req.resp.details=JSON.stringify(r.details);
req.factorAuth()
}else{
failedAuthentication(req.body.function)
}
})
}else{
req.factorAuth()

View File

@ -938,7 +938,7 @@
</label>
</div>
</div>
<div class="form-group h_rec_mtd_input h_rec_mtd_hot">
<div class="form-group h_rec_mtd_input h_rec_mtd_hot h_rec_mtd_sip">
<label><div><span><%-lang['Timeout Reset on Next Event']%></span></div>
<div><select class="form-control" detail="watchdog_reset">
<option value="0"><%-lang.No%></option>