From 071d63b9ab639730ccbb2886adb9703c4d9a1c71 Mon Sep 17 00:00:00 2001 From: Erik Fonnesbeck Date: Tue, 16 Mar 2010 23:13:15 -0600 Subject: Restore attribute support, but with some extra checks in the function that uses it. --- etc/inc/regdomain.inc | 162 ------------------------------------------- etc/inc/xmlparse.inc | 41 ++++++++++- etc/pfSense.obsoletedfiles | 1 + usr/local/www/interfaces.php | 28 ++++---- 4 files changed, 57 insertions(+), 175 deletions(-) delete mode 100644 etc/inc/regdomain.inc diff --git a/etc/inc/regdomain.inc b/etc/inc/regdomain.inc deleted file mode 100644 index a8f1a7f..0000000 --- a/etc/inc/regdomain.inc +++ /dev/null @@ -1,162 +0,0 @@ -. - - 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. -*/ - -/* The following items will be treated as arrays in regdomain.xml */ -function listtags_rd() { - $ret = explode(" ", - "band country flags freqband netband rd " - ); - return $ret; -} - -function startElement_rd($parser, $name, $attrs) { - global $parsedcfg, $depth, $curpath, $havedata, $listtags; - - array_push($curpath, strtolower($name)); - - $ptr =& $parsedcfg; - foreach ($curpath as $path) { - $ptr =& $ptr[$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 (!empty($attrs)) - $ptr[count($ptr)]['attributes'] = $attrs; - - } else if (isset($ptr)) { - /* multiple entries not allowed for this element, bail out */ - die(sprintf("XML error: %s at line %d cannot occur more than once\n", - $name, - xml_get_current_line_number($parser))); - } else if (!empty($attrs)) { - $ptr['attributes'] = $attrs; - } - - $depth++; - $havedata = $depth; -} - -function endElement_rd($parser, $name) { - global $depth, $curpath, $parsedcfg, $havedata, $listtags; - - if ($havedata == $depth) { - $ptr =& $parsedcfg; - foreach ($curpath as $path) { - $ptr =& $ptr[$path]; - } - if (!isset($ptr)) - $ptr = ""; - } - - array_pop($curpath); - - if (in_array(strtolower($name), $listtags)) - array_pop($curpath); - - $depth--; -} - -function cData_rd($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 .= $data; - } else { - if (trim($data, " ") != "") { - $ptr = $data; - $havedata++; - } - } - } -} - -function parse_xml_regdomain($rdfile = '/etc/regdomain.xml', $rootobj = 'regulatory-data') { - global $listtags; - $listtags = listtags_rd(); - return parse_xml_regdomain_raw($rdfile, $rootobj); -} - -function parse_xml_regdomain_raw($rdfile, $rootobj) { - - global $depth, $curpath, $parsedcfg, $havedata, $listtags; - $parsedcfg = array(); - $curpath = array(); - $depth = 0; - $havedata = 0; - - $xml_parser = xml_parser_create(); - - xml_set_element_handler($xml_parser, "startElement_rd", "endElement_rd"); - xml_set_character_data_handler($xml_parser, "cData_rd"); - xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE, 1); - - if (!($fp = fopen($rdfile, "r"))) { - die("Error: could not open XML input\n"); - } - - 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))); - return -1; - } - } - xml_parser_free($xml_parser); - - if (!$parsedcfg[$rootobj]) { - die("XML error: no $rootobj object found!\n"); - } - - return $parsedcfg[$rootobj]; -} - -?> diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc index 7c5a554..85f18e7 100644 --- a/etc/inc/xmlparse.inc +++ b/etc/inc/xmlparse.inc @@ -59,14 +59,28 @@ function listtags_pkg() { return $ret; } +/* The following items will be treated as arrays in regdomain.xml */ +function listtags_rd() { + $ret = explode(" ", + "band country flags freqband netband rd " + ); + return $ret; +} + function startElement($parser, $name, $attrs) { - global $parsedcfg, $depth, $curpath, $havedata, $listtags; + global $parsedcfg, $depth, $curpath, $havedata, $listtags, $parsedattrs, $parsingattrs; array_push($curpath, strtolower($name)); $ptr =& $parsedcfg; + if (isset($parsingattrs) && !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? */ @@ -80,11 +94,19 @@ function startElement($parser, $name, $attrs) { 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("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++; @@ -154,6 +176,23 @@ function parse_xml_config_pkg($cffile, $rootobj, $isstring = "false") { return parse_xml_config_raw($cffile, $rootobj, $isstring); } +function parse_xml_regdomain(&$rdattributes, $rdfile = '/etc/regdomain.xml', $rootobj = 'regulatory-data') { + global $listtags, $parsedattrs, $parsingattrs; + $listtags = listtags_rd(); + if (isset($rdattributes)) { + $parsedattrs = array(); + $parsingattrs = true; + $ret = parse_xml_config_raw($rdfile, $rootobj); + if ($parsedattrs[$rootobj]) + $rdattributes = $parsedattrs[$rootobj]; + unset($parsedattrs); + unset($parsingattrs); + return $ret; + } else { + return parse_xml_config_raw($rdfile, $rootobj); + } +} + function parse_xml_config_raw($cffile, $rootobj, $isstring = "false") { global $depth, $curpath, $parsedcfg, $havedata, $listtags; diff --git a/etc/pfSense.obsoletedfiles b/etc/pfSense.obsoletedfiles index e062088..6737386 100644 --- a/etc/pfSense.obsoletedfiles +++ b/etc/pfSense.obsoletedfiles @@ -1,4 +1,5 @@ /etc/phpshellsessions/cvssync +/etc/inc/regdomain.inc /etc/inc/sysctl.inc /usr/local/www/interfaces_wan.php /usr/local/www/interfaces_lan.php diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index 959f448..28af188 100755 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -52,7 +52,6 @@ require("filter.inc"); require("shaper.inc"); require("rrd.inc"); require("vpn.inc"); -require('regdomain.inc'); if ($_REQUEST['if']) { $if = $_REQUEST['if']; @@ -219,7 +218,12 @@ if (isset($wancfg['wireless'])) { interface_wireless_clone($wlanif, $wancfg); $wlanbaseif = interface_get_wireless_base($wancfg['if']); $wl_modes = get_wireless_modes($if); - $wl_regdomains = parse_xml_regdomain(); + $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']; $pconfig['standard'] = $wancfg['wireless']['standard']; $pconfig['mode'] = $wancfg['wireless']['mode']; $pconfig['protmode'] = $wancfg['wireless']['protmode']; @@ -699,7 +703,7 @@ function handle_pppoe_reset() { } function handle_wireless_post() { - global $_POST, $config, $g, $wancfg, $if, $wl_regdomains; + global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr; if (!is_array($wancfg['wireless'])) $wancfg['wireless'] = array(); $wancfg['wireless']['standard'] = $_POST['standard']; @@ -714,9 +718,9 @@ function handle_wireless_post() { $wancfg['wireless']['regcountry'] = $_POST['regcountry']; $wancfg['wireless']['reglocation'] = $_POST['reglocation']; if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) { - foreach($wl_regdomains['country-codes']['country'] as $wl_country) { - if ($wancfg['wireless']['regcountry'] == $wl_country['attributes']['ID']) { - $wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['attributes']['REF']; + foreach($wl_countries_attr as $wl_country) { + if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) { + $wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF']; break; } } @@ -1388,12 +1392,12 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" @@ -1402,12 +1406,12 @@ $types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" -- cgit v1.1