1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
system_routes_edit.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
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
|
require("guiconfig.inc");
|
33
|
|
34
|
if (!is_array($config['staticroutes']['route']))
|
35
|
$config['staticroutes']['route'] = array();
|
36
|
|
37
|
staticroutes_sort();
|
38
|
$a_routes = &$config['staticroutes']['route'];
|
39
|
|
40
|
$id = $_GET['id'];
|
41
|
if (isset($_POST['id']))
|
42
|
$id = $_POST['id'];
|
43
|
|
44
|
if (isset($id) && $a_routes[$id]) {
|
45
|
$pconfig['interface'] = $a_routes[$id]['interface'];
|
46
|
list($pconfig['network'],$pconfig['network_subnet']) =
|
47
|
explode('/', $a_routes[$id]['network']);
|
48
|
$pconfig['gateway'] = $a_routes[$id]['gateway'];
|
49
|
$pconfig['descr'] = $a_routes[$id]['descr'];
|
50
|
}
|
51
|
|
52
|
if ($_POST) {
|
53
|
|
54
|
unset($input_errors);
|
55
|
$pconfig = $_POST;
|
56
|
|
57
|
/* input validation */
|
58
|
$reqdfields = explode(" ", "interface network network_subnet gateway");
|
59
|
$reqdfieldsn = explode(",", "Interface,Destination network,Destination network bit count,Gateway");
|
60
|
|
61
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
62
|
|
63
|
if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
|
64
|
$input_errors[] = "A valid destination network must be specified.";
|
65
|
}
|
66
|
if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
|
67
|
$input_errors[] = "A valid destination network bit count must be specified.";
|
68
|
}
|
69
|
if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
|
70
|
$input_errors[] = "A valid gateway IP address must be specified.";
|
71
|
}
|
72
|
|
73
|
/* check for overlaps */
|
74
|
$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
|
75
|
foreach ($a_routes as $route) {
|
76
|
if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
|
77
|
continue;
|
78
|
|
79
|
if ($route['network'] == $osn) {
|
80
|
$input_errors[] = "A route to this destination network already exists.";
|
81
|
break;
|
82
|
}
|
83
|
}
|
84
|
|
85
|
if (!$input_errors) {
|
86
|
$route = array();
|
87
|
$route['interface'] = $_POST['interface'];
|
88
|
$route['network'] = $osn;
|
89
|
$route['gateway'] = $_POST['gateway'];
|
90
|
$route['descr'] = $_POST['descr'];
|
91
|
|
92
|
if (isset($id) && $a_routes[$id])
|
93
|
$a_routes[$id] = $route;
|
94
|
else
|
95
|
$a_routes[] = $route;
|
96
|
|
97
|
touch($d_staticroutesdirty_path);
|
98
|
|
99
|
write_config();
|
100
|
|
101
|
header("Location: system_routes.php");
|
102
|
exit;
|
103
|
}
|
104
|
}
|
105
|
?>
|
106
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
107
|
<html>
|
108
|
<head>
|
109
|
<title><?=gentitle("System: Static routes: Edit route");?></title>
|
110
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
111
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
112
|
</head>
|
113
|
|
114
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
115
|
<?php include("fbegin.inc"); ?>
|
116
|
<p class="pgtitle">System: Static routes: Edit route</p>
|
117
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
118
|
<form action="system_routes_edit.php" method="post" name="iform" id="iform">
|
119
|
<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
|
<input name="Submit" type="submit" class="formbtn" value="Save">
|
167
|
<?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>
|