Project

General

Profile

« Previous | Next » 

Revision d173230c

Added by Seth Mos over 17 years ago

Add prelimenary Routing page.
Allow multiple gateways on one (static) interface

View differences:

etc/inc/interfaces.inc
859 859
				mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
860 860
					escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']));
861 861
			}
862
			/* install default route */
863
			mwexec("/sbin/route delete default");
864

  
865
			$dont_add_route = false;
866
			/* if OLSRD is enabled, allow WAN to house DHCP. */
867
			if($config['installedpackages']['olsrd']) {
868
				foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
869
						if($olsrd['enabledyngw'] == "on") {
870
							$dont_add_route = true;
871
						}
872
				}
873
			}
874

  
875
			if($dont_add_route == false)
876
				mwexec("/sbin/route add default " . escapeshellarg($config['interfaces']['wan']['gateway']));
877 862

  
878 863
			/* resync pf (done automatically for DHCP/PPPoE/PPTP) */
879 864
			filter_configure();
etc/inc/pfsense-utils.inc
3380 3380
		$gw = file_get_contents("{$g['tmp_path']}/{$realif}_router");
3381 3381
		$gw = rtrim($gw);
3382 3382
	} else {
3383
		$gw = $config['interfaces'][$interface]['gateway'];
3383
		foreach($config['gateways']['gateway_item'] as $gateway) {
3384
			if($gateway['name'] == $gateway['name']) {
3385
				$gatewayip = $gateway['gateway'];
3386
				$interfacegw = $gateway['interface'];
3387
			}
3388
		}
3389
		$gw = $gatewayip;
3384 3390
	}
3385 3391
	/* if wan is requested, return it */
3386 3392
	if($interface == "wan")
etc/inc/system.inc
251 251
		unlink("{$g['vardb_path']}/routes.db");
252 252
	}
253 253

  
254
	/* if list */
255
	$iflist = array("lan", "wan");
256
	for ($i = 1; isset($config['interfaces']['opt' . $i]['enable']); $i++)
257
		$iflist['opt' . $i] = "opt{$i}";
258

  
259
	$dont_remove_route = false;
260
	foreach ($iflist as $ifent => $ifname) {
261
		/* do not process interfaces that will end up with gateways */
262
		if($config['interfaces'][$ifname]['ipaddr'] == "dhcp" or
263
			$config['interfaces'][$ifname]['ipaddr'] == "bigpond" or
264
			$config['interfaces'][$ifname]['ipaddr'] == "pppoe" or
265
			$config['interfaces'][$ifname]['ipaddr'] == "pptp")
266
			$dont_remove_route = true;
267
	}
268

  
269
	if($dont_remove_route == false) {
270
		/* remove default route */
271
		mwexec("/sbin/route delete default");
272
	}
273

  
274
	$dont_add_route = false;
275
	/* if OLSRD is enabled, allow WAN to house DHCP. */
276
	if($config['installedpackages']['olsrd']) {
277
		foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
278
			if($olsrd['enabledyngw'] == "on") {
279
				$dont_add_route = true;
280
			}
281
		}
282
	}
283

  
284
	if($dont_add_route == false) {
285
		foreach($config['gateways']['gateway_item'] as $gateway) {
286
	        	if(isset($gateway['defaultgw'])) {
287
				$gatewayip = $gateway['gateway'];
288
				$interfacegw = $gateway['interface'];
289
			}
290
		}
291
		mwexec("/sbin/route add default " . escapeshellarg($gatewayip));
292
	}
293

  
254 294
	if (is_array($config['staticroutes']['route'])) {
255 295

  
256 296
		$fd = fopen("{$g['vardb_path']}/routes.db", "w");
......
260 300
		}
261 301

  
262 302
		foreach ($config['staticroutes']['route'] as $rtent) {
303
			foreach($config['gateways']['gateway_item'] as $gateway) {
304
				if($rtent['gateway'] == $gateway['name']) {
305
					$gatewayip = $gateway['gateway'];
306
					$interfacegw = $gateway['interface'];
307
				}
308
			}
263 309
			if(isset($rtent['interfacegateway'])) {
264 310
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
265
					" -iface " . escapeshellarg(convert_friendly_interface_to_real_interface_name($rtent['interface'])));
311
					" -iface " . escapeshellarg(convert_friendly_interface_to_real_interface_name($interfacegw)));
266 312
			} else {
267 313
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
268
					" " . escapeshellarg($rtent['gateway']));
314
					" " . escapeshellarg($gatewayip));
269 315
			}
270 316
			/* record route so it can be easily removed later (if necessary) */
271 317
			fwrite($fd, $rtent['network'] . "\n");
