Project

General

Profile

Download (12.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
4
	system_routes_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2010 Scott Ullrich
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_MODULE:	routing
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-system-staticroutes-editroute
38
##|*NAME=System: Static Routes: Edit route page
39
##|*DESCR=Allow access to the 'System: Static Routes: Edit route' page.
40
##|*MATCH=system_routes_edit.php*
41
##|-PRIV
42

    
43
function staticroutecmp($a, $b) {
44
	return strcmp($a['network'], $b['network']);
45
}
46

    
47
function staticroutes_sort() {
48
        global $g, $config;
49

    
50
        if (!is_array($config['staticroutes']['route']))
51
                return;
52

    
53
        usort($config['staticroutes']['route'], "staticroutecmp");
54
}
55

    
56
require("guiconfig.inc");
57

    
58
if (!is_array($config['staticroutes']['route']))
59
	$config['staticroutes']['route'] = array();
60

    
61
$a_routes = &$config['staticroutes']['route'];
62
$a_gateways = return_gateways_array(true);
63

    
64
$id = $_GET['id'];
65
if (isset($_POST['id']))
66
	$id = $_POST['id'];
67

    
68
if (isset($_GET['dup'])) {
69
	$id = $_GET['dup'];
70
}
71

    
72
if (isset($id) && $a_routes[$id]) {
73
	list($pconfig['network'],$pconfig['network_subnet']) = 
74
		explode('/', $a_routes[$id]['network']);
75
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
76
	$pconfig['descr'] = $a_routes[$id]['descr'];
77
}
78

    
79
if (isset($_GET['dup']))
80
	unset($id);
81

    
82
if ($_POST) {
83

    
84
	unset($input_errors);
85
	$pconfig = $_POST;
86

    
87
	/* input validation */
88
	$reqdfields = explode(" ", "network network_subnet gateway");
89
	$reqdfieldsn = explode(",",
90
			gettext("Destination network") . "," .
91
			gettext("Destination network bit count") . "," .
92
			gettext("Gateway"));		
93
	
94
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95
	
96
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
97
		$input_errors[] = gettext("A valid destination network must be specified.");
98
	}
99
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
100
		$input_errors[] = gettext("A valid destination network bit count must be specified.");
101
	}
102
	if ($_POST['gateway']) {
103
		if (!isset($a_gateways[$_POST['gateway']]))
104
			$input_errors[] = gettext("A valid gateway must be specified.");
105
	}
106

    
107
	/* check for overlaps */
108
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
109
	foreach ($a_routes as $route) {
110
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
111
			continue;
112

    
113
		if ($route['network'] == $osn) {
114
			$input_errors[] = gettext("A route to this destination network already exists.");
115
			break;
116
		}
117
	}
118

    
119
	if (!$input_errors) {
120
		$route = array();
121
		$route['network'] = $osn;
122
		$route['gateway'] = $_POST['gateway'];
123
		$route['descr'] = $_POST['descr'];
124

    
125
		if (isset($id) && $a_routes[$id])
126
			$a_routes[$id] = $route;
127
		else
128
			$a_routes[] = $route;
129
		staticroutes_sort();
130
		
131
		mark_subsystem_dirty('staticroutes');
132
		
133
		write_config();
134
		
135
		header("Location: system_routes.php");
136
		exit;
137
	}
138
}
139

    
140
$pgtitle = array(gettext("System"),gettext("Static Routes"),gettext("Edit route"));
141
include("head.inc");
142

    
143
?>
144

    
145
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
146
<?php include("fbegin.inc"); ?>
147
<?php if ($input_errors) print_input_errors($input_errors); ?>
148
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
149
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
150
				<tr>
151
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit route entry"); ?></td>
152
				</tr>	
153
                <tr>
154
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Destination network"); ?></td>
155
                  <td width="78%" class="vtable"> 
156
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
157
				  / 
158
                    <select name="network_subnet" class="formselect" id="network_subnet">
159
                      <?php for ($i = 32; $i >= 1; $i--): ?>
160
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
161
                      <?=$i;?>
162
                      </option>
163
                      <?php endfor; ?>
164
                    </select>
165
                    <br> <span class="vexpl"><?=gettext("Destination network for this static route"); ?></span></td>
166
                </tr>
167
                <tr> 
168
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
169
                  <td width="78%" class="vtable">
170
			<select name="gateway" id="gateway" class="formselect">
171
			<?php
172
				foreach ($a_gateways as $gateway) {
173
					if ($gateway['attribute'] == "system") {
174
	                      			echo "<option value='{$gateway['friendlyiface']}' ";
175
						if ($gateway['friendlyiface'] == $pconfig['gateway'])
176
							echo "selected";
177
					} else {
178
	                      			echo "<option value='{$gateway['name']}' ";
179
						if ($gateway['name'] == $pconfig['gateway'])
180
							echo "selected";
181
					}
182
	                      		echo ">" . htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']) . "</option>\n";
183
				}
184
			?>
185
                    </select> <br />
186
			<div id='addgwbox'>
187
				<?=gettext("Choose which gateway this route applies to or"); ?> <a OnClick="show_add_gateway();" href="#"><?=gettext("add a new one.");?></a>
188
								</div>
189
								<div id='notebox'>
190
								</div>
191
								<div style="display:none" name ="status" id="status">
192
								</div>								
193
								<div style="display:none" id="addgateway" name="addgateway">
194
									<p> 
195
									<table border="1" style="background:#990000; border-style: none none none none; width:225px;"><tr><td>
196
										<table bgcolor="#990000" cellpadding="1" cellspacing="1">
197
											<tr><td>&nbsp;</td>
198
											<tr>
