RulesPage

1. Overview

GTK rules-management page that loads daemon rule JSON files, presents editable action, duration, operand, data, and enabled state columns, and creates, updates, reloads, or removes protected rule files.

File role: Implementation. The file contains 665 lines and belongs to the pages/RulesPage.cpp path.

The companion file is pages/RulesPage.hpp.


2. Component Responsibilities

  • Implement the behavior declared by the corresponding header or entry-point contract.
  • Build combo-box models for rule action and duration
  • Enumerate JSON rule files from the system rules directory
  • Parse each rule into the tree model
  • Apply inline edits to JSON fields
  • Create new rule documents from a dialog
  • Write protected files through a temporary file and privileged install
  • Delete selected rules through pkexec
  • Refresh the displayed rule count

3. Dependencies and Integration

Project-level dependencies:

  • RulesPage.hpp
  • glibmm/i18n.h
  • glibmm/main.h
  • gtkmm/cellrenderercombo.h
  • gtkmm/cellrenderertoggle.h
  • gtkmm/dialog.h
  • gtkmm/entry.h
  • gtkmm/checkbutton.h
  • gtkmm/comboboxtext.h
  • gtkmm/grid.h
  • unistd.h

System and library dependencies:

  • cstdlib
  • filesystem
  • fstream
  • iostream
  • regex
  • sstream
  • memory

4. Constants and Fixed Configuration

The file declares or uses the following fixed values:

static const char* RULES_DIR = "/etc/bastionguard-secure-connectiond/rules/";

5. Signals and Event Integration

The file exposes or connects the following signal-related elements:

  • m_createBtn.signal_clicked().connect(
  • m_reloadBtn.signal_clicked().connect(
  • m_deleteBtn.signal_clicked().connect(
  • cell->signal_edited().connect(
  • cell->signal_toggled().connect(
  • closeBtn->signal_clicked().connect([&dialog]() {
  • dialog.signal_response().connect([&](int id) {

GTK-facing callbacks must execute on the main UI context. Components with worker threads use dispatchers or idle callbacks to cross the thread boundary.


6. Functions and Methods

The file exposes or implements 19 detected function or method signatures.

1. RulesPage

RulesPage::RulesPage() : Gtk::Box(Gtk::Orientation::VERTICAL, 0)

Implements the rules page operation declared by this component.

2. buildComboModels

void RulesPage::buildComboModels()

Builds and configures the combo models user-interface or internal structure.

3. buildToolbar

void RulesPage::buildToolbar()

Builds and configures the toolbar user-interface or internal structure.

4. buildTreeView

void RulesPage::buildTreeView()

Builds and configures the tree view user-interface or internal structure.

5. loadRules

void RulesPage::loadRules()

Loads rules from its persistent or runtime source.

6. jsonField

std::string RulesPage::jsonField(const std::string& json, const std::string& key)

Implements the json field operation declared by this component.

7. replaceJsonStringField

bool RulesPage::replaceJsonStringField(const std::string& filepath, const std::string& key, const std::string& value)

Implements the replace json string field operation declared by this component.

8. replaceJsonBoolField

bool RulesPage::replaceJsonBoolField(const std::string& filepath, const std::string& key, bool value)

Implements the replace json bool field operation declared by this component.

9. writeFileAsRoot

bool RulesPage::writeFileAsRoot(const std::string& filepath, const std::string& content)

Writes file as root to its destination.

10. createRuleFileAsRoot

bool RulesPage::createRuleFileAsRoot(const Rule& rule)

Creates rule file as root and initializes the resulting object or file.

11. makeSafeFilename

std::string RulesPage::makeSafeFilename(const std::string& input)

Creates or derives safe filename.

12. escapeJson

std::string RulesPage::escapeJson(const std::string& input)

Implements the escape json operation declared by this component.

13. onActionEdited

void RulesPage::onActionEdited(const Glib::ustring& path, const Glib::ustring& new_text)

Handles the action edited callback or user event.

14. onDurationEdited

void RulesPage::onDurationEdited(const Glib::ustring& path, const Glib::ustring& new_text)

Handles the duration edited callback or user event.

15. onDataEdited

void RulesPage::onDataEdited(const Glib::ustring& path, const Glib::ustring& new_text)

Handles the data edited callback or user event.

16. onEnabledToggled

void RulesPage::onEnabledToggled(const Glib::ustring& path)

Handles the enabled toggled callback or user event.

17. onCreateRule

void RulesPage::onCreateRule()

Handles the create rule callback or user event.

18. onDelete

void RulesPage::onDelete()

Handles the delete callback or user event.

19. updateCount

void RulesPage::updateCount()

Updates count using the latest runtime data.


7. Filesystem, IPC, Network, and Command Interfaces

Relevant literal paths, endpoints, or resource locations include:

  • /etc/bastionguard-secure-connectiond/rules/
  • /tmp/bsc-rule-edit-

Relevant command or protocol construction lines include:

"pkexec sh -c 'install -m 0644 \"" + tmpfile + "\" \"" + filepath + "\"'";
const std::string cmd = "pkexec rm -f \"" + std::string(path) + "\"";

8. Runtime Flow

  1. Build combo-box models for rule action and duration
  2. Enumerate JSON rule files from the system rules directory
  3. Parse each rule into the tree model
  4. Apply inline edits to JSON fields
  5. Create new rule documents from a dialog
  6. Write protected files through a temporary file and privileged install
  7. Delete selected rules through pkexec
  8. Refresh the displayed rule count

9. Runtime and Security Considerations

  • Sanitizes generated rule filenames.
  • Escapes JSON text before creating or updating documents.
  • Uses a temporary file and privileged install for protected rule paths.
  • Requires explicit user selection before deletion.
  • Privileged file or service modifications are delegated through pkexec.
  • JSON input and output must be treated as external data and validated before applying decisions.
  • Temporary paths are used; file naming, permissions, and replacement behavior form part of the privilege boundary.

10. Error Handling and Operational Notes

  • Diagnostic failures are written to standard error or the GLib logging channel.
  • Boolean-returning operations use false to report recoverable failure.

11. Source Integrity

Relative source path: pages/RulesPage.cpp

SHA-256:

5aa28442152886c254ce3668ddae1acd1c7937512bcd28a4177d31a3a4877870

12. Licensing

The source header identifies this component as distributed under the GNU General Public License version 3. BastionGuard branding and trademarks remain subject to the notices stated in the source file.