Project

General

Profile

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