mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 10:54:52 +00:00
API
- Add PHP logging when API queries fail because of SQL errors - Add user agent to logging - Enhance asset update endpoint
This commit is contained in:
@@ -3,89 +3,8 @@
|
||||
require_once('../validate_api_key.php');
|
||||
require_once('../require_post_method.php');
|
||||
|
||||
// Parse info
|
||||
|
||||
// Variable assignment - assigning blank if a value is not provided
|
||||
if (isset($_POST['asset_name'])) {
|
||||
$name = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_name'])));
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
if (isset($_POST['asset_type'])) {
|
||||
$type = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_type'])));
|
||||
} else {
|
||||
$type = '';
|
||||
}
|
||||
if (isset($_POST['asset_make'])) {
|
||||
$make = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_make'])));
|
||||
} else {
|
||||
$make = '';
|
||||
}
|
||||
if (isset($_POST['asset_model'])) {
|
||||
$model = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_model'])));
|
||||
} else {
|
||||
$model = '';
|
||||
}
|
||||
if (isset($_POST['asset_serial'])) {
|
||||
$serial = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_serial'])));
|
||||
} else {
|
||||
$serial = '';
|
||||
}
|
||||
if (isset($_POST['asset_os'])) {
|
||||
$os = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_os'])));
|
||||
} else {
|
||||
$os = '';
|
||||
}
|
||||
if (isset($_POST['asset_ip'])) {
|
||||
$aip = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_ip'])));
|
||||
} else {
|
||||
$aip = '';
|
||||
}
|
||||
if (isset($_POST['asset_mac'])) {
|
||||
$mac = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_mac'])));
|
||||
} else {
|
||||
$mac = '';
|
||||
}
|
||||
if (isset($_POST['asset_purchase_date'])) {
|
||||
$purchase_date = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_purchase_date'])));
|
||||
} else {
|
||||
$purchase_date = "0000-00-00";
|
||||
}
|
||||
if (isset($_POST['asset_warranty_expire'])) {
|
||||
$warranty_expire = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_warranty_expire'])));
|
||||
} else {
|
||||
$warranty_expire = "0000-00-00";
|
||||
}
|
||||
if (isset($_POST['asset_install_date'])) {
|
||||
$install_date = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_install_date'])));
|
||||
} else {
|
||||
$install_date = "0000-00-00";
|
||||
}
|
||||
if (isset($_POST['asset_notes'])) {
|
||||
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['asset_notes'])));
|
||||
} else {
|
||||
$notes = '';
|
||||
}
|
||||
if (isset($_POST['asset_vendor_id'])) {
|
||||
$vendor = intval($_POST['asset_vendor_id']);
|
||||
} else {
|
||||
$vendor = '0';
|
||||
}
|
||||
if (isset($_POST['asset_location_id'])) {
|
||||
$location = intval($_POST['asset_location_id']);
|
||||
} else {
|
||||
$location = '0';
|
||||
}
|
||||
if (isset($_POST['asset_contact_id'])) {
|
||||
$contact = intval($_POST['asset_contact_id']);
|
||||
} else {
|
||||
$contact = '0';
|
||||
}
|
||||
if (isset($_POST['asset_network_id'])) {
|
||||
$network = intval($_POST['asset_network_id']);
|
||||
} else {
|
||||
$network = '0';
|
||||
}
|
||||
// Parse POST info
|
||||
require_once('asset_model.php');
|
||||
|
||||
// Default
|
||||
$insert_id = false;
|
||||
@@ -98,8 +17,8 @@ if (!empty($name) && !empty($client_id)) {
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = '$client_id', company_id = $company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created asset $name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = '$client_id', company_id = $company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = '$client_id', company_id = $company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created asset $name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = '$client_id', company_id = $company_id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user