etc/inc/xmlparse.inc
36 36
		"earlyshellcmd encryption-algorithm-option field fieldname hash-algorithm-option " .
37 37
		"hosts group interface_array item key lbpool menu mobilekey mount onetoone option package passthrumac priv proxyarpnet " .
38 38
		"queue pages pipe route row rule schedule service servernat servers serversdisabled earlyshellcmd shellcmd staticmap subqueue " .
39
		"timerange tunnel user vip virtual_server vlan winsserver ntpserver wolentry widget depends_on_package");
39
		"timerange tunnel user vip virtual_server vlan winsserver ntpserver wolentry widget depends_on_package gateway_item");
40 40
	return $ret;
41 41
}
42 42

  
......
259 259
	return $xmlconfig;
260 260
}
261 261

  
262
?>
262
?>
usr/local/www/fbegin.inc
127 127
							<li><a href="/pkg_mgr.php" class="navlnk">Packages</a></li>
128 128
						<?php endif; ?>
129 129
							<li><a href="/wizard.php?xml=setup_wizard.xml" class="navlnk">Setup wizard</a></li>
130
							<li><a href="/system_routes.php" class="navlnk">Static routes</a></li>
130
							<li><a href="/system_gateways.php" class="navlnk">Routing</a></li>
131 131
							<li><a href="/firewall_system_tunables.php" class="navlnk">Tunables</a></li>
132 132
							<li><a href="/system_usermanager.php" class="navlnk">User Manager</a></li>
133 133
						</ul>
usr/local/www/interfaces.php
68 68

  
69 69
require("guiconfig.inc");
70 70

  
71
if (!is_array($config['gateways']['gateway_item']))
72
	$config['gateways']['gateway_item'] = array();
73
$a_gateways = &$config['gateways']['gateway_item'];
74

  
71 75
$wancfg = &$config['interfaces']['wan'];
72 76
$optcfg = &$config['interfaces']['wan'];
73 77

  
......
136 140
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
137 141
$pconfig['alias-address'] = $wancfg['alias-address'];
138 142
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
139
$pconfig['use_rrd_gateway'] = $wancfg['use_rrd_gateway'];
140 143

  
141 144
if ($wancfg['ipaddr'] == "dhcp") {
142 145
	$pconfig['type'] = "DHCP";
......
252 255
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
253 256
		$input_errors[] = "A valid alias subnet bit count must be specified.";
254 257
	}
255
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
256
		$input_errors[] = "A valid gateway must be specified.";
258
	if ($_POST['gateway']) {
259
		$match = false;
260
		foreach($a_gateways as $gateway) {
261
			if(in_array($_POST['gateway'], $gateway)) {
262
				$match = true;
263
			}
264
		}
265
		if(!$match)
266
			$input_errors[] = "A valid gateway must be specified.";
257 267
	}
258 268
	if (($_POST['pointtopoint'] && !is_ipaddr($_POST['pointtopoint']))) {
259 269
		$input_errors[] = "A valid point-to-point IP address must be specified.";
......
264 274
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
265 275
		$input_errors[] = "The idle timeout value must be an integer.";
266 276
	}
267
	if (($_POST['use_rrd_gateway'] && !is_ipaddr($_POST['use_rrd_gateway']))) {
268
		$input_errors[] = "A valid monitor IP address must be specified.";
269
	}
270 277
	if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && 
271 278
		$_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
272 279
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
......
358 365
			system_start_ftp_helpers();
359 366
		}
360 367

  
361
		/* per interface rrd gateway monitor helper */
362
		if($_POST['use_rrd_gateway'] <> "") {
363
			$wancfg['use_rrd_gateway'] = $_POST['use_rrd_gateway'];
364
		}
