人人商城

filecheck.ctrl.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->func('file');
  8. load()->model('cloud');
  9. load()->func('communication');
  10. $dos = array('check');
  11. $do = in_array($do, $dos) ? $do : '';
  12. $_W['page']['title'] = '系统文件校验 - 常用系统工具 - 系统管理';
  13. if ($do == 'check') {
  14. $filetree = file_tree(IA_ROOT, array('api', 'app', 'framework', 'payment', 'web', 'api.php', 'index.php'));
  15. $modify = $unknown = $lose = $clouds = array();
  16. $params = _cloud_build_params();
  17. $params['method'] = 'application.build';
  18. $response = cloud_request('http://v2.addons.we7.cc/gateway.php', $params);
  19. $file = IA_ROOT . '/data/application.build';
  20. $cloud_data = _cloud_shipping_parse($response, $file);
  21. if (!empty($cloud_data['files'])) {
  22. foreach ($cloud_data['files'] as $value) {
  23. $clouds[$value['path']]['path'] = $value['path'];
  24. $clouds[$value['path']]['checksum'] = $value['checksum'];
  25. }
  26. foreach ($filetree as $filename) {
  27. $file = str_replace(IA_ROOT, '', $filename);
  28. $ignore_list = array(
  29. strpos($file, '/data/tpl/') === 0,
  30. substr($file, -8) == 'map.json',
  31. strpos($file, '/data/logs') === 0,
  32. strpos($file, '/attachment') === 0,
  33. $file == '/data/config.php',
  34. strpos($file, '/data') === 0 &&
  35. substr($file, -4) == 'lock',
  36. strpos($file, '/app/themes/default') === 0,
  37. $file == '/framework/version.inc.php'
  38. );
  39. if (in_array(true, $ignore_list)) {
  40. continue;
  41. }
  42. if (preg_match('/\/addons\/([a-zA-Z_0-9\-]+)\/.*/', $file, $match)) {
  43. $module = IA_ROOT . '/addons/' . $match[1];
  44. if (file_exists($module . '/map.json')) {
  45. $maps = file_get_contents($module . '/map.json');
  46. $maps = json_decode($maps, true);
  47. if (!empty($maps)) {
  48. $checksum_found = false;
  49. foreach ($maps as $map) {
  50. if (!is_array($map) || empty($map['checksum'])) {
  51. continue;
  52. } else {
  53. $checksum_found = true;
  54. $clouds['/addons/'.$match[1].$map['path']] = array('path' => '/addons/'.$match[1].$map['path'], 'checksum' => $map['checksum']);
  55. }
  56. }
  57. if (empty($checksum_found)) {
  58. continue;
  59. }
  60. }
  61. } else {
  62. continue;
  63. }
  64. }
  65. if (preg_match('/\/app\/themes\/([a-zA-Z_0-9\-]+)\/.*/', $file, $match)) {
  66. $template = IA_ROOT . '/app/themes/' . $match[1];
  67. if (file_exists($template . '/map.json')) {
  68. $maps = file_get_contents($template . '/map.json');
  69. $maps = json_decode($maps, true);
  70. if (!empty($maps)) {
  71. $checksum_found = false;
  72. foreach ($maps as $map) {
  73. if (!is_array($map) || empty($map['checksum'])) {
  74. continue;
  75. } else {
  76. $checksum_found = true;
  77. $clouds['/app/themes/'.$match[1].$map['path']] = array('path' => '/app/themes/'.$match[1].$map['path'], 'checksum' => $map['checksum']);
  78. }
  79. }
  80. if (empty($checksum_found)) {
  81. continue;
  82. }
  83. }
  84. } else {
  85. continue;
  86. }
  87. }
  88. if (!empty($clouds[$file])) {
  89. if (!is_file($filename) || md5_file($filename) != $clouds[$file]['checksum']) {
  90. $modify[] = $file;
  91. }
  92. } else {
  93. $unknown[] = $file;
  94. }
  95. }
  96. foreach ($clouds as $value) {
  97. $cloud = IA_ROOT.$value['path'];
  98. if (!in_array($cloud, $filetree)) {
  99. $cloud = str_replace(IA_ROOT, '', $cloud);
  100. $lose[] = $cloud;
  101. }
  102. }
  103. }
  104. $count_unknown = count($unknown);
  105. $count_lose = count($lose);
  106. $count_modify = count($modify);
  107. }
  108. template('system/filecheck');