git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

install.php 14.8 KB
Newer Older
1
<?php
2
/**
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2009-2010, StatusNet, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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/>.
18
 *
Brenda Wallace's avatar
Brenda Wallace committed
19 20
 * @category Installation
 * @package  Installation
21
 *
22 23 24 25 26 27
 * @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>
28
 * @author   Eric Helgeson <helfire@Erics-MBP.local>
29
 * @author   Evan Prodromou <evan@status.net>
30
 * @author   Mikael Nordfeldth <mmn@hethane.se>
31
 * @author   Robin Millette <millette@controlyourself.ca>
32
 * @author   Sarven Capadisli <csarven@status.net>
33
 * @author   Tom Adams <tom@holizz.com>
34
 * @author   Zach Copley <zach@status.net>
35
 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
36
 * @license  GNU Affero General Public License http://www.gnu.org/licenses/
Brenda Wallace's avatar
Brenda Wallace committed
37
 * @version  0.9.x
Brenda Wallace's avatar
Brenda Wallace committed
38
 * @link     http://status.net
39
 */
40

41 42
define('INSTALLDIR', dirname(__FILE__));

43
require INSTALLDIR . '/lib/installer.php';
44

45
/**
46
 * Helper class for building form
47
 */
48
class Posted {
49 50 51 52 53
    /**
     * HTML-friendly escaped string for the POST param of given name, or empty.
     * @param string $name
     * @return string
     */
54
    function value($name)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    {
        return htmlspecialchars($this->string($name));
    }

    /**
     * The given POST parameter value, forced to a string.
     * Missing value will give ''.
     *
     * @param string $name
     * @return string
     */
    function string($name)
    {
        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
     */
    function raw($name)
80 81
    {
        if (isset($_POST[$name])) {
82
            return $this->dequote($_POST[$name]);
83
        } else {
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
            return null;
        }
    }

    /**
     * If necessary, strip magic quotes from the given value.
     *
     * @param mixed $val
     * @return mixed
     */
    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);
            }
102
        }
103
        return $val;
104 105
    }
}
106

107
/**
108
 * Web-based installer: provides a form and such.
109
 */
110
class WebInstaller extends Installer
111
{
112 113 114 115 116 117 118 119 120
    /**
     * the actual installation.
     * If call libraries are present, then install
     *
     * @return void
     */
    function main()
    {
        if (!$this->checkPrereqs()) {
121
            $this->warning(_('Please fix the above stated problems and refresh this page to continue installing.'));
122
            return;
123
        }
124

125 126 127 128
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->handlePost();
        } else {
            $this->showForm();
129 130
        }
    }
131

132 133 134 135 136 137 138 139
    /**
     * Web implementation of warning output
     */
    function warning($message, $submessage='')
    {
        print "<p class=\"error\">$message</p>\n";
        if ($submessage != '') {
            print "<p>$submessage</p>\n";
Brenda Wallace's avatar
Brenda Wallace committed
140
        }
141
    }
142

143 144 145 146 147 148
    /**
     * Web implementation of status output
     */
    function updateStatus($status, $error=false)
    {
        echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
149 150
    }

151 152 153 154
    /**
     * Show the web form!
     */
    function showForm()
155
    {
156 157 158
        global $dbModules;
        $post = new Posted();
        $dbRadios = '';
159
        $dbtype = $post->raw('dbtype');
160 161 162 163 164 165 166 167
        foreach (self::$dbModules as $type => $info) {
            if ($this->checkExtension($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 = '';
                }
mmn's avatar
mmn committed
168 169 170
                $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']));
171
            }
172
        }
173

174 175 176 177 178 179 180
        $ssl = array('always'=>null, 'never'=>null);
        if (!empty($_SERVER['HTTPS'])) {
            $ssl['always'] = 'checked="checked"';
        } else {
            $ssl['never'] = 'checked="checked"';
        }

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        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>
198 199 200 201 202 203
                    <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 />
                        <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>
204 205 206 207 208 209 210 211 212 213 214 215 216
                </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>
mmn's avatar
mmn committed
217
                        {$dbRadios}
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
                        <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')}" />
244
                        <p class="form_guide">Nickname for the initial user (administrator)</p>
245 246 247 248
                    </li>
                    <li>
                        <label for="admin_password">Administrator password</label>
                        <input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
249
                        <p class="form_guide">Password for the initial user (administrator)</p>
250 251 252 253 254 255 256 257
                    </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')}" />
258
                        <p class="form_guide">Optional email address for the initial user (administrator)</p>
259 260 261
                    </li>
                </ul>
            </fieldset>
262
            <fieldset id="settings_profile">
Zach Copley's avatar
Zach Copley committed
263
                <legend>Site profile</legend>
264 265
                <ul class="form_data">
                    <li>
Zach Copley's avatar
Zach Copley committed
266 267
                        <label for="site_profile">Type of site</label>
                        <select id="site_profile" name="site_profile">
268
                            <option value="community">Community</option>
269 270 271
                            <option value="public">Public (open registration)</option>
                            <option value="singleuser">Single User</option>
                            <option value="private">Private (no federation)</option>
272 273 274 275 276
                        </select>
                        <p class="form_guide">Initial access settings for your site</p>
                    </li>
                </ul>
            </fieldset>
277
            <input type="submit" name="submit" class="submit" value="Submit" />
278
        </fieldset>
279
    </form>
280 281

E_O_T;
282 283
    }

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    /**
     * Handle a POST submission... if we have valid input, start the install!
     * Otherwise shows the form along with any error messages.
     */
    function handlePost()
    {
        echo <<<STR
        <dl class="system_notice">
            <dt>Page notice</dt>
            <dd>
                <ul>
STR;
        $this->validated = $this->prepare();
        if ($this->validated) {
            $this->doInstall();
299
        }
300 301 302 303 304 305 306
        echo <<<STR
            </ul>
        </dd>
    </dl>
STR;
        if (!$this->validated) {
            $this->showForm();
307 308 309
        }
    }