365

  
366 368
		if ($_POST['type'] == "Static") {
367 369
			$wancfg['ipaddr'] = $_POST['ipaddr'];
368 370
			$wancfg['subnet'] = $_POST['subnet'];
......
788 790
                </tr><?php endif; ?>
789 791
                <tr>
790 792
                  <td valign="top" class="vncellreq">Gateway</td>
791
                  <td class="vtable"> <input name="gateway" type="text" class="formfld unknown" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>">
793
                  <td class="vtable"><select name="gateway" class="formselect" id="gateway">
794
			<?php
795
			foreach ($a_gateways as $gateway) {
796
				if($gateway['interface'] == "wan") {
797
			?>
798
					<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
799
					<?=htmlspecialchars($gateway['name']);?>
800
					</option>
801
			<?php
802
				}
803
			}
804
			?>
805
			</select> <br>
792 806
                  </td>
793 807
                </tr>
794 808
                <tr>
......
1008 1022
				<strong>Disable the userland FTP-Proxy application</strong>
1009 1023
				<br />
1010 1024
			</td>
1011
		</tr>
1012
		<tr>
1013
			<td width="22%" valign="top" class="vncell">Monitor IP</td>
1014
			<td width="78%" class="vtable">
1015
				<div id="showmonbox">
1016
					<input type="button" onClick="show_mon_config()" value="Advanced"></input> - Show Monitor IP configuration</a>
1017
				</div>
1018
				<div id="showmon" style="display:none">
1019
					<input name="use_rrd_gateway" type="text" id="use_rrd_gateway" value="<?php echo ($wancfg['use_rrd_gateway']) ; ?>" />
1020
					<strong>Alternative monitor IP</strong> <br />
1021
					Enter a alternative address here to be used to monitor the link. This is used for the 
1022
					quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond 
1023
					to icmp requests.</strong>
1024
					<br />
1025
				</div>
1026
			</td>
1027 1025
		</tr>
1028 1026
		        <?php
1029 1027
				/* Wireless interface? */
usr/local/www/interfaces_opt.php
48 48
	return preg_replace('/[^a-z|_|0-9]/i','',$string);
49 49
}
50 50

  
51
if (!is_array($config['gateways']['gateway_item']))
52
	$config['gateways']['gateway_item'] = array();
53
$a_gateways = &$config['gateways']['gateway_item'];
54

  
51 55
$optcfg = &$config['interfaces']['opt' . $index];
52 56
$optcfg['descr'] = remove_bad_chars($optcfg['descr']);
53 57

  
......
62 66
$pconfig['mtu'] = $optcfg['mtu'];
63 67

  
64 68
$pconfig['disableftpproxy'] = isset($optcfg['disableftpproxy']);
65
$pconfig['use_rrd_gateway'] = $optcfg['use_rrd_gateway'];
66 69

  
67 70
/* Wireless interface? */
68 71
if (isset($optcfg['wireless'])) {
......
162 165
				if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
163 166
					$input_errors[] = "A valid subnet bit count must be specified.";
164 167
				}
165
				if($_POST['gateway'] <> "" && !is_ipaddr($_POST['gateway'])) {
166
					$input_errors[] = "A valid gateway must be specified.";
168
				if ($_POST['gateway']) {
169
					$match = false;
170
					foreach($a_gateways as $gateway) {
171
						if(in_array($_POST['gateway'], $gateway)) {
172
							$match = true;
173
						}
174
					}
175
					if(!$match)
176
						$input_errors[] = "A valid gateway must be specified.";
167 177
				}
168 178
			}
169 179
		}
......
217 227
		$optcfg['bridge'] = $_POST['bridge'];
218 228
		$optcfg['enable'] = $_POST['enable'] ? true : false;
219 229

  
220
		/* per interface rrd gateway monitor helper */
221
		if($_POST['use_rrd_gateway'] <> "") {
222
			$optcfg['use_rrd_gateway'] = $_POST['use_rrd_gateway'];
223
		}
