Change messages for wrapper

parent da78648e
<?php
$settings = require(__DIR__ . '/settings.php');
/**
* Convinience function to send a json encoded response and exit
*
* @param $response array Array containing the response to json encode
* @param $error_code HTTP STATUS response code
*/
function error_response($response, $error_code = 200)
{
http_response_code($error_code);
header("Content-Type: application/json");
echo json_encode($response);
exit(0);
}
//
$settings_file = __DIR__ . '/settings.php';
if (is_readable($settings_file)) {
$settings = require($settings_file);
} else {
error_response(['message' => 'Error: Application Server (Internal Error, cannot read file system or missing property file)'], 500);
}
/**
* Get params.
......@@ -50,6 +71,14 @@ function wscall($params)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
error_response(['message' => 'Error: EDET Web Service Unreachable'], 500);
}
if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
http_response_code($http_code);
}
curl_close($ch);
return $result;
}
......@@ -83,16 +112,7 @@ function check_input($identity)
$valid = true;
if (preg_match('/^[0-9]{12}$/', $identity) !== 1) {
$valid = [
"message" => "Error: Malformed identity"
];
}
if ($valid !== true) {
http_response_code(500);
header("Content-Type: application/json");
echo json_encode($valid);
exit(0);
error_response(['message' => 'Error: Service Call Parameters Error, academic id must be 12 digit number'], 500);
}
return true;
......@@ -112,26 +132,13 @@ function check_authentication_header($username, $password)
$auth_parts = [];
if (preg_match('/^Basic (.+)$/', $header, $auth_parts) === 1) {
if ($auth_parts[1] !== md5("{$username}:{$password}")) {
$auth = [
"message" => "Error: Invalid Credentials"
];
error_response(['message' => 'Error: Invalid or Missing Basic Authorization Credentials'], 401);
}
} else {
$auth = [
"message" => "Error: Mallformed Authorization Header"
];
error_response(['message' => 'Error: Invalid or Missing Basic Authorization Credentials'], 401);
}
} else {
$auth = [
"message" => "Error: Missing Authorization Header"
];
}
if ($auth !== true) {
http_response_code(401);
header("Content-Type: application/json");
echo json_encode($auth);
exit(0);
error_response(['message' => 'Error: Missing Basic Authorization Header'], 401);
}
return true;
......@@ -165,7 +172,6 @@ switch ($params['operation']) {
case 'echo':
default:
header("Content-Type: text/plain");
// $result = filter_input(INPUT_SERVER, 'QUERY_STRING');
unset($_GET['operation']);
$result = http_build_query($_GET);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment