Project

General

Profile

Download (11 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2
/*
3
	interfaces_assign.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	Written by Jim McBeath based on existing m0n0wall files
6
	
7 94a77286 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8 5b237745 Scott Ullrich
	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 94a77286 Scott Ullrich
$pgtitle = array("Interfaces", "Assign network ports");
33 5b237745 Scott Ullrich
require("guiconfig.inc");
34
35
/*
36
	In this file, "port" refers to the physical port name,
37
	while "interface" refers to LAN, WAN, or OPTn.
38
*/
39
40
/* get list without VLAN interfaces */
41
$portlist = get_interface_list();
42
43
/* add VLAN interfaces */
44
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
45
	foreach ($config['vlans']['vlan'] as $vlan) {
46 d59557dc Ermal Luçi
		$portlist[$vlan['vlanif']] = $vlan;
47
		$portlist[$vlan['vlanif']]['isvlan'] = true;
48 5b237745 Scott Ullrich
	}
49
}
50
51 860c4e80 Chris Buechler
/* add PPP interfaces */
52
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
53
	$i = 0;
54
	foreach ($config['ppps']['ppp'] as $ppp) {
55
		$portname = 'ppp_' . basename($ppp['port']);
56
		$portlist[$portname] = $ppp;
57
		$portlist[$portname]['isppp'] = true;
58
		$i++;
59
	}
60
}
61
62 d59557dc Ermal Luçi
if ($_POST['apply']) {
63
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
64
		exec("/etc/rc.reboot");
65
	else {
66
		write_config();
67
68
		$retval = 0;
69
		$savemsg = get_std_save_message($retval);
70
71
		config_lock();
72
		$retval = filter_configure();
73
		config_unlock();
74
75
		if (stristr($retval, "error") <> true)
76
			$savemsg = get_std_save_message($retval);
77
		else
78
			$savemsg = $retval;
79
80 4a166751 Ermal Luçi
		unlink_if_exists("/tmp/reload_interfaces");
81 d59557dc Ermal Luçi
	}
82
83
} else if ($_POST) {
84 5b237745 Scott Ullrich
85
	unset($input_errors);
86
87
	/* input validation */
88
89
	/* Build a list of the port names so we can see how the interfaces map */
90
	$portifmap = array();
91
	foreach ($portlist as $portname => $portinfo)
92
		$portifmap[$portname] = array();
93
94
	/* Go through the list of ports selected by the user,
95
	   build a list of port-to-interface mappings in portifmap */
96
	foreach ($_POST as $ifname => $ifport) {
97
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
98
			$portifmap[$ifport][] = strtoupper($ifname);
99
	}
100
101
	/* Deliver error message for any port with more than one assignment */
102
	foreach ($portifmap as $portname => $ifnames) {
103
		if (count($ifnames) > 1) {
104
			$errstr = "Port " . $portname .
105
				" was assigned to " . count($ifnames) .
106
				" interfaces:";
107
				
108
			foreach ($portifmap[$portname] as $ifn)
109
				$errstr .= " " . $ifn;
110
			
111
			$input_errors[] = $errstr;
112
		}
113
	}
114
115
116
	if (!$input_errors) {
117
		/* No errors detected, so update the config */
118
		foreach ($_POST as $ifname => $ifport) {
119
		
120
			if (($ifname == 'lan') || ($ifname == 'wan') ||
121
				(substr($ifname, 0, 3) == 'opt')) {
122
				
123
				if (!is_array($ifport)) {
124
					$config['interfaces'][$ifname]['if'] = $ifport;
125 860c4e80 Chris Buechler
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
126
						$config['interfaces'][$ifname]['pointtopoint'] = true;
127
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
128
					}
129
130 5b237745 Scott Ullrich
					/* check for wireless interfaces, set or clear ['wireless'] */
131 94a77286 Scott Ullrich
					if (preg_match($g['wireless_regex'], $ifport)) {
132 5b237745 Scott Ullrich
						if (!is_array($config['interfaces'][$ifname]['wireless']))
133
							$config['interfaces'][$ifname]['wireless'] = array();
134
					} else {
135
						unset($config['interfaces'][$ifname]['wireless']);
136
					}
137
					
138 d59557dc Ermal Luçi
					/* make sure there is a descr for all interfaces */
139
					if (!isset($config['interfaces'][$ifname]['descr']))
140
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
141 5b237745 Scott Ullrich
				}
142
			}
143
		}
144
	
145
		write_config();
146 182c30de Scott Ullrich
		
147 d59557dc Ermal Luçi
		touch("/tmp/reload_interfaces");
148 5b237745 Scott Ullrich
	}