224

  
225 230
		if ($_POST['type'] == "Static") {
226 231
			$optcfg['ipaddr'] = $_POST['ipaddr'];
227 232
			$optcfg['subnet'] = $_POST['subnet'];
......
400 405
				 </td>
401 406
				</tr>
402 407
		<tr>
403
                  <td width="22%" valign="top" class="vncell">Gateway</td>
404
                  <td width="78%" class="vtable">
405
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
406
			<br>
407
			If you have multiple WAN connections, enter the next hop gateway (router) IP address here.  Otherwise, leave this option blank.
408
		  <td valign="top" class="vncellreq">Gateway</td>
409
		  <td class="vtable"><select name="gateway" class="formselect" id="gateway">
410
			<?php
411
			foreach ($a_gateways as $gateway) {
412
				if($gateway['interface'] == "opt{$index}") {
413
			?>
414
				<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
415
				<?=htmlspecialchars($gateway['name']);?>
416
				</option>
417
			<?php
418
				}
419
			}
420
			?>
421
			</select> <br>
408 422
		  </td>
409 423
		</tr>
410 424
                <tr>
......
420 434
				<strong>Disable the userland FTP-Proxy application</strong>
421 435
				<br />
422 436
			</td>
423
		</tr>
424
		<tr>
425
			<td width="22%" valign="top" class="vncell">Monitor IP</td>
426
			<td width="78%" class="vtable">
427
			<div id="showmonbox">
428
				<input type="button" onClick="show_mon_config()" value="Advanced"></input> - Show Monitor IP configuration
429
			</div>
430
			<div id="showmon" style="display:none">
431
				<input name="use_rrd_gateway" type="text" id="use_rrd_gateway" value="<?php echo ($optcfg['use_rrd_gateway']) ; ?>" />
432
					<strong>Alternative monitor IP</strong> <br />
433
					Enter a alternative address here to be used to monitor the link. This is used for the
434
					quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
435
					to icmp requests.</strong>
436
					<br />
437
				</div>
438
			</td>
439 437
		</tr>
440 438
				<?php /* Wireless interface? */
441 439
				if (isset($optcfg['wireless']))
usr/local/www/interfaces_wan.php
68 68

  
69 69
require("guiconfig.inc");
70 70

  
71
if (!is_array($config['gateways']['gateway_item']))
72
	$config['gateways']['gateway_item'] = array();
73
$a_gateways = &$config['gateways']['gateway_item'];
74

  
71 75
$wancfg = &$config['interfaces']['wan'];
72 76
$optcfg = &$config['interfaces']['wan'];
73 77

  
......
136 140
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
137 141
$pconfig['alias-address'] = $wancfg['alias-address'];
138 142
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
139
$pconfig['use_rrd_gateway'] = $wancfg['use_rrd_gateway'];
140 143

  
141 144
if ($wancfg['ipaddr'] == "dhcp") {
142 145
	$pconfig['type'] = "DHCP";
......
252 255
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
253 256
		$input_errors[] = "A valid alias subnet bit count must be specified.";
254 257
	}
255
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
256
		$input_errors[] = "A valid gateway must be specified.";
258
	if ($_POST['gateway']) {
259
		$match = false;
260
		foreach($a_gateways as $gateway) {
261
			if(in_array($_POST['gateway'], $gateway)) {
262
				$match = true;
263
			}
264
		}
265
		if(!$match)
266
			$input_errors[] = "A valid gateway must be specified.";
257 267
	}
258 268
	if (($_POST['pointtopoint'] && !is_ipaddr($_POST['pointtopoint']))) {
259 269
		$input_errors[] = "A valid point-to-point IP address must be specified.";
......
264 274
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
265 275
		$input_errors[] = "The idle timeout value must be an integer.";
266 276
	}
267
	if (($_POST['use_rrd_gateway'] && !is_ipaddr($_POST['use_rrd_gateway']))) {
268
		$input_errors[] = "A valid monitor IP address must be specified.";
269
	}
270 277
	if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && 
271 278
		$_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) {
272 279
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
......
358 365
			system_start_ftp_helpers();
359 366
		}
360 367

  
361
		/* per interface rrd gateway monitor helper */
362
		if($_POST['use_rrd_gateway'] <> "") {
363
			$wancfg['use_rrd_gateway'] = $_POST['use_rrd_gateway'];
364
		}