310 311 312
    /**
     * Read and validate input data.
     * May output side effects.
Zach Copley's avatar
Zach Copley committed
313
     *
314 315 316 317
     * @return boolean success
     */
    function prepare()
    {
318 319 320 321 322 323 324 325
        $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');
326

327 328 329 330
        $this->adminNick    = strtolower($post->string('admin_nickname'));
        $this->adminPass    = $post->string('admin_password');
        $adminPass2         = $post->string('admin_password2');
        $this->adminEmail   = $post->string('admin_email');
331

Zach Copley's avatar
Zach Copley committed
332 333
        $this->siteProfile = $post->string('site_profile');

334 335
        $this->ssl = $post->string('ssl');

336 337 338 339 340 341
        $this->server = $_SERVER['HTTP_HOST'];
        $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);

        $fail = false;
        if (!$this->validateDb()) {
            $fail = true;
342 343
        }

344 345
        if (!$this->validateAdmin()) {
            $fail = true;
346
        }
Zach Copley's avatar
Zach Copley committed
347

348 349 350 351
        if ($this->adminPass != $adminPass2) {
            $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
            $fail = true;
        }
Zach Copley's avatar
Zach Copley committed
352

mmn's avatar
mmn committed
353
        if (!in_array($this->ssl, array('never', 'always'))) {
354 355 356 357
            $this->updateStatus("Bad value for server SSL enabling.");
            $fail = true;
        }

Zach Copley's avatar
Zach Copley committed
358 359 360 361
        if (!$this->validateSiteProfile()) {
            $fail = true;
        }

362
        return !$fail;
363
    }
364 365 366

}

367
?>
Sarven Capadisli's avatar
Sarven Capadisli committed
368 369 370 371 372 373
<?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">
    <head>
374
        <title>Install GNU social</title>
mmn's avatar
mmn committed
375
        <link rel="shortcut icon" href="favicon.ico"/>
376
        <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
377
        <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
mmn's avatar
mmn committed
378
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
379
        <script src="js/extlib/jquery.js"></script>
380
        <script src="js/install.js"></script>
Sarven Capadisli's avatar
Sarven Capadisli committed
381 382 383 384
    </head>
    <body id="install">
        <div id="wrap">
            <div id="header">
mmn's avatar
mmn committed
385 386 387 388
                <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
Sarven Capadisli's avatar
Sarven Capadisli committed
389 390
                    </a>
                </address>
391
                <div id="site_nav_global_primary"></div>
Sarven Capadisli's avatar
Sarven Capadisli committed
392 393
            </div>
            <div id="core">
394 395 396 397
             <div id="aside_primary_wrapper">
              <div id="content_wrapper">
               <div id="site_nav_local_views_wrapper">
                <div id="site_nav_local_views"></div>
Zach Copley's avatar
Zach Copley committed
398

Sarven Capadisli's avatar
Sarven Capadisli committed
399
                <div id="content">
400
                     <div id="content_inner">
401
                        <h1>Install GNU social</h1>
Zach Copley's avatar
Zach Copley committed
402
<?php
403 404 405
$installer = new WebInstaller();
$installer->main();
?>
406
                   </div>
Sarven Capadisli's avatar
Sarven Capadisli committed
407
                </div>
408 409 410 411 412

                <div id="aside_primary" class="aside"></div>
               </div>
              </div>
             </div>
Sarven Capadisli's avatar
Sarven Capadisli committed
413
            </div>
414
            <div id="footer"></div>
Sarven Capadisli's avatar
Sarven Capadisli committed
415 416
        </div>
    </body>
417
</html>