* fix(script-server): keep each response on one line
script_server.php buffered only the include of a script file, so a data
source function that printed anything wrote it to the poller ahead of its
result, and a result containing a line break was written as several
lines. spine and cmd.php read one line per request, so either case
shifted every later reply on that server by one.
Buffer the function call and discard its output, closing the buffer even
when the function throws and logging only the size of what was dropped at
debug verbosity, since the output can carry credentials. Replace line
breaks in the result with spaces before writing it, which keeps a
multipart name:value result intact.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(script-server): print parse errors only when debugging
parseArgs() printed an ERROR line to STDOUT when a request could not be
parsed, and the caller then answered U, so the poller read the error as
the reply to that request and the U as the reply to the next one. Print
the error only when debugging, as 1.2.x already does.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(script-server): log an unparsable argument list by size only
When a request could not be parsed, the warning logged the raw argument
string, which can carry device credentials. Log its size instead, as
1.2.x already does.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(script-server): mask device credentials in logged arguments
The debug request log and the missing function warning wrote the script
arguments as given, and the signal handler logged the raw argument
string, so device SNMP credentials passed to a script reached the log.
Mask every argument, and every colon separated field of one, that
matches a configured device credential, and log only the argument count
from the signal handler, as 1.2.x already does.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(poller): mask device credentials in cmd.php script logs
cmd.php logged script and Script Server commands as given, and those
commands carry the device SNMP credentials. Mask each credential, in
every form cacti_escapeshellarg() and cacti_escapeshellarg_cmd() can
write it, before the command is logged, as 1.2.x already does.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(poller): define the Script Server pipes before cmd.php uses them
$pipes was only ever set by proc_open(), so PHPStan reported it as
possibly undefined where cmd.php closes the Script Server pipes. Start
it as an empty array, which is what every path that does not open the
Script Server already relies on.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(poller): mask device credentials in cmd.php recache logs
The recache checks logged each reindex command as given, and a data
query script or Script Server command carries the device SNMP
credentials. Mask them with the device's credentials before logging,
as the data source logs already do.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* docs(changelog): note the Script Server response and logging fixes
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test(poller): cover the win32 forms of masked cmd.php credentials
CACTI_SERVER_OS is a constant, so the unit suite only ever builds the
unix forms of cacti_escapeshellarg() and cacti_escapeshellarg_cmd().
Build the win32 forms in a separate process and check that
poller_redact_snmp_secrets() masks each one, including the colon
separated SNMPv3 field, as the 1.2.x tests do.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* docs(changelog): number the Script Server entries with issue#8596
The CHANGELOG check requires every new entry to carry an issue or
pull-request number. Both entries come from issue#8596, which sorts
after issue#8480 at the end of the issue group.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test(poller): give the changed-line coverage gate the masking evidence
The unit tests load the Script Server, poller and cmd.php functions
from temporary source slices, which the unit coverage report cannot
attribute to the real files, so the 80 percent changed-line gate saw
13 of 96 lines. Add a request-coverage probe that runs the same
functions at their original line numbers with checked results, and
dispatch it when cmd.php, script_server.php or lib/poller.php change.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(poller): store the first line of script output, as 1.2.x does
exec_poll() returned the line exec_with_timeout() reports, which is
the last one. A script that ends its output with a newline, as most
do, left that line empty, so cmd.php stored U for every such data
source and recache check. Return the first line instead, which is
what 1.2.x reads with fgets() and what every caller trims and stores.
exec_with_timeout() keeps its contract for its other caller.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(poller): mask device credentials when a failing script is logged
When a script exits with an error, exec_poll() logs the command and
its output, and exec_with_timeout() logs the command and its stderr. A
script data source command carries the device SNMP credentials, and
the script can echo them. exec_poll() now takes the poller item and
masks its credentials in both warnings; exec_with_timeout() takes an
optional mask for its warning, so lib/reports.php logs as before. The
masking runs only when a failure is logged. cmd.php, cmd_realtime.php
and remote_agent.php pass the item.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* docs(changelog): note the script output and failure warning fixes
Add issue#8676 entries for the first-line script output fix and the
masking of credentials in failing-script warnings, after the
issue#8596 entries at the end of the issue group.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test(poller): share the cmd.php device stand-ins between test and fixture
The cmd.php log masking test and its request-coverage fixture each
declared the same database, ping, SNMP and Script Server stand-ins.
Move them into tests/Helpers/CmdDeviceStubs.php and load both in its
namespace. The test also checks that each reply is logged with its
SCRIPT or SERVER label.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* refactor(poller): share one cmd.php path for script and Script Server replies
The script and Script Server cases of collect_device_data() repeated
the same validation and logging, differing only in how the reply is
read and in the SCRIPT or SERVER log label. Read the reply per action
and run the shared validation and logging once. The log lines and the
error data sources are unchanged.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
---------
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* style(php): wrap CLI and poller calls without changing execution
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(ci): review security inventories after poller wrapping
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test(boost): compare handoff source contracts by PHP tokens
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* style(php): wrap poller constant strings without changing values
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* style(php): wrap poller concatenations with token-preserving source contracts
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test(cli): assert CDEF repair queries after constant folding
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* test: verify PHP formatting preserves parsed behavior
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
---------
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix: harden CSV encoding and process execution handling
Route CSV export cells through a shared cacti_csv_cell() helper so values with quotes, commas, or leading formula characters round-trip correctly, and add defensive guards on shell construction, unchecked proc_open handles, discarded exec exit codes, and gap values in nth-percentile fetch math.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix: address review feedback on CSV and process hardening
- escape poller_id in cmd_realtime proc_open command to match remote_agent
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix: keep numeric CSV cells unquoted and guard snmptrap and rrdtool process failures
- exempt numeric values from the CSV formula-injection prefix and preserve empty snmptrap positions while bailing out when the RRDtool process fails to spawn
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* ci: ignore phpstan function.alreadyNarrowedType identifier
Clears the level 6 alreadyNarrowedType error on lib/data_query.php:2591 that
develop currently emits, matching the sibling narrowing identifiers already ignored.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
---------
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
* fix: preserve realtime poller session token
* ci(phpstan): baseline upstream undefined-variable and isset errors
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
* fix(test): escape $poller_id in double-quoted toContain string
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
---------
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
* Fix#6539 - Allow Standard Cacti Log Files to be Rotated on Demand from the Cacti UI
* QA: php-cs-fixer updates and documentation for lib/database.php
* QA: Update .gitignore for composer files
* QA: Update .gitignore for composer files
* QA: Back off .gitignore change its duplicated
* QA: Fix typing of db_has_permissions
* QA: Fixing typing issue in db_format_index_create
* Update lib/clog_webapi.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* QA: Fix additional code issues
* QA: Applying more defaults to add device
* QA: Fix at the database layer
* QA: Fixes based upon automated testing
* QA: Fix at the database layer
* QA: After new SQL checking
* QA: Skip MacTrack oui database download warnings
* QA: Fixing type issue
* QA: Recommendation from Copilot
* QA: Recommendation from Copilot
* QA: Recommendation from Copilot
* QA: Recommendation from Copilot
* QA: Some minor changes to avoid errors in testing
* QA: Unused variable
* QA: Recommendation from Copilot
* QA: Recommendation from Copilot
* QA: Recommendation from Copilot
* QA: Minor introduced code defect
* QA: Adding some unifying space around concatination
* QA: Consistent comments and new function alias'
* QA: Multi-line comment corrections
* QA: Fix SQL Style
* QA: Missed one function alias
* QA: PHPStan Level 2 and PHPDoc fixes
* QA: PHPStan Level 2 and PHPDoc Fixes
* QA: PHPStan Level 6 Fixes
* QA: Fix lib/xml.php to PHPStan Level 6
* QA: Wrong grep -v
* PHPStan Level 6 for lib/vdef.php
* PHPStan Level 8 for lib/time.php
* QA: Raise PHPStan to Level 6 for lib/database.php
* QA: Remove @deprecated tag from grv()
* QA: Switch to htmle() alias over html_escape()
* QA: More addressing PHPStan issues at Level 6
* QA: Change recommended by Copilot for Readability
* QA: More PHPStan fixes
* QA: More PHPStan fixes
* QA: More PHPStan fixes for lib/utility.php
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: Raise PHPStan to Level 6 More Functions
* QA: More PHPStan fixes at Level 6
* QA: Some phpseclib3 fixups to update to latest
* QA: More fixups for graphing for magic strings
* QA: More PHPStan fixes at Level 6
* QA: Fixing order string type on get_allowed_graphs()
* QA: Fixing improper use of print
* QA: Optimization of color_templates
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Copilot recommendation
* QA: Raise PHPStan to Level 6 More Functions
* QA: Issues insalling Cacti
* QA: Issues insalling Cacti
* QA: Issues insalling Cacti
* QA: Issues insalling Cacti
* QA: Issues insalling Cacti
* QA: Issues testing Cacti
* QA: Copilot recommendation
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: More PHPStan fixes at Level 6
* QA: Installer failing
* Undo ownership changes to remove tar errors
* QA: Updates after php-cs-fixer
* QA: Adding code checks to syntax checking
* QA Change syntax flow language
* QA: Reduce the number of cures
* QA: Use sequentional option
* Change runner to self-hosted for check job
* Fix typo in OS version in workflow file
* Add Git installation step in workflow
Added step to install Git if not already installed.
* Add '-y' flag to apt-get install and update commands
Updated apt-get commands to include '-y' for automatic confirmation.
* Change workflow OS version to 'ubuntu-latest'
Updated the workflow to use 'ubuntu-latest' instead of 'ubuntu:latest' and modified the 'runs-on' configuration.
* Remove sequential option from phpcsfixer script
* Remove PHPCS fixer step from workflow
Removed PHP coding standards check from workflow.
* Move code checks to before plugins
Moving these core checks to before the plugins are installed as we really want to check only the base Cacti here.
* Add Composer validation and caching to start of workflow
* QA: Addressing PHPStan additional
* QA: Restore composer lock file
* QA: Addressing PHPStan additional
* QA: Addressing PHPStan additional
* QA: Complete LDAP Project
* QA: php-cs-fixer doing it's thing
* QA: Syntax is already happening in PHPStan
* QA: The md5 function no longer exists
* QA: Update after ldap changes
* QA: Undo that last password hack
* QA: Attempting to switch to MariaDB 11.8
* QA: Attempting to switch to MariaDB 11.8
* QA: Resolving some issues with PHP8.4
* QA: Resolving some issues with PHP8.4
* QA: Add PHP8.5 to the matrix
* QA: Removing PHP8.5 due to dependency issues
* QA: Add the DB version to the testing output
* QA: Switch back to MySQL for the moment
* QA: More fidelity in reporting
* QA: The pipe must be mixed
* QA: Moving audit_schema.php changes from 1.2.x
* QA: Moving audit_schema.php changes from 1.2.x
* QA: Restore mysql monitoring
* QA: php-cs-fixer issues
* QA: Attempt to roll back to MariaDB 10.6
* QA: Attempt to fix check_all_pages.sh
* QA: Make installer functional again
* QA: Fix installer php-cs-fixer issues
* QA: Type to a string
* QA: Get the database version correctly
* QA: Fix issue with reports in check_all_pages.sh
* QA: Check the server version in the right place
* Feature: Support SHA256 as a new hash for passwords
* QA: Function definition and return typing audit
* QA: Refinement of form types
* QA: Refinement of form types
* QA: Consistency of comments
* QA: Issues with php-cs-fixer and more comments
* QA: More typing issues
* QA: php-cs-fixer on merge conflict resolution
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>