365

  
366 368
		if ($_POST['type'] == "Static") {
367 369
			$wancfg['ipaddr'] = $_POST['ipaddr'];
368 370
			$wancfg['subnet'] = $_POST['subnet'];
......
788 790
                </tr><?php endif; ?>
789 791
                <tr>
790 792
                  <td valign="top" class="vncellreq">Gateway</td>
791
                  <td class="vtable"> <input name="gateway" type="text" class="formfld unknown" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>">
793
                  <td class="vtable"><select name="gateway" class="formselect" id="gateway">
794
			<?php
795
			foreach ($a_gateways as $gateway) {
796
				if($gateway['interface'] == "wan") {
797
			?>
798
					<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
799
					<?=htmlspecialchars($gateway['name']);?>
800
					</option>
801
			<?php
802
				}
803
			}
804
			?>
805
			</select> <br>
792 806
                  </td>
793 807
                </tr>
794 808
                <tr>
......
1008 1022
				<strong>Disable the userland FTP-Proxy application</strong>
1009 1023
				<br />
1010 1024
			</td>
1011
		</tr>
1012
		<tr>
1013
			<td width="22%" valign="top" class="vncell">Monitor IP</td>
1014
			<td width="78%" class="vtable">
1015
				<div id="showmonbox">
1016
					<input type="button" onClick="show_mon_config()" value="Advanced"></input> - Show Monitor IP configuration</a>
1017
				</div>
1018
				<div id="showmon" style="display:none">
1019
					<input name="use_rrd_gateway" type="text" id="use_rrd_gateway" value="<?php echo ($wancfg['use_rrd_gateway']) ; ?>" />
1020
					<strong>Alternative monitor IP</strong> <br />
1021
					Enter a alternative address here to be used to monitor the link. This is used for the 
1022
					quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond 
1023
					to icmp requests.</strong>
1024
					<br />
1025
				</div>
1026
			</td>
1027 1025
		</tr>
1028 1026
		        <?php
1029 1027
				/* Wireless interface? */
usr/local/www/system_gateways.php
1
<?php
2
/* $Id$ */
3
/*
4
	system_gateways.php
5
	part of pfSense (http://pfsense.com)
6

  
7
	Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>.
8
	All rights reserved.
9

  
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

  
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

  
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

  
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

  
32
require("guiconfig.inc");
33

  
34
if (!is_array($config['gateways']['gateway_item']))
35
	$config['gateways']['gateway_item'] = array();
36

  
37
$a_gateways = &$config['gateways']['gateway_item'];
38
$changedesc = "Gateways: ";
39

  
40
if ($_POST) {
41

  
42
	$pconfig = $_POST;
43

  
44
	if ($_POST['apply']) {
45

  
46
		$retval = 0;
47

  
48
		$retval = system_routing_configure();
49
		$retval |= filter_configure();
50

  
51
		$savemsg = get_std_save_message($retval);
52
		if ($retval == 0) {
53
			if (file_exists($d_staticroutesdirty_path)) {
54
				config_lock();
55
				unlink($d_staticroutesdirty_path);
56
				config_unlock();
57
			}
58
		}
59
	}
60
}
61

  
62
if ($_GET['act'] == "del") {
63
	if ($a_gateways[$_GET['id']]) {
64
		$changedesc .= "removed gateway {$_GET['id']}";
65
		unset($a_gateways[$_GET['id']]);
66
		write_config($changedesc);
67
		touch($d_staticroutesdirty_path);
68
		header("Location: system_gateways.php");
69
		exit;
70
	}
71
}
72

  
73
$pgtitle = "System: Gateways";
74
include("head.inc");
75

  
76
?>
77

  
78
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
79
<?php include("fbegin.inc"); ?>
80
<p class="pgtitle"><?=$pgtitle?></p>
81
<form action="system_gateways.php" method="post">
82
<input type="hidden" name="y1" value="1">
83
<?php if ($savemsg) print_info_box($savemsg); ?>
84
<?php if (file_exists($d_staticroutesdirty_path)): ?><p>
85
<?php print_info_box_np("The gateway configuration has been changed.<br>You must apply the changes in order for them to take 
86
effect.");?><br>
87
<?php endif; ?>
88
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
89
		<tr>
90
		  <td>
91
<?php
92
			$tab_array = array();
93
			$tab_array[0] = array("Gateways", true, "system_gateways.php");
94
			$tab_array[1] = array("Routes", false, "system_routes.php");
95
			display_top_tabs($tab_array);
96
?>
97
		  </td>
98
		</tr>
99
                <tr>
100
                  <td width="15%" class="listhdrr">Name</td>
101
                  <td width="15%" class="listhdrr">Interface</td>
102
                  <td width="20%" class="listhdrr">Gateway</td>
103
                  <td width="20%" class="listhdrr">Monitor IP</td>
104
                  <td width="30%" class="listhdr">Description</td>
105
                  <td width="10%" class="list">
106
			<table border="0" cellspacing="0" cellpadding="1">
107
			   <tr>
108
				<td width="17"></td>
109
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
110
			   </tr>
111
			</table>
112
		  </td>
113
		</tr>
114
			  <?php $i = 0; foreach ($a_gateways as $gateway): ?>
115
                <tr>
116
                  <td class="listlr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
117
                    <?php
118
			echo $gateway['name'];
119
			if(isset($gateway['defaultgw'])) {
120
				echo " <strong>(default)<strong>";
121
			}
122
			?>
123
			
124
                  </td>
125
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
126
                    <?php
127
				$iflabels = array('wan' => 'WAN', 'lan' => 'LAN');
128
				for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
129
					$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
130
				echo htmlspecialchars($iflabels[$gateway['interface']]); ?>
131
                  </td>
132
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
133
				  <?php
134
					if(isset($gateway['interfacegateway'])) {
135
						echo strtoupper($gateway['interface']) . " ";
136
					} else {
137
						echo $gateway['gateway'] . " ";
138
					}
139
				  ?>
140
                  </td>
141
                  <td class="listr" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
142
                    <?=htmlspecialchars($gateway['monitor']);?>&nbsp;
143
                  </td>
144
                  <td class="listbg" ondblclick="document.location='system_gateways_edit.php?id=<?=$i;?>';">
145
                    <font color="#FFFFFF"><?=htmlspecialchars($gateway['descr']);?>&nbsp;
146
                  </td>
147
                  <td valign="middle" nowrap class="list">
148
			<table border="0" cellspacing="0" cellpadding="1">
149
			   <tr>
150
				<td><a href="system_gateways_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
151
				<td><a href="system_gateways.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this gateway?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
152
			   </tr>
153
			   <tr>
154
				<td width="17"></td>
155
				<td><a href="system_gateways_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
156
			   </tr>
157
			</table>
158

  
159
		</tr>
160
			  <?php $i++; endforeach; ?>
161
                <tr>
162
                  <td class="list" colspan="5"></td>
163
                  <td class="list">
164
			<table border="0" cellspacing="0" cellpadding="1">
165
			   <tr>
166
				<td width="17"></td>
167
				<td><a href="system_gateways_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
168
			   </tr>
169
			</table>
170
		  </td>
171
		</tr>
172
              </table>
173
            </form>
174
<?php include("fend.inc"); ?>
175
</body>
176
</html>
usr/local/www/system_gateways_edit.php
1
<?php 
2
/* $Id$ */
3
/*
4
	system_gateways_edit.php
5
	part of pfSense (http://pfsense.com)
6
	
7
	Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>.
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

  
32
require("guiconfig.inc");
33

  
34
if (!is_array($config['gateways']['gateway_item']))
35
	$config['gateways']['gateway_item'] = array();
36

  
37
$a_gateways = &$config['gateways']['gateway_item'];
38

  
39
$id = $_GET['id'];
40
if (isset($_POST['id']))
41
	$id = $_POST['id'];
42

  
43
if (isset($_GET['dup'])) {
44
	$id = $_GET['dup'];
45
}
46

  
47
if (isset($id) && $a_gateways[$id]) {
48
	$pconfig['name'] = $a_gateways[$id]['name'];
49
	$pconfig['interface'] = $a_gateways[$id]['interface'];
50
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
51
	$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
52
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
53
	$pconfig['descr'] = $a_gateways[$id]['descr'];
54
}
55

  
56
if (isset($_GET['dup']))
57
	unset($id);
58

  
59
if ($_POST) {
60

  
61
	unset($input_errors);
62
	$pconfig = $_POST;
63

  
64
	/* input validation */
65
	$reqdfields = explode(" ", "interface name gateway");
66
	$reqdfieldsn = explode(",", "Interface,Name,Gateway");		
67
	
68
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
69
	
70
	if (! isset($_POST['name'])) {
71
		$input_errors[] = "A valid gateway name must be specified.";
72
	}
73
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
74
		$input_errors[] = "A valid gateway IP address must be specified.";
75
	}
