Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id: system_gateways_edit.php,v 1.3 2008/11/24 05:48:02 sumacob Exp $ */
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
##|+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
require_once("guiconfig.inc");
41
require_once("IPv6.inc");
42

    
43
if (!is_array($config['gateways']['gateway_item']))
44
	$config['gateways']['gateway_item'] = array();
45

    
46
$a_gateways = &$config['gateways']['gateway_item'];
47

    
48
if (isset($_GET['id'])) {
49
	$id = $_GET['id'];
50
} else if (isset($_POST['id'])) {
51
	$id = $_POST['id'];
52
} else {
53
	$id = -1;
54
}
55

    
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
	$pconfig['type'] = $a_gateways[$id]['type'];
68
}
69

    
70
if (isset($_GET['dup']))
71
	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

    
88
	if ($_POST['type'] == 'IPv4') {
89
		if (!is_ipaddr($_POST['gateway'])) {
90
			$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
		if (!Net_IPv6::checkIPv6($_POST['gateway'])) {
98
			$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
	}
107
	
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

    
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
		if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
126
			$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
127
			break;
128
		}
129
		if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
130
			$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
131
			break;
132
		}
133
		if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
134
			$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
135
			break;
136
		}
137
	}
138

    
139
	if (!$input_errors) {
140
		$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

    
148
		if($_POST['defaultgw'] == "yes") {
149
			$gateway['defaultgw'] = true;
150
		}
151

    
152
		if (isset($id) && $a_gateways[$id])
153
			$a_gateways[$id] = $gateway;
154
		else
155
			$a_gateways[] = $gateway;
156
		
157
		touch($d_staticroutesdirty_path);
158
		
159
		write_config();
160
		
161
		if($_REQUEST['isAjax']) {
162
			echo $_POST['name'];
163
			exit;
164
		}
165
		
166
		header("Location: system_gateways.php");
167
		exit;
168
	}
169
}
170

    
171
$pgtitle = array("System","Gateways","Edit gateway");
172
include("head.inc");
173

    
174
?>
175

    
176
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
177
<?php include("fbegin.inc"); ?>
178
<?php if ($input_errors) print_input_errors($input_errors); ?>
179
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
180
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
181
				<tr>
182
					<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
183
				</tr>	
184
                <tr> 
185
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
186
                  <td width="78%" class="vtable">
187
			<select name="interface" class="formselect">
188
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
189
					  foreach ($interfaces as $iface => $ifacename): ?>
190
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
191
                      <?=htmlspecialchars($ifacename);?>
192
                      </option>
193
                      <?php 
194
						endforeach;
195
						if (is_package_installed("openbgpd") == 1) {
196
							echo "<option value=\"bgpd\"";
197
							if($pconfig['interface'] == "bgpd") 
198
								echo " selected";
199
							echo ">Use BGPD</option>";
200
						}
201
 					  ?>
202
                    </select> <br>
203
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
204
                </tr>
205
                <tr>
206
                  <td width="22%" valign="top" class="vncellreq">Name</td>
207
                  <td width="78%" class="vtable"> 
208
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
209
                    <br> <span class="vexpl">Gateway name</span></td>
210
                </tr>
211
		<tr>
212
                  <td width="22%" valign="top" class="vncellreq">Type</td>
213
                  <td width="78%" class="vtable"> 
214
		<!-- XXX -->
215
		<? /*
216
		<?php if (isset($_GET['id']) || $_POST): ?>
217
                    <select class="formselect" disabled="true">
218
			<?php
219
				if ($pconfig['type'] == 'IPv6') {
220
					$str = <<<EOD
221
					<option value="IPv6" selected>IPv6</option>
222
EOD;
223
				} else {
224
					$str = <<<EOD
225
					<option value="IPv4" selected>IPv4</option>
226
EOD;
227
				}
228

    
229
				echo $str;
230
			?>
231
		    </select>
232
		    <input type="hidden" name="type" id="type" value="<?php htmlspecialchars($pconfig['type']); ?>" />
233
		<? else: ?>
234
                    <select name="type" class="formselect">
235
			<?php
236
				if ($pconfig['type'] == 'IPv6') {
237
					$str = <<<EOD
238
					<option value="IPv4">IPv4</option>
239
					<option value="IPv6" selected>IPv6</option>
240
EOD;
241
				} else {
242
					$str = <<<EOD
243
					<option value="IPv4" selected>IPv4</option>
244
					<option value="IPv6">IPv6</option>
245
EOD;
246
				}
247

    
248
				echo $str;
249
			?>
250
		    </select>
251
		<? endif; ?>
252
		*/ ?>
253
                    <select name="type" class="formselect">
254
			<?php
255
				if ($pconfig['type'] == 'IPv6') {
256
					$str = <<<EOD
257
					<option value="IPv4">IPv4</option>
258
					<option value="IPv6" selected>IPv6</option>
259
EOD;
260
				} else {
261
					$str = <<<EOD
262
					<option value="IPv4" selected>IPv4</option>
263
					<option value="IPv6">IPv6</option>
264
EOD;
265
				}
266

    
267
				echo $str;
268
			?>
269
		    </select>
270
                  </td>
271
                </tr>
272
		<tr>
273
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
274
                  <td width="78%" class="vtable"> 
275
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
276
                    <br> <span class="vexpl">Gateway IPv4/IPv6 address</span></td>
277
                </tr>
278
		<tr>
279
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
280
		  <td width="78%" class="vtable">
281
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
282
			<strong>Default Gateway</strong><br />
283
			This will select the above gateway as the default gateway
284
		  </td>
285
		</tr>
286
		<tr>
287
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
288
		  <td width="78%" class="vtable">
289
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
290
			<strong>Alternative monitor IP</strong> <br />
291
			Enter an alternative address here to be used to monitor the link. This is used for the
292
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
293
			to icmp requests.</strong>
294
			<br />
295
		  </td>
296
		</tr>
297
		<tr>
298
                  <td width="22%" valign="top" class="vncell">Description</td>
299
                  <td width="78%" class="vtable"> 
300
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
301
                    <br> <span class="vexpl">You may enter a description here
302
                    for your reference (not parsed).</span></td>
303
                </tr>
304
                <tr>
305
                  <td width="22%" valign="top">&nbsp;</td>
306
                  <td width="78%"> 
307
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
308
                    <?php if (isset($id) && $a_gateways[$id]): ?>
309
                    <input name="id" type="hidden" value="<?=$id;?>">
310
                    <?php endif; ?>
311
                  </td>
312
                </tr>
313
              </table>
314
</form>
315
<?php include("fend.inc"); ?>
316
<script language="JavaScript">
317
	enable_change();
318
</script>
319
</body>
320
</html>
(182-182/214)