Copyright (C) 2010 Ermal Luçi 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"); /* * find_ip_interface($ip): return the interface where an ip is defined * (or if $bits is specified, where an IP within the subnet is defined) */ function find_ip_interface($ip, $bits = null) { if (!is_ipaddr($ip)) return false; $isv6ip = is_ipaddrv6($ip); /* if list */ $ifdescrs = get_configured_interface_list(); foreach ($ifdescrs as $ifdescr => $ifname) { $ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname); if (is_null($ifip)) continue; if (is_null($bits)) { if ($ip == $ifip) { $int = get_real_interface($ifname); return $int; } } else { if (ip_in_subnet($ifip, $ip . "/" . $bits)) { $int = get_real_interface($ifname); return $int; } } } return false; } $stepid = '0'; if (isset($_POST['stepid'])) { $stepid = htmlspecialchars($_POST['stepid']); } elseif (isset($_GET['stepid'])) { $stepid = htmlspecialchars($_GET['stepid']); } $xml = ''; if (isset($_GET['xml'])) { $xml = htmlspecialchars($_GET['xml']); } elseif (isset($_POST['xml'])) { $xml = htmlspecialchars($_POST['xml']); } switch ($xml) { case 'openvpn': case 'system': break; default: print_info_box(gettext('ERROR: Could not find wizard file.')); die; } $listtags = array_flip(array( 'additional_files_needed', 'alias', 'build_port_path', 'columnitem', 'depends_on_package', 'field', 'file', 'item', 'menu', 'onetoone', 'option', 'package', 'package', 'queue', 'rowhelperfield', 'rule', 'servernat', 'service', 'step', 'tab', 'template', )); $pkg = parse_xml_config_raw("/usr/local/wizard/{$xml}.xml", 'wizard', false); if (!is_array($pkg)) { print_info_box(sprintf(gettext("ERROR: Could not parse %s wizard file."), $xml)); die; } $totalsteps = $pkg['totalsteps']; if ($pkg['includefile']) { require_once($pkg['includefile']); } if($pkg['step'][$stepid]['stepsubmitbeforesave']) { eval($pkg['step'][$stepid]['stepsubmitbeforesave']); } if ($_POST && !$input_errors) { foreach ($pkg['step'][$stepid]['fields']['field'] as $field) { if(!empty($field['bindstofield']) and $field['type'] <> "submit") { $fieldname = $field['name']; $fieldname = str_replace(" ", "", $fieldname); $fieldname = strtolower($fieldname); // update field with posted values. if($field['unsetfield'] <> "") $unset_fields = "yes"; else $unset_fields = ""; if($field['arraynum'] <> "") $arraynum = $field['arraynum']; else $arraynum = ""; update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']); } } // run custom php code embedded in xml config. if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") { eval($pkg['step'][$stepid]['stepsubmitphpaction']); } if (!$input_errors) { write_config(); } $stepid++; if($stepid > $totalsteps) { $stepid = $totalsteps; } } $extraBreadcrumb = $pkg['step'][$stepid]['title']; function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) { global $config; $field_split = explode("->",$field); foreach ($field_split as $f) $field_conv .= "['" . $f . "']"; if($field_conv == "") return; if ($arraynum <> "") $field_conv .= "[" . $arraynum . "]"; if(($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") { /* * item is a checkbox, it should have the value "on" * if it was checked */ $var = "\$config{$field_conv}"; $text = "if (isset({$var})) unset({$var});"; eval($text); return; } if($field_type == "interfaces_selection") { $var = "\$config{$field_conv}"; $text = "if (isset({$var})) unset({$var});"; $text .= "\$config" . $field_conv . " = '" . addslashes($updatetext) . "';"; eval($text); return; } if($unset == "yes") { $text = "unset(\$config" . $field_conv . ");"; eval($text); } $text = "\$config" . $field_conv . " = '" . addslashes($updatetext) . "';"; eval($text); } function redirect_url() { global $config, $title; switch($config['system']['webgui']['protocol']) { case "http": $proto = "http"; break; case "https": $proto = "https"; break; default: $proto = "http"; break; } $port = $config['system']['webgui']['port']; if($port != "") { if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) { $urlport = ":" . $port; } elseif ($port != "80" and $port != "443") { $urlport = ":" . $port; } else { $urlport = ""; } } $http_host = $_SERVER['SERVER_NAME']; $urlhost = $http_host; // If finishing the setup wizard, check if accessing on a LAN or WAN address that changed if($title == "Reload in progress") { if (is_ipaddr($urlhost)) { $host_if = find_ip_interface($urlhost); if ($host_if) { $host_if = convert_real_interface_to_friendly_interface_name($host_if); if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) $urlhost = $config['interfaces'][$host_if]['ipaddr']; } } else if ($urlhost == $config['system']['hostname']) { $urlhost = $config['wizardtemp']['system']['hostname']; } else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) { $urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain']; } } if ($urlhost != $http_host) { file_put_contents('/tmp/setupwizard_lastreferrer', $proto . '://' . $http_host . $urlport . $_SERVER['REQUEST_URI']); } return $proto . '://' . $urlhost . $urlport; } // handle before form display event. do { $oldstepid = $stepid; if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != '') { eval($pkg['step'][$stepid]['stepbeforeformdisplay']); } } while ($oldstepid != $stepid); include("head.inc"); ?>
"") { ?>