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

This commit is contained in:
Isaac Connor 2018-11-28 10:41:47 -05:00
commit 35be1d5281
14 changed files with 106 additions and 60 deletions

View File

@ -559,7 +559,8 @@ CREATE TABLE `Servers` (
`Protocol` TEXT,
`Hostname` TEXT,
`Port` INTEGER UNSIGNED,
`PathPrefix` TEXT,
`PathToIndex` TEXT,
`PathToZMS` TEXT,
`Name` varchar(64) NOT NULL default '',
`State_Id` int(10) unsigned,
`Status` enum('Unknown','NotRunning','Running') NOT NULL default 'Unknown',

View File

@ -2,12 +2,6 @@
-- This updates a 1.32.2 database to 1.32.3
--
--
-- Add some additional monitor preset values
--
INSERT INTO MonitorPresets VALUES (NULL,'D-link DCS-930L, 640x480, mjpeg','Remote','http',0,0,'http','simple','<ip-address>',80,'/mjpeg.cgi',NULL,640,480,3,NULL,0,NULL,NULL,NULL,100,100);
--
-- Add Protocol column to Storage
--
@ -25,16 +19,32 @@ PREPARE stmt FROM @s;
EXECUTE stmt;
--
-- Add Prefix column to Storage
-- Add PathToIndex column to Storage
--
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Servers'
AND column_name = 'PathPrefix'
AND column_name = 'PathToIndex'
) > 0,
"SELECT 'Column PathPrefix already exists in Servers'",
"ALTER TABLE Servers ADD `PathPrefix` TEXT AFTER `Hostname`"
"SELECT 'Column PathToIndex already exists in Servers'",
"ALTER TABLE Servers ADD `PathToIndex` TEXT AFTER `Hostname`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
--
-- Add PathToZMS column to Storage
--
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Servers'
AND column_name = 'PathToZMS'
) > 0,
"SELECT 'Column PathToZMS already exists in Servers'",
"ALTER TABLE Servers ADD `PathToZMS` TEXT AFTER `PathToIndex`"
));
PREPARE stmt FROM @s;

View File