149
}
150
151
if ($_GET['act'] == "del") {
152
	$id = $_GET['id'];
153 3c43a344 Scott Ullrich
154
	unset($config['interfaces'][$id]['enable']);
155 f1f60c92 Ermal Luçi
	interface_bring_down($id);   /* down the interface */
156 3c43a344 Scott Ullrich
		
157 bda86e8f Scott Ullrich
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
158 5b237745 Scott Ullrich
159 d59557dc Ermal Luçi
	if($id == "lan") {
160 bda86e8f Scott Ullrich
		unset($config['interfaces']['lan']);
161
		unset($config['dhcpd']['lan']);
162 7385b511 Scott Ullrich
		unset($config['shaper']);
163
		unset($config['ezshaper']);
164 5bf11e36 Scott Ullrich
		unset($config['nat']);
165 f2366cc0 Scott Ullrich
		system("rm /var/dhcpd/var/db/*");
166 d59557dc Ermal Luçi
        	services_dhcpd_configure();
167 5b237745 Scott Ullrich
	}
168
169 c3bc7432 Ermal Luçi
	if ($config['filter']['rule'] > 0)
170
        foreach ($config['filter']['rule'] as $x => $rule) {
171
                        if($rule['interface'] == $id)
172
                                unset($config['filter']['rule'][$x]);
173
        }
174
	if ($config['nat']['advancedoutbound']['rule'] > 0)
175
        foreach ($config['nat']['advancedoutbound']['rule'] as $id => $rule) {
176
                        if($rule['interface'] == $x)
177
                                unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
178
        }
179
        if (count($config['nat']['rule']) > 0) 
180
        foreach ($config['nat']['rule'] as $x => $rule) {
181
                        if($rule['interface'] == $id)
182
                                unset($config['nat']['rule'][$x]['interface']);
183
        }
184
185
186 5b237745 Scott Ullrich
	write_config();
187 21eebbb0 Scott Ullrich
	
188 d59557dc Ermal Luçi
	/* XXX: What is this for?!?! */
189 bda86e8f Scott Ullrich
	if($config['interfaces']['lan']) {
190
		unset($config['dhcpd']['wan']);		
191
	}
192 98a0128c Scott Ullrich
	
193 21eebbb0 Scott Ullrich
	$savemsg = "Interface has been deleted.";
194 5b237745 Scott Ullrich
}
195
196
if ($_GET['act'] == "add") {
197
	/* find next free optional interface number */
198 bda86e8f Scott Ullrich
	if(!$config['interfaces']['lan']) {
199
		$newifname = "lan";
200 0d21552c Scott Ullrich
		$config['interfaces'][$newifname] = array();
201 d59557dc Ermal Luçi
		$config['interfaces'][$newifname]['descr'] = $descr;
202 bda86e8f Scott Ullrich
	} else {
203 d59557dc Ermal Luçi
		$i = 1;
204
                foreach ($config['interfaces'] as $ifname => $if) {
205
                        if ($ifname == "wan" || $ifname == "lan")
206
                                continue;
207
                        if (substr($ifname, 3) == $i) {
208
                                $i++;
209
                                continue;
210
                        }
211
                        break;
212
                }
213 bda86e8f Scott Ullrich
		$newifname = 'opt' . $i;
214 d59557dc Ermal Luçi
		$descr = "OPT{$i}";
215 0d21552c Scott Ullrich
		$config['interfaces'][$newifname] = array();
216 d59557dc Ermal Luçi
		$config['interfaces'][$newifname]['descr'] = $descr;
217
		ksort($config['interfaces']);
218 bda86e8f Scott Ullrich
	}
219 5b237745 Scott Ullrich
	
220
	/* Find an unused port for this interface */
221
	foreach ($portlist as $portname => $portinfo) {
222
		$portused = false;
223
		foreach ($config['interfaces'] as $ifname => $ifdata) {
224
			if ($ifdata['if'] == $portname) {
225
				$portused = true;
226
				break;
227
			}
228
		}
229
		if (!$portused) {
230
			$config['interfaces'][$newifname]['if'] = $portname;
231 94a77286 Scott Ullrich
			if (preg_match($g['wireless_regex'], $portname))
232 5b237745 Scott Ullrich
				$config['interfaces'][$newifname]['wireless'] = array();
233
			break;
234
		}
235
	}
236
	
237 d59557dc Ermal Luçi
        /* XXX: Do not remove this. */
238
        mwexec("rm -f /tmp/config.cache");
239
240 5b237745 Scott Ullrich
	write_config();
241 093a01b0 Scott Ullrich
242 21eebbb0 Scott Ullrich
	$savemsg = "Interface has been added.";
243
244 5b237745 Scott Ullrich
}
245
246 7f43ca88 Scott Ullrich
include("head.inc");
247
248 23be6f1b Scott Ullrich
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
249 d59557dc Ermal Luçi
	if ($_POST)
