]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - install.php
Merge branch '0.9.x' 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     function value($name)
49     {
50         if (isset($_POST[$name])) {
51             return htmlspecialchars(strval($_POST[$name]));
52         } else {
53             return '';
54         }
55     }
56 }
57
58 /**
59  * Web-based installer: provides a form and such.
60  */
61 class WebInstaller extends Installer
62 {
63     /**
64      * the actual installation.
65      * If call libraries are present, then install
66      *
67      * @return void
68      */
69     function main()
70     {
71         if (!$this->checkPrereqs()) {
72             $this->showForm();
73             return;
74         }
75
76         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
77             $this->handlePost();
78         } else {
79             $this->showForm();
80         }
81     }
82
83     /**
84      * Web implementation of warning output
85      */
86     function warning($message, $submessage='')
87     {
88         print "<p class=\"error\">$message</p>\n";
89         if ($submessage != '') {
90             print "<p>$submessage</p>\n";
91         }
92     }
93
94     /**
95      * Web implementation of status output
96      */
97     function updateStatus($status, $error=false)
98     {
99         echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
100     }
101
102     /**
103      * Show the web form!
104      */
105     function showForm()
106     {
107         global $dbModules;
108         $post = new Posted();
109         $dbRadios = '';
110         if (isset($_POST['dbtype'])) {
111             $dbtype = $_POST['dbtype'];
112         } else {
113             $dbtype = null;
114         }
115         foreach (self::$dbModules as $type => $info) {
116             if ($this->checkExtension($info['check_module'])) {
117                 if ($dbtype == null || $dbtype == $type) {
118                     $checked = 'checked="checked" ';
119                     $dbtype = $type; // if we didn't have one checked, hit the first
120                 } else {
121                     $checked = '';
122                 }
123                 $dbRadios .= "<input type=\"radio\" name=\"dbtype\" id=\"dbtype-$type\" value=\"$type\" $checked/> $info[name]<br />\n";
124             }
125         }
126
127         echo<<<E_O_T
128     <form method="post" action="install.php" class="form_settings" id="form_install">
129         <fieldset>
130             <fieldset id="settings_site">
131                 <legend>Site settings</legend>
132                 <ul class="form_data">
133                     <li>
134                         <label for="sitename">Site name</label>
135                         <input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
136                         <p class="form_guide">The name of your site</p>
137                     </li>
138                     <li>
139                         <label for="fancy-enable">Fancy URLs</label>
140                         <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
141                         <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
142                         <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
143                     </li>
144                 </ul>
145             </fieldset>
146
147             <fieldset id="settings_db">
148                 <legend>Database settings</legend>
149                 <ul class="form_data">
150                     <li>
151                         <label for="host">Hostname</label>
152                         <input type="text" id="host" name="host" value="{$post->value('host')}" />
153                         <p class="form_guide">Database hostname</p>
154                     </li>
155                     <li>
156                         <label for="dbtype">Type</label>
157                         $dbRadios
158                         <p class="form_guide">Database type</p>
159                     </li>
160                     <li>
161                         <label for="database">Name</label>
162                         <input type="text" id="database" name="database" value="{$post->value('database')}" />
163                         <p class="form_guide">Database name</p>
164                     </li>
165                     <li>
166                         <label for="dbusername">DB username</label>
167                         <input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
168                         <p class="form_guide">Database username</p>
169                     </li>
170                     <li>
171                         <label for="dbpassword">DB password</label>
172                         <input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
173                         <p class="form_guide">Database password (optional)</p>
174                     </li>
175                 </ul>
176             </fieldset>
177
178             <fieldset id="settings_admin">
179                 <legend>Administrator settings</legend>
180                 <ul class="form_data">
181                     <li>
182                         <label for="admin_nickname">Administrator nickname</label>
183                         <input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
184                         <p class="form_guide">Nickname for the initial StatusNet user (administrator)</p>
185                     </li>
186                     <li>
187                         <label for="admin_password">Administrator password</label>
188                         <input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
189                         <p class="form_guide">Password for the initial StatusNet user (administrator)</p>
190                     </li>
191                     <li>
192                         <label for="admin_password2">Confirm password</label>
193                         <input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
194                     </li>
195                     <li>
196                         <label for="admin_email">Administrator e-mail</label>
197                         <input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
198                         <p class="form_guide">Optional email address for the initial StatusNet user (administrator)</p>
199                     </li>
200                     <li>
201                         <label for="admin_updates">Subscribe to announcements</label>
202                         <input type="checkbox" id="admin_updates" name="admin_updates" value="true" checked="checked" />
203                         <p class="form_guide">Release and security feed from <a href="http://update.status.net/">update@status.net</a> (recommended)</p>
204                     </li>
205                 </ul>
206             </fieldset>
207             <input type="submit" name="submit" class="submit" value="Submit" />
208         </fieldset>
209     </form>
210
211 E_O_T;
212     }
213
214     /**
215      * Handle a POST submission... if we have valid input, start the install!
216      * Otherwise shows the form along with any error messages.
217      */
218     function handlePost()
219     {
220         echo <<<STR
221         <dl class="system_notice">
222             <dt>Page notice</dt>
223             <dd>
224                 <ul>
225 STR;
226         $this->validated = $this->prepare();
227         if ($this->validated) {
228             $this->doInstall();
229         }
230         echo <<<STR
231             </ul>
232         </dd>
233     </dl>
234 STR;
235         if (!$this->validated) {
236             $this->showForm();
237         }
238     }
239
240     /**
241      * Read and validate input data.
242      * May output side effects.
243      * 
244      * @return boolean success
245      */
246     function prepare()
247     {
248         $this->host     = $_POST['host'];
249         $this->dbtype   = $_POST['dbtype'];
250         $this->database = $_POST['database'];
251         $this->username = $_POST['dbusername'];
252         $this->password = $_POST['dbpassword'];
253         $this->sitename = $_POST['sitename'];
254         $this->fancy    = !empty($_POST['fancy']);
255
256         $this->adminNick    = strtolower($_POST['admin_nickname']);
257         $this->adminPass    = $_POST['admin_password'];
258         $adminPass2         = $_POST['admin_password2'];
259         $this->adminEmail   = $_POST['admin_email'];
260         $this->adminUpdates = $_POST['admin_updates'];
261
262         $this->server = $_SERVER['HTTP_HOST'];
263         $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
264
265         $fail = false;
266         if (!$this->validateDb()) {
267             $fail = true;
268         }
269
270         if (!$this->validateAdmin()) {
271             $fail = true;
272         }
273         
274         if ($this->adminPass != $adminPass2) {
275             $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
276             $fail = true;
277         }
278         
279         return !$fail;
280     }
281
282 }
283
284 ?>
285 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
286 <!DOCTYPE html
287 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
288        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
289 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
290     <head>
291         <title>Install StatusNet</title>
292         <link rel="shortcut icon" href="favicon.ico"/>
293         <link rel="stylesheet" type="text/css" href="theme/default/css/display.css" media="screen, projection, tv"/>
294         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css" /><![endif]-->
295         <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css" /><![endif]-->
296         <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/default/css/ie.css" /><![endif]-->
297         <script src="js/jquery.min.js"></script>
298         <script src="js/install.js"></script>
299     </head>
300     <body id="install">
301         <div id="wrap">
302             <div id="header">
303                 <address id="site_contact" class="vcard">
304                     <a class="url home bookmark" href=".">
305                         <img class="logo photo" src="theme/default/logo.png" alt="StatusNet"/>
306                         <span class="fn org">StatusNet</span>
307                     </a>
308                 </address>
309             </div>
310             <div id="core">
311                 <div id="content">
312                      <div id="content_inner">
313                         <h1>Install StatusNet</h1>
314 <?php 
315 $installer = new WebInstaller();
316 $installer->main();
317 ?>
318                    </div>
319                 </div>
320             </div>
321         </div>
322     </body>
323 </html>