diff --git a/api/admin/canned/index.php b/api/admin/canned/index.php index 39312959..210f7a97 100644 --- a/api/admin/canned/index.php +++ b/api/admin/canned/index.php @@ -5,7 +5,9 @@ define('API_PATH', '../../'); require_once(HESK_PATH . 'hesk_settings.inc.php'); require_once(HESK_PATH . 'inc/common.inc.php'); require_once(API_PATH . 'core/output.php'); +require_once(API_PATH . 'core/'); require_once(API_PATH . 'dao/canned_dao.php'); +require_once(API_PATH . 'businesslogic/security_retriever.php'); hesk_load_api_database_functions(); hesk_dbConnect(); @@ -13,6 +15,21 @@ hesk_dbConnect(); // Routing $request_method = $_SERVER['REQUEST_METHOD']; if ($request_method == 'GET') { + $headers = getallheaders(); + $token = NULL; + if (isset($headers['X-Auth-Token'])) { + $token = $headers['X-Auth-Token']; + } + + try { + get_user_for_token($token, $hesk_settings); + } catch (AccessException $e) { + if ($e->getCode() == 422) { + print_error($e->getMessage(), $e->getMessage()); + } + return http_response_code($e->getCode()); + } + if (isset($_GET['id'])) { $results = get_canned_response($hesk_settings, $_GET['id']); } else { @@ -22,7 +39,7 @@ if ($request_method == 'GET') { if ($results == NULL) { return http_response_code(404); } - output($results); + return output($results); } return http_response_code(405); \ No newline at end of file diff --git a/api/businesslogic/security_retriever.php b/api/businesslogic/security_retriever.php index ef2fbfe9..742d97c7 100644 --- a/api/businesslogic/security_retriever.php +++ b/api/businesslogic/security_retriever.php @@ -2,6 +2,7 @@ require_once(API_PATH . 'dao/security_dao.php'); function get_user_for_token($token, $hesk_settings) { + $hash = hash('sha512', $token); return get_user_for_token_hash($hash, $hesk_settings); diff --git a/api/core/headers.php b/api/core/headers.php new file mode 100644 index 00000000..892fafb0 --- /dev/null +++ b/api/core/headers.php @@ -0,0 +1,9 @@ +