Asset Interfaces: Renamed Port to Description, added Interface Type

This commit is contained in:
johnnyq 2025-02-12 17:13:39 -05:00
parent 8d8b0f4a48
commit fe762ef926
11 changed files with 152 additions and 89 deletions

View File

@ -20,7 +20,7 @@ if (!empty($name) && !empty($client_id)) {
$insert_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_port = 'eth0', interface_primary = 1, interface_network_id = $network, interface_asset_id = $insert_id");
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = '1', interface_mac = '$mac', interface_ip = '$ip', interface_primary = 1, interface_network_id = $network, interface_asset_id = $insert_id");
// Logging
logAction("Asset", "Create", "$name via API ($api_key_name)", $client_id, $insert_id);

View File

@ -99,17 +99,17 @@ if (isset($_GET['asset_id'])) {
SELECT
ai.interface_id,
ai.interface_name,
ai.interface_description,
ai.interface_type,
ai.interface_mac,
ai.interface_ip,
ai.interface_ipv6,
ai.interface_port,
ai.interface_primary,
ai.interface_notes,
n.network_name,
n.network_id,
connected_interfaces.interface_id AS connected_interface_id,
connected_interfaces.interface_name AS connected_interface_name,
connected_interfaces.interface_port AS connected_interface_port,
connected_assets.asset_name AS connected_asset_name
FROM asset_interfaces AS ai
LEFT JOIN networks AS n
@ -391,10 +391,10 @@ if (isset($_GET['asset_id'])) {
<table class="table table-striped table-borderless table-hover table-sm">
<thead class="<?php if ($interface_count == 0) { echo "d-none"; } ?>">
<tr>
<th>Name</th>
<th>Name / Port</th>
<th>Type</th>
<th>MAC</th>
<th>IP</th>
<th>Port</th>
<th>Network</th>
<th>Connected To</th>
<th class="text-center">Action</th>
@ -405,10 +405,11 @@ if (isset($_GET['asset_id'])) {
<?php
$interface_id = intval($row['interface_id']);
$interface_name = nullable_htmlentities($row['interface_name']);
$interface_description = nullable_htmlentities($row['interface_description']);
$interface_type = nullable_htmlentities($row['interface_type']);
$interface_mac = nullable_htmlentities($row['interface_mac']);
$interface_ip = nullable_htmlentities($row['interface_ip']);
$interface_ipv6 = nullable_htmlentities($row['interface_ipv6']);
$interface_port = nullable_htmlentities($row['interface_port']);
$interface_primary = intval($row['interface_primary']);
$network_id = intval($row['network_id']);
$network_name = nullable_htmlentities($row['network_name']);
@ -417,18 +418,18 @@ if (isset($_GET['asset_id'])) {
// Prepare display text
$interface_mac_display = $interface_mac ?: '-';
$interface_ip_display = $interface_ip ?: '-';
$interface_port_display = $interface_port ?: '-';
$interface_type_display = $interface_type ?: '-';
$network_name_display = $network_name
? "<i class='fas fa-fw fa-network-wired mr-1'></i>$network_name $network_id"
: '-';
// Connected interface details
$connected_asset_name = nullable_htmlentities($row['connected_asset_name']);
$connected_interface_port = nullable_htmlentities($row['connected_interface_port']);
$connected_interface_name = nullable_htmlentities($row['connected_interface_name']);
// Show either "-" or "AssetName - Port"
if ($connected_asset_name) {
$connected_to_display = "<strong>$connected_asset_name</strong> - $connected_interface_port";
$connected_to_display = "<strong>$connected_asset_name</strong> - $connected_interface_name";
} else {
$connected_to_display = "-";
}
@ -440,9 +441,9 @@ if (isset($_GET['asset_id'])) {
<?php echo $interface_name; ?>
</a>
</td>
<td><?php echo $interface_type_display; ?></td>
<td><?php echo $interface_mac_display; ?></td>
<td><?php echo $interface_ip_display; ?></td>
<td><?php echo $interface_port_display; ?></td>
<td><?php echo $network_name_display; ?></td>
<td><?php echo $connected_to_display; ?></td>
<td>

View File

@ -2471,7 +2471,6 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
if (CURRENT_DATABASE_VERSION == '1.8.0') {
mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_order` int(11) NOT NULL DEFAULT 0");
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_order` int(11) NOT NULL DEFAULT 0");
@ -2482,11 +2481,19 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.1'");
}
if (CURRENT_DATABASE_VERSION == '1.8.1') {
mysqli_query($mysqli, "ALTER TABLE `asset_interfaces` CHANGE `interface_port` `interface_description` VARCHAR(200) DEFAULT NULL AFTER `interface_name`");
// if (CURRENT_DATABASE_VERSION == '1.8.1') {
// // Insert queries here required to update to DB version 1.8.2
mysqli_query($mysqli, "ALTER TABLE `asset_interfaces` ADD `interface_type` VARCHAR(50) DEFAULT NULL AFTER `interface_description`");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.2'");
}
// if (CURRENT_DATABASE_VERSION == '1.8.2') {
// // Insert queries here required to update to DB version 1.8.3
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.2'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.3'");
// }
} else {

11
db.sql
View File

@ -167,11 +167,12 @@ DROP TABLE IF EXISTS `asset_interfaces`;
CREATE TABLE `asset_interfaces` (
`interface_id` int(11) NOT NULL AUTO_INCREMENT,
`interface_name` varchar(200) NOT NULL,
`interface_description` varchar(200) DEFAULT NULL,
`interface_type` varchar(50) DEFAULT NULL,
`interface_mac` varchar(200) DEFAULT NULL,
`interface_ip` varchar(200) DEFAULT NULL,
`interface_nat_ip` varchar(200) DEFAULT NULL,
`interface_ipv6` varchar(200) DEFAULT NULL,
`interface_port` varchar(200) DEFAULT NULL,
`interface_notes` text DEFAULT NULL,
`interface_primary` tinyint(1) DEFAULT 0,
`interface_created_at` datetime NOT NULL DEFAULT current_timestamp(),
@ -1704,9 +1705,6 @@ CREATE TABLE `settings` (
`config_ticket_autoclose_hours` int(5) NOT NULL DEFAULT 72,
`config_ticket_new_ticket_notification_email` varchar(200) DEFAULT NULL,
`config_ticket_default_billable` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_default_view` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_moving_columns` tinyint(1) NOT NULL DEFAULT 1,
`config_ticket_ordering` tinyint(1) NOT NULL DEFAULT 0,
`config_enable_cron` tinyint(1) NOT NULL DEFAULT 0,
`config_recurring_auto_send_invoice` tinyint(1) NOT NULL DEFAULT 1,
`config_enable_alert_domain_expire` tinyint(1) NOT NULL DEFAULT 1,
@ -1743,6 +1741,9 @@ CREATE TABLE `settings` (
`config_phone_mask` tinyint(1) NOT NULL DEFAULT 1,
`config_whitelabel_enabled` int(11) NOT NULL DEFAULT 0,
`config_whitelabel_key` text DEFAULT NULL,
`config_ticket_default_view` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_ordering` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_moving_columns` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@ -2347,4 +2348,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2025-01-25 21:47:06
-- Dump completed on 2025-02-12 17:12:46

View File

@ -309,3 +309,9 @@ $note_types_array = array (
'In Person'=>'fa-people-arrows',
'Note'=>'fa-sticky-note'
);
$interface_types_array = array (
'Ethernet',
'SFP',
'WiFi'
);

View File

@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/
DEFINE("LATEST_DATABASE_VERSION", "1.8.1");
DEFINE("LATEST_DATABASE_VERSION", "1.8.2");

View File

@ -16,12 +16,45 @@
<!-- Interface Name -->
<div class="form-group">
<label>Interface Name</label>
<label>Interface Name / Port</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
</div>
<input type="text" class="form-control" name="name" placeholder="Interface Name" maxlength="200" required>
<input type="text" class="form-control" name="name" placeholder="Interface name or port number" maxlength="200" required>
</div>
</div>
<!-- Type -->
<div class="form-group">
<label for="network">Type</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
</div>
<select class="form-control select2" name="type">
<option value="">- Select Type -</option>
<?php foreach($interface_types_array as $interface_type) { ?>
<option><?php echo $interface_type; ?></option>
<?php } ?>
</select>
</div>
</div>
<!-- Interface Description -->
<div class="form-group">
<label>Description</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
</div>
<input
type="text"
class="form-control"
name="description"
placeholder="Short Description"
maxlength="200"
>
</div>
</div>
@ -63,17 +96,6 @@
</div>
</div>
<!-- Port -->
<div class="form-group">
<label>Port</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
</div>
<input type="text" class="form-control" name="port" placeholder="Interface Port ex. eth0" maxlength="200">
</div>
</div>
<!-- Network -->
<div class="form-group">
<label>Network</label>
@ -108,7 +130,7 @@
<option value="">- None -</option>
<?php
$sql_interfaces_select = mysqli_query($mysqli, "
SELECT i.interface_id, i.interface_port, a.asset_name
SELECT i.interface_id, i.interface_name, a.asset_name
FROM asset_interfaces i
LEFT JOIN assets a ON a.asset_id = i.interface_asset_id
WHERE a.asset_archived_at IS NULL
@ -116,16 +138,16 @@
AND a.asset_id != $asset_id
AND i.interface_id NOT IN (SELECT interface_a_id FROM asset_interface_links)
AND i.interface_id NOT IN (SELECT interface_b_id FROM asset_interface_links)
ORDER BY a.asset_name ASC, i.interface_port ASC
ORDER BY a.asset_name ASC, i.interface_name ASC
");
while ($row = mysqli_fetch_array($sql_interfaces_select)) {
$interface_id_select = intval($row['interface_id']);
$interface_port_select = nullable_htmlentities($row['interface_port']);
$interface_name_select = nullable_htmlentities($row['interface_name']);
$asset_name_select = nullable_htmlentities($row['asset_name']);
?>
<option value="<?php echo $interface_id_select; ?>">
<?php echo "$asset_name_select - $interface_port_select"; ?>
<?php echo "$asset_name_select - $interface_name_select"; ?>
</option>
<?php } ?>
</select>

View File

@ -25,7 +25,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
<div class="modal-header">
<h5 class="modal-title">
<i class="fa fa-fw fa-ethernet mr-2"></i>
Editing: <?php echo htmlspecialchars($interface_name, ENT_QUOTES, 'UTF-8'); ?>
Editing: <?php echo $interface_name; ?>
</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
@ -40,7 +40,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
<!-- Interface Name -->
<div class="form-group">
<label>Interface Name</label>
<label>Interface Name / Port</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
@ -49,14 +49,50 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
type="text"
class="form-control"
name="name"
placeholder="Interface Name"
placeholder="Interface name or port number"
maxlength="200"
value="<?php echo nullable_htmlentities($interface_name); ?>"
value="<?php echo $interface_name; ?>"
required
>
</div>
</div>
<!-- Interface Description -->
<div class="form-group">
<label>Description</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
</div>
<input
type="text"
class="form-control"
name="description"
placeholder="Short Description"
maxlength="200"
value="<?php echo $interface_description; ?>"
>
</div>
</div>
<!-- Type -->
<div class="form-group">
<label for="network">Type</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
</div>
<select class="form-control select2" name="type">
<option value="">- Select Type -</option>
<?php foreach($interface_types_array as $interface_type_select) { ?>
<option <?php if($interface_type == $interface_type_select) { echo "selected"; } ?>>
<?php echo $interface_type_select; ?>
</option>
<?php } ?>
</select>
</div>
</div>
<!-- MAC Address -->
<div class="form-group">
<label>MAC Address</label>
@ -70,7 +106,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
name="mac"
placeholder="MAC Address"
maxlength="200"
value="<?php echo nullable_htmlentities($interface_mac); ?>"
value="<?php echo $interface_mac; ?>"
data-inputmask="'alias': 'mac'"
data-mask
>
@ -90,7 +126,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
name="ip"
placeholder="IP Address"
maxlength="200"
value="<?php echo nullable_htmlentities($interface_ip); ?>"
value="<?php echo $interface_ip; ?>"
data-inputmask="'alias': 'ip'"
data-mask
>
@ -121,25 +157,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
name="ipv6"
placeholder="IPv6 Address"
maxlength="200"
value="<?php echo nullable_htmlentities($interface_ipv6); ?>"
>
</div>
</div>
<!-- Port -->
<div class="form-group">
<label>Port</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
</div>
<input
type="text"
class="form-control"
name="port"
placeholder="Interface Port ex. eth0"
maxlength="200"
value="<?php echo nullable_htmlentities($interface_port); ?>"
value="<?php echo $interface_ipv6; ?>"
>
</div>
</div>
@ -152,7 +170,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
<span class="input-group-text"><i class="fa fa-fw fa-network-wired"></i></span>
</div>
<select class="form-control select2" name="network">
<option value="">- None -</option>
<option value="">- Select Network -</option>
<?php
$sql_network_select = mysqli_query($mysqli, "
SELECT network_id, network_name, network
@ -184,10 +202,10 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
</div>
<select class="form-control select2" name="connected_to">
<option value="">- None -</option>
<option value="">- Select Asset -</option>
<?php
$sql_interfaces_select = mysqli_query($mysqli, "
SELECT i.interface_id, i.interface_port, a.asset_name
SELECT i.interface_id, i.interface_name, a.asset_name
FROM asset_interfaces i
LEFT JOIN assets a ON a.asset_id = i.interface_asset_id
WHERE a.asset_archived_at IS NULL
@ -201,16 +219,16 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
)
OR i.interface_id = " . (int)$linked_interface_id . "
)
ORDER BY a.asset_name ASC, i.interface_port ASC
ORDER BY a.asset_name ASC, i.interface_name ASC
");
while ($row_if = mysqli_fetch_array($sql_interfaces_select)) {
$iface_id_select = intval($row_if['interface_id']);
$iface_port_select = nullable_htmlentities($row_if['interface_port']);
$iface_name_select = nullable_htmlentities($row_if['interface_name']);
$iface_asset_name_select = nullable_htmlentities($row_if['asset_name']);
$selected = ($linked_interface_id === $iface_id_select) ? 'selected' : '';
echo "<option value='$iface_id_select' $selected>";
echo "$iface_asset_name_select - $iface_port_select";
echo "$iface_asset_name_select - $iface_name_select";
echo "</option>";
}
?>

View File

@ -27,7 +27,7 @@
<!-- Number of Interfaces -->
<div class="form-group">
<label for="interfaces">Number of Interfaces</label>
<label for="interfaces">Number of Interfaces / Ports</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
@ -36,9 +36,25 @@
</div>
</div>
<!-- Type -->
<div class="form-group">
<label for="network">Type</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
</div>
<select class="form-control select2" name="type">
<option value="">- Select Type -</option>
<?php foreach($interface_types_array as $interface_type) { ?>
<option><?php echo $interface_type; ?></option>
<?php } ?>
</select>
</div>
</div>
<!-- Interface Name -->
<div class="form-group">
<label for="name_prefix">Interface Name Prefix (Optional)</label>
<label for="name_prefix">Interface Name / Port Prefix (Optional)</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
@ -47,17 +63,6 @@
</div>
</div>
<!-- Port Prefix -->
<div class="form-group">
<label for="port_prefix">Port Prefix (Optional)</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
</div>
<input type="text" id="port_prefix" class="form-control" name="port_prefix" placeholder="e.g., fe" maxlength="200">
</div>
</div>
<!-- Network -->
<div class="form-group">
<label for="network">Network Assignment</label>

View File

@ -39,7 +39,7 @@ if (isset($_POST['add_asset'])) {
}
// Add Primary Interface
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_port = '1', 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 = '1', interface_mac = '$mac', interface_ip = '$ip', interface_nat_ip = '$nat_ip', interface_ipv6 = '$ipv6', interface_port = '1', 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");
@ -732,10 +732,11 @@ 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_ipv6 = '$ipv6',
interface_port = '$port',
interface_notes = '$notes',
interface_network_id = $network,
interface_asset_id = $asset_id
@ -777,8 +778,8 @@ if (isset($_POST['add_asset_multiple_interfaces'])) {
$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']);
$port_prefix = sanitizeInput($_POST['port_prefix']);
$network = intval($_POST['network']);
$notes = sanitizeInput($_POST['notes']);
@ -795,7 +796,7 @@ if (isset($_POST['add_asset_multiple_interfaces'])) {
$sql_insert = "
INSERT INTO asset_interfaces SET
interface_name = '$name_prefix$formatted_interface_number',
interface_port = '$port_prefix$formatted_interface_number',
interface_type = '$type',
interface_notes = '$notes',
interface_network_id = $network,
interface_asset_id = $asset_id
@ -837,10 +838,11 @@ 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_ipv6 = '$ipv6',
interface_notes = '$notes',
interface_network_id = $network
WHERE interface_id = $interface_id

View File

@ -2,13 +2,14 @@
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
$name = sanitizeInput($_POST['name']);
$description = sanitizeInput($_POST['description']);
$type = sanitizeInput($_POST['type']);
$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']);
$connected_to = intval($_POST['connected_to']);