4#include <spdlog/logger.h>
9#include "proto/service.pb.h"
16 explicit Database(
const std::string &db_path);
21 std::vector<std::vector<std::string>>
select_query(
const std::string &query);
24 const std::string &display_name,
25 const std::string &file_path, int64_t start,
26 int64_t end, proto::DataLinkType data_link);
34 const std::vector<std::pair<std::string, std::string>> &vendors);
35 std::vector<std::vector<std::string>>
get_vendors();
38 bool insert_network(
const std::string &ssid,
const std::string &bssid,
39 const std::string &psk, uint32_t total_packet_count,
40 uint32_t decrypted_packet_count,
41 uint32_t group_packet_count,
const std::string &security,
42 std::string recording_id, uint32_t group_rekeys,
43 const std::string &vendor_oid);
45 uint64_t end, uint32_t packet_count);
47 bool insert_client(
const std::string &address, uint32_t packet_count,
48 uint32_t decrypted_packet_count,
49 const std::string &network_id);
50 std::vector<std::vector<std::string>>
get_clients();
52 const std::string &network_id, uint64_t start,
53 uint64_t end, uint32_t packet_count);
59 std::shared_ptr<spdlog::logger> logger;
61 const std::string schema = R
"(
62CREATE TABLE IF NOT EXISTS Vendors (
63 oid TEXT PRIMARY KEY, -- MAC address prefix (first 3 bytes)
67CREATE TABLE IF NOT EXISTS Recordings (
76CREATE TABLE IF NOT EXISTS Networks (
78 bssid TEXT PRIMARY KEY,
80 total_packet_count INTEGER,
81 decrypted_packet_count INTEGER,
82 group_packet_count INTEGER,
83 security TEXT, -- Numbers separated by space (ex. "3 4")
87 FOREIGN KEY (vendor_oid) REFERENCES Vendors(oid),
88 FOREIGN KEY (recording_id) REFERENCES Recordings(id) ON DELETE CASCADE
91CREATE TABLE IF NOT EXISTS GroupDecryptionWindow (
96 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
99CREATE TABLE IF NOT EXISTS Clients (
100 address TEXT PRIMARY KEY,
101 packet_count INTEGER,
102 decrypted_packet_count INTEGER,
104 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
107CREATE TABLE IF NOT EXISTS ClientDecryptionWindow (
112 packet_count INTEGER,
113 FOREIGN KEY (client_address) REFERENCES Clients(address) ON DELETE CASCADE,
114 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
bool execute_query(const std::string &query)
Definition database.cpp:33
bool recording_exists(const uuid::UUIDv4 &uuid)
Definition database.cpp:117
bool initialize()
Definition database.cpp:16
std::vector< std::vector< std::string > > get_clients()
Definition database.cpp:420
std::vector< std::vector< std::string > > get_group_windows()
Definition database.cpp:386
Database(const std::string &db_path)
Definition database.cpp:7
bool insert_recording(const uuid::UUIDv4 &uuid, const std::string &display_name, const std::string &file_path, int64_t start, int64_t end, proto::DataLinkType data_link)
Definition database.cpp:90
bool vendor_exists(const std::string &oid)
Definition database.cpp:286
std::vector< std::vector< std::string > > get_recordings()
Definition database.cpp:103
bool delete_recording(const uuid::UUIDv4 &uuid) const
Definition database.cpp:155
bool insert_client(const std::string &address, uint32_t packet_count, uint32_t decrypted_packet_count, const std::string &network_id)
Definition database.cpp:391
bool refresh_database()
Definition database.cpp:462
std::vector< std::string > get_recording(const uuid::UUIDv4 &uuid)
Definition database.cpp:108
bool load_vendors(const std::string &OID_path)
Definition database.cpp:190
std::vector< std::vector< std::string > > get_vendors()
Definition database.cpp:272
bool insert_vendors(const std::vector< std::pair< std::string, std::string > > &vendors)
Definition database.cpp:227
bool insert_group_window(const std::string &network_id, uint64_t start, uint64_t end, uint32_t packet_count)
Definition database.cpp:355
std::vector< std::vector< std::string > > select_query(const std::string &query)
Definition database.cpp:45
~Database()
Definition database.cpp:11
bool insert_client_window(const std::string &client_address, const std::string &network_id, uint64_t start, uint64_t end, uint32_t packet_count)
Definition database.cpp:425
std::string get_vendor_name(const std::string &oid)
Definition database.cpp:277
bool check_vendors(bool seeding=false)
Definition database.cpp:69
std::vector< std::vector< std::string > > get_client_windows()
Definition database.cpp:457
bool insert_network(const std::string &ssid, const std::string &bssid, const std::string &psk, uint32_t total_packet_count, uint32_t decrypted_packet_count, uint32_t group_packet_count, const std::string &security, std::string recording_id, uint32_t group_rekeys, const std::string &vendor_oid)
Definition database.cpp:293
bool recording_exists_path(const std::string &file_path)
Definition database.cpp:136
std::string UUIDv4
Definition uuid.h:11
Definition access_point.cpp:22