250
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
251 c35e12af Scott Ullrich
	else
252 00404818 Chris Buechler
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
253 23be6f1b Scott Ullrich
254 5b237745 Scott Ullrich
?>
255 6eb47218 Scott Ullrich
256
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
257 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
258
<?php if ($input_errors) print_input_errors($input_errors); ?>
259 2e506568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
260 a2dab9bc Bill Marquette
261 5b237745 Scott Ullrich
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
262 d59557dc Ermal Luçi
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
263
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
264
 the changes in order for them to take effect.");?><br>
265
<?php endif; ?>
266
267 5b237745 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
268 94a77286 Scott Ullrich
  <tr><td class="tabnavtbl">
269 c8b8ff69 Scott Ullrich
<?php
270
	$tab_array = array();
271 931066a8 Bill Marquette
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
272
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
273 860c4e80 Chris Buechler
	$tab_array[2] = array("PPP", false, "interfaces_ppp.php");
274 f1f60c92 Ermal Luçi
	$tab_array[3] = array("Bridges", false, "interfaces_bridges.php");
275 c8b8ff69 Scott Ullrich
	display_top_tabs($tab_array);
276
?>  
277 5b237745 Scott Ullrich
  </td></tr>
278
  <tr> 
279 d732f186 Bill Marquette
    <td>
280
	<div id="mainarea">
281
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
282
       <tr> 
283 5b237745 Scott Ullrich
	<td class="listhdrr">Interface</td>
284
	<td class="listhdr">Network port</td>
285
	<td class="list">&nbsp;</td>
286
  </tr>
287
  <?php foreach ($config['interfaces'] as $ifname => $iface):
288
  	if ($iface['descr'])
289
		$ifdescr = $iface['descr'];
290
	else
291
		$ifdescr = strtoupper($ifname);
292
	?>
293
  <tr> 
294
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
295
	  <td valign="middle" class="listr">
296 d59557dc Ermal Luçi
		<select name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
297 5b237745 Scott Ullrich
		  <?php foreach ($portlist as $portname => $portinfo): ?>
298
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
299
		  <?php if ($portinfo['isvlan']) {
300
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
301
					if ($portinfo['descr'])
302
						$descr .= " (" . $portinfo['descr'] . ")";
303
					echo htmlspecialchars($descr);
304 860c4e80 Chris Buechler
				} elseif ($portinfo['isppp']) {
305
					$descr = "PPP {$portinfo['port']}";
306
					if ($portinfo['descr'])
307
						$descr .= " (" . $portinfo['descr'] . ")";
308
					echo htmlspecialchars($descr);
309 5b237745 Scott Ullrich
				  } else
310
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
311
		  ?>
312
		  </option>
313
		  <?php endforeach; ?>
314
		</select>
315
		</td>
316
		<td valign="middle" class="list"> 
317 b0d756ba Scott Ullrich
		  <?php if ($ifname != 'wan'): ?>
318 677c0869 Erik Kristensen
		  <a href="interfaces_assign.php?act=del&id=<?=$ifname;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete interface" width="17" height="17" border="0"></a> 
319 5b237745 Scott Ullrich
		  <?php endif; ?>
320
		</td>
321
  </tr>
322
  <?php endforeach; ?>
323
  <?php if (count($config['interfaces']) < count($portlist)): ?>
324
  <tr>
325
	<td class="list" colspan="2"></td>
326
	<td class="list" nowrap>
327 677c0869 Erik Kristensen
	<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add interface" width="17" height="17" border="0"></a>
328 5b237745 Scott Ullrich
	</td>
329
  </tr>
330
  <?php else: ?>
331
  <tr>
332
	<td class="list" colspan="3" height="10"></td>
333
  </tr>
334
  <?php endif; ?>
335
</table>
336 d732f186 Bill Marquette
</div>
337 0d21552c Scott Ullrich
<br/>
338
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
339 56afcab6 Scott Ullrich
<p>
340 bd705fb8 Scott Ullrich
</p>
341 94a77286 Scott Ullrich
<ul>
342
  <li><span class="vexpl">change the IP address of your computer</span></li>
343
  <li><span class="vexpl">renew its DHCP lease</span></li>
344 709cc6e0 Bill Marquette
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
345 94a77286 Scott Ullrich
</ul></td>
346 5b237745 Scott Ullrich
	</tr>
347
</table>
348
</form>
349
<?php include("fend.inc"); ?>
350 c8b8ff69 Scott Ullrich
</body>
351
</html>