File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import time
55import os
66import sys
7+ import sqlite3
8+ import settings
9+ from utility .paths import get_database_path
710
811class StartUpMenu :
912 def __init__ (self ):
@@ -287,6 +290,78 @@ def _skip_loading(self):
287290 print ("Skipping IP2LOC loading..." )
288291 self ._complete_loading ()
289292
293+ def init_database ():
294+ """Initialize SQLite databases for the application"""
295+ try :
296+ # Initialize cameras database
297+ cameras_db_path = get_database_path ('cameras.db' )
298+ os .makedirs (os .path .dirname (cameras_db_path ), exist_ok = True )
299+
300+ conn = sqlite3 .connect (cameras_db_path )
301+ cursor = conn .cursor ()
302+
303+ cursor .execute ('''
304+ CREATE TABLE IF NOT EXISTS cameras (
305+ ip TEXT PRIMARY KEY,
306+ status TEXT,
307+ last_check TIMESTAMP,
308+ resolution TEXT,
309+ stream_type TEXT,
310+ endpoint TEXT,
311+ location TEXT
312+ )
313+ ''' )
314+ conn .commit ()
315+ conn .close ()
316+
317+ # Initialize IP info database
318+ ip_info_db_path = get_database_path ('ip_info.db' )
319+ os .makedirs (os .path .dirname (ip_info_db_path ), exist_ok = True )
320+
321+ conn = sqlite3 .connect (ip_info_db_path )
322+ cursor = conn .cursor ()
323+
324+ cursor .execute ('''
325+ CREATE TABLE IF NOT EXISTS ip_info (
326+ ip TEXT PRIMARY KEY,
327+ lat REAL,
328+ lon REAL,
329+ city TEXT,
330+ country TEXT,
331+ last_updated TIMESTAMP
332+ )
333+ ''' )
334+ conn .commit ()
335+ conn .close ()
336+
337+ # Initialize IoT devices database
338+ iot_db_path = get_database_path ('iot_devices.db' )
339+ os .makedirs (os .path .dirname (iot_db_path ), exist_ok = True )
340+
341+ conn = sqlite3 .connect (iot_db_path )
342+ cursor = conn .cursor ()
343+
344+ cursor .execute ('''
345+ CREATE TABLE IF NOT EXISTS iot_devices (
346+ ip TEXT PRIMARY KEY,
347+ device_type TEXT,
348+ status TEXT,
349+ last_check TIMESTAMP,
350+ manufacturer TEXT,
351+ model TEXT,
352+ firmware_version TEXT,
353+ vulnerabilities TEXT
354+ )
355+ ''' )
356+ conn .commit ()
357+ conn .close ()
358+
359+ print ("Databases initialized successfully" )
360+
361+ except Exception as e :
362+ print (f"Error initializing databases: { e } " )
363+ raise
364+
290365def init_gui ():
291366 """Initialize the GUI"""
292367 try :
You can’t perform that action at this time.
0 commit comments