Project

General

Profile

Download (10.2 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
	$i = 0;
46
	foreach ($config['vlans']['vlan'] as $vlan) {
47
		$portlist['vlan' . $i] = $vlan;
48
		$portlist['vlan' . $i]['isvlan'] = true;
49
		$i++;
50
	}
51
}
52

    
53
/* add PPP interfaces */
54
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
55
	$i = 0;
56
	foreach ($config['ppps']['ppp'] as $ppp) {
57
		$portname = 'ppp_' . basename($ppp['port']);
58
		$portlist[$portname] = $ppp;
59
		$portlist[$portname]['isppp'] = true;
60
		$i++;
61
	}
62
}
63

    
64
if ($_POST) {
65

    
66
	unset($input_errors);
67

    
68
	/* input validation */
69

    
70
	/* Build a list of the port names so we can see how the interfaces map */
71
	$portifmap = array();
72
	foreach ($portlist as $portname => $portinfo)
73
		$portifmap[$portname] = array();
74

    
75
	/* Go through the list of ports selected by the user,
76
	   build a list of port-to-interface mappings in portifmap */
77
	foreach ($_POST as $ifname => $ifport) {
78
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
79
			$portifmap[$ifport][] = strtoupper($ifname);
80
	}
81

    
82
	/* Deliver error message for any port with more than one assignment */
83
	foreach ($portifmap as $portname => $ifnames) {
84
		if (count($ifnames) > 1) {
85
			$errstr = "Port " . $portname .
86
				" was assigned to " . count($ifnames) .
87
				" interfaces:";
88
				
89
			foreach ($portifmap[$portname] as $ifn)
90
				$errstr .= " " . $ifn;
91
			
92
			$input_errors[] = $errstr;
93
		}
94
	}
95

    
96

    
97
	if (!$input_errors) {
98
		/* No errors detected, so update the config */
99
		foreach ($_POST as $ifname => $ifport) {
100
		
101
			if (($ifname == 'lan') || ($ifname == 'wan') ||
102
				(substr($ifname, 0, 3) == 'opt')) {
103
				
104
				if (!is_array($ifport)) {
105
					$config['interfaces'][$ifname]['if'] = $ifport;
106
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
107
						$config['interfaces'][$ifname]['pointtopoint'] = true;
108
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
109
					}
110

    
111
					/* check for wireless interfaces, set or clear ['wireless'] */
112
					if (preg_match($g['wireless_regex'], $ifport)) {
113
						if (!is_array($config['interfaces'][$ifname]['wireless']))
114
							$config['interfaces'][$ifname]['wireless'] = array();
115
					} else {
116
						unset($config['interfaces'][$ifname]['wireless']);
117
					}
118
					
119
					/* make sure there is a name for OPTn */
120
					if (substr($ifname, 0, 3) == 'opt') {
121
						if (!isset($config['interfaces'][$ifname]['descr']))
122
							$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
123
					}
124
				}
125
			}
126
		}
127
	
128
		$savemsg = get_std_save_message($retval);
129
	
130
		write_config();
131
		
132
	}
