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: Header Interface. The file contains 100 lines and belongs to the pages/RulesPage.hpp path.
The companion file is pages/RulesPage.cpp.
2. Component Responsibilities
- Declare the component API, owned state, callbacks, and data structures.
- 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:
gtkmm.h
System and library dependencies:
string
4. Declared Types
RulesPage
Declares a class derived from or associated with public Gtk::Box.
Columns
Declares a struct derived from or associated with public Gtk::TreeModel::ColumnRecord.
ComboColumns
Declares a struct derived from or associated with public Gtk::TreeModel::ColumnRecord.
Rule
Declares a struct.
5. Owned State and UI Members
User-interface members
Gtk::TreeModelColumn<Glib::ustring> col_name;Gtk::TreeModelColumn<Glib::ustring> col_action;Gtk::TreeModelColumn<Glib::ustring> col_duration;Gtk::TreeModelColumn<Glib::ustring> col_operand;Gtk::TreeModelColumn<Glib::ustring> col_data;Gtk::TreeModelColumn<bool> col_enabled;Gtk::TreeModelColumn<Glib::ustring> col_filepath;Gtk::TreeModelColumn<Glib::ustring> col_value;Glib::RefPtr<Gtk::ListStore> m_actionModel;Glib::RefPtr<Gtk::ListStore> m_durationModel;Glib::RefPtr<Gtk::ListStore> m_store;Gtk::TreeView m_treeView;Gtk::ScrolledWindow m_scroll;Gtk::Box m_toolbar { Gtk::Orientation::HORIZONTAL, 6 };Gtk::Button m_createBtn;Gtk::Button m_reloadBtn;Gtk::Button m_deleteBtn;Gtk::Label m_countLabel;
Data and configuration state
Columns m_columns;ComboColumns m_comboColumns;std::string name;std::string action;std::string duration;std::string operand;std::string data;bool enabled = true;std::string filepath;
6. Functions and Methods
The file exposes or implements 20 detected function or method signatures.
1. RulesPage
RulesPage()
Implements the rules page operation declared by this component.
2. replaceJsonStringField
bool replaceJsonStringField(const std::string& filepath, const std::string& key, const std::string& value)
Implements the replace json string field operation declared by this component.
3. replaceJsonBoolField
bool replaceJsonBoolField(const std::string& filepath, const std::string& key, bool value)
Implements the replace json bool field operation declared by this component.
4. writeFileAsRoot
bool writeFileAsRoot(const std::string& filepath, const std::string& content)
Writes file as root to its destination.
5. createRuleFileAsRoot
bool createRuleFileAsRoot(const Rule& rule)
Creates rule file as root and initializes the resulting object or file.
6. escapeJson
std::string escapeJson(const std::string& input)
Implements the escape json operation declared by this component.
7. makeSafeFilename
std::string makeSafeFilename(const std::string& input)
Creates or derives safe filename.
8. onActionEdited
void onActionEdited(const Glib::ustring& path, const Glib::ustring& new_text)
Handles the action edited callback or user event.
9. onDurationEdited
void onDurationEdited(const Glib::ustring& path, const Glib::ustring& new_text)
Handles the duration edited callback or user event.
10. onDataEdited
void onDataEdited(const Glib::ustring& path, const Glib::ustring& new_text)
Handles the data edited callback or user event.
11. onEnabledToggled
void onEnabledToggled(const Glib::ustring& path)
Handles the enabled toggled callback or user event.
12. buildComboModels
void buildComboModels()
Builds and configures the combo models user-interface or internal structure.
13. buildToolbar
void buildToolbar()
Builds and configures the toolbar user-interface or internal structure.
14. buildTreeView
void buildTreeView()
Builds and configures the tree view user-interface or internal structure.
15. loadRules
void loadRules()
Loads rules from its persistent or runtime source.
16. parseRule
Rule parseRule(const std::string& filepath)
Parses rule into a structured representation.
17. jsonField
std::string jsonField(const std::string& json, const std::string& key)
Implements the json field operation declared by this component.
18. onCreateRule
void onCreateRule()
Handles the create rule callback or user event.
19. onDelete
void onDelete()
Handles the delete callback or user event.
20. updateCount
void updateCount()
Updates count using the latest runtime data.
7. Runtime Flow
- 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
8. 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.
- JSON input and output must be treated as external data and validated before applying decisions.
9. Error Handling and Operational Notes
- Errors are propagated through the return type, callbacks, or the owning controller.
10. Source Integrity
Relative source path: pages/RulesPage.hpp
SHA-256:
18be50537e518bb1f1e71b474f6d1a380c47059feaf849d905704671fc5c23ab
11. 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.
