Project

General

Profile

Download (14.4 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

    
96
/* add PPP interfaces */
97
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
98
	$i = 0;
99
	foreach ($config['ppps']['ppp'] as $ppp) {
100
		$portname = 'ppp_' . basename($ppp['port']);
101
		$portlist[$portname] = $ppp;
102
		$portlist[$portname]['isppp'] = true;
103
		$i++;
104
	}
105
}
106

    
107
if ($_POST['apply']) {
108
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
109
		exec("/etc/rc.reboot");
110
	else {
111
		write_config();
112

    
113
		$retval = 0;
114
		$savemsg = get_std_save_message($retval);
115

    
116
		config_lock();
117
		$retval = filter_configure();
118
		config_unlock();
119

    
120
		if (stristr($retval, "error") <> true)
121
			$savemsg = get_std_save_message($retval);
122
		else
123
			$savemsg = $retval;
124

    
125
		unlink_if_exists("/tmp/reload_interfaces");
126
	}
127

    
128
} else if ($_POST) {
129

    
130
	unset($input_errors);
131

    
132
	/* input validation */
133

    
134
	/* Build a list of the port names so we can see how the interfaces map */
135
	$portifmap = array();
136
	foreach ($portlist as $portname => $portinfo)
137
		$portifmap[$portname] = array();
138

    
139
	/* Go through the list of ports selected by the user,
140
	   build a list of port-to-interface mappings in portifmap */
141
	foreach ($_POST as $ifname => $ifport) {
142
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
143
			$portifmap[$ifport][] = strtoupper($ifname);
144
	}
145

    
146
	/* Deliver error message for any port with more than one assignment */
147
	foreach ($portifmap as $portname => $ifnames) {
148
		if (count($ifnames) > 1) {
149
			$errstr = "Port " . $portname .
150
				" was assigned to " . count($ifnames) .
151
				" interfaces:";
152
				
153
			foreach ($portifmap[$portname] as $ifn)
154
				$errstr .= " " . $ifn;
155
			
156
			$input_errors[] = $errstr;
157
		}
158
	}
159

    
160

    
161
	if (!$input_errors) {
162
		/* No errors detected, so update the config */
163
		foreach ($_POST as $ifname => $ifport) {
164
		
165
			if (($ifname == 'lan') || ($ifname == 'wan') ||
166
				(substr($ifname, 0, 3) == 'opt')) {
167
				
168
				if (!is_array($ifport)) {
169
					$config['interfaces'][$ifname]['if'] = $ifport;
170
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
171
						$config['interfaces'][$ifname]['pointtopoint'] = true;
172
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
173
					}
174

    
175
					/* check for wireless interfaces, set or clear ['wireless'] */
176
					if (preg_match($g['wireless_regex'], $ifport)) {
177
						if (!is_array($config['interfaces'][$ifname]['wireless']))
178
							$config['interfaces'][$ifname]['wireless'] = array();
179
					} else {
180
						unset($config['interfaces'][$ifname]['wireless']);
181
					}
182
					
183
					/* make sure there is a descr for all interfaces */
184
					if (!isset($config['interfaces'][$ifname]['descr']))
185
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
186
				}
187
			}
188
		}
189
	
190
		write_config();
191
		
192
		touch("/tmp/reload_interfaces");
193
	}
194
}
195

    
196
if ($_GET['act'] == "del") {
197
	$id = $_GET['id'];
198

    
199
	if (link_interface_to_bridge($id))
200
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
201
	else if (link_interface_to_gre($id))
202
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
203
	else if (link_interface_to_gif($id))
204
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
205
	else {
206
		unset($config['interfaces'][$id]['enable']);
207
		interface_bring_down($id);   /* down the interface */
208
		
209
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
210

    
211
		if($id == "lan") {
212
			unset($config['interfaces']['lan']);
213
			if (is_array($config['dhcpd']))
214
				unset($config['dhcpd']['lan']);
215
				unset($config['shaper']);
216
				unset($config['ezshaper']);
217
				unset($config['nat']);
218
				system("rm /var/dhcpd/var/db/*");
219
        			services_dhcpd_configure();
220
		}
221

    
222
		if ($config['filter']['rule'] > 0)
223
       	 	foreach ($config['filter']['rule'] as $x => $rule) {
224
                	        if($rule['interface'] == $id)
225
               		                 unset($config['filter']['rule'][$x]);
226
        	}
227
		if ($config['nat']['advancedoutbound']['rule'] > 0)
228
        	foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
229
                	        if($rule['interface'] == $id)
230
           	    	                 unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
231
        	}
232
        	if (count($config['nat']['rule']) > 0) 
233
        	foreach ($config['nat']['rule'] as $x => $rule) {
234
                        	if($rule['interface'] == $id)
235
                	                unset($config['nat']['rule'][$x]['interface']);
236
        	}
237

    
238
		write_config();
239
	
240
		/* XXX: What is this for?!?! */
241
		if($config['interfaces']['lan']) {
242
			unset($config['dhcpd']['wan']);		
243
		}
244
	
245
		$savemsg = "Interface has been deleted.";
246
	}
247
}
248

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

    
287
	write_config();
288

    
289
	$savemsg = "Interface has been added.";
290

    
291
}
292

    
293
include("head.inc");
294

    
295
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
296
	if ($_POST)
297
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
298
	else
299
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
300

    
301
?>
302

    
303
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
304
<?php include("fbegin.inc"); ?>
305
<?php if ($input_errors) print_input_errors($input_errors); ?>
306
<?php if ($savemsg) print_info_box($savemsg); ?>
307

    
308
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
309
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
310
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
311
 the changes in order for them to take effect.");?><br>
312
<?php endif; ?>
313

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