diff --git a/api/v1/assets/asset_model.php b/api/v1/assets/asset_model.php new file mode 100644 index 00000000..ffbfa6df --- /dev/null +++ b/api/v1/assets/asset_model.php @@ -0,0 +1,129 @@ + 0) { else { $return_arr['success'] = "False"; $return_arr['message'] = "Auth success but delete query failed. Ensure ALL required variables are provided and database schema is up-to-date. Most likely cause: asset/client/company ID mismatch."; + + // Log any database/schema related errors to the PHP Error log + if (mysqli_error($mysqli)) { + error_log("API Database Error: " . mysqli_error($mysqli)); + } } echo json_encode($return_arr); -exit(); \ No newline at end of file +exit(); diff --git a/api/v1/read_output.php b/api/v1/read_output.php index 42c6cde9..97162ace 100644 --- a/api/v1/read_output.php +++ b/api/v1/read_output.php @@ -21,6 +21,12 @@ if ($sql && mysqli_num_rows($sql) > 0) { else { $return_arr['success'] = "False"; $return_arr['message'] = "No resource (for this client and company) with the specified parameter(s)."; + + // Log any database/schema related errors to the PHP Error log + if (mysqli_error($mysqli)) { + error_log("API Database Error: " . mysqli_error($mysqli)); + } + echo json_encode($return_arr); exit(); -} \ No newline at end of file +} diff --git a/api/v1/update_output.php b/api/v1/update_output.php index 59e7c13c..da985b54 100644 --- a/api/v1/update_output.php +++ b/api/v1/update_output.php @@ -16,8 +16,13 @@ if (isset($update_count) && is_numeric($update_count) && $update_count > 0) { // Query returned false: something went wrong, or it was declined due to required variables missing else { $return_arr['success'] = "False"; - $return_arr['message'] = "Auth success but update query failed/returned no results. Ensure ALL required variables are provided and database schema is up-to-date. Most likely cause: non-existent module ID (contact ID/ticket ID/etc)"; + $return_arr['message'] = "Auth success but update query failed/returned no results. Ensure ALL required variables are provided and database schema is up-to-date. Most likely cause: non-existent module ID (i.e. bad contact ID/ticket ID/etc)."; + + // Log any database/schema related errors to the PHP Error log + if (mysqli_error($mysqli)) { + error_log("API Database Error: " . mysqli_error($mysqli)); + } } echo json_encode($return_arr); -exit(); \ No newline at end of file +exit(); diff --git a/api/v1/validate_api_key.php b/api/v1/validate_api_key.php index 6fa07065..e2f29590 100644 --- a/api/v1/validate_api_key.php +++ b/api/v1/validate_api_key.php @@ -16,9 +16,8 @@ header('Content-Type: application/json'); // POST data $_POST = json_decode(file_get_contents('php://input'), true); -// Get user IP +// Get IP & UA $ip = strip_tags(mysqli_real_escape_string($mysqli, getIP())); -// Get user agent $user_agent = strip_tags(mysqli_real_escape_string($mysqli, $_SERVER['HTTP_USER_AGENT'])); // Setup return array @@ -81,10 +80,10 @@ if (isset($api_key)) { header(WORDING_UNAUTHORIZED); echo json_encode($return_arr); exit(); - } - // Success - else { + } else { + + // SUCCESS // Set client ID, company ID & key name $row = mysqli_fetch_array($sql); @@ -95,21 +94,17 @@ if (isset($api_key)) { // Set limit & offset for queries if (isset($_GET['limit'])) { $limit = intval($_GET['limit']); - } - elseif (isset($_POST['limit'])) { + } elseif (isset($_POST['limit'])) { $limit = intval($_POST['limit']); - } - else { + } else { $limit = 50; } if (isset($_GET['offset'])) { $offset = intval($_GET['offset']); - } - elseif (isset($_POST['offset'])) { + } elseif (isset($_POST['offset'])) { $offset = intval($_POST['offset']); - } - else { + } else { $offset = 0; }