Project

General

Profile

Download (11 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 PPP interfaces */
52
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
53
	$i = 0;
54
	foreach ($config['ppps']['ppp'] as $ppp) {
55
		$portname = 'ppp_' . basename($ppp['port']);
56
		$portlist[$portname] = $ppp;
57
		$portlist[$portname]['isppp'] = true;
58
		$i++;
59
	}
60
}
61

    
62
if ($_POST['apply']) {
63
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
64
		exec("/etc/rc.reboot");
65
	else {
66
		write_config();
67

    
68
		$retval = 0;
69
		$savemsg = get_std_save_message($retval);
70

    
71
		config_lock();
72
		$retval = filter_configure();
73
		config_unlock();
74

    
75
		if (stristr($retval, "error") <> true)
76
			$savemsg = get_std_save_message($retval);
77
		else
78
			$savemsg = $retval;
79

    
80
		unlink_if_exists("/tmp/reload_interfaces");
81
	}
82

    
83
} else if ($_POST) {
84

    
85
	unset($input_errors);
86

    
87
	/* input validation */
88

    
89
	/* Build a list of the port names so we can see how the interfaces map */
90
	$portifmap = array();
91
	foreach ($portlist as $portname => $portinfo)
92
		$portifmap[$portname] = array();
93

    
94
	/* Go through the list of ports selected by the user,
95
	   build a list of port-to-interface mappings in portifmap */
96
	foreach ($_POST as $ifname => $ifport) {
97
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
98
			$portifmap[$ifport][] = strtoupper($ifname);
99
	}
100

    
101
	/* Deliver error message for any port with more than one assignment */
102
	foreach ($portifmap as $portname => $ifnames) {
103
		if (count($ifnames) > 1) {
104
			$errstr = "Port " . $portname .
105
				" was assigned to " . count($ifnames) .
106
				" interfaces:";
107
				
108
			foreach ($portifmap[$portname] as $ifn)
109
				$errstr .= " " . $ifn;
110
			
111
			$input_errors[] = $errstr;
112
		}
113
	}
114

    
115

    
116
	if (!$input_errors) {
117
		/* No errors detected, so update the config */
118
		foreach ($_POST as $ifname => $ifport) {
119
		
120
			if (($ifname == 'lan') || ($ifname == 'wan') ||
121
				(substr($ifname, 0, 3) == 'opt')) {
122
				
123
				if (!is_array($ifport)) {
124
					$config['interfaces'][$ifname]['if'] = $ifport;
125
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
126
						$config['interfaces'][$ifname]['pointtopoint'] = true;
127
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
128
					}
129

    
130
					/* check for wireless interfaces, set or clear ['wireless'] */
131
					if (preg_match($g['wireless_regex'], $ifport)) {
132
						if (!is_array($config['interfaces'][$ifname]['wireless']))
133
							$config['interfaces'][$ifname]['wireless'] = array();
134
					} else {
135
						unset($config['interfaces'][$ifname]['wireless']);
136
					}
137
					
138
					/* make sure there is a descr for all interfaces */
139
					if (!isset($config['interfaces'][$ifname]['descr']))
140
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
141
				}
142
			}
143
		}
144
	
145
		write_config();
146
		
147
		touch("/tmp/reload_interfaces");
148
	}
149
}
150

    
151
if ($_GET['act'] == "del") {
152
	$id = $_GET['id'];
153

    
154
	unset($config['interfaces'][$id]['enable']);
155
	interface_bring_down($id);   /* down the interface */
156
		
157
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
158

    
159
	if($id == "lan") {
160
		unset($config['interfaces']['lan']);
161
		unset($config['dhcpd']['lan']);
162
		unset($config['shaper']);
163
		unset($config['ezshaper']);
164
		unset($config['nat']);
165
		system("rm /var/dhcpd/var/db/*");
166
        	services_dhcpd_configure();
167
	}
168

    
169
	if ($config['filter']['rule'] > 0)
170
        foreach ($config['filter']['rule'] as $x => $rule) {
171
                        if($rule['interface'] == $id)
172
                                unset($config['filter']['rule'][$x]);
173
        }
174
	if ($config['nat']['advancedoutbound']['rule'] > 0)
175
        foreach ($config['nat']['advancedoutbound']['rule'] as $id => $rule) {
176
                        if($rule['interface'] == $x)
177
                                unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
178
        }
179
        if (count($config['nat']['rule']) > 0) 
180
        foreach ($config['nat']['rule'] as $x => $rule) {
181
                        if($rule['interface'] == $id)
182
                                unset($config['nat']['rule'][$x]['interface']);
183
        }
184

    
185

    
186
	write_config();
187
	
188
	/* XXX: What is this for?!?! */
189
	if($config['interfaces']['lan']) {
190
		unset($config['dhcpd']['wan']);		
191
	}
192
	
193
	$savemsg = "Interface has been deleted.";
194
}
195

    
196
if ($_GET['act'] == "add") {
197
	/* find next free optional interface number */
198
	if(!$config['interfaces']['lan']) {
199
		$newifname = "lan";
200
		$config['interfaces'][$newifname] = array();
201
		$config['interfaces'][$newifname]['descr'] = $descr;
202
	} else {
203
		$i = 1;
204
                foreach ($config['interfaces'] as $ifname => $if) {
205
                        if ($ifname == "wan" || $ifname == "lan")
206
                                continue;
207
                        if (substr($ifname, 3) == $i) {
208
                                $i++;
209
                                continue;
210
                        }
211
                        break;
212
                }
213
		$newifname = 'opt' . $i;
214
		$descr = "OPT{$i}";
215
		$config['interfaces'][$newifname] = array();
216
		$config['interfaces'][$newifname]['descr'] = $descr;
217
		ksort($config['interfaces']);
218
	}
219
	
220
	/* Find an unused port for this interface */
221
	foreach ($portlist as $portname => $portinfo) {
222
		$portused = false;
223
		foreach ($config['interfaces'] as $ifname => $ifdata) {
224
			if ($ifdata['if'] == $portname) {
225
				$portused = true;
226
				break;
227
			}
228
		}
229
		if (!$portused) {
230
			$config['interfaces'][$newifname]['if'] = $portname;
231
			if (preg_match($g['wireless_regex'], $portname))
232
				$config['interfaces'][$newifname]['wireless'] = array();
233
			break;
234
		}
235
	}
236
	
237
        /* XXX: Do not remove this. */
238
        mwexec("rm -f /tmp/config.cache");
239

    
240
	write_config();
241

    
242
	$savemsg = "Interface has been added.";
243

    
244
}
245

    
246
include("head.inc");
247

    
248
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
249
	if ($_POST)
