Project

General

Profile

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