Project

General

Profile

Download (12.7 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
61
$a_routes = &$config['staticroutes']['route'];
62 a529aced Ermal
$a_gateways = return_gateways_array(true);
63 5b237745 Scott Ullrich
64
$id = $_GET['id'];
65
if (isset($_POST['id']))
66
	$id = $_POST['id'];
67
68 18f7352b Seth Mos
if (isset($_GET['dup'])) {
69
	$id = $_GET['dup'];
70
}
71
72 5b237745 Scott Ullrich
if (isset($id) && $a_routes[$id]) {
73
	list($pconfig['network'],$pconfig['network_subnet']) = 
74
		explode('/', $a_routes[$id]['network']);
75
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
76
	$pconfig['descr'] = $a_routes[$id]['descr'];
77
}
78
79 18f7352b Seth Mos
if (isset($_GET['dup']))
80
	unset($id);
81
82 5b237745 Scott Ullrich
if ($_POST) {
83
84
	unset($input_errors);
85
	$pconfig = $_POST;
86
87
	/* input validation */
88 dde169d9 Vinicius Coque
	$reqdfields = explode(" ", "network network_subnet gateway");
89 38fb1109 Vinicius Coque
	$reqdfieldsn = explode(",",
90
			gettext("Destination network") . "," .
91
			gettext("Destination network bit count") . "," .
92
			gettext("Gateway"));		
93 5b237745 Scott Ullrich
	
94
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95
	
96
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
97 169e0008 Carlos Eduardo Ramos
		$input_errors[] = gettext("A valid destination network must be specified.");
98 5b237745 Scott Ullrich
	}
99
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
100 169e0008 Carlos Eduardo Ramos
		$input_errors[] = gettext("A valid destination network bit count must be specified.");
101 5b237745 Scott Ullrich
	}
102 d173230c Seth Mos
	if ($_POST['gateway']) {
103 a529aced Ermal
		if (!isset($a_gateways[$_POST['gateway']]))
104 169e0008 Carlos Eduardo Ramos
			$input_errors[] = gettext("A valid gateway must be specified.");
105 5b237745 Scott Ullrich
	}
106
107
	/* check for overlaps */
108
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
109
	foreach ($a_routes as $route) {
110
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
111
			continue;
112
113
		if ($route['network'] == $osn) {
114 169e0008 Carlos Eduardo Ramos
			$input_errors[] = gettext("A route to this destination network already exists.");
115 5b237745 Scott Ullrich
			break;
116
		}
117
	}
118
119
	if (!$input_errors) {
120
		$route = array();
121
		$route['network'] = $osn;
122
		$route['gateway'] = $_POST['gateway'];
123
		$route['descr'] = $_POST['descr'];
124
125
		if (isset($id) && $a_routes[$id])
126
			$a_routes[$id] = $route;
127
		else
128
			$a_routes[] = $route;
129 0e3aa71c Erik Fonnesbeck
		staticroutes_sort();
130 5b237745 Scott Ullrich
		
131 a368a026 Ermal Lu?i
		mark_subsystem_dirty('staticroutes');
132 5b237745 Scott Ullrich
		
133
		write_config();
134
		
135
		header("Location: system_routes.php");
136
		exit;
137
	}
138
}
139 4df96eff Scott Ullrich
140 169e0008 Carlos Eduardo Ramos
$pgtitle = array(gettext("System"),gettext("Static Routes"),gettext("Edit route"));
141 4df96eff Scott Ullrich
include("head.inc");
142
143 5b237745 Scott Ullrich
?>
144 4df96eff Scott Ullrich
145 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
146
<?php include("fbegin.inc"); ?>
147
<?php if ($input_errors) print_input_errors($input_errors); ?>
148
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
149
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
150 0cece4a2 Scott Ullrich
				<tr>
151 169e0008 Carlos Eduardo Ramos
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit route entry"); ?></td>
152 0cece4a2 Scott Ullrich
				</tr>	
153 5b237745 Scott Ullrich
                <tr>
154 169e0008 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Destination network"); ?></td>
155 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
156 b5c78501 Seth Mos
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
157 5b237745 Scott Ullrich
				  / 
158 b5c78501 Seth Mos
                    <select name="network_subnet" class="formselect" id="network_subnet">
159 5b237745 Scott Ullrich
                      <?php for ($i = 32; $i >= 1; $i--): ?>
160
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
161
                      <?=$i;?>
