API: Add some missing end points

This commit is contained in:
johnnyq
2026-04-11 18:21:03 -04:00
parent 1e02322382
commit c4ba2bc326
45 changed files with 1570 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
$network_row = false; // Creation, not an update
require_once 'network_model.php';
// Default
$insert_id = false;
if (!empty($name)) {
$insert_sql = mysqli_query($mysqli, "INSERT INTO networks SET network_name = '$name', network_description = '$description', network_address = '$address', network_dns = '$dns', network_gateway = '$gateway', network_vlan = '$vlan', network_notes = '$notes', network_location_id = $location_id, network_client_id = $client_id");
if ($insert_sql) {
$insert_id = mysqli_insert_id($mysqli);
// Logging
logAction("Network", "Create", "Created network $name via API ($api_key_name)", $client_id, $insert_id);
logAction("API", "Success", "Created network $name via API ($api_key_name)", $client_id);
}
}
// Output
require_once '../create_output.php';

View File

@@ -0,0 +1,28 @@
<?php
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
// Parse ID
$network_id = intval($_POST['network_id']);
// Default
$delete_count = false;
if (!empty($network_id)) {
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM networks WHERE network_id = $network_id AND network_client_id = $client_id LIMIT 1"));
$network_name = $row['network_name'];
$delete_sql = mysqli_query($mysqli, "DELETE FROM networks WHERE network_id = $network_id AND network_client_id = $client_id LIMIT 1");
if ($delete_sql && !empty($network_name)) {
$delete_count = mysqli_affected_rows($mysqli);
// Logging
logAction("Network", "Delete", "$network_name via API ($api_key_name)", $client_id);
}
}
// Output
require_once '../delete_output.php';

View File

@@ -0,0 +1,67 @@
<?php
// Variable assignment from POST (or: blank/from DB is updating)
if (isset($_POST['network_name'])) {
$name = sanitizeInput($_POST['network_name']);
} elseif ($network_row) {
$name = mysqli_real_escape_string($mysqli, $network_row['network_name']);
} else {
$name = '';
}
if (isset($_POST['network_description'])) {
$description = sanitizeInput($_POST['network_description']);
} elseif ($network_row) {
$description = mysqli_real_escape_string($mysqli, $network_row['network_description']);
} else {
$description = '';
}
if (isset($_POST['network_address'])) {
$address = sanitizeInput($_POST['network_address']);
} elseif ($network_row) {
$address = mysqli_real_escape_string($mysqli, $network_row['network_address']);
} else {
$address = '';
}
if (isset($_POST['network_dns'])) {
$dns = sanitizeInput($_POST['network_dns']);
} elseif ($network_row) {
$dns = mysqli_real_escape_string($mysqli, $network_row['network_dns']);
} else {
$dns = '';
}
if (isset($_POST['network_gateway'])) {
$gateway = sanitizeInput($_POST['network_gateway']);
} elseif ($network_row) {
$gateway = mysqli_real_escape_string($mysqli, $network_row['network_gateway']);
} else {
$gateway = '';
}
if (isset($_POST['network_vlan'])) {
$vlan = sanitizeInput($_POST['network_vlan']);
} elseif ($network_row) {
$vlan = mysqli_real_escape_string($mysqli, $network_row['network_vlan']);
} else {
$vlan = '';
}
if (isset($_POST['network_notes'])) {
$notes = sanitizeInput($_POST['network_notes']);
} elseif ($network_row) {
$notes = mysqli_real_escape_string($mysqli, $network_row['network_notes']);
} else {
$notes = '';
}
if (isset($_POST['network_location_id'])) {
$location_id = intval($_POST['network_location_id']);
} elseif ($network_row) {
$location_id = $network_row['network_location_id'];
} else {
$location_id = 0;
}

View File

@@ -0,0 +1,31 @@
<?php
require_once '../validate_api_key.php';
require_once '../require_post_method.php';
// Parse ID
$network_id = intval($_POST['network_id']);
// Default
$update_count = false;
if (!empty($network_id)) {
$network_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM networks WHERE network_id = '$network_id' AND network_client_id = $client_id LIMIT 1"));
require_once 'network_model.php';
$update_sql = mysqli_query($mysqli, "UPDATE networks SET network_name = '$name', network_description = '$description', network_address = '$address', network_dns = '$dns', network_gateway = '$gateway', network_vlan = '$vlan', network_notes = '$notes', network_location_id = $location_id WHERE network_id = $network_id AND network_client_id = $client_id LIMIT 1");
if ($update_sql) {
$update_count = mysqli_affected_rows($mysqli);
// Logging
logAction("Network", "Edit", "$name via API ($api_key_name)", $client_id);
logAction("API", "Success", "Edited network $name via API ($api_key_name)", $client_id);
}
}
// Output
require_once '../update_output.php';