Project

General

Profile

Download (13.9 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']['bridge']) && count($config['bridges']['bridge'])) {
61
        foreach ($config['bridges']['bridge'] 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
		$i = 1;
245
                foreach ($config['interfaces'] as $ifname => $if) {
246
                        if ($ifname == "wan" || $ifname == "lan")
247
                                continue;
248
                        if (substr($ifname, 3) == $i) {
249
                                $i++;
250
                                continue;
251
                        }
252
                        break;
253
                }
254
		$newifname = 'opt' . $i;
255
		$descr = "OPT{$i}";
256
		$config['interfaces'][$newifname] = array();
257
		$config['interfaces'][$newifname]['descr'] = $descr;
258
		ksort($config['interfaces']);
259
	}
260
	
261
	/* Find an unused port for this interface */
262
	foreach ($portlist as $portname => $portinfo) {
263
		$portused = false;
264
		foreach ($config['interfaces'] as $ifname => $ifdata) {
265
			if ($ifdata['if'] == $portname) {
266
				$portused = true;
267
				break;
268
			}
269
		}
270
		if (!$portused) {
271
			$config['interfaces'][$newifname]['if'] = $portname;
272
			if (preg_match($g['wireless_regex'], $portname))
273
				$config['interfaces'][$newifname]['wireless'] = array();
274
			break;
275
		}
276
	}
277
	
278
        /* XXX: Do not remove this. */
279
        mwexec("rm -f /tmp/config.cache");
280

    
281
	write_config();
282

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

    
285
}
286

    
287
include("head.inc");
288

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

    
295
?>
296

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

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

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