250
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
251
	else
252
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
253

    
254
?>
255

    
256
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
257
<?php include("fbegin.inc"); ?>
258
<?php if ($input_errors) print_input_errors($input_errors); ?>
259
<?php if ($savemsg) print_info_box($savemsg); ?>
260

    
261
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
262
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
263
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
264
 the changes in order for them to take effect.");?><br>
265
<?php endif; ?>
266

    
267
<table width="100%" border="0" cellpadding="0" cellspacing="0">
268
  <tr><td class="tabnavtbl">
269
<?php
270
	$tab_array = array();
271
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
272
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
273
	$tab_array[2] = array("PPP", false, "interfaces_ppp.php");
274
        $tab_array[3] = array("GRE", false, "interfaces_gre.php");
275
        $tab_array[4] = array("GIF", false, "interfaces_gif.php");
276
	display_top_tabs($tab_array);
277
?>  
278
  </td></tr>
279
  <tr> 
280
    <td>
281
	<div id="mainarea">
282
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
283
       <tr> 
284
	<td class="listhdrr">Interface</td>
285
	<td class="listhdr">Network port</td>
286
	<td class="list">&nbsp;</td>
287
  </tr>
288
  <?php foreach ($config['interfaces'] as $ifname => $iface):
289
  	if ($iface['descr'])
290
		$ifdescr = $iface['descr'];
291
	else
292
		$ifdescr = strtoupper($ifname);
293
	?>
294
  <tr> 
295
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
296
	  <td valign="middle" class="listr">
297
		<select name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
298
		  <?php foreach ($portlist as $portname => $portinfo): ?>
299
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
300
		  <?php if ($portinfo['isvlan']) {
301
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
302
					if ($portinfo['descr'])
303
						$descr .= " (" . $portinfo['descr'] . ")";
304
					echo htmlspecialchars($descr);
305
				} elseif ($portinfo['isppp']) {
306
					$descr = "PPP {$portinfo['port']}";
307
					if ($portinfo['descr'])
308
						$descr .= " (" . $portinfo['descr'] . ")";
309
					echo htmlspecialchars($descr);
310
				  } else
311
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
312
		  ?>
313
		  </option>
314
		  <?php endforeach; ?>
315
		</select>
316
		</td>
317
		<td valign="middle" class="list"> 
318
		  <?php if ($ifname != 'wan'): ?>
319
		  <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> 
320
		  <?php endif; ?>
321
		</td>
322
  </tr>
323
  <?php endforeach; ?>
324
  <?php if (count($config['interfaces']) < count($portlist)): ?>
325
  <tr>
326
	<td class="list" colspan="2"></td>
327
	<td class="list" nowrap>
328
	<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>
329
	</td>
330
  </tr>
331
  <?php else: ?>
332
  <tr>
333
	<td class="list" colspan="3" height="10"></td>
334
  </tr>
335
  <?php endif; ?>
336
</table>
337
</div>
338
<br/>
339
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
340
<p>
341
</p>
342
<ul>
343
  <li><span class="vexpl">change the IP address of your computer</span></li>
344
  <li><span class="vexpl">renew its DHCP lease</span></li>
345
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
346
</ul></td>
347
	</tr>
348
</table>
349
</form>
350
<?php include("fend.inc"); ?>
351
</body>
352
</html>
(76-76/204)