We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

install.php 11.7 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
 *
Brenda Wallace's avatar
Brenda Wallace committed
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>
Brenda Wallace's avatar
Brenda Wallace committed
30
 * @author   Robin Millette <millette@controlyourself.ca>
31
 * @author   Sarven Capadisli <csarven@status.net>
Brenda Wallace's avatar
Brenda Wallace committed
32
 * @author   Tom Adams <tom@holizz.com>
33
 * @author   Zach Copley <zach@status.net>
Brenda Wallace's avatar
Brenda Wallace committed
34
 * @license  GNU Affero General Public License http://www.gnu.org/licenses/
Brenda Wallace's avatar
Brenda Wallace committed
35
 * @version  0.9.x
Brenda Wallace's avatar
Brenda Wallace committed
36
 * @link     http://status.net
37
 */
38

39 40
define('INSTALLDIR', dirname(__FILE__));

41
require INSTALLDIR . '/lib/installer.php';
Craig Andrews's avatar
Craig Andrews committed
42

43
/**
44
 * Helper class for building form
Brenda Wallace's avatar
Brenda Wallace committed
45
 */
46 47 48 49 50
class Posted {
    function value($name)
    {
        if (isset($_POST[$name])) {
            return htmlspecialchars(strval($_POST[$name]));
Craig Andrews's avatar
Craig Andrews committed
51
        } else {
52
            return '';
Craig Andrews's avatar
Craig Andrews committed
53 54 55
        }
    }
}
56

Brenda Wallace's avatar
Brenda Wallace committed
57
/**
58
 * Web-based installer: provides a form and such.
Brenda Wallace's avatar
Brenda Wallace committed
59
 */
60
class WebInstaller extends Installer
61
{
62 63 64 65 66 67 68 69 70 71 72
    /**
     * the actual installation.
     * If call libraries are present, then install
     *
     * @return void
     */
    function main()
    {
        if (!$this->checkPrereqs()) {
            $this->showForm();
            return;
73
        }
74

75 76 77 78
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this->handlePost();
        } else {
            $this->showForm();
79 80
        }
    }
81

82 83 84 85 86 87 88 89
    /**
     * 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
90
        }
91
    }
92

93 94 95 96 97 98
    /**
     * Web implementation of status output
     */
    function updateStatus($status, $error=false)
    {
        echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
Craig Andrews's avatar
Craig Andrews committed
99 100
    }

101 102 103 104
    /**
     * Show the web form!
     */
    function showForm()
105
    {
106 107 108 109 110
        global $dbModules;
        $post = new Posted();
        $dbRadios = '';
        if (isset($_POST['dbtype'])) {
            $dbtype = $_POST['dbtype'];
111
        } else {
112
            $dbtype = null;
113
        }
114 115 116 117 118 119 120 121 122
        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 = '';
                }
                $dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
123
            }
124
        }
125

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
        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>
                </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 StatusNet 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 StatusNet 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 StatusNet user (administrator)</p>
                    </li>
                    <li>
                        <label for="admin_updates">Subscribe to announcements</label>
                        <input type="checkbox" id="admin_updates" name="admin_updates" value="true" checked="checked" />
                        <p class="form_guide">Release and security feed from <a href="http://update.status.net/">update@status.net</a> (recommended)</p>
                    </li>
                </ul>
            </fieldset>
            <input type="submit" name="submit" class="submit" value="Submit" />
207
        </fieldset>
208
    </form>
209 210

E_O_T;
211 212
    }

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    /**
     * 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();
228
        }
229 230 231 232 233 234 235
        echo <<<STR
            </ul>
        </dd>
    </dl>
STR;
        if (!$this->validated) {
            $this->showForm();
236 237 238
        }
    }

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    /**
     * Read and validate input data.
     * May output side effects.
     * 
     * @return boolean success
     */
    function prepare()
    {
        $this->host     = $_POST['host'];
        $this->dbtype   = $_POST['dbtype'];
        $this->database = $_POST['database'];
        $this->username = $_POST['dbusername'];
        $this->password = $_POST['dbpassword'];
        $this->sitename = $_POST['sitename'];
        $this->fancy    = !empty($_POST['fancy']);

        $this->adminNick    = strtolower($_POST['admin_nickname']);
        $this->adminPass    = $_POST['admin_password'];
        $adminPass2         = $_POST['admin_password2'];
        $this->adminEmail   = $_POST['admin_email'];
        $this->adminUpdates = $_POST['admin_updates'];

        $this->server = $_SERVER['HTTP_HOST'];
        $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);

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

269 270
        if (!$this->validateAdmin()) {
            $fail = true;
271
        }
272 273 274 275 276 277 278
        
        if ($this->adminPass != $adminPass2) {
            $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
            $fail = true;
        }
        
        return !$fail;
279
    }
280 281 282

}

Evan Prodromou's avatar
Evan Prodromou committed
283
?>
Sarven Capadisli's avatar
Sarven Capadisli committed
284 285 286 287 288 289
<?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>
290
        <title>Install StatusNet</title>
291
	<link rel="shortcut icon" href="favicon.ico"/>
292 293 294 295
        <link rel="stylesheet" type="text/css" href="theme/default/css/display.css" media="screen, projection, tv"/>
        <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css" /><![endif]-->
        <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css" /><![endif]-->
        <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/default/css/ie.css" /><![endif]-->
296 297
        <script src="js/jquery.min.js"></script>
        <script src="js/install.js"></script>
Sarven Capadisli's avatar
Sarven Capadisli committed
298 299 300 301 302 303
    </head>
    <body id="install">
        <div id="wrap">
            <div id="header">
                <address id="site_contact" class="vcard">
                    <a class="url home bookmark" href=".">
304 305
                        <img class="logo photo" src="theme/default/logo.png" alt="StatusNet"/>
                        <span class="fn org">StatusNet</span>
Sarven Capadisli's avatar
Sarven Capadisli committed
306 307 308 309 310
                    </a>
                </address>
            </div>
            <div id="core">
                <div id="content">
311 312
                     <div id="content_inner">
                        <h1>Install StatusNet</h1>
313 314 315 316
<?php 
$installer = new WebInstaller();
$installer->main();
?>
317
                   </div>
Sarven Capadisli's avatar
Sarven Capadisli committed
318 319 320 321
                </div>
            </div>
        </div>
    </body>
322
</html>