Project

General

Profile

Download (10.3 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
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-system-gateways-editgateway
37
##|*NAME=System: Gateways: Edit Gateway page
38
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway' page.
39
##|*MATCH=system_gateways_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require("pkg-utils.inc");
44

    
45
$a_gateways = return_gateways_array();
46
$a_gateways_arr = array();
47
foreach($a_gateways as $gw) {
48
	$a_gateways_arr[] = $gw;
49
}
50
$a_gateways = $a_gateways_arr;
51

    
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
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['attribute'] = $a_gateways[$id]['attribute'];
68
}
69

    
70
if (isset($_GET['dup'])) {
71
	unset($id);
72
	unset($pconfig['attribute']);
73
}
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = explode(" ", "interface name gateway");
82
	$reqdfieldsn = explode(",", "Interface,Name,Gateway");		
83
	
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85
	
86
	if (! isset($_POST['name'])) {
87
		$input_errors[] = "A valid gateway name must be specified.";
88
	}
89
	if (! is_validaliasname($_POST['name'])) {
90
		$input_errors[] = "The gateway name must not contain invalid characters.";
91
	}
92
	/* skip system gateways which have been automatically added */
93
	if ($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system")) {
94
		$input_errors[] = "A valid gateway IP address must be specified.";
95
	}
96
	if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system")) {
97
		$parent_ip = get_interface_ip($_POST['interface']);
98
		$parent_sn = get_interface_subnet($_POST['interface']);
99
		if(!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn)) {
100
			$input_errors[] = "The gateway address {$_POST['gateway']} does not lie within the chosen interface's subnet.";
101
		}
102
	}
103
	if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
104
		$input_errors[] = "A valid monitor IP address must be specified.";
105
	}
106

    
107
	if (isset($_POST['name'])) {
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
			if (($gateway['name'] <> "") && (in_array($_POST['name'], $gateway))) {
114
				$input_errors[] = "The gateway name \"{$_POST['name']}\" already exists.";
115
				break;
116
			}
117
			if (($gateway['gateway'] <> "") && (in_array($_POST['gateway'], $gateway))) {
118
				$input_errors[] = "The gateway IP address \"{$_POST['gateway']}\" already exists.";
119
				break;
120
			}
121
			if (($gateway['monitor'] <> "") && (in_array($_POST['monitor'], $gateway))) {
122
				$input_errors[] = "The monitor IP address \"{$_POST['monitor']}\" is already in use. You must choose a different monitor IP.";
123
				break;
124
			}
125
		}
126
	}
127

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

    
134
		/* Manual gateways are handled differently */
135
		/* rebuild the array with the manual entries only */
136
		if (!is_array($config['gateways']['gateway_item']))
137
			$config['gateways']['gateway_item'] = array();
138

    
139
		$a_gateways = &$config['gateways']['gateway_item'];
140

    
141
		if ($pconfig['attribute'] != "system") {
142
			$gateway = array();
143
			$gateway['interface'] = $_POST['interface'];
144
			$gateway['name'] = $_POST['name'];
145
			$gateway['gateway'] = $_POST['gateway'];
146
			$gateway['descr'] = $_POST['descr'];
147
			$gateway['monitor'] = $_POST['monitor'];
148
			
149
			if ($_POST['defaultgw'] == "yes" or $_POST['defaultgw'] == "on") {
150
				$i = 0;
151
				foreach($a_gateways as $gw) {
152
					unset($config['gateways'][$i]['defaultgw']);
153
					$i++;
154
				}
155
				$gateway['defaultgw'] = true;
156
			} else {
157
				unset($gateway['defaultgw']);
158
			}
159

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

    
183
$pgtitle = array("System","Gateways","Edit gateway");
184
include("head.inc");
185

    
186
?>
187

    
188
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
189
<?php include("fbegin.inc"); ?>
190
<?php if ($input_errors) print_input_errors($input_errors); ?>
191
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
192
	<?php
193
	/* If this is a automatically added system gateway we need this var */
194
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
195
		echo "<input type='hidden' name='attribute' id='attribute' value='{$pconfig['attribute']}' >\n";
196
	}
197
	?>
198
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
199
				<tr>
200
					<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
201
				</tr>	
202
                <tr> 
203
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
204
                  <td width="78%" class="vtable">
205
				  <select name="interface" class="formselect">
206
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
207
					  foreach ($interfaces as $iface => $ifacename): ?>
208
                      <option value="<?=$iface;?>" <?php if (get_real_interface($iface) == $pconfig['interface']) echo " selected"; ?>> 
209
                      <?=htmlspecialchars($ifacename);?>
210
                      </option>
211
					iface = <?=$iface?> ;  pconfig = <?=$pconfig['interface']?>  ;  ifacename = <?=$ifacename?>
212
                      <?php 
213
						endforeach;
214
						if (is_package_installed("openbgpd") == 1) {
215
							echo "<option value=\"bgpd\"";
216
							if($pconfig['interface'] == "bgpd") 
217
								echo " selected";
218
							echo ">Use BGPD</option>";
219
						}
220
 					  ?>
221
                    </select> <br>
222
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
223
                </tr>
224
                <tr>
225
                  <td width="22%" valign="top" class="vncellreq">Name</td>
226
                  <td width="78%" class="vtable"> 
227
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
228
                    <br> <span class="vexpl">Gateway name</span></td>
229
                </tr>
230
		<tr>
231
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
232
                  <td width="78%" class="vtable"> 
233
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
234
                    <br> <span class="vexpl">Gateway IP address</span></td>
235
                </tr>
236
		<tr>
237
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
238
		  <td width="78%" class="vtable">
239
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
240
			<strong>Default Gateway</strong><br />
241
			This will select the above gateway as the default gateway
242
		  </td>
243
		</tr>
244
		<tr>
245
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
246
		  <td width="78%" class="vtable">
247
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
248
			<strong>Alternative monitor IP</strong> <br />
249
			Enter an alternative address here to be used to monitor the link. This is used for the
250
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
251
			to ICMP echo requests (pings).</strong>
252
			<br />
253
		  </td>
254
		</tr>
255
		<tr>
256
                  <td width="22%" valign="top" class="vncell">Description</td>
257
                  <td width="78%" class="vtable"> 
258
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
259
                    <br> <span class="vexpl">You may enter a description here
260
                    for your reference (not parsed).</span></td>
261
                </tr>
262
                <tr>
263
                  <td width="22%" valign="top">&nbsp;</td>
264
                  <td width="78%"> 
265
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
266
                    <?php if (isset($id) && $a_gateways[$id]): ?>
267
                    <input name="id" type="hidden" value="<?=$id;?>">
268
                    <?php endif; ?>
269
                  </td>
270
                </tr>
271
              </table>
272
</form>
273
<?php include("fend.inc"); ?>
274
<script language="JavaScript">
275
	enable_change();
276
</script>
277
</body>
278
</html>
(182-182/214)