Index.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Hook;
  4. use think\Db;
  5. class Index extends Base
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function login()
  12. {
  13. if (Request()->isPost()) {
  14. $data = input('post.');
  15. $res = model('Admin')->login($data);
  16. if ($res['code'] > 1) {
  17. return $this->error($res['msg']);
  18. }
  19. return $this->success($res['msg']);
  20. }
  21. Hook::listen("admin_login_init", $this->request);
  22. return $this->fetch('admin@index/login');
  23. }
  24. public function logout()
  25. {
  26. $res = model('Admin')->logout();
  27. $this->redirect('index/login');
  28. }
  29. public function index()
  30. {
  31. $menus = @include MAC_ADMIN_COMM . 'auth.php';
  32. $version = config('version');
  33. foreach ($menus as $k1 => $v1) {
  34. foreach ($v1['sub'] as $k2 => $v2) {
  35. if ($v2['show'] == 1) {
  36. if (strpos($v2['action'], 'javascript') !== false) {
  37. $url = $v2['action'];
  38. } else {
  39. $url = url('admin/' . $v2['controller'] . '/' . $v2['action']);
  40. }
  41. if (!empty($v2['param'])) {
  42. $url .= '?' . $v2['param'];
  43. }
  44. if ($this->check_auth($v2['controller'], $v2['action'])) {
  45. $menus[$k1]['sub'][$k2]['url'] = $url;
  46. } else {
  47. unset($menus[$k1]['sub'][$k2]);
  48. }
  49. } else {
  50. unset($menus[$k1]['sub'][$k2]);
  51. }
  52. }
  53. if (empty($menus[$k1]['sub'])) {
  54. unset($menus[$k1]);
  55. }
  56. }
  57. $quickmenu = config('quickmenu');
  58. if (empty($quickmenu)) {
  59. $quickmenu = mac_read_file(APP_PATH . 'data/config/quickmenu.txt');
  60. $quickmenu = explode(chr(13), $quickmenu);
  61. }
  62. if (!empty($quickmenu)) {
  63. $menus[1]['sub'][13] = ['name' => lang('admin/index/quick_tit'), 'url' => 'javascript:void(0);return false;', 'controller' => '', 'action' => ''];
  64. foreach ($quickmenu as $k => $v) {
  65. if (empty($v)) {
  66. continue;
  67. }
  68. $one = explode(',', trim($v));
  69. if (substr($one[1], 0, 4) == 'http' || substr($one[1], 0, 2) == '//') {
  70. } elseif (substr($one[1], 0, 1) == '/') {
  71. } elseif (strpos($one[1], '###') !== false || strpos($one[1], 'javascript:') !== false) {
  72. } else {
  73. $one[1] = url($one[1]);
  74. }
  75. $menus[1]['sub'][14 + $k] = ['name' => $one[0], 'url' => $one[1], 'controller' => '', 'action' => ''];
  76. }
  77. }
  78. $langs = glob('./application/lang/*.php');
  79. foreach ($langs as $k => &$v) {
  80. $v = str_replace(['./application/lang/','.php'],['',''],$v);
  81. }
  82. $config = config('maccms');
  83. $this->assign('config', $config);
  84. $this->assign('langs', $langs);
  85. $this->assign('version', $version);
  86. $this->assign('menus', $menus);
  87. $this->assign('title', lang('admin/index/title'));
  88. return $this->fetch('admin@index/index');
  89. }
  90. public function welcome()
  91. {
  92. $version = config('version');
  93. $update_sql = file_exists('./application/data/update/database.php');
  94. $this->assign('spider_data', $this->botlist());
  95. $this->assign('os_data', $this->get_system_status());
  96. $this->assign('version', $version);
  97. $this->assign('update_sql', $update_sql);
  98. $this->assign('mac_lang', config('default_lang'));
  99. $this->assign('dashboard_data', $this->getAdminDashboardData());
  100. $this->assign('admin', $this->_admin);
  101. $this->assign('title', lang('admin/index/welcome/title'));
  102. return $this->fetch('admin@index/welcome');
  103. }
  104. public function quickmenu()
  105. {
  106. if (Request()->isPost()) {
  107. $param = input();
  108. $validate = \think\Loader::validate('Token');
  109. if (!$validate->check($param)) {
  110. return $this->error($validate->getError());
  111. }
  112. $quickmenu = input('post.quickmenu');
  113. $quickmenu = str_replace(chr(10), '', $quickmenu);
  114. $menu_arr = explode(chr(13), $quickmenu);
  115. $res = mac_arr2file(APP_PATH . 'extra/quickmenu.php', $menu_arr);
  116. if ($res === false) {
  117. return $this->error(lang('save_err'));
  118. }
  119. return $this->success(lang('save_ok'));
  120. } else {
  121. $config_menu = config('quickmenu');
  122. if (empty($config_menu)) {
  123. $quickmenu = mac_read_file(APP_PATH . 'data/config/quickmenu.txt');
  124. } else {
  125. $quickmenu = array_values($config_menu);
  126. $quickmenu = join(chr(13), $quickmenu);
  127. }
  128. $this->assign('quickmenu', $quickmenu);
  129. $this->assign('title', lang('admin/index/quickmenu/title'));
  130. return $this->fetch('admin@index/quickmenu');
  131. }
  132. }
  133. public function checkcache()
  134. {
  135. $res = 'no';
  136. $r = cache('cache_data');
  137. if ($r == '1') {
  138. $res = 'haved';
  139. }
  140. echo $res;
  141. }
  142. public function clear()
  143. {
  144. $res = $this->_cache_clear();
  145. //运行缓存
  146. if (!$res) {
  147. $this->error(lang('admin/index/clear_err'));
  148. }
  149. // 搜索缓存结果清理
  150. model('VodSearch')->clearOldResult(true);
  151. return $this->success(lang('admin/index/clear_ok'));
  152. }
  153. public function iframe()
  154. {
  155. $val = input('post.val', 0);
  156. if ($val != 0 && $val != 1) {
  157. return $this->error(lang('admin/index/clear_ok'));
  158. }
  159. if ($val == 1) {
  160. cookie('is_iframe', 'yes');
  161. } else {
  162. cookie('is_iframe', null);
  163. }
  164. return $this->success(lang('admin/index/iframe'));
  165. }
  166. public function unlocked()
  167. {
  168. $param = input();
  169. $password = $param['password'];
  170. if ($this->_admin['admin_pwd'] != md5($password)) {
  171. return $this->error(lang('admin/index/pass_err'));
  172. }
  173. return $this->success(lang('admin/index/unlock_ok'));
  174. }
  175. public function check_back_link()
  176. {
  177. $param = input();
  178. $res = mac_check_back_link($param['url']);
  179. return json($res);
  180. }
  181. public function select()
  182. {
  183. $param = input();
  184. $tpl = $param['tpl'];
  185. $tab = $param['tab'];
  186. $col = $param['col'];
  187. $ids = $param['ids'];
  188. $url = $param['url'];
  189. $val = $param['val'];
  190. $refresh = $param['refresh'];
  191. if (empty($tpl) || empty($tab) || empty($col) || empty($ids) || empty($url)) {
  192. return $this->error(lang('param_err'));
  193. }
  194. if (is_array($ids)) {
  195. $ids = join(',', $ids);
  196. }
  197. if (empty($refresh)) {
  198. $refresh = 'yes';
  199. }
  200. $url = url($url);
  201. $mid = 1;
  202. if ($tab == 'art') {
  203. $mid = 2;
  204. } elseif ($tab == 'actor') {
  205. $mid = 8;
  206. } elseif ($tab == 'website') {
  207. $mid = 11;
  208. }
  209. $this->assign('mid', $mid);
  210. if ($tpl == 'select_type') {
  211. $type_tree = model('Type')->getCache('type_tree');
  212. $this->assign('type_tree', $type_tree);
  213. } elseif ($tpl == 'select_level') {
  214. $level_list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  215. $this->assign('level_list', $level_list);
  216. }
  217. $this->assign('refresh', $refresh);
  218. $this->assign('url', $url);
  219. $this->assign('tab', $tab);
  220. $this->assign('col', $col);
  221. $this->assign('ids', $ids);
  222. $this->assign('val', $val);
  223. return $this->fetch('admin@public/' . $tpl);
  224. }
  225. public function get_system_status()
  226. {
  227. //判斷系統
  228. $os_name = strtoupper(substr(PHP_OS, 0, 3));
  229. $os_data = [];
  230. $os_data['os_name'] = '';
  231. if ($os_name == 'WIN') {
  232. $os_data['os_name'] = 'WINDOWS';
  233. $os_data['disk_datas'] = $this->get_spec_disk('all');
  234. $os_data['cpu_usage'] = $this->getCpuUsage();
  235. $mem_arr = $this->getMemoryUsage();
  236. $os_data['mem_usage'] = $mem_arr['usage'];
  237. $os_data['mem_total'] = round($mem_arr['TotalVisibleMemorySize'] / 1024, 2);
  238. $os_data['mem_used'] = $os_data['mem_total'] - round($mem_arr['FreePhysicalMemory'] / 1024, 2);
  239. } else if ($os_name == 'LIN') {
  240. $os_data['os_name'] = 'LINUX';
  241. $totalSpace = disk_total_space('/'); // 获取根目录的总容量
  242. $freeSpace = disk_free_space('/'); // 获取根目录的可用容量
  243. $totalSpaceGB = $totalSpace / (1024 * 1024 * 1024); // 将总容量转换为GB
  244. $freeSpaceGB = $freeSpace / (1024 * 1024 * 1024); // 将可用容量转换为GB
  245. $tmp_disk_data = [];
  246. $tmp_disk_data[0] = $totalSpaceGB - $freeSpaceGB;
  247. $tmp_disk_data[1] = $totalSpaceGB;
  248. $tmp_disk_data[2] = (100 - round(($freeSpaceGB / $totalSpaceGB) * 100, 2));
  249. $os_data['disk_datas']['/'] = $tmp_disk_data;
  250. $mem_arr = $this->get_linux_server_memory_usage();
  251. $os_data['mem_usage'] = $mem_arr['usage'];
  252. $os_data['mem_used'] = $mem_arr['used'];
  253. $os_data['mem_total'] = $mem_arr['total'];
  254. $os_data['cpu_usage'] = $this->get_linux_server_cpu_usage()['usage'];
  255. // if (is_readable("/proc/stat")) {
  256. // $statData1 = $this->_getServerLoadLinuxData();
  257. // sleep(0.5);
  258. // $statData2 = $this->_getServerLoadLinuxData();
  259. // if (
  260. // (!is_null($statData1)) &&
  261. // (!is_null($statData2))
  262. // ) {
  263. // $statData2[0] -= $statData1[0];
  264. // $statData2[1] -= $statData1[1];
  265. // $statData2[2] -= $statData1[2];
  266. // $statData2[3] -= $statData1[3];
  267. // $cpuTime = $statData2[0] + $statData2[1] + $statData2[2] + $statData2[3];
  268. // if ($cpuTime > 0) {
  269. // $os_data['cpu_usage'] = 100 - ($statData2[3] * 100 / $cpuTime);
  270. // } else {
  271. // $os_data['cpu_usage'] = 0;
  272. // }
  273. // }
  274. // }
  275. }
  276. return $os_data;
  277. }
  278. private function byte_format($size, $dec = 2)
  279. {
  280. $a = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  281. $pos = 0;
  282. while ($size >= 1024) {
  283. $size /= 1024;
  284. $pos++;
  285. }
  286. return round($size, $dec);
  287. }
  288. private function get_disk_space($letter)
  289. {
  290. //获取磁盘信息
  291. $diskct = 0;
  292. $disk = array();
  293. $diskz = 0; //磁盘总容量
  294. $diskk = 0; //磁盘剩余容量
  295. $is_disk = $letter . ':';
  296. if (@disk_total_space($is_disk) != NULL) {
  297. $diskct++;
  298. $disk[$letter][0] = $this->byte_format(@disk_free_space($is_disk));
  299. $disk[$letter][1] = $this->byte_format(@disk_total_space($is_disk));
  300. // $disk[$letter][2] = (100-round(((@disk_free_space($is_disk)/(1024*1024*1024))/(@disk_total_space($is_disk)/(1024*1024*1024)))*100,2));
  301. $disk[$letter][2] = (round(100 - round(((@disk_free_space($is_disk) / (1024 * 1024 * 1024)) / (@disk_total_space($is_disk) / (1024 * 1024 * 1024))) * 100, 2), 2));
  302. $diskk += $this->byte_format(@disk_free_space($is_disk));
  303. $diskz += $this->byte_format(@disk_total_space($is_disk));
  304. }
  305. return $disk;
  306. }
  307. private function get_spec_disk($type = 'system')
  308. {
  309. $disk = array();
  310. switch ($type) {
  311. case 'system':
  312. //strrev(array_pop(explode(':',strrev(getenv_info('SystemRoot')))));//取得系统盘符
  313. $disk = $this->get_disk_space(strrev(array_pop(explode(':', strrev(getenv('SystemRoot'))))));
  314. break;
  315. case 'all':
  316. foreach (range('b', 'z') as $letter) {
  317. $disk = array_merge($disk, $this->get_disk_space(strtoupper($letter)));
  318. }
  319. break;
  320. default:
  321. $disk = $this->get_disk_space($type);
  322. break;
  323. }
  324. return $disk;
  325. }
  326. private function getFilePath($fileName, $content)
  327. {
  328. $path = dirname(__FILE__) . "\\$fileName";
  329. if (!file_exists($path)) {
  330. file_put_contents($path, $content);
  331. }
  332. return $path;
  333. }
  334. /**
  335. * 获得cpu使用率vbs文件生成函数
  336. * @return string 返回vbs文件路径
  337. */
  338. private function getCupUsageVbsPath()
  339. {
  340. return $this->getFilePath(
  341. 'cpu_usage.vbs',
  342. "On Error Resume Next
  343. Set objProc = GetObject(\"winmgmts:\\\\.\\root\cimv2:win32_processor='cpu0'\")
  344. WScript.Echo(objProc.LoadPercentage)"
  345. );
  346. }
  347. /**
  348. * 获得总内存及可用物理内存JSON vbs文件生成函数
  349. * @return string 返回vbs文件路径
  350. */
  351. private function getMemoryUsageVbsPath()
  352. {
  353. return $this->getFilePath(
  354. 'memory_usage.vbs',
  355. "On Error Resume Next
  356. Set objWMI = GetObject(\"winmgmts:\\\\.\\root\cimv2\")
  357. Set colOS = objWMI.InstancesOf(\"Win32_OperatingSystem\")
  358. For Each objOS in colOS
  359. Wscript.Echo(\"{\"\"TotalVisibleMemorySize\"\":\" & objOS.TotalVisibleMemorySize & \",\"\"FreePhysicalMemory\"\":\" & objOS.FreePhysicalMemory & \"}\")
  360. Next"
  361. );
  362. }
  363. /**
  364. * 获得CPU使用率
  365. * @return Number
  366. */
  367. private function getCpuUsage()
  368. {
  369. $path = $this->getCupUsageVbsPath();
  370. exec("cscript -nologo $path", $usage);
  371. return $usage[0];
  372. }
  373. /**
  374. * 获得内存使用率数组
  375. * @return array
  376. */
  377. private function getMemoryUsage()
  378. {
  379. $path = $this->getMemoryUsageVbsPath();
  380. exec("cscript -nologo $path", $usage);
  381. $memory = json_decode($usage[0], true);
  382. $memory['usage'] = Round((($memory['TotalVisibleMemorySize'] - $memory['FreePhysicalMemory']) / $memory['TotalVisibleMemorySize']) * 100);
  383. return $memory;
  384. }
  385. private function get_linux_server_memory_usage()
  386. {
  387. $free = shell_exec('free');
  388. $free = (string)trim($free);
  389. $free_arr = explode("\n", $free);
  390. $mem = explode(" ", $free_arr[1]);
  391. $mem = array_filter($mem);
  392. $mem = array_merge($mem);
  393. $memory_usage = $mem[2] / $mem[1] * 100;
  394. $mem_array = [];
  395. $mem_array['total'] = round($mem[1] / 1024, 2);
  396. $mem_array['used'] = round($mem[2] / 1024, 2);
  397. $mem_array['usage'] = round($memory_usage, 2);
  398. return $mem_array;
  399. }
  400. private function get_linux_server_cpu_usage()
  401. {
  402. $cpu_load = shell_exec("top -bn1 | grep 'Cpu(s)'");
  403. if (empty($cpu_load)) {
  404. return ['error' => 'Failed to retrieve CPU usage.'];
  405. }
  406. preg_match('/\s([\d.]+)\s*us/', $cpu_load, $matches);
  407. if (isset($matches[1])) {
  408. $cpu_usage = (float)$matches[1];
  409. } else {
  410. return ['error' => 'Failed to parse CPU usage.'];
  411. }
  412. return [
  413. 'usage' => round($cpu_usage, 2)
  414. ];
  415. }
  416. private function _getServerLoadLinuxData()
  417. {
  418. if (is_readable("/proc/stat")) {
  419. $stats = @file_get_contents("/proc/stat");
  420. if ($stats !== false) {
  421. // Remove double spaces to make it easier to extract values with explode()
  422. $stats = preg_replace("/[[:blank:]]+/", " ", $stats);
  423. // Separate lines
  424. $stats = str_replace(array("\r\n", "\n\r", "\r"), "\n", $stats);
  425. $stats = explode("\n", $stats);
  426. // Separate values and find line for main CPU load
  427. foreach ($stats as $statLine) {
  428. $statLineData = explode(" ", trim($statLine));
  429. // Found!
  430. if (
  431. (count($statLineData) >= 5) &&
  432. ($statLineData[0] == "cpu")
  433. ) {
  434. return array(
  435. $statLineData[1],
  436. $statLineData[2],
  437. $statLineData[3],
  438. $statLineData[4],
  439. );
  440. }
  441. }
  442. }
  443. }
  444. return null;
  445. }
  446. private function getAdminDashboardData()
  447. {
  448. $result = [];
  449. //已注册总用户数量
  450. $result['user_count'] = model('User')->count();
  451. $result['user_count'] = number_format($result['user_count'], 0, '.', ',');
  452. //已审核用户数量
  453. $result['user_active_count'] = model('User')->where('user_status', 1)->count();
  454. $result['user_active_count'] = number_format($result['user_active_count'], 0, '.', ',');
  455. $today_start = strtotime(date('Y-m-d 00:00:00'));
  456. $today_end = $today_start + 86399;
  457. //本日来客量
  458. $result['today_visit_count'] = model('Visit')->where('visit_time', 'between', $today_start . ',' . $today_end)->count();
  459. $result['today_visit_count'] = number_format($result['today_visit_count'], 0, '.', ',');
  460. //本日总入金
  461. $result['today_money_get'] = model('Order')->where('order_time', 'between', $today_start . ',' . $today_end)->where('order_status', 1)->sum('order_price');
  462. $result['today_money_get'] = number_format($result['today_money_get'], 2, '.', ',');
  463. //前七天 每日用户访问数
  464. $tmp_arr = Db::query("select FROM_UNIXTIME(visit_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_visit where visit_time >= (unix_timestamp(CURDATE())-604800)) as temp group by days");
  465. $result['seven_day_visit_day'] = [];
  466. $result['seven_day_visit_count'] = [];
  467. $result['raise_visit_user_today'] = 0;
  468. if (is_array($tmp_arr) && count($tmp_arr) > 1 && (strtotime(end($tmp_arr)['days']) == strtotime(date('Y-m-d')))) {
  469. $yesterday_visit_count = $tmp_arr[count($tmp_arr) - 2]['count'];
  470. $lastday_visit_count = end($tmp_arr)['count'];
  471. $result['raise_visit_user_today'] = number_format((($lastday_visit_count - $yesterday_visit_count) / $yesterday_visit_count) * 100, 2, '.', ',');
  472. }
  473. foreach ($tmp_arr as $data) {
  474. array_push($result['seven_day_visit_day'], $data['days']);
  475. array_push($result['seven_day_visit_count'], $data['count']);
  476. }
  477. //近七日用户访问总量
  478. $result['seven_day_visit_total_count'] = 0;
  479. foreach ($result['seven_day_visit_data'] as $k => $value) {
  480. $result['seven_day_visit_total_count'] = $result['seven_day_visit_total_count'] + $value['count'];
  481. }
  482. $result['seven_day_visit_total_count'] = number_format($result['seven_day_visit_total_count'], 0, '.', ',');
  483. //前七天 每日用户注册数
  484. $result['seven_day_reg_data'] = Db::query("select FROM_UNIXTIME(user_reg_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_user where user_reg_time >= (unix_timestamp(CURDATE())-604800)) as tmp group by days");
  485. //近七日用户注册总量
  486. $result['seven_day_reg_total_count'] = 0;
  487. $result['seven_day_reg_day'] = [];
  488. $result['seven_day_reg_count'] = [];
  489. foreach ($result['seven_day_reg_data'] as $k => $value) {
  490. array_push($result['seven_day_reg_day'], $value['days']);
  491. array_push($result['seven_day_reg_count'], $value['count']);
  492. $result['seven_day_reg_total_count'] = $result['seven_day_reg_total_count'] + $value['count'];
  493. }
  494. //比較前一天的註冊量漲幅
  495. $result['raise_reg_user_today'] = 0;
  496. if (is_array($result['seven_day_reg_data']) && count($result['seven_day_reg_data']) > 1 && (strtotime(end($result['seven_day_reg_data'])['days']) == strtotime(date('Y-m-d')))) {
  497. $yesterday_reg_count = $result['seven_day_reg_data'][count($result['seven_day_reg_data']) - 2]['count'];
  498. $lastday_reg_count = end($result['seven_day_reg_data'])['count'];
  499. $result['raise_reg_user_today'] = number_format((($lastday_reg_count - $yesterday_reg_count) / $yesterday_reg_count) * 100, 2, '.', ',');
  500. }
  501. $result['seven_day_reg_total_count'] = number_format($result['seven_day_reg_total_count'], 0, '.', ',');
  502. return $result;
  503. }
  504. public function rangeDateDailyVisit()
  505. {
  506. $range_daily_visit_data = Db::query("select FROM_UNIXTIME(visit_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_visit where visit_time >= " . strtotime($_POST['startDate']) . "&& visit_time <= " . strtotime($_POST['endDate']) . " ) as temp group by days");
  507. $result = [];
  508. $range_visit_day = [];
  509. $range_visit_count = [];
  510. $range_visit_sum = 0;
  511. foreach ($range_daily_visit_data as $data) {
  512. $range_visit_sum = $range_visit_sum + $data['count'];
  513. array_push($range_visit_day, $data['days']);
  514. array_push($range_visit_count, $data['count']);
  515. }
  516. $result['days'] = $range_visit_day;
  517. $result['count'] = $range_visit_count;
  518. $result['sum'] = $range_visit_sum;
  519. return json_encode($result);
  520. }
  521. public function botlist()
  522. {
  523. $day_arr = [];
  524. //列出最近10天的日期
  525. for ($i = 0; $i < 7; $i++) {
  526. $day_arr[$i] = date('Y-m-d', time() - $i * 60 * 60 * 24);
  527. }
  528. $google_arr = [];
  529. $baidu_arr = [];
  530. $sogou_arr = [];
  531. $soso_arr = [];
  532. $yahoo_arr = [];
  533. $msn_arr = [];
  534. $msn_bot_arr = [];
  535. $sohu_arr = [];
  536. $yodao_arr = [];
  537. $twiceler_arr = [];
  538. $alexa_arr = [];
  539. $bot_list = [];
  540. foreach ($day_arr as $day_vo) {
  541. if (file_exists(ROOT_PATH . 'runtime/log/bot/' . $day_vo . '.txt')) {
  542. $bot_content = file_get_contents(ROOT_PATH . 'runtime/log/bot/' . $day_vo . '.txt');
  543. } else {
  544. $bot_content = '';
  545. }
  546. $google_arr[$day_vo] = substr_count($bot_content, 'Google');
  547. $baidu_arr[$day_vo] = substr_count($bot_content, 'Baidu');
  548. $sogou_arr[$day_vo] = substr_count($bot_content, 'Sogou');
  549. $soso_arr[$day_vo] = substr_count($bot_content, 'SOSO');
  550. $yahoo_arr[$day_vo] = substr_count($bot_content, 'Yahoo');
  551. $msn_arr[$day_vo] = substr_count($bot_content, 'MSN');
  552. $msn_bot_arr[$day_vo] = substr_count($bot_content, 'msnbot');
  553. $sohu_arr[$day_vo] = substr_count($bot_content, 'Sohu');
  554. $yodao_arr[$day_vo] = substr_count($bot_content, 'Yodao');
  555. $twiceler_arr[$day_vo] = substr_count($bot_content, 'Twiceler');
  556. $alexa_arr[$day_vo] = substr_count($bot_content, 'Alexa');
  557. }
  558. $bot_list['Google']['key'] = array_keys($google_arr);
  559. $bot_list['Google']['values'] = array_values($google_arr);
  560. $bot_list['Baidu']['keys'] = array_keys($baidu_arr);
  561. $bot_list['Baidu']['values'] = array_values($baidu_arr);
  562. $bot_list['Sogou']['keys'] = array_keys($sogou_arr);
  563. $bot_list['Sogou']['values'] = array_values($sogou_arr);
  564. $bot_list['SOSO']['keys'] = array_keys($soso_arr);
  565. $bot_list['SOSO']['values'] = array_values($soso_arr);
  566. $bot_list['Yahoo']['keys'] = array_keys($yahoo_arr);
  567. $bot_list['Yahoo']['values'] = array_values($yahoo_arr);
  568. $bot_list['MSN']['keys'] = array_keys($msn_arr);
  569. $bot_list['MSN']['values'] = array_values($msn_arr);
  570. $bot_list['msnbot']['keys'] = array_keys($msn_bot_arr);
  571. $bot_list['msnbot']['values'] = array_values($msn_bot_arr);
  572. $bot_list['Sohu']['keys'] = array_keys($sohu_arr);
  573. $bot_list['Sohu']['values'] = array_values($sohu_arr);
  574. $bot_list['Yodao']['keys'] = array_keys($yodao_arr);
  575. $bot_list['Yodao']['values'] = array_values($yodao_arr);
  576. $bot_list['Twiceler']['keys'] = array_keys($twiceler_arr);
  577. $bot_list['Twiceler']['values'] = array_values($twiceler_arr);
  578. $bot_list['Alexa']['keys'] = array_keys($alexa_arr);
  579. $bot_list['Alexa']['values'] = array_values($alexa_arr);
  580. if (!empty($_POST['category'])) {
  581. return $bot_list[$_POST['category']];
  582. } else {
  583. return $bot_list;
  584. }
  585. }
  586. public function botlog()
  587. {
  588. $parm = input();
  589. $data = $parm['data'];
  590. $bot_content = file_get_contents(ROOT_PATH . 'runtime/log/bot/' . $data . '.txt');
  591. $bot_list = array_slice(array_reverse(explode("\r\n", trim($bot_content))), 0, 20);
  592. $this->assign('bot_list', $bot_list);
  593. return $this->fetch('admin@others/botlog');
  594. }
  595. }