Project

General

Profile

Download (9.75 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

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

    
49
$id = $_GET['id'];
50
if (isset($_POST['id']))
51
	$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
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
65
}
66

    
67
if (isset($_GET['dup'])) {
68
	unset($id);
69
	unset($pconfig['attribute']);
70
}
71

    
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
	if (! is_validaliasname($_POST['name'])) {
87
		$input_errors[] = "The gateway name must not contain invalid characters.";
88
	}
89
	/* 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
	}
96

    
97
	if (isset($_POST['name'])) {
98
		/* 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
		}
116
	}
117

    
118
	if (!$input_errors) {
119
		/* 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
		}
123

    
124
		/* 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
			$gateway['monitor'] = $_POST['monitor'];
138
			
139
			if ($_POST['defaultgw'] == "yes") {
140
				$i = 0;
141
				foreach($a_gateways as $gw) {
142
					unset($config['gateways'][$i]['defaultgw']);
143
					$i++;
144
				}
145
				$gateway['defaultgw'] = true;
146
			} else {
147
				unset($gateway['defaultgw']);
148
			}
149

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

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

    
176
?>
177

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