Skip to content
API Documentation
BastionGuard™
anonymous_namespace{MainWindow.cpp} Namespace Reference

Functions

std::optional< bool > queryScreensaverActiveOnce (const char *bus_name, const char *object_path, const char *interface_name)
std::optional< bool > queryScreensaverActive ()
std::string autostartDesktopContent ()
bool writeServiceControlPreference (bool enabled, const std::string &backupFile)
bool writeConfigAutostartDesktop (const std::filesystem::path &path)
std::string shellQuote (const std::string &s)
bool runCommand (const std::string &cmd)
std::string firstExistingPath (const std::initializer_list< std::string > &candidates)
std::string displayNameForStatus (const ConnectionInfo &info)

Variables

constexpr int kNotifDesktopActive = 15
constexpr int kNotifDesktopIdle = 16
constexpr const char * kUISocketPath = "unix:///tmp/bsd-daemon.sock"
constexpr const char * kServiceName = "bsc-daemon.service"
constexpr const char * kServiceCtlPath = BSC_SERVICECTL_PATH
constexpr const char * kSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop"
constexpr const char * kFallbackSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc.desktop"
constexpr const char * kSystemAutostartBackupDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop.bak"

Function Documentation

◆ autostartDesktopContent()

std::string anonymous_namespace{MainWindow.cpp}::autostartDesktopContent ( )

Definition at line 104 of file MainWindow.cpp.

105 {
106 return std::string(
107 "[Desktop Entry]\n"
108 "Name=BastionGuard Secure Connection\n"
109 "Name[it]=BastionGuard Connessione Sicura\n"
110 "Comment=Interactive application firewall\n"
111 "Comment[it]=Firewall applicativo interattivo\n"
112 "Exec=bastionguard-sc-ui --start-minimized\n"
113 "Icon=/usr/share/bastionguard-sc/data/logo.svg\n"
114 "Terminal=false\n"
115 "Type=Application\n"
116 "Categories=Network;Security;System;\n"
117 "Keywords=firewall;network;security;connection;\n"
118 "StartupNotify=true\n");
119 }

References autostartDesktopContent().

Referenced by autostartDesktopContent(), and writeConfigAutostartDesktop().

◆ displayNameForStatus()

std::string anonymous_namespace{MainWindow.cpp}::displayNameForStatus ( const ConnectionInfo & info)

Definition at line 181 of file MainWindow.cpp.

182 {
184 info.app_comm, info.app_path, info.app_args, info.dest_ip, info.src_ip);
185 }
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, displayNameForStatus(), and ConnectionInfo::src_ip.

Referenced by displayNameForStatus().

◆ firstExistingPath()

std::string anonymous_namespace{MainWindow.cpp}::firstExistingPath ( const std::initializer_list< std::string > & candidates)

Definition at line 173 of file MainWindow.cpp.

174 {
175 for (const auto& p : candidates) {
176 if (std::filesystem::exists(p)) return p;
177 }
178 return {};
179 }

References firstExistingPath().

Referenced by firstExistingPath().

◆ queryScreensaverActive()

std::optional< bool > anonymous_namespace{MainWindow.cpp}::queryScreensaverActive ( )

Definition at line 74 of file MainWindow.cpp.

75 {
76 struct Candidate {
77 const char* bus;
78 const char* path;
79 const char* iface;
80 };
81
82 static constexpr Candidate candidates[] = {
83 {"org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver"},
84 {"org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver"},
85 {"org.cinnamon.ScreenSaver", "/org/cinnamon/ScreenSaver", "org.cinnamon.ScreenSaver"},
86 {"org.mate.ScreenSaver", "/org/mate/ScreenSaver", "org.mate.ScreenSaver"},
87 };
88
89 for (const auto& c : candidates) {
90 if (auto v = queryScreensaverActiveOnce(c.bus, c.path, c.iface))
91 return v;
92 }
93 return std::nullopt;
94 }
std::optional< bool > queryScreensaverActiveOnce(const char *bus_name, const char *object_path, const char *interface_name)

References queryScreensaverActive(), and queryScreensaverActiveOnce().

Referenced by queryScreensaverActive().

◆ queryScreensaverActiveOnce()

std::optional< bool > anonymous_namespace{MainWindow.cpp}::queryScreensaverActiveOnce ( const char * bus_name,
const char * object_path,
const char * interface_name )

Definition at line 37 of file MainWindow.cpp.

40 {
41 GError* error = nullptr;
42 GDBusConnection* conn = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error);
43 if (!conn) {
44 if (error) g_error_free(error);
45 return std::nullopt;
46 }
47
48 GVariant* reply = g_dbus_connection_call_sync(
49 conn,
50 bus_name,
51 object_path,
52 interface_name,
53 "GetActive",
54 nullptr,
55 G_VARIANT_TYPE("(b)"),
56 G_DBUS_CALL_FLAGS_NONE,
57 180,
58 nullptr,
59 &error);
60
61 g_object_unref(conn);
62
63 if (!reply) {
64 if (error) g_error_free(error);
65 return std::nullopt;
66 }
67
68 gboolean active = FALSE;
69 g_variant_get(reply, "(b)", &active);
70 g_variant_unref(reply);
71 return active == TRUE;
72 }

