Skip to content

Use set_config_option(), bound values and cacti_escapeshellarg() in the remaining hand-built calls - #103

Merged
somethingwithproof merged 6 commits into
developfrom
fix/idiomatic-core-api
Dec 3, 2026
Merged

somethingwithproof merged 6 commits into
developfrom
fix/idiomatic-core-api

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Intent: replace the remaining hand-built settings writes, SQL with values pasted into the text, and unquoted CLI arguments with the core APIs available at the plugin's 1.2.25 floor. Fixes #102.

Scope: poller_hmib.php, poller_graphs.php, setup.php, hmib.php, hmib_types.php. Settings run times and statistics go through set_config_option(). Values are bound in the summary device lookups, the rescan cleanup, the Devices tab graph count, the batch-name filter, the system collector update, hmib_update_summaries(), the plugin_config refresh and the script server hooks. The processor position in hmib_get_cpu() is a LIMIT offset that cannot be bound, so it must be a plain number. Graph automation quotes every id it passes to the core CLI scripts. The CLI scripts are kept rather than calling api_device_save() or run_data_query() directly, because add_device.php fills about 30 defaults from settings and poller_reindex_hosts.php holds the core reindex lock. The Poll Now rows in includes/health.php stay direct settings writes because they are cross-process state that must not go through the settings cache.

Risk: low. The stored values and command lines are unchanged for valid input. A malformed script server argument now matches nothing or returns 0 instead of raising an SQL error.

Verification (local, PHP 8.5, MariaDB 11.8, Cacti 1.2.x, snmpd): full Pest suite, which includes new unit, integration (real MariaDB) and end-to-end tests. The end-to-end tests run poller_hmib.php and poller_graphs.php as subprocesses and serve the pages through php -S. The changed-line coverage gate also ran. Hosted CI has not run yet.

somethingwithproof and others added 6 commits December 2, 2026 18:29
The main run, the autodiscovery scan and the graph automation stored their
last run times and the run statistics with hand-built REPLACE INTO settings
statements. Use set_config_option() instead, so the values are bound and the
process's settings cache stays current. Nothing re-reads these settings in
the same process, and no caller depends on bypassing the cache.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ipts

The template, device and data query ids handed to add_device.php,
poller_reindex_hosts.php and add_graphs.php now go through
cacti_escapeshellarg() like the data query field and value already did.
The ids are integers, so the arguments the scripts receive do not change.
The CLI scripts stay: add_device.php fills its defaults from the settings and
poller_reindex_hosts.php holds the core reindex lock, which a direct
api_device_save() or run_data_query() call would not.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Bind the summary device lookups of the graph automation, the placeholder
type cleanup of the OS type rescan, the graph count on the Devices tab, the
batch job filter and the system collector update of the worker, the device
filter of the summary update, the plugin_config refresh and the device id
and index of the script server hooks. The processor position of
hmib_get_cpu() is a LIMIT offset, which cannot be bound, so anything but a
plain number answers 0 as the SQL error it caused before did.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Unit tests check the bound parameters and the quoted add_graphs.php command
lines, and run a data query value with shell characters through a stand-in
PHP binary. Integration tests run the script server hooks, the system
collector and the summary update against MariaDB with values shaped like
SQL. End-to-end tests record the arguments the pollers hand to the core CLI
scripts and the settings rows a main run and the graph automation leave.
The set_config_option() stub takes core's signature and updates the
settings a later read_config_option() returns.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@somethingwithproof
somethingwithproof merged commit 3f61e5d into develop Dec 3, 2026
7 checks passed
@somethingwithproof
somethingwithproof deleted the fix/idiomatic-core-api branch December 3, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the core settings, prepared statement and shell escaping APIs in the remaining hand-built calls

3 participants