Project

General

Profile

Download (7.13 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	system_routes_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34

    
35
if (!is_array($config['staticroutes']['route']))
36
	$config['staticroutes']['route'] = array();
37

    
38
staticroutes_sort();
39
$a_routes = &$config['staticroutes']['route'];
40

    
41
$id = $_GET['id'];
42
if (isset($_POST['id']))
43
	$id = $_POST['id'];
44

    
45
if (isset($id) && $a_routes[$id]) {
46
	$pconfig['interface'] = $a_routes[$id]['interface'];
47
	list($pconfig['network'],$pconfig['network_subnet']) = 
48
		explode('/', $a_routes[$id]['network']);
49
	$pconfig['gateway'] = $a_routes[$id]['gateway'];
50
	$pconfig['descr'] = $a_routes[$id]['descr'];
51
}
52

    
53
if ($_POST) {
54

    
55
	unset($input_errors);
56
	$pconfig = $_POST;
57

    
58
	/* input validation */
59
	$reqdfields = explode(" ", "interface network network_subnet gateway");
60
	$reqdfieldsn = explode(",", "Interface,Destination network,Destination network bit count,Gateway");
61
	
62
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
63
	
64
	if (($_POST['network'] && !is_ipaddr($_POST['network']))) {
65
		$input_errors[] = "A valid destination network must be specified.";
66
	}
67
	if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) {
68
		$input_errors[] = "A valid destination network bit count must be specified.";
69
	}
70
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
71
		$input_errors[] = "A valid gateway IP address must be specified.";
72
	}
73

    
74
	/* check for overlaps */
75
	$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
76
	foreach ($a_routes as $route) {
77
		if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route))
78
			continue;
79

    
80
		if ($route['network'] == $osn) {
81
			$input_errors[] = "A route to this destination network already exists.";
82
			break;
83
		}
84
	}
85

    
86
	if (!$input_errors) {
87
		$route = array();
88
		$route['interface'] = $_POST['interface'];
89
		$route['network'] = $osn;
90
		$route['gateway'] = $_POST['gateway'];
91
		$route['descr'] = $_POST['descr'];
92

    
93
		if (isset($id) && $a_routes[$id])
94
			$a_routes[$id] = $route;
95
		else
96
			$a_routes[] = $route;
97
		
98
		touch($d_staticroutesdirty_path);
99
		
100
		write_config();
101
		
102
		header("Location: system_routes.php");
103
		exit;
104
	}
105
}
106
?>
107
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
108
<html>
109
<head>
110
<title><?=gentitle("System: Static routes: Edit route");?></title>
111
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
112
<link href="gui.css" rel="stylesheet" type="text/css">
113
</head>
114

    
115
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
116
<?php include("fbegin.inc"); ?>
117
<p class="pgtitle">System: Static routes: Edit route</p>
118
<?php if ($input_errors) print_input_errors($input_errors); ?>
119
            <form action="system_routes_edit.php" method="post" name="iform" id="iform">
120
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
121
                <tr> 
122
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
123
                  <td width="78%" class="vtable">
124
<select name="interface" class="formfld">
125
                      <?php $interfaces = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
126
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
127
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
128
					  }
129
					  foreach ($interfaces as $iface => $ifacename): ?>
130
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
131
                      <?=htmlspecialchars($ifacename);?>
132
                      </option>
133
                      <?php endforeach; ?>
134
                    </select> <br>
135
                    <span class="vexpl">Choose which interface this route applies to.</span></td>
136
                </tr>
137
                <tr>
138
                  <td width="22%" valign="top" class="vncellreq">Destination network</td>
139
                  <td width="78%" class="vtable"> 
140
                    <input name="network" type="text" class="formfld" id="network" size="20" value="<?=htmlspecialchars($pconfig['network']);?>"> 
141
				  / 
142
                    <select name="network_subnet" class="formfld" id="network_subnet">
143
                      <?php for ($i = 32; $i >= 1; $i--): ?>
144
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['network_subnet']) echo "selected"; ?>>
145
                      <?=$i;?>
146
                      </option>
147
                      <?php endfor; ?>
148
                    </select>
149
                    <br> <span class="vexpl">Destination network for this static route</span></td>
150
                </tr>
151
				<tr>
152
                  <td width="22%" valign="top" class="vncellreq">Gateway</td>
153
                  <td width="78%" class="vtable"> 
154
                    <input name="gateway" type="text" class="formfld" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
155
                    <br> <span class="vexpl">Gateway to be used to reach the destination network</span></td>
156
                </tr>
157
				<tr>
158
                  <td width="22%" valign="top" class="vncell">Description</td>
159
                  <td width="78%" class="vtable"> 
160
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
161
                    <br> <span class="vexpl">You may enter a description here
162
                    for your reference (not parsed).</span></td>
163
                </tr>
164
                <tr>
165
                  <td width="22%" valign="top">&nbsp;</td>
166
                  <td width="78%"> 
167
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" class="formbtn"  onclick="history.back()">
168
                    <?php if (isset($id) && $a_routes[$id]): ?>
169
                    <input name="id" type="hidden" value="<?=$id;?>">
170
                    <?php endif; ?>
171
                  </td>
172
                </tr>
173
              </table>
174
</form>
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>
(102-102/117)