From 4e43ef22708ccdc9cb613b1e1b36d72f0c608f14 Mon Sep 17 00:00:00 2001 From: Stephen Beaver Date: Wed, 30 Sep 2015 09:27:26 -0400 Subject: Wizard system completed and tested agains all wizard files Progress bar added to show progess through wizard steps --- src/usr/local/www/wizard.php | 773 +++++++++++++++++-------------------------- 1 file changed, 312 insertions(+), 461 deletions(-) diff --git a/src/usr/local/www/wizard.php b/src/usr/local/www/wizard.php index 2f50863..f77b1c4 100644 --- a/src/usr/local/www/wizard.php +++ b/src/usr/local/www/wizard.php @@ -2,32 +2,58 @@ /* $Id$ */ /* wizard.php - Copyright (C) 2013-2015 Electric Sheep Fencing, LP - Copyright (C) 2010 Ermal Luçi - Copyright (C) 2004 Scott Ullrich - 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. */ +/* ==================================================================== + * Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved. + * Copyright (c) 2004, 2005 Scott Ullrich + * + * 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. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgment: + * "This product includes software developed by the pfSense Project + * for use in the pfSense software distribution. (http://www.pfsense.org/). + * + * 4. The names "pfSense" and "pfSense Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * coreteam@pfsense.org. + * + * 5. Products derived from this software may not be called "pfSense" + * nor may "pfSense" appear in their names without prior written + * permission of the Electric Sheep Fencing, LLC. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * + * "This product includes software developed by the pfSense Project + * for use in the pfSense software distribution (http://www.pfsense.org/). + * + * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY + * EXPRESSED 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 pfSense PROJECT OR + * ITS CONTRIBUTORS 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. + * + * ==================================================================== + * + */ ##|+PRIV ##|*IDENT=page-pfsensewizardsubsystem @@ -36,7 +62,6 @@ ##|*MATCH=wizard.php* ##|-PRIV - require("globals.inc"); require("guiconfig.inc"); require("functions.inc"); @@ -55,6 +80,7 @@ $stepid = htmlspecialchars($_GET['stepid']); if (isset($_POST['stepid'])) { $stepid = htmlspecialchars($_POST['stepid']); } + if (!$stepid) { $stepid = "0"; } @@ -110,6 +136,7 @@ if ($_POST && !$input_errors) { } else { $unset_fields = ""; } + if ($field['arraynum'] != "") { $arraynum = $field['arraynum']; } else { @@ -127,6 +154,7 @@ if ($_POST && !$input_errors) { if (!$input_errors) { write_config(); } + $stepid++; if ($stepid > $totalsteps) { $stepid = $totalsteps; @@ -193,10 +221,8 @@ if (file_exists("/usr/local/www/themes/{$g['theme']}/wizard.css")) { } else { echo ""; } -?> - - +if ($pkg['step'][$stepid]['fields']['field'] != "") { ?> - -
- - - -
- - 
- - http[s]://ip_address:port/ + 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") { - $ip = fixup_string("\$myurl"); - } else { - $ip = "/"; + 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']; + } } -/* - echo ""; -?> -logo-black -

 

-
-

logo-black



- - - - -
 
- - - - - - - + + +

logo-black



