Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	system_routes_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8 38936dc7 Ermal Lu?i
	Copyright (C) 2010 Scott Ullrich
9 5b237745 Scott Ullrich
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32 1d333258 Scott Ullrich
/*
33
	pfSense_MODULE:	routing
34
*/
35 5b237745 Scott Ullrich
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-system-staticroutes-editroute
38
##|*NAME=System: Static Routes: Edit route page
39
##|*DESCR=Allow access to the 'System: Static Routes: Edit route' page.
40
##|*MATCH=system_routes_edit.php*
41
##|-PRIV
42
43 4504a769 Ermal Lu?i
function staticroutecmp($a, $b) {
44
	return strcmp($a['network'], $b['network']);
45
}
46
47 0d64af59 Ermal Lu?i
function staticroutes_sort() {
48
        global $g, $config;
49
50
        if (!is_array($config['staticroutes']['route']))
51
                return;
52
53
        usort($config['staticroutes']['route'], "staticroutecmp");
54
}
55 6b07c15a Matthew Grooms
56 5b237745 Scott Ullrich
require("guiconfig.inc");
57
58
if (!is_array($config['staticroutes']['route']))
59
	$config['staticroutes']['route'] = array();
60 d173230c Seth Mos
if (!is_array($config['gateways']['gateway_item']))
61
	$config['gateways']['gateway_item'] = array();
62 5b237745 Scott Ullrich
63
$a_routes = &$config['staticroutes']['route'];
64 d173230c Seth Mos
$a_gateways = &$config['gateways']['gateway_item'];
65 5b237745 Scott Ullrich
66
$id = $_GET['id'];
67
if (isset($_POST['id']))
68
	$id = $_POST['id'];
69
70 18f7352b Seth Mos
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
}
73
74 5b237745 Scott Ullrich
if (isset($id) && $a_routes[$id]) {
75
	list($pconfig['network'],$pconfig['network_subnet']) = 
76
		explode('/', $a_routes[$id]['network']);
77
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
78
	$pconfig['descr'] = $a_routes[$id]['descr'];
79
}
80
81 18f7352b Seth Mos
if (isset($_GET['dup']))
82
	unset($id);
83
84 5b237745 Scott Ullrich
if ($_POST) {
85
86
	unset($input_errors);
87
	$pconfig = $_POST;
88
89
	/* input validation */
90 d173230c Seth Mos
	$reqdfields = explode(" ", "network network_subnet gateway");
91
	$reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway");		
92 5b237745 Scott Ullrich
	
93
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
94
	
95
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
96
		$input_errors[] = "A valid destination network must be specified.";
97
	}
98
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
99
		$input_errors[] = "A valid destination network bit count must be specified.";
100
	}
101 d173230c Seth Mos
	if ($_POST['gateway']) {
102
		$match = false;
103
		foreach($a_gateways as $gateway) {
104
			if(in_array($_POST['gateway'], $gateway)) {
105
				$match = true;
106
			}
107
		}
108
		if(!$match)
109
			$input_errors[] = "A valid gateway must be specified.";
110 5b237745 Scott Ullrich
	}
111
112
	/* check for overlaps */
113
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
114
	foreach ($a_routes as $route) {
115
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
116
			continue;
117
118
		if ($route['network'] == $osn) {
119
			$input_errors[] = "A route to this destination network already exists.";
120
			break;
121
		}
122
	}
123
124
	if (!$input_errors) {
125
		$route = array();
126
		$route['network'] = $osn;
127
		$route['gateway'] = $_POST['gateway'];
128
		$route['descr'] = $_POST['descr'];
129
130
		if (isset($id) && $a_routes[$id])
131
			$a_routes[$id] = $route;
132
		else
133
			$a_routes[] = $route;
134 0e3aa71c Erik Fonnesbeck
		staticroutes_sort();
135 5b237745 Scott Ullrich
		
136 a368a026 Ermal Lu?i
		mark_subsystem_dirty('staticroutes');
137 5b237745 Scott Ullrich
		
138
		write_config();
139
		
140
		header("Location: system_routes.php");
141
		exit;
142
	}
