* add support for systemd, OpenRC, SysVinit, and Dinit * add automatic init-system detection through CMake * make libsystemd optional for non-systemd builds * add native service definitions for all supported init systems * add Gentoo ebuild and Alpine APKBUILD packaging support * publish the official BastionGuard source repository * update the README with supported distributions, init systems, repository information, and build documentation
233 lines
7.3 KiB
C++
233 lines
7.3 KiB
C++
/*
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
*
|
|
* BastionGuard™ is a trademark of Calogero Scarnà.
|
|
* The BastionGuard™ name and branding are not licensed under the GPL.
|
|
*/
|
|
|
|
#pragma once
|
|
#include <gtkmm.h>
|
|
#include "ClamdConfig.hpp"
|
|
#include "LifetimeGuard.hpp"
|
|
#include <map>
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
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<Glib::ustring> col_path;
|
|
Gtk::TreeModelColumn<Glib::ustring> col_color;
|
|
};
|
|
|
|
void goto_page(int n) { if (n >= 0 && static_cast<size_t>(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<Gtk::Widget*> 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<std::string, Gtk::CheckButton*> 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<Glib::ustring> name;
|
|
};
|
|
RuleColumns ruleCols;
|
|
Glib::RefPtr<Gtk::ListStore> 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<Gtk::ListStore> sambaStore;
|
|
Gtk::TreeView sambaView;
|
|
Gtk::CheckButton chk_enableSamba;
|
|
Gtk::Button btnAddSamba, btnRemSamba, btnScanNow;
|
|
Gtk::Switch switchEnableSamba;
|
|
|
|
|
|
bool enable_samba = false;
|
|
std::vector<std::string> samba_dirs;
|
|
|
|
void onAddSambaDir();
|
|
void onRemoveSambaDir();
|
|
void onScanNowSamba();
|
|
bool validate_samba_dirs();
|
|
std::vector<std::string> collect_samba_dirs(
|
|
const Glib::RefPtr<Gtk::ListStore>& store,
|
|
const SambaColumns& cols
|
|
);
|
|
|
|
|
|
Gtk::Switch antiphishSwitch;
|
|
Gtk::Label antiphishStatus;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> phishStore;
|
|
Gtk::TreeView phishView;
|
|
Gtk::Switch googleSafeSwitch;
|
|
Gtk::Entry googleSafeKeyEntry;
|
|
Glib::RefPtr<Gtk::SingleSelection> whitelistSelection;
|
|
Glib::RefPtr<Gtk::StringList> whitelistStore;
|
|
Gtk::ListView whitelistView;
|
|
|
|
class PhishColumns : public Gtk::TreeModel::ColumnRecord {
|
|
public:
|
|
PhishColumns() { add(source); }
|
|
Gtk::TreeModelColumn<Glib::ustring> 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<Glib::ustring> col_hash;
|
|
Gtk::TreeModelColumn<Glib::ustring> col_rule;
|
|
};
|
|
AllowlistCols allowCols;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> allowStore;
|
|
Gtk::TreeView allowView;
|
|
|
|
void onAntiransomToggled();
|
|
void refreshAntiransomRules();
|
|
void loadYaraRules();
|
|
|
|
void loadScannerConfig(bool& use_rules, bool& use_db,
|
|
int& interval, std::vector<std::string>& dirs);
|
|
void saveScannerConfig(bool use_rules, bool use_db,
|
|
int interval,
|
|
const std::vector<std::string>& 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<std::string>& argv,
|
|
std::string* out_stdout = nullptr,
|
|
bool silence_stderr = true);
|
|
|
|
bool pkexec_servicectl(const std::vector<std::string>& args,
|
|
std::string* out_stdout = nullptr);
|
|
|
|
void build_services_section(Gtk::Box& parent,
|
|
const std::vector<std::tuple<std::string, Glib::ustring, Glib::ustring>>& services,
|
|
bool system_units);
|
|
void build_system_services_tab();
|
|
|
|
bool updatingToggle = false;
|
|
std::map<std::string, bool> 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();
|
|
};
|