]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - install.php
Introduced common_location_shared() to check if location sharing is always,
[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                 </ul>
261             </fieldset>
262             <fieldset id="settings_profile">
263                 <legend>Site profile</legend>
264                 <ul class="form_data">
265                     <li>
266                         <label for="site_profile">Type of site</label>
267                         <select id="site_profile" name="site_profile">
268                             <option value="community">Community</option>
269                             <option value="public">Public (open registration)</option>
270                             <option value="singleuser">Single User</option>
271                             <option value="private">Private (no federation)</option>
272                         </select>
273                         <p class="form_guide">Initial access settings for your site</p>
274                     </li>
275                 </ul>
276             </fieldset>
277             <input type="submit" name="submit" class="submit" value="Submit" />
278         </fieldset>
279     </form>
280
281 E_O_T;
282     }
283
284     /**
285      * Handle a POST submission... if we have valid input, start the install!
286      * Otherwise shows the form along with any error messages.
287      */
288     function handlePost()
289     {
290         echo <<<STR
291         <dl class="system_notice">
292             <dt>Page notice</dt>
293             <dd>
294                 <ul>
295 STR;
296         $this->validated = $this->prepare();
297         if ($this->validated) {
298             $this->doInstall();
299         }
300         echo <<<STR
301             </ul>
302         </dd>
303     </dl>
304 STR;
305         if (!$this->validated) {
306             $this->showForm();
307         }
308     }
309
310     /**
311      * Read and validate input data.
312      * May output side effects.
313      *
314      * @return boolean success
315      */
316     function prepare()
317     {
318         $post = new Posted();
319         $this->host     = $post->string('host');
320         $this->dbtype   = $post->string('dbtype');
321         $this->database = $post->string('database');
322         $this->username = $post->string('dbusername');
323         $this->password = $post->string('dbpassword');
324         $this->sitename = $post->string('sitename');
325         $this->fancy    = (bool)$post->string('fancy');
326
327         $this->adminNick    = strtolower($post->string('admin_nickname'));
328         $this->adminPass    = $post->string('admin_password');
329         $adminPass2         = $post->string('admin_password2');
330         $this->adminEmail   = $post->string('admin_email');
331
332         $this->siteProfile = $post->string('site_profile');
333
334         $this->ssl = $post->string('ssl');
335
336         $this->server = $_SERVER['HTTP_HOST'];
337         $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
338
339         $fail = false;
340         if (!$this->validateDb()) {
341             $fail = true;
342         }
343
344         if (!$this->validateAdmin()) {
345             $fail = true;
346         }
347
348         if ($this->adminPass != $adminPass2) {
349             $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
350             $fail = true;
351         }
352
353         if (!in_array($this->ssl, array('never', 'sometimes', 'always'))) {
354             $this->updateStatus("Bad value for server SSL enabling.");
355             $fail = true;
356         }
357
358         if (!$this->validateSiteProfile()) {
359             $fail = true;
360         }
361
362         return !$fail;
363     }
364
365 }
366
367 ?>
368 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
369 <!DOCTYPE html
370 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
371        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
372 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
373     <head>
374         <title>Install GNU social</title>
375         <link rel="shortcut icon" href="favicon.ico"/>
376         <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
377         <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
378         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
379         <script src="js/extlib/jquery.js"></script>
380         <script src="js/install.js"></script>
381     </head>
382     <body id="install">
383         <div id="wrap">
384             <div id="header">
385                 <address id="site_contact" class="h-card">
386                     <a class="u-url p-name home bookmark org" href=".">
387                         <img class="logo u-photo" src="theme/neo/logo.png" alt="GNU social"/>
388                         GNU social
389                     </a>
390                 </address>
391                 <div id="site_nav_global_primary"></div>
392             </div>
393             <div id="core">
394              <div id="aside_primary_wrapper">
395               <div id="content_wrapper">
396                <div id="site_nav_local_views_wrapper">
397                 <div id="site_nav_local_views"></div>
398
399                 <div id="content">
400                      <div id="content_inner">
401                         <h1>Install GNU social</h1>
402 <?php
403 $installer = new WebInstaller();
404 $installer->main();
405 ?>
406                    </div>
407                 </div>
408
409                 <div id="aside_primary" class="aside"></div>
410                </div>
411               </div>
412              </div>
413             </div>
414             <div id="footer"></div>
415         </div>
416     </body>
417 </html>