Skip to content

Commit

Permalink
Upgrade ProcessWire installer (and related site profile files) to sup…
Browse files Browse the repository at this point in the history
…port specification of debug mode as one of the interactive installation options. Also updated some wording in various parts of the installer.
  • Loading branch information
ryancramerdesign committed Jul 5, 2019
1 parent 562565f commit 161d6fb
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 97 deletions.
102 changes: 79 additions & 23 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* https://processwire.com
*
* @todo have installer set session name
* @todo have installer support enabling debug mode if user chooses it
*
*/

Expand Down Expand Up @@ -543,11 +542,35 @@ protected function dbConfig($values = array(), $hasNumTables = 0) {
$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 <u>/site/config.php</u> (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 <code>\$config->httpHosts</code> setting in the <u>/site/config.php</u> 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(
"<label><input type='radio' name='debugMode' $yesChecked value='1'> <strong>Enabled</strong> " .
"<span class='uk-text-small uk-text-muted'>(recommended while sites are in development or while testing ProcessWire)</span></label><br />" .
"<label><input type='radio' name='debugMode' $noChecked value='0'> <strong>Disabled</strong> " .
"<span class='uk-text-small uk-text-muted'>(recommended once a site goes live or becomes publicly accessible)</span></label> "
);
$this->p(
"You can also enable or disable debug mode at any time by editing the <u>/site/config.php</u> file and setting " .
"<code>\$config->debug = true;</code> or <code>\$config->debug = false;</code>"
);
$this->sectionStop();

$this->btn("Continue", 4);
$this->p("Note: After you click the button above, be patient &hellip; it may take a minute.", "detail");
}
Expand All @@ -570,6 +593,7 @@ protected function dbSaveConfig() {
$values[$field] = $value;
}

// timezone
$timezone = (int) $_POST['timezone'];
$timezones = $this->timezones();
if(isset($timezones[$timezone])) {
Expand All @@ -583,6 +607,7 @@ protected function dbSaveConfig() {
$values['timezone'] = 'America/New_York';
}

// http hosts
$values['httpHosts'] = array();
$httpHosts = trim($_POST['httpHosts']);
if(strlen($httpHosts)) {
Expand All @@ -594,6 +619,9 @@ protected function dbSaveConfig() {
}
$values['httpHosts'] = $httpHosts;
}

// debug mode
$values['debugMode'] = (int) $_POST['debugMode'];

// db configuration
$fields = array('dbUser', 'dbName', 'dbPass', 'dbHost', 'dbPort', 'dbEngine', 'dbCharset');
Expand Down Expand Up @@ -822,6 +850,18 @@ protected function dbSaveConfigFile(array $values) {
$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");
Expand Down Expand Up @@ -1052,7 +1092,7 @@ protected function adminAccount($wire = null) {

$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);
Expand All @@ -1061,17 +1101,16 @@ protected function adminAccount($wire = null) {
/**
* 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 = '';

Expand Down Expand Up @@ -1124,7 +1163,7 @@ protected function getRemoveableItems($wire, $getMarkup = false, $removeNow = fa
$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");
}
Expand All @@ -1136,7 +1175,9 @@ protected function getRemoveableItems($wire, $getMarkup = false, $removeNow = fa
}
}

if(empty($out)) $out = "None found";
if($getMarkup) return $out;

return $items;
}

Expand Down Expand Up @@ -1226,22 +1267,36 @@ protected function adminAccountSave($wire) {
$this->sectionStop();

$this->sectionStart("fa-life-buoy Complete &amp; Secure Your Installation");
$this->getRemoveableItems($wire, false, true);
$this->getRemoveableItems(false, true);

$this->ok("Note that future runtime errors are logged to <b>/site/assets/logs/errors.txt</b> (not web accessible).");
$this->ok("For more configuration options see <b>/wire/config.php</b> and place any edits in /site/config.php.");
$this->ok("For more configuration options see <b>/wire/config.php</b> and place any edits in <u>/site/config.php</u>.");
$this->ok("Consider making your <b>/site/config.php</b> file non-writable, and readable only to you and Apache.");
$this->ok("View and edit your <b>.htaccess</b> file to force HTTPS, setup redirects, and more.");

$this->p(
"Please make your <b>/site/config.php</b> file non-writable, and readable only to you and Apache.<br />" .
"<a target='_blank' href='https://processwire.com/docs/security/file-permissions/#securing-your-site-config.php-file'>" .
"How to secure your /site/config.php file <i class='fa fa-angle-right'></i></a>"
"<a target='_blank' href='https://processwire.com/docs/security/'>" .
"Lean more about securing your ProcessWire installation <i class='fa fa-angle-right'></i></a>"
);
$this->sectionStop();

if(is_writable("./site/modules/")) wireChmod("./site/modules/", true);

$this->sectionStart("fa-coffee Use The Site!");
$this->ok("Your admin URL is <a href='./$adminName/'>/$adminName/</a>");
$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 <a target='_blank' href='./$adminName/'>/$adminName/</a>"
);
$this->ok(
"Learn more about ProcessWire in the <a target='_blank' href='https://processwire.com/docs/'>documentation</a> " .
"and <a target='_blank' href='https://processwire.com/api/ref/'>API reference</a>. "
);
$this->ok(
"Visit our <a target='_blank' href='https://processwire.com/talk/'>support forums</a> for friendly help and discussion."
);
$this->ok(
"<a target='_blank' href='https://processwire.com/community/newsletter/subscribe/'>Subscribe to keep up-to-date</a> " .
"with new versions and important updates."
);
$this->sectionStop();

$this->btn("Login to Admin", 1, 'sign-in', false, true, "./$adminName/");
Expand All @@ -1261,13 +1316,14 @@ protected function adminAccountSave($wire) {

/**
* @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<div class='uk-alert uk-alert-primary'><i class='fa fa-fw fa-check'></i> $str</div>";
echo "\n<div class='uk-alert uk-alert-primary'><i class='fa fa-fw fa-$icon'></i> $str</div>";
}
}

Expand Down Expand Up @@ -1337,15 +1393,15 @@ protected function warn($str) {
* 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<li class='ui-state-highlight'><i class='fa fa-check-square-o'></i> $str</li>";
echo "\n<div class=''><i class='fa fa-fw fa-check'></i> $str</div>";
echo "\n<div class=''><i class='fa fa-fw fa-$icon'></i> $str</div>";
}
return true;
}
Expand All @@ -1366,7 +1422,7 @@ protected function btn($label, $value, $icon = 'angle-right', $secondary = false
if($float) $class .= " uk-float-left";
$type = 'submit';
if($href) $type = 'button';
if($href) echo "<a href='$href'>";
if($href) echo "<a href='$href' target='_blank'>";
echo "\n<p><button name='step' type='$type' class='ui-button ui-widget ui-state-default $class ui-corner-all' value='$value'>";
echo "<span class='ui-button-text'><i class='fa fa-$icon'></i> $label</span>";
echo "</button></p>";
Expand Down
12 changes: 0 additions & 12 deletions site-beginner/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

/** @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
*
Expand Down
12 changes: 0 additions & 12 deletions site-blank/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

/** @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?
*
Expand Down
12 changes: 0 additions & 12 deletions site-classic/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

/** @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?
*
Expand Down
12 changes: 0 additions & 12 deletions site-default/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

/** @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
*
Expand Down
2 changes: 2 additions & 0 deletions site-default/finished.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace ProcessWire;

if(!defined("PROCESSWIRE")) die();

/**
* ProcessWire Request Finished
* ============================
Expand Down
2 changes: 2 additions & 0 deletions site-default/init.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace ProcessWire;

if(!defined("PROCESSWIRE")) die();

/**
* ProcessWire Bootstrap Initialization
* ====================================
Expand Down
2 changes: 2 additions & 0 deletions site-default/ready.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace ProcessWire;

if(!defined("PROCESSWIRE")) die();

/**
* ProcessWire Bootstrap API Ready
* ===============================
Expand Down
12 changes: 0 additions & 12 deletions site-languages/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

/** @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
*
Expand Down
16 changes: 2 additions & 14 deletions site-regular/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -21,18 +21,6 @@

/*** 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;
Expand Down
2 changes: 2 additions & 0 deletions site-regular/ready.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*
*/

if(!defined("PROCESSWIRE")) die();

/** @var ProcessWire $wire */

/**
Expand Down

0 comments on commit 161d6fb

Please sign in to comment.