added control page
This commit is contained in:
@@ -44,6 +44,27 @@ def init_ping_db(db_path=DB_PATH):
|
||||
pass # column already exists
|
||||
conn.close()
|
||||
|
||||
def init_settings_db(db_path=DB_PATH):
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT NOT NULL)")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_setting(key: str, db_path=DB_PATH) -> str | None:
|
||||
conn = sqlite3.connect(db_path)
|
||||
row = conn.execute("SELECT value FROM settings WHERE key = ?", (key,)).fetchone()
|
||||
conn.close()
|
||||
return row[0] if row else None
|
||||
|
||||
def set_setting(key: str, value: str, db_path=DB_PATH):
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.execute(
|
||||
"INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
||||
(key, value)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def insert_ping_result(target_ip: str, success: bool, latency_ms: float | None, is_gateway: bool = False, db_path=DB_PATH):
|
||||
conn = sqlite3.connect(db_path)
|
||||
c = conn.cursor()
|
||||
|
||||
Reference in New Issue
Block a user