162
                      </option>
163
                      <?php endfor; ?>
164
                    </select>
165 169e0008 Carlos Eduardo Ramos
                    <br> <span class="vexpl"><?=gettext("Destination network for this static route"); ?></span></td>
166 5b237745 Scott Ullrich
                </tr>
167 d173230c Seth Mos
                <tr> 
168 169e0008 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
169 d173230c Seth Mos
                  <td width="78%" class="vtable">
170 38936dc7 Ermal Lu?i
			<select name="gateway" id="gateway" class="formselect">
171 d173230c Seth Mos
			<?php
172 a529aced Ermal
				foreach ($a_gateways as $gateway) {
173
					if ($gateway['attribute'] == "system") {
174
	                      			echo "<option value='{$gateway['friendlyiface']}' ";
175
						if ($gateway['friendlyiface'] == $pconfig['gateway'])
176
							echo "selected";
177
					} else {
178
	                      			echo "<option value='{$gateway['name']}' ";
179
						if ($gateway['name'] == $pconfig['gateway'])
180
							echo "selected";
181
					}
182 189ceb32 Chris Buechler
	                      		echo ">" . htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']) . "</option>\n";
183 a529aced Ermal
				}
184
			?>
185 38936dc7 Ermal Lu?i
                    </select> <br />
186
			<div id='addgwbox'>
187 bfb0b9dc Vinicius Coque
				<?=gettext("Choose which gateway this route applies to or"); ?> <a OnClick="show_add_gateway();" href="#"><?=gettext("add a new one");?></a>.
188 38936dc7 Ermal Lu?i
								</div>
189
								<div id='notebox'>
190
								</div>
191
								<div style="display:none" name ="status" id="status">
192
								</div>								
193
								<div style="display:none" id="addgateway" name="addgateway">
194
									<p> 
195
									<table border="1" style="background:#990000; border-style: none none none none; width:225px;"><tr><td>
196
										<table bgcolor="#990000" cellpadding="1" cellspacing="1">
197
											<tr><td>&nbsp;</td>
198
											<tr>
199 169e0008 Carlos Eduardo Ramos
												<td colspan="2"><center><b><font color="white"><?=gettext("Add new gateway"); ?>:</b></center></td>
200 38936dc7 Ermal Lu?i
											</tr>
201
											<tr><td>&nbsp;</td>
202
											<tr>
203 0e94685b Renato Botelho
												<td width="45%" align="right"><font color="white"><?=gettext("Default gateway"); ?>:</td><td><input type="checkbox" id="defaultgw" name="defaultgw"<?=$checked?>></td>
204 38936dc7 Ermal Lu?i
											</tr>												
205
											<tr>
206 169e0008 Carlos Eduardo Ramos
												<td width="45%" align="right"><font color="white"><?=gettext("Interface"); ?>:</td>
207 38936dc7 Ermal Lu?i
												<td><select name="addinterfacegw" id="addinterfacegw">
208
												<?php $gwifs = get_configured_interface_with_descr();
209
													foreach($gwifs as $fif => $dif)
210
														echo "<option value=\"{$fif}\">{$dif}</option>\n";
211
												?>
212
												</select></td>
213
											</tr>
214
											<tr>
215 169e0008 Carlos Eduardo Ramos
												<td align="right"><font color="white"><?=gettext("Gateway Name"); ?>:</td><td><input id="name" name="name" value="GW"></td>
216 38936dc7 Ermal Lu?i
											</tr>
217
											<tr>
218 169e0008 Carlos Eduardo Ramos
												<td align="right"><font color="white"><?=gettext("Gateway IP"); ?>:</td><td><input id="gatewayip" name="gatewayip"></td>
219 38936dc7 Ermal Lu?i
											</tr>
220
											<tr>
221 169e0008 Carlos Eduardo Ramos
												<td align="right"><font color="white"><?=gettext("Description"); ?>:</td><td><input id="gatewaydescr" name="gatewaydescr"></td>
222 38936dc7 Ermal Lu?i
											</tr>
223
											<tr><td>&nbsp;</td>
224
											<tr>
225
												<td colspan="2">
226
													<center>
227
														<div id='savebuttondiv'>
228
															<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
229 169e0008 Carlos Eduardo Ramos
															<input id="gwsave" type="Button" value="<?=gettext("Save Gateway"); ?>" onClick='hide_add_gatewaysave();'> 
