From 161d6fb737d2f201e2ffb3c113071a794b1e51d3 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 5 Jul 2019 11:35:25 -0400 Subject: [PATCH] Upgrade ProcessWire installer (and related site profile files) to support specification of debug mode as one of the interactive installation options. Also updated some wording in various parts of the installer. --- install.php | 102 +++++++++++++++++++++++++++++--------- site-beginner/config.php | 12 ----- site-blank/config.php | 12 ----- site-classic/config.php | 12 ----- site-default/config.php | 12 ----- site-default/finished.php | 2 + site-default/init.php | 2 + site-default/ready.php | 2 + site-languages/config.php | 12 ----- site-regular/config.php | 16 +----- site-regular/ready.php | 2 + 11 files changed, 89 insertions(+), 97 deletions(-) diff --git a/install.php b/install.php index 48da1552..df08cb3f 100644 --- a/install.php +++ b/install.php @@ -15,7 +15,6 @@ * https://processwire.com * * @todo have installer set session name - * @todo have installer support enabling debug mode if user chooses it * */ @@ -543,11 +542,35 @@ class Installer { $this->sectionStop(); $this->sectionStart('fa-server HTTP Host Names'); - $this->p("What host names will this installation run on now and in the future? Please enter one host per line. You may also choose to leave this blank to auto-detect on each request, but we recommend using this whitelist for the best security in production environments."); - $this->p("This field is recommended but not required. You can set this later by editing the file /site/config.php (setting \$config->httpHosts).", "detail"); + $this->p( + "What host names will this installation run on now and in the future? Please enter one host per line. " . + "You can also modify this setting later by editing the \$config->httpHosts setting in the /site/config.php file." + ); $rows = substr_count($values['httpHosts'], "\n") + 2; $this->textarea('httpHosts', '', $values['httpHosts'], $rows); $this->sectionStop(); + + $this->sectionStart('fa-bug Debug mode?'); + $this->p( + "When debug mode is enabled, errors and exceptions are visible in ProcessWire’s output. This is helpful when developing a website or testing ProcessWire. " . + "When debug mode is NOT enabled, fatal errors/exceptions halt the request with an ambiguous http 500 error, and non-fatal errors are not shown. " . + "Regardless of debug mode, fatal errors are always logged and always visible to superusers. " . + "Debug mode should not be enabled for live or production sites, but at this stage (installation) it is worthwhile to have it enabled. " + ); + $noChecked = empty($values['debugMode']) ? "checked='checked'" : ""; + $yesChecked = empty($noChecked) ? "checked='checked'" : ""; + $this->p( + "
" . + " " + ); + $this->p( + "You can also enable or disable debug mode at any time by editing the /site/config.php file and setting " . + "\$config->debug = true; or \$config->debug = false;" + ); + $this->sectionStop(); + $this->btn("Continue", 4); $this->p("Note: After you click the button above, be patient … it may take a minute.", "detail"); } @@ -570,6 +593,7 @@ class Installer { $values[$field] = $value; } + // timezone $timezone = (int) $_POST['timezone']; $timezones = $this->timezones(); if(isset($timezones[$timezone])) { @@ -583,6 +607,7 @@ class Installer { $values['timezone'] = 'America/New_York'; } + // http hosts $values['httpHosts'] = array(); $httpHosts = trim($_POST['httpHosts']); if(strlen($httpHosts)) { @@ -594,6 +619,9 @@ class Installer { } $values['httpHosts'] = $httpHosts; } + + // debug mode + $values['debugMode'] = (int) $_POST['debugMode']; // db configuration $fields = array('dbUser', 'dbName', 'dbPass', 'dbHost', 'dbPort', 'dbEngine', 'dbCharset'); @@ -822,6 +850,18 @@ class Installer { $cfg = rtrim($cfg, ", ") . ");\n\n"; } + $cfg .= + "\n/**" . + "\n * Installer: Debug mode?" . + "\n * " . + "\n * When debug mode is true, errors and exceptions are visible. " . + "\n * When false, they are not visible except to superuser and in logs. " . + "\n * Should be true for development sites and false for live/production sites. " . + "\n * " . + "\n */" . + "\n\$config->debug = " . ($values['debugMode'] ? 'true;' : 'false;') . + "\n\n"; + if(($fp = fopen("./site/config.php", "a")) && fwrite($fp, $cfg)) { fclose($fp); $this->alertOk("Saved configuration to ./site/config.php"); @@ -1052,7 +1092,7 @@ class Installer { $this->sectionStart("fa-bath Cleanup"); $this->p("Directories and files listed below are no longer needed and should be removed. If you choose to leave any of them in place, you should delete them before migrating to a production environment.", "detail"); - $this->p($this->getRemoveableItems($wire, true)); + $this->p($this->getRemoveableItems(true)); $this->sectionStop(); $this->btn("Continue", 5); @@ -1061,17 +1101,16 @@ class Installer { /** * Get post-install optionally removable items * - * @param ProcessWire $wire * @param bool $getMarkup Get markup of options/form inputs rather than array of items? * @param bool $removeNow Allow processing of submitted form (via getMarkup) to remove items now? * @return array|string * */ - protected function getRemoveableItems($wire, $getMarkup = false, $removeNow = false) { + protected function getRemoveableItems($getMarkup = false, $removeNow = false) { $root = dirname(__FILE__) . '/'; - $isPost = $wire->input->post('remove_items') !== null; - $postItems = $isPost ? $wire->input->post('remove_items') : array(); + $isPost = isset($_POST['remove_items']); + $postItems = $isPost ? $_POST['remove_items'] : array(); if(!is_array($postItems)) $postItems = array(); $out = ''; @@ -1124,7 +1163,7 @@ class Installer { $success = true; } if($success) { - $this->ok("Completed: " . $item['label']); + // $this->ok("Completed: " . $item['label']); } else { $this->err("Unable to remove $item[file] - please remove manually, as it is no longer needed"); } @@ -1136,7 +1175,9 @@ class Installer { } } + if(empty($out)) $out = "None found"; if($getMarkup) return $out; + return $items; } @@ -1226,22 +1267,36 @@ class Installer { $this->sectionStop(); $this->sectionStart("fa-life-buoy Complete & Secure Your Installation"); - $this->getRemoveableItems($wire, false, true); + $this->getRemoveableItems(false, true); $this->ok("Note that future runtime errors are logged to /site/assets/logs/errors.txt (not web accessible)."); - $this->ok("For more configuration options see /wire/config.php and place any edits in /site/config.php."); + $this->ok("For more configuration options see /wire/config.php and place any edits in /site/config.php."); + $this->ok("Consider making your /site/config.php file non-writable, and readable only to you and Apache."); + $this->ok("View and edit your .htaccess file to force HTTPS, setup redirects, and more."); + $this->p( - "Please make your /site/config.php file non-writable, and readable only to you and Apache.
" . - "" . - "How to secure your /site/config.php file " + "" . + "Lean more about securing your ProcessWire installation " ); $this->sectionStop(); if(is_writable("./site/modules/")) wireChmod("./site/modules/", true); - $this->sectionStart("fa-coffee Use The Site!"); - $this->ok("Your admin URL is /$adminName/"); - $this->p("If you'd like, you may change this later by editing the admin page and changing the name.", "detail"); + $this->sectionStart("fa-coffee Get Started!"); + $this->ok( + "Your admin URL is /$adminName/" + ); + $this->ok( + "Learn more about ProcessWire in the documentation " . + "and API reference. " + ); + $this->ok( + "Visit our support forums for friendly help and discussion." + ); + $this->ok( + "Subscribe to keep up-to-date " . + "with new versions and important updates." + ); $this->sectionStop(); $this->btn("Login to Admin", 1, 'sign-in', false, true, "./$adminName/"); @@ -1261,13 +1316,14 @@ class Installer { /** * @param string $str + * @param string $icon * */ - protected function alertOk($str) { + protected function alertOk($str, $icon = 'check') { if($this->inSection) { $this->ok($str); } else { - echo "\n
$str
"; + echo "\n
$str
"; } } @@ -1337,15 +1393,15 @@ class Installer { * Report success * * @param string $str + * @param string $icon * @return bool * */ - protected function ok($str) { + protected function ok($str, $icon = 'check') { if(!$this->inSection) { $this->alertOk($str); } else { - //echo "\n
  • $str
  • "; - echo "\n
    $str
    "; + echo "\n
    $str
    "; } return true; } @@ -1366,7 +1422,7 @@ class Installer { if($float) $class .= " uk-float-left"; $type = 'submit'; if($href) $type = 'button'; - if($href) echo ""; + if($href) echo ""; echo "\n

    "; diff --git a/site-beginner/config.php b/site-beginner/config.php index 94ac48af..cefe9967 100644 --- a/site-beginner/config.php +++ b/site-beginner/config.php @@ -28,18 +28,6 @@ if(!defined("PROCESSWIRE")) die(); /** @var Config $config */ -/** - * Enable debug mode? - * - * Debug mode causes additional info to appear for use during dev and debugging. - * This is almost always recommended for sites in development. However, you should - * always have this disabled for live/production sites. - * - * @var bool - * - */ -$config->debug = false; - /** * Prepend template file * diff --git a/site-blank/config.php b/site-blank/config.php index 300c6b27..2e0821dc 100644 --- a/site-blank/config.php +++ b/site-blank/config.php @@ -28,18 +28,6 @@ if(!defined("PROCESSWIRE")) die(); /** @var Config $config */ -/** - * Enable debug mode? - * - * Debug mode causes additional info to appear for use during dev and debugging. - * This is almost always recommended for sites in development. However, you should - * always have this disabled for live/production sites. - * - * @var bool - * - */ -$config->debug = false; - /** * Allow core API variables to also be accessed as functions? * diff --git a/site-classic/config.php b/site-classic/config.php index 700d5436..15ec6907 100644 --- a/site-classic/config.php +++ b/site-classic/config.php @@ -28,18 +28,6 @@ if(!defined("PROCESSWIRE")) die(); /** @var Config $config */ -/** - * Enable debug mode? - * - * Debug mode causes additional info to appear for use during dev and debugging. - * This is almost always recommended for sites in development. However, you should - * always have this disabled for live/production sites. - * - * @var bool - * - */ -$config->debug = false; - /** * Allow core API variables to also be accessed as functions? * diff --git a/site-default/config.php b/site-default/config.php index 6c5acb36..06a3dd80 100755 --- a/site-default/config.php +++ b/site-default/config.php @@ -28,18 +28,6 @@ if(!defined("PROCESSWIRE")) die(); /** @var Config $config */ -/** - * Enable debug mode? - * - * Debug mode causes additional info to appear for use during dev and debugging. - * This is almost always recommended for sites in development. However, you should - * always have this disabled for live/production sites. - * - * @var bool - * - */ -$config->debug = false; - /** * Prepend template file * diff --git a/site-default/finished.php b/site-default/finished.php index 0e316226..c618feb1 100644 --- a/site-default/finished.php +++ b/site-default/finished.php @@ -1,5 +1,7 @@ debug = false; - /** * Prepend template file * diff --git a/site-regular/config.php b/site-regular/config.php index 9ebcfa84..0eaf235a 100644 --- a/site-regular/config.php +++ b/site-regular/config.php @@ -4,14 +4,14 @@ * ProcessWire Configuration File * * Site-specific configuration for ProcessWire. - * This config.php file was generated by the ProcessExportProfile module. + * https://processwire.com/api/ref/config/ * * Please see the file /wire/config.php which contains all configuration options you may * specify here. Simply copy any of the configuration options from that file and paste * them into this file in order to modify them. * * ProcessWire 3.x - * Copyright (C) 2018 by Ryan Cramer + * Copyright (C) 2019 by Ryan Cramer * * https://processwire.com * @@ -21,18 +21,6 @@ if(!defined("PROCESSWIRE")) die(); /*** SITE CONFIG *************************************************************************/ -/** - * Enable debug mode? - * - * Debug mode causes additional info to appear for use during dev and debugging. - * This is almost always recommended for sites in development. However, you should - * always have this disabled for live/production sites. - * - * @var bool - * - */ -$config->debug = true; - $config->prependTemplateFile = '_init.php'; $config->appendTemplateFile = '_main.php'; $config->useMarkupRegions = true; diff --git a/site-regular/ready.php b/site-regular/ready.php index cf4a287b..2378f889 100644 --- a/site-regular/ready.php +++ b/site-regular/ready.php @@ -11,6 +11,8 @@ * */ +if(!defined("PROCESSWIRE")) die(); + /** @var ProcessWire $wire */ /**