Project

General

Profile

Download (10.1 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
		if(! ip_in_subnet($_POST['gateway']), get_interface_subnet($interface)) {
98
			$input_errors[] = "The Address {$_POST['gateway']} does not lie in the interface subnet";                
99
		}
100
	}
101
	if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
102
		$input_errors[] = "A valid monitor IP address must be specified.";
103
	}
104

    
105
	if (isset($_POST['name'])) {
106
		/* check for overlaps */
107
		foreach ($a_gateways as $gateway) {
108
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
109
				continue;
110

    
111
			if (($gateway['name'] <> "") && (in_array($_POST['name'], $gateway))) {
112
				$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
113
				break;
114
			}
115
			if (($gateway['gateway'] <> "") && (in_array($_POST['gateway'], $gateway))) {
116
				$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
117
				break;
118
			}
119
			if (($gateway['monitor'] <> "") && (in_array($_POST['monitor'], $gateway))) {
120
				$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
121
				break;
122
			}
123
		}
124
	}
125

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

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

    
137
		$a_gateways = &$config['gateways']['gateway_item'];
138

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

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

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

    
184
?>
185

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