Project

General

Profile

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