Skip to content
Merged
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
36 changes: 20 additions & 16 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ When generating code for this repository:
## Project Structure

```
evidence/ # Repository root (install to plugins/evidence/ in Cacti)
evidence/ # Repository root (install to plugins/evidence/ in Cacti)
├── include/
│ ├── functions.php # Core polling, display and hook logic
│ ├── database.php # Table creation and upgrade logic
│ ├── settings.php # Plugin config_settings hook
│ ├── arrays.php # Configuration arrays (entities, datatypes)
│ └── index.php # Access protection
├── data/ # SQL seed data (enterprise-numbers.sql) and prep scripts
├── images/ # Tab icons and UI images
├── evidence.php # Main standalone/console page
├── evidence_tab.php # Device tab integration page
│ ├── functions.php # Core polling, display and hook logic
│ ├── database.php # Table creation and upgrade logic
│ ├── settings.php # Plugin config_settings hook
│ ├── arrays.php # Configuration arrays (entities, datatypes)
│ └── index.php # Access protection
├── data/ # SQL seed data (enterprise-numbers.sql) and prep scripts
├── images/ # Tab icons and UI images
├── evidence.php # Main standalone/console page
├── evidence_tab.php # Device tab integration page
├── js/
│ └── evidence.js # Client-side JS for device edit page
├── poller_evidence.php # Background poller entry point (CLI)
├── setup.php # Plugin install/uninstall/upgrade hooks
├── INFO # Plugin metadata (name, version, compat)
├── README.md # Feature overview, installation and usage
└── CHANGELOG.md # Version history
│ └── evidence.js # Client-side JS for device edit page
├── poller_evidence.php # Background poller entry point (CLI)
├── setup.php # Plugin install/uninstall/upgrade hooks
├── INFO # Plugin metadata (name, version, compat)
├── README.md # Feature overview, installation and usage
└── CHANGELOG.md # Version history
```

## Naming Conventions
Expand Down Expand Up @@ -427,3 +427,7 @@ existing code or adding new code, not just in dedicated cleanup passes:
line, `@param` lines, a blank comment line, then `@return`. Infer parameter/return types from
actual usage; don't change the function's real type-hints in the same pass (let static analysis
flag mismatches separately). Skip vendored third-party library files.

## File manifest & upgrade pruning

The plugin ships a root `manifest.json` with three arrays: `tombstones` (files/directories older versions shipped that have since moved or been removed), `expected` (the top-level files and directories that ship today, directories written with a trailing `/`), and `whitelist` (paths holding user data that must never be touched). Keep `expected` current: CI runs `tests/bin/validate-manifest.php`, which fails on any drift between `expected` and the real top-level tree (it ignores `tests/`, `phpunit.xml`, `.git*`, `.md*`, and whitelisted paths). Custom customer CSS/theme files belong in `expected`, and stylesheets live in `css/` (not `themes/`). On upgrade, `evidence_prune_files()` deletes the tombstoned paths, the dev-only `tests/` tree, and the `phpunit.xml` test config, leaves `whitelist`, `.git*`, and `.md*` alone, and logs (without removing) any top-level entry the manifest does not account for. As a safety measure it refuses any tombstone that resolves outside the plugin directory (a tampered manifest.json) and logs a warning for any file or directory it cannot remove. When you move or delete a shipped file, add its old path to `tombstones` and update `expected` in the same change.
3 changes: 3 additions & 0 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ jobs:
- name: Check PHP version
run: php -v

- name: Validate plugin manifest (expected-file drift)
run: php cacti/plugins/evidence/tests/bin/validate-manifest.php

- name: Run apt-get update
run: sudo apt-get update

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

--- develop ---
* dev: Move the plugin's library directory from `include/` to `includes/` and re-register the affected hooks on upgrade (via a `plugin_hooks` file repoint in `plugin_evidence_upgrade_database()`) so existing installations load them from the new path
* dev: Measure CI coverage with xdebug instead of pcov so the plugin's own sources are instrumented (pcov auto-scopes to the Composer root and skipped cacti/plugins/, leaving the patch-coverage gate with nothing to measure)
* dev: Enforce patch coverage of changed lines in CI and remove the inert COMPOSER_ROOT_VERSION env from the Pest step
* security: Add a version-safe CSP nonce (`plugin_evidence_csp_nonce()`) to every inline `<script>` tag so pages stay compatible with Cacti's Content-Security-Policy nonce enforcement, while falling back cleanly on older Cacti releases that lack the `CactiSecureHeaders` class
Expand Down
6 changes: 3 additions & 3 deletions evidence.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/

