Project

General

Profile

Download (14 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
	unset($config['interfaces'][$id]['enable']);
200
	interface_bring_down($id);   /* down the interface */
201
		
202
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
203

    
204
	if($id == "lan") {
205
		unset($config['interfaces']['lan']);
206
		if (is_array($config['dhcpd']))
207
			unset($config['dhcpd']['lan']);
208
		unset($config['shaper']);
209
		unset($config['ezshaper']);
210
		unset($config['nat']);
211
		system("rm /var/dhcpd/var/db/*");
212
        	services_dhcpd_configure();
213
	}
214

    
215
	if ($config['filter']['rule'] > 0)
216
        foreach ($config['filter']['rule'] as $x => $rule) {
217
                        if($rule['interface'] == $id)
218
                                unset($config['filter']['rule'][$x]);
219
        }
220
	if ($config['nat']['advancedoutbound']['rule'] > 0)
221
        foreach ($config['nat']['advancedoutbound']['rule'] as $id => $rule) {
222
                        if($rule['interface'] == $x)
223
                                unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
224
        }
225
        if (count($config['nat']['rule']) > 0) 
226
        foreach ($config['nat']['rule'] as $x => $rule) {
227
                        if($rule['interface'] == $id)
228
                                unset($config['nat']['rule'][$x]['interface']);
229
        }
230

    
231

    
232
	write_config();
233
	
234
	/* XXX: What is this for?!?! */
235
	if($config['interfaces']['lan']) {
236
		unset($config['dhcpd']['wan']);		
237
	}
238
	
239
	$savemsg = "Interface has been deleted.";
240
}
241

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

    
280
	write_config();
281

    
282
	$savemsg = "Interface has been added.";
283

    
284
}
285

    
286
include("head.inc");
287

    
288
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
289
	if ($_POST)
290
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
291
	else
292
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
293

    
294
?>
295

    
296
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
297
<?php include("fbegin.inc"); ?>
298
<?php if ($input_errors) print_input_errors($input_errors); ?>
299
<?php if ($savemsg) print_info_box($savemsg); ?>
300

    
301
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
302
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
303
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
304
 the changes in order for them to take effect.");?><br>
305
<?php endif; ?>
306

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