+ + +
+
+
+
+ "; - } -?> -*/ - $form = new Form(false); - $form->addGlobal(new Form_Input( - 'stepid', - null, - 'hidden', - $stepid - )); - $section = new Form_Section(fixup_string($title)); +$form = new Form(false); - if($description) { - $section->addInput(new Form_StaticText( - null, - $description - )); - } +$form->addGlobal(new Form_Input( + 'stepid', + null, + 'hidden', + $stepid +)); - $inputaliases = array(); - if ($pkg['step'][$stepid]['fields']['field'] != "") { - foreach ($pkg['step'][$stepid]['fields']['field'] as $field) { +$form->addGlobal(new Form_Input( + 'xml', + null, + 'hidden', + $xml +)); - $value = $field['value']; - $name = $field['name']; +$section = new Form_Section(fixup_string($title)); - $name = preg_replace("/\s+/", "", $name); - $name = strtolower($name); +if($description) { + $section->addInput(new Form_StaticText( + null, + fixup_string($description) + )); +} - if ($field['bindstofield'] != "") { - $arraynum = ""; - $field_conv = ""; - $field_split = explode("->", $field['bindstofield']); - // arraynum is used in cases where there is an array of the same field - // name such as dnsserver (2 of them) - if ($field['arraynum'] != "") { - $arraynum = "[" . $field['arraynum'] . "]"; - } - foreach ($field_split as $f) { - $field_conv .= "['" . $f . "']"; - } - if ($field['type'] == "checkbox") { - $toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }"; - } else { - $toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";"; - } +$inputaliases = array(); +if ($pkg['step'][$stepid]['fields']['field'] != "") { + foreach ($pkg['step'][$stepid]['fields']['field'] as $field) { + + $value = $field['value']; + $name = $field['name']; - eval($toeval); + $name = preg_replace("/\s+/", "", $name); + $name = strtolower($name); + + if ($field['bindstofield'] != "") { + $arraynum = ""; + $field_conv = ""; + $field_split = explode("->", $field['bindstofield']); + // arraynum is used in cases where there is an array of the same field + // name such as dnsserver (2 of them) + if ($field['arraynum'] != "") { + $arraynum = "[" . $field['arraynum'] . "]"; } -/* - if (!$field['combinefieldsend']) { - echo ""; + + foreach ($field_split as $f) { + $field_conv .= "['" . $f . "']"; } -*/ - switch ($field['type']) { + + if ($field['type'] == "checkbox") { + $toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }"; + } else { + $toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";"; + } + + eval($toeval); + } + + switch ($field['type']) { case "input": if ($field['displayname']) { $etitle = $field['displayname']; @@ -442,31 +518,13 @@ events.push(function(){ $etitle = fixup_string($field['name']); } - if (!$field['dontcombinecells']) { -// echo "\n"; + $etitle = $field['displayname']; + } else if (!$field['dontdisplayname']) { - echo "\n"; - } - if (!$field['dontcombinecells']) { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; -// echo ""; - } - - echo "\n"; - } -*/ - } - $form->add($section); - print($form); - } +$form->add($section); +print($form); ?> @@ -1079,79 +1005,4 @@ if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") { echo "\n\n"; } -/* - * HELPER FUNCTIONS - */ - -function fixup_string($string) { - global $config, $g, $myurl, $title; - $newstring = $string; - // fixup #1: $myurl -> http[s]://ip_address:port/ - 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("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']); - } - $myurl = $proto . "://" . $urlhost . $urlport . "/"; - - if (strstr($newstring, "\$myurl")) { - $newstring = str_replace("\$myurl", $myurl, $newstring); - } - // fixup #2: $wanip - if (strstr($newstring, "\$wanip")) { - $curwanip = get_interface_ip(); - $newstring = str_replace("\$wanip", $curwanip, $newstring); - } - // fixup #3: $lanip - if (strstr($newstring, "\$lanip")) { - $lanip = get_interface_ip("lan"); - $newstring = str_replace("\$lanip", $lanip, $newstring); - } - // fixup #4: fix'r'up here. - return $newstring; -} - -function is_timezone($elt) { - return !preg_match("/\/$/", $elt); -} - include("foot.inc"); - - -- cgit v1.1
 
" . fixup_string($title) . "
\n"; - } - -/* - echo "\n"; - - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ $section->addInput(new Form_Input( $name, $etitle, 'text', $value ))->setHelp($field['description']) - ->setOnchange(($field['validate']) ? 'onchange=\'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); + ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); break; case "text": @@ -474,70 +532,60 @@ events.push(function(){ null, $field['description'] )); -/* - echo "
\n"; - if ($field['description'] != "") { - echo "

" . $field['description'] . "
"; - } -*/ + break; case "inputalias": if ($field['displayname']) { - echo "
\n"; - echo $field['displayname']; - echo ":\n"; - echo fixup_string($field['name']); - echo ":\n"; + $etitle = fixup_string($field['name']); } - $inputaliases[] = $name; - echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } + $section->addInput(new Form_Input( + $name, + $etitle, + 'text', + $value + ))->setAttribute('autocomplete', 'off') + ->setOnchange($onchange) + ->setHelp($field['description']); + break; case "interfaces_selection": case "interface_select": - $size = ""; - $multiple = ""; + $name = strtolower($name); - echo "
\n"; - echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n"; - echo "\n"; - if ($field['size'] != "") { - $size = "size=\"{$field['size']}\""; - } - if ($field['multiple'] != "" and $field['multiple'] != "0") { - $multiple = "multiple=\"multiple\""; - $name .= "[]"; - } - echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } + $section->addInput(new Form_Select( + $name, + $etitle, + ($multiple) ? $selected:$selected[0], + $options, + $multiple + ))->setHelp($field['description']); break; case "password": @@ -575,54 +627,37 @@ events.push(function(){ $etitle = fixup_string($field['name']); } - if (!$field['dontcombinecells']) { - //echo "
"; - } - $section->addInput(new Form_Input( $name, $etitle, 'password', $value ))->setHelp($field['description']) - ->setOnchange(($field['validate']) ? 'onchange=\'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); -/* - echo "\n"; + ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ break; case "certca_selection": - $size = ""; - $multiple = ""; + $options = array(); + $selected = ""; + $name = strtolower($name); - echo "
\n"; - echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n"; - echo "\n"; - if ($field['size'] != "") { - $size = "size=\"{$field['size']}\""; - } - echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } + $section->addInput(new Form_Select( + $name, + $etitle, + $selected, + $options + ))->setHelp($field['description']); break; case "cert_selection": - $size = ""; - $multiple = ""; + $options = array(); + $selected = array(); + + $multiple = false; $name = strtolower($name); - echo "
\n"; - echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n"; - echo "\n"; - if ($field['size'] != "") { - $size = "size=\"{$field['size']}\""; - } + + $etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']); + echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } + $section->addInput(new Form_Select( + $name, + $etitle, + ($multiple) ? $selected:$selected[0], + $options, + $multiple + ))->setHelp($field['description']); break; case "select": @@ -704,10 +746,6 @@ events.push(function(){ $multiple = ($field['multiple'] == "yes"); - if (!$field['dontcombinecells']) { -// echo "
\n"; - } - $onchange = ""; foreach ($field['options']['option'] as $opt) { if ($opt['enablefields'] != "") { @@ -715,8 +753,6 @@ events.push(function(){ } } -// echo "\n"; -// echo "\n"; - $section->addInput(new Form_Select( $name, $etitle, @@ -746,10 +777,6 @@ events.push(function(){ $multiple ))->setHelp($field['description'])->setOnchange($onchange); -// if ($field['description'] != "") { -// echo $field['description']; -// } - break; case "textarea": if ($field['displayname']) { @@ -758,55 +785,26 @@ events.push(function(){ $etitle = fixup_string($field['name']); } - if (!$field['dontcombinecells']) { - //echo ""; - } - $section->addInput(new Form_TextArea( $name, $etitle, $value ))->setHelp($field['description']) ->setAttribute('rows', $field['rows']) - ->setOnchange(($field['validate']) ? 'onchange=\'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); -/* - echo "\n"; - + ->setOnchange(($field['validate']) ? 'FieldValidate(this.value, "{$field[\'validate\']}", "{$field[\'message\']}");':''); - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ break; case "submit": $form->addGlobal(new Form_Button( $name, $field['name'] )); -/* - echo "
 
"; - echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ break; case "listtopic": $form->add($section); $section = new Form_Section($field['name']); -// echo "
 
" . $field['name'] . "
\n"; - break; case "subnet_select": if ($field['displayname']) { @@ -815,10 +813,6 @@ events.push(function(){ $etitle = fixup_string($field['name']); } - if (!$field['dontcombinecells']) { -// echo "
"; - } - $section->addInput(new Form_Select( $name, $etitle, @@ -826,22 +820,6 @@ events.push(function(){ array_combine(range(32, 1, -1), range(32, 1, -1)) ))->setHelp($field['description']); -/* echo "\n"; - - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ break; case "timezone_select": exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist); @@ -863,37 +841,13 @@ events.push(function(){ //echo "
"; } - if (!$field['dontcombinecells']) { -// echo ""; - } - - $section->addInput(new Form_Select( $name, $etitle, $value, array_combine($timezonelist, $timezonelist) ))->setHelp($field['description']); -/* - echo "\n"; - if ($field['description'] != "") { - echo "
" . $field['description']; - } -*/ break; case "checkbox": if ($field['displayname']) { @@ -918,40 +872,13 @@ events.push(function(){ ))->setHelp($field['description']) ->setOnclick($onclick); -/* - echo "
\n"; - - if ($field['description'] != "") { - echo $field['description']; - } -*/ break; - } + } // e-o-switch + } // e-o-foreach(package) +} // e-o- if(we have fields) -/* - if ($field['typehint'] != "") { - echo $field['typehint']; - } - - if ($field['warning'] != "") { - echo "
" . $field['warning'] . ""; - } - - if (!$field['combinefieldsbegin']) { - if (!$field['dontcombinecells']) { - echo "