Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
##|+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("guiconfig.inc");
41
require_once("IPv6.inc");
42

    
43
$a_gateways = return_gateways_array();
44

    
45
if (isset($_GET['id'])) {
46
	$id = $_GET['id'];
47
} else if (isset($_POST['id'])) {
48
	$id = $_POST['id'];
49
} else {
50
	$id = -1;
51
}
52

    
53
if (isset($_GET['dup'])) {
54
	$id = $_GET['dup'];
55
}
56

    
57
if (isset($id) && $a_gateways[$id]) {
58
	$pconfig['name'] = $a_gateways[$id]['name'];
59
	$pconfig['interface'] = $a_gateways[$id]['interface'];
60
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
61
	$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
62
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
63
	$pconfig['descr'] = $a_gateways[$id]['descr'];
64
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
65
	$pconfig['type'] = $a_gateways[$id]['type'];
66
}
67

    
68
if (isset($_GET['dup'])) {
69
	unset($id);
70
	unset($pconfig['attribute']);
71
}
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
	/* Does this gateway name already exist? */
85
	foreach($config['gateways']['gateway_item'] as $gw) 
86
		if($gw['name'] == $_POST['name']) 
87
			$input_errors[] = "This gateway name already exists.";
88
	
89
	if (! isset($_POST['name'])) {
90
		$input_errors[] = "A valid gateway name must be specified.";
91
	}
92

    
93
	if ($_POST['type'] == 'IPv4') {
94
		if (!is_ipaddr($_POST['gateway']) && $pconfig['attribute'] != 'system') {
95
			$input_errors[] = "A valid IPv4 gateway address must be specified.";
96
		}
97

    
98
		if ($_POST['monitor'] && !is_ipaddr($_POST['monitor'])) {
99
			$input_errors[] = "A valid IPv4 monitor address must be specified.";
100
		}
101
	} else if ($_POST['type'] == 'IPv6') {
102
		if (!Net_IPv6::checkIPv6($_POST['gateway']) && $pconfig['attribute'] != 'system') {
103
			$input_errors[] = "A valid IPv6 gateway address must be specified.";
104
		}
105

    
106
		if ($_POST['monitor'] && !Net_IPv6::checkIPv6($_POST['monitor'])) {
107
			$input_errors[] = "A valid IPv6 monitor address must be specified.";
108
		}
109
	} else {
110
		$input_errors[] = "A network type must be specified.";
111
	}
112

    
113
	/* check for overlaps */
114
	foreach ($a_gateways as $gateway) {
115
		if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
116
			continue;
117

    
118
		if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
119
			$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
120
			break;
121
		}
122
		if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
123
			$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
124
			break;
125
		}
126
		if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
127
			$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
128
			break;
129
		}
130
	}
131

    
132
	if (!$input_errors) {
133
		/* if we are processing a system gateway only save the monitorip */
134
		if($pconfig['attribute'] == "system") {
135
			$config['interfaces'][$_POST['interface']]['monitorip'] = $_POST['monitor'];
136
		}
137

    
138
		/* Manual gateways are handled differently */
139
		/* rebuild the array with the manual entries only */
140
		if (!is_array($config['gateways']['gateway_item']))
141
			$config['gateways']['gateway_item'] = array();
142

    
143
		$a_gateways = &$config['gateways']['gateway_item'];
144

    
145
		if ($pconfig['attribute'] != "system") {
146
			$gateway = array();
147
			$gateway['interface'] = $_POST['interface'];
148
			$gateway['name'] = $_POST['name'];
149
			$gateway['gateway'] = $_POST['gateway'];
150
			$gateway['descr'] = $_POST['descr'];
151
			$gateway['type'] = $_POST['type'];
152

    
153
			if ($_POST['defaultgw'] == "yes") {
154
				$i=0;
155
				foreach ($a_gateways as $gateway) {
156
					if($id != $i && $config['gateways']['gateway_item'][$i]['type'] == $_POST['type']) {
157
						unset($config['gateways']['gateway_item'][$i]['defaultgw']);
158
					} else if ($config['gateways']['gateway_item'][$i]['type'] == $_POST['type']) {
159
						$config['gateways']['gateway_item'][$i]['defaultgw'] = true;
160
					}
161
					$i++;
162
				}
163
			}
164

    
165
			/* when saving the manual gateway we use the attribute which has the corresponding id */
166
			$id = $pconfig['attribute'];
167
			if (isset($id) && $a_gateways[$id]) {
168
				$a_gateways[$id] = $gateway;
169
			} else {
170
				$a_gateways[] = $gateway;
171
			}
172
		}
173
		
174
		touch($d_staticroutesdirty_path);
175
		
176
		write_config();
177
		
178
		if($_REQUEST['isAjax']) {
179
			echo $_POST['name'];
180
			exit;
181
		}
182
		
183
		header("Location: system_gateways.php");
184
		exit;
185
	}
186
}
187

    
188
$pgtitle = array("System","Gateways","Edit gateway");
189
include("head.inc");
190

    
191
?>
192

    
193
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
194
<?php include("fbegin.inc"); ?>
195
<?php if ($input_errors) print_input_errors($input_errors); ?>
196
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
197
	<?php
198
	/* If this is a automatically added system gateway we need this var */
199
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
200
		echo "<input type='hidden' name='attribute' id='attribute' value='{$pconfig['attribute']}' >\n";
201
	}
202
	?>
203
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
204
				<tr>
205
					<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
206
				</tr>	
207
                <tr> 
208
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
209
                  <td width="78%" class="vtable">
210
			<select name="interface" class="formselect">
211
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
212
					  foreach ($interfaces as $iface => $ifacename): ?>
213
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
214
                      <?=htmlspecialchars($ifacename);?>
215
                      </option>
216
                      <?php 
217
						endforeach;
218
						if (is_package_installed("openbgpd") == 1) {
219
							echo "<option value=\"bgpd\"";
220
							if($pconfig['interface'] == "bgpd") 
221
								echo " selected";
222
							echo ">Use BGPD</option>";
223
						}
224
 					  ?>
225
                    </select> <br>
226
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
227
                </tr>
228
                <tr>
229
                  <td width="22%" valign="top" class="vncellreq">Name</td>
230
                  <td width="78%" class="vtable"> 
231
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
232
                    <br> <span class="vexpl">Gateway name</span></td>
233
                </tr>
234
		<tr>
235
                  <td width="22%" valign="top" class="vncellreq">Type</td>
236
                  <td width="78%" class="vtable"> 
237
                    <select name="type" class="formselect">
238
			<?php
239
				if ($pconfig['type'] == 'IPv6') {
240
					$str = <<<EOD
241
					<option value="IPv4">IPv4</option>
242
					<option value="IPv6" selected>IPv6</option>
243
EOD;
244
				} else {
245
					$str = <<<EOD
246
					<option value="IPv4" selected>IPv4</option>
247
					<option value="IPv6">IPv6</option>
248
EOD;
249
				}
250

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