Added the Ability Set which interface is primary under add / edit interface section

This commit is contained in:
johnnyq 2025-02-13 16:26:21 -05:00
parent c81b430318
commit 2e9e49a203
5 changed files with 64 additions and 6 deletions

View File

@ -438,7 +438,7 @@ if (isset($_GET['asset_id'])) {
<td>
<i class="fa fa-fw fa-ethernet text-secondary mr-1"></i>
<a class="text-dark" href="#" data-toggle="modal" data-target="#editAssetInterfaceModal<?php echo $interface_id; ?>">
<?php echo $interface_name; ?>
<?php echo $interface_name; ?> <?php if($interface_primary) { echo "<small class='text-primary'>(Primary)</small>"; } ?>
</a>
</td>
<td><?php echo $interface_type_display; ?></td>

View File

@ -16,12 +16,17 @@
<!-- Interface Name -->
<div class="form-group">
<label>Interface Name / Port</label>
<label>Interface Name or Port / <span class="text-secondary">Primary</span></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 or port number" maxlength="200" required>
<div class="input-group-append">
<div class="input-group-text">
<input type="checkbox" name="primary_interface" value="1" title="Mark Interface as primary">
</div>
</div>
</div>
</div>
@ -85,6 +90,23 @@
</div>
</div>
<!-- NAT IP -->
<div class="form-group">
<label>NAT IP</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="nat_ip"
placeholder="Nat IP"
maxlength="200"
>
</div>
</div>
<!-- IPv6 -->
<div class="form-group">
<label>IPv6</label>
@ -104,7 +126,7 @@
<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 * FROM networks WHERE network_archived_at IS NULL AND network_client_id = $client_id ORDER BY network_name ASC");
while ($row = mysqli_fetch_array($sql_network_select)) {
@ -127,7 +149,7 @@
<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="">- NSelect Asset and Interface -</option>
<?php
$sql_interfaces_select = mysqli_query($mysqli, "
SELECT i.interface_id, i.interface_name, a.asset_name

View File

@ -40,7 +40,7 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
<!-- Interface Name -->
<div class="form-group">
<label>Interface Name / Port</label>
<label>Interface Name or Port / <span class="text-secondary">Primary</span></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
@ -54,6 +54,11 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
value="<?php echo $interface_name; ?>"
required
>
<div class="input-group-append">
<div class="input-group-text">
<input type="checkbox" name="primary_interface" value="1" <?php if($interface_primary) { echo "checked"; } ?> title="Mark Interface as primary">
</div>
</div>
</div>
</div>
@ -144,6 +149,24 @@ if ($link_row = mysqli_fetch_assoc($sql_link)) {
</div>
</div>
<!-- NAT IP -->
<div class="form-group">
<label>NAT IP</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="nat_ip"
placeholder="Nat IP"
maxlength="200"
value="<?php echo $interface_nat_ip; ?>"
>
</div>
</div>
<!-- IPv6 -->
<div class="form-group">
<label>IPv6</label>
@ -202,7 +225,7 @@ 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="">- Select Asset -</option>
<option value="">- Select Asset and Interface -</option>
<?php
$sql_interfaces_select = mysqli_query($mysqli, "
SELECT i.interface_id, i.interface_name, a.asset_name

View File

@ -745,6 +745,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 = "
@ -849,6 +855,12 @@ if (isset($_POST['edit_asset_interface'])) {
";
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

View File

@ -2,6 +2,7 @@
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
$name = sanitizeInput($_POST['name']);
$primary_interface = sanitizeInput($_POST['primary_interface']) ?? 0;
$description = sanitizeInput($_POST['description']);
$type = sanitizeInput($_POST['type']);
$mac = sanitizeInput($_POST['mac']);