Repository navigation
Use set_config_option(), bound values and cacti_escapeshellarg() in the remaining hand-built calls - #103
Merged
Conversation
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>
…-api # Conflicts: # CHANGELOG.md
|
TheWitness
approved these changes
Dec 3, 2026
xmacan
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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 throughset_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(), theplugin_configrefresh and the script server hooks. The processor position inhmib_get_cpu()is aLIMIToffset 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 callingapi_device_save()orrun_data_query()directly, becauseadd_device.phpfills about 30 defaults from settings andpoller_reindex_hosts.phpholds the core reindex lock. The Poll Now rows inincludes/health.phpstay directsettingswrites 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.phpandpoller_graphs.phpas subprocesses and serve the pages throughphp -S. The changed-line coverage gate also ran. Hosted CI has not run yet.