Project

General

Profile

Download (12.2 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
if (!is_array($config['gateways']['gateway_item']))
61
	$config['gateways']['gateway_item'] = array();
62

    
63
staticroutes_sort();
64
$a_routes = &$config['staticroutes']['route'];
65
$a_gateways = &$config['gateways']['gateway_item'];
66

    
67
$id = $_GET['id'];
68
if (isset($_POST['id']))
69
	$id = $_POST['id'];
70

    
71
if (isset($_GET['dup'])) {
72
	$id = $_GET['dup'];
73
}
74

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

    
82
if (isset($_GET['dup']))
83
	unset($id);
84

    
85
if ($_POST) {
86

    
87
	unset($input_errors);
88
	$pconfig = $_POST;
89

    
90
	/* input validation */
91
	$reqdfields = explode(" ", "network network_subnet gateway");
92
	$reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway");		
93
	
94
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
95
	
96
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
97
		$input_errors[] = "A valid destination network must be specified.";
98
	}
99
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
100
		$input_errors[] = "A valid destination network bit count must be specified.";
101
	}
102
	if ($_POST['gateway']) {
103
		$match = false;
104
		foreach($a_gateways as $gateway) {
105
			if(in_array($_POST['gateway'], $gateway)) {
106
				$match = true;
107
			}
108
		}
109
		if(!$match)
110
			$input_errors[] = "A valid gateway must be specified.";
111
	}
112

    
113
	/* check for overlaps */
114
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
115
	foreach ($a_routes as $route) {
116
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
117
			continue;
118

    
119
		if ($route['network'] == $osn) {
120
			$input_errors[] = "A route to this destination network already exists.";
121
			break;
122
		}
123
	}
124

    
125
	if (!$input_errors) {
126
		$route = array();
127
		$route['network'] = $osn;
128
		$route['gateway'] = $_POST['gateway'];
129
		$route['descr'] = $_POST['descr'];
130

    
131
		staticroutes_sort();
132
		if (isset($id) && $a_routes[$id])
133
			$a_routes[$id] = $route;
134
		else
135
			$a_routes[] = $route;
136
		
137
		mark_subsystem_dirty('staticroutes');
138
		
139
		write_config();
140
		
141
		header("Location: system_routes.php");
142
		exit;
143
	}
144
}
145

    
146
$pgtitle = array("System","Static Routes","Edit route");
147
include("head.inc");
148

    
149
?>
150

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