133
}
134

    
135
if ($_GET['act'] == "del") {
136
	$id = $_GET['id'];
137

    
138
	$i = substr($id, 3); /* the number of the OPTn port being deleted */
139
	unset($config['interfaces'][$id]['enable']);
140
	interfaces_optional_configure_if($i);   /* down the interface */
141
		
142
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
143

    
144
	if($id <> "lan") {
145
		/* shift down other OPTn interfaces to get rid of holes */
146
		$i++;
147
	
148
		/* look at the following OPTn ports */
149
		while (is_array($config['interfaces']['opt' . $i])) {
150
			$config['interfaces']['opt' . ($i - 1)] =
151
				$config['interfaces']['opt' . $i];
152
		
153
			if ($config['interfaces']['opt' . ($i - 1)]['descr'] == "OPT" . $i)
154
				$config['interfaces']['opt' . ($i - 1)]['descr'] = "OPT" . ($i - 1);
155
		
156
			unset($config['interfaces']['opt' . $i]);
157
			$i++;
158
		}
159
	} else {
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
	write_config();
170
	
171
	if($id <> "lan") {
172
		/*   move all the interfaces up.  for example:
173
	 	*      opt1 --> opt1
174
	 	*		opt2 --> delete
175
	 	*		opt3 --> opt2
176
     	*      opt4 --> opt3
177
     	*/
178
		cleanup_opt_interfaces_after_removal($i);
179
	}
180

    
181
	parse_config(true);
182

    
183
	if($config['interfaces']['lan']) {
184
		unset($config['dhcpd']['wan']);		
185
	}
186
	
187
	$savemsg = "Interface has been deleted.";
188

    
189
}
190

    
191
if ($_GET['act'] == "add") {
192
	/* find next free optional interface number */
193
	$i = 1;
194
	if(!$config['interfaces']['lan']) {
195
		$newifname = "lan";
196
		$config['interfaces'][$newifname] = array();
197
		$config['interfaces'][$newifname]['descr'] = "{$descr}";
198
	} else {
199
		while (is_array($config['interfaces']['opt' . $i]))
200
			$i++;
201
		$newifname = 'opt' . $i;
202
		$descr = "OPT";
203
		$config['interfaces'][$newifname] = array();
204
		$config['interfaces'][$newifname]['descr'] = "{$descr}" . $i;
205
	}
206
	
207
	/* Find an unused port for this interface */
208
	foreach ($portlist as $portname => $portinfo) {
209
		$portused = false;
210
		foreach ($config['interfaces'] as $ifname => $ifdata) {
211
			if ($ifdata['if'] == $portname) {
212
				$portused = true;
213
				break;
214
			}
215
		}
216
		if (!$portused) {
217
			$config['interfaces'][$newifname]['if'] = $portname;
218
			if (preg_match($g['wireless_regex'], $portname))
219
				$config['interfaces'][$newifname]['wireless'] = array();
220
			break;
221
		}
222
	}
223
	
224
	write_config();
225

    
226
	$savemsg = "Interface has been added.";
227

    
228
}
229

    
230
include("head.inc");
231

    
232
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
233
	if ($_POST) 
234
		$savemsg = "The firewall is now rebooting.";
235
	else
236
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
237

    
238
?>
239

    
240
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
241
<?php include("fbegin.inc"); ?>
242
<?php if ($input_errors) print_input_errors($input_errors); ?>
243
<?php if ($savemsg) print_info_box($savemsg); ?>
244

    
245
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
246
  <div id="save_button" style="display:none"><?php print_info_box_np("Assignment change detected, changes are not yet saved.", "save", "Save Changes"); ?></div>
247
<table width="100%" border="0" cellpadding="0" cellspacing="0">
248
  <tr><td class="tabnavtbl">
249
<?php
250
	$tab_array = array();
251
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
252
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
253
	$tab_array[2] = array("PPP", false, "interfaces_ppp.php");
254
	display_top_tabs($tab_array);
255
?>  
256
  </td></tr>
257
  <tr> 
258
    <td>
259
	<div id="mainarea">
260
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
261
       <tr> 
262
	<td class="listhdrr">Interface</td>
263
	<td class="listhdr">Network port</td>
264
	<td class="list">&nbsp;</td>
265
  </tr>
266
  <?php foreach ($config['interfaces'] as $ifname => $iface):
267
  	if ($iface['descr'])
268
		$ifdescr = $iface['descr'];
269
	else
270
		$ifdescr = strtoupper($ifname);
271
	?>
272
  <tr> 
273
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
274
	  <td valign="middle" class="listr">
275
		<select onChange="document.getElementById('save_button').style.display='inline';" name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
276
		  <?php foreach ($portlist as $portname => $portinfo): ?>
277
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
278
		  <?php if ($portinfo['isvlan']) {
279
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
280
					if ($portinfo['descr'])
281
						$descr .= " (" . $portinfo['descr'] . ")";
282
					echo htmlspecialchars($descr);
283
				} elseif ($portinfo['isppp']) {
284
					$descr = "PPP {$portinfo['port']}";
285
					if ($portinfo['descr'])
286
						$descr .= " (" . $portinfo['descr'] . ")";
287
					echo htmlspecialchars($descr);
288
				  } else
289
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
290
		  ?>
291
		  </option>
292
		  <?php endforeach; ?>
293
		</select>
294
		</td>
295
		<td valign="middle" class="list"> 
296
		  <?php if ($ifname != 'wan'): ?>
297
		  <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> 
298
		  <?php endif; ?>
299
		</td>
300
  </tr>
301
  <?php endforeach; ?>
302
  <?php if (count($config['interfaces']) < count($portlist)): ?>
303
  <tr>
304
	<td class="list" colspan="2"></td>
305
	<td class="list" nowrap>
306
	<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>
307
	</td>
308
  </tr>
309
  <?php else: ?>
310
  <tr>
311
	<td class="list" colspan="3" height="10"></td>
312
  </tr>
313
  <?php endif; ?>
314
</table>
315
</div>
316
<br/>
317
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
318
<p>
319
</p>
320
<ul>
321
  <li><span class="vexpl">change the IP address of your computer</span></li>
322
  <li><span class="vexpl">renew its DHCP lease</span></li>
323
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
324
</ul></td>
325
	</tr>
326
</table>
327
</form>
328
<?php include("fend.inc"); ?>
329
</body>
330
</html>
331

    
332
<?php
333

    
334
	if ($_POST) {
335
		if (!$input_errors)
336
			touch("/tmp/reload_interfaces");
337
		if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
338
			exec("/etc/rc.reboot");
339
	}
340
	
341
?>
(74-74/190)