Project

General

Profile

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

    
40
$pgtitle = array("Interfaces", "Assign network ports");
41
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
		$portlist[$vlan['vlanif']] = $vlan;
55
		$portlist[$vlan['vlanif']]['isvlan'] = true;
56
	}
57
}
58

    
59
/* add Bridge interfaces */
60
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
61
        foreach ($config['bridges']['bridged'] as $bridge) {
62
                $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
/* 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
/* 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
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
		unlink_if_exists("/tmp/reload_interfaces");
122
	}
123

    
124
} else if ($_POST) {
125

    
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
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
167
						$config['interfaces'][$ifname]['pointtopoint'] = true;
168
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
169
					}
170

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

    
192
if ($_GET['act'] == "del") {
193
	$id = $_GET['id'];
194

    
195
	unset($config['interfaces'][$id]['enable']);
196
	interface_bring_down($id);   /* down the interface */
197
		
198
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
199

    
200
	if($id == "lan") {
201
		unset($config['interfaces']['lan']);
202
		unset($config['dhcpd']['lan']);
203
		unset($config['shaper']);
204
		unset($config['ezshaper']);
205
		unset($config['nat']);
206
		system("rm /var/dhcpd/var/db/*");
207
        	services_dhcpd_configure();
208
	}
209

    
210
	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
	write_config();
228
	
229
	/* XXX: What is this for?!?! */
230
	if($config['interfaces']['lan']) {
231
		unset($config['dhcpd']['wan']);		
232
	}
233
	
234
	$savemsg = "Interface has been deleted.";
235
}
236

    
237
if ($_GET['act'] == "add") {
238
	/* find next free optional interface number */
239
	if(!$config['interfaces']['lan']) {
240
		$newifname = "lan";
241
		$config['interfaces'][$newifname] = array();
242
		$config['interfaces'][$newifname]['descr'] = $descr;
243
	} else {
244
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
245
			if (!$config['interfaces']["opt{$i}"])
246
				break;
247
		}
248
		$newifname = 'opt' . $i;
249
		$descr = "OPT{$i}";
250
		$config['interfaces'][$newifname] = array();
251
		$config['interfaces'][$newifname]['descr'] = $descr;
252
		ksort($config['interfaces']);
253
	}
254
	
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
			if (preg_match($g['wireless_regex'], $portname))
267
				$config['interfaces'][$newifname]['wireless'] = array();
268
			break;
269
		}
270
	}
271
	
272
        /* XXX: Do not remove this. */
273
        mwexec("rm -f /tmp/config.cache");
274

    
275
	write_config();
276

    
277
	$savemsg = "Interface has been added.";
278

    
279
}
280

    
281
include("head.inc");
282

    
283
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
284
	if ($_POST)
285
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
286
	else
287
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
288

    
289
?>
290

    
291
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
292
<?php include("fbegin.inc"); ?>
293
<?php if ($input_errors) print_input_errors($input_errors); ?>
294
<?php if ($savemsg) print_info_box($savemsg); ?>
295

    
296
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
297
<?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
<table width="100%" border="0" cellpadding="0" cellspacing="0">
303
  <tr><td class="tabnavtbl">
304
<?php
305
	$tab_array = array();
306
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
307
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
308
	$tab_array[2] = array("PPP", false, "interfaces_ppp.php");
309
        $tab_array[3] = array("GRE", false, "interfaces_gre.php");
310
        $tab_array[4] = array("GIF", false, "interfaces_gif.php");
311
	$tab_array[5] = array("Bridges", false, "interfaces_bridge.php");
312
	$tab_array[6] = array("LAGG", false, "interfaces_lagg.php");
313
	display_top_tabs($tab_array);
314
?>  
315
  </td></tr>
316
  <tr> 
317
    <td>
318
	<div id="mainarea">
319
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
320
       <tr> 
321
	<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
		<select name="<?=$ifname;?>" id="<?=$ifname;?>">
335
		  <?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
				} elseif ($portinfo['isppp']) {
343
					$descr = "PPP {$portinfo['port']}";
344
					if ($portinfo['descr'])
345
						$descr .= " (" . $portinfo['descr'] . ")";
346
					echo htmlspecialchars($descr);
347
                                 } 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
                                 } elseif ($portinfo['islagg']) {
363
                                         $descr = strtoupper($portinfo['laggif']);
364
                                         if ($portinfo['descr'])
365
                                                 $descr .= " (" . $portinfo['descr'] . ")";
366
                                        echo htmlspecialchars($descr);
367
				  } else
368
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
369
		  ?>
370
		  </option>
371
		  <?php endforeach; ?>
372
		</select>
373
		</td>
374
		<td valign="middle" class="list"> 
375
		  <?php if ($ifname != 'wan'): ?>
376
		  <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
		  <?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
	<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
	</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
</div>
395
<br/>
396
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
397
<p>
398
</p>
399
<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
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
403
</ul></td>
404
	</tr>
405
</table>
406
</form>
407
<?php include("fend.inc"); ?>
408
</body>
409
</html>
(74-74/211)