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

/phpmyfaq/install/setup.php

https://github.com/max-koehler/phpMyFAQ
PHP | 1023 lines | 871 code | 72 blank | 80 comment | 69 complexity | 9f1ac39f5bb3f72a3e8ccf9ef687b2e8 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
  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.2
  9. *
  10. * The contents of this file are subject to the Mozilla Public License
  11. * Version 1.1 (the "License"); you may not use this file except in
  12. * compliance with the License. You may obtain a copy of the License at
  13. * http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS IS"
  16. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  17. * License for the specific language governing rights and limitations
  18. * under the License.
  19. *
  20. * @category phpMyFAQ
  21. * @package Setup
  22. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  23. * @author Tom Rochester <tom.rochester@gmail.com>
  24. * @author Johannes Schlueter <johannes@php.net>
  25. * @author Uwe Pries <uwe.pries@digartis.de>
  26. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  27. * @copyright 2002-2010 phpMyFAQ Team
  28. * @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
  29. * @link http://www.phpmyfaq.de
  30. * @since 2002-08-20
  31. */
  32. define('VERSION', '2.7.0-alpha');
  33. define('APIVERSION', 2);
  34. define('COPYRIGHT', '&copy; 2001-2010 <a href="http://www.phpmyfaq.de/">phpMyFAQ Team</a> | All rights reserved.');
  35. define('SAFEMODE', @ini_get('safe_mode'));
  36. define('PMF_ROOT_DIR', dirname(dirname(__FILE__)));
  37. if (SAFEMODE) {
  38. set_time_limit(0);
  39. }
  40. require PMF_ROOT_DIR . '/config/constants.php';
  41. require PMF_ROOT_DIR . '/inc/autoLoader.php';
  42. require PMF_ROOT_DIR . '/inc/functions.php';
  43. //
  44. // Initalizing static string wrapper
  45. //
  46. PMF_String::init('en');
  47. $query = $uninst = array();
  48. // permission levels
  49. $permLevels = array(
  50. 'basic' => 'Basic (no group support)',
  51. 'medium' => 'Medium (with group support)');
  52. $enabledExtensions = array(
  53. 'dom',
  54. 'gd',
  55. 'json',
  56. 'xmlwriter',
  57. 'filter');
  58. /**
  59. * Executes the uninstall set of queries
  60. *
  61. * @return void
  62. * @access public
  63. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  64. */
  65. function db_uninstall()
  66. {
  67. global $uninst, $db;
  68. while ($each_query = each($uninst)) {
  69. $db->query($each_query[1]);
  70. }
  71. }
  72. /**
  73. * Print out the XHTML Footer
  74. *
  75. * @return void
  76. * @access public
  77. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  78. */
  79. function HTMLFooter()
  80. {
  81. printf('<p class="center">%s</p></body></html>', COPYRIGHT);
  82. }
  83. /**
  84. * Removes the data.php and the dataldap.php if an installation failed
  85. *
  86. * @return void
  87. * @access public
  88. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  89. */
  90. function cleanInstallation()
  91. {
  92. // Remove 'database.php' file: no need of prompt anything to the user
  93. if (file_exists(PMF_ROOT_DIR.'/config/database.php')) {
  94. @unlink(PMF_ROOT_DIR.'/config/database.php');
  95. }
  96. // Remove 'dataldap.php' file: no need of prompt anything to the user
  97. if (file_exists(PMF_ROOT_DIR.'/config/ldap.php')) {
  98. @unlink(PMF_ROOT_DIR.'/config/ldap.php');
  99. }
  100. }
  101. /**
  102. * Output the data as an HTML Definition List.
  103. *
  104. * @param mixed $value Value
  105. * @param string $key Key
  106. * @param string $ident Identian
  107. *
  108. * @return void
  109. */
  110. function data_printer($value, $key, $ident = "\n\t")
  111. {
  112. echo $ident, '<dt>', htmlentities($key), '</dt>', $ident, "\t", '<dd>';
  113. if (is_array($value)) {
  114. echo '<dl>';
  115. array_walk($value, 'data_printer', $ident."\t");
  116. echo $ident, "\t", '</dl>';
  117. } else {
  118. echo htmlentities($value);
  119. }
  120. echo '</dd>';
  121. }
  122. ?>
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
  124. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  125. <head>
  126. <title>phpMyFAQ <?php print VERSION; ?> Setup</title>
  127. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
  128. <link rel="shortcut icon" href="../template/default/favicon.ico" type="image/x-icon" />
  129. <link rel="icon" href="../template/default/favicon.ico" type="image/x-icon" />
  130. <script language="javascript" type="text/javascript">
  131. /*<![CDATA[*/
  132. // <!--
  133. function cssAddClass(ele, className) {
  134. if (typeof ele == 'string') {
  135. ele = document.getElementById(ele);
  136. }
  137. ele.className += ' ' + className;
  138. }
  139. function cssDelClass(ele, className) {
  140. if (typeof ele == 'string') {
  141. ele = document.getElementById(ele);
  142. }
  143. var regexp = new RegExp(
  144. '^'+className+'\\b\\s*|\\s*\\b'+className+'\\b', 'ig'
  145. );
  146. ele.className = ele.className.replace(regexp, '');
  147. }
  148. function select_database(field) {
  149. switch (field.value) {
  150. case 'sqlite':
  151. cssDelClass('dbsqlite', 'collapsed');
  152. cssAddClass('dbdatafull', 'collapsed');
  153. break;
  154. default:
  155. cssAddClass('dbsqlite', 'collapsed');
  156. cssDelClass('dbdatafull', 'collapsed');
  157. break;
  158. }
  159. }
  160. // -->
  161. /*]]>*/
  162. </script>
  163. <style media="screen" type="text/css">@import url(style/setup.css);</style>
  164. </head>
  165. <body>
  166. <h1 id="header">phpMyFAQ <?php print VERSION; ?> Setup</h1>
  167. <?php
  168. $system = new PMF_System();
  169. if (version_compare(PHP_VERSION, '5.2.0', '<')) {
  170. print "<p class=\"center\">You need PHP 5.2.0 or later!</p>\n";
  171. HTMLFooter();
  172. die();
  173. }
  174. if (!$system->checkDatabase($supported_databases)) {
  175. print '<p class="center">No supported database detected! Please install one of the following' .
  176. ' database systems and enable the corresponding PHP extension:</p>';
  177. print '<ul>';
  178. foreach ($supported_databases as $database) {
  179. printf(' <li>%s</li>', $database[1]);
  180. }
  181. print '</ul>';
  182. HTMLFooter();
  183. die();
  184. }
  185. $missing = array();
  186. if (!$system->checkExtension($enabledExtensions)) {
  187. print "<p class=\"center\">The following extensions are missing! Please enable the PHP extension:</p>\n";
  188. print "<ul>\n";
  189. foreach ($system->getMissingExtensions() as $extension) {
  190. printf(' <li>ext/%s</li>', $extension);
  191. }
  192. print "</ul>\n";
  193. HTMLFooter();
  194. die();
  195. }
  196. if (!$system->checkphpMyFAQInstallation()) {
  197. print '<p class="center">It seems you\'re already running a version of phpMyFAQ.<br />Please use the <a href="update.php">update script</a>.</p>';
  198. HTMLFooter();
  199. die();
  200. }
  201. $dirs = array('/attachments', '/config', '/data');
  202. $faileddirs = array();
  203. foreach ($dirs as $dir) {
  204. if (!@is_dir(PMF_ROOT_DIR . $dir)) {
  205. if (!@mkdir (PMF_ROOT_DIR . $dir, 0755)) {
  206. $faileddirs[] = $dir;
  207. }
  208. } else if (!@is_writable(PMF_ROOT_DIR . $dir)) {
  209. $faileddirs[] = $dir;
  210. } else {
  211. @copy('index.html', PMF_ROOT_DIR . $dir . '/index.html');
  212. }
  213. }
  214. if (sizeof($faileddirs)) {
  215. print '<p class="center">The following directory/-ies could not be created or are not writable:</p><ul>';
  216. foreach ($faileddirs as $dir) {
  217. print "<li>$dir</li>\n";
  218. }
  219. print '</ul><p class="center">Please create it manually and/or change access to chmod 755 (or greater if necessary).</p>';
  220. HTMLFooter();
  221. die();
  222. }
  223. if (!isset($_POST["sql_server"]) && !isset($_POST["sql_user"]) && !isset($_POST["sql_db"])) {
  224. ?>
  225. <p class="center">Your PHP version: <strong>PHP <?php print PHP_VERSION; ?></strong></p>
  226. <?php
  227. if (SAFEMODE == 1) {
  228. print '<p class="center">The PHP safe mode is enabled. You may have problems when phpMyFAQ writes in some ' .
  229. 'directories.</p>';
  230. }
  231. if (!extension_loaded('gd')) {
  232. print '<p class="center">You don\'t have GD support enabled in your PHP installation. Please enabled GD ' .
  233. 'support in your php.ini file otherwise you can\'t use Captchas for spam protection.</p>';
  234. }
  235. if (!function_exists('imagettftext')) {
  236. print '<p class="center">You don\'t have Freetype support enabled in the GD extension of your PHP ' .
  237. 'installation. Please enabled Freetype support in GD extension otherwise the Captchas for spam protection ' .
  238. 'will be quite easy to break.</p>';
  239. }
  240. ?>
  241. <p class="center">
  242. Did you already read the <a href="../docs/documentation.en.html">documentation</a> carefully before
  243. starting the phpMyFAQ setup?</p>
  244. <form action="setup.php" method="post">
  245. <fieldset class="installation">
  246. <legend class="installation">Please add your database connection setup information</legend>
  247. <label class="left">SQL server:</label>
  248. <select class="input" name="sql_type" id="sql_selector" size="1" onchange="select_database(this);">
  249. <?php
  250. // check what extensions are loaded in PHP
  251. foreach ($supported_databases as $extension => $database) {
  252. if (extension_loaded($extension) && version_compare(PHP_VERSION, $database[0]) >= 0) {
  253. // prevent MySQLi with zend.ze1_compatibility_mode enabled due to a few cloning isssues
  254. if (($extension == 'mysqli') && ini_get('zend.ze1_compatibility_mode')) {
  255. continue;
  256. }
  257. printf('<option value="%s">%s</option>', $extension, $database[1]);
  258. }
  259. }
  260. ?>
  261. </select><br />
  262. <div id="dbdatafull">
  263. <label class="left">SQL server host:</label>
  264. <input class="input" type="text" name="sql_server" title="Please enter the host of your SQL server here." /><br />
  265. <label class="left">SQL username:</label>
  266. <input class="input" type="text" name="sql_user" title="Please enter your SQL username here." /><br />
  267. <label class="left">SQL password:</label>
  268. <input class="input" name="sql_passwort" type="password" title="Please enter your SQL password here." /><br />
  269. <label class="left">SQL database:</label>
  270. <input class="input" type="text" name="sql_db" title="Please enter your SQL database name here." /><br />
  271. </div>
  272. <div id="dbsqlite" class="collapsed">
  273. <label class="left">SQLite database file:</label>
  274. <input class="input" type="text" name="sql_sqlitefile" value="<?php print dirname(dirname(__FILE__)); ?>" title="Please enter the full path to your SQLite datafile which should be outside your documentation root." /><br />
  275. </div>
  276. <label class="left">Table prefix:</label>
  277. <input class="input" type="text" name="sqltblpre" title="Please enter a table prefix here if you want to install more phpMyFAQ installations on one database." />
  278. </fieldset>
  279. <script language="javascript" type="text/javascript">
  280. obj = document.getElementById("sql_selector");
  281. if (obj.options.length > obj.selectedIndex) {
  282. select_database(obj.options[obj.selectedIndex]);
  283. }
  284. </script>
  285. <br />
  286. <?php
  287. if (extension_loaded('ldap')) {
  288. ?>
  289. <fieldset class="installation">
  290. <legend class="installation">LDAP information</legend>
  291. <label class="left">Enable LDAP support?</label>
  292. <input class="checkbox" type="checkbox" name="ldap_enabled" value="yes" /><br />
  293. <label class="left">LDAP server host:</label>
  294. <input class="input" type="text" name="ldap_server" title="Please enter the host of your LDAP server here." /><br />
  295. <label class="left">LDAP server port:</label>
  296. <input class="input" type="text" name="ldap_port" value="389" title="Please enter the port of your LDAP server here." /><br />
  297. <label class="left">LDAP username:</label>
  298. <input class="input" type="text" name="ldap_user" title="Please enter your specified RDN username here." /><br />
  299. <label class="left">LDAP password:</label>
  300. <input class="input" name="ldap_password" type="password" title="Please enter your LDAP password here." /><br />
  301. <label class="left">Distinguished name (dn):</label>
  302. <input class="input" type="text" name="ldap_base" title="Please enter your distinguished name, e.g. 'cn=John Smith,ou=Accounts,o=My Company,c=US' here." />
  303. </fieldset>
  304. <br />
  305. <?php
  306. }
  307. ?>
  308. <fieldset class="installation">
  309. <legend class="installation">phpMyFAQ information</legend>
  310. <label class="left">Default language:</label>
  311. <select class="input" name="language" size="1" title="Please select your default language.">
  312. <?php
  313. if ($dir = @opendir(PMF_ROOT_DIR . '/lang')) {
  314. while ($dat = @readdir($dir)) {
  315. if (substr($dat, -4) == '.php') {
  316. printf('<option value="%s"', $dat);
  317. if ($dat == "language_en.php") {
  318. print ' selected="selected"';
  319. }
  320. print '>' . $languageCodes[substr(strtoupper($dat), 9, 2)] . '</option>';
  321. }
  322. }
  323. } else {
  324. print '<option>english</option>';
  325. }
  326. ?>
  327. </select><br />
  328. <label class="left">Permission level:</label>
  329. <select class="input" name="permLevel" size="1" title="Complexity of user and right administration. Basic: users may have user-rights. Medium: users may have user-rights; group administration; groups may have group-rights; user have group-rights via group-memberships.">
  330. <?php
  331. foreach ($permLevels as $level => $desc) {
  332. printf(' <option value="%s">%s</option>', $level, $desc);
  333. }
  334. ?>
  335. </select><br />
  336. <label class="left">Admin's real name:</label>
  337. <input class="input" type="text" name="realname" title="Please enter your real name here." /><br />
  338. <label class="left">Admin's e-mail address:</label>
  339. <input class="input" type="text" name="email" title="Please enter your email adress here." /><br />
  340. <label class="left">Admin's username:</label>
  341. <input class="input" type="text" name="username" title="You don't have to do anything here." value="admin" readonly="readonly" /><br />
  342. <label class="left">Admin's password:</label>
  343. <input class="input" type="password" name="password" title="Please enter your password for the admin area." /><br />
  344. <label class="left">Retype password:</label>
  345. <input class="input" type="password" name="password_retyped" title="Please retype your password for checkup." /><br />
  346. </fieldset>
  347. <p class="center"><strong>Do not use it if you're already running a version of phpMyFAQ!</strong></p>
  348. <p class="center"><input type="submit" value="Click to install phpMyFAQ <?php print VERSION; ?>" class="button" /></p>
  349. </form>
  350. <?php
  351. HTMLFooter();
  352. } else {
  353. // Ckeck table prefix
  354. $sqltblpre = PMF_Filter::filterInput(INPUT_POST, 'sqltblpre', FILTER_SANITIZE_STRING, '');
  355. if (!defined('SQLPREFIX')) {
  356. define('SQLPREFIX', $sqltblpre);
  357. }
  358. // check database entries
  359. $sql_type = PMF_Filter::filterInput(INPUT_POST, 'sql_type', FILTER_SANITIZE_STRING);
  360. if (!is_null($sql_type)) {
  361. $sql_type = trim($sql_type);
  362. if (file_exists(PMF_ROOT_DIR . '/install/' . $sql_type . '.sql.php')) {
  363. require PMF_ROOT_DIR . '/install/' . $sql_type . '.sql.php';
  364. } else {
  365. print '<p class="error"><strong>Error:</strong> Invalid server type.</p>';
  366. HTMLFooter();
  367. die();
  368. }
  369. } else {
  370. print "<p class=\"error\"><strong>Error:</strong> There's no DB server input.</p>\n";
  371. HTMLFooter();
  372. die();
  373. }
  374. $sql_server = PMF_Filter::filterInput(INPUT_POST, 'sql_server', FILTER_SANITIZE_STRING);
  375. if (is_null($sql_server) && $sql_type != 'sqlite') {
  376. print "<p class=\"error\"><strong>Error:</strong> There's no DB server input.</p>\n";
  377. HTMLFooter();
  378. die();
  379. }
  380. $sql_user = PMF_Filter::filterInput(INPUT_POST, 'sql_user', FILTER_SANITIZE_STRING);
  381. if (is_null($sql_user) && $sql_type != 'sqlite') {
  382. print "<p class=\"error\"><strong>Error:</strong> There's no DB username input.</p>\n";
  383. HTMLFooter();
  384. die();
  385. }
  386. $sql_passwort = PMF_Filter::filterInput(INPUT_POST, 'sql_passwort', FILTER_SANITIZE_STRING);
  387. if (is_null($sql_passwort) && $sql_type == 'sqlite') {
  388. // Password can be empty...
  389. $sql_passwort = '';
  390. }
  391. $sql_db = PMF_Filter::filterInput(INPUT_POST, 'sql_db', FILTER_SANITIZE_STRING);
  392. if (is_null($sql_db) && $sql_type != 'sqlite') {
  393. print "<p class=\"error\"><strong>Error:</strong> There's no DB database input.</p>\n";
  394. HTMLFooter();
  395. die();
  396. }
  397. if ($sql_type == 'sqlite') {
  398. $sql_sqllitefile = PMF_Filter::filterInput(INPUT_POST, 'sql_sqlitefile', FILTER_SANITIZE_STRING);
  399. if (!is_null($sql_sqllitefile)) {
  400. $sql_server = $sql_sqllitefile; // We're using $sql_server, too!
  401. } else {
  402. print "<p class=\"error\"><strong>Error:</strong> There's no SQLite database filename input.</p>\n";
  403. HTMLFooter();
  404. die();
  405. }
  406. }
  407. // check database connection
  408. require PMF_ROOT_DIR . "/inc/Db.php";
  409. require PMF_ROOT_DIR . "/inc/PMF_DB/Driver.php";
  410. $db = PMF_Db::dbSelect($sql_type);
  411. $db->connect($sql_server, $sql_user, $sql_passwort, $sql_db);
  412. if (!$db) {
  413. print "<p class=\"error\"><strong>DB Error:</strong> ".$db->error()."</p>\n";
  414. HTMLFooter();
  415. die();
  416. }
  417. // check LDAP if available
  418. $ldap_enabled = PMF_Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_STRING);
  419. if (extension_loaded('ldap') && !is_null($ldap_enabled)) {
  420. // check LDAP entries
  421. $ldap_server = PMF_Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_STRING);
  422. if (is_null($ldap_server)) {
  423. print "<p class=\"error\"><strong>Error:</strong> There's no LDAP server input.</p>\n";
  424. HTMLFooter();
  425. die();
  426. }
  427. $ldap_port = PMF_Filter::filterInput(INPUT_POST, 'ldap_port', FILTER_VALIDATE_INT);
  428. if (is_null($ldap_port)) {
  429. print "<p class=\"error\"><strong>Error:</strong> There's no LDAP port input.</p>\n";
  430. HTMLFooter();
  431. die();
  432. }
  433. $ldap_user = PMF_Filter::filterInput(INPUT_POST, 'ldap_user', FILTER_SANITIZE_STRING);
  434. if (is_null($ldap_user)) {
  435. print "<p class=\"error\"><strong>Error:</strong> There's no LDAP username input.</p>\n";
  436. HTMLFooter();
  437. die();
  438. }
  439. $ldap_password = PMF_Filter::filterInput(INPUT_POST, 'ldap_password', FILTER_SANITIZE_STRING);
  440. if (is_null($ldap_password)) {
  441. print "<p class=\"error\"><strong>Error:</strong> There's no LDAP password input.</p>\n";
  442. HTMLFooter();
  443. die();
  444. }
  445. $ldap_base = PMF_Filter::filterInput(INPUT_POST, 'ldap_base', FILTER_SANITIZE_STRING);
  446. if (is_null($ldap_base)) {
  447. print "<p class=\"error\"><strong>Error:</strong> There's no distinguished name input for LDAP.</p>\n";
  448. HTMLFooter();
  449. die();
  450. }
  451. // check LDAP connection
  452. require PMF_ROOT_DIR . "/inc/Ldap.php";
  453. $ldap = new PMF_Ldap($ldap_server, $ldap_port, $ldap_base, $ldap_user, $ldap_password);
  454. if (!$ldap) {
  455. print "<p class=\"error\"><strong>LDAP Error:</strong> ".$ldap->error()."</p>\n";
  456. HTMLFooter();
  457. die();
  458. }
  459. }
  460. // check user entries
  461. $password = PMF_Filter::filterInput(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
  462. if (is_null($password)) {
  463. print "<p class=\"error\"><strong>Error:</strong> There's no password for the administrator's account. Please set your password.</p>\n";
  464. HTMLFooter();
  465. die();
  466. }
  467. $password_retyped = PMF_Filter::filterInput(INPUT_POST, 'password_retyped', FILTER_SANITIZE_STRING);
  468. if (is_null($password_retyped)) {
  469. print "<p class=\"error\"><strong>Error:</strong> There's no retyped password. Please set your retyped password.</p>\n";
  470. HTMLFooter();
  471. die();
  472. }
  473. if (strlen($password) <= 5 || strlen($password_retyped) <= 5) {
  474. print "<p class=\"error\"><strong>Error:</strong> Your password and retyped password are too short. Please set your password and your retyped password with a minimum of 6 characters.</p>\n";
  475. HTMLFooter();
  476. die();
  477. }
  478. if ($password != $password_retyped) {
  479. print "<p class=\"error\"><strong>Error:</strong> Your password and retyped password are not equal. Please check your password and your retyped password.</p>\n";
  480. HTMLFooter();
  481. die();
  482. }
  483. $language = PMF_Filter::filterInput(INPUT_POST, 'language', FILTER_SANITIZE_STRING, 'en');
  484. $realname = PMF_Filter::filterInput(INPUT_POST, 'realname', FILTER_SANITIZE_STRING, '');
  485. $email = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL, '');
  486. $permLevel = PMF_Filter::filterInput(INPUT_POST, 'permLevel', FILTER_SANITIZE_STRING, 'basic');
  487. // Write the DB variables in database.php
  488. $datafile = PMF_ROOT_DIR . '/config/database.php';
  489. $ret = file_put_contents($datafile, "<?php\n\$DB[\"server\"] = '".$sql_server."';\n\$DB[\"user\"] = '".$sql_user."';\n\$DB[\"password\"] = '".$sql_passwort."';\n\$DB[\"db\"] = '".$sql_db."';\n\$DB[\"prefix\"] = '".$sqltblpre."';\n\$DB[\"type\"] = '".$sql_type."';", LOCK_EX);
  490. if (!$ret) {
  491. print "<p class=\"error\"><strong>Error:</strong> Cannot write to data.php.</p>";
  492. HTMLFooter();
  493. cleanInstallation();
  494. die();
  495. }
  496. // check LDAP if available
  497. if (extension_loaded('ldap') && !is_null($ldap_enabled)) {
  498. $datafile = PMF_ROOT_DIR . '/config/ldap.php';
  499. $ret = file_put_contents($datafile, "<?php\n\$PMF_LDAP[\"ldap_server\"] = '".$ldap_server."';\n\$PMF_LDAP[\"ldap_port\"] = '".$ldap_port."';\n\$PMF_LDAP[\"ldap_user\"] = '".$ldap_user."';\n\$PMF_LDAP[\"ldap_password\"] = '".$ldap_password."';\n\$PMF_LDAP[\"ldap_base\"] = '".$ldap_base."';", LOCK_EX);
  500. if (!$ret) {
  501. print "<p class=\"error\"><strong>Error:</strong> Cannot write to dataldap.php.</p>";
  502. HTMLFooter();
  503. cleanInstallation();
  504. die();
  505. }
  506. }
  507. // connect to the database using inc/data.php
  508. require PMF_ROOT_DIR . '/config/database.php';
  509. $db = PMF_Db::dbSelect($sql_type);
  510. $db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']);
  511. if (!$db) {
  512. print "<p class=\"error\"><strong>DB Error:</strong> ".$db->error()."</p>\n";
  513. HTMLFooter();
  514. cleanInstallation();
  515. die();
  516. }
  517. require_once $sql_type . '.sql.php'; // CREATE TABLES
  518. require_once 'config.sql.php'; // INSERTs for configuration
  519. require_once 'stopwords.sql.php'; // INSERTs for stopwords
  520. print '<p class="center">';
  521. @ob_flush();
  522. flush();
  523. // Erase any table before starting creating the required ones
  524. db_uninstall();
  525. // Start creating the required tables
  526. $count = 0;
  527. while ($each_query = each($query)) {
  528. $result = @$db->query($each_query[1]);
  529. if (!$result) {
  530. print "\n<div class=\"error\">\n";
  531. print "<p><strong>Error:</strong> Please install your version of phpMyFAQ once again or send us a <a href=\"http://bugs.phpmyfaq.de\" target=\"_blank\">bug report</a>.</p>";
  532. print "<p><strong>DB error:</strong> ".$db->error()."</p>\n";
  533. print "<div style=\"text-align: left;\"><p>Query:\n";
  534. print "<pre>".htmlentities($each_query[1])."</pre></p></div>\n";
  535. print "</div>";
  536. db_uninstall();
  537. cleanInstallation();
  538. HTMLFooter();
  539. die();
  540. }
  541. wait(25);
  542. $count++;
  543. if (!($count % 10)) {
  544. print '| ';
  545. @ob_flush();
  546. flush();
  547. }
  548. }
  549. @ob_flush();
  550. flush();
  551. // add admin account and rights
  552. $admin = new PMF_User();
  553. $admin->createUser('admin', $password, 1);
  554. $admin->setStatus('protected');
  555. $adminData = array(
  556. 'display_name' => $realname,
  557. 'email' => $email);
  558. $admin->setUserData($adminData);
  559. $adminID = $admin->getUserId();
  560. // add rights
  561. $rights = array(
  562. //1 => "adduser",
  563. array(
  564. 'name' => 'adduser',
  565. 'description' => 'Right to add user accounts',
  566. 'for_users' => 1,
  567. 'for_groups' => 1
  568. ),
  569. //2 => "edituser",
  570. array(
  571. 'name' => 'edituser',
  572. 'description' => 'Right to edit user accounts',
  573. 'for_users' => 1,
  574. 'for_groups' => 1
  575. ),
  576. //3 => "deluser",
  577. array(
  578. 'name' => 'deluser',
  579. 'description' => 'Right to delete user accounts',
  580. 'for_users' => 1,
  581. 'for_groups' => 1
  582. ),
  583. //4 => "addbt",
  584. array(
  585. 'name' => 'addbt',
  586. 'description' => 'Right to add faq entries',
  587. 'for_users' => 1,
  588. 'for_groups' => 1
  589. ),
  590. //5 => "editbt",
  591. array(
  592. 'name' => 'editbt',
  593. 'description' => 'Right to edit faq entries',
  594. 'for_users' => 1,
  595. 'for_groups' => 1
  596. ),
  597. //6 => "delbt",
  598. array(
  599. 'name' => 'delbt',
  600. 'description' => 'Right to delete faq entries',
  601. 'for_users' => 1,
  602. 'for_groups' => 1
  603. ),
  604. //7 => "viewlog",
  605. array(
  606. 'name' => 'viewlog',
  607. 'description' => 'Right to view logfiles',
  608. 'for_users' => 1,
  609. 'for_groups' => 1
  610. ),
  611. //8 => "adminlog",
  612. array(
  613. 'name' => 'adminlog',
  614. 'description' => 'Right to view admin log',
  615. 'for_users' => 1,
  616. 'for_groups' => 1
  617. ),
  618. //9 => "delcomment",
  619. array(
  620. 'name' => 'delcomment',
  621. 'description' => 'Right to delete comments',
  622. 'for_users' => 1,
  623. 'for_groups' => 1
  624. ),
  625. //10 => "addnews",
  626. array(
  627. 'name' => 'addnews',
  628. 'description' => 'Right to add news',
  629. 'for_users' => 1,
  630. 'for_groups' => 1
  631. ),
  632. //11 => "editnews",
  633. array(
  634. 'name' => 'editnews',
  635. 'description' => 'Right to edit news',
  636. 'for_users' => 1,
  637. 'for_groups' => 1
  638. ),
  639. //12 => "delnews",
  640. array(
  641. 'name' => 'delnews',
  642. 'description' => 'Right to delete news',
  643. 'for_users' => 1,
  644. 'for_groups' => 1
  645. ),
  646. //13 => "addcateg",
  647. array(
  648. 'name' => 'addcateg',
  649. 'description' => 'Right to add categories',
  650. 'for_users' => 1,
  651. 'for_groups' => 1
  652. ),
  653. //14 => "editcateg",
  654. array(
  655. 'name' => 'editcateg',
  656. 'description' => 'Right to edit categories',
  657. 'for_users' => 1,
  658. 'for_groups' => 1
  659. ),
  660. //15 => "delcateg",
  661. array(
  662. 'name' => 'delcateg',
  663. 'description' => 'Right to delete categories',
  664. 'for_users' => 1,
  665. 'for_groups' => 1
  666. ),
  667. //16 => "passwd",
  668. array(
  669. 'name' => 'passwd',
  670. 'description' => 'Right to change passwords',
  671. 'for_users' => 1,
  672. 'for_groups' => 1
  673. ),
  674. //17 => "editconfig",
  675. array(
  676. 'name' => 'editconfig',
  677. 'description' => 'Right to edit configuration',
  678. 'for_users' => 1,
  679. 'for_groups' => 1
  680. ),
  681. //18 => "addatt",
  682. array(
  683. 'name' => 'addatt',
  684. 'description' => 'Right to add attachments',
  685. 'for_users' => 1,
  686. 'for_groups' => 1
  687. ),
  688. //19 => "delatt",
  689. array(
  690. 'name' => 'delatt',
  691. 'description' => 'Right to delete attachments',
  692. 'for_users' => 1,
  693. 'for_groups' => 1
  694. ),
  695. //20 => "backup",
  696. array(
  697. 'name' => 'backup',
  698. 'description' => 'Right to save backups',
  699. 'for_users' => 1,
  700. 'for_groups' => 1
  701. ),
  702. //21 => "restore",
  703. array(
  704. 'name' => 'restore',
  705. 'description' => 'Right to load backups',
  706. 'for_users' => 1,
  707. 'for_groups' => 1
  708. ),
  709. //22 => "delquestion",
  710. array(
  711. 'name' => 'delquestion',
  712. 'description' => 'Right to delete questions',
  713. 'for_users' => 1,
  714. 'for_groups' => 1
  715. ),
  716. //23 => 'addglossary',
  717. array(
  718. 'name' => 'addglossary',
  719. 'description' => 'Right to add glossary entries',
  720. 'for_users' => 1,
  721. 'for_groups' => 1
  722. ),
  723. //24 => 'editglossary',
  724. array(
  725. 'name' => 'editglossary',
  726. 'description' => 'Right to edit glossary entries',
  727. 'for_users' => 1,
  728. 'for_groups' => 1
  729. ),
  730. //25 => 'delglossary'
  731. array(
  732. 'name' => 'delglossary',
  733. 'description' => 'Right to delete glossary entries',
  734. 'for_users' => 1,
  735. 'for_groups' => 1
  736. ),
  737. //26 => 'changebtrevs'
  738. array(
  739. 'name' => 'changebtrevs',
  740. 'description' => 'Right to edit revisions',
  741. 'for_users' => 1,
  742. 'for_groups' => 1
  743. ),
  744. //27 => "addgroup",
  745. array(
  746. 'name' => 'addgroup',
  747. 'description' => 'Right to add group accounts',
  748. 'for_users' => 1,
  749. 'for_groups' => 1
  750. ),
  751. //28 => "editgroup",
  752. array(
  753. 'name' => 'editgroup',
  754. 'description' => 'Right to edit group accounts',
  755. 'for_users' => 1,
  756. 'for_groups' => 1
  757. ),
  758. //29 => "delgroup",
  759. array(
  760. 'name' => 'delgroup',
  761. 'description' => 'Right to delete group accounts',
  762. 'for_users' => 1,
  763. 'for_groups' => 1
  764. ),
  765. //30 => "addtranslation",
  766. array(
  767. 'name' => 'addtranslation',
  768. 'description' => 'Right to add translation',
  769. 'for_users' => 1,
  770. 'for_groups' => 1
  771. ),
  772. //31 => "edittranslation",
  773. array(
  774. 'name' => 'edittranslation',
  775. 'description' => 'Right to edit translations',
  776. 'for_users' => 1,
  777. 'for_groups' => 1
  778. ),
  779. //32 => "deltranslation",
  780. array(
  781. 'name' => 'deltranslation',
  782. 'description' => 'Right to delete translations',
  783. 'for_users' => 1,
  784. 'for_groups' => 1
  785. ),
  786. // 33 => 'approverec'
  787. array(
  788. 'name' => 'approverec',
  789. 'description' => 'Right to approve records',
  790. 'for_users' => 1,
  791. 'for_groups' => 1
  792. ),
  793. );
  794. foreach ($rights as $right) {
  795. $rightID = $admin->perm->addRight($right);
  796. $admin->perm->grantUserRight($adminID, $rightID);
  797. }
  798. // Add anonymous user account
  799. $anonymous = new PMF_User();
  800. $anonymous->createUser('anonymous', null, -1);
  801. $anonymous->setStatus('protected');
  802. $anonymousData = array(
  803. 'display_name' => 'Anonymous User',
  804. 'email' => null);
  805. $anonymous->setUserData($anonymousData);
  806. $oConf = PMF_Configuration::getInstance();
  807. $oConf->getAll();
  808. $configs = $oConf->config;
  809. $configs['spam.enableCaptchaCode'] = (extension_loaded('gd') ? 'true' : 'false');
  810. $configs['main.referenceURL'] = PMF_Link::getSystemUri('/install/setup.php');
  811. $configs['main.phpMyFAQToken'] = md5(uniqid(rand()));
  812. $oConf->update($configs);
  813. print "</p>\n";
  814. print "<p class=\"center\">All database tables were successfully created.</p>\n";
  815. print "<p class=\"center\">Congratulation! Everything seems to be okay.</p>\n";
  816. ?>
  817. <script type="text/javascript">
  818. //<![CDATA[
  819. var iframect = 0;
  820. function iframeUpdated() {
  821. if (iframect++ == 0) {
  822. return;
  823. }
  824. $('#questionnaireForm').hide();
  825. $('#questionnaireThanks').show();
  826. }
  827. function hide(item) {
  828. cssAddClass(item, 'collapsed');
  829. }
  830. function show(item) {
  831. cssDelClass(item, 'collapsed');
  832. }
  833. //]]>
  834. </script>
  835. <iframe onload="iframeUpdated();" name="questionaireResult" style="display:none"></iframe>
  836. <form action="http://www.phpmyfaq.de/stats/getstatdata.php" method="post" target="questionaireResult" id="questionnaireForm">
  837. <p class="center">For further development we would like to get some feedback from our users.<br />Therefore we'd ask you to take a few minutes of your time to answer a few questions.</p>
  838. <p class="center">If you don't want to participate in the survey, you can directly visit <a href="../index.php">your version of phpMyFAQ</a> or login into your <a href="../admin/index.php">admin section</a>.</p>
  839. <fieldset class="installation">
  840. <legend class="installation">General questions</legend>
  841. <label class="leftquestionaire">How do you act like?</label>
  842. <select name="q[individual]">
  843. <option>as an individual</option>
  844. <option>as an organisation</option>
  845. </select>
  846. <br/>
  847. <label class="leftquestionaire">What kind of organisation is that?</label>
  848. <select name="q[organisation]">
  849. <option>private held</option>
  850. <option>public held</option>
  851. <option>government organisation</option>
  852. <option>foundation</option>
  853. <option>other</option>
  854. </select>
  855. </fieldset>
  856. <br />
  857. <fieldset class="installation">
  858. <legend class="installation">Technical questions</legend>
  859. <label class="leftquestionaire">Where did you installed phpMyFAQ?</label>
  860. <select name="q[server]">
  861. <option>server run by a hosting company</option>
  862. <option>public server run by you/your organisation</option>
  863. <option>private server run by you/your organisation</option>
  864. <option>Don't know</option>
  865. </select>
  866. </fieldset>
  867. <br />
  868. <fieldset class="installation">
  869. <legend class="installation">Beyond our own nose</legend>
  870. <label class="leftquestionaire">Which PHP software do you also use?</label>
  871. <input name="q[other]" /><br />
  872. <label class="leftquestionaire">Are you using other web technologies?</label>
  873. <input type="checkbox" name="q[other][]" value="ASP" />ASP
  874. <input type="checkbox" name="q[other][]" value="ASP.NET" />ASP.NET
  875. <input type="checkbox" name="q[other][]" value="jsp" />JAVA JSP
  876. <input type="checkbox" name="q[other][]" value="perl" />Perl
  877. <input type="checkbox" name="q[other][]" value="ruby" />Ruby / Ruby on Rails
  878. <input type="checkbox" name="q[other][]" value="python" />Python
  879. </fieldset>
  880. <br />
  881. <p class="center">Additional to your input we're going to submit some information about your system setup for statstic purpose.</p>
  882. <p class="center">We are not storing any personal information. You can see the data by clicking <a href="#" onclick="show('configliste');return false;">here</a>.</p>
  883. <div id="configliste" class="collapsed">
  884. <a href="#" onclick="hide('configliste'); return false;">hide again</a>
  885. <dl>
  886. <?php
  887. $questionnaire = new PMF_Helper_Questionnaire($configs);
  888. $options = $questionnaire->get();
  889. array_walk($options, 'data_printer');
  890. echo '</dl><input type="hidden" name="systemdata" value="' .
  891. PMF_String::htmlspecialchars(serialize($questionnaire->get()), ENT_QUOTES) . '" />';
  892. ?>
  893. </div>
  894. <p class="center"><input type="submit" value="Click here to submit the data and finish the installation process" /></p>
  895. </form>
  896. <div id="questionnaireThanks" style="display:none;">
  897. <p class="center"><b>Thank you for giving your feedback!</b></p>
  898. <p class="center">You can visit <a href="../index.php">your version of phpMyFAQ</a> or</p>
  899. <p class="center">login into your <a href="../admin/index.php">admin section</a>.</p>
  900. </div>
  901. <br />
  902. <?php
  903. // Remove 'phpmyfaq.spec' file: no need of prompt anything to the user
  904. if (file_exists(PMF_ROOT_DIR."/phpmyfaq.spec")) {
  905. @unlink(PMF_ROOT_DIR."/phpmyfaq.spec");
  906. }
  907. // Remove 'setup.php' file
  908. if (@unlink(basename($_SERVER["PHP_SELF"]))) {
  909. print "<p class=\"center\">The file <em>./install/setup.php</em> was deleted automatically.</p>\n";
  910. } else {
  911. print "<p class=\"center\">Please delete the file <em>./install/setup.php</em> manually.</p>\n";
  912. }
  913. // Remove 'update.php' file
  914. if (@unlink(dirname($_SERVER["PATH_TRANSLATED"])."/update.php")) {
  915. print "<p class=\"center\">The file <em>./install/update.php</em> was deleted automatically.</p>\n";
  916. } else {
  917. print "<p class=\"center\">Please delete the file <em>./install/update.php</em> manually.</p>\n";
  918. }
  919. HTMLFooter();
  920. }