. /** * Web Installer * * @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', dirname(__DIR__)); define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); require INSTALLDIR . '/lib/util/installer.php'; /** * Helper class for building form */ class Posted { /** * HTML-friendly escaped string for the POST param of given name, or empty. * @param string $name * @return string */ public function value(string $name): string { return htmlspecialchars($this->string($name)); } /** * The given POST parameter value, forced to a string. * Missing value will give ''. * * @param string $name * @return string */ public function string(string $name): string { return strval($this->raw($name)); } /** * The given POST parameter value, in its original form. * Magic quotes are stripped, if provided. * Missing value will give null. * * @param string $name * @return mixed */ public function raw(string $name) { if (isset($_POST[$name])) { return $this->dequote($_POST[$name]); } else { return null; } } /** * If necessary, strip magic quotes from the given value. * * @param mixed $val * @return mixed */ public function dequote($val) { if (get_magic_quotes_gpc()) { if (is_string($val)) { return stripslashes($val); } elseif (is_array($val)) { return array_map([$this, 'dequote'], $val); } } return $val; } } /** * Web-based installer: provides a form and such. */ class WebInstaller extends Installer { /** * the actual installation. * If call libraries are present, then install * * @return void */ public function main() { 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 * @param string $message * @param string $submessage */ public function warning(string $message, string $submessage = '') { print "

$message

\n"; if ($submessage != '') { print "

$submessage

\n"; } } /** * Web implementation of status output * @param string $status * @param bool $error */ public function updateStatus(string $status, bool $error = false) { echo '$status"; } /** * Show the web form! */ public function showForm() { global $dbModules; $post = new Posted(); $dbRadios = ''; $dbtype = $post->raw('dbtype'); foreach (self::$dbModules as $type => $info) { 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']) ); } } $ssl = ['always' => null, 'never' => null]; if (!empty($_SERVER['HTTPS'])) { $ssl['always'] = 'checked="checked"'; } else { $ssl['never'] = 'checked="checked"'; } echo <<
Site settings
  • The name of your site

  • enable
    disable

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

  • enable
    disable
    proxied

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

Database settings
  • Database hostname

  • {$dbRadios}

    Database type

  • Database name

  • Database username

  • Database password (optional)

Administrator settings
  • Nickname for the initial user (administrator)

  • Password for the initial user (administrator)

  • Optional email address for the initial user (administrator)

Site profile
  • Initial access settings for your site

E_O_T; } /** * Handle a POST submission... if we have valid input, start the install! * Otherwise shows the form along with any error messages. */ public function handlePost() { echo <<
Page notice
    STR; $this->validated = $this->prepare(); if ($this->validated) { $this->doInstall(); } echo <<
STR; if (!$this->validated) { $this->showForm(); } } /** * Read and validate input data. * May output side effects. * * @return bool success */ public function prepare(): bool { $post = new Posted(); $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->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'); $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; } if (!in_array($this->ssl, ['never', 'always', 'proxy'])) { $this->updateStatus("Bad value for server SSL enabling."); $fail = true; } if (!$this->validateSiteProfile()) { $fail = true; } return !$fail; } } ?> Install GNU social