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

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 181 lines · 159 code · 16 blank · 6 comment · 22 complexity · a5387f227ab5850f7a800c64a990611f 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 9/9/2010, 6:51
  7. */
  8. if (!defined('NV_IS_FILE_WEBTOOLS'))
  9. die('Stop!!!');
  10. $page_title = $lang_module['clearsystem'];
  11. function nv_clear_files($dir, $base)
  12. {
  13. global $client_info;
  14. $dels = array();
  15. if ($dh = opendir($dir))
  16. {
  17. while (($file = readdir($dh)) !== false)
  18. {
  19. if (!preg_match("/^[\.]{1,2}([a-zA-Z0-9]*)$/", $file) and $file != "index.html" and is_file($dir . '/' . $file) and $file != "sess_" . $client_info['session_id'])
  20. {
  21. if (unlink($dir . '/' . $file))
  22. {
  23. $dels[] = $base . '/' . $file;
  24. }
  25. }
  26. }
  27. closedir($dh);
  28. }
  29. if (!file_exists($dir . "/index.html"))
  30. {
  31. file_put_contents($dir . "/index.html", "");
  32. }
  33. return $dels;
  34. }
  35. $xtpl = new XTemplate("clearsystem.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file . "");
  36. $xtpl->assign('LANG', $lang_module);
  37. if ($nv_Request->isset_request('submit', 'post') and $nv_Request->isset_request('deltype', 'post'))
  38. {
  39. $deltype = $nv_Request->get_typed_array('deltype', 'post', 'string', array());
  40. nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['clearsystem'], implode(", ", $deltype), $admin_info['userid']);
  41. clearstatcache();
  42. if (in_array('clearcache', $deltype))
  43. {
  44. $cacheDir = NV_ROOTDIR . '/cache';
  45. $files = nv_clear_files($cacheDir, 'cache');
  46. foreach ($files as $file)
  47. {
  48. $xtpl->assign('DELFILE', $file);
  49. $xtpl->parse('main.delfile.loop');
  50. }
  51. $cssDir = NV_ROOTDIR . '/' . NV_FILES_DIR . '/css';
  52. $files = nv_clear_files($cssDir, NV_FILES_DIR . '/css');
  53. foreach ($files as $file)
  54. {
  55. $xtpl->assign('DELFILE', $file);
  56. $xtpl->parse('main.delfile.loop');
  57. }
  58. $jsDir = NV_ROOTDIR . '/' . NV_FILES_DIR . '/js';
  59. $files = nv_clear_files($jsDir, NV_FILES_DIR . '/js');
  60. foreach ($files as $file)
  61. {
  62. $xtpl->assign('DELFILE', $file);
  63. $xtpl->parse('main.delfile.loop');
  64. }
  65. }
  66. if (in_array('clearsession', $deltype))
  67. {
  68. $ssDir = NV_ROOTDIR . "/" . NV_SESSION_SAVE_PATH;
  69. $files = nv_clear_files($ssDir, NV_SESSION_SAVE_PATH);
  70. foreach ($files as $file)
  71. {
  72. $xtpl->assign('DELFILE', $file);
  73. $xtpl->parse('main.delfile.loop');
  74. }
  75. }
  76. if (in_array('cleardumpbackup', $deltype))
  77. {
  78. $log_dir = NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup";
  79. $files = nv_clear_files($log_dir, NV_LOGS_DIR . "/dump_backup");
  80. foreach ($files as $file)
  81. {
  82. $xtpl->assign('DELFILE', $file);
  83. $xtpl->parse('main.delfile.loop');
  84. }
  85. }
  86. if (in_array('clearfiletemp', $deltype))
  87. {
  88. $dir = NV_ROOTDIR . "/" . NV_TEMP_DIR;
  89. if ($dh = opendir($dir))
  90. {
  91. while (($file = readdir($dh)) !== false)
  92. {
  93. if (preg_match("/^(" . nv_preg_quote(NV_TEMPNAM_PREFIX) . ")[a-zA-Z0-9\_\.]+$/", $file))
  94. {
  95. if (is_file($dir . '/' . $file))
  96. {
  97. if (@unlink($dir . '/' . $file))
  98. {
  99. $xtpl->assign('DELFILE', NV_TEMP_DIR . '/' . $file);
  100. $xtpl->parse('main.delfile.loop');
  101. }
  102. }
  103. else
  104. {
  105. $rt = nv_deletefile($dir . '/' . $file, true);
  106. if ($rt[0] == 1)
  107. {
  108. $xtpl->assign('DELFILE', NV_TEMP_DIR . '/' . $file);
  109. $xtpl->parse('main.delfile.loop');
  110. }
  111. }
  112. }
  113. }
  114. closedir($dh);
  115. }
  116. }
  117. if (in_array('clearerrorlogs', $deltype))
  118. {
  119. $dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/error_logs';
  120. $files = nv_clear_files($dir, NV_LOGS_DIR . '/error_logs');
  121. foreach ($files as $file)
  122. {
  123. $xtpl->assign('DELFILE', $file);
  124. $xtpl->parse('main.delfile.loop');
  125. }
  126. $dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/error_logs/errors256';
  127. $files = nv_clear_files($dir, NV_LOGS_DIR . '/error_logs/errors256');
  128. foreach ($files as $file)
  129. {
  130. $xtpl->assign('DELFILE', $file);
  131. $xtpl->parse('main.delfile.loop');
  132. }
  133. $dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/error_logs/old';
  134. $files = nv_clear_files($dir, NV_LOGS_DIR . '/error_logs/old');
  135. foreach ($files as $file)
  136. {
  137. $xtpl->assign('DELFILE', $file);
  138. $xtpl->parse('main.delfile.loop');
  139. }
  140. $dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/error_logs/tmp';
  141. $files = nv_clear_files($dir, NV_LOGS_DIR . '/error_logs/tmp');
  142. foreach ($files as $file)
  143. {
  144. $xtpl->assign('DELFILE', $file);
  145. $xtpl->parse('main.delfile.loop');
  146. }
  147. }
  148. if (in_array('clearip_logs', $deltype))
  149. {
  150. $dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/ip_logs';
  151. $files = nv_clear_files($dir, NV_LOGS_DIR . '/ip_logs');
  152. foreach ($files as $file)
  153. {
  154. $xtpl->assign('DELFILE', $file);
  155. $xtpl->parse('main.delfile.loop');
  156. }
  157. }
  158. $xtpl->parse('main.delfile');
  159. }
  160. $xtpl->parse('main');
  161. $contents = $xtpl->text('main');
  162. include (NV_ROOTDIR . "/includes/header.php");
  163. echo nv_admin_theme($contents);
  164. include (NV_ROOTDIR . "/includes/footer.php");
  165. ?>