-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
80 lines (70 loc) · 3.37 KB
/
setup.php
File metadata and controls
80 lines (70 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
================================================================================
File: setup.php
Description: Run this file ONCE to create the database and tables.
================================================================================
*/
try {
// This path is for the Docker setup. For non-Docker, use __DIR__ . '/monitor.db'
$db_path = '/data/monitor.db';
$db = new PDO('sqlite:' . $db_path);
// Set errormode to exceptions
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Create monitors table
$db->exec("CREATE TABLE IF NOT EXISTS monitors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
ip_address TEXT NOT NULL,
parent_id INTEGER,
last_status TEXT DEFAULT 'pending', -- 'up', 'down', 'pending'
last_check DATETIME,
is_notifying INTEGER DEFAULT 0, -- Boolean 0 or 1
FOREIGN KEY (parent_id) REFERENCES monitors(id) ON DELETE SET NULL
)");
// Create ping history table
$db->exec("CREATE TABLE IF NOT EXISTS ping_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
monitor_id INTEGER NOT NULL,
status TEXT NOT NULL, -- 'up' or 'down'
check_time DATETIME NOT NULL,
FOREIGN KEY (monitor_id) REFERENCES monitors(id) ON DELETE CASCADE
)");
// Create settings table
$db->exec("CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT
)");
// Populate default settings
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('discord_webhook_url', '')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('enable_email', '0')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('enable_discord', '0')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('email_to', '')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('smtp_host', '')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('smtp_port', '587')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('smtp_user', '')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('smtp_pass', '')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('smtp_encryption', 'tls')");
$db->exec("INSERT OR IGNORE INTO settings (key, value) VALUES ('check_interval_seconds', '300')"); // NEW: Check interval
// Create Proxmox servers table
$db->exec("CREATE TABLE IF NOT EXISTS proxmox_servers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
hostname TEXT NOT NULL,
port INTEGER NOT NULL DEFAULT 8006,
username TEXT NOT NULL,
api_token TEXT NOT NULL,
verify_ssl INTEGER NOT NULL DEFAULT 1, -- Boolean 0 or 1
anchor_monitor_id INTEGER,
FOREIGN KEY (anchor_monitor_id) REFERENCES monitors(id) ON DELETE SET NULL
)");
echo "<h1>Setup Complete!</h1>";
echo "<p>Database 'monitor.db' and its tables have been created/updated successfully.</p>";
echo "<p>You can now navigate to <a href='index.php'>index.php</a> to use the application.</p>";
echo "<p><strong>IMPORTANT: For security, you should delete this 'setup.php' file now.</strong></p>";
} catch(PDOException $e) {
// Print PDOException message
echo "<h1>Setup Failed!</h1>";
echo "<p>Error: " . $e->getMessage() . "</p>";
}
?>