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` (
|
||||
`Id` int(10) unsigned NOT NULL auto_increment,
|
||||
`Hostname` TEXT,
|
||||
`PathPrefix` TEXT,
|
||||
`Name` varchar(64) NOT NULL default '',
|
||||
`State_Id` int(10) unsigned,
|
||||
`Status` enum('Unknown','NotRunning','Running') NOT NULL default 'Unknown',
|
||||
|
|
|
@ -189,25 +189,19 @@ class Event {
|
|||
|
||||
public function getStreamSrc( $args=array(), $querySep='&' ) {
|
||||
|
||||
$streamSrc = ZM_BASE_PROTOCOL.'://';
|
||||
$streamSrc = '';
|
||||
if ( $this->Storage()->ServerId() ) {
|
||||
$Server = $this->Storage()->Server();
|
||||
$streamSrc .= $Server->Hostname();
|
||||
if ( ZM_MIN_STREAMING_PORT ) {
|
||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
||||
}
|
||||
} else if ( $this->Monitor()->ServerId() ) {
|
||||
# Assume that the server that recorded it has it
|
||||
$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 {
|
||||
$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' ) {
|
||||
$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.
|
||||
# We always store at least 1 image when capturing
|
||||
|
||||
$streamSrc = ZM_BASE_PROTOCOL.'://';
|
||||
$streamSrc = '';
|
||||
if ( $this->Storage()->ServerId() ) {
|
||||
$Server = $this->Storage()->Server();
|
||||
$streamSrc .= $Server->Hostname();
|
||||
if ( ZM_MIN_STREAMING_PORT ) {
|
||||
$streamSrc .= ':'.(ZM_MIN_STREAMING_PORT+$this->{'MonitorId'});
|
||||
}
|
||||
} else if ( $this->Monitor()->ServerId() ) {
|
||||
# Assume that the server that recorded it has it
|
||||
$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 {
|
||||
$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';
|
||||
$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;
|
||||
|
||||
$args['monitor'] = $this->{'Id'};
|
||||
|
@ -230,9 +223,9 @@ private $control_fields = array(
|
|||
$args['rand'] = time();
|
||||
}
|
||||
|
||||
$streamSrc .= '?'.http_build_query( $args,'', $querySep );
|
||||
$streamSrc .= '?'.http_build_query($args,'', $querySep);
|
||||
|
||||
return( $streamSrc );
|
||||
return $streamSrc;
|
||||
} // end function getStreamSrc
|
||||
|
||||
public function Width($new = null) {
|
||||
|
@ -487,9 +480,10 @@ private $control_fields = array(
|
|||
$source = preg_replace( '/^.*\//', '', $this->{'Path'} );
|
||||
} elseif ( $this->{'Type'} == 'Ffmpeg' || $this->{'Type'} == 'Libvlc' || $this->{'Type'} == 'WebSite' ) {
|
||||
$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'];
|
||||
} 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['pass']);
|
||||
#unset($url_parts['scheme']);
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
<?php
|
||||
require_once( 'database.php' );
|
||||
require_once('database.php');
|
||||
|
||||
class Server {
|
||||
private $defaults = array(
|
||||
'Id' => null,
|
||||
'Name' => '',
|
||||
'Hostname' => '',
|
||||
'zmaudit' => 1,
|
||||
'zmstats' => 1,
|
||||
'zmtrigger' => 0,
|
||||
'Id' => null,
|
||||
'Name' => '',
|
||||
'Hostname' => '',
|
||||
'PathPrefix' => '/zm',
|
||||
'zmaudit' => 1,
|
||||
'zmstats' => 1,
|
||||
'zmtrigger' => 0,
|
||||
);
|
||||
public function __construct( $IdOrRow = NULL ) {
|
||||
|
||||
public function __construct($IdOrRow = NULL) {
|
||||
$row = NULL;
|
||||
if ( $IdOrRow ) {
|
||||
if ( is_integer( $IdOrRow ) or ctype_digit( $IdOrRow ) ) {
|
||||
$row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) );
|
||||
if ( ! $row ) {
|
||||
Error("Unable to load Server record for Id=" . $IdOrRow );
|
||||
if ( is_integer($IdOrRow) or ctype_digit($IdOrRow) ) {
|
||||
$row = dbFetchOne('SELECT * FROM Servers WHERE Id=?', NULL, array($IdOrRow));
|
||||
if ( !$row ) {
|
||||
Error('Unable to load Server record for Id='.$IdOrRow);
|
||||
}
|
||||
} elseif ( is_array( $IdOrRow ) ) {
|
||||
} elseif ( is_array($IdOrRow) ) {
|
||||
$row = $IdOrRow;
|
||||
}
|
||||
} # end if isset($IdOrRow)
|
||||
|
@ -27,11 +29,12 @@ class Server {
|
|||
$this->{$k} = $v;
|
||||
}
|
||||
} else {
|
||||
$this->{'Name'} = '';
|
||||
$this->{'Hostname'} = '';
|
||||
# Set defaults
|
||||
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();
|
||||
$sql = 'SELECT * FROM Servers ';
|
||||
$values = array();
|
||||
|
@ -42,9 +45,9 @@ class Server {
|
|||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
} else if ( is_array($value) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
||||
$fields[] = $field.' IN ('.implode(',', array_map($func, $value) ). ')';
|
||||
$values += $value;
|
||||
|
||||
} else {
|
||||
|
@ -52,10 +55,10 @@ class Server {
|
|||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
$sql .= implode(' AND ', $fields);
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server');
|
||||
|
@ -65,20 +68,19 @@ class Server {
|
|||
return $filters;
|
||||
}
|
||||
|
||||
public function Url() {
|
||||
if ( $this->Id() ) {
|
||||
return ZM_BASE_PROTOCOL . '://'. $this->Hostname();
|
||||
} else {
|
||||
return ZM_BASE_PROTOCOL . '://'. $_SERVER['SERVER_NAME'];
|
||||
return '';
|
||||
}
|
||||
}
|
||||
public function Hostname() {
|
||||
if ( isset( $this->{'Hostname'} ) and ( $this->{'Hostname'} != '' ) ) {
|
||||
return $this->{'Hostname'};
|
||||
}
|
||||
return $this->{'Name'};
|
||||
}
|
||||
public function Url($port=null) {
|
||||
return ZM_BASE_PROTOCOL.'://'.$this->Hostname().($port ? ':'.$port : '').$this->{'PathPrefix'};
|
||||
}
|
||||
|
||||
public function Hostname() {
|
||||
if ( isset( $this->{'Hostname'}) and ( $this->{'Hostname'} != '' ) ) {
|
||||
return $this->{'Hostname'};
|
||||
} else if ( $this->Id() ) {
|
||||
return $this->{'Name'};
|
||||
}
|
||||
return $_SERVER['SERVER_NAME'];
|
||||
}
|
||||
|
||||
public function __call($fn, array $args){
|
||||
if ( count($args) ) {
|
||||
$this->{$fn} = $args[0];
|
||||
|
@ -86,49 +88,49 @@ class Server {
|
|||
if ( array_key_exists($fn, $this) ) {
|
||||
return $this->{$fn};
|
||||
} else {
|
||||
if ( array_key_exists( $fn, $this->defaults ) ) {
|
||||
if ( array_key_exists($fn, $this->defaults) ) {
|
||||
return $this->defaults{$fn};
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$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';
|
||||
$values = array();
|
||||
if ( sizeof($parameters) ) {
|
||||
$sql .= ' WHERE ' . implode( ' AND ', array_map(
|
||||
$sql .= ' WHERE ' . implode(' AND ', array_map(
|
||||
function($v){ return $v.'=?'; },
|
||||
array_keys( $parameters )
|
||||
) );
|
||||
$values = array_values( $parameters );
|
||||
array_keys($parameters)
|
||||
));
|
||||
$values = array_values($parameters);
|
||||
}
|
||||
if ( is_integer( $limit ) or ctype_digit( $limit ) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
$results = dbFetchAll( $sql, NULL, $values );
|
||||
if ( is_integer($limit) or ctype_digit($limit) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
$results = dbFetchAll($sql, NULL, $values);
|
||||
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() ) {
|
||||
$results = Server::find( $parameters, 1 );
|
||||
if ( ! sizeof( $results ) ) {
|
||||
public static function find_one($parameters = array()) {
|
||||
$results = Server::find($parameters, 1);
|
||||
if ( !sizeof($results) ) {
|
||||
return;
|
||||
}
|
||||
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 ( !($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';
|
||||
return;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ if ( $_REQUEST['id'] ) {
|
|||
$newServer = array();
|
||||
$newServer['Name'] = translate('NewServer');
|
||||
$newServer['Hostname'] = '';
|
||||
$newServer['PathPrefix'] = '/zm';
|
||||
$newServer['zmstats'] = '';
|
||||
$newServer['zmaudit'] = '';
|
||||
$newServer['zmtrigger'] = '';
|
||||
|
@ -39,7 +40,7 @@ if ( $_REQUEST['id'] ) {
|
|||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
||||
xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name']);
|
||||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
|
@ -47,7 +48,7 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
|||
<h2><?php echo translate('Server').' - '.$newServer['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($newServer['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']) ?>"/>
|
||||
|
@ -61,6 +62,10 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$newServer['Name'] );
|
|||
<th scope="row"><?php echo translate('Hostname') ?></th>
|
||||
<td><input type="text" name="newServer[Hostname]" value="<?php echo $newServer['Hostname'] ?>"/></td>
|
||||
</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>
|
||||
<th scope="row"><?php echo translate('RunStats') ?></th>
|
||||
<td>
|
||||
|
|
Loading…
Reference in New Issue