[INSTALL] Minor reformatting and modernization. Shouldn't change functionality significatively.

This commit is contained in:
Diogo Cordeiro 2019-07-15 01:40:31 +01:00
parent 7d262ad50b
commit 893bafa14b
3 changed files with 380 additions and 365 deletions

View File

@ -1,25 +1,23 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <http://www.gnu.org/licenses/>.
*
* @category Installation
* @package Installation
*
* @author Adrian Lang <mail@adrianlang.de>
* @author Brenda Wallace <shiny@cpan.org>
* @author Brett Taylor <brett@webfroot.co.nz>
@ -33,44 +31,58 @@
* @author Sarven Capadisli <csarven@status.net>
* @author Tom Adams <tom@holizz.com>
* @author Zach Copley <zach@status.net>
* @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
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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,9 +92,9 @@ abstract class Installer
/**
* Check if all is ready for installation
*
* @return void
* @return bool
*/
function checkPrereqs()
public function checkPrereqs(): bool
{
$pass = true;
@ -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: <code>%s</code>', $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: <code>%s</code></p>', INSTALLDIR),
sprintf('On your server, try this command: <code>chmod a+w %s</code>', INSTALLDIR));
$this->warning(
sprintf('Cannot write config file to: <code>%s</code></p>', INSTALLDIR),
sprintf('On your server, try this command: <code>chmod a+w %s</code>', 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
$_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];
$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: <code>%s</code>', $fileSubdir, $fileFullPath),
sprintf('On your server, try this command: <code>chmod a+w %s</code>', $fileFullPath));
$this->warning(
sprintf('Cannot write to directory: <code>%s</code>', $fileFullPath),
sprintf('On your server, try this command: <code>chmod a+w %s</code>', $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;
@ -239,9 +235,10 @@ abstract class Installer
'" 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);
@ -259,9 +256,9 @@ 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)) {
$this->updateStatus("No site profile selected.", true);
@ -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');
$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') {
$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 server_encoding')[0];
if ($server_encoding != 'UTF8') {
$this->updateStatus("GNU social requires UTF8 character encoding. Your database is " . htmlentities($server_encoding));
return false;
}
}
@ -321,9 +321,9 @@ abstract class Installer
return false;
}
foreach (array('sms_carrier' => 'SMS carrier',
foreach (['sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
'foreign_services' => 'foreign service')
'foreign_services' => 'foreign service']
as $scr => $name) {
$this->updateStatus(sprintf("Adding %s data to database...", $name));
$res = $this->runDbScript($scr . '.sql', $conn);
@ -333,17 +333,17 @@ abstract class Installer
}
}
$db = array('type' => $this->dbtype, 'database' => $dsn);
$db = ['type' => $this->dbtype, 'database' => $dsn];
return $db;
}
/**
* Open a connection to the database.
*
* @param <type> $dsn
* @return <type>
* @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,33 +396,33 @@ 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'))
'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 = "<?php\n" .
@ -465,12 +466,12 @@ 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
@ -497,9 +498,9 @@ abstract class Installer
* @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,
$data = ['nickname' => $this->adminNick,
'password' => $this->adminPass,
'fullname' => $this->adminNick);
'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;
@ -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);
}

View File

@ -1,24 +1,23 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009-2010, StatusNet, Inc.
* Web Installer
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Installation
* @package Installation
*
* @author Adrian Lang <mail@adrianlang.de>
* @author Brenda Wallace <shiny@cpan.org>
* @author Brett Taylor <brett@webfroot.co.nz>
@ -32,26 +31,26 @@
* @author Sarven Capadisli <csarven@status.net>
* @author Tom Adams <tom@holizz.com>
* @author Zach Copley <zach@status.net>
* @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
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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);
} elseif (is_array($val)) {
return array_map(array($this, 'dequote'), $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 "<p class=\"error\">$message</p>\n";
if ($submessage != '') {
@ -142,8 +143,10 @@ 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 '<li' . ($error ? ' class="error"' : '') . ">$status</li>";
}
@ -151,27 +154,30 @@ class WebInstaller extends Installer
/**
* 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('<input type="radio" name="dbtype" id="dbtype-%1$s" value="%1$s" %2$s/>%3$s<br />',
htmlspecialchars($type), $checked,
htmlspecialchars($info['name']));
$dbRadios .= sprintf(
'<input type="radio" name="dbtype" id="dbtype-%1$s" value="%1$s" %2$s/>%3$s<br>',
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 {
@ -186,19 +192,19 @@ class WebInstaller extends Installer
<ul class="form_data">
<li>
<label for="sitename">Site name</label>
<input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
<input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}">
<p class="form_guide">The name of your site</p>
</li>
<li>
<label for="fancy-enable">Fancy URLs</label>
<input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
<input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
<input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked'> enable<br>
<input type="radio" name="fancy" id="fancy-disable" value=""> disable<br>
<p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
</li>
<li>
<label for="ssl">Server SSL</label>
<input type="radio" name="ssl" id="ssl-always" value="always" {$ssl['always']} /> enable<br />
<input type="radio" name="ssl" id="ssl-never" value="never" {$ssl['never']} /> disable<br />
<input type="radio" name="ssl" id="ssl-always" value="always" {$ssl['always']}> enable<br>
<input type="radio" name="ssl" id="ssl-never" value="never" {$ssl['never']}> disable<br>
<p class="form_guide" id="ssl-form_guide">Enabling SSL (https://) requires extra webserver configuration and certificate generation not offered by this installation.</p>
</li>
</ul>
@ -209,7 +215,7 @@ class WebInstaller extends Installer
<ul class="form_data">
<li>
<label for="host">Hostname</label>
<input type="text" id="host" name="host" value="{$post->value('host')}" />
<input type="text" id="host" name="host" value="{$post->value('host')}">
<p class="form_guide">Database hostname</p>
</li>
<li>
@ -219,17 +225,17 @@ class WebInstaller extends Installer
</li>
<li>
<label for="database">Name</label>
<input type="text" id="database" name="database" value="{$post->value('database')}" />
<input type="text" id="database" name="database" value="{$post->value('database')}">
<p class="form_guide">Database name</p>
</li>
<li>
<label for="dbusername">DB username</label>
<input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
<input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}">
<p class="form_guide">Database username</p>
</li>
<li>
<label for="dbpassword">DB password</label>
<input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
<input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}">
<p class="form_guide">Database password (optional)</p>
</li>
</ul>
@ -240,21 +246,21 @@ class WebInstaller extends Installer
<ul class="form_data">
<li>
<label for="admin_nickname">Administrator nickname</label>
<input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
<input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}">
<p class="form_guide">Nickname for the initial user (administrator)</p>
</li>
<li>
<label for="admin_password">Administrator password</label>
<input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
<input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}">
<p class="form_guide">Password for the initial user (administrator)</p>
</li>
<li>
<label for="admin_password2">Confirm password</label>
<input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
<input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}">
</li>
<li>
<label for="admin_email">Administrator e-mail</label>
<input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
<input id="admin_email" name="admin_email" value="{$post->value('admin_email')}">
<p class="form_guide">Optional email address for the initial user (administrator)</p>
</li>
</ul>
@ -274,7 +280,7 @@ class WebInstaller extends Installer
</li>
</ul>
</fieldset>
<input type="submit" name="submit" class="submit" value="Submit" />
<input type="submit" name="submit" class="submit" value="Submit">
</fieldset>
</form>
@ -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 <<<STR
<dl class="system_notice">
@ -311,9 +317,9 @@ 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');
@ -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,21 +367,17 @@ STR;
return !$fail;
}
}
?>
<?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<!DOCTYPE html>
<html lang="en">
<head>
<title>Install GNU social</title>
<link rel="shortcut icon" href="favicon.ico"/>
<link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
<link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv">
<link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="js/extlib/jquery.js"></script>
<script src="js/install.js"></script>
</head>

View File

@ -1,37 +1,36 @@
#!/usr/bin/env php
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social 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.
//
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
* CLI Installer
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Installation
* @package Installation
*
* @author Brion Vibber <brion@status.net>
* @author Brion Vibber <brion@pobox.com>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @license GNU Affero General Public License http://www.gnu.org/licenses/
* @version 1.1.x
* @link http://status.net
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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,9 +42,9 @@ 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()) {
@ -60,13 +59,13 @@ 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(
$longoptions = ['quiet', 'verbose', 'help', 'skip-config'];
$map = [
'-s' => 'server',
'--server' => 'server',
'-p' => 'path',
@ -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) . '=';
@ -146,15 +145,15 @@ class CliInstaller extends Installer
return !$fail;
}
function handle()
public function handle()
{
return $this->doInstall();
}
function showHelp()
public function showHelp()
{
echo <<<END_HELP
install_cli.php - StatusNet command-line installer
install_cli.php - GNU social command-line installer
-s --server=<name> Use <name> as server name (required)
-p --path=<path> Use <path> 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('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
$breakout = preg_replace(
'/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
'\2 &lt;\1&gt;',
$html);
$html
);
return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
}
}