PageRenderTime 96ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/install/index.php

http://viet-group.googlecode.com/
PHP | 719 lines | 634 code | 61 blank | 24 comment | 107 complexity | f35dacaf74ced13b4f4993c1271dc47f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-1-2010 22:42
  7. */
  8. define( 'NV_ADMIN', true );
  9. require_once ( 'mainfile.php' );
  10. $file_config_temp = NV_TEMP_DIR . "/config_" . md5( $global_config['sitekey'] ) . ".php";
  11. $dirs = nv_scandir( NV_ROOTDIR . "/language", "/^([a-z]{2})/" );
  12. $languageslist = array();
  13. foreach ( $dirs as $file )
  14. {
  15. if ( is_file( NV_ROOTDIR . '/language/' . $file . '/install.php' ) )
  16. {
  17. $languageslist[] = $file;
  18. }
  19. }
  20. require_once ( NV_ROOTDIR . "/modules/users/language/" . NV_LANG_DATA . ".php" );
  21. require_once ( NV_ROOTDIR . "/language/" . NV_LANG_DATA . "/install.php" );
  22. require_once ( NV_ROOTDIR . "/install/template.php" );
  23. require_once ( NV_ROOTDIR . "/includes/core/admin_functions.php" );
  24. if ( is_file( NV_ROOTDIR . '/' . $file_config_temp ) )
  25. {
  26. require_once ( NV_ROOTDIR . '/' . $file_config_temp );
  27. //Bat dau phien lam viec cua MySQL
  28. require_once ( NV_ROOTDIR . '/includes/class/mysql.class.php' );
  29. $db_config['new_link'] = NV_MYSQL_NEW_LINK;
  30. $db_config['persistency'] = NV_MYSQL_PERSISTENCY;
  31. }
  32. $contents = "";
  33. $step = $nv_Request->get_int( 'step', 'post,get', 1 );
  34. $maxstep = $nv_Request->get_int( 'maxstep', 'session', 1 );
  35. if ( $step <= 0 or $step > 7 )
  36. {
  37. Header( "Location: " . NV_BASE_SITEURL . "install/index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=1" );
  38. exit();
  39. }
  40. if ( $step > $maxstep )
  41. {
  42. $step = $maxstep;
  43. Header( "Location: " . NV_BASE_SITEURL . "install/index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step );
  44. exit();
  45. }
  46. if ( file_exists( NV_ROOTDIR . "/" . NV_CONFIG_FILENAME ) and $step < 7 )
  47. {
  48. Header( "Location: " . NV_BASE_SITEURL . "index.php" );
  49. exit();
  50. }
  51. if ( $step == 1 )
  52. {
  53. if ( $step < 2 )
  54. {
  55. $nv_Request->set_Session( 'maxstep', 2 );
  56. }
  57. $title = $lang_module['select_language'];
  58. $contents = nv_step_1();
  59. }
  60. elseif ( $step == 2 )
  61. {
  62. if ( $step < 3 )
  63. {
  64. $nv_Request->set_Session( 'maxstep', 3 );
  65. }
  66. $title = $lang_module['license'];
  67. if ( file_exists( NV_ROOTDIR . "/install/licenses_" . NV_LANG_DATA . ".html" ) )
  68. {
  69. $license = file_get_contents( NV_ROOTDIR . "/install/licenses_" . NV_LANG_DATA . ".html" );
  70. }
  71. else
  72. {
  73. $license = file_get_contents( NV_ROOTDIR . "/install/licenses.html" );
  74. }
  75. $contents = nv_step_2( $license );
  76. }
  77. elseif ( $step == 3 )
  78. {
  79. $nextstep = 1;
  80. $title = $lang_module['check_server'];
  81. $array_resquest = array();
  82. $array_resquest_key = array( 'php_support', 'mysql_support', 'opendir_support', 'gd_support', 'session_support', 'fileuploads_support' );
  83. foreach ( $array_resquest_key as $key )
  84. {
  85. $array_resquest[$key] = ( $sys_info[$key] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  86. if ( ! $sys_info[$key] )
  87. {
  88. $nextstep = 0;
  89. }
  90. }
  91. if ( $step < 4 and $nextstep == 1 )
  92. {
  93. $nv_Request->set_Session( 'maxstep', 4 );
  94. }
  95. $array_suport = array();
  96. $array_support['supports_rewrite'] = ( empty( $sys_info['supports_rewrite'] ) ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  97. $array_support['safe_mode'] = ( $sys_info['safe_mode'] ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  98. $array_support['register_globals'] = ( ini_get( 'register_globals' ) == '1' || strtolower( ini_get( 'register_globals' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  99. $array_support['magic_quotes_runtime'] = ( ini_get( 'magic_quotes_runtime' ) == '1' || strtolower( ini_get( 'magic_quotes_runtime' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  100. $array_support['magic_quotes_gpc'] = ( ini_get( 'magic_quotes_gpc' ) == '1' || strtolower( ini_get( 'magic_quotes_gpc' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  101. $array_support['magic_quotes_sybase'] = ( ini_get( 'magic_quotes_sybase' ) == '1' || strtolower( ini_get( 'magic_quotes_sybase' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  102. $array_support['output_buffering'] = ( ini_get( 'output_buffering' ) == '1' || strtolower( ini_get( 'output_buffering' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  103. $array_support['session_auto_start'] = ( ini_get( 'session.auto_start' ) == '1' || strtolower( ini_get( 'session.auto_start' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  104. $array_support['display_errors'] = ( ini_get( 'display_errors' ) == '1' || strtolower( ini_get( 'display_errors' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  105. $array_support['allowed_set_time_limit'] = ( $sys_info['allowed_set_time_limit'] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  106. $array_support['zlib_support'] = ( $sys_info['zlib_support'] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  107. $array_support['zip_support'] = ( extension_loaded( 'zip' ) ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  108. $contents = nv_step_3( $array_resquest, $array_support, $nextstep );
  109. }
  110. elseif ( $step == 4 )
  111. {
  112. $array_dir = array( NV_SESSION_SAVE_PATH, NV_LOGS_DIR, NV_LOGS_DIR . "/data_logs", NV_LOGS_DIR . "/dump_backup", NV_LOGS_DIR . "/error_logs", NV_LOGS_DIR . "/error_logs/errors256", NV_LOGS_DIR . "/error_logs/old", NV_LOGS_DIR . "/error_logs/tmp", NV_LOGS_DIR . "/ip_logs", NV_LOGS_DIR . "/ref_logs", NV_LOGS_DIR . "/voting_logs", NV_CACHEDIR, NV_UPLOADS_DIR, NV_TEMP_DIR, NV_FILES_DIR, NV_FILES_DIR . "/css", NV_FILES_DIR . "/js", NV_DATADIR );
  113. $array_file_data = nv_scandir( NV_ROOTDIR . "/" . NV_DATADIR, "/^([a-zA-Z0-9\-\_\.]+)\.([a-z0-9]{2,6})$/" );
  114. foreach ( $array_file_data as $file_i )
  115. {
  116. $array_dir[] = NV_DATADIR . "/" . $file_i;
  117. }
  118. $array_dir[] = $file_config_temp;
  119. if ( ! empty( $sys_info['supports_rewrite'] ) )
  120. {
  121. if ( $sys_info['supports_rewrite'] == "rewrite_mode_apache" )
  122. {
  123. $array_dir[] = ".htaccess";
  124. }
  125. else
  126. {
  127. $array_dir[] = "web.config";
  128. }
  129. }
  130. $ftp_check_login = 0;
  131. $global_config['ftp_server'] = $nv_Request->get_string( 'ftp_server', 'post', 'localhost' );
  132. $global_config['ftp_port'] = $nv_Request->get_int( 'ftp_port', 'post', 21 );
  133. $global_config['ftp_user_name'] = $nv_Request->get_string( 'ftp_user_name', 'post', '' );
  134. $global_config['ftp_user_pass'] = $nv_Request->get_string( 'ftp_user_pass', 'post', '' );
  135. $global_config['ftp_path'] = $nv_Request->get_string( 'ftp_path', 'post', '/' );
  136. $array_ftp_data = array( 'ftp_server' => $global_config['ftp_server'], 'ftp_port' => $global_config['ftp_port'], 'ftp_user_name' => $global_config['ftp_user_name'], 'ftp_user_pass' => $global_config['ftp_user_pass'], 'ftp_path' => $global_config['ftp_path'], 'error' => '' );
  137. $modftp = $nv_Request->get_int( 'modftp', 'post', 0 );
  138. if ( $modftp )
  139. {
  140. if ( ! empty( $global_config['ftp_server'] ) and ! empty( $global_config['ftp_user_name'] ) and ! empty( $global_config['ftp_user_pass'] ) )
  141. {
  142. // set up basic connection
  143. $conn_id = ftp_connect( $global_config['ftp_server'], $global_config['ftp_port'] );
  144. // login with username and password
  145. $login_result = ftp_login( $conn_id, $global_config['ftp_user_name'], $global_config['ftp_user_pass'] );
  146. if ( ( ! $conn_id ) || ( ! $login_result ) )
  147. {
  148. $ftp_check_login = 3;
  149. $array_ftp_data['error'] = $lang_module['ftp_error_account'];
  150. }
  151. elseif ( ftp_chdir( $conn_id, $global_config['ftp_path'] ) )
  152. {
  153. $check_files = array( NV_CACHEDIR, NV_DATADIR, "images", "includes", "index.php", "js", "language", NV_LOGS_DIR, "mainfile.php", "modules", NV_SESSION_SAVE_PATH, "themes", NV_TEMP_DIR, NV_UPLOADS_DIR );
  154. $list_files = ftp_nlist( $conn_id, "." );
  155. $a = 0;
  156. foreach ( $list_files as $filename )
  157. {
  158. $filename = basename( $filename );
  159. if ( in_array( $filename, $check_files ) )
  160. {
  161. $a ++;
  162. }
  163. }
  164. if ( $a == count( $check_files ) )
  165. {
  166. $ftp_check_login = 1;
  167. nv_chmod_dir( $conn_id, NV_DATADIR, true );
  168. nv_chmod_dir( $conn_id, NV_TEMP_DIR, true );
  169. nv_save_file_config();
  170. nv_chmod_dir( $conn_id, NV_TEMP_DIR, true );
  171. }
  172. else
  173. {
  174. $ftp_check_login = 2;
  175. $array_ftp_data['error'] = $lang_module['ftp_error_path'];
  176. }
  177. }
  178. else
  179. {
  180. $ftp_check_login = 2;
  181. $array_ftp_data['error'] = $lang_module['ftp_error_path'];
  182. }
  183. $global_config['ftp_check_login'] = $ftp_check_login;
  184. }
  185. }
  186. $nextstep = 1;
  187. $array_dir_check = array();
  188. foreach ( $array_dir as $dir )
  189. {
  190. if ( $ftp_check_login == 1 )
  191. {
  192. if ( ! is_dir( NV_ROOTDIR . '/' . $dir ) and $dir != $file_config_temp )
  193. {
  194. ftp_mkdir( $conn_id, $dir );
  195. }
  196. if ( ! is_writable( NV_ROOTDIR . '/' . $dir ) )
  197. {
  198. if ( substr( $sys_info['os'], 0, 3 ) != 'WIN' ) ftp_chmod( $conn_id, 0777, $dir );
  199. }
  200. }
  201. if ( $dir == $file_config_temp and ! file_exists( NV_ROOTDIR . '/' . $file_config_temp ) and is_writable( NV_ROOTDIR . '/' . NV_TEMP_DIR ) )
  202. {
  203. file_put_contents( NV_ROOTDIR . '/' . $file_config_temp, '', LOCK_EX );
  204. }
  205. if ( is_file( NV_ROOTDIR . '/' . $dir ) )
  206. {
  207. if ( is_writable( NV_ROOTDIR . '/' . $dir ) )
  208. {
  209. $array_dir_check[$dir] = $lang_module['dir_writable'];
  210. }
  211. else
  212. {
  213. $array_dir_check[$dir] = $lang_module['dir_not_writable'];
  214. $nextstep = 0;
  215. }
  216. }
  217. elseif ( is_dir( NV_ROOTDIR . '/' . $dir ) )
  218. {
  219. if ( is_writable( NV_ROOTDIR . '/' . $dir ) )
  220. {
  221. $array_dir_check[$dir] = $lang_module['dir_writable'];
  222. }
  223. else
  224. {
  225. $array_dir_check[$dir] = $lang_module['dir_not_writable'];
  226. $nextstep = 0;
  227. }
  228. }
  229. else
  230. {
  231. $array_dir_check[$dir] = $lang_module['dir_noexit'];
  232. $nextstep = 0;
  233. }
  234. }
  235. if ( ! nv_save_file_config( $db_config, $global_config ) and $ftp_check_login == 1 )
  236. {
  237. ftp_chmod( $conn_id, 0777, $file_config_temp );
  238. }
  239. if ( $ftp_check_login > 0 )
  240. {
  241. ftp_close( $conn_id );
  242. }
  243. if ( $step < 5 and $nextstep == 1 )
  244. {
  245. $nv_Request->set_Session( 'maxstep', 5 );
  246. }
  247. $title = $lang_module['check_chmod'];
  248. $contents = nv_step_4( $array_dir_check, $array_ftp_data, $nextstep );
  249. }
  250. elseif ( $step == 5 )
  251. {
  252. $nextstep = 0;
  253. $db_config['dbport'] = "";
  254. $db_config['error'] = "";
  255. $db_config['dbhost'] = $nv_Request->get_string( 'dbhost', 'post', $db_config['dbhost'] );
  256. $db_config['dbname'] = $nv_Request->get_string( 'dbname', 'post', $db_config['dbname'] );
  257. $db_config['dbuname'] = $nv_Request->get_string( 'dbuname', 'post', $db_config['dbuname'] );
  258. $db_config['dbpass'] = $nv_Request->get_string( 'dbpass', 'post', $db_config['dbpass'] );
  259. $db_config['prefix'] = $nv_Request->get_string( 'prefix', 'post', 'nv3' );
  260. $db_config['db_detete'] = $nv_Request->get_int( 'db_detete', 'post', '0' );
  261. $db_config['num_table'] = 0;
  262. $db_config['create_db'] = 1;
  263. $db_config['prefix'] = preg_replace( '/(\W+)/i', '_', $db_config['prefix'] );
  264. if ( ! empty( $db_config['dbhost'] ) and ! empty( $db_config['dbname'] ) and ! empty( $db_config['dbuname'] ) and ! empty( $db_config['prefix'] ) )
  265. {
  266. $db = new sql_db( $db_config );
  267. if ( ! empty( $db->error ) )
  268. {
  269. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  270. }
  271. else
  272. {
  273. $tables = array();
  274. $result = $db->sql_query( "SHOW TABLE STATUS LIKE '" . $db_config['prefix'] . "\_%'" );
  275. $num_table = intval( $db->sql_numrows( $result ) );
  276. if ( $num_table > 0 )
  277. {
  278. if ( $db_config['db_detete'] == 1 )
  279. {
  280. while ( $item = $db->sql_fetch_assoc( $result ) )
  281. {
  282. $db->sql_query( "DROP TABLE `" . $item['Name'] . "`" );
  283. }
  284. $num_table = 0;
  285. }
  286. else
  287. {
  288. $db_config['error'] = $lang_module['db_err_prefix'];
  289. }
  290. }
  291. $db_config['num_table'] = $num_table;
  292. if ( $num_table == 0 )
  293. {
  294. nv_save_file_config();
  295. $db_config['error'] = "";
  296. $sql_create_table = array();
  297. //cai dat du lieu cho he thong
  298. require_once ( NV_ROOTDIR . "/install/data.php" );
  299. foreach ( $sql_create_table as $query )
  300. {
  301. if ( ! $db->sql_query( $query ) )
  302. {
  303. $nv_Request->set_Session( 'maxstep', 1 );
  304. die( $query );
  305. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  306. break;
  307. }
  308. }
  309. //Het cai dat du lieu cho he thong
  310. //Cai dat du lieu cho cac module
  311. if ( empty( $db_config['error'] ) )
  312. {
  313. define( 'NV_IS_MODADMIN', true );
  314. $module_name = "modules";
  315. $lang_module['modules'] = "";
  316. $lang_module['vmodule_add'] = "";
  317. $lang_module['autoinstall'] = "";
  318. $lang_global['mod_modules'] = "";
  319. require_once ( NV_ROOTDIR . "/" . NV_ADMINDIR . "/modules/modules/functions.php" );
  320. $module_name = "";
  321. require_once ( NV_ROOTDIR . '/includes/sqldata.php' );
  322. $modules_exit = nv_scandir( NV_ROOTDIR . "/modules", $global_config['check_module'] );
  323. $modules_exit[] = 'global';
  324. //cai dat du lieu cho ngon ngu
  325. $sql_create_table = nv_create_table_sys( NV_LANG_DATA );
  326. foreach ( $sql_create_table as $query )
  327. {
  328. if ( ! $db->sql_query( $query ) )
  329. {
  330. $nv_Request->set_Session( 'maxstep', 1 );
  331. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  332. break;
  333. }
  334. }
  335. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . NV_LANG_DATA . "_modules` ORDER BY `weight` ASC";
  336. $result = $db->sql_query( $sql );
  337. while ( $row = $db->sql_fetchrow( $result ) )
  338. {
  339. $setmodule = $row['title'];
  340. if ( in_array( $row['module_file'], $modules_exit ) )
  341. {
  342. $sm = nv_setup_data_module( NV_LANG_DATA, $setmodule );
  343. if ( $sm != "OK_" . $setmodule )
  344. {
  345. die( "error set module: " . $setmodule );
  346. }
  347. }
  348. else
  349. {
  350. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . NV_LANG_DATA . "_modules` WHERE `title`=" . $db->dbescape( $setmodule );
  351. $db->sql_query( $sql );
  352. }
  353. }
  354. //cai dat du lieu mau
  355. $filesavedata = NV_LANG_DATA;
  356. $lang_data = NV_LANG_DATA;
  357. if ( ! file_exists( NV_ROOTDIR . "/install/data_" . $lang_data . ".php" ) )
  358. {
  359. $filesavedata = "en";
  360. }
  361. include_once ( NV_ROOTDIR . "/install/data_" . $filesavedata . ".php" );
  362. foreach ( $sql_create_table as $query )
  363. {
  364. if ( ! $db->sql_query( $query ) )
  365. {
  366. $nv_Request->set_Session( 'maxstep', 1 );
  367. die( $query );
  368. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  369. break;
  370. }
  371. }
  372. //xoa du lieu tai bang nv3_vi_blocks
  373. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_weight` WHERE `bid` in (SELECT `bid` FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_groups` WHERE `module` NOT IN ('" . implode( "', '", $modules_exit ) . "'))";
  374. $db->sql_query( $sql );
  375. //xoa du lieu tai bang nv3_vi_blocks_groups
  376. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_groups` WHERE `module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  377. $db->sql_query( $sql );
  378. //xoa du lieu tai bang nv3_vi_modthemes
  379. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modthemes` WHERE `func_id` in (SELECT `func_id` FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modfuncs` WHERE `in_module` NOT IN ('" . implode( "', '", $modules_exit ) . "'))";
  380. $db->sql_query( $sql );
  381. //xoa du lieu tai bang nv3_vi_modfuncs
  382. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modfuncs` WHERE `in_module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  383. $db->sql_query( $sql );
  384. //xoa du lieu tai bang nv3_vi_modules
  385. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modules` WHERE `title` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  386. $db->sql_query( $sql );
  387. //xoa du lieu tai bang nv3_setup_modules
  388. $sql = "DELETE FROM `" . $db_config['prefix'] . "_setup_modules` WHERE `title` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  389. $db->sql_query( $sql );
  390. ///xoa du lieu tai bang nv3_config
  391. $sql = "DELETE FROM `" . $db_config['prefix'] . "_config` WHERE `lang`=" . $db->dbescape( $lang_data ) . " AND `module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  392. $db->sql_query( $sql );
  393. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . NV_LANG_DATA . "_modules` WHERE `title`='news'";
  394. $result = $db->sql_query( $sql );
  395. if ( $db->sql_numrows( $result ) )
  396. {
  397. $result = $db->sql_query( "SELECT catid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_cat` ORDER BY `order` ASC" );
  398. while ( list( $catid_i ) = $db->sql_fetchrow( $result ) )
  399. {
  400. nv_create_table_news( $catid_i );
  401. }
  402. $db->sql_freeresult();
  403. $result = $db->sql_query( "SELECT id, listcatid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` ORDER BY `id` ASC" );
  404. while ( list( $id, $listcatid ) = $db->sql_fetchrow( $result ) )
  405. {
  406. $arr_catid = explode( ",", $listcatid );
  407. foreach ( $arr_catid as $catid )
  408. {
  409. $db->sql_query( "INSERT INTO `" . $db_config['prefix'] . "_" . $lang_data . "_news_" . $catid . "` SELECT * FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` WHERE `id`=" . $id . "" );
  410. }
  411. }
  412. $db->sql_freeresult();
  413. }
  414. $step ++;
  415. $nv_Request->set_Session( 'maxstep', $step );
  416. Header( "Location: " . NV_BASE_SITEURL . "install/index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step );
  417. exit();
  418. }
  419. // Het cai dat du lieu cho cac module
  420. }
  421. }
  422. }
  423. $title = $lang_module['config_database'];
  424. $contents = nv_step_5( $db_config, $nextstep );
  425. }
  426. elseif ( $step == 6 )
  427. {
  428. $nextstep = 0;
  429. $array_data = array();
  430. $error = $site_name = $login = $email = $password = $re_password = "";
  431. if ( $nv_Request->isset_request( 'nv_login,nv_password', 'post' ) )
  432. {
  433. $site_name = filter_text_input( 'site_name', 'post', '', 1 );
  434. $login = filter_text_input( 'nv_login', 'post', '', 1, NV_UNICKMAX );
  435. $email = filter_text_input( 'nv_email', 'post', '' );
  436. $password = filter_text_input( 'nv_password', 'post', '' );
  437. $re_password = filter_text_input( 're_password', 'post', '' );
  438. $check_login = nv_check_valid_login( $login, NV_UNICKMAX, NV_UNICKMIN );
  439. $check_pass = nv_check_valid_pass( $password, NV_UPASSMAX, NV_UPASSMIN );
  440. $check_email = nv_check_valid_email( $email );
  441. $question = filter_text_input( 'question', 'post', '', 1 );
  442. $answer_question = filter_text_input( 'answer_question', 'post', '', 1 );
  443. $array_data['site_name'] = $site_name;
  444. $array_data['nv_login'] = $login;
  445. $array_data['nv_email'] = $email;
  446. $array_data['nv_password'] = $password;
  447. $array_data['re_password'] = $re_password;
  448. $array_data['nv_login'] = $login;
  449. $array_data['question'] = $question;
  450. $array_data['answer_question'] = $answer_question;
  451. $global_config['site_email'] = $email;
  452. $db = new sql_db( $db_config );
  453. if ( ! empty( $db->error ) )
  454. {
  455. $error = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  456. }
  457. elseif ( empty( $site_name ) )
  458. {
  459. $error = $lang_module['err_sitename'];
  460. }
  461. elseif ( ! empty( $check_login ) )
  462. {
  463. $error = $check_login;
  464. }
  465. elseif ( $login != $db->fixdb( $login ) )
  466. {
  467. $error = sprintf( $lang_module['account_deny_name'], '<strong>' . $login . '</strong>' );
  468. }
  469. elseif ( ! empty( $check_email ) )
  470. {
  471. $error = $check_email;
  472. }
  473. elseif ( ! empty( $check_pass ) )
  474. {
  475. $error = $check_pass;
  476. }
  477. elseif ( $password != $re_password )
  478. {
  479. $error = sprintf( $lang_global['passwordsincorrect'], $password, $re_password );
  480. }
  481. elseif ( empty( $question ) )
  482. {
  483. $error = $lang_module['your_question_empty'];
  484. }
  485. elseif ( empty( $answer_question ) )
  486. {
  487. $error = $lang_module['answer_empty'];
  488. }
  489. else
  490. {
  491. $password = $crypt->hash( $password );
  492. define( 'NV_CONFIG_GLOBALTABLE', $db_config['prefix'] . '_config' );
  493. $db->sql_query( "TRUNCATE TABLE `" . $db_config['prefix'] . "_users`" );
  494. $sql = "INSERT INTO `" . $db_config['prefix'] . "_users` (`userid`, `username`, `md5username`, `password`, `email`, `full_name`, `gender`, `photo`, `birthday`, `sig`, `regdate`, `website`, `location`, `yim`, `telephone`, `fax`, `mobile`, `question`, `answer`, `passlostkey`, `view_mail`, `remember`, `in_groups`, `active`, `checknum`, `last_login`, `last_ip`, `last_agent`, `last_openid`)
  495. VALUES(NULL, " . $db->dbescape( $login ) . ", " . $db->dbescape( md5( $login ) ) . ", " . $db->dbescape( $password ) . ", " . $db->dbescape( $email ) . ", " . $db->dbescape( $login ) . ", '', '', 0, NULL, " . NV_CURRENTTIME . ", '', '', '', '', '', '', " . $db->dbescape( $question ) . ", " . $db->dbescape( $answer_question ) . ", '', 0, 1, '', 1, '', " . NV_CURRENTTIME . ", '', '', '')";
  496. $userid = $db->sql_query_insert_id( $sql );
  497. $db->sql_query( "TRUNCATE TABLE `" . $db_config['prefix'] . "_authors`" );
  498. $sql = "INSERT INTO `" . $db_config['prefix'] . "_authors` (`admin_id`, `editor`, `lev`, `files_level`, `position`, `addtime`, `edittime`, `is_suspend`, `susp_reason`, `check_num`, `last_login`, `last_ip`, `last_agent`) VALUES(" . $userid . ", 'ckeditor', 1, 'adobe,application,archives,audio,documents,flash,images,real,video|1|1|1', 'Administrator', 0, 0, 0, '', '', 0, '', '')";
  499. if ( $userid > 0 and $db->sql_query( $sql ) )
  500. {
  501. $sql = array();
  502. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_email', " . $db->dbescape_string( $global_config['site_email'] ) . ")";
  503. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'error_send_email', " . $db->dbescape_string( $global_config['site_email'] ) . ")";
  504. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'my_domains', " . $db->dbescape_string( NV_SERVER_NAME ) . ")";
  505. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'cookie_prefix', " . $db->dbescape_string( $global_config['cookie_prefix'] ) . ")";
  506. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'session_prefix', " . $db->dbescape_string( $global_config['session_prefix'] ) . ")";
  507. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_timezone', " . $db->dbescape_string( $global_config['site_timezone'] ) . ")";
  508. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'proxy_blocker', " . $db->dbescape_string( $global_config['proxy_blocker'] ) . ")";
  509. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'str_referer_blocker', " . $db->dbescape_string( $global_config['str_referer_blocker'] ) . ")";
  510. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'lang_multi', " . $db->dbescape_string( $global_config['lang_multi'] ) . ")";
  511. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_lang', " . $db->dbescape_string( $global_config['site_lang'] ) . ")";
  512. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_server', " . $db->dbescape_string( $global_config['ftp_server'] ) . ")";
  513. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_port', " . $db->dbescape_string( $global_config['ftp_port'] ) . ")";
  514. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_user_name', " . $db->dbescape_string( $global_config['ftp_user_name'] ) . ")";
  515. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_user_pass', " . $db->dbescape_string( $global_config['ftp_user_pass'] ) . ")";
  516. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_path', " . $db->dbescape_string( $global_config['ftp_path'] ) . ")";
  517. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_check_login', " . $db->dbescape_string( $global_config['ftp_check_login'] ) . ")";
  518. $sql[] = "UPDATE `" . NV_CONFIG_GLOBALTABLE . "` SET `config_value` = " . $db->dbescape_string( $site_name ) . " WHERE `module` = 'global' AND `config_name` = 'site_name'";
  519. foreach ( $sql as $sql_i )
  520. {
  521. $result = $db->sql_query( $sql_i );
  522. }
  523. nv_save_file_config();
  524. if ( nv_save_file_config_global() )
  525. {
  526. $step ++;
  527. $nv_Request->set_Session( 'maxstep', $step );
  528. nv_save_file_config();
  529. nv_rewrite_change( $array_config_rewrite );
  530. @rename( NV_ROOTDIR . "/" . $file_config_temp, NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME );
  531. Header( "Location: " . NV_BASE_SITEURL . "install/index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step );
  532. exit();
  533. }
  534. }
  535. else
  536. {
  537. $error = "Error add Administrator";
  538. }
  539. }
  540. }
  541. $array_data['error'] = $error;
  542. $title = $lang_module['website_info'];
  543. $contents = nv_step_6( $array_data, $nextstep );
  544. }
  545. elseif ( $step == 7 )
  546. {
  547. $finish = 0;
  548. if ( file_exists( NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME ) )
  549. {
  550. $ftp_check_login = 0;
  551. $ftp_server_array = array( 'ftp_check_login' => 0 );
  552. if ( $nv_Request->isset_request( 'ftp_server_array', 'session' ) )
  553. {
  554. $ftp_server_array = $nv_Request->get_string( 'ftp_server_array', 'session' );
  555. $ftp_server_array = unserialize( $ftp_server_array );
  556. }
  557. if ( isset( $ftp_server_array['ftp_check_login'] ) and intval( $ftp_server_array['ftp_check_login'] ) == 1 )
  558. {
  559. // set up basic connection
  560. $conn_id = ftp_connect( $ftp_server_array['ftp_server'], $ftp_server_array['ftp_port'] );
  561. // login with username and password
  562. $login_result = ftp_login( $conn_id, $ftp_server_array['ftp_user_name'], $ftp_server_array['ftp_user_pass'] );
  563. if ( ( ! $conn_id ) || ( ! $login_result ) )
  564. {
  565. $ftp_check_login = 3;
  566. }
  567. elseif ( ftp_chdir( $conn_id, $ftp_server_array['ftp_path'] ) )
  568. {
  569. $ftp_check_login = 1;
  570. }
  571. }
  572. if ( $ftp_check_login == 1 )
  573. {
  574. ftp_rename( $conn_id, NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME, NV_CONFIG_FILENAME );
  575. nv_chmod_dir( $conn_id, NV_UPLOADS_DIR, true );
  576. ftp_chmod( $conn_id, 0644, NV_CONFIG_FILENAME );
  577. ftp_close( $conn_id );
  578. }
  579. else
  580. {
  581. @rename( NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME, NV_ROOTDIR . "/" . NV_CONFIG_FILENAME );
  582. }
  583. }
  584. if ( file_exists( NV_ROOTDIR . "/" . NV_CONFIG_FILENAME ) )
  585. {
  586. $finish = 1;
  587. }
  588. else
  589. {
  590. $finish = 2;
  591. }
  592. $title = $lang_module['done'];
  593. $contents = nv_step_7( $finish );
  594. }
  595. echo nv_site_theme( $step, $title, $contents );
  596. function nv_save_file_config ( )
  597. {
  598. global $nv_Request, $file_config_temp, $db_config, $global_config, $step;
  599. if ( is_writable( NV_ROOTDIR . '/' . $file_config_temp ) or is_writable( NV_ROOTDIR . '/' . NV_TEMP_DIR ) )
  600. {
  601. $global_config['cookie_prefix'] = ( empty( $global_config['cookie_prefix'] ) or $global_config['cookie_prefix'] == "nv3" ) ? "nv3c_" . nv_genpass( 5 ) : $global_config['cookie_prefix'];
  602. $global_config['session_prefix'] = ( empty( $global_config['session_prefix'] ) or $global_config['session_prefix'] == "nv3" ) ? "nv3s_" . nv_genpass( 6 ) : $global_config['session_prefix'];
  603. $global_config['site_email'] = ( ! isset( $global_config['site_email'] ) ) ? "" : $global_config['site_email'];
  604. $db_config['dbhost'] = ( ! isset( $db_config['dbhost'] ) ) ? "localhost" : $db_config['dbhost'];
  605. $db_config['dbport'] = ( ! isset( $db_config['dbport'] ) ) ? "" : $db_config['dbport'];
  606. $db_config['dbname'] = ( ! isset( $db_config['dbname'] ) ) ? "" : $db_config['dbname'];
  607. $db_config['dbuname'] = ( ! isset( $db_config['dbuname'] ) ) ? "" : $db_config['dbuname'];
  608. $db_config['dbpass'] = ( ! isset( $db_config['dbpass'] ) ) ? "" : $db_config['dbpass'];
  609. $db_config['prefix'] = ( ! isset( $db_config['prefix'] ) ) ? "nv3" : $db_config['prefix'];
  610. $content = "";
  611. $content .= "<?php\n\n";
  612. $content .= NV_FILEHEAD . "\n\n";
  613. $content .= "if ( ! defined( 'NV_MAINFILE' ) )\n";
  614. $content .= "{\n";
  615. $content .= " die( 'Stop!!!' );\n";
  616. $content .= "}\n\n";
  617. $content .= "\$db_config['dbhost'] = \"" . $db_config['dbhost'] . "\";\n";
  618. $content .= "\$db_config['dbport'] = \"" . $db_config['dbport'] . "\";\n";
  619. $content .= "\$db_config['dbname'] = \"" . $db_config['dbname'] . "\";\n";
  620. $content .= "\$db_config['dbuname'] = \"" . $db_config['dbuname'] . "\";\n";
  621. $content .= "\$db_config['dbpass'] = \"" . $db_config['dbpass'] . "\";\n";
  622. $content .= "\$db_config['prefix'] = \"" . $db_config['prefix'] . "\";\n";
  623. $content .= "\n";
  624. $content .= "\$global_config['sitekey'] = \"" . $global_config['sitekey'] . "\";// Do not change sitekey!\n";
  625. if ( $step < 7 )
  626. {
  627. $content .= "\$global_config['cookie_prefix'] = \"" . $global_config['cookie_prefix'] . "\";\n";
  628. $content .= "\$global_config['session_prefix'] = \"" . $global_config['session_prefix'] . "\";\n";
  629. $global_config['ftp_server'] = ( ! isset( $global_config['ftp_server'] ) ) ? "localhost" : $global_config['ftp_server'];
  630. $global_config['ftp_port'] = ( ! isset( $global_config['ftp_port'] ) ) ? 21 : $global_config['ftp_port'];
  631. $global_config['ftp_user_name'] = ( ! isset( $global_config['ftp_user_name'] ) ) ? "" : $global_config['ftp_user_name'];
  632. $global_config['ftp_user_pass'] = ( ! isset( $global_config['ftp_user_pass'] ) ) ? "" : $global_config['ftp_user_pass'];
  633. $global_config['ftp_path'] = ( ! isset( $global_config['ftp_path'] ) ) ? "" : $global_config['ftp_path'];
  634. $global_config['ftp_check_login'] = ( ! isset( $global_config['ftp_check_login'] ) ) ? 0 : $global_config['ftp_check_login'];
  635. if ( $global_config['ftp_check_login'] )
  636. {
  637. $ftp_server_array = array( "ftp_server" => $global_config['ftp_server'], "ftp_port" => $global_config['ftp_port'], "ftp_user_name" => $global_config['ftp_user_name'], "ftp_user_pass" => $global_config['ftp_user_pass'], "ftp_path" => $global_config['ftp_path'], "ftp_check_login" => $global_config['ftp_check_login'] );
  638. $nv_Request->set_Session( 'ftp_server_array', serialize( $ftp_server_array ) );
  639. }
  640. $content .= "\n";
  641. $content .= "\$global_config['ftp_server'] = \"" . $global_config['ftp_server'] . "\";\n";
  642. $content .= "\$global_config['ftp_port'] = \"" . $global_config['ftp_port'] . "\";\n";
  643. $content .= "\$global_config['ftp_user_name'] = \"" . $global_config['ftp_user_name'] . "\";\n";
  644. $content .= "\$global_config['ftp_user_pass'] = \"" . $global_config['ftp_user_pass'] . "\";\n";
  645. $content .= "\$global_config['ftp_path'] = \"" . $global_config['ftp_path'] . "\";\n";
  646. $content .= "\$global_config['ftp_check_login'] = \"" . $global_config['ftp_check_login'] . "\";\n";
  647. }
  648. $content .= "\n";
  649. $content .= "?>";
  650. file_put_contents( NV_ROOTDIR . '/' . $file_config_temp, $content, LOCK_EX );
  651. return true;
  652. }
  653. else
  654. {
  655. return false;
  656. }
  657. }
  658. ?>