|
|
|
|
@@ -39,7 +39,7 @@ if (isset($_POST['add_asset'])) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '1', interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_primary = 1, interface_network_id = $network, interface_asset_id = $asset_id");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($_POST['username'])) {
|
|
|
|
|
@@ -89,7 +89,7 @@ if (isset($_POST['edit_asset'])) {
|
|
|
|
|
|
|
|
|
|
if(mysqli_num_rows($sql_interfaces) == 0 ) {
|
|
|
|
|
// 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");
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '1', interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_primary = 1, interface_network_id = $network, interface_asset_id = $asset_id");
|
|
|
|
|
} else {
|
|
|
|
|
// 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 WHERE interface_asset_id = $asset_id AND interface_primary = 1");
|
|
|
|
|
@@ -120,61 +120,6 @@ if (isset($_POST['edit_asset'])) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['change_client_asset'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
|
|
|
|
|
validateCSRFToken($_POST['csrf_token']);
|
|
|
|
|
|
|
|
|
|
$current_asset_id = intval($_POST['current_asset_id']);
|
|
|
|
|
$new_client_id = intval($_POST['new_client_id']);
|
|
|
|
|
|
|
|
|
|
// Get Asset details and current client ID/Name for logging
|
|
|
|
|
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name FROM assets LEFT JOIN clients ON client_id = asset_client_id WHERE asset_id = $current_asset_id"));
|
|
|
|
|
$asset_name = sanitizeInput($row['asset_name']);
|
|
|
|
|
$asset_notes = sanitizeInput($row['asset_notes']);
|
|
|
|
|
$current_client_id = intval($row['asset_client_id']);
|
|
|
|
|
$current_client_name = sanitizeInput($row['client_name']);
|
|
|
|
|
|
|
|
|
|
// Get new client name for logging
|
|
|
|
|
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id"));
|
|
|
|
|
$new_client_name = sanitizeInput($row['client_name']);
|
|
|
|
|
|
|
|
|
|
// Create new asset
|
|
|
|
|
mysqli_query($mysqli, "
|
|
|
|
|
INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important)
|
|
|
|
|
SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important
|
|
|
|
|
FROM assets
|
|
|
|
|
WHERE asset_id = $current_asset_id
|
|
|
|
|
");
|
|
|
|
|
$new_asset_id = mysqli_insert_id($mysqli);
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id");
|
|
|
|
|
|
|
|
|
|
// Archive/log the current asset
|
|
|
|
|
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
|
|
|
|
mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id");
|
|
|
|
|
|
|
|
|
|
// Log Archive
|
|
|
|
|
logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id);
|
|
|
|
|
|
|
|
|
|
// Log Transfer
|
|
|
|
|
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id);
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id");
|
|
|
|
|
|
|
|
|
|
// Log the new asset
|
|
|
|
|
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
|
|
|
|
logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id);
|
|
|
|
|
|
|
|
|
|
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id);
|
|
|
|
|
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id");
|
|
|
|
|
|
|
|
|
|
$_SESSION['alert_message'] = "Asset <strong>$name</strong> transferred";
|
|
|
|
|
|
|
|
|
|
header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['archive_asset'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
@@ -303,6 +248,92 @@ if (isset($_POST['bulk_assign_asset_location'])) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['bulk_transfer_client_asset'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
|
|
|
|
|
validateCSRFToken($_POST['csrf_token']);
|
|
|
|
|
|
|
|
|
|
$new_client_id = intval($_POST['bulk_client_id']);
|
|
|
|
|
|
|
|
|
|
// Transfer selected asset to new client
|
|
|
|
|
if (isset($_POST['asset_ids'])) {
|
|
|
|
|
|
|
|
|
|
// Get Count
|
|
|
|
|
$asset_count = count($_POST['asset_ids']);
|
|
|
|
|
|
|
|
|
|
foreach($_POST['asset_ids'] as $current_asset_id) {
|
|
|
|
|
$current_asset_id = intval($current_asset_id);
|
|
|
|
|
|
|
|
|
|
// Get Asset details and current client ID/Name for logging
|
|
|
|
|
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name
|
|
|
|
|
FROM assets
|
|
|
|
|
LEFT JOIN clients ON client_id = asset_client_id
|
|
|
|
|
WHERE asset_id = $current_asset_id")
|
|
|
|
|
);
|
|
|
|
|
$asset_name = sanitizeInput($row['asset_name']);
|
|
|
|
|
$asset_notes = sanitizeInput($row['asset_notes']);
|
|
|
|
|
$current_client_id = intval($row['asset_client_id']);
|
|
|
|
|
$current_client_name = sanitizeInput($row['client_name']);
|
|
|
|
|
|
|
|
|
|
// Get new client name for logging
|
|
|
|
|
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id"));
|
|
|
|
|
$new_client_name = sanitizeInput($row['client_name']);
|
|
|
|
|
|
|
|
|
|
// Create new asset
|
|
|
|
|
mysqli_query($mysqli, "
|
|
|
|
|
INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important)
|
|
|
|
|
SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important
|
|
|
|
|
FROM assets
|
|
|
|
|
WHERE asset_id = $current_asset_id
|
|
|
|
|
");
|
|
|
|
|
$new_asset_id = mysqli_insert_id($mysqli);
|
|
|
|
|
|
|
|
|
|
// Transfer all Interfaces over too
|
|
|
|
|
$sql_interfaces = mysqli_query($mysqli, "SELECT * FROM asset_interfaces WHERE interface_asset_id = $current_asset_id");
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_array($sql_interfaces)) {
|
|
|
|
|
$interface_name = sanitizeInput($row['interface_name']);
|
|
|
|
|
$interface_mac = sanitizeInput($row['interface_mac']);
|
|
|
|
|
$interface_port = sanitizeInput($row['interface_port']);
|
|
|
|
|
$interface_primary = intval($row['interface_primary']);
|
|
|
|
|
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '$interface_name', interface_mac = '$interface_mac', interface_port = '$interface_port', interface_primary = $interface_primary, interface_asset_id = $new_asset_id");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id");
|
|
|
|
|
|
|
|
|
|
// Archive/log the current asset
|
|
|
|
|
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
|
|
|
|
mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id");
|
|
|
|
|
|
|
|
|
|
// Log Archive
|
|
|
|
|
logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id);
|
|
|
|
|
|
|
|
|
|
// Log Transfer
|
|
|
|
|
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id);
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id");
|
|
|
|
|
|
|
|
|
|
// Log the new asset
|
|
|
|
|
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
|
|
|
|
logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id);
|
|
|
|
|
|
|
|
|
|
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id);
|
|
|
|
|
|
|
|
|
|
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id");
|
|
|
|
|
|
|
|
|
|
} // End Transfer to Client Loop
|
|
|
|
|
|
|
|
|
|
// Bulk Logging
|
|
|
|
|
logAction("Asset", "Bulk Transfer", "$session_name transferred $asset_count assets to $new_client_name", $new_client_id);
|
|
|
|
|
|
|
|
|
|
$_SESSION['alert_message'] = "Transferred <strong>$asset_count</strong> assets to <strong>$new_client_name</strong>.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['bulk_assign_asset_contact'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
@@ -569,7 +600,7 @@ if (isset($_POST["import_client_assets_csv"])) {
|
|
|
|
|
$asset_id = mysqli_insert_id($mysqli);
|
|
|
|
|
|
|
|
|
|
// Add Primary Interface
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_port = 'eth0', interface_primary = 1, interface_asset_id = $asset_id");
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '1', interface_primary = 1, interface_asset_id = $asset_id");
|
|
|
|
|
|
|
|
|
|
$row_count = $row_count + 1;
|
|
|
|
|
} else {
|
|
|
|
|
@@ -701,10 +732,12 @@ if (isset($_POST['add_asset_interface'])) {
|
|
|
|
|
$sql_insert = "
|
|
|
|
|
INSERT INTO asset_interfaces SET
|
|
|
|
|
interface_name = '$name',
|
|
|
|
|
interface_description= '$description',
|
|
|
|
|
interface_type = '$type',
|
|
|
|
|
interface_mac = '$mac',
|
|
|
|
|
interface_ip = '$ip',
|
|
|
|
|
interface_nat_ip = '$nat_ip',
|
|
|
|
|
interface_ipv6 = '$ipv6',
|
|
|
|
|
interface_port = '$port',
|
|
|
|
|
interface_notes = '$notes',
|
|
|
|
|
interface_network_id = $network,
|
|
|
|
|
interface_asset_id = $asset_id
|
|
|
|
|
@@ -713,6 +746,12 @@ if (isset($_POST['add_asset_interface'])) {
|
|
|
|
|
|
|
|
|
|
$new_interface_id = mysqli_insert_id($mysqli);
|
|
|
|
|
|
|
|
|
|
// If Primary Interface Checked set all interfaces primary to 0 then set the new interface as primary with a 1
|
|
|
|
|
if ($primary_interface) {
|
|
|
|
|
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 0 WHERE interface_asset_id = $asset_id");
|
|
|
|
|
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 1 WHERE interface_id = $new_interface_id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5) If user selected a connected interface, insert row in asset_interface_links
|
|
|
|
|
if (!empty($connected_to) && intval($connected_to) > 0) {
|
|
|
|
|
$sql_link = "
|
|
|
|
|
@@ -738,6 +777,48 @@ if (isset($_POST['add_asset_interface'])) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['add_asset_multiple_interfaces'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
validateCSRFToken($_POST['csrf_token']);
|
|
|
|
|
|
|
|
|
|
$asset_id = intval($_POST['asset_id']);
|
|
|
|
|
$interface_start = intval($_POST['interface_start']);
|
|
|
|
|
$interfaces = intval($_POST['interfaces']);
|
|
|
|
|
$type = sanitizeInput($_POST['type']);
|
|
|
|
|
$name_prefix = sanitizeInput($_POST['name_prefix']);
|
|
|
|
|
$network = intval($_POST['network']);
|
|
|
|
|
$notes = sanitizeInput($_POST['notes']);
|
|
|
|
|
|
|
|
|
|
$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']);
|
|
|
|
|
|
|
|
|
|
for ($interface_number = $interface_start; $interface_number < $interface_start + $interfaces; $interface_number++) {
|
|
|
|
|
|
|
|
|
|
// Format $interface_number as a 2-digit number
|
|
|
|
|
$formatted_interface_number = str_pad($interface_number, 2, '0', STR_PAD_LEFT);
|
|
|
|
|
|
|
|
|
|
$sql_insert = "
|
|
|
|
|
INSERT INTO asset_interfaces SET
|
|
|
|
|
interface_name = '$name_prefix$formatted_interface_number',
|
|
|
|
|
interface_type = '$type',
|
|
|
|
|
interface_notes = '$notes',
|
|
|
|
|
interface_network_id = $network,
|
|
|
|
|
interface_asset_id = $asset_id
|
|
|
|
|
";
|
|
|
|
|
mysqli_query($mysqli, $sql_insert);
|
|
|
|
|
|
|
|
|
|
logAction("Asset Interface", "Create", "$session_name created interface $name for asset $asset_name", $client_id, $asset_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logAction("Asset Interface", "Bulk Create", "$session_name created $interfaces for asset $asset_name", $client_id, $asset_id);
|
|
|
|
|
$_SESSION['alert_message'] = "Created <strong>$interfaces</strong> Interface(s) for asset <strong>$asset_name</strong>";
|
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['edit_asset_interface'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
@@ -764,16 +845,24 @@ if (isset($_POST['edit_asset_interface'])) {
|
|
|
|
|
$sql_update = "
|
|
|
|
|
UPDATE asset_interfaces SET
|
|
|
|
|
interface_name = '$name',
|
|
|
|
|
interface_description= '$description',
|
|
|
|
|
interface_type = '$type',
|
|
|
|
|
interface_mac = '$mac',
|
|
|
|
|
interface_ip = '$ip',
|
|
|
|
|
interface_ipv6 = '$ipv6',
|
|
|
|
|
interface_port = '$port',
|
|
|
|
|
interface_nat_ip = '$nat_ip',
|
|
|
|
|
interface_ipv6 = '$ipv6',
|
|
|
|
|
interface_notes = '$notes',
|
|
|
|
|
interface_network_id = $network
|
|
|
|
|
WHERE interface_id = $interface_id
|
|
|
|
|
";
|
|
|
|
|
mysqli_query($mysqli, $sql_update);
|
|
|
|
|
|
|
|
|
|
// If Primary Interface Checked set all interfaces primary to 0 then set the new interface as primary with a 1
|
|
|
|
|
if ($primary_interface) {
|
|
|
|
|
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 0 WHERE interface_asset_id = $asset_id");
|
|
|
|
|
mysqli_query($mysqli,"UPDATE asset_interfaces SET interface_primary = 1 WHERE interface_id = $interface_id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3) Remove any existing link for this interface (one-to-one)
|
|
|
|
|
$sql_delete_link = "
|
|
|
|
|
DELETE FROM asset_interface_links
|
|
|
|
|
@@ -849,3 +938,205 @@ if (isset($_GET['delete_asset_interface'])) {
|
|
|
|
|
header("Location: " . $_SERVER['HTTP_REFERER']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST["import_client_asset_interfaces_csv"])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
|
|
|
|
|
|
validateCSRFToken($_POST['csrf_token']);
|
|
|
|
|
|
|
|
|
|
$asset_id = intval($_POST['asset_id']);
|
|
|
|
|
$file_name = $_FILES["file"]["tmp_name"];
|
|
|
|
|
|
|
|
|
|
// Get Asset Details for logging
|
|
|
|
|
$sql_asset = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_id = $asset_id");
|
|
|
|
|
$row = mysqli_fetch_assoc($sql_asset);
|
|
|
|
|
$client_id = intval($row['asset_client_id']);
|
|
|
|
|
$asset_name = sanitizeInput($row['asset_name']);
|
|
|
|
|
|
|
|
|
|
$error = false;
|
|
|
|
|
|
|
|
|
|
if (!empty($_FILES["file"]["tmp_name"])) {
|
|
|
|
|
$file_name = $_FILES["file"]["tmp_name"];
|
|
|
|
|
} else {
|
|
|
|
|
$_SESSION['alert_message'] = "Please select a file to upload.";
|
|
|
|
|
$_SESSION['alert_type'] = "error";
|
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check file is CSV
|
|
|
|
|
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
|
|
|
|
|
$allowed_file_extensions = array('csv');
|
|
|
|
|
if (in_array($file_extension,$allowed_file_extensions) === false) {
|
|
|
|
|
$error = true;
|
|
|
|
|
$_SESSION['alert_message'] = "Bad file extension";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check file isn't empty
|
|
|
|
|
elseif ($_FILES["file"]["size"] < 1) {
|
|
|
|
|
$error = true;
|
|
|
|
|
$_SESSION['alert_message'] = "Bad file size (empty?)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//(Else)Check column count (Name, Description, Type, MAC, IP, NAT IP, IPv6, Network)
|
|
|
|
|
$f = fopen($file_name, "r");
|
|
|
|
|
$f_columns = fgetcsv($f, 1000, ",");
|
|
|
|
|
if (!$error & count($f_columns) != 8) {
|
|
|
|
|
$error = true;
|
|
|
|
|
$_SESSION['alert_message'] = "Bad column count.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Else, parse the file
|
|
|
|
|
if (!$error) {
|
|
|
|
|
$file = fopen($file_name, "r");
|
|
|
|
|
fgetcsv($file, 1000, ","); // Skip first line
|
|
|
|
|
$row_count = 0;
|
|
|
|
|
$duplicate_count = 0;
|
|
|
|
|
while(($column = fgetcsv($file, 1000, ",")) !== false) {
|
|
|
|
|
|
|
|
|
|
// Default variables (if undefined)
|
|
|
|
|
$description = $type = $mac = $ip = $nat_ip = $ipv6 = $network = '';
|
|
|
|
|
|
|
|
|
|
$duplicate_detect = 0;
|
|
|
|
|
if (isset($column[0])) {
|
|
|
|
|
$name = sanitizeInput($column[0]);
|
|
|
|
|
if (mysqli_num_rows(mysqli_query($mysqli,"SELECT interface_name FROM asset_interfaces WHERE interface_asset_id = $asset_id AND interface_name = '$name'")) > 0) {
|
|
|
|
|
$duplicate_detect = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[1])) {
|
|
|
|
|
$description = sanitizeInput($column[1]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[2])) {
|
|
|
|
|
$type = sanitizeInput($column[2]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[3])) {
|
|
|
|
|
$mac = sanitizeInput($column[3]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[4])) {
|
|
|
|
|
$ip = sanitizeInput($column[4]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[5])) {
|
|
|
|
|
$nat_ip = sanitizeInput($column[5]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[6])) {
|
|
|
|
|
$ipv6 = sanitizeInput($column[6]);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($column[7])) {
|
|
|
|
|
$network = sanitizeInput($column[7]);
|
|
|
|
|
if ($network) {
|
|
|
|
|
$sql_network = mysqli_query($mysqli,"SELECT * FROM networks WHERE network_name = '$network' AND network_archived_at IS NULL AND network_client_id = $client_id");
|
|
|
|
|
$row = mysqli_fetch_assoc($sql_network);
|
|
|
|
|
$network_id = intval($row['network_id']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if duplicate was detected
|
|
|
|
|
if ($duplicate_detect == 0) {
|
|
|
|
|
//Add
|
|
|
|
|
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '$name', interface_description = '$description', interface_type = '$type', interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_network_id = $network_id, interface_asset_id = $asset_id");
|
|
|
|
|
|
|
|
|
|
$row_count = $row_count + 1;
|
|
|
|
|
} else {
|
|
|
|
|
$duplicate_count = $duplicate_count + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose($file);
|
|
|
|
|
|
|
|
|
|
// Logging
|
|
|
|
|
logAction("Asset", "Import", "$session_name imported $row_count interfaces(s) to asset $asset_name via CSV file", $client_id);
|
|
|
|
|
|
|
|
|
|
$_SESSION['alert_message'] = "<strong>$row_count</strong> Interfaces(s) added to asset <strong>$asset_name</stong>, <strong>$duplicate_count</strong> duplicate(s) detected";
|
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
|
|
|
}
|
|
|
|
|
//Check for any errors, if there are notify user and redirect
|
|
|
|
|
if ($error) {
|
|
|
|
|
$_SESSION['alert_type'] = "warning";
|
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['download_client_asset_interfaces_csv_template'])) {
|
|
|
|
|
$asset_id = intval($_GET['download_client_asset_interfaces_csv_template']);
|
|
|
|
|
|
|
|
|
|
//get records from database
|
|
|
|
|
$sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id");
|
|
|
|
|
$row = mysqli_fetch_array($sql);
|
|
|
|
|
|
|
|
|
|
$asset_name = $row['asset_name'];
|
|
|
|
|
|
|
|
|
|
$delimiter = ",";
|
|
|
|
|
$filename = strtoAZaz09($asset_name) . "-Asset-Interfaces-Template.csv";
|
|
|
|
|
|
|
|
|
|
//create a file pointer
|
|
|
|
|
$f = fopen('php://memory', 'w');
|
|
|
|
|
|
|
|
|
|
//set column headers
|
|
|
|
|
$fields = array('Name', 'Description', 'Type', 'MAC', 'IP', 'NAT IP', 'IPv6', 'Network');
|
|
|
|
|
fputcsv($f, $fields, $delimiter);
|
|
|
|
|
|
|
|
|
|
//move back to beginning of file
|
|
|
|
|
fseek($f, 0);
|
|
|
|
|
|
|
|
|
|
//set headers to download file rather than displayed
|
|
|
|
|
header('Content-Type: text/csv');
|
|
|
|
|
header('Content-Disposition: attachment; filename="' . $filename . '";');
|
|
|
|
|
|
|
|
|
|
//output all remaining data on a file pointer
|
|
|
|
|
fpassthru($f);
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['export_client_asset_interfaces_csv'])) {
|
|
|
|
|
|
|
|
|
|
enforceUserPermission('module_support');
|
|
|
|
|
|
|
|
|
|
validateCSRFToken($_POST['csrf_token']);
|
|
|
|
|
|
|
|
|
|
$asset_id = intval($_POST['asset_id']);
|
|
|
|
|
|
|
|
|
|
//get records from database
|
|
|
|
|
$sql = mysqli_query($mysqli,"SELECT * FROM asset_interfaces LEFT JOIN assets ON asset_id = interface_asset_id LEFT JOIN networks ON interface_network_id = network_id LEFT JOIN clients ON asset_client_id = client_id WHERE asset_id = $asset_id AND interface_archived_at IS NULL ORDER BY interface_name ASC");
|
|
|
|
|
$row = mysqli_fetch_array($sql);
|
|
|
|
|
|
|
|
|
|
$asset_name = $row['asset_name'];
|
|
|
|
|
$client_id = $row['asset_client_id'];
|
|
|
|
|
|
|
|
|
|
$num_rows = mysqli_num_rows($sql);
|
|
|
|
|
|
|
|
|
|
if ($num_rows > 0) {
|
|
|
|
|
$delimiter = ",";
|
|
|
|
|
$filename = strtoAZaz09($asset_name) . "-Interfaces-" . date('Y-m-d') . ".csv";
|
|
|
|
|
|
|
|
|
|
//create a file pointer
|
|
|
|
|
$f = fopen('php://memory', 'w');
|
|
|
|
|
|
|
|
|
|
//set column headers
|
|
|
|
|
$fields = array('Name', 'Description', 'Type', 'MAC', 'IP', 'NAT IP', 'IPv6', 'Network');
|
|
|
|
|
fputcsv($f, $fields, $delimiter);
|
|
|
|
|
|
|
|
|
|
//output each row of the data, format line as csv and write to file pointer
|
|
|
|
|
while($row = mysqli_fetch_array($sql)) {
|
|
|
|
|
$lineData = array($row['interface_name'], $row['interface_description'], $row['interface_type'], $row['interface_mac'], $row['interface_ip'], $row['interface_nat_ip'], $row['interface_ipv6'], $row['network_name']);
|
|
|
|
|
fputcsv($f, $lineData, $delimiter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//move back to beginning of file
|
|
|
|
|
fseek($f, 0);
|
|
|
|
|
|
|
|
|
|
//set headers to download file rather than displayed
|
|
|
|
|
header('Content-Type: text/csv');
|
|
|
|
|
header('Content-Disposition: attachment; filename="' . $filename . '";');
|
|
|
|
|
|
|
|
|
|
//output all remaining data on a file pointer
|
|
|
|
|
fpassthru($f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Logging
|
|
|
|
|
logAction("Asset Interface", "Export", "$session_name exported $num_rows interfaces(s) to a CSV file", $client_id);
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
}
|