Révision 7c611a3e
Ajouté par Renato Botelho il y a plus de 9 ans
usr/local/www/interfaces_assign.php | ||
---|---|---|
190 | 190 |
$ovpn_descrs[$c['vpnid']] = $c['description']; |
191 | 191 |
} |
192 | 192 |
|
193 |
if ($_POST['apply']) { |
|
193 |
if (isset($_POST['add_x']) && isset($_POST['if_add'])) { |
|
194 |
/* Be sure this port is not being used */ |
|
195 |
$portused = false; |
|
196 |
foreach ($config['interfaces'] as $ifname => $ifdata) { |
|
197 |
if ($ifdata['if'] == $_PORT['if_add']) { |
|
198 |
$portused = true; |
|
199 |
break; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
if ($portused === false) { |
|
204 |
/* find next free optional interface number */ |
|
205 |
if(!$config['interfaces']['lan']) { |
|
206 |
$newifname = gettext("lan"); |
|
207 |
$descr = gettext("LAN"); |
|
208 |
} else { |
|
209 |
for ($i = 1; $i <= count($config['interfaces']); $i++) { |
|
210 |
if (!$config['interfaces']["opt{$i}"]) |
|
211 |
break; |
|
212 |
} |
|
213 |
$newifname = 'opt' . $i; |
|
214 |
$descr = "OPT" . $i; |
|
215 |
} |
|
216 |
|
|
217 |
$config['interfaces'][$newifname] = array(); |
|
218 |
$config['interfaces'][$newifname]['descr'] = $descr; |
|
219 |
$config['interfaces'][$newifname]['if'] = $_POST['if_add']; |
|
220 |
if (preg_match($g['wireless_regex'], $_POST['if_add'])) { |
|
221 |
$config['interfaces'][$newifname]['wireless'] = array(); |
|
222 |
interface_sync_wireless_clones($config['interfaces'][$newifname], false); |
|
223 |
} |
|
224 |
|
|
225 |
uksort($config['interfaces'], "compare_interface_friendly_names"); |
|
226 |
|
|
227 |
/* XXX: Do not remove this. */ |
|
228 |
unlink_if_exists("{$g['tmp_path']}/config.cache"); |
|
229 |
|
|
230 |
write_config(); |
|
231 |
|
|
232 |
$savemsg = gettext("Interface has been added."); |
|
233 |
} |
|
234 |
|
|
235 |
} else if (isset($_POST['apply'])) { |
|
194 | 236 |
if (file_exists("/var/run/interface_mismatch_reboot_needed")) { |
195 | 237 |
system_reboot(); |
196 | 238 |
$rebootingnow = true; |
... | ... | |
206 | 248 |
$savemsg = $retval; |
207 | 249 |
} |
208 | 250 |
|
209 |
} else if ($_POST) {
|
|
251 |
} else if (isset($_POST['Submit'])) {
|
|
210 | 252 |
|
211 | 253 |
unset($input_errors); |
212 | 254 |
|
... | ... | |
308 | 350 |
|
309 | 351 |
enable_rrd_graphing(); |
310 | 352 |
} |
311 |
} |
|
353 |
} else { |
|
354 |
/* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ |
|
355 |
unset($delbtn); |
|
356 |
foreach ($_POST as $pn => $pd) { |
|
357 |
if (preg_match("/del_(.+)_x/", $pn, $matches)) |
|
358 |
$delbtn = $matches[1]; |
|
359 |
} |
|
312 | 360 |
|
313 |
if ($_GET['act'] == "del") {
|
|
314 |
$id = $_GET['id'];
|
|
315 |
|
|
316 |
if (link_interface_to_group($id)) |
|
317 |
$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue"); |
|
318 |
else if (link_interface_to_bridge($id)) |
|
319 |
$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue"); |
|
320 |
else if (link_interface_to_gre($id)) |
|
321 |
$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue"); |
|
322 |
else if (link_interface_to_gif($id)) |
|
323 |
$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue"); |
|
324 |
else { |
|
325 |
unset($config['interfaces'][$id]['enable']); |
|
326 |
$realid = get_real_interface($id); |
|
327 |
interface_bring_down($id); /* down the interface */ |
|
328 |
|
|
329 |
unset($config['interfaces'][$id]); /* delete the specified OPTn or LAN*/ |
|
330 |
|
|
331 |
if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) { |
|
332 |
unset($config['dhcpd'][$id]); |
|
333 |
services_dhcpd_configure(); |
|
334 |
} |
|
361 |
if (isset($delbtn)) {
|
|
362 |
$id = $delbtn;
|
|
363 |
|
|
364 |
if (link_interface_to_group($id))
|
|
365 |
$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
|
|
366 |
else if (link_interface_to_bridge($id))
|
|
367 |
$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
|
|
368 |
else if (link_interface_to_gre($id))
|
|
369 |
$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
|
|
370 |
else if (link_interface_to_gif($id))
|
|
371 |
$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
|
|
372 |
else {
|
|
373 |
unset($config['interfaces'][$id]['enable']);
|
|
374 |
$realid = get_real_interface($id);
|
|
375 |
interface_bring_down($id); /* down the interface */
|
|
376 |
|
|
377 |
unset($config['interfaces'][$id]); /* delete the specified OPTn or LAN*/
|
|
378 |
|
|
379 |
if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) {
|
|
380 |
unset($config['dhcpd'][$id]);
|
|
381 |
services_dhcpd_configure();
|
|
382 |
}
|
|
335 | 383 |
|
336 |
if (count($config['filter']['rule']) > 0) { |
|
337 |
foreach ($config['filter']['rule'] as $x => $rule) { |
|
338 |
if($rule['interface'] == $id) |
|
339 |
unset($config['filter']['rule'][$x]); |
|
384 |
if (count($config['filter']['rule']) > 0) { |
|
385 |
foreach ($config['filter']['rule'] as $x => $rule) { |
|
386 |
if($rule['interface'] == $id) |
|
387 |
unset($config['filter']['rule'][$x]); |
|
388 |
} |
|
340 | 389 |
} |
341 |
}
|
|
342 |
if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
|
|
343 |
foreach ($config['nat']['rule'] as $x => $rule) {
|
|
344 |
if($rule['interface'] == $id)
|
|
345 |
unset($config['nat']['rule'][$x]['interface']);
|
|
390 |
if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
|
|
391 |
foreach ($config['nat']['rule'] as $x => $rule) {
|
|
392 |
if($rule['interface'] == $id)
|
|
393 |
unset($config['nat']['rule'][$x]['interface']);
|
|
394 |
}
|
|
346 | 395 |
} |
347 |
} |
|
348 | 396 |
|
349 |
write_config(); |
|
397 |
write_config();
|
|
350 | 398 |
|
351 |
/* If we are in firewall/routing mode (not single interface) |
|
352 |
* then ensure that we are not running DHCP on the wan which |
|
353 |
* will make a lot of ISP's unhappy. |
|
354 |
*/ |
|
355 |
if($config['interfaces']['lan'] && $config['dhcpd']['wan']) { |
|
356 |
unset($config['dhcpd']['wan']); |
|
357 |
} |
|
399 |
/* If we are in firewall/routing mode (not single interface)
|
|
400 |
* then ensure that we are not running DHCP on the wan which
|
|
401 |
* will make a lot of ISP's unhappy.
|
|
402 |
*/
|
|
403 |
if($config['interfaces']['lan'] && $config['dhcpd']['wan']) {
|
|
404 |
unset($config['dhcpd']['wan']);
|
|
405 |
}
|
|
358 | 406 |
|
359 |
link_interface_to_vlans($realid, "update"); |
|
407 |
link_interface_to_vlans($realid, "update");
|
|
360 | 408 |
|
361 |
$savemsg = gettext("Interface has been deleted."); |
|
362 |
} |
|
363 |
} |
|
364 |
|
|
365 |
if ($_GET['act'] == "add" && (count($config['interfaces']) < count($portlist))) { |
|
366 |
/* find next free optional interface number */ |
|
367 |
if(!$config['interfaces']['lan']) { |
|
368 |
$newifname = gettext("lan"); |
|
369 |
$descr = gettext("LAN"); |
|
370 |
$config['interfaces'][$newifname] = array(); |
|
371 |
$config['interfaces'][$newifname]['descr'] = $descr; |
|
372 |
} else { |
|
373 |
for ($i = 1; $i <= count($config['interfaces']); $i++) { |
|
374 |
if (!$config['interfaces']["opt{$i}"]) |
|
375 |
break; |
|
409 |
$savemsg = gettext("Interface has been deleted."); |
|
376 | 410 |
} |
377 |
$newifname = 'opt' . $i; |
|
378 |
$descr = "OPT" . $i; |
|
379 |
$config['interfaces'][$newifname] = array(); |
|
380 |
$config['interfaces'][$newifname]['descr'] = $descr; |
|
381 | 411 |
} |
412 |
} |
|
382 | 413 |
|
383 |
uksort($config['interfaces'], "compare_interface_friendly_names"); |
|
384 |
|
|
385 |
/* Find an unused port for this interface */ |
|
386 |
foreach ($portlist as $portname => $portinfo) { |
|
387 |
$portused = false; |
|
388 |
foreach ($config['interfaces'] as $ifname => $ifdata) { |
|
389 |
if ($ifdata['if'] == $portname) { |
|
390 |
$portused = true; |
|
391 |
break; |
|
392 |
} |
|
393 |
} |
|
394 |
if (!$portused) { |
|
395 |
$config['interfaces'][$newifname]['if'] = $portname; |
|
396 |
if (preg_match($g['wireless_regex'], $portname)) { |
|
397 |
$config['interfaces'][$newifname]['wireless'] = array(); |
|
398 |
interface_sync_wireless_clones($config['interfaces'][$newifname], false); |
|
399 |
} |
|
414 |
/* Create a list of unused ports */ |
|
415 |
$unused_portlist = array(); |
|
416 |
foreach ($portlist as $portname => $portinfo) { |
|
417 |
$portused = false; |
|
418 |
foreach ($config['interfaces'] as $ifname => $ifdata) { |
|
419 |
if ($ifdata['if'] == $portname) { |
|
420 |
$portused = true; |
|
400 | 421 |
break; |
401 | 422 |
} |
402 | 423 |
} |
403 |
|
|
404 |
/* XXX: Do not remove this. */ |
|
405 |
unlink_if_exists("{$g['tmp_path']}/config.cache"); |
|
406 |
|
|
407 |
write_config(); |
|
408 |
|
|
409 |
$savemsg = gettext("Interface has been added."); |
|
410 |
|
|
411 |
} else if ($_GET['act'] == "add") |
|
412 |
$input_errors[] = "No more interfaces available to be assigned."; |
|
424 |
if ($portused === false) |
|
425 |
$unused_portlist[$portname] = $portinfo; |
|
426 |
} |
|
413 | 427 |
|
414 | 428 |
include("head.inc"); |
415 | 429 |
|
... | ... | |
493 | 507 |
<?php |
494 | 508 |
if ($ifname != 'wan'): |
495 | 509 |
?> |
496 |
<a href="interfaces_assign.php?act=del&id=<?=$ifname;?>" onclick="return confirm('<?=gettext("Do you really want to delete this interface?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete interface"); ?>" width="17" height="17" border="0" alt="delete" /></a> |
|
510 |
<input name="del_<?=$ifname;?>" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" |
|
511 |
title="<?=gettext("delete interface");?>" |
|
512 |
type="image" style="height:17;width:17;border:0" |
|
513 |
onclick="return confirm('<?=gettext("Do you really want to delete this interface?"); ?>')" /> |
|
497 | 514 |
<?php |
498 | 515 |
endif; |
499 | 516 |
?> |
... | ... | |
504 | 521 |
if (count($config['interfaces']) < count($portlist)): |
505 | 522 |
?> |
506 | 523 |
<tr> |
507 |
<td class="list" colspan="2"></td> |
|
508 |
<td class="list nowrap"> |
|
509 |
<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add interface"); ?>" width="17" height="17" border="0" alt="add" /></a> |
|
524 |
<td class="list"> |
|
525 |
<strong><?=gettext("Available network ports:");?></strong> |
|
510 | 526 |
</td> |
511 |
</tr> |
|
527 |
<td class="list"> |
|
528 |
<select name="if_add" id="if_add"> |
|
512 | 529 |
<?php |
513 |
else:
|
|
530 |
foreach ($unused_portlist as $portname => $portinfo):
|
|
514 | 531 |
?> |
515 |
<tr> |
|
516 |
<td class="list" colspan="3" height="10"></td> |
|
532 |
<option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo " selected=\"selected\"";?>> |
|
533 |
<?=interface_assign_description($portinfo, $portname);?> |
|
534 |
</option> |
|
535 |
<?php |
|
536 |
endforeach; |
|
537 |
?> |
|
538 |
</select> |
|
539 |
</td> |
|
540 |
<td class="list"> |
|
541 |
<input name="add" type="image" src="/themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" style="width:17;height:17;border:0" title="<?=gettext("add selected interface");?>" /> |
|
542 |
</td> |
|
517 | 543 |
</tr> |
518 | 544 |
<?php |
519 | 545 |
endif; |
... | ... | |
521 | 547 |
</table> |
522 | 548 |
</div> |
523 | 549 |
<br /> |
524 |
<div id='savediv' <?php if (empty($_GET['act'])) echo "style='display:none;'"; ?>>
|
|
550 |
<div id='savediv' style='display:none'>
|
|
525 | 551 |
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /><br /><br /> |
526 | 552 |
</div> |
527 | 553 |
<ul> |
Formats disponibles : Unified diff
Improvements on interfaces_assign.php:
- Let user select network port to add instead of pick the first
available, it fixes #3846
- While I'm here, drop GET and use only POST