Skip to content
API Documentation
BastionGuard™
AppsPage Class Reference

#include <AppsPage.hpp>

Inheritance diagram for AppsPage:

Classes

struct  Columns

Public Member Functions

 AppsPage ()
void noteConnection (const ConnectionInfo &info, const std::string &verdict)
void clear ()

Private Member Functions

void buildUI ()

Static Private Member Functions

static std::string currentTimeString ()
static std::string displayNameFor (const ConnectionInfo &info)

Private Attributes

Columns m_columns
Glib::RefPtr< Gtk::ListStore > m_store
Gtk::TreeView m_treeView
Gtk::ScrolledWindow m_scroll
Gtk::Label m_headerLabel
Gtk::Button m_clearBtn
std::unordered_map< std::string, Gtk::TreeModel::iterator > m_appRows

Detailed Description

Pagina che elenca tutte le applicazioni che hanno aperto connessioni nella sessione corrente, con conteggio + ultimo host contattato + timestamp.

Identita' applicazione: nome reale del processo dal kernel (/proc/<pid>/comm). Nessuna scansione dei file .desktop.

Aggregazione per process_path (binario unico). Aggiornata a O(1) tramite mappa path -> iterator nel ListStore.

Definition at line 25 of file AppsPage.hpp.

Constructor & Destructor Documentation

◆ AppsPage()

AppsPage::AppsPage ( )

Definition at line 16 of file AppsPage.cpp.

17: Gtk::Box(Gtk::Orientation::VERTICAL, 0)
18{
19 // Classe CSS sulla pagina intera per consentire al tema (BSC.css /
20 // BSC-dark.css) di personalizzare colori, padding e bordi in modo
21 // coerente con le altre pagine.
22 get_style_context()->add_class("bsc-page");
23 get_style_context()->add_class("bsc-apps-page");
24 buildUI();
25}
void buildUI()
Definition AppsPage.cpp:27

References buildUI().

Member Function Documentation

◆ buildUI()

void AppsPage::buildUI ( )
private

Definition at line 27 of file AppsPage.cpp.

28{
29 set_margin_start(12);
30 set_margin_end(12);
31 set_margin_top(12);
32 set_margin_bottom(12);
33
34 // ── Header ─────────────────────────────────────────────────────────
35 auto header = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 8);
36 header->get_style_context()->add_class("bsc-page-header");
37
38 m_headerLabel.set_markup("<b>" + Glib::ustring(_("Applicazioni")) + "</b>");
39 m_headerLabel.set_halign(Gtk::Align::START);
40 m_headerLabel.set_hexpand(true);
41 m_headerLabel.get_style_context()->add_class("bsc-page-title");
42 header->append(m_headerLabel);
43
44 m_clearBtn.set_label(_("Pulisci"));
45 m_clearBtn.get_style_context()->add_class("bsc-toolbar-button");
46 m_clearBtn.signal_clicked().connect([this]() { clear(); });
47 header->append(m_clearBtn);
48
49 append(*header);
50
51 // ── Store + TreeView ───────────────────────────────────────────────
52 m_store = Gtk::ListStore::create(m_columns);
53 m_treeView.set_model(m_store);
54 m_treeView.set_headers_visible(true);
55 m_treeView.set_hexpand(true);
56 m_treeView.set_vexpand(true);
57 // Classi CSS coerenti con le altre TreeView (Connessioni, Regole)
58 m_treeView.get_style_context()->add_class("bsc-treeview");
59 m_treeView.get_style_context()->add_class("bsc-apps-treeview");
60
61 // ── Colonne ────────────────────────────────────────────────────────
62 // Nessuna colonna icona: senza .desktop scanning non avremmo modo di
63 // mostrare un'icona significativa, e una colonna vuota e' peggio di
64 // nessuna colonna. La prima colonna ora e' direttamente il NOME.
65 m_treeView.append_column(_("Applicazione"), m_columns.col_name);
66 m_treeView.append_column(_("Path"), m_columns.col_path);
67 m_treeView.append_column(_("Connessioni"), m_columns.col_count);
68 m_treeView.append_column(_("Ultimo host"), m_columns.col_last_host);
69 m_treeView.append_column(_("Ultimo esito"), m_columns.col_last_verdict);
70 m_treeView.append_column(_("Aggiornata"), m_columns.col_last_time);
71
72 // Tutte le colonne sono ridimensionabili dall'utente; la colonna "Path"
73 // si espande per occupare lo spazio rimanente (e' il dato piu' lungo).
74 for (int i = 0; i < m_treeView.get_n_columns(); ++i) {
75 if (auto* c = m_treeView.get_column(i)) {
76 c->set_resizable(true);
77 c->set_reorderable(false);
78 }
79 }
80 if (auto* path_col = m_treeView.get_column(1)) {
81 path_col->set_expand(true);
82 path_col->set_min_width(200);
83 }
84
85 m_scroll.set_child(m_treeView);
86 m_scroll.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
87 m_scroll.set_hexpand(true);
88 m_scroll.set_vexpand(true);
89 m_scroll.get_style_context()->add_class("bsc-scrolled");
90 append(m_scroll);
91}
#define _(s)
Gtk::Button m_clearBtn
Definition AppsPage.hpp:59
Gtk::ScrolledWindow m_scroll
Definition AppsPage.hpp:57
void clear()
Definition AppsPage.cpp:150
Glib::RefPtr< Gtk::ListStore > m_store
Definition AppsPage.hpp:55
Gtk::Label m_headerLabel
Definition AppsPage.hpp:58
Gtk::TreeView m_treeView
Definition AppsPage.hpp:56
Columns m_columns
Definition AppsPage.hpp:54
Gtk::TreeModelColumn< Glib::ustring > col_name
Definition AppsPage.hpp:46
Gtk::TreeModelColumn< Glib::ustring > col_last_host
Definition AppsPage.hpp:49
Gtk::TreeModelColumn< Glib::ustring > col_last_verdict
Definition AppsPage.hpp:50
Gtk::TreeModelColumn< Glib::ustring > col_last_time
Definition AppsPage.hpp:51
Gtk::TreeModelColumn< Glib::ustring > col_path
Definition AppsPage.hpp:47
Gtk::TreeModelColumn< uint32_t > col_count
Definition AppsPage.hpp:48

