Project

General

Profile

Download (7.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
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
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+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
function staticroutecmp($a, $b) {
43
	return strcmp($a['network'], $b['network']);
44
}
45

    
46
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

    
55
require("guiconfig.inc");
56

    
57
if (!is_array($config['staticroutes']['route']))
58
	$config['staticroutes']['route'] = array();
59
if (!is_array($config['gateways']['gateway_item']))
60
	$config['gateways']['gateway_item'] = array();
61

    
62
staticroutes_sort();
63
$a_routes = &$config['staticroutes']['route'];
64
$a_gateways = &$config['gateways']['gateway_item'];
65

    
66
$id = $_GET['id'];
67
if (isset($_POST['id']))
68
	$id = $_POST['id'];
69

    
70
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
}
73

    
74
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
if (isset($_GET['dup']))
82
	unset($id);
83

    
84
if ($_POST) {
85

    
86
	unset($input_errors);
87
	$pconfig = $_POST;
88

    
89
	/* input validation */
90
	$reqdfields = explode(" ", "network network_subnet gateway");
91
	$reqdfieldsn = explode(",", "Destination network,Destination network bit count,Gateway");		
92
	
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
	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
	}
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
		staticroutes_sort();
131
		if (isset($id) && $a_routes[$id])
132
			$a_routes[$id] = $route;
133
		else
134
			$a_routes[] = $route;
135
		
136
		mark_subsystem_dirty('staticroutes');
137
		
138
		write_config();
139
		
140
		header("Location: system_routes.php");
141
		exit;
142
	}
143
}
144

    
145
$pgtitle = array("System","Static Routes","Edit route");
146
include("head.inc");
147

    
148
?>
149

    
150
<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
				<tr>
156
					<td colspan="2" valign="top" class="listtopic">Edit route entry</td>
157
				</tr>	
158
                <tr>
159
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
160
                  <td width="78%" class="vtable"> 
161
                    <input name="network" type="text" class="formfld unknown" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
162
				  / 
163
                    <select name="network_subnet" class="formselect" id="network_subnet">
164
                      <?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
                <tr> 
173
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
174
                  <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
                </tr>
185
		<tr>
186
                  <td width="22%" valign="top" class="vncell">Description</td>
187
                  <td width="78%" class="vtable"> 
188
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
189
                    <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
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
196
                    <?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
<script language="JavaScript">
205
	enable_change();
206
</script>
207
</body>
208
</html>
(187-187/214)