PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/yurivn/admincp/modlog.php

https://gitlab.com/trang1104/portable_project
PHP | 426 lines | 342 code | 55 blank | 29 comment | 52 complexity | 325f5582c08d0c1f08b225d3d6198c2e MD5 | raw file
Possible License(s): GPL-2.0, BSD-2-Clause, AGPL-1.0, Apache-2.0, GPL-3.0, MPL-2.0, LGPL-3.0, LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. /*======================================================================*\
  3. || #################################################################### ||
  4. || # vBulletin 4.2.2 Alpha 1 - Licence Number VBFSA2W3VC
  5. || # ---------------------------------------------------------------- # ||
  6. || # Copyright ©2000-2013 vBulletin Solutions Inc. All Rights Reserved. ||
  7. || # This file may not be redistributed in whole or significant part. # ||
  8. || # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
  9. || # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
  10. || #################################################################### ||
  11. \*======================================================================*/
  12. // ######################## SET PHP ENVIRONMENT ###########################
  13. error_reporting(E_ALL & ~E_NOTICE);
  14. // ##################### DEFINE IMPORTANT CONSTANTS #######################
  15. define('CVS_REVISION', '$RCSfile$ - $Revision: 42666 $');
  16. // #################### PRE-CACHE TEMPLATES AND DATA ######################
  17. $phrasegroups = array('logging', 'threadmanage');
  18. $specialtemplates = array();
  19. // ########################## REQUIRE BACK-END ############################
  20. require_once('./global.php');
  21. require_once(DIR . '/includes/functions_log_error.php');
  22. // ############################# LOG ACTION ###############################
  23. if (!can_administer('canadminmodlog'))
  24. {
  25. print_cp_no_permission();
  26. }
  27. log_admin_action();
  28. // ########################################################################
  29. // ######################### START MAIN SCRIPT ############################
  30. // ########################################################################
  31. print_cp_header($vbphrase['moderator_log']);
  32. if (empty($_REQUEST['do']))
  33. {
  34. $_REQUEST['do'] = 'choose';
  35. }
  36. // ###################### Start view #######################
  37. if ($_REQUEST['do'] == 'view')
  38. {
  39. $vbulletin->input->clean_array_gpc('r', array(
  40. 'perpage' => TYPE_UINT,
  41. 'pagenumber' => TYPE_UINT,
  42. 'userid' => TYPE_UINT,
  43. 'modaction' => TYPE_STR,
  44. 'orderby' => TYPE_NOHTML,
  45. 'product' => TYPE_STR,
  46. 'startdate' => TYPE_UNIXTIME,
  47. 'enddate' => TYPE_UNIXTIME,
  48. ));
  49. $princids = array(
  50. 'poll_question' => $vbphrase['question'],
  51. 'post_title' => $vbphrase['post'],
  52. 'thread_title' => $vbphrase['thread'],
  53. 'forum_title' => $vbphrase['forum'],
  54. 'attachment_title' => $vbphrase['attachment'],
  55. );
  56. $sqlconds = array();
  57. $hook_query_fields = $hook_query_joins = '';
  58. if ($vbulletin->GPC['perpage'] < 1)
  59. {
  60. $vbulletin->GPC['perpage'] = 15;
  61. }
  62. if ($vbulletin->GPC['userid'] OR $vbulletin->GPC['modaction'])
  63. {
  64. if ($vbulletin->GPC['userid'])
  65. {
  66. $sqlconds[] = "moderatorlog.userid = " . $vbulletin->GPC['userid'];
  67. }
  68. if ($vbulletin->GPC['modaction'])
  69. {
  70. $sqlconds[] = "moderatorlog.action LIKE '%" . $db->escape_string_like($vbulletin->GPC['modaction']) . "%'";
  71. }
  72. }
  73. if ($vbulletin->GPC['startdate'])
  74. {
  75. $sqlconds[] = "moderatorlog.dateline >= " . $vbulletin->GPC['startdate'];
  76. }
  77. if ($vbulletin->GPC['enddate'])
  78. {
  79. $sqlconds[] = "moderatorlog.dateline <= " . $vbulletin->GPC['enddate'];
  80. }
  81. if ($vbulletin->GPC['product'])
  82. {
  83. if ($vbulletin->GPC['product'] == 'vbulletin')
  84. {
  85. $sqlconds[] = "moderatorlog.product IN ('', 'vbulletin')";
  86. }
  87. else
  88. {
  89. $sqlconds[] = "moderatorlog.product = '" . $db->escape_string($vbulletin->GPC['product']) . "'";
  90. }
  91. }
  92. ($hook = vBulletinHook::fetch_hook('admin_modlogviewer_query')) ? eval($hook) : false;
  93. $counter = $db->query_first("
  94. SELECT COUNT(*) AS total
  95. FROM " . TABLE_PREFIX . "moderatorlog AS moderatorlog
  96. " . (!empty($sqlconds) ? "WHERE " . implode("\r\n\tAND ", $sqlconds) : "") . "
  97. ");
  98. $totalpages = ceil($counter['total'] / $vbulletin->GPC['perpage']);
  99. if ($vbulletin->GPC['pagenumber'] < 1)
  100. {
  101. $vbulletin->GPC['pagenumber'] = 1;
  102. }
  103. $startat = ($vbulletin->GPC['pagenumber'] - 1) * $vbulletin->GPC['perpage'];
  104. switch($vbulletin->GPC['orderby'])
  105. {
  106. case 'user':
  107. $order = 'username ASC, dateline DESC';
  108. break;
  109. case 'modaction':
  110. $order = 'action ASC, dateline DESC';
  111. break;
  112. case 'date':
  113. default:
  114. $order = 'dateline DESC';
  115. }
  116. $logs = $db->query_read("
  117. SELECT moderatorlog.*, user.username,
  118. post.title AS post_title, forum.title AS forum_title, thread.title AS thread_title, poll.question AS poll_question, attachment.filename AS attachment_title
  119. $hook_query_fields
  120. FROM " . TABLE_PREFIX . "moderatorlog AS moderatorlog
  121. LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = moderatorlog.userid)
  122. LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = moderatorlog.postid)
  123. LEFT JOIN " . TABLE_PREFIX . "forum AS forum ON (forum.forumid = moderatorlog.forumid)
  124. LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = moderatorlog.threadid)
  125. LEFT JOIN " . TABLE_PREFIX . "poll AS poll ON (poll.pollid = moderatorlog.pollid)
  126. LEFT JOIN " . TABLE_PREFIX . "attachment AS attachment ON (attachment.attachmentid = moderatorlog.attachmentid)
  127. $hook_join_fields
  128. " . (!empty($sqlconds) ? "WHERE " . implode("\r\n\tAND ", $sqlconds) : "") . "
  129. ORDER BY $order
  130. LIMIT $startat, " . $vbulletin->GPC['perpage'] . "
  131. ");
  132. if ($db->num_rows($logs))
  133. {
  134. $vbulletin->GPC['modaction'] = htmlspecialchars_uni($vbulletin->GPC['modaction']);
  135. if ($vbulletin->GPC['pagenumber'] != 1)
  136. {
  137. $prv = $vbulletin->GPC['pagenumber'] - 1;
  138. $firstpage = "<input type=\"button\" class=\"button\" value=\"&laquo; " . $vbphrase['first_page'] . "\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=1'\">";
  139. $prevpage = "<input type=\"button\" class=\"button\" value=\"&lt; " . $vbphrase['prev_page'] . "\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$prv'\">";
  140. }
  141. if ($vbulletin->GPC['pagenumber'] != $totalpages)
  142. {
  143. $nxt = $vbulletin->GPC['pagenumber'] + 1;
  144. $nextpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['next_page'] . " &gt;\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$nxt'\">";
  145. $lastpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['last_page'] . " &raquo;\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$totalpages'\">";
  146. }
  147. print_form_header('modlog', 'remove');
  148. print_description_row(construct_link_code($vbphrase['restart'], "modlog.php?" . $vbulletin->session->vars['sessionurl'] . ""), 0, 6, 'thead', vB_Template_Runtime::fetchStyleVar('right'));
  149. print_table_header(construct_phrase($vbphrase['moderator_log_viewer_page_x_y_there_are_z_total_log_entries'], vb_number_format($vbulletin->GPC['pagenumber']), vb_number_format($totalpages), vb_number_format($counter['total'])), 6);
  150. $headings = array();
  151. $headings[] = $vbphrase['id'];
  152. $headings[] = "<a href=\"modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=user&page=" . $vbulletin->GPC['pagenumber'] . "\">" . str_replace(' ', '&nbsp;', $vbphrase['username']) . "</a>";
  153. $headings[] = "<a href=\"modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=date&page=" . $vbulletin->GPC['pagenumber'] . "\">" . $vbphrase['date'] . "</a>";
  154. //$headings[] = "<a href=\"modlog.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=modaction&page=" . $vbulletin->GPC['pagenumber'] . "\">" . $vbphrase['action'] . "</a>";
  155. $headings[] = $vbphrase['action'];
  156. $headings[] = $vbphrase['info'];
  157. $headings[] = str_replace(' ', '&nbsp;', $vbphrase['ip_address']);
  158. print_cells_row($headings, 1);
  159. while ($log = $db->fetch_array($logs))
  160. {
  161. $cell = array();
  162. $cell[] = $log['moderatorlogid'];
  163. $cell[] = "<a href=\"user.php?" . $vbulletin->session->vars['sessionurl'] . "do=edit&u=$log[userid]\"><b>$log[username]</b></a>";
  164. $cell[] = '<span class="smallfont">' . vbdate($vbulletin->options['logdateformat'], $log['dateline']) . '</span>';
  165. if ($log['type'])
  166. {
  167. $phrase = fetch_modlogactions($log['type']);
  168. if ($unserialized = unserialize($log['action']))
  169. {
  170. array_unshift($unserialized, $vbphrase["$phrase"]);
  171. $log['action'] = call_user_func_array('construct_phrase', $unserialized);
  172. }
  173. else
  174. {
  175. $log['action'] = construct_phrase($vbphrase["$phrase"], $log['action']);
  176. }
  177. }
  178. if ($log['thread_title'] == '' AND $log['threadtitle'] != '')
  179. {
  180. $log['thread_title'] =& $log['threadtitle'];
  181. }
  182. $cell[] = $log['action'];
  183. ($hook = vBulletinHook::fetch_hook('admin_modlogviewer_query_loop')) ? eval($hook) : false;
  184. $celldata = '';
  185. reset($princids);
  186. foreach ($princids AS $sqlfield => $output)
  187. {
  188. if ($sqlfield == 'post_title' AND $log['post_title'] == '' AND !empty($log['postid']))
  189. {
  190. $log['post_title'] = $vbphrase['untitled'];
  191. }
  192. if ($log["$sqlfield"])
  193. {
  194. if ($celldata)
  195. {
  196. $celldata .= "<br />\n";
  197. }
  198. $celldata .= "<b>$output:</b> ";
  199. switch($sqlfield)
  200. {
  201. case 'post_title':
  202. $celldata .= construct_link_code($log["$sqlfield"],
  203. fetch_seo_url('thread|bburl', $log, array('p' => $log['postid']), 'threadid', 'thread_title') . "#post$log[postid]",
  204. true);
  205. break;
  206. case 'thread_title':
  207. $celldata .= construct_link_code($log["$sqlfield"],
  208. fetch_seo_url('thread|bburl', $log, null, 'threadid', 'thread_title'), true);
  209. break;
  210. case 'forum_title':
  211. $celldata .= construct_link_code($log["$sqlfield"],
  212. fetch_seo_url('forum|bburl', $log, null, 'forumid', 'forum_title'), true);
  213. break;
  214. case 'attachment_title':
  215. $celldata .= construct_link_code(htmlspecialchars_uni($log["$sqlfield"]), "../attachment.php?" . $vbulletin->session->vars['sessionurl'] . "attachmentid=$log[attachmentid]&amp;nocache=" . TIMENOW, true);
  216. break;
  217. default:
  218. $handled = false;
  219. ($hook = vBulletinHook::fetch_hook('admin_modlogviewer_query_linkfield')) ? eval($hook) : false;
  220. if (!$handled)
  221. {
  222. $celldata .= $log["$sqlfield"];
  223. }
  224. }
  225. }
  226. }
  227. $cell[] = $celldata;
  228. $cell[] = '<span class="smallfont">' . iif($log['ipaddress'], "<a href=\"usertools.php?" . $vbulletin->session->vars['sessionurl'] . "do=gethost&ip=$log[ipaddress]\">$log[ipaddress]</a>", '&nbsp;') . '</span>';
  229. print_cells_row($cell, 0, 0, -4);
  230. }
  231. print_table_footer(6, "$firstpage $prevpage &nbsp; $nextpage $lastpage");
  232. }
  233. else
  234. {
  235. print_stop_message('no_results_matched_your_query');
  236. }
  237. }
  238. // ###################### Start prune log #######################
  239. if ($_REQUEST['do'] == 'prunelog' AND can_access_logs($vbulletin->config['SpecialUsers']['canpruneadminlog'], 0, '<p>' . $vbphrase['control_panel_log_pruning_permission_restricted'] . '</p>'))
  240. {
  241. $vbulletin->input->clean_array_gpc('r', array(
  242. 'daysprune' => TYPE_UINT,
  243. 'userid' => TYPE_UINT,
  244. 'modaction' => TYPE_STR,
  245. 'product' => TYPE_STR,
  246. ));
  247. $datecut = TIMENOW - (86400 * $vbulletin->GPC['daysprune']);
  248. $sqlconds = array("dateline < $datecut");
  249. if ($vbulletin->GPC['userid'])
  250. {
  251. $sqlconds[] = "userid = " . $vbulletin->GPC['userid'];
  252. }
  253. if ($vbulletin->GPC['modaction'])
  254. {
  255. $sqlconds[] = "action LIKE '%" . $db->escape_string_like($vbulletin->GPC['modaction']) . "%'";
  256. }
  257. if ($vbulletin->GPC['product'])
  258. {
  259. if ($vbulletin->GPC['product'] == 'vbulletin')
  260. {
  261. $sqlconds[] = "product IN ('', 'vbulletin')";
  262. }
  263. else
  264. {
  265. $sqlconds[] = "product = '" . $db->escape_string($vbulletin->GPC['product']) . "'";
  266. }
  267. }
  268. $logs = $db->query_first("
  269. SELECT COUNT(*) AS total
  270. FROM " . TABLE_PREFIX . "moderatorlog
  271. WHERE " . (!empty($sqlconds) ? implode("\r\n\tAND ", $sqlconds) : "") . "
  272. ");
  273. if ($logs['total'])
  274. {
  275. print_form_header('modlog', 'doprunelog');
  276. construct_hidden_code('datecut', $datecut);
  277. construct_hidden_code('modaction', $vbulletin->GPC['modaction']);
  278. construct_hidden_code('userid', $vbulletin->GPC['userid']);
  279. construct_hidden_code('product', $vbulletin->GPC['product']);
  280. print_table_header($vbphrase['prune_moderator_log']);
  281. print_description_row(construct_phrase($vbphrase['are_you_sure_you_want_to_prune_x_log_entries_from_moderator_log'], vb_number_format($logs['total'])));
  282. print_submit_row($vbphrase['yes'], 0, 0, $vbphrase['no']);
  283. }
  284. else
  285. {
  286. print_stop_message('no_logs_matched_your_query');
  287. }
  288. }
  289. // ###################### Start do prune log #######################
  290. if ($_POST['do'] == 'doprunelog' AND can_access_logs($vbulletin->config['SpecialUsers']['canpruneadminlog'], 0, '<p>' . $vbphrase['control_panel_log_pruning_permission_restricted'] . '</p>'))
  291. {
  292. $vbulletin->input->clean_array_gpc('p', array(
  293. 'datecut' => TYPE_UINT,
  294. 'modaction' => TYPE_STR,
  295. 'userid' => TYPE_UINT,
  296. 'product' => TYPE_STR,
  297. ));
  298. $sqlconds = array("dateline < " . $vbulletin->GPC['datecut']);
  299. if (!empty($vbulletin->GPC['modaction']))
  300. {
  301. $sqlconds[] = "action LIKE '%" . $db->escape_string_like($vbulletin->GPC['modaction']) . "%'";
  302. }
  303. if (!empty($vbulletin->GPC['userid']))
  304. {
  305. $sqlconds[] = "userid = " . $vbulletin->GPC['userid'];
  306. }
  307. if ($vbulletin->GPC['product'])
  308. {
  309. if ($vbulletin->GPC['product'] == 'vbulletin')
  310. {
  311. $sqlconds[] = "product IN ('', 'vbulletin')";
  312. }
  313. else
  314. {
  315. $sqlconds[] = "product = '" . $db->escape_string($vbulletin->GPC['product']) . "'";
  316. }
  317. }
  318. $db->query_write("
  319. DELETE FROM " . TABLE_PREFIX . "moderatorlog
  320. WHERE " . (!empty($sqlconds) ? implode("\r\n\tAND ", $sqlconds) : "") . "
  321. ");
  322. define('CP_REDIRECT', 'modlog.php?do=choose');
  323. print_stop_message('pruned_moderator_log_successfully');
  324. }
  325. // ###################### Start modify #######################
  326. if ($_REQUEST['do'] == 'choose')
  327. {
  328. $users = $db->query_read("
  329. SELECT DISTINCT moderatorlog.userid, user.username
  330. FROM " . TABLE_PREFIX . "moderatorlog AS moderatorlog
  331. INNER JOIN " . TABLE_PREFIX . "user AS user USING(userid)
  332. ORDER BY username
  333. ");
  334. $userlist = array('no_value' => $vbphrase['all_log_entries']);
  335. while ($user = $db->fetch_array($users))
  336. {
  337. $userlist["$user[userid]"] = $user['username'];
  338. }
  339. print_form_header('modlog', 'view');
  340. print_table_header($vbphrase['moderator_log_viewer']);
  341. print_input_row($vbphrase['log_entries_to_show_per_page'], 'perpage', 15);
  342. print_select_row($vbphrase['show_only_entries_generated_by'], 'userid', $userlist);
  343. print_time_row($vbphrase['start_date'], 'startdate', 0, 0);
  344. print_time_row($vbphrase['end_date'], 'enddate', 0, 0);
  345. if (count($products = fetch_product_list()) > 1)
  346. {
  347. print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products);
  348. }
  349. print_select_row($vbphrase['order_by'], 'orderby', array('date' => $vbphrase['date'], 'user' => $vbphrase['username']), 'date');
  350. print_submit_row($vbphrase['view'], 0);
  351. if (can_access_logs($vbulletin->config['SpecialUsers']['canpruneadminlog'], 0, ''))
  352. {
  353. print_form_header('modlog', 'prunelog');
  354. print_table_header($vbphrase['prune_moderator_log']);
  355. print_select_row($vbphrase['remove_entries_logged_by_user'], 'userid', $userlist);
  356. if (count($products) > 1)
  357. {
  358. print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products);
  359. }
  360. print_input_row($vbphrase['remove_entries_older_than_days'], 'daysprune', 30);
  361. print_submit_row($vbphrase['prune_log_entries'], 0);
  362. }
  363. }
  364. print_cp_footer();
  365. /*======================================================================*\
  366. || ####################################################################
  367. || # Downloaded: 03:13, Sat Sep 7th 2013
  368. || # CVS: $RCSfile$ - $Revision: 42666 $
  369. || ####################################################################
  370. \*======================================================================*/
  371. ?>