Skip to content
Open
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
10 changes: 3 additions & 7 deletions audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

chdir('../../');
include_once('./include/auth.php');
include_once('./plugins/audit/ui_helpers.php');

set_default_action();

Expand All @@ -35,9 +36,7 @@
case 'purge':
audit_purge();

top_header();
audit_log();
bottom_footer();
audit_render_with_layout('audit_log');

break;
case 'getdata':
Expand Down Expand Up @@ -132,9 +131,7 @@

break;
default:
top_header();
audit_log();
bottom_footer();
audit_render_with_layout('audit_log');
}

function audit_purge() {
Expand Down Expand Up @@ -463,4 +460,3 @@ function audit_log() {
<script type='text/javascript' src='plugins/audit/js/functions.js'></script>
<?php
}

65 changes: 65 additions & 0 deletions tests/test_layout_wrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| Regression checks for shared layout wrapper routing in audit.php |
| |
| Run: php tests/test_layout_wrapper.php |
+-------------------------------------------------------------------------+
*/

$pass = 0;
$fail = 0;
$events = array();

function assert_true($label, $value) {
global $pass, $fail;

if ($value) {
echo "PASS $label\n";
$pass++;
} else {
echo "FAIL $label\n";
$fail++;
}
}

function top_header() {
global $events;
$events[] = 'top_header';
}

function bottom_footer() {
global $events;
$events[] = 'bottom_footer';
}

require_once __DIR__ . '/../ui_helpers.php';

$events = array();
$runs = 0;

audit_render_with_layout(function () use (&$events, &$runs) {
$runs++;
$events[] = 'content';
});

assert_true('layout callback executes once', $runs === 1);
assert_true('layout call order is top->content->bottom', $events === array('top_header', 'content', 'bottom_footer'));

$source = file_get_contents(__DIR__ . '/../audit.php');

assert_true(
'purge/default actions use shared layout helper',
substr_count($source, "audit_render_with_layout('audit_log');") >= 2
);
assert_true(
'audit.php includes ui helper file',
strpos($source, "include_once('./plugins/audit/ui_helpers.php');") !== false
Comment on lines +53 to +59
);

echo "\n";
echo "Results: $pass passed, $fail failed\n";

exit($fail > 0 ? 1 : 0);
Comment on lines +62 to +65
19 changes: 19 additions & 0 deletions ui_helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*
+-------------------------------------------------------------------------+
| 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. |
+-------------------------------------------------------------------------+
*/
Comment on lines +6 to +11

if (!function_exists('audit_render_with_layout')) {
function audit_render_with_layout($renderer) {
top_header();
call_user_func($renderer);
bottom_footer();
}
}
Loading