Skip to content
API Documentation
BastionGuard™
SettingsPage.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22#include <gtkmm.h>
23#include "ClamdConfig.hpp"
24#include "LifetimeGuard.hpp"
25#include <map>
26#include <vector>
27#include <string>
28
29class SettingsPage : public Gtk::Box {
30public:
31 explicit SettingsPage(ClamdConfig& config);
32 ~SettingsPage() override;
33
34 struct SambaColumns : public Gtk::TreeModel::ColumnRecord {
36 Gtk::TreeModelColumn<Glib::ustring> col_path;
37 Gtk::TreeModelColumn<Glib::ustring> col_color;
38 };
39
40 void goto_page(int n) { if (n >= 0 && static_cast<size_t>(n) < page_order_.size()) stack.set_visible_child(*page_order_[n]); }
41 void set_notebook_no_tabs() { stack_switcher.set_visible(false); }
42private:
44
45 Gtk::Stack stack;
46 Gtk::StackSwitcher stack_switcher;
47 std::vector<Gtk::Widget*> page_order_;
48
49
50 Gtk::Switch clamonaccSwitch;
51 Gtk::Label realtimeLabel;
52 Gtk::Label quarantineLabel;
53 Gtk::Button quarantineButton;
54 Gtk::ListBox listbox_paths;
55
56 Gtk::Button btn_addPath;
57 Gtk::Button btn_removePath;
58
59 Gtk::Box box_scanOptions{Gtk::Orientation::VERTICAL};
60 std::map<std::string, Gtk::CheckButton*> checkOptions;
61
62 Gtk::Switch toggleAllSwitch;
63 Gtk::Label toggleAllLabel;
64
65 Gtk::Button btn_save;
66 Gtk::Button btn_applyBase;
70 void refresh_clamav_db_list(Gtk::Box* listBox);
72
73 Gtk::Label* clamdb_count_label_ = nullptr;
74
75 Gtk::ComboBoxText combo_os_;
76 Gtk::Entry entry_http_port_;
78 bool http_updating_ = false;
79 bool https_updating_ = false;
81
82
83 Gtk::Switch antiransomSwitch;
84 Gtk::Label antiransomStatus;
85
86 class RuleColumns : public Gtk::TreeModel::ColumnRecord {
87 public:
88 RuleColumns() { add(name); }
89 Gtk::TreeModelColumn<Glib::ustring> name;
90 };
92 Glib::RefPtr<Gtk::ListStore> rulesStore;
93 Gtk::TreeView rulesView;
94
95 Gtk::CheckButton chk_enableYara;
96 Gtk::CheckButton chk_enableSanesecurity;
97 Gtk::Label lbl_scanPaths;
98 Gtk::ListBox listbox_scanPaths;
99 Gtk::Button btn_addScanPath;
101 Gtk::SpinButton spin_interval;
102
104 Glib::RefPtr<Gtk::ListStore> sambaStore;
105 Gtk::TreeView sambaView;
106 Gtk::CheckButton chk_enableSamba;
108 Gtk::Switch switchEnableSamba;
109
110
111 bool enable_samba = false;
112 std::vector<std::string> samba_dirs;
113
118 std::vector<std::string> collect_samba_dirs(
119 const Glib::RefPtr<Gtk::ListStore>& store,
120 const SambaColumns& cols
121 );
122
123
124 Gtk::Switch antiphishSwitch;
125 Gtk::Label antiphishStatus;
126
127 Glib::RefPtr<Gtk::ListStore> phishStore;
128 Gtk::TreeView phishView;
129 Gtk::Switch googleSafeSwitch;
131 Glib::RefPtr<Gtk::SingleSelection> whitelistSelection;
132 Glib::RefPtr<Gtk::StringList> whitelistStore;
133 Gtk::ListView whitelistView;
134
135 class PhishColumns : public Gtk::TreeModel::ColumnRecord {
136 public:
138 Gtk::TreeModelColumn<Glib::ustring> source;
139 };
141
142
143 Gtk::ComboBoxText combo_language_;
145
146
147 void onQuarantineClicked();
148 void onAddPath();
149 void onRemovePath();
150 void onSave();
151 void onRealtimeToggled();
152
153 Gtk::CheckButton* chkSuspOnly = nullptr;
154 Gtk::Entry* txtIgnPaths = nullptr;
155 Gtk::Entry* txtCompany = nullptr;
156 Gtk::Entry* txtIgnExt = nullptr;
157 Gtk::Entry* txtSuspExt = nullptr;
158
159
162 void loadAdvancedConfig();
163 void loadAllowlistUI();
164 void saveAllowlistUI();
165
166 void saveAdvancedConfig(bool suspicious_only,
167 const Glib::ustring& ignore_paths,
168 const Glib::ustring& ignore_ext,
169 const Glib::ustring& suspicious_ext);
170
171 struct AllowlistCols : public Gtk::TreeModel::ColumnRecord {
173 Gtk::TreeModelColumn<Glib::ustring> col_hash;
174 Gtk::TreeModelColumn<Glib::ustring> col_rule;
175 };
177
178 Glib::RefPtr<Gtk::ListStore> allowStore;
179 Gtk::TreeView allowView;
180
181 void onAntiransomToggled();
183 void loadYaraRules();
184
185 void loadScannerConfig(bool& use_rules, bool& use_db,
186 int& interval, std::vector<std::string>& dirs);
187 void saveScannerConfig(bool use_rules, bool use_db,
188 int interval,
189 const std::vector<std::string>& dirs);
190
191
192
193 void build_antiphish_tab();
194 void onAntiphishToggled();
195 void refreshPhishLists();
196 void loadPhishLists();
197 void build_options_tab();
198 void build_whitelist_tab();
199
201
202 bool is_user_service_enabled(const std::string& service_name);
203 bool enable_user_service(const std::string& service_name);
204 bool disable_user_service(const std::string& service_name);
205
206 bool is_system_service_enabled(const std::string& unit_name);
207 bool enable_system_service(const std::string& unit_name);
208 bool disable_system_service(const std::string& unit_name);
209
210 static void show_service_error_dialog(
211 const Glib::ustring& message,
212 const std::string& service_name
213 );
214
215 bool run_cmd(const std::vector<std::string>& argv,
216 std::string* out_stdout = nullptr,
217 bool silence_stderr = true);
218
219 bool pkexec_servicectl(const std::vector<std::string>& args,
220 std::string* out_stdout = nullptr);
221
222 void build_services_section(Gtk::Box& parent,
223 const std::vector<std::tuple<std::string, Glib::ustring, Glib::ustring>>& services,
224 bool system_units);
226
227 bool updatingToggle = false;
228 std::map<std::string, bool> toggleControlled;
229
230 // Alive flag per proteggere i lambda asincroni da use-after-free se
231 // la pagina viene distrutta prima che idle/thread callback partano.
233};
Gtk::TreeModelColumn< Glib::ustring > source
Gtk::TreeModelColumn< Glib::ustring > name
Gtk::ListBox listbox_paths
Gtk::Label antiransomStatus
Glib::RefPtr< Gtk::ListStore > allowStore
std::vector< std::string > samba_dirs
Gtk::Entry * txtSuspExt
Gtk::CheckButton chk_enableYara
void saveScannerConfig(bool use_rules, bool use_db, int interval, const std::vector< std::string > &dirs)
void onQuarantineClicked()
void saveAdvancedConfig(bool suspicious_only, const Glib::ustring &ignore_paths, const Glib::ustring &ignore_ext, const Glib::ustring &suspicious_ext)
void refreshAntiransomRules()
Gtk::StackSwitcher stack_switcher
Gtk::Button btn_apply_language_
Gtk::Switch antiphishSwitch
Gtk::Switch clamonaccSwitch
SettingsPage(ClamdConfig &config)
Gtk::Button btn_removePath
Gtk::CheckButton chk_enableSanesecurity
Gtk::Label toggleAllLabel
bool enable_system_service(const std::string &unit_name)
void refresh_clamav_db_list(Gtk::Box *listBox)
BastionGuard::AliveFlag alive_
Gtk::Label lbl_scanPaths
Gtk::Switch antiransomSwitch
Gtk::Button quarantineButton
void loadAdvancedConfig()
Gtk::Switch switchEnableSamba
AllowlistCols allowCols
Gtk::Switch googleSafeSwitch
RuleColumns ruleCols
Gtk::ComboBoxText combo_os_
static void show_service_error_dialog(const Glib::ustring &message, const std::string &service_name)
void build_services_section(Gtk::Box &parent, const std::vector< std::tuple< std::string, Glib::ustring, Glib::ustring > > &services, bool system_units)
Gtk::TreeView rulesView
void onScanNowSamba()
Gtk::Entry entry_http_port_
void build_clamav_db_tab()
Gtk::TreeView sambaView
void onRealtimeToggled()
Gtk::ComboBoxText combo_language_
void loadScannerConfig(bool &use_rules, bool &use_db, int &interval, std::vector< std::string > &dirs)
void build_secure_payments_tab()
void build_system_services_tab()
Gtk::TreeView phishView
Gtk::Button btn_addPath
Gtk::Button btn_applyBase
Gtk::Button btn_removeScanPath
void goto_page(int n)
void onAntiphishToggled()
Gtk::Entry googleSafeKeyEntry
void refreshPhishLists()
Gtk::Label * clamdb_count_label_
bool run_cmd(const std::vector< std::string > &argv, std::string *out_stdout=nullptr, bool silence_stderr=true)
void onAntiransomToggled()
Gtk::Box box_scanOptions
Glib::RefPtr< Gtk::SingleSelection > whitelistSelection
Gtk::CheckButton chk_enableSamba
std::map< std::string, bool > toggleControlled
bool enable_user_service(const std::string &service_name)
Gtk::ListView whitelistView
bool is_user_service_enabled(const std::string &service_name)
void build_email_security_tab()
void onAddSambaDir()
Gtk::Button btnAddSamba
Gtk::Stack stack
Gtk::Button btn_save
Gtk::Label realtimeLabel
void build_antiransom_tab()
Gtk::Button btn_addScanPath
bool validate_samba_dirs()
bool is_system_service_enabled(const std::string &unit_name)
Gtk::Switch toggleAllSwitch
Gtk::Entry * txtCompany
Gtk::Label antiphishStatus
void onRemoveSambaDir()
ClamdConfig & clamdConfig
PhishColumns phishCols
Glib::RefPtr< Gtk::ListStore > phishStore
void build_proxy_bypass_tab()
Gtk::Entry entry_https_port_
Gtk::SpinButton spin_interval
SambaColumns sambaCols
Gtk::Button btnRemSamba
std::map< std::string, Gtk::CheckButton * > checkOptions
void build_antiphish_tab()
Gtk::Entry * txtIgnExt
void set_notebook_no_tabs()
Gtk::ListBox listbox_scanPaths
Gtk::TreeView allowView
void build_whitelist_tab()
void build_options_tab()
std::vector< Gtk::Widget * > page_order_
void build_antiransom_advanced_tab()
Gtk::Entry * txtIgnPaths
void build_user_services_tab()
bool disable_user_service(const std::string &service_name)
bool pkexec_servicectl(const std::vector< std::string > &args, std::string *out_stdout=nullptr)
Glib::RefPtr< Gtk::ListStore > sambaStore
Gtk::Button btnScanNow
bool disable_system_service(const std::string &unit_name)
std::vector< std::string > collect_samba_dirs(const Glib::RefPtr< Gtk::ListStore > &store, const SambaColumns &cols)
Gtk::Button btn_apply_webconfig_
Glib::RefPtr< Gtk::StringList > whitelistStore
Gtk::CheckButton * chkSuspOnly
Gtk::Label quarantineLabel
Glib::RefPtr< Gtk::ListStore > rulesStore
std::shared_ptr< std::atomic< bool > > AliveFlag
AliveFlag make_alive_flag()
Gtk::TreeModelColumn< Glib::ustring > col_hash
Gtk::TreeModelColumn< Glib::ustring > col_rule
Gtk::TreeModelColumn< Glib::ustring > col_path
Gtk::TreeModelColumn< Glib::ustring > col_color