mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Better debugging for 3rd party-apps
This commit is contained in:
@@ -168,14 +168,16 @@ class API extends CI_Controller {
|
||||
$raw = file_get_contents("php://input");
|
||||
$raw = $raw = preg_replace('#<([eE][oO][rR])>[\r\n\t]+#', '<$1>', $raw);
|
||||
$obj = json_decode($raw,true);
|
||||
$raw='';
|
||||
if ($obj === NULL) {
|
||||
log_message("Debug",'API Call 200. Wrong JSON provided: '.$raw);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]);
|
||||
die();
|
||||
}
|
||||
$raw='';
|
||||
|
||||
if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) {
|
||||
http_response_code(401);
|
||||
log_message("Debug",'API Call 401. Invalid API Key: '.($obj['key'] ?? 'N/A'));
|
||||
echo json_encode(['status' => 'failed', 'reason' => "missing or wrong api key"]);
|
||||
die();
|
||||
}
|
||||
@@ -205,6 +207,7 @@ class API extends CI_Controller {
|
||||
|
||||
if(!isset($obj['station_profile_id']) || $this->stations->check_station_against_user($obj['station_profile_id'], $userid) == false) {
|
||||
http_response_code(401);
|
||||
log_message("Debug",'API Call 401: Wrong station_id '.($obj['station_profile_id'] ?? 'N/A').' for User '.$userid);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "station id does not belong to the API key owner."]);
|
||||
die();
|
||||
}
|
||||
@@ -263,9 +266,11 @@ class API extends CI_Controller {
|
||||
|
||||
if ($adif_errors == 0) {
|
||||
http_response_code(201);
|
||||
log_message("Debug",'API Call 201: QSO created for Station-ID: '.($obj['station_profile_id'] ?? 'N/A').' and User: '.$userid);
|
||||
echo json_encode(['status' => 'created', 'type' => $obj['type'], 'string' => $obj['string'], 'adif_count' => $adif_count, 'adif_errors' => $adif_errors, 'messages' => $return_msg ]);
|
||||
} else {
|
||||
$return_msg[]=$custom_errors;
|
||||
log_message("Debug",'API Call 400: QSO NOT created for Station-ID: '.($obj['station_profile_id'] ?? 'N/A').' and User: '.$userid.' Reason: '.implode($return_msg));
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'abort', 'type' => $obj['type'], 'string' => $obj['string'], 'adif_count' => $adif_count, 'adif_errors' => $adif_errors, 'messages' => $return_msg ]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user