Feature: Added network IPs section to document network IP and their hostnames

This commit is contained in:
johnnyq
2026-08-25 12:19:02 -04:00
parent ffda605195
commit 1381add82b
13 changed files with 1163 additions and 5 deletions

View File

@@ -0,0 +1,65 @@
<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$network_id = intval($_GET['network_id'] ?? 0);
$sql = mysqli_query($mysqli, "SELECT network, network_client_id, network_name FROM networks WHERE network_id = $network_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$network_name = escapeHtml($row['network_name']);
$network = escapeHtml($row['network']);
$client_id = intval($row['network_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-map-pin me-2"></i>New IP Address</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="network_id" value="<?= $network_id ?>">
<div class="modal-body">
<div class="mb-3">
<label>IP Address <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-map-pin"></i></span>
<input type="text" class="form-control font-monospace" name="ip_address" placeholder="Must be inside <?= $network ?>" maxlength="45" required autofocus>
</div>
<small class="text-secondary"><?= $network_name ?> &mdash; <span class="font-monospace"><?= $network ?></span></small>
</div>
<div class="mb-3">
<label>Hostname</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
<input type="text" class="form-control" name="hostname" placeholder="dc01, printer-hr, ap-lobby" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
<input type="text" class="form-control" name="description" placeholder="Domain controller, HR floor printer" maxlength="200">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="add_network_ip" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,70 @@
<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$ip_id = intval($_GET['id']);
$sql = mysqli_query($mysqli, "SELECT ip_address, ip_description, ip_hostname, ip_network_id, network, network_client_id, network_name FROM network_ips
LEFT JOIN networks ON network_id = ip_network_id
WHERE ip_id = $ip_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$ip_address = escapeHtml($row['ip_address']);
$ip_hostname = escapeHtml($row['ip_hostname']);
$ip_description = escapeHtml($row['ip_description']);
$network_name = escapeHtml($row['network_name']);
$network = escapeHtml($row['network']);
$client_id = intval($row['network_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-map-pin me-2"></i>Editing <span class="font-monospace"><?= $ip_address ?></span></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ip_id" value="<?= $ip_id ?>">
<div class="modal-body">
<div class="mb-3">
<label>IP Address <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-map-pin"></i></span>
<input type="text" class="form-control font-monospace" name="ip_address" value="<?= $ip_address ?>" maxlength="45" required>
</div>
<small class="text-secondary"><?= $network_name ?> &mdash; <span class="font-monospace"><?= $network ?></span></small>
</div>
<div class="mb-3">
<label>Hostname</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
<input type="text" class="form-control" name="hostname" value="<?= $ip_hostname ?>" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
<input type="text" class="form-control" name="description" value="<?= $ip_description ?>" maxlength="200">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="edit_network_ip" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,38 @@
<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support');
// Scoped to one network, so there are no page filters to inherit - column
// selection only, same as the asset interfaces export
$network_id = intval($_GET['network_id'] ?? 0);
$client_id = intval(getFieldById('networks', $network_id, 'network_client_id'));
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-download me-2"></i>Export IP Addresses</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="network_id" value="<?= $network_id ?>">
<div class="modal-body">
<?php renderExportColumnPicker('network_ips'); ?>
</div>
<div class="modal-footer">
<?php renderExportButtons('export_network_ips'); ?>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,47 @@
<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$network_id = intval($_GET['network_id'] ?? 0);
$sql = mysqli_query($mysqli, "SELECT network, network_client_id, network_name FROM networks WHERE network_id = $network_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$network_name = escapeHtml($row['network_name']);
$network = escapeHtml($row['network']);
$client_id = intval($row['network_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-upload me-2"></i>Import IP Addresses</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="network_id" value="<?= $network_id ?>">
<div class="modal-body">
<p><strong>Format csv file with headings &amp; data:</strong><br>IP Address, Hostname, Description</p>
<p class="text-secondary mb-0">Importing into <strong><?= $network_name ?></strong> (<span class="font-monospace"><?= $network ?></span>). Rows that aren't a valid address, fall outside the subnet, or are already documented here are skipped.</p>
<hr>
<div class="mb-3 my-4">
<input type="file" class="form-control" name="file" accept=".csv" required>
</div>
<hr>
<div>Download: <a class="text-bold" href="post.php?download_network_ips_csv_template=<?= $network_id ?>">sample csv template</a></div>
</div>
<div class="modal-footer">
<button type="submit" name="import_network_ips_csv" class="btn btn-primary text-bold"><i class="fa fa-upload me-2"></i>Import</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';