PageRenderTime 77ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/install/index.php

https://github.com/Doap/FrogCMS
PHP | 251 lines | 205 code | 21 blank | 25 comment | 14 complexity | 687aba7ccbd6d1f671dae864203fd00a MD5 | raw file
  1. <?php
  2. /**
  3. * Frog CMS - Content Management Simplified. <http://www.madebyfrog.com>
  4. * Copyright (C) 2008 Philippe Archambault <philippe.archambault@gmail.com>
  5. *
  6. * This file is part of Frog CMS.
  7. *
  8. * Frog CMS is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Frog CMS is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Frog CMS. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * Frog CMS has made an exception to the GNU General Public License for plugins.
  22. * See exception.txt for details and the full text.
  23. */
  24. define('DEFAULT_ADMIN_USER', 'admin');
  25. define('CORE_ROOT', dirname(__FILE__).'/../frog');
  26. $config_file = '../config.php';
  27. include 'Template.php';
  28. if (file_exists($config_file))
  29. include $config_file;
  30. $msg = '';
  31. $PDO = false;
  32. // lets install this nice little CMS
  33. if ( ! defined('DEBUG') && isset($_POST['commit']) && (file_exists($config_file) && is_writable($config_file)))
  34. {
  35. define('INSTALL_SEQUENCE', true);
  36. $admin_name = DEFAULT_ADMIN_USER;
  37. $admin_passwd = '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8';
  38. $admin_passwd_precrypt = 'password';
  39. $_POST['config']['use_pdo'] = class_exists('PDO');
  40. // check if the PDO driver we need is installed
  41. if ($_POST['config']['use_pdo'] and !in_array($_POST['config']['db_driver'], PDO::getAvailableDrivers()))
  42. $_POST['config']['use_pdo'] = false;
  43. $config_tmpl = new Template('config.tmpl');
  44. $config_tmpl->assign($_POST['config']);
  45. $config_content = $config_tmpl->fetch();
  46. file_put_contents($config_file, $config_content);
  47. $msg .= "<ul><li>Config file successfully written.</li>\n";
  48. include $config_file;
  49. // setup admin name (default to 'admin')
  50. if (isset($_POST['config']['admin_username'])) {
  51. $admin_name = $_POST['config']['admin_username'];
  52. $admin_name = trim($admin_name);
  53. $admin_passwd_precrypt = '12'.dechex(rand(100000000, 4294967295)).'K';
  54. $admin_passwd = sha1($admin_passwd_precrypt);
  55. }
  56. if (USE_PDO)
  57. {
  58. try {
  59. $PDO = new PDO(DB_DSN, DB_USER, DB_PASS);
  60. } catch (PDOException $e) {
  61. $msg = 'Frog has not been installed properly.<br />The following error has occured: <p><strong>'. $e->getMessage() ."</strong></p>\n";
  62. file_put_contents($config_file, '');
  63. }
  64. }
  65. else if ($_POST['config']['db_driver'] == 'mysql')
  66. {
  67. require_once CORE_ROOT . '/libraries/DoLite.php';
  68. $PDO = new DoLite(DB_DSN, DB_USER, DB_PASS);
  69. }
  70. else
  71. {
  72. $msg = "Frog has not been installed properly.<br />You need PDO and SQLite 3 drive to use SQLite 3.<br />\n";
  73. }
  74. if ($PDO)
  75. {
  76. $msg .= '<li>Database connection successfull.</li>';
  77. include 'schema_'.$_POST['config']['db_driver'].'.php';
  78. include 'sql_data.php';
  79. $msg .= '<li>Tables loaded successfully</li></ul><p>You can login with: <br /><br /><strong>login</strong>: '.$admin_name.'<br /><strong>password</strong>: '.$admin_passwd_precrypt.'<br /><br />
  80. <strong>at</strong>: <a href="../admin/">login page</a></p>
  81. <p>Please be aware: the password is generated by Frog, please use it to login to Frog and <strong>change your password</strong>!</p>';
  82. }
  83. else $error = 'Unable to connect to the database! Tables are not loaded!';
  84. }
  85. ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  87. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  88. <html>
  89. <head>
  90. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  91. <title>Frog CMS - Install</title>
  92. <link href="../admin/stylesheets/admin.css" media="screen" rel="Stylesheet" type="text/css" />
  93. <script type="text/javascript" charset="utf-8" src="../admin/javascripts/prototype.js"></script>
  94. <script type="text/javascript" charset="utf-8" src="../admin/javascripts/effects.js"></script>
  95. </head>
  96. <body id="installation">
  97. <div id="header">
  98. <div id="site-title">Frog CMS</div>
  99. </div>
  100. <div id="main">
  101. <div id="content-wrapper">
  102. <div id="content">
  103. <!-- Content -->
  104. <h1>Frog Installation</h1>
  105. <p style="color: red">
  106. <?php if ( ! file_exists($config_file)) { ?>
  107. <strong>Error</strong>: config.php doesn't exist<br />
  108. <?php } else if ( ! is_writable($config_file)) { ?>
  109. <strong>Error</strong>: config.php must be writable<br />
  110. <?php } ?>
  111. <?php if ( ! is_writable('../public/')): ?>
  112. <strong>Error</strong>: public/ folder must be writable<br />
  113. <?php endif; ?>
  114. </p>
  115. <?php if ( ! defined('DEBUG')): ?>
  116. <form action="index.php" method="post">
  117. <table class="fieldset" cellpadding="0" cellspacing="0" border="0">
  118. <tr>
  119. <td colspan="3"><h3>Database information</h3></td>
  120. </tr>
  121. <tr>
  122. <td class="label"><label for="config_db_driver">Database driver</label></td>
  123. <td class="field">
  124. <select id="config_db_driver" name="config[db_driver]" onchange="db_driver_change(this[this.selectedIndex].value);">
  125. <option value="mysql">MySQL</option>
  126. <option value="sqlite">SQLite 3</option>
  127. </select>
  128. <script type="text/javascript" language="javascript">
  129. function db_driver_change(driver)
  130. {
  131. Element.toggle('row-db-host');
  132. Element.toggle('row-db-port');
  133. Element.toggle('row-db-user');
  134. Element.toggle('row-db-pass');
  135. Element.toggle('row-table-prefix');
  136. if (driver == 'sqlite')
  137. {
  138. $('help-db-name').innerHTML = 'Required. Enter the <strong>absolute</strong> path to the database file.';
  139. }
  140. else if (driver == 'mysql')
  141. {
  142. $('help-db-name').innerHTML = 'Required. You have to create a database manually and enter its name here.';
  143. }
  144. }
  145. </script>
  146. </td>
  147. <td class="help">Required. PDO support and the SQLite 3 plugin are required to use SQLite 3.</td>
  148. </tr>
  149. <tr id="row-db-host">
  150. <td class="label"><label for="config_db_host">Database server</label></td>
  151. <td class="field"><input class="textbox" id="config_db_host" maxlength="100" name="config[db_host]" size="100" type="text" value="localhost" /></td>
  152. <td class="help">Required.</td>
  153. </tr>
  154. <tr id="row-db-port">
  155. <td class="label"><label for="config_db_port">Port</label></td>
  156. <td class="field"><input class="textbox" id="config_db_port" maxlength="10" name="config[db_port]" size="100" type="text" value="3306" /></td>
  157. <td class="help">Optional. Default: 3306</td>
  158. </tr>
  159. <tr id="row-db-user">
  160. <td class="label"><label for="config_db_user">Database user</label></td>
  161. <td class="field"><input class="textbox" id="config_db_user" maxlength="255" name="config[db_user]" size="255" type="text" value="root" /></td>
  162. <td class="help">Required.</td>
  163. </tr>
  164. <tr id="row-db-pass">
  165. <td class="label"><label class="optional" for="config_db_pass">Database password</label></td>
  166. <td class="field"><input class="textbox" id="config_db_pass" maxlength="40" name="config[db_pass]" size="40" type="password" value="" /></td>
  167. <td class="help">Optional. If there is no database password, leave it blank.</td>
  168. </tr>
  169. <tr id="row-db-name">
  170. <td class="label"><label for="config_db_name">Database name</label></td>
  171. <td class="field"><input class="textbox" id="config_db_name" maxlength="40" name="config[db_name]" size="40" type="text" value="frog" /></td>
  172. <td class="help" id="help-db-name">Required. You have to create a database manually and enter its name here.</td>
  173. </tr>
  174. <tr id="row-table-prefix">
  175. <td class="label"><label class="optional" for="config_table_prefix">Table prefix</label></td>
  176. <td class="field"><input class="textbox" id="config_table_prefix" maxlength="40" name="config[table_prefix]" size="40" type="text" value="" /></td>
  177. <td class="help">Optional. Usefull to prevent conflicts if you have, or plan to have, multiple Frog installations with a single database.</td>
  178. </tr>
  179. <tr>
  180. <td colspan="3"><h3>Other information</h3></td>
  181. </tr>
  182. <tr>
  183. <td class="label"><label class="optional" for="config_admin_username">Administrator username</label></td>
  184. <td class="field"><input class="textbox" id="config_admin_username" maxlength="40" name="config[admin_username]" size="40" type="text" value="<?php echo DEFAULT_ADMIN_USER; ?>" /></td>
  185. <td class="help">Required. Allows you to specify a custom username for the administrator. Default: admin</td>
  186. </tr>
  187. <tr>
  188. <td class="label"><label class="optional" for="config_url_suffix">URL suffix</label></td>
  189. <td class="field"><input class="textbox" id="config_url_suffix" maxlength="40" name="config[url_suffix]" size="40" type="text" value=".html" /></td>
  190. <td class="help">Optional. Add a suffix to simulate static html files.</td>
  191. </tr>
  192. </table>
  193. <p class="buttons">
  194. <button class="button" name="commit" type="submit"> Install now </button>
  195. </p>
  196. </form>
  197. <?php else: ?>
  198. <?php echo $msg; ?>
  199. <?php if (isset($error)): ?>
  200. <p style="color: red;"><?php echo $error; ?></p>
  201. <p><a href="index.php">Click here and try again</a></p>
  202. <?php else: ?>
  203. <p>
  204. <strong>Frog CMS</strong> is installed, <b>you should now:</b><br />
  205. 1. delete the <em>install/</em> folder!<br />
  206. 2. remove all write permissions from the <em>config.php</em> file!<br />
  207. 3. remove changelog.txt and similar files to enhance security.
  208. </p>
  209. <?php endif; ?>
  210. <?php endif; ?>
  211. </div>
  212. </div>
  213. </div>
  214. <div id="footer">
  215. <p>This system was made with <a href="http://www.php.net" target="_blank">PHP</a> and is powered by <a href="http://www.madebyfrog.com/">Frog CMS</a></p>
  216. </div>
  217. </body>
  218. </html>