Project

General

Profile

Download (9.59 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php 
2 124aee67 Chris Buechler
/* $Id$ */
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 124aee67 Chris Buechler
require("guiconfig.inc");
41 d173230c Seth Mos
42 124aee67 Chris Buechler
$a_gateways = return_gateways_array();
43 87f0be87 Chris Buechler
$a_gateways_arr = array();
44
foreach($a_gateways as $gw) {
45
	$a_gateways_arr[] = $gw;
46
}
47
$a_gateways = $a_gateways_arr;
48 d173230c Seth Mos
49 87f0be87 Chris Buechler
$id = $_GET['id'];
50
if (isset($_POST['id']))
51 d173230c Seth Mos
	$id = $_POST['id'];
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 124aee67 Chris Buechler
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
65 d173230c Seth Mos
}
66
67 124aee67 Chris Buechler
if (isset($_GET['dup'])) {
68 d173230c Seth Mos
	unset($id);
69 124aee67 Chris Buechler
	unset($pconfig['attribute']);
70
}
71 d173230c Seth Mos
72
if ($_POST) {
73
74
	unset($input_errors);
75
	$pconfig = $_POST;
76
77
	/* input validation */
78
	$reqdfields = explode(" ", "interface name gateway");
79
	$reqdfieldsn = explode(",", "Interface,Name,Gateway");		
80
	
81
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
82
	
83
	if (! isset($_POST['name'])) {
84
		$input_errors[] = "A valid gateway name must be specified.";
85
	}
86 31ace93c Seth Mos
	if (! is_validaliasname($_POST['name'])) {
87
		$input_errors[] = "The gateway name must not contain invalid characters.";
88
	}
89 87f0be87 Chris Buechler
	/* skip system gateways which have been automatically added */
90
	if ($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system")) {
91
		$input_errors[] = "A valid gateway IP address must be specified.";
92
	}
93
	if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
94
		$input_errors[] = "A valid monitor IP address must be specified.";
95 d173230c Seth Mos
	}
96
97 8b060357 Seth Mos
	if (isset($_POST['name'])) {
98 31ace93c Seth Mos
		/* check for overlaps */
99
		foreach ($a_gateways as $gateway) {
100
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
101
				continue;
102
103
			if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
104
				$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
105
				break;
106
			}
107
			if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
108
				$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
109
				break;
110
			}
111
			if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
112
				$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
113
				break;
114
			}
115 d173230c Seth Mos
		}
116
	}
117
118
	if (!$input_errors) {
119 124aee67 Chris Buechler
		/* if we are processing a system gateway only save the monitorip */
120
		if($pconfig['attribute'] == "system") {
121
			$config['interfaces'][$_POST['interface']]['monitorip'] = $_POST['monitor'];
122 d7dfd5f8 Seth Mos
		}
123 e3153473 Simon Cornelius P. Umacob
124 124aee67 Chris Buechler
		/* Manual gateways are handled differently */
125
		/* rebuild the array with the manual entries only */
126
		if (!is_array($config['gateways']['gateway_item']))
127
			$config['gateways']['gateway_item'] = array();
128
129
		$a_gateways = &$config['gateways']['gateway_item'];
130
131
		if ($pconfig['attribute'] != "system") {
132
			$gateway = array();
133
			$gateway['interface'] = $_POST['interface'];
134
			$gateway['name'] = $_POST['name'];
135
			$gateway['gateway'] = $_POST['gateway'];
136
			$gateway['descr'] = $_POST['descr'];
137
138
			if ($_POST['defaultgw'] == "yes") {
139 87f0be87 Chris Buechler
				$i = 0;
140
				foreach($a_gateways as $gw) {
141
					unset($config['gateways'][$i]['defaultgw']);
142 124aee67 Chris Buechler
					$i++;
143
				}
144 87f0be87 Chris Buechler
				$gateway['defaultgw'] = true;
145
			} else {
146
				unset($gateway['defaultgw']);
147 124aee67 Chris Buechler
			}
148
149
			/* when saving the manual gateway we use the attribute which has the corresponding id */
150
			$id = $pconfig['attribute'];
151
			if (isset($id) && $a_gateways[$id]) {
152
				$a_gateways[$id] = $gateway;
153
			} else {
154
				$a_gateways[] = $gateway;
155
			}
156
		}
157 d173230c Seth Mos
		
158
		touch($d_staticroutesdirty_path);
159
		
160
		write_config();
161
		
162 ad862220 Charlie
		if($_REQUEST['isAjax']) {
163
			echo $_POST['name'];
164
			exit;
165
		}
166
		
167 d173230c Seth Mos
		header("Location: system_gateways.php");
168
		exit;
169
	}
