Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php 
2 e3153473 Simon Cornelius P. Umacob
/* $Id: system_gateways_edit.php,v 1.3 2008/11/24 05:48:02 sumacob Exp $ */
3 d173230c Seth Mos
/*
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 e3153473 Simon Cornelius P. Umacob
require_once("guiconfig.inc");
41 f193cf92 Simon Cornelius P. Umacob
require_once("IPv6.inc");
42 d173230c Seth Mos
43 e3153473 Simon Cornelius P. Umacob
if (!is_array($config['gateways']['gateway_item']))
44
	$config['gateways']['gateway_item'] = array();
45
46
$a_gateways = &$config['gateways']['gateway_item'];
47 d173230c Seth Mos
48 f193cf92 Simon Cornelius P. Umacob
if (isset($_GET['id'])) {
49
	$id = $_GET['id'];
50
} else if (isset($_POST['id'])) {
51 d173230c Seth Mos
	$id = $_POST['id'];
52 f193cf92 Simon Cornelius P. Umacob
} else {
53
	$id = -1;
54
}
55 d173230c Seth Mos
56
if (isset($_GET['dup'])) {
57
	$id = $_GET['dup'];
58
}
59
60
if (isset($id) && $a_gateways[$id]) {
61
	$pconfig['name'] = $a_gateways[$id]['name'];
62
	$pconfig['interface'] = $a_gateways[$id]['interface'];
63
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
64
	$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
65
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
66
	$pconfig['descr'] = $a_gateways[$id]['descr'];
67 f193cf92 Simon Cornelius P. Umacob
	$pconfig['type'] = $a_gateways[$id]['type'];
68 d173230c Seth Mos
}
69
70 e3153473 Simon Cornelius P. Umacob
if (isset($_GET['dup']))
71 d173230c Seth Mos
	unset($id);
72
73
if ($_POST) {
74
75
	unset($input_errors);
76
	$pconfig = $_POST;
77
78
	/* input validation */
79
	$reqdfields = explode(" ", "interface name gateway");
80
	$reqdfieldsn = explode(",", "Interface,Name,Gateway");		
81
	
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83
	
84
	if (! isset($_POST['name'])) {
85
		$input_errors[] = "A valid gateway name must be specified.";
86
	}
87 f193cf92 Simon Cornelius P. Umacob
88
	if ($_POST['type'] == 'IPv4') {
89 e3153473 Simon Cornelius P. Umacob
		if (!is_ipaddr($_POST['gateway'])) {
90 f193cf92 Simon Cornelius P. Umacob
			$input_errors[] = "A valid IPv4 gateway address must be specified.";
91
		}
92
93
		if ($_POST['monitor'] && !is_ipaddr($_POST['monitor'])) {
94
			$input_errors[] = "A valid IPv4 monitor address must be specified.";
95
		}
96
	} else if ($_POST['type'] == 'IPv6') {
97 e3153473 Simon Cornelius P. Umacob
		if (!Net_IPv6::checkIPv6($_POST['gateway'])) {
98 f193cf92 Simon Cornelius P. Umacob
			$input_errors[] = "A valid IPv6 gateway address must be specified.";
99
		}
100
101
		if ($_POST['monitor'] && !Net_IPv6::checkIPv6($_POST['monitor'])) {
102
			$input_errors[] = "A valid IPv6 monitor address must be specified.";
103
		}
104
	} else {
105
		$input_errors[] = "A network type must be specified.";
106 d173230c Seth Mos
	}
107 e3153473 Simon Cornelius P. Umacob
	
108
	if ($_POST['defaultgw'] == "yes") {
109
		$i=0;
110
		foreach ($a_gateways as $gateway) {
111
			if($id != $i && $config['gateways']['gateway_item'][$i]['type'] == $_POST['type']) {
112
	                        unset($config['gateways']['gateway_item'][$i]['defaultgw']);
113
			} else if ($config['gateways']['gateway_item'][$i]['type'] == $_POST['type']) {
114
	                        $config['gateways']['gateway_item'][$i]['defaultgw'] = true;
115
			}
116
			$i++;
117
		}
118
	}
119 d173230c Seth Mos
120
	/* check for overlaps */
121
	foreach ($a_gateways as $gateway) {
122
		if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
123
			continue;
124
125 23956e22 Seth Mos
		if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
126
			$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
127 d173230c Seth Mos
			break;
128
		}
129 23956e22 Seth Mos
		if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
130
			$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
131 d173230c Seth Mos
			break;
132
		}
133 23956e22 Seth Mos
		if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
134
			$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
135 d173230c Seth Mos
			break;
136
		}
137
	}
138
139
	if (!$input_errors) {
140 e3153473 Simon Cornelius P. Umacob
		$gateway = array();
141
		$gateway['interface'] = $_POST['interface'];
142
		$gateway['name'] = $_POST['name'];
143
		$gateway['gateway'] = $_POST['gateway'];
144
		$gateway['monitor'] = $_POST['monitor'];
145
		$gateway['descr'] = $_POST['descr'];
146
		$gateway['type'] = $_POST['type'];
147 d7dfd5f8 Seth Mos
148 e3153473 Simon Cornelius P. Umacob
		if($_POST['defaultgw'] == "yes") {
149
			$gateway['defaultgw'] = true;
150 d7dfd5f8 Seth Mos
		}
151 e3153473 Simon Cornelius P. Umacob
152
		if (isset($id) && $a_gateways[$id])
153
			$a_gateways[$id] = $gateway;
154
		else
155
			$a_gateways[] = $gateway;
156 d173230c Seth Mos
		
157
		touch($d_staticroutesdirty_path);
158
		
159
		write_config();
160
		
161
		header("Location: system_gateways.php");
162
		exit;
163
	}