76
	if (($_POST['monitor'] && !is_ipaddr($_POST['monitor']))) {
77
		$input_errors[] = "A valid monitor IP address must be specified.";
78
	}
79

  
80
	if ($_POST['defaultgw'] == "yes") {
81
		$i=0;
82
		foreach ($a_gateways as $gateway) {
83
			if($id != $i) {
84
	                        unset($config['gateways']['gateway_item'][$i]['defaultgw']);
85
			} else {
86
	                        $config['gateways']['gateway_item'][$i]['defaultgw'] = true;
87
			}
88
			$i++;
89
		}
90
	} else {
91
		$i=0;
92
		foreach ($a_gateways as $gateway) {
93
			if($id == $i) {
94
	                        unset($config['gateways']['gateway_item'][$i]['defaultgw']);
95
			}
96
			$i++;
97
		}
98
	}
99

  
100
	/* check for overlaps */
101
	foreach ($a_gateways as $gateway) {
102
		if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
103
			continue;
104

  
105
		if ($gateway['name'] == $_POST['name']) {
106
			$input_errors[] = "A gateway with this name \"{$_POST['name']}\" already exists.";
107
			break;
108
		}
109
		if ($gateway['gateway'] == $_POST['gateway']) {
110
			$input_errors[] = "A gateway with the IP address \"{$_POST['gateway']}\" already exists.";
111
			break;
112
		}
113
		if ($gateway['monitor'] == $_POST['monitor']) {
114
			$input_errors[] = "A monitor with the IP address \"{$_POST['monitor']}\" already exists.";
115
			break;
116
		}
117
	}
118

  
119
	if (!$input_errors) {
120
		$gateway = array();
121
		$gateway['interface'] = $_POST['interface'];
122
		$gateway['name'] = $_POST['name'];
123
		$gateway['gateway'] = $_POST['gateway'];
124
		$gateway['defaultgw'] = $_POST['defaultgw'];
125
		$gateway['monitor'] = $_POST['monitor'];
126
		$gateway['descr'] = $_POST['descr'];
127

  
128
		if (isset($id) && $a_gateways[$id])
129
			$a_gateways[$id] = $gateway;
130
		else
131
			$a_gateways[] = $gateway;
132
		
133
		touch($d_staticroutesdirty_path);
134
		
135
		write_config();
136
		
137
		header("Location: system_gateways.php");
138
		exit;
139
	}
140
}
141

  
142
$pgtitle = "System: Gateways: Edit gateway";
143
include("head.inc");
144

  
145
?>
146

  
147
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
148
<?php include("fbegin.inc"); ?>
149
<p class="pgtitle"><?=$pgtitle?></p>
150
<?php if ($input_errors) print_input_errors($input_errors); ?>
151
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
152
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
153
                <tr> 
