diff --git a/api/v1/assets/create.php b/api/v1/assets/create.php new file mode 100644 index 00000000..6969f176 --- /dev/null +++ b/api/v1/assets/create.php @@ -0,0 +1,55 @@ +insert_id; + if(isset($insert_id) && is_numeric($insert_id)){ + // Insert successful + $return_arr['success'] = "True"; + $return_arr['count'] = '1'; + $return_arr['data'][] = [ + 'insert_id' => $insert_id + ]; + } + // We shouldn't get here + else{ + $return_arr['success'] = "False"; + $return_arr['message'] = "Auth success but insert failed, possibly database connection. Seek support if this error continues."; + } +} + +// 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 insert query failed, ensure required variables are provided and database schema is up-to-date."; +} + +echo json_encode($return_arr); +exit(); \ No newline at end of file diff --git a/api/v1/read_output.php b/api/v1/read_output.php index f2477180..0bb69ed6 100644 --- a/api/v1/read_output.php +++ b/api/v1/read_output.php @@ -1,21 +1,26 @@ 0){ - $return_arr['success'] = "True"; - $return_arr['count'] = mysqli_num_rows($sql); + $return_arr['success'] = "True"; + $return_arr['count'] = mysqli_num_rows($sql); - $row = array(); - while($row = mysqli_fetch_array($sql)){ - $return_arr['data'][] = $row; - } + $row = array(); + while($row = mysqli_fetch_array($sql)){ + $return_arr['data'][] = $row; + } - echo json_encode($return_arr); - exit(); + echo json_encode($return_arr); + exit(); } else{ - $return_arr['success'] = "False"; - $return_arr['message'] = "No resource for this company with the specified parameter(s)."; - echo json_encode($return_arr); - exit(); + $return_arr['success'] = "False"; + $return_arr['message'] = "No resource (for this company) with the specified parameter(s)."; + echo json_encode($return_arr); + exit(); } \ No newline at end of file diff --git a/api/v1/tickets/read.php b/api/v1/tickets/read.php index 3470b32d..7366dd99 100644 --- a/api/v1/tickets/read.php +++ b/api/v1/tickets/read.php @@ -2,22 +2,22 @@ require('../validate_api_key.php'); if($_SERVER['REQUEST_METHOD'] !== "GET"){ - header("HTTP/1.1 405 Method Not Allowed"); - $return_arr['success'] = "False"; - $return_arr['message'] = "Can only send GET requests to this endpoint."; - echo json_encode($return_arr); - exit(); + header("HTTP/1.1 405 Method Not Allowed"); + $return_arr['success'] = "False"; + $return_arr['message'] = "Can only send GET requests to this endpoint."; + echo json_encode($return_arr); + exit(); } // Specific ticket via ID (single) if(isset($_GET['ticket_id'])){ - $id = intval($_GET['ticket_id']); - $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = '$id' AND company_id = '$company_id'"); + $id = intval($_GET['ticket_id']); + $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = '$id' AND company_id = '$company_id'"); } // All tickets else{ - $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE company_id = '$company_id' ORDER BY ticket_id LIMIT $limit OFFSET $offset"); + $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE company_id = '$company_id' ORDER BY ticket_id LIMIT $limit OFFSET $offset"); } // Output diff --git a/api/v1/validate_api_key.php b/api/v1/validate_api_key.php index 01695ae8..45c6e851 100644 --- a/api/v1/validate_api_key.php +++ b/api/v1/validate_api_key.php @@ -1,4 +1,11 @@ NOW()"); + $sql = mysqli_query($mysqli,"SELECT * FROM api_keys WHERE api_key_secret = '$api_key' AND api_key_expire > NOW() LIMIT 1"); - // Failed - if(mysqli_num_rows($sql) != 1){ - // Invalid Key - header("HTTP/1.1 401 Unauthorized"); - mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = 'Incorrect or expired Key', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW()"); + // Failed + if(mysqli_num_rows($sql) !== 1){ + // Invalid Key + header("HTTP/1.1 401 Unauthorized"); + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = 'Incorrect or expired Key', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW()"); - $return_arr['success'] = "False"; - $return_arr['message'] = "API Key authentication failure or expired."; + $return_arr['success'] = "False"; + $return_arr['message'] = "API Key authentication failure or expired."; - header("HTTP/1.1 401 Unauthorized"); - echo json_encode($return_arr); - exit(); + header("HTTP/1.1 401 Unauthorized"); + echo json_encode($return_arr); + exit(); + } + + // Success + else{ + + // Set company ID + $row = mysqli_fetch_array($sql); + $company_id = $row['company_id']; + + // Set limit & offset for queries + if(isset($_GET['limit'])){ + $limit = intval($_GET['limit']); + } + elseif(isset($_POST['limit'])){ + $limit = intval($_POST['limit']); } - - // Success else{ - - // Set company ID - $row = mysqli_fetch_array($sql); - $company_id = $row['company_id']; - - // Set limit & offset for queries - if(isset($_GET['limit'])){ - $limit = intval($_GET['limit']); - } - elseif(isset($_POST['limit'])){ - $limit = intval($_POST['limit']); - } - else{ - $limit = 50; - } - - if(isset($_GET['offset'])){ - $offset = intval($_GET['offset']); - } - elseif(isset($_POST['offset'])){ - $offset = intval($_POST['offset']); - } - else{ - $offset = 0; - } - + $limit = 50; } + + if(isset($_GET['offset'])){ + $offset = intval($_GET['offset']); + } + elseif(isset($_POST['offset'])){ + $offset = intval($_POST['offset']); + } + else{ + $offset = 0; + } + + } } \ No newline at end of file