.
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
+13 -21
View File
@@ -366,27 +366,10 @@ function handleComments($method, $id, $db) {
function handleNodes($method, $id, $db) {
switch ($method) {
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;
case 'POST':
$data = json_decode(file_get_contents('php://input'), true);
try {
$stmt = $db->prepare("
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y, notes)
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,
$data['notes'] ?? ''
]);
} catch (Exception $e) {
// Fallback without notes column
$stmt = $db->prepare("
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y)
VALUES (?, ?, ?, ?, ?, ?, ?)
@@ -400,8 +383,14 @@ function handleNodes($method, $id, $db) {
$data['pos_x'] ?? 0,
$data['pos_y'] ?? 0
]);
$nodeId = $db->lastInsertId();
if (!empty($data['notes'])) {
try {
$db->prepare("INSERT INTO node_notes (node_id, notes) VALUES (?, ?) ON DUPLICATE KEY UPDATE notes = VALUES(notes)")
->execute([$nodeId, $data['notes']]);
} catch (Exception $e) {}
}
echo json_encode(['id' => $db->lastInsertId()]);
echo json_encode(['id' => $nodeId]);
break;
case 'PUT':
if ($id) {
@@ -419,9 +408,12 @@ function handleNodes($method, $id, $db) {
$stmt = $db->prepare("UPDATE network_nodes SET " . implode(', ', $fields) . " WHERE id = ?");
$stmt->execute($params);
}
// Update notes separately (column may not exist)
// Update notes via separate table
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]);
}
+5 -1
View File
@@ -39,7 +39,11 @@ function migrate($db) {
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
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) {
}
}
+7
View File
@@ -69,3 +69,10 @@ INSERT IGNORE INTO teams (name, color) VALUES
('Red Team', '#dc3545'),
('SOC', '#ffc107'),
('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
);