Skip to content
API Documentation
BastionGuard™
VpnPage.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
23#include <gtkmm.h>
24#include <atomic>
25#include <functional>
26#include <memory>
27#include <string>
28
29#include "LifetimeGuard.hpp"
31
32/*
33 * VpnPage
34 * -------
35 * Pagina per il controllo della VPN WireGuard verso il server dell'utente.
36 *
37 * Layout: Gtk::Notebook con tre schede
38 * 1. Connessione – connetti/disconnetti, stato, IP pubblico prima/dopo
39 * 2. Configurazione – genera wg0.conf (chiavi client + dati server) o importa
40 * 3. Kill-switch – blocca il traffico se il tunnel cade
41 * In fondo, condiviso fra le schede, un riquadro di log.
42 */
43class VpnPage : public Gtk::Box {
44public:
45 VpnPage();
46 ~VpnPage() override;
47
48private:
49 // --- Header ---------------------------------------------------------
50 Gtk::Label lbl_title_;
51 Gtk::Label lbl_subtitle_;
52
53 Gtk::Notebook notebook_;
54
55 // --- Scheda 1: Connessione -----------------------------------------
56 Gtk::Box tab_conn_{Gtk::Orientation::VERTICAL, 12};
57 Gtk::Button btn_connect_;
58 Gtk::Button btn_disconnect_;
59 Gtk::Label lbl_state_;
60 Gtk::Label lbl_endpoint_;
61 Gtk::Spinner spinner_;
62 Gtk::Label lbl_ip_before_;
63 Gtk::Label lbl_ip_after_;
64 Gtk::Button btn_refresh_ip_;
65
66 // --- Scheda 2: Configurazione --------------------------------------
67 Gtk::Box tab_config_{Gtk::Orientation::VERTICAL, 10};
70 Gtk::Button btn_gen_keys_;
72 Gtk::Entry entry_endpoint_;
73 Gtk::Entry entry_address_;
74 Gtk::Entry entry_dns_;
75 Gtk::Entry entry_allowed_;
76 Gtk::Button btn_generate_;
77 Gtk::Entry entry_conf_path_;
78 Gtk::Button btn_browse_;
79 Gtk::Button btn_import_;
80
81 // --- Scheda 3: Kill-switch -----------------------------------------
82 Gtk::Box tab_ks_{Gtk::Orientation::VERTICAL, 10};
83 Gtk::Switch switch_ks_;
84
85 // --- Log condiviso --------------------------------------------------
86 Gtk::ScrolledWindow log_scroller_;
87 Gtk::TextView txt_log_;
88
89 // --- Stato ----------------------------------------------------------
90 std::unique_ptr<BastionGuard::WireguardBackend> backend_;
91 std::atomic<bool> busy_{false};
92 std::string ip_before_;
93 sigc::connection poll_conn_;
94
95 // --- Costruzione ----------------------------------------------------
96 void build_ui();
97 Gtk::Widget* build_tab_connection();
98 Gtk::Widget* build_tab_config();
99 Gtk::Widget* build_tab_killswitch();
100
101 // --- Helpers --------------------------------------------------------
102 void append_log(const std::string& line);
103 void set_busy(bool b);
105 static Gtk::Box* labeled_row(const std::string& label, Gtk::Widget& field);
106
107 // --- Azioni ---------------------------------------------------------
108 void on_connect_clicked();
111 // Aggiorna l'IP pubblico scrivendolo nello slot indicato, senza
112 // indovinare lo stato del tunnel (evita race subito dopo il connect).
113 enum class IpSlot { Before, After, Auto };
114 void refresh_public_ip(IpSlot slot);
117 void on_browse_clicked();
118 void on_import_clicked();
120
121 void run_async(std::function<BastionGuard::OpResult()> work,
122 std::function<void(BastionGuard::OpResult)> done);
123
124 bool on_poll_status();
125
127};
void refresh_public_ip(IpSlot slot)
Definition VpnPage.cpp:509
void on_killswitch_toggled()
Definition VpnPage.cpp:546
Gtk::Button btn_disconnect_
Definition VpnPage.hpp:58
Gtk::Widget * build_tab_config()
Definition VpnPage.cpp:178
Gtk::Label lbl_ip_after_
Definition VpnPage.hpp:63
std::string ip_before_
Definition VpnPage.hpp:92
void on_disconnect_clicked()
Definition VpnPage.cpp:489
sigc::connection poll_conn_
Definition VpnPage.hpp:93
void run_async(std::function< BastionGuard::OpResult()> work, std::function< void(BastionGuard::OpResult)> done)
Definition VpnPage.cpp:346
Gtk::Widget * build_tab_connection()
Definition VpnPage.cpp:129
Gtk::ScrolledWindow log_scroller_
Definition VpnPage.hpp:86
void on_refresh_ip_clicked()
Definition VpnPage.cpp:505
Gtk::Label lbl_subtitle_
Definition VpnPage.hpp:51
Gtk::Entry entry_allowed_
Definition VpnPage.hpp:75
Gtk::Entry entry_server_pub_
Definition VpnPage.hpp:71
void on_import_clicked()
Definition VpnPage.cpp:440
BastionGuard::AliveFlag alive_
Definition VpnPage.hpp:126
void append_log(const std::string &line)
Definition VpnPage.cpp:292
Gtk::Entry entry_client_pub_
Definition VpnPage.hpp:69
void on_connect_clicked()
Definition VpnPage.cpp:456
Gtk::Button btn_browse_
Definition VpnPage.hpp:78
Gtk::Switch switch_ks_
Definition VpnPage.hpp:83
Gtk::Entry entry_conf_path_
Definition VpnPage.hpp:77
void on_generate_keys_clicked()
Definition VpnPage.cpp:363
Gtk::Spinner spinner_
Definition VpnPage.hpp:61
Gtk::Label lbl_ip_before_
Definition VpnPage.hpp:62
void on_browse_clicked()
Definition VpnPage.cpp:414
Gtk::Button btn_import_
Definition VpnPage.hpp:79
Gtk::Label lbl_title_
Definition VpnPage.hpp:50
Gtk::Button btn_generate_
Definition VpnPage.hpp:76
void set_busy(bool b)
Definition VpnPage.cpp:300
Gtk::Entry entry_endpoint_
Definition VpnPage.hpp:72
Gtk::Button btn_refresh_ip_
Definition VpnPage.hpp:64
std::unique_ptr< BastionGuard::WireguardBackend > backend_
Definition VpnPage.hpp:90
Gtk::Entry entry_client_priv_
Definition VpnPage.hpp:68
Gtk::Box tab_conn_
Definition VpnPage.hpp:56
Gtk::Box tab_ks_
Definition VpnPage.hpp:82
bool on_poll_status()
Definition VpnPage.cpp:570
Gtk::Button btn_gen_keys_
Definition VpnPage.hpp:70
Gtk::Label lbl_state_
Definition VpnPage.hpp:59
void refresh_state_ui(const BastionGuard::WgStatus &st)
Definition VpnPage.cpp:316
Gtk::Widget * build_tab_killswitch()
Definition VpnPage.cpp:262
Gtk::Entry entry_dns_
Definition VpnPage.hpp:74
static Gtk::Box * labeled_row(const std::string &label, Gtk::Widget &field)
Definition VpnPage.cpp:61
VpnPage()
Definition VpnPage.cpp:30
Gtk::Notebook notebook_
Definition VpnPage.hpp:53
void on_generate_config_clicked()
Definition VpnPage.cpp:391
Gtk::Button btn_connect_
Definition VpnPage.hpp:57
Gtk::TextView txt_log_
Definition VpnPage.hpp:87
Gtk::Label lbl_endpoint_
Definition VpnPage.hpp:60
std::atomic< bool > busy_
Definition VpnPage.hpp:91
Gtk::Entry entry_address_
Definition VpnPage.hpp:73
void build_ui()
Definition VpnPage.cpp:76
Gtk::Box tab_config_
Definition VpnPage.hpp:67
std::shared_ptr< std::atomic< bool > > AliveFlag
AliveFlag make_alive_flag()