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