add Event disk space recalc to zmaudit

pull/2077/head
Isaac Connor 2017-10-10 12:11:59 -07:00
parent ffc1ac43f5
commit 7f50a13074
8 changed files with 62 additions and 30 deletions
scripts
ZoneMinder/lib/ZoneMinder

View File

@ -32,6 +32,7 @@ require ZoneMinder::Base;
require ZoneMinder::Object; require ZoneMinder::Object;
require ZoneMinder::Storage; require ZoneMinder::Storage;
require Date::Manip; require Date::Manip;
require File;
#our @ISA = qw(ZoneMinder::Object); #our @ISA = qw(ZoneMinder::Object);
use parent qw(ZoneMinder::Object); use parent qw(ZoneMinder::Object);
@ -358,6 +359,17 @@ sub age {
return $_[0]{age}; return $_[0]{age};
} }
sub DiskUsage {
if ( @_ > 1 ) {
$_[0]{DiskUsage} = $_[1];
}
if ( ! defined $_[0]{DiskUsage} ) {
my $size = 0;
File::find( sub { $size += -f $_ ? -s _ : 0 }, $_[0]->Path() );
$_[0]{DiskUsage} = $size;
}
}
1; 1;
__END__ __END__

View File

@ -246,6 +246,7 @@ MAIN: while( $loop ) {
$$Event{Path} = join('/', $Storage->Path(), $day_dir,$event_path); $$Event{Path} = join('/', $Storage->Path(), $day_dir,$event_path);
$Event->MonitorId( $monitor_dir ); $Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->DiskUsage( undef );
} # event path exists } # event path exists
} # end foreach event_link } # end foreach event_link
chdir( $Storage->Path() ); chdir( $Storage->Path() );

View File

