From a3158fcc97315fcd8c34a4d94ac735ded8ef9ae5 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Wed, 2 May 2018 12:26:28 -0400 Subject: [PATCH 1/3] auth_key api for different situations (#2090) * auth_key api for different situations * added new flag to indicate if password needs to be appended * pure json view --- web/api/app/Controller/HostController.php | 42 ++++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index 3f1770f42..cdde92e35 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -30,20 +30,36 @@ class HostController extends AppController { )); } - function getAuthHash() { - if ( $zmOptAuth == '1' ) { - require_once '../../../includes/auth.php'; - $this->set(array( - 'auth_hash' => generateAuthHash(ZM_AUTH_HASH_IPS), - '_serialize' => array('auth_hash') - ) ); - } else { - $this->set(array( - 'auth_hash' => '', - '_serialize' => array('auth_hash') - ) ); + function getCredentials() { + // ignore debug warnings from other functions + $this->view='Json'; + $appendPassword = 0; + $this->loadModel('Config'); + $isZmAuth = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_OPT_USE_AUTH')))['Config']['Value']; + $authVal = ""; + if ($isZmAuth) { + $zmAuthRelay = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_RELAY')))['Config']['Value']; + if ($zmAuthRelay == 'hashed') { + + $zmAuthHashIps= $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_HASH_IPS')))['Config']['Value']; + $authVal = 'auth='.generateAuthHash($zmAuthHashIps); + } + elseif ($zmAuthRelay == 'plain') { + // user will need to append the store password here + $authVal = "user=".$this->Session->read('user.Username')."&pass="; + $appendPassword = 1; + } + elseif ($zmAuthRelay == 'none') { + $authVal = "user=".$this->Session->read('user.Username'); + } } - } + $this->set(array( + 'auth_key'=> $authVal, + 'append_password'=>$appendPassword, + '_serialize' => array('auth_key', 'append_password') + ) ); + } + // If $mid is set, only return disk usage for that monitor // Else, return an array of total disk usage, and per-monitor From e953a04f615d820da1948339157c26edbba64de2 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Thu, 3 May 2018 14:03:49 -0400 Subject: [PATCH 2/3] naming consistency of attribute (#2096) --- web/api/app/Controller/HostController.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index cdde92e35..0313bd97a 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -32,31 +32,32 @@ class HostController extends AppController { function getCredentials() { // ignore debug warnings from other functions - $this->view='Json'; - $appendPassword = 0; + $this->view='Json'; + $credentials = ""; + $appendPassword = 0; + $this->loadModel('Config'); $isZmAuth = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_OPT_USE_AUTH')))['Config']['Value']; - $authVal = ""; + if ($isZmAuth) { $zmAuthRelay = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_RELAY')))['Config']['Value']; if ($zmAuthRelay == 'hashed') { - $zmAuthHashIps= $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_HASH_IPS')))['Config']['Value']; - $authVal = 'auth='.generateAuthHash($zmAuthHashIps); + $credentials = 'auth='.generateAuthHash($zmAuthHashIps); } elseif ($zmAuthRelay == 'plain') { // user will need to append the store password here - $authVal = "user=".$this->Session->read('user.Username')."&pass="; + $credentials = "user=".$this->Session->read('user.Username')."&pass="; $appendPassword = 1; } elseif ($zmAuthRelay == 'none') { - $authVal = "user=".$this->Session->read('user.Username'); + $credentials = "user=".$this->Session->read('user.Username'); } } $this->set(array( - 'auth_key'=> $authVal, + 'credentials'=> $credentials, 'append_password'=>$appendPassword, - '_serialize' => array('auth_key', 'append_password') + '_serialize' => array('credentials', 'append_password') ) ); } From 7bc2c6dbc5339fbd683d3f1ed2055252a994c2e8 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 4 May 2018 12:04:28 -0500 Subject: [PATCH 3/3] Downgrade Unable to send stream to warning Downgraded this from en Error to a Warning. This message can trigger following the normal closing of a monitor. Thus, it's not necessarily an error. --- src/zm_monitorstream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zm_monitorstream.cpp b/src/zm_monitorstream.cpp index d41b73a70..48d83200c 100644 --- a/src/zm_monitorstream.cpp +++ b/src/zm_monitorstream.cpp @@ -330,7 +330,7 @@ bool MonitorStream::sendFrame(const char *filepath, struct timeval *timestamp) { fprintf(stdout, "Content-Length: %d\r\n", img_buffer_size); if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) { if ( ! zm_terminate ) - Error("Unable to send stream frame: %s", strerror(errno)); + Warning("Unable to send stream frame: %s", strerror(errno)); return false; } fputs("\r\n\r\n", stdout); @@ -407,7 +407,7 @@ bool MonitorStream::sendFrame(Image *image, struct timeval *timestamp) { if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) { if ( !zm_terminate ){ // If the pipe was closed, we will get signalled SIGPIPE to exit, which will set zm_terminate - Error("Unable to send stream frame: %s", strerror(errno)); + Warning("Unable to send stream frame: %s", strerror(errno)); } return false; }