@ -450,9 +450,23 @@ sub delete_files {
}
} # end sub delete_files
sub StorageId {
my $event = shift;
if ( @_ ) {
$$event{StorageId} = shift;
delete $$event{Storage};
delete $$event{Path};
}
return $$event{StorageId};
}
sub Storage {
if ( @_ > 1 ) {
$_[0]{Storage} = $_[1];
if ( $_[0]{Storage} ) {
$_[0]{StorageId} = $_[0]{Storage}->Id();
delete $_[0]{Path};
}
}
if ( ! $_[0]{Storage} ) {
$_[0]{Storage} = new ZoneMinder::Storage($_[0]{StorageId});

View File

@ -176,8 +176,10 @@ MAIN: while( $loop ) {
} # end while can't connect to the db
my @Storage_Areas;
my @all_Storage_Areas = ZoneMinder::Storage->find();
if ( defined $storage_id ) {
@Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id );
@Storage_Areas = map { $$_{Id} == $storage_id ? $_ : () } @all_Storage_Areas;
if ( !@Storage_Areas ) {
Error("No Storage Area found with Id $storage_id");
Term();
@ -403,7 +405,7 @@ MAIN: while( $loop ) {
$$Event{RelativePath} = $event_dir;
$Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() );
$Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($$Event{Path})) ) );
$Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($Event->Path())) ) );
} # end foreach event
}
@ -523,7 +525,7 @@ MAIN: while( $loop ) {
# If we found the monitor in the file system
my $fs_events = $fs_monitors->{$db_monitor};
while ( my ( $db_event, $age ) = each( %$db_events ) ) {
EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
if ( ! ($fs_events and defined( $fs_events->{$db_event} ) ) ) {
Debug("Don't have an fs event for $db_event");
my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
@ -533,13 +535,15 @@ MAIN: while( $loop ) {
}
Debug("Event $db_event is not in fs. Should have been at ".$Event->Path());
# Check for existence in other Storage Areas
foreach my $Storage ( ZoneMinder::Storage->find( ( $$Event{StorageId} ? ( 'Id !='=>$$Event{StorageId} ) : () ) ) ) {
foreach my $Storage ( @all_Storage_Areas ) {
next if $$Storage{Id} == $$Event{StorageId};
my $path = $Storage->Path().'/'.$Event->RelativePath();
if ( -e $path ) {
Info("Event $$Event{Id} found at $path instead of $$Event{Path}");
if ( confirm() ) {
if ( confirm('update', 'updating') ) {
$Event->save({StorageId=>$$Storage{Id}});
last;
next EVENT;
}
} else {
Debug("$$Event{Id} Not found at $path");
@ -587,6 +591,7 @@ MAIN: while( $loop ) {
Warning("Not found at " . $Event->Path() . ' was found at ' . $$fs_events{$db_event}->Path() );
Warning($Event->to_string());
Warning($$fs_events{$db_event}->to_string());
$$Event{Scheme} = '' if ! defined $$Event{Scheme};
if ( $$fs_events{$db_event}->Scheme() ne $Event->Scheme() ) {
Info("Updating scheme on event $$Event{Id} from $$Event{Scheme} to $$fs_events{$db_event}{Scheme}");
$Event->Scheme($$fs_events{$db_event}->Scheme());
@ -996,7 +1001,7 @@ sub delete_empty_directories {
#Debug("delete_empty_directories $_[0] has " . @contents .' entries:' . ( @contents <= 2 ? join(',',@contents) : '' ));
my @dirs = map { -d $_[0].'/'.$_ ? $_ : () } @contents;
if ( @dirs ) {
Debug("Have " . @dirs . " dirs");
Debug("Have " . @dirs . " dirs in $_[0]");
foreach ( @dirs ) {
delete_empty_directories( $_[0].'/'.$_ );
}

View File

@ -361,6 +361,7 @@ class MonitorsController extends AppController {
));
$monitor = $monitor['Monitor'];
$daemons = array();
if ( ! $daemon ) {
if ( $monitor['Function'] == 'Monitor' ) {
array_push($daemons, 'zmc');

View File

@ -72,6 +72,19 @@ class Server {
return $_SERVER['SERVER_PORT'];
}
public function PathToZMS( $new = null ) {
if ( $new != null )
$this{'PathToZMS'} = $new;
if ( $this->Id() and $this->{'PathToZMS'} ) {
return $this->{'PathToZMS'};
} else {
return ZM_PATH_ZMS;
}
}
public function UrlToZMS( ) {
return $this->Url().$this->PathToZMS();
}
public function Url( $port = null ) {
$url = $this->Protocol().'://';
if ( $this->Id() ) {
@ -84,21 +97,24 @@ class Server {
} else {
$url .= ':'.$this->Port();
}
$url .= $this->PathPrefix();
return $url;
}
public function PathPrefix( $new = null ) {
public function PathToIndex( $new = null ) {
if ( $new != null )
$this->{'PathPrefix'} = $new;
$this->{'PathToIndex'} = $new;
if ( isset($this->{'PathPrefix'}) and $this->{'PathPrefix'} ) {
return $this->{'PathPrefix'};
if ( isset($this->{'PathToIndex'}) and $this->{'PathToIndex'} ) {
return $this->{'PathToIndex'};
}
return '';
//return $_SERVER['PHP_SELF'];
}
public function UrlToIndex( ) {
return $this->Url().$this->PathToIndex();
}
public function __call($fn, array $args){
if ( count($args) ) {
$this->{$fn} = $args[0];

View File

@ -586,7 +586,8 @@ $SLANG = array(
'Parameter' => 'Parameter',
'Password' => 'Password',
'PasswordsDifferent' => 'The new and confirm passwords are different',
'PathPrefix' => 'Path Prefix',
'PathToIndex' => 'Path To Index',
'PathToZMS' => 'Path To ZMS',
'Paths' => 'Paths',
'Pause' => 'Pause',
'PhoneBW' => 'Phone&nbsp;B/W',

View File

@ -35,7 +35,7 @@ monitorData[monitorData.length] = {
'connKey': <?php echo $monitor->connKey() ?>,
'width': <?php echo $monitor->Width() ?>,
'height':<?php echo $monitor->Height() ?>,
'url': '<?php echo $monitor->Url() ?>',
'url': '<?php echo $monitor->UrlToIndex() ?>',
'onclick': function(){createPopup( '?view=watch&mid=<?php echo $monitor->Id() ?>', 'zmWatch<?php echo $monitor->Id() ?>', 'watch', <?php echo reScale( $monitor->Width(), $monitor->PopupScale() ); ?>, <?php echo reScale( $monitor->Height(), $monitor->PopupScale() ); ?> );},
'type': '<?php echo $monitor->Type() ?>',
'refresh': '<?php echo $monitor->Refresh() ?>'

View File

@ -500,11 +500,11 @@ function getEventCmdResponse( respObj, respText ) {
var cells = row.getElements( 'td' );
var link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&terms=1&attr1=MonitorId&op1=%3d&val1='+monitorId+'&page=1&popup=1', event.Width, event.Height ] ) } });
var link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId+'&page=1&popup=1', event.Width, event.Height ] ) } });
link.set( 'text', event.Id );
link.inject( row.getElement( 'td.colId' ) );
link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&terms=1&attr1=MonitorId&op1=%3d&val1='+monitorId+'&page=1&popup=1', event.Width, event.Height ] ) } });
link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId+'&page=1&popup=1', event.Width, event.Height ] ) } });
link.set( 'text', event.Name );
link.inject( row.getElement( 'td.colName' ) );

View File

@ -48,7 +48,7 @@ var maxDisplayEvents = <?php echo 2 * MAX_EVENTS ?>;
var monitorId = <?php echo $monitor->Id() ?>;
var monitorWidth = <?php echo $monitor->Width() ?>;
var monitorHeight = <?php echo $monitor->Height() ?>;
var monitorUrl = '<?php echo $monitor->Url(); ?>/index.php';
var monitorUrl = '<?php echo $monitor->UrlToIndex(); ?>';
var monitorType = '<?php echo ( $monitor->Type() ) ?>';
var monitorRefresh = '<?php echo ( $monitor->Refresh() ) ?>';

View File

@ -101,7 +101,7 @@ var streamMode = "<?php echo $streamMode ?>";
var connKey = '<?php echo $connkey ?>';
var monitorId = <?php echo $monitor->Id() ?>;
var monitorUrl = '<?php echo ( $monitor->Url() ) ?>';
var monitorUrl = '<?php echo ( $monitor->UrlToIndex() ) ?>';
var streamSrc = "<?php echo preg_replace( '/&amp;/', '&', $streamSrc ) ?>";

View File

@ -1,4 +1,4 @@
var connKey = '<?php echo $connkey ?>';
var monitorUrl = '<?php echo ( $monitor->Url() ) ?>';
var monitorUrl = '<?php echo ( $monitor->UrlToIndex() ) ?>';
var CMD_QUIT = <?php echo CMD_QUIT ?>;

View File

@ -209,6 +209,8 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
<tr>
<th class="colName"><?php echo translate('Name') ?></th>
<th class="colUrl"><?php echo translate('Url') ?></th>
<th class="colPathToIndex"><?php echo translate('PathToIndex') ?></th>
<th class="colPathToZMS"><?php echo translate('PathToZMS') ?></th>
<th class="colStatus"><?php echo translate('Status') ?></th>
<th class="colMonitorCount"><?php echo translate('Monitors') ?></th>
<th class="colCpuLoad"><?php echo translate('CpuLoad') ?></th>
@ -228,7 +230,9 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
<tr>
<td class="colName"><?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($Server->Name()), $canEdit) ?></td>
<td class="colUrl"><?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($Server->Url()), $canEdit) ?></td>
<td class="colStatus <?php if ( $row['Status'] == 'NotRunning' ) { echo 'danger'; } ?>">
<td class="colPathToIndex"><?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($Server->PathToIndex()), $canEdit) ?></td>
<td class="colPathToZMS"><?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($Server->PathToZMS()), $canEdit) ?></td>
<td class="colStatus <?php if ( $Server->Status() == 'NotRunning' ) { echo 'danger'; } ?>">
<?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($Server->Status()), $canEdit) ?></td>
<td class="colMonitorCount">
<?php echo makePopupLink('?view=server&amp;id='.$Server->Id(), 'zmServer', 'server', validHtmlStr($monitor_counts[$Server->Id()]), $canEdit) ?>

View File

@ -23,33 +23,23 @@ if ( !canEdit('System') ) {
return;
}
if ( $_REQUEST['id'] ) {
if ( !($newServer = dbFetchOne('SELECT * FROM Servers WHERE Id = ?', NULL, ARRAY($_REQUEST['id'])) ) ) {
$view = 'error';
return;
}
} else {
$newServer = array();
$newServer['Name'] = translate('NewServer');
$newServer['Protocol'] = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
$newServer['Hostname'] = '';
$newServer['PathPrefix'] = '/zm';
$newServer['zmstats'] = '';
$newServer['zmaudit'] = '';
$newServer['zmtrigger'] = '';
$Server = new Server($_REQUEST['id']);
if ( $_REQUEST['id'] and ! $Server->Id() ) {
$view = 'error';
return;
}
$focusWindow = true;
xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name']);
xhtmlHeaders(__FILE__, translate('Server').' - '.$Server->Name());
?>
<body>
<div id="page">
<div id="header">
<h2><?php echo translate('Server').' - '.$newServer['Name'] ?></h2>
<h2><?php echo translate('Server').' - '.$Server->Name() ?></h2>
</div>
<div id="content">
<form name="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" onsubmit="return validateForm(this, <?php echo empty($newServer['Name'])?'true':'false' ?>)">
<form name="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" onsubmit="return validateForm(this, <?php echo empty($Server->Name())?'true':'false' ?>)">
<input type="hidden" name="view" value="<?php echo $view ?>"/>
<input type="hidden" name="object" value="server"/>
<input type="hidden" name="id" value="<?php echo validHtmlStr($_REQUEST['id']) ?>"/>
@ -57,43 +47,47 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name']);
<tbody>
<tr>
<th scope="row"><?php echo translate('Name') ?></th>
<td><input type="text" name="newServer[Name]" value="<?php echo $newServer['Name'] ?>"/></td>
<td><input type="text" name="newServer[Name]" value="<?php echo $Server->Name() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Protocol') ?></th>
<td><input type="text" name="newServer[Protocol]" value="<?php echo $newServer['Protocol'] ?>"/></td>
<td><input type="text" name="newServer[Protocol]" value="<?php echo $Server->Protocol() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Hostname') ?></th>
<td><input type="text" name="newServer[Hostname]" value="<?php echo $newServer['Hostname'] ?>"/></td>
<td><input type="text" name="newServer[Hostname]" value="<?php echo $Server->Hostname() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Port') ?></th>
<td><input type="number" name="newServer[Port]" value="<?php echo $newServer['Port'] ?>"/></td>
<td><input type="number" name="newServer[Port]" value="<?php echo $Server->Port() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('PathPrefix') ?></th>
<td><input type="text" name="newServer[PathPrefix]" value="<?php echo $newServer['PathPrefix'] ?>"/></td>
<th scope="row"><?php echo translate('PathToIndex') ?></th>
<td><input type="text" name="newServer[PathToIndex]" value="<?php echo $Server->PathToIndex() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('PathToZMS') ?></th>
<td><input type="text" name="newServer[PathToZMS]" value="<?php echo $Server->PathToZMS() ?>"/></td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunStats') ?></th>
<td>
<input type="radio" name="newServer[zmstats]" value="1"<?php echo $newServer['zmstats'] ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmstats]" value="0"<?php echo $newServer['zmstats'] ? '' : ' checked="checked"' ?>/> No
<input type="radio" name="newServer[zmstats]" value="1"<?php echo $Server->zmstats() ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmstats]" value="0"<?php echo $Server->zmstats() ? '' : ' checked="checked"' ?>/> No
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunAudit') ?></th>
<td>
<input type="radio" name="newServer[zmaudit]" value="1"<?php echo $newServer['zmaudit'] ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmaudit]" value="0"<?php echo $newServer['zmaudit'] ? '' : ' checked="checked"' ?>/> No
<input type="radio" name="newServer[zmaudit]" value="1"<?php echo $Server->zmaudit() ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmaudit]" value="0"<?php echo $Server->zmaudit() ? '' : ' checked="checked"' ?>/> No
</td>
</tr>
<tr>
<th scope="row"><?php echo translate('RunTrigger') ?></th>
<td>
<input type="radio" name="newServer[zmtrigger]" value="1"<?php echo $newServer['zmtrigger'] ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmtrigger]" value="0"<?php echo $newServer['zmtrigger'] ? '' : ' checked="checked"' ?>/> No
<input type="radio" name="newServer[zmtrigger]" value="1"<?php echo $Server->zmtrigger() ? ' checked="checked"' : '' ?>/> Yes
<input type="radio" name="newServer[zmtrigger]" value="0"<?php echo $Server->zmtrigger() ? '' : ' checked="checked"' ?>/> No
</td>
</tr>
</tbody>