143
}
144 4df96eff Scott Ullrich
145 d88c6a9f Scott Ullrich
$pgtitle = array("System","Static Routes","Edit route");
146 4df96eff Scott Ullrich
include("head.inc");
147
148 5b237745 Scott Ullrich
?>
149 4df96eff Scott Ullrich
150 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
151
<?php include("fbegin.inc"); ?>
152
<?php if ($input_errors) print_input_errors($input_errors); ?>
153
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
154
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
155 0cece4a2 Scott Ullrich
				<tr>
156
					<td colspan="2" valign="top" class="listtopic">Edit route entry</td>
157
				</tr>	
158 5b237745 Scott Ullrich
                <tr>
159
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
160
                  <td width="78%" class="vtable"> 
161 b5c78501 Seth Mos
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
162 5b237745 Scott Ullrich
				  / 
163 b5c78501 Seth Mos
                    <select name="network_subnet" class="formselect" id="network_subnet">
164 5b237745 Scott Ullrich
                      <?php for ($i = 32; $i >= 1; $i--): ?>
165
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
166
                      <?=$i;?>
167
                      </option>
168
                      <?php endfor; ?>
169
                    </select>
170
                    <br> <span class="vexpl">Destination network for this static route</span></td>
171
                </tr>
172 d173230c Seth Mos
                <tr> 
173 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
174 d173230c Seth Mos
                  <td width="78%" class="vtable">
175 38936dc7 Ermal Lu?i
			<select name="gateway" id="gateway" class="formselect">
176 d173230c Seth Mos
			<?php
177
				foreach ($a_gateways as $gateway): ?>
178
	                      <option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>> 
179
	                      <?=htmlspecialchars($gateway['name']);?>
180
                      </option>
181
                      <?php endforeach; ?>
182 38936dc7 Ermal Lu?i
                    </select> <br />
183
			<div id='addgwbox'>
184
				Choose which gateway this route applies to or <a OnClick="show_add_gateway();" href="#">add a new one</a>.
185
								</div>
186
								<div id='notebox'>
187
								</div>
188
								<div style="display:none" name ="status" id="status">
189
								</div>								
190
								<div style="display:none" id="addgateway" name="addgateway">
191
									<p> 
192
									<table border="1" style="background:#990000; border-style: none none none none; width:225px;"><tr><td>
193
										<table bgcolor="#990000" cellpadding="1" cellspacing="1">
194
											<tr><td>&nbsp;</td>
195
											<tr>
196
												<td colspan="2"><center><b><font color="white">Add new gateway:</b></center></td>
197
											</tr>
198
											<tr><td>&nbsp;</td>
199
											<tr>
200
												<td width="45%" align="right"><font color="white">Default  gateway:</td><td><input type="checkbox" id="defaultgw" name="defaultgw"<?=$checked?>></td>
201
											</tr>												
202
											<tr>
203
												<td width="45%" align="right"><font color="white">Interface:</td>
204
												<td><select name="addinterfacegw" id="addinterfacegw">
205
												<?php $gwifs = get_configured_interface_with_descr();
206
													foreach($gwifs as $fif => $dif)
207
														echo "<option value=\"{$fif}\">{$dif}</option>\n";
208
												?>
209
												</select></td>
210
											</tr>
211
											<tr>
212
												<td align="right"><font color="white">Gateway Name:</td><td><input id="name" name="name" value="GW"></td>
213
											</tr>
214
											<tr>
215
												<td align="right"><font color="white">Gateway IP:</td><td><input id="gatewayip" name="gatewayip"></td>
216
											</tr>
217
											<tr>
218
												<td align="right"><font color="white">Description:</td><td><input id="gatewaydescr" name="gatewaydescr"></td>
219
											</tr>
220
											<tr><td>&nbsp;</td>
221
											<tr>
222
												<td colspan="2">
223
													<center>
224
														<div id='savebuttondiv'>
225
															<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
226
															<input id="gwsave" type="Button" value="Save Gateway" onClick='hide_add_gatewaysave();'> 
