PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/install.php

http://avecms.googlecode.com/
PHP | 279 lines | 218 code | 52 blank | 9 comment | 45 complexity | db074edd5d09873db02d2af515b725ef MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * AVE.cms
  4. *
  5. * @package AVE.cms
  6. * @filesource
  7. */
  8. /**
  9. * @subpackage install
  10. */
  11. error_reporting(E_ALL ^ E_NOTICE);
  12. global $config, $lang_i;
  13. ob_start();
  14. define('SETUP', 1);
  15. define('BASE_DIR', str_replace("\\", "/", dirname(__FILE__)));
  16. include(BASE_DIR . '/data/lang/ru.php');
  17. if (!is_writable(BASE_DIR . '/templates_c/')) die($lang_i['templates_c_notwritable']);
  18. include(BASE_DIR . '/inc/db.config.php');
  19. include(BASE_DIR . '/inc/config.php');
  20. include(BASE_DIR . '/functions/func.common.php');
  21. include(BASE_DIR . '/class/class.template.php');
  22. $AVE_Template = new AVE_Template(BASE_DIR . '/data/tpl/');
  23. $ver = APP_NAME . ' ' . APP_VERSION;
  24. $AVE_Template->assign('version_setup', $lang_i['install_name'] . ' ' . $ver);
  25. $AVE_Template->assign('app_info', APP_INFO);
  26. $AVE_Template->assign('la', $lang_i);
  27. function check_db_connect($dbhost = '', $dbuser = '', $dbpass = '', $dbname = '')
  28. {
  29. if ($dbhost != '' && $dbuser != '' && $dbname != '')
  30. {
  31. if (@mysql_select_db($dbname, @mysql_connect($dbhost, $dbuser, $dbpass))) return true;
  32. }
  33. return false;
  34. }
  35. $db_connect = check_db_connect($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']);
  36. function check_installed()
  37. {
  38. global $config, $lang_i;
  39. $query = @mysql_query("SELECT 1 FROM " . $config['dbpref'] . "_users LIMIT 1");
  40. if (@mysql_num_rows($query)) {echo '<pre>' . $lang_i['installed'] . '</pre>'; exit;}
  41. }
  42. if ($db_connect && $_REQUEST['step'] != 'finish') check_installed();
  43. $error_is_required = array();
  44. function check_required()
  45. {
  46. global $error_is_required, $lang_i;
  47. $required_php = 423;
  48. $required = array();
  49. $required[] = '/data/eula/ru.tpl';
  50. foreach ($required as $is_required)
  51. {
  52. if (@!is_file(BASE_DIR . $is_required))
  53. {
  54. array_push($error_is_required, $lang_i['error_is_required'] . $is_required . $lang_i['error_is_required_2'] );
  55. }
  56. }
  57. $myphp = @PHP_VERSION;
  58. if ($myphp)
  59. {
  60. $myphp_v = str_replace('.', '', $myphp);
  61. if ($myphp_v < $required_php)
  62. {
  63. array_push($error_is_required, $lang_i['phpversion_toold'] . $required_php);
  64. }
  65. }
  66. }
  67. check_required();
  68. function check_writable()
  69. {
  70. global $error_is_required, $lang_i;
  71. $writeable = array();
  72. $writeable[] = '/attachments/';
  73. $writeable[] = '/cache/';
  74. $writeable[] = '/uploads/';
  75. $writeable[] = '/inc/db.config.php';
  76. foreach ($writeable as $must_writeable)
  77. {
  78. if (!is_writable(BASE_DIR . $must_writeable))
  79. {
  80. array_push($error_is_required, $lang_i['error_is_writeable'] . $must_writeable . $lang_i['error_is_writeable_2'] );
  81. }
  82. }
  83. }
  84. check_writable();
  85. $count_error = sizeof((array) $error_is_required);
  86. if (1 == $count_error)
  87. {
  88. $AVE_Template->assign('error_header', $lang_i['erroro']);
  89. }
  90. elseif ($count_error > 1)
  91. {
  92. $AVE_Template->assign('error_header', $lang_i['erroro_more']);
  93. }
  94. if ($count_error > 0 && ! (isset($_REQUEST['force']) && 1 == $_REQUEST['force']))
  95. {
  96. $AVE_Template->assign('error_is_required', $error_is_required);
  97. $AVE_Template->display('error.tpl');
  98. exit;
  99. }
  100. $_REQUEST['step'] = isset($_REQUEST['step']) ? $_REQUEST['step'] : '';
  101. switch ($_REQUEST['step'])
  102. {
  103. case '' :
  104. case '1' :
  105. $AVE_Template->display('step1.tpl');
  106. break;
  107. case '2' :
  108. if (false === $db_connect && !empty($_POST['dbname']) && !empty($_POST['dbprefix']))
  109. {
  110. $db_connect = check_db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname']);
  111. if (true === $db_connect)
  112. {
  113. if (! @is_writeable(BASE_DIR . '/inc/db.config.php'))
  114. {
  115. $AVE_Template->assign('config_isnt_writeable', 1);
  116. $AVE_Template->display('error.tpl');
  117. exit;
  118. }
  119. $fp = @fopen(BASE_DIR . '/inc/db.config.php', 'w+');
  120. @fwrite($fp, "<?php\n"
  121. . "\$config['dbhost'] = \"" . stripslashes(trim($_POST['dbhost'])) . "\";\n"
  122. . "\$config['dbuser'] = \"" . stripslashes(trim($_POST['dbuser'])) . "\";\n"
  123. . "\$config['dbpass'] = \"" . stripslashes(trim($_POST['dbpass'])) . "\";\n"
  124. . "\$config['dbname'] = \"" . stripslashes(trim($_POST['dbname'])) . "\";\n"
  125. . "\$config['dbpref'] = \"" . stripslashes(trim($_POST['dbprefix'])) . "\";\n"
  126. . "?>"
  127. );
  128. @fclose($fp);
  129. $AVE_Template->display('step3.tpl');
  130. exit;
  131. }
  132. else
  133. {
  134. $AVE_Template->assign('warnnodb', $lang_i['enoconn']);
  135. }
  136. }
  137. else
  138. {
  139. $dbpref = make_random_string(5, 'abcdefghijklmnopqrstuvwxyz0123456789');
  140. $AVE_Template->assign('dbpref', $dbpref);
  141. }
  142. $AVE_Template->display('step2.tpl');
  143. break;
  144. case '3' :
  145. if (true === $db_connect)
  146. {
  147. if (isset($_POST['demo']) && 1 == $_POST['demo'])
  148. {
  149. $filename = BASE_DIR . '/data/structure_demo.sql';
  150. }
  151. else
  152. {
  153. $filename = BASE_DIR . '/data/structure_base.sql';
  154. $_REQUEST['demo'] = '0';
  155. }
  156. $handle = fopen($filename, 'r');
  157. $db_structure = fread($handle, filesize($filename));
  158. fclose($handle);
  159. $db_structure = str_replace('%%PRFX%%', $config['dbpref'], $db_structure);
  160. $ar = explode('#inst#', $db_structure);
  161. foreach ($ar as $in)
  162. {
  163. @mysql_query($in);
  164. }
  165. $AVE_Template->display('step4.tpl');
  166. exit;
  167. }
  168. $AVE_Template->display('step3.tpl');
  169. break;
  170. case '4' :
  171. $_POST['email'] = chop($_POST['email']);
  172. $_POST['username'] = chop($_POST['username']);
  173. $regex_username = '/[^\w-]/';
  174. $regex_password = '/[^\x20-\xFF]/';
  175. $regex_email = '/^[\w.-]+@[a-z0-9.-]+\.(?:[a-z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$/i';
  176. $errors = array();
  177. if ($_POST['email'] == '') array_push($errors, $lang_i['noemail']);
  178. if (! preg_match($regex_email, $_POST['email'])) array_push($errors, $lang_i['email_no_specialchars']);
  179. if (empty($_POST['pass']) || preg_match($regex_password, $_POST['pass'])) array_push($errors, $lang_i['check_pass']);
  180. if (strlen($_POST['pass']) < 5) array_push($errors, $lang_i['pass_too_small']);
  181. if (empty($_POST['username']) || preg_match($regex_username, $_POST['username'])) array_push($errors, $lang_i['check_username']);
  182. if (true === $db_connect && ! sizeof($errors))
  183. {
  184. if (isset($_POST['demo']) && 1 == $_POST['demo'])
  185. {
  186. $filename = BASE_DIR . '/data/data_demo.sql';
  187. }
  188. else
  189. {
  190. $filename = BASE_DIR . '/data/data_base.sql';
  191. }
  192. $handle = fopen($filename, 'r');
  193. $dbin = fread($handle, filesize($filename));
  194. fclose($handle);
  195. $salt = make_random_string();
  196. $hash = md5(md5($_POST['pass'] . $salt));
  197. $dbin = str_replace('%%SITENAME%%', $ver, $dbin);
  198. $dbin = str_replace('%%PRFX%%', $config['dbpref'], $dbin);
  199. $dbin = str_replace('%%EMAIL%%', $_POST['email'], $dbin);
  200. $dbin = str_replace('%%SALT%%', $salt, $dbin);
  201. $dbin = str_replace('%%PASS%%', $hash, $dbin);
  202. $dbin = str_replace('%%ZEIT%%', time(), $dbin);
  203. $dbin = str_replace('%%VORNAME%%', $_POST['firstname'], $dbin);
  204. $dbin = str_replace('%%NACHNAME%%', $_POST['lastname'], $dbin);
  205. $dbin = str_replace('%%USERNAME%%', $_POST['username'], $dbin);
  206. $dbin = str_replace('%%FON%%', $_POST['fon'], $dbin);
  207. $dbin = str_replace('%%FAX%%', $_POST['fax'], $dbin);
  208. $dbin = str_replace('%%PLZ%%', $_POST['zip'], $dbin);
  209. $dbin = str_replace('%%ORT%%', $_POST['town'], $dbin);
  210. $dbin = str_replace('%%STRASSE%%', $_POST['street'], $dbin);
  211. $dbin = str_replace('%%HNR%%', $_POST['hnr'], $dbin);
  212. $ar = explode('#inst#', $dbin);
  213. foreach ($ar as $in)
  214. {
  215. @mysql_query("SET NAMES 'utf8'");
  216. @mysql_query("SET COLLATION_CONNECTION = 'utf8_general_ci'");
  217. mysql_query($in);
  218. }
  219. $auth = base64_encode(serialize(array('id'=>'1', 'hash'=>$hash)));
  220. @setcookie('auth', $auth);
  221. $AVE_Template->display('step5.tpl');
  222. exit;
  223. }
  224. $AVE_Template->display('step4.tpl');
  225. break;
  226. }
  227. ?>