Merge ../ZoneMinder.master into server_path_prefix
This commit is contained in:
commit
7ef43a0684
|
@ -556,6 +556,7 @@ DROP TABLE IF EXISTS `Servers`;
|
||||||
CREATE TABLE `Servers` (
|
CREATE TABLE `Servers` (
|
||||||
`Id` int(10) unsigned NOT NULL auto_increment,
|
`Id` int(10) unsigned NOT NULL auto_increment,
|
||||||
`Hostname` TEXT,
|
`Hostname` TEXT,
|
||||||
|
`PathPrefix` TEXT,
|
||||||
`Name` varchar(64) NOT NULL default '',
|
`Name` varchar(64) NOT NULL default '',
|
||||||
`State_Id` int(10) unsigned,
|
`State_Id` int(10) unsigned,
|
||||||
`Status` enum('Unknown','NotRunning','Running') NOT NULL default 'Unknown',
|
`Status` enum('Unknown','NotRunning','Running') NOT NULL default 'Unknown',
|
||||||
|
|
|
@ -189,25 +189,19 @@ class Event {
|
||||||
|
|
||||||
public function getStreamSrc( $args=array(), $querySep='&' ) {
|
public function getStreamSrc( $args=array(), $querySep='&' ) {
|
||||||
|
|
||||||
$streamSrc = ZM_BASE_PROTOCOL.'://';
|
$streamSrc = '';
|
||||||
if ( $this->Storage()->ServerId() ) {
|
if ( $this->Storage()->ServerId() ) {
|
||||||
$Server = $this->Storage()->Server();
|
$Server = $this->Storage()->Server();
|
||||||
$streamSrc .= $Server->Hostname();
|
|
||||||
if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
}
|
|
||||||
} else if ( $this->Monitor()->ServerId() ) {
|
} else if ( $this->Monitor()->ServerId() ) {
|
||||||
# Assume that the server that recorded it has it
|
# Assume that the server that recorded it has it
|
||||||
$Server = $this->Monitor()->Server();
|
$Server = $this->Monitor()->Server();
|
||||||
$streamSrc .= $Server->Hostname();
|
|
||||||
if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
}
|
|
||||||
} else if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= $_SERVER['SERVER_NAME'].':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
} else {
|
} else {
|
||||||
$streamSrc .= $_SERVER['HTTP_HOST'];
|
$Server = new Server;
|
||||||
}
|
}
|
||||||
|
$streamSrc .= $Server->Url(
|
||||||
|
ZM_MIN_STREAMING_PORT ?
|
||||||
|
ZM_MIN_STREAMING_PORT+$this->{'MonitorId'} :
|
||||||
|
null);
|
||||||
|
|
||||||
if ( $this->{'DefaultVideo'} and $args['mode'] != 'jpeg' ) {
|
if ( $this->{'DefaultVideo'} and $args['mode'] != 'jpeg' ) {
|
||||||
$streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php';
|
$streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php';
|
||||||
|
@ -319,25 +313,19 @@ class Event {
|
||||||
# The thumbnail is theoretically the image with the most motion.
|
# The thumbnail is theoretically the image with the most motion.
|
||||||
# We always store at least 1 image when capturing
|
# We always store at least 1 image when capturing
|
||||||
|
|
||||||
$streamSrc = ZM_BASE_PROTOCOL.'://';
|
$streamSrc = '';
|
||||||
if ( $this->Storage()->ServerId() ) {
|
if ( $this->Storage()->ServerId() ) {
|
||||||
$Server = $this->Storage()->Server();
|
$Server = $this->Storage()->Server();
|
||||||
$streamSrc .= $Server->Hostname();
|
|
||||||
if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
}
|
|
||||||
} else if ( $this->Monitor()->ServerId() ) {
|
} else if ( $this->Monitor()->ServerId() ) {
|
||||||
|
# Assume that the server that recorded it has it
|
||||||
$Server = $this->Monitor()->Server();
|
$Server = $this->Monitor()->Server();
|
||||||
$streamSrc .= $Server->Hostname();
|
|
||||||
if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= $_SERVER['SERVER_NAME'].':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
|
||||||
} else {
|
} else {
|
||||||
$streamSrc .= $_SERVER['HTTP_HOST'];
|
$Server = new Server;
|
||||||
}
|
}
|
||||||
|
$streamSrc .= $Server->Url(
|
||||||
|
ZM_MIN_STREAMING_PORT ?
|
||||||
|
ZM_MIN_STREAMING_PORT+$this->{'MonitorId'} :
|
||||||
|
null);
|
||||||
|
|
||||||
$streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php';
|
$streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php';
|
||||||
$args['eid'] = $this->{'Id'};
|
$args['eid'] = $this->{'Id'};
|
||||||
|
|
|
@ -195,20 +195,13 @@ private $control_fields = array(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStreamSrc( $args, $querySep='&' ) {
|
public function getStreamSrc($args, $querySep='&') {
|
||||||
|
|
||||||
|
$streamSrc = $this->Server()->Url(
|
||||||
|
ZM_MIN_STREAMING_PORT ?
|
||||||
|
ZM_MIN_STREAMING_PORT+$this->{'Id'} :
|
||||||
|
null);
|
||||||
|
|
||||||
$streamSrc = ZM_BASE_PROTOCOL.'://';
|
|
||||||
if ( isset($this->{'ServerId'}) and $this->{'ServerId'} ) {
|
|
||||||
$Server = new Server( $this->{'ServerId'} );
|
|
||||||
$streamSrc .= $Server->Hostname();
|
|
||||||
if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'Id'});
|
|
||||||
}
|
|
||||||
} else if ( ZM_MIN_STREAMING_PORT ) {
|
|
||||||
$streamSrc .= $_SERVER['SERVER_NAME'].':'.(ZM_MIN_STREAMING_PORT+$this->{'Id'});
|
|
||||||
} else {
|
|
||||||
$streamSrc .= $_SERVER['HTTP_HOST'];
|
|
||||||
}
|
|
||||||
$streamSrc .= ZM_PATH_ZMS;
|
$streamSrc .= ZM_PATH_ZMS;
|
||||||
|
|
||||||
$args['monitor'] = $this->{'Id'};
|
$args['monitor'] = $this->{'Id'};
|
||||||
|
@ -230,9 +223,9 @@ private $control_fields = array(
|
||||||
$args['rand'] = time();
|
$args['rand'] = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
$streamSrc .= '?'.http_build_query( $args,'', $querySep );
|
$streamSrc .= '?'.http_build_query($args,'', $querySep);
|
||||||
|
|
||||||
return( $streamSrc );
|
return $streamSrc;
|
||||||
} // end function getStreamSrc
|
} // end function getStreamSrc
|
||||||
|
|
||||||
public function Width($new = null) {
|
public function Width($new = null) {
|
||||||
|
@ -487,9 +480,10 @@ private $control_fields = array(
|
||||||
$source = preg_replace( '/^.*\//', '', $this->{'Path'} );
|
$source = preg_replace( '/^.*\//', '', $this->{'Path'} );
|
||||||
} elseif ( $this->{'Type'} == 'Ffmpeg' || $this->{'Type'} == 'Libvlc' || $this->{'Type'} == 'WebSite' ) {
|
} elseif ( $this->{'Type'} == 'Ffmpeg' || $this->{'Type'} == 'Libvlc' || $this->{'Type'} == 'WebSite' ) {
|
||||||
$url_parts = parse_url( $this->{'Path'} );
|
$url_parts = parse_url( $this->{'Path'} );
|
||||||
if ( ZM_WEB_FILTER_SOURCE == "Hostname" ) { # Filter out everything but the hostname
|
if ( ZM_WEB_FILTER_SOURCE == 'Hostname' ) { # Filter out everything but the hostname
|
||||||
$source = $url_parts['host'];
|
$source = $url_parts['host'];
|
||||||
} elseif ( ZM_WEB_FILTER_SOURCE == "NoCredentials" ) { # Filter out sensitive and common items
|
} elseif ( ZM_WEB_FILTER_SOURCE == 'NoCredentials' ) {
|
||||||
|
# Filter out sensitive and common items
|
||||||
unset($url_parts['user']);
|
unset($url_parts['user']);
|
||||||
unset($url_parts['pass']);
|
unset($url_parts['pass']);
|
||||||
#unset($url_parts['scheme']);
|
#unset($url_parts['scheme']);
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
require_once( 'database.php' );
|
require_once('database.php');
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
private $defaults = array(
|
private $defaults = array(
|
||||||
'Id' => null,
|
'Id' => null,
|
||||||
'Name' => '',
|
'Name' => '',
|
||||||
'Hostname' => '',
|
'Hostname' => '',
|
||||||
'zmaudit' => 1,
|
'PathPrefix' => '/zm',
|
||||||
'zmstats' => 1,
|
'zmaudit' => 1,
|
||||||
'zmtrigger' => 0,
|
'zmstats' => 1,
|
||||||
|
'zmtrigger' => 0,
|
||||||
);
|
);
|
||||||
public function __construct( $IdOrRow = NULL ) {
|
|
||||||
|
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) ) {
|
||||||
$row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) );
|
$row = dbFetchOne('SELECT * FROM Servers WHERE Id=?', NULL, array($IdOrRow));
|
||||||
if ( ! $row ) {
|
if ( !$row ) {
|
||||||
Error("Unable to load Server record for Id=" . $IdOrRow );
|
Error('Unable to load Server record for Id='.$IdOrRow);
|
||||||
}
|
}
|
||||||
} elseif ( is_array( $IdOrRow ) ) {
|
} elseif ( is_array($IdOrRow) ) {
|
||||||
$row = $IdOrRow;
|
$row = $IdOrRow;
|
||||||
}
|
}
|
||||||
} # end if isset($IdOrRow)
|
} # end if isset($IdOrRow)
|
||||||
|
@ -27,11 +29,12 @@ class Server {
|
||||||
$this->{$k} = $v;
|
$this->{$k} = $v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->{'Name'} = '';
|
# Set defaults
|
||||||
$this->{'Hostname'} = '';
|
foreach ( $this->defaults as $k => $v ) $this->{$k} = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function find_all( $parameters = null, $options = null ) {
|
|
||||||
|
public static function find_all($parameters = null, $options = null) {
|
||||||
$filters = array();
|
$filters = array();
|
||||||
$sql = 'SELECT * FROM Servers ';
|
$sql = 'SELECT * FROM Servers ';
|
||||||
$values = array();
|
$values = array();
|
||||||
|
@ -42,9 +45,9 @@ class Server {
|
||||||
foreach ( $parameters as $field => $value ) {
|
foreach ( $parameters as $field => $value ) {
|
||||||
if ( $value == null ) {
|
if ( $value == null ) {
|
||||||
$fields[] = $field.' IS NULL';
|
$fields[] = $field.' IS NULL';
|
||||||
} else if ( is_array( $value ) ) {
|
} else if ( is_array($value) ) {
|
||||||
$func = function(){return '?';};
|
$func = function(){return '?';};
|
||||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
$fields[] = $field.' IN ('.implode(',', array_map($func, $value) ). ')';
|
||||||
$values += $value;
|
$values += $value;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,10 +55,10 @@ class Server {
|
||||||
$values[] = $value;
|
$values[] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql .= implode(' AND ', $fields );
|
$sql .= implode(' AND ', $fields);
|
||||||
}
|
}
|
||||||
if ( $options and isset($options['order']) ) {
|
if ( $options and isset($options['order']) ) {
|
||||||
$sql .= ' ORDER BY ' . $options['order'];
|
$sql .= ' ORDER BY ' . $options['order'];
|
||||||
}
|
}
|
||||||
$result = dbQuery($sql, $values);
|
$result = dbQuery($sql, $values);
|
||||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server');
|
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server');
|
||||||
|
@ -65,20 +68,19 @@ class Server {
|
||||||
return $filters;
|
return $filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Url() {
|
public function Url($port=null) {
|
||||||
if ( $this->Id() ) {
|
return ZM_BASE_PROTOCOL.'://'.$this->Hostname().($port ? ':'.$port : '').$this->{'PathPrefix'};
|
||||||
return ZM_BASE_PROTOCOL . '://'. $this->Hostname();
|
}
|
||||||
} else {
|
|
||||||
return ZM_BASE_PROTOCOL . '://'. $_SERVER['SERVER_NAME'];
|
public function Hostname() {
|
||||||
return '';
|
if ( isset( $this->{'Hostname'}) and ( $this->{'Hostname'} != '' ) ) {
|
||||||
}
|
return $this->{'Hostname'};
|
||||||
}
|
} else if ( $this->Id() ) {
|
||||||
public function Hostname() {
|
return $this->{'Name'};
|
||||||
if ( isset( $this->{'Hostname'} ) and ( $this->{'Hostname'} != '' ) ) {
|
}
|
||||||
return $this->{'Hostname'};
|
return $_SERVER['SERVER_NAME'];
|
||||||
}
|
}
|
||||||
return $this->{'Name'};
|
|
||||||
}
|
|
||||||
public function __call($fn, array $args){
|
public function __call($fn, array $args){
|
||||||
if ( count($args) ) {
|
if ( count($args) ) {
|
||||||
$this->{$fn} = $args[0];
|
$this->{$fn} = $args[0];
|
||||||
|
@ -86,49 +88,49 @@ class Server {
|
||||||
if ( array_key_exists($fn, $this) ) {
|
if ( array_key_exists($fn, $this) ) {
|
||||||
return $this->{$fn};
|
return $this->{$fn};
|
||||||
} else {
|
} else {
|
||||||
if ( array_key_exists( $fn, $this->defaults ) ) {
|
if ( array_key_exists($fn, $this->defaults) ) {
|
||||||
return $this->defaults{$fn};
|
return $this->defaults{$fn};
|
||||||
} else {
|
} else {
|
||||||
$backTrace = debug_backtrace();
|
$backTrace = debug_backtrace();
|
||||||
$file = $backTrace[1]['file'];
|
$file = $backTrace[1]['file'];
|
||||||
$line = $backTrace[1]['line'];
|
$line = $backTrace[1]['line'];
|
||||||
Warning( "Unknown function call Server->$fn from $file:$line" );
|
Warning("Unknown function call Server->$fn from $file:$line");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function find( $parameters = array(), $limit = NULL ) {
|
public static function find($parameters = array(), $limit = NULL) {
|
||||||
$sql = 'SELECT * FROM Servers';
|
$sql = 'SELECT * FROM Servers';
|
||||||
$values = array();
|
$values = array();
|
||||||
if ( sizeof($parameters) ) {
|
if ( sizeof($parameters) ) {
|
||||||
$sql .= ' WHERE ' . implode( ' AND ', array_map(
|
$sql .= ' WHERE ' . implode(' AND ', array_map(
|
||||||
function($v){ return $v.'=?'; },
|
function($v){ return $v.'=?'; },
|
||||||
array_keys( $parameters )
|
array_keys($parameters)
|
||||||
) );
|
));
|
||||||
$values = array_values( $parameters );
|
$values = array_values($parameters);
|
||||||
}
|
}
|
||||||
if ( is_integer( $limit ) or ctype_digit( $limit ) ) {
|
if ( is_integer($limit) or ctype_digit($limit) ) {
|
||||||
$sql .= ' LIMIT ' . $limit;
|
$sql .= ' LIMIT ' . $limit;
|
||||||
} else {
|
} else {
|
||||||
$backTrace = debug_backtrace();
|
$backTrace = debug_backtrace();
|
||||||
$file = $backTrace[1]['file'];
|
$file = $backTrace[1]['file'];
|
||||||
$line = $backTrace[1]['line'];
|
$line = $backTrace[1]['line'];
|
||||||
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$results = dbFetchAll( $sql, NULL, $values );
|
$results = dbFetchAll($sql, NULL, $values);
|
||||||
if ( $results ) {
|
if ( $results ) {
|
||||||
return array_map( function($id){ return new Server($id); }, $results );
|
return array_map(function($id){ return new Server($id); }, $results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function find_one( $parameters = array() ) {
|
public static function find_one($parameters = array()) {
|
||||||
$results = Server::find( $parameters, 1 );
|
$results = Server::find($parameters, 1);
|
||||||
if ( ! sizeof( $results ) ) {
|
if ( !sizeof($results) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $results[0];
|
return $results[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} # end class Server
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ if ( !canEdit( 'System' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $_REQUEST['id'] ) {
|
if ( $_REQUEST['id'] ) {
|
||||||
if ( !($newServer = dbFetchOne( 'SELECT * FROM Servers WHERE Id = ?', NULL, ARRAY($_REQUEST['id'])) ) ) {
|
if ( !($newServer = dbFetchOne('SELECT * FROM Servers WHERE Id = ?', NULL, ARRAY($_REQUEST['id']))) ) {
|
||||||
$view = 'error';
|
$view = 'error';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ if ( $_REQUEST['id'] ) {
|
||||||
$newServer = array();
|
$newServer = array();
|
||||||
$newServer['Name'] = translate('NewServer');
|
$newServer['Name'] = translate('NewServer');
|
||||||
$newServer['Hostname'] = '';
|
$newServer['Hostname'] = '';
|
||||||
|
$newServer['PathPrefix'] = '/zm';
|
||||||
$newServer['zmstats'] = '';
|
$newServer['zmstats'] = '';
|
||||||
$newServer['zmaudit'] = '';
|
$newServer['zmaudit'] = '';
|
||||||
$newServer['zmtrigger'] = '';
|
$newServer['zmtrigger'] = '';
|
||||||
|
@ -39,7 +40,7 @@ if ( $_REQUEST['id'] ) {
|
||||||
|
|
||||||
$focusWindow = true;
|
$focusWindow = true;
|
||||||
|
|
||||||
xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name']);
|
||||||
?>
|
?>
|
||||||
<body>
|
<body>
|
||||||
<div id="page">
|
<div id="page">
|
||||||
|
@ -47,7 +48,7 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
||||||
<h2><?php echo translate('Server').' - '.$newServer['Name'] ?></h2>
|
<h2><?php echo translate('Server').' - '.$newServer['Name'] ?></h2>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<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($newServer['Name'])?'true':'false' ?>)">
|
||||||
<input type="hidden" name="view" value="<?php echo $view ?>"/>
|
<input type="hidden" name="view" value="<?php echo $view ?>"/>
|
||||||
<input type="hidden" name="object" value="server"/>
|
<input type="hidden" name="object" value="server"/>
|
||||||
<input type="hidden" name="id" value="<?php echo validHtmlStr($_REQUEST['id']) ?>"/>
|
<input type="hidden" name="id" value="<?php echo validHtmlStr($_REQUEST['id']) ?>"/>
|
||||||
|
@ -61,6 +62,10 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
||||||
<th scope="row"><?php echo translate('Hostname') ?></th>
|
<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 $newServer['Hostname'] ?>"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><?php echo translate('PathPrefix') ?></th>
|
||||||
|
<td><input type="text" name="newServer[PathPrefix]" value="<?php echo $newServer['PathPrefix'] ?>"/></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php echo translate('RunStats') ?></th>
|
<th scope="row"><?php echo translate('RunStats') ?></th>
|
||||||
<td>
|
<td>
|
||||||
|
|
Loading…
Reference in New Issue