diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-02-23 14:38:05 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-02-23 14:38:05 +0100 |
commit | 780cc50f5f1acd9963edc0ccff1ebee9f612827a (patch) | |
tree | 4ae40c82eb2107a2548d8123360627226d1b3388 | |
parent | 4bf2d1c7d09bd20bccc0b6449486804899e53b91 (diff) | |
download | webadmin-780cc50f5f1acd9963edc0ccff1ebee9f612827a.tar.gz |
Added protocol detection to build proper API URL
-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; + } } |