#!/usr/local/bin/php -f . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* parse the configuration and include all functions used below */ require_once("config.inc"); require_once("functions.inc"); $fp = fopen('php://stdin', 'r'); $addr_blank = false; /* build an interface collection */ $ifdescrs = array ("wan"); if($config['interfaces']['lan']) { $ifdescrs[] = "lan"; } for ($j = 1; isset ($config['interfaces']['opt' . $j]); $j++) { if(isset($config['interfaces']['opt' . $j]['enable'])) $ifdescrs['opt' . $j] = filter_get_opt_interface_descr("opt" . $j); } if($config['interfaces']['lan']) $j++; // incriment for wan $j++; /* grab interface that we will operate on */ echo "Available interfaces:\n\n"; $x=1; foreach($ifdescrs as $iface) { echo "{$x} - " . strtoupper($iface) . "\n"; $x++; } echo "\nEnter interface # that you would like to configure: "; $intnum = chop(fgets($fp)); if($intnum < 1) exit; if($intnum > $j) exit; $interface = $ifdescrs[$intnum-1]; if(!$interface) { echo "Invalid interface!\n"; exit; } do { if($interface == "wan") { echo gettext("Would you like to enable DHCP on the {$interface} Press or n for no:") . "\n> "; $intdhcp = chop(fgets($fp)); if(strtolower($intdhcp) == "y" || strtolower($intdhcp) == "yes") { $intip = "DHCP"; $intbits = ""; $isintdhcp = true; } } if($isintdhcp == false or $interface <> "wan") { do { echo "\n" . gettext("Enter the new {$interface} IPv4 address. Press for none:") . "\n> "; $intip = chop(fgets($fp)); $addr_blank = false; } while (!(is_ipaddr($intip) || $intip == '')); } if ($intip != '') { echo "\n" . gettext("Subnet masks are entered as bit counts (as in CIDR notation) in {$g['product_name']}.") . "\n"; echo "e.g. 255.255.255.0 = 24\n"; echo " 255.255.0.0 = 16\n"; echo " 255.0.0.0 = 8\n"; do { echo "\n" . gettext("Enter the new {$interface} IPv4 subnet bit count:") . "\n> "; $intbits = chop(fgets($fp)); } while (!is_numeric($intbits) || ($intbits < 1) || ($intbits > 31)); } } while ($addr_blank); $config['interfaces'][$interface]['ipaddr'] = $intip; $config['interfaces'][$interface]['subnet'] = $intbits; if($interface <> "wan") { do { $good = false; echo "\n" . gettext("Do you want to enable the DHCP server on {$interface} [y|n]?") . " "; $yn = strtolower(chop(fgets($fp))); if ($yn[0] == "y" or $yn[0] == "n") $good = true; } while (!$good); } else { $yn = "n"; } // TODO: Add DHCP IPv6 support if ($yn == "y") { do { echo gettext("Enter the start address of the client address range:") . " "; $dhcpstartip = chop(fgets($fp)); if ($dhcpstartip === "") { fclose($fp); exit(0); } } while (!(is_ipaddr($dhcpstartip))); do { echo gettext("Enter the end address of the client address range:") . " "; $dhcpendip = chop(fgets($fp)); if ($dhcpendip === "") { fclose($fp); exit(0); } } while (!(is_ipaddr($dhcpendip))); $config['dhcpd'][$interface]['enable'] = true; $config['dhcpd'][$interface]['range']['from'] = $dhcpstartip; $config['dhcpd'][$interface]['range']['to'] = $dhcpendip; } else { unset($config['dhcpd'][$interface]['enable']); } if ($config['system']['webgui']['protocol'] == "https") { do { $good = false; echo "\n" . gettext("Do you want to revert to HTTP as the webConfigurator protocol? (y/n)") . " "; $yn = strtolower(chop(fgets($fp))); if ($yn[0] == "y" or $yn[0] == "n") $good = true; } while (!$good); if ($yn == "y") $config['system']['webgui']['protocol'] = "http"; } if (isset($config['system']['webgui']['noantilockout'])) { echo "\n" . gettext("Note: the anti-lockout rule on {$interface} has been re-enabled.") . "\n"; unset($config['system']['webgui']['noantilockout']); } if($config['interfaces']['lan']) { unset($config['dhcpd']['wan']); } if(!$config['interfaces']['lan']) { unset($config['interfaces']['lan']); unset($config['dhcpd']['lan']); unset($config['shaper']); unset($config['ezshaper']); unset($config['nat']); system("rm /var/dhcpd/var/db/*"); services_dhcpd_configure(); } echo "\nPlease wait, saving your changes to {$interface}..."; write_config(gettext("{$interface} IP configuration from console menu")); interfaces_lan_configure(); echo " Reloading filter..."; filter_configure_sync(); echo "\n"; if ($intip != '') { echo "\n\n" . gettext("The IPv4 {$interface} address has been set to ") . "{$intip}/{$intbits}\n" ; echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n"; echo " {$config['system']['webgui']['protocol']}://{$intip}/\n"; } echo "\n" . gettext('Press to continue.'); fgets($fp); fclose($fp); ?>