Project

General

Profile

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