From f5eb5ea80e27a795f9ff87a40fda8219824ccc15 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 25 Sep 2015 11:07:09 +0200 Subject: [PATCH] wizard: some sanity improvements o We could potentially pass files using xml=../../xxx, so just hardcode the wizards we know for now. I don't expect them to grow, otherwise we may be able to do a directory expand. o Move xml files out of the /usr/local/www/wizards into /usr/local/wizard. o Move the include file to the normal include path /usr/local/etc/inc. o Allow the menu to always expand to the setup wizard, even though we many be triggering the OpenVPN wizard. This gives a consistent feel of navigation, especially since POST requests hide the invoked wizard later on anyway. --- .../wizards => etc/inc}/openvpn_wizard.inc | 15 ++-- .../app/models/OPNsense/Base/Menu/Menu.xml | 5 +- .../openvpn_wizard.xml => wizard/openvpn.xml} | 22 +++--- .../setup_wizard.xml => wizard/setup.xml} | 4 +- src/www/index.php | 2 +- src/www/vpn_openvpn_server.php | 2 +- src/www/wizard.php | 68 +++++++++++++------ 7 files changed, 73 insertions(+), 45 deletions(-) rename src/{www/wizards => etc/inc}/openvpn_wizard.inc (97%) rename src/{www/wizards/openvpn_wizard.xml => wizard/openvpn.xml} (97%) rename src/{www/wizards/setup_wizard.xml => wizard/setup.xml} (99%) diff --git a/src/www/wizards/openvpn_wizard.inc b/src/etc/inc/openvpn_wizard.inc similarity index 97% rename from src/www/wizards/openvpn_wizard.inc rename to src/etc/inc/openvpn_wizard.inc index eb4809731..b223ea61d 100644 --- a/src/www/wizards/openvpn_wizard.inc +++ b/src/etc/inc/openvpn_wizard.inc @@ -1,4 +1,5 @@ - + + + @@ -206,7 +208,6 @@ - diff --git a/src/www/wizards/openvpn_wizard.xml b/src/wizard/openvpn.xml similarity index 97% rename from src/www/wizards/openvpn_wizard.xml rename to src/wizard/openvpn.xml index 602a75e31..85ea7ec7f 100644 --- a/src/www/wizards/openvpn_wizard.xml +++ b/src/wizard/openvpn.xml @@ -66,7 +66,7 @@ step1_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 2 @@ -102,7 +102,7 @@ step2_stepbeforeformdisplay(); step2_submitphpaction(); enablechange(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 3 @@ -229,7 +229,7 @@ step3_submitphpaction(); enablechange(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 4 @@ -265,7 +265,7 @@ step4_stepbeforeformdisplay(); step4_submitphpaction(); enablechange(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 5 @@ -314,7 +314,7 @@ step5_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 6 @@ -343,7 +343,7 @@ step6_stepbeforeformdisplay(); step6_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 7 @@ -444,7 +444,7 @@ step7_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc enablechange(); @@ -474,7 +474,7 @@ step8_stepbeforeformdisplay(); step8_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 9 @@ -576,7 +576,7 @@ step9_stepbeforeformdisplay(); step9_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 10 @@ -911,7 +911,7 @@ step10_stepbeforeformdisplay(); step10_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc 11 @@ -979,6 +979,6 @@ step12_submitphpaction(); - /usr/local/www/wizards/openvpn_wizard.inc + openvpn_wizard.inc diff --git a/src/www/wizards/setup_wizard.xml b/src/wizard/setup.xml similarity index 99% rename from src/www/wizards/setup_wizard.xml rename to src/wizard/setup.xml index db1fa8106..803962513 100644 --- a/src/www/wizards/setup_wizard.xml +++ b/src/wizard/setup.xml @@ -484,7 +484,7 @@ $config['interfaces']['wan']['ipaddr'] = $_POST['selectedtype']; write_config(); if(!$config['interfaces']['lan']) - header("Location: /wizard.php?xml=setup_wizard.xml&stepid=6&next=Next"); + header("Location: /wizard.php?xml=setup&stepid=6&next=Next"); } ]]> @@ -622,7 +622,7 @@ Reload in progress A reload is now in progress. Please wait. <p> - <meta http-equiv="refresh" content="5; url=wizard.php?xml=setup_wizard.xml&stepid=8" > + <meta http-equiv="refresh" content="5; url=wizard.php?xml=setup&stepid=8" > <p> The wizard will redirect to the next step once the reload is completed. diff --git a/src/www/index.php b/src/www/index.php index 24769f63c..66b657622 100644 --- a/src/www/index.php +++ b/src/www/index.php @@ -400,7 +400,7 @@ if (isset($config['trigger_initial_wizard'])) : - + diff --git a/src/www/vpn_openvpn_server.php b/src/www/vpn_openvpn_server.php index e5d847a09..a54d652cb 100644 --- a/src/www/vpn_openvpn_server.php +++ b/src/www/vpn_openvpn_server.php @@ -1771,7 +1771,7 @@ else : - +   diff --git a/src/www/wizard.php b/src/www/wizard.php index 00df14a1a..ad6861e3d 100644 --- a/src/www/wizard.php +++ b/src/www/wizard.php @@ -70,41 +70,67 @@ function find_ip_interface($ip, $bits = null) { } -global $g; - $stepid = htmlspecialchars($_GET['stepid']); if (isset($_POST['stepid'])) $stepid = htmlspecialchars($_POST['stepid']); if (!$stepid) $stepid = "0"; -$xml = htmlspecialchars($_GET['xml']); -if($_POST['xml']) +$xml = ''; +if (isset($_GET['xml'])) { + $xml = htmlspecialchars($_GET['xml']); +} elseif (isset($_POST['xml'])) { $xml = htmlspecialchars($_POST['xml']); - -if(empty($xml)) { - $xml = "not_defined"; - print_info_box_np(sprintf(gettext("ERROR: Could not open %s."), $xml)); - die; -} else { - if (file_exists("/usr/local/www/wizards/{$xml}")) { - global $listtags ; - $listtags = array_flip(array('build_port_path', 'depends_on_package', 'onetoone', 'queue', 'rule', 'servernat', 'alias', 'additional_files_needed', 'tab', 'template', 'menu', 'rowhelperfield', 'service', 'step', 'package', 'columnitem', 'option', 'item', 'field', 'package', 'file')); - $pkg = parse_xml_config_raw('/usr/local/www/wizards/' . $xml, 'opnsensewizard', false); - } else { - print_info_box_np(sprintf(gettext("ERROR: Could not open %s."), $xml)); - die; - } } +/* + * XXX If we don't want hardcoding we could + * probe /usr/local/wizard for viable files. + */ +switch ($xml) { + case 'openvpn': + $xml = 'openvpn.xml'; + break; + default: + $xml = 'setup.xml'; + break; +} + +global $g, $listtags; + +$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, 'opnsensewizard', false); if (!is_array($pkg)) { - print_info_box_np(sprintf(gettext("ERROR: Could not parse /usr/local/www/wizards/%s file."), $xml)); + print_info_box_np(sprintf(gettext("ERROR: Could not parse %s wizard file."), $xml)); die; } -$title = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']); $description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']); -$totalsteps = $pkg['totalsteps']; +$title = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']); +$totalsteps = $pkg['totalsteps']; if ($pkg['includefile']) require_once($pkg['includefile']);