Project

General

Profile

Download (8.47 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
require("guiconfig.inc");
33

    
34
if (!is_array($config['gateways']['gateway_item']))
35
	$config['gateways']['gateway_item'] = array();
36

    
37
$a_gateways = &$config['gateways']['gateway_item'];
38

    
39
$id = $_GET['id'];
40
if (isset($_POST['id']))
41
	$id = $_POST['id'];
42

    
43
if (isset($_GET['dup'])) {
44
	$id = $_GET['dup'];
45
}
46

    
47
if (isset($id) && $a_gateways[$id]) {
48
	$pconfig['name'] = $a_gateways[$id]['name'];
49
	$pconfig['interface'] = $a_gateways[$id]['interface'];
50
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
51
	$pconfig['defaultgw'] = $a_gateways[$id]['defaultgw'];
52
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
53
	$pconfig['descr'] = $a_gateways[$id]['descr'];
54
}
55

    
56
if (isset($_GET['dup']))
57
	unset($id);
58

    
59
if ($_POST) {
60

    
61
	unset($input_errors);
62
	$pconfig = $_POST;
63

    
64
	/* input validation */
65
	$reqdfields = explode(" ", "interface name gateway");
66
	$reqdfieldsn = explode(",", "Interface,Name,Gateway");		
67
	
68
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
69
	
70
	if (! isset($_POST['name'])) {
71
		$input_errors[] = "A valid gateway name must be specified.";
72
	}
73
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
74
		$input_errors[] = "A valid gateway IP address must be specified.";
75
	}
76
	if ((($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']))) {
77
		$input_errors[] = "A valid monitor IP address must be specified.";
78
	}
79

    
80
	if ($_POST['defaultgw'] == "yes") {
81
		$i=0;
82
		foreach ($a_gateways as $gateway) {
83
			if($id != $i) {
84
	                        unset($config['gateways']['gateway_item'][$i]['defaultgw']);
85
			} else {
86
	                        $config['gateways']['gateway_item'][$i]['defaultgw'] = true;
87
			}
88
			$i++;
89
		}
90
	} else {
91
		$i=0;
92
		foreach ($a_gateways as $gateway) {
93
			if($id == $i) {
94
	                        unset($config['gateways']['gateway_item'][$i]['defaultgw']);
95
			}
96
			$i++;
97
		}
98
	}
99

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

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

    
119
	if (!$input_errors) {
120
		$gateway = array();
121
		$gateway['interface'] = $_POST['interface'];
122
		$gateway['name'] = $_POST['name'];
123
		$gateway['gateway'] = $_POST['gateway'];
124
		$gateway['monitor'] = $_POST['monitor'];
125
		$gateway['descr'] = $_POST['descr'];
126

    
127
		if($_POST['defaultgw'] == "yes") {
128
			$i = 0;
129
			foreach($a_gateways as $gw) {
130
				unset($config['gateways'][$i]['defaultgw']);
131
				$i++;
132
			}
133
			$gateway['defaultgw'] = true;
134
		} else {
135
			unset($gateway['defaultgw']);
136
		}
137

    
138
		if (isset($id) && $a_gateways[$id])
139
			$a_gateways[$id] = $gateway;
140
		else
141
			$a_gateways[] = $gateway;
142
		
143
		touch($d_staticroutesdirty_path);
144
		
145
		write_config();
146
		
147
		header("Location: system_gateways.php");
148
		exit;
149
	}
150
}
151

    
152
$pgtitle = array("System","Gateways","Edit gateway");
153
include("head.inc");
154

    
155
?>
156

    
157
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
158
<?php include("fbegin.inc"); ?>
159
<?php if ($input_errors) print_input_errors($input_errors); ?>
160
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
161
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
162
                <tr> 
163
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
164
                  <td width="78%" class="vtable">
165
			<select name="interface" class="formselect">
166
                      <?php $interfaces = get_configured_interface_with_descr(false, true);
167
					  foreach ($interfaces as $iface => $ifacename): ?>
168
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
169
                      <?=htmlspecialchars($ifacename);?>
170
                      </option>
171
                      <?php 
172
						endforeach;
173
						if (is_package_installed("openbgpd") == 1) {
174
							echo "<option value=\"bgpd\"";
175
							if($pconfig['interface'] == "bgpd") 
176
								echo " selected";
177
							echo ">Use BGPD</option>";
178
						}
179
 					  ?>
180
                    </select> <br>
181
                    <span class="vexpl">Choose which interface this gateway applies to.</span></td>
182
                </tr>
183
                <tr>
184
                  <td width="22%" valign="top" class="vncellreq">Name</td>
185
                  <td width="78%" class="vtable"> 
186
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
187
                    <br> <span class="vexpl">Gateway name</span></td>
188
                </tr>
189
		<tr>
190
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
191
                  <td width="78%" class="vtable"> 
192
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
193
                    <br> <span class="vexpl">Gateway IP address</span></td>
194
                </tr>
195
		<tr>
196
		  <td width="22%" valign="top" class="vncell">Default Gateway</td>
197
		  <td width="78%" class="vtable">
198
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?> onclick="enable_change(false)" />
199
			<strong>Default Gateway</strong><br />
200
			This will select the above gateway as the default gateway
201
		  </td>
202
		</tr>
203
		<tr>
204
		  <td width="22%" valign="top" class="vncell">Monitor IP</td>
205
		  <td width="78%" class="vtable">
206
			<input name="monitor" type="text" id="monitor" value="<?php echo ($pconfig['monitor']) ; ?>" />
207
			<strong>Alternative monitor IP</strong> <br />
208
			Enter a alternative address here to be used to monitor the link. This is used for the
209
			quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond
210
			to icmp requests.</strong>
211
			<br />
212
		  </td>
213
		</tr>
214
		<tr>
215
                  <td width="22%" valign="top" class="vncell">Description</td>
216
                  <td width="78%" class="vtable"> 
217
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
218
                    <br> <span class="vexpl">You may enter a description here
219
                    for your reference (not parsed).</span></td>
220
                </tr>
221
                <tr>
222
                  <td width="22%" valign="top">&nbsp;</td>
223
                  <td width="78%"> 
224
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
225
                    <?php if (isset($id) && $a_gateways[$id]): ?>
226
                    <input name="id" type="hidden" value="<?=$id;?>">
227
                    <?php endif; ?>
228
                  </td>
229
                </tr>
230
              </table>
231
</form>
232
<?php include("fend.inc"); ?>
233
<script language="JavaScript">
234
	enable_change();
235
</script>
236
</body>
237
</html>
(161-161/200)