\n";
}
@@ -2064,27 +2102,27 @@ function create_export_directory_structure(&$export, $root_path, $export_path) {
copy("$root_path/include/themes/$theme/images/cacti_logo.svg", "$export_path/images/cacti_logo.svg");
/* jstree theme files */
- $files = array('32px.png', '40px.png', 'style.css', 'throbber.gif');
+ $files = ['32px.png', '40px.png', 'style.css', 'throbber.gif'];
foreach($files as $file) {
copy("$root_path/include/themes/$theme/default/$file", "$export_path/css/default/$file");
}
$directory = "$root_path/include/themes/$theme/images";
- $directory = array_diff(glob("$directory/*.*"), array("$directory/.", "$directory/.."));
+ $directory = array_diff(glob("$directory/*.*"), ["$directory/.", "$directory/.."]);
foreach($directory as $file) {
$file = basename($file);
copy("$root_path/include/themes/$theme/images/$file", "$export_path/css/images/$file");
}
$directory = "$root_path/include/fa/webfonts";
- $directory = array_diff(glob("$directory/*.*"), array("$directory/.", "$directory/.."));
+ $directory = array_diff(glob("$directory/*.*"), ["$directory/.", "$directory/.."]);
foreach($directory as $file) {
$file = basename($file);
copy("$root_path/include/fa/webfonts/$file", "$export_path/webfonts/$file");
}
$directory = "$root_path/include/fa/svgs";
- $directory = array_diff(glob("$directory/*.*"), array("$directory/.", "$directory/.."));
+ $directory = array_diff(glob("$directory/*.*"), ["$directory/.", "$directory/.."]);
foreach($directory as $file) {
$file = basename($file);
copy("$root_path/include/fa/svgs/$file", "$export_path/svgs/$file");
@@ -2094,13 +2132,13 @@ function create_export_directory_structure(&$export, $root_path, $export_path) {
/* get_host_description - a simple function to return the host description of a host.
@arg $host_id - the id of the host in question */
function get_host_description($host_id) {
- return db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($host_id));
+ return db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', [$host_id]);
}
/* get_tree_name - a simple function to return the tree name of a tree.
@arg $tree_id - the id of the tree in question */
function get_tree_name($tree_id) {
- return db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($tree_id));
+ return db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', [$tree_id]);
}
/* del_directory - delete the directory pointed to by the $path variable.
diff --git a/gexport.php b/gexport.php
index fa23718..50a7fe1 100644
--- a/gexport.php
+++ b/gexport.php
@@ -25,6 +25,7 @@
chdir('../../');
include('./include/auth.php');
include_once('./plugins/gexport/functions.php');
+include_once('./plugins/gexport/gexport_security.php');
$export_actions = array(
'1' => __('Delete', 'gexport'),
@@ -148,7 +149,7 @@ function export_form_save() {
function duplicate_export($_export_id, $export_title) {
global $fields_export_edit;
- $export = db_fetch_row_prepared('SELECT * FROM graph_exports WHERE id = ?', array($_export_id));
+ $export = db_fetch_row_prepared('SELECT * FROM graph_exports WHERE id = ?', [$_export_id]);
/* substitute the title variable */
$export['name'] = str_replace('', $export['name'], $export_title);
@@ -173,12 +174,14 @@ function duplicate_export($_export_id, $export_title) {
function export_form_actions() {
global $export_actions;
+ $bulk_action = gexport_normalize_bulk_action(get_nfilter_request_var('drp_action'));
+
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
- if (get_nfilter_request_var('drp_action') === '1') { /* delete */
+ if ($bulk_action === '1') { /* delete */
/* do a referential integrity check */
if (sizeof($selected_items)) {
foreach($selected_items as $export_id) {
@@ -193,7 +196,7 @@ function export_form_actions() {
if (isset($export_ids)) {
db_execute('DELETE FROM graph_exports WHERE ' . array_to_sql_or($export_ids, 'id'));
}
- } elseif (get_nfilter_request_var('drp_action') === '2') { /* enable */
+ } elseif ($bulk_action === '2') { /* enable */
for ($i=0;($i';
+ $export_list .= '
' . db_fetch_cell_prepared('SELECT name FROM graph_exports WHERE id = ?', [$matches[1]]) . '
" . __n('Click \'Continue\' to delete the following Graph Export Definition.', 'Click \'Continue\' to delete following Graph Export Definitions.', sizeof($export_array), 'gexport') . "
" . __n('Click \'Continue\' to disable the following Graph Export Definition.', 'Click \'Continue\' to disable following Graph Export Definitions.', sizeof($export_array), 'gexport') . "
" . __n('Click \'Continue\' to enable the following Graph Export Definition.', 'Click \'Continue\' to enable following Graph Export Definitions.', sizeof($export_array), 'gexport') . "
" . __n('Click \'Continue\' to run the following Graph Export Definition now.', 'Click \'Continue\' to run following Graph Export Definitions now.', sizeof($export_array)) . "
@@ -301,7 +304,7 @@ function export_form_actions() {
-
+
$save_html
";
@@ -318,11 +321,11 @@ function export_form_actions() {
--------------------- */
function export_enable($export_id) {
- db_execute_prepared('UPDATE graph_exports SET enabled="on" WHERE id = ?', array($export_id));
+ db_execute_prepared('UPDATE graph_exports SET enabled="on" WHERE id = ?', [$export_id]);
}
function export_disable($export_id) {
- db_execute_prepared('UPDATE graph_exports SET enabled="" WHERE id = ?', array($export_id));
+ db_execute_prepared('UPDATE graph_exports SET enabled="" WHERE id = ?', [$export_id]);
}
function export_runnow($export_id) {
@@ -330,7 +333,7 @@ function export_runnow($export_id) {
include_once('./lib/poller.php');
- $status = db_fetch_row_prepared('SELECT status, enabled FROM graph_exports WHERE id = ?', array($export_id));
+ $status = db_fetch_row_prepared('SELECT status, enabled FROM graph_exports WHERE id = ?', [$export_id]);
if (($status['status'] == 0 || $status['status'] == 2) && $status['enabled'] == 'on') {
$command_string = read_config_option('path_php_binary');
@@ -361,8 +364,8 @@ function export_edit() {
draw_edit_form(
array(
- 'config' => array('no_form_tag' => true),
- 'fields' => inject_form_variables($fields_export_edit, (isset($export) ? $export : array()))
+ 'config' => ['no_form_tag' => true],
+ 'fields' => inject_form_variables($fields_export_edit, (isset($export) ? $export : []))
)
);
@@ -695,40 +698,40 @@ function gexport() {
/* ================= input validation and session storage ================= */
$filters = array(
- 'rows' => array(
+ 'rows' => [
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
+ ],
+ 'page' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'refresh' => array(
+ ],
+ 'refresh' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '20'
- ),
- 'filter' => array(
+ ],
+ 'filter' => [
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
- ),
+ ],
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
- 'options' => array('options' => 'sanitize_search_string')
+ 'options' => ['options' => 'sanitize_search_string']
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
+ 'options' => ['options' => 'sanitize_search_string']
)
);
validate_store_request_vars($filters, 'sess_gexport');
/* ================= input validation ================= */
- $refresh = array();
+ $refresh = [];
$refresh['page'] = 'gexport.php?header=false';
$refresh['seconds'] = get_request_var('refresh');
$refresh['logout'] = 'false';
@@ -738,7 +741,7 @@ function gexport() {
export_filter();
$total_rows = 0;
- $exports = array();
+ $exports = [];
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
@@ -821,7 +824,7 @@ function gexport() {
)
);
- $nav = html_nav_bar('gexport.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, sizeof($display_text) + 1, __('Export Definitions', 'gexport'), 'page', 'main');
+ $nav = html_nav_bar(gexport_build_nav_filter_url(get_request_var('filter')), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, sizeof($display_text) + 1, __('Export Definitions', 'gexport'), 'page', 'main');
form_start('gexport.php', 'chk');
@@ -837,7 +840,7 @@ function gexport() {
$user = db_fetch_cell_prepared('SELECT username
FROM user_auth
WHERE id = ?',
- array($export['export_effective_user']));
+ [$export['export_effective_user']]);
if ($export['export_pid'] > 0 && $export['status'] > 0) {
if (function_exists('posix_getpgid')) {
@@ -850,7 +853,7 @@ function gexport() {
db_execute_prepared('UPDATE graph_exports
SET status=0, export_pid=0, last_error="Killed Outside Cacti", last_errored=NOW()
WHERE id = ?',
- array($export['id']));
+ [$export['id']]);
}
}
@@ -937,4 +940,3 @@ function gexport() {
form_end();
}
-
diff --git a/gexport_security.php b/gexport_security.php
new file mode 100644
index 0000000..f318e62
--- /dev/null
+++ b/gexport_security.php
@@ -0,0 +1,28 @@
+ 4) {
+ return '';
+ }
+
+ return (string) $action;
+}
+
+function gexport_build_nav_filter_url($filter) {
+ return 'gexport.php?filter=' . rawurlencode((string) $filter);
+}
diff --git a/setup.php b/setup.php
index 5a26d25..8505e81 100644
--- a/setup.php
+++ b/setup.php
@@ -71,7 +71,7 @@ function gexport_check_upgrade() {
include_once($config['library_path'] . '/functions.php');
// Let's only run this check if we are on a page that actually needs the data
- $files = array('plugins.php', 'gexport.php');
+ $files = ['plugins.php', 'gexport.php'];
if (!in_array(get_current_page(), $files)) {
return;
}
@@ -259,13 +259,13 @@ function gexport_config_arrays() {
$tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR;
if (isset($_SESSION['gexport_message']) && $_SESSION['gexport_message'] != '') {
- $messages['gexport_message'] = array('message' => $_SESSION['gexport_message'], 'type' => 'info');
+ $messages['gexport_message'] = ['message' => $_SESSION['gexport_message'], 'type' => 'info'];
}
$menu[__('Utilities')]['plugins/gexport/gexport.php'] = __('Graph Exports', 'gexport');
if (function_exists('auth_augment_roles')) {
- auth_augment_roles(__('General Administration'), array('gexport.php'));
+ auth_augment_roles(__('General Administration'), ['gexport.php']);
}
$sites = array_rekey(db_fetch_assoc('SELECT "0" AS id, "All Sites" AS name UNION SELECT id, name FROM sites ORDER BY name'), 'id', 'name');
diff --git a/tests/Integration/test_bulk_action_output_security.php b/tests/Integration/test_bulk_action_output_security.php
new file mode 100644
index 0000000..0d2e44b
--- /dev/null
+++ b/tests/Integration/test_bulk_action_output_security.php
@@ -0,0 +1,32 @@
+',
+);
+
+foreach ($checks as $check) {
+ if (strpos($contents, $check) === false) {
+ fwrite(STDERR, "Missing expected security wiring: {$check}\n");
+ exit(1);
+ }
+}
+
+print "OK\n";
diff --git a/tests/Unit/test_gexport_security_helpers.php b/tests/Unit/test_gexport_security_helpers.php
new file mode 100644
index 0000000..107c4b7
--- /dev/null
+++ b/tests/Unit/test_gexport_security_helpers.php
@@ -0,0 +1,37 @@
+