Commit f2219ed4 authored by Franco Fichtner's avatar Franco Fichtner

src: add portable url_safe() like we have exec_safe(); closes #1068

(cherry picked from commit 35ec2adc)
(cherry picked from commit f52dd530)
(cherry picked from commit 54ec6487)
parent ecdba588
...@@ -988,6 +988,21 @@ function log_error($error) ...@@ -988,6 +988,21 @@ function log_error($error)
syslog(LOG_ERR, "$page: $error"); syslog(LOG_ERR, "$page: $error");
} }
function url_safe($format, $args = array())
{
if (!is_array($args)) {
/* just in case there's only one argument */
$args = array($args);
}
foreach ($args as $id => $arg) {
$args[$id] = urlencode($arg);
}
return vsprintf($format, $args);
}
/****f* util/exec_command /****f* util/exec_command
* NAME * NAME
* exec_command - Execute a command and return a string of the result. * exec_command - Execute a command and return a string of the result.
......
...@@ -33,19 +33,19 @@ require_once("interfaces.inc"); ...@@ -33,19 +33,19 @@ require_once("interfaces.inc");
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if(!empty($_GET['if'])) { if(!empty($_GET['if'])) {
$if = htmlspecialchars($_GET['if']); $if = $_GET['if'];
} }
if (!empty($_GET['savemsg']) && $_GET['savemsg'] == 'rescan') { if (!empty($_GET['savemsg']) && $_GET['savemsg'] == 'rescan') {
$savemsg = gettext("Rescan has been initiated in the background. Refresh this page in 10 seconds to see the results."); $savemsg = gettext("Rescan has been initiated in the background. Refresh this page in 10 seconds to see the results.");
} }
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['if'])) { if (!empty($_POST['if'])) {
$if = htmlspecialchars($_POST['if']); $if = $_POST['if'];
} }
$rwlif = escapeshellarg(get_real_interface($if)); $rwlif = escapeshellarg(get_real_interface($if));
if(!empty($_POST['rescanwifi'])) { if(!empty($_POST['rescanwifi'])) {
mwexec_bg("/sbin/ifconfig {$rwlif} scan 2>&1"); mwexecf_bg('/sbin/ifconfig %s scan', $rwlif);
header("Location: status_wireless.php?if=" . $if. "&savemsg=rescan"); header(url_safe('Location: status_wireless.php?if=%s&savemsg=rescan', $if));
exit; exit;
} }
} }
...@@ -86,7 +86,7 @@ include("head.inc"); ...@@ -86,7 +86,7 @@ include("head.inc");
?> ?>
<div class="content-box"> <div class="content-box">
<form method="post" name="iform" id="iform"> <form method="post" name="iform" id="iform">
<input type="hidden" name="if" id="if" value="<?=$if;?>"> <input type="hidden" name="if" id="if" value="<?= html_safe($if) ?>">
<header class="content-box-head container-fluid"> <header class="content-box-head container-fluid">
<h3><?=gettext("Nearby access points or ad-hoc peers"); ?></h3> <h3><?=gettext("Nearby access points or ad-hoc peers"); ?></h3>
</header> </header>
......
...@@ -173,7 +173,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -173,7 +173,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($a_user[$id]); unset($a_user[$id]);
write_config(); write_config();
$savemsg = sprintf(gettext('The user "%s" was successfully removed.'), $userdeleted); $savemsg = sprintf(gettext('The user "%s" was successfully removed.'), $userdeleted);
header("Location: system_usermanager.php?savemsg=".$savemsg); header(url_safe('Location: system_usermanager.php?savemsg=%s', $savemsg));
exit; exit;
} }
} elseif ($act == "delcert" && isset($id)) { } elseif ($act == "delcert" && isset($id)) {
...@@ -183,7 +183,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -183,7 +183,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($a_user[$id]['cert'][$pconfig['certid']]); unset($a_user[$id]['cert'][$pconfig['certid']]);
write_config(); write_config();
$savemsg = sprintf(gettext('The certificate association "%s" was successfully removed.'), $certdeleted); $savemsg = sprintf(gettext('The certificate association "%s" was successfully removed.'), $certdeleted);
header("Location: system_usermanager.php?savemsg=".$savemsg."&act=edit&userid=".$id); header(url_safe('Location: system_usermanager.php?savemsg=%s&act=edit&userid=%s', array($savemsg, $id)));
exit; exit;
} elseif ($act == "newApiKey" && isset($id)) { } elseif ($act == "newApiKey" && isset($id)) {
// every action is using the sequence of the user, to keep it understandable, we will use // every action is using the sequence of the user, to keep it understandable, we will use
...@@ -209,7 +209,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -209,7 +209,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$savemsg = gettext('No API key found'); $savemsg = gettext('No API key found');
} }
// redirect // redirect
header("Location: system_usermanager.php?savemsg=".$savemsg."&act=edit&userid=".$id); header(url_safe('Location: system_usermanager.php?savemsg=%s&act=edit&userid=%s', array($savemsg, $id)));
exit; exit;
} elseif (isset($pconfig['save'])) { } elseif (isset($pconfig['save'])) {
// save user // save user
...@@ -347,17 +347,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -347,17 +347,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($pconfig['chkNewCert'])) { if (!empty($pconfig['chkNewCert'])) {
// redirect to cert manager when a new cert is requested for this user // redirect to cert manager when a new cert is requested for this user
header("Location: system_certmanager.php?act=new&userid=".(count($a_user)-1)); header(url_safe('Location: system_certmanager.php?act=new&userid=%s', count($a_user) - 1));
} else { } else {
header("Location: system_usermanager.php"); header(url_safe('Location: system_usermanager.php'));
exit; exit;
} }
} }
} elseif (isset($id)) { } elseif (isset($id)) {
header("Location: system_usermanager.php?userid=".$id); header(url_safe('Location: system_usermanager.php?userid=%s', $id));
exit; exit;
} else { } else {
header("Location: system_usermanager.php"); header(url_safe('Location: system_usermanager.php'));
exit; exit;
} }
} }
......
...@@ -52,7 +52,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -52,7 +52,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_type = "group"; $input_type = "group";
$id = $_GET['groupid']; $id = $_GET['groupid'];
} else { } else {
header("Location: system_usermanager.php"); header(url_safe('Location: system_usermanager.php'));
exit; exit;
} }
if ($input_type == "group") { if ($input_type == "group") {
...@@ -80,7 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -80,7 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$retval = write_config(); $retval = write_config();
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
header("Location: system_usermanager.php?act=edit&userid=".$userid."&savemsg=".$savemsg); header(url_safe('Location: system_usermanager.php?act=edit&userid=%s&savemsg=%s', array($userid, $savemsg)));
exit; exit;
} elseif ($_POST['input_type'] == 'group' && isset($config['system']['group'][$pconfig['id']]['name'])) { } elseif ($_POST['input_type'] == 'group' && isset($config['system']['group'][$pconfig['id']]['name'])) {
$groupid = $_POST['id']; $groupid = $_POST['id'];
...@@ -101,11 +101,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -101,11 +101,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
write_config(); write_config();
header("Location: system_groupmanager.php?act=edit&groupid={$groupid}"); header(url_safe('Location: system_groupmanager.php?act=edit&groupid=%s', $groupid));
exit; exit;
} }
} }
header("Location: system_usermanager.php"); header(url_safe('Location: system_usermanager.php'));
exit; exit;
} }
......
...@@ -85,14 +85,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -85,14 +85,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = $_POST; $pconfig = $_POST;
if (isset($_POST['create'])) { if (isset($_POST['create'])) {
// create new phase1 entry // create new phase1 entry
header("Location: vpn_ipsec_phase1.php?mobile=true"); header(url_safe('Location: vpn_ipsec_phase1.php?mobile=true'));
exit; exit;
} elseif (isset($_POST['apply'])) { } elseif (isset($_POST['apply'])) {
// apply changes // apply changes
ipsec_configure(); ipsec_configure();
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
clear_subsystem_dirty('ipsec'); clear_subsystem_dirty('ipsec');
header("Location: vpn_ipsec_mobile.php?savemsg=".$savemsg); header(url_safe('Location: vpn_ipsec_mobile.php?savemsg=%s', $savemsg));
exit; exit;
} elseif (isset($_POST['submit'])) { } elseif (isset($_POST['submit'])) {
// save form changes // save form changes
...@@ -173,7 +173,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -173,7 +173,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
write_config(); write_config();
mark_subsystem_dirty('ipsec'); mark_subsystem_dirty('ipsec');
header("Location: vpn_ipsec_mobile.php"); header(url_safe('Location: vpn_ipsec_mobile.php'));
exit; exit;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment