.
Deploy / deploy (push) Successful in 38s

This commit is contained in:
2026-05-07 21:26:48 +02:00
parent ffe1e26cc7
commit 2376ee98e7
3 changed files with 39 additions and 36 deletions
+26 -34
View File
@@ -366,42 +366,31 @@ function handleComments($method, $id, $db) {
function handleNodes($method, $id, $db) { function handleNodes($method, $id, $db) {
switch ($method) { switch ($method) {
case 'GET': case 'GET':
echo json_encode($db->query("SELECT * FROM network_nodes ORDER BY group_name, label")->fetchAll(PDO::FETCH_ASSOC)); echo json_encode($db->query("SELECT n.*, nn.notes FROM network_nodes n LEFT JOIN node_notes nn ON n.id = nn.node_id ORDER BY n.group_name, n.label")->fetchAll(PDO::FETCH_ASSOC));
break; break;
case 'POST': case 'POST':
$data = json_decode(file_get_contents('php://input'), true); $data = json_decode(file_get_contents('php://input'), true);
try { $stmt = $db->prepare("
$stmt = $db->prepare(" INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y)
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y, notes) VALUES (?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
"); $stmt->execute([
$stmt->execute([ $data['label'],
$data['label'], $data['ip_address'] ?? '',
$data['ip_address'] ?? '', $data['node_type'] ?? 'host',
$data['node_type'] ?? 'host', $data['status'] ?? 'unknown',
$data['status'] ?? 'unknown', $data['group_name'] ?? 'default',
$data['group_name'] ?? 'default', $data['pos_x'] ?? 0,
$data['pos_x'] ?? 0, $data['pos_y'] ?? 0
$data['pos_y'] ?? 0, ]);
$data['notes'] ?? '' $nodeId = $db->lastInsertId();
]); if (!empty($data['notes'])) {
} catch (Exception $e) { try {
// Fallback without notes column $db->prepare("INSERT INTO node_notes (node_id, notes) VALUES (?, ?) ON DUPLICATE KEY UPDATE notes = VALUES(notes)")
$stmt = $db->prepare(" ->execute([$nodeId, $data['notes']]);
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y) } catch (Exception $e) {}
VALUES (?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$data['label'],
$data['ip_address'] ?? '',
$data['node_type'] ?? 'host',
$data['status'] ?? 'unknown',
$data['group_name'] ?? 'default',
$data['pos_x'] ?? 0,
$data['pos_y'] ?? 0
]);
} }
echo json_encode(['id' => $db->lastInsertId()]); echo json_encode(['id' => $nodeId]);
break; break;
case 'PUT': case 'PUT':
if ($id) { if ($id) {
@@ -419,9 +408,12 @@ function handleNodes($method, $id, $db) {
$stmt = $db->prepare("UPDATE network_nodes SET " . implode(', ', $fields) . " WHERE id = ?"); $stmt = $db->prepare("UPDATE network_nodes SET " . implode(', ', $fields) . " WHERE id = ?");
$stmt->execute($params); $stmt->execute($params);
} }
// Update notes separately (column may not exist) // Update notes via separate table
if (isset($data['notes'])) { if (isset($data['notes'])) {
try { $db->prepare("UPDATE network_nodes SET notes = ? WHERE id = ?")->execute([$data['notes'], $id]); } catch (Exception $e) {} try {
$db->prepare("INSERT INTO node_notes (node_id, notes) VALUES (?, ?) ON DUPLICATE KEY UPDATE notes = VALUES(notes)")
->execute([$id, $data['notes']]);
} catch (Exception $e) {}
} }
echo json_encode(['updated' => true]); echo json_encode(['updated' => true]);
} }
+5 -1
View File
@@ -39,7 +39,11 @@ function migrate($db) {
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)"); )");
try { try {
$db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT ''"); $db->exec("CREATE TABLE IF NOT EXISTS node_notes (
node_id INT PRIMARY KEY,
notes TEXT DEFAULT '',
FOREIGN KEY (node_id) REFERENCES network_nodes(id) ON DELETE CASCADE
)");
} catch (Exception $e) { } catch (Exception $e) {
} }
} }
+8 -1
View File
@@ -68,4 +68,11 @@ INSERT IGNORE INTO teams (name, color) VALUES
('Blue Team', '#0d6efd'), ('Blue Team', '#0d6efd'),
('Red Team', '#dc3545'), ('Red Team', '#dc3545'),
('SOC', '#ffc107'), ('SOC', '#ffc107'),
('Threat Intel', '#198754'); ('Threat Intel', '#198754');
-- Ensure notes column exists and grant ALTER privilege
CREATE TABLE IF NOT EXISTS node_notes (
node_id INT PRIMARY KEY,
notes TEXT DEFAULT '',
FOREIGN KEY (node_id) REFERENCES network_nodes(id) ON DELETE CASCADE
);