A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
11 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file install/index.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. define('IN_uF',true);
  11. include('./../config.php');
  12. include('./../includes/constants.php');
  13. include('./../includes/errors.php');
  14. include('./../includes/db.php');
  15. include('./functions_add.php');
  16. include('./../admin/check_script_data.php');
  17. if (ini_get('short_open_tag')==0)
  18. {
  19. die('<font color="red" size="4">Please enable <b>short_open_tag</b> in PHP configuration. Aborted!</font>');
  20. }
  21. if(get_magic_quotes_gpc())
  22. {
  23. die('<font color="red" size="4">Please disable <b>magic_quotes_gpc</b> in PHP configuration. Aborted!</font>');
  24. }
  25. if(ini_get('register_globals'))
  26. {
  27. die('<font color="red" size="4">Please disable <b>register_globals</b> in PHP configuration. Aborted!</font>');
  28. }
  29. $count =0;
  30. for($i=0; $i<count($script_files);$i++)
  31. {
  32. $actual = check_size_md5($script_files[$i]);
  33. $rule = $size_md5[$script_files[$i]];
  34. if ($actual!=$rule)
  35. {
  36. $count +=1;
  37. }
  38. }
  39. if (UF_INSTALLED)
  40. {
  41. header('Location: ../index.php');
  42. }
  43. if (!isset($_GET['page']))
  44. {
  45. header('Location: index.php?page=step1');
  46. }
  47. if(!isset($_COOKIE['lang']))
  48. {
  49. $_COOKIE['lang']='Polish';
  50. }
  51. if (@is_file('./../lngs/'.$_COOKIE['lang'].'/install.php'))
  52. {
  53. include('./../lngs/'.$_COOKIE['lang'].'/install.php');
  54. }
  55. $header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  56. <head>
  57. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  58. <title>&micro;Forum Installer</title>
  59. <style type="text/css">
  60. body
  61. {
  62. font-family: Verdana;
  63. font-color: black;
  64. font-size: 11px;
  65. }
  66. </style>
  67. </head>
  68. <body class="body">
  69. <center>
  70. <div align="center" style="width: 748px; background-color: #EBEBEB">
  71. <table class="maintable" width="748">
  72. <tr><td align="center" colspan="2"><font face="Verdana" style="font-size: 24pt"><b>'.$lng['install_header'].'</b></font></td></tr>';
  73. switch($_GET['page'])
  74. {
  75. case 'step1':
  76. {
  77. if (isset($_POST['lang']))
  78. {
  79. setcookie('lang',$_POST['lang'], time()+360000000);
  80. header('Location: index.php?page=step2');
  81. }
  82. else
  83. {
  84. echo $header.'
  85. <tr><td width="748" height="400" align="center">
  86. <span class="fstandard"><b>Select a language:</b>
  87. <form action="index.php?page=step1" method="POST">
  88. <select style="width: 150px" onchange="this.form.submit()" name="lang">
  89. <option value="Polish">&nbsp;</option>
  90. '.AddLangs(false).'
  91. </select></td></tr></table></div></center></body></html>';
  92. }
  93. break;
  94. }
  95. case 'step2':
  96. {
  97. if (isset($_POST['accept']))
  98. {
  99. header('Location: index.php?page=step3');
  100. }
  101. else
  102. {
  103. echo $header.'
  104. <tr><td align="center"><span class="fstandard"><b>'.$lng['licence'].'</b></td></tr>
  105. <tr><td width="748" align="center">
  106. <form action="index.php?page=step2" method="POST">
  107. <iframe width="748" height="500" src="licence.html">
  108. Sorry, you browser doesn\'t support frames</iframe>
  109. <input type="submit" class="fbutton" value="'.$lng['accept_licence'].'"
  110. <input type="hidden" name="accept">
  111. </td></tr></table></div></body></html>';
  112. }
  113. break;
  114. }
  115. case 'step3':
  116. {
  117. if (isset($_POST['next']))
  118. {
  119. header('Location: index.php?page=step4');
  120. }
  121. else
  122. {
  123. $bad = 0;
  124. if (!@is_writable($folders[0])) { $bad =+1; }
  125. if (!@is_writable($folders[1])) { $bad =+1; }
  126. if (!@is_writable($folders[2])) { $bad =+1; }
  127. if (phpversion()<'4.3.10') { $bad=+1; }
  128. if (mysql_get_client_info()<'4.1') { $bad =+1; }
  129. if ($count>1) { $bad =+1; }
  130. echo $header;
  131. $skin=array(
  132. 'L.name'=>$lng['name'],
  133. 'L.value'=>$lng['value'],
  134. 'L.php_version'=>$lng['php_version'],
  135. 'PHP.version'=>phpversion(),
  136. 'PHP.value' => (phpversion()>='5.0.7') ? '<font color="green">OK</font>' : ' <font color="red">Error - No OK</font>',
  137. 'mySQL.version'=>mysql_get_client_info(),
  138. 'L.mySQL_version'=>$lng['mysql_version'],
  139. 'mySQL.value'=>(mysql_get_client_info()>='4.1') ? '<font color="green">OK</font>' : ' <font color="red">Error - No OK</font>',
  140. 'L.cat_name'=>$lng['catalog'],
  141. 'cat1.name'=> $folders[0],
  142. 'cat1.value'=> (@is_writable($folders[0])) ? '<font color="green">'.$lng['is_writable'].' - OK</font>' : '<font color="red">'.$lng['not_writable'].' Error - No OK</font>',
  143. 'cat2.name'=> $folders[1],
  144. 'cat2.value'=> (@is_writable($folders[1])) ? '<font color="green">'.$lng['is_writable'].' - OK</font>' : '<font color="red">'.$lng['not_writable'].' Error - No OK</font>',
  145. 'cat3.name'=> $folders[2],
  146. 'cat3.value'=> (@is_writable($folders[2])) ? '<font color="green">'.$lng['is_writable'].' - OK</font>' : '<font color="red">'.$lng['not_writable'].' Error - No OK</font>',
  147. 'successfully' => ($count <1) ? '<font color="green">'.$lng['files_is_good'].' ('.count($script_files).')</font>' : '<font color="red">'.$lng['files_not_good'].' ('.$count.')</font>'
  148. );
  149. include('./tpls/install_check_script.tpl');
  150. for($i=0; $i<count($script_files);$i++)
  151. {
  152. $actual = check_size_md5($script_files[$i]);
  153. $rule = $size_md5[$script_files[$i]];
  154. if ($actual!=$rule)
  155. {
  156. $skin=array(
  157. 'L.sum_actual'=>$lng['actual_sum'],
  158. 'sum_actual'=>$actual,
  159. 'L.invalid_md5sum'=>$lng['invalid_md5sum'].' ('.substr($script_files[$i], strrpos($script_files[$i], '/') + 1, strlen($script_files[$i])).')'
  160. );
  161. include('./tpls/invalidfile_body.tpl');
  162. }
  163. }
  164. echo '<form action="index.php?page=step3" method="POST"><input type="hidden" name="next">';
  165. if ($bad>0)
  166. {
  167. echo '<input type="button" class="fbutton" value="'.$lng['no_next_page'].'"><br>';
  168. echo '<a href="index.php?page=step4">'.$lng['click_next'].'</a>';
  169. }
  170. else
  171. {
  172. echo '<input type="submit" class="fbutton" value="'.$lng['next_page'].'">';
  173. }
  174. echo '</form>';
  175. }
  176. break;
  177. }
  178. case 'step4':
  179. {
  180. if (isset($_POST['mysql_host'],$_POST['database'],$_POST['mysql_prefix'],$_POST['mysql_user'],$_POST['mysql_pass']))
  181. {
  182. $open = @fopen('../config.php','a+');
  183. $config_file = @fread($open,@filesize('../config.php'));
  184. $config_file = str_replace('%host%',strip_tags($_POST['mysql_host']),$config_file);
  185. $config_file = str_replace('%user%',strip_tags($_POST['mysql_user']),$config_file);
  186. $config_file = str_replace('%pass%',strip_tags($_POST['mysql_pass']),$config_file);
  187. $config_file = str_replace('%dbname%',strip_tags($_POST['database']),$config_file);
  188. $config_file = str_replace('%dbprefix%',strip_tags($_POST['mysql_prefix']),$config_file);
  189. $connect = @mysql_connect($_POST['mysql_host'],$_POST['mysql_user'],$_POST['mysql_pass']) or message_die('GENERAL','Could not connect to database server. Error with installation!',@mysql_error());
  190. @fwrite(@fopen('../config.php','w'),$config_file) or message_die('GENERAL','Could not write config file. Error with installation!','');
  191. @mysql_query("SET NAMES 'utf8'",$connect);
  192. @mysql_select_db($_POST['database'],$connect) or message_die('GENERAL','Could not connect to database. Error with installation!',@mysql_error());
  193. include('./../includes/sql_parse.php');
  194. $sql = @fread(@fopen('uf_tables.sql','r'),@filesize('uf_tables.sql'));
  195. $sql = preg_replace('/uf_/', $_POST['mysql_prefix'], $sql);
  196. $sql = remove_remarks($sql);
  197. $sql = split_sql_file($sql);
  198. for ($i=0;$i<count($sql);$i++)
  199. {
  200. DataBase::sql_query($sql[$i],'ERROR','Error of SQL Query: '.$sql[$i].' Error with install script!');
  201. }
  202. DataBase::sql_query("UPDATE `".$_POST['mysql_prefix']."config` SET `value`='".time()."' WHERE `name`='date_install'",'GENERAL','Could not update date install information');
  203. $patch = substr('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],0 ,-strlen('install/index.php?page=step4'));
  204. DataBase::sql_query("UPDATE `".$_POST['mysql_prefix']."config` SET `value`='".$patch."' WHERE `name`='forumpatch'",'GENERAL','Could not update date install information');
  205. header('Location: index.php?page=step5');
  206. }
  207. else
  208. {
  209. if (!isset($_POST['database'])) { $_POST['database']=''; }
  210. if (!isset($_POST['mysql_user'])) { $_POST['mysql_user']=''; }
  211. if (!isset($_POST['mysql_pass'])) { $_POST['mysql_pass']=''; }
  212. }
  213. echo $header;
  214. $skin = array(
  215. 'L.mysql_host'=>$lng['mysql_host'],
  216. 'L.mysql_user'=>$lng['mysql_user'],
  217. 'L.database'=>$lng['db_name'],
  218. 'L.mysql_pass'=>$lng['mysql_pass'],
  219. 'L.mysql_prefix'=>$lng['mysql_prefix'],
  220. 'L.submit'=>$lng['start_install'],
  221. );
  222. include('./tpls/install_step4.tpl');
  223. break;
  224. }
  225. case 'step5':
  226. {
  227. echo $header.'<tr><td class="fitem" align="center"><span class="fstandard">'.$lng['install_complete'].'</span></td></tr></table><meta http-equiv="refresh" content="1.5; url=index.php?page=step6"></body></html>';
  228. break;
  229. }
  230. case 'step6':
  231. {
  232. DataBase::db_connect();
  233. if (isset($_POST['user_name'],$_POST['password'],$_POST['retype_password'],$_POST['email']))
  234. {
  235. if ($_POST['password']==$_POST['retype_password'])
  236. {
  237. if (ereg("^.+@.+\..+$", $_POST['email']))
  238. {
  239. $sql = "UPDATE `".USERS_TABLE."` SET
  240. `nick`='".htmlspecialchars($_POST['user_name'])."',
  241. `pass`='".md5(htmlspecialchars($_POST['password']))."',
  242. `email`='".htmlspecialchars($_POST['email'])."',
  243. `lang`= '".$_COOKIE['lang']."',
  244. `regdate`='".time()."',
  245. `lastvisit`='".time()."'
  246. WHERE `u_id`='1';";
  247. DataBase::sql_query($sql,'CRITICAL','Could not update user. Error with install script!');
  248. $sql = "UPDATE `".POSTS_TABLE."` SET `ptime`='".time()."' WHERE `p_id`='1'";
  249. DataBase::sql_query($sql,'CRITICAL','Could not update post. Error with install script!');
  250. $sql = "UPDATE `".TOPICS_TABLE."` SET `lastpost_time`='".time()."' WHERE `t_id`='1'";
  251. DataBase::sql_query($sql,'CRITICAL','Could not update topic. Error with install script!');
  252. header('Location: index.php?page=step7');
  253. }
  254. else
  255. {
  256. alert($lng['invalid_email']);
  257. }
  258. }
  259. else
  260. {
  261. alert($lng['invalid_passwords']);
  262. }
  263. }
  264. else
  265. {
  266. if (!isset($_POST['user_name'])) { $_POST['user_name'] = ''; }
  267. if (!isset($_POST['email'])) { $_POST['email'] = ''; }
  268. $_POST['password'] = '';
  269. $_POST['retype_password'] = '';
  270. }
  271. echo $header;
  272. $skin = array(
  273. 'L.user_name'=>$lng['user_name'],
  274. 'L.password'=>$lng['password'],
  275. 'L.retype_password'=>$lng['retype_password'],
  276. 'L.email'=>$lng['email'],
  277. 'L.submit'=>$lng['save']
  278. );
  279. include('./tpls/install_step6.tpl');
  280. break;
  281. }
  282. case 'step7':
  283. {
  284. $open = @fopen('../config.php','a+');
  285. $config_file = @fread($open,@filesize('../config.php'));
  286. $config_file = str_replace('false','true',$config_file);
  287. @fwrite(@fopen('../config.php','w'),$config_file) or message_die('GENERAL','Could not write config file. Error with installation!','');
  288. echo $header.'<tr><td class="fitem" align="center"><span class="fstandard">'.$lng['info_2'].'</span></td></tr></table><meta http-equiv="refresh" content="4; url=../index.php"></body></html>';
  289. break;
  290. }
  291. }
  292. ?>