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