References _, clear(), AppsPage::Columns::col_count, AppsPage::Columns::col_last_host, AppsPage::Columns::col_last_time, AppsPage::Columns::col_last_verdict, AppsPage::Columns::col_name, AppsPage::Columns::col_path, m_clearBtn, m_columns, m_headerLabel, m_scroll, m_store, and m_treeView.

Referenced by AppsPage().

◆ clear()

void AppsPage::clear ( )

Azzera la lista.

Definition at line 150 of file AppsPage.cpp.

151{
152 m_store->clear();
153 m_appRows.clear();
154}
std::unordered_map< std::string, Gtk::TreeModel::iterator > m_appRows
Definition AppsPage.hpp:62

References m_appRows, and m_store.

Referenced by buildUI().

◆ currentTimeString()

std::string AppsPage::currentTimeString ( )
staticprivate

Definition at line 93 of file AppsPage.cpp.

94{
95 std::time_t t = std::time(nullptr);
96 std::tm tm{};
97 ::localtime_r(&t, &tm);
98 std::ostringstream oss;
99 oss << std::put_time(&tm, "%H:%M:%S");
100 return oss.str();
101}

Referenced by noteConnection().

◆ displayNameFor()

std::string AppsPage::displayNameFor ( const ConnectionInfo & info)
staticprivate

Definition at line 103 of file AppsPage.cpp.

104{
106 info.app_comm, info.app_path, info.app_args, info.dest_ip, info.src_ip);
107}
std::string best_connection_display_name(const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args, const std::string &dst_ip, const std::string &src_ip)
std::string src_ip
Definition UIServer.hpp:35
std::string app_path
Definition UIServer.hpp:27
std::vector< std::string > app_args
Definition UIServer.hpp:30
std::string dest_ip
Definition UIServer.hpp:38
std::string app_comm
Definition UIServer.hpp:28

References ConnectionInfo::app_args, ConnectionInfo::app_comm, ConnectionInfo::app_path, bsc::ui_util::best_connection_display_name(), ConnectionInfo::dest_ip, and ConnectionInfo::src_ip.

Referenced by noteConnection().

◆ noteConnection()

void AppsPage::noteConnection ( const ConnectionInfo & info,
const std::string & verdict )

Registra una connessione nella vista per-app.

Definition at line 109 of file AppsPage.cpp.

