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