]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - install.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[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   Robin Millette <millette@controlyourself.ca>
31  * @author   Sarven Capadisli <csarven@status.net>
32  * @author   Tom Adams <tom@holizz.com>
33  * @author   Zach Copley <zach@status.net>
34  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
35  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
36  * @version  0.9.x
37  * @link     http://status.net
38  */
39
40 define('INSTALLDIR', dirname(__FILE__));
41
42 require INSTALLDIR . '/lib/installer.php';
43
44 /**
45  * Helper class for building form
46  */
47 class Posted {
48     /**
49      * HTML-friendly escaped string for the POST param of given name, or empty.
50      * @param string $name
51      * @return string
52      */
53     function value($name)
54     {
55         return htmlspecialchars($this->string($name));
56     }
57
58     /**
59      * The given POST parameter value, forced to a string.
60      * Missing value will give ''.
61      *
62      * @param string $name
63      * @return string
64      */
65     function string($name)
66     {
67         return strval($this->raw($name));
68     }
69
70     /**
71      * The given POST parameter value, in its original form.
72      * Magic quotes are stripped, if provided.
73      * Missing value will give null.
74      *
75      * @param string $name
76      * @return mixed
77      */
78     function raw($name)
79     {
80         if (isset($_POST[$name])) {
81             return $this->dequote($_POST[$name]);
82         } else {
83             return null;
84         }
85     }
86
87     /**
88      * If necessary, strip magic quotes from the given value.
89      *
90      * @param mixed $val
91      * @return mixed
92      */
93     function dequote($val)
94     {
95         if (get_magic_quotes_gpc()) {
96             if (is_string($val)) {
97                 return stripslashes($val);
98             } else if (is_array($val)) {
99                 return array_map(array($this, 'dequote'), $val);
100             }
101         }
102         return $val;
103     }
104 }
105
106 /**
107  * Web-based installer: provides a form and such.
108  */
109 class WebInstaller extends Installer
110 {
111     /**
112      * the actual installation.
113      * If call libraries are present, then install
114      *
115      * @return void
116      */
117     function main()
118     {
119         if (!$this->checkPrereqs()) {
120             $this->showForm();
121             return;
122         }
123
124         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
125             $this->handlePost();
126         } else {
127             $this->showForm();
128         }
129     }
130
131     /**
132      * Web implementation of warning output
133      */
134     function warning($message, $submessage='')
135     {
136         print "<p class=\"error\">$message</p>\n";
137         if ($submessage != '') {
138             print "<p>$submessage</p>\n";
139         }
140     }
141
142     /**
143      * Web implementation of status output
144      */
145     function updateStatus($status, $error=false)
146     {
147         echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
148     }
149
150     /**
151      * Show the web form!
152      */
153     function showForm()
154     {
155         global $dbModules;
156         $post = new Posted();
157         $dbRadios = '';
158         $dbtype = $post->raw('dbtype');
159         foreach (self::$dbModules as $type => $info) {
160             if ($this->checkExtension($info['check_module'])) {
161                 if ($dbtype == null || $dbtype == $type) {
162                     $checked = 'checked="checked" ';
163                     $dbtype = $type; // if we didn't have one checked, hit the first
164                 } else {
165                     $checked = '';
166                 }
167                 $dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
168             }
169         }
170
171         echo<<<E_O_T
172     <form method="post" action="install.php" class="form_settings" id="form_install">
173         <fieldset>
174             <fieldset id="settings_site">
175                 <legend>Site settings</legend>
176                 <ul class="form_data">
177                     <li>
178                         <label for="sitename">Site name</label>
179                         <input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
180                         <p class="form_guide">The name of your site</p>
181                     </li>
182                     <li>
183                         <label for="fancy-enable">Fancy URLs</label>
184                         <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
185                         <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
186                         <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
187                     </li>
188                 </ul>
189             </fieldset>
190
191             <fieldset id="settings_db">
192                 <legend>Database settings</legend>
193                 <ul class="form_data">
194                     <li>
195                         <label for="host">Hostname</label>
196                         <input type="text" id="host" name="host" value="{$post->value('host')}" />
197                         <p class="form_guide">Database hostname</p>
198                     </li>
199                     <li>
200                         <label for="dbtype">Type</label>
201                         $dbRadios
202                         <p class="form_guide">Database type</p>
203                     </li>
204                     <li>
205                         <label for="database">Name</label>
206                         <input type="text" id="database" name="database" value="{$post->value('database')}" />
207                         <p class="form_guide">Database name</p>
208                     </li>
209                     <li>
210                         <label for="dbusername">DB username</label>
211                         <input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
212                         <p class="form_guide">Database username</p>
213                     </li>
214                     <li>
215                         <label for="dbpassword">DB password</label>
216                         <input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
217                         <p class="form_guide">Database password (optional)</p>
218                     </li>
219                 </ul>
220             </fieldset>
221
222             <fieldset id="settings_admin">
223                 <legend>Administrator settings</legend>
224                 <ul class="form_data">
225                     <li>
226                         <label for="admin_nickname">Administrator nickname</label>
227                         <input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
228                         <p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
229                     </li>
230                     <li>
231                         <label for="admin_password">Administrator password</label>
232                         <input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
233                         <p class="form_guide">Password for the initial StatusNet user (administrator)</p>
234                     </li>
235                     <li>
236                         <label for="admin_password2">Confirm password</label>
237                         <input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
238                     </li>
239                     <li>
240                         <label for="admin_email">Administrator e-mail</label>
241                         <input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
242                         <p class="form_guide">Optional email address for the initial StatusNet user (administrator)</p>
243                     </li>
244                     <li>
245                         <label for="admin_updates">Subscribe to announcements</label>
246                         <input type="checkbox" id="admin_updates" name="admin_updates" value="true" checked="checked" />
247                         <p class="form_guide">Release and security feed from <a href="http://update.status.net/">update@status.net</a> (recommended)</p>
248                     </li>
249                 </ul>
250             </fieldset>
251             <input type="submit" name="submit" class="submit" value="Submit" />
252         </fieldset>
253     </form>
254
255 E_O_T;
256     }
257
258     /**
259      * Handle a POST submission... if we have valid input, start the install!
260      * Otherwise shows the form along with any error messages.
261      */
262     function handlePost()
263     {
264         echo <<<STR
265         <dl class="system_notice">
266             <dt>Page notice</dt>
267             <dd>
268                 <ul>
269 STR;
270         $this->validated = $this->prepare();
271         if ($this->validated) {
272             $this->doInstall();
273         }
274         echo <<<STR
275             </ul>
276         </dd>
277     </dl>
278 STR;
279         if (!$this->validated) {
280             $this->showForm();
281         }
282     }
283
284     /**
285      * Read and validate input data.
286      * May output side effects.
287      * 
288      * @return boolean success
289      */
290     function prepare()
291     {
292         $post = new Posted();
293         $this->host     = $post->string('host');
294         $this->dbtype   = $post->string('dbtype');
295         $this->database = $post->string('database');
296         $this->username = $post->string('dbusername');
297         $this->password = $post->string('dbpassword');
298         $this->sitename = $post->string('sitename');
299         $this->fancy    = (bool)$post->string('fancy');
300
301         $this->adminNick    = strtolower($post->string('admin_nickname'));
302         $this->adminPass    = $post->string('admin_password');
303         $adminPass2         = $post->string('admin_password2');
304         $this->adminEmail   = $post->string('admin_email');
305         $this->adminUpdates = $post->string('admin_updates');
306
307         $this->server = $_SERVER['HTTP_HOST'];
308         $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
309
310         $fail = false;
311         if (!$this->validateDb()) {
312             $fail = true;
313         }
314
315         if (!$this->validateAdmin()) {
316             $fail = true;
317         }
318         
319         if ($this->adminPass != $adminPass2) {
320             $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
321             $fail = true;
322         }
323         
324         return !$fail;
325     }
326
327 }
328
329 ?>
330 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
331 <!DOCTYPE html
332 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
333        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
334 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
335     <head>
336         <title>Install StatusNet</title>
337         <link rel="shortcut icon" href="favicon.ico"/>
338         <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
339         <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
340         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css" /><![endif]-->
341         <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css" /><![endif]-->
342         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/neo/css/ie.css" /><![endif]-->
343         <script src="js/jquery.min.js"></script>
344         <script src="js/install.js"></script>
345     </head>
346     <body id="install">
347         <div id="wrap">
348             <div id="header">
349                 <address id="site_contact" class="vcard">
350                     <a class="url home bookmark" href=".">
351                         <img class="logo photo" src="theme/neo/logo.png" alt="StatusNet"/>
352                         <span class="fn org">StatusNet</span>
353                     </a>
354                 </address>
355                 <div id="site_nav_global_primary"></div>
356             </div>
357             <div id="core">
358              <div id="aside_primary_wrapper">
359               <div id="content_wrapper">
360                <div id="site_nav_local_views_wrapper">
361                 <div id="site_nav_local_views"></div>
362                 
363                 <div id="content">
364                      <div id="content_inner">
365                         <h1>Install StatusNet</h1>
366 <?php 
367 $installer = new WebInstaller();
368 $installer->main();
369 ?>
370                    </div>
371                 </div>
372
373                 <div id="aside_primary" class="aside"></div>
374                </div>
375               </div>
376              </div>
377             </div>
378             <div id="footer"></div>
379         </div>
380     </body>
381 </html>