install.php 15 KB

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