PageRenderTime 31ms CodeModel.GetById 31ms RepoModel.GetById 4ms app.codeStats 0ms

/01.Source/01.CORE/install/index.php

http://creative-portal.googlecode.com/
PHP | 670 lines | 585 code | 51 blank | 34 comment | 99 complexity | 3eba7c4908076f0e7e3d2918d0e8573a 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 > $maxstep )
  36. {
  37. $step = $maxstep;
  38. Header( "Location: " . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step . "" );
  39. exit();
  40. }
  41. if ( file_exists( NV_ROOTDIR . "/" . NV_CONFIG_FILENAME ) and $step < 7 )
  42. {
  43. Header( "Location: " . NV_BASE_SITEURL . "../index.php" );
  44. exit();
  45. }
  46. if ( $step == 1 )
  47. {
  48. if ( $step < 2 )
  49. {
  50. $nv_Request->set_Session( 'maxstep', 2 );
  51. }
  52. $title = $lang_module['select_language'];
  53. $contents = nv_step_1();
  54. }
  55. elseif ( $step == 2 )
  56. {
  57. if ( $step < 3 )
  58. {
  59. $nv_Request->set_Session( 'maxstep', 3 );
  60. }
  61. $title = $lang_module['license'];
  62. if ( file_exists( NV_ROOTDIR . "/install/licenses_" . NV_LANG_DATA . ".html" ) )
  63. {
  64. $license = file_get_contents( NV_ROOTDIR . "/install/licenses_" . NV_LANG_DATA . ".html" );
  65. }
  66. else
  67. {
  68. $license = file_get_contents( NV_ROOTDIR . "/install/licenses.html" );
  69. }
  70. $contents = nv_step_2( $license );
  71. }
  72. elseif ( $step == 3 )
  73. {
  74. $nextstep = 1;
  75. $title = $lang_module['check_server'];
  76. $array_resquest = array();
  77. $array_resquest_key = array(
  78. 'php_support', 'mysql_support', 'opendir_support', 'gd_support', 'session_support', 'fileuploads_support'
  79. );
  80. foreach ( $array_resquest_key as $key )
  81. {
  82. $array_resquest[$key] = ( $sys_info[$key] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  83. if ( ! $sys_info[$key] )
  84. {
  85. $nextstep = 0;
  86. }
  87. }
  88. if ( $step < 4 and $nextstep == 1 )
  89. {
  90. $nv_Request->set_Session( 'maxstep', 4 );
  91. }
  92. $array_suport = array();
  93. $array_support['supports_rewrite'] = ( empty( $sys_info['supports_rewrite'] ) ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  94. $array_support['safe_mode'] = ( $sys_info['safe_mode'] ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  95. $array_support['register_globals'] = ( ini_get( 'register_globals' ) == '1' || strtolower( ini_get( 'register_globals' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  96. $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'];
  97. $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'];
  98. $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'];
  99. $array_support['output_buffering'] = ( ini_get( 'output_buffering' ) == '1' || strtolower( ini_get( 'output_buffering' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  100. $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'];
  101. $array_support['display_errors'] = ( ini_get( 'display_errors' ) == '1' || strtolower( ini_get( 'display_errors' ) ) == 'on' ) ? $lang_module['not_compatible'] : $lang_module['compatible'];
  102. $array_support['allowed_set_time_limit'] = ( $sys_info['allowed_set_time_limit'] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  103. $array_support['zlib_support'] = ( $sys_info['zlib_support'] ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  104. $array_support['zip_support'] = ( extension_loaded( 'zip' ) ) ? $lang_module['compatible'] : $lang_module['not_compatible'];
  105. $contents = nv_step_3( $array_resquest, $array_support, $nextstep );
  106. }
  107. elseif ( $step == 4 )
  108. {
  109. $array_dir = array(
  110. NV_DATADIR, 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
  111. );
  112. $array_dir[] = $file_config_temp;
  113. if ( ! empty( $sys_info['supports_rewrite'] ) )
  114. {
  115. if ( $sys_info['supports_rewrite'] == "rewrite_mode_apache" )
  116. {
  117. $array_dir[] = ".htaccess";
  118. }
  119. else
  120. {
  121. $array_dir[] = "web.config";
  122. }
  123. }
  124. $ftp_check_login = 0;
  125. $global_config['ftp_server'] = $nv_Request->get_string( 'ftp_server', 'post', 'localhost' );
  126. $global_config['ftp_port'] = $nv_Request->get_int( 'ftp_port', 'post', 21 );
  127. $global_config['ftp_user_name'] = $nv_Request->get_string( 'ftp_user_name', 'post', '' );
  128. $global_config['ftp_user_pass'] = $nv_Request->get_string( 'ftp_user_pass', 'post', '' );
  129. $global_config['ftp_path'] = $nv_Request->get_string( 'ftp_path', 'post', '/' );
  130. $array_ftp_data = array(
  131. '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' => ''
  132. );
  133. $modftp = $nv_Request->get_int( 'modftp', 'post', 0 );
  134. if ( $modftp )
  135. {
  136. if ( ! empty( $global_config['ftp_server'] ) and ! empty( $global_config['ftp_user_name'] ) and ! empty( $global_config['ftp_user_pass'] ) )
  137. {
  138. // set up basic connection
  139. $conn_id = ftp_connect( $global_config['ftp_server'], $global_config['ftp_port'] );
  140. // login with username and password
  141. $login_result = ftp_login( $conn_id, $global_config['ftp_user_name'], $global_config['ftp_user_pass'] );
  142. if ( ( ! $conn_id ) || ( ! $login_result ) )
  143. {
  144. $ftp_check_login = 3;
  145. $array_ftp_data['error'] = $lang_module['ftp_error_account'];
  146. }
  147. elseif ( ftp_chdir( $conn_id, $global_config['ftp_path'] ) )
  148. {
  149. $ftp_check_login = 1;
  150. nv_chmod_dir( $conn_id, NV_DATADIR, true );
  151. nv_chmod_dir( $conn_id, NV_TEMP_DIR, true );
  152. nv_save_file_config();
  153. nv_chmod_dir( $conn_id, NV_TEMP_DIR, true );
  154. }
  155. else
  156. {
  157. $ftp_check_login = 2;
  158. $array_ftp_data['error'] = $lang_module['ftp_error_path'];
  159. }
  160. $global_config['ftp_check_login'] = $ftp_check_login;
  161. }
  162. }
  163. $nextstep = 1;
  164. $array_dir_check = array();
  165. foreach ( $array_dir as $dir )
  166. {
  167. if ( $ftp_check_login == 1 )
  168. {
  169. if ( ! is_dir( NV_ROOTDIR . '/' . $dir ) and $dir != $file_config_temp )
  170. {
  171. ftp_mkdir( $conn_id, $dir );
  172. }
  173. if ( ! is_writable( NV_ROOTDIR . '/' . $dir ) )
  174. {
  175. ftp_chmod( $conn_id, 0777, $dir );
  176. }
  177. }
  178. if ( $dir == $file_config_temp and ! file_exists( NV_ROOTDIR . '/' . $file_config_temp ) and is_writable( NV_ROOTDIR . '/' . NV_TEMP_DIR ) )
  179. {
  180. file_put_contents( NV_ROOTDIR . '/' . $file_config_temp, '', LOCK_EX );
  181. }
  182. if ( is_file( NV_ROOTDIR . '/' . $dir ) )
  183. {
  184. if ( is_writable( NV_ROOTDIR . '/' . $dir ) )
  185. {
  186. $array_dir_check[$dir] = $lang_module['dir_writable'];
  187. }
  188. else
  189. {
  190. $array_dir_check[$dir] = $lang_module['dir_not_writable'];
  191. $nextstep = 0;
  192. }
  193. }
  194. elseif ( is_dir( NV_ROOTDIR . '/' . $dir ) )
  195. {
  196. if ( is_writable( NV_ROOTDIR . '/' . $dir ) )
  197. {
  198. $array_dir_check[$dir] = $lang_module['dir_writable'];
  199. }
  200. else
  201. {
  202. $array_dir_check[$dir] = $lang_module['dir_not_writable'];
  203. $nextstep = 0;
  204. }
  205. }
  206. else
  207. {
  208. $array_dir_check[$dir] = $lang_module['dir_noexit'];
  209. $nextstep = 0;
  210. }
  211. }
  212. if ( ! nv_save_file_config( $db_config, $global_config ) and $ftp_check_login == 1 )
  213. {
  214. ftp_chmod( $conn_id, 0777, $file_config_temp );
  215. }
  216. if ( $ftp_check_login > 0 )
  217. {
  218. ftp_close( $conn_id );
  219. }
  220. if ( $step < 5 and $nextstep == 1 )
  221. {
  222. $nv_Request->set_Session( 'maxstep', 5 );
  223. }
  224. $title = $lang_module['check_chmod'];
  225. $contents = nv_step_4( $array_dir_check, $array_ftp_data, $nextstep );
  226. }
  227. elseif ( $step == 5 )
  228. {
  229. $nextstep = 0;
  230. $db_config['dbport'] = "";
  231. $db_config['error'] = "";
  232. $db_config['dbhost'] = $nv_Request->get_string( 'dbhost', 'post', $db_config['dbhost'] );
  233. $db_config['dbname'] = $nv_Request->get_string( 'dbname', 'post', $db_config['dbname'] );
  234. $db_config['dbuname'] = $nv_Request->get_string( 'dbuname', 'post', $db_config['dbuname'] );
  235. $db_config['dbpass'] = $nv_Request->get_string( 'dbpass', 'post', $db_config['dbpass'] );
  236. $db_config['prefix'] = $nv_Request->get_string( 'prefix', 'post', 'nv3' );
  237. $db_config['db_detete'] = $nv_Request->get_int( 'db_detete', 'post', '0' );
  238. $db_config['num_table'] = 0;
  239. $db_config['create_db'] = 1;
  240. if ( ! empty( $db_config['dbhost'] ) and ! empty( $db_config['dbname'] ) and ! empty( $db_config['dbuname'] ) and ! empty( $db_config['prefix'] ) )
  241. {
  242. $db = new sql_db( $db_config );
  243. if ( ! empty( $db->error ) )
  244. {
  245. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  246. }
  247. else
  248. {
  249. $tables = array();
  250. $result = $db->sql_query( "SHOW TABLE STATUS LIKE '" . $db_config['prefix'] . "\_%'" );
  251. $num_table = intval( $db->sql_numrows( $result ) );
  252. if ( $num_table > 0 )
  253. {
  254. if ( $db_config['db_detete'] == 1 )
  255. {
  256. while ( $item = $db->sql_fetch_assoc( $result ) )
  257. {
  258. $db->sql_query( "DROP TABLE `" . $item['Name'] . "`" );
  259. }
  260. $num_table = 0;
  261. }
  262. else
  263. {
  264. $db_config['error'] = $lang_module['db_err_prefix'];
  265. }
  266. }
  267. $db_config['num_table'] = $num_table;
  268. if ( $num_table == 0 )
  269. {
  270. nv_save_file_config();
  271. $db_config['error'] = "";
  272. $sql_create_table = array();
  273. //cai dat du lieu cho he thong
  274. require_once ( NV_ROOTDIR . "/install/data.php" );
  275. foreach ( $sql_create_table as $query )
  276. {
  277. if ( ! $db->sql_query( $query ) )
  278. {
  279. $nv_Request->set_Session( 'maxstep', 1 );
  280. die( $query );
  281. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  282. break;
  283. }
  284. }
  285. //Het cai dat du lieu cho he thong
  286. //Cai dat du lieu cho cac module
  287. if ( empty( $db_config['error'] ) )
  288. {
  289. define( 'NV_IS_MODADMIN', true );
  290. $module_name = "";
  291. $lang_module['modules'] = "";
  292. $lang_module['vmodule_add'] = "";
  293. $lang_module['blocks'] = "";
  294. $lang_module['autoinstall'] = "";
  295. $lang_global['mod_modules'] = "";
  296. require_once ( NV_ROOTDIR . "/" . NV_ADMINDIR . "/modules/modules/functions.php" );
  297. require_once ( NV_ROOTDIR . '/includes/sqldata.php' );
  298. //cai dat du lieu cho ngon ngu
  299. $sql_create_table = nv_create_table_sys( NV_LANG_DATA );
  300. foreach ( $sql_create_table as $query )
  301. {
  302. if ( ! $db->sql_query( $query ) )
  303. {
  304. $nv_Request->set_Session( 'maxstep', 1 );
  305. die( $query );
  306. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  307. break;
  308. }
  309. }
  310. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . NV_LANG_DATA . "_modules` ORDER BY `weight` ASC";
  311. $result = $db->sql_query( $sql );
  312. while ( $row = $db->sql_fetchrow( $result ) )
  313. {
  314. $setmodule = $row['title'];
  315. $sm = nv_setup_data_module( NV_LANG_DATA, $setmodule );
  316. if ( $sm != "OK_" . $setmodule )
  317. {
  318. die( "error set module: " . $setmodule );
  319. }
  320. }
  321. //cai dat du lieu mau
  322. $filesavedata = NV_LANG_DATA;
  323. $lang_data = NV_LANG_DATA;
  324. if ( ! file_exists( NV_ROOTDIR . "/install/data_" . $lang_data . ".php" ) )
  325. {
  326. $filesavedata = "en";
  327. }
  328. include_once ( NV_ROOTDIR . "/install/data_" . $filesavedata . ".php" );
  329. foreach ( $sql_create_table as $query )
  330. {
  331. if ( ! $db->sql_query( $query ) )
  332. {
  333. $nv_Request->set_Session( 'maxstep', 1 );
  334. die( $query );
  335. $db_config['error'] = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  336. break;
  337. }
  338. }
  339. $result = $db->sql_query( "SELECT catid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_cat` ORDER BY `order` ASC" );
  340. while ( list( $catid_i ) = $db->sql_fetchrow( $result ) )
  341. {
  342. nv_create_table_news( $catid_i );
  343. }
  344. $db->sql_freeresult();
  345. $result = $db->sql_query( "SELECT id, listcatid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` ORDER BY `id` ASC" );
  346. while ( list( $id, $listcatid ) = $db->sql_fetchrow( $result ) )
  347. {
  348. $arr_catid = explode( ",", $listcatid );
  349. foreach ( $arr_catid as $catid )
  350. {
  351. $db->sql_query( "INSERT INTO `" . $db_config['prefix'] . "_" . $lang_data . "_news_" . $catid . "` SELECT * FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` WHERE `id`=" . $id . "" );
  352. }
  353. }
  354. $db->sql_freeresult();
  355. /*$return = "<table summary=\"" . $lang_global['show_queries'] . "\" class=\"tab1\">\n";
  356. $return .= "<col width=\"16\" />\n";
  357. foreach ( $db->query_strs as $key => $field )
  358. {
  359. if ( empty( $field[1] ) )
  360. {
  361. $class = ( $key % 2 ) ? " class=\"second\"" : "";
  362. $return .= "<tbody" . $class . ">\n";
  363. $return .= "<tr>\n";
  364. $return .= "<td>" . ( $field[1] ? "<img alt=\"" . $lang_global['ok'] . "\" title=\"" . $lang_global['ok'] . "\" src=\"http://127.0.0.3/themes/" . $global_config['site_theme'] . "/images/icons/good.png\" width=\"16\" height=\"16\" />" : "<img alt=\"" . $lang_global['fail'] . "\" title=\"" . $lang_global['fail'] . "\" src=\"http://127.0.0.3/themes/default/images/icons/bad.png\" width=\"16\" height=\"16\" />" ) . "</td>\n";
  365. $return .= "<td>" . nv_htmlspecialchars( $field[0] ) . "</td>\n";
  366. $return .= "</tr>\n";
  367. $return .= "</tbody>\n";
  368. }
  369. }
  370. $return .= "</table>\n";
  371. die( $return );*/
  372. $step ++;
  373. $nv_Request->set_Session( 'maxstep', $step );
  374. Header( "Location: " . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step );
  375. exit();
  376. }
  377. //Het cai dat du lieu cho cac module
  378. }
  379. }
  380. }
  381. $title = $lang_module['config_database'];
  382. $contents = nv_step_5( $db_config, $nextstep );
  383. }
  384. elseif ( $step == 6 )
  385. {
  386. $nextstep = 0;
  387. $array_data = array();
  388. $error = $site_name = $login = $email = $password = $re_password = "";
  389. if ( $nv_Request->isset_request( 'nv_login,nv_password', 'post' ) )
  390. {
  391. $site_name = filter_text_input( 'site_name', 'post', '',1);
  392. $login = filter_text_input( 'nv_login', 'post', '' );
  393. $email = filter_text_input( 'nv_email', 'post', '' );
  394. $password = filter_text_input( 'nv_password', 'post', '' );
  395. $re_password = filter_text_input( 're_password', 'post', '' );
  396. $check_login = nv_check_valid_login( $login, NV_ANICKMAX, NV_ANICKMIN );
  397. $check_pass = nv_check_valid_pass( $password, NV_APASSMAX, NV_APASSMIN );
  398. $check_email = nv_check_valid_email( $email );
  399. $question = filter_text_input( 'question', 'post', '', 1 );
  400. $answer_question = filter_text_input( 'answer_question', 'post', '', 1 );
  401. $array_data['site_name'] = $site_name;
  402. $array_data['nv_login'] = $login;
  403. $array_data['nv_email'] = $email;
  404. $array_data['nv_password'] = $password;
  405. $array_data['re_password'] = $re_password;
  406. $array_data['nv_login'] = $login;
  407. $array_data['question'] = $question;
  408. $array_data['answer_question'] = $answer_question;
  409. $global_config['site_email'] = $email;
  410. $db = new sql_db( $db_config );
  411. if ( ! empty( $db->error ) )
  412. {
  413. $error = ( ! empty( $db->error['user_message'] ) ) ? $db->error['user_message'] : $db->error['message'];
  414. }
  415. elseif ( empty( $site_name ) )
  416. {
  417. $error = $lang_module['err_sitename'];
  418. }
  419. elseif ( ! empty( $check_login ) )
  420. {
  421. $error = $check_login;
  422. }
  423. elseif ( $login != $db->fixdb( $login ) )
  424. {
  425. $error = sprintf( $lang_module['account_deny_name'], '<strong>' . $login . '</strong>' );
  426. }
  427. elseif ( ! empty( $check_email ) )
  428. {
  429. $error = $check_email;
  430. }
  431. elseif ( ! empty( $check_pass ) )
  432. {
  433. $error = $check_pass;
  434. }
  435. elseif ( $password != $re_password )
  436. {
  437. $error = sprintf( $lang_global['passwordsincorrect'], $password, $re_password );
  438. }
  439. elseif ( empty( $question ) )
  440. {
  441. $error = $lang_module['your_question_empty'];;
  442. }
  443. elseif ( empty( $answer_question ) )
  444. {
  445. $error = $lang_module['answer_empty'];;
  446. }
  447. else
  448. {
  449. $password = $crypt->hash( $password );
  450. define( 'NV_CONFIG_GLOBALTABLE', $db_config['prefix'] . '_config' );
  451. $db->sql_query( "TRUNCATE TABLE `" . $db_config['prefix'] . "_users`" );
  452. $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`)
  453. 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 . ", '', '', '')";
  454. $userid = $db->sql_query_insert_id( $sql );
  455. $db->sql_query( "TRUNCATE TABLE `" . $db_config['prefix'] . "_authors`" );
  456. $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, 'images,flash,documents,archives|1|1|1', 'Administrator', 0, 0, 0, '', '', 0, '', '')";
  457. if ( $userid > 0 and $db->sql_query( $sql ) )
  458. {
  459. $sql = array();
  460. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_email', " . $db->dbescape_string( $global_config['site_email'] ) . ")";
  461. $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'] ) . ")";
  462. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'my_domains', " . $db->dbescape_string( NV_SERVER_NAME ) . ")";
  463. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'cookie_prefix', " . $db->dbescape_string( $global_config['cookie_prefix'] ) . ")";
  464. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'session_prefix', " . $db->dbescape_string( $global_config['session_prefix'] ) . ")";
  465. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_timezone', " . $db->dbescape_string( $global_config['site_timezone'] ) . ")";
  466. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'proxy_blocker', " . $db->dbescape_string( $global_config['proxy_blocker'] ) . ")";
  467. $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'] ) . ")";
  468. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'lang_multi', " . $db->dbescape_string( $global_config['lang_multi'] ) . ")";
  469. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'site_lang', " . $db->dbescape_string( $global_config['site_lang'] ) . ")";
  470. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_server', " . $db->dbescape_string( $global_config['ftp_server'] ) . ")";
  471. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_port', " . $db->dbescape_string( $global_config['ftp_port'] ) . ")";
  472. $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'] ) . ")";
  473. $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'] ) . ")";
  474. $sql[] = "INSERT INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'ftp_path', " . $db->dbescape_string( $global_config['ftp_path'] ) . ")";
  475. $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'] ) . ")";
  476. $sql[] = "UPDATE `" . NV_CONFIG_GLOBALTABLE . "` SET `config_value` = " . $db->dbescape_string( $site_name ) . " WHERE `module` = 'global' AND `config_name` = 'site_name'";
  477. foreach ( $sql as $sql_i )
  478. {
  479. $result = $db->sql_query( $sql_i );
  480. }
  481. nv_save_file_config();
  482. if ( nv_save_file_config_global() )
  483. {
  484. $step ++;
  485. $nv_Request->set_Session( 'maxstep', $step );
  486. nv_save_file_config();
  487. @rename( NV_ROOTDIR . "/" . $file_config_temp, NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME );
  488. Header( "Location: " . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&step=" . $step );
  489. exit();
  490. }
  491. }
  492. else
  493. {
  494. $error = "Error add Administrator";
  495. }
  496. }
  497. }
  498. $array_data['error'] = $error;
  499. $title = $lang_module['website_info'];
  500. $contents = nv_step_6( $array_data, $nextstep );
  501. }
  502. elseif ( $step == 7 )
  503. {
  504. $finish = 0;
  505. if ( file_exists( NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME ) )
  506. {
  507. $ftp_check_login = 0;
  508. $ftp_server_array = array(
  509. 'ftp_check_login' => 0
  510. );
  511. if ( $nv_Request->isset_request( 'ftp_server_array', 'session' ) )
  512. {
  513. $ftp_server_array = $nv_Request->get_string( 'ftp_server_array', 'session' );
  514. $ftp_server_array = unserialize( $ftp_server_array );
  515. }
  516. if ( isset( $ftp_server_array['ftp_check_login'] ) and intval( $ftp_server_array['ftp_check_login'] ) == 1 )
  517. {
  518. // set up basic connection
  519. $conn_id = ftp_connect( $ftp_server_array['ftp_server'], $ftp_server_array['ftp_port'] );
  520. // login with username and password
  521. $login_result = ftp_login( $conn_id, $ftp_server_array['ftp_user_name'], $ftp_server_array['ftp_user_pass'] );
  522. if ( ( ! $conn_id ) || ( ! $login_result ) )
  523. {
  524. $ftp_check_login = 3;
  525. }
  526. elseif ( ftp_chdir( $conn_id, $ftp_server_array['ftp_path'] ) )
  527. {
  528. $ftp_check_login = 1;
  529. }
  530. }
  531. if ( $ftp_check_login == 1 )
  532. {
  533. ftp_rename( $conn_id, NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME, NV_CONFIG_FILENAME );
  534. nv_chmod_dir( $conn_id, NV_UPLOADS_DIR, true );
  535. ftp_chmod( $conn_id, 0644, NV_CONFIG_FILENAME );
  536. ftp_close( $conn_id );
  537. }
  538. else
  539. {
  540. @rename( NV_ROOTDIR . "/" . NV_TEMP_DIR . "/" . NV_CONFIG_FILENAME, NV_ROOTDIR . "/" . NV_CONFIG_FILENAME );
  541. }
  542. }
  543. if ( file_exists( NV_ROOTDIR . "/" . NV_CONFIG_FILENAME ) )
  544. {
  545. $finish = 1;
  546. }
  547. else
  548. {
  549. $finish = 2;
  550. }
  551. $title = $lang_module['done'];
  552. $contents = nv_step_7( $finish );
  553. }
  554. echo nv_site_theme( $step, $title, $contents );
  555. function nv_save_file_config ( )
  556. {
  557. global $nv_Request, $file_config_temp, $db_config, $global_config, $step;
  558. if ( is_writable( NV_ROOTDIR . '/' . $file_config_temp ) or is_writable( NV_ROOTDIR . '/' . NV_TEMP_DIR ) )
  559. {
  560. $global_config['cookie_prefix'] = ( empty( $global_config['cookie_prefix'] ) or $global_config['cookie_prefix'] == "nv3" ) ? "nv3c_" . nv_genpass( 5 ) : $global_config['cookie_prefix'];
  561. $global_config['session_prefix'] = ( empty( $global_config['session_prefix'] ) or $global_config['session_prefix'] == "nv3" ) ? "nv3s_" . nv_genpass( 6 ) : $global_config['session_prefix'];
  562. $global_config['site_email'] = ( ! isset( $global_config['site_email'] ) ) ? "" : $global_config['site_email'];
  563. $db_config['dbhost'] = ( ! isset( $db_config['dbhost'] ) ) ? "localhost" : $db_config['dbhost'];
  564. $db_config['dbport'] = ( ! isset( $db_config['dbport'] ) ) ? "" : $db_config['dbport'];
  565. $db_config['dbname'] = ( ! isset( $db_config['dbname'] ) ) ? "" : $db_config['dbname'];
  566. $db_config['dbuname'] = ( ! isset( $db_config['dbuname'] ) ) ? "" : $db_config['dbuname'];
  567. $db_config['dbpass'] = ( ! isset( $db_config['dbpass'] ) ) ? "" : $db_config['dbpass'];
  568. $db_config['prefix'] = ( ! isset( $db_config['prefix'] ) ) ? "nv3" : $db_config['prefix'];
  569. $content = "";
  570. $content .= "<?php\n\n";
  571. $content .= NV_FILEHEAD . "\n\n";
  572. $content .= "if ( ! defined( 'NV_MAINFILE' ) )\n";
  573. $content .= "{\n";
  574. $content .= " die( 'Stop!!!' );\n";
  575. $content .= "}\n\n";
  576. $content .= "\$db_config['dbhost'] = \"" . $db_config['dbhost'] . "\";\n";
  577. $content .= "\$db_config['dbport'] = \"" . $db_config['dbport'] . "\";\n";
  578. $content .= "\$db_config['dbname'] = \"" . $db_config['dbname'] . "\";\n";
  579. $content .= "\$db_config['dbuname'] = \"" . $db_config['dbuname'] . "\";\n";
  580. $content .= "\$db_config['dbpass'] = \"" . $db_config['dbpass'] . "\";\n";
  581. $content .= "\$db_config['prefix'] = \"" . $db_config['prefix'] . "\";\n";
  582. $content .= "\n";
  583. $content .= "\$global_config['sitekey'] = \"" . $global_config['sitekey'] . "\";// Do not change sitekey!\n";
  584. if ( $step < 7 )
  585. {
  586. $content .= "\$global_config['cookie_prefix'] = \"" . $global_config['cookie_prefix'] . "\";\n";
  587. $content .= "\$global_config['session_prefix'] = \"" . $global_config['session_prefix'] . "\";\n";
  588. $global_config['ftp_server'] = ( ! isset( $global_config['ftp_server'] ) ) ? "localhost" : $global_config['ftp_server'];
  589. $global_config['ftp_port'] = ( ! isset( $global_config['ftp_port'] ) ) ? 21 : $global_config['ftp_port'];
  590. $global_config['ftp_user_name'] = ( ! isset( $global_config['ftp_user_name'] ) ) ? "" : $global_config['ftp_user_name'];
  591. $global_config['ftp_user_pass'] = ( ! isset( $global_config['ftp_user_pass'] ) ) ? "" : $global_config['ftp_user_pass'];
  592. $global_config['ftp_path'] = ( ! isset( $global_config['ftp_path'] ) ) ? "" : $global_config['ftp_path'];
  593. $global_config['ftp_check_login'] = ( ! isset( $global_config['ftp_check_login'] ) ) ? 0 : $global_config['ftp_check_login'];
  594. if ( $global_config['ftp_check_login'] )
  595. {
  596. $ftp_server_array = array(
  597. "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']
  598. );
  599. $nv_Request->set_Session( 'ftp_server_array', serialize( $ftp_server_array ) );
  600. }
  601. $content .= "\n";
  602. $content .= "\$global_config['ftp_server'] = \"" . $global_config['ftp_server'] . "\";\n";
  603. $content .= "\$global_config['ftp_port'] = \"" . $global_config['ftp_port'] . "\";\n";
  604. $content .= "\$global_config['ftp_user_name'] = \"" . $global_config['ftp_user_name'] . "\";\n";
  605. $content .= "\$global_config['ftp_user_pass'] = \"" . $global_config['ftp_user_pass'] . "\";\n";
  606. $content .= "\$global_config['ftp_path'] = \"" . $global_config['ftp_path'] . "\";\n";
  607. $content .= "\$global_config['ftp_check_login'] = \"" . $global_config['ftp_check_login'] . "\";\n";
  608. }
  609. $content .= "\n";
  610. $content .= "?>";
  611. file_put_contents( NV_ROOTDIR . '/' . $file_config_temp, $content, LOCK_EX );
  612. return true;
  613. }
  614. else
  615. {
  616. return false;
  617. }
  618. }
  619. ?>