Copyright (C) 2006 Daniel S. Haischt Copyright (C) 2003-2004 Manuel Kasper 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. */ require_once("guiconfig.inc"); require_once("filter.inc"); require_once("rrd.inc"); require_once("system.inc"); require_once("interfaces.inc"); require_once("services.inc"); /*************************************************************************************************************** * imported from xmlparse_attr.inc ***************************************************************************************************************/ function startElement_attr($parser, $name, $attrs) { global $parsedcfg, $depth, $curpath, $havedata, $listtags, $parsedattrs; array_push($curpath, strtolower($name)); $ptr =& $parsedcfg; if (!empty($attrs)) { $attrptr =& $parsedattrs; $writeattrs = true; } foreach ($curpath as $path) { $ptr =& $ptr[$path]; if (isset($writeattrs)) { $attrptr =& $attrptr[$path]; } } /* is it an element that belongs to a list? */ if (in_array(strtolower($name), $listtags)) { /* is there an array already? */ if (!is_array($ptr)) { /* make an array */ $ptr = array(); } array_push($curpath, count($ptr)); if (isset($writeattrs)) { if (!is_array($attrptr)) { $attrptr = array(); } $attrptr[count($ptr)] = $attrs; } } else if (isset($ptr)) { /* multiple entries not allowed for this element, bail out */ die(sprintf(gettext('XML error: %s at line %d cannot occur more than once') . "\n", $name, xml_get_current_line_number($parser))); } else if (isset($writeattrs)) { $attrptr = $attrs; } $depth++; $havedata = $depth; } function endElement_attr($parser, $name) { global $depth, $curpath, $parsedcfg, $havedata, $listtags; if ($havedata == $depth) { $ptr =& $parsedcfg; foreach ($curpath as $path) { $ptr =& $ptr[$path]; } $ptr = ""; } array_pop($curpath); if (in_array(strtolower($name), $listtags)) { array_pop($curpath); } $depth--; } function cData_attr($parser, $data) { global $depth, $curpath, $parsedcfg, $havedata; $data = trim($data, "\t\n\r"); if ($data != "") { $ptr =& $parsedcfg; foreach ($curpath as $path) { $ptr =& $ptr[$path]; } if (is_string($ptr)) { $ptr .= html_entity_decode($data); } else { if (trim($data, " ") != "") { $ptr = html_entity_decode($data); $havedata++; } } } } function parse_xml_regdomain(&$rdattributes, $rdfile = '', $rootobj = 'regulatory-data') { global $listtags; if (empty($rdfile)) { $rdfile = '/etc/regdomain.xml'; } $listtags = explode(" ", "band country flags freqband netband rd"); $parsed_xml = array(); if (file_exists('/tmp/regdomain.cache')) { $parsed_xml = unserialize(file_get_contents('/tmp/regdomain.cache')); if (!empty($parsed_xml)) { $rdmain = $parsed_xml['main']; $rdattributes = $parsed_xml['attributes']; } } if (empty($parsed_xml) && file_exists('/etc/regdomain.xml')) { $rdmain = parse_xml_config_raw_attr($rdfile, $rootobj, $rdattributes); // unset parts that aren't used before making cache foreach ($rdmain['regulatory-domains']['rd'] as $rdkey => $rdentry) { if (isset($rdmain['regulatory-domains']['rd'][$rdkey]['netband'])) { unset($rdmain['regulatory-domains']['rd'][$rdkey]['netband']); } if (isset($rdattributes['regulatory-domains']['rd'][$rdkey]['netband'])) { unset($rdattributes['regulatory-domains']['rd'][$rdkey]['netband']); } } if (isset($rdmain['shared-frequency-bands'])) { unset($rdmain['shared-frequency-bands']); } if (isset($rdattributes['shared-frequency-bands'])) { unset($rdattributes['shared-frequency-bands']); } $parsed_xml = array('main' => $rdmain, 'attributes' => $rdattributes); $rdcache = fopen('/tmp/regdomain.cache', 'w'); fwrite($rdcache, serialize($parsed_xml)); fclose($rdcache); } return $rdmain; } function parse_xml_config_raw_attr($cffile, $rootobj, &$parsed_attributes, $isstring = "false") { global $depth, $curpath, $parsedcfg, $havedata, $listtags, $parsedattrs; $parsedcfg = array(); $curpath = array(); $depth = 0; $havedata = 0; if (isset($parsed_attributes)) { $parsedattrs = array(); } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement_attr", "endElement_attr"); xml_set_character_data_handler($xml_parser, "cData_attr"); xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE, 1); if (!($fp = fopen($cffile, "r"))) { log_error('Error: could not open XML input'); if (isset($parsed_attributes)) { $parsed_attributes = array(); unset($parsedattrs); } return -1; } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { log_error(sprintf('XML error: %s at line %d' . "\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); if (isset($parsed_attributes)) { $parsed_attributes = array(); unset($parsedattrs); } return -1; } } xml_parser_free($xml_parser); if (!$parsedcfg[$rootobj]) { log_error(sprintf('XML error: no %s object found!', $rootobj)); if (isset($parsed_attributes)) { $parsed_attributes = array(); unset($parsedattrs); } return -1; } if (isset($parsed_attributes)) { if ($parsedattrs[$rootobj]) { $parsed_attributes = $parsedattrs[$rootobj]; } unset($parsedattrs); } return $parsedcfg[$rootobj]; } /*************************************************************************************************************** * End of import ***************************************************************************************************************/ function get_wireless_modes($interface) { /* return wireless modes and channels */ $wireless_modes = array(); $cloned_interface = get_real_interface($interface); if ($cloned_interface && is_interface_wireless($cloned_interface)) { $chan_list = "/sbin/ifconfig {$cloned_interface} list chan"; $stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'"; $format_list = "/usr/bin/awk '{print \$5 \" \" \$6 \",\" \$1}'"; $interface_channels = ""; exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels); $interface_channel_count = count($interface_channels); $c = 0; while ($c < $interface_channel_count) { $channel_line = explode(",", $interface_channels["$c"]); $wireless_mode = trim($channel_line[0]); $wireless_channel = trim($channel_line[1]); if (trim($wireless_mode) != "") { /* if we only have 11g also set 11b channels */ if ($wireless_mode == "11g") { if (!isset($wireless_modes["11b"])) { $wireless_modes["11b"] = array(); } } else if ($wireless_mode == "11g ht") { if (!isset($wireless_modes["11b"])) { $wireless_modes["11b"] = array(); } elseif (!isset($wireless_modes["11g"])) { $wireless_modes["11g"] = array(); } $wireless_mode = "11ng"; } else if ($wireless_mode == "11a ht") { if (!isset($wireless_modes["11a"])) { $wireless_modes["11a"] = array(); } $wireless_mode = "11na"; } $wireless_modes["$wireless_mode"]["$c"] = $wireless_channel; } $c++; } } return($wireless_modes); } /* return channel numbers, frequency, max txpower, and max regulation txpower */ function get_wireless_channel_info($interface) { $wireless_channels = array(); $cloned_interface = get_real_interface($interface); if ($cloned_interface && is_interface_wireless($cloned_interface)) { $chan_list = "/sbin/ifconfig {$cloned_interface} list txpower"; $stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'"; $format_list = "/usr/bin/awk '{print \$1 \",\" \$3 \" \" \$4 \",\" \$5 \",\" \$7}'"; $interface_channels = ""; exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels); foreach ($interface_channels as $channel_line) { $channel_line = explode(",", $channel_line); if (!isset($wireless_channels[$channel_line[0]])) { $wireless_channels[$channel_line[0]] = $channel_line; } } } return($wireless_channels); } // Get configured interface list $ifdescrs = get_configured_interface_with_descr(false, true); // reference to interface section $a_interfaces = &config_read_array('interfaces'); $a_ppps = &config_read_array('ppps', 'ppp'); if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($_GET['if']) && !empty($a_interfaces[$_GET['if']])) { $if = $_GET['if']; } else { // no interface provided, redirect to interface assignments header(url_safe('Location: /interfaces_assign.php')); exit; } $pconfig = array(); $std_copy_fieldnames = array( "if", "descr", "dhcphostname", "alias-address", "alias-subnet", "dhcprejectfrom", "ipaddr", "subnet", "gateway", "ipaddrv6", "media", "mediaopt", "adv_dhcp_pt_timeout", "adv_dhcp_pt_retry", "adv_dhcp_pt_select_timeout", "adv_dhcp_pt_reboot", "adv_dhcp_pt_backoff_cutoff", "adv_dhcp_pt_initial_interval", "adv_dhcp_pt_values", "adv_dhcp_send_options", "adv_dhcp_request_options", "adv_dhcp_required_options", "adv_dhcp_option_modifiers", "adv_dhcp_config_advanced", "adv_dhcp_config_file_override", "adv_dhcp_config_file_override_path", "adv_dhcp6_interface_statement_send_options", "adv_dhcp6_interface_statement_request_options", "adv_dhcp6_interface_statement_information_only_enable", "adv_dhcp6_interface_statement_script", "adv_dhcp6_id_assoc_statement_address_enable", "adv_dhcp6_id_assoc_statement_address", "adv_dhcp6_id_assoc_statement_address_id", "adv_dhcp6_id_assoc_statement_address_pltime", "adv_dhcp6_id_assoc_statement_address_vltime", "adv_dhcp6_id_assoc_statement_prefix_enable", "adv_dhcp6_id_assoc_statement_prefix", "adv_dhcp6_id_assoc_statement_prefix_id", "adv_dhcp6_id_assoc_statement_prefix_pltime", "adv_dhcp6_id_assoc_statement_prefix_vltime", "adv_dhcp6_prefix_interface_statement_sla_id", "adv_dhcp6_prefix_interface_statement_sla_len", "adv_dhcp6_authentication_statement_authname", "adv_dhcp6_authentication_statement_protocol", "adv_dhcp6_authentication_statement_algorithm", "adv_dhcp6_authentication_statement_rdm", "adv_dhcp6_key_info_statement_keyname", "adv_dhcp6_key_info_statement_realm", "adv_dhcp6_key_info_statement_keyid", "adv_dhcp6_key_info_statement_secret", "adv_dhcp6_key_info_statement_expire", "adv_dhcp6_config_advanced", "adv_dhcp6_config_file_override", "adv_dhcp6_config_file_override_path", "spoofmac", "mtu", "mss", 'dhcp6vlanprio', "dhcp6-ia-pd-len", "track6-interface", "track6-prefix-id", "prefix-6rd", "prefix-6rd-v4plen", "gateway-6rd", "ipaddrv6", "subnetv6", "gatewayv6" ); foreach ($std_copy_fieldnames as $fieldname) { $pconfig[$fieldname] = isset($a_interfaces[$if][$fieldname]) ? $a_interfaces[$if][$fieldname] : null; } $pconfig['enable'] = isset($a_interfaces[$if]['enable']); $pconfig['lock'] = isset($a_interfaces[$if]['lock']); $pconfig['blockpriv'] = isset($a_interfaces[$if]['blockpriv']); $pconfig['blockbogons'] = isset($a_interfaces[$if]['blockbogons']); $pconfig['dhcp6-ia-pd-send-hint'] = isset($a_interfaces[$if]['dhcp6-ia-pd-send-hint']); $pconfig['dhcp6sendsolicit'] = isset($a_interfaces[$if]['dhcp6sendsolicit']); $pconfig['dhcp6prefixonly'] = isset($a_interfaces[$if]['dhcp6prefixonly']); $pconfig['dhcp6usev4iface'] = isset($a_interfaces[$if]['dhcp6usev4iface']); $pconfig['dhcp6norelease'] = isset($a_interfaces[$if]['dhcp6norelease']); // Due to the settings being split per interface type, we need to copy the settings that use the same // config directive. $pconfig['staticv6usev4iface'] = $pconfig['dhcp6usev4iface']; $pconfig['adv_dhcp6_debug'] = isset($a_interfaces[$if]['adv_dhcp6_debug']); $pconfig['track6-prefix-id--hex'] = sprintf("%x", empty($pconfig['track6-prefix-id']) ? 0 :$pconfig['track6-prefix-id']); // ipv4 type (from ipaddr) if (is_ipaddrv4($pconfig['ipaddr'])) { $pconfig['type'] = "staticv4"; } else { if (empty($pconfig['ipaddr'])) { $pconfig['type'] = "none"; } else { $pconfig['type'] = $pconfig['ipaddr']; } $pconfig['ipaddr'] = null; } // ipv6 type (from ipaddrv6) if (is_ipaddrv6($pconfig['ipaddrv6'])) { $pconfig['type6'] = "staticv6"; } else { if (empty($pconfig['ipaddrv6'])) { $pconfig['type6'] = "none"; } else { $pconfig['type6'] = $pconfig['ipaddrv6']; } $pconfig['ipaddrv6'] = null; } /* locate PPP details (if any) */ $pppid = count($a_ppps); foreach ($a_ppps as $key => $ppp) { if ($a_interfaces[$if]['if'] == $ppp['if']) { $pppid = $key; break; } } $std_ppp_copy_fieldnames = array("ptpid", "ports", "username", "phone", "apn", "provider", "idletimeout", "localip", 'hostuniq'); foreach ($std_ppp_copy_fieldnames as $fieldname) { $pconfig[$fieldname] = isset($a_ppps[$pppid][$fieldname]) ? $a_ppps[$pppid][$fieldname] : null; } $pconfig['password'] = base64_decode($a_ppps[$pppid]['password']); // ppp password field $pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']); $pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']); $pconfig['pppoe_password'] = $pconfig['password']; // pppoe password field $pconfig['pppoe_username'] = $pconfig['username']; $pconfig['pppoe_hostuniq'] = $pconfig['hostuniq']; $pconfig['pppoe_idletimeout'] = $pconfig['idletimeout']; $pconfig['pptp_username'] = $pconfig['username']; $pconfig['pptp_password'] = $pconfig['password']; $pconfig['pptp_subnet'] = $a_ppps[$pppid]['subnet']; $pconfig['pptp_remote'] = $a_ppps[$pppid]['gateway']; $pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout']; if (isset($a_ppps[$pppid])) { $pconfig['pppid'] = $pppid; } else { $pconfig['ptpid'] = interfaces_ptpid_next(); $pppid = count($a_ppps); } /* Wireless interface */ if (isset($a_interfaces[$if]['wireless'])) { /* Sync first to be sure it displays the actual settings that will be used */ interface_sync_wireless_clones($a_interfaces[$if], false); /* Get wireless modes */ $wlanif = get_real_interface($if); if (!does_interface_exist($wlanif)) { interface_wireless_clone($wlanif, $a_interfaces[$if]); } $wlanbaseif = interface_get_wireless_base($a_interfaces[$if]['if']); $std_wl_copy_fieldnames = array( 'standard', 'mode','protmode', 'ssid', 'channel', 'txpower', 'diversity', 'txantenna', 'rxantenna', 'regdomain', 'regcountry', 'reglocation', 'authmode', 'auth_server_addr', 'auth_server_port', 'auth_server_shared_secret', 'auth_server_addr2', 'auth_server_port2', 'auth_server_shared_secret2', 'mac_acl' ); foreach ($std_wl_copy_fieldnames as $fieldname) { $pconfig[$fieldname] = isset($a_interfaces[$if]['wireless'][$fieldname]) ? $a_interfaces[$if]['wireless'][$fieldname] : null; } $pconfig['persistcommonwireless'] = isset($config['wireless']['interfaces'][$wlanbaseif]); $pconfig['wme_enable'] = isset($a_interfaces[$if]['wireless']['wme']['enable']); $pconfig['apbridge_enable'] = isset($a_interfaces[$if]['wireless']['apbridge']['enable']); $pconfig['hidessid_enable'] = isset($a_interfaces[$if]['wireless']['hidessid']['enable']); $pconfig['wep_enable'] = isset($a_interfaces[$if]['wireless']['wep']['enable']); if (isset($a_interfaces[$if]['wireless']['puren']['enable'])) { $pconfig['puremode'] = '11n'; } elseif (isset($a_interfaces[$if]['wireless']['pureg']['enable'])) { $pconfig['puremode'] = '11g'; } else { $pconfig['puremode'] = 'any'; } if (isset($a_interfaces[$if]['wireless']['wpa']) && is_array($a_interfaces[$if]['wireless']['wpa'])) { $std_wl_wpa_copy_fieldnames = array( 'debug_mode', 'macaddr_acl', 'auth_algs', 'wpa_mode', 'wpa_key_mgmt', 'wpa_pairwise', 'wpa_group_rekey', 'wpa_gmk_rekey', 'passphrase', 'ext_wpa_sw' ); foreach ($std_wl_wpa_copy_fieldnames as $fieldname) { $pconfig[$fieldname] = isset($a_interfaces[$if]['wireless']['wpa'][$fieldname]) ? $a_interfaces[$if]['wireless']['wpa'][$fieldname] : null; } $pconfig['ieee8021x'] = isset($a_interfaces[$if]['wireless']['wpa']['ieee8021x']['enable']); $pconfig['rsn_preauth'] = isset($a_interfaces[$if]['wireless']['wpa']['rsn_preauth']); $pconfig['mac_acl_enable'] = isset($a_interfaces[$if]['wireless']['wpa']['mac_acl_enable']); $pconfig['wpa_strict_rekey'] = isset($a_interfaces[$if]['wireless']['wpa']['wpa_strict_rekey']); $pconfig['wpa_enable'] = isset($a_interfaces[$if]['wireless']['wpa']['enable']); } if (is_array($a_interfaces[$if]['wireless']['wep']) && is_array($a_interfaces[$if]['wireless']['wep']['key'])) { $i = 1; foreach ($a_interfaces[$if]['wireless']['wep']['key'] as $wepkey) { $pconfig['key' . $i] = $wepkey['value']; if (isset($wepkey['txkey'])) { $pconfig['txkey'] = $i; } $i++; } if (!isset($wepkey['txkey'])) { $pconfig['txkey'] = 1; } } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $pconfig = $_POST; $input_errors = array(); if (!empty($_POST['if']) && !empty($a_interfaces[$_POST['if']])) { $if = $_POST['if']; // read physcial interface name from config.xml $pconfig['if'] = $a_interfaces[$if]['if']; } if (!empty($pconfig['apply'])) { if (!is_subsystem_dirty('interfaces')) { $intput_errors[] = gettext("You have already applied your settings!"); } else { clear_subsystem_dirty('interfaces'); if (file_exists('/tmp/.interfaces.apply')) { $toapplylist = unserialize(file_get_contents('/tmp/.interfaces.apply')); foreach ($toapplylist as $ifapply => $ifcfgo) { if (isset($config['interfaces'][$ifapply]['enable'])) { interface_bring_down($ifapply, $ifcfgo); interface_configure($ifapply, true); } else { interface_bring_down($ifapply, $ifcfgo); } } } /* * XXX possibly wrong to configure interfaces through newwanip * when the interface is dynamic and this gets called again... */ plugins_configure('newwanip'); /* sync filter configuration */ setup_gateways_monitor(); filter_configure(); rrd_configure(); if (is_subsystem_dirty('staticroutes') && (system_routing_configure() == 0)) { clear_subsystem_dirty('staticroutes'); } } @unlink('/tmp/.interfaces.apply'); header(url_safe('Location: /interfaces.php?if=%s', array($if))); exit; } elseif (empty($pconfig['enable'])) { if (isset($a_interfaces[$if]['enable'])) { unset($a_interfaces[$if]['enable']); } if (!empty($pconfig['lock'])) { $a_interfaces[$if]['lock'] = true; } elseif (isset($a_interfaces[$if]['lock'])) { unset($a_interfaces[$if]['lock']); } if (isset($a_interfaces[$if]['wireless'])) { interface_sync_wireless_clones($a_interfaces[$if], false); } write_config("Interface {$pconfig['descr']}({$if}) is now disabled."); mark_subsystem_dirty('interfaces'); if (file_exists('/tmp/.interfaces.apply')) { $toapplylist = unserialize(file_get_contents('/tmp/.interfaces.apply')); } else { $toapplylist = array(); } $toapplylist[$if]['ifcfg'] = $a_interfaces[$if]; $toapplylist[$if]['ppps'] = $a_ppps; /* we need to be able remove IP aliases for IPv6 */ file_put_contents('/tmp/.interfaces.apply', serialize($toapplylist)); header(url_safe('Location: /interfaces.php?if=%s', array($if))); exit; } else { // locate sequence in ppp list $pppid = count($a_ppps); foreach ($a_ppps as $key => $ppp) { if ($a_interfaces[$if]['if'] == $ppp['if']) { $pppid = $key; break; } } $old_ppps = $a_ppps; // perform validations if (isset($config['aliases']['alias'])) { foreach($config['aliases']['alias'] as $alias) { if ($alias['name'] == $pconfig['descr']) { $input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."),$pconfig['descr']); } } } /* description unique? */ foreach ($ifdescrs as $ifent => $ifdescr) { if ($if != $ifent && $ifdescr == $pconfig['descr']) { $input_errors[] = gettext("An interface with the specified description already exists."); break; } } /* input validation */ if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (! preg_match("/^staticv4/", $pconfig['type']))) { $input_errors[] = gettext("The DHCP Server is active on this interface and it can be used only with a static IP configuration. Please disable the DHCP Server service on this interface first, then change the interface configuration."); } if (isset($config['dhcpdv6']) && isset($config['dhcpdv6'][$if]['enable']) && (! preg_match("/^staticv6/", $pconfig['type6']))) { $input_errors[] = gettext("The DHCPv6 Server is active on this interface and it can be used only with a static IPv6 configuration. Please disable the DHCPv6 Server service on this interface first, then change the interface configuration."); } switch (strtolower($pconfig['type'])) { case "staticv4": $reqdfields = explode(" ", "ipaddr subnet gateway"); $reqdfieldsn = array(gettext("IPv4 address"),gettext("Subnet bit count"),gettext("Gateway")); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; case "none": if (isset($config['virtualip']['vip'])) { foreach ($config['virtualip']['vip'] as $vip) { if (is_ipaddrv4($vip['subnet']) && $vip['interface'] == $if) { $input_errors[] = gettext("This interface is referenced by IPv4 VIPs. Please delete those before setting the interface to 'none' configuration."); } } } case "dhcp": if (in_array($a_interfaces[$if]['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) { $input_errors[] = sprintf(gettext("You have to reassign the interface to be able to configure as %s."),$pconfig['type']); } if (!empty($pconfig['adv_dhcp_config_file_override'] && !file_exists($pconfig['adv_dhcp_config_file_override_path']))) { $input_errors[] = sprintf(gettext('The DHCP override file "%s" does not exist.'), $pconfig['adv_dhcp_config_file_override_path']); } break; case "ppp": $reqdfields = explode(" ", "ports phone"); $reqdfieldsn = array(gettext("Modem Port"),gettext("Phone Number")); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; case "pppoe": if (!empty($pconfig['pppoe_dialondemand'])) { $reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout"); $reqdfieldsn = array(gettext("PPPoE username"),gettext("PPPoE password"),gettext("Dial on demand"),gettext("Idle timeout value")); } else { $reqdfields = explode(" ", "pppoe_username pppoe_password"); $reqdfieldsn = array(gettext("PPPoE username"),gettext("PPPoE password")); } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; case "pptp": if (!empty($pconfig['pptp_dialondemand'])) { $reqdfields = explode(" ", "pptp_username pptp_password localip pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout"); $reqdfieldsn = array(gettext("PPTP username"),gettext("PPTP password"),gettext("PPTP local IP address"),gettext("PPTP subnet"),gettext("PPTP remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value")); } else { $reqdfields = explode(" ", "pptp_username pptp_password localip pptp_subnet pptp_remote"); $reqdfieldsn = array(gettext("PPTP username"),gettext("PPTP password"),gettext("PPTP local IP address"),gettext("PPTP subnet"),gettext("PPTP remote IP address")); } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; case "l2tp": if (!empty($pconfig['pptp_dialondemand'])) { $reqdfields = explode(" ", "pptp_username pptp_password pptp_remote pptp_dialondemand pptp_idletimeout"); $reqdfieldsn = array(gettext("L2TP username"),gettext("L2TP password"),gettext("L2TP remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value")); } else { $reqdfields = explode(" ", "pptp_username pptp_password pptp_remote"); $reqdfieldsn = array(gettext("L2TP username"),gettext("L2TP password"),gettext("L2TP remote IP address")); } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; } switch (strtolower($pconfig['type6'])) { case "staticv6": $reqdfields = explode(" ", "ipaddrv6 subnetv6 gatewayv6"); $reqdfieldsn = array(gettext("IPv6 address"),gettext("Subnet bit count"),gettext("Gateway")); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); break; case "dhcp6": if (!empty($pconfig['adv_dhcp6_config_file_override'] && !file_exists($pconfig['adv_dhcp6_config_file_override_path']))) { $input_errors[] = sprintf(gettext('The DHCPv6 override file "%s" does not exist.'), $pconfig['adv_dhcp6_config_file_override_path']); } break; case "none": if (isset($config['virtualip']['vip'])) { foreach ($config['virtualip']['vip'] as $vip) { if (is_ipaddrv6($vip['subnet']) && $vip['interface'] == $if) { $input_errors[] = gettext("This interface is referenced by IPv6 VIPs. Please delete those before setting the interface to 'none' configuration."); } } } break; case "6rd": foreach ($ifdescrs as $ifent => $ifdescr) { if ($if != $ifent && ($config[interfaces][$ifent]['ipaddrv6'] == $pconfig['type6'])) { if ($config[interfaces][$ifent]['prefix-6rd'] == $pconfig['prefix-6rd']) { $input_errors[] = gettext("You can only have one interface configured in 6rd with same prefix."); break; } } } break; case "6to4": foreach ($ifdescrs as $ifent => $ifdescr) { if ($if != $ifent && ($config[interfaces][$ifent]['ipaddrv6'] == $pconfig['type6'])) { $input_errors[] = sprintf(gettext("You can only have one interface configured as 6to4."), $pconfig['type6']); break; } } break; case "track6": if (!empty($pconfig['track6-prefix-id--hex']) && !ctype_xdigit($pconfig['track6-prefix-id--hex'])) { $input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID."); } elseif (!empty($pconfig['track6-interface'])) { $ipv6_delegation_length = calculate_ipv6_delegation_length($pconfig['track6-interface']); $ipv6_num_prefix_ids = pow(2, $ipv6_delegation_length); $track6_prefix_id = intval($pconfig['track6-prefix-id--hex'], 16); if ($track6_prefix_id < 0 || $track6_prefix_id >= $ipv6_num_prefix_ids) { $input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range."); } } break; } /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */ $staticroutes = get_staticroutes(true); if (!empty($pconfig['ipaddr'])) { if (!is_ipaddrv4($pconfig['ipaddr'])) { $input_errors[] = gettext("A valid IPv4 address must be specified."); } else { if (is_ipaddr_configured($pconfig['ipaddr'], $if)) { $input_errors[] = gettext("This IPv4 address is being used by another interface or VIP."); } /* Do not accept network or broadcast address, except if subnet is 31 or 32 */ if ($pconfig['subnet'] < 31) { if ($pconfig['ipaddr'] == gen_subnet($pconfig['ipaddr'], $pconfig['subnet'])) { $input_errors[] = gettext("This IPv4 address is the network address and cannot be used"); } elseif ($pconfig['ipaddr'] == gen_subnet_max($pconfig['ipaddr'], $pconfig['subnet'])) { $input_errors[] = gettext("This IPv4 address is the broadcast address and cannot be used"); } } foreach ($staticroutes as $route_subnet) { list($network, $subnet) = explode("/", $route_subnet); if ($pconfig['subnet'] == $subnet && $network == gen_subnet($pconfig['ipaddr'], $pconfig['subnet'])) { $input_errors[] = gettext("This IPv4 address conflicts with a Static Route."); break; } unset($network, $subnet); } } } if (!empty($pconfig['ipaddrv6'])) { if (!is_ipaddrv6($pconfig['ipaddrv6'])) { $input_errors[] = gettext("A valid IPv6 address must be specified."); } else { if (is_ipaddr_configured($pconfig['ipaddrv6'], $if)) { $input_errors[] = gettext("This IPv6 address is being used by another interface or VIP."); } foreach ($staticroutes as $route_subnet) { list($network, $subnet) = explode("/", $route_subnet); if ($pconfig['subnetv6'] == $subnet && $network == gen_subnetv6($pconfig['ipaddrv6'], $pconfig['subnetv6'])) { $input_errors[] = gettext("This IPv6 address conflicts with a Static Route."); break; } unset($network, $subnet); } } } if (!empty($pconfig['subnet']) && !is_numeric($pconfig['subnet'])) { $input_errors[] = gettext("A valid subnet bit count must be specified."); } if (!empty($pconfig['subnetv6']) && !is_numeric($pconfig['subnetv6'])) { $input_errors[] = gettext("A valid subnet bit count must be specified."); } if (!empty($pconfig['alias-address']) && !is_ipaddrv4($pconfig['alias-address'])) { $input_errors[] = gettext("A valid alias IP address must be specified."); } if (!empty($pconfig['alias-subnet']) && !is_numeric($pconfig['alias-subnet'])) { $input_errors[] = gettext("A valid alias subnet bit count must be specified."); } if (!empty($pconfig['dhcprejectfrom']) && !is_ipaddrv4($pconfig['dhcprejectfrom'])) { $input_errors[] = gettext("A valid alias IP address must be specified to reject DHCP Leases from."); } if ($pconfig['gateway'] != "none" || $pconfig['gatewayv6'] != "none") { $match = false; if (!empty($config['gateways']['gateway_item'])) { foreach($config['gateways']['gateway_item'] as $gateway) { if (in_array($pconfig['gateway'], $gateway)) { $match = true; } } foreach($config['gateways']['gateway_item'] as $gateway) { if (in_array($pconfig['gatewayv6'], $gateway)) { $match = true; } } } if (!$match) { $input_errors[] = gettext("A valid gateway must be specified."); } } if (!empty($pconfig['provider']) && !is_domain($pconfig['provider'])){ $input_errors[] = gettext("The service name contains invalid characters."); } if (!empty($pconfig['pppoe_idletimeout']) && !is_numericint($pconfig['pppoe_idletimeout'])) { $input_errors[] = gettext("The idle timeout value must be an integer."); } if (!empty($pconfig['localip']) && !is_ipaddrv4($pconfig['localip'])) { $input_errors[] = gettext("A valid PPTP local IP address must be specified."); } if (!empty($pconfig['pptp_subnet']) && !is_numeric($pconfig['pptp_subnet'])) { $input_errors[] = gettext("A valid PPTP subnet bit count must be specified."); } if (!empty($pconfig['pptp_remote']) && !is_ipaddrv4($pconfig['pptp_remote']) && !is_hostname($pconfig['gateway'][$iface])) { $input_errors[] = gettext("A valid PPTP remote IP address must be specified."); } if (!empty($pconfig['pptp_idletimeout']) && !is_numericint($pconfig['pptp_idletimeout'])) { $input_errors[] = gettext("The idle timeout value must be an integer."); } if (!empty($pconfig['spoofmac']) && !is_macaddr($pconfig['spoofmac'])) { $input_errors[] = gettext("A valid MAC address must be specified."); } if (!empty($pconfig['mtu'])) { if ($pconfig['mtu'] < 576 || $pconfig['mtu'] > 9000) { $input_errors[] = gettext("The MTU must be greater than 576 bytes and less than 9000."); } if (stristr($a_interfaces[$if]['if'], "_vlan")) { $parentif = get_parent_interface($a_interfaces[$if]['if'])[0]; $intf_details = legacy_interface_details($parentif); if ($intf_details['mtu'] < $pconfig['mtu']) { $input_errors[] = gettext("MTU of a vlan should not be bigger than parent interface."); } } else { foreach ($config['interfaces'] as $idx => $ifdata) { if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) { continue; } $realhwif_array = get_parent_interface($ifdata['if']); // Need code to handle MLPPP if we ever use $realhwif for MLPPP handling $parent_realhwif = $realhwif_array[0]; if ($parent_realhwif != $a_interfaces[$if]['if']) { continue; } if (isset($ifdata['mtu']) && $ifdata['mtu'] > $pconfig['mtu']) { $input_errors[] = sprintf(gettext("Interface %s (VLAN) has MTU set to a bigger value"), $ifdata['descr']); } } } } if (!empty($pconfig['mss']) && $pconfig['mss'] < 576) { $input_errors[] = gettext("The MSS must be greater than 576 bytes."); } /* Wireless interface */ if (isset($a_interfaces[$if]['wireless'])) { $reqdfields = array("mode"); $reqdfieldsn = array(gettext("Mode")); if ($pconfig['mode'] == 'hostap') { $reqdfields[] = "ssid"; $reqdfieldsn[] = gettext("SSID"); } do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); // check_wireless_mode (more wireless weirness) // validations shouldn't perform actual actions, needs serious fixing at some point if ($a_interfaces[$if]['wireless']['mode'] != $pconfig['mode']) { if (does_interface_exist(interface_get_wireless_clone($wlanbaseif))) { $clone_count = 1; } else { $clone_count = 0; } if (isset($config['wireless']['clone']) && is_array($config['wireless']['clone'])) { foreach ($config['wireless']['clone'] as $clone) { if ($clone['if'] == $wlanbaseif) { $clone_count++; } } } if ($clone_count > 1) { $wlanif = get_real_interface($if); $old_wireless_mode = $a_interfaces[$if]['wireless']['mode']; $a_interfaces[$if]['wireless']['mode'] = $pconfig['mode']; if (!interface_wireless_clone("{$wlanif}_", $a_interfaces[$if])) { $input_errors[] = sprintf(gettext("Unable to change mode to %s. You may already have the maximum number of wireless clones supported in this mode."), $wlan_modes[$a_interfaces[$if]['wireless']['mode']]); } else { mwexec("/sbin/ifconfig " . escapeshellarg($wlanif) . "_ destroy"); } } } /* loop through keys and enforce size */ for ($i = 1; $i <= 4; $i++) { if ($pconfig['key' . $i]) { if (strlen($pconfig['key' . $i]) == 5) { /* 64 bit */ continue; } elseif (strlen($pconfig['key' . $i]) == 10) { /* hex key */ if (stristr($pconfig['key' . $i], "0x") == false) { $pconfig['key' . $i] = "0x" . $pconfig['key' . $i]; } continue; } elseif (strlen($pconfig['key' . $i]) == 12) { /* hex key */ if (stristr($pconfig['key' . $i], "0x") == false) { $pconfig['key' . $i] = "0x" . $pconfig['key' . $i]; } continue; } elseif (strlen($pconfig['key' . $i]) == 13) { /* 128 bit */ continue; } elseif (strlen($pconfig['key' . $i]) == 26) { /* hex key */ if (stristr($pconfig['key' . $i], "0x") == false) $_POST['key' . $i] = "0x" . $pconfig['key' . $i]; continue; } elseif (strlen($pconfig['key' . $i]) == 28) { continue; } else { $input_errors[] = gettext("Invalid WEP key size. Sizes should be 40 (64) bit keys or 104 (128) bit."); } } } if (!empty($pconfig['passphrase'])) { $passlen = strlen($pconfig['passphrase']); if ($passlen < 8 || $passlen > 63) { $input_errors[] = gettext("The length of the passphrase should be between 8 and 63 characters."); } } } // save form data if (count($input_errors) == 0) { $old_config = $a_interfaces[$if]; $new_config = array(); $new_ppp_config = array(); // copy physical interface data (wireless is a strange case, partly managed via interface_sync_wireless_clones) $new_config["if"] = $old_config["if"]; if (!empty($old_config['wireless'])) { $new_config['wireless'] = $old_config['wireless']; } // $new_config['descr'] = preg_replace('/[^a-z_0-9]/i', '', $pconfig['descr']); $new_config['enable'] = !empty($pconfig['enable']); $new_config['lock'] = !empty($pconfig['lock']); $new_config['spoofmac'] = $pconfig['spoofmac']; $new_config['blockpriv'] = !empty($pconfig['blockpriv']); $new_config['blockbogons'] = !empty($pconfig['blockbogons']); if (!empty($pconfig['mtu'])) { $new_config['mtu'] = $pconfig['mtu']; } if (!empty($pconfig['mss'])) { $new_config['mss'] = $pconfig['mss']; } if (!empty($pconfig['mediaopt'])) { $mediaopts = explode(' ', $pconfig['mediaopt']); if (isset($mediaopts[0])) { $new_config['media'] = $mediaopts[0]; } if (isset($mediaopts[0])) { $new_config ['mediaopt'] = $mediaopts[1]; } } // switch ipv4 config by type switch($pconfig['type']) { case "staticv4": $new_config['ipaddr'] = $pconfig['ipaddr']; $new_config['subnet'] = $pconfig['subnet']; if ($pconfig['gateway'] != "none") { $new_config['gateway'] = $pconfig['gateway']; } break; case "dhcp": $new_config['ipaddr'] = "dhcp"; $new_config['dhcphostname'] = $pconfig['dhcphostname']; $new_config['alias-address'] = $pconfig['alias-address']; $new_config['alias-subnet'] = $pconfig['alias-subnet']; $new_config['dhcprejectfrom'] = $pconfig['dhcprejectfrom']; $new_config['adv_dhcp_pt_timeout'] = $pconfig['adv_dhcp_pt_timeout']; $new_config['adv_dhcp_pt_retry'] = $pconfig['adv_dhcp_pt_retry']; $new_config['adv_dhcp_pt_select_timeout'] = $pconfig['adv_dhcp_pt_select_timeout']; $new_config['adv_dhcp_pt_reboot'] = $pconfig['adv_dhcp_pt_reboot']; $new_config['adv_dhcp_pt_backoff_cutoff'] = $pconfig['adv_dhcp_pt_backoff_cutoff']; $new_config['adv_dhcp_pt_initial_interval'] = $pconfig['adv_dhcp_pt_initial_interval']; $new_config['adv_dhcp_pt_values'] = $pconfig['adv_dhcp_pt_values']; $new_config['adv_dhcp_send_options'] = $pconfig['adv_dhcp_send_options']; $new_config['adv_dhcp_request_options'] = $pconfig['adv_dhcp_request_options']; $new_config['adv_dhcp_required_options'] = $pconfig['adv_dhcp_required_options']; $new_config['adv_dhcp_option_modifiers'] = $pconfig['adv_dhcp_option_modifiers']; $new_config['adv_dhcp_config_advanced'] = $pconfig['adv_dhcp_config_advanced']; $new_config['adv_dhcp_config_file_override'] = $pconfig['adv_dhcp_config_file_override']; $new_config['adv_dhcp_config_file_override_path'] = $pconfig['adv_dhcp_config_file_override_path']; break; case "ppp": $new_config['if'] = $pconfig['type'] . $pconfig['ptpid']; $new_config['ipaddr'] = $pconfig['type']; $new_ppp_config['ptpid'] = $pconfig['ptpid']; $new_ppp_config['type'] = $pconfig['type']; $new_ppp_config['if'] = $pconfig['type'].$pconfig['ptpid']; $new_ppp_config['ports'] = $pconfig['ports']; $new_ppp_config['username'] = $pconfig['username']; $new_ppp_config['password'] = base64_encode($pconfig['password']); $new_ppp_config['phone'] = $pconfig['phone']; $new_ppp_config['apn'] = $pconfig['apn']; break; case "pppoe": $new_config['if'] = $pconfig['type'].$pconfig['ptpid']; $new_config['ipaddr'] = $pconfig['type']; $new_ppp_config['ptpid'] = $pconfig['ptpid']; $new_ppp_config['type'] = $pconfig['type']; $new_ppp_config['if'] = $pconfig['type'].$pconfig['ptpid']; if (!empty($pconfig['ppp_port'])) { $new_ppp_config['ports'] = $pconfig['ppp_port']; } else { $new_ppp_config['ports'] = $old_config['if']; } $new_ppp_config['username'] = $pconfig['pppoe_username']; $new_ppp_config['password'] = base64_encode($pconfig['pppoe_password']); if (!empty($pconfig['provider'])) { $new_ppp_config['provider'] = $pconfig['provider']; } if (!empty($pconfig['pppoe_hostuniq'])) { $new_ppp_config['hostuniq'] = $pconfig['pppoe_hostuniq']; } $new_ppp_config['ondemand'] = !empty($pconfig['pppoe_dialondemand']); if (!empty($pconfig['pppoe_idletimeout'])) { $new_ppp_config['idletimeout'] = $pconfig['pppoe_idletimeout']; } break; case "pptp": case "l2tp": $new_config['if'] = $pconfig['type'].$pconfig['ptpid']; $new_config['ipaddr'] = $pconfig['type']; $new_ppp_config['ptpid'] = $pconfig['ptpid']; $new_ppp_config['type'] = $pconfig['type']; $new_ppp_config['if'] = $pconfig['type'].$pconfig['ptpid']; if (!empty($pconfig['ppp_port'])) { $new_ppp_config['ports'] = $pconfig['ppp_port']; } else { $new_ppp_config['ports'] = $old_config['if']; } $new_ppp_config['username'] = $pconfig['pptp_username']; $new_ppp_config['password'] = base64_encode($pconfig['pptp_password']); $new_ppp_config['localip'] = $pconfig['localip']; $new_ppp_config['subnet'] = $pconfig['pptp_subnet']; $new_ppp_config['gateway'] = $pconfig['pptp_remote']; $new_ppp_config['ondemand'] = !empty($pconfig['pptp_dialondemand']); if (!empty($pconfig['pptp_idletimeout'])) { $new_ppp_config['idletimeout'] = $pconfig['pptp_idletimeout']; } break; } // switch ipv6 config by type switch($pconfig['type6']) { case "staticv6": if (!empty($pconfig['staticv6usev4iface'])) { $new_config['dhcp6usev4iface'] = true; } $new_config['ipaddrv6'] = $pconfig['ipaddrv6']; $new_config['subnetv6'] = $pconfig['subnetv6']; if ($pconfig['gatewayv6'] != "none") { $new_config['gatewayv6'] = $pconfig['gatewayv6']; } break; case "slaac": $new_config['ipaddrv6'] = "slaac"; break; case "dhcp6": $new_config['ipaddrv6'] = "dhcp6"; $new_config['dhcp6-ia-pd-len'] = $pconfig['dhcp6-ia-pd-len']; if (!empty($pconfig['dhcp6-ia-pd-send-hint'])) { $new_config['dhcp6-ia-pd-send-hint'] = true; } if (!empty($pconfig['dhcp6prefixonly'])) { $new_config['dhcp6prefixonly'] = true; } if (!empty($pconfig['dhcp6sendsolicit'])) { $new_config['dhcp6sendsolicit'] = true; } if (!empty($pconfig['dhcp6usev4iface'])) { $new_config['dhcp6usev4iface'] = true; } if (!empty($pconfig['dhcp6norelease'])) { $new_config['dhcp6norelease'] = true; } if (isset($pconfig['dhcp6vlanprio']) && $pconfig['dhcp6vlanprio'] !== '') { $new_config['dhcp6vlanprio'] = $pconfig['dhcp6vlanprio']; } $new_config['adv_dhcp6_debug'] = !empty($pconfig['adv_dhcp6_debug']); $new_config['adv_dhcp6_interface_statement_send_options'] = $pconfig['adv_dhcp6_interface_statement_send_options']; $new_config['adv_dhcp6_interface_statement_request_options'] = $pconfig['adv_dhcp6_interface_statement_request_options']; $new_config['adv_dhcp6_interface_statement_information_only_enable'] = $pconfig['adv_dhcp6_interface_statement_information_only_enable']; $new_config['adv_dhcp6_interface_statement_script'] = $pconfig['adv_dhcp6_interface_statement_script']; $new_config['adv_dhcp6_id_assoc_statement_address_enable'] = $pconfig['adv_dhcp6_id_assoc_statement_address_enable']; $new_config['adv_dhcp6_id_assoc_statement_address'] = $pconfig['adv_dhcp6_id_assoc_statement_address']; $new_config['adv_dhcp6_id_assoc_statement_address_id'] = $pconfig['adv_dhcp6_id_assoc_statement_address_id']; $new_config['adv_dhcp6_id_assoc_statement_address_pltime'] = $pconfig['adv_dhcp6_id_assoc_statement_address_pltime']; $new_config['adv_dhcp6_id_assoc_statement_address_vltime'] = $pconfig['adv_dhcp6_id_assoc_statement_address_vltime']; $new_config['adv_dhcp6_id_assoc_statement_prefix_enable'] = $pconfig['adv_dhcp6_id_assoc_statement_prefix_enable']; $new_config['adv_dhcp6_id_assoc_statement_prefix'] = $pconfig['adv_dhcp6_id_assoc_statement_prefix']; $new_config['adv_dhcp6_id_assoc_statement_prefix_id'] = $pconfig['adv_dhcp6_id_assoc_statement_prefix_id']; $new_config['adv_dhcp6_id_assoc_statement_prefix_pltime'] = $pconfig['adv_dhcp6_id_assoc_statement_prefix_pltime']; $new_config['adv_dhcp6_id_assoc_statement_prefix_vltime'] = $pconfig['adv_dhcp6_id_assoc_statement_prefix_vltime']; $new_config['adv_dhcp6_prefix_interface_statement_sla_id'] = $pconfig['adv_dhcp6_prefix_interface_statement_sla_id']; $new_config['adv_dhcp6_prefix_interface_statement_sla_len'] = $pconfig['adv_dhcp6_prefix_interface_statement_sla_len']; $new_config['adv_dhcp6_authentication_statement_authname'] = $pconfig['adv_dhcp6_authentication_statement_authname']; $new_config['adv_dhcp6_authentication_statement_protocol'] = $pconfig['adv_dhcp6_authentication_statement_protocol']; $new_config['adv_dhcp6_authentication_statement_algorithm'] = $pconfig['adv_dhcp6_authentication_statement_algorithm']; $new_config['adv_dhcp6_authentication_statement_rdm'] = $pconfig['adv_dhcp6_authentication_statement_rdm']; $new_config['adv_dhcp6_key_info_statement_keyname'] = $pconfig['adv_dhcp6_key_info_statement_keyname']; $new_config['adv_dhcp6_key_info_statement_realm'] = $pconfig['adv_dhcp6_key_info_statement_realm']; $new_config['adv_dhcp6_key_info_statement_keyid'] = $pconfig['adv_dhcp6_key_info_statement_keyid']; $new_config['adv_dhcp6_key_info_statement_secret'] = $pconfig['adv_dhcp6_key_info_statement_secret']; $new_config['adv_dhcp6_key_info_statement_expire'] = $pconfig['adv_dhcp6_key_info_statement_expire']; $new_config['adv_dhcp6_config_advanced'] = $pconfig['adv_dhcp6_config_advanced']; $new_config['adv_dhcp6_config_file_override'] = $pconfig['adv_dhcp6_config_file_override']; $new_config['adv_dhcp6_config_file_override_path'] = $pconfig['adv_dhcp6_config_file_override_path']; break; case "6rd": $new_config['ipaddrv6'] = "6rd"; $new_config['prefix-6rd'] = $pconfig['prefix-6rd']; $new_config['prefix-6rd-v4plen'] = $pconfig['prefix-6rd-v4plen']; $new_config['gateway-6rd'] = $pconfig['gateway-6rd']; break; case "6to4": $new_config['ipaddrv6'] = "6to4"; break; case "track6": $new_config['ipaddrv6'] = "track6"; $new_config['track6-interface'] = $pconfig['track6-interface']; $new_config['track6-prefix-id'] = 0; if (ctype_xdigit($pconfig['track6-prefix-id--hex'])) { $new_config['track6-prefix-id'] = intval($pconfig['track6-prefix-id--hex'], 16); } break; } // wireless if (isset($new_config['wireless'])) { $new_config['wireless']['wpa'] = array(); $new_config['wireless']['wme'] = array(); $new_config['wireless']['wep'] = array(); $new_config['wireless']['hidessid'] = array(); $new_config['wireless']['pureg'] = array(); $new_config['wireless']['puren'] = array(); $new_config['wireless']['ieee8021x'] = array(); $new_config['wireless']['standard'] = $pconfig['standard']; $new_config['wireless']['mode'] = $pconfig['mode']; $new_config['wireless']['protmode'] = $pconfig['protmode']; $new_config['wireless']['ssid'] = $pconfig['ssid']; $new_config['wireless']['hidessid']['enable'] = !empty($pconfig['hidessid_enable']); $new_config['wireless']['channel'] = $pconfig['channel']; $new_config['wireless']['authmode'] = $pconfig['authmode']; $new_config['wireless']['txpower'] = $pconfig['txpower']; $new_config['wireless']['regdomain'] = $pconfig['regdomain']; $new_config['wireless']['regcountry'] = $pconfig['regcountry']; $new_config['wireless']['reglocation'] = $pconfig['reglocation']; if (!empty($pconfig['regcountry']) && !empty($pconfig['reglocation'])) { $wl_regdomain_xml_attr = array(); $wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr); $wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country']; foreach($wl_countries_attr as $wl_country) { if ($pconfig['regcountry'] == $wl_country['ID']) { $new_config['wireless']['regdomain'] = $wl_country['rd'][0]['REF']; break; } } } if (isset($pconfig['diversity']) && is_numeric($pconfig['diversity'])) { $new_config['wireless']['diversity'] = $pconfig['diversity']; } elseif (isset($new_config['wireless']['diversity'])) { unset($new_config['wireless']['diversity']); } if (isset($pconfig['txantenna']) && is_numeric($pconfig['txantenna'])) { $new_config['wireless']['txantenna'] = $pconfig['txantenna']; } elseif (isset($new_config['wireless']['txantenna'])) { unset($new_config['wireless']['txantenna']); } if (isset($pconfig['rxantenna']) && is_numeric($pconfig['rxantenna'])) { $new_config['wireless']['rxantenna'] = $_POST['rxantenna']; } elseif (isset($new_config['wireless']['rxantenna'])) { unset($new_config['wireless']['rxantenna']); } $new_config['wireless']['wpa']['macaddr_acl'] = $pconfig['macaddr_acl']; $new_config['wireless']['wpa']['auth_algs'] = $pconfig['auth_algs']; $new_config['wireless']['wpa']['wpa_mode'] = $pconfig['wpa_mode']; $new_config['wireless']['wpa']['wpa_key_mgmt'] = $pconfig['wpa_key_mgmt']; $new_config['wireless']['wpa']['wpa_pairwise'] = $pconfig['wpa_pairwise']; $new_config['wireless']['wpa']['wpa_group_rekey'] = $pconfig['wpa_group_rekey']; $new_config['wireless']['wpa']['wpa_gmk_rekey'] = $pconfig['wpa_gmk_rekey']; $new_config['wireless']['wpa']['passphrase'] = $pconfig['passphrase']; $new_config['wireless']['wpa']['ext_wpa_sw'] = $pconfig['ext_wpa_sw']; $new_config['wireless']['wpa']['mac_acl_enable'] = !empty($pconfig['mac_acl_enable']); $new_config['wireless']['wpa']['rsn_preauth'] = !empty($pconfig['rsn_preauth']); $new_config['wireless']['wpa']['ieee8021x']['enable'] = !empty($pconfig['ieee8021x']); $new_config['wireless']['wpa']['wpa_strict_rekey'] = !empty($pconfig['wpa_strict_rekey']); $new_config['wireless']['wpa']['debug_mode'] = !empty($pconfig['debug_mode']); $new_config['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = !empty($pconfig['wpa_enable']); $new_config['wireless']['auth_server_addr'] = $pconfig['auth_server_addr']; $new_config['wireless']['auth_server_port'] = $pconfig['auth_server_port']; $new_config['wireless']['auth_server_shared_secret'] = $pconfig['auth_server_shared_secret']; $new_config['wireless']['auth_server_addr2'] = $pconfig['auth_server_addr2']; $new_config['wireless']['auth_server_port2'] = $pconfig['auth_server_port2']; $new_config['wireless']['auth_server_shared_secret2'] = $pconfig['auth_server_shared_secret2']; $new_config['wireless']['wep']['enable'] = !empty($pconfig['wep_enable']); $new_config['wireless']['wme']['enable'] = !empty($pconfig['wme_enable']); $new_config['wireless']['pureg']['enable'] = !empty($pconfig['puremode']) && $pconfig['puremode'] == "11g"; $new_config['wireless']['puren']['enable'] = !empty($pconfig['puremode']) && $pconfig['puremode'] == "11n"; $new_config['wireless']['apbridge'] = array(); $new_config['wireless']['apbridge']['enable'] = !empty($pconfig['apbridge_enable']); $new_config['wireless']['turbo'] = array(); $new_config['wireless']['turbo']['enable'] = $pconfig['standard'] == "11g Turbo" || $pconfig['standard'] == "11a Turbo"; $new_config['wireless']['wep']['key'] = array(); for ($i = 1; $i <= 4; $i++) { if (!empty($pconfig['key' . $i])) { $newkey = array(); $newkey['value'] = $pconfig['key' . $i]; if ($pconfig['txkey'] == $i) { $newkey['txkey'] = true; } $new_config['wireless']['wep']['key'][] = $newkey; } } // todo: it's probably better to choose one place to store wireless data // this construction implements a lot of weirness (more info interface_sync_wireless_clones) $wlanbaseif = interface_get_wireless_base($a_interfaces[$if]['if']); if (!empty($pconfig['persistcommonwireless'])) { if (!isset($config['wireless']) || !is_array($config['wireless'])) { $config['wireless'] = array(); } if (!isset($config['wireless']['interfaces']) || !is_array($config['wireless']['interfaces'])) { $config['wireless']['interfaces'] = array(); } if (empty($config['wireless']['interfaces'][$wlanbaseif])) { $config['wireless']['interfaces'][$wlanbaseif] = array(); } } else if (isset($config['wireless']['interfaces'][$wlanbaseif])) { unset($config['wireless']['interfaces'][$wlanbaseif]); } // quite obscure this... copies parts of the config interface_sync_wireless_clones($new_config, true); } if (count($new_ppp_config) > 0) { // ppp details changed $a_ppps[$pppid] = $new_ppp_config; } elseif (!empty($a_ppps[$pppid])) { // ppp removed $new_config['if'] = $a_ppps[$pppid]['ports']; unset($a_ppps[$pppid]); } // save interface details $a_interfaces[$if] = $new_config; if (!empty($old_config['ipaddr']) && $old_config['ipaddr'] == 'dhcp' && $new_config['ipaddr'] != 'dhcp') { // change from dhcp to something else, kill dhclient kill_dhclient_process($old_config['if']); } if (!empty($old_config['ipaddrv6']) && $old_config['ipaddrv6'] == 'dhcp6' && $new_config['ipaddrv6'] != 'dhcp6') { // change from dhcp to something else, kill dhcp6c killbypid("/var/run/dhcp6c_{$old_config['if']}.pid", 'TERM', true); } // save to config write_config(); // log changes for apply action // (it would be better to diff the physical situation with the new config for changes) if (file_exists('/tmp/.interfaces.apply')) { $toapplylist = unserialize(file_get_contents('/tmp/.interfaces.apply')); } else { $toapplylist = array(); } $old_config['realif'] = get_real_interface($if); $toapplylist[$if]['ifcfg'] = $old_config; $toapplylist[$if]['ppps'] = $old_ppps; file_put_contents('/tmp/.interfaces.apply', serialize($toapplylist)); mark_subsystem_dirty('interfaces'); header(url_safe('Location: /interfaces.php?if=%s', array($if))); exit; } } } legacy_html_escape_form_data($pconfig); // some wireless settings require additional details to build the listbox if (isset($a_interfaces[$if]['wireless'])) { $wl_modes = get_wireless_modes($if); $wlanbaseif = interface_get_wireless_base($a_interfaces[$if]['if']); preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split); $wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2]; $wl_sysctl = get_sysctl(array("{$wl_sysctl_prefix}.diversity", "{$wl_sysctl_prefix}.txantenna", "{$wl_sysctl_prefix}.rxantenna")); $wl_regdomain_xml_attr = array(); $wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr); $wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd']; $wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd']; $wl_countries = &$wl_regdomain_xml['country-codes']['country']; $wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country']; } // Find all possible media options for the interface $mediaopts_list = array(); $optlist_intf = get_parent_interface($pconfig['if']); if (count($optlist_intf) > 0) { exec("/sbin/ifconfig -m {$optlist_intf[0]} | grep \"media \"", $mediaopts); foreach ($mediaopts as $mediaopt){ preg_match("/media (.*)/", $mediaopt, $matches); if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)){ // there is media + mediaopt like "media 1000baseT mediaopt full-duplex" array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]); } else { // there is only media like "media 1000baseT" array_push($mediaopts_list, $matches[1]); } } } include("head.inc"); ?>
0) { print_input_errors($input_errors); } if (is_subsystem_dirty('interfaces')) { print_info_box_apply(sprintf(gettext("The %s configuration has been changed."),$pconfig['descr'])."
".gettext("You must apply the changes in order for them to take effect.")."
".gettext("Don't forget to adjust the DHCP Server range if needed after applying.")); } if (isset($savemsg)) { print_info_box($savemsg); } ?>
 
/>
/>
" /> " onclick="window.location.href='/interfaces.php'" />