From: Diogo Cordeiro Date: Mon, 15 Jul 2019 00:40:31 +0000 (+0100) Subject: [INSTALL] Minor reformatting and modernization. Shouldn't change functionality signif... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=893bafa14b7fd5c1cbc1cc0dcd712371d721be43;p=quix0rs-gnu-social.git [INSTALL] Minor reformatting and modernization. Shouldn't change functionality significatively. --- diff --git a/lib/installer.php b/lib/installer.php index f0fedc524b..acbea35ee5 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -1,76 +1,88 @@ . /** - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2009-2010, StatusNet, Inc. + * Installation lib * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * @category Installation - * @package Installation - * - * @author Adrian Lang - * @author Brenda Wallace - * @author Brett Taylor - * @author Brion Vibber - * @author CiaranG - * @author Craig Andrews - * @author Eric Helgeson - * @author Evan Prodromou - * @author Mikael Nordfeldth - * @author Robin Millette - * @author Sarven Capadisli - * @author Tom Adams - * @author Zach Copley - * @copyright 2009-2010 StatusNet, Inc http://status.net - * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org - * @license GNU Affero General Public License http://www.gnu.org/licenses/ - * @version 1.0.x - * @link http://status.net + * @package Installation + * @author Adrian Lang + * @author Brenda Wallace + * @author Brett Taylor + * @author Brion Vibber + * @author CiaranG + * @author Craig Andrews + * @author Eric Helgeson + * @author Evan Prodromou + * @author Mikael Nordfeldth + * @author Robin Millette + * @author Sarven Capadisli + * @author Tom Adams + * @author Zach Copley + * @author Diogo Cordeiro + * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ abstract class Installer { /** Web site info */ - public $sitename, $server, $path, $fancy, $siteProfile, $ssl; + public $sitename; + public $server; + public $path; + public $fancy; + public $siteProfile; + public $ssl; /** DB info */ - public $host, $database, $dbtype, $username, $password, $db; + public $host; + public $database; + public $dbtype; + public $username; + public $password; + public $db; /** Storage info */ - public $avatarDir, $fileDir; + public $avatarDir; + public $fileDir; /** Administrator info */ - public $adminNick, $adminPass, $adminEmail; + public $adminNick; + public $adminPass; + public $adminEmail; /** Should we skip writing the configuration file? */ public $skipConfig = false; - public static $dbModules = array( - 'mysql' => array( + public static $dbModules = [ + 'mysql' => [ 'name' => 'MariaDB 10.3+', 'check_module' => 'mysqli', 'scheme' => 'mysqli', // DSN prefix for PEAR::DB - ), -/* 'pgsql' => array( + ], + /*'pgsql' => [ 'name' => 'PostgreSQL', 'check_module' => 'pgsql', 'scheme' => 'pgsql', // DSN prefix for PEAR::DB - ),*/ - ); + ]*/ + ]; /** * Attempt to include a PHP file and report if it worked, while * suppressing the annoying warning messages on failure. + * @param string $filename + * @return bool */ - private function haveIncludeFile($filename) { + private function haveIncludeFile(string $filename): bool + { $old = error_reporting(error_reporting() & ~E_WARNING); $ok = include_once($filename); error_reporting($old); @@ -80,13 +92,13 @@ abstract class Installer /** * Check if all is ready for installation * - * @return void + * @return bool */ - function checkPrereqs() + public function checkPrereqs(): bool { $pass = true; - $config = INSTALLDIR.'/config.php'; + $config = INSTALLDIR . '/config.php'; if (!$this->skipConfig && file_exists($config)) { if (!is_writable($config) || filesize($config) > 0) { if (filesize($config) == 0) { @@ -103,20 +115,19 @@ abstract class Installer $pass = false; } - $reqs = array('gd', 'curl', 'intl', 'json', - 'xmlwriter', 'mbstring', 'xml', 'dom', 'simplexml'); - + $reqs = ['bcmath', 'curl', 'dom', 'gd', 'intl', 'json', 'mbstring', 'openssl', 'simplexml', 'xml', 'xmlwriter']; foreach ($reqs as $req) { - if (!$this->checkExtension($req)) { + // Checks if a php extension is both installed and loaded + if (!extension_loaded($req)) { $this->warning(sprintf('Cannot load required extension: %s', $req)); $pass = false; } } // Make sure we have at least one database module available - $missingExtensions = array(); + $missingExtensions = []; foreach (self::$dbModules as $type => $info) { - if (!$this->checkExtension($info['check_module'])) { + if (!extension_loaded($info['check_module'])) { $missingExtensions[] = $info['check_module']; } } @@ -129,8 +140,10 @@ abstract class Installer // @fixme this check seems to be insufficient with Windows ACLs if (!$this->skipConfig && !is_writable(INSTALLDIR)) { - $this->warning(sprintf('Cannot write config file to: %s

', INSTALLDIR), - sprintf('On your server, try this command: chmod a+w %s', INSTALLDIR)); + $this->warning( + sprintf('Cannot write config file to: %s

', INSTALLDIR), + sprintf('On your server, try this command: chmod a+w %s', INSTALLDIR) + ); $pass = false; } @@ -140,22 +153,29 @@ abstract class Installer define('GNUSOCIAL', true); define('STATUSNET', true); require_once INSTALLDIR . '/lib/language.php'; - $_server=$this->server; $_path=$this->path; // We won't be using those so it's safe to do this small hack - require_once INSTALLDIR.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'util.php'; - require_once INSTALLDIR.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'default.php'; - $fileSubdirs = [empty($this->avatarDir) ? $default['avatar']['dir'] : $this->avatarDir, - empty($this->fileDir) ? $default['attachments']['dir'] : $this->fileDir]; + $_server = $this->server; + $_path = $this->path; // We won't be using those so it's safe to do this small hack + require_once INSTALLDIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'util.php'; + require_once INSTALLDIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'default.php'; + $fileSubdirs = [ + empty($this->avatarDir) ? $default['avatar']['dir'] : $this->avatarDir, + empty($this->fileDir) ? $default['attachments']['dir'] : $this->fileDir + ]; unset($default); foreach ($fileSubdirs as $fileFullPath) { if (!file_exists($fileFullPath)) { $pass = $pass && mkdir($fileFullPath); } elseif (!is_dir($fileFullPath)) { - $this->warning(sprintf('GNU social expected a directory but found something else on this path: %s', $fileFullPath), - 'Either make sure it goes to a directory or remove it and a directory will be created.'); + $this->warning( + sprintf('GNU social expected a directory but found something else on this path: %s', $fileFullPath), + 'Either make sure it goes to a directory or remove it and a directory will be created.' + ); $pass = false; } elseif (!is_writable($fileFullPath)) { - $this->warning(sprintf('Cannot write to %s directory: %s', $fileSubdir, $fileFullPath), - sprintf('On your server, try this command: chmod a+w %s', $fileFullPath)); + $this->warning( + sprintf('Cannot write to directory: %s', $fileFullPath), + sprintf('On your server, try this command: chmod a+w %s', $fileFullPath) + ); $pass = false; } } @@ -164,36 +184,12 @@ abstract class Installer } /** - * Checks if a php extension is both installed and loaded - * - * @param string $name of extension to check - * - * @return boolean whether extension is installed and loaded - */ - function checkExtension($name) - { - if (extension_loaded($name)) { - return true; - } elseif (function_exists('dl') && ini_get('enable_dl') && !ini_get('safe_mode')) { - // dl will throw a fatal error if it's disabled or we're in safe mode. - // More fun, it may not even exist under some SAPIs in 5.3.0 or later... - $soname = $name . '.' . PHP_SHLIB_SUFFIX; - if (PHP_SHLIB_SUFFIX == 'dll') { - $soname = "php_" . $soname; - } - return @dl($soname); - } else { - return false; - } - } - - /** - * Basic validation on the database paramters + * Basic validation on the database parameters * Side effects: error output if not valid * - * @return boolean success + * @return bool success */ - function validateDb() + public function validateDb(): bool { $fail = false; @@ -221,12 +217,12 @@ abstract class Installer } /** - * Basic validation on the administrator user paramters + * Basic validation on the administrator user parameters * Side effects: error output if not valid * - * @return boolean success + * @return bool success */ - function validateAdmin() + public function validateAdmin(): bool { $fail = false; @@ -236,15 +232,16 @@ abstract class Installer } if ($this->adminNick && !preg_match('/^[0-9a-z]{1,64}$/', $this->adminNick)) { $this->updateStatus('The user nickname "' . htmlspecialchars($this->adminNick) . - '" is invalid; should be plain letters and numbers no longer than 64 characters.', true); + '" is invalid; should be plain letters and numbers no longer than 64 characters.', true); $fail = true; } + // @fixme hardcoded list; should use Nickname::isValid() // if/when it's safe to have loaded the infrastructure here - $blacklist = array('main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook', 'activity'); + $blacklist = ['main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook', 'activity']; if (in_array($this->adminNick, $blacklist)) { $this->updateStatus('The user nickname "' . htmlspecialchars($this->adminNick) . - '" is reserved.', true); + '" is reserved.', true); $fail = true; } @@ -259,11 +256,11 @@ abstract class Installer /** * Make sure a site profile was selected * - * @return type boolean success + * @return bool success */ - function validateSiteProfile() + public function validateSiteProfile(): bool { - if (empty($this->siteProfile)) { + if (empty($this->siteProfile)) { $this->updateStatus("No site profile selected.", true); return false; } @@ -277,8 +274,9 @@ abstract class Installer * * @fixme escape things in the connection string in case we have a funny pass etc * @return mixed array of database connection params on success, false on failure + * @throws Exception */ - function setupDatabase() + public function setupDatabase() { if ($this->db) { throw new Exception("Bad order of operations: DB already set up."); @@ -302,15 +300,17 @@ abstract class Installer } // ensure database encoding is UTF8 + $conn->query('SET NAMES utf8mb4'); if ($this->dbtype == 'mysql') { - // @fixme utf8m4 support for mysql 5.5? - // Force the comms charset to utf8 for sanity - // This doesn't currently work. :P - //$conn->executes('set names utf8'); - } else if ($this->dbtype == 'pgsql') { - $record = $conn->getRow('SHOW server_encoding'); - if ($record->server_encoding != 'UTF8') { - $this->updateStatus("GNU social requires UTF8 character encoding. Your database is ". htmlentities($record->server_encoding)); + $server_encoding = $conn->getRow("SHOW VARIABLES LIKE 'character_set_server'")[1]; + if ($server_encoding != 'utf8mb4') { + $this->updateStatus("GNU social requires UTF8 character encoding. Your database is " . htmlentities($server_encoding)); + return false; + } + } elseif ($this->dbtype == 'pgsql') { + $server_encoding = $conn->getRow('SHOW server_encoding')[0]; + if ($server_encoding != 'UTF8') { + $this->updateStatus("GNU social requires UTF8 character encoding. Your database is " . htmlentities($server_encoding)); return false; } } @@ -321,29 +321,29 @@ abstract class Installer return false; } - foreach (array('sms_carrier' => 'SMS carrier', - 'notice_source' => 'notice source', - 'foreign_services' => 'foreign service') - as $scr => $name) { + foreach (['sms_carrier' => 'SMS carrier', + 'notice_source' => 'notice source', + 'foreign_services' => 'foreign service'] + as $scr => $name) { $this->updateStatus(sprintf("Adding %s data to database...", $name)); - $res = $this->runDbScript($scr.'.sql', $conn); + $res = $this->runDbScript($scr . '.sql', $conn); if ($res === false) { $this->updateStatus(sprintf("Can't run %s script.", $name), true); return false; } } - $db = array('type' => $this->dbtype, 'database' => $dsn); + $db = ['type' => $this->dbtype, 'database' => $dsn]; return $db; } /** * Open a connection to the database. * - * @param $dsn - * @return + * @param string $dsn + * @return DB|DB_Error */ - function connectDatabase($dsn) + public function connectDatabase(string $dsn) { global $_DB; return $_DB->connect($dsn); @@ -353,8 +353,9 @@ abstract class Installer * Create core tables on the given database connection. * * @param DB_common $conn + * @return bool */ - function createCoreTables(DB_common $conn) + public function createCoreTables(DB_common $conn): bool { $schema = Schema::get($conn); $tableDefs = $this->getCoreSchema(); @@ -372,9 +373,9 @@ abstract class Installer * * @return array of table names => table def arrays */ - function getCoreSchema() + public function getCoreSchema(): array { - $schema = array(); + $schema = []; include INSTALLDIR . '/db/core.php'; return $schema; } @@ -386,7 +387,7 @@ abstract class Installer * @param mixed $val * @return string */ - function phpVal($val) + public function phpVal($val): string { return var_export($val, true); } @@ -395,63 +396,63 @@ abstract class Installer * Return an array of parseable PHP literal for the given values. * These will include quotes for strings, etc. * - * @param mixed $val + * @param mixed $map * @return array */ - function phpVals($map) + public function phpVals($map): array { - return array_map(array($this, 'phpVal'), $map); + return array_map([$this, 'phpVal'], $map); } /** * Write a stock configuration file. * - * @return boolean success + * @return bool success * * @fixme escape variables in output in case we have funny chars, apostrophes etc */ - function writeConf() + public function writeConf(): bool { - $vals = $this->phpVals(array( + $vals = $this->phpVals([ 'sitename' => $this->sitename, 'server' => $this->server, 'path' => $this->path, - 'ssl' => in_array($this->ssl, array('never', 'always')) - ? $this->ssl - : 'never', + 'ssl' => in_array($this->ssl, ['never', 'always']) + ? $this->ssl + : 'never', 'db_database' => $this->db['database'], 'db_type' => $this->db['type'] - )); + ]); // assemble configuration file in a string - $cfg = "fancy ? "\$config['site']['fancy'] = true;\n\n":''). + // checks if fancy URLs are enabled + ($this->fancy ? "\$config['site']['fancy'] = true;\n\n" : '') . - // database - "\$config['db']['database'] = {$vals['db_database']};\n\n". - ($this->db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n":''). - "\$config['db']['type'] = {$vals['db_type']};\n\n". + // database + "\$config['db']['database'] = {$vals['db_database']};\n\n" . + ($this->db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n" : '') . + "\$config['db']['type'] = {$vals['db_type']};\n\n" . - "// Uncomment below for better performance. Just remember you must run\n". - "// php scripts/checkschema.php whenever your enabled plugins change!\n". - "//\$config['db']['schemacheck'] = 'script';\n\n"; + "// Uncomment below for better performance. Just remember you must run\n" . + "// php scripts/checkschema.php whenever your enabled plugins change!\n" . + "//\$config['db']['schemacheck'] = 'script';\n\n"; // Normalize line endings for Windows servers $cfg = str_replace("\n", PHP_EOL, $cfg); // write configuration file out to install directory - $res = file_put_contents(INSTALLDIR.'/config.php', $cfg); + $res = file_put_contents(INSTALLDIR . '/config.php', $cfg); return $res; } @@ -465,16 +466,16 @@ abstract class Installer * * @return int res number of bytes written */ - function writeSiteProfile() + public function writeSiteProfile(): int { - $vals = $this->phpVals(array( + $vals = $this->phpVals([ 'site_profile' => $this->siteProfile, 'nickname' => $this->adminNick - )); + ]); $cfg = - // site profile - "\$config['site']['profile'] = {$vals['site_profile']};\n"; + // site profile + "\$config['site']['profile'] = {$vals['site_profile']};\n"; if ($this->siteProfile == "singleuser") { $cfg .= "\$config['singleuser']['nickname'] = {$vals['nickname']};\n\n"; @@ -486,7 +487,7 @@ abstract class Installer $cfg = str_replace("\n", PHP_EOL, $cfg); // write configuration file out to install directory - $res = file_put_contents(INSTALLDIR.'/config.php', $cfg, FILE_APPEND); + $res = file_put_contents(INSTALLDIR . '/config.php', $cfg, FILE_APPEND); return $res; } @@ -494,12 +495,12 @@ abstract class Installer /** * Install schema into the database * - * @param string $filename location of database schema file - * @param DB_common $conn connection to database + * @param string $filename location of database schema file + * @param DB_common $conn connection to database * - * @return boolean - indicating success or failure + * @return bool - indicating success or failure */ - function runDbScript($filename, DB_common $conn) + public function runDbScript(string $filename, DB_common $conn): bool { $sql = trim(file_get_contents(INSTALLDIR . '/db/' . $filename)); $stmts = explode(';', $sql); @@ -509,7 +510,7 @@ abstract class Installer continue; } try { - $res = $conn->simpleQuery($stmt); + $res = $conn->query($stmt); } catch (Exception $e) { $error = $e->getMessage(); $this->updateStatus("ERROR ($error) for SQL '$stmt'"); @@ -524,16 +525,16 @@ abstract class Installer * Side effect: may load portions of GNU social framework. * Side effect: outputs program info */ - function registerInitialUser() + public function registerInitialUser(): bool { // initalize hostname from install arguments, so it can be used to find // the /etc config file from the commandline installer $server = $this->server; require_once INSTALLDIR . '/lib/common.php'; - $data = array('nickname' => $this->adminNick, - 'password' => $this->adminPass, - 'fullname' => $this->adminNick); + $data = ['nickname' => $this->adminNick, + 'password' => $this->adminPass, + 'fullname' => $this->adminNick]; if ($this->adminEmail) { $data['email'] = $this->adminEmail; } @@ -558,9 +559,9 @@ abstract class Installer * * Prerequisites: validation of input data. * - * @return boolean success + * @return bool success */ - function doInstall() + public function doInstall(): bool { global $config; @@ -595,8 +596,8 @@ abstract class Installer } if (!$this->skipConfig) { - // Make sure we can write to the file twice - $oldUmask = umask(000); + // Make sure we can write to the file twice + $oldUmask = umask(000); $this->updateStatus("Writing config file..."); $res = $this->writeConf(); @@ -631,18 +632,18 @@ abstract class Installer return false; } - // Restore original umask - umask($oldUmask); - // Set permissions back to something decent - chmod(INSTALLDIR.'/config.php', 0644); + // Restore original umask + umask($oldUmask); + // Set permissions back to something decent + chmod(INSTALLDIR . '/config.php', 0644); } - + $scheme = $this->ssl === 'always' ? 'https' : 'http'; $link = "{$scheme}://{$this->server}/{$this->path}"; $this->updateStatus("GNU social has been installed at $link"); $this->updateStatus( - 'DONE! You can visit your new GNU social site (log in as "'.htmlspecialchars($this->adminNick).'"). If this is your first GNU social install, make your experience the best possible by visiting our resource site to join the mailing list or IRC. FAQ is found here.' + 'DONE! You can visit your new GNU social site (log in as "' . htmlspecialchars($this->adminNick) . '"). If this is your first GNU social install, make your experience the best possible by visiting our resource site to join the mailing list or IRC. FAQ is found here.' ); return true; @@ -653,13 +654,12 @@ abstract class Installer * @param string $message HTML ok, but should be plaintext-able * @param string $submessage HTML ok, but should be plaintext-able */ - abstract function warning($message, $submessage=''); + abstract public function warning(string $message, string $submessage = ''); /** * Output an install-time progress message - * @param string $message HTML ok, but should be plaintext-able - * @param boolean $error true if this should be marked as an error condition + * @param string $status HTML ok, but should be plaintext-able + * @param bool $error true if this should be marked as an error condition */ - abstract function updateStatus($status, $error=false); - + abstract public function updateStatus(string $status, bool $error = false); } diff --git a/public/install.php b/public/install.php index dfa0eae5ee..b1b04a4300 100644 --- a/public/install.php +++ b/public/install.php @@ -1,57 +1,56 @@ . + /** - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2009-2010, StatusNet, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. + * Web Installer * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * @category Installation - * @package Installation - * - * @author Adrian Lang - * @author Brenda Wallace - * @author Brett Taylor - * @author Brion Vibber - * @author CiaranG - * @author Craig Andrews - * @author Eric Helgeson - * @author Evan Prodromou - * @author Mikael Nordfeldth - * @author Robin Millette - * @author Sarven Capadisli - * @author Tom Adams - * @author Zach Copley - * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org - * @license GNU Affero General Public License http://www.gnu.org/licenses/ - * @version 0.9.x - * @link http://status.net + * @package Installation + * @author Adrian Lang + * @author Brenda Wallace + * @author Brett Taylor + * @author Brion Vibber + * @author CiaranG + * @author Craig Andrews + * @author Eric Helgeson + * @author Evan Prodromou + * @author Mikael Nordfeldth + * @author Robin Millette + * @author Sarven Capadisli + * @author Tom Adams + * @author Zach Copley + * @author Diogo Cordeiro + * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -define('INSTALLDIR', __DIR__); +define('INSTALLDIR', dirname(__DIR__)); -require dirname(INSTALLDIR) . '/lib/installer.php'; +require INSTALLDIR . '/lib/installer.php'; /** * Helper class for building form */ -class Posted { +class Posted +{ /** * HTML-friendly escaped string for the POST param of given name, or empty. * @param string $name * @return string */ - function value($name) + public function value(string $name): string { return htmlspecialchars($this->string($name)); } @@ -63,7 +62,7 @@ class Posted { * @param string $name * @return string */ - function string($name) + public function string(string $name): string { return strval($this->raw($name)); } @@ -76,7 +75,7 @@ class Posted { * @param string $name * @return mixed */ - function raw($name) + public function raw(string $name) { if (isset($_POST[$name])) { return $this->dequote($_POST[$name]); @@ -91,13 +90,13 @@ class Posted { * @param mixed $val * @return mixed */ - function dequote($val) + public function dequote($val) { if (get_magic_quotes_gpc()) { if (is_string($val)) { return stripslashes($val); - } else if (is_array($val)) { - return array_map(array($this, 'dequote'), $val); + } elseif (is_array($val)) { + return array_map([$this, 'dequote'], $val); } } return $val; @@ -115,7 +114,7 @@ class WebInstaller extends Installer * * @return void */ - function main() + public function main() { if (!$this->checkPrereqs()) { $this->warning(_('Please fix the above stated problems and refresh this page to continue installing.')); @@ -131,8 +130,10 @@ class WebInstaller extends Installer /** * Web implementation of warning output + * @param string $message + * @param string $submessage */ - function warning($message, $submessage='') + public function warning(string $message, string $submessage = '') { print "

$message

\n"; if ($submessage != '') { @@ -142,43 +143,48 @@ class WebInstaller extends Installer /** * Web implementation of status output + * @param string $status + * @param bool $error */ - function updateStatus($status, $error=false) + public function updateStatus(string $status, bool $error = false) { - echo '$status"; + echo '$status"; } /** * Show the web form! */ - function showForm() + public function showForm() { global $dbModules; $post = new Posted(); $dbRadios = ''; $dbtype = $post->raw('dbtype'); foreach (self::$dbModules as $type => $info) { - if ($this->checkExtension($info['check_module'])) { + if (extension_loaded($info['check_module'])) { if ($dbtype == null || $dbtype == $type) { $checked = 'checked="checked" '; $dbtype = $type; // if we didn't have one checked, hit the first } else { $checked = ''; } - $dbRadios .= sprintf('%3$s
', - htmlspecialchars($type), $checked, - htmlspecialchars($info['name'])); + $dbRadios .= sprintf( + '%3$s
', + htmlspecialchars($type), + $checked, + htmlspecialchars($info['name']) + ); } } - $ssl = array('always'=>null, 'never'=>null); + $ssl = ['always' => null, 'never' => null]; if (!empty($_SERVER['HTTPS'])) { $ssl['always'] = 'checked="checked"'; } else { $ssl['never'] = 'checked="checked"'; } - echo<<
@@ -186,19 +192,19 @@ class WebInstaller extends Installer
  • - +

    The name of your site

  • - enable
    - disable
    + enable
    + disable

    Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.

  • - enable
    - disable
    + enable
    + disable

    Enabling SSL (https://) requires extra webserver configuration and certificate generation not offered by this installation.

@@ -209,7 +215,7 @@ class WebInstaller extends Installer
  • - +

    Database hostname

  • @@ -219,17 +225,17 @@ class WebInstaller extends Installer
  • - +

    Database name

  • - +

    Database username

  • - +

    Database password (optional)

@@ -240,21 +246,21 @@ class WebInstaller extends Installer
  • - +

    Nickname for the initial user (administrator)

  • - +

    Password for the initial user (administrator)

  • - +
  • - +

    Optional email address for the initial user (administrator)

@@ -274,7 +280,7 @@ class WebInstaller extends Installer
- +
@@ -285,7 +291,7 @@ E_O_T; * Handle a POST submission... if we have valid input, start the install! * Otherwise shows the form along with any error messages. */ - function handlePost() + public function handlePost() { echo << @@ -311,23 +317,23 @@ STR; * Read and validate input data. * May output side effects. * - * @return boolean success + * @return bool success */ - function prepare() + public function prepare(): bool { $post = new Posted(); - $this->host = $post->string('host'); - $this->dbtype = $post->string('dbtype'); + $this->host = $post->string('host'); + $this->dbtype = $post->string('dbtype'); $this->database = $post->string('database'); $this->username = $post->string('dbusername'); $this->password = $post->string('dbpassword'); $this->sitename = $post->string('sitename'); - $this->fancy = (bool)$post->string('fancy'); + $this->fancy = (bool)$post->string('fancy'); - $this->adminNick = strtolower($post->string('admin_nickname')); - $this->adminPass = $post->string('admin_password'); - $adminPass2 = $post->string('admin_password2'); - $this->adminEmail = $post->string('admin_email'); + $this->adminNick = strtolower($post->string('admin_nickname')); + $this->adminPass = $post->string('admin_password'); + $adminPass2 = $post->string('admin_password2'); + $this->adminEmail = $post->string('admin_email'); $this->siteProfile = $post->string('site_profile'); @@ -350,7 +356,7 @@ STR; $fail = true; } - if (!in_array($this->ssl, array('never', 'always'))) { + if (!in_array($this->ssl, ['never', 'always'])) { $this->updateStatus("Bad value for server SSL enabling."); $fail = true; } @@ -361,57 +367,53 @@ STR; return !$fail; } - } ?> - xml version="1.0" encoding="UTF-8" "; ?> - - - - Install GNU social - - - - - - - - -
- -
-
-
- + +
+ diff --git a/scripts/install_cli.php b/scripts/install_cli.php index da5f0f4b0c..cb1ef4c0e1 100755 --- a/scripts/install_cli.php +++ b/scripts/install_cli.php @@ -1,37 +1,36 @@ #!/usr/bin/env php . + /** - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2010, StatusNet, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * @category Installation - * @package Installation + * CLI Installer * - * @author Brion Vibber - * @author Mikael Nordfeldth - * @license GNU Affero General Public License http://www.gnu.org/licenses/ - * @version 1.1.x - * @link http://status.net + * @package Installation + * @author Brion Vibber + * @author Mikael Nordfeldth + * @author Diogo Cordeiro + * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ if (php_sapi_name() !== 'cli') { exit(1); } -define('INSTALLDIR', dirname(dirname(__FILE__))); +define('INSTALLDIR', dirname(__DIR__)); set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib'); require_once INSTALLDIR . '/lib/installer.php'; @@ -43,16 +42,16 @@ class CliInstaller extends Installer /** * Go for it! - * @return boolean success + * @return bool success */ - function main() + public function main(): bool { if ($this->prepare()) { - if (!$this->checkPrereqs()) { - return false; - } + if (!$this->checkPrereqs()) { + return false; + } return $this->handle(); - } else { + } else { $this->showHelp(); return false; } @@ -60,23 +59,23 @@ class CliInstaller extends Installer /** * Get our input parameters... - * @return boolean success + * @return bool success */ - function prepare() + public function prepare(): bool { $shortoptions = 'qvh'; - $longoptions = array('quiet', 'verbose', 'help', 'skip-config'); - $map = array( - '-s' => 'server', - '--server' => 'server', - '-p' => 'path', - '--path' => 'path', + $longoptions = ['quiet', 'verbose', 'help', 'skip-config']; + $map = [ + '-s' => 'server', + '--server' => 'server', + '-p' => 'path', + '--path' => 'path', '--sitename' => 'sitename', - '--fancy' => 'fancy', - '--ssl' => 'ssl', + '--fancy' => 'fancy', + '--ssl' => 'ssl', - '--dbtype' => 'dbtype', - '--host' => 'host', + '--dbtype' => 'dbtype', + '--host' => 'host', '--database' => 'database', '--username' => 'username', '--password' => 'password', @@ -86,7 +85,7 @@ class CliInstaller extends Installer '--admin-email' => 'adminEmail', '--site-profile' => 'siteProfile' - ); + ]; foreach ($map as $arg => $target) { if (substr($arg, 0, 2) == '--') { $longoptions[] = substr($arg, 2) . '='; @@ -116,13 +115,13 @@ class CliInstaller extends Installer if ($arg == '--fancy') { $this->$var = ($option[1] != 'false') && ($option[1] != 'no'); } - } else if ($arg == '--skip-config') { + } elseif ($arg == '--skip-config') { $this->skipConfig = true; - } else if ($arg == 'q' || $arg == '--quiet') { + } elseif ($arg == 'q' || $arg == '--quiet') { $this->verbose = false; - } else if ($arg == 'v' || $arg == '--verbose') { + } elseif ($arg == 'v' || $arg == '--verbose') { $this->verbose = true; - } else if ($arg == 'h' || $arg == '--help') { + } elseif ($arg == 'h' || $arg == '--help') { // will go back to show help return false; } @@ -146,15 +145,15 @@ class CliInstaller extends Installer return !$fail; } - function handle() + public function handle() { return $this->doInstall(); } - function showHelp() + public function showHelp() { echo << Use as server name (required) -p --path= Use as path name @@ -189,7 +188,11 @@ install_cli.php - StatusNet command-line installer END_HELP; } - function warning($message, $submessage='') + /** + * @param string $message + * @param string $submessage + */ + public function warning(string $message, string $submessage = '') { print $this->html2text($message) . "\n"; if ($submessage != '') { @@ -198,7 +201,11 @@ END_HELP; print "\n"; } - function updateStatus($status, $error=false) + /** + * @param string $status + * @param bool $error + */ + public function updateStatus(string $status, bool $error = false) { if ($this->verbose || $error) { if ($error) { @@ -209,12 +216,18 @@ END_HELP; } } - private function html2text($html) + /** + * @param string $html + * @return string + */ + private function html2text(string $html): string { // break out any links for text legibility - $breakout = preg_replace('/+]\bhref="(.*)"[^>]*>(.*)<\/a>/', - '\2 <\1>', - $html); + $breakout = preg_replace( + '/+]\bhref="(.*)"[^>]*>(.*)<\/a>/', + '\2 <\1>', + $html + ); return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8'); } }