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

Functions

static std::string trim_copy (std::string s)
static std::string normalize_domain (std::string domain)
static std::string iso_today_yyyy_mm_dd ()
static void restart_cef_service_user ()

Function Documentation

◆ iso_today_yyyy_mm_dd()

std::string anonymous_namespace{BankPage.cpp}::iso_today_yyyy_mm_dd ( )
static

Definition at line 96 of file BankPage.cpp.

96 {
97 auto now = Glib::DateTime::create_now_local();
98 return now.format("%Y-%m-%d");
99}

References iso_today_yyyy_mm_dd().

Referenced by iso_today_yyyy_mm_dd().

◆ normalize_domain()

std::string anonymous_namespace{BankPage.cpp}::normalize_domain ( std::string domain)
static

Definition at line 56 of file BankPage.cpp.

56 {
57 domain = trim_copy(domain);
58 if (domain.empty()) return {};
59
60 auto pos = domain.find("://");
61 if (pos != std::string::npos)
62 domain.erase(0, pos + 3);
63
64 pos = domain.find('/');
65 if (pos != std::string::npos)
66 domain.erase(pos);
67
68 pos = domain.find('@');
69 if (pos != std::string::npos)
70 domain = domain.substr(pos + 1);
71
72 pos = domain.find(':');
73 if (pos != std::string::npos)
74 domain.erase(pos);
75
76 if (domain.rfind("www.", 0) == 0)
77 domain.erase(0, 4);
78
79 std::transform(domain.begin(), domain.end(), domain.begin(),
80 [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
81
82 if (!domain.empty() && domain.front() == '.')
83 domain.erase(domain.begin());
84
85 while (!domain.empty() && domain.back() == '.')
86 domain.pop_back();
87
88 domain = trim_copy(domain);
89
90 if (domain.empty()) return {};
91 if (domain.find('.') == std::string::npos) return {};
92
93 return domain;
94}
static std::string trim_copy(std::string s)
Definition BankPage.cpp:49

References normalize_domain(), and trim_copy().

Referenced by normalize_domain().

◆ restart_cef_service_user()

void anonymous_namespace{BankPage.cpp}::restart_cef_service_user ( )
static

Definition at line 101 of file BankPage.cpp.

101 {
102 int rc = (bg_process::run({"/usr/libexec/bastionguard/bastionguard-service", "--user", "restart", "BastionGuard-cef.service"}).exit_code);
103 if (rc == 0)
104 std::cout << _("[BankPage] ✔ BastionGuard-cef.service riavviato\n");
105 else
106 std::cerr << _("[BankPage] ⚠ Impossibile riavviare BastionGuard-cef.service\n");
107}
#define _(s)
Result run(const std::vector< std::string > &args, bool merge_stderr=false, std::size_t limit=8U *1024U *1024U, const std::map< std::string, std::string > &environment={}, const std::function< bool(const std::string &)> &on_line={})

References _, restart_cef_service_user(), and bg_process::run().

Referenced by restart_cef_service_user().

◆ trim_copy()

std::string anonymous_namespace{BankPage.cpp}::trim_copy ( std::string s)
static

Definition at line 49 of file BankPage.cpp.

49 {
50 auto l = s.find_first_not_of(" \t\r\n");
51 auto r = s.find_last_not_of(" \t\r\n");
52 if (l == std::string::npos) return {};
53 return s.substr(l, r - l + 1);
54}

References trim_copy().

Referenced by normalize_domain(), and trim_copy().