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 {
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$');
@ -371,7 +358,6 @@ sub delete {
return;
}
}
>>>>>>> master
if ( $$event{Id} ) {
# Need to have an event Id if we are to delete from the db.
@ -680,9 +666,9 @@ sub recover_timestamps {
my ( $Event, $path ) = @_;
$path = $Event->Path() if ! $path;
if ( ! opendir(DIR, $path) ) {
if ( !opendir(DIR, $path) ) {
Error("Can't open directory '$path': $!");
next;
return;
}
my @contents = readdir(DIR);
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");
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 ) {
@Storage_Areas = ZoneMinder::Storage->find( ServerId => $server_id );
if ( ! @Storage_Areas ) {
@ -128,11 +128,11 @@ if ( defined $storage_id ) {
Term();
}
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 {
@Storage_Areas = ZoneMinder::Storage->find();
Info("Auditing All Storage Areas");
Info("Recovering from All Storage Areas");
}
my @Monitors = ZoneMinder::Monitor->find();
@ -231,9 +231,12 @@ Debug("@Monitors");
$Event->Height( $Monitor->Height() );
$Event->Orientation( $Monitor->Orientation() );
$Event->recover_timestamps();
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
if ( $$Event{StartTime} ) {
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
next;
} # end if resurrection
} # event path exists
@ -291,8 +294,12 @@ Debug("@Monitors");
$Event->StorageId( $Storage->Id() );
$Event->DiskSpace( undef );
$Event->recover_timestamps();
$Event->save({}, 1);
Debug("Event resurrected as " . $Event->to_string() );
if ( $$Event{StartTime} ) {
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
next;
}
} # end if event found
@ -351,8 +358,12 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() );
$Event->recover_timestamps();
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
if ( $$Event{StartTime} ) {
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
}
} # end foreach event
} # end search for Medium
@ -389,8 +400,12 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() );
$Event->recover_timestamps();
$Event->save({}, 1);
Debug("Event resurrected as " . $Event->to_string() );
if ( $$Event{StartTime} ) {
$Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() );
} else {
Warning("Unable to determine starttime. Not resurrecting this event.");
}
}
} # end foreach event
chdir( $Storage->Path() );

View File

@ -388,7 +388,7 @@ int RtspThread::run() {
std::string trackUrl = mUrl;
std::string controlUrl;
_AVCODECID codecId;
_AVCODECID codecId = AV_CODEC_ID_NONE;
if ( mFormatContext->nb_streams >= 1 ) {
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)
)
) {
if ( !defined('ZM_SERVER_ID')) {
Logger::Debug("Not defined ZM_SERVER_ID");
}
$this->daemonControl($this->Monitor->id, 'start');
}
} else {
@ -349,26 +352,28 @@ class MonitorsController extends AppController {
));
}
public function daemonControl($id, $command, $monitor=null, $daemon=null) {
$daemons = array();
public function daemonControl($id, $command, $daemon=null) {
if ( !$monitor ) {
// Need to see if it is local or remote
$monitor = $this->Monitor->find('first', array(
'fields' => array('Type', 'Function', 'Device'),
'conditions' => array('Id' => $id)
));
$monitor = $monitor['Monitor'];
}
// Need to see if it is local or remote
$monitor = $this->Monitor->find('first', array(
'fields' => array('Type', 'Function', 'Device'),
'conditions' => array('Id' => $id)
));
$monitor = $monitor['Monitor'];
if ( $monitor['Function'] == 'Monitor' ) {
array_push($daemons, 'zmc');
if ( ! $daemon ) {
if ( $monitor['Function'] == 'Monitor' ) {
array_push($daemons, 'zmc');
} else {
array_push($daemons, 'zmc', 'zma');
}
} else {
array_push($daemons, 'zmc', 'zma');
array_push($daemons, $daemon);
}
$zm_path_bin = Configure::read('ZM_PATH_BIN');
$status_text = '';
foreach ( $daemons as $daemon ) {
$args = '';
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");
$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

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() ) {
$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_AUTH_RELAY == 'hashed' ) {
$url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS );
@ -472,17 +472,8 @@ private $control_fields = array(
}
}
Logger::Debug("sending command to $url");
$data = array('Monitor[Function]' => $this->{'Function'} );
// use key 'http' even if you send the request to https://...
$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);
$context = stream_context_create();
try {
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */
@ -518,6 +509,33 @@ private $control_fields = array(
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 public function zmaControl