Project

General

Profile

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