Files
cacti/tests/tools/check_cli_version.sh
Thomas VincentandTheWitness 76b2b693a0 fix: resolve shellcheck and actionlint issues (#6876)
* fix: shellcheck fixes, codespell config, and actionlint config

- Add .github/actionlint.yaml with no-shellcheck to disable
  false positives in run: blocks
- Update .codespell.cfg to skip third-party assets, themes,
  mock data; add intentional words to ignore list
- Fix shellcheck issues in all shell scripts: quoting, egrep
  to grep -E, glob iteration, bare redirects, SIGKILL trap

Does not touch workflow YAML files (handled in #6874).

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

* hardening: move to argument array pattern for shell execution (#6854)

* docs: update exec_background docblock for string|array param types

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

* docs: add PHPDoc to __rrd_execute for PHPStan

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

* fix: resolve php-cs-fixer formatting issues

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

* revert: remove oauth2.php fix (moved to standalone PR #6886)

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

* chore: remove files that belong in other PRs

- Revert lib/poller.php and lib/rrd.php arg-array changes (belong in PR #6855)
- Remove ArgArrayHardeningTest.php (belongs in PR #6855)
- Revert vendor/composer updates (should be a separate PR)

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

* chore: remove composer.lock from tracking

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

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-03-24 08:10:13 -04:00

97 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#+-------------------------------------------------------------------------+
#| Copyright (C) 2004-2026 The Cacti Group |
#| |
#| This program is free software; you can redistribute it and/or |
#| modify it under the terms of the GNU General Public License |
#| as published by the Free Software Foundation; either version 2 |
#| of the License, or (at your option) any later version. |
#| |
#| This program is distributed in the hope that it will be useful, |
#| but WITHOUT ANY WARRANTY; without even the implied warranty of |
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
#| GNU General Public License for more details. |
#+-------------------------------------------------------------------------+
#| Cacti: The Complete RRDtool-based Graphing Solution |
#+-------------------------------------------------------------------------+
#| This code is designed, written, and maintained by the Cacti Group. See |
#| about.php and/or the AUTHORS file for specific developer information. |
#+-------------------------------------------------------------------------+
#| http://www.cacti.net/ |
#+-------------------------------------------------------------------------+
SCRIPTPATH="$( cd "$(dirname "$0")" || exit ; pwd -P )"
cd "${SCRIPTPATH}/../../" || exit
FILES1=$(find cli -name \*.php | grep -v "index.php" | sort)
FILES2=$(find . -maxdepth 1 -name 'poller*.php' | grep -E -v "(index.php|pollers.php)" | sort)
FILES3="cactid.php cmd.php"
# shellcheck disable=SC2009 # pgrep lacks awk/user-filtering in one step; ps pipeline required
WEBUSER=$(ps -ef | grep -E '(httpd|apache2|apache)' | grep -v "$(whoami)" | grep -v root | head -n1 | awk '{print $1}')
PWD=$(pwd)
FAILED=0
HEADER="#!/usr/bin/env php"
echo "Current User is: $(whoami)"
echo "Web User is: ${WEBUSER}"
echo "Working Directory: ${PWD}"
for script in $FILES1 $FILES2 $FILES3; do
if [[ $script == "index.php" ]]; then
continue;
fi
echo "Testing script: ${script}"
script_output=$(head -n 1 "${script}")
if [[ "${script_output}" != "$HEADER" ]]; then
FAILED=2
echo " x Failed header check (${script_output})"
echo " - should be '${HEADER}'"
echo " - found '${script_output}'"
fi
script_output=$(php -q "${script}" --version)
script_result=$?
script_lines=$(echo "${script_output}" | wc -l)
if [[ "${script_output}" == *"System log file is not available for writing"* ]]; then
FAILED=1
echo "Please run this test as the website user";
break;
fi
if [[ $script_result -ne 0 ]]; then
FAILED=2
echo " x Failed version result test (${script_result})"
echo " ==============================================================================="
echo "${script_output}"
echo " ==============================================================================="
fi
if [[ $script_lines -ne 1 ]]; then
FAILED=3
echo " x Failed version output test (${script_lines})";
echo " ==============================================================================="
echo "${script_output}"
echo " ==============================================================================="
fi
script_output=$(php -q "${script}" --help)
script_result=$?
script_lines=$(echo "${script_output}" | wc -l)
if [[ $script_result -ne 0 ]]; then
FAILED=4
echo " x Failed help result test (${script_result})"
echo " ==============================================================================="
echo "${script_output}"
echo " ==============================================================================="
fi
if [[ $script_lines -lt 3 ]]; then
FAILED=5
echo " x Failed help output test (${script_lines})";
fi
done
exit $FAILED