Commit Graph
303 Commits
Author SHA1 Message Date
3e1dc3c886 fix: replace strtolower/strtoupper with locale-independent wrappers (#6717)
* cleanup: remove unreachable defensive error logs in aggregate graph item validation

* fix: replace strtolower/strtoupper with locale-independent wrappers

PHP 8.5 deprecates locale-sensitive strtolower() and strtoupper().
Add cacti_strtolower() and cacti_strtoupper() wrappers that use
mb_strtolower/mb_strtoupper with explicit UTF-8 encoding, then
replace all 185 call sites across 65 files.

Existing mb_strtolower() calls (email normalization) are left as-is
since they already specify encoding explicitly.

Includes 18 Pest tests covering ASCII, UTF-8, protocol names, config
values, hex strings, NaN detection, and file extension patterns.

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

* fix: correct docblock references and month_shift() strpos check

Fix docblocks to reference strtolower()/strtoupper() (the deprecated
PHP builtins) instead of the wrapper names. Fix month_shift() to use
strpos() !== false instead of > 0 so 'month' at position 0 is matched.

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

* chore: drop unrelated lib/api_aggregate changes

Keep PR scope focused on the issue for this branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-03-05 19:51:02 -05:00
TheWitness 39846b4df2 Diagnosis and Resolution of Recursion Errors in Debug (#6686)
* Adding background capture of top processes

* Run this periodically

* Slight tweak to remove warings

* Re-introduce memory issue

* Switch to debug and attempt to locate the page

* Chagne to 2 second granularity to better trace

* Allow test to run now, keeping at debug

* Fixing infinite recursion on connection went away

* Change logging profile for 2002 and 2006 errors

* Correcting php-cs-fixer issue

* Add priority to syslog message

* One more pass to check for completion

* Reenable Debug for run

* Per copilot check_all_pages.sh not saving logs first

* Re-enable execption mode

* Fix php-cs-fixer issue

* Removing debug flag now

* Checking with non-persistent connections

* Final changes before merge
2026-03-02 11:49:10 -05:00
Thomas Vincent b400242618 fix: use strict comparison for $db_conn sentinel in db_table_exists and db_column_exists (#6679)
Both functions use $db_conn == false to detect the "use global
connection" sentinel. Loose comparison also matches 0, '', and null,
which silently falls back to the global connection instead of surfacing
a caller bug.

Replace with === false.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-03-01 11:22:03 -05:00
TheWitness 102e575e1c Partial rollback of database change (#6666)
* Partial rollback of database change

* Roll back array_map change

* More rollback searching for memory exhaustion solution

* One more try for solving memory issue

* Memory leak identified, rolling back one at a time

* One more roll back in search of the leak

* Seeing if we can preserve exception mode

* Switching to silent error mode due to memory leak
2026-02-28 11:01:40 -05:00
Thomas VincentandTheWitness a36c7a2503 fix: escape values in array_to_sql_or() to prevent SQL injection (#6648)
* fix: escape values in array_to_sql_or() to prevent SQL injection

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

* style: apply php-cs-fixer formatting

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

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-02-25 11:39:18 -05:00
TheWitness 9e4820a362 Removing src-* files over composer process (#6646)
* Removing src-* files over composer process

* Fixing PHP-CS-Fixer and PHP-Stan issues

* Minor fixups to format
2026-02-25 15:36:10 +00:00
Thomas VincentandTheWitness 4fb1ad6cfd fix: switch PDO to ERRMODE_EXCEPTION with proper error handling (#6627)
* fix: switch PDO to ERRMODE_EXCEPTION with proper error handling

- Fix $flage typo to $flags so PDO error mode flag is actually applied
  to connections via constructor
- Switch from ERRMODE_SILENT to ERRMODE_EXCEPTION for fail-fast error
  detection instead of silent query failures returning false
- Move prepare() inside existing try/catch in db_execute_prepared() so
  SQL syntax errors are caught consistently
- Wrap db_cacti_initialized() direct PDO calls in try/catch so
  uninitialized databases show the friendly setup message instead of
  crashing with an uncaught PDOException

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

* fix: remove redundant setAttribute after constructor flag fix

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

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-02-24 08:10:29 -05:00
TheWitness 27919c50d7 Updating Copyrights to 2026 (#6578) 2026-01-28 16:11:10 -05:00
TheWitnessandCopilot b993471579 Fix #6539 - Allow Standard Cacti Log Files to be Rotated on Demand,PHPdoc, and Typing (#6540)
* 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>
2026-01-25 10:13:56 -05:00
TheWitness 3d7cd822b8 QA: Fixing additional files phpdoc specs 2025-11-18 23:22:24 -05:00
TheWitness c0afb6a976 Preparing for phpstan analysis by adding bootstrapFiles 2025-11-18 21:47:55 -05:00
TheWitness b9334a15d9 QA: Updates for files for php-cs-fixer and some php-doc changes 2025-11-18 21:01:15 -05:00
Petr Macek 0118b3cd35 fix #6185 - add test if database contains tables (#6448)
* fix #6185 - add test if database contains tables

* formatting

* change table
2025-11-06 07:52:21 -05:00
TheWitness fc14c73db2 QA: Handle 1020 Errors like 1213 Errors
These errors are transient and should result in a retry
2025-10-16 16:40:57 -04:00
TheWitness 2d6ee98a65 QA: Fix: #6262 - Soft database restart recovery
If the database service restarts during polling or other activities errors occur
2025-06-16 08:43:02 -04:00
Linegod db304b7b18 typo 2025-05-09 13:42:25 -06:00
TheWitness 685d4b9357 Start addressing PHPStan Issues 2025-03-23 14:09:11 -04:00
TheWitness abc07dc997 Leave the old wrapper in place 2025-03-23 10:33:23 -04:00
TheWitness d2624514cc Restore parts of lib/rrd.php move/rename a function 2025-03-23 10:23:11 -04:00
TheWitness e5c4015e0e QA: Remove most references to $config
This removes most entries to $config in the base code.  A few new constants were defined to achieve this:

* CACTI_CONNECTION - The status of the current connection
* CACTI_CSRF_SECRET - The path to the csrf secret file
* CACTI_PHP_SNMP - True if php-snmp is installed
* CACTI_WHITELIST - The path to the Cacti Whitelist file if defined

I also moved several $config['poller_id'] to the existing POLLER_ID and move a number of $config['is_web'] to the existing CACTI_WEB constants.

There remain a few artifacts in the code.  They will be handled in a separate commit.
2025-03-22 16:48:59 -04:00
MSS db4eb59dc5 Fixes related to Windows (#6180)
* Update database.php

fix typo:
cacti_log('ERROR: Column: ' . $key . ' contains and invalid value: ' . $value, false, 'DBCALL');

to:
cacti_log('ERROR: Column: ' . $key . ' contains an invalid value: ' . $value, false, 'DBCALL');

* Update dsstats.php

dsstats_get_and_store_ds_avgpeak_values('daily', 'child', 0);
should be:
dsstats_get_and_store_ds_avgpeak_values('daily', 'child', 1);

* Update ping.php

* Update main.css

* Update poller.php

* Update poller_automation.php

* Update rrdcleaner.php

* Update poller_automation.php

* Update poller.php

* Update poller.php

* Update poller_automation.php

* Update rrdcleaner.php
2025-03-21 16:29:48 -04:00
TheWitness 2c779273f9 Copyright Updates and PHP-CS-Fixer updates 2025-03-09 14:34:19 -04:00
Jimmy ConnerandTheWitness 65ab16f5cf Start converting to newer PHP Syntax and Functions (#6103)
* Add Rector

* Add Rector

* Fix "Cashed" misspelling

Also harmonize the phrase with the one below it

* Fix implode error in db_table_create

Only relevant when multiple primary keys

* Fix auth issue, parentheses in the wrong location

Was causing too many arguments to be sent to cacti_sizeof which only take 1, instead of get_allowed_devices.

* Fix issue with session_var not properly using class variable

* Fix pass by reference error in get_allowed_devices

get_allowed_devices has a pass by reference on the "total_rows" field.  It is used in several places to pass the total_rows back to a counter.  Here though, we are passing a number directly to the function, which errors out with "Uncaught Error: get_allowed_devices(): Argument #4 ($total_rows) cannot be passed by reference".  So we will just place a dummy variable in front to catch the pass.

This wasn't caught before because the previous parentheses issue.

* Fix undefined variable "field_array" in html_filter

* Fix undefined function 'get_nfilter_filter_request_var'

* Fix undefined variable 'resizable'

I corrected the function parameter, as that was technically the incorrect spelling

* Fix invalid variable $user_id

* Fix undefined vars in spikekill class

* Fix copy and paste error

Oops

* Forgot to use the dummy variables

* Add missing $

Oops

* Start converting to newer PHP Syntax and Functions

* Test fixing the workflow by install composer

* Lets not valid the composer file right now
Seems we have a few things to fix it in

* Validate composer

* Lite formating changes

* lite formatting

* lite formatting

* lite format changes

* lite format changes

* lite format changes

* lite format changes

* lite format changes

* lite format changes

* lite format changes

* lite format changes

---------

Co-authored-by: TheWitness <thewitness@cacti.net>
2025-02-23 15:14:54 -05:00
Jimmy Conner f80747e857 Fix implode error in db_table_create
Only relevant when multiple primary keys
2025-02-21 23:15:46 -06:00
TheWitness 512ba34307 QA: Unable to add defaults of ON UPDATE ... 2024-12-30 22:18:46 -05:00
TheWitness 2b39ba4cd2 QA: Remove debugging
* This time without the buggered up audit_schema.sql
2024-12-29 19:28:51 -05:00
TheWitness fa145e1bd7 Revert "QA: Remove debugging"
This reverts commit 009fe40930.
2024-12-29 19:28:04 -05:00
TheWitness 009fe40930 QA: Remove debugging 2024-12-29 19:26:06 -05:00
TheWitness e4f677c224 QA: Recognize mariadb-dump in addition to mysqldump 2024-12-29 18:49:28 -05:00
TheWitness 8ae86b8991 QA: Fix: #5995 - String substitution error leading to errors 2024-12-15 09:51:23 -05:00
TheWitness cf2a148599 Fix: #5973 - Database function don't handle unique indexes
* Upon setting up new table structures, noticed this defect.  Lumping in with prior related fixes.
* Update the cli script to handle this case as well in a compatible way.
2024-12-09 12:38:26 -05:00
TheWitness 4f783471fa Fix: #5973 - Issues with db_update_table() function
* Multiple Issues with database API function db_update_table() preventing correct update of an existing table
2024-12-09 11:23:14 -05:00
Jimmy Conner ad07471bb1 Lots of PHPDoc formatting and cleanup
Lots more to go
2024-12-09 02:50:06 -06:00
TheWitness fdd9cd766b Fix: #5963 and #5961 - Replication Issues and Database Caching
* Cacti caching for db_table_exists() and db_column_exists() is not connection aware and replication does not replicate empty table structures
* Issues with Replication of Tables and Misleading Full Sync Time
2024-12-05 10:40:54 -05:00
Linegod 2e82c190ee typos 2024-12-01 16:41:47 -06:00
Linegod c3b176780f typos 2024-11-24 23:22:15 -06:00
TheWitness 927da7ee79 QA: Syntax Error when changing the tables CHARSET 2024-11-19 06:23:31 -05:00
TheWitness b937f67456 Fix #5866 - Add database to database permissions structure 2024-11-09 13:01:02 -05:00
TheWitness 5dcda9f670 Fixing Issues #5783 and #5784 - Database Issues
* These issues are to fix an issue encountered when trying to support technologies such as MaxScale readonly and readwrite split connections from the same PHP session.

The first issue is to fix a bug where the main Cacti connection was being closed even when you were trying to close another connection.  The second enhancement is to enable logging of connects, disconnects and the first SQL execution from a connection.

* issue#5783: Cacti improperly handles connection closing leading to issues with third party connections
* feature#5784: Provide a means by which a user can track Cacti connections and disconnects from the php error_log
2024-07-04 19:35:04 -04:00
TheWitness 1aa72d24c9 QA: Update Copyright to 2024 2024-02-03 14:18:57 -05:00
TheWitness 9a90b50050 Fixing Issue #5612 - Function db_check_reconnect() issues
Function db_check_reconnect() does not properly return a value
2023-12-11 19:56:19 -05:00
TheWitness b27fd23c68 QA: Address formatting issues with Pull 2023-11-18 13:10:54 -05:00
jkbzhandJose Kahan d5615333e4 Support for PDO::MYSQL_ATTR_SSL_CAPATH and PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT (#5522)
* Make PDO::MYSQL_ATTR_SSL_CAPATH and PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT
accessible thru $database_ssl_capath and $database_ssl_verify_server_cert
configuration options.

* typo: wrong variable name

* fixing typo

---------

Co-authored-by: Jose Kahan <jose.kahan@w3.org>
2023-10-04 18:16:26 -04:00
TheWitness 2aabd74a26 QA: Ensure cacti can install and operate using defaults 2023-10-01 13:28:57 -04:00
TheWitness 68117e3f1f Finalizing #5434 - Remove these two settings entirely 2023-08-04 12:46:33 -04:00
TheWitness 9e01ad6019 QA On #5434 - Next offender
Will have to make one more commit after we see what is going on.
2023-08-04 12:46:06 -04:00
TheWitness 82085f808e Fixing #5434 - SQL Mode NO_AUTO_CREATE_USER
This setting is now braking out build test system.
2023-08-04 12:19:15 -04:00
TheWitness ecd629300c Correct against possible SQL Injections 2023-08-04 12:18:45 -04:00
TheWitness b95e8d7927 Two minor fixes #5406 and #5407
-feature#5406: Cacti connection handling should forcibly close connections to work around PDO uncertainty
-feature#5407: Add last_updated column to the boost table to increase diagnostics in Cacti
2023-07-21 09:33:06 -04:00
TheWitness b629b3d8a3 QA: Refixing #5364 - Database reconnect warnings 2023-06-19 18:47:25 -04:00