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
$pgtitle = array("Interfaces", "Assign network ports");
33
require("guiconfig.inc");
34

    
35
/*
36
	In this file, "port" refers to the physical port name,
37
	while "interface" refers to LAN, WAN, or OPTn.
38
*/
39

    
40
/* get list without VLAN interfaces */
41
$portlist = get_interface_list();
42

    
43
/* add VLAN interfaces */
44
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
45
	foreach ($config['vlans']['vlan'] as $vlan) {
46
		$portlist[$vlan['vlanif']] = $vlan;
47
		$portlist[$vlan['vlanif']]['isvlan'] = true;
48
	}
49
}
50

    
51
/* add Bridge interfaces */
52
if (is_array($config['bridges']['bridge']) && count($config['bridges']['bridge'])) {
53
        foreach ($config['bridges']['bridge'] as $bridge) {
54
                $portlist[$bridge['bridgeif']] = $bridge;
55
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
56
        }
57
}
58

    
59
/* add GIF interfaces */
60
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
61
        foreach ($config['gifs']['gif'] as $gif) {
62
                $portlist[$gif['gifif']] = $gif;
63
                $portlist[$gif['gifif']]['isgif'] = true;
64
        }
65
}
66

    
67
/* add GRE interfaces */
68
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
69
        foreach ($config['gres']['gre'] as $gre) {
70
                $portlist[$gre['greif']] = $gre;
71
                $portlist[$gre['greif']]['isgre'] = true;
72
        }
73
}
74

    
75
/* add GRE interfaces */
76
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
77
        foreach ($config['laggs']['lagg'] as $lagg) {
78
                $portlist[$lagg['laggif']] = $lagg;
79
                $portlist[$lagg['laggif']]['islagg'] = true;
80
        }
81
}
82

    
83

    
84
/* add PPP interfaces */
85
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
86
	$i = 0;
87
	foreach ($config['ppps']['ppp'] as $ppp) {
88
		$portname = 'ppp_' . basename($ppp['port']);
89
		$portlist[$portname] = $ppp;
90
		$portlist[$portname]['isppp'] = true;
91
		$i++;
92
	}
93
}
94

    
95
if ($_POST['apply']) {
96
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
97
		exec("/etc/rc.reboot");
98
	else {
99
		write_config();
100

    
101
		$retval = 0;
102
		$savemsg = get_std_save_message($retval);
103

    
104
		config_lock();
105
		$retval = filter_configure();
106
		config_unlock();
107

    
108
		if (stristr($retval, "error") <> true)
109
			$savemsg = get_std_save_message($retval);
110
		else
111
			$savemsg = $retval;
112

    
113
		unlink_if_exists("/tmp/reload_interfaces");
114
	}
115

    
116
} else if ($_POST) {
117

    
118
	unset($input_errors);
119

    
120
	/* input validation */
121

    
122
	/* Build a list of the port names so we can see how the interfaces map */
123
	$portifmap = array();
124
	foreach ($portlist as $portname => $portinfo)
125
		$portifmap[$portname] = array();
126

    
127
	/* Go through the list of ports selected by the user,
128
	   build a list of port-to-interface mappings in portifmap */
129
	foreach ($_POST as $ifname => $ifport) {
130
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
131
			$portifmap[$ifport][] = strtoupper($ifname);
132
	}
133

    
134
	/* Deliver error message for any port with more than one assignment */
135
	foreach ($portifmap as $portname => $ifnames) {
136
		if (count($ifnames) > 1) {
137
			$errstr = "Port " . $portname .
138
				" was assigned to " . count($ifnames) .
139
				" interfaces:";
140
				
141
			foreach ($portifmap[$portname] as $ifn)
142
				$errstr .= " " . $ifn;
143
			
144
			$input_errors[] = $errstr;
145
		}
146
	}
147

    
148

    
149
	if (!$input_errors) {
150
		/* No errors detected, so update the config */
151
		foreach ($_POST as $ifname => $ifport) {
152
		
153
			if (($ifname == 'lan') || ($ifname == 'wan') ||
154
				(substr($ifname, 0, 3) == 'opt')) {
155
				
156
				if (!is_array($ifport)) {
157
					$config['interfaces'][$ifname]['if'] = $ifport;
158
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
159
						$config['interfaces'][$ifname]['pointtopoint'] = true;
160
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
161
					}
162

    
163
					/* check for wireless interfaces, set or clear ['wireless'] */
164
					if (preg_match($g['wireless_regex'], $ifport)) {
165
						if (!is_array($config['interfaces'][$ifname]['wireless']))
166
							$config['interfaces'][$ifname]['wireless'] = array();
167
					} else {
168
						unset($config['interfaces'][$ifname]['wireless']);
169
					}
170
					
171
					/* make sure there is a descr for all interfaces */
172
					if (!isset($config['interfaces'][$ifname]['descr']))
173
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
174
				}
175
			}
176
		}
177
	
178
		write_config();
179
		
180
		touch("/tmp/reload_interfaces");
181
	}