170
}
171
172 d88c6a9f Scott Ullrich
$pgtitle = array("System","Gateways","Edit gateway");
173 d173230c Seth Mos
include("head.inc");
174
175
?>
176
177
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
178
<?php include("fbegin.inc"); ?>
179
<?php if ($input_errors) print_input_errors($input_errors); ?>
180
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
181 124aee67 Chris Buechler
	<?php
182
	/* If this is a automatically added system gateway we need this var */
183
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
184
		echo "<input type='hidden' name='attribute' id='attribute' value='{$pconfig['attribute']}' >\n";
185
	}
186
	?>
187 d173230c Seth Mos
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
188 56d4e7fb Scott Ullrich
				<tr>
189
					<td colspan="2" valign="top" class="listtopic">Edit gateway</td>
190
				</tr>	
191 d173230c Seth Mos
                <tr> 
192
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
193
                  <td width="78%" class="vtable">
194
			<select name="interface" class="formselect">
195 3e321df2 Ermal Luçi
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
196 d173230c Seth Mos
					  foreach ($interfaces as $iface => $ifacename): ?>
197
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
198
                      <?=htmlspecialchars($ifacename);?>
199
                      </option>
200 8e21cbb8 Scott Ullrich
                      <?php 
201
						endforeach;
202
						if (is_package_installed("openbgpd") == 1) {
203
							echo "<option value=\"bgpd\"";
204
							if($pconfig['interface'] == "bgpd") 
205
								echo " selected";
206
							echo ">Use BGPD</option>";
207
						}
208
 					  ?>
209 d173230c Seth Mos
                    </select> <br>
210
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
211
                </tr>
212
                <tr>
213
                  <td width="22%" valign="top" class="vncellreq">Name</td>
214
                  <td width="78%" class="vtable"> 
215
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
216
                    <br> <span class="vexpl">Gateway name</span></td>
217
                </tr>
218
		<tr>
219
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
220
                  <td width="78%" class="vtable"> 
221
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
222 87f0be87 Chris Buechler
                    <br> <span class="vexpl">Gateway IP address</span></td>
223 d173230c Seth Mos
                </tr>
224
		<tr>
225
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
226
		  <td width="78%" class="vtable">
227
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
228
			<strong>Default Gateway</strong><br />
229
			This will select the above gateway as the default gateway
230
		  </td>
231
		</tr>
232
		<tr>
233
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
234
		  <td width="78%" class="vtable">
235
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
236
			<strong>Alternative monitor IP</strong> <br />
237 87f0be87 Chris Buechler
			Enter a alternative address here to be used to monitor the link. This is used for the
238 d173230c Seth Mos
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
239
			to icmp requests.</strong>
240
			<br />
241
		  </td>
242
		</tr>
243
		<tr>
244
                  <td width="22%" valign="top" class="vncell">Description</td>
245
                  <td width="78%" class="vtable"> 
246
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
247
                    <br> <span class="vexpl">You may enter a description here
248
                    for your reference (not parsed).</span></td>
249
                </tr>
250
                <tr>
251
                  <td width="22%" valign="top">&nbsp;</td>
252
                  <td width="78%"> 
253
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
254
                    <?php if (isset($id) && $a_gateways[$id]): ?>
255
                    <input name="id" type="hidden" value="<?=$id;?>">
256
                    <?php endif; ?>
257
                  </td>
258
                </tr>
259
              </table>
260
</form>
261
<?php include("fend.inc"); ?>
262
<script language="JavaScript">
263
	enable_change();
264
</script>
265
</body>
266
</html>