154
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
155
                  <td width="78%" class="vtable">
156
			<select name="interface" class="formselect">
157
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
158
					  for ($i = 1; isset($config['interfaces']['opt' . $i]['enable']); $i++) {
159
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
160
					  }
161
					  foreach ($interfaces as $iface => $ifacename): ?>
162
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
163
                      <?=htmlspecialchars($ifacename);?>
164
                      </option>
165
                      <?php endforeach; ?>
166
                    </select> <br>
167
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
168
                </tr>
169
                <tr>
170
                  <td width="22%" valign="top" class="vncellreq">Name</td>
171
                  <td width="78%" class="vtable"> 
172
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
173
                    <br> <span class="vexpl">Gateway name</span></td>
174
                </tr>
175
		<tr>
176
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
177
                  <td width="78%" class="vtable"> 
178
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
179
                    <br> <span class="vexpl">Gateway IP address</span></td>
180
                </tr>
181
		<tr>
182
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
183
		  <td width="78%" class="vtable">
184
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
185
			<strong>Default Gateway</strong><br />
186
			This will select the above gateway as the default gateway
187
		  </td>
188
		</tr>
189
		<tr>
190
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
191
		  <td width="78%" class="vtable">
192
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
193
			<strong>Alternative monitor IP</strong> <br />
194
			Enter a alternative address here to be used to monitor the link. This is used for the
195
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
196
			to icmp requests.</strong>
197
			<br />
198
		  </td>
199
		</tr>
200
		<tr>
201
                  <td width="22%" valign="top" class="vncell">Description</td>
202
                  <td width="78%" class="vtable"> 
203
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
204
                    <br> <span class="vexpl">You may enter a description here
205
                    for your reference (not parsed).</span></td>
206
                </tr>
207
                <tr>
208
                  <td width="22%" valign="top">&nbsp;</td>
209
                  <td width="78%"> 
210
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
211
                    <?php if (isset($id) && $a_gateways[$id]): ?>
212
                    <input name="id" type="hidden" value="<?=$id;?>">
213
                    <?php endif; ?>
214
                  </td>
215
                </tr>
216
              </table>
217
</form>
218
<?php include("fend.inc"); ?>
219
<script language="JavaScript">
220
	enable_change();
221
</script>
222
</body>
223
</html>
usr/local/www/system_routes.php
34 34
if (!is_array($config['staticroutes']['route']))
35 35
	$config['staticroutes']['route'] = array();
36 36

  
37
if (!is_array($config['gateways']['gateway_item']))
38
	$config['gateways']['gateway_item'] = array();
