From 7279a3d293738d61f5e43869e482db2387a5128a Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 8 Oct 2026 14:48:05 -0400 Subject: [PATCH 1/3] bug: pass bool (not int) to api_plugin_register_hook() enable argument Cacti 1.3 types api_plugin_register_hook() 5th arg as bool enable. These calls passed int 1, which only coerces while the file lacks declare(strict_types=1); pass true so they stay type-correct. php -l clean. --- CHANGELOG.md | 1 + includes/database.php | 4 ++-- setup.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f5737e3..05d8ed4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## ChangeLog --- develop --- +* bug: Pass a boolean (not the integer `1`) to `api_plugin_register_hook()`'s `$enable` argument so the hook registration stays type-correct under Cacti 1.3's strict `bool $enable` type-hint (the int only coerces while this file lacks `declare(strict_types=1)`) * security: Replace the confirmation pages' inline `onClick='cactiReturnTo()'` Cancel buttons with the CSP-safe `cactiReturnTo` class so they no longer trip Cacti's Content-Security-Policy `script-src-attr` directive * security: Move the filter controls' inline `onChange`/`onClick` handlers into jQuery `ready()` event bindings on the threshold, notification list, notification queue, template and device/log status pages so they no longer trip Cacti's Content-Security-Policy `script-src-attr` directive * dev: Remove the inert COMPOSER_ROOT_VERSION env from the Pest CI step diff --git a/includes/database.php b/includes/database.php index 8c270b5d..02861c4c 100644 --- a/includes/database.php +++ b/includes/database.php @@ -1815,8 +1815,8 @@ function thold_upgrade_database($force = false) { db_execute('ALTER TABLE thold_data MODIFY COLUMN name varchar(255) NOT NULL default ""'); - api_plugin_register_hook('thold', 'device_template_change', 'thold_device_template_change', 'setup.php', 1); - api_plugin_register_hook('thold', 'settings_bottom', 'thold_settings_bottom', 'setup.php', 1); + api_plugin_register_hook('thold', 'device_template_change', 'thold_device_template_change', 'setup.php', true); + api_plugin_register_hook('thold', 'settings_bottom', 'thold_settings_bottom', 'setup.php', true); api_plugin_register_realm('thold', 'notify_lists.php,notify_queue.php', 'Manage Notification Lists', 1); diff --git a/setup.php b/setup.php index 074dd48f..35f83623 100644 --- a/setup.php +++ b/setup.php @@ -118,7 +118,7 @@ function plugin_thold_install($upgrade = false) { api_plugin_register_hook($plugin, 'api_device_new', 'thold_api_device_new', 'setup.php'); // Allow settings javascript hooks - api_plugin_register_hook('thold', 'settings_bottom', 'thold_settings_bottom', 'setup.php', 1); + api_plugin_register_hook('thold', 'settings_bottom', 'thold_settings_bottom', 'setup.php', true); // Miscellaneous hooks api_plugin_register_hook($plugin, 'graphs_new_top_links', 'thold_graphs_new', 'setup.php'); From 59aad4adf40084158884938bac979611dcaa0c6c Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 8 Oct 2026 15:00:48 -0400 Subject: [PATCH 2/3] Exclude live-DB reinstall body of plugin_thold_install() from coverage --- setup.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup.php b/setup.php index 35f83623..1bc0edfe 100644 --- a/setup.php +++ b/setup.php @@ -51,6 +51,11 @@ function plugin_thold_install($upgrade = false) { return false; } + // The reinstall below registers the plugin's hooks/realms and provisions + // its schema against a live Cacti database (include_once database.php plus + // thold_setup_database()/thold_upgrade_database()), so it cannot run in the + // isolated unit process. + // @codeCoverageIgnoreStart $plugin = 'thold'; // Insert CSS and JavaScript @@ -146,6 +151,7 @@ function plugin_thold_install($upgrade = false) { thold_setup_database(); thold_snmpagent_cache_install(); } + // @codeCoverageIgnoreEnd } /** From 47ea825d5dc98bed1845a58af1c9bbf753ff056b Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 8 Oct 2026 15:11:01 -0400 Subject: [PATCH 3/3] bug: pass bool true (not string '1') at remaining register-hook upgrade sites Convert the 17 other api_plugin_register_hook() 5th arguments in includes/database.php from the string '1' to boolean true so the upgrade/re-registration paths are strict_types-safe against Cacti develop's bool \ signature. --- includes/database.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/includes/database.php b/includes/database.php index 02861c4c..b5d7b634 100644 --- a/includes/database.php +++ b/includes/database.php @@ -250,14 +250,14 @@ function thold_upgrade_database($force = false) { AND hook = "poller_bottom"'); // Register the new hooks - api_plugin_register_hook('thold', 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php', '1'); - api_plugin_register_hook('thold', 'graph_buttons', 'thold_graph_button', 'setup.php', '1'); - api_plugin_register_hook('thold', 'data_source_action_array', 'thold_data_source_action_array', 'setup.php', '1'); - api_plugin_register_hook('thold', 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php', '1'); - api_plugin_register_hook('thold', 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php', '1'); - api_plugin_register_hook('thold', 'graphs_action_array', 'thold_graphs_action_array', 'setup.php', '1'); - api_plugin_register_hook('thold', 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php', '1'); - api_plugin_register_hook('thold', 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php', '1'); + api_plugin_register_hook('thold', 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php', true); + api_plugin_register_hook('thold', 'graph_buttons', 'thold_graph_button', 'setup.php', true); + api_plugin_register_hook('thold', 'data_source_action_array', 'thold_data_source_action_array', 'setup.php', true); + api_plugin_register_hook('thold', 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php', true); + api_plugin_register_hook('thold', 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php', true); + api_plugin_register_hook('thold', 'graphs_action_array', 'thold_graphs_action_array', 'setup.php', true); + api_plugin_register_hook('thold', 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php', true); + api_plugin_register_hook('thold', 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php', true); // Fix our realms db_execute('UPDATE plugin_realms @@ -275,8 +275,8 @@ function thold_upgrade_database($force = false) { db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_insert"'); db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_arrays"'); - api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php', '1'); - api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php', '1'); + api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php', true); + api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php', true); api_plugin_enable_hooks('thold'); @@ -544,7 +544,7 @@ function thold_upgrade_database($force = false) { db_execute('ALTER TABLE thold_template DROP COLUMN bl_enabled', false); } - api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php', '1'); + api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php', true); api_plugin_register_realm('thold', 'notify_lists.php', 'Manage Notification Lists', 1); // set unique hash values for all thold templates @@ -781,10 +781,10 @@ function thold_upgrade_database($force = false) { $data['comment'] = 'Table of Device Template Threshold Templates'; api_plugin_db_table_create('thold', 'plugin_thold_host_template', $data); - api_plugin_register_hook('thold', 'device_template_edit', 'thold_device_template_edit', 'setup.php', '1'); - api_plugin_register_hook('thold', 'device_template_top', 'thold_device_template_top', 'setup.php', '1'); - api_plugin_register_hook('thold', 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php', '1'); - api_plugin_register_hook('thold', 'api_device_new', 'thold_api_device_new', 'setup.php', '1'); + api_plugin_register_hook('thold', 'device_template_edit', 'thold_device_template_edit', 'setup.php', true); + api_plugin_register_hook('thold', 'device_template_top', 'thold_device_template_top', 'setup.php', true); + api_plugin_register_hook('thold', 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php', true); + api_plugin_register_hook('thold', 'api_device_new', 'thold_api_device_new', 'setup.php', true); api_plugin_register_hook('thold', 'page_head', 'thold_page_head', 'setup.php'); if (api_plugin_is_enabled('thold')) { @@ -2107,8 +2107,8 @@ function thold_setup_database() { $data['comment'] = 'Table of Notification Lists'; api_plugin_db_table_create('thold', 'plugin_notification_lists', $data); - api_plugin_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php', '1'); - api_plugin_register_hook('thold', 'device_top', 'thold_device_top', 'setup.php', '1'); + api_plugin_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php', true); + api_plugin_register_hook('thold', 'device_top', 'thold_device_top', 'setup.php', true); api_plugin_db_add_column('thold', 'host', ['name' => 'thold_send_email', 'type' => 'int(10)', 'NULL' => false, 'default' => '1', 'after' => 'disabled']); api_plugin_db_add_column('thold', 'host', ['name' => 'thold_host_email', 'type' => 'int(10)', 'NULL' => true, 'after' => 'thold_send_email']);