Project

General

Profile

Download (9.78 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("pkg-utils.inc");
42

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

    
50
$id = $_GET['id'];
51
if (isset($_POST['id']))
52
	$id = $_POST['id'];
53

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

    
58
if (isset($id) && $a_gateways[$id]) {
59
	$pconfig['name'] = $a_gateways[$id]['name'];
60
	$pconfig['interface'] = $a_gateways[$id]['interface'];
61
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
62
	$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
63
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
64
	$pconfig['descr'] = $a_gateways[$id]['descr'];
65
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
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
	if (! isset($_POST['name'])) {
85
		$input_errors[] = "A valid gateway name must be specified.";
86
	}
87
	if (! is_validaliasname($_POST['name'])) {
88
		$input_errors[] = "The gateway name must not contain invalid characters.";
89
	}
90
	/* skip system gateways which have been automatically added */
91
	if ($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system")) {
92
		$input_errors[] = "A valid gateway IP address must be specified.";
93
	}
94
	if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
95
		$input_errors[] = "A valid monitor IP address must be specified.";
96
	}
97

    
98
	if (isset($_POST['name'])) {
99
		/* check for overlaps */
100
		foreach ($a_gateways as $gateway) {
101
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway))
102
				continue;
103

    
104
			if (($gateway['name'] <> "") && (in_array($gateway, $_POST['name']))) {
105
				$input_errors[] = "The name \"{$_POST['name']}\" already exists.";
106
				break;
107
			}
108
			if (($gateway['gateway'] <> "") && (in_array($gateway, $_POST['gateway']))) {
109
				$input_errors[] = "The IP address \"{$_POST['gateway']}\" already exists.";
110
				break;
111
			}
112
			if (($gateway['monitor'] <> "") && (in_array($gateway, $gateway['monitor']))) {
113
				$input_errors[] = "The IP address \"{$_POST['monitor']}\" already exists.";
114
				break;
115
			}
116
		}
117
	}
118

    
119
	if (!$input_errors) {
120
		/* if we are processing a system gateway only save the monitorip */
121
		if($pconfig['attribute'] == "system") {
122
			$config['interfaces'][$_POST['interface']]['monitorip'] = $_POST['monitor'];
123
		}
124

    
125
		/* Manual gateways are handled differently */
126
		/* rebuild the array with the manual entries only */
127
		if (!is_array($config['gateways']['gateway_item']))
128
			$config['gateways']['gateway_item'] = array();
129

    
130
		$a_gateways = &$config['gateways']['gateway_item'];
131

    
132
		if ($pconfig['attribute'] != "system") {
133
			$gateway = array();
134
			$gateway['interface'] = $_POST['interface'];
135
			$gateway['name'] = $_POST['name'];
136
			$gateway['gateway'] = $_POST['gateway'];
137
			$gateway['descr'] = $_POST['descr'];
138
			$gateway['monitor'] = $_POST['monitor'];
139
			
140
			if ($_POST['defaultgw'] == "yes") {
141
				$i = 0;
142
				foreach($a_gateways as $gw) {
143
					unset($config['gateways'][$i]['defaultgw']);
144
					$i++;
145
				}
146
				$gateway['defaultgw'] = true;
147
			} else {
148
				unset($gateway['defaultgw']);
149
			}
150

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

    
174
$pgtitle = array("System","Gateways","Edit gateway");
175
include("head.inc");
176

    
177
?>
178

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