]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - install.php
Installer database adjustments
[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->warning(_('Please fix the above stated problems and refresh this page to continue installing.'));
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 .= sprintf('<input type="radio" name="dbtype" id="dbtype-%1$s" value="%1$s" %2$s/>%3$s<br />',
169                                 htmlspecialchars($type), $checked,
170                                 htmlspecialchars($info['name']));
171             }
172         }
173
174         $ssl = array('always'=>null, 'never'=>null);
175         if (!empty($_SERVER['HTTPS'])) {
176             $ssl['always'] = 'checked="checked"';
177         } else {
178             $ssl['never'] = 'checked="checked"';
179         }
180
181         echo<<<E_O_T
182     <form method="post" action="install.php" class="form_settings" id="form_install">
183         <fieldset>
184             <fieldset id="settings_site">
185                 <legend>Site settings</legend>
186                 <ul class="form_data">
187                     <li>
188                         <label for="sitename">Site name</label>
189                         <input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
190                         <p class="form_guide">The name of your site</p>
191                     </li>
192                     <li>
193                         <label for="fancy-enable">Fancy URLs</label>
194                         <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
195                         <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
196                         <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
197                     </li>
198                     <li>
199                         <label for="ssl">Server SSL</label>
200                         <input type="radio" name="ssl" id="ssl-always" value="always" {$ssl['always']} /> enable<br />
201                         <input type="radio" name="ssl" id="ssl-never" value="never" {$ssl['never']} /> disable<br />
202                         <p class="form_guide" id="ssl-form_guide">Enabling SSL (https://) requires extra webserver configuration and certificate generation not offered by this installation.</p>
203                     </li>
204                 </ul>
205             </fieldset>
206
207             <fieldset id="settings_db">
208                 <legend>Database settings</legend>
209                 <ul class="form_data">
210                     <li>
211                         <label for="host">Hostname</label>
212                         <input type="text" id="host" name="host" value="{$post->value('host')}" />
213                         <p class="form_guide">Database hostname</p>
214                     </li>
215                     <li>
216                         <label for="dbtype">Type</label>
217                         {$dbRadios}
218                         <p class="form_guide">Database type</p>
219                     </li>
220                     <li>
221                         <label for="database">Name</label>
222                         <input type="text" id="database" name="database" value="{$post->value('database')}" />
223                         <p class="form_guide">Database name</p>
224                     </li>
225                     <li>
226                         <label for="dbusername">DB username</label>
227                         <input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
228                         <p class="form_guide">Database username</p>
229                     </li>
230                     <li>
231                         <label for="dbpassword">DB password</label>
232                         <input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
233                         <p class="form_guide">Database password (optional)</p>
234                     </li>
235                 </ul>
236             </fieldset>
237
238             <fieldset id="settings_admin">
239                 <legend>Administrator settings</legend>
240                 <ul class="form_data">
241                     <li>
242                         <label for="admin_nickname">Administrator nickname</label>
243                         <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                     </li>
246                     <li>
247                         <label for="admin_password">Administrator password</label>
248                         <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                     </li>
251                     <li>
252                         <label for="admin_password2">Confirm password</label>
253                         <input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
254                     </li>
255                     <li>
256                         <label for="admin_email">Administrator e-mail</label>
257                         <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                     </li>
260                     <li>
261                         <label for="admin_updates">Subscribe to announcements</label>
262                         <input type="checkbox" id="admin_updates" name="admin_updates" value="true" checked="checked" />
263                         <p class="form_guide">Release and security feed from <a href="http://update.status.net/">update@status.net</a> (recommended)</p>
264                     </li>
265                 </ul>
266             </fieldset>
267             <fieldset id="settings_profile">
268                 <legend>Site profile</legend>
269                 <ul class="form_data">
270                     <li>
271                         <label for="site_profile">Type of site</label>
272                         <select id="site_profile" name="site_profile">
273                             <option value="private">Private</option>
274                             <option value="community">Community</option>
275                             <option value ="public">Public</option>
276                             <option value ="singleuser">Single User</option>
277                         </select>
278                         <p class="form_guide">Initial access settings for your site</p>
279                     </li>
280                 </ul>
281             </fieldset>
282             <input type="submit" name="submit" class="submit" value="Submit" />
283         </fieldset>
284     </form>
285
286 E_O_T;
287     }
288
289     /**
290      * Handle a POST submission... if we have valid input, start the install!
291      * Otherwise shows the form along with any error messages.
292      */
293     function handlePost()
294     {
295         echo <<<STR
296         <dl class="system_notice">
297             <dt>Page notice</dt>
298             <dd>
299                 <ul>
300 STR;
301         $this->validated = $this->prepare();
302         if ($this->validated) {
303             $this->doInstall();
304         }
305         echo <<<STR
306             </ul>
307         </dd>
308     </dl>
309 STR;
310         if (!$this->validated) {
311             $this->showForm();
312         }
313     }
314
315     /**
316      * Read and validate input data.
317      * May output side effects.
318      *
319      * @return boolean success
320      */
321     function prepare()
322     {
323         $post = new Posted();
324         $this->host     = $post->string('host');
325         $this->dbtype   = $post->string('dbtype');
326         $this->database = $post->string('database');
327         $this->username = $post->string('dbusername');
328         $this->password = $post->string('dbpassword');
329         $this->sitename = $post->string('sitename');
330         $this->fancy    = (bool)$post->string('fancy');
331
332         $this->adminNick    = strtolower($post->string('admin_nickname'));
333         $this->adminPass    = $post->string('admin_password');
334         $adminPass2         = $post->string('admin_password2');
335         $this->adminEmail   = $post->string('admin_email');
336         $this->adminUpdates = $post->string('admin_updates');
337
338         $this->siteProfile = $post->string('site_profile');
339
340         $this->ssl = $post->string('ssl');
341
342         $this->server = $_SERVER['HTTP_HOST'];
343         $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
344
345         $fail = false;
346         if (!$this->validateDb()) {
347             $fail = true;
348         }
349
350         if (!$this->validateAdmin()) {
351             $fail = true;
352         }
353
354         if ($this->adminPass != $adminPass2) {
355             $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
356             $fail = true;
357         }
358
359         if (!in_array($this->ssl, array('never', 'sometimes', 'always'))) {
360             $this->updateStatus("Bad value for server SSL enabling.");
361             $fail = true;
362         }
363
364         if (!$this->validateSiteProfile()) {
365             $fail = true;
366         }
367
368         return !$fail;
369     }
370
371 }
372
373 ?>
374 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
375 <!DOCTYPE html
376 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
377        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
378 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
379     <head>
380         <title>Install GNU social</title>
381         <link rel="shortcut icon" href="favicon.ico"/>
382         <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
383         <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
384         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
385         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css" /><![endif]-->
386         <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css" /><![endif]-->
387         <!--[if lte IE 7]><link rel="stylesheet" type="text/css" theme/base/css/ie7.css" /><![endif]-->
388         <script src="js/extlib/jquery.js"></script>
389         <script src="js/install.js"></script>
390     </head>
391     <body id="install">
392         <div id="wrap">
393             <div id="header">
394                 <address id="site_contact" class="vcard">
395                     <a class="url home bookmark" href=".">
396                         <img class="logo photo" src="theme/neo/logo.png" alt="GNU social"/>
397                         <span class="fn org">GNU social</span>
398                     </a>
399                 </address>
400                 <div id="site_nav_global_primary"></div>
401             </div>
402             <div id="core">
403              <div id="aside_primary_wrapper">
404               <div id="content_wrapper">
405                <div id="site_nav_local_views_wrapper">
406                 <div id="site_nav_local_views"></div>
407
408                 <div id="content">
409                      <div id="content_inner">
410                         <h1>Install GNU social</h1>
411 <?php
412 $installer = new WebInstaller();
413 $installer->main();
414 ?>
415                    </div>
416                 </div>
417
418                 <div id="aside_primary" class="aside"></div>
419                </div>
420               </div>
421              </div>
422             </div>
423             <div id="footer"></div>
424         </div>
425     </body>
426 </html>