PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/phpmyfaq/install/setup.php

http://github.com/thorsten/phpMyFAQ
PHP | 935 lines | 846 code | 51 blank | 38 comment | 46 complexity | 0120cebcca3ed2c3b28208b995d8e907 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * The main phpMyFAQ Setup
  4. *
  5. * This script checks the complete environment, writes the database connection
  6. * parameters into the file config/database.php and the configuration into the database.
  7. *
  8. * PHP Version 5.3
  9. *
  10. * This Source Code Form is subject to the terms of the Mozilla Public License,
  11. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  12. * obtain one at http://mozilla.org/MPL/2.0/.
  13. *
  14. * @category phpMyFAQ
  15. * @package Setup
  16. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  17. * @author Tom Rochester <tom.rochester@gmail.com>
  18. * @author Johannes Schl?ter <johannes@php.net>
  19. * @author Uwe Pries <uwe.pries@digartis.de>
  20. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  21. * @copyright 2002-2012 phpMyFAQ Team
  22. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  23. * @link http://www.phpmyfaq.de
  24. * @since 2002-08-20
  25. */
  26. define('COPYRIGHT', '&copy; 2001-2012 <a href="http://www.phpmyfaq.de/">phpMyFAQ Team</a> | Follow us on <a href="http://twitter.com/phpMyFAQ">Twitter</a> | All rights reserved.');
  27. define('PMF_ROOT_DIR', dirname(__DIR__));
  28. define('IS_VALID_PHPMYFAQ', null);
  29. if (! defined('DEBUG')) {
  30. define('DEBUG', true);
  31. }
  32. if ((@ini_get('safe_mode') != 'On' || @ini_get('safe_mode') !== 1)) {
  33. set_time_limit(0);
  34. }
  35. require PMF_ROOT_DIR . '/config/constants.php';
  36. require PMF_ROOT_DIR . '/inc/Autoloader.php';
  37. require PMF_ROOT_DIR . '/inc/functions.php';
  38. require PMF_ROOT_DIR . '/install/questionnaire.php';
  39. //
  40. // Initalizing static string wrapper
  41. //
  42. PMF_String::init('en');
  43. $query = $uninst = array();
  44. /**
  45. * Print out the HTML5 Footer
  46. *
  47. * @return void
  48. */
  49. function HTMLFooter()
  50. {
  51. printf(
  52. '</div></div></section><footer><div class="container"><p class="pull-right">%s</p><div></footer></body></html>',
  53. COPYRIGHT
  54. );
  55. }
  56. $system = new PMF_System();
  57. $instanceSetup = new PMF_Instance_Setup();
  58. $instanceSetup->setRootDir(PMF_ROOT_DIR);
  59. ?>
  60. <!doctype html>
  61. <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
  62. <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
  63. <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
  64. <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
  65. <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
  66. <head>
  67. <meta charset="utf-8">
  68. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  69. <title>phpMyFAQ <?php print PMF_System::getVersion(); ?> Setup</title>
  70. <meta name="viewport" content="width=device-width;">
  71. <meta name="application-name" content="phpMyFAQ <?php print PMF_System::getVersion(); ?>">
  72. <meta name="copyright" content="(c) 2001-<?php print date('Y'); ?> phpMyFAQ Team">
  73. <link rel="stylesheet" href="../assets/template/default/css/style.css?v=1">
  74. <script src="../assets/js/libs/modernizr.min.js"></script>
  75. <script src="../assets/js/libs/jquery.min.js"></script>
  76. <link rel="shortcut icon" href="../assets/template/default/favicon.ico">
  77. <link rel="apple-touch-icon" href="../assets/template/default/apple-touch-icon.png">
  78. <script type="text/javascript">
  79. function selectDatabaseSetup(field) {
  80. switch (field.value) {
  81. case 'sqlite':
  82. case 'sqlite3':
  83. $('#dbsqlite').show()
  84. $('#dbdatafull').hide();
  85. break;
  86. default:
  87. $('#dbsqlite').hide();
  88. $('#dbdatafull').show();
  89. break;
  90. }
  91. }
  92. </script>
  93. </head>
  94. <body>
  95. <!--[if lt IE 8 ]>
  96. <div class="internet-explorer-error">
  97. Do you know that your Internet Explorer is out of date?<br/>
  98. Please use Internet Explorer 8+, Mozilla Firefox 4+, Google Chrome, Apple Safari 5+ or Opera 11+
  99. </div>
  100. <![endif]-->
  101. <div class="navbar navbar-fixed-top">
  102. <div class="navbar-inner">
  103. <div class="container">
  104. <nav class="nav-collapse">
  105. <ul class="nav">
  106. <li><a target="_blank" href="http://www.phpmyfaq.de/documentation.php">Documentation</a></li>
  107. <li><a target="_blank" href="http://www.phpmyfaq.de/support.php">Support</a></li>
  108. <li><a target="_blank" href="http://forum.phpmyfaq.de/">Forums</a></li>
  109. <li><a target="_blank" href="http://faq.phpmyfaq.de/">FAQ</a></li>
  110. </ul>
  111. </nav>
  112. </div>
  113. </div>
  114. </div>
  115. <section id="main">
  116. <div class="container">
  117. <div class="row" style="padding-left: 20px;">
  118. <div class="hero-unit hello-phpmyfaq" style="text-align: center; height: 60px;">
  119. <h1>phpMyFAQ <?php print PMF_System::getVersion(); ?> Setup</h1>
  120. <p>
  121. Did you already read the <a style="color: #ffffff; text-decoration: underline;"
  122. href="http://www.phpmyfaq.de/documentation.php">documentation</a> carefully before starting the
  123. phpMyFAQ setup? :-)
  124. </p>
  125. </div>
  126. </div>
  127. <div class="row" style="padding-left: 20px;">
  128. <?php
  129. if (version_compare(PHP_VERSION, PMF_System::VERSION_MINIMUM_PHP, '<')) {
  130. printf('<p class="alert alert-error">Sorry, but you need PHP %s or later!</p>', PMF_System::VERSION_MINIMUM_PHP);
  131. HTMLFooter();
  132. die();
  133. }
  134. if (! function_exists('date_default_timezone_set')) {
  135. print '<p class="alert alert-error">Sorry, but setting a default timezone doesn\'t work in your environment!</p>';
  136. HTMLFooter();
  137. die();
  138. }
  139. if (! $system->checkDatabase()) {
  140. print '<p class="alert alert-error">No supported database detected! Please install one of the following' .
  141. ' database systems and enable the corresponding PHP extension in php.ini:</p>';
  142. print '<ul>';
  143. foreach ($system->getSupportedDatabases() as $database) {
  144. printf(' <li>%s</li>', $database[1]);
  145. }
  146. print '</ul>';
  147. HTMLFooter();
  148. die();
  149. }
  150. if (! $system->checkRequiredExtensions()) {
  151. print '<p class="alert alert-error">The following extensions are missing! Please enable the PHP extension(s) in ' .
  152. 'php.ini.</p>';
  153. print '<ul>';
  154. foreach ($system->getMissingExtensions() as $extension) {
  155. printf(' <li>ext/%s</li>', $extension);
  156. }
  157. print '</ul>';
  158. HTMLFooter();
  159. die();
  160. }
  161. if (! $system->checkphpMyFAQInstallation()) {
  162. print '<p class="alert alert-error">It seems you\'re already running a version of phpMyFAQ. Please use the ' .
  163. '<a href="update.php">update script</a>.</p>';
  164. HTMLFooter();
  165. die();
  166. }
  167. $dirs = array('/attachments', '/config', '/data', '/images');
  168. $faileddirs = $instanceSetup->checkDirs($dirs);
  169. if (sizeof($faileddirs)) {
  170. print '<p class="alert alert-error">The following directory/-ies could not be created or are not writable:</p><ul>';
  171. foreach ($faileddirs as $dir) {
  172. print "<li>$dir</li>\n";
  173. }
  174. print '</ul><p class="alert alert-error">Please create it/them manually and/or change access to chmod 755 (or ' .
  175. 'greater if necessary).</p>';
  176. HTMLFooter();
  177. die();
  178. }
  179. if (!isset($_POST["sql_server"]) && !isset($_POST["sql_user"]) && !isset($_POST["sql_db"])) {
  180. if ((@ini_get('safe_mode') == 'On' || @ini_get('safe_mode') === 1)) {
  181. print '<p class="alert alert-error">The PHP safe mode is enabled. You may have problems when phpMyFAQ tries to write ' .
  182. ' in some directories.</p>';
  183. }
  184. if (! extension_loaded('gd')) {
  185. print '<p class="alert alert-error">You don\'t have GD support enabled in your PHP installation. Please enable GD ' .
  186. 'support in your php.ini file otherwise you can\'t use Captchas for spam protection.</p>';
  187. }
  188. if (! function_exists('imagettftext')) {
  189. print '<p class="alert alert-error">You don\'t have Freetype support enabled in the GD extension of your PHP ' .
  190. 'installation. Please enable Freetype support in GD extension otherwise the Captchas for spam ' .
  191. 'protection will be quite easy to break.</p>';
  192. }
  193. if (! extension_loaded('curl') || ! extension_loaded('openssl')) {
  194. print '<p class="alert alert-error">You don\'t have cURL and/or OpenSSL support enabled in your PHP installation. ' .
  195. 'Please enable cURL and/or OpenSSL support in your php.ini file otherwise you can\'t use the Twitter ' .
  196. ' support.</p>';
  197. }
  198. ?>
  199. </div>
  200. <form class="form-horizontal" action="setup.php" method="post">
  201. <div class="row">
  202. <div class="span6">
  203. <fieldset>
  204. <legend>Add your database connection setup</legend>
  205. <div class="control-group">
  206. <label class="control-label" for="sql_type">Database server:</label>
  207. <div class="controls">
  208. <select name="sql_type" id="sql_type" size="1" onchange="selectDatabaseSetup(this);">
  209. <?php
  210. // check what extensions are loaded in PHP
  211. foreach ($system->getSupportedDatabases() as $extension => $database) {
  212. if (extension_loaded($extension) && version_compare(PHP_VERSION, $database[0]) >= 0) {
  213. // prevent MySQLi with zend.ze1_compatibility_mode enabled due to a few cloning isssues
  214. if (($extension == 'mysqli') && ini_get('zend.ze1_compatibility_mode')) {
  215. continue;
  216. }
  217. printf('<option value="%s">%s</option>', $extension, $database[1]);
  218. }
  219. }
  220. ?>
  221. </select>
  222. <p class="help-block">Please select your preferred database type.</p>
  223. </div>
  224. </div>
  225. <div id="dbdatafull">
  226. <div class="control-group">
  227. <label class="control-label" for="sql_server">Database hostname:</label>
  228. <div class="controls">
  229. <input type="text" name="sql_server" id="sql_server" />
  230. <p class="help-block">Please enter the host of your database server.</p>
  231. </div>
  232. </div>
  233. <div class="control-group">
  234. <label class="control-label" for="sql_user">Database user:</label>
  235. <div class="controls">
  236. <input type="text" name="sql_user" id="sql_user" />
  237. <p class="help-block">Please enter your database user.</p>
  238. </div>
  239. </div>
  240. <div class="control-group">
  241. <label class="control-label" for="sql_password">Database password:</label>
  242. <div class="controls">
  243. <input name="sql_passwort" type="password" id="sql_password" />
  244. <p class="help-block">Please enter your database password.</p>
  245. </div>
  246. </div>
  247. <div class="control-group">
  248. <label class="control-label" for="sql_db">Database name:</label>
  249. <div class="controls">
  250. <input type="text" name="sql_db" id="sql_db" />
  251. <p class="help-block">Please enter your database name.</p>
  252. </div>
  253. </div>
  254. </div>
  255. <div id="dbsqlite" class="hide">
  256. <div class="control-group">
  257. <label class="control-label" for="sql_sqlitefile">SQLite database file:</label>
  258. <div class="controls">
  259. <input type="text" name="sql_sqlitefile" id="sql_sqlitefile"
  260. value="<?php print dirname(__DIR__); ?>" />
  261. <p class="help-block">
  262. Please enter the full path to your SQLite datafile which should be outside your
  263. docroot.
  264. </p>
  265. </div>
  266. </div>
  267. </div>
  268. <div class="control-group">
  269. <label class="control-label" for="sqltblpre">Table prefix:</label>
  270. <div class="controls">
  271. <input type="text" name="sqltblpre" id="sqltblpre" />
  272. <p class="help-block">
  273. Please enter a table prefix here if you want to install more phpMyFAQ installations on
  274. one database.
  275. </p>
  276. </div>
  277. </div>
  278. </fieldset>
  279. </div>
  280. <?php if (extension_loaded('ldap')): ?>
  281. <div class="span6">
  282. <fieldset>
  283. <legend>Add your LDAP setup</legend>
  284. <div class="control-group">
  285. <label class="control-label" for="ldap_enabled">&nbsp;</label>
  286. <div class="controls">
  287. <label class="checkbox">
  288. <input id="ldap_enabled" type="checkbox" name="ldap_enabled" value="yes" />
  289. Enable LDAP support?
  290. </label>
  291. <p class="help-block">You can enable LDAP later if you like.</p>
  292. </div>
  293. </div>
  294. <div class="control-group">
  295. <label class="control-label" for="ldap_server">LDAP server host:</label>
  296. <div class="controls">
  297. <input type="text" name="ldap_server" id="ldap_server" />
  298. <p class="help-block">Please enter the host of your LDAP server.</p>
  299. </div>
  300. </div>
  301. <div class="control-group">
  302. <label class="control-label" for="ldap_port">LDAP server port:</label>
  303. <div class="controls">
  304. <input type="number" name="ldap_port" value="389" id="ldap_port" />
  305. <p class="help-block">Please enter the port of your LDAP server.</p>
  306. </div>
  307. </div>
  308. <div class="control-group">
  309. <label class="control-label" for="ldap_user">LDAP user DN:</label>
  310. <div class="controls">
  311. <input type="text" name="ldap_user" id="ldap_user" />
  312. <p class="help-block">Please enter your specified RDN username.</p>
  313. </div>
  314. </div>
  315. <div class="control-group">
  316. <label class="control-label" for="ldap_password">LDAP password:</label>
  317. <div class="controls">
  318. <input name="ldap_password" type="password" id="ldap_password" />
  319. <p class="help-block">Please enter your LDAP password.</p>
  320. </div>
  321. </div>
  322. <div class="control-group">
  323. <label class="control-label" for="ldap_base">LDAP base DN:</label>
  324. <div class="controls">
  325. <input type="text" name="ldap_base" id="ldap_base" />
  326. <p class="help-block">
  327. Please enter your distinguished name, e.g. 'cn=John Doe,ou=Accounts,o=My Company,c=US'.
  328. </p>
  329. </div>
  330. </div>
  331. <p class="alert alert-info">
  332. You can add additional LDAP configuration and more LDAP servers in the file
  333. config/constants_ldap.php.
  334. </p>
  335. </fieldset>
  336. </div>
  337. </div>
  338. <div class="row">
  339. <?php endif; ?>
  340. <div class="span6">
  341. <fieldset>
  342. <legend>Your phpMyFAQ setup</legend>
  343. <div class="control-group">
  344. <label class="control-label" for="language">Default language:</label>
  345. <div class="controls">
  346. <select name="language" size="1" id="language">
  347. <?php
  348. if ($dir = @opendir(PMF_ROOT_DIR . '/lang')) {
  349. while ($dat = @readdir($dir)) {
  350. if (substr($dat, -4) == '.php') {
  351. printf('<option value="%s"', $dat);
  352. if ($dat == "language_en.php") {
  353. print ' selected="selected"';
  354. }
  355. printf(
  356. '>%s</option>',
  357. $languageCodes[substr(strtoupper($dat), 9, 2)]
  358. );
  359. }
  360. }
  361. } else {
  362. print '<option>english</option>';
  363. }
  364. ?>
  365. </select>
  366. <p class="help-block">Please select your default language.</p>
  367. </div>
  368. </div>
  369. <div class="control-group">
  370. <label class="control-label" for="permLevel">Permission level:</label>
  371. <div class="controls">
  372. <select id="permLevel" name="permLevel" size="1" required="required">
  373. <option value="basic">Basic (no group support)</option>
  374. <option value="medium">Medium (with group support)</option>
  375. </select>
  376. <p class="help-block">
  377. Complexity of rights and permissions.
  378. </p>
  379. </div>
  380. </div>
  381. <div class="control-group">
  382. <label class="control-label" for="realname">Your name:</label>
  383. <div class="controls">
  384. <input type="text" name="realname" id="realname" required="required" />
  385. <p class="help-block">Please enter your real name.</p>
  386. </div>
  387. </div>
  388. <div class="control-group">
  389. <label class="control-label" for="email">Your email address:</label>
  390. <div class="controls">
  391. <input type="email" name="email" id="email" required="required" />
  392. <p class="help-block">Please enter your email adress.</p>
  393. </div>
  394. </div>
  395. <div class="control-group">
  396. <label class="control-label" for="loginname">Your login name:</label>
  397. <div class="controls">
  398. <input type="text" name="loginname" id="loginname" required="required" />
  399. <p class="help-block">Please enter your login name.</p>
  400. </div>
  401. </div>
  402. <div class="control-group">
  403. <label class="control-label" for="password">Your password:</label>
  404. <div class="controls">
  405. <input type="password" name="password" id="password" required="required" />
  406. <p class="help-block">Please enter your password.</p>
  407. </div>
  408. </div>
  409. <div class="control-group">
  410. <label class="control-label" for="password_retype">Retype password:</label>
  411. <div class="controls">
  412. <input type="password" name="password_retyped" id="password_retype" required="required" />
  413. <p class="help-block">Please retype your password.</p>
  414. </div>
  415. </div>
  416. </fieldset>
  417. </div>
  418. </div>
  419. <div class="row" style="padding-left: 20px; text-align: center;">
  420. <p class="alert alert-danger">
  421. Dude, this is an early alpha version. Please don't install this version on production!
  422. </p>
  423. <input class="btn-primary btn-large" type="submit"
  424. value="Click to install phpMyFAQ <?php print PMF_System::getVersion(); ?>" />
  425. </div>
  426. <div class="row" style="padding-left: 20px;">
  427. <p class="alert alert-info" style="margin-top: 20px;">
  428. Your password will be saved with a <strong><?php print PMF_ENCRYPTION_TYPE; ?></strong>
  429. encryption. You can change the encryption type for passwords in <em>config/constants.php</em>.
  430. </p>
  431. </div>
  432. </form>
  433. <?php
  434. HTMLFooter();
  435. } else {
  436. $dbSetup = array();
  437. // Check table prefix
  438. $dbSetup['dbPrefix'] = $sqltblpre = PMF_Filter::filterInput(INPUT_POST, 'sqltblpre', FILTER_SANITIZE_STRING, '');
  439. if (!defined('SQLPREFIX')) {
  440. define('SQLPREFIX', $dbSetup['dbPrefix']);
  441. }
  442. // Check database entries
  443. $dbSetup['dbType'] = PMF_Filter::filterInput(INPUT_POST, 'sql_type', FILTER_SANITIZE_STRING);
  444. if (!is_null($dbSetup['dbType'])) {
  445. $dbSetup['dbType'] = trim($dbSetup['dbType']);
  446. if (! file_exists(PMF_ROOT_DIR . '/install/' . $dbSetup['dbType'] . '.sql.php')) {
  447. printf(
  448. '<p class="alert alert-error"><strong>Error:</strong> Invalid server type: %s</p>',
  449. $dbSetup['dbType']
  450. );
  451. HTMLFooter();
  452. die();
  453. }
  454. } else {
  455. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please select a database type.</p>\n";
  456. HTMLFooter();
  457. die();
  458. }
  459. $dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_server', FILTER_SANITIZE_STRING);
  460. if (is_null($dbSetup['dbServer']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
  461. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database server.</p>\n";
  462. HTMLFooter();
  463. die();
  464. }
  465. $dbSetup['dbUser'] = PMF_Filter::filterInput(INPUT_POST, 'sql_user', FILTER_SANITIZE_STRING);
  466. if (is_null($dbSetup['dbUser']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
  467. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database username.</p>\n";
  468. HTMLFooter();
  469. die();
  470. }
  471. $dbSetup['dbPassword'] = PMF_Filter::filterInput(INPUT_POST, 'sql_passwort', FILTER_UNSAFE_RAW);
  472. if (is_null($dbSetup['dbPassword']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
  473. // Password can be empty...
  474. $dbSetup['dbPassword'] = '';
  475. }
  476. $dbSetup['dbDatabaseName'] = PMF_Filter::filterInput(INPUT_POST, 'sql_db', FILTER_SANITIZE_STRING);
  477. if (is_null($dbSetup['dbDatabaseName']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
  478. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database name.</p>\n";
  479. HTMLFooter();
  480. die();
  481. }
  482. if (PMF_System::isSqlite($dbSetup['dbType'])) {
  483. $dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_sqlitefile', FILTER_SANITIZE_STRING);
  484. if (is_null($dbSetup['dbServer'])) {
  485. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a SQLite database filename.</p>\n";
  486. HTMLFooter();
  487. die();
  488. }
  489. }
  490. // check database connection
  491. require PMF_ROOT_DIR . "/inc/Db.php";
  492. require PMF_ROOT_DIR . "/inc/DB/Driver.php";
  493. $db = PMF_Db::factory($dbSetup['dbType']);
  494. $db->connect($dbSetup['dbServer'], $dbSetup['dbUser'], $dbSetup['dbPassword'], $dbSetup['dbDatabaseName']);
  495. if (!$db) {
  496. printf("<p class=\"alert alert-error\"><strong>DB Error:</strong> %s</p>\n", $db->error());
  497. HTMLFooter();
  498. die();
  499. }
  500. $configuration = new PMF_Configuration($db);
  501. // check LDAP if available
  502. $ldapEnabled = PMF_Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_STRING);
  503. if (extension_loaded('ldap') && !is_null($ldapEnabled)) {
  504. $ldapSetup = array();
  505. // check LDAP entries
  506. $ldapSetup['ldapServer'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_STRING);
  507. if (is_null($ldapSetup['ldapServer'])) {
  508. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP server.</p>\n";
  509. HTMLFooter();
  510. die();
  511. }
  512. $ldapSetup['ldapPort'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_port', FILTER_VALIDATE_INT);
  513. if (is_null($ldapSetup['ldapPort'])) {
  514. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP port.</p>\n";
  515. HTMLFooter();
  516. die();
  517. }
  518. $ldapSetup['ldapBase'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_base', FILTER_SANITIZE_STRING);
  519. if (is_null($ldapSetup['ldapBase'])) {
  520. print "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP base search DN.</p>\n";
  521. HTMLFooter();
  522. die();
  523. }
  524. // LDAP User and LDAP password are optional
  525. $ldapSetup['ldapUser'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_user', FILTER_SANITIZE_STRING, '');
  526. $ldapSetup['ldapPassword'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_password', FILTER_SANITIZE_STRING, '');
  527. // check LDAP connection
  528. require PMF_ROOT_DIR . "/inc/Ldap.php";
  529. $ldap = new PMF_Ldap($configuration);
  530. $ldap->connect(
  531. $ldapSetup['ldapServer'],
  532. $ldapSetup['ldapPort'],
  533. $ldapSetup['ldapBase'],
  534. $ldapSetup['ldapUser'],
  535. $ldapSetup['ldapPassword']
  536. );
  537. if (!$ldap) {
  538. print "<p class=\"alert alert-error\"><strong>LDAP Error:</strong> " . $ldap->error() . "</p>\n";
  539. HTMLFooter();
  540. die();
  541. }
  542. }
  543. // check loginname
  544. $loginname = PMF_Filter::filterInput(INPUT_POST, 'loginname', FILTER_SANITIZE_STRING);
  545. if (is_null($loginname)) {
  546. print '<p class="alert alert-error"><strong>Error:</strong> Please add a loginname for your account.</p>';
  547. HTMLFooter();
  548. die();
  549. }
  550. // check user entries
  551. $password = PMF_Filter::filterInput(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
  552. if (is_null($password)) {
  553. print '<p class="alert alert-error"><strong>Error:</strong> Please add a password for the your account.</p>';
  554. HTMLFooter();
  555. die();
  556. }
  557. $password_retyped = PMF_Filter::filterInput(INPUT_POST, 'password_retyped', FILTER_SANITIZE_STRING);
  558. if (is_null($password_retyped)) {
  559. print '<p class="alert alert-error"><strong>Error:</strong> Please add a retyped password.</p>';
  560. HTMLFooter();
  561. die();
  562. }
  563. if (strlen($password) <= 5 || strlen($password_retyped) <= 5) {
  564. print '<p class="alert alert-error"><strong>Error:</strong> Your password and retyped password are too short.' .
  565. ' Please set your password and your retyped password with a minimum of 6 characters.</p>';
  566. HTMLFooter();
  567. die();
  568. }
  569. if ($password != $password_retyped) {
  570. print '<p class="alert alert-error"><strong>Error:</strong> Your password and retyped password are not equal.' .
  571. ' Please check your password and your retyped password.</p>';
  572. HTMLFooter();
  573. die();
  574. }
  575. $language = PMF_Filter::filterInput(INPUT_POST, 'language', FILTER_SANITIZE_STRING, 'en');
  576. $realname = PMF_Filter::filterInput(INPUT_POST, 'realname', FILTER_SANITIZE_STRING, '');
  577. $email = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL, '');
  578. $permLevel = PMF_Filter::filterInput(INPUT_POST, 'permLevel', FILTER_SANITIZE_STRING, 'basic');
  579. // Write the DB variables in database.php
  580. if (! $instanceSetup->createDatabaseFile($dbSetup)) {
  581. print "<p class=\"alert alert-error\"><strong>Error:</strong> Setup cannot write to ./config/database.php.</p>";
  582. HTMLFooter();
  583. $system->cleanInstallation();
  584. die();
  585. }
  586. // check LDAP if available
  587. if (extension_loaded('ldap') && !is_null($ldapEnabled)) {
  588. if (! $instanceSetup->createLdapFile($ldapSetup)) {
  589. print "<p class=\"alert alert-error\"><strong>Error:</strong> Setup cannot write to ./config/ldap.php.</p>";
  590. HTMLFooter();
  591. $system->cleanInstallation();
  592. die();
  593. }
  594. }
  595. // connect to the database using config/database.php
  596. require PMF_ROOT_DIR . '/config/database.php';
  597. $db = PMF_Db::factory($dbSetup['dbType']);
  598. $db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']);
  599. if (!$db) {
  600. print "<p class=\"alert alert-error\"><strong>DB Error:</strong> ".$db->error()."</p>\n";
  601. HTMLFooter();
  602. $system->cleanInstallation();
  603. die();
  604. }
  605. require $dbSetup['dbType'] . '.sql.php'; // CREATE TABLES
  606. require 'stopwords.sql.php'; // INSERTs for stopwords
  607. $system->setDatabase($db);
  608. print '<p>';
  609. // Erase any table before starting creating the required ones
  610. if (! PMF_System::isSqlite($dbSetup['dbType'])) {
  611. $system->dropTables($uninst);
  612. }
  613. // Start creating the required tables
  614. $count = 0;
  615. foreach ($query as $executeQuery) {
  616. $result = @$db->query($executeQuery);
  617. if (!$result) {
  618. print '<p class="alert alert-error"><strong>Error:</strong> Please install your version of phpMyFAQ once again or send
  619. us a <a href=\"http://www.phpmyfaq.de\" target=\"_blank\">bug report</a>.</p>';
  620. printf('<p class="alert alert-error"><strong>DB error:</strong> %s</p>', $db->error());
  621. printf('<code>%s</code>', htmlentities($executeQuery));
  622. $system->dropTables($uninst);
  623. $system->cleanInstallation();
  624. HTMLFooter();
  625. die();
  626. }
  627. usleep(2500);
  628. $count++;
  629. if (!($count % 10)) {
  630. print '| ';
  631. }
  632. }
  633. $link = new PMF_Link(null, $configuration);
  634. // add main configuration, add personal settings
  635. include 'configurationdata.php';
  636. $mainConfig['spam.enableCaptchaCode'] = (extension_loaded('gd') ? 'true' : 'false');
  637. $mainConfig['main.metaPublisher'] = $realname;
  638. $mainConfig['main.administrationMail'] = $email;
  639. $mainConfig['main.currentVersion'] = PMF_System::getVersion();
  640. $mainConfig['main.currentApiVersion'] = PMF_System::getApiVersion();
  641. $mainConfig['main.language'] = $language;
  642. $mainConfig['main.languageDetection'] = 'true';
  643. $mainConfig['main.phpMyFAQToken'] = md5(uniqid(rand()));
  644. $mainConfig['security.permLevel'] = $permLevel;
  645. foreach ($mainConfig as $name => $value) {
  646. $configuration->add($name, $value);
  647. }
  648. $configuration->update(array('main.referenceURL' => $link->getSystemUri('/install/setup.php')));
  649. // add admin account and rights
  650. $admin = new PMF_User($configuration);
  651. $admin->createUser($loginname, $password, 1);
  652. $admin->setStatus('protected');
  653. $adminData = array(
  654. 'display_name' => $realname,
  655. 'email' => $email
  656. );
  657. $admin->setUserData($adminData);
  658. // add default rights
  659. include 'rightdata.php';
  660. foreach ($mainRights as $right) {
  661. $rightId = $admin->perm->addRight($right);
  662. $admin->perm->grantUserRight($admin->getUserId(), $rightId);
  663. }
  664. // Add anonymous user account
  665. $anonymous = new PMF_User($configuration);
  666. $anonymous->createUser('anonymous', null, -1);
  667. $anonymous->setStatus('protected');
  668. $anonymousData = array(
  669. 'display_name' => 'Anonymous User',
  670. 'email' => null
  671. );
  672. $anonymous->setUserData($anonymousData);
  673. // Add master instance
  674. $instanceData = array(
  675. 'url' => $link->getSystemUri($_SERVER['SCRIPT_NAME']),
  676. 'instance' => $link->getSystemRelativeUri('install/setup.php'),
  677. 'comment' => 'phpMyFAQ ' . PMF_System::getVersion()
  678. );
  679. $faqInstance = new PMF_Instance($configuration);
  680. $faqInstance->addInstance($instanceData);
  681. $faqInstanceMaster = new PMF_Instance_Master($configuration);
  682. $faqInstanceMaster->createMaster($faqInstance);
  683. print '</p>';
  684. ?>
  685. <p class="alert alert-success">
  686. Wow, looks like the installation worked like a charm. This is pretty cool, isn't it? :-)
  687. </p>
  688. <script type="text/javascript">
  689. //<![CDATA[
  690. var iframect = 0;
  691. function iframeUpdated() {
  692. if (iframect++ == 0) {
  693. return;
  694. }
  695. $('#questionnaireForm').hide();
  696. $('#questionnaireThanks').show();
  697. }
  698. function hide(item) {
  699. $('#configliste').hide();
  700. }
  701. function show(item) {
  702. $('#configliste').show();
  703. }
  704. //]]>
  705. </script>
  706. <iframe onload="iframeUpdated();" name="questionaireResult" style="display:none"></iframe>
  707. <form action="http://www.phpmyfaq.de/stats/getstatdata.php" method="post" target="questionaireResult"
  708. id="questionnaireForm" class="form-horizontal">
  709. <p>
  710. For further development we would like to get some feedback from our users. Therefore we'd ask you to
  711. take a few minutes of your time to answer a few questions.
  712. </p>
  713. <p>
  714. If you don't want to participate in the survey, you can directly visit
  715. <a href="../index.php">your version of phpMyFAQ</a> or login into your
  716. <a href="../admin/index.php">admin section</a>.
  717. </p>
  718. <fieldset>
  719. <legend>General questions</legend>
  720. <div class="control-group">
  721. <label class="control-label">How do you act like?</label>
  722. <div class="controls">
  723. <select name="q[individual]">
  724. <option>as an individual</option>
  725. <option>as an organisation</option>
  726. </select>
  727. </div>
  728. </div>
  729. <div class="control-group">
  730. <label class="control-label">What kind of organisation is that?</label>
  731. <div class="controls">
  732. <select name="q[organisation]">
  733. <option>private held</option>
  734. <option>public held</option>
  735. <option>government organisation</option>
  736. <option>foundation</option>
  737. <option>other</option>
  738. </select>
  739. </div>
  740. </div>
  741. </fieldset>
  742. <fieldset>
  743. <legend>Technical questions</legend>
  744. <div class="control-group">
  745. <label class="control-label">Where did you installed phpMyFAQ?</label>
  746. <div class="controls">
  747. <select name="q[server]">
  748. <option>server run by a hosting company</option>
  749. <option>public server run by you/your organisation</option>
  750. <option>private server run by you/your organisation</option>
  751. <option>Don't know</option>
  752. </select>
  753. </div>
  754. </div>
  755. </fieldset>
  756. <fieldset>
  757. <legend>Beyond our own nose</legend>
  758. <div class="control-group">
  759. <label class="control-label">Which PHP software do you also use?</label>
  760. <div class="controls">
  761. <input name="q[other]" />
  762. </div>
  763. </div>
  764. <div class="control-group">
  765. <label class="control-label">Are you using other web technologies?</label>
  766. <div class="controls">
  767. <label class="checkbox inline">
  768. <input type="checkbox" name="q[other][]" value="ASP" />ASP
  769. </label>
  770. <label class="checkbox inline">
  771. <input type="checkbox" name="q[other][]" value="ASP.NET" />ASP.NET
  772. </label>
  773. <label class="checkbox inline">
  774. <input type="checkbox" name="q[other][]" value="jsp" />JAVA JSP
  775. </label>
  776. <label class="checkbox inline">
  777. <input type="checkbox" name="q[other][]" value="perl" />Perl
  778. </label>
  779. <label class="checkbox inline">
  780. <input type="checkbox" name="q[other][]" value="ruby" />Ruby / Ruby on Rails
  781. </label>
  782. <label class="checkbox inline">
  783. <input type="checkbox" name="q[other][]" value="python" />Python
  784. </label>
  785. <label class="checkbox inline">
  786. <input type="checkbox" name="q[other][]" value="clojure" />Clojure
  787. </label>
  788. <label class="checkbox inline">
  789. <input type="checkbox" name="q[other][]" value="scala" />Scala
  790. </label>
  791. <label class="checkbox inline">
  792. <input type="checkbox" name="q[other][]" value="go" />Go
  793. </label>
  794. </div>
  795. </div>
  796. </fieldset>
  797. <p class="alert alert-info">
  798. Additional to your input we're going to submit some information about your system setup for statstic
  799. purpose.
  800. </p>
  801. <p class="alert alert-info">
  802. We are not storing any personal information. You can see the data by clicking
  803. <a href="#" onclick="show('configliste'); return false;">here</a>.
  804. </p>
  805. <div id="configliste" class="hide">
  806. <a href="#" onclick="hide('configliste'); return false;">hide again</a>
  807. <dl>
  808. <?php
  809. $q = new PMF_Questionnaire_Data($mainConfig);
  810. $options = $q->get();
  811. array_walk($options, 'data_printer');
  812. echo '</dl><input type="hidden" name="systemdata" value="'.PMF_String::htmlspecialchars(serialize($q->get()), ENT_QUOTES).'" />';
  813. ?>
  814. </div>
  815. <p style="text-align: center;">
  816. <input class="btn-primary" type="submit" value="Click here to submit the data and finish the installation process" />
  817. </p>
  818. </form>
  819. <div id="questionnaireThanks" style="display:none;">
  820. <p class="alert alert-success"><b>Thank you for giving your feedback!</b></p>
  821. <p>
  822. You can visit <a href="../index.php">your version of phpMyFAQ</a> or login into your
  823. <a href="../admin/index.php">admin section</a>.
  824. </p>
  825. </div>
  826. <?php
  827. // Remove 'setup.php' file
  828. if (@unlink(basename($_SERVER['SCRIPT_NAME']))) {
  829. print "<p class=\"alert alert-success\">The file <em>./install/setup.php</em> was deleted automatically.</p>\n";
  830. } else {
  831. print "<p class=\"alert alert-info\">Please delete the file <em>./install/setup.php</em> manually.</p>\n";
  832. }
  833. // Remove 'update.php' file
  834. if (@unlink(dirname($_SERVER["PATH_TRANSLATED"])."/update.php")) {
  835. print "<p class=\"alert alert-success\">The file <em>./install/update.php</em> was deleted automatically.</p>\n";
  836. } else {
  837. print "<p class=\"alert alert-info\">Please delete the file <em>./install/update.php</em> manually.</p>\n";
  838. }
  839. HTMLFooter();
  840. }