199
												<td colspan="2"><center><b><font color="white"><?=gettext("Add new gateway:"); ?></b></center></td>
200
											</tr>
201
											<tr><td>&nbsp;</td>
202
											<tr>
203
												<td width="45%" align="right"><font color="white"><?=gettext("Default gateway:"); ?></td><td><input type="checkbox" id="defaultgw" name="defaultgw"<?=$checked?>></td>
204
											</tr>												
205
											<tr>
206
												<td width="45%" align="right"><font color="white"><?=gettext("Interface:"); ?></td>
207
												<td><select name="addinterfacegw" id="addinterfacegw">
208
												<?php $gwifs = get_configured_interface_with_descr();
209
													foreach($gwifs as $fif => $dif)
210
														echo "<option value=\"{$fif}\">{$dif}</option>\n";
211
												?>
212
												</select></td>
213
											</tr>
214
											<tr>
215
												<td align="right"><font color="white"><?=gettext("Gateway Name:"); ?></td><td><input id="name" name="name" value="GW"></td>
216
											</tr>
217
											<tr>
218
												<td align="right"><font color="white"><?=gettext("Gateway IP:"); ?></td><td><input id="gatewayip" name="gatewayip"></td>
219
											</tr>
220
											<tr>
221
												<td align="right"><font color="white"><?=gettext("Description:"); ?></td><td><input id="gatewaydescr" name="gatewaydescr"></td>
222
											</tr>
223
											<tr><td>&nbsp;</td>
224
											<tr>
225
												<td colspan="2">
226
													<center>
227
														<div id='savebuttondiv'>
228
															<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
229
															<input id="gwsave" type="Button" value="<?=gettext("Save Gateway"); ?>" onClick='hide_add_gatewaysave();'> 
230
															<input id="gwcancel" type="Button" value="<?=gettext("Cancel"); ?>" onClick='hide_add_gateway();'>
231
														</div>
232
													</center>
233
												</td>
234
											</tr>
235
											<tr><td>&nbsp;</td>
236
										</table>
237
										</td></tr></table>
238
									<p/>
239
								</div>
240
                </tr>
241
		<tr>
242
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
243
                  <td width="78%" class="vtable"> 
244
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
245
                    <br> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)."); ?></span></td>
246
                </tr>
247
                <tr>
248
                  <td width="22%" valign="top">&nbsp;</td>
249
                  <td width="78%"> 
250
                    <input id="save" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input id="cancel" type="button" value="<?=gettext("Cancel"); ?>" class="formbtn"  onclick="history.back()">
251
                    <?php if (isset($id) && $a_routes[$id]): ?>
252
                    <input name="id" type="hidden" value="<?=$id;?>">
253
                    <?php endif; ?>
254
                  </td>
255
                </tr>
256
              </table>
257
</form>
258
<script type="text/javascript">
259
					var gatewayip;
260
					var name;
261
					function show_add_gateway() {
262
						document.getElementById("addgateway").style.display = '';
263
						document.getElementById("addgwbox").style.display = 'none';
264
						document.getElementById("gateway").style.display = 'none';
265
						document.getElementById("save").style.display = 'none';
266
						document.getElementById("cancel").style.display = 'none';
267
						document.getElementById("gwsave").style.display = '';
268
						document.getElementById("gwcancel").style.display = '';
269
						$('notebox').innerHTML="";
270
					}
271
					function hide_add_gateway() {
272
						document.getElementById("addgateway").style.display = 'none';
273
						document.getElementById("addgwbox").style.display = '';	
274
						document.getElementById("gateway").style.display = '';
275
						document.getElementById("save").style.display = '';
276
						document.getElementById("cancel").style.display = '';
277
						document.getElementById("gwsave").style.display = '';
278
						document.getElementById("gwcancel").style.display = '';
279
					}
280
					function hide_add_gatewaysave() {
281
						document.getElementById("addgateway").style.display = 'none';
282
						$('status').innerHTML = '<img src="/themes/metallic/images/misc/loader.gif"> <?=gettext("One moment please..."); ?>';
283
						var iface = $('addinterfacegw').getValue();
284
						name = $('name').getValue();
285
						var descr = $('gatewaydescr').getValue();
286
						gatewayip = $('gatewayip').getValue();
287
						addrtype = $('addrtype').getValue();
288
						var defaultgw = $('defaultgw').getValue();
289
						var url = "system_gateways_edit.php";
290
						var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
291
						var myAjax = new Ajax.Request(
292
							url,
293
							{
294
								method: 'post',
295
								parameters: pars,
296
								onFailure: report_failure,
297
								onComplete: save_callback
298
							});	
299
					}
300
					function addOption(selectbox,text,value)
301
					{
302
						var optn = document.createElement("OPTION");
303
						optn.text = text;
304
						optn.value = value;
305
						selectbox.options.add(optn);
306
						selectbox.selectedIndex = (selectbox.options.length-1);
307
						$('notebox').innerHTML="<p/><strong><?=gettext("NOTE:");?></strong> <?php printf(gettext("You can manage Gateways %shere%s."), "<a target='_new' href='system_gateways.php'>", "</a>");?>
308
					}				
309
					function report_failure() {
310
						alert("<?=gettext("Sorry, we could not create your gateway at this time."); ?>");
311
						hide_add_gateway();
312
					}
313
					function save_callback(transport) {
314
						var response = transport.responseText;
315
						if (response) {
316
							document.getElementById("addgateway").style.display = 'none';
317
							hide_add_gateway();
318
							$('status').innerHTML = '';
319
							addOption($('gateway'), name, name);
320
						} else {
321
							report_failure();
322
						}
323
					}
324
				</script>
325
<?php include("fend.inc"); ?>
326
</body>
327
</html>
(193-193/222)