References queryScreensaverActiveOnce().

Referenced by queryScreensaverActive(), and queryScreensaverActiveOnce().

◆ runCommand()

bool anonymous_namespace{MainWindow.cpp}::runCommand ( const std::string & cmd)

Definition at line 167 of file MainWindow.cpp.

168 {
169 const int rc = std::system(cmd.c_str());
170 return rc == 0;
171 }

References runCommand().

Referenced by runCommand().

◆ shellQuote()

std::string anonymous_namespace{MainWindow.cpp}::shellQuote ( const std::string & s)

Definition at line 156 of file MainWindow.cpp.

157 {
158 std::string out = "'";
159 for (char c : s) {
160 if (c == '\'') out += "'\\''";
161 else out += c;
162 }
163 out += "'";
164 return out;
165 }

References shellQuote().

Referenced by shellQuote().

◆ writeConfigAutostartDesktop()

bool anonymous_namespace{MainWindow.cpp}::writeConfigAutostartDesktop ( const std::filesystem::path & path)

Definition at line 144 of file MainWindow.cpp.

145 {
146 try {
147 std::filesystem::create_directories(path.parent_path());
148 std::ofstream out(path, std::ios::trunc);
150 return static_cast<bool>(out);
151 } catch (...) {
152 return false;
153 }
154 }

References autostartDesktopContent(), and writeConfigAutostartDesktop().

Referenced by writeConfigAutostartDesktop().

◆ writeServiceControlPreference()

bool anonymous_namespace{MainWindow.cpp}::writeServiceControlPreference ( bool enabled,
const std::string & backupFile )

Definition at line 121 of file MainWindow.cpp.

122 {
123 try {
124 const std::filesystem::path cfgDir =
125 std::filesystem::path(Glib::get_user_config_dir()) / "bastionguard-sc";
126 std::filesystem::create_directories(cfgDir);
127
128 std::ofstream out(cfgDir / "service-control.ini", std::ios::trunc);
129 out << "[ServiceControl]\n";
130 out << "enabled=" << (enabled ? "true" : "false") << "\n";
131 out << "autostart_enabled=" << (enabled ? "true" : "false") << "\n";
132 out << "daemon_enabled=" << (enabled ? "true" : "false") << "\n";
133 out << "service=" << kServiceName << "\n";
134 out << "autostart_path=" << kSystemAutostartDesktop << "\n";
135 out << "fallback_autostart_path=" << kFallbackSystemAutostartDesktop << "\n";
136 out << "generated_autostart_file=" << (cfgDir / "bastionguard-sc-autostart.desktop").string() << "\n";
137 out << "backup_path=" << backupFile << "\n";
138 return static_cast<bool>(out);
139 } catch (...) {
140 return false;
141 }
142 }
constexpr const char * kSystemAutostartDesktop
constexpr const char * kFallbackSystemAutostartDesktop
constexpr const char * kServiceName

References kFallbackSystemAutostartDesktop, kServiceName, kSystemAutostartDesktop, and writeServiceControlPreference().

Referenced by writeServiceControlPreference().

Variable Documentation

◆ kFallbackSystemAutostartDesktop

const char* anonymous_namespace{MainWindow.cpp}::kFallbackSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc.desktop"
constexpr

Definition at line 101 of file MainWindow.cpp.

Referenced by writeServiceControlPreference().

◆ kNotifDesktopActive

int anonymous_namespace{MainWindow.cpp}::kNotifDesktopActive = 15
constexpr

Definition at line 34 of file MainWindow.cpp.

◆ kNotifDesktopIdle

int anonymous_namespace{MainWindow.cpp}::kNotifDesktopIdle = 16
constexpr

Definition at line 35 of file MainWindow.cpp.

◆ kServiceCtlPath

const char* anonymous_namespace{MainWindow.cpp}::kServiceCtlPath = BSC_SERVICECTL_PATH
constexpr

Definition at line 99 of file MainWindow.cpp.

◆ kServiceName

const char* anonymous_namespace{MainWindow.cpp}::kServiceName = "bsc-daemon.service"
constexpr

Definition at line 98 of file MainWindow.cpp.

Referenced by writeServiceControlPreference().

◆ kSystemAutostartBackupDesktop

const char* anonymous_namespace{MainWindow.cpp}::kSystemAutostartBackupDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop.bak"
constexpr

Definition at line 102 of file MainWindow.cpp.

◆ kSystemAutostartDesktop

const char* anonymous_namespace{MainWindow.cpp}::kSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop"
constexpr

Definition at line 100 of file MainWindow.cpp.

Referenced by writeServiceControlPreference().

◆ kUISocketPath

const char* anonymous_namespace{MainWindow.cpp}::kUISocketPath = "unix:///tmp/bsd-daemon.sock"
constexpr

Definition at line 96 of file MainWindow.cpp.