commit
6fbc779c6c
@ -1,4 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Patch for when using nginx instead of apache, source: http://php.net/manual/en/function.getallheaders.php#84262
|
||||||
|
if (!function_exists('getallheaders')) {
|
||||||
|
function getallheaders() {
|
||||||
|
$headers = '';
|
||||||
|
|
||||||
|
foreach ($_SERVER as $name => $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.
|
// Log an action. If $itemId is set, it is an item action.
|
||||||
function logAction($comment, $oldValue, $newValue, $itemId=null) {
|
function logAction($comment, $oldValue, $newValue, $itemId=null) {
|
||||||
$activity = R::dispense('activity');
|
$activity = R::dispense('activity');
|
||||||
@ -27,8 +43,8 @@ function setUserToken($user, $expires) {
|
|||||||
function getUser() {
|
function getUser() {
|
||||||
global $jsonResponse;
|
global $jsonResponse;
|
||||||
|
|
||||||
if (isset(apache_request_headers()['Authorization'])) {
|
if (isset(getallheaders()['Authorization'])) {
|
||||||
$hash = apache_request_headers()['Authorization'];
|
$hash = getallheaders()['Authorization'];
|
||||||
try {
|
try {
|
||||||
$payload = JWT::decode($hash, getJwtKey());
|
$payload = JWT::decode($hash, getJwtKey());
|
||||||
$user = R::load('user', $payload->uid);
|
$user = R::load('user', $payload->uid);
|
||||||
@ -46,7 +62,7 @@ function getUser() {
|
|||||||
// Get all users.
|
// Get all users.
|
||||||
function getUsers($sanitize = true) {
|
function getUsers($sanitize = true) {
|
||||||
try {
|
try {
|
||||||
$hash = apache_request_headers()['Authorization'];
|
$hash = getallheaders()['Authorization'];
|
||||||
$payload = JWT::decode($hash, getJwtKey());
|
$payload = JWT::decode($hash, getJwtKey());
|
||||||
|
|
||||||
$users = R::findAll('user');
|
$users = R::findAll('user');
|
||||||
@ -246,8 +262,8 @@ function validateToken($requireAdmin = false) {
|
|||||||
function checkDbToken() {
|
function checkDbToken() {
|
||||||
$user = getUser();
|
$user = getUser();
|
||||||
if (null != $user) {
|
if (null != $user) {
|
||||||
if (isset(apache_request_headers()['Authorization'])) {
|
if (isset(getallheaders()['Authorization'])) {
|
||||||
$hash = apache_request_headers()['Authorization'];
|
$hash = getallheaders()['Authorization'];
|
||||||
return $hash == $user->token;
|
return $hash == $user->token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +275,7 @@ function clearDbToken() {
|
|||||||
$payload = null;
|
$payload = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$payload = JWT::decode(apache_request_headers()['Authorization'], getJwtKey());
|
$payload = JWT::decode(getallheaders()['Authorization'], getJwtKey());
|
||||||
} catch (Exception $e) {}
|
} catch (Exception $e) {}
|
||||||
|
|
||||||
if (null != $payload) {
|
if (null != $payload) {
|
||||||
@ -358,3 +374,5 @@ function updateItemFromAction(&$item, $action) {
|
|||||||
}
|
}
|
||||||
R::store($item);
|
R::store($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user