Diff -- /var/www/vhosts/3dshawn.com/site1/_schema/drift_sense_agent_mode.sql

O Operator
Diff

/var/www/vhosts/3dshawn.com/site1/_schema/drift_sense_agent_mode.sql

deleted on local at 2026-07-12 01:52:02

Added
+0
lines
Removed
-44
lines
Context
0
unchanged
Blobs
from 14342878e899
to
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1-- DriftSense -- agent-mode schema extension (Stealth Flavor 2)
2--
3-- Extends SERVERS with SSH connection details so _agent_scan.pl can
4-- SSH into a monitored host, walk its filesystem via a restricted key,
5-- and pull file content back into the central BLOB_STORE. Monitored
6-- hosts run zero DriftSense code -- only footprint is one authorized_keys
7-- entry with a command-restricted wrapper.
8--
9-- Idempotent: uses INFORMATION_SCHEMA probes so re-running is safe.
10
11-- Add ssh_* columns to SERVERS if not present.
12-- MariaDB 5.5 doesn't support ALTER TABLE ... ADD COLUMN IF NOT EXISTS,
13-- so we probe first and only fire the ALTER when needed.
14
15DELIMITER $$
16DROP PROCEDURE IF EXISTS _drift_add_col $$
17CREATE PROCEDURE _drift_add_col(IN t_name VARCHAR(64), IN c_name VARCHAR(64), IN c_ddl VARCHAR(500))
18BEGIN
19 IF NOT EXISTS (
20 SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
21 WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = t_name AND COLUMN_NAME = c_name
22 ) THEN
23 SET @sql = CONCAT('ALTER TABLE ', t_name, ' ADD COLUMN ', c_name, ' ', c_ddl);
24 PREPARE stmt FROM @sql;
25 EXECUTE stmt;
26 DEALLOCATE PREPARE stmt;
27 END IF;
28END $$
29DELIMITER ;
30
31CALL _drift_add_col('SERVERS', 'kind', "ENUM('local','ssh_agent') NOT NULL DEFAULT 'local'");
32CALL _drift_add_col('SERVERS', 'ssh_host', "VARCHAR(255) DEFAULT NULL");
33CALL _drift_add_col('SERVERS', 'ssh_user', "VARCHAR(64) DEFAULT NULL");
34CALL _drift_add_col('SERVERS', 'ssh_port', "INT UNSIGNED NOT NULL DEFAULT 22");
35CALL _drift_add_col('SERVERS', 'ssh_key_path', "VARCHAR(500) DEFAULT NULL");
36CALL _drift_add_col('SERVERS', 'ssh_options', "VARCHAR(500) DEFAULT NULL");
37CALL _drift_add_col('SERVERS', 'last_agent_scan_at', "DATETIME DEFAULT NULL");
38CALL _drift_add_col('SERVERS', 'last_agent_error', "VARCHAR(500) DEFAULT NULL");
39
40DROP PROCEDURE _drift_add_col;
41
42-- Ensure the local server exists with kind='local' (the default we've
43-- been using since v2 install).
44UPDATE SERVERS SET kind = 'local' WHERE server_id = 1 AND kind IS NULL;