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