182
}
183

    
184
if ($_GET['act'] == "del") {
185
	$id = $_GET['id'];
186

    
187
	unset($config['interfaces'][$id]['enable']);
188
	interface_bring_down($id);   /* down the interface */
189
		
190
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
191

    
192
	if($id == "lan") {
193
		unset($config['interfaces']['lan']);
194
		unset($config['dhcpd']['lan']);
195
		unset($config['shaper']);
196
		unset($config['ezshaper']);
197
		unset($config['nat']);
198
		system("rm /var/dhcpd/var/db/*");
199
        	services_dhcpd_configure();
200
	}
201

    
202
	if ($config['filter']['rule'] > 0)
203
        foreach ($config['filter']['rule'] as $x => $rule) {
204
                        if($rule['interface'] == $id)
205
                                unset($config['filter']['rule'][$x]);
206
        }
207
	if ($config['nat']['advancedoutbound']['rule'] > 0)
208
        foreach ($config['nat']['advancedoutbound']['rule'] as $id => $rule) {
209
                        if($rule['interface'] == $x)
210
                                unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
211
        }
212
        if (count($config['nat']['rule']) > 0) 
213
        foreach ($config['nat']['rule'] as $x => $rule) {
214
                        if($rule['interface'] == $id)
215
                                unset($config['nat']['rule'][$x]['interface']);
216
        }
217

    
218

    
219
	write_config();
220
	
221
	/* XXX: What is this for?!?! */
222
	if($config['interfaces']['lan']) {
223
		unset($config['dhcpd']['wan']);		
224
	}
225
	
226
	$savemsg = "Interface has been deleted.";
227
}
228

    
229
if ($_GET['act'] == "add") {
230
	/* find next free optional interface number */
231
	if(!$config['interfaces']['lan']) {
232
		$newifname = "lan";
233
		$config['interfaces'][$newifname] = array();
234
		$config['interfaces'][$newifname]['descr'] = $descr;
235
	} else {
236
		$i = 1;
237
                foreach ($config['interfaces'] as $ifname => $if) {
238
                        if ($ifname == "wan" || $ifname == "lan")
239
                                continue;
240
                        if (substr($ifname, 3) == $i) {
241
                                $i++;
242
                                continue;
243
                        }
244
                        break;
245
                }
246
		$newifname = 'opt' . $i;
247
		$descr = "OPT{$i}";
248
		$config['interfaces'][$newifname] = array();
249
		$config['interfaces'][$newifname]['descr'] = $descr;
250
		ksort($config['interfaces']);
251
	}
252
	
253
	/* Find an unused port for this interface */
254
	foreach ($portlist as $portname => $portinfo) {
255
		$portused = false;
256
		foreach ($config['interfaces'] as $ifname => $ifdata) {
257
			if ($ifdata['if'] == $portname) {
258
				$portused = true;
259
				break;
260
			}
261
		}
262
		if (!$portused) {
263
			$config['interfaces'][$newifname]['if'] = $portname;
264
			if (preg_match($g['wireless_regex'], $portname))
265
				$config['interfaces'][$newifname]['wireless'] = array();
266
			break;
267
		}
268
	}
269
	
270
        /* XXX: Do not remove this. */
271
        mwexec("rm -f /tmp/config.cache");
272

    
273
	write_config();
274

    
275
	$savemsg = "Interface has been added.";
276

    
277
}
278

    
279
include("head.inc");
280

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

    
287
?>
288

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

    
294
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
295
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
296
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
297
 the changes in order for them to take effect.");?><br>
298
<?php endif; ?>
299

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