]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - install.php
Bad route config (thanks brw12)
[quix0rs-gnu-social.git] / install.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009-2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @category Installation
20  * @package  Installation
21  *
22  * @author   Adrian Lang <mail@adrianlang.de>
23  * @author   Brenda Wallace <shiny@cpan.org>
24  * @author   Brett Taylor <brett@webfroot.co.nz>
25  * @author   Brion Vibber <brion@pobox.com>
26  * @author   CiaranG <ciaran@ciarang.com>
27  * @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/
37  * @version  0.9.x
38  * @link     http://status.net
39  */
40
41 define('INSTALLDIR', dirname(__FILE__));
42
43 require INSTALLDIR . '/lib/installer.php';
44
45 /**
46  * Helper class for building form
47  */
48 class Posted {
49     /**
50      * HTML-friendly escaped string for the POST param of given name, or empty.
51      * @param string $name
52      * @return string
53      */
54     function value($name)
55     {
56         return htmlspecialchars($this->string($name));
57     }
58
59     /**
60      * The given POST parameter value, forced to a string.
61      * Missing value will give ''.
62      *
63      * @param string $name
64      * @return string
65      */
66     function string($name)
67     {
68         return strval($this->raw($name));
69     }
70
71     /**
72      * The given POST parameter value, in its original form.
73      * Magic quotes are stripped, if provided.
74      * Missing value will give null.
75      *
76      * @param string $name
77      * @return mixed
78      */
79     function raw($name)
80     {
81         if (isset($_POST[$name])) {
82             return $this->dequote($_POST[$name]);
83         } else {
84             return null;
85         }
86     }
87
88     /**
89      * If necessary, strip magic quotes from the given value.
90      *
91      * @param mixed $val
92      * @return mixed
93      */
94     function dequote($val)
95     {
96         if (get_magic_quotes_gpc()) {
97             if (is_string($val)) {
98                 return stripslashes($val);
99             } else if (is_array($val)) {
100                 return array_map(array($this, 'dequote'), $val);
101             }
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      * the actual installation.
114      * If call libraries are present, then install
115      *
116      * @return void
117      */
118     function main()
119     {
120         if (!$this->checkPrereqs()) {
121             $this->showForm();
122             return;
123         }
124
125         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
126             $this->handlePost();
127         } else {
128             $this->showForm();
129         }
130     }
131
132     /**
133      * Web implementation of warning output
134      */
135     function warning($message, $submessage='')
136     {
137         print "<p class=\"error\">$message</p>\n";
138         if ($submessage != '') {
139             print "<p>$submessage</p>\n";
140         }
141     }
142
143     /**
144      * Web implementation of status output
145      */
146     function updateStatus($status, $error=false)
147     {
148         echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
149     }
150
151     /**
152      * Show the web form!
153      */
154     function showForm()
155     {
156         global $dbModules;
157         $post = new Posted();
158         $dbRadios = '';
159         $dbtype = $post->raw('dbtype');
160         foreach (self::$dbModules as $type => $info) {
161             if ($this->checkExtension($info['check_module'])) {
162                 if ($dbtype == null || $dbtype == $type) {
163                     $checked = 'checked="checked" ';
164                     $dbtype = $type; // if we didn't have one checked, hit the first
165                 } else {
166                     $checked = '';
167                 }
168                 $dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
169             }
170         }
171
172         $ssl = array('always'=>null, 'never'=>null);
173         if (!empty($_SERVER['HTTPS'])) {
174             $ssl['always'] = 'checked="checked"';
175         } else {
176             $ssl['never'] = 'checked="checked"';
177         }
178
179         echo<<<E_O_T
180     <form method="post" action="install.php" class="form_settings" id="form_install">
181         <fieldset>
182             <fieldset id="settings_site">
183                 <legend>Site settings</legend>
184                 <ul class="form_data">
185                     <li>
186                         <label for="sitename">Site name</label>
187                         <input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
188                         <p class="form_guide">The name of your site</p>
189                     </li>
190                     <li>
191                         <label for="fancy-enable">Fancy URLs</label>
192                         <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
193                         <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
194                         <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
195                     </li>
196                     <li>
197                         <label for="ssl">Server SSL</label>
198                         <input type="radio" name="ssl" id="ssl-always" value="always" {$ssl['always']} /> enable<br />
199                         <input type="radio" name="ssl" id="ssl-never" value="never" {$ssl['never']} /> disable<br />
200                         <p class="form_guide" id="ssl-form_guide">Enabling SSL (https://) requires extra webserver configuration and certificate generation not offered by this installation.</p>
201                     </li>
202                 </ul>
203             </fieldset>
204
205             <fieldset id="settings_db">
206                 <legend>Database settings</legend>
207                 <ul class="form_data">
208                     <li>
209                         <label for="host">Hostname</label>
210                         <input type="text" id="host" name="host" value="{$post->value('host')}" />
211                         <p class="form_guide">Database hostname</p>
212                     </li>
213                     <li>
214                         <label for="dbtype">Type</label>
215                         $dbRadios
216                         <p class="form_guide">Database type</p>
217                     </li>
218                     <li>
219                         <label for="database">Name</label>
220                         <input type="text" id="database" name="database" value="{$post->value('database')}" />
221                         <p class="form_guide">Database name</p>
222                     </li>
223                     <li>
224                         <label for="dbusername">DB username</label>
225                         <input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
226                         <p class="form_guide">Database username</p>
227                     </li>
228                     <li>
229                         <label for="dbpassword">DB password</label>
230                         <input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
231                         <p class="form_guide">Database password (optional)</p>
232                     </li>
233                 </ul>
234             </fieldset>
235
236             <fieldset id="settings_admin">
237                 <legend>Administrator settings</legend>
238                 <ul class="form_data">
239                     <li>
240                         <label for="admin_nickname">Administrator nickname</label>
241                         <input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
242                         <p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
243                     </li>
244                     <li>
245                         <label for="admin_password">Administrator password</label>
246                         <input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
247                         <p class="form_guide">Password for the initial StatusNet user (administrator)</p>
248                     </li>
249                     <li>
250                         <label for="admin_password2">Confirm password</label>
251                         <input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
252                     </li>
253                     <li>
254                         <label for="admin_email">Administrator e-mail</label>
255                         <input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
256                         <p class="form_guide">Optional email address for the initial StatusNet user (administrator)</p>
257                     </li>
258                     <li>
259                         <label for="admin_updates">Subscribe to announcements</label>
260                         <input type="checkbox" id="admin_updates" name="admin_updates" value="true" checked="checked" />
261                         <p class="form_guide">Release and security feed from <a href="http://update.status.net/">update@status.net</a> (recommended)</p>
262                     </li>
263                 </ul>
264             </fieldset>
265             <fieldset id="settings_profile">
266                 <legend>Site profile</legend>
267                 <ul class="form_data">
268                     <li>
269                         <label for="site_profile">Type of site</label>
270                         <select id="site_profile" name="site_profile">
271                             <option value="private">Private</option>
272                             <option value="community">Community</option>
273                             <option value ="public">Public</option>
274                             <option value ="singleuser">Single User</option>
275                         </select>
276                         <p class="form_guide">Initial access settings for your site</p>
277                     </li>
278                 </ul>
279             </fieldset>
280             <input type="submit" name="submit" class="submit" value="Submit" />
281         </fieldset>
282     </form>
283
284 E_O_T;
285     }
286
287     /**
288      * Handle a POST submission... if we have valid input, start the install!
289      * Otherwise shows the form along with any error messages.
290      */
291     function handlePost()
292     {
293         echo <<<STR
294         <dl class="system_notice">
295             <dt>Page notice</dt>
296             <dd>
297                 <ul>
298 STR;
299         $this->validated = $this->prepare();
300         if ($this->validated) {
301             $this->doInstall();
302         }
303         echo <<<STR
304             </ul>
305         </dd>
306     </dl>
307 STR;
308         if (!$this->validated) {
309             $this->showForm();
310         }
311     }
312
313     /**
314      * Read and validate input data.
315      * May output side effects.
316      *
317      * @return boolean success
318      */
319     function prepare()
320     {
321         $post = new Posted();
322         $this->host     = $post->string('host');
323         $this->dbtype   = $post->string('dbtype');
324         $this->database = $post->string('database');
325         $this->username = $post->string('dbusername');
326         $this->password = $post->string('dbpassword');
327         $this->sitename = $post->string('sitename');
328         $this->fancy    = (bool)$post->string('fancy');
329
330         $this->adminNick    = strtolower($post->string('admin_nickname'));
331         $this->adminPass    = $post->string('admin_password');
332         $adminPass2         = $post->string('admin_password2');
333         $this->adminEmail   = $post->string('admin_email');
334         $this->adminUpdates = $post->string('admin_updates');
335
336         $this->siteProfile = $post->string('site_profile');
337
338         $this->ssl = $post->string('ssl');
339
340         $this->server = $_SERVER['HTTP_HOST'];
341         $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
342
343         $fail = false;
344         if (!$this->validateDb()) {
345             $fail = true;
346         }
347
348         if (!$this->validateAdmin()) {
349             $fail = true;
350         }
351
352         if ($this->adminPass != $adminPass2) {
353             $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
354             $fail = true;
355         }
356
357         if (!in_array($this->ssl, array('never', 'sometimes', 'always'))) {
358             $this->updateStatus("Bad value for server SSL enabling.");
359             $fail = true;
360         }
361
362         if (!$this->validateSiteProfile()) {
363             $fail = true;
364         }
365
366         return !$fail;
367     }
368
369 }
370
371 ?>
372 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
373 <!DOCTYPE html
374 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
375        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
376 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
377     <head>
378         <title>Install StatusNet</title>
379         <link rel="shortcut icon" href="favicon.ico"/>
380         <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
381         <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
382         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css" /><![endif]-->
383         <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css" /><![endif]-->
384         <!--[if lte IE 7]><link rel="stylesheet" type="text/css" theme/base/css/ie7.css" /><![endif]-->
385         <script src="js/extlib/jquery.min.js"></script>
386         <script src="js/install.js"></script>
387     </head>
388     <body id="install">
389         <div id="wrap">
390             <div id="header">
391                 <address id="site_contact" class="vcard">
392                     <a class="url home bookmark" href=".">
393                         <img class="logo photo" src="theme/neo/logo.png" alt="StatusNet"/>
394                         <span class="fn org">StatusNet</span>
395                     </a>
396                 </address>
397                 <div id="site_nav_global_primary"></div>
398             </div>
399             <div id="core">
400              <div id="aside_primary_wrapper">
401               <div id="content_wrapper">
402                <div id="site_nav_local_views_wrapper">
403                 <div id="site_nav_local_views"></div>
404
405                 <div id="content">
406                      <div id="content_inner">
407                         <h1>Install StatusNet</h1>
408 <?php
409 $installer = new WebInstaller();
410 $installer->main();
411 ?>
412                    </div>
413                 </div>
414
415                 <div id="aside_primary" class="aside"></div>
416                </div>
417               </div>
418              </div>
419             </div>
420             <div id="footer"></div>
421         </div>
422     </body>
423 </html>