Project

General

Profile

Download (7.17 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
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
	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 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	routing
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-system-staticroutes-editroute
37
##|*NAME=System: Static Routes: Edit route page
38
##|*DESCR=Allow access to the 'System: Static Routes: Edit route' page.
39
##|*MATCH=system_routes_edit.php*
40
##|-PRIV
41
42 4504a769 Ermal Lu?i
function staticroutecmp($a, $b) {
43
	return strcmp($a['network'], $b['network']);
44
}
45
46 0d64af59 Ermal Lu?i
function staticroutes_sort() {
47
        global $g, $config;
48
49
        if (!is_array($config['staticroutes']['route']))
50
                return;
51
52
        usort($config['staticroutes']['route'], "staticroutecmp");
53
}
54 6b07c15a Matthew Grooms
55 5b237745 Scott Ullrich
require("guiconfig.inc");
56
57
if (!is_array($config['staticroutes']['route']))
58
	$config['staticroutes']['route'] = array();
59 d173230c Seth Mos
if (!is_array($config['gateways']['gateway_item']))
60
	$config['gateways']['gateway_item'] = array();
61 5b237745 Scott Ullrich
62
staticroutes_sort();
63
$a_routes = &$config['staticroutes']['route'];
64 d173230c Seth Mos
$a_gateways = &$config['gateways']['gateway_item'];
65 5b237745 Scott Ullrich
66
$id = $_GET['id'];
67
if (isset($_POST['id']))
68
	$id = $_POST['id'];
69
70 18f7352b Seth Mos
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
}
73
74 5b237745 Scott Ullrich
if (isset($id) && $a_routes[$id]) {
75
	list($pconfig['network'],$pconfig['network_subnet']) = 
76
		explode('/', $a_routes[$id]['network']);
77
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
78
	$pconfig['descr'] = $a_routes[$id]['descr'];
79
}
80
81 18f7352b Seth Mos
if (isset($_GET['dup']))
82
	unset($id);
83
84 5b237745 Scott Ullrich
if ($_POST) {
85
86
	unset($input_errors);
87
	$pconfig = $_POST;
88
89
	/* input validation */
90 d173230c Seth Mos
	$reqdfields = explode(" ", "network network_subnet gateway");
91
	$reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway");		
92 5b237745 Scott Ullrich
	
93
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
94
	
95
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
96
		$input_errors[] = "A valid destination network must be specified.";
97
	}
98
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
99
		$input_errors[] = "A valid destination network bit count must be specified.";
100
	}
101 d173230c Seth Mos
	if ($_POST['gateway']) {
102
		$match = false;
103
		foreach($a_gateways as $gateway) {
104
			if(in_array($_POST['gateway'], $gateway)) {
105
				$match = true;
106
			}
107
		}
108
		if(!$match)
109
			$input_errors[] = "A valid gateway must be specified.";
110 5b237745 Scott Ullrich
	}
111
112
	/* check for overlaps */
113
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
114
	foreach ($a_routes as $route) {
115
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
116
			continue;
117
118
		if ($route['network'] == $osn) {
119
			$input_errors[] = "A route to this destination network already exists.";
120
			break;
121
		}
122
	}
123
124
	if (!$input_errors) {
125
		$route = array();
126
		$route['network'] = $osn;
127
		$route['gateway'] = $_POST['gateway'];
128
		$route['descr'] = $_POST['descr'];
129
130 0d64af59 Ermal Lu?i
		staticroutes_sort();
131 5b237745 Scott Ullrich
		if (isset($id) && $a_routes[$id])
132
			$a_routes[$id] = $route;
133
		else
134
			$a_routes[] = $route;
135
		
136 a368a026 Ermal Lu?i
		mark_subsystem_dirty('staticroutes');
137 5b237745 Scott Ullrich
		
138
		write_config();
139
		
140
		header("Location: system_routes.php");
141
		exit;
142
	}
143
}
144 4df96eff Scott Ullrich
145 d88c6a9f Scott Ullrich
$pgtitle = array("System","Static Routes","Edit route");
146 4df96eff Scott Ullrich
include("head.inc");
147
148 5b237745 Scott Ullrich
?>
149 4df96eff Scott Ullrich
150 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
151
<?php include("fbegin.inc"); ?>
152
<?php if ($input_errors) print_input_errors($input_errors); ?>
153
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
154
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
155 0cece4a2 Scott Ullrich
				<tr>
156
					<td colspan="2" valign="top" class="listtopic">Edit route entry</td>
157
				</tr>	
158 5b237745 Scott Ullrich
                <tr>
159
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
160
                  <td width="78%" class="vtable"> 
161 b5c78501 Seth Mos
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
162 5b237745 Scott Ullrich
				  / 
163 b5c78501 Seth Mos
                    <select name="network_subnet" class="formselect" id="network_subnet">
164 5b237745 Scott Ullrich
                      <?php for ($i = 32; $i >= 1; $i--): ?>
165
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
166
                      <?=$i;?>
167
                      </option>
168
                      <?php endfor; ?>
169
                    </select>
170
                    <br> <span class="vexpl">Destination network for this static route</span></td>
171
                </tr>
172 d173230c Seth Mos
                <tr> 
173 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
174 d173230c Seth Mos
                  <td width="78%" class="vtable">
175
			<select name="gateway" class="formselect">
176
			<?php
177
				foreach ($a_gateways as $gateway): ?>
178
	                      <option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>> 
179
	                      <?=htmlspecialchars($gateway['name']);?>
180
                      </option>
181
                      <?php endforeach; ?>
182
                    </select> <br>
183
                    <span class="vexpl">Choose which gateway this route applies to.</span></td>
184 5b237745 Scott Ullrich
                </tr>
185 d173230c Seth Mos
		<tr>
186 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
187
                  <td width="78%" class="vtable"> 
188 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
189 5b237745 Scott Ullrich
                    <br> <span class="vexpl">You may enter a description here
190
                    for your reference (not parsed).</span></td>
191
                </tr>
192
                <tr>
193
                  <td width="22%" valign="top">&nbsp;</td>
194
                  <td width="78%"> 
195 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
196 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_routes[$id]): ?>
197
                    <input name="id" type="hidden" value="<?=$id;?>">
198
                    <?php endif; ?>
199
                  </td>
200
                </tr>
201
              </table>
202
</form>
203
<?php include("fend.inc"); ?>
204 fef3a8ef Scott Ullrich
<script language="JavaScript">
205
	enable_change();
206
</script>
207 5b237745 Scott Ullrich
</body>
208
</html>