Project

General

Profile

Download (9.84 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['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
97
		$input_errors[] = "A valid monitor IP address must be specified.";
98
	}
99

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

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

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

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

    
132
		$a_gateways = &$config['gateways']['gateway_item'];
133

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

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

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

    
179
?>
180

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