commit 5a24d994097025f8079857588eebc5bc1fa8208b
Author: Viktor Gurov <viktor@netgate.com>
Date:   Tue Dec 31 09:46:49 2019 +0300

    fixes

diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc
index ee4e7078a8..b64e5b73bb 100644
--- a/src/etc/inc/gwlb.inc
+++ b/src/etc/inc/gwlb.inc
@@ -2027,7 +2027,7 @@ function save_gateway($gateway_settings, $realid = "") {
 		$realif = get_real_interface($a_gateway_item[$realid]['interface']);
 		$inet = (!is_ipaddrv4($a_gateway_item[$realid]['gateway']) ? "-inet6" : "-inet");
 		$rgateway = $a_gateway_item[$realid]['gateway'];
-		$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateway_item[$realid]['gateway']) . " -iface " . escapeshellarg($realif . " " . escapeshellarg($rgateway));
+		$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateway_item[$realid]['gateway']) . " -iface " . escapeshellarg($realif) . " " . escapeshellarg($rgateway);
 		mwexec($cmd);
 	}
 
@@ -2127,7 +2127,7 @@ function gateway_set_enabled($name, $enabled) {
 					$cgw = getcurrentdefaultgatewayip('inet6');
 				}
 				if ($gateway['gateway'] == $cgw) {
-					mwexec("/sbin/route delete -{$inet} default {$cgw}");
+					mwexec("/sbin/route delete -{$inet} default " . escapeshellarg{$cgw});
 				}
 			}
 			$gateway['disabled'] = true;
diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc
index 3b95d6be59..9ef445244a 100644
--- a/src/etc/inc/system.inc
+++ b/src/etc/inc/system.inc
@@ -202,8 +202,8 @@ function system_resolvconf_generate($dynupdate = false) {
 				route_add_or_change("-host {$inet6}{$dnsserver} {$gatewayip}");
 			} else {
 				/* Remove old route when disable gw */
-				$gatewayip = exec("/sbin/route -n show {$dnsserver} | grep gateway | cut -d' ' -f6");
-				mwexec("/sbin/route -q delete -host {$inet6}{$dnsserver} {$gatewayip}");
+				$gatewayip = exec("/sbin/route -n get {$dnsserver} | /usr/bin/awk '/gateway:/ {print $2;}'");
+				mwexec("/sbin/route -q delete -host {$inet6}{$dnsserver} " . escapeshellarg($gatewayip));
 				if (isset($config['system']['route-debug'])) {
 					$mt = microtime();
 					log_error("ROUTING debug: $mt - route delete -host {$inet6}{$dnsserver} {$gatewayip}");
diff --git a/src/usr/local/www/system_gateways.php b/src/usr/local/www/system_gateways.php
index 1b17557d1e..c5f9eba745 100644
--- a/src/usr/local/www/system_gateways.php
+++ b/src/usr/local/www/system_gateways.php
@@ -142,9 +142,8 @@ function delete_gateway_item($id) {
 	    !isset($a_gateways[$id]['disabled']) &&
 	    isset($a_gateways[$id]['isdefaultgw'])) {
 		$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? '-inet6' : '-inet');
-		$rgateway = $a_gateways[$id]['gateway'];
 		file_put_contents("/dev/console", "\n[".getmypid()."] DEL_GW, route= delete {$inet} default");
-		mwexec("/sbin/route delete {$inet} default {$rgateway}");
+		mwexec("/sbin/route delete {$inet} default " . escapeshellarg($a_gateways[$id]['gateway']));
 	}
 
 	/* NOTE: Cleanup static routes for the interface route if any */
diff --git a/src/usr/local/www/system_routes_edit.php b/src/usr/local/www/system_routes_edit.php
index 98da335b96..21c5662c1e 100644
--- a/src/usr/local/www/system_routes_edit.php
+++ b/src/usr/local/www/system_routes_edit.php
@@ -199,8 +199,9 @@ if ($_POST['save']) {
 				foreach ($delete_targets as $dts) {
 					if (is_ipaddrv6($dts)) {
 						$family = "-inet6";
-					$rgateway = exec("/sbin/route -n show {$dts} | grep gateway | cut -d' ' -f6");
-					$toapplylist[] = "/sbin/route delete {$family} {$dts} {$rgateway}";
+					}
+					$rgateway = exec("/sbin/route -n get {$dts} | /usr/bin/awk '/gateway:/ {print $2;}'");
+					$toapplylist[] = "/sbin/route delete {$family} {$dts} " . escapeshellarg($rgateway);
 				}
 			}
 		}
diff --git a/src/usr/local/www/vpn_ipsec.php b/src/usr/local/www/vpn_ipsec.php
index 920863204b..c478be5ffc 100644
--- a/src/usr/local/www/vpn_ipsec.php
+++ b/src/usr/local/www/vpn_ipsec.php
@@ -197,8 +197,8 @@ if ($_POST['apply']) {
 	} else if (isset($delbtn)) {
 		/* remove static route if interface is not WAN */
 		if ($a_phase1[$delbtn]['interface'] <> "wan") {
-			$rgateway = exec("/sbin/route -n show {$a_phase1[$delbtn]['remote-gateway']} | grep gateway | cut -d' ' -f6");
-			mwexec("/sbin/route delete -host {$a_phase1[$delbtn]['remote-gateway']} {$rgateway}");
+			$rgateway = exec("/sbin/route -n get {$a_phase1[$delbtn]['remote-gateway']} | /usr/bin/awk '/gateway:/ {print $2;}'");
+			mwexec("/sbin/route delete -host {$a_phase1[$delbtn]['remote-gateway']} " escapeshellarg($rgateway));
 		}
 
 		/* remove all phase2 entries that match the ikeid */
diff --git a/src/usr/local/www/vpn_ipsec_phase1.php b/src/usr/local/www/vpn_ipsec_phase1.php
index d9399a4cb9..9f4bfd406b 100644
--- a/src/usr/local/www/vpn_ipsec_phase1.php
+++ b/src/usr/local/www/vpn_ipsec_phase1.php
@@ -468,8 +468,8 @@ if ($_POST['save']) {
 		/* the ipsec_configure() handles adding the route */
 		if ($pconfig['interface'] <> "wan") {
 			if ($old_ph1ent['remote-gateway'] <> $pconfig['remotegw']) {
-                                $rgateway = exec("/sbin/route -n show {$old_ph1ent} | grep gateway | cut -d' ' -f6");
-				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']} {$rgateway}");
+                                $rgateway = exec("/sbin/route -n get {$old_ph1ent} | /usr/bin/awk '/gateway:/ {print $2;}'");
+				mwexec("/sbin/route delete -host {$old_ph1ent['remote-gateway']} " . escapeshellarg($rgateway));
 			}
 		}
 
