1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-19 13:01:26 +02:00

Small improvements to ProcessWire installer

This commit is contained in:
Ryan Cramer
2019-07-04 10:47:58 -04:00
parent 5663803e05
commit b5b1a796ec
3 changed files with 95 additions and 22 deletions

View File

@@ -11,10 +11,11 @@
* If that file exists, the installer will not run. So if you need to re-run this installer for any * If that file exists, the installer will not run. So if you need to re-run this installer for any
* reason, then you'll want to delete that file. This was implemented just in case someone doesn't delete the installer. * reason, then you'll want to delete that file. This was implemented just in case someone doesn't delete the installer.
* *
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer * ProcessWire 3.x, Copyright 2019 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @todo have installer set session name * @todo have installer set session name
* @todo have installer support enabling debug mode if user chooses it
* *
*/ */
@@ -322,7 +323,7 @@ class Installer {
} }
$this->checkFunction("filter_var", "Filter functions (filter_var)"); $this->checkFunction("filter_var", "Filter functions (filter_var)");
$this->checkFunction("mysqli_connect", "MySQLi (not required by core, but may be required by some 3rd party modules)"); $this->checkFunction("mysqli_connect", "MySQLi (not used by core, but may still be used by some older 3rd party modules)");
$this->checkFunction("imagecreatetruecolor", "GD 2.0 or newer"); $this->checkFunction("imagecreatetruecolor", "GD 2.0 or newer");
$this->checkFunction("json_encode", "JSON support"); $this->checkFunction("json_encode", "JSON support");
$this->checkFunction("preg_match", "PCRE support"); $this->checkFunction("preg_match", "PCRE support");
@@ -334,7 +335,7 @@ class Installer {
if(function_exists('apache_get_modules')) { if(function_exists('apache_get_modules')) {
if(in_array('mod_rewrite', apache_get_modules())) $this->ok("Found Apache module: mod_rewrite"); if(in_array('mod_rewrite', apache_get_modules())) $this->ok("Found Apache module: mod_rewrite");
else $this->err("Apache mod_rewrite does not appear to be installed and is required by ProcessWire."); else $this->err("Apache 'mod_rewrite' module does not appear to be installed and is required by ProcessWire.");
} else { } else {
// apache_get_modules doesn't work on a cgi installation. // apache_get_modules doesn't work on a cgi installation.
// check for environment var set in htaccess file, as submitted by jmarjie. // check for environment var set in htaccess file, as submitted by jmarjie.
@@ -342,7 +343,11 @@ class Installer {
if($mod_rewrite) { if($mod_rewrite) {
$this->ok("Found Apache module (cgi): mod_rewrite"); $this->ok("Found Apache module (cgi): mod_rewrite");
} else { } else {
$this->err("Unable to determine if Apache mod_rewrite (required by ProcessWire) is installed. On some servers, we may not be able to detect it until your .htaccess file is place. Please click the 'check again' button at the bottom of this screen, if you haven't already."); $this->err(
"Unable to determine if Apache mod_rewrite (required by ProcessWire) is installed. " .
"On some servers, we may not be able to detect it until your .htaccess file is place. " .
"Please click the 'check again' button at the bottom of this screen, if you haven't already."
);
} }
} }
@@ -863,9 +868,10 @@ class Installer {
if(is_dir($profile . "files")) $this->profileImportFiles($profile); if(is_dir($profile . "files")) $this->profileImportFiles($profile);
else $this->mkdir("./site/assets/files/"); else $this->mkdir("./site/assets/files/");
$this->mkdir("./site/assets/cache/"); $this->mkdir("./site/assets/cache/", true, true);
$this->mkdir("./site/assets/logs/"); $this->mkdir("./site/assets/logs/", true, true);
$this->mkdir("./site/assets/sessions/"); $this->mkdir("./site/assets/backups/", true, true);
$this->mkdir("./site/assets/sessions/", true, true);
} else { } else {
$this->ok("A profile is already imported, skipping..."); $this->ok("A profile is already imported, skipping...");
@@ -890,6 +896,16 @@ class Installer {
} else { } else {
// they are installing site-default already // they are installing site-default already
} }
// install the site/.htaccess (not really required but potentially useful fallback)
$dir = "./site/";
$defaultDir = "./site-default/";
if(is_file($dir . 'htaccess.txt')) {
$this->renameFile($dir . 'htaccess.txt', $dir . '.htaccess');
} else if(is_file($defaultDir . 'htaccess.txt')) {
$this->copyFile($defaultDir . 'htaccess.txt', $dir . '.htaccess');
}
$this->sectionStop(); $this->sectionStop();
$this->adminAccount(); $this->adminAccount();
} }
@@ -1042,11 +1058,20 @@ class Installer {
$this->btn("Continue", 5); $this->btn("Continue", 5);
} }
/**
* 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($wire, $getMarkup = false, $removeNow = false) {
$root = dirname(__FILE__) . '/'; $root = dirname(__FILE__) . '/';
$isPost = $wire->input->post->remove_items !== null; $isPost = $wire->input->post('remove_items') !== null;
$postItems = $isPost ? $wire->input->post->remove_items : array(); $postItems = $isPost ? $wire->input->post('remove_items') : array();
if(!is_array($postItems)) $postItems = array(); if(!is_array($postItems)) $postItems = array();
$out = ''; $out = '';
@@ -1508,21 +1533,60 @@ class Installer {
/** /**
* Create a directory and assign permission * Create a directory and assign permission
* *
* @param string $path * @param string $path Path to create
* @param bool $showNote * @param bool $showNote Show notification about what was done?
* @param bool $block Add an htaccess file that blocks http access? (default=false)
* @return bool * @return bool
* *
*/ */
protected function mkdir($path, $showNote = true) { protected function mkdir($path, $showNote = true, $block = false) {
if(self::TEST_MODE) return true; if(self::TEST_MODE) return true;
if(is_dir($path) || mkdir($path)) { $path = rtrim($path, '/') . '/';
$isDir = is_dir($path);
if($isDir || mkdir($path)) {
chmod($path, octdec($this->chmodDir)); chmod($path, octdec($this->chmodDir));
if($showNote) $this->alertOk("Created directory: $path"); if($showNote && !$isDir) $this->alertOk("Created directory: $path");
return true; $result = true;
} else { } else {
if($showNote) $this->alertErr("Error creating directory: $path"); if($showNote) $this->alertErr("Error creating directory: $path");
$result = false;
}
$file = $path . '.htaccess';
if($result && $block && !file_exists($file)) {
$data = array(
'# Start ProcessWire:pwball (install)',
'# Block all access (fallback if root .htaccess missing)',
'<IfModule mod_authz_core.c>',
' Require all denied',
'</IfModule>',
'<IfModule !mod_authz_core.c>',
' Order allow,deny',
' Deny from all',
'</IfModule>',
'# End ProcessWire:pwball',
);
file_put_contents($file, implode("\n", $data));
chmod($file, octdec($this->chmodFile));
}
return $result;
}
protected function copyFile($src, $dst) {
if(!@copy($src, $dst)) {
$this->alertErr("Unable to copy $src => $dst (please copy manually if possible)");
return false; return false;
} }
chmod($dst, octdec($this->chmodFile));
return true;
}
protected function renameFile($src, $dst) {
if(!@rename($src, $dst)) {
$this->alertErr("Unable to rename $src => $dst (please rename manually if possible)");
return false;
}
chmod($dst, octdec($this->chmodFile));
return true;
} }
/** /**
@@ -1562,8 +1626,15 @@ class Installer {
return true; return true;
} }
/**
* Get all timezone selections
*
* @return array
*
*/
protected function timezones() { protected function timezones() {
$timezones = timezone_identifiers_list(); $timezones = timezone_identifiers_list();
if(!is_array($timezones)) return array('UTC');
$extras = array( $extras = array(
'US Eastern|America/New_York', 'US Eastern|America/New_York',
'US Central|America/Chicago', 'US Central|America/Chicago',

View File

@@ -1,4 +1,5 @@
# ProcessWire: Block any PHP files from direct access # Start ProcessWire:pwbphp (install)
# Block PHP files from direct access (optional fallback if root .htaccess missing)
<FilesMatch "\.(php|module|inc)$"> <FilesMatch "\.(php|module|inc)$">
<IfModule mod_authz_core.c> <IfModule mod_authz_core.c>
Require all denied Require all denied
@@ -8,3 +9,4 @@
Deny from all Deny from all
</IfModule> </IfModule>
</FilesMatch> </FilesMatch>
# End ProcessWire:pwbphp

View File

@@ -10,7 +10,7 @@ if(!defined("PROCESSWIRE_INSTALL")) die();
<!-- FOOTER --> <!-- FOOTER -->
<footer id='pw-footer' class='uk-margin'> <footer id='pw-footer' class='uk-margin'>
<div class='pw-container uk-container uk-container-center'> <div class='pw-container uk-container uk-container-center'>
<p>ProcessWire 3.x &copy; 2018</p> <p>ProcessWire 3.x &copy; 2019</p>
</div> </div>
</footer> </footer>