PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/admin/modules/modules/install_check.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 314 lines | 291 code | 13 blank | 10 comment | 20 complexity | 45e5ba298bbf82eef6caab1e331f50cf MD5 | raw file
  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-2-2010 12:55
  7. */
  8. if ( ! defined( 'NV_IS_FILE_MODULES' ) ) die( 'Stop!!!' );
  9. $error = "";
  10. $info_error = array();
  11. $info_error['errorfile'] = array();
  12. $info_error['errorfolder'] = array();
  13. $allowfolder = array( 'themes', 'modules', 'uploads', 'includes/blocks' );
  14. $filename = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . 'auto_' . md5( $global_config['sitekey'] . session_id() ) . '.zip';
  15. if ( file_exists( $filename ) )
  16. {
  17. require_once NV_ROOTDIR . '/includes/class/pclzip.class.php';
  18. $zip = new PclZip( $filename );
  19. $ziplistContent = $zip->listContent();
  20. $overwrite = $nv_Request->get_string( 'overwrite', 'get', '' );
  21. if ( $overwrite != md5( $filename . $global_config['sitekey'] . session_id() ) )
  22. {
  23. foreach ( $ziplistContent as $array_file )
  24. {
  25. //Check exist file on system
  26. if ( empty( $array_file['folder'] ) and file_exists( NV_ROOTDIR . '/' . trim( $array_file['filename'] ) ) )
  27. {
  28. $info_error['errorfile'][] = $array_file['filename'];
  29. }
  30. //Check valid folder structure nukeviet (modules, themes, uploads)
  31. $folder = explode( '/', $array_file['filename'] );
  32. if ( ! in_array( $folder[0], $allowfolder ) and ! in_array( $folder[0] . '/' . $folder[1], $allowfolder ) )
  33. {
  34. $info_error['errorfolder'][] = $array_file['filename'];
  35. }
  36. }
  37. }
  38. if ( ! $info_error['errorfile'] and ! $info_error['errorfolder'] )
  39. {
  40. $temp_extract_dir = NV_TEMP_DIR . '/' . md5( $filename . $global_config['sitekey'] . session_id() );
  41. $no_extract = array();
  42. $error_create_folder = array();
  43. $error_move_folder = array();
  44. if ( NV_ROOTDIR . '/' . $temp_extract_dir )
  45. {
  46. nv_deletefile( NV_ROOTDIR . '/' . $temp_extract_dir, true );
  47. }
  48. $ftp_check_login = 0;
  49. if ( $sys_info['ftp_support'] and intval( $global_config['ftp_check_login'] ) == 1 )
  50. {
  51. $ftp_server = nv_unhtmlspecialchars( $global_config['ftp_server'] );
  52. $ftp_port = intval( $global_config['ftp_port'] );
  53. $ftp_user_name = nv_unhtmlspecialchars( $global_config['ftp_user_name'] );
  54. $ftp_user_pass = nv_unhtmlspecialchars( $global_config['ftp_user_pass'] );
  55. $ftp_path = nv_unhtmlspecialchars( $global_config['ftp_path'] );
  56. // set up basic connection
  57. $conn_id = ftp_connect( $ftp_server, $ftp_port, 10);
  58. // login with username and password
  59. $login_result = ftp_login( $conn_id, $ftp_user_name, $ftp_user_pass );
  60. if ( ( ! $conn_id ) || ( ! $login_result ) )
  61. {
  62. $ftp_check_login = 3;
  63. }
  64. elseif ( ftp_chdir( $conn_id, $ftp_path ) )
  65. {
  66. $ftp_check_login = 1;
  67. }
  68. else
  69. {
  70. $ftp_check_login = 2;
  71. }
  72. }
  73. if ( $ftp_check_login == 1 )
  74. {
  75. ftp_mkdir( $conn_id, $temp_extract_dir );
  76. if ( substr( $sys_info['os'], 0, 3 ) != 'WIN' ) ftp_chmod( $conn_id, 0777, $temp_extract_dir );
  77. foreach ( $ziplistContent as $array_file )
  78. {
  79. if ( ! empty( $array_file['folder'] ) and ! file_exists( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'] ) )
  80. {
  81. $cp = "";
  82. $e = explode( "/", $array_file['filename'] );
  83. foreach ( $e as $p )
  84. {
  85. if ( ! empty( $p ) and ! is_dir( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $cp . $p ) )
  86. {
  87. ftp_mkdir( $conn_id, $temp_extract_dir . '/' . $cp . $p );
  88. if ( substr( $sys_info['os'], 0, 3 ) != 'WIN' ) ftp_chmod( $conn_id, 0777, $temp_extract_dir . '/' . $cp . $p );
  89. }
  90. $cp .= $p . '/';
  91. }
  92. }
  93. }
  94. }
  95. $extract = $zip->extract( PCLZIP_OPT_PATH, NV_ROOTDIR . '/' . $temp_extract_dir );
  96. foreach ( $extract as $extract_i )
  97. {
  98. $filename_i = str_replace( NV_ROOTDIR, "", str_replace( '\\', '/', $extract_i['filename'] ) );
  99. if ( $extract_i['status'] != 'ok' and $extract_i['status'] != 'already_a_directory' )
  100. {
  101. $no_extract[] = $filename_i;
  102. }
  103. }
  104. if ( empty( $no_extract ) )
  105. {
  106. foreach ( $ziplistContent as $array_file )
  107. {
  108. $dir_name = "";
  109. if ( ! empty( $array_file['folder'] ) and ! file_exists( NV_ROOTDIR . '/' . $array_file['filename'] ) )
  110. {
  111. $dir_name = $array_file['filename'];
  112. }
  113. elseif ( ! file_exists( NV_ROOTDIR . '/' . dirname( $array_file['filename'] ) ) )
  114. {
  115. $dir_name = dirname( $array_file['filename'] );
  116. }
  117. if ( ! empty( $dir_name ) )
  118. {
  119. $cp = "";
  120. $e = explode( "/", $dir_name );
  121. foreach ( $e as $p )
  122. {
  123. if ( ! empty( $p ) and ! is_dir( NV_ROOTDIR . '/' . $cp . $p ) )
  124. {
  125. if ( ! ( $ftp_check_login == 1 and ftp_mkdir( $conn_id, $cp . $p ) ) )
  126. {
  127. @mkdir( NV_ROOTDIR . '/' . $cp . $p );
  128. }
  129. if ( ! is_dir( NV_ROOTDIR . '/' . $cp . $p ) )
  130. {
  131. $error_create_folder[] = $cp . $p;
  132. break;
  133. }
  134. }
  135. $cp .= $p . '/';
  136. }
  137. }
  138. }
  139. $error_create_folder = array_unique( $error_create_folder );
  140. if ( empty( $error_create_folder ) )
  141. {
  142. foreach ( $ziplistContent as $array_file )
  143. {
  144. if ( empty( $array_file['folder'] ) )
  145. {
  146. if ( file_exists( NV_ROOTDIR . '/' . $array_file['filename'] ) )
  147. {
  148. if ( ! ( $ftp_check_login == 1 and ftp_delete( $conn_id, $array_file['filename'] ) ) )
  149. {
  150. nv_deletefile( NV_ROOTDIR . '/' . $array_file['filename'] );
  151. }
  152. }
  153. if ( ! ( $ftp_check_login == 1 and ftp_rename( $conn_id, $temp_extract_dir . '/' . $array_file['filename'], $array_file['filename'] ) ) )
  154. {
  155. @rename( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'], NV_ROOTDIR . '/' . $array_file['filename'] );
  156. }
  157. if ( file_exists( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'] ) )
  158. {
  159. $error_move_folder[] = $array_file['filename'];
  160. }
  161. }
  162. }
  163. if ( empty( $error_move_folder ) )
  164. {
  165. nv_deletefile( $filename );
  166. nv_deletefile( NV_ROOTDIR . '/' . $temp_extract_dir, true );
  167. }
  168. }
  169. if ( $ftp_check_login > 0 )
  170. {
  171. ftp_close( $conn_id );
  172. }
  173. }
  174. $xtpl = new XTemplate( "install_check.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  175. $xtpl->assign( 'LANG', $lang_module );
  176. $xtpl->assign( 'GLANG', $lang_global );
  177. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  178. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  179. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  180. $xtpl->assign( 'NV_OP_VARIABLE', NV_OP_VARIABLE );
  181. $xtpl->assign( 'MODULE_NAME', $module_name );
  182. $xtpl->assign( 'CHECKSESS', md5( $filename . $global_config['sitekey'] . session_id() ) );
  183. if( ! empty( $no_extract ) )
  184. {
  185. $i = 0;
  186. foreach( $no_extract as $tmp )
  187. {
  188. $xtpl->assign( 'FILENAME', $tmp );
  189. $xtpl->assign( 'CLASS', ( $i % 2 == 0 ) ? " class=\"second\"" : "" );
  190. $xtpl->parse( 'complete.no_extract.loop' );
  191. $i ++;
  192. }
  193. $xtpl->parse( 'complete.no_extract' );
  194. }
  195. elseif( ! empty( $error_create_folder ) )
  196. {
  197. $i = 0;
  198. asort( $error_create_folder );
  199. foreach( $error_create_folder as $tmp )
  200. {
  201. $xtpl->assign( 'FILENAME', $tmp );
  202. $xtpl->assign( 'CLASS', ( $i % 2 == 0 ) ? " class=\"second\"" : "" );
  203. $xtpl->parse( 'complete.error_create_folder.loop' );
  204. $i ++;
  205. }
  206. $xtpl->parse( 'complete.error_create_folder' );
  207. }
  208. elseif( ! empty( $error_move_folder ) )
  209. {
  210. $i = 0;
  211. asort( $error_move_folder );
  212. foreach( $error_move_folder as $tmp )
  213. {
  214. $xtpl->assign( 'FILENAME', $tmp );
  215. $xtpl->assign( 'CLASS', ( $i % 2 == 0 ) ? " class=\"second\"" : "" );
  216. $xtpl->parse( 'complete.error_move_folder.loop' );
  217. $i ++;
  218. }
  219. $xtpl->parse( 'complete.error_move_folder' );
  220. }
  221. else
  222. {
  223. $xtpl->assign( 'URL_GO', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=setup" );
  224. $xtpl->parse( 'complete.ok' );
  225. }
  226. $xtpl->parse( 'complete' );
  227. $contents = $xtpl->text( 'complete' );
  228. include ( NV_ROOTDIR . "/includes/header.php" );
  229. echo ( $contents );
  230. include ( NV_ROOTDIR . "/includes/footer.php" );
  231. exit();
  232. }
  233. }
  234. else
  235. {
  236. $error = $lang_module['autoinstall_module_error_uploadfile'];
  237. }
  238. $xtpl = new XTemplate( "install_check.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  239. $xtpl->assign( 'LANG', $lang_module );
  240. $xtpl->assign( 'GLANG', $lang_global );
  241. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  242. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  243. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  244. $xtpl->assign( 'NV_OP_VARIABLE', NV_OP_VARIABLE );
  245. $xtpl->assign( 'MODULE_NAME', $module_name );
  246. $xtpl->assign( 'CHECKSESS', md5( $filename . $global_config['sitekey'] . session_id() ) );
  247. if( ! empty( $error ) )
  248. {
  249. $xtpl->assign( 'ERROR', $error );
  250. $xtpl->parse( 'main.error' );
  251. }
  252. if( ! empty( $info_error['errorfile'] ) or ! empty( $info_error['errorfolder'] ) )
  253. {
  254. $xtpl->parse( 'main.infoerror' );
  255. }
  256. if( ! empty( $info_error['errorfile'] ) )
  257. {
  258. $i = 0;
  259. foreach( $info_error['errorfile'] as $tmp )
  260. {
  261. $xtpl->assign( 'FILENAME', $tmp );
  262. $xtpl->assign( 'CLASS', ( $i % 2 == 0 ) ? " class=\"second\"" : "" );
  263. $xtpl->parse( 'main.errorfile.loop' );
  264. $i ++;
  265. }
  266. $xtpl->parse( 'main.errorfile' );
  267. }
  268. if( ! empty( $info_error['errorfolder'] ) )
  269. {
  270. $i = 0;
  271. foreach( $info_error['errorfolder'] as $tmp )
  272. {
  273. $xtpl->assign( 'FILENAME', $tmp );
  274. $xtpl->assign( 'CLASS', ( $i % 2 == 0 ) ? " class=\"second\"" : "" );
  275. $xtpl->parse( 'main.errorfolder.loop' );
  276. $i ++;
  277. }
  278. $xtpl->parse( 'main.errorfolder' );
  279. }
  280. $xtpl->parse( 'main' );
  281. $contents = $xtpl->text( 'main' );
  282. include ( NV_ROOTDIR . "/includes/header.php" );
  283. echo ( $contents );
  284. include ( NV_ROOTDIR . "/includes/footer.php" );
  285. ?>