The official, canonical postActiv repository. http://www.postactiv.com

install.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <?php
  2. /* ============================================================================
  3. * Title: Install
  4. * Web-based installation script
  5. *
  6. * postActiv:
  7. * the micro-blogging software
  8. *
  9. * Copyright:
  10. * Copyright (C) 2016-2017, Maiyannah Bishop
  11. *
  12. * Derived from code copyright various sources:
  13. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  14. * o StatusNet (C) 2008-2012, StatusNet, Inc
  15. * ----------------------------------------------------------------------------
  16. * License:
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. * <https://www.gnu.org/licenses/agpl.html>
  30. * ----------------------------------------------------------------------------
  31. * About:
  32. * Web installation script for postActiv
  33. *
  34. * PHP version:
  35. * Tested with PHP 5.6, PHP 7
  36. * ----------------------------------------------------------------------------
  37. * File Authors:
  38. * o Evan Prodromou <evan@status.net>
  39. * o Adrian Lang <mail@adrianlang.de>
  40. * o Brenda Wallace <shiny@cpan.org>
  41. * o Brett Taylor <brett@webfroot.co.nz>
  42. * o Brion Vibber <brion@pobox.com>
  43. * o Ciaran Gultneiks <ciaran@ciarang.com>
  44. * o Craig Andrews <candrews@integralblue.com>
  45. * o Eric Helgeson
  46. * o Robin Millette
  47. * o Sarven Capadisli
  48. * o Tom Adams <tom@holizz.com>
  49. * o Zach Copley
  50. * o Mikael Nordfeldth <mmn@hethane.se>
  51. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  52. *
  53. * Web:
  54. * o postActiv <http://www.postactiv.com>
  55. * o GNU social <https://www.gnu.org/s/social/>
  56. * ============================================================================
  57. */
  58. // This file is formatted so that it provides useful documentation output in
  59. // NaturalDocs. Please be considerate of this before changing formatting.
  60. define('INSTALLDIR', dirname(__FILE__));
  61. require INSTALLDIR . '/lib/installer.php';
  62. /**
  63. * Helper class for building form
  64. */
  65. class Posted {
  66. /**
  67. * HTML-friendly escaped string for the POST param of given name, or empty.
  68. * @param string $name
  69. * @return string
  70. */
  71. function value($name)
  72. {
  73. return htmlspecialchars($this->string($name));
  74. }
  75. /**
  76. * The given POST parameter value, forced to a string.
  77. * Missing value will give ''.
  78. *
  79. * @param string $name
  80. * @return string
  81. */
  82. function string($name)
  83. {
  84. return strval($this->raw($name));
  85. }
  86. /**
  87. * The given POST parameter value, in its original form.
  88. * Magic quotes are stripped, if provided.
  89. * Missing value will give null.
  90. *
  91. * @param string $name
  92. * @return mixed
  93. */
  94. function raw($name)
  95. {
  96. if (isset($_POST[$name])) {
  97. return $this->dequote($_POST[$name]);
  98. } else {
  99. return null;
  100. }
  101. }
  102. /**
  103. * If necessary, strip magic quotes from the given value.
  104. *
  105. * @param mixed $val
  106. * @return mixed
  107. */
  108. function dequote($val)
  109. {
  110. if (get_magic_quotes_gpc()) {
  111. if (is_string($val)) {
  112. return stripslashes($val);
  113. } else if (is_array($val)) {
  114. return array_map(array($this, 'dequote'), $val);
  115. }
  116. }
  117. return $val;
  118. }
  119. }
  120. /**
  121. * Web-based installer: provides a form and such.
  122. */
  123. class WebInstaller extends Installer
  124. {
  125. /**
  126. * the actual installation.
  127. * If call libraries are present, then install
  128. *
  129. * @return void
  130. */
  131. function main()
  132. {
  133. if (!$this->checkPrereqs()) {
  134. $this->warning(_('Please fix the above stated problems and refresh this page to continue installing.'));
  135. return;
  136. }
  137. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  138. $this->handlePost();
  139. } else {
  140. $this->showForm();
  141. }
  142. }
  143. /**
  144. * Web implementation of warning output
  145. */
  146. function warning($message, $submessage='')
  147. {
  148. print "<p class=\"error\">$message</p>\n";
  149. if ($submessage != '') {
  150. print "<p>$submessage</p>\n";
  151. }
  152. }
  153. /**
  154. * Web implementation of status output
  155. */
  156. function updateStatus($status, $error=false)
  157. {
  158. echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
  159. }
  160. /**
  161. * Show the web form!
  162. */
  163. function showForm()
  164. {
  165. global $dbModules;
  166. $post = new Posted();
  167. $dbRadios = '';
  168. $dbtype = $post->raw('dbtype');
  169. foreach (self::$dbModules as $type => $info) {
  170. if ($this->checkExtension($info['check_module'])) {
  171. if ($dbtype == null || $dbtype == $type) {
  172. $checked = 'checked="checked" ';
  173. $dbtype = $type; // if we didn't have one checked, hit the first
  174. } else {
  175. $checked = '';
  176. }
  177. $dbRadios .= sprintf('<input type="radio" name="dbtype" id="dbtype-%1$s" value="%1$s" %2$s/>%3$s<br />',
  178. htmlspecialchars($type), $checked,
  179. htmlspecialchars($info['name']));
  180. }
  181. }
  182. $ssl = array('always'=>null, 'never'=>null);
  183. if (!empty($_SERVER['HTTPS'])) {
  184. $ssl['always'] = 'checked="checked"';
  185. } else {
  186. $ssl['never'] = 'checked="checked"';
  187. }
  188. echo<<<E_O_T
  189. <form method="post" action="install.php" class="form_settings" id="form_install">
  190. <fieldset>
  191. <fieldset id="settings_site">
  192. <legend>Site settings</legend>
  193. <ul class="form_data">
  194. <li>
  195. <label for="sitename">Site name</label>
  196. <input type="text" id="sitename" name="sitename" value="{$post->value('sitename')}" />
  197. <p class="form_guide">The name of your site</p>
  198. </li>
  199. <li>
  200. <label for="fancy-enable">Fancy URLs</label>
  201. <input type="radio" name="fancy" id="fancy-enable" value="enable" checked='checked' /> enable<br />
  202. <input type="radio" name="fancy" id="fancy-disable" value="" /> disable<br />
  203. <p class="form_guide" id='fancy-form_guide'>Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.</p>
  204. </li>
  205. <li>
  206. <label for="ssl">Server SSL</label>
  207. <input type="radio" name="ssl" id="ssl-always" value="always" {$ssl['always']} /> enable<br />
  208. <input type="radio" name="ssl" id="ssl-never" value="never" {$ssl['never']} /> disable<br />
  209. <p class="form_guide" id="ssl-form_guide">Enabling SSL (https://) requires extra webserver configuration and certificate generation not offered by this installation.</p>
  210. </li>
  211. </ul>
  212. </fieldset>
  213. <fieldset id="settings_db">
  214. <legend>Database settings</legend>
  215. <ul class="form_data">
  216. <li>
  217. <label for="host">Hostname</label>
  218. <input type="text" id="host" name="host" value="{$post->value('host')}" />
  219. <p class="form_guide">Database hostname</p>
  220. </li>
  221. <li>
  222. <label for="dbtype">Type</label>
  223. {$dbRadios}
  224. <p class="form_guide">Database type</p>
  225. </li>
  226. <li>
  227. <label for="database">Name</label>
  228. <input type="text" id="database" name="database" value="{$post->value('database')}" />
  229. <p class="form_guide">Database name</p>
  230. </li>
  231. <li>
  232. <label for="dbusername">DB username</label>
  233. <input type="text" id="dbusername" name="dbusername" value="{$post->value('dbusername')}" />
  234. <p class="form_guide">Database username</p>
  235. </li>
  236. <li>
  237. <label for="dbpassword">DB password</label>
  238. <input type="password" id="dbpassword" name="dbpassword" value="{$post->value('dbpassword')}" />
  239. <p class="form_guide">Database password (optional)</p>
  240. </li>
  241. </ul>
  242. </fieldset>
  243. <fieldset id="settings_admin">
  244. <legend>Administrator settings</legend>
  245. <ul class="form_data">
  246. <li>
  247. <label for="admin_nickname">Administrator nickname</label>
  248. <input type="text" id="admin_nickname" name="admin_nickname" value="{$post->value('admin_nickname')}" />
  249. <p class="form_guide">Nickname for the initial user (administrator)</p>
  250. </li>
  251. <li>
  252. <label for="admin_password">Administrator password</label>
  253. <input type="password" id="admin_password" name="admin_password" value="{$post->value('admin_password')}" />
  254. <p class="form_guide">Password for the initial user (administrator)</p>
  255. </li>
  256. <li>
  257. <label for="admin_password2">Confirm password</label>
  258. <input type="password" id="admin_password2" name="admin_password2" value="{$post->value('admin_password2')}" />
  259. </li>
  260. <li>
  261. <label for="admin_email">Administrator e-mail</label>
  262. <input id="admin_email" name="admin_email" value="{$post->value('admin_email')}" />
  263. <p class="form_guide">Optional email address for the initial user (administrator)</p>
  264. </li>
  265. </ul>
  266. </fieldset>
  267. <fieldset id="settings_profile">
  268. <legend>Site profile</legend>
  269. <ul class="form_data">
  270. <li>
  271. <label for="site_profile">Type of site</label>
  272. <select id="site_profile" name="site_profile">
  273. <option value="community">Community</option>
  274. <option value="public">Public (open registration)</option>
  275. <option value="singleuser">Single User</option>
  276. <option value="private">Private (no federation)</option>
  277. </select>
  278. <p class="form_guide">Initial access settings for your site</p>
  279. </li>
  280. </ul>
  281. </fieldset>
  282. <input type="submit" name="submit" class="submit" value="Submit" />
  283. </fieldset>
  284. </form>
  285. E_O_T;
  286. }
  287. /**
  288. * Handle a POST submission... if we have valid input, start the install!
  289. * Otherwise shows the form along with any error messages.
  290. */
  291. function handlePost()
  292. {
  293. echo <<<STR
  294. <dl class="system_notice">
  295. <dt>Page notice</dt>
  296. <dd>
  297. <ul>
  298. STR;
  299. $this->validated = $this->prepare();
  300. if ($this->validated) {
  301. $this->doInstall();
  302. }
  303. echo <<<STR
  304. </ul>
  305. </dd>
  306. </dl>
  307. STR;
  308. if (!$this->validated) {
  309. $this->showForm();
  310. }
  311. }
  312. /**
  313. * Read and validate input data.
  314. * May output side effects.
  315. *
  316. * @return boolean success
  317. */
  318. function prepare()
  319. {
  320. $post = new Posted();
  321. $this->host = $post->string('host');
  322. $this->dbtype = $post->string('dbtype');
  323. $this->database = $post->string('database');
  324. $this->username = $post->string('dbusername');
  325. $this->password = $post->string('dbpassword');
  326. $this->sitename = $post->string('sitename');
  327. $this->fancy = (bool)$post->string('fancy');
  328. $this->adminNick = strtolower($post->string('admin_nickname'));
  329. $this->adminPass = $post->string('admin_password');
  330. $adminPass2 = $post->string('admin_password2');
  331. $this->adminEmail = $post->string('admin_email');
  332. $this->siteProfile = $post->string('site_profile');
  333. $this->ssl = $post->string('ssl');
  334. $this->server = $_SERVER['HTTP_HOST'];
  335. $this->path = substr(dirname($_SERVER['PHP_SELF']), 1);
  336. $fail = false;
  337. if (!$this->validateDb()) {
  338. $fail = true;
  339. }
  340. if (!$this->validateAdmin()) {
  341. $fail = true;
  342. }
  343. if ($this->adminPass != $adminPass2) {
  344. $this->updateStatus("Administrator passwords do not match. Did you mistype?", true);
  345. $fail = true;
  346. }
  347. if (!in_array($this->ssl, array('never', 'always'))) {
  348. $this->updateStatus("Bad value for server SSL enabling.");
  349. $fail = true;
  350. }
  351. if (!$this->validateSiteProfile()) {
  352. $fail = true;
  353. }
  354. return !$fail;
  355. }
  356. }
  357. ?>
  358. <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
  359. <!DOCTYPE html
  360. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  361. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  362. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
  363. <head>
  364. <title>Install GNU social</title>
  365. <link rel="shortcut icon" href="favicon.ico"/>
  366. <link rel="stylesheet" type="text/css" href="theme/base/css/display.css" media="screen, projection, tv"/>
  367. <link rel="stylesheet" type="text/css" href="theme/neo/css/display.css" media="screen, projection, tv"/>
  368. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  369. <script src="js/extlib/jquery.js"></script>
  370. <script src="js/install.js"></script>
  371. </head>
  372. <body id="install">
  373. <div id="wrap">
  374. <div id="header">
  375. <address id="site_contact" class="h-card">
  376. <a class="u-url p-name home bookmark org" href=".">
  377. <img class="logo u-photo" src="theme/neo/logo.png" alt="GNU social"/>
  378. GNU social
  379. </a>
  380. </address>
  381. <div id="site_nav_global_primary"></div>
  382. </div>
  383. <div id="core">
  384. <div id="aside_primary_wrapper">
  385. <div id="content_wrapper">
  386. <div id="site_nav_local_views_wrapper">
  387. <div id="site_nav_local_views"></div>
  388. <div id="content">
  389. <div id="content_inner">
  390. <h1>Install GNU social</h1>
  391. <?php
  392. $installer = new WebInstaller();
  393. $installer->main();
  394. ?>
  395. </div>
  396. </div>
  397. <div id="aside_primary" class="aside"></div>
  398. </div>
  399. </div>
  400. </div>
  401. </div>
  402. <div id="footer"></div>
  403. </div>
  404. </body>
  405. </html>
  406. ?>