A tumblelog CMS built on AJAX, PHP and MySQL.

install.php 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?php
  9. $configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
  10. if (!file_exists($configFile)) {
  11. $mensaje = "
  12. <h3 class=\"important\">Error reading configuration file</h3>
  13. <p>There doesn't seem to be a <code>config.php</code> file. I need this before we can get started.</p>
  14. <p>This either means that you did not rename the <code>config-sample.php</code> file to <code>config.php</code>.</p>";
  15. die($mensaje);
  16. } else {
  17. require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
  18. $showForm = true;
  19. }
  20. include("classes/functions.php");
  21. $errors_d=array();
  22. $errors_d[1]="The login field cannot be empty";
  23. $errors_d[2]="The password field cannot be empty";
  24. $errors_d[3]="Password does not match the confirm password";
  25. $errors_d[4]="The e-mail field cannot be empty";
  26. $errors_d[5]="The installation URL field cannot be empty";
  27. $errors_d[6]="Error establishing a database connection";
  28. $action="";
  29. $errors="";
  30. if (isset($_POST['action'])){
  31. $action=$_POST['action'];
  32. }
  33. if ($action=="config") {
  34. $sep_err="";
  35. if (!$_POST['login']) {
  36. $errors=$errors.$sep_err."1";
  37. $sep_err="|";
  38. }
  39. if (!$_POST['password']) {
  40. $errors=$errors.$sep_err."2";
  41. $sep_err="|";
  42. }
  43. if (!$_POST['email']) {
  44. $errors=$errors.$sep_err."4";
  45. $sep_err="|";
  46. }
  47. if (!$_POST['url_installation']) {
  48. $errors=$errors.$sep_err."5";
  49. $sep_err="|";
  50. }
  51. if ($_POST['password']!=$_POST['password2']) {
  52. $errors=$errors.$sep_err."3";
  53. $sep_err="|";
  54. }
  55. if (!$errors) {
  56. if (installdb($_POST['login'], $_POST['password'], $_POST['email'], $_POST['title'], $_POST['description'], $_POST['url_installation'], $_POST['posts_limit'], $_POST['lang'], $_POST['template'], $_POST['website'], $_POST['about'], $_POST['url_friendly'], $_POST['rich_text'])) {
  57. $showForm=false;
  58. } else {
  59. $errors=$errors.$sep_err."6";
  60. $sep_err="|";
  61. $showForm=true;
  62. }
  63. } else {
  64. $showForm=true;
  65. }
  66. }
  67. ?>
  68. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  69. <html xmlns="http://www.w3.org/1999/xhtml">
  70. <head>
  71. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  72. <title>gelato :: installation</title>
  73. <meta name="generator" content="sabros.us <?php echo version();?>" />
  74. <link rel="shortcut icon" href="images/favicon.ico" />
  75. <style type="text/css" media="screen">
  76. @import "admin/css/style.css";
  77. </style>
  78. </head>
  79. <body>
  80. <div id="cont">
  81. <div id="head">
  82. <h1><a href="index.php" title="gelato :: home">gelato cms</a></h1>
  83. </div>
  84. <div id="main">
  85. <?
  86. if ($showForm) {
  87. ?>
  88. <div class="box">
  89. <ul class="menu manage">
  90. <h3>gelato :: installation</h3>
  91. <li class="selected"><a>Install</a></li>
  92. </ul>
  93. <div class="tabla">
  94. <form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
  95. <fieldset>
  96. <legend class="install">Admin user</legend>
  97. <ul>
  98. <li><label for="login">User:</label>
  99. <input type="text" name="login" id="login" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"1")?></li>
  100. <li><label for="password">Password:</label>
  101. <input type="password" name="password" id="password" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"2")?></li>
  102. <li><label for="password2">Re-type password:</label>
  103. <input type="password" name="password2" id="password2" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"3")?></li>
  104. <li><label for="email">E-mail:</label>
  105. <input type="text" name="email" id="email" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"4")?></li>
  106. </ul>
  107. </fieldset><br />
  108. <fieldset>
  109. <legend class="install">Tumblelog configuration</legend>
  110. <ul>
  111. <li><label for="title">Title:</label>
  112. <input type="text" name="title" id="title" value="" class="txt"/></li>
  113. <li><label for="description">Description:</label>
  114. <input type="text" name="description" id="description" value="" class="txt"/></li>
  115. <li><label for="url_installation">Installation URL</label>
  116. <input type="text" name="url_installation" id="url_installation" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"5")?></li>
  117. <li><label for="posts_limit">Post limit:</label>
  118. <input type="text" name="posts_limit" id="posts_limit" value="10" class="txt"/></li>
  119. <li><label for="lang">Language:</label>
  120. <select id="lang" name="lang">
  121. <option value="en" selected="selected">english</option>
  122. </select>
  123. </li>
  124. <li><label for="template">Template:</label>
  125. <select id="template" name="template">
  126. <?php
  127. $themes = getThemes();
  128. foreach ($themes as $theme) {
  129. echo "<option value=\"".$theme."\" selected=\"true\">".$theme."</option>\n";
  130. }
  131. ?>
  132. </select>
  133. </li>
  134. </ul>
  135. </fieldset>
  136. <p>
  137. <input type="hidden" name="website" id="website" value="" />
  138. <input type="hidden" name="about" id="about" value="" />
  139. <input type="hidden" name="url_friendly" id="url_friendly" value="0" />
  140. <input type="hidden" name="rich_text" id="rich_text" value="0" />
  141. <input type="hidden" name="action" id="action" value="config" />
  142. <input type="submit" name="btnsubmit" id="btnsubmit" value="<< Install >>" class="submit"/>
  143. </p>
  144. </form>
  145. </div>
  146. <div class="footer-box">&nbsp;</div>
  147. </div>
  148. <?php
  149. } else {
  150. echo "<p><em>Finished!</em></p>";
  151. echo "<p>Now you can <a href=\"login.php\" class=\"inslnl\">log in</a> with your <strong>username</strong> and <strong>password</strong></p>";
  152. }
  153. ?>
  154. </div>
  155. <div id="foot">
  156. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  157. </div>
  158. </div>
  159. </body>
  160. </html>
  161. <?php
  162. function installdb($login, $password, $email, $title, $description, $url_installation, $posts_limit, $lang, $template, $website, $about, $url_friendly, $rich_text){
  163. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  164. $sqlStr = "CREATE TABLE `".Table_prefix."data` (
  165. `id_post` int(11) NOT NULL auto_increment,
  166. `title` text NULL,
  167. `url` varchar(250) default NULL,
  168. `description` text NULL,
  169. `type` tinyint(4) NOT NULL default '1',
  170. `date` datetime NOT NULL,
  171. `id_user` int(10) NOT NULL,
  172. PRIMARY KEY (`id_post`)
  173. ) ENGINE = MYISAM ;";
  174. $db->ejecutarConsulta($sqlStr);
  175. $sqlStr = "CREATE TABLE `".Table_prefix."users` (
  176. `id_user` int(10) unsigned NOT NULL auto_increment,
  177. `name` varchar(100) default NULL,
  178. `login` varchar(100) NOT NULL default '',
  179. `password` varchar(64) NOT NULL default '',
  180. `email` varchar(100) default NULL,
  181. `website` varchar(150) default NULL,
  182. `about` text,
  183. PRIMARY KEY (`id_user`)
  184. ) ENGINE = MYISAM;";
  185. $db->ejecutarConsulta($sqlStr);
  186. $sqlStr = "CREATE TABLE `".Table_prefix."config` (
  187. `posts_limit` int(3) NOT NULL,
  188. `title` varchar(250) NOT NULL,
  189. `description` text NOT NULL,
  190. `lang` varchar(10) NOT NULL,
  191. `template` varchar(100) NOT NULL,
  192. `url_installation` varchar(250) NOT NULL,
  193. `url_friendly` tinyint(1) NOT NULL,
  194. `rich_text` tinyint(1) NOT NULL,
  195. PRIMARY KEY (`title`)
  196. ) ENGINE = MYISAM ;";
  197. $db->ejecutarConsulta($sqlStr);
  198. $url_installation = (endsWith($url_installation, "/")) ? substr($url_installation, 0, strlen($url_installation)-1) : $url_installation ;
  199. $sqlStr = "INSERT INTO `".Table_prefix."config` VALUES (".$posts_limit.", '".$title."', '".$description."', '".$lang."', '".$template."', '".$url_installation."', ".$url_friendly.", ".$rich_text.");";
  200. $db->ejecutarConsulta($sqlStr);
  201. $sqlStr = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$login."', '".md5($password)."', '".$email."', '".$website."', '".$about."');";
  202. $db->ejecutarConsulta($sqlStr);
  203. return true;
  204. }
  205. function inerrors($errors,$n) {
  206. if (strpos($errors,$n)===false)
  207. return false;
  208. else
  209. return true;
  210. }
  211. function mostrarerror($errors,$errors_d,$n) {
  212. if (inerrors($errors,$n))
  213. return '<span class="error">'.$errors_d[$n].'</span>';
  214. else
  215. return "";
  216. }
  217. ?>