110{
111 // Aggregazione per path completo: lo stesso binario eseguito due volte
112 // produce un'unica riga aggregata.
113 std::string key = info.app_path.empty() ? info.app_comm : info.app_path;
114 if (key.empty() && bsc::ui_util::is_safe_local_connection(info.dest_ip, info.src_ip)) {
115 key = "__bsc_safe_local_process__";
116 }
117 if (key.empty()) return;
118
119 const std::string host = !info.dest_host.empty() ? info.dest_host : info.dest_ip;
120 const std::string time_str = currentTimeString();
121
122 auto it = m_appRows.find(key);
123 if (it != m_appRows.end()) {
124 // Riga esistente: aggiorna contatore + ultimi valori
125 auto row = *(it->second);
126 const uint32_t count = row[m_columns.col_count];
127 row[m_columns.col_count] = count + 1;
128 row[m_columns.col_last_host] = host + ":" + std::to_string(info.dest_port);
129 row[m_columns.col_last_verdict] = verdict;
130 row[m_columns.col_last_time] = time_str;
131 return;
132 }
133
134 // Nuova riga
135 auto iter = m_store->append();
136 auto row = *iter;
137 row[m_columns.col_name] = displayNameFor(info);
138 row[m_columns.col_path] = info.app_path.empty()
140 ? std::string{"loopback/local"}
141 : std::string{})
142 : info.app_path;
143 row[m_columns.col_count] = 1u;
144 row[m_columns.col_last_host] = host + ":" + std::to_string(info.dest_port);
145 row[m_columns.col_last_verdict] = verdict;
146 row[m_columns.col_last_time] = time_str;
147 m_appRows.emplace(key, iter);
148}
static std::string currentTimeString()
Definition AppsPage.cpp:93
static std::string displayNameFor(const ConnectionInfo &info)
Definition AppsPage.cpp:103
bool is_safe_local_connection(const std::string &dst_ip, const std::string &src_ip)
std::string dest_host
Definition UIServer.hpp:37
uint32_t dest_port
Definition UIServer.hpp:39

References ConnectionInfo::app_comm, ConnectionInfo::app_path, AppsPage::Columns::col_count, AppsPage::Columns::col_last_host, AppsPage::Columns::col_last_time, AppsPage::Columns::col_last_verdict, AppsPage::Columns::col_name, AppsPage::Columns::col_path, currentTimeString(), ConnectionInfo::dest_host, ConnectionInfo::dest_ip, ConnectionInfo::dest_port, displayNameFor(), bsc::ui_util::is_safe_local_connection(), m_appRows, m_columns, m_store, and ConnectionInfo::src_ip.

Referenced by MainWindow::onDaemonAlert(), MainWindow::onNewConnection(), and MainWindow::onVerdict().

Member Data Documentation

◆ m_appRows

std::unordered_map<std::string, Gtk::TreeModel::iterator> AppsPage::m_appRows
private

Definition at line 62 of file AppsPage.hpp.

Referenced by clear(), and noteConnection().

◆ m_clearBtn

Gtk::Button AppsPage::m_clearBtn
private

Definition at line 59 of file AppsPage.hpp.

Referenced by buildUI().

◆ m_columns

Columns AppsPage::m_columns
private

Definition at line 54 of file AppsPage.hpp.

Referenced by buildUI(), and noteConnection().

◆ m_headerLabel

Gtk::Label AppsPage::m_headerLabel
private

Definition at line 58 of file AppsPage.hpp.

Referenced by buildUI().

◆ m_scroll

Gtk::ScrolledWindow AppsPage::m_scroll
private

Definition at line 57 of file AppsPage.hpp.

Referenced by buildUI().

◆ m_store

Glib::RefPtr<Gtk::ListStore> AppsPage::m_store
private

Definition at line 55 of file AppsPage.hpp.

Referenced by buildUI(), clear(), and noteConnection().

◆ m_treeView

Gtk::TreeView AppsPage::m_treeView
private

Definition at line 56 of file AppsPage.hpp.

Referenced by buildUI().


The documentation for this class was generated from the following files:
  • BastionGuard/thirdparty/bastionguard-secure-connection/ui/src/pages/AppsPage.hpp
  • BastionGuard/thirdparty/bastionguard-secure-connection/ui/src/pages/AppsPage.cpp