PageRenderTime 62ms CodeModel.GetById 9ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 0ms

/core/admincp/modlog.php

https://gitlab.com/hub/vbulletin
PHP | 330 lines | 251 code | 50 blank | 29 comment | 38 complexity | 6749f78f056aed21a966b759b2b44ccb MD5 | raw file
  1<?php
  2/*======================================================================*\
  3|| #################################################################### ||
  4|| # vBulletin 5.0.0
  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
 13// ######################## SET PHP ENVIRONMENT ###########################
 14error_reporting(E_ALL & ~E_NOTICE);
 15
 16// ##################### DEFINE IMPORTANT CONSTANTS #######################
 17define('CVS_REVISION', '$RCSfile$ - $Revision: 69205 $');
 18
 19// #################### PRE-CACHE TEMPLATES AND DATA ######################
 20global $phrasegroups, $specialtemplates, $vbphrase, $vbulletin;
 21$phrasegroups = array('logging', 'threadmanage');
 22$specialtemplates = array();
 23
 24// ########################## REQUIRE BACK-END ############################
 25require_once(dirname(__FILE__) . '/global.php');
 26require_once(DIR . '/includes/functions_log_error.php');
 27
 28// ############################# LOG ACTION ###############################
 29if (!can_administer('canadminmodlog'))
 30{
 31	print_cp_no_permission();
 32}
 33
 34log_admin_action();
 35
 36// ########################################################################
 37// ######################### START MAIN SCRIPT ############################
 38// ########################################################################
 39
 40$vb5_config =& vB::getConfig();
 41print_cp_header($vbphrase['moderator_log_gthreadmanage']);
 42
 43if (empty($_REQUEST['do']))
 44{
 45	$_REQUEST['do'] = 'choose';
 46}
 47
 48// ###################### Start view #######################
 49if ($_REQUEST['do'] == 'view')
 50{
 51	$vbulletin->input->clean_array_gpc('r', array(
 52		'perpage'    => vB_Cleaner::TYPE_UINT,
 53		'pagenumber' => vB_Cleaner::TYPE_UINT,
 54		'userid'     => vB_Cleaner::TYPE_UINT,
 55		'modaction'  => vB_Cleaner::TYPE_STR,
 56		'orderby'    => vB_Cleaner::TYPE_NOHTML,
 57		'product'    => vB_Cleaner::TYPE_STR,
 58		'startdate'  => vB_Cleaner::TYPE_UNIXTIME,
 59		'enddate'    => vB_Cleaner::TYPE_UNIXTIME,
 60	));
 61
 62	if ($vbulletin->GPC['perpage'] < 1)
 63	{
 64		$vbulletin->GPC['perpage'] = 15;
 65	}
 66
 67	$counterres = vB::getDbAssertor()->assertQuery('fetchModlogCount',$vbulletin->GPC);
 68	$counter = $counterres->current();
 69	$totalpages = ceil($counter['total'] / $vbulletin->GPC['perpage']);
 70
 71	if ($vbulletin->GPC['pagenumber'] < 1)
 72	{
 73		$vbulletin->GPC['pagenumber'] = 1;
 74	}
 75
 76	$logs = vB::getDbAssertor()->assertQuery('fetchModlogs',$vbulletin->GPC);
 77
 78	if ($logs AND $logs->valid())
 79	{
 80		$vbulletin->GPC['modaction'] = htmlspecialchars_uni($vbulletin->GPC['modaction']);
 81
 82		if ($vbulletin->GPC['pagenumber'] != 1)
 83		{
 84			$prv = $vbulletin->GPC['pagenumber'] - 1;
 85			$firstpage = "<input type=\"button\" class=\"button\" value=\"&laquo; " . $vbphrase['first_page'] . "\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=1'\">";
 86			$prevpage = "<input type=\"button\" class=\"button\" value=\"&lt; " . $vbphrase['prev_page'] . "\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$prv'\">";
 87		}
 88
 89		if ($vbulletin->GPC['pagenumber'] != $totalpages)
 90		{
 91			$nxt = $vbulletin->GPC['pagenumber'] + 1;
 92			$nextpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['next_page'] . " &gt;\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$nxt'\">";
 93			$lastpage = "<input type=\"button\" class=\"button\" value=\"" . $vbphrase['last_page'] . " &raquo;\" tabindex=\"1\" onclick=\"window.location='modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=" . $vbulletin->GPC['orderby'] . "&page=$totalpages'\">";
 94		}
 95
 96		print_form_header('modlog', 'remove');
 97		print_description_row(construct_link_code($vbphrase['restart'], "modlog.php?" . vB::getCurrentSession()->get('sessionurl') . ""), 0, 5, 'thead', vB_Template_Runtime::fetchStyleVar('right'));
 98		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);
 99
100		$headings = array();
101		$headings[] = $vbphrase['id'];
102		$headings[] = "<a href=\"modlog.php?" . vB::getCurrentSession()->get('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>";
103		$headings[] = "<a href=\"modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=date&page=" . $vbulletin->GPC['pagenumber'] . "\">" . $vbphrase['date'] . "</a>";
104		$headings[] = "<a href=\"modlog.php?" . vB::getCurrentSession()->get('sessionurl') . "do=view&modaction=" . $vbulletin->GPC['modaction'] . "&u=" . $vbulletin->GPC['userid'] . "&pp=" . $vbulletin->GPC['perpage'] . "&orderby=modaction&page=" . $vbulletin->GPC['pagenumber'] . "\">" . $vbphrase['action'] . "</a>";
105		$headings[] = str_replace(' ', '&nbsp;', $vbphrase['ip_address']);
106
107		print_cells_row($headings, 1, 0, -3);
108
109		foreach ($logs as $log)
110		{
111			$cell = array();
112			$cell[] = $log['moderatorlogid'];
113			$cell[] = "<a href=\"user.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&u=$log[userid]\"><b>$log[username]</b></a>";
114			$cell[] = '<span class="smallfont">' . vbdate($vbulletin->options['logdateformat'], $log['dateline']) . '</span>';
115
116			if ($log['type'])
117			{
118				$phrase = vB_Library_Admin::GetModlogAction($log['type']);
119
120				if (!$log['nodeid'])
121				{
122					// Pre vB5 logs
123					if ($unserialized = @unserialize($log['action']))
124					{
125						array_unshift($unserialized, $vbphrase[$phrase]);
126						$action = call_user_func_array('construct_phrase', $unserialized);
127					}
128					else
129					{
130						$action = construct_phrase($vbphrase[$phrase], $log['action']);
131					}
132
133					if ($log['threadtitle'])
134					{
135						$action .= ', \'' . $log['threadtitle'] . '\'';
136					}
137				}
138				else
139				{
140					// vB5 logs
141					$temp = array();
142					$logdata = @unserialize($log['action']);
143					$action = construct_phrase($vbphrase[$phrase], $log['username']);
144
145					if ($logdata['userid'] AND $logdata['username'])
146					{
147						$name = '<a href="user.php?' . vB::getCurrentSession()->get('sessionurl') . 'do=edit&u=' . $logdata['userid'] . '">' . $logdata['username'] . '</a>';
148						$temp[] = $vbphrase['author'] . ' = ' . $name;
149						unset($logdata['userid'], $logdata['username']);
150					}
151
152					$logdata['nodeid'] = $log['nodeid'];
153
154					if ($log['nodetitle'])
155					{
156						$logdata['title'] = $log['nodetitle'];
157					}
158					else
159					{
160						$logdata['title'] = $vbphrase['untitled'];
161					}
162
163					if (!empty($logdata))
164					{
165						foreach ($logdata AS $key => $data)
166						{
167							$temp[] = "$key = $data";
168						}
169						
170						$action .= '<br />' . implode('; ', $temp);
171					}
172				}
173			}
174			else
175			{
176				$action = '-';
177			}
178
179			$cell[] = $action;
180
181			$cell[] = '<span class="smallfont">' . iif($log['ipaddress'], "<a href=\"usertools.php?" . vB::getCurrentSession()->get('sessionurl') . "do=gethost&ip=$log[ipaddress]\">$log[ipaddress]</a>", '&nbsp;') . '</span>';
182
183			print_cells_row($cell, 0, 0, -3);
184		}
185
186		print_table_footer(5, "$firstpage $prevpage &nbsp; $nextpage $lastpage");
187	}
188	else
189	{
190		print_stop_message2('no_results_matched_your_query');
191	}
192}
193
194// ###################### Start prune log #######################
195if ($_REQUEST['do'] == 'prunelog' AND can_access_logs($vb5_config['SpecialUsers']['canpruneadminlog'], 0, '<p>' . $vbphrase['control_panel_log_pruning_permission_restricted'] . '</p>'))
196{
197	$vbulletin->input->clean_array_gpc('r', array(
198		'daysprune' => vB_Cleaner::TYPE_UINT,
199		'userid'    => vB_Cleaner::TYPE_UINT,
200		'modaction' => vB_Cleaner::TYPE_STR,
201		'product'   => vB_Cleaner::TYPE_STR,
202	));
203
204	$datecut = TIMENOW - (86400 * $vbulletin->GPC['daysprune']);
205	$conditions[] = array('field' => 'dateline', 'value' => $vbulletin->GPC['datecut'], 'operator' => vB_dB_Query::OPERATOR_LT);
206
207	if ($vbulletin->GPC['userid'])
208	{
209		$conditions[] = array('field' => 'userid', 'value' => $vbulletin->GPC['userid'], 'operator' => vB_dB_Query::OPERATOR_EQ);
210	}
211
212	if ($vbulletin->GPC['modaction'])
213	{
214		$conditions[] = array('field' => 'action', 'value' => $vbulletin->GPC['modaction'], 'operator' => vB_dB_Query::OPERATOR_INCLUDES);
215	}
216
217	if ($vbulletin->GPC['product'])
218	{
219			if ($vbulletin->GPC['product'] == 'vbulletin')
220		{
221			$conditions[] = array('field' => 'product', 'value' => array('', 'vbulletin'), 'operator' => vB_dB_Query::OPERATOR_EQ);
222		}
223		else
224		{
225			$conditions[] = array('field' => 'product', 'value' => $vbulletin->GPC['product'], 'operator' => vB_dB_Query::OPERATOR_EQ);
226		}
227	}
228
229	$logsres = vB::getDbAssertor()->assertQuery('getModLogsByConds', array('conds' => $conditions));
230	$logs = $logsres->current();
231
232	if ($logs['total'])
233	{
234		print_form_header('modlog', 'doprunelog');
235		construct_hidden_code('datecut', $datecut);
236		construct_hidden_code('modaction', $vbulletin->GPC['modaction']);
237		construct_hidden_code('userid', $vbulletin->GPC['userid']);
238		construct_hidden_code('product', $vbulletin->GPC['product']);
239		print_table_header($vbphrase['prune_moderator_log']);
240		print_description_row(construct_phrase($vbphrase['are_you_sure_you_want_to_prune_x_log_entries_from_moderator_log'], vb_number_format($logs['total'])));
241		print_submit_row($vbphrase['yes'], 0, 0, $vbphrase['no']);
242	}
243	else
244	{
245		print_stop_message2('no_logs_matched_your_query');
246	}
247
248}
249
250// ###################### Start do prune log #######################
251if ($_POST['do'] == 'doprunelog' AND can_access_logs($vb5_config['SpecialUsers']['canpruneadminlog'], 0, '<p>' . $vbphrase['control_panel_log_pruning_permission_restricted'] . '</p>'))
252{
253	$vbulletin->input->clean_array_gpc('p', array(
254		'datecut'   => vB_Cleaner::TYPE_UINT,
255		'modaction' => vB_Cleaner::TYPE_STR,
256		'userid'    => vB_Cleaner::TYPE_UINT,
257		'product'   => vB_Cleaner::TYPE_STR,
258	));
259	$conditions[] = array('field' => 'dateline', 'value' => $vbulletin->GPC['datecut'], 'operator' => vB_dB_Query::OPERATOR_LT);
260	if (!empty($vbulletin->GPC['modaction']))
261	{
262		$conditions[] = array('field' => 'action', 'value' => $vbulletin->GPC['modaction'], 'operator' => vB_dB_Query::OPERATOR_INCLUDES);
263	}
264	if (!empty($vbulletin->GPC['userid']))
265	{
266		$conditions[] = array('field' => 'userid', 'value' => $vbulletin->GPC['userid'], 'operator' => vB_dB_Query::OPERATOR_EQ);
267	}
268	if ($vbulletin->GPC['product'])
269	{
270		if ($vbulletin->GPC['product'] == 'vbulletin')
271		{
272			$conditions[] = array('field' => 'product', 'value' => array('', 'vbulletin'), 'operator' => vB_dB_Query::OPERATOR_EQ);
273		}
274		else
275		{
276			$conditions[] = array('field' => 'product', 'value' => $vbulletin->GPC['product'], 'operator' => vB_dB_Query::OPERATOR_EQ);
277		}
278	}
279
280	vB::getDbAssertor()->delete('moderatorlog', $conditions);
281
282	print_stop_message2('pruned_moderator_log_successfully', 'modlog', array('do'=>'choose'));
283}
284
285// ###################### Start modify #######################
286if ($_REQUEST['do'] == 'choose')
287{
288	$users = vB::getDbAssertor()->assertQuery('chooseModLog');
289	$userlist = array('no_value' => $vbphrase['all_log_entries']);
290	foreach ($users as $user)
291	{
292		$userlist["$user[userid]"] = $user['username'];
293	}
294
295	print_form_header('modlog', 'view');
296	print_table_header($vbphrase['moderator_log_viewer']);
297	print_input_row($vbphrase['log_entries_to_show_per_page'], 'perpage', 15);
298	print_select_row($vbphrase['show_only_entries_generated_by'], 'userid', $userlist);
299	print_time_row($vbphrase['start_date'], 'startdate', 0, 0);
300	print_time_row($vbphrase['end_date'], 'enddate', 0, 0);
301	if (count($products = fetch_product_list()) > 1)
302	{
303		print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products);
304	}
305	print_select_row($vbphrase['order_by_gcpglobal'], 'orderby', array('date' => $vbphrase['date'], 'user' => $vbphrase['username']), 'date');
306	print_submit_row($vbphrase['view'], 0);
307
308	if (can_access_logs($vb5_config['SpecialUsers']['canpruneadminlog'], 0, ''))
309	{
310		print_form_header('modlog', 'prunelog');
311		print_table_header($vbphrase['prune_moderator_log']);
312		print_select_row($vbphrase['remove_entries_logged_by_user'], 'userid', $userlist);
313		if (count($products) > 1)
314		{
315			print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products);
316		}
317		print_input_row($vbphrase['remove_entries_older_than_days'], 'daysprune', 30);
318		print_submit_row($vbphrase['prune_log_entries'], 0);
319	}
320
321}
322
323print_cp_footer();
324
325/*======================================================================*\
326|| ####################################################################
327|| # CVS: $RCSfile$ - $Revision: 69205 $
328|| ####################################################################
329\*======================================================================*/
330?>