1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
system_routes_edit.php
|
6 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
7 |
|
|
|
8 |
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9 |
|
|
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 |
|
|
|
33 |
|
|
require("guiconfig.inc");
|
34 |
|
|
|
35 |
|
|
if (!is_array($config['staticroutes']['route']))
|
36 |
|
|
$config['staticroutes']['route'] = array();
|
37 |
|
|
|
38 |
|
|
staticroutes_sort();
|
39 |
|
|
$a_routes = &$config['staticroutes']['route'];
|
40 |
|
|
|
41 |
|
|
$id = $_GET['id'];
|
42 |
|
|
if (isset($_POST['id']))
|
43 |
|
|
$id = $_POST['id'];
|
44 |
|
|
|
45 |
|
|
if (isset($id) && $a_routes[$id]) {
|
46 |
|
|
$pconfig['interface'] = $a_routes[$id]['interface'];
|
47 |
|
|
list($pconfig['network'],$pconfig['network_subnet']) =
|
48 |
|
|
explode('/', $a_routes[$id]['network']);
|
49 |
|
|
$pconfig['gateway'] = $a_routes[$id]['gateway'];
|
50 |
|
|
$pconfig['descr'] = $a_routes[$id]['descr'];
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
if ($_POST) {
|
54 |
|
|
|
55 |
|
|
unset($input_errors);
|
56 |
|
|
$pconfig = $_POST;
|
57 |
|
|
|
58 |
|
|
/* input validation */
|
59 |
|
|
$reqdfields = explode(" ", "interface network network_subnet gateway");
|
60 |
|
|
$reqdfieldsn = explode(",", "Interface,Destination network,Destination network bit count,Gateway");
|
61 |
|
|
|
62 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
63 |
|
|
|
64 |
|
|
if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
|
65 |
|
|
$input_errors[] = "A valid destination network must be specified.";
|
66 |
|
|
}
|
67 |
|
|
if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
|
68 |
|
|
$input_errors[] = "A valid destination network bit count must be specified.";
|
69 |
|
|
}
|
70 |
|
|
if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
|
71 |
|
|
$input_errors[] = "A valid gateway IP address must be specified.";
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/* check for overlaps */
|
75 |
|
|
$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
|
76 |
|
|
foreach ($a_routes as $route) {
|
77 |
|
|
if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
|
78 |
|
|
continue;
|
79 |
|
|
|
80 |
|
|
if ($route['network'] == $osn) {
|
81 |
|
|
$input_errors[] = "A route to this destination network already exists.";
|
82 |
|
|
break;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
if (!$input_errors) {
|
87 |
|
|
$route = array();
|
88 |
|
|
$route['interface'] = $_POST['interface'];
|
89 |
|
|
$route['network'] = $osn;
|
90 |
|
|
$route['gateway'] = $_POST['gateway'];
|
91 |
|
|
$route['descr'] = $_POST['descr'];
|
92 |
|
|
|
93 |
|
|
if (isset($id) && $a_routes[$id])
|
94 |
|
|
$a_routes[$id] = $route;
|
95 |
|
|
else
|
96 |
|
|
$a_routes[] = $route;
|
97 |
|
|
|
98 |
|
|
touch($d_staticroutesdirty_path);
|
99 |
|
|
|
100 |
|
|
write_config();
|
101 |
|
|
|
102 |
|
|
header("Location: system_routes.php");
|
103 |
|
|
exit;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
4df96eff
|
Scott Ullrich
|
|
107 |
39cf364d
|
Bill Marquette
|
$pgtitle = "System: Static Routes: Edit route";
|
108 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
109 |
|
|
|
110 |
5b237745
|
Scott Ullrich
|
?>
|
111 |
4df96eff
|
Scott Ullrich
|
|
112 |
5b237745
|
Scott Ullrich
|
|
113 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
114 |
|
|
<?php include("fbegin.inc"); ?>
|
115 |
74f446e8
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
116 |
5b237745
|
Scott Ullrich
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
117 |
|
|
<form action="system_routes_edit.php" method="post" name="iform" id="iform">
|
118 |
ef97ce1b
|
Bill Marquette
|
<?display_topbar()?>
|
119 |
5b237745
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
120 |
|
|
<tr>
|
121 |
|
|
<td width="22%" valign="top" class="vncellreq">Interface</td>
|
122 |
|
|
<td width="78%" class="vtable">
|
123 |
|
|
<select name="interface" class="formfld">
|
124 |
|
|
<?php $interfaces = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
|
125 |
|
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
126 |
|
|
$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
|
127 |
|
|
}
|
128 |
|
|
foreach ($interfaces as $iface => $ifacename): ?>
|
129 |
|
|
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
|
130 |
|
|
<?=htmlspecialchars($ifacename);?>
|
131 |
|
|
</option>
|
132 |
|
|
<?php endforeach; ?>
|
133 |
|
|
</select> <br>
|
134 |
|
|
<span class="vexpl">Choose which interface this route applies to.</span></td>
|
135 |
|
|
</tr>
|
136 |
|
|
<tr>
|
137 |
|
|
<td width="22%" valign="top" class="vncellreq">Destination network</td>
|
138 |
|
|
<td width="78%" class="vtable">
|
139 |
|
|
<input name="network" type="text" class="formfld" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>">
|
140 |
|
|
/
|
141 |
|
|
<select name="network_subnet" class="formfld" id="network_subnet">
|
142 |
|
|
<?php for ($i = 32; $i >= 1; $i--): ?>
|
143 |
|
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
|
144 |
|
|
<?=$i;?>
|
145 |
|
|
</option>
|
146 |
|
|
<?php endfor; ?>
|
147 |
|
|
</select>
|
148 |
|
|
<br> <span class="vexpl">Destination network for this static route</span></td>
|
149 |
|
|
</tr>
|
150 |
|
|
<tr>
|
151 |
|
|
<td width="22%" valign="top" class="vncellreq">Gateway</td>
|
152 |
|
|
<td width="78%" class="vtable">
|
153 |
|
|
<input name="gateway" type="text" class="formfld" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
|
154 |
|
|
<br> <span class="vexpl">Gateway to be used to reach the destination network</span></td>
|
155 |
|
|
</tr>
|
156 |
|
|
<tr>
|
157 |
|
|
<td width="22%" valign="top" class="vncell">Description</td>
|
158 |
|
|
<td width="78%" class="vtable">
|
159 |
|
|
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
160 |
|
|
<br> <span class="vexpl">You may enter a description here
|
161 |
|
|
for your reference (not parsed).</span></td>
|
162 |
|
|
</tr>
|
163 |
|
|
<tr>
|
164 |
|
|
<td width="22%" valign="top"> </td>
|
165 |
|
|
<td width="78%">
|
166 |
fc01e414
|
Scott Ullrich
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn" onclick="history.back()">
|
167 |
5b237745
|
Scott Ullrich
|
<?php if (isset($id) && $a_routes[$id]): ?>
|
168 |
|
|
<input name="id" type="hidden" value="<?=$id;?>">
|
169 |
|
|
<?php endif; ?>
|
170 |
|
|
</td>
|
171 |
|
|
</tr>
|
172 |
|
|
</table>
|
173 |
|
|
</form>
|
174 |
|
|
<?php include("fend.inc"); ?>
|
175 |
|
|
</body>
|
176 |
|
|
</html>
|