A tumblelog CMS built on AJAX, PHP and MySQL.

install.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. /* ===========================
  3. gelato CMS - A PHP based tumblelog CMS
  4. development version
  5. http://www.gelatocms.com/
  6. gelato CMS is a free software licensed under the GPL 2.0
  7. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  8. =========================== */
  9. ?>
  10. <?php
  11. $configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
  12. if (!file_exists($configFile)) {
  13. $mensaje = "
  14. <h3 class=\"important\">Error reading configuration file</h3>
  15. <p>There doesn't seem to be a <code>config.php</code> file. I need this before we can get started.</p>
  16. <p>This either means that you did not rename the <code>config-sample.php</code> file to <code>config.php</code>.</p>";
  17. die($mensaje);
  18. } else {
  19. require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
  20. $showForm = true;
  21. }
  22. include("classes/functions.php");
  23. $errors_d=array();
  24. $errors_d[1]="The login field cannot be empty";
  25. $errors_d[2]="The password field cannot be empty";
  26. $errors_d[3]="Password does not match the confirm password";
  27. $errors_d[4]="The e-mail field cannot be empty";
  28. $errors_d[5]="The installation URL field cannot be empty";
  29. $errors_d[6]="Error establishing a database connection";
  30. $action="";
  31. $errors="";
  32. if (isset($_POST['action'])){
  33. $action=$_POST['action'];
  34. }
  35. if ($action=="config" && !is_db_installed()) {
  36. $sep_err="";
  37. if (!$_POST['login']) {
  38. $errors=$errors.$sep_err."1";
  39. $sep_err="|";
  40. }
  41. if (!$_POST['password']) {
  42. $errors=$errors.$sep_err."2";
  43. $sep_err="|";
  44. }
  45. if (!$_POST['email']) {
  46. $errors=$errors.$sep_err."4";
  47. $sep_err="|";
  48. }
  49. if (!$_POST['url_installation']) {
  50. $errors=$errors.$sep_err."5";
  51. $sep_err="|";
  52. }
  53. if ($_POST['password']!=$_POST['password2']) {
  54. $errors=$errors.$sep_err."3";
  55. $sep_err="|";
  56. }
  57. $off_r= split("," , $_POST['time_offsets']);
  58. $_POST['offset_time'] = $off_r[0];
  59. $_POST['offset_city'] = $off_r[1];
  60. unset($_POST['time_offsets']);
  61. if (!$errors) {
  62. if (install_db($_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['offset_city'], $_POST['offset_time'])) {
  63. $showForm=false;
  64. } else {
  65. $errors=$errors.$sep_err."6";
  66. $sep_err="|";
  67. $showForm=true;
  68. }
  69. } else {
  70. $showForm=true;
  71. }
  72. }
  73. $showForm = (!is_db_installed());
  74. ?>
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  76. <html xmlns="http://www.w3.org/1999/xhtml">
  77. <head>
  78. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  79. <meta name="generator" content="gelato cms <?php echo version();?>" />
  80. <title>gelato :: installation</title>
  81. <link rel="shortcut icon" href="images/favicon.ico" />
  82. <style type="text/css" media="screen">
  83. @import "admin/css/style.css";
  84. </style>
  85. </head>
  86. <body>
  87. <div id="cont">
  88. <div id="head">
  89. <h1><a href="index.php" title="gelato :: home">gelato cms</a></h1>
  90. </div>
  91. <div id="main">
  92. <?
  93. if ($showForm) {
  94. ?>
  95. <div class="box">
  96. <ul class="menu manage">
  97. <h3>gelato :: installation</h3>
  98. <li class="selected"><a>Install</a></li>
  99. </ul>
  100. <div class="tabla">
  101. <form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
  102. <fieldset>
  103. <legend class="install">Admin user</legend>
  104. <ul>
  105. <li><label for="login">User:</label>
  106. <input type="text" name="login" id="login" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"1")?></li>
  107. <li><label for="password">Password:</label>
  108. <input type="password" name="password" id="password" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"2")?></li>
  109. <li><label for="password2">Re-type password:</label>
  110. <input type="password" name="password2" id="password2" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"3")?></li>
  111. <li><label for="email">E-mail:</label>
  112. <input type="text" name="email" id="email" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"4")?></li>
  113. </ul>
  114. </fieldset><br />
  115. <fieldset>
  116. <legend class="install">Tumblelog configuration</legend>
  117. <ul>
  118. <li><label for="title">Title:</label>
  119. <input type="text" name="title" id="title" value="" class="txt"/></li>
  120. <li><label for="description">Description:</label>
  121. <input type="text" name="description" id="description" value="" class="txt"/></li>
  122. <li><label for="url_installation">Installation URL</label>
  123. <input type="text" name="url_installation" id="url_installation" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"5")?></li>
  124. <li><label for="posts_limit">Post limit:</label>
  125. <input type="text" name="posts_limit" id="posts_limit" value="10" class="txt"/></li>
  126. <li><label for="lang">Language:</label>
  127. <select id="lang" name="lang">
  128. <option value="en" selected="selected">english</option>
  129. </select>
  130. </li>
  131. <li><label for="template">Template:</label>
  132. <select id="template" name="template">
  133. <?php
  134. $themes = getThemes();
  135. foreach ($themes as $theme) {
  136. echo "<option value=\"".$theme."\" selected=\"true\">".$theme."</option>\n";
  137. }
  138. ?> </select>
  139. <li>
  140. <li><label for="time_offsets">Time Offset:</label>
  141. <select id="time_offsets" name="time_offsets">
  142. <option value="-12,Pacific/Kwajalein">(GMT -12:00) International Date Line West</option>
  143. <option value="-11,Pacific/Samoa">(GMT -11:00) Midway Island, Samoa</option>
  144. <option value="-10,Pacific/Honolulu">(GMT -10:00) Hawaii</option>
  145. <option value="-9,US/Alaska">(GMT -9:00) Alaska</option>
  146. <option value="-8,US/Pacific">(GMT -8:00) Pacific Time (US &amp; Canada); Tijuana</option>
  147. <option value="-7,US/Mountain">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
  148. <option value="-7,US/Arizona">(GMT -7:00) Arizona</option>
  149. <option value="-7,Mexico/BajaNorte">(GMT -7:00) Chihuahua, La Paz, Mazatlan</option>
  150. <option value="-6,US/Central">(GMT -6:00) Central Time (US &amp; Canada)</option>
  151. <option value="-6,America/Costa_Rica">(GMT -6:00) Central America</option>
  152. <option value="-6,Mexico/General" selected="selected">(GMT -6:00) Guadalajara, Mexico City, Monterrey</option>
  153. <option value="-6,Canada/Saskatchewan">(GMT -6:00) Saskatchewan</option>
  154. <option value="-5,US/Eastern">(GMT -5:00) Eastern Time (US &amp; Canada)</option>
  155. <option value="-5,America/Bogota">(GMT -5:00) Bogota, Lima, Quito</option>
  156. <option value="-5,US/East-Indiana">(GMT -5:00) Indiana (East)</option>
  157. <option value="-4,Canada/Eastern">(GMT -4:00) Atlantic Time (Canada)</option>
  158. <option value="-4,America/Caracas">(GMT -4:00) Caracas, La Paz</option>
  159. <option value="-4,America/Santiago">(GMT -4:00) Santiago</option>
  160. <option value="-3.50,Canada/Newfoundland">(GMT -3:30) Newfoundland</option>
  161. <option value="-3,Canada/Atlantic">(GMT -3:00) Brasilia, Greenland</option>
  162. <option value="-3,America/Buenos_Aires">(GMT -3:00) Buenos Aires, Georgetown</option>
  163. <option value="-1,Atlantic/Cape_Verde">(GMT -1:00) Cape Verde Is.</option>
  164. <option value="-1,Atlantic/Azores">(GMT -1:00) Azores</option>
  165. <option value="0,Africa/Casablanca">(GMT) Casablanca, Monrovia</option>
  166. <option value="0,Europe/Dublin">(GMT) Greenwich Mean Time : Dublin, Edinburgh, London</option>
  167. <option value="1,Europe/Amsterdam">(GMT +1:00) Amsterdam, Berlin, Rome, Stockholm, Vienna</option>
  168. <option value="1,Europe/Prague">(GMT +1:00) Belgrade, Bratislava, Budapest, Prague</option>
  169. <option value="1,Europe/Paris">(GMT +1:00) Brussels, Copenhagen, Madrid, Paris</option>
  170. <option value="1,Europe/Warsaw">(GMT +1:00) Sarajevo, Skopje, Warsaw, Zagreb</option>
  171. <option value="1,Africa/Bangui">(GMT +1:00) West Central Africa</option>
  172. <option value="2,Europe/Istanbul">(GMT +2:00) Athens, Beirut, Bucharest, Cairo, Istanbul </option>
  173. <option value="2,Asia/Jerusalem">(GMT +2:00) Harare, Jerusalem, Pretoria</option>
  174. <option value="2,Europe/Kiev">(GMT +2:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius</option>
  175. <option value="3,Asia/Riyadh">(GMT +3:00) Kuwait, Nairobi, Riyadh</option>
  176. <option value="3,Europe/Moscow">(GMT +3:00) Baghdad, Moscow, St. Petersburg, Volgograd</option>
  177. <option value="3.50,Asia/Tehran">(GMT +3:30) Tehran</option>
  178. <option value="4,Asia/Muscat">(GMT +4:00) Abu Dhabi, Muscat</option>
  179. <option value="4,Asia/Baku">(GMT +4:00) Baku, Tbilsi, Yerevan</option>
  180. <option value="4.50,Asia/Kabul">(GMT +4:30) Kabul</option>
  181. <option value="5,Asia/Yekaterinburg">(GMT +5:00) Yekaterinburg</option>
  182. <option value="5,Asia/Karachi">(GMT +5:00) Islamabad, Karachi, Tashkent</option>
  183. <option value="5.50,Asia/Calcutta">(GMT +5:30) Chennai, Calcutta, Mumbai, New Delhi</option>
  184. <option value="5.75,Asia/Katmandu">(GMT +5:45) Katmandu</option>
  185. <option value="6,Asia/Almaty">(GMT +6:00) Almaty, Novosibirsk</option>
  186. <option value="6,Asia/Dhaka">(GMT +6:00) Astana, Dhaka, Sri Jayawardenepura</option>
  187. <option value="6.50,Asia/Rangoon">(GMT +6:30) Rangoon</option>
  188. <option value="7,Asia/Bangkok">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
  189. <option value="7,Asia/Krasnoyarsk">(GMT +7:00) Krasnoyarsk</option>
  190. <option value="8,Asia/Hong_Kong">(GMT +8:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
  191. <option value="8,Asia/Irkutsk">(GMT +8:00) Irkutsk, Ulaan Bataar</option>
  192. <option value="8,Asia/Singapore">(GMT +8:00) Kuala Lumpar, Perth, Singapore, Taipei</option>
  193. <option value="9,Asia/Tokyo">(GMT +9:00) Osaka, Sapporo, Tokyo</option>
  194. <option value="9,Asia/Seoul">(GMT +9:00) Seoul</option>
  195. <option value="9,Asia/Yakutsk">(GMT +9:00) Yakutsk</option>
  196. <option value="9.50,Australia/Adelaide">(GMT +9:30) Adelaide</option>
  197. <option value="9.50Australia/Darwin">(GMT +9:30) Darwin</option>
  198. <option value="10,Australia/Brisbane">(GMT +10:00) Brisbane, Guam, Port Moresby</option>
  199. <option value="10,Australia/Canberra">(GMT +10:00) Canberra, Hobart, Melbourne, Sydney, Vladivostok</option>
  200. <option value="11,Asia/Magadan">(GMT +11:00) Magadan, Soloman Is., New Caledonia</option>
  201. <option value="12,Pacific/Auckland">(GMT +12:00) Auckland, Wellington</option>
  202. <option value="12,Pacific/Fiji">(GMT +12:00) Fiji, Kamchatka, Marshall Is.</option>
  203. </select>
  204. </li>
  205. </ul>
  206. </fieldset>
  207. <p>
  208. <input type="hidden" name="website" id="website" value="" />
  209. <input type="hidden" name="about" id="about" value="" />
  210. <input type="hidden" name="action" id="action" value="config" />
  211. <input type="submit" name="btnsubmit" id="btnsubmit" value="<< Install >>" class="submit"/>
  212. </p>
  213. </form>
  214. </div>
  215. <div class="footer-box">&nbsp;</div>
  216. </div>
  217. <?php
  218. } else {
  219. echo "<p><em>Finished!</em></p>";
  220. echo "<p>Now you can <a href=\"login.php\" class=\"inslnl\">log in</a> with your <strong>username</strong> and <strong>password</strong></p>";
  221. }
  222. ?>
  223. </div>
  224. <div id="foot">
  225. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  226. </div>
  227. </div>
  228. </body>
  229. </html>
  230. <?php
  231. function install_db($login, $password, $email, $title, $description, $url_installation, $posts_limit, $lang, $template, $website, $about, $offset_city, $offset_time){
  232. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  233. $sqlStr = "CREATE TABLE `".Table_prefix."data` (
  234. `id_post` int(11) NOT NULL auto_increment,
  235. `title` text NULL,
  236. `url` varchar(250) default NULL,
  237. `description` text NULL,
  238. `type` tinyint(4) NOT NULL default '1',
  239. `date` datetime NOT NULL,
  240. `id_user` int(10) NOT NULL,
  241. PRIMARY KEY (`id_post`)
  242. ) ENGINE = MYISAM ;";
  243. $db->ejecutarConsulta($sqlStr);
  244. $sqlStr = "CREATE TABLE `".Table_prefix."users` (
  245. `id_user` int(10) unsigned NOT NULL auto_increment,
  246. `name` varchar(100) default NULL,
  247. `login` varchar(100) NOT NULL default '',
  248. `password` varchar(64) NOT NULL default '',
  249. `email` varchar(100) default NULL,
  250. `website` varchar(150) default NULL,
  251. `about` text,
  252. PRIMARY KEY (`id_user`)
  253. ) ENGINE = MYISAM;";
  254. $db->ejecutarConsulta($sqlStr);
  255. $sqlStr = "CREATE TABLE `".Table_prefix."config` (
  256. `posts_limit` int(3) NOT NULL,
  257. `title` varchar(250) NOT NULL,
  258. `description` text NOT NULL,
  259. `lang` varchar(10) NOT NULL,
  260. `template` varchar(100) NOT NULL,
  261. `url_installation` varchar(250) NOT NULL,
  262. PRIMARY KEY (`title`)
  263. ) ENGINE = MYISAM ;";
  264. $db->ejecutarConsulta($sqlStr);
  265. $sqlStr = "CREATE TABLE `".Table_prefix."options` (
  266. `name` varchar(100) NOT NULL,
  267. `val` varchar(255) NOT NULL,
  268. PRIMARY KEY (`name`)
  269. ) ENGINE = MYISAM ;";
  270. $db->ejecutarConsulta($sqlStr);
  271. $sqlStr = "CREATE TABLE `".Table_prefix."comments` (
  272. `id_comment` int(11) NOT NULL auto_increment,
  273. `id_post` int(11) NOT NULL,
  274. `username` varchar(50) NOT NULL,
  275. `email` varchar(100) NOT NULL,
  276. `web` varchar(250) default NULL,
  277. `content` text NOT NULL,
  278. `ip_user` varchar(50) NOT NULL,
  279. `comment_date` datetime NOT NULL,
  280. `spam` tinyint(4) NOT NULL,
  281. PRIMARY KEY (`id_comment`)
  282. ) ENGINE = MYISAM ;";
  283. $db->ejecutarConsulta($sqlStr);
  284. $url_installation = (endsWith($url_installation, "/")) ? substr($url_installation, 0, strlen($url_installation)-1) : $url_installation ;
  285. $sqlStr = "INSERT INTO `".Table_prefix."config` VALUES (".$posts_limit.", '".$title."', '".$description."', '".$lang."', '".$template."', '".$url_installation."');";
  286. $db->ejecutarConsulta($sqlStr);
  287. $sqlStr = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$login."', '".md5($password)."', '".$email."', '".$website."', '".$about."');";
  288. $db->ejecutarConsulta($sqlStr);
  289. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '1');";
  290. $db->ejecutarConsulta($sqlStr);
  291. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
  292. $db->ejecutarConsulta($sqlStr);
  293. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
  294. $db->ejecutarConsulta($sqlStr);
  295. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$offset_city."');";
  296. $db->ejecutarConsulta($sqlStr);
  297. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$offset_time."');";
  298. $db->ejecutarConsulta($sqlStr);
  299. $db->cierraConexion();
  300. return true;
  301. }
  302. function inerrors($errors,$n) {
  303. if (strpos($errors,$n)===false) {
  304. return false;
  305. } else {
  306. return true;
  307. }
  308. }
  309. function mostrarerror($errors,$errors_d,$n) {
  310. if (inerrors($errors,$n)) {
  311. return '<span class="error">'.$errors_d[$n].'</span>';
  312. } else {
  313. return "";
  314. }
  315. }
  316. function is_db_installed(){
  317. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  318. $sqlStr = "SELECT * FROM `".Table_prefix."config`";
  319. $db->ejecutarConsulta($sqlStr);
  320. return ($db->contarRegistros() > 0);
  321. }
  322. ?>