Project

General

Profile

Download (6.55 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 39cf364d Bill Marquette
$pgtitle = "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 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
129 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
130
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
131
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
132
                <tr>
133
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
134
                  <td width="78%" class="vtable"> 
135 b5c78501 Seth Mos
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
136 5b237745 Scott Ullrich
				  / 
137 b5c78501 Seth Mos
                    <select name="network_subnet" class="formselect" id="network_subnet">
138 5b237745 Scott Ullrich
                      <?php for ($i = 32; $i >= 1; $i--): ?>
139
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
140
                      <?=$i;?>
141
                      </option>
142
                      <?php endfor; ?>
143
                    </select>
144
                    <br> <span class="vexpl">Destination network for this static route</span></td>
145
                </tr>
146 d173230c Seth Mos
                <tr> 
147 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
148 d173230c Seth Mos
                  <td width="78%" class="vtable">
149
			<select name="gateway" class="formselect">
150
			<?php
151
				foreach ($a_gateways as $gateway): ?>
152
	                      <option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>> 
153
	                      <?=htmlspecialchars($gateway['name']);?>
154
                      </option>
155
                      <?php endforeach; ?>
156
                    </select> <br>
157
                    <span class="vexpl">Choose which gateway this route applies to.</span></td>
158 5b237745 Scott Ullrich
                </tr>
159 d173230c Seth Mos
		<tr>
160 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
161
                  <td width="78%" class="vtable"> 
162 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
163 5b237745 Scott Ullrich
                    <br> <span class="vexpl">You may enter a description here
164
                    for your reference (not parsed).</span></td>
165
                </tr>
166
                <tr>
167
                  <td width="22%" valign="top">&nbsp;</td>
168
                  <td width="78%"> 
169 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
170 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_routes[$id]): ?>
171
                    <input name="id" type="hidden" value="<?=$id;?>">
172
                    <?php endif; ?>
173
                  </td>
174
                </tr>
175
              </table>
176
</form>
177
<?php include("fend.inc"); ?>
178 fef3a8ef Scott Ullrich
<script language="JavaScript">
179
	enable_change();
180
</script>
181 5b237745 Scott Ullrich
</body>
182
</html>