Skip to content

Commit

Permalink
WG tunnel download validation. Fixes #12731
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-p committed Jan 26, 2022
1 parent 3364533 commit 6914215
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 deletions net/pfSense-pkg-WireGuard/Makefile
@@ -1,5 +1,6 @@
PORTNAME= pfSense-pkg-WireGuard
PORTVERSION= 0.1.6
PORTREVISION= 1
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
Expand Up @@ -919,6 +919,8 @@ function wg_make_tunnel_conf_file($tunnel, $include_endpoint = false) {
function wg_download_tunnel($tunnel_name, $failure_redirect) {
global $wgg;

$tunnel_name = basename(trim($tunnel_name));

// Fetch and build the latest info
wg_resync();

Expand Down
55 changes: 36 additions & 19 deletions net/pfSense-pkg-WireGuard/files/usr/local/www/wg/vpn_wg_tunnels.php
Expand Up @@ -63,27 +63,44 @@

if (isset($_POST['tun'])) {
$tun_name = $_POST['tun'];
switch ($_POST['act']) {
case 'download':
wg_download_tunnel($tun_name, '/wg/vpn_wg_tunnels.php');
exit();
break;

case 'toggle':
$res = wg_toggle_tunnel($tun_name);
break;

case 'delete':
$res = wg_delete_tunnel($tun_name);
break;

default:
// Shouldn't be here, so bail out.
header('Location: /wg/vpn_wg_tunnels.php');
break;

/* Check if the submitted tunnel exists
* https://redmine.pfsense.org/issues/12731
*/
$tun_found = false;
if (is_array($wgg['tunnels']) && count($wgg['tunnels']) > 0) {
foreach ($wgg['tunnels'] as $tunnel) {
if ($tunnel['name'] == $tun_name) {
$tun_found = true;
break;
}
}
}

$input_errors = $res['input_errors'];
if ($tun_found) {
switch ($_POST['act']) {
case 'download':
wg_download_tunnel($tun_name, '/wg/vpn_wg_tunnels.php');
exit();
break;
case 'toggle':
$res = wg_toggle_tunnel($tun_name);
break;
case 'delete':
$res = wg_delete_tunnel($tun_name);
break;
default:
// Shouldn't be here, so bail out.
header('Location: /wg/vpn_wg_tunnels.php');
break;
}
$input_errors = $res['input_errors'];
} else {
/* User submitted a tunnel that does not exist, so bail.
* https://redmine.pfsense.org/issues/12731
*/
$input_errors = array(gettext("The requested tunnel does not exist."));
}

if (empty($input_errors)) {
if (wg_is_service_running() && $res['changes']) {
Expand Down

0 comments on commit 6914215

Please sign in to comment.