2015-09-17 03:16:07 +08:00
|
|
|
<?php
|
2019-02-22 22:19:07 +08:00
|
|
|
namespace ZM;
|
2018-07-10 00:09:57 +08:00
|
|
|
require_once('database.php');
|
2019-09-20 04:24:05 +08:00
|
|
|
require_once('Object.php');
|
2015-12-31 23:13:48 +08:00
|
|
|
|
2018-09-15 21:42:59 +08:00
|
|
|
|
2019-09-20 04:24:05 +08:00
|
|
|
class Server extends ZM_Object {
|
|
|
|
protected static $table = 'Servers';
|
2019-02-22 22:19:07 +08:00
|
|
|
|
2019-09-20 04:24:05 +08:00
|
|
|
protected $defaults = array(
|
2019-02-27 22:28:36 +08:00
|
|
|
'Id' => null,
|
|
|
|
'Name' => '',
|
|
|
|
'Protocol' => '',
|
|
|
|
'Hostname' => '',
|
|
|
|
'Port' => null,
|
|
|
|
'PathToIndex' => null,
|
|
|
|
'PathToZMS' => ZM_PATH_ZMS,
|
|
|
|
'PathToApi' => '/zm/api',
|
|
|
|
'zmaudit' => 1,
|
|
|
|
'zmstats' => 1,
|
|
|
|
'zmtrigger' => 0,
|
|
|
|
'zmeventnotification' => 0,
|
2018-01-18 03:22:04 +08:00
|
|
|
);
|
2018-07-10 00:09:57 +08:00
|
|
|
|
2019-09-20 04:24:05 +08:00
|
|
|
public static function find( $parameters = array(), $options = array() ) {
|
|
|
|
return ZM_Object::_find(get_class(), $parameters, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function find_one( $parameters = array(), $options = array() ) {
|
|
|
|
return ZM_Object::_find_one(get_class(), $parameters, $options);
|
2016-05-06 03:33:28 +08:00
|
|
|
}
|
2018-07-10 00:09:57 +08:00
|
|
|
|
2018-11-22 23:04:33 +08:00
|
|
|
public function Hostname( $new = null ) {
|
|
|
|
if ( $new != null )
|
|
|
|
$this->{'Hostname'} = $new;
|
2018-01-14 04:15:14 +08:00
|
|
|
|
2018-11-22 23:04:33 +08:00
|
|
|
if ( isset( $this->{'Hostname'}) and ( $this->{'Hostname'} != '' ) ) {
|
|
|
|
return $this->{'Hostname'};
|
|
|
|
} else if ( $this->Id() ) {
|
|
|
|
return $this->{'Name'};
|
2018-01-14 04:15:14 +08:00
|
|
|
}
|
2019-10-09 22:00:13 +08:00
|
|
|
# This theoretically will match ipv6 addresses as well
|
|
|
|
if ( preg_match( '/^(\[[[:xdigit:]:]+\]|[^:]+)(:[[:digit:]]+)?$/', $_SERVER['HTTP_HOST'], $matches ) ) {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
|
2019-09-24 00:03:19 +08:00
|
|
|
$result = explode(':', $_SERVER['HTTP_HOST']);
|
2018-12-07 21:39:23 +08:00
|
|
|
return $result[0];
|
2018-11-22 23:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Protocol( $new = null ) {
|
|
|
|
if ( $new != null )
|
|
|
|
$this->{'Protocol'} = $new;
|
|
|
|
|
|
|
|
if ( isset($this->{'Protocol'}) and ( $this->{'Protocol'} != '' ) ) {
|
|
|
|
return $this->{'Protocol'};
|
2018-01-14 04:15:14 +08:00
|
|
|
}
|
2018-12-13 23:24:32 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' )
|
|
|
|
or
|
|
|
|
( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and ( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) )
|
|
|
|
) ? 'https' : 'http';
|
2018-01-14 04:15:14 +08:00
|
|
|
}
|
2015-09-18 03:34:26 +08:00
|
|
|
|
2018-11-22 23:04:33 +08:00
|
|
|
public function Port( $new = '' ) {
|
|
|
|
if ( $new != '' )
|
|
|
|
$this->{'Port'} = $new;
|
|
|
|
|
|
|
|
if ( isset($this->{'Port'}) and $this->{'Port'} ) {
|
|
|
|
return $this->{'Port'};
|
|
|
|
}
|
2018-12-13 23:24:32 +08:00
|
|
|
|
|
|
|
if ( isset($_SERVER['HTTP_X_FORWARDED_PORT']) ) {
|
|
|
|
return $_SERVER['HTTP_X_FORWARDED_PORT'];
|
|
|
|
}
|
|
|
|
|
2018-11-22 23:04:33 +08:00
|
|
|
return $_SERVER['SERVER_PORT'];
|
2018-07-10 00:09:57 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 06:35:25 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 03:26:30 +08:00
|
|
|
|
2018-12-01 03:45:58 +08:00
|
|
|
public function UrlToZMS( $port = null ) {
|
|
|
|
return $this->Url($port).$this->PathToZMS();
|
2018-11-28 06:35:25 +08:00
|
|
|
}
|
|
|
|
|
2018-10-08 21:55:47 +08:00
|
|
|
public function Url( $port = null ) {
|
2018-11-22 23:04:33 +08:00
|
|
|
$url = $this->Protocol().'://';
|
2018-12-07 21:39:23 +08:00
|
|
|
$url .= $this->Hostname();
|
2018-10-08 21:55:47 +08:00
|
|
|
if ( $port ) {
|
|
|
|
$url .= ':'.$port;
|
2018-10-19 22:59:16 +08:00
|
|
|
} else {
|
2018-11-22 23:04:33 +08:00
|
|
|
$url .= ':'.$this->Port();
|
2018-07-10 00:09:57 +08:00
|
|
|
}
|
2018-10-08 21:55:47 +08:00
|
|
|
return $url;
|
2015-09-18 03:34:26 +08:00
|
|
|
}
|
2018-11-22 23:04:33 +08:00
|
|
|
|
2018-11-28 06:35:25 +08:00
|
|
|
public function PathToIndex( $new = null ) {
|
2018-11-22 23:04:33 +08:00
|
|
|
if ( $new != null )
|
2018-11-28 06:35:25 +08:00
|
|
|
$this->{'PathToIndex'} = $new;
|
2018-11-22 23:04:33 +08:00
|
|
|
|
2018-11-28 06:35:25 +08:00
|
|
|
if ( isset($this->{'PathToIndex'}) and $this->{'PathToIndex'} ) {
|
|
|
|
return $this->{'PathToIndex'};
|
2018-11-22 23:04:33 +08:00
|
|
|
}
|
2019-02-10 14:12:36 +08:00
|
|
|
// We can't trust PHP_SELF to not include an XSS vector. See note in skin.js.php.
|
|
|
|
return preg_replace('/\.php.*$/i', '.php', $_SERVER['PHP_SELF']);
|
2018-07-10 00:09:57 +08:00
|
|
|
}
|
|
|
|
|
2018-12-01 03:45:58 +08:00
|
|
|
public function UrlToIndex( $port=null ) {
|
|
|
|
return $this->Url($port).$this->PathToIndex();
|
2018-11-28 06:35:25 +08:00
|
|
|
}
|
2018-12-01 03:45:58 +08:00
|
|
|
public function UrlToApi( $port=null ) {
|
|
|
|
return $this->Url($port).$this->PathToApi();
|
2018-11-30 03:26:30 +08:00
|
|
|
}
|
|
|
|
public function PathToApi( $new = null ) {
|
|
|
|
if ( $new != null )
|
|
|
|
$this->{'PathToApi'} = $new;
|
|
|
|
|
|
|
|
if ( isset($this->{'PathToApi'}) and $this->{'PathToApi'} ) {
|
|
|
|
return $this->{'PathToApi'};
|
|
|
|
}
|
|
|
|
return '/zm/api';
|
|
|
|
}
|
2018-07-10 00:09:57 +08:00
|
|
|
} # end class Server
|
2015-09-17 03:16:07 +08:00
|
|
|
?>
|