From 4cfed769abf450ad473fe6b73e2f79b42deba084 Mon Sep 17 00:00:00 2001 From: Alex van den Hoogen Date: Mon, 20 Oct 2014 12:53:56 +0200 Subject: [PATCH 1/2] Update helpers.php A patch for when people are using nginx (or any other webserver) instead of apache to serve Taskboard. This adds an helper function from php.net and replaces the apache_ functions with the generic getallheaders, that is supported since php 5.3. --- api/helpers.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/api/helpers.php b/api/helpers.php index 036a4b0..dc23e64 100644 --- a/api/helpers.php +++ b/api/helpers.php @@ -1,4 +1,20 @@ $value) { + if (substr($name, 0, 5) == 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + + return $headers; + } +} + // Log an action. If $itemId is set, it is an item action. function logAction($comment, $oldValue, $newValue, $itemId=null) { $activity = R::dispense('activity'); @@ -27,8 +43,8 @@ function setUserToken($user, $expires) { function getUser() { global $jsonResponse; - if (isset(apache_request_headers()['Authorization'])) { - $hash = apache_request_headers()['Authorization']; + if (isset(getallheaders()['Authorization'])) { + $hash = getallheaders()['Authorization']; try { $payload = JWT::decode($hash, getJwtKey()); $user = R::load('user', $payload->uid); @@ -46,7 +62,7 @@ function getUser() { // Get all users. function getUsers($sanitize = true) { try { - $hash = apache_request_headers()['Authorization']; + $hash = getallheaders()['Authorization']; $payload = JWT::decode($hash, getJwtKey()); $users = R::findAll('user'); @@ -246,8 +262,8 @@ function validateToken($requireAdmin = false) { function checkDbToken() { $user = getUser(); if (null != $user) { - if (isset(apache_request_headers()['Authorization'])) { - $hash = apache_request_headers()['Authorization']; + if (isset(getallheaders()['Authorization'])) { + $hash = getallheaders()['Authorization']; return $hash == $user->token; } } @@ -259,7 +275,7 @@ function clearDbToken() { $payload = null; try { - $payload = JWT::decode(apache_request_headers()['Authorization'], getJwtKey()); + $payload = JWT::decode(getallheaders()['Authorization'], getJwtKey()); } catch (Exception $e) {} if (null != $payload) { @@ -358,3 +374,5 @@ function updateItemFromAction(&$item, $action) { } R::store($item); } + + From a476b7afc377d110dcb4e9baaaf5af89baadc547 Mon Sep 17 00:00:00 2001 From: Alex van den Hoogen Date: Mon, 20 Oct 2014 12:58:12 +0200 Subject: [PATCH 2/2] Update helpers.php Forgot to remove a char. --- api/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/helpers.php b/api/helpers.php index dc23e64..55f0f03 100644 --- a/api/helpers.php +++ b/api/helpers.php @@ -2,7 +2,7 @@ // Patch for when using nginx instead of apache, source: http://php.net/manual/en/function.getallheaders.php#84262 if (!function_exists('getallheaders')) { - function getallheaders() \{ + function getallheaders() { $headers = ''; foreach ($_SERVER as $name => $value) {