123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- require INSTALLDIR . '/lib/util/installer.php';
- class Posted
- {
-
- public function value(string $name): string
- {
- return htmlspecialchars($this->string($name));
- }
-
- public function string(string $name): string
- {
- return strval($this->raw($name));
- }
-
- public function raw(string $name)
- {
- return filter_input(INPUT_POST, $name);
- }
- }
- class WebInstaller extends Installer
- {
-
- 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();
- }
- }
-
- public function warning(string $message, string $submessage = '')
- {
- print "<p class=\"error\">$message</p>\n";
- if ($submessage != '') {
- print "<p>$submessage</p>\n";
- }
- }
-
- public function updateStatus(string $status, bool $error = false)
- {
- echo '<li' . ($error ? ' class="error"' : '') . ">$status</li>";
- }
-
- 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;
- } 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'])
- );
- }
- }
- $ssl = ['always' => null, 'never' => null];
- if (!empty($_SERVER['HTTPS'])) {
- $ssl['always'] = 'checked="checked"';
- } else {
- $ssl['never'] = 'checked="checked"';
- }
- echo <<<E_O_T
- <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>
- <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>
- <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-proxy" value="proxy"> proxied<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>
- </fieldset>
- <fieldset id="settings_db">
- <legend>Database settings</legend>
- <ul class="form_data">
- <li>
- <label for="host">Hostname</label>
- <input type="text" id="host" name="host" value="{$post->value('host')}">
- <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>
- <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')}">
- <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')}">
- <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>
- <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')}">
- <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')}">
- </li>
- <li>
- <label for="admin_email">Administrator e-mail</label>
- <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>
- </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>
- <input type="submit" name="submit" class="submit" value="Submit">
- </fieldset>
- </form>
- E_O_T;
- }
-
- public function handlePost()
- {
- 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();
- }
- }
-
- 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;
- }
- }
- ?>
- <!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>
- </div>
- </div>
- </div>
- </div>
- <div id="footer"></div>
- </div>
- </body>
- </html>
|