1 |
d173230c
|
Seth Mos
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
system_gateways_edit.php
|
5 |
|
|
part of pfSense (http://pfsense.com)
|
6 |
|
|
|
7 |
|
|
Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>.
|
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 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
33 |
|
|
##|*IDENT=page-system-gateways-editgateway
|
34 |
|
|
##|*NAME=System: Gateways: Edit Gateway page
|
35 |
|
|
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway' page.
|
36 |
|
|
##|*MATCH=system_gateways_edit.php*
|
37 |
|
|
##|-PRIV
|
38 |
|
|
|
39 |
|
|
|
40 |
d173230c
|
Seth Mos
|
require("guiconfig.inc");
|
41 |
|
|
|
42 |
|
|
if (!is_array($config['gateways']['gateway_item']))
|
43 |
|
|
$config['gateways']['gateway_item'] = array();
|
44 |
|
|
|
45 |
|
|
$a_gateways = &$config['gateways']['gateway_item'];
|
46 |
|
|
|
47 |
|
|
$id = $_GET['id'];
|
48 |
|
|
if (isset($_POST['id']))
|
49 |
|
|
$id = $_POST['id'];
|
50 |
|
|
|
51 |
|
|
if (isset($_GET['dup'])) {
|
52 |
|
|
$id = $_GET['dup'];
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
if (isset($id) && $a_gateways[$id]) {
|
56 |
|
|
$pconfig['name'] = $a_gateways[$id]['name'];
|
57 |
|
|
$pconfig['interface'] = $a_gateways[$id]['interface'];
|
58 |
|
|
$pconfig['gateway'] = $a_gateways[$id]['gateway'];
|
59 |
|
|
$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
|
60 |
|
|
$pconfig['monitor'] = $a_gateways[$id]['monitor'];
|
61 |
|
|
$pconfig['descr'] = $a_gateways[$id]['descr'];
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
if (isset($_GET['dup']))
|
65 |
|
|
unset($id);
|
66 |
|
|
|
67 |
|
|
if ($_POST) {
|
68 |
|
|
|
69 |
|
|
unset($input_errors);
|
70 |
|
|
$pconfig = $_POST;
|
71 |
|
|
|
72 |
|
|
/* input validation */
|
73 |
|
|
$reqdfields = explode(" ", "interface name gateway");
|
74 |
|
|
$reqdfieldsn = explode(",", "Interface,Name,Gateway");
|
75 |
|
|
|
76 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
77 |
|
|
|
78 |
|
|
if (! isset($_POST['name'])) {
|
79 |
|
|
$input_errors[] = "A valid gateway name must be specified.";
|
80 |
|
|
}
|
81 |
|
|
if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
|
82 |
|
|
$input_errors[] = "A valid gateway IP address must be specified.";
|
83 |
|
|
}
|
84 |
23956e22
|
Seth Mos
|
if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
|
85 |
d173230c
|
Seth Mos
|
$input_errors[] = "A valid monitor IP address must be specified.";
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
if ($_POST['defaultgw'] == "yes") {
|
89 |
|
|
$i=0;
|
90 |
|
|
foreach ($a_gateways as $gateway) {
|
91 |
|
|
if($id != $i) {
|
92 |
|
|
unset($config['gateways']['gateway_item'][$i]['defaultgw']);
|
93 |
|
|
} else {
|
94 |
|
|
$config['gateways']['gateway_item'][$i]['defaultgw'] = true;
|
95 |
|
|
}
|
96 |
|
|
$i++;
|
97 |
|
|
}
|
98 |
|
|
} else {
|
99 |
|
|
$i=0;
|
100 |
|
|
foreach ($a_gateways as $gateway) {
|
101 |
|
|
if($id == $i) {
|
102 |
|
|
unset($config['gateways']['gateway_item'][$i]['defaultgw']);
|
103 |
|
|
}
|
104 |
|
|
$i++;
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
/* check for overlaps */
|
109 |
|
|
foreach ($a_gateways as $gateway) {
|
110 |
|
|
if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
|
111 |
|
|
continue;
|
112 |
|
|
|
113 |
23956e22
|
Seth Mos
|
if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
|
114 |
|
|
$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
|
115 |
d173230c
|
Seth Mos
|
break;
|
116 |
|
|
}
|
117 |
23956e22
|
Seth Mos
|
if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
|
118 |
|
|
$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
|
119 |
d173230c
|
Seth Mos
|
break;
|
120 |
|
|
}
|
121 |
23956e22
|
Seth Mos
|
if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
|
122 |
|
|
$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
|
123 |
d173230c
|
Seth Mos
|
break;
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
if (!$input_errors) {
|
128 |
|
|
$gateway = array();
|
129 |
|
|
$gateway['interface'] = $_POST['interface'];
|
130 |
|
|
$gateway['name'] = $_POST['name'];
|
131 |
|
|
$gateway['gateway'] = $_POST['gateway'];
|
132 |
|
|
$gateway['monitor'] = $_POST['monitor'];
|
133 |
|
|
$gateway['descr'] = $_POST['descr'];
|
134 |
|
|
|
135 |
519352da
|
Seth Mos
|
if($_POST['defaultgw'] == "yes") {
|
136 |
|
|
$i = 0;
|
137 |
|
|
foreach($a_gateways as $gw) {
|
138 |
|
|
unset($config['gateways'][$i]['defaultgw']);
|
139 |
|
|
$i++;
|
140 |
|
|
}
|
141 |
|
|
$gateway['defaultgw'] = true;
|
142 |
|
|
} else {
|
143 |
|
|
unset($gateway['defaultgw']);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
d173230c
|
Seth Mos
|
if (isset($id) && $a_gateways[$id])
|
147 |
|
|
$a_gateways[$id] = $gateway;
|
148 |
|
|
else
|
149 |
|
|
$a_gateways[] = $gateway;
|
150 |
|
|
|
151 |
|
|
touch($d_staticroutesdirty_path);
|
152 |
|
|
|
153 |
|
|
write_config();
|
154 |
|
|
|
155 |
|
|
header("Location: system_gateways.php");
|
156 |
|
|
exit;
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
|
160 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("System","Gateways","Edit gateway");
|
161 |
d173230c
|
Seth Mos
|
include("head.inc");
|
162 |
|
|
|
163 |
|
|
?>
|
164 |
|
|
|
165 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
166 |
|
|
<?php include("fbegin.inc"); ?>
|
167 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
168 |
|
|
<form action="system_gateways_edit.php" method="post" name="iform" id="iform">
|
169 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
170 |
56d4e7fb
|
Scott Ullrich
|
<tr>
|
171 |
|
|
<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
|
172 |
|
|
</tr>
|
173 |
d173230c
|
Seth Mos
|
<tr>
|
174 |
|
|
<td width="22%" valign="top" class="vncellreq">Interface</td>
|
175 |
|
|
<td width="78%" class="vtable">
|
176 |
|
|
<select name="interface" class="formselect">
|
177 |
3e321df2
|
Ermal Luçi
|
<?php $interfaces = get_configured_interface_with_descr(false, true);
|
178 |
d173230c
|
Seth Mos
|
foreach ($interfaces as $iface => $ifacename): ?>
|
179 |
|
|
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
|
180 |
|
|
<?=htmlspecialchars($ifacename);?>
|
181 |
|
|
</option>
|
182 |
8e21cbb8
|
Scott Ullrich
|
<?php
|
183 |
|
|
endforeach;
|
184 |
|
|
if (is_package_installed("openbgpd") == 1) {
|
185 |
|
|
echo "<option value=\"bgpd\"";
|
186 |
|
|
if($pconfig['interface'] == "bgpd")
|
187 |
|
|
echo " selected";
|
188 |
|
|
echo ">Use BGPD</option>";
|
189 |
|
|
}
|
190 |
|
|
?>
|
191 |
d173230c
|
Seth Mos
|
</select> <br>
|
192 |
|
|
<span class="vexpl">Choose which interface this gateway applies to.</span></td>
|
193 |
|
|
</tr>
|
194 |
|
|
<tr>
|
195 |
|
|
<td width="22%" valign="top" class="vncellreq">Name</td>
|
196 |
|
|
<td width="78%" class="vtable">
|
197 |
|
|
<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>">
|
198 |
|
|
<br> <span class="vexpl">Gateway name</span></td>
|
199 |
|
|
</tr>
|
200 |
|
|
<tr>
|
201 |
|
|
<td width="22%" valign="top" class="vncellreq">Gateway</td>
|
202 |
|
|
<td width="78%" class="vtable">
|
203 |
|
|
<input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
|
204 |
|
|
<br> <span class="vexpl">Gateway IP address</span></td>
|
205 |
|
|
</tr>
|
206 |
|
|
<tr>
|
207 |
|
|
<td width="22%" valign="top" class="vncell">Default Gateway</td>
|
208 |
|
|
<td width="78%" class="vtable">
|
209 |
|
|
<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
|
210 |
|
|
<strong>Default Gateway</strong><br />
|
211 |
|
|
This will select the above gateway as the default gateway
|
212 |
|
|
</td>
|
213 |
|
|
</tr>
|
214 |
|
|
<tr>
|
215 |
|
|
<td width="22%" valign="top" class="vncell">Monitor IP</td>
|
216 |
|
|
<td width="78%" class="vtable">
|
217 |
|
|
<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
|
218 |
|
|
<strong>Alternative monitor IP</strong> <br />
|
219 |
|
|
Enter a alternative address here to be used to monitor the link. This is used for the
|
220 |
|
|
quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
|
221 |
|
|
to icmp requests.</strong>
|
222 |
|
|
<br />
|
223 |
|
|
</td>
|
224 |
|
|
</tr>
|
225 |
|
|
<tr>
|
226 |
|
|
<td width="22%" valign="top" class="vncell">Description</td>
|
227 |
|
|
<td width="78%" class="vtable">
|
228 |
|
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
229 |
|
|
<br> <span class="vexpl">You may enter a description here
|
230 |
|
|
for your reference (not parsed).</span></td>
|
231 |
|
|
</tr>
|
232 |
|
|
<tr>
|
233 |
|
|
<td width="22%" valign="top"> </td>
|
234 |
|
|
<td width="78%">
|
235 |
|
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn" onclick="history.back()">
|
236 |
|
|
<?php if (isset($id) && $a_gateways[$id]): ?>
|
237 |
|
|
<input name="id" type="hidden" value="<?=$id;?>">
|
238 |
|
|
<?php endif; ?>
|
239 |
|
|
</td>
|
240 |
|
|
</tr>
|
241 |
|
|
</table>
|
242 |
|
|
</form>
|
243 |
|
|
<?php include("fend.inc"); ?>
|
244 |
|
|
<script language="JavaScript">
|
245 |
|
|
enable_change();
|
246 |
|
|
</script>
|
247 |
|
|
</body>
|
248 |
|
|
</html>
|