From 1c17f334d31ce444d96d257a396d3499d75a7585 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 29 Nov 2018 14:26:30 -0500 Subject: [PATCH] fix missing bits. Implement UrlToIndex in Monitor and fix use of Url(). Implement PathToApi as well --- db/zm_create.sql.in | 1 + db/zm_update-1.32.3.sql | 16 ++++++++++++++++ web/includes/Event.php | 11 +++++------ web/includes/Monitor.php | 8 +++----- web/includes/Server.php | 17 ++++++++++++++++- web/lang/en_gb.php | 1 + web/skins/classic/views/options.php | 2 ++ web/skins/classic/views/server.php | 4 ++++ 8 files changed, 48 insertions(+), 12 deletions(-) diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 240e8f345..e9f0ca9ab 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -561,6 +561,7 @@ CREATE TABLE `Servers` ( `Port` INTEGER UNSIGNED, `PathToIndex` TEXT, `PathToZMS` TEXT, + `PathToApi` TEXT, `Name` varchar(64) NOT NULL default '', `State_Id` int(10) unsigned, `Status` enum('Unknown','NotRunning','Running') NOT NULL default 'Unknown', diff --git a/db/zm_update-1.32.3.sql b/db/zm_update-1.32.3.sql index a5f6eca1b..6c3e2c47f 100644 --- a/db/zm_update-1.32.3.sql +++ b/db/zm_update-1.32.3.sql @@ -329,6 +329,22 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +-- +-- Add PathToApi column to Storage +-- + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Servers' + AND column_name = 'PathToApi' + ) > 0, +"SELECT 'Column PathToApi already exists in Servers'", +"ALTER TABLE Servers ADD `PathToApi` TEXT AFTER `PathToZMS`" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; + -- -- Add Port column to Storage -- diff --git a/web/includes/Event.php b/web/includes/Event.php index 2046f5ddf..27d9ae015 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -221,11 +221,11 @@ class Event { null); if ( $this->{'DefaultVideo'} and $args['mode'] != 'jpeg' ) { - $streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php'; + $streamSrc .= $Server->PathToIndex(); $args['eid'] = $this->{'Id'}; $args['view'] = 'view_video'; } else { - $streamSrc .= ZM_PATH_ZMS; + $streamSrc .= $Server->PathToZMS(); $args['source'] = 'event'; $args['event'] = $this->{'Id'}; @@ -340,12 +340,11 @@ class Event { } else { $Server = new Server(); } - $streamSrc .= $Server->Url( + $streamSrc .= $Server->UrlToIndex( ZM_MIN_STREAMING_PORT ? ZM_MIN_STREAMING_PORT+$this->{'MonitorId'} : null); - $streamSrc .= ( ZM_BASE_PATH != '/' ? ZM_BASE_PATH : '' ).'/index.php'; $args['eid'] = $this->{'Id'}; $args['fid'] = 'snapshot'; $args['view'] = 'image'; @@ -573,7 +572,7 @@ class Event { $Server = $Storage->ServerId() ? $Storage->Server() : $this->Monitor()->Server(); if ( $Server->Id() != ZM_SERVER_ID ) { - $url = $Server->Url() . '/zm/api/events/'.$this->{'Id'}.'.json'; + $url = $Server->UrlToApi() . '/events/'.$this->{'Id'}.'.json'; if ( ZM_OPT_USE_AUTH ) { if ( ZM_AUTH_RELAY == 'hashed' ) { $url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS ); @@ -617,7 +616,7 @@ class Event { $Server = $Storage->ServerId() ? $Storage->Server() : $this->Monitor()->Server(); if ( $Server->Id() != ZM_SERVER_ID ) { - $url = $Server->Url() . '/zm/api/events/'.$this->{'Id'}.'.json'; + $url = $Server->UrlToApi() . '/events/'.$this->{'Id'}.'.json'; if ( ZM_OPT_USE_AUTH ) { if ( ZM_AUTH_RELAY == 'hashed' ) { $url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS ); diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index 500ae171f..c1a6a47df 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -282,13 +282,11 @@ private $control_fields = array( public function getStreamSrc($args, $querySep='&') { - $streamSrc = $this->Server()->Url( + $streamSrc = $this->Server()->UrlToZMS( ZM_MIN_STREAMING_PORT ? ZM_MIN_STREAMING_PORT+$this->{'Id'} : null); - $streamSrc .= ZM_PATH_ZMS; - $args['monitor'] = $this->{'Id'}; if ( ZM_OPT_USE_AUTH ) { @@ -620,8 +618,8 @@ private $control_fields = array( return $source; } // end function Source - public function Url() { - return $this->Server()->Url( ZM_MIN_STREAMING_PORT ? (ZM_MIN_STREAMING_PORT+$this->Id()) : null ); + public function UrlToIndex() { + return $this->Server()->UrlToIndex(ZM_MIN_STREAMING_PORT ? (ZM_MIN_STREAMING_PORT+$this->Id()) : null); } } // end class Monitor diff --git a/web/includes/Server.php b/web/includes/Server.php index 4c7dc79b2..069e5830c 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -10,7 +10,9 @@ class Server { 'Protocol' => '', 'Hostname' => '', 'Port' => null, - 'PathPrefix' => '/zm', + 'PathToIndex' => '/zm', + 'PathToZMS' => ZM_PATH_ZMS, + 'PathToApi' => '/zm/api', 'zmaudit' => 1, 'zmstats' => 1, 'zmtrigger' => 0, @@ -81,6 +83,7 @@ class Server { return ZM_PATH_ZMS; } } + public function UrlToZMS( ) { return $this->Url().$this->PathToZMS(); } @@ -113,6 +116,18 @@ class Server { public function UrlToIndex( ) { return $this->Url().$this->PathToIndex(); } + public function UrlToApi( ) { + return $this->Url().$this->PathToApi(); + } + public function PathToApi( $new = null ) { + if ( $new != null ) + $this->{'PathToApi'} = $new; + + if ( isset($this->{'PathToApi'}) and $this->{'PathToApi'} ) { + return $this->{'PathToApi'}; + } + return '/zm/api'; + } public function __call($fn, array $args){ if ( count($args) ) { diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 24950fa8e..721a86253 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -586,6 +586,7 @@ $SLANG = array( 'PasswordsDifferent' => 'The new and confirm passwords are different', 'PathToIndex' => 'Path To Index', 'PathToZMS' => 'Path To ZMS', + 'PathToApi' => 'Path To Api', 'Paths' => 'Paths', 'Pause' => 'Pause', 'PhoneBW' => 'Phone B/W', diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index d394f32a1..1b907dfc1 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -211,6 +211,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI + @@ -232,6 +233,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI Id(), 'zmServer', 'server', validHtmlStr($Server->Url()), $canEdit) ?> Id(), 'zmServer', 'server', validHtmlStr($Server->PathToIndex()), $canEdit) ?> Id(), 'zmServer', 'server', validHtmlStr($Server->PathToZMS()), $canEdit) ?> + Id(), 'zmServer', 'server', validHtmlStr($Server->PathToApi()), $canEdit) ?> Id(), 'zmServer', 'server', validHtmlStr($Server->Status()), $canEdit) ?> diff --git a/web/skins/classic/views/server.php b/web/skins/classic/views/server.php index 6b8f41893..42dd5fc6f 100644 --- a/web/skins/classic/views/server.php +++ b/web/skins/classic/views/server.php @@ -69,6 +69,10 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$Server->Name()); + + + +