Skip to content

Commit

Permalink
removing many $_GET, $_REQUEST, and $_POST variable usage
Browse files Browse the repository at this point in the history
There are still three steps to go in this overall.  The first is to
replace all the page filtering session storing and validation functions
and the second is to propagate those changes into various areas of the
lib directory that include the use of the various variables, lastly,
developer mode will have to be enable to see if there are any variables
used in the code that have not been sanitized.  Note, at this point the
develop branch should be thought of as slightly unstable
  • Loading branch information
cigamit committed Feb 7, 2016
1 parent 732d423 commit 2387bd4
Show file tree
Hide file tree
Showing 54 changed files with 2,381 additions and 2,209 deletions.
16 changes: 8 additions & 8 deletions aggregate_graphs.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ function form_save() {
$save['gprint_prefix'] = get_request_var_post('gprint_prefix');
$save['total_prefix'] = get_request_var_post('total_prefix');

$save['total'] = get_sanitize_request_var('total', FILTER_VALIDATE_INT);
$save['graph_type'] = get_sanitize_request_var('graph_type', FILTER_VALIDATE_INT);
$save['total_type'] = get_sanitize_request_var('total_type', FILTER_VALIDATE_INT);
$save['order_type'] = get_sanitize_request_var('order_type', FILTER_VALIDATE_INT);
$save['total'] = get_filter_request_var('total');
$save['graph_type'] = get_filter_request_var('graph_type');
$save['total_type'] = get_filter_request_var('total_type');
$save['order_type'] = get_filter_request_var('order_type');

/* see if anything changed, if so, we will have to push out the aggregate */
if (!empty($aggregate_graph_id)) {
Expand Down Expand Up @@ -256,8 +256,8 @@ function form_actions() {
}elseif (get_request_var_post('drp_action') == '11') { /* dis-associate with aggregate */
api_aggregate_disassociate($selected_items);
}elseif (preg_match('/^tr_([0-9]+)$/', get_request_var_post('drp_action'), $matches)) { /* place on tree */
input_validate_input_number(get_request_var_post('tree_id'));
input_validate_input_number(get_request_var_post('tree_item_id'));
get_filter_request_var('tree_id');
get_filter_request_var('tree_item_id');
for ($i=0;($i<count($selected_items));$i++) {
api_tree_item_save(0, get_request_var_post('tree_id'), TREE_ITEM_TYPE_GRAPH, get_request_var_post('tree_item_id'), '', $selected_items[$i], read_graph_config_option('default_rra_id'), 0, 0, 0, false);
}
Expand Down Expand Up @@ -446,7 +446,7 @@ function item() {
global $consolidation_functions, $graph_item_types, $struct_graph_item;

/* ================= input validation ================= */
input_validate_input_number(get_request_var('id'));
get_filter_request_var('id');
/* ==================================================== */

if (isempty_request_var('id')) {
Expand Down Expand Up @@ -491,7 +491,7 @@ function graph_edit() {
global $config, $struct_graph, $struct_aggregate_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;

/* ================= input validation ================= */
get_sanitize_request_var('id', FILTER_VALIDATE_INT);
get_filter_request_var('id');
/* ==================================================== */

/* purge any old graphs */
Expand Down
361 changes: 183 additions & 178 deletions aggregate_items.php

Large diffs are not rendered by default.

127 changes: 66 additions & 61 deletions aggregate_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
);

/* set default action */
if (!isset($_REQUEST['action'])) $_REQUEST['action'] = '';
set_default_action();

if ($_REQUEST['action'] == 'save' && $_REQUEST['id'] == 0 && isset($_REQUEST['_graph_template_id']) && $_REQUEST['_graph_template_id'] == 0) {
$_REQUEST['action'] = 'edit';
if (get_request_var('action') == 'save') {
if (get_request_var('id') == 0 && isset_request_var('_graph_template_id') && get_request_var('_graph_template_id') == 0) {
set_request_var('action', 'edit');
}
}

switch ($_REQUEST['action']) {
switch (get_request_var('action')) {
case 'save':
aggregate_form_save();
break;
Expand All @@ -65,15 +67,15 @@
*/
function aggregate_form_save() {
/* make sure we are saving aggregate template */
if (!isset($_POST['save_component_template'])) {
if (!isset_request_var('save_component_template')) {
header('Location: aggregate_templates.php?header=false&action=edit&id=' . get_request_var_post('id'));
return null;
}

$save1 = array();

/* updating existing template or creating a new one? */
if (isset_request_var('id') && $_POST['id'] > 0) {
if (isset_request_var('id') && get_request_var('id') > 0) {
$is_new = false;
$save1['id'] = get_request_var_post('id');
} else {
Expand All @@ -82,14 +84,14 @@ function aggregate_form_save() {
}

/* set some defaults for possibly disabled values */
if (!isset_request_var('total')) $_POST['total'] = 0;
if (!isset_request_var('total_type')) $_POST['total_type'] = 0;
if (!isset_request_var('order_type')) $_POST['order_type'] = 0;
if (!isset_request_var('total_prefix')) $_POST['total_prefix'] = '';
if (!isset_request_var('total')) set_request_var('total', 0);
if (!isset_request_var('total_type')) set_request_var('total_type', 0);
if (!isset_request_var('order_type')) set_request_var('order_type', 0);
if (!isset_request_var('total_prefix')) set_request_var('total_prefix', '');

/* populate aggregate template save array and validate posted values*/
$save1['name'] = form_input_validate(get_request_var_post('name'), 'name', '', false, 3);
$save1['graph_template_id'] = $_POST['_graph_template_id'];
$save1['graph_template_id'] = get_filter_request_var('_graph_template_id');
$save1['gprint_prefix'] = form_input_validate(get_request_var_post('gprint_prefix'), 'gprint_prefix', '', true, 3);
$save1['graph_type'] = form_input_validate(get_request_var_post('graph_type'), 'graph_type', '', false, 3);
$save1['total'] = form_input_validate(get_request_var_post('total'), 'total', '', false, 3);
Expand Down Expand Up @@ -166,15 +168,17 @@ function aggregate_form_save() {


/* save only if all posted form fields passed validation */
if (!is_error_message())
if (!is_error_message()) {
sql_save($params_new, 'aggregate_graph_templates_graph', 'aggregate_template_id', false);
}

/* save the template items now */
/* get existing item ids and sequences from graph template */
$graph_templates_items = array_rekey(
db_fetch_assoc('SELECT id, sequence FROM graph_templates_item WHERE local_graph_id=0 AND graph_template_id=' . $save1['graph_template_id']),
'id', array('sequence')
);

/* get existing aggregate template items */
$aggregate_template_items_old = array_rekey(
db_fetch_assoc('SELECT * FROM aggregate_graph_templates_item WHERE aggregate_template_id='.$id),
Expand All @@ -186,6 +190,7 @@ function aggregate_form_save() {

$items_changed = false;
$items_to_save = array();

foreach($graph_templates_items as $item_id => $data) {
$item_new = array();
$item_new['aggregate_template_id'] = $id;
Expand Down Expand Up @@ -230,7 +235,6 @@ function aggregate_get_graph_items($table, $id) {

}


/* ------------------------
The 'actions' function
------------------------ */
Expand All @@ -242,7 +246,7 @@ function aggregate_form_actions() {
include_once($config['base_path'] . '/api_aggregate.php');

/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('drp_action'));
get_filter_request_var('drp_action');
/* ==================================================== */

/* if we are to save this form, instead of display it */
Expand Down Expand Up @@ -322,11 +326,11 @@ function aggregate_template_edit() {
global $image_types, $struct_aggregate_template;

/* ================= input validation ================= */
input_validate_input_number(get_request_var('id'));
get_filter_request_var('id');
/* ==================================================== */

if (!empty($_GET['id'])) {
$template = db_fetch_row('SELECT * FROM aggregate_graph_templates WHERE id=' . $_GET['id']);
if (!isempty_request_var('id')) {
$template = db_fetch_row('SELECT * FROM aggregate_graph_templates WHERE id=' . get_request_var('id'));
$header_label = '[edit: ' . $template['name'] . ']';
}else{
$header_label = '[new]';
Expand All @@ -335,7 +339,7 @@ function aggregate_template_edit() {
/* populate the graph template id if it's set */
if (isset_request_var('graph_template_id') && !isset($template)) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var('graph_template_id'));
get_filter_request_var('graph_template_id');
/* ==================================================== */
$template['graph_template_id'] = get_request_var_post('graph_template_id');
$template['id'] = 0;
Expand All @@ -359,14 +363,13 @@ function aggregate_template_edit() {
draw_aggregate_template_graph_config($template['id'], $template['graph_template_id']);
}


form_hidden_box('id', (isset($template['id']) ? $template['id'] : '0'), '0');
form_hidden_box('save_component_template', '1', '');
form_save_button('aggregate_templates.php', 'return', 'id');

?>
<script type='text/javascript'>
$().ready(function() {
$(function() {
if ($('#id').val() == 0) {
$('[id^="agg_total_"]').prop('checked', true);
}
Expand Down Expand Up @@ -453,7 +456,6 @@ function changeTotalsType() {
}
}
}
-->
</script>
<?php
}
Expand All @@ -465,8 +467,8 @@ function aggregate_template() {
global $aggregate_actions, $item_rows, $config;

/* ================= input validation ================= */
input_validate_input_number(get_request_var('page'));
input_validate_input_number(get_request_var('rows'));
get_filter_request_var('page');
get_filter_request_var('rows');
/* ==================================================== */

/* clean up search string */
Expand Down Expand Up @@ -532,26 +534,28 @@ function aggregate_template() {
html_start_box('Aggregate Templates', '100%', '', '3', 'center', 'aggregate_templates.php?action=edit');

$filter_html = '<tr class="even">
<td>
<table class="filterTable">
<tr>
<td>
Search
</td>
<td>
<input type="text" id="filter" size="25" value="' . get_request_var("filter") . '">
</td>
<td>
Templates
</td>
<td>
<table class="filterTable">
<tr>
<td>
Search
</td>
<td>
<input type="text" id="filter" size="25" value="' . get_request_var("filter") . '">
</td>
<td>
Templates
</td>
<td>
<select id="rows" onChange="applyFilter()">
<option value="-1"';
<select id="rows" onChange="applyFilter()">
<option value="-1"';

if (get_request_var("rows") == "-1") {
$filter_html .= 'selected';
}

$filter_html .= '>Default</option>';
if (sizeof($item_rows) > 0) {
if (sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
$filter_html .= "<option value='" . $key . "'";
if (get_request_var("rows") == $key) {
Expand All @@ -560,25 +564,26 @@ function aggregate_template() {
$filter_html .= ">" . $value . "</option>\n";
}
}
$filter_html .= ' </select>
</td>
<td>
<input type="checkbox" id="has_graphs" ' . ($_REQUEST['has_graphs'] == 'true' ? 'checked':'') . ' onChange="applyFilter()">
</td>
<td>
<label for="has_graphs">Has Graphs</label>
</td>
<td>
<input type="button" value="Go" id="refresh">
</td>
<td>
<input type="button" value="Clear" id="clear">
</td>
</tr>
</table>

$filter_html .= '</select>
</td>
<td>
<input type="checkbox" id="has_graphs" ' . (get_request_var('has_graphs') == 'true' ? 'checked':'') . ' onChange="applyFilter()">
</td>
<td>
<label for="has_graphs">Has Graphs</label>
</td>
<td>
<input type="button" value="Go" id="refresh">
</td>
<td><input type="hidden" id="page" value="' . $_REQUEST['page'] . '"></td>
</tr>';
<td>
<input type="button" value="Clear" id="clear">
</td>
</tr>
</table>
</td>
<td><input type="hidden" id="page" value="' . get_request_var('page') . '"></td>
</tr>';

print $filter_html;

Expand All @@ -588,11 +593,11 @@ function aggregate_template() {

/* form the 'where' clause for our main sql query */
$sql_where = '';
if (strlen($_REQUEST['filter'])) {
$sql_where = "WHERE (pgt.name LIKE '%%" . $_REQUEST['filter'] . "%%' OR gt.name LIKE '%%" . $_REQUEST['filter'] . "%%')";
if (get_request_var('filter') != '') {
$sql_where = "WHERE (pgt.name LIKE '%" . get_request_var('filter') . "%' OR gt.name LIKE '%" . get_request_var('filter') . "%')";
}

if ($_REQUEST['has_graphs'] == 'true') {
if (get_request_var('has_graphs') == 'true') {
$sql_where .= (strlen($sql_where) ? ' AND ':'WHERE ') . 'graphs.graphs>0';
}

Expand Down Expand Up @@ -624,7 +629,7 @@ function aggregate_template() {
LEFT JOIN graph_templates AS gt
ON gt.id=pgt.graph_template_id
$sql_where
ORDER BY " . $_REQUEST['sort_column'] . ' ' . $_REQUEST['sort_direction'] .
ORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') .
' LIMIT ' . (get_request_var('rows')*(get_request_var('page')-1)) . ',' . get_request_var('rows'));

$nav = html_nav_bar('aggregate_templates.php', MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('rows'), $total_rows, 5, 'Aggregate Templates', 'page', 'main');
Expand All @@ -637,7 +642,7 @@ function aggregate_template() {
'graphs.graphs' => array('display' => 'Graphs', 'align' => 'right', 'sort' => 'DESC'),
'graph_template_name' => array('display' => 'Graph Template', 'align' => 'left', 'sort' => 'ASC'));

html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);

if (sizeof($template_list)) {
foreach ($template_list as $template) {
Expand Down
18 changes: 9 additions & 9 deletions auth_changepassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
/* set default action */
set_default_action();

switch ($_REQUEST['action']) {
switch (get_request_var('action')) {
case 'changepassword':
if ($user['password'] != md5($_POST['current_password'])) {
if ($user['password'] != md5(get_nfilter_request_var('current_password'))) {
$bad_password = true;
$errorMessage = "<span color='#FF0000'>Your current password is not correct. Please try again.</span>";
}
Expand All @@ -97,7 +97,7 @@
$errorMessage = "<span color='#FF0000'>You can not use a previously entered password!</span>";
}

if ($bad_password == false && get_request_var_post('password') == $_POST['confirm'] && $_POST['password'] != '') {
if ($bad_password == false && get_request_var_post('password') == get_nfilter_request_var('confirm') && get_nfilter_request_var('password') != '') {
// Password change is good to go
if (read_config_option('secpass_expirepass') > 0) {
db_execute("UPDATE user_auth SET lastchange = " . time() . " WHERE id = " . intval($_SESSION['sess_user_id']) . " AND realm = 0 AND enabled = 'on'");
Expand Down Expand Up @@ -127,18 +127,18 @@
$realm_id = $user_auth_realm_filenames['index.php'];
$has_console = db_fetch_cell('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array($_SESSION['sess_user_id'], $realm_id));

if (basename($_POST['ref']) == 'auth_changepassword.php' || basename($_POST['ref']) == '') {
if (basename(get_nfilter_request_var('ref')) == 'auth_changepassword.php' || basename(get_nfilter_request_var('ref')) == '') {
if ($has_console) {
$_POST['ref'] = 'index.php';
set_request_var('ref', 'index.php');
}else{
$_POST['ref'] = 'graph_view.php';
set_request_var('ref', 'graph_view.php');
}
}

if (!empty($has_console)) {
switch ($user['login_opts']) {
case '1': /* referer */
header('Location: ' . sanitize_uri($_POST['ref'])); break;
header('Location: ' . sanitize_uri(get_nfilter_request_var('ref'))); break;
case '2': /* default console page */
header('Location: index.php'); break;
case '3': /* default graph page */
Expand All @@ -164,7 +164,7 @@

if ($bad_password && $errorMessage == "") {
$errorMessage = "<span color='#FF0000'>Your new passwords do not match, please retype.</span>";
}elseif ($_REQUEST['action'] == 'force') {
}elseif (get_request_var('action') == 'force') {
$errorMessage = "<span color='#FF0000'>*** Forced password change ***</span>";
}

Expand Down Expand Up @@ -192,7 +192,7 @@
<legend>Change Password</legend>
<form name='login' method='post' action='" . basename($_SERVER['PHP_SELF']) . "'>
<input type='hidden' name='action' value='changepassword'>
<input type='hidden' name='ref' value='" . (isset($_REQUEST['ref']) ? sanitize_uri($_REQUEST['ref']) : '') . "'>
<input type='hidden' name='ref' value='" . sanitize_uri(get_request_var('ref')) . "'>
<input type='hidden' name='name' value='" . (isset($user['username']) ? $user['username'] : '') . "'>
<div class='loginTitle'>
<p>Please enter your current password and your new<br>Cacti password.</p>
Expand Down
Loading

0 comments on commit 2387bd4

Please sign in to comment.