Project

General

Profile

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