chdir('../../');
include_once('./include/auth.php');
include_once('./lib/snmp.php');
include_once('./plugins/evidence/include/functions.php');
require_once('./include/auth.php');
require_once('./lib/snmp.php');
require_once('./plugins/evidence/includes/functions.php');

$evidence_records = read_config_option('evidence_records');

Expand Down
8 changes: 4 additions & 4 deletions evidence_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*/

chdir('../../');
include_once('./include/auth.php');
include_once('./lib/snmp.php');
include_once('./plugins/evidence/include/functions.php');
include_once('./plugins/evidence/include/arrays.php');
require_once('./include/auth.php');
require_once('./lib/snmp.php');
require_once('./plugins/evidence/includes/functions.php');
require_once('./plugins/evidence/includes/arrays.php');

set_default_action();

Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions include/database.php → includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function plugin_evidence_initialize_database() {
$data = [];
$data['columns'][] = ['name' => 'id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'organization', 'type' => 'varchar(200)', 'NULL' => false];
$data['primary'] = 'id';
$data['primary'] = ['id'];
$data['type'] = 'InnoDB';
$data['comment'] = 'evidence organizations';
api_plugin_db_table_create('evidence', 'plugin_evidence_organization', $data);
Expand All @@ -65,7 +65,7 @@ function plugin_evidence_initialize_database() {
$data['columns'][] = ['name' => 'method', 'type' => 'enum("get", "walk", "info", "table")', 'default' => 'get', 'NULL' => false];
$data['columns'][] = ['name' => 'table_items', 'type' => 'varchar(100)', 'default' => null, 'NULL' => true];
$data['columns'][] = ['name' => 'mandatory', 'type' => 'enum("yes","no")', 'default' => 'yes', 'NULL' => false];
$data['primary'] = 'id';
$data['primary'] = ['id'];
$data['type'] = 'InnoDB';
$data['comment'] = 'evidence specific';
api_plugin_db_table_create('evidence', 'plugin_evidence_specific_query', $data);
Expand Down Expand Up @@ -313,6 +313,12 @@ function plugin_evidence_upgrade_database() {
api_plugin_db_table_create('evidence', 'plugin_evidence_snmp_info', $data);
}

// The plugin's library directory moved from include/ to includes/; repoint
// any hook still registered against the old path so existing installs load
// them from the new location after upgrade.
db_execute("UPDATE plugin_hooks SET file = REPLACE(file, 'include/', 'includes/') WHERE name = 'evidence' AND file LIKE 'include/%'");
// Remove files tombstoned in manifest.json (the old include/ tree).
evidence_prune_files();
// Set the new version
db_execute_prepared("UPDATE plugin_config
SET version = ?, author = ?, webpage = ?
Expand Down
6 changes: 3 additions & 3 deletions include/functions.php → includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function plugin_evidence_host_edit_bottom() {
print get_md5_include_js($config['base_path'] . '/plugins/evidence/js/evidence.js');

if (read_config_option('evidence_show_host_data')) {
include_once('./plugins/evidence/include/functions.php');
include_once('./plugins/evidence/includes/functions.php');
print '<br/><br/>';

$host = db_fetch_row_prepared('SELECT host.*, host_template.name as `template_name`
Expand Down Expand Up @@ -1671,7 +1671,7 @@ function evidence_show_host_data($host_id, $scan_date) {
function evidence_show_host_info($data, $host_id) {
global $config, $datatypes;

include_once($config['base_path'] . '/plugins/evidence/include/arrays.php');
include_once($config['base_path'] . '/plugins/evidence/includes/arrays.php');

$short = false;

Expand Down Expand Up @@ -1817,7 +1817,7 @@ function evidence_show_host_info($data, $host_id) {
function evidence_show_actual_data($data) {
global $config, $datatypes;

include_once($config['base_path'] . '/plugins/evidence/include/arrays.php');
include_once($config['base_path'] . '/plugins/evidence/includes/arrays.php');

if (isset($data['org_name'])) {
print $data['org_name'];
Expand Down
File renamed without changes.
Loading
Loading