39

  
37 40
staticroutes_sort();
38 41
$a_routes = &$config['staticroutes']['route'];
42
$a_gateways = &$config['gateways']['gateway_item'];
39 43
$changedesc = "Static Routes: ";
40 44

  
41 45
if ($_POST) {
......
112 116
	     <?php endif; ?>
113 117

  
114 118
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
119
		<tr>
120
		  <td>
121
<?php
122
			$tab_array = array();
123
			$tab_array[0] = array("Gateways", false, "system_gateways.php");
124
			$tab_array[1] = array("Routes", true, "system_routes.php");
125
                        display_top_tabs($tab_array);
126
?>
127
		  </td>
128
		</tr>
115 129
                <tr>
116
                  <td width="15%" class="listhdrr">Interface</td>
117 130
                  <td width="25%" class="listhdrr">Network</td>
118 131
                  <td width="20%" class="listhdrr">Gateway</td>
132
                  <td width="15%" class="listhdrr">Interface</td>
119 133
                  <td width="30%" class="listhdr">Description</td>
120 134
                  <td width="10%" class="list">
121 135
			<table border="0" cellspacing="0" cellpadding="1">
......
126 140
			</table>
127 141
		  </td>
128 142
		</tr>
129
			  <?php $i = 0; foreach ($a_routes as $route): ?>
130 143
                <tr>
144
			<?php $i = 0; foreach ($a_routes as $route): ?>
131 145
                  <td class="listlr" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
132
                    <?php
133
				  $iflabels = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
134
				  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
135
				  	$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
136
				  echo htmlspecialchars($iflabels[$route['interface']]); ?>
146
                    <?=strtolower($route['network']);?>
137 147
                  </td>
138 148
                  <td class="listr" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
139
                    <?=strtolower($route['network']);?>
149
			<?php
150
				echo $route['gateway'] . " ";
151
			?>
140 152
                  </td>
141 153
                  <td class="listr" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
142
				  <?php
143
					if(isset($route['interfacegateway'])) {
144
						echo strtoupper($route['interface']) . " ";
145
					} else {
146
						echo strtolower($route['gateway']) . " ";
154
			<?php
155
				foreach($a_gateways as $gateway) {
156
					if($gateway['name'] == $route['gateway']) {
157
						echo strtoupper($gateway['interface']) . " ";
147 158
					}
148
				  ?>
159
				}
160

  
161
			?>
149 162
                  </td>
150 163
                  <td class="listbg" ondblclick="document.location='system_routes_edit.php?id=<?=$i;?>';">
151 164
                    <font color="#FFFFFF"><?=htmlspecialchars($route['descr']);?>&nbsp;
......
161 174
				<td><a href="system_routes_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
162 175
			   </tr>
163 176
			</table>
164

  
177
		  </td>
165 178
		</tr>
166 179
			  <?php $i++; endforeach; ?>
167 180
                <tr>
usr/local/www/system_routes_edit.php
33 33

  
34 34
if (!is_array($config['staticroutes']['route']))
35 35
	$config['staticroutes']['route'] = array();
36
if (!is_array($config['gateways']['gateway_item']))
37
	$config['gateways']['gateway_item'] = array();
36 38

  
37 39
staticroutes_sort();
38 40
$a_routes = &$config['staticroutes']['route'];
41
$a_gateways = &$config['gateways']['gateway_item'];
39 42

  
40 43
$id = $_GET['id'];
41 44
if (isset($_POST['id']))
......
46 49
}
47 50

  
48 51
if (isset($id) && $a_routes[$id]) {
49
	$pconfig['interface'] = $a_routes[$id]['interface'];
50 52
	list($pconfig['network'],$pconfig['network_subnet']) = 
51 53
		explode('/', $a_routes[$id]['network']);
52 54
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
......
62 64
	$pconfig = $_POST;
63 65

  
64 66
	/* input validation */
65
	$reqdfields = explode(" ", "interface network network_subnet gateway");
66
	$reqdfieldsn = explode(",", "Interface,Destination network,Destination network bit count,Gateway");		
67
	$reqdfields = explode(" ", "network network_subnet gateway");
68
	$reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway");		
67 69
	
68 70
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
69 71
	
......
73 75
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
74 76
		$input_errors[] = "A valid destination network bit count must be specified.";
75 77
	}
76
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
77
		$input_errors[] = "A valid gateway IP address must be specified.";
78
	if ($_POST['gateway']) {
79
		$match = false;
80
		foreach($a_gateways as $gateway) {
81
			if(in_array($_POST['gateway'], $gateway)) {
82
				$match = true;
83
			}
84
		}
85
		if(!$match)
86
			$input_errors[] = "A valid gateway must be specified.";
78 87
	}
79 88

  
80 89
	/* check for overlaps */
......
91 100

  
92 101
	if (!$input_errors) {
93 102
		$route = array();
94
		$route['interface'] = $_POST['interface'];
95 103
		$route['network'] = $osn;
96 104
		$route['gateway'] = $_POST['gateway'];
97 105
		$route['descr'] = $_POST['descr'];
......
121 129
<?php if ($input_errors) print_input_errors($input_errors); ?>
122 130
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
123 131
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
124
                <tr> 
125
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
126
                  <td width="78%" class="vtable">
127
			<select name="interface" class="formselect">
128
                      <?php $interfaces = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
129
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
130
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
131
					  }
132
					  foreach ($interfaces as $iface => $ifacename): ?>
133
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
134
                      <?=htmlspecialchars($ifacename);?>
135
                      </option>
136
                      <?php endforeach; ?>
137
                    </select> <br>
138
                    <span class="vexpl">Choose which interface this route applies to.</span></td>
139
                </tr>
140 132
                <tr>
141 133
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
142 134
                  <td width="78%" class="vtable"> 
......
151 143
                    </select>
152 144
                    <br> <span class="vexpl">Destination network for this static route</span></td>
153 145
                </tr>
154
				<tr>
146
                <tr> 
155 147
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
156
                  <td width="78%" class="vtable"> 
157
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
158
                    <br> <span class="vexpl">Gateway to be used to reach the destination network</span></td>
148
                  <td width="78%" class="vtable">
149
			<select name="gateway" class="formselect">
150
			<?php
151
				foreach ($a_gateways as $gateway): ?>
152
	                      <option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>> 
153
	                      <?=htmlspecialchars($gateway['name']);?>
154
                      </option>
155
                      <?php endforeach; ?>
156
                    </select> <br>
157
                    <span class="vexpl">Choose which gateway this route applies to.</span></td>
159 158
                </tr>
160
				<tr>
159
		<tr>
161 160
                  <td width="22%" valign="top" class="vncell">Description</td>
162 161
                  <td width="78%" class="vtable"> 
163 162
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">

Also available in: Unified diff