2015-09-18 03:29:36 +08:00
|
|
|
<?php
|
|
|
|
require_once( 'database.php' );
|
|
|
|
require_once( 'Server.php' );
|
|
|
|
|
|
|
|
class Monitor {
|
2015-12-02 03:03:55 +08:00
|
|
|
public function __construct( $IdOrRow ) {
|
|
|
|
$row = NULL;
|
2015-12-22 22:52:33 +08:00
|
|
|
if ( $IdOrRow ) {
|
|
|
|
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
|
|
|
|
$row = dbFetchOne( 'SELECT * FROM Monitors WHERE Id=?', NULL, array( $IdOrRow ) );
|
|
|
|
if ( ! $row ) {
|
|
|
|
Error("Unable to load Server record for Id=" . $IdOrRow );
|
|
|
|
}
|
|
|
|
} elseif ( is_array( $IdOrRow ) ) {
|
|
|
|
$row = $IdOrRow;
|
|
|
|
} else {
|
|
|
|
Error("Unknown argument passed to Monitor Constructor ($IdOrRow)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} # end if isset($IdOrRow)
|
2015-12-02 03:03:55 +08:00
|
|
|
|
|
|
|
if ( $row ) {
|
|
|
|
foreach ($row as $k => $v) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
|
|
|
if ( $this->{'Controllable'} ) {
|
|
|
|
$s = dbFetchOne( 'SELECT * FROM Controls WHERE Id=?', NULL, array( $this->{'ControlId'} ) );
|
2015-09-18 03:34:09 +08:00
|
|
|
foreach ($s as $k => $v) {
|
2015-12-02 03:03:55 +08:00
|
|
|
if ( $k == 'Id' ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-18 03:34:09 +08:00
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
2015-09-18 03:29:36 +08:00
|
|
|
}
|
2015-12-02 03:03:55 +08:00
|
|
|
|
2015-09-18 03:29:36 +08:00
|
|
|
} else {
|
2015-12-02 03:03:55 +08:00
|
|
|
Error("No row for Monitor " . $IdOrRow );
|
2015-09-18 03:29:36 +08:00
|
|
|
}
|
|
|
|
} // end function __construct
|
2015-12-03 00:21:04 +08:00
|
|
|
public function Server() {
|
|
|
|
return new Server( $this->{'ServerId'} );
|
|
|
|
}
|
2015-09-18 03:29:36 +08:00
|
|
|
public function __call( $fn, array $args){
|
|
|
|
if(isset($this->{$fn})){
|
2015-12-02 04:16:18 +08:00
|
|
|
return $this->{$fn};
|
2015-09-18 03:29:36 +08:00
|
|
|
#array_unshift($args, $this);
|
|
|
|
#call_user_func_array( $this->{$fn}, $args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function getStreamSrc( $args, $querySep='&' ) {
|
|
|
|
if ( isset($this->{'ServerId'}) and $this->{'ServerId'} ) {
|
|
|
|
$Server = new Server( $this->{'ServerId'} );
|
2015-09-18 04:06:47 +08:00
|
|
|
$streamSrc = ZM_BASE_PROTOCOL.'://'.$Server->Hostname().ZM_PATH_ZMS;
|
2015-09-18 03:29:36 +08:00
|
|
|
} else {
|
|
|
|
$streamSrc = ZM_BASE_URL.ZM_PATH_ZMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$args[] = "monitor=".$this->{'Id'};
|
|
|
|
|
|
|
|
if ( ZM_OPT_USE_AUTH ) {
|
|
|
|
if ( ZM_AUTH_RELAY == "hashed" ) {
|
|
|
|
$args[] = "auth=".generateAuthHash( ZM_AUTH_HASH_IPS );
|
|
|
|
} elseif ( ZM_AUTH_RELAY == "plain" ) {
|
|
|
|
$args[] = "user=".$_SESSION['username'];
|
|
|
|
$args[] = "pass=".$_SESSION['password'];
|
|
|
|
} elseif ( ZM_AUTH_RELAY == "none" ) {
|
|
|
|
$args[] = "user=".$_SESSION['username'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) {
|
|
|
|
$args[] = "connkey=".$GLOBALS['connkey'];
|
|
|
|
}
|
|
|
|
if ( ZM_RAND_STREAM ) {
|
|
|
|
$args[] = "rand=".time();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( count($args) ) {
|
|
|
|
$streamSrc .= "?".join( $querySep, $args );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( $streamSrc );
|
2016-04-01 23:35:38 +08:00
|
|
|
} // end function getStreamSrc
|
2016-01-05 02:15:50 +08:00
|
|
|
public function Width() {
|
|
|
|
if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) {
|
|
|
|
return $this->{'Height'};
|
|
|
|
}
|
|
|
|
return $this->{'Width'};
|
|
|
|
}
|
|
|
|
public function Height() {
|
|
|
|
if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) {
|
|
|
|
return $this->{'Width'};
|
|
|
|
}
|
|
|
|
return $this->{'Height'};
|
|
|
|
}
|
2016-04-01 22:34:40 +08:00
|
|
|
public function set( $data ) {
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if ( is_array( $v ) ) {
|
|
|
|
# perhaps should turn into a comma-separated string
|
|
|
|
$this->{$k} = implode(',',$v);
|
|
|
|
} else if ( is_string( $v ) ) {
|
|
|
|
$this->{$k} = trim( $v );
|
|
|
|
} else {
|
|
|
|
Error( "Unknown type of var " . gettype( $v ) );
|
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 03:29:36 +08:00
|
|
|
}
|
|
|
|
?>
|