mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
MAJOR Feature Update - Backup before updating Migrated Asset Network info to a seperate table to allow for multiple interfaces per asset
This commit is contained in:
109
post/asset.php
109
post/asset.php
@@ -52,10 +52,13 @@ if (isset($_POST['add_asset'])) {
|
||||
|
||||
$alert_extended = "";
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO assets SET asset_name = '$name', asset_description = '$description', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_ip = '$ip', asset_ipv6 = '$ipv6', asset_nat_ip = '$nat_ip', asset_mac = '$mac', asset_uri = '$uri', asset_uri_2 = '$uri_2', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_status = '$status', asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes', asset_network_id = $network, asset_client_id = $client_id");
|
||||
mysqli_query($mysqli,"INSERT INTO assets SET asset_name = '$name', asset_description = '$description', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_uri = '$uri', asset_uri_2 = '$uri_2', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_status = '$status', asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes', asset_client_id = $client_id");
|
||||
|
||||
$asset_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Add Primary Interface
|
||||
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_port = 'eth0', interface_primary = 1, interface_network_id = $network, interface_asset_id = $asset_id");
|
||||
|
||||
if (!empty($_POST['username'])) {
|
||||
$username = trim(mysqli_real_escape_string($mysqli, encryptLoginEntry($_POST['username'])));
|
||||
$password = trim(mysqli_real_escape_string($mysqli, encryptLoginEntry($_POST['password'])));
|
||||
@@ -127,7 +130,10 @@ if (isset($_POST['edit_asset'])) {
|
||||
}
|
||||
$notes = sanitizeInput($_POST['notes']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE assets SET asset_name = '$name', asset_description = '$description', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_ip = '$ip', asset_ipv6 = '$ipv6', asset_nat_ip = '$nat_ip', asset_mac = '$mac', asset_uri = '$uri', asset_uri_2 = '$uri_2', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_status = '$status', asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes', asset_network_id = $network WHERE asset_id = $asset_id");
|
||||
mysqli_query($mysqli,"UPDATE assets SET asset_name = '$name', asset_description = '$description', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_uri = '$uri', asset_uri_2 = '$uri_2', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_status = '$status', asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes' WHERE asset_id = $asset_id");
|
||||
|
||||
// Update Primary Interface
|
||||
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_network_id = $network, interface_asset_id = $asset_id AND interface_primary = 1");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Asset', log_action = 'Modify', log_description = '$session_name modified asset $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $asset_id");
|
||||
@@ -199,6 +205,9 @@ if (isset($_GET['delete_asset'])) {
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM assets WHERE asset_id = $asset_id");
|
||||
|
||||
// Delete Interfaces
|
||||
mysqli_query($mysqli,"DELETE FROM asset_interfaces WHERE interface_asset_id = $asset_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Asset', log_action = 'Delete', log_description = '$session_name deleted asset $asset_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $asset_id");
|
||||
|
||||
@@ -588,3 +597,99 @@ if (isset($_POST['export_client_assets_csv'])) {
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['add_asset_interface'])) {
|
||||
|
||||
validateTechRole();
|
||||
|
||||
$asset_id = intval($_POST['asset_id']);
|
||||
|
||||
// Get Asset Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$asset_name = sanitizeInput($row['asset_name']);
|
||||
$client_id = intval($row['asset_client_id']);
|
||||
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$mac = sanitizeInput($_POST['mac']);
|
||||
$ip = sanitizeInput($_POST['ip']);
|
||||
if($_POST['dhcp'] == 1){
|
||||
$ip = 'DHCP';
|
||||
}
|
||||
$ipv6 = sanitizeInput($_POST['ipv6']);
|
||||
$port = sanitizeInput($_POST['port']);
|
||||
$network = intval($_POST['network']);
|
||||
$notes = sanitizeInput($_POST['notes']);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '$name', interface_mac = '$mac', interface_ip = '$ip', interface_ipv6 = '$ipv6', interface_port = '$port', interface_notes = '$notes', interface_network_id = $network, interface_asset_id = $asset_id");
|
||||
|
||||
$interface_id = mysqli_insert_id($mysqli);
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Interface', log_action = 'Create', log_description = '$session_name created interface $name for asset $asset_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $asset_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Interface <strong>$name</strong> created";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_asset_interface'])) {
|
||||
|
||||
validateTechRole();
|
||||
|
||||
$interface_id = intval($_POST['interface_id']);
|
||||
|
||||
// Get Asset Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id, asset_id FROM asset_interfaces LEFT JOIN assets ON asset_id = interface_asset_id WHERE interface_id = $interface_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$asset_name = sanitizeInput($row['asset_name']);
|
||||
$client_id = intval($row['asset_client_id']);
|
||||
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$mac = sanitizeInput($_POST['mac']);
|
||||
$ip = sanitizeInput($_POST['ip']);
|
||||
if($_POST['dhcp'] == 1){
|
||||
$ip = 'DHCP';
|
||||
}
|
||||
$ipv6 = sanitizeInput($_POST['ipv6']);
|
||||
$port = sanitizeInput($_POST['port']);
|
||||
$network = intval($_POST['network']);
|
||||
$notes = sanitizeInput($_POST['notes']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_name = '$name', interface_mac = '$mac', interface_ip = '$ip', interface_ipv6 = '$ipv6', interface_port = '$port', interface_notes = '$notes', interface_network_id = $network WHERE interface_id = $interface_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Interface', log_action = 'Create', log_description = '$session_name edited interface $name for asset $asset_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $asset_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Interface <strong>$name</strong> edited";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_asset_interface'])) {
|
||||
|
||||
validateAdminRole();
|
||||
|
||||
$interface_id = intval($_GET['delete_asset_interface']);
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT asset_name, interface_name, asset_client_id, asset_id FROM asset_interfaces LEFT JOIN assets ON asset_id = interface_asset_id WHERE interface_id = $interface_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$asset_id = intval($row['asset_id']);
|
||||
$interface_name = sanitizeInput($row['interface_name']);
|
||||
$asset_name = sanitizeInput($row['asset_name']);
|
||||
$client_id = intval($row['asset_client_id']);
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM asset_interfaces WHERE interface_id = $interface_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Interface', log_action = 'Delete', log_description = '$session_name deleted interface $interface_name from asset $asset_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $asset_id");
|
||||
|
||||
$_SESSION['alert_type'] = "error";
|
||||
$_SESSION['alert_message'] = "Interface <strong>$interface_name</strong> deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
@@ -418,15 +418,16 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$sql_assets = mysqli_query($mysqli,"SELECT * FROM assets
|
||||
LEFT JOIN contacts ON asset_contact_id = contact_id
|
||||
LEFT JOIN locations ON asset_location_id = location_id
|
||||
LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
|
||||
WHERE asset_client_id = $client_id
|
||||
AND asset_archived_at IS NULL
|
||||
ORDER BY asset_type ASC"
|
||||
);
|
||||
$sql_asset_workstations = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id WHERE asset_client_id = $client_id AND (asset_type = 'desktop' OR asset_type = 'laptop') AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_servers = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN locations ON asset_location_id = location_id WHERE asset_client_id = $client_id AND asset_type = 'server' AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_vms = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_client_id = $client_id AND asset_type = 'virtual machine' AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_network = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN locations ON asset_location_id = location_id WHERE asset_client_id = $client_id AND (asset_type = 'Firewall/Router' OR asset_type = 'Switch' OR asset_type = 'Access Point') AND asset_archived_at IS NULL ORDER BY asset_type ASC");
|
||||
$sql_asset_other = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id WHERE asset_client_id = $client_id AND (asset_type NOT LIKE 'laptop' AND asset_type NOT LIKE 'desktop' AND asset_type NOT LIKE 'server' AND asset_type NOT LIKE 'virtual machine' AND asset_type NOT LIKE 'firewall/router' AND asset_type NOT LIKE 'switch' AND asset_type NOT LIKE 'access point') AND asset_archived_at IS NULL ORDER BY asset_type ASC");
|
||||
$sql_asset_workstations = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id = $client_id AND (asset_type = 'desktop' OR asset_type = 'laptop') AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_servers = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id = $client_id AND asset_type = 'server' AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_vms = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id = $client_id AND asset_type = 'virtual machine' AND asset_archived_at IS NULL ORDER BY asset_name ASC");
|
||||
$sql_asset_network = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id = $client_id AND (asset_type = 'Firewall/Router' OR asset_type = 'Switch' OR asset_type = 'Access Point') AND asset_archived_at IS NULL ORDER BY asset_type ASC");
|
||||
$sql_asset_other = mysqli_query($mysqli,"SELECT * FROM assets LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_client_id = $client_id AND (asset_type NOT LIKE 'laptop' AND asset_type NOT LIKE 'desktop' AND asset_type NOT LIKE 'server' AND asset_type NOT LIKE 'virtual machine' AND asset_type NOT LIKE 'firewall/router' AND asset_type NOT LIKE 'switch' AND asset_type NOT LIKE 'access point') AND asset_archived_at IS NULL ORDER BY asset_type ASC");
|
||||
$sql_networks = mysqli_query($mysqli,"SELECT * FROM networks WHERE network_client_id = $client_id AND network_archived_at IS NULL ORDER BY network_name ASC");
|
||||
$sql_domains = mysqli_query($mysqli,"SELECT * FROM domains WHERE domain_client_id = $client_id AND domain_archived_at IS NULL ORDER BY domain_name ASC");
|
||||
$sql_certficates = mysqli_query($mysqli,"SELECT * FROM certificates WHERE certificate_client_id = $client_id AND certificate_archived_at IS NULL ORDER BY certificate_name ASC");
|
||||
@@ -892,8 +893,8 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$asset_model = $row['asset_model'];
|
||||
$asset_serial = $row['asset_serial'];
|
||||
$asset_os = $row['asset_os'];
|
||||
$asset_ip = $row['asset_ip'];
|
||||
$asset_mac = $row['asset_mac'];
|
||||
$asset_ip = $row['interface_ip'];
|
||||
$asset_mac = $row['interface_mac'];
|
||||
$asset_purchase_date = $row['asset_purchase_date'];
|
||||
$asset_warranty_expire = $row['asset_warranty_expire'];
|
||||
$asset_install_date = $row['asset_install_date'];
|
||||
@@ -1011,8 +1012,8 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$asset_model = $row['asset_model'];
|
||||
$asset_serial = $row['asset_serial'];
|
||||
$asset_os = $row['asset_os'];
|
||||
$asset_ip = $row['asset_ip'];
|
||||
$asset_mac = $row['asset_mac'];
|
||||
$asset_ip = $row['interface_ip'];
|
||||
$asset_mac = $row['interface_mac'];
|
||||
$asset_purchase_date = $row['asset_purchase_date'];
|
||||
$asset_warranty_expire = $row['asset_warranty_expire'];
|
||||
$asset_install_date = $row['asset_install_date'];
|
||||
@@ -1105,8 +1106,8 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$asset_model = $row['asset_model'];
|
||||
$asset_serial = $row['asset_serial'];
|
||||
$asset_os = $row['asset_os'];
|
||||
$asset_ip = $row['asset_ip'];
|
||||
$asset_mac = $row['asset_mac'];
|
||||
$asset_ip = $row['interface_ip'];
|
||||
$asset_mac = $row['interface_mac'];
|
||||
$asset_purchase_date = $row['asset_purchase_date'];
|
||||
$asset_warranty_expire = $row['asset_warranty_expire'];
|
||||
$asset_install_date = $row['asset_install_date'];
|
||||
@@ -1198,8 +1199,8 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$asset_model = $row['asset_model'];
|
||||
$asset_serial = $row['asset_serial'];
|
||||
$asset_os = $row['asset_os'];
|
||||
$asset_ip = $row['asset_ip'];
|
||||
$asset_mac = $row['asset_mac'];
|
||||
$asset_ip = $row['interface_ip'];
|
||||
$asset_mac = $row['interface_mac'];
|
||||
$asset_purchase_date = $row['asset_purchase_date'];
|
||||
$asset_warranty_expire = $row['asset_warranty_expire'];
|
||||
$asset_install_date = $row['asset_install_date'];
|
||||
@@ -1312,8 +1313,8 @@ if (isset($_POST['export_client_pdf'])) {
|
||||
$asset_model = $row['asset_model'];
|
||||
$asset_serial = $row['asset_serial'];
|
||||
$asset_os = $row['asset_os'];
|
||||
$asset_ip = $row['asset_ip'];
|
||||
$asset_mac = $row['asset_mac'];
|
||||
$asset_ip = $row['interface_ip'];
|
||||
$asset_mac = $row['interface_mac'];
|
||||
$asset_purchase_date = $row['asset_purchase_date'];
|
||||
$asset_warranty_expire = $row['asset_warranty_expire'];
|
||||
$asset_install_date = $row['asset_install_date'];
|
||||
|
||||
Reference in New Issue
Block a user