Merge branch 'storageareas' of github.com:connortechnology/ZoneMinder into tesla

pull/2077/head
Isaac Connor 2018-01-26 10:17:54 -08:00
commit dc46f23af0
9 changed files with 93 additions and 42 deletions

2
.gitmodules vendored
View File

@ -4,4 +4,4 @@
branch = 3.0
[submodule "web/api/app/Plugin/CakePHP-Enum-Behavior"]
path = web/api/app/Plugin/CakePHP-Enum-Behavior
url = https://github.com/asper/CakePHP-Enum-Behavior.git
url = https://github.com/connortechnology/CakePHP-Enum-Behavior.git

View File

@ -273,10 +273,26 @@ CREATE TABLE `Events_Archived` (
) ENGINE=@ZM_MYSQL_ENGINE@;
drop trigger if exists event_update_trigger;
drop procedure if exists update_storage_stats;
delimiter //
create procedure update_storage_stats(IN StorageId smallint(5), IN space BIGINT)
sql security invoker
deterministic
begin
update Storage set DiskSpace = DiskSpace + space where Id = StorageId;
end;
//
drop trigger if exists event_update_trigger//
CREATE TRIGGER event_update_trigger AFTER UPDATE ON Events
FOR EACH ROW
BEGIN

View File

@ -210,11 +210,10 @@ MAIN: while( $loop ) {
$db_events->{$event->{Id}} = $event->{Age};
}
Debug( 'Got '.int(keys(%$db_events))." events for monitor $monitor->{Id}" );
}
} # end while monitors
my $fs_monitors;
foreach my $Storage ( @Storage_Areas ) {
Debug('Checking events in ' . $Storage->Path() );
if ( ! chdir( $Storage->Path() ) ) {
@ -224,7 +223,10 @@ MAIN: while( $loop ) {
# Please note that this glob will take all files beginning with a digit.
foreach my $monitor ( glob('[0-9]*') ) {
next if $monitor =~ /\D/;
if ( $monitor =~ /\D/ ) {
Debug("Weird non digit characters in $monitor");
next;
}
Debug( "Found filesystem monitor '$monitor'" );
$fs_monitors->{$monitor} = {} if ! $fs_monitors->{$monitor};
@ -233,8 +235,10 @@ MAIN: while( $loop ) {
# De-taint
( my $monitor_dir ) = ( $monitor =~ /^(.*)$/ );
#if ( $$Storage{Scheme} eq 'Deep' ) {
foreach my $day_dir ( glob("$monitor_dir/[0-9][0-9]/[0-9][0-9]/[0-9][0-9]") ) {
{
my @day_dirs = glob("$monitor_dir/[0-9][0-9]/[0-9][0-9]/[0-9][0-9]");
Debug(qq`Checking for Deep Events under using glob("$monitor_dir/[0-9][0-9]/[0-9][0-9]/[0-9][0-9]") returned `. scalar @day_dirs . " events");
foreach my $day_dir ( @day_dirs ) {
Debug( "Checking day dir $day_dir" );
( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint
if ( ! chdir( $day_dir ) ) {
@ -279,9 +283,17 @@ MAIN: while( $loop ) {
} # end foreach event_link
chdir( $Storage->Path() );
} # end foreach day dir
}
foreach my $event_dir ( glob("$monitor_dir/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*") ) {
next if ! -d $event_dir;
Debug("Checking for Medium Scheme Events under $monitor_dir");
{
my @event_dirs = glob("$monitor_dir/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*");
Debug(qq`glob("$monitor_dir/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*") returned ` . scalar @event_dirs . " entries." );
foreach my $event_dir ( @event_dirs ) {
if ( ! -d $event_dir ) {
Debug( "$event_dir is not a dir. Skipping" );
next;
}
my ( $date, $event_id ) = $event_dir =~ /^$monitor_dir\/(\d{4}\-\d{2}\-\d{2})\/(\d+)$/;
if ( ! $event_id ) {
Debug("Unable to parse date/event_id from $event_dir");
@ -290,13 +302,16 @@ MAIN: while( $loop ) {
my $Event = $fs_events->{$event_id} = new ZoneMinder::Event();
$$Event{Id} = $event_id;
$$Event{Path} = join('/', $Storage->Path(), $event_dir );
Debug("Have event $$Event{Id} at $$Event{Path}");
$$Event{Scheme} = 'Medium';
$$Event{RelativePath} = $event_dir;
$Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() );
} # end foreach event
}
if ( ! $$Storage{Scheme} ) {
Debug("Storage Scheme not set on $$Storage{Name}");
if ( ! chdir( $monitor_dir ) ) {
Error( "Can't chdir directory '$$Storage{Path}/$monitor_dir': $!" );
next;
@ -321,12 +336,21 @@ MAIN: while( $loop ) {
#delete_empty_directories( $monitor_dir );
} # end foreach monitor
redo MAIN if ( $cleaned );
if ( $cleaned ) {
Debug("First stage cleaning done. Restarting.");
redo MAIN;
}
$cleaned = 0;
while ( my ( $monitor_id, $fs_events ) = each(%$fs_monitors) ) {
if ( my $db_events = $db_monitors->{$monitor_id} ) {
next if ! $fs_events;
if ( ! $fs_events ) {
Debug("No fs_events for database monitor $monitor_id");
next;
}
my @event_ids = keys %$fs_events;
Debug("Have " .scalar @event_ids . " events for monitor $monitor_id");
foreach my $fs_event_id ( sort { $a <=> $b } keys %$fs_events ) {

View File

@ -43,7 +43,12 @@ int Event::pre_alarm_count = 0;
Event::PreAlarmData Event::pre_alarm_data[MAX_PRE_ALARM_FRAMES] = { { 0 } };
Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string &p_cause, const StringSetMap &p_noteSetMap, bool p_videoEvent ) :
Event::Event(
Monitor *p_monitor,
struct timeval p_start_time,
const std::string &p_cause,
const StringSetMap &p_noteSetMap,
bool p_videoEvent ) :
monitor( p_monitor ),
start_time( p_start_time ),
cause( p_cause ),
@ -53,12 +58,12 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
{
std::string notes;
createNotes( notes );
createNotes(notes);
bool untimedEvent = false;
if ( !start_time.tv_sec ) {
untimedEvent = true;
gettimeofday( &start_time, 0 );
gettimeofday(&start_time, 0);
}
Storage * storage = monitor->getStorage();
@ -216,7 +221,8 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
Event::~Event() {
static char sql[ZM_SQL_MED_BUFSIZ];
struct DeltaTimeval delta_time;
DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 );
DELTA_TIMEVAL(delta_time, end_time, start_time, DT_PREC_2);
Debug(2, "start_time:%d.%d end_time%d.%d", start_time.tv_sec, start_time.tv_usec, end_time.tv_sec, end_time.tv_usec );
if ( frames > last_db_frame ) {
@ -462,6 +468,11 @@ void Event::AddFramesInternal( int n_frames, int start_frame, Image **images, st
struct DeltaTimeval delta_time;
DELTA_TIMEVAL( delta_time, *(timestamps[i]), start_time, DT_PREC_2 );
if ( delta_time.sec > 99999999 ) {
Warning("Invalid delta_time from_unixtime(%ld), %s%ld.%02ld",
timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
delta_time.sec = 0;
}
int sql_len = strlen(sql);
snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
@ -474,7 +485,6 @@ void Event::AddFramesInternal( int n_frames, int start_frame, Image **images, st
*(sql+strlen(sql)-2) = '\0';
if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't insert frames: %s, sql was (%s)", mysql_error( &dbconn ), sql );
exit( mysql_errno( &dbconn ) );
}
last_db_frame = frames;
} else {

View File

@ -148,13 +148,27 @@ class MonitorsController extends AppController {
throw new NotFoundException(__('Invalid monitor'));
}
if ($this->Session->Read('monitorPermission') != 'Edit') {
throw new UnauthorizedException(__('Insufficient privileges'));
throw new UnauthorizedException(__('Insufficient privileges'));
return;
}
if ($this->Monitor->save($this->request->data)) {
$message = '';
if ( $this->Monitor->save($this->request->data) ) {
$message = 'Saved';
$Monitor = $this->Monitor->find('first', array(
'fields' => array('Function','ServerId'),
'conditions' => array('Id' => $id)
))['Monitor'];
// - restart or stop this monitor after change
$func = $Monitor['Function'];
// We don't pass the request data as the monitor object because it may be a subset of the full monitor array
$this->daemonControl( $this->Monitor->id, 'stop' );
if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID')) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) {
$this->daemonControl( $this->Monitor->id, 'start' );
}
} else {
$message = 'Error';
$message = 'Error ' . print_r($this->Monitor->invalidFields(), true);
}
$this->set(array(
@ -162,18 +176,6 @@ class MonitorsController extends AppController {
'_serialize' => array('message')
));
$Monitor = $this->Monitor->find('first', array(
'fields' => array('Function','ServerId'),
'conditions' => array('Id' => $id)
))['Monitor'];
// - restart or stop this monitor after change
$func = $Monitor['Function'];
// We don't pass the request data as the monitor object because it may be a subset of the full monitor array
$this->daemonControl( $this->Monitor->id, 'stop' );
if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID')) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) {
$this->daemonControl( $this->Monitor->id, 'start' );
}
} // end function edit
/**

View File

@ -110,13 +110,13 @@ class Monitor extends AppModel {
);
public $actsAs = array(
'CakePHP-Enum-Behavior.Enum' => array(
'Type' => array('Local','Remote','File','Ffmpeg','Libvlc','cURL'),
'Function' => array('None','Monitor','Modect','Record','Mocord','Nodect'),
'Orientation' => array('0','90','180','270','hori','vert'),
'OutputCodec' => array('h264','mjpeg','mpeg1','mpeg2'),
'OutputContainer' => array('auto','mp4','mkv'),
'DefaultView' => array('Events','Control'),
'Status' => array('Unknown','NotRunning','Running','NoSignal','Signal'),
'Type' => array('Local','Remote','File','Ffmpeg','Libvlc','cURL'),
'Function' => array('None','Monitor','Modect','Record','Mocord','Nodect'),
'Orientation' => array('0','90','180','270','hori','vert'),
'OutputCodec' => array('h264','mjpeg','mpeg1','mpeg2'),
'OutputContainer' => array('auto','mp4','mkv'),
'DefaultView' => array('Events','Control'),
'Status' => array('Unknown','NotRunning','Running','NoSignal','Signal'),
)
);

@ -1 +1 @@
Subproject commit 7108489f218c54d36d235d3af91d6da2f8311237
Subproject commit ca91b87fda8e006e4fca2ed870f24f9a29c2905d

View File

@ -218,7 +218,7 @@ if ( $redirect ) {
return;
}
if ( isset( $_REQUEST['request'] ) ) {
if ( $request ) {
foreach ( getSkinIncludes( 'ajax/'.$request.'.php', true, true ) as $includeFile ) {
if ( !file_exists( $includeFile ) )
Fatal( "Request '$request' does not exist" );

View File

@ -38,7 +38,6 @@ function changeScale() {
newHeight = monitorHeight * scale / SCALE_BASE;
}
Cookie.write( 'zmWatchScale'+monitorId, scale, { duration: 10*365 } );
/*Stream could be an applet so can't use moo tools*/
@ -108,7 +107,7 @@ var streamCmdParms = "view=request&request=stream&connkey="+connKey;
if ( auth_hash )
streamCmdParms += '&auth='+auth_hash;
var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStreamCmdResponse } );
var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'get', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStreamCmdResponse } );
var streamCmdTimer = null;
var streamStatus;