227
															<input id="gwcancel" type="Button" value="Cancel" onClick='hide_add_gateway();'>
228
														</div>
229
													</center>
230
												</td>
231
											</tr>
232
											<tr><td>&nbsp;</td>
233
										</table>
234
										</td></tr></table>
235
									<p/>
236
								</div>
237 5b237745 Scott Ullrich
                </tr>
238 d173230c Seth Mos
		<tr>
239 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
240
                  <td width="78%" class="vtable"> 
241 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
242 5b237745 Scott Ullrich
                    <br> <span class="vexpl">You may enter a description here
243
                    for your reference (not parsed).</span></td>
244
                </tr>
245
                <tr>
246
                  <td width="22%" valign="top">&nbsp;</td>
247
                  <td width="78%"> 
248 38936dc7 Ermal Lu?i
                    <input id="save" name="Submit" type="submit" class="formbtn" value="Save"> <input id="cancel" type="button" value="Cancel" class="formbtn"  onclick="history.back()">
249 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_routes[$id]): ?>
250
                    <input name="id" type="hidden" value="<?=$id;?>">
251
                    <?php endif; ?>
252
                  </td>
253
                </tr>
254
              </table>
255
</form>
256 38936dc7 Ermal Lu?i
<script type="text/javascript">
257
					var gatewayip;
258
					var name;
259
					function show_add_gateway() {
260
						document.getElementById("addgateway").style.display = '';
261
						document.getElementById("addgwbox").style.display = 'none';
262
						document.getElementById("gateway").style.display = 'none';
263
						document.getElementById("save").style.display = 'none';
264
						document.getElementById("cancel").style.display = 'none';
265
						document.getElementById("gwsave").style.display = '';
266
						document.getElementById("gwcancel").style.display = '';
267
						$('notebox').innerHTML="";
268
					}
269
					function hide_add_gateway() {
270
						document.getElementById("addgateway").style.display = 'none';
271
						document.getElementById("addgwbox").style.display = '';	
272
						document.getElementById("gateway").style.display = '';
273
						document.getElementById("save").style.display = '';
274
						document.getElementById("cancel").style.display = '';
275
						document.getElementById("gwsave").style.display = '';
276
						document.getElementById("gwcancel").style.display = '';
277
					}
278
					function hide_add_gatewaysave() {
279
						document.getElementById("addgateway").style.display = 'none';
280
						$('status').innerHTML = '<img src="/themes/metallic/images/misc/loader.gif"> One moment please...';
281
						var iface = $('addinterfacegw').getValue();
282
						name = $('name').getValue();
283
						var descr = $('gatewaydescr').getValue();
284
						gatewayip = $('gatewayip').getValue();
285
						addrtype = $('addrtype').getValue();
286
						var defaultgw = $('defaultgw').getValue();
287
						var url = "system_gateways_edit.php";
288
						var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
289
						var myAjax = new Ajax.Request(
290
							url,
291
							{
292
								method: 'post',
293
								parameters: pars,
294
								onFailure: report_failure,
295
								onComplete: save_callback
296
							});	
297
					}
298
					function addOption(selectbox,text,value)
299
					{
300
						var optn = document.createElement("OPTION");
301
						optn.text = text;
302
						optn.value = value;
303
						selectbox.options.add(optn);
304
						selectbox.selectedIndex = (selectbox.options.length-1);
305
						$('notebox').innerHTML="<p/><strong>NOTE:</strong> You can manage Gateways <a target='_new' href='system_gateways.php'>here</a>.";
306
					}				
307
					function report_failure() {
308
						alert("Sorry, we could not create your gateway at this time.");
309
						hide_add_gateway();
310
					}
311
					function save_callback(transport) {
312
						var response = transport.responseText;
313
						if (response) {
314
							document.getElementById("addgateway").style.display = 'none';
315
							hide_add_gateway();
316
							$('status').innerHTML = '';
317
							addOption($('gateway'), name, name);
318
						} else {
319
							report_failure();
320
						}
321
					}
322
				</script>
323 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
324
</body>
325
</html>