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

This commit is contained in:
Isaac Connor 2018-11-14 13:02:48 -05:00
commit 0546c54f5a
7 changed files with 89 additions and 55 deletions

View File

@ -342,19 +342,6 @@ sub GenerateVideo {
sub delete { sub delete {
my $event = $_[0]; my $event = $_[0];
<<<<<<< HEAD
if ( ! ( $event->{Id} and $event->{MonitorId} and $event->{StartTime} ) ) {
my ( $caller, undef, $line ) = caller;
Warning("Can't delete event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime} from $caller:$line");
return;
}
if ( ! -e $event->Storage()->Path() ) {
Warning("Not deleting event because storage path doesn't exist");
return;
}
Info("Deleting event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime}");
$ZoneMinder::Database::dbh->ping();
=======
my $in_zmaudit = ( $0 =~ 'zmaudit.pl$'); my $in_zmaudit = ( $0 =~ 'zmaudit.pl$');
@ -371,7 +358,6 @@ sub delete {
return; return;
} }
} }
>>>>>>> master
if ( $$event{Id} ) { if ( $$event{Id} ) {
# Need to have an event Id if we are to delete from the db. # Need to have an event Id if we are to delete from the db.
@ -680,9 +666,9 @@ sub recover_timestamps {
my ( $Event, $path ) = @_; my ( $Event, $path ) = @_;
$path = $Event->Path() if ! $path; $path = $Event->Path() if ! $path;
if ( ! opendir(DIR, $path) ) { if ( !opendir(DIR, $path) ) {
Error("Can't open directory '$path': $!"); Error("Can't open directory '$path': $!");
next; return;
} }
my @contents = readdir(DIR); my @contents = readdir(DIR);
Debug('Have ' . @contents . " files in $path"); Debug('Have ' . @contents . " files in $path");

View File

@ -120,7 +120,7 @@ if ( defined $storage_id ) {
Error("No Storage Area found with Id $storage_id"); Error("No Storage Area found with Id $storage_id");
Term(); Term();
} }
Info("Auditing Storage Area $Storage_Areas[0]{Id} $Storage_Areas[0]{Name} at $Storage_Areas[0]{Path}"); Info("Recovering from Storage Area $Storage_Areas[0]{Id} $Storage_Areas[0]{Name} at $Storage_Areas[0]{Path}");
} elsif ( $server_id ) { } elsif ( $server_id ) {
@Storage_Areas = ZoneMinder::Storage->find( ServerId => $server_id ); @Storage_Areas = ZoneMinder::Storage->find( ServerId => $server_id );
if ( ! @Storage_Areas ) { if ( ! @Storage_Areas ) {
@ -128,11 +128,11 @@ if ( defined $storage_id ) {
Term(); Term();
} }
foreach my $Storage ( @Storage_Areas ) { foreach my $Storage ( @Storage_Areas ) {
Info('Auditing ' . $Storage->Name() . ' at ' . $Storage->Path() . ' on ' . $Storage->Server()->Name() ); Info('Recovering from ' . $Storage->Name() . ' at ' . $Storage->Path() . ' on ' . $Storage->Server()->Name() );
} }
} else { } else {
@Storage_Areas = ZoneMinder::Storage->find(); @Storage_Areas = ZoneMinder::Storage->find();
Info("Auditing All Storage Areas"); Info("Recovering from All Storage Areas");
} }
my @Monitors = ZoneMinder::Monitor->find(); my @Monitors = ZoneMinder::Monitor->find();
@ -231,9 +231,12 @@ Debug("@Monitors");
$Event->Height( $Monitor->Height() ); $Event->Height( $Monitor->Height() );
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->recover_timestamps(); $Event->recover_timestamps();
if ( $$Event{StartTime} ) {
$Event->save({}, 1); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() ); Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
next; next;
} # end if resurrection } # end if resurrection
} # event path exists } # event path exists
@ -291,8 +294,12 @@ Debug("@Monitors");
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->DiskSpace( undef ); $Event->DiskSpace( undef );
$Event->recover_timestamps(); $Event->recover_timestamps();
$Event->save({}, 1); if ( $$Event{StartTime} ) {
Debug("Event resurrected as " . $Event->to_string() ); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
next; next;
} }
} # end if event found } # end if event found
@ -351,8 +358,12 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->recover_timestamps(); $Event->recover_timestamps();
$Event->save({}, 1); if ( $$Event{StartTime} ) {
Info("Event resurrected as " . $Event->to_string() ); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
} }
} # end foreach event } # end foreach event
} # end search for Medium } # end search for Medium
@ -389,8 +400,12 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->recover_timestamps(); $Event->recover_timestamps();
$Event->save({}, 1); if ( $$Event{StartTime} ) {
Debug("Event resurrected as " . $Event->to_string() ); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
} }
} # end foreach event } # end foreach event
chdir( $Storage->Path() ); chdir( $Storage->Path() );

View File