230
															<input id="gwcancel" type="Button" value="<?=gettext("Cancel"); ?>" onClick='hide_add_gateway();'>
231 38936dc7 Ermal Lu?i
														</div>
232
													</center>
233
												</td>
234
											</tr>
235
											<tr><td>&nbsp;</td>
236
										</table>
237
										</td></tr></table>
238
									<p/>
239
								</div>
240 5b237745 Scott Ullrich
                </tr>
241 d173230c Seth Mos
		<tr>
242 169e0008 Carlos Eduardo Ramos
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
243 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
244 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
245 0e94685b Renato Botelho
                    <br> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span></td>
246 5b237745 Scott Ullrich
                </tr>
247
                <tr>
248
                  <td width="22%" valign="top">&nbsp;</td>
249
                  <td width="78%"> 
250 bfb0b9dc Vinicius Coque
                    <input id="save" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input id="cancel" type="button" value="<?=gettext("Cancel"); ?>" class="formbtn"  onclick="history.back()">
251 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_routes[$id]): ?>
252
                    <input name="id" type="hidden" value="<?=$id;?>">
253
                    <?php endif; ?>
254
                  </td>
255
                </tr>
256
              </table>
257
</form>
258 38936dc7 Ermal Lu?i
<script type="text/javascript">
259
					var gatewayip;
260
					var name;
261
					function show_add_gateway() {
262
						document.getElementById("addgateway").style.display = '';
263
						document.getElementById("addgwbox").style.display = 'none';
264
						document.getElementById("gateway").style.display = 'none';
265
						document.getElementById("save").style.display = 'none';
266
						document.getElementById("cancel").style.display = 'none';
267
						document.getElementById("gwsave").style.display = '';
268
						document.getElementById("gwcancel").style.display = '';
269
						$('notebox').innerHTML="";
270
					}
271
					function hide_add_gateway() {
272
						document.getElementById("addgateway").style.display = 'none';
273
						document.getElementById("addgwbox").style.display = '';	
274
						document.getElementById("gateway").style.display = '';
275
						document.getElementById("save").style.display = '';
276
						document.getElementById("cancel").style.display = '';
277
						document.getElementById("gwsave").style.display = '';
278
						document.getElementById("gwcancel").style.display = '';
279
					}
280
					function hide_add_gatewaysave() {
281
						document.getElementById("addgateway").style.display = 'none';
282 169e0008 Carlos Eduardo Ramos
						$('status').innerHTML = '<img src="/themes/metallic/images/misc/loader.gif"> <?=gettext("One moment please..."); ?>';
283 38936dc7 Ermal Lu?i
						var iface = $('addinterfacegw').getValue();
284
						name = $('name').getValue();
285
						var descr = $('gatewaydescr').getValue();
286
						gatewayip = $('gatewayip').getValue();
287
						addrtype = $('addrtype').getValue();
288
						var defaultgw = $('defaultgw').getValue();
289
						var url = "system_gateways_edit.php";
290
						var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
291
						var myAjax = new Ajax.Request(
292
							url,
293
							{
294
								method: 'post',
295
								parameters: pars,
296
								onFailure: report_failure,
297
								onComplete: save_callback
298
							});	
299
					}
300
					function addOption(selectbox,text,value)
301
					{
302
						var optn = document.createElement("OPTION");
303
						optn.text = text;
304
						optn.value = value;
305
						selectbox.options.add(optn);
306
						selectbox.selectedIndex = (selectbox.options.length-1);
307 169e0008 Carlos Eduardo Ramos
						$('notebox').innerHTML="<p/><strong>NOTE:</strong> <?=gettext("You can manage Gateways"); ?> <a target='_new' href='system_gateways.php'>here</a>.";
308 38936dc7 Ermal Lu?i
					}				
309
					function report_failure() {
310 169e0008 Carlos Eduardo Ramos
						alert("<?=gettext("Sorry, we could not create your gateway at this time"); ?>.");
311 38936dc7 Ermal Lu?i
						hide_add_gateway();
312
					}
313
					function save_callback(transport) {
314
						var response = transport.responseText;
315
						if (response) {
316
							document.getElementById("addgateway").style.display = 'none';
317
							hide_add_gateway();
318
							$('status').innerHTML = '';
319
							addOption($('gateway'), name, name);
320
						} else {
321
							report_failure();
322
						}
323
					}
324
				</script>
325 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
326
</body>
327
</html>