diff options
-rw-r--r-- | lib/kolab_client_task.php | 6 | ||||
-rw-r--r-- | lib/kolab_utils.php | 25 |
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php index 7cc8863..6a6fac1 100644 --- a/lib/kolab_client_task.php +++ b/lib/kolab_client_task.php @@ -103,11 +103,11 @@ class kolab_client_task */ private function api_init() { - $url = $this->config_get('api_url', ''); + $url = $this->config_get('api_url', ''); if (!$url) { - // @TODO: http/https - $url = 'http://' . $_SERVER['SERVER_NAME']; + $url = kolab_utils::https_check() ? 'https://' : 'http://'; + $url .= $_SERVER['SERVER_NAME']; $url .= preg_replace('/\/?\?.*$/', '', $_SERVER['REQUEST_URI']); $url .= '/api'; } diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php index 167c9d2..390b9eb 100644 --- a/lib/kolab_utils.php +++ b/lib/kolab_utils.php @@ -103,6 +103,10 @@ class kolab_utils /** * Make sure the string ends with a slash + * + * @param string $str String to parse + * + * @return string String with one slash at the end */ public static function slashify($str) { @@ -111,10 +115,31 @@ class kolab_utils /** * Remove slash at the end of the string + * + * @param string $str String to parse + * + * @return string String without any slashes at the end */ public static function unslashify($str) { return preg_replace('/\/$/', '', $str); } + /** + * Check if secure protocol is being used. + * + * @return bool True when using https protocol, False otherwise + */ + public static function https_check() + { + if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { + return true; + } + + if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') { + return true; + } + + return false; + } } |