@ -388,7 +388,7 @@ int RtspThread::run() {
std::string trackUrl = mUrl; std::string trackUrl = mUrl;
std::string controlUrl; std::string controlUrl;
_AVCODECID codecId; _AVCODECID codecId = AV_CODEC_ID_NONE;
if ( mFormatContext->nb_streams >= 1 ) { if ( mFormatContext->nb_streams >= 1 ) {
for ( unsigned int i = 0; i < mFormatContext->nb_streams; i++ ) { for ( unsigned int i = 0; i < mFormatContext->nb_streams; i++ ) {

View File

@ -182,6 +182,9 @@ class MonitorsController extends AppController {
($Monitor['ServerId']==ZM_SERVER_ID) ($Monitor['ServerId']==ZM_SERVER_ID)
) )
) { ) {
if ( !defined('ZM_SERVER_ID')) {
Logger::Debug("Not defined ZM_SERVER_ID");
}
$this->daemonControl($this->Monitor->id, 'start'); $this->daemonControl($this->Monitor->id, 'start');
} }
} else { } else {
@ -349,26 +352,28 @@ class MonitorsController extends AppController {
)); ));
} }
public function daemonControl($id, $command, $monitor=null, $daemon=null) { public function daemonControl($id, $command, $daemon=null) {
$daemons = array();
if ( !$monitor ) { // Need to see if it is local or remote
// Need to see if it is local or remote $monitor = $this->Monitor->find('first', array(
$monitor = $this->Monitor->find('first', array( 'fields' => array('Type', 'Function', 'Device'),
'fields' => array('Type', 'Function', 'Device'), 'conditions' => array('Id' => $id)
'conditions' => array('Id' => $id) ));
)); $monitor = $monitor['Monitor'];
$monitor = $monitor['Monitor'];
}
if ( $monitor['Function'] == 'Monitor' ) { if ( ! $daemon ) {
array_push($daemons, 'zmc'); if ( $monitor['Function'] == 'Monitor' ) {
array_push($daemons, 'zmc');
} else {
array_push($daemons, 'zmc', 'zma');
}
} else { } else {
array_push($daemons, 'zmc', 'zma'); array_push($daemons, $daemon);
} }
$zm_path_bin = Configure::read('ZM_PATH_BIN'); $zm_path_bin = Configure::read('ZM_PATH_BIN');
$status_text = '';
foreach ( $daemons as $daemon ) { foreach ( $daemons as $daemon ) {
$args = ''; $args = '';
if ( $daemon == 'zmc' and $monitor['Type'] == 'Local' ) { if ( $daemon == 'zmc' and $monitor['Type'] == 'Local' ) {
@ -378,7 +383,14 @@ class MonitorsController extends AppController {
} }
$shellcmd = escapeshellcmd("$zm_path_bin/zmdc.pl $command $daemon $args"); $shellcmd = escapeshellcmd("$zm_path_bin/zmdc.pl $command $daemon $args");
$status = exec( $shellcmd ); Logger::Debug("Command $shellcmd");
$status = exec($shellcmd);
$status_text .= $status."\n";
} }
} $this->set(array(
'status' => 'ok',
'statustext' => $status_text,
'_serialize' => array('status','statustext'),
));
} // end function daemonControl
} // end class MonitorsController } // end class MonitorsController

View File

@ -0,0 +1 @@
echo json_encode($status_text);

View File

@ -0,0 +1,2 @@
$xml = Xml::fromArray(array('response' => $status_text));
echo $xml->asXML();

View File

@ -460,7 +460,7 @@ private $control_fields = array(
} else if ( $this->ServerId() ) { } else if ( $this->ServerId() ) {
$Server = $this->Server(); $Server = $this->Server();
$url = ZM_BASE_PROTOCOL . '://'.$Server->Hostname().'/zm/api/monitors/'.$this->{'Id'}.'.json'; $url = ZM_BASE_PROTOCOL . '://'.$Server->Hostname().'/zm/api/monitors/daemonControl/'.$this->{'Id'}.'/'.$mode.'/zmc.json';
if ( ZM_OPT_USE_AUTH ) { if ( ZM_OPT_USE_AUTH ) {
if ( ZM_AUTH_RELAY == 'hashed' ) { if ( ZM_AUTH_RELAY == 'hashed' ) {
$url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS ); $url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS );
@ -472,17 +472,8 @@ private $control_fields = array(
} }
} }
Logger::Debug("sending command to $url"); Logger::Debug("sending command to $url");
$data = array('Monitor[Function]' => $this->{'Function'} );
// use key 'http' even if you send the request to https://... $context = stream_context_create();
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
try { try {
$result = file_get_contents($url, false, $context); $result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ if ($result === FALSE) { /* Handle error */
@ -518,6 +509,33 @@ private $control_fields = array(
daemonControl( 'reload', 'zma', '-m '.$this->{'Id'} ); daemonControl( 'reload', 'zma', '-m '.$this->{'Id'} );
} }
} }
} else if ( $this->ServerId() ) {
$Server = $this->Server();
$url = ZM_BASE_PROTOCOL . '://'.$Server->Hostname().'/zm/api/monitors/daemonControl/'.$this->{'Id'}.'/'.$mode.'/zma.json';
if ( ZM_OPT_USE_AUTH ) {
if ( ZM_AUTH_RELAY == 'hashed' ) {
$url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS );
} elseif ( ZM_AUTH_RELAY == 'plain' ) {
$url = '?user='.$_SESSION['username'];
$url = '?pass='.$_SESSION['password'];
} elseif ( ZM_AUTH_RELAY == 'none' ) {
$url = '?user='.$_SESSION['username'];
}
}
Logger::Debug("sending command to $url");
$context = stream_context_create();
try {
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */
Error("Error restarting zma using $url");
}
} catch ( Exception $e ) {
Error("Except $e thrown trying to restart zma");
}
} else {
Error("Server not assigned to Monitor in a multi-server setup. Please assign a server to the Monitor.");
} // end if we are on the recording server } // end if we are on the recording server
} // end public function zmaControl } // end public function zmaControl