Project

General

Profile

Download (14.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
	Copyright (C) 2003-2005 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
##|+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
$pgtitle = array("Interfaces", "Assign network ports");
40
require("guiconfig.inc");
41

    
42
/*
43
	In this file, "port" refers to the physical port name,
44
	while "interface" refers to LAN, WAN, or OPTn.
45
*/
46

    
47
/* get list without VLAN interfaces */
48
$portlist = get_interface_list();
49

    
50
/* add VLAN interfaces */
51
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
52
	foreach ($config['vlans']['vlan'] as $vlan) {
53
		$portlist[$vlan['vlanif']] = $vlan;
54
		$portlist[$vlan['vlanif']]['isvlan'] = true;
55
	}
56
}
57

    
58
/* add Bridge interfaces */
59
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
60
        foreach ($config['bridges']['bridged'] as $bridge) {
61
                $portlist[$bridge['bridgeif']] = $bridge;
62
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
63
        }
64
}
65

    
66
/* add GIF interfaces */
67
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
68
        foreach ($config['gifs']['gif'] as $gif) {
69
                $portlist[$gif['gifif']] = $gif;
70
                $portlist[$gif['gifif']]['isgif'] = true;
71
        }
72
}
73

    
74
/* add GRE interfaces */
75
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
76
        foreach ($config['gres']['gre'] as $gre) {
77
                $portlist[$gre['greif']] = $gre;
78
                $portlist[$gre['greif']]['isgre'] = true;
79
        }
80
}
81

    
82
/* add LAGG interfaces */
83
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
84
        foreach ($config['laggs']['lagg'] as $lagg) {
85
                $portlist[$lagg['laggif']] = $lagg;
86
                $portlist[$lagg['laggif']]['islagg'] = true;
87
		/* LAGG members cannot be assigned */
88
		$lagifs = explode(',', $lagg['members']);
89
		foreach ($lagifs as $lagif)
90
			if (isset($portlist[$lagif]))
91
				unset($portlist[$lagif]);
92
        }
93
}
94

    
95
/* add QinQ interfaces */
96
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
97
        foreach ($config['qinqs']['qinqentry'] as $qinq) {
98
                $portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
99
                $portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
100
                /* QinQ members */
101
                $qinqifs = explode(' ', $qinq['members']);
102
                foreach ($qinqifs as $qinqif) {
103
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
104
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
105
		}
106
        }
107
}
108

    
109
/* add PPP interfaces */
110
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
111
	$i = 0;
112
	foreach ($config['ppps']['ppp'] as $ppp) {
113
		$portname = 'ppp_' . basename($ppp['port']);
114
		$portlist[$portname] = $ppp;
115
		$portlist[$portname]['isppp'] = true;
116
		$i++;
117
	}
118
}
119

    
120
if ($_POST['apply']) {
121
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
122
		exec("/etc/rc.reboot");
123
	else {
124
		write_config();
125

    
126
		$retval = 0;
127
		$retval = filter_configure();
128
		$savemsg = get_std_save_message($retval);
129

    
130
		if (stristr($retval, "error") <> true)
131
			$savemsg = get_std_save_message($retval);
132
		else
133
			$savemsg = $retval;
134

    
135
		unlink_if_exists("/tmp/reload_interfaces");
136
	}
137

    
138
} else if ($_POST) {
139

    
140
	unset($input_errors);
141

    
142
	/* input validation */
143

    
144
	/* Build a list of the port names so we can see how the interfaces map */
145
	$portifmap = array();
146
	foreach ($portlist as $portname => $portinfo)
147
		$portifmap[$portname] = array();
148

    
149
	/* Go through the list of ports selected by the user,
150
	   build a list of port-to-interface mappings in portifmap */
151
	foreach ($_POST as $ifname => $ifport) {
152
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
153
			$portifmap[$ifport][] = strtoupper($ifname);
154
	}
155

    
156
	/* Deliver error message for any port with more than one assignment */
157
	foreach ($portifmap as $portname => $ifnames) {
158
		if (count($ifnames) > 1) {
159
			$errstr = "Port " . $portname .
160
				" was assigned to " . count($ifnames) .
161
				" interfaces:";
162
				
163
			foreach ($portifmap[$portname] as $ifn)
164
				$errstr .= " " . $ifn;
165
			
166
			$input_errors[] = $errstr;
167
		}
168
	}
169

    
170

    
171
	if (!$input_errors) {
172
		/* No errors detected, so update the config */
173
		foreach ($_POST as $ifname => $ifport) {
174
		
175
			if (($ifname == 'lan') || ($ifname == 'wan') ||
176
				(substr($ifname, 0, 3) == 'opt')) {
177
				
178
				if (!is_array($ifport)) {
179
					$config['interfaces'][$ifname]['if'] = $ifport;
180
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
181
						$config['interfaces'][$ifname]['pointtopoint'] = true;
182
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
183
					}
184

    
185
					/* check for wireless interfaces, set or clear ['wireless'] */
186
					if (preg_match($g['wireless_regex'], $ifport)) {
187
						if (!is_array($config['interfaces'][$ifname]['wireless']))
188
							$config['interfaces'][$ifname]['wireless'] = array();
189
					} else {
190
						unset($config['interfaces'][$ifname]['wireless']);
191
					}
192
					
193
					/* make sure there is a descr for all interfaces */
194
					if (!isset($config['interfaces'][$ifname]['descr']))
195
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
196
				}
197
			}
198
		}
199
	
200
		write_config();
201
		
202
		touch("/tmp/reload_interfaces");
203
	}
