1
|
<?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
|
Copyright (C) 2010 Scott Ullrich
|
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
|
pfSense_MODULE: routing
|
33
|
*/
|
34
|
|
35
|
##|+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
|
function staticroutecmp($a, $b) {
|
43
|
return strcmp($a['network'], $b['network']);
|
44
|
}
|
45
|
|
46
|
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
|
|
55
|
require_once("guiconfig.inc");
|
56
|
require_once("filter.inc");
|
57
|
require_once("util.inc");
|
58
|
require_once("gwlb.inc");
|
59
|
|
60
|
if (!is_array($config['staticroutes']['route']))
|
61
|
$config['staticroutes']['route'] = array();
|
62
|
|
63
|
$a_routes = &$config['staticroutes']['route'];
|
64
|
$a_gateways = return_gateways_array(true, true);
|
65
|
|
66
|
if (is_numericint($_GET['id']))
|
67
|
$id = $_GET['id'];
|
68
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
69
|
$id = $_POST['id'];
|
70
|
|
71
|
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
|
72
|
$id = $_GET['dup'];
|
73
|
|
74
|
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
|
$pconfig['disabled'] = isset($a_routes[$id]['disabled']);
|
80
|
}
|
81
|
|
82
|
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
|
83
|
unset($id);
|
84
|
|
85
|
if ($_POST) {
|
86
|
|
87
|
global $aliastable;
|
88
|
|
89
|
unset($input_errors);
|
90
|
$pconfig = $_POST;
|
91
|
|
92
|
/* input validation */
|
93
|
$reqdfields = explode(" ", "network network_subnet gateway");
|
94
|
$reqdfieldsn = explode(",",
|
95
|
gettext("Destination network") . "," .
|
96
|
gettext("Destination network bit count") . "," .
|
97
|
gettext("Gateway"));
|
98
|
|
99
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
100
|
|
101
|
if (($_POST['network'] && !is_ipaddr($_POST['network']) && !is_alias($_POST['network']))) {
|
102
|
$input_errors[] = gettext("A valid IPv4 or IPv6 destination network must be specified.");
|
103
|
}
|
104
|
if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
|
105
|
$input_errors[] = gettext("A valid destination network bit count must be specified.");
|
106
|
}
|
107
|
if (($_POST['gateway']) && is_ipaddr($_POST['network'])) {
|
108
|
if (!isset($a_gateways[$_POST['gateway']]))
|
109
|
$input_errors[] = gettext("A valid gateway must be specified.");
|
110
|
if(!validate_address_family($_POST['network'], lookup_gateway_ip_by_name($_POST['gateway'])))
|
111
|
$input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family as network '{$_POST['network']}'.");
|
112
|
}
|
113
|
|
114
|
/* check for overlaps */
|
115
|
$current_targets = get_staticroutes(true);
|
116
|
$new_targets = array();
|
117
|
if(is_ipaddrv6($_POST['network'])) {
|
118
|
$osn = gen_subnetv6($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
|
119
|
$new_targets[] = $osn;
|
120
|
}
|
121
|
if (is_ipaddrv4($_POST['network'])) {
|
122
|
if($_POST['network_subnet'] > 32)
|
123
|
$input_errors[] = gettext("A IPv4 subnet can not be over 32 bits.");
|
124
|
else {
|
125
|
$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
|
126
|
$new_targets[] = $osn;
|
127
|
}
|
128
|
} elseif (is_alias($_POST['network'])) {
|
129
|
$osn = $_POST['network'];
|
130
|
$fqdn_found = 0;
|
131
|
foreach (filter_expand_alias_array($osn, true) as $tgt) {
|
132
|
if (is_ipaddrv4($tgt))
|
133
|
$tgt .= "/32";
|
134
|
if (is_ipaddrv6($tgt))
|
135
|
$tgt .= "/128";
|
136
|
if (is_fqdn($tgt)) {
|
137
|
$input_errors[] = sprintf(gettext("The alias (%s) has one or more FQDNs configured and cannot be used to configure a static route."), $_POST['network']);
|
138
|
$fqdn_found = 1;
|
139
|
break;
|
140
|
}
|
141
|
if (is_subnet($tgt))
|
142
|
$new_targets[] = $tgt;
|
143
|
}
|
144
|
}
|
145
|
if (!isset($id))
|
146
|
$id = count($a_routes);
|
147
|
$oroute = $a_routes[$id];
|
148
|
$old_targets = array();
|
149
|
if (!empty($oroute)) {
|
150
|
if (is_alias($oroute['network'])) {
|
151
|
foreach (filter_expand_alias_array($oroute['network']) as $tgt) {
|
152
|
if (is_ipaddrv4($tgt))
|
153
|
$tgt .= "/32";
|
154
|
else if (is_ipaddrv6($tgt))
|
155
|
$tgt .= "/128";
|
156
|
if (!is_subnet($tgt))
|
157
|
continue;
|
158
|
$old_targets[] = $tgt;
|
159
|
}
|
160
|
} else {
|
161
|
$old_targets[] = $oroute['network'];
|
162
|
}
|
163
|
}
|
164
|
|
165
|
$overlaps = array_intersect($current_targets, $new_targets);
|
166
|
$overlaps = array_diff($overlaps, $old_targets);
|
167
|
if (count($overlaps)) {
|
168
|
$input_errors[] = gettext("A route to these destination networks already exists") . ": " . implode(", ", $overlaps);
|
169
|
}
|
170
|
|
171
|
if (is_array($config['interfaces'])) {
|
172
|
foreach ($config['interfaces'] as $if) {
|
173
|
if (is_ipaddrv4($_POST['network'])
|
174
|
&& isset($if['ipaddr']) && isset($if['subnet'])
|
175
|
&& is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet'])
|
176
|
&& ($_POST['network_subnet'] == $if['subnet'])
|
177
|
&& (gen_subnet($_POST['network'], $_POST['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet'])))
|
178
|
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
|
179
|
|
180
|
else if (is_ipaddrv6($_POST['network'])
|
181
|
&& isset($if['ipaddrv6']) && isset($if['subnetv6'])
|
182
|
&& is_ipaddrv6($if['ipaddrv6']) && is_numeric($if['subnetv6'])
|
183
|
&& ($_POST['network_subnet'] == $if['subnetv6'])
|
184
|
&& (gen_subnetv6($_POST['network'], $_POST['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6'])))
|
185
|
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
|
186
|
}
|
187
|
}
|
188
|
|
189
|
if (!$input_errors) {
|
190
|
$route = array();
|
191
|
$route['network'] = $osn;
|
192
|
$route['gateway'] = $_POST['gateway'];
|
193
|
$route['descr'] = $_POST['descr'];
|
194
|
if ($_POST['disabled'])
|
195
|
$route['disabled'] = true;
|
196
|
else
|
197
|
unset($route['disabled']);
|
198
|
|
199
|
if (file_exists("{$g['tmp_path']}/.system_routes.apply"))
|
200
|
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
|
201
|
else
|
202
|
$toapplylist = array();
|
203
|
$a_routes[$id] = $route;
|
204
|
|
205
|
if (!empty($oroute)) {
|
206
|
$delete_targets = array_diff($old_targets, $new_targets);
|
207
|
if (count($delete_targets))
|
208
|
foreach ($delete_targets as $dts) {
|
209
|
if(is_ipaddrv6($dts))
|
210
|
$family = "-inet6";
|
211
|
$toapplylist[] = "/sbin/route delete {$family} {$dts}";
|
212
|
}
|
213
|
}
|
214
|
file_put_contents("{$g['tmp_path']}/.system_routes.apply", serialize($toapplylist));
|
215
|
staticroutes_sort();
|
216
|
|
217
|
mark_subsystem_dirty('staticroutes');
|
218
|
|
219
|
write_config();
|
220
|
|
221
|
header("Location: system_routes.php");
|
222
|
exit;
|
223
|
}
|
224
|
}
|
225
|
|
226
|
$pgtitle = array(gettext("System"),gettext("Static Routes"),gettext("Edit route"));
|
227
|
$shortcut_section = "routing";
|
228
|
include("head.inc");
|
229
|
?>
|
230
|
|
231
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
232
|
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
|
233
|
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
|
234
|
<script type="text/javascript" src="/javascript/suggestions.js"></script>
|
235
|
<?php include("fbegin.inc");?>
|
236
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
237
|
<form action="system_routes_edit.php" method="post" name="iform" id="iform">
|
238
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system routes edit">
|
239
|
<tr>
|
240
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit route entry"); ?></td>
|
241
|
</tr>
|
242
|
<tr>
|
243
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination network"); ?></td>
|
244
|
<td width="78%" class="vtable">
|
245
|
<input name="network" type="text" class="formfldalias ipv4v6" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>" />
|
246
|
/
|
247
|
<select name="network_subnet" class="formselect ipv4v6" id="network_subnet">
|
248
|
<?php for ($i = 129; $i >= 1; $i--): ?>
|
249
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected=\"selected\""; ?>>
|
250
|
<?=$i;?>
|
251
|
</option>
|
252
|
<?php endfor; ?>
|
253
|
</select>
|
254
|
<br/><span class="vexpl"><?=gettext("Destination network for this static route"); ?></span>
|
255
|
</td>
|
256
|
</tr>
|
257
|
<tr>
|
258
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
|
259
|
<td width="78%" class="vtable">
|
260
|
<select name="gateway" id="gateway" class="formselect">
|
261
|
<?php
|
262
|
foreach ($a_gateways as $gateway) {
|
263
|
echo "<option value='{$gateway['name']}' ";
|
264
|
if ($gateway['name'] == $pconfig['gateway'])
|
265
|
echo "selected=\"selected\"";
|
266
|
echo ">" . htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']) . "</option>\n";
|
267
|
}
|
268
|
?>
|
269
|
</select> <br />
|
270
|
<div id='addgwbox'>
|
271
|
<?=gettext("Choose which gateway this route applies to or"); ?> <a onclick="show_add_gateway();" href="#"><?=gettext("add a new one.");?></a>
|
272
|
</div>
|
273
|
<div id='notebox'>
|
274
|
</div>
|
275
|
<div style="display:none" id="status">
|
276
|
</div>
|
277
|
<div style="display:none" id="addgateway">
|
278
|
<table border="1" style="background:#990000; border-style: none none none none; width:225px;" summary="add gateway">
|
279
|
<tr>
|
280
|
<td>
|
281
|
<table bgcolor="#990000" cellpadding="1" cellspacing="1" summary="add">
|
282
|
<tr><td> </td></tr>
|
283
|
<tr>
|
284
|
<td colspan="2" align="center"><b><font color="white"><?=gettext("Add new gateway:"); ?></font></b></td>
|
285
|
</tr>
|
286
|
<tr><td> </td></tr>
|
287
|
<tr>
|
288
|
<td width="45%" align="right"><font color="white"><?=gettext("Default gateway:"); ?></font></td><td><input type="checkbox" id="defaultgw" name="defaultgw" /></td>
|
289
|
</tr>
|
290
|
<tr>
|
291
|
<td width="45%" align="right"><font color="white"><?=gettext("Interface:"); ?></font></td>
|
292
|
<td>
|
293
|
<select name="addinterfacegw" id="addinterfacegw">
|
294
|
<?php $gwifs = get_configured_interface_with_descr();
|
295
|
foreach($gwifs as $fif => $dif)
|
296
|
echo "<option value=\"{$fif}\">{$dif}</option>\n";
|
297
|
?>
|
298
|
</select>
|
299
|
</td>
|
300
|
</tr>
|
301
|
<tr>
|
302
|
<td align="right"><font color="white"><?=gettext("Gateway Name:"); ?></font></td><td><input id="name" name="name" value="GW" /></td>
|
303
|
</tr>
|
304
|
<tr>
|
305
|
<td align="right"><font color="white"><?=gettext("Gateway IP:"); ?></font></td><td><input id="gatewayip" name="gatewayip" /></td>
|
306
|
</tr>
|
307
|
<tr>
|
308
|
<td align="right"><font color="white"><?=gettext("Description:"); ?></font></td><td><input id="gatewaydescr" name="gatewaydescr" /></td>
|
309
|
</tr>
|
310
|
<tr><td> </td></tr>
|
311
|
<tr>
|
312
|
<td colspan="2" align="center">
|
313
|
<div id='savebuttondiv'>
|
314
|
<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
|
315
|
<input id="gwsave" type="button" value="<?=gettext("Save Gateway"); ?>" onclick='hide_add_gatewaysave();' />
|
316
|
<input id="gwcancel" type="button" value="<?=gettext("Cancel"); ?>" onclick='hide_add_gateway();' />
|
317
|
</div>
|
318
|
</td>
|
319
|
</tr>
|
320
|
<tr><td> </td></tr>
|
321
|
</table>
|
322
|
</td>
|
323
|
</tr>
|
324
|
</table>
|
325
|
</div>
|
326
|
</td>
|
327
|
</tr>
|
328
|
<tr>
|
329
|
<td width="22%" valign="top" class="vncell"><?=gettext("Disabled");?></td>
|
330
|
<td width="78%" class="vtable">
|
331
|
<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
|
332
|
<strong><?=gettext("Disable this static route");?></strong><br />
|
333
|
<span class="vexpl"><?=gettext("Set this option to disable this static route without removing it from the list.");?></span>
|
334
|
</td>
|
335
|
</tr>
|
336
|
<tr>
|
337
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
|
338
|
<td width="78%" class="vtable">
|
339
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
340
|
<br/><span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)."); ?></span>
|
341
|
</td>
|
342
|
</tr>
|
343
|
<tr>
|
344
|
<td width="22%" valign="top"> </td>
|
345
|
<td width="78%">
|
346
|
<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()" />
|
347
|
<?php if (isset($id) && $a_routes[$id]): ?>
|
348
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
349
|
<?php endif; ?>
|
350
|
</td>
|
351
|
</tr>
|
352
|
</table>
|
353
|
</form>
|
354
|
<script type="text/javascript">
|
355
|
//<![CDATA[
|
356
|
var gatewayip;
|
357
|
var name;
|
358
|
function show_add_gateway() {
|
359
|
document.getElementById("addgateway").style.display = '';
|
360
|
document.getElementById("addgwbox").style.display = 'none';
|
361
|
document.getElementById("gateway").style.display = 'none';
|
362
|
document.getElementById("save").style.display = 'none';
|
363
|
document.getElementById("cancel").style.display = 'none';
|
364
|
document.getElementById("gwsave").style.display = '';
|
365
|
document.getElementById("gwcancel").style.display = '';
|
366
|
jQuery('#notebox').html("");
|
367
|
}
|
368
|
function hide_add_gateway() {
|
369
|
document.getElementById("addgateway").style.display = 'none';
|
370
|
document.getElementById("addgwbox").style.display = '';
|
371
|
document.getElementById("gateway").style.display = '';
|
372
|
document.getElementById("save").style.display = '';
|
373
|
document.getElementById("cancel").style.display = '';
|
374
|
document.getElementById("gwsave").style.display = '';
|
375
|
document.getElementById("gwcancel").style.display = '';
|
376
|
}
|
377
|
function hide_add_gatewaysave() {
|
378
|
document.getElementById("addgateway").style.display = 'none';
|
379
|
jQuery('#status').html('<img src="/themes/<?=$g['theme'];?>/images/misc/loader.gif"> One moment please...');
|
380
|
var iface = jQuery('#addinterfacegw').val();
|
381
|
name = jQuery('#name').val();
|
382
|
var descr = jQuery('#gatewaydescr').val();
|
383
|
gatewayip = jQuery('#gatewayip').val();
|
384
|
addrtype = jQuery('#addrtype').val();
|
385
|
var defaultgw = '';
|
386
|
if (jQuery('#defaultgw').checked)
|
387
|
defaultgw = 'yes';
|
388
|
var url = "system_gateways_edit.php";
|
389
|
var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
|
390
|
jQuery.ajax(
|
391
|
url,
|
392
|
{
|
393
|
type: 'post',
|
394
|
data: pars,
|
395
|
error: report_failure,
|
396
|
complete: save_callback
|
397
|
});
|
398
|
}
|
399
|
function addOption(selectbox,text,value)
|
400
|
{
|
401
|
var optn = document.createElement("OPTION");
|
402
|
optn.text = text;
|
403
|
optn.value = value;
|
404
|
selectbox.append(optn);
|
405
|
selectbox.prop('selectedIndex',selectbox.children('option').length-1);
|
406
|
jQuery('#notebox').html("<p><strong><?=gettext("NOTE:");?><\/strong> <?php printf(gettext("You can manage Gateways %shere%s."), "<a target='_blank' href='system_gateways.php'>", "<\/a>");?> <\/strong><\/p>");
|
407
|
}
|
408
|
function report_failure() {
|
409
|
alert("<?=gettext("Sorry, we could not create your gateway at this time."); ?>");
|
410
|
hide_add_gateway();
|
411
|
}
|
412
|
function save_callback(transport) {
|
413
|
var response = transport.responseText;
|
414
|
if (response) {
|
415
|
document.getElementById("addgateway").style.display = 'none';
|
416
|
hide_add_gateway();
|
417
|
jQuery('#status').html('');
|
418
|
addOption(jQuery('#gateway'), name, name);
|
419
|
} else {
|
420
|
report_failure();
|
421
|
}
|
422
|
}
|
423
|
var addressarray = <?= json_encode(get_alias_list(array("host", "network"))) ?>;
|
424
|
var oTextbox1 = new AutoSuggestControl(document.getElementById("network"), new StateSuggestions(addressarray));
|
425
|
//]]>
|
426
|
</script>
|
427
|
<?php include("fend.inc"); ?>
|
428
|
</body>
|
429
|
</html>
|