2018-03-12 03:23:55 +00:00
|
|
|
<?php
|
2019-07-15 01:40:31 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2018-03-12 03:23:55 +00:00
|
|
|
/**
|
2019-07-15 01:40:31 +01:00
|
|
|
* Web Installer
|
2018-03-12 03:23:55 +00:00
|
|
|
*
|
2019-07-15 01:40:31 +01:00
|
|
|
* @package Installation
|
|
|
|
* @author Adrian Lang <mail@adrianlang.de>
|
|
|
|
* @author Brenda Wallace <shiny@cpan.org>
|
|
|
|
* @author Brett Taylor <brett@webfroot.co.nz>
|
|
|
|
* @author Brion Vibber <brion@pobox.com>
|
|
|
|
* @author CiaranG <ciaran@ciarang.com>
|
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
|
|
|
* @author Eric Helgeson <helfire@Erics-MBP.local>
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Robin Millette <millette@controlyourself.ca>
|
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
|
|
|
* @author Tom Adams <tom@holizz.com>
|
|
|
|
* @author Zach Copley <zach@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
|
2018-03-12 03:23:55 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
define('INSTALLDIR', dirname(__DIR__));
|
2019-07-14 21:02:38 +01:00
|
|
|
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
2018-03-12 03:23:55 +00:00
|
|
|
|
2019-09-12 09:52:04 +01:00
|
|
|
require INSTALLDIR . '/lib/util/installer.php';
|
2018-03-12 03:23:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class for building form
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
class Posted
|
|
|
|
{
|
2018-03-12 03:23:55 +00:00
|
|
|
/**
|
|
|
|
* HTML-friendly escaped string for the POST param of given name, or empty.
|
|
|
|
* @param string $name
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function value(string $name): string
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
return htmlspecialchars($this->string($name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The given POST parameter value, forced to a string.
|
|
|
|
* Missing value will give ''.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function string(string $name): string
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
return strval($this->raw($name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The given POST parameter value, in its original form.
|
|
|
|
* Missing value will give null.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function raw(string $name)
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
2020-09-15 12:59:27 +01:00
|
|
|
return filter_input(INPUT_POST, $name);
|
2018-03-12 03:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Web-based installer: provides a form and such.
|
|
|
|
*/
|
|
|
|
class WebInstaller extends Installer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* the actual installation.
|
|
|
|
* If call libraries are present, then install
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function main()
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
if (!$this->checkPrereqs()) {
|
|
|
|
$this->warning(_('Please fix the above stated problems and refresh this page to continue installing.'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
$this->handlePost();
|
|
|
|
} else {
|
|
|
|
$this->showForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Web implementation of warning output
|
2019-07-15 01:40:31 +01:00
|
|
|
* @param string $message
|
|
|
|
* @param string $submessage
|
2018-03-12 03:23:55 +00:00
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function warning(string $message, string $submessage = '')
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
print "<p class=\"error\">$message</p>\n";
|
|
|
|
if ($submessage != '') {
|
|
|
|
print "<p>$submessage</p>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Web implementation of status output
|
2019-07-15 01:40:31 +01:00
|
|
|
* @param string $status
|
|
|
|
* @param bool $error
|
2018-03-12 03:23:55 +00:00
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function updateStatus(string $status, bool $error = false)
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
2019-07-15 01:40:31 +01:00
|
|
|
echo '<li' . ($error ? ' class="error"' : '') . ">$status</li>";
|
2018-03-12 03:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the web form!
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function showForm()
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
global $dbModules;
|
|
|
|
$post = new Posted();
|
|
|
|
$dbRadios = '';
|
|
|
|
$dbtype = $post->raw('dbtype');
|
|
|
|
foreach (self::$dbModules as $type => $info) {
|
2019-07-15 01:40:31 +01:00
|
|
|
if (extension_loaded($info['check_module'])) {
|
2018-03-12 03:23:55 +00:00
|
|
|
if ($dbtype == null || $dbtype == $type) {
|
|
|
|
$checked = 'checked="checked" ';
|
|
|
|
$dbtype = $type; // if we didn't have one checked, hit the first
|
|
|
|
} else {
|
|
|
|
$checked = '';
|
|
|
|
}
|
2019-07-15 01:40:31 +01:00
|
|
|
$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'])
|
|
|
|
);
|
2018-03-12 03:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
$ssl = ['always' => null, 'never' => null];
|
2018-03-12 03:23:55 +00:00
|
|
|
if (!empty($_SERVER['HTTPS'])) {
|
|
|
|
$ssl['always'] = 'checked="checked"';
|
|
|
|
} else {
|
|
|
|
$ssl['never'] = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
echo <<<E_O_T
|
2018-03-12 03:23:55 +00:00
|
|
|
<form method="post" action="install.php" class="form_settings" id="form_install">
|
|
|
|
<fieldset>
|
|
|
|
<fieldset id="settings_site">
|
|
|
|
<legend>Site settings</legend>
|
|
|
|
<ul class="form_data">
|
|
|
|
<li>
|
|
|
|
<label for="sitename">Site name</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">The name of your site</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="fancy-enable">Fancy URLs</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<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>
|
2018-03-12 03:23:55 +00:00
|
|
|
<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>
|
2019-07-15 01:40:31 +01:00
|
|
|
<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>
|
2020-03-15 21:37:37 +00:00
|
|
|
<input type="radio" name="ssl" id="ssl-proxy" value="proxy"> proxied<br>
|
2018-03-12 03:23:55 +00:00
|
|
|
<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>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset id="settings_db">
|
|
|
|
<legend>Database settings</legend>
|
|
|
|
<ul class="form_data">
|
|
|
|
<li>
|
|
|
|
<label for="host">Hostname</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="text" id="host" name="host" value="{$post->value('host')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Database hostname</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="dbtype">Type</label>
|
|
|
|
{$dbRadios}
|
|
|
|
<p class="form_guide">Database type</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="database">Name</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="text" id="database" name="database" value="{$post->value('database')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Database name</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="dbusername">DB username</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Database username</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="dbpassword">DB password</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Database password (optional)</p>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset id="settings_admin">
|
|
|
|
<legend>Administrator settings</legend>
|
|
|
|
<ul class="form_data">
|
|
|
|
<li>
|
|
|
|
<label for="admin_nickname">Administrator nickname</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Nickname for the initial user (administrator)</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="admin_password">Administrator password</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Password for the initial user (administrator)</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="admin_password2">Confirm password</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label for="admin_email">Administrator e-mail</label>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input id="admin_email" name="admin_email" value="{$post->value('admin_email')}">
|
2018-03-12 03:23:55 +00:00
|
|
|
<p class="form_guide">Optional email address for the initial user (administrator)</p>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset id="settings_profile">
|
|
|
|
<legend>Site profile</legend>
|
|
|
|
<ul class="form_data">
|
|
|
|
<li>
|
|
|
|
<label for="site_profile">Type of site</label>
|
|
|
|
<select id="site_profile" name="site_profile">
|
|
|
|
<option value="community">Community</option>
|
|
|
|
<option value="public">Public (open registration)</option>
|
|
|
|
<option value="singleuser">Single User</option>
|
|
|
|
<option value="private">Private (no federation)</option>
|
|
|
|
</select>
|
|
|
|
<p class="form_guide">Initial access settings for your site</p>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</fieldset>
|
2019-07-15 01:40:31 +01:00
|
|
|
<input type="submit" name="submit" class="submit" value="Submit">
|
2018-03-12 03:23:55 +00:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
E_O_T;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a POST submission... if we have valid input, start the install!
|
|
|
|
* Otherwise shows the form along with any error messages.
|
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function handlePost()
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
echo <<<STR
|
|
|
|
<dl class="system_notice">
|
|
|
|
<dt>Page notice</dt>
|
|
|
|
<dd>
|
|
|
|
<ul>
|
|
|
|
STR;
|
|
|
|
$this->validated = $this->prepare();
|
|
|
|
if ($this->validated) {
|
|
|
|
$this->doInstall();
|
|
|
|
}
|
|
|
|
echo <<<STR
|
|
|
|
</ul>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
STR;
|
|
|
|
if (!$this->validated) {
|
|
|
|
$this->showForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read and validate input data.
|
|
|
|
* May output side effects.
|
|
|
|
*
|
2019-07-15 01:40:31 +01:00
|
|
|
* @return bool success
|
2018-03-12 03:23:55 +00:00
|
|
|
*/
|
2019-07-15 01:40:31 +01:00
|
|
|
public function prepare(): bool
|
2018-03-12 03:23:55 +00:00
|
|
|
{
|
|
|
|
$post = new Posted();
|
2019-07-15 01:40:31 +01:00
|
|
|
$this->host = $post->string('host');
|
|
|
|
$this->dbtype = $post->string('dbtype');
|
2018-03-12 03:23:55 +00:00
|
|
|
$this->database = $post->string('database');
|
|
|
|
$this->username = $post->string('dbusername');
|
|
|
|
$this->password = $post->string('dbpassword');
|
|
|
|
$this->sitename = $post->string('sitename');
|
2019-07-15 01:40:31 +01:00
|
|
|
$this->fancy = (bool)$post->string('fancy');
|
2018-03-12 03:23:55 +00:00
|
|
|
|
2019-07-15 01:40:31 +01:00
|
|
|
$this->adminNick = strtolower($post->string('admin_nickname'));
|
|
|
|
$this->adminPass = $post->string('admin_password');
|
|
|
|
$adminPass2 = $post->string('admin_password2');
|
|
|
|
$this->adminEmail = $post->string('admin_email');
|
2018-03-12 03:23:55 +00:00
|
|
|
|
|
|
|
$this->siteProfile = $post->string('site_profile');
|
|
|
|
|
|
|
|
$this->ssl = $post->string('ssl');
|
|
|
|
|
|
|
|
$this->server = $_SERVER['HTTP_HOST'];
|
|
|
|
$this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
|
|
|
|
|
|
|
|
$fail = false;
|
|
|
|
if (!$this->validateDb()) {
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->validateAdmin()) {
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->adminPass != $adminPass2) {
|
|
|
|
$this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
2020-03-15 21:37:37 +00:00
|
|
|
if (!in_array($this->ssl, ['never', 'always', 'proxy'])) {
|
2018-03-12 03:23:55 +00:00
|
|
|
$this->updateStatus("Bad value for server SSL enabling.");
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->validateSiteProfile()) {
|
|
|
|
$fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !$fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
2019-07-15 01:40:31 +01:00
|
|
|
<!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">
|
|
|
|
<script src="js/extlib/jquery.js"></script>
|
|
|
|
<script src="js/install.js"></script>
|
|
|
|
</head>
|
|
|
|
<body id="install">
|
|
|
|
<div id="wrap">
|
|
|
|
<div id="header">
|
|
|
|
<address id="site_contact" class="h-card">
|
|
|
|
<a class="u-url p-name home bookmark org" href=".">
|
|
|
|
<img class="logo u-photo" src="theme/neo/logo.png" alt="GNU social"/>
|
|
|
|
GNU social
|
|
|
|
</a>
|
|
|
|
</address>
|
|
|
|
<div id="site_nav_global_primary"></div>
|
|
|
|
</div>
|
|
|
|
<div id="core">
|
|
|
|
<div id="aside_primary_wrapper">
|
|
|
|
<div id="content_wrapper">
|
|
|
|
<div id="site_nav_local_views_wrapper">
|
|
|
|
<div id="site_nav_local_views"></div>
|
|
|
|
|
|
|
|
<div id="content">
|
|
|
|
<div id="content_inner">
|
|
|
|
<h1>Install GNU social</h1>
|
|
|
|
<?php
|
|
|
|
$installer = new WebInstaller();
|
|
|
|
$installer->main();
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="aside_primary" class="aside"></div>
|
2018-03-12 03:23:55 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-15 01:40:31 +01:00
|
|
|
</div>
|
|
|
|
<div id="footer"></div>
|
|
|
|
</div>
|
|
|
|
</body>
|
2018-03-12 03:23:55 +00:00
|
|
|
</html>
|