204
}
205

    
206
if ($_GET['act'] == "del") {
207
	$id = $_GET['id'];
208

    
209
	if (link_interface_to_bridge($id))
210
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
211
	else if (link_interface_to_gre($id))
212
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
213
	else if (link_interface_to_gif($id))
214
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
215
	else {
216
		unset($config['interfaces'][$id]['enable']);
217
		interface_bring_down($id);   /* down the interface */
218
		
219
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
220

    
221
		if($id == "lan") {
222
			unset($config['interfaces']['lan']);
223
			if (is_array($config['dhcpd']))
224
				unset($config['dhcpd']['lan']);
225
				unset($config['shaper']);
226
				unset($config['ezshaper']);
227
				unset($config['nat']);
228
				system("rm /var/dhcpd/var/db/*");
229
        			services_dhcpd_configure();
230
		}
231

    
232
		if ($config['filter']['rule'] > 0)
233
       	 	foreach ($config['filter']['rule'] as $x => $rule) {
234
                	        if($rule['interface'] == $id)
235
               		                 unset($config['filter']['rule'][$x]);
236
        	}
237
		if ($config['nat']['advancedoutbound']['rule'] > 0)
238
        	foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
239
                	        if($rule['interface'] == $id)
240
           	    	                 unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
241
        	}
242
        	if (count($config['nat']['rule']) > 0) 
243
        	foreach ($config['nat']['rule'] as $x => $rule) {
244
                        	if($rule['interface'] == $id)
245
                	                unset($config['nat']['rule'][$x]['interface']);
246
        	}
247

    
248
		write_config();
249
	
250
		/* XXX: What is this for?!?! */
251
		if($config['interfaces']['lan']) {
252
			unset($config['dhcpd']['wan']);		
253
		}
254
	
255
		$savemsg = "Interface has been deleted.";
256
	}
257
}
258

    
259
if ($_GET['act'] == "add") {
260
	/* find next free optional interface number */
261
	if(!$config['interfaces']['lan']) {
262
		$newifname = "lan";
263
		$config['interfaces'][$newifname] = array();
264
		$config['interfaces'][$newifname]['descr'] = $descr;
265
	} else {
266
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
267
			if (!$config['interfaces']["opt{$i}"])
268
				break;
269
		}
270
		$newifname = 'opt' . $i;
271
		$descr = "OPT{$i}";
272
		$config['interfaces'][$newifname] = array();
273
		$config['interfaces'][$newifname]['descr'] = $descr;
274
		ksort($config['interfaces']);
275
	}
276
	
277
	/* Find an unused port for this interface */
278
	foreach ($portlist as $portname => $portinfo) {
279
		$portused = false;
280
		foreach ($config['interfaces'] as $ifname => $ifdata) {
281
			if ($ifdata['if'] == $portname) {
282
				$portused = true;
283
				break;
284
			}
285
		}
286
		if (!$portused) {
287
			$config['interfaces'][$newifname]['if'] = $portname;
288
			if (preg_match($g['wireless_regex'], $portname))
289
				$config['interfaces'][$newifname]['wireless'] = array();
290
			break;
291
		}
292
	}
293
	
294
        /* XXX: Do not remove this. */
295
        mwexec("rm -f /tmp/config.cache");
296

    
297
	write_config();
298

    
299
	$savemsg = "Interface has been added.";
300

    
301
}
302

    
303
include("head.inc");
304

    
305
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
306
	if ($_POST)
307
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
308
	else