164
}
165
166 d88c6a9f Scott Ullrich
$pgtitle = array("System","Gateways","Edit gateway");
167 d173230c Seth Mos
include("head.inc");
168
169
?>
170
171
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
172
<?php include("fbegin.inc"); ?>
173
<?php if ($input_errors) print_input_errors($input_errors); ?>
174
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
175
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
176 56d4e7fb Scott Ullrich
				<tr>
177
					<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
178
				</tr>	
179 d173230c Seth Mos
                <tr> 
180
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
181
                  <td width="78%" class="vtable">
182
			<select name="interface" class="formselect">
183 3e321df2 Ermal Luçi
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
184 d173230c Seth Mos
					  foreach ($interfaces as $iface => $ifacename): ?>
185
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
186
                      <?=htmlspecialchars($ifacename);?>
187
                      </option>
188 8e21cbb8 Scott Ullrich
                      <?php 
189
						endforeach;
190
						if (is_package_installed("openbgpd") == 1) {
191
							echo "<option value=\"bgpd\"";
192
							if($pconfig['interface'] == "bgpd") 
193
								echo " selected";
194
							echo ">Use BGPD</option>";
195
						}
196
 					  ?>
197 d173230c Seth Mos
                    </select> <br>
198
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
199
                </tr>
200
                <tr>
201
                  <td width="22%" valign="top" class="vncellreq">Name</td>
202
                  <td width="78%" class="vtable"> 
203
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
204
                    <br> <span class="vexpl">Gateway name</span></td>
205
                </tr>
206 f193cf92 Simon Cornelius P. Umacob
		<tr>
207
                  <td width="22%" valign="top" class="vncellreq">Type</td>
208
                  <td width="78%" class="vtable"> 
209 e3153473 Simon Cornelius P. Umacob
		<!-- XXX -->
210
		<? /*
211
		<?php if (isset($_GET['id']) || $_POST): ?>
212
                    <select class="formselect" disabled="true">
213
			<?php
214
				if ($pconfig['type'] == 'IPv6') {
215
					$str = <<<EOD
216
					<option value="IPv6" selected>IPv6</option>
217
EOD;
218
				} else {
219
					$str = <<<EOD
220
					<option value="IPv4" selected>IPv4</option>
221
EOD;
222
				}
223
224
				echo $str;
225
			?>
226
		    </select>
227
		    <input type="hidden" name="type" id="type" value="<?php htmlspecialchars($pconfig['type']); ?>" />
228
		<? else: ?>
229
                    <select name="type" class="formselect">
230
			<?php
231
				if ($pconfig['type'] == 'IPv6') {
232
					$str = <<<EOD
233
					<option value="IPv4">IPv4</option>
234
					<option value="IPv6" selected>IPv6</option>
235
EOD;
236
				} else {
237
					$str = <<<EOD
238
					<option value="IPv4" selected>IPv4</option>
239
					<option value="IPv6">IPv6</option>
240
EOD;
241
				}
242
243
				echo $str;
244
			?>
245
		    </select>
246
		<? endif; ?>
247
		*/ ?>
248 f193cf92 Simon Cornelius P. Umacob
                    <select name="type" class="formselect">
249
			<?php
250
				if ($pconfig['type'] == 'IPv6') {
251
					$str = <<<EOD
252
					<option value="IPv4">IPv4</option>
253
					<option value="IPv6" selected>IPv6</option>
254
EOD;
255
				} else {
256
					$str = <<<EOD
257
					<option value="IPv4" selected>IPv4</option>
258
					<option value="IPv6">IPv6</option>
259
EOD;
260
				}
261
262
				echo $str;
263
			?>
264
		    </select>
265
                  </td>
266
                </tr>
267 d173230c Seth Mos
		<tr>
268
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
269
                  <td width="78%" class="vtable"> 
270
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
271 f193cf92 Simon Cornelius P. Umacob
                    <br> <span class="vexpl">Gateway IPv4/IPv6 address</span></td>
272 d173230c Seth Mos
                </tr>
273
		<tr>
274
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
275
		  <td width="78%" class="vtable">
276
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
277
			<strong>Default Gateway</strong><br />
278
			This will select the above gateway as the default gateway
279
		  </td>
280
		</tr>
281
		<tr>
282
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
283
		  <td width="78%" class="vtable">
284
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
285
			<strong>Alternative monitor IP</strong> <br />
286 f193cf92 Simon Cornelius P. Umacob
			Enter an alternative address here to be used to monitor the link. This is used for the
287 d173230c Seth Mos
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
288
			to icmp requests.</strong>
289
			<br />
290
		  </td>
291
		</tr>
292
		<tr>
293
                  <td width="22%" valign="top" class="vncell">Description</td>
294
                  <td width="78%" class="vtable"> 
295
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
296
                    <br> <span class="vexpl">You may enter a description here
297
                    for your reference (not parsed).</span></td>
298
                </tr>
299
                <tr>
300
                  <td width="22%" valign="top">&nbsp;</td>
301
                  <td width="78%"> 
302
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
303
                    <?php if (isset($id) && $a_gateways[$id]): ?>
304
                    <input name="id" type="hidden" value="<?=$id;?>">
305
                    <?php endif; ?>
306
                  </td>
307
                </tr>
308
              </table>
309
</form>
310
<?php include("fend.inc"); ?>
311
<script language="JavaScript">
312
	enable_change();
313
</script>
314
</body>
315
</html>