@ -3,7 +3,7 @@ require_once( 'database.php' );
require_once( 'Event.php' ); require_once( 'Event.php' );
class Frame { class Frame {
public function __construct( $IdOrRow ) { public function __construct( $IdOrRow=null ) {
$row = NULL; $row = NULL;
if ( $IdOrRow ) { if ( $IdOrRow ) {
if ( is_integer( $IdOrRow ) or ctype_digit($IdOrRow) ) { if ( is_integer( $IdOrRow ) or ctype_digit($IdOrRow) ) {
@ -17,15 +17,15 @@ class Frame {
Error("Unknown argument passed to Frame Constructor ($IdOrRow)"); Error("Unknown argument passed to Frame Constructor ($IdOrRow)");
return; return;
} }
} # end if isset($IdOrRow)
if ( $row ) { if ( $row ) {
foreach ($row as $k => $v) { foreach ($row as $k => $v) {
$this->{$k} = $v; $this->{$k} = $v;
}
} else {
Error("No row for Frame " . $IdOrRow );
} }
} else { } # end if isset($IdOrRow)
Error("No row for Frame " . $IdOrRow );
}
} // end function __construct } // end function __construct
public function Storage() { public function Storage() {

View File

@ -1,22 +1,22 @@
<?php <?php
require_once( 'database.php' ); require_once( 'database.php' );
$storage_cache = array(); #$storage_cache = array();
class Storage { class Storage {
public function __construct( $IdOrRow = NULL ) { public function __construct( $IdOrRow = NULL ) {
$row = NULL; $row = NULL;
if ( $IdOrRow ) { if ( $IdOrRow ) {
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) { if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
if ( isset( $storage_cache[$IdOrRow] ) ) { #if ( isset( $storage_cache[$IdOrRow] ) ) {
Logger::Debug("Using cached Storage object for $IdOrRow"); #Warning("using cached object for $dOrRow");
return $storage_cache[$IdOrRow]; #return $storage_cache[$IdOrRow];
} else { #} else {
#Warning("Not using cached object for $dOrRow");
$row = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array( $IdOrRow ) ); $row = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array( $IdOrRow ) );
if ( ! $row ) { if ( ! $row ) {
Error("Unable to load Storage record for Id=" . $IdOrRow ); Error("Unable to load Storage record for Id=" . $IdOrRow );
} }
}
} elseif ( is_array( $IdOrRow ) ) { } elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow; $row = $IdOrRow;
} }
@ -25,7 +25,7 @@ Logger::Debug("Using cached Storage object for $IdOrRow");
foreach ($row as $k => $v) { foreach ($row as $k => $v) {
$this->{$k} = $v; $this->{$k} = $v;
} }
$storage_cache[$IdOrRow] = $this; #$storage_cache[$IdOrRow] = $this;
} else { } else {
$this->{'Name'} = ''; $this->{'Name'} = '';
$this->{'Path'} = ''; $this->{'Path'} = '';

View File

@ -19,6 +19,11 @@
// //
$servers = Server::find_all(); $servers = Server::find_all();
$ServersById = array();
foreach ( $servers as $S ) {
$ServersById[$S->Id()] = $S;
}
$storage_areas = Storage::find_all(); $storage_areas = Storage::find_all();
$StorageById = array(); $StorageById = array();
foreach ( $storage_areas as $S ) { foreach ( $storage_areas as $S ) {
@ -252,7 +257,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
<td class="colFunction"><?php echo makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'</span>', canEdit( 'Monitors' ) ) ?></td> <td class="colFunction"><?php echo makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'</span>', canEdit( 'Monitors' ) ) ?></td>
<?php <?php
if ( count($servers) ) { ?> if ( count($servers) ) { ?>
<td class="colServer"><?php $Server = new Server( $monitor['ServerId'] ); echo $Server->Name(); ?></td> <td class="colServer"><?php $Server = isset($ServersById[$monitor['ServerId']]) ? $ServersById[$monitor['ServerId']] : new Server( $monitor['ServerId'] ); echo $Server->Name(); ?></td>
<?php <?php
} }
$source = ''; $source = '';

View File

@ -215,7 +215,11 @@ makePopupLink( '?view=monitor&amp;mid='.$event->MonitorId(), 'zmMonitor'.$event-
?> ?>
<td class="colThumbnail"> <td class="colThumbnail">
<?php <?php
if ( file_exists( $event->Path().'/snapshot.jpg' ) ) {
$imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid=snapshot&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height'];
} else {
$imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'].'&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height']; $imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'].'&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height'];
}
$streamSrc = $event->getStreamSrc( array( 'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single') ); $streamSrc = $event->getStreamSrc( array( 'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single') );
$imgHtml = '<img id="thumbnail'.$event->id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($thumbData['Width']) .'px;height:'. validInt( $thumbData['Height'] ).'px;" onmouseover="this.src=\''.$streamSrc.'\';" onmouseout="this.src=\''.$imgSrc.'\';"/>'; $imgHtml = '<img id="thumbnail'.$event->id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($thumbData['Width']) .'px;height:'. validInt( $thumbData['Height'] ).'px;" onmouseover="this.src=\''.$streamSrc.'\';" onmouseout="this.src=\''.$imgSrc.'\';"/>';

View File

@ -50,7 +50,7 @@ monitorNames['<?php echo validJsStr($name) ?>'] = true;
function validateForm( form ) { function validateForm( form ) {
var errors = new Array(); var errors = new Array();
if ( form.elements['newMonitor[Name]'].value.search( /[^\w-\. ]/ ) >= 0 ) if ( form.elements['newMonitor[Name]'].value.search( /[^\w-\.\(\)\:\/ ]/ ) >= 0 )
errors[errors.length] = "<?php echo translate('BadNameChars') ?>"; errors[errors.length] = "<?php echo translate('BadNameChars') ?>";
else if ( form.elements.mid.value == 0 && monitorNames[form.elements['newMonitor[Name]'].value] ) else if ( form.elements.mid.value == 0 && monitorNames[form.elements['newMonitor[Name]'].value] )
errors[errors.length] = "<?php echo translate('DuplicateMonitorName') ?>"; errors[errors.length] = "<?php echo translate('DuplicateMonitorName') ?>";

View File

@ -59,21 +59,31 @@ $Event = null;
$path = null; $path = null;
if ( empty($_REQUEST['path']) ) { if ( empty($_REQUEST['path']) ) {
if ( ! empty($_REQUEST['fid']) ) {
$show = empty($_REQUEST['show']) ? 'capture' : $_REQUEST['show']; if ( ! empty($_REQUEST['fid']) ) {
if ( $_REQUEST['fid'] == 'snapshot' ) {
if ( ! empty($_REQUEST['eid'] ) ) { $Event = new Event( $_REQUEST['eid'] );
$Event = new Event( $_REQUEST['eid'] ); $Frame = new Frame();
$Frame = Frame::find_one( array( 'EventId' => $_REQUEST['eid'], 'FrameId' => $_REQUEST['fid'] ) ); $Frame->FrameId('snapshot');
if ( ! $Frame ) { $path = $Event->Path().'/snapshot.jpg';
Fatal("No Frame found for event(".$_REQUEST['eid'].") and frame id(".$_REQUEST['fid'].")"); Warning("Path to snapshot: $path");
} } else {
} else {
$show = empty($_REQUEST['show']) ? 'capture' : $_REQUEST['show'];
if ( ! empty($_REQUEST['eid'] ) ) {
$Event = new Event( $_REQUEST['eid'] );
$Frame = Frame::find_one( array( 'EventId' => $_REQUEST['eid'], 'FrameId' => $_REQUEST['fid'] ) );
if ( ! $Frame ) {
Fatal("No Frame found for event(".$_REQUEST['eid'].") and frame id(".$_REQUEST['fid'].")");
}
} else {
# If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame # # If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame #
$Frame = new Frame( $_REQUEST['fid'] ); $Frame = new Frame( $_REQUEST['fid'] );
$Event = new Event( $Frame->EventId() ); $Event = new Event( $Frame->EventId() );
}
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
} }
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
} else { } else {
Fatal("No Frame ID specified"); Fatal("No Frame ID specified");