309
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
310

    
311
?>
312

    
313
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
314
<?php include("fbegin.inc"); ?>
315

    
316
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
317

    
318
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
319
	<?php print_info_box_np("The interface configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
320
<?php elseif($savemsg): ?>
321
	<?php print_info_box($savemsg); ?>
322
<?php endif; ?>
323

    
324
<?php if ($input_errors) print_input_errors($input_errors); ?>
325

    
326
<table width="100%" border="0" cellpadding="0" cellspacing="0">
327
  <tr><td class="tabnavtbl">
328
<?php
329
	$tab_array = array();
330
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
331
	$tab_array[1] = array("Interface Groups", false, "interfaces_groups.php");
332
	$tab_array[2] = array("VLANs", false, "interfaces_vlan.php");
333
	$tab_array[3] = array("QinQs", false, "interfaces_qinq.php");
334
	$tab_array[4] = array("PPP", false, "interfaces_ppp.php");
335
        $tab_array[5] = array("GRE", false, "interfaces_gre.php");
336
        $tab_array[6] = array("GIF", false, "interfaces_gif.php");
337
	$tab_array[7] = array("Bridges", false, "interfaces_bridge.php");
338
	$tab_array[8] = array("LAGG", false, "interfaces_lagg.php");
339
	display_top_tabs($tab_array);
340
?>  
341
  </td></tr>
342
  <tr> 
343
    <td>
344
	<div id="mainarea">
345
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
346
       <tr> 
347
	<td class="listhdrr">Interface</td>
348
	<td class="listhdr">Network port</td>
349
	<td class="list">&nbsp;</td>
350
  </tr>
351
  <?php foreach ($config['interfaces'] as $ifname => $iface):
352
  	if ($iface['descr'])
353
		$ifdescr = $iface['descr'];
354
	else
355
		$ifdescr = strtoupper($ifname);
356
	?>
357
  <tr> 
358
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
359
	  <td valign="middle" class="listr">
360
		<select name="<?=$ifname;?>" id="<?=$ifname;?>">
361
		  <?php foreach ($portlist as $portname => $portinfo): ?>
362
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
363
		  <?php if ($portinfo['isvlan']) {
364
			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
365
		if ($portinfo['descr'])
366
			$descr .= " (" . $portinfo['descr'] . ")";
367
			echo htmlspecialchars($descr);
368
		} elseif ($portinfo['isppp']) {
369
			$descr = "PPP {$portinfo['port']}";
370
			if ($portinfo['descr'])
371
				$descr .= " (" . $portinfo['descr'] . ")";
372
			echo htmlspecialchars($descr);
373
                } elseif ($portinfo['isbridge']) {
374
                        $descr = strtoupper($portinfo['bridgeif']);
375
                        if ($portinfo['descr'])
376
				$descr .= " (" . $portinfo['descr'] . ")";
377
                        echo htmlspecialchars($descr);
378
                } elseif ($portinfo['isgre']) {
379
                        $descr = "GRE {$portinfo['remote-addr']}";
380
                        if ($portinfo['descr'])
381
				$descr .= " (" . $portinfo['descr'] . ")";
382
                        echo htmlspecialchars($descr);
383
                } elseif ($portinfo['isgif']) {
384
                        $descr = "GRE {$portinfo['remote-addr']}";
385
                        if ($portinfo['descr'])
386
				$descr .= " (" . $portinfo['descr'] . ")";
387
                        echo htmlspecialchars($descr);
388
                } elseif ($portinfo['islagg']) {
389
                        $descr = strtoupper($portinfo['laggif']);
390
                        if ($portinfo['descr'])
391
				$descr .= " (" . $portinfo['descr'] . ")";
392
                        echo htmlspecialchars($descr);
393
		} elseif ($portinfo['isqinq']) {
394
			echo htmlspecialchars($portinfo['descr']);
395
		} else
396
			echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
397
		?>
398
		</option>
399
		<?php endforeach; ?>
400
	</select>
401
	</td>
402
	<td valign="middle" class="list">
403
		  <?php if ($ifname != 'wan'): ?>
404
		  <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> 
405
		  <?php endif; ?>
406
		</td>
407
  </tr>
408
  <?php endforeach; ?>
409
  <?php if (count($config['interfaces']) < count($portlist)): ?>
410
  <tr>
411
	<td class="list" colspan="2"></td>
412
	<td class="list" nowrap>
413
	<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>
414
	</td>
415
  </tr>
416
  <?php else: ?>
417
  <tr>
418
	<td class="list" colspan="3" height="10"></td>
419
  </tr>
420
  <?php endif; ?>
421
</table>
422
</div>
423
<br/>
424
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
425
<p>
426
</p>
427
<ul>
428
  <li><span class="vexpl">change the IP address of your computer</span></li>
429
  <li><span class="vexpl">renew its DHCP lease</span></li>
430
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
431
  <li><span class="vexpl">interfaces that are configured as members of a lagg(4) interface will not be shown.</span></li>
432
</ul></td>
433
	</tr>
434
</table>
435
</form>
436
<?php include("fend.inc"); ?>
437
</body>
438
</html>
(79-79/217)