Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# +-------------------------------------------------------------------------+
# | 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. |
# +-------------------------------------------------------------------------+
# | Cacti: The Complete RRDtool-based Graphing Solution |
# +-------------------------------------------------------------------------+

name: Code Quality

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

permissions:
contents: read

jobs:
lint:
name: PHP Lint (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout plugin
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Install PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

# Lint only the plugin's own PHP. Vendored code (Net/, vendor/) is pruned
# so third-party sources never gate the plugin.
- name: Lint plugin PHP
run: |
find . -path ./.git -prune \
-o -path ./Net -prune \
-o -path ./vendor -prune \
-o -name '*.php' -print0 \
| xargs -0 -n1 -P4 php -l

phpstan:
name: PHPStan level 6 (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout Cacti core
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Cacti/cacti
ref: release/1.2.31
path: cacti

- name: Checkout plugin
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
path: cacti/plugins/mactrack

- name: Install PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, phpstan

# Cacti core ships an incomplete vendor tree; its bootstrap needs the
# runtime dependencies installed so core functions resolve for PHPStan.
- name: Install Cacti core dependencies
working-directory: cacti
run: composer install --no-dev --no-interaction --no-progress

# release/1.2.31 does not ship .phpstan-bootstrap.php (develop does).
# Provide a no-op stub so the plugin config can load either core tree.
- name: Ensure PHPStan bootstrap exists
working-directory: cacti
run: |
if [ ! -f .phpstan-bootstrap.php ]; then
printf '%s\n' '<?php' '// Stub bootstrap for Cacti trees without a core PHPStan entrypoint' > .phpstan-bootstrap.php
fi

# Analysis runs against the plugin's own code only; the config excludes
# Net/ and vendor/. The committed baseline pins the accepted findings.
- name: Run PHPStan
working-directory: cacti/plugins/mactrack
run: phpstan analyse --configuration=.phpstan.neon --no-progress --memory-limit=2G
44 changes: 34 additions & 10 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: Cacti/cacti
ref: release/1.2.31
path: cacti

- name: Checkout mactrack Plugin
Expand All @@ -85,7 +86,7 @@ jobs:
run: sudo apt-get update

- name: Install System Dependencies
run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping libapache2-mod-php${{ matrix.php }}
run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping

- name: Start SNMPD Agent and Test
run: |
Expand Down Expand Up @@ -164,6 +165,13 @@ jobs:
run: |
cd ${{ github.workspace }}/cacti
sudo php cli/install_cacti.php --accept-eula --install --force

- name: Install Mactrack Composer Dependencies
run: |
cd ${{ github.workspace }}/cacti/plugins/mactrack
if [ -f composer.json ]; then
sudo composer install --no-dev --prefer-dist --no-progress --no-interaction
fi

- name: Install mactrack Plugin
run: |
Expand All @@ -182,24 +190,40 @@ jobs:
- name: Check PHP Syntax for Plugin
run: |
cd ${{ github.workspace }}/cacti/plugins/mactrack
if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then
echo "Syntax errors found!"
exit 1
fi

find . -path './vendor' -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l

# Cacti 1.2.31 has no .phpstan.neon / lint scripts; only touch them when present.
- name: Remove the plugins directory exclusion from the .phpstan.neon
run: sed '/plugins/d' -i .phpstan.neon
run: |
if [ -f .phpstan.neon ]; then
sed '/plugins/d' -i .phpstan.neon
else
echo '.phpstan.neon not present; skipping'
fi
working-directory: ${{ github.workspace }}/cacti

- name: Mark composer scripts executable
run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/*
run: |
if [ -d "${{ github.workspace }}/cacti/include/vendor/bin" ]; then
sudo find "${{ github.workspace }}/cacti/include/vendor/bin" -maxdepth 1 -type f -exec chmod +x {} +
fi

- name: Run Linter on base code
run: composer run-script lint ${{ github.workspace }}/cacti/plugins/mactrack
run: |
if composer run-script --list | grep -qE '^ lint'; then
composer run-script lint ${{ github.workspace }}/cacti/plugins/mactrack
else
echo 'Composer lint script is not defined; skipping.'
fi
working-directory: ${{ github.workspace }}/cacti

- name: Checking coding standards on base code
run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/mactrack
run: |
if composer run-script --list | grep -qE '^ phpcsfixer'; then
composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/mactrack
else
echo 'Composer phpcsfixer script is not defined; skipping.'
fi
working-directory: ${{ github.workspace }}/cacti

# - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues
Expand Down
48 changes: 48 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
includes:
- phpstan-baseline.neon

parameters:
level: 6
parallel:
maximumNumberOfProcesses: 8
# Cacti core is checked out at ../.. by the Code Quality workflow so its
# library functions resolve for the plugin. Only the plugin's own code is
# analyzed; vendored Net_DNS2 (Net/, vendor/) is never scanned.
scanDirectories:
- ../../lib
- ../../include
paths:
- lib
- includes
- .
excludePaths:
analyseAndScan:
- Net/*
- vendor/*
- tests/*
bootstrapFiles:
- ../../.phpstan-bootstrap.php
- ../../include/vendor/autoload.php
- ../../include/config.php.dist
- ../../include/global_constants.php
- ../../lib/functions.php
- ../../include/global.php
- ../../include/global_languages.php
- ../../include/global_arrays.php
- ../../include/global_form.php
- ../../include/global_settings.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: if.alwaysFalse
- identifier: notEqual.alwaysFalse
- identifier: notEqual.alwaysTrue
- identifier: equal.alwaysTrue
- identifier: if.alwaysTrue
- identifier: while.alwaysTrue
- identifier: greater.alwaysFalse
- identifier: identical.alwaysTrue
- identifier: identical.alwaysFalse
- identifier: booleanAnd.leftAlwaysTrue
- identifier: booleanAnd.leftAlwaysFalse
- identifier: function.alreadyNarrowedType
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

--- develop ---

* compat: Replace vendored Net_DNS2 with Composer-managed mikepultz/netdns2 1.5, retaining the established resolver API
* issue: Harden device-type vendor filtering against SQL injection
* issue: Validate aggregated MAC bulk-action IDs and use prepared deletion SQL
* security: Replace MAC action request deserialization with escaped JSON payloads
* security: Validate and escape MAC bulk-action form values before rendering
* security: Escape rescan executable and script paths before command execution
* security: Parameterize stale-process site filtering and validate process IDs before termination
* security: Escape Cabletron SNMP command arguments and normalize numeric options
* security: Safely quote ignored-interface regexes and normalize interface report filters
* security: Normalize device report SQL filters before query construction
* security: Normalize administrative device list SQL filters before query construction
* security: Validate canonical local-file paths for OUI database imports
* compat: Fix PHP 8 parameter ordering and partition conversion arguments
* issue#246: Fix Cisco device collection
* issue#248: Cacti process control, terminate dns resolvet when is nothing to do
* issue#250: Disable automatic MIBs load
Expand Down
Loading
Loading