/* * BastionGuard™ * Copyright (C) 2025–2026 Calogero Scarnà * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * BastionGuard™ is a trademark of Calogero Scarnà. * The BastionGuard™ name and branding are not licensed under the GPL. */ #pragma once #include #include "ClamdConfig.hpp" #include "LifetimeGuard.hpp" #include #include #include class SettingsPage : public Gtk::Box { public: explicit SettingsPage(ClamdConfig& config); ~SettingsPage() override; struct SambaColumns : public Gtk::TreeModel::ColumnRecord { SambaColumns() { add(col_path); add(col_color); } Gtk::TreeModelColumn col_path; Gtk::TreeModelColumn col_color; }; void goto_page(int n) { if (n >= 0 && static_cast(n) < page_order_.size()) stack.set_visible_child(*page_order_[n]); } void set_notebook_no_tabs() { stack_switcher.set_visible(false); } private: ClamdConfig& clamdConfig; Gtk::Stack stack; Gtk::StackSwitcher stack_switcher; std::vector page_order_; Gtk::Switch clamonaccSwitch; Gtk::Label realtimeLabel; Gtk::Label quarantineLabel; Gtk::Button quarantineButton; Gtk::ListBox listbox_paths; Gtk::Button btn_addPath; Gtk::Button btn_removePath; Gtk::Box box_scanOptions{Gtk::Orientation::VERTICAL}; std::map checkOptions; Gtk::Switch toggleAllSwitch; Gtk::Label toggleAllLabel; Gtk::Button btn_save; Gtk::Button btn_applyBase; void build_secure_payments_tab(); void build_proxy_bypass_tab(); void build_clamav_db_tab(); void refresh_clamav_db_list(Gtk::Box* listBox); void build_email_security_tab(); Gtk::Label* clamdb_count_label_ = nullptr; Gtk::ComboBoxText combo_os_; Gtk::Entry entry_http_port_; Gtk::Entry entry_https_port_; bool http_updating_ = false; bool https_updating_ = false; Gtk::Button btn_apply_webconfig_; Gtk::Switch antiransomSwitch; Gtk::Label antiransomStatus; class RuleColumns : public Gtk::TreeModel::ColumnRecord { public: RuleColumns() { add(name); } Gtk::TreeModelColumn name; }; RuleColumns ruleCols; Glib::RefPtr rulesStore; Gtk::TreeView rulesView; Gtk::CheckButton chk_enableYara; Gtk::CheckButton chk_enableSanesecurity; Gtk::Label lbl_scanPaths; Gtk::ListBox listbox_scanPaths; Gtk::Button btn_addScanPath; Gtk::Button btn_removeScanPath; Gtk::SpinButton spin_interval; SambaColumns sambaCols; Glib::RefPtr sambaStore; Gtk::TreeView sambaView; Gtk::CheckButton chk_enableSamba; Gtk::Button btnAddSamba, btnRemSamba, btnScanNow; Gtk::Switch switchEnableSamba; bool enable_samba = false; std::vector samba_dirs; void onAddSambaDir(); void onRemoveSambaDir(); void onScanNowSamba(); bool validate_samba_dirs(); std::vector collect_samba_dirs( const Glib::RefPtr& store, const SambaColumns& cols ); Gtk::Switch antiphishSwitch; Gtk::Label antiphishStatus; Glib::RefPtr phishStore; Gtk::TreeView phishView; Gtk::Switch googleSafeSwitch; Gtk::Entry googleSafeKeyEntry; Glib::RefPtr whitelistSelection; Glib::RefPtr whitelistStore; Gtk::ListView whitelistView; class PhishColumns : public Gtk::TreeModel::ColumnRecord { public: PhishColumns() { add(source); } Gtk::TreeModelColumn source; }; PhishColumns phishCols; Gtk::ComboBoxText combo_language_; Gtk::Button btn_apply_language_; void onQuarantineClicked(); void onAddPath(); void onRemovePath(); void onSave(); void onRealtimeToggled(); Gtk::CheckButton* chkSuspOnly = nullptr; Gtk::Entry* txtIgnPaths = nullptr; Gtk::Entry* txtCompany = nullptr; Gtk::Entry* txtIgnExt = nullptr; Gtk::Entry* txtSuspExt = nullptr; void build_antiransom_tab(); void build_antiransom_advanced_tab(); void loadAdvancedConfig(); void loadAllowlistUI(); void saveAllowlistUI(); void saveAdvancedConfig(bool suspicious_only, const Glib::ustring& ignore_paths, const Glib::ustring& ignore_ext, const Glib::ustring& suspicious_ext); struct AllowlistCols : public Gtk::TreeModel::ColumnRecord { AllowlistCols() { add(col_hash); add(col_rule); } Gtk::TreeModelColumn col_hash; Gtk::TreeModelColumn col_rule; }; AllowlistCols allowCols; Glib::RefPtr allowStore; Gtk::TreeView allowView; void onAntiransomToggled(); void refreshAntiransomRules(); void loadYaraRules(); void loadScannerConfig(bool& use_rules, bool& use_db, int& interval, std::vector& dirs); void saveScannerConfig(bool use_rules, bool use_db, int interval, const std::vector& dirs); void build_antiphish_tab(); void onAntiphishToggled(); void refreshPhishLists(); void loadPhishLists(); void build_options_tab(); void build_whitelist_tab(); void build_user_services_tab(); bool is_user_service_enabled(const std::string& service_name); bool enable_user_service(const std::string& service_name); bool disable_user_service(const std::string& service_name); bool is_system_service_enabled(const std::string& unit_name); bool enable_system_service(const std::string& unit_name); bool disable_system_service(const std::string& unit_name); static void show_service_error_dialog( const Glib::ustring& message, const std::string& service_name ); bool run_cmd(const std::vector& argv, std::string* out_stdout = nullptr, bool silence_stderr = true); bool pkexec_servicectl(const std::vector& args, std::string* out_stdout = nullptr); void build_services_section(Gtk::Box& parent, const std::vector>& services, bool system_units); void build_system_services_tab(); bool updatingToggle = false; std::map toggleControlled; // Alive flag per proteggere i lambda asincroni da use-after-free se // la pagina viene distrutta prima che idle/thread callback partano. BastionGuard::AliveFlag alive_ = BastionGuard::make_alive_flag(); };