inital commit

This commit is contained in:
2026-06-19 20:08:01 +06:00
commit 8a5abeeae4
13128 changed files with 3192007 additions and 0 deletions

View File

@@ -0,0 +1,614 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->admin_logs, "index.php?module=tools-adminlog");
$sub_tabs['admin_logs'] = array(
'title' => $lang->admin_logs,
'link' => "index.php?module=tools-adminlog",
'description' => $lang->admin_logs_desc
);
$sub_tabs['prune_admin_logs'] = array(
'title' => $lang->prune_admin_logs,
'link' => "index.php?module=tools-adminlog&amp;action=prune",
'description' => $lang->prune_admin_logs_desc
);
$plugins->run_hooks("admin_tools_adminlog_begin");
if($mybb->input['action'] == 'prune')
{
if(!is_super_admin($mybb->user['uid']))
{
flash_message($lang->cannot_perform_action_super_admin_general, 'error');
admin_redirect("index.php?module=tools-adminlog");
}
$plugins->run_hooks("admin_tools_adminlog_prune");
if($mybb->request_method == 'post')
{
$is_today = false;
$mybb->input['older_than'] = $mybb->get_input('older_than', MyBB::INPUT_INT);
if($mybb->input['older_than'] <= 0)
{
$is_today = true;
$mybb->input['older_than'] = 1;
}
$where = 'dateline < '.(TIME_NOW-($mybb->input['older_than']*86400));
// Searching for entries by a particular user
if($mybb->input['uid'])
{
$where .= " AND uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'";
}
// Searching for entries in a specific module
if($mybb->input['filter_module'])
{
$where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'";
}
$query = $db->delete_query("adminlog", $where);
$num_deleted = $db->affected_rows();
$plugins->run_hooks("admin_tools_adminlog_prune_commit");
// Log admin action
log_admin_action($mybb->input['older_than'], $mybb->input['uid'], $mybb->input['filter_module'], $num_deleted);
$success = $lang->success_pruned_admin_logs;
if($is_today == true && $num_deleted > 0)
{
$success .= ' '.$lang->note_logs_locked;
}
elseif($is_today == true && $num_deleted == 0)
{
flash_message($lang->note_logs_locked, 'error');
admin_redirect("index.php?module=tools-adminlog");
}
flash_message($success, 'success');
admin_redirect("index.php?module=tools-adminlog");
}
$page->add_breadcrumb_item($lang->prune_admin_logs, "index.php?module=tools-adminlog&amp;action=prune");
$page->output_header($lang->prune_admin_logs);
$page->output_nav_tabs($sub_tabs, 'prune_admin_logs');
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = 'selected="selected"';
$ordersel[$mybb->input['order']] = 'selected="selected"';
$user_options[''] = $lang->all_administrators;
$user_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.uid, u.username
FROM ".TABLE_PREFIX."adminlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
ORDER BY u.username ASC
");
while($user = $db->fetch_array($query))
{
$user_options[$user['uid']] = htmlspecialchars_uni($user['username']);
}
$module_options = array();
$module_options[''] = $lang->all_modules;
$module_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.module
FROM ".TABLE_PREFIX."adminlog l
ORDER BY l.module ASC
");
while($module = $db->fetch_array($query))
{
$module_options[$module['module']] = str_replace(' ', ' -&gt; ', ucwords(str_replace('/', ' ', $module['module'])));
}
$form = new Form("index.php?module=tools-adminlog&amp;action=prune", "post");
$form_container = new FormContainer($lang->prune_administrator_logs);
$form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->input['filter_module'], array('id' => 'filter_module')), 'filter_module');
$form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
if(!$mybb->input['older_than'])
{
$mybb->input['older_than'] = '30';
}
$form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_numeric_field('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 50px', 'min' => 0))." {$lang->days}", 'older_than');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->prune_administrator_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if(!$mybb->input['action'])
{
$page->output_header($lang->admin_logs);
$page->output_nav_tabs($sub_tabs, 'admin_logs');
$perpage = $mybb->get_input('perpage', MyBB::INPUT_INT);
if(!$perpage)
{
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
$perpage = $mybb->settings['threadsperpage'];
}
$where = '';
$plugins->run_hooks("admin_tools_adminlog_start");
// Searching for entries by a particular user
if($mybb->input['uid'])
{
$where .= " AND l.uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'";
}
// Searching for entries in a specific module
if($mybb->input['filter_module'])
{
$where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'";
}
// Order?
switch($mybb->input['sortby'])
{
case "username":
$sortby = "u.username";
break;
default:
$sortby = "l.dateline";
}
$order = $mybb->input['order'];
if($order != 'asc')
{
$order = 'desc';
}
$query = $db->query("
SELECT COUNT(l.dateline) AS count
FROM ".TABLE_PREFIX."adminlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
WHERE 1=1 {$where}
");
$rescount = $db->fetch_field($query, "count");
// Figure out if we need to display multiple pages.
if($mybb->input['page'] != "last")
{
$pagecnt = $mybb->get_input('page', MyBB::INPUT_INT);
}
$postcount = (int)$rescount;
$pages = $postcount / $perpage;
$pages = ceil($pages);
if($mybb->input['page'] == "last")
{
$pagecnt = $pages;
}
if($pagecnt > $pages)
{
$pagecnt = 1;
}
if($pagecnt)
{
$start = ($pagecnt-1) * $perpage;
}
else
{
$start = 0;
$pagecnt = 1;
}
$table = new Table;
$table->construct_header($lang->username, array('width' => '10%'));
$table->construct_header($lang->date, array('class' => 'align_center', 'width' => '15%'));
$table->construct_header($lang->information, array('class' => 'align_center', 'width' => '65%'));
$table->construct_header($lang->ipaddress, array('class' => 'align_center', 'width' => '10%'));
$query = $db->query("
SELECT l.*, u.username, u.usergroup, u.displaygroup
FROM ".TABLE_PREFIX."adminlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
WHERE 1=1 {$where}
ORDER BY {$sortby} {$order}
LIMIT {$start}, {$perpage}
");
while($logitem = $db->fetch_array($query))
{
$information = '';
$trow = alt_trow();
$logitem['username'] = htmlspecialchars_uni($logitem['username']);
$username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']);
$logitem['data'] = my_unserialize($logitem['data']);
$logitem['profilelink'] = build_profile_link($username, $logitem['uid'], "_blank");
$logitem['dateline'] = my_date('relative', $logitem['dateline']);
// Get detailed information from meta
$information = get_admin_log_action($logitem);
$table->construct_cell($logitem['profilelink']);
$table->construct_cell($logitem['dateline'], array('class' => 'align_center'));
$table->construct_cell($information);
$table->construct_cell(my_inet_ntop($db->unescape_binary($logitem['ipaddress'])), array('class' => 'align_center'));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_adminlogs, array('colspan' => '4'));
$table->construct_row();
}
$table->output($lang->admin_logs);
// Do we need to construct the pagination?
if($rescount > $perpage)
{
echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-adminlog&amp;perpage=$perpage&amp;uid={$mybb->input['uid']}&amp;fid={$mybb->input['fid']}&amp;sortby={$mybb->input['sortby']}&amp;order={$order}&amp;filter_module=".htmlspecialchars_uni($mybb->input['filter_module']))."<br />";
}
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = 'selected="selected"';
$ordersel[$mybb->input['order']] = 'selected="selected"';
$user_options[''] = $lang->all_administrators;
$user_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.uid, u.username
FROM ".TABLE_PREFIX."adminlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
ORDER BY u.username ASC
");
while($user = $db->fetch_array($query))
{
$user_options[$user['uid']] = htmlspecialchars_uni($user['username']);
}
$module_options = array();
$module_options[''] = $lang->all_modules;
$module_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.module
FROM ".TABLE_PREFIX."adminlog l
ORDER BY l.module ASC
");
while($module = $db->fetch_array($query))
{
$module_options[$module['module']] = str_replace(' ', ' -&gt; ', ucwords(str_replace('/', ' ', $module['module'])));
}
$sort_by = array(
'dateline' => $lang->date,
'username' => $lang->username
);
$order_array = array(
'asc' => $lang->asc,
'desc' => $lang->desc
);
$form = new Form("index.php?module=tools-adminlog", "post");
$form_container = new FormContainer($lang->filter_administrator_logs);
$form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->input['filter_module'], array('id' => 'filter_module')), 'filter_module');
$form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
$form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order');
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $perpage, array('id' => 'perpage', 'min' => 1)), 'perpage');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->filter_administrator_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
/**
* Returns language-friendly string describing $logitem
* @param array $logitem The log item (one row from mybb_adminlogs)
* @return string The description
*/
function get_admin_log_action($logitem)
{
global $lang, $plugins, $mybb;
$logitem['module'] = str_replace('/', '-', $logitem['module']);
list($module, $action) = explode('-', $logitem['module']);
$lang_string = 'admin_log_'.$module.'_'.$action.'_'.$logitem['action'];
// Specific page overrides
switch($lang_string)
{
// == CONFIG ==
case 'admin_log_config_banning_add': // Banning IP/Username/Email
case 'admin_log_config_banning_delete': // Removing banned IP/username/emails
switch($logitem['data'][2])
{
case 1:
$lang_string = 'admin_log_config_banning_'.$logitem['action'].'_ip';
break;
case 2:
$lang_string = 'admin_log_config_banning_'.$logitem['action'].'_username';
break;
case 3:
$lang_string = 'admin_log_config_banning_'.$logitem['action'].'_email';
break;
}
break;
case 'admin_log_config_help_documents_add': // Help documents and sections
case 'admin_log_config_help_documents_edit':
case 'admin_log_config_help_documents_delete':
$lang_string .= "_{$logitem['data'][2]}"; // adds _section or _document
break;
case 'admin_log_config_languages_edit': // Editing language variables
$logitem['data'][1] = basename($logitem['data'][1]);
if($logitem['data'][2] == 1)
{
$lang_string = 'admin_log_config_languages_edit_admin';
}
break;
case 'admin_log_config_mycode_toggle_status': // Custom MyCode toggle activation
if($logitem['data'][2] == 1)
{
$lang_string .= '_enabled';
}
else
{
$lang_string .= '_disabled';
}
break;
case 'admin_log_config_plugins_activate': // Installing plugin
if($logitem['data'][1])
{
$lang_string .= '_install';
}
break;
case 'admin_log_config_plugins_deactivate': // Uninstalling plugin
if($logitem['data'][1])
{
$lang_string .= '_uninstall';
}
break;
// == FORUM ==
case 'admin_log_forum_attachments_delete': // Deleting attachments
if($logitem['data'][2])
{
$lang_string .= '_post';
}
break;
case 'admin_log_forum_management_copy': // Forum copy
if($logitem['data'][4])
{
$lang_string .= '_with_permissions';
}
break;
case 'admin_log_forum_management_': // add mod, permissions, forum orders
// first parameter already set with action
$lang_string .= $logitem['data'][0];
if($logitem['data'][0] == 'orders' && $logitem['data'][1])
{
$lang_string .= '_sub'; // updating forum orders in a subforum
}
break;
case 'admin_log_forum_moderation_queue_': //moderation queue
// first parameter already set with action
$lang_string .= $logitem['data'][0];
break;
// == HOME ==
case 'admin_log_home_preferences_': // 2FA
$lang_string .= $logitem['data'][0]; // either "enabled" or "disabled"
break;
// == STYLE ==
case 'admin_log_style_templates_delete_template': // deleting templates
// global template set
if($logitem['data'][2] == -1)
{
$lang_string .= '_global';
}
break;
case 'admin_log_style_templates_edit_template': // editing templates
// global template set
if($logitem['data'][2] == -1)
{
$lang_string .= '_global';
}
break;
// == TOOLS ==
case 'admin_log_tools_adminlog_prune': // Admin Log Pruning
if($logitem['data'][1] && !$logitem['data'][2])
{
$lang_string = 'admin_log_tools_adminlog_prune_user';
}
elseif($logitem['data'][2] && !$logitem['data'][1])
{
$lang_string = 'admin_log_tools_adminlog_prune_module';
}
elseif($logitem['data'][1] && $logitem['data'][2])
{
$lang_string = 'admin_log_tools_adminlog_prune_user_module';
}
break;
case 'admin_log_tools_modlog_prune': // Moderator Log Pruning
if($logitem['data'][1] && !$logitem['data'][2])
{
$lang_string = 'admin_log_tools_modlog_prune_user';
}
elseif($logitem['data'][2] && !$logitem['data'][1])
{
$lang_string = 'admin_log_tools_modlog_prune_forum';
}
elseif($logitem['data'][1] && $logitem['data'][2])
{
$lang_string = 'admin_log_tools_modlog_prune_user_forum';
}
break;
case 'admin_log_tools_backupdb_backup': // Create backup
if($logitem['data'][0] == 'download')
{
$lang_string = 'admin_log_tools_backupdb_backup_download';
}
$logitem['data'][1] = '...'.substr($logitem['data'][1], -20);
break;
case 'admin_log_tools_backupdb_dlbackup': // Download backup
$logitem['data'][0] = '...'.substr($logitem['data'][0], -20);
break;
case 'admin_log_tools_backupdb_delete': // Delete backup
$logitem['data'][0] = '...'.substr($logitem['data'][0], -20);
break;
case 'admin_log_tools_optimizedb_': // Optimize DB
$logitem['data'][0] = @implode(', ', my_unserialize($logitem['data'][0]));
break;
case 'admin_log_tools_recount_rebuild_': // Recount and rebuild
$detail_lang_string = $lang_string.$logitem['data'][0];
if(isset($lang->$detail_lang_string))
{
$lang_string = $detail_lang_string;
}
break;
case 'admin_log_tools_spamlog_prune': // Spam Log Pruning
if($logitem['data'][1] && !$logitem['data'][2])
{
$lang_string = 'admin_log_tools_spamlog_prune_user';
}
elseif($logitem['data'][2] && !$logitem['data'][1])
{
$lang_string = 'admin_log_tools_spamlog_prune_email';
}
elseif($logitem['data'][1] && $logitem['data'][2])
{
$lang_string = 'admin_log_tools_spamlog_prune_user_email';
}
break;
// == USERS ==
case 'admin_log_user_admin_permissions_edit': // editing default/group/user admin permissions
if($logitem['data'][0] > 0)
{
// User
$lang_string .= '_user';
}
elseif($logitem['data'][0] < 0)
{
// Group
$logitem['data'][0] = abs($logitem['data'][0]);
$lang_string .= '_group';
}
break;
case 'admin_log_user_admin_permissions_delete': // deleting group/user admin permissions
if($logitem['data'][0] > 0)
{
// User
$lang_string .= '_user';
}
elseif($logitem['data'][0] < 0)
{
// Group
$logitem['data'][0] = abs($logitem['data'][0]);
$lang_string .= '_group';
}
break;
case 'admin_log_user_awaiting_activation_activate':
if($logitem['data'][0] == 'deleted')
{
$lang_string .= '_deleted';
}
else
{
$lang_string .= '_activated';
}
break;
case 'admin_log_user_banning_': // banning
if($logitem['data'][2] == 0)
{
$lang_string = 'admin_log_user_banning_add_permanent';
}
else
{
$logitem['data'][2] = my_date($mybb->settings['dateformat'], $logitem['data'][2]);
$lang_string = 'admin_log_user_banning_add_temporary';
}
break;
case 'admin_log_user_groups_join_requests':
if($logitem['data'][0] == 'approve')
{
$lang_string = 'admin_log_user_groups_join_requests_approve';
}
else
{
$lang_string = 'admin_log_user_groups_join_requests_deny';
}
break;
case 'admin_log_user_users_inline_banned':
if($logitem['data'][1] == 0)
{
$lang_string = 'admin_log_user_users_inline_banned_perm';
}
else
{
$logitem['data'][1] = my_date($mybb->settings['dateformat'], $logitem['data'][1]);
$lang_string = 'admin_log_user_users_inline_banned_temp';
}
break;
}
$plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string);
$plugins->run_hooks("admin_tools_get_admin_log_action", $plugin_array);
foreach($logitem['data'] as $key => $value)
{
$logitem['data'][$key] = htmlspecialchars_uni($value);
}
if(isset($lang->$lang_string))
{
array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string
$string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']);
if(!$string)
{
$string = $lang->$lang_string; // Fall back to the one in the language pack
}
}
else
{
if(isset($logitem['data']['type']) && $logitem['data']['type'] == 'admin_locked_out')
{
$string = $lang->sprintf($lang->admin_log_admin_locked_out, (int) $logitem['data']['uid'], htmlspecialchars_uni($logitem['data']['username']));
}
else
{
// Build a default string
$string = $logitem['module'].' - '.$logitem['action'];
if(is_array($logitem['data']) && count($logitem['data']) > 0)
{
$string .= '('.implode(', ', $logitem['data']).')';
}
}
}
return $string;
}

View File

@@ -0,0 +1,483 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
/**
* Allows us to refresh cache to prevent over flowing
*
* @param resource $fp
* @param string $contents
*/
function clear_overflow($fp, &$contents)
{
global $mybb;
if($mybb->input['method'] == 'disk')
{
if($mybb->input['filetype'] == 'gzip')
{
gzwrite($fp, $contents);
}
else
{
fwrite($fp, $contents);
}
}
else
{
if($mybb->input['filetype'] == "gzip")
{
echo gzencode($contents);
}
else
{
echo $contents;
}
}
$contents = '';
}
$page->add_breadcrumb_item($lang->database_backups, "index.php?module=tools-backupdb");
$plugins->run_hooks("admin_tools_backupdb_begin");
if($mybb->input['action'] == "dlbackup")
{
if(empty($mybb->input['file']))
{
flash_message($lang->error_file_not_specified, 'error');
admin_redirect("index.php?module=tools-backupdb");
}
$plugins->run_hooks("admin_tools_backupdb_dlbackup");
$file = basename($mybb->input['file']);
$ext = get_extension($file);
if(file_exists(MYBB_ADMIN_DIR.'backups/'.$file) && filetype(MYBB_ADMIN_DIR.'backups/'.$file) == 'file' && ($ext == 'gz' || $ext == 'sql'))
{
$plugins->run_hooks("admin_tools_backupdb_dlbackup_commit");
// Log admin action
log_admin_action($file);
header('Content-disposition: attachment; filename='.$file);
header("Content-type: ".$ext);
header("Content-length: ".filesize(MYBB_ADMIN_DIR.'backups/'.$file));
$handle = fopen(MYBB_ADMIN_DIR.'backups/'.$file, 'rb');
while(!feof($handle))
{
echo fread($handle, 8192);
}
fclose($handle);
}
else
{
flash_message($lang->error_invalid_backup, 'error');
admin_redirect("index.php?module=tools-backupdb");
}
}
if($mybb->input['action'] == "delete")
{
if($mybb->input['no'])
{
admin_redirect("index.php?module=tools-backupdb");
}
$file = basename($mybb->input['file']);
if(!trim($mybb->input['file']) || !file_exists(MYBB_ADMIN_DIR.'backups/'.$file))
{
flash_message($lang->error_backup_doesnt_exist, 'error');
admin_redirect("index.php?module=tools-backupdb");
}
$plugins->run_hooks("admin_tools_backupdb_delete");
if($mybb->request_method == "post")
{
$delete = @unlink(MYBB_ADMIN_DIR.'backups/'.$file);
if($delete)
{
$plugins->run_hooks("admin_tools_backupdb_delete_commit");
// Log admin action
log_admin_action($file);
flash_message($lang->success_backup_deleted, 'success');
admin_redirect("index.php?module=tools-backupdb");
}
else
{
flash_message($lang->error_backup_not_deleted, 'error');
admin_redirect("index.php?module=tools-backupdb");
}
}
else
{
$page->output_confirm_action("index.php?module=tools-backupdb&amp;action=delete&amp;file={$mybb->input['file']}", $lang->confirm_backup_deletion);
}
}
if($mybb->input['action'] == "backup")
{
$plugins->run_hooks("admin_tools_backupdb_backup");
if($mybb->request_method == "post")
{
if(!is_array($mybb->input['tables']))
{
flash_message($lang->error_tables_not_selected, 'error');
admin_redirect("index.php?module=tools-backupdb&action=backup");
}
@set_time_limit(0);
if($mybb->input['method'] == 'disk')
{
$file = MYBB_ADMIN_DIR.'backups/backup_'.date("_Ymd_His_").random_str(16);
if($mybb->input['filetype'] == 'gzip')
{
if(!function_exists('gzopen')) // check zlib-ness
{
flash_message($lang->error_no_zlib, 'error');
admin_redirect("index.php?module=tools-backupdb&action=backup");
}
$fp = gzopen($file.'.incomplete.sql.gz', 'w9');
}
else
{
$fp = fopen($file.'.incomplete.sql', 'w');
}
}
else
{
$file = 'backup_'.substr(md5($mybb->user['uid'].TIME_NOW), 0, 10).random_str(54);
if($mybb->input['filetype'] == 'gzip')
{
if(!function_exists('gzopen')) // check zlib-ness
{
flash_message($lang->error_no_zlib, 'error');
admin_redirect("index.php?module=tools-backupdb&action=backup");
}
// Send headers for gzip file
header('Content-Type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$file.'.sql.gz"');
}
else
{
// Send standard headers for .sql
header('Content-Type: text/x-sql');
header('Content-Disposition: attachment; filename="'.$file.'.sql"');
}
}
$db->set_table_prefix('');
$time = date('dS F Y \a\t H:i', TIME_NOW);
$header = "-- MyBB Database Backup\n-- Generated: {$time}\n-- -------------------------------------\n\n";
$contents = $header;
foreach($mybb->input['tables'] as $table)
{
if(!$db->table_exists($db->escape_string($table)))
{
continue;
}
if($mybb->input['analyzeoptimize'] == 1)
{
$db->optimize_table($table);
$db->analyze_table($table);
}
$field_list = array();
$fields_array = $db->show_fields_from($table);
foreach($fields_array as $field)
{
$field_list[] = $field['Field'];
}
$fields = "`".implode("`,`", $field_list)."`";
if($mybb->input['contents'] != 'data')
{
$structure = $db->show_create_table($table).";\n";
$contents .= $structure;
clear_overflow($fp, $contents);
}
if($mybb->input['contents'] != 'structure')
{
if($db->engine == 'mysqli')
{
$query = mysqli_query($db->read_link, "SELECT * FROM {$db->table_prefix}{$table}", MYSQLI_USE_RESULT);
}
else
{
$query = $db->simple_select($table);
}
while($row = $db->fetch_array($query))
{
$insert = "INSERT INTO {$table} ($fields) VALUES (";
$comma = '';
foreach($field_list as $field)
{
if(!isset($row[$field]) || is_null($row[$field]))
{
$insert .= $comma."NULL";
}
else if($db->engine == 'mysqli')
{
$insert .= $comma."'".mysqli_real_escape_string($db->read_link, $row[$field])."'";
}
else
{
$insert .= $comma."'".$db->escape_string($row[$field])."'";
}
$comma = ',';
}
$insert .= ");\n";
$contents .= $insert;
clear_overflow($fp, $contents);
}
$db->free_result($query);
}
}
$db->set_table_prefix(TABLE_PREFIX);
if($mybb->input['method'] == 'disk')
{
if($mybb->input['filetype'] == 'gzip')
{
gzwrite($fp, $contents);
gzclose($fp);
rename($file.'.incomplete.sql.gz', $file.'.sql.gz');
}
else
{
fwrite($fp, $contents);
fclose($fp);
rename($file.'.incomplete.sql', $file.'.sql');
}
if($mybb->input['filetype'] == 'gzip')
{
$ext = '.sql.gz';
}
else
{
$ext = '.sql';
}
$plugins->run_hooks("admin_tools_backupdb_backup_disk_commit");
// Log admin action
log_admin_action("disk", $file.$ext);
$file_from_admindir = 'index.php?module=tools-backupdb&amp;action=dlbackup&amp;file='.basename($file).$ext;
flash_message("<span><em>{$lang->success_backup_created}</em></span><p>{$lang->backup_saved_to}<br />{$file}{$ext} (<a href=\"{$file_from_admindir}\">{$lang->download}</a>)</p>", 'success');
admin_redirect("index.php?module=tools-backupdb");
}
else
{
$plugins->run_hooks("admin_tools_backupdb_backup_download_commit");
// Log admin action
log_admin_action("download");
if($mybb->input['filetype'] == 'gzip')
{
echo gzencode($contents);
}
else
{
echo $contents;
}
}
exit;
}
$page->extra_header = " <script type=\"text/javascript\">
function changeSelection(action, prefix)
{
var select_box = document.getElementById('table_select');
for(var i = 0; i < select_box.length; i++)
{
if(action == 'select')
{
select_box[i].selected = true;
}
else if(action == 'deselect')
{
select_box[i].selected = false;
}
else if(action == 'forum' && prefix != 0)
{
select_box[i].selected = false;
var row = select_box[i].value;
var subString = row.substring(prefix.length, 0);
if(subString == prefix)
{
select_box[i].selected = true;
}
}
}
}
</script>\n";
$page->add_breadcrumb_item($lang->new_database_backup);
$page->output_header($lang->new_database_backup);
$sub_tabs['database_backup'] = array(
'title' => $lang->database_backups,
'link' => "index.php?module=tools-backupdb"
);
$sub_tabs['new_backup'] = array(
'title' => $lang->new_backup,
'link' => "index.php?module=tools-backupdb&amp;action=backup",
'description' => $lang->new_backup_desc
);
$page->output_nav_tabs($sub_tabs, 'new_backup');
// Check if file is writable, before allowing submission
if(!is_writable(MYBB_ADMIN_DIR."/backups"))
{
$lang->update_button = '';
$page->output_alert($lang->alert_not_writable);
$cannot_write = true;
}
$table = new Table;
$table->construct_header($lang->table_selection);
$table->construct_header($lang->backup_options);
$table_selects = array();
$table_list = $db->list_tables($config['database']['database']);
foreach($table_list as $id => $table_name)
{
$table_selects[$table_name] = $table_name;
}
$form = new Form("index.php?module=tools-backupdb&amp;action=backup", "post", "table_selection", 0, "table_selection");
$table->construct_cell("{$lang->table_select_desc}\n<br /><br />\n<a href=\"javascript:changeSelection('select', 0);\">{$lang->select_all}</a><br />\n<a href=\"javascript:changeSelection('deselect', 0);\">{$lang->deselect_all}</a><br />\n<a href=\"javascript:changeSelection('forum', '".TABLE_PREFIX."');\">{$lang->select_forum_tables}</a>\n<br /><br />\n<div class=\"form_row\">".$form->generate_select_box("tables[]", $table_selects, false, array('multiple' => true, 'id' => 'table_select', 'size' => 20))."</div>", array('rowspan' => 5, 'width' => '50%', 'style' => 'border-bottom: 0px'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->file_type}</strong><br />\n{$lang->file_type_desc}<br />\n<div class=\"form_row\">".$form->generate_radio_button("filetype", "gzip", $lang->gzip_compressed, array('checked' => 1))."<br />\n".$form->generate_radio_button("filetype", "plain", $lang->plain_text)."</div>", array('width' => '50%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->save_method}</strong><br />\n{$lang->save_method_desc}<br /><div class=\"form_row\">".$form->generate_radio_button("method", "disk", $lang->backup_directory)."<br />\n".$form->generate_radio_button("method", "download", $lang->download, array('checked' => 1))."</div>", array('width' => '50%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->backup_contents}</strong><br />\n{$lang->backup_contents_desc}<br /><div class=\"form_row\">".$form->generate_radio_button("contents", "both", $lang->structure_and_data, array('checked' => 1))."<br />\n".$form->generate_radio_button("contents", "structure", $lang->structure_only)."<br />\n".$form->generate_radio_button("contents", "data", $lang->data_only)."</div>", array('width' => '50%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->analyze_and_optimize}</strong><br />\n{$lang->analyze_and_optimize_desc}<br /><div class=\"form_row\">".$form->generate_yes_no_radio("analyzeoptimize")."</div>", array('width' => '50%'));
$table->construct_row();
$table->output($lang->new_database_backup);
$buttons[] = $form->generate_submit_button($lang->perform_backup);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if(!$mybb->input['action'])
{
$page->add_breadcrumb_item($lang->backups);
$page->output_header($lang->database_backups);
$sub_tabs['database_backup'] = array(
'title' => $lang->database_backups,
'link' => "index.php?module=tools-backupdb",
'description' => $lang->database_backups_desc
);
$sub_tabs['new_backup'] = array(
'title' => $lang->new_backup,
'link' => "index.php?module=tools-backupdb&amp;action=backup",
);
$plugins->run_hooks("admin_tools_backupdb_start");
$page->output_nav_tabs($sub_tabs, 'database_backup');
$backups = array();
$dir = MYBB_ADMIN_DIR.'backups/';
$handle = opendir($dir);
if($handle !== false)
{
while(($file = readdir($handle)) !== false)
{
if(filetype(MYBB_ADMIN_DIR.'backups/'.$file) == 'file')
{
$ext = get_extension($file);
if($ext == 'gz' || $ext == 'sql')
{
$backups[@filemtime(MYBB_ADMIN_DIR.'backups/'.$file)] = array(
"file" => $file,
"time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file),
"type" => $ext
);
}
}
}
closedir($handle);
}
$count = count($backups);
krsort($backups);
$table = new Table;
$table->construct_header($lang->backup_filename);
$table->construct_header($lang->file_size, array("class" => "align_center"));
$table->construct_header($lang->creation_date);
$table->construct_header($lang->controls, array("class" => "align_center"));
foreach($backups as $backup)
{
$time = "-";
if($backup['time'])
{
$time = my_date('relative', $backup['time']);
}
$table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=dlbackup&amp;file={$backup['file']}\">{$backup['file']}</a>");
$table->construct_cell(get_friendly_size(filesize(MYBB_ADMIN_DIR.'backups/'.$backup['file'])), array("class" => "align_center"));
$table->construct_cell($time);
$table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=backup&amp;action=delete&amp;file={$backup['file']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_backup_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
$table->construct_row();
}
if($count == 0)
{
$table->construct_cell($lang->no_backups, array('colspan' => 4));
$table->construct_row();
}
$table->output($lang->existing_database_backups);
$page->output_footer();
}

View File

@@ -0,0 +1,276 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->cache_manager, "index.php?module=tools-cache");
$plugins->run_hooks("admin_tools_cache_begin");
if($mybb->input['action'] == 'view')
{
if(!trim($mybb->input['title']))
{
flash_message($lang->error_no_cache_specified, 'error');
admin_redirect("index.php?module=tools-cache");
}
$plugins->run_hooks("admin_tools_cache_view");
// Rebuilds forum settings
if($mybb->input['title'] == 'settings')
{
$cachedsettings = (array)$mybb->settings;
if(isset($cachedsettings['internal']))
{
unset($cachedsettings['internal']);
}
$cacheitem = array(
'title' => 'settings',
'cache' => my_serialize($cachedsettings)
);
}
else
{
$query = $db->simple_select("datacache", "*", "title = '".$db->escape_string($mybb->input['title'])."'");
$cacheitem = $db->fetch_array($query);
}
if(!$cacheitem)
{
flash_message($lang->error_incorrect_cache, 'error');
admin_redirect("index.php?module=tools-cache");
}
$cachecontents = unserialize($cacheitem['cache']);
if(empty($cachecontents))
{
$cachecontents = $lang->error_empty_cache;
}
ob_start();
print_r($cachecontents);
$cachecontents = htmlspecialchars_uni(ob_get_contents());
ob_end_clean();
$page->add_breadcrumb_item($lang->view);
$page->output_header($lang->cache_manager);
$table = new Table;
$table->construct_cell("<pre>\n{$cachecontents}\n</pre>");
$table->construct_row();
$table->output($lang->cache." {$cacheitem['title']}");
$page->output_footer();
}
if($mybb->input['action'] == "rebuild" || $mybb->input['action'] == "reload")
{
if(!verify_post_check($mybb->input['my_post_key']))
{
flash_message($lang->invalid_post_verify_key2, 'error');
admin_redirect("index.php?module=tools-cache");
}
$plugins->run_hooks("admin_tools_cache_rebuild");
// Rebuilds forum settings
if($mybb->input['title'] == 'settings')
{
rebuild_settings();
$plugins->run_hooks("admin_tools_cache_rebuild_commit");
// Log admin action
log_admin_action($mybb->input['title']);
flash_message($lang->success_cache_reloaded, 'success');
admin_redirect("index.php?module=tools-cache");
}
if(method_exists($cache, "update_{$mybb->input['title']}"))
{
$func = "update_{$mybb->input['title']}";
$cache->$func();
$plugins->run_hooks("admin_tools_cache_rebuild_commit");
// Log admin action
log_admin_action($mybb->input['title']);
flash_message($lang->success_cache_rebuilt, 'success');
admin_redirect("index.php?module=tools-cache");
}
elseif(method_exists($cache, "reload_{$mybb->input['title']}"))
{
$func = "reload_{$mybb->input['title']}";
$cache->$func();
$plugins->run_hooks("admin_tools_cache_rebuild_commit");
// Log admin action
log_admin_action($mybb->input['title']);
flash_message($lang->success_cache_reloaded, 'success');
admin_redirect("index.php?module=tools-cache");
}
elseif(function_exists("update_{$mybb->input['title']}"))
{
$func = "update_{$mybb->input['title']}";
$func();
$plugins->run_hooks("admin_tools_cache_rebuild_commit");
// Log admin action
log_admin_action($mybb->input['title']);
flash_message($lang->success_cache_rebuilt, 'success');
admin_redirect("index.php?module=tools-cache");
}
elseif(function_exists("reload_{$mybb->input['title']}"))
{
$func = "reload_{$mybb->input['title']}";
$func();
$plugins->run_hooks("admin_tools_cache_rebuild_commit");
// Log admin action
log_admin_action($mybb->input['title']);
flash_message($lang->success_cache_reloaded, 'success');
admin_redirect("index.php?module=tools-cache");
}
else
{
flash_message($lang->error_cannot_rebuild, 'error');
admin_redirect("index.php?module=tools-cache");
}
}
if($mybb->input['action'] == "rebuild_all")
{
if(!verify_post_check($mybb->input['my_post_key']))
{
flash_message($lang->invalid_post_verify_key2, 'error');
admin_redirect("index.php?module=tools-cache");
}
$plugins->run_hooks("admin_tools_cache_rebuild_all");
$query = $db->simple_select("datacache");
while($cacheitem = $db->fetch_array($query))
{
if(method_exists($cache, "update_{$cacheitem['title']}"))
{
$func = "update_{$cacheitem['title']}";
$cache->$func();
}
elseif(method_exists($cache, "reload_{$cacheitem['title']}"))
{
$func = "reload_{$cacheitem['title']}";
$cache->$func();
}
elseif(function_exists("update_{$cacheitem['title']}"))
{
$func = "update_{$cacheitem['title']}";
$func();
}
elseif(function_exists("reload_{$cacheitem['title']}"))
{
$func = "reload_{$cacheitem['title']}";
$func();
}
}
// Rebuilds forum settings
rebuild_settings();
$plugins->run_hooks("admin_tools_cache_rebuild_all_commit");
// Log admin action
log_admin_action();
flash_message($lang->success_cache_reloaded, 'success');
admin_redirect("index.php?module=tools-cache");
}
if(!$mybb->input['action'])
{
$page->output_header($lang->cache_manager);
$sub_tabs['cache_manager'] = array(
'title' => $lang->cache_manager,
'link' => "index.php?module=tools-cache",
'description' => $lang->cache_manager_description
);
$plugins->run_hooks("admin_tools_cache_start");
$page->output_nav_tabs($sub_tabs, 'cache_manager');
$table = new Table;
$table->construct_header($lang->name);
$table->construct_header($lang->size, array("class" => "align_center", "width" => 100));
$table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
$query = $db->simple_select("datacache");
while($cacheitem = $db->fetch_array($query))
{
$table->construct_cell("<strong><a href=\"index.php?module=tools-cache&amp;action=view&amp;title=".urlencode($cacheitem['title'])."\">{$cacheitem['title']}</a></strong>");
$table->construct_cell(get_friendly_size(strlen($cacheitem['cache'])), array("class" => "align_center"));
if(method_exists($cache, "update_".$cacheitem['title']))
{
$table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=rebuild&amp;title=".urlencode($cacheitem['title'])."&amp;my_post_key={$mybb->post_code}\">".$lang->rebuild_cache."</a>", array("class" => "align_center"));
}
elseif(method_exists($cache, "reload_".$cacheitem['title']))
{
$table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=".urlencode($cacheitem['title'])."&amp;my_post_key={$mybb->post_code}\">".$lang->reload_cache."</a>", array("class" => "align_center"));
}
elseif(function_exists("update_".$cacheitem['title']))
{
$table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=rebuild&amp;title=".urlencode($cacheitem['title'])."&amp;my_post_key={$mybb->post_code}\">".$lang->rebuild_cache."</a>", array("class" => "align_center"));
}
elseif(function_exists("reload_".$cacheitem['title']))
{
$table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=".urlencode($cacheitem['title'])."&amp;my_post_key={$mybb->post_code}\">".$lang->reload_cache."</a>", array("class" => "align_center"));
}
else
{
$table->construct_cell("");
}
$table->construct_row();
}
// Rebuilds forum settings
$cachedsettings = (array)$mybb->settings;
if(isset($cachedsettings['internal']))
{
unset($cachedsettings['internal']);
}
$table->construct_cell("<strong><a href=\"index.php?module=tools-cache&amp;action=view&amp;title=settings\">settings</a></strong>");
$table->construct_cell(get_friendly_size(strlen(my_serialize($cachedsettings))), array("class" => "align_center"));
$table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=settings&amp;my_post_key={$mybb->post_code}\">".$lang->reload_cache."</a>", array("class" => "align_center"));
$table->construct_row();
$table->output("<div style=\"float: right;\"><small><a href=\"index.php?module=tools-cache&amp;action=rebuild_all&amp;my_post_key={$mybb->post_code}\">".$lang->rebuild_reload_all."</a></small></div>".$lang->cache_manager);
$page->output_footer();
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
@set_time_limit(0);
$page->add_breadcrumb_item($lang->file_verification, "index.php?module=tools-file_verification");
$plugins->run_hooks("admin_tools_file_verification_begin");
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_file_verification_check");
if($mybb->request_method == "post")
{
// User clicked no
if($mybb->input['no'])
{
admin_redirect("index.php?module=tools-system_health");
}
$page->add_breadcrumb_item($lang->checking, "index.php?module=tools-file_verification");
$page->output_header($lang->file_verification." - ".$lang->checking);
$file = explode("\n", @file_get_contents("https://mybb.com/checksums/release_mybb_{$mybb->version_code}.txt"));
if(strstr($file[0], "<?xml") !== false || empty($file[0]))
{
$page->output_inline_error($lang->error_communication);
$page->output_footer();
exit;
}
// Parser-up our checksum file from the MyBB Server
foreach($file as $line)
{
$parts = explode(" ", $line, 2);
if(empty($parts[0]) || empty($parts[1]))
{
continue;
}
if(substr($parts[1], 0, 7) == "./admin")
{
$parts[1] = "./{$mybb->config['admin_dir']}".substr($parts[1], 7);
}
if(file_exists(MYBB_ROOT."forums.php") && !file_exists(MYBB_ROOT."portal.php"))
{
if(trim($parts[1]) == "./index.php")
{
$parts[1] = "./forums.php";
}
elseif($parts[1] == "./portal.php")
{
$parts[1] = "./index.php";
}
}
if(!file_exists(MYBB_ROOT."inc/plugins/hello.php") && $parts[1] == "./inc/plugins/hello.php")
{
continue;
}
if(!is_dir(MYBB_ROOT."install/") && substr($parts[1], 0, 10) == "./install/")
{
continue;
}
$checksums[trim($parts[1])][] = $parts[0];
}
$bad_files = verify_files();
$plugins->run_hooks("admin_tools_file_verification_check_commit_start");
$table = new Table;
$table->construct_header($lang->file);
$table->construct_header($lang->status, array("class" => "align_center", "width" => 100));
foreach($bad_files as $file)
{
switch($file['status'])
{
case "changed":
$file['status'] = $lang->changed;
$color = "#F22B48";
break;
case "missing":
$file['status'] = $lang->missing;
$color = "#5B5658";
break;
}
$table->construct_cell("<strong><span style=\"color: {$color};\">".htmlspecialchars_uni(substr($file['path'], 2))."</span></strong>");
$table->construct_cell("<strong><span style=\"color: {$color};\">{$file['status']}</span></strong>", array("class" => "align_center"));
$table->construct_row();
}
$no_errors = false;
if($table->num_rows() == 0)
{
$no_errors = true;
$table->construct_cell($lang->no_corrupt_files_found, array('colspan' => 3));
$table->construct_row();
}
if($no_errors)
{
$table->output($lang->file_verification.": ".$lang->no_problems_found);
}
else
{
$table->output($lang->file_verification.": ".$lang->found_problems);
}
$page->output_footer();
exit;
}
$page->output_confirm_action("index.php?module=tools-file_verification", $lang->file_verification_message, $lang->file_verification);
}

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title></title>
</head>
<body>
&nbsp;
</body>
</html>

View File

@@ -0,0 +1,269 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->system_email_log, "index.php?module=tools-mailerrors");
$plugins->run_hooks("admin_tools_mailerrors_begin");
if($mybb->input['action'] == "prune" && $mybb->request_method == "post")
{
$plugins->run_hooks("admin_tools_mailerrors_prune");
if($mybb->input['delete_all'])
{
$db->delete_query("mailerrors");
$num_deleted = $db->affected_rows();
$plugins->run_hooks("admin_tools_mailerrors_prune_delete_all_commit");
// Log admin action
log_admin_action($num_deleted);
flash_message($lang->all_logs_deleted, 'success');
admin_redirect("index.php?module=tools-mailerrors");
}
else if(is_array($mybb->input['log']))
{
$log_ids = implode(",", array_map("intval", $mybb->input['log']));
if($log_ids)
{
$db->delete_query("mailerrors", "eid IN ({$log_ids})");
$num_deleted = $db->affected_rows();
}
// Log admin action
log_admin_action($num_deleted);
}
$plugins->run_hooks("admin_tools_mailerrors_prune_commit");
flash_message($lang->selected_logs_deleted, 'success');
admin_redirect("index.php?module=tools-mailerrors");
}
if($mybb->input['action'] == "view")
{
$query = $db->simple_select("mailerrors", "*", "eid='".$mybb->get_input('eid', MyBB::INPUT_INT)."'");
$log = $db->fetch_array($query);
if(!$log['eid'])
{
exit;
}
$plugins->run_hooks("admin_tools_mailerrors_view");
$log['toaddress'] = htmlspecialchars_uni($log['toaddress']);
$log['fromaddress'] = htmlspecialchars_uni($log['fromaddress']);
$log['subject'] = htmlspecialchars_uni($log['subject']);
$log['error'] = htmlspecialchars_uni($log['error']);
$log['smtperror'] = htmlspecialchars_uni($log['smtpcode']);
$log['dateline'] = my_date('relative', $log['dateline']);
$log['message'] = nl2br(htmlspecialchars_uni($log['message']));
?>
<div class="modal">
<div style="overflow-y: auto; max-height: 400px;">
<?php
$table = new Table();
$table->construct_cell($log['error'], array("colspan" => 2));
$table->construct_row();
if($log['smtpcode'])
{
$table->construct_cell($lang->smtp_code);
$table->construct_cell($log['smtpcode']);
$table->construct_row();
}
if($log['smtperror'])
{
$table->construct_cell($lang->smtp_server_response);
$table->construct_cell($log['smtperror']);
$table->construct_row();
}
$table->output($lang->error);
$table = new Table();
$table->construct_cell($lang->to.":");
$table->construct_cell("<a href=\"mailto:{$log['toaddress']}\">{$log['toaddress']}</a>");
$table->construct_row();
$table->construct_cell($lang->from.":");
$table->construct_cell("<a href=\"mailto:{$log['fromaddress']}\">{$log['fromaddress']}</a>");
$table->construct_row();
$table->construct_cell($lang->subject.":");
$table->construct_cell($log['subject']);
$table->construct_row();
$table->construct_cell($lang->date.":");
$table->construct_cell($log['dateline']);
$table->construct_row();
$table->construct_cell($log['message'], array("colspan" => 2));
$table->construct_row();
$table->output($lang->email);
?>
</div>
</div>
<?php
exit;
}
if(!$mybb->input['action'])
{
$query = $db->simple_select("mailerrors l", "COUNT(eid) AS logs", "1=1 {$additional_sql_criteria}");
$total_rows = $db->fetch_field($query, "logs");
$per_page = 20;
if($mybb->input['page'] && $mybb->input['page'] > 1)
{
$mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($mybb->input['page']*$per_page)-$per_page;
$pages = ceil($total_rows / $per_page);
if($mybb->input['page'] > $pages)
{
$mybb->input['page'] = 1;
$start = 0;
}
}
else
{
$mybb->input['page'] = 1;
$start = 0;
}
$additional_criteria = array();
$plugins->run_hooks("admin_tools_mailerrors_start");
$page->output_header($lang->system_email_log);
$sub_tabs['mailerrors'] = array(
'title' => $lang->system_email_log,
'link' => "index.php?module=tools-mailerrors",
'description' => $lang->system_email_log_desc
);
$page->output_nav_tabs($sub_tabs, 'mailerrors');
$form = new Form("index.php?module=tools-mailerrors&amp;action=prune", "post");
// Begin criteria filtering
if($mybb->input['subject'])
{
$additional_sql_criteria .= " AND subject LIKE '%".$db->escape_string_like($mybb->input['subject'])."%'";
$additional_criteria[] = "subject=".htmlspecialchars_uni($mybb->input['subject']);
$form->generate_hidden_field("subject", $mybb->input['subject']);
}
if($mybb->input['fromaddress'])
{
$additional_sql_criteria .= " AND fromaddress LIKE '%".$db->escape_string_like($mybb->input['fromaddress'])."%'";
$additional_criteria[] = "fromaddress=".urlencode($mybb->input['fromaddress']);
$form->generate_hidden_field("fromaddress", $mybb->input['fromaddress']);
}
if($mybb->input['toaddress'])
{
$additional_sql_criteria .= " AND toaddress LIKE '%".$db->escape_string_like($mybb->input['toaddress'])."%'";
$additional_criteria[] = "toaddress=".urlencode($mybb->input['toaddress']);
$form->generate_hidden_field("toaddress", $mybb->input['toaddress']);
}
if($mybb->input['error'])
{
$additional_sql_criteria .= " AND error LIKE '%".$db->escape_string_like($mybb->input['error'])."%'";
$additional_criteria[] = "error=".urlencode($mybb->input['error']);
$form->generate_hidden_field("error", $mybb->input['error']);
}
if($additional_criteria)
{
$additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
}
else
{
$additional_criteria = '';
}
$table = new Table;
$table->construct_header($form->generate_check_box("allbox", 1, '', array('class' => 'checkall')));
$table->construct_header($lang->subject);
$table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
$table->construct_header($lang->error_message, array("class" => "align_center", "width" => "30%"));
$table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
$query = $db->simple_select('mailerrors', '*', "1=1 $additional_sql_criteria", array('order_by' => 'dateline', 'order_dir' => 'DESC', 'limit_start' => $start, 'limit' => $per_page));
while($log = $db->fetch_array($query))
{
$log['subject'] = htmlspecialchars_uni($log['subject']);
$log['toemail'] = htmlspecialchars_uni($log['toemail']);
$log['error'] = htmlspecialchars_uni($log['error']);
$log['dateline'] = my_date('relative', $log['dateline']);
$table->construct_cell($form->generate_check_box("log[{$log['eid']}]", $log['eid'], ''));
$table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-mailerrors&amp;action=view&amp;eid={$log['eid']}', null, true);\">{$log['subject']}</a>");
$find_from = "<div class=\"float_right\"><a href=\"index.php?module=tools-mailerrors&amp;toaddress={$log['toaddress']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->fine_emails_to_addr}\" alt=\"{$lang->find}\" /></a></div>";
$table->construct_cell("{$find_from}<div>{$log['toaddress']}</div>");
$table->construct_cell($log['error']);
$table->construct_cell($log['dateline'], array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_logs, array("colspan" => 5));
$table->construct_row();
$table->output($lang->system_email_log);
}
else
{
$table->output($lang->system_email_log);
$buttons[] = $form->generate_submit_button($lang->delete_selected, array('onclick' => "return confirm('{$lang->confirm_delete_logs}');"));
$buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_delete_all_logs}');"));
$form->output_submit_wrapper($buttons);
}
$form->end();
echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools-mailerrors&amp;page={page}{$additional_criteria}");
$form = new Form("index.php?module=tools-mailerrors", "post");
$form_container = new FormContainer($lang->filter_system_email_log);
$form_container->output_row($lang->subject_contains, "", $form->generate_text_box('subject', $mybb->input['subject'], array('id' => 'subject')), 'subject');
$form_container->output_row($lang->error_message_contains, "", $form->generate_text_box('error', $mybb->input['error'], array('id' => 'error')), 'error');
$form_container->output_row($lang->to_address_contains, "", $form->generate_text_box('toaddress', $mybb->input['toaddress'], array('id' => 'toaddress')), 'toaddress');
$form_container->output_row($lang->from_address_contains, "", $form->generate_text_box('fromaddress', $mybb->input['fromaddress'], array('id' => 'fromaddress')), 'fromaddress');
$form_container->end();
$buttons = array();
$buttons[] = $form->generate_submit_button($lang->filter_system_email_log);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,456 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->user_email_log, "index.php?module=tools-maillogs");
$plugins->run_hooks("admin_tools_maillogs_begin");
if($mybb->input['action'] == "prune" && $mybb->request_method == "post")
{
$plugins->run_hooks("admin_tools_maillogs_prune");
if($mybb->input['delete_all'])
{
$db->delete_query("maillogs");
$num_deleted = $db->affected_rows();
$plugins->run_hooks("admin_tools_maillogs_prune_delete_all_commit");
// Log admin action
log_admin_action($num_deleted);
flash_message($lang->all_logs_deleted, 'success');
admin_redirect("index.php?module=tools-maillogs");
}
else if(is_array($mybb->input['log']))
{
$log_ids = implode(",", array_map("intval", $mybb->input['log']));
if($log_ids)
{
$db->delete_query("maillogs", "mid IN ({$log_ids})");
$num_deleted = $db->affected_rows();
}
// Log admin action
log_admin_action($num_deleted);
}
$plugins->run_hooks("admin_tools_maillogs_prune_commit");
flash_message($lang->selected_logs_deleted, 'success');
admin_redirect("index.php?module=tools-maillogs");
}
if($mybb->input['action'] == "view")
{
$query = $db->simple_select("maillogs", "*", "mid='".$mybb->get_input('mid', MyBB::INPUT_INT)."'");
$log = $db->fetch_array($query);
if(!$log['mid'])
{
exit;
}
$plugins->run_hooks("admin_tools_maillogs_view");
$log['toemail'] = htmlspecialchars_uni($log['toemail']);
$log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
$log['subject'] = htmlspecialchars_uni($log['subject']);
$log['dateline'] = my_date('relative', $log['dateline']);
if($mybb->settings['mail_logging'] == 1)
{
$log['message'] = $lang->na;
}
else
{
$log['message'] = nl2br(htmlspecialchars_uni($log['message']));
}
?>
<div class="modal">
<div style="overflow-y: auto; max-height: 400px;">
<?php
$table = new Table();
$table->construct_cell($lang->to.":");
$table->construct_cell("<a href=\"mailto:{$log['toemail']}\">{$log['toemail']}</a>");
$table->construct_row();
$table->construct_cell($lang->from.":");
$table->construct_cell("<a href=\"mailto:{$log['fromemail']}\">{$log['fromemail']}</a>");
$table->construct_row();
$table->construct_cell($lang->ip_address.":");
$table->construct_cell(my_inet_ntop($db->unescape_binary($log['ipaddress'])));
$table->construct_row();
$table->construct_cell($lang->subject.":");
$table->construct_cell($log['subject']);
$table->construct_row();
$table->construct_cell($lang->date.":");
$table->construct_cell($log['dateline']);
$table->construct_row();
$table->construct_cell($log['message'], array("colspan" => 2));
$table->construct_row();
$table->output($lang->user_email_log_viewer);
?>
</div>
</div>
<?php
}
if(!$mybb->input['action'])
{
$query = $db->simple_select("maillogs l", "COUNT(l.mid) as logs", "1=1 {$additional_sql_criteria}");
$total_rows = $db->fetch_field($query, "logs");
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
$per_page = $mybb->settings['threadsperpage'];
if(!$per_page)
{
$per_page = 20;
}
if($mybb->input['page'] && $mybb->input['page'] > 1)
{
$mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($mybb->input['page']*$per_page)-$per_page;
$pages = ceil($total_rows / $per_page);
if($mybb->input['page'] > $pages)
{
$mybb->input['page'] = 1;
$start = 0;
}
}
else
{
$mybb->input['page'] = 1;
$start = 0;
}
$additional_criteria = array();
$plugins->run_hooks("admin_tools_maillogs_start");
// Filter form was submitted - play around with the values
if($mybb->request_method == "post")
{
if($mybb->input['from_type'] == "user")
{
$mybb->input['fromname'] = $mybb->input['from_value'];
}
else if($mybb->input['from_type'] == "email")
{
$mybb->input['fromemail'] = $mybb->input['from_value'];
}
if($mybb->input['to_type'] == "user")
{
$mybb->input['toname'] = $mybb->input['to_value'];
}
else if($mybb->input['to_type'] == "email")
{
$mybb->input['toemail'] = $mybb->input['to_value'];
}
}
$touid = $mybb->get_input('touid', MyBB::INPUT_INT);
$toname = $db->escape_string($mybb->input['toname']);
$toemail = $db->escape_string_like($mybb->input['toemail']);
$fromuid = $mybb->get_input('fromuid', MyBB::INPUT_INT);
$fromemail = $db->escape_string_like($mybb->input['fromemail']);
$subject = $db->escape_string_like($mybb->input['subject']);
// Begin criteria filtering
if($mybb->input['subject'])
{
$additional_sql_criteria .= " AND l.subject LIKE '%{$subject}%'";
$additional_criteria[] = "subject=".urlencode($mybb->input['subject']);
}
if($mybb->input['fromuid'])
{
$query = $db->simple_select("users", "uid, username", "uid = '{$fromuid}'");
$user = $db->fetch_array($query);
$from_filter = $user['username'];
$additional_sql_criteria .= " AND l.fromuid = '{$fromuid}'";
$additional_criteria[] = "fromuid={$fromuid}";
}
else if($mybb->input['fromname'])
{
$user = get_user_by_username($mybb->input['fromname'], array('fields' => 'uid, username'));
$from_filter = $user['username'];
if(!$user['uid'])
{
flash_message($lang->error_invalid_user, 'error');
admin_redirect("index.php?module=tools-maillogs");
}
$additional_sql_criteria .= "AND l.fromuid = '{$user['uid']}'";
$additional_criteria[] = "fromuid={$user['uid']}";
}
if($mybb->input['fromemail'])
{
$additional_sql_criteria .= " AND l.fromemail LIKE '%{$fromemail}%'";
$additional_criteria[] = "fromemail=".urlencode($mybb->input['fromemail']);
$from_filter = $mybb->input['fromemail'];
}
if($mybb->input['touid'])
{
$query = $db->simple_select("users", "uid, username", "uid = '{$touid}'");
$user = $db->fetch_array($query);
$to_filter = $user['username'];
$additional_sql_criteria .= " AND l.touid = '{$touid}'";
$additional_criteria[] = "touid={$touid}";
}
else if($mybb->input['toname'])
{
$user = get_user_by_username($toname, array('fields' => 'username'));
$to_filter = $user['username'];
if(!$user['uid'])
{
flash_message($lang->error_invalid_user, 'error');
admin_redirect("index.php?module=tools-maillogs");
}
$additional_sql_criteria .= "AND l.touid='{$user['uid']}'";
$additional_criteria[] = "touid={$user['uid']}";
}
if($mybb->input['toemail'])
{
$additional_sql_criteria .= " AND l.toemail LIKE '%{$toemail}%'";
$additional_criteria[] = "toemail=".urlencode($mybb->input['toemail']);
$to_filter = $mybb->input['toemail'];
}
if(!empty($additional_criteria))
{
$additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
}
else
{
$additional_criteria = '';
}
$page->output_header($lang->user_email_log);
$sub_tabs['maillogs'] = array(
'title' => $lang->user_email_log,
'link' => "index.php?module=tools-maillogs",
'description' => $lang->user_email_log_desc
);
$page->output_nav_tabs($sub_tabs, 'maillogs');
$form = new Form("index.php?module=tools-maillogs&amp;action=prune", "post");
$table = new Table;
$table->construct_header($form->generate_check_box("allbox", 1, '', array('class' => 'checkall')));
$table->construct_header($lang->subject, array("colspan" => 2));
$table->construct_header($lang->from, array("class" => "align_center", "width" => "20%"));
$table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
$table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
$table->construct_header($lang->ip_address, array("class" => "align_center", 'width' => '10%'));
$query = $db->query("
SELECT l.*, r.username AS to_username, f.username AS from_username, t.subject AS thread_subject
FROM ".TABLE_PREFIX."maillogs l
LEFT JOIN ".TABLE_PREFIX."users r ON (r.uid=l.touid)
LEFT JOIN ".TABLE_PREFIX."users f ON (f.uid=l.fromuid)
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
WHERE 1=1 {$additional_sql_criteria}
ORDER BY l.dateline DESC
LIMIT {$start}, {$per_page}
");
while($log = $db->fetch_array($query))
{
$table->construct_cell($form->generate_check_box("log[{$log['mid']}]", $log['mid'], ''), array("width" => 1));
$log['subject'] = htmlspecialchars_uni($log['subject']);
$log['dateline'] = my_date('relative', $log['dateline']);
if($log['type'] == 2)
{
if($log['thread_subject'])
{
$log['thread_subject'] = htmlspecialchars_uni($log['thread_subject']);
$thread_link = "<a href=\"../".get_thread_link($log['tid'])."\">".$log['thread_subject']."</a>";
}
else
{
$thread_link = $lang->deleted;
}
$table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_thread.png\" title=\"{$lang->sent_using_send_thread_feature}\" alt=\"\" />", array("width" => 1));
$table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a><br /><small>{$lang->thread} {$thread_link}</small>");
if($log['fromuid'] > 0)
{
$find_from = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;fromuid={$log['fromuid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_by_user}\" alt=\"{$lang->find}\" /></a></div>";
}
if(!$log['from_username'] && $log['fromuid'] > 0)
{
$table->construct_cell("{$find_from}<div>{$lang->deleted_user}</div>");
}
elseif($log['fromuid'] == 0)
{
$log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
$table->construct_cell("{$find_from}<div>{$log['fromemail']}</div>");
}
else
{
$table->construct_cell("{$find_from}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
}
$log['toemail'] = htmlspecialchars_uni($log['toemail']);
$table->construct_cell($log['toemail']);
}
elseif($log['type'] == 1)
{
$table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_user.png\" title=\"{$lang->email_sent_to_user}\" alt=\"\" />", array("width" => 1));
$table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a>");
if($log['fromuid'] > 0)
{
$find_from = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;fromuid={$log['fromuid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_by_user}\" alt=\"{$lang->find}\" /></a></div>";
}
if(!$log['from_username'] && $log['fromuid'] > 0)
{
$table->construct_cell("{$find_from}<div>{$lang->deleted_user}</div>");
}
elseif($log['fromuid'] == 0)
{
$log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
$table->construct_cell("{$find_from}<div>{$log['fromemail']}</div>");
}
else
{
$table->construct_cell("{$find_from}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
}
$find_to = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;touid={$log['touid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_to_user}\" alt=\"{$lang->find}\" /></a></div>";
if(!$log['to_username'])
{
$table->construct_cell("{$find_to}<div>{$lang->deleted_user}</div>");
}
else
{
$table->construct_cell("{$find_to}<div><a href=\"../".get_profile_link($log['touid'])."\">{$log['to_username']}</a></div>");
}
}
elseif($log['type'] == 3)
{
$table->construct_cell("<img src=\"styles/{$page->style}/images/icons/maillogs_contact.png\" title=\"{$lang->email_sent_using_contact_form}\" alt=\"\" />", array("width" => 1));
$table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools-maillogs&amp;action=view&amp;mid={$log['mid']}', null, true);\">{$log['subject']}</a>");
if($log['fromuid'] > 0)
{
$find_from = "<div class=\"float_right\"><a href=\"index.php?module=tools-maillogs&amp;fromuid={$log['fromuid']}\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->find_emails_by_user}\" alt=\"{$lang->find}\" /></a></div>";
}
if(!$log['from_username'] && $log['fromuid'] > 0)
{
$table->construct_cell("{$find_from}<div>{$lang->deleted_user}</div>");
}
elseif($log['fromuid'] == 0)
{
$log['fromemail'] = htmlspecialchars_uni($log['fromemail']);
$table->construct_cell("{$find_from}<div>{$log['fromemail']}</div>");
}
else
{
$table->construct_cell("{$find_from}<div><a href=\"../".get_profile_link($log['fromuid'])."\">{$log['from_username']}</a></div>");
}
$log['toemail'] = htmlspecialchars_uni($log['toemail']);
$table->construct_cell($log['toemail']);
}
$table->construct_cell($log['dateline'], array("class" => "align_center"));
$table->construct_cell(my_inet_ntop($db->unescape_binary($log['ipaddress'])), array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_logs, array("colspan" => "7"));
$table->construct_row();
$table->output($lang->user_email_log);
}
else
{
$table->output($lang->user_email_log);
$buttons[] = $form->generate_submit_button($lang->delete_selected, array('onclick' => "return confirm('{$lang->confirm_delete_logs}');"));
$buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_delete_all_logs}');"));
$form->output_submit_wrapper($buttons);
}
$form->end();
echo "<br />".draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools-maillogs&amp;page={page}{$additional_criteria}");
$form = new Form("index.php?module=tools-maillogs", "post");
$form_container = new FormContainer($lang->filter_user_email_log);
$user_email = array(
"user" => $lang->username_is,
"email" => $lang->email_contains
);
$form_container->output_row($lang->subject_contains, "", $form->generate_text_box('subject', $mybb->input['subject'], array('id' => 'subject')), 'subject');
if($from_username)
{
$from_type = "user";
}
else if($mybb->input['fromemail'])
{
$from_type = "email";
}
$form_container->output_row($lang->from, "", $form->generate_select_box('from_type', $user_email, $from_type)." ".$form->generate_text_box('from_value', htmlspecialchars_uni($from_filter), array('id' => 'from_value')), 'from_value');
if($to_username)
{
$to_type = "user";
}
else if($mybb->input['toemail'])
{
$to_type = "email";
}
$form_container->output_row($lang->to, "", $form->generate_select_box('to_type', $user_email, $to_type)." ".$form->generate_text_box('to_value', htmlspecialchars_uni($to_filter), array('id' => 'to_value')), 'to_value');
$form_container->end();
$buttons = array();
$buttons[] = $form->generate_submit_button($lang->filter_user_email_log);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,362 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->mod_logs, "index.php?module=tools-modlog");
$sub_tabs['mod_logs'] = array(
'title' => $lang->mod_logs,
'link' => "index.php?module=tools-modlog",
'description' => $lang->mod_logs_desc
);
$sub_tabs['prune_mod_logs'] = array(
'title' => $lang->prune_mod_logs,
'link' => "index.php?module=tools-modlog&amp;action=prune",
'description' => $lang->prune_mod_logs_desc
);
$plugins->run_hooks("admin_tools_modlog_begin");
if($mybb->input['action'] == 'prune')
{
$plugins->run_hooks("admin_tools_modlog_prune");
if($mybb->request_method == 'post')
{
$is_today = false;
$mybb->input['older_than'] = $mybb->get_input('older_than', MyBB::INPUT_INT);
if($mybb->input['older_than'] <= 0)
{
$is_today = true;
$mybb->input['older_than'] = 1;
}
$where = 'dateline < '.(TIME_NOW-($mybb->input['older_than']*86400));
// Searching for entries by a particular user
if($mybb->input['uid'])
{
$where .= " AND uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'";
}
// Searching for entries in a specific module
if($mybb->input['fid'] > 0)
{
$where .= " AND fid='".$db->escape_string($mybb->input['fid'])."'";
}
else
{
$mybb->input['fid'] = 0;
}
$db->delete_query("moderatorlog", $where);
$num_deleted = $db->affected_rows();
$plugins->run_hooks("admin_tools_modlog_prune_commit");
if(!is_array($forum_cache))
{
$forum_cache = cache_forums();
}
// Log admin action
log_admin_action($mybb->input['older_than'], $mybb->input['uid'], $mybb->input['fid'], $num_deleted, $forum_cache[$mybb->input['fid']]['name']);
$success = $lang->success_pruned_mod_logs;
if($is_today == true && $num_deleted > 0)
{
$success .= ' '.$lang->note_logs_locked;
}
elseif($is_today == true && $num_deleted == 0)
{
flash_message($lang->note_logs_locked, 'error');
admin_redirect("index.php?module=tools-modlog");
}
flash_message($success, 'success');
admin_redirect("index.php?module=tools-modlog");
}
$page->add_breadcrumb_item($lang->prune_mod_logs, "index.php?module=tools-modlog&amp;action=prune");
$page->output_header($lang->prune_mod_logs);
$page->output_nav_tabs($sub_tabs, 'prune_mod_logs');
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = 'selected="selected"';
$ordersel[$mybb->input['order']] = 'selected="selected"';
$user_options[''] = $lang->all_moderators;
$user_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.uid, u.username
FROM ".TABLE_PREFIX."moderatorlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
ORDER BY u.username ASC
");
while($user = $db->fetch_array($query))
{
// Deleted Users
if(!$user['username'])
{
$user['username'] = htmlspecialchars_uni($lang->na_deleted);
}
$user_options[$user['uid']] = htmlspecialchars_uni($user['username']);
}
$form = new Form("index.php?module=tools-modlog&amp;action=prune", "post");
$form_container = new FormContainer($lang->prune_moderator_logs);
$form_container->output_row($lang->forum, "", $form->generate_forum_select('fid', $mybb->input['fid'], array('id' => 'fid', 'main_option' => $lang->all_forums)), 'fid');
$form_container->output_row($lang->forum_moderator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
if(!$mybb->input['older_than'])
{
$mybb->input['older_than'] = '30';
}
$form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_numeric_field('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 50px', 'min' => 0)).' '.$lang->days, 'older_than');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->prune_moderator_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_modlog_start");
$page->output_header($lang->mod_logs);
$page->output_nav_tabs($sub_tabs, 'mod_logs');
$perpage = $mybb->get_input('perpage', MyBB::INPUT_INT);
if(!$perpage)
{
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
$perpage = $mybb->settings['threadsperpage'];
}
$where = 'WHERE 1=1';
// Searching for entries by a particular user
if($mybb->input['uid'])
{
$where .= " AND l.uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'";
}
// Searching for entries in a specific forum
if($mybb->input['fid'] > 0)
{
$where .= " AND l.fid='".$mybb->get_input('fid', MyBB::INPUT_INT)."'";
}
// Order?
switch($mybb->input['sortby'])
{
case "username":
$sortby = "u.username";
break;
case "forum":
$sortby = "f.name";
break;
case "thread":
$sortby = "t.subject";
break;
default:
$sortby = "l.dateline";
}
$order = $mybb->input['order'];
if($order != "asc")
{
$order = "desc";
}
$query = $db->query("
SELECT COUNT(l.dateline) AS count
FROM ".TABLE_PREFIX."moderatorlog l
{$where}
");
$rescount = $db->fetch_field($query, "count");
// Figure out if we need to display multiple pages.
if($mybb->input['page'] != "last")
{
$pagecnt = $mybb->get_input('page', MyBB::INPUT_INT);
}
$postcount = (int)$rescount;
$pages = $postcount / $perpage;
$pages = ceil($pages);
if($mybb->input['page'] == "last")
{
$pagecnt = $pages;
}
if($pagecnt > $pages)
{
$pagecnt = 1;
}
if($pagecnt)
{
$start = ($pagecnt-1) * $perpage;
}
else
{
$start = 0;
$pagecnt = 1;
}
$table = new Table;
$table->construct_header($lang->username, array('width' => '10%'));
$table->construct_header($lang->date, array("class" => "align_center", 'width' => '15%'));
$table->construct_header($lang->action, array("class" => "align_center", 'width' => '35%'));
$table->construct_header($lang->information, array("class" => "align_center", 'width' => '30%'));
$table->construct_header($lang->ipaddress, array("class" => "align_center", 'width' => '10%'));
$query = $db->query("
SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject
FROM ".TABLE_PREFIX."moderatorlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid)
LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid)
{$where}
ORDER BY {$sortby} {$order}
LIMIT {$start}, {$perpage}
");
while($logitem = $db->fetch_array($query))
{
$information = '';
$logitem['action'] = htmlspecialchars_uni($logitem['action']);
$logitem['dateline'] = my_date('relative', $logitem['dateline']);
$trow = alt_trow();
if($logitem['username'])
{
$username = format_name(htmlspecialchars_uni($logitem['username']), $logitem['usergroup'], $logitem['displaygroup']);
$logitem['profilelink'] = build_profile_link($username, $logitem['uid'], "_blank");
}
else
{
$username = $logitem['profilelink'] = $logitem['username'] = htmlspecialchars_uni($lang->na_deleted);
}
if($logitem['tsubject'])
{
$information = "<strong>{$lang->thread}</strong> <a href=\"../".get_thread_link($logitem['tid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['tsubject'])."</a><br />";
}
if($logitem['fname'])
{
$information .= "<strong>{$lang->forum}</strong> <a href=\"../".get_forum_link($logitem['fid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['fname'])."</a><br />";
}
if($logitem['psubject'])
{
$information .= "<strong>{$lang->post}</strong> <a href=\"../".get_post_link($logitem['pid'])."#pid{$logitem['pid']}\" target=\"_blank\">".htmlspecialchars_uni($logitem['psubject'])."</a>";
}
if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject'])
{
$data = my_unserialize($logitem['data']);
if($data['uid'])
{
$information = "<strong>{$lang->user_info}</strong> <a href=\"../".get_profile_link($data['uid'])."\" target=\"_blank\">".htmlspecialchars_uni($data['username'])."</a>";
}
if($data['aid'])
{
$information = "<strong>{$lang->announcement}</strong> <a href=\"../".get_announcement_link($data['aid'])."\" target=\"_blank\">".htmlspecialchars_uni($data['subject'])."</a>";
}
}
$plugins->run_hooks("admin_tools_modlog_modlogs_result");
$table->construct_cell($logitem['profilelink']);
$table->construct_cell($logitem['dateline'], array("class" => "align_center"));
$table->construct_cell($logitem['action'], array("class" => "align_center"));
$table->construct_cell($information);
$table->construct_cell(my_inet_ntop($db->unescape_binary($logitem['ipaddress'])), array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_modlogs, array("colspan" => "5"));
$table->construct_row();
}
$table->output($lang->mod_logs);
// Do we need to construct the pagination?
if($rescount > $perpage)
{
echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-modlog&amp;perpage=$perpage&amp;uid={$mybb->input['uid']}&amp;fid={$mybb->input['fid']}&amp;sortby={$mybb->input['sortby']}&amp;order={$order}")."<br />";
}
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = "selected=\"selected\"";
$ordersel[$mybb->input['order']] = "selected=\"selected\"";
$user_options[''] = $lang->all_moderators;
$user_options['0'] = '----------';
$query = $db->query("
SELECT DISTINCT l.uid, u.username
FROM ".TABLE_PREFIX."moderatorlog l
LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
ORDER BY u.username ASC
");
while($user = $db->fetch_array($query))
{
// Deleted Users
if(!$user['username'])
{
$user['username'] = $lang->na_deleted;
}
$selected = '';
if($mybb->input['uid'] == $user['uid'])
{
$selected = "selected=\"selected\"";
}
$user_options[$user['uid']] = htmlspecialchars_uni($user['username']);
}
$sort_by = array(
'dateline' => $lang->date,
'username' => $lang->username,
'forum' => $lang->forum_name,
'thread' => $lang->thread_subject
);
$order_array = array(
'asc' => $lang->asc,
'desc' => $lang->desc
);
$form = new Form("index.php?module=tools-modlog", "post");
$form_container = new FormContainer($lang->filter_moderator_logs);
$form_container->output_row($lang->forum, "", $form->generate_forum_select('fid', $mybb->input['fid'], array('id' => 'fid', 'main_option' => $lang->all_forums)), 'fid');
$form_container->output_row($lang->forum_moderator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
$form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order');
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $perpage, array('id' => 'perpage', 'min' => 1)), 'perpage');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->filter_moderator_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
/**
* @return bool true
*/
function tools_meta()
{
global $page, $lang, $plugins;
$sub_menu = array();
$sub_menu['10'] = array("id" => "system_health", "title" => $lang->system_health, "link" => "index.php?module=tools-system_health");
$sub_menu['20'] = array("id" => "cache", "title" => $lang->cache_manager, "link" => "index.php?module=tools-cache");
$sub_menu['30'] = array("id" => "tasks", "title" => $lang->task_manager, "link" => "index.php?module=tools-tasks");
$sub_menu['40'] = array("id" => "recount_rebuild", "title" => $lang->recount_and_rebuild, "link" => "index.php?module=tools-recount_rebuild");
$sub_menu['50'] = array("id" => "php_info", "title" => $lang->view_php_info, "link" => "index.php?module=tools-php_info");
$sub_menu['60'] = array("id" => "backupdb", "title" => $lang->database_backups, "link" => "index.php?module=tools-backupdb");
$sub_menu['70'] = array("id" => "optimizedb", "title" => $lang->optimize_database, "link" => "index.php?module=tools-optimizedb");
$sub_menu['80'] = array("id" => "file_verification", "title" => $lang->file_verification, "link" => "index.php?module=tools-file_verification");
$sub_menu = $plugins->run_hooks("admin_tools_menu", $sub_menu);
$page->add_menu_item($lang->tools_and_maintenance, "tools", "index.php?module=tools", 50, $sub_menu);
return true;
}
/**
* @param string $action
*
* @return string
*/
function tools_action_handler($action)
{
global $page, $lang, $plugins;
$page->active_module = "tools";
$actions = array(
'php_info' => array('active' => 'php_info', 'file' => 'php_info.php'),
'tasks' => array('active' => 'tasks', 'file' => 'tasks.php'),
'backupdb' => array('active' => 'backupdb', 'file' => 'backupdb.php'),
'optimizedb' => array('active' => 'optimizedb', 'file' => 'optimizedb.php'),
'cache' => array('active' => 'cache', 'file' => 'cache.php'),
'recount_rebuild' => array('active' => 'recount_rebuild', 'file' => 'recount_rebuild.php'),
'maillogs' => array('active' => 'maillogs', 'file' => 'maillogs.php'),
'mailerrors' => array('active' => 'mailerrors', 'file' => 'mailerrors.php'),
'adminlog' => array('active' => 'adminlog', 'file' => 'adminlog.php'),
'modlog' => array('active' => 'modlog', 'file' => 'modlog.php'),
'warninglog' => array('active' => 'warninglog', 'file' => 'warninglog.php'),
'spamlog' => array('active' => 'spamlog', 'file' => 'spamlog.php'),
'system_health' => array('active' => 'system_health', 'file' => 'system_health.php'),
'file_verification' => array('active' => 'file_verification', 'file' => 'file_verification.php'),
'statistics' => array('active' => 'statistics', 'file' => 'statistics.php'),
);
$actions = $plugins->run_hooks("admin_tools_action_handler", $actions);
$sub_menu = array();
$sub_menu['10'] = array("id" => "adminlog", "title" => $lang->administrator_log, "link" => "index.php?module=tools-adminlog");
$sub_menu['20'] = array("id" => "modlog", "title" => $lang->moderator_log, "link" => "index.php?module=tools-modlog");
$sub_menu['30'] = array("id" => "maillogs", "title" => $lang->user_email_log, "link" => "index.php?module=tools-maillogs");
$sub_menu['40'] = array("id" => "mailerrors", "title" => $lang->system_mail_log, "link" => "index.php?module=tools-mailerrors");
$sub_menu['50'] = array("id" => "warninglog", "title" => $lang->user_warning_log, "link" => "index.php?module=tools-warninglog");
$sub_menu['60'] = array("id" => "spamlog", "title" => $lang->spam_log, "link" => "index.php?module=tools-spamlog");
$sub_menu['70'] = array("id" => "statistics", "title" => $lang->statistics, "link" => "index.php?module=tools-statistics");
$sub_menu = $plugins->run_hooks("admin_tools_menu_logs", $sub_menu);
if(!isset($actions[$action]))
{
$page->active_action = "system_health";
}
$sidebar = new SidebarItem($lang->logs);
$sidebar->add_menu_items($sub_menu, $actions[$action]['active']);
$page->sidebar .= $sidebar->get_markup();
if(isset($actions[$action]))
{
$page->active_action = $actions[$action]['active'];
return $actions[$action]['file'];
}
else
{
return "system_health.php";
}
}
/**
* @return array
*/
function tools_admin_permissions()
{
global $lang, $plugins;
$admin_permissions = array(
"system_health" => $lang->can_access_system_health,
"cache" => $lang->can_manage_cache,
"tasks" => $lang->can_manage_tasks,
"backupdb" => $lang->can_manage_db_backup,
"optimizedb" => $lang->can_optimize_db,
"recount_rebuild" => $lang->can_recount_and_rebuild,
"adminlog" => $lang->can_manage_admin_logs,
"modlog" => $lang->can_manage_mod_logs,
"maillogs" => $lang->can_manage_user_mail_log,
"mailerrors" => $lang->can_manage_system_mail_log,
"warninglog" => $lang->can_manage_user_warning_log,
"spamlog" => $lang->can_manage_spam_log,
"php_info" => $lang->can_view_php_info,
"file_verification" => $lang->can_manage_file_verification,
"statistics" => $lang->can_view_statistics,
);
$admin_permissions = $plugins->run_hooks("admin_tools_permissions", $admin_permissions);
return array("name" => $lang->tools_and_maintenance, "permissions" => $admin_permissions, "disporder" => 50);
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->optimize_database, "index.php?module=tools-optimizedb");
$plugins->run_hooks("admin_tools_optimizedb_begin");
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_optimizedb_start");
if($mybb->request_method == "post")
{
if(!is_array($mybb->input['tables']))
{
flash_message($lang->error_no_tables_selected, 'error');
admin_redirect("index.php?module=tools-optimizedb");
}
@set_time_limit(0);
$db->set_table_prefix('');
foreach($mybb->input['tables'] as $table)
{
if($db->table_exists($db->escape_string($table)))
{
$db->optimize_table($table);
$db->analyze_table($table);
}
}
$db->set_table_prefix(TABLE_PREFIX);
$plugins->run_hooks("admin_tools_optimizedb_start_begin");
// Log admin action
log_admin_action(my_serialize($mybb->input['tables']));
flash_message($lang->success_tables_optimized, 'success');
admin_redirect("index.php?module=tools-optimizedb");
}
$page->extra_header = " <script type=\"text/javascript\">
function changeSelection(action, prefix)
{
var select_box = document.getElementById('table_select');
for(var i = 0; i < select_box.length; i++)
{
if(action == 'select')
{
select_box[i].selected = true;
}
else if(action == 'deselect')
{
select_box[i].selected = false;
}
else if(action == 'forum' && prefix != 0)
{
select_box[i].selected = false;
var row = select_box[i].value;
var subString = row.substring(prefix.length, 0);
if(subString == prefix)
{
select_box[i].selected = true;
}
}
}
}
</script>\n";
$page->output_header($lang->optimize_database);
$table = new Table;
$table->construct_header($lang->table_selection);
$table_selects = array();
$table_list = $db->list_tables($config['database']['database']);
foreach($table_list as $id => $table_name)
{
$table_selects[$table_name] = $table_name;
}
$form = new Form("index.php?module=tools-optimizedb", "post", "table_selection", 0, "table_selection");
$table->construct_cell("{$lang->tables_select_desc}\n<br /><br />\n<a href=\"javascript:changeSelection('select', 0);\">{$lang->select_all}</a><br />\n<a href=\"javascript:changeSelection('deselect', 0);\">{$lang->deselect_all}</a><br />\n<a href=\"javascript:changeSelection('forum', '".TABLE_PREFIX."');\">{$lang->select_forum_tables}</a>\n<br /><br />\n<div class=\"form_row\">".$form->generate_select_box("tables[]", $table_selects, false, array('multiple' => true, 'id' => 'table_select', 'size' => 20))."</div>", array('rowspan' => 5, 'width' => '50%'));
$table->construct_row();
$table->output($lang->optimize_database);
$buttons[] = $form->generate_submit_button($lang->optimize_selected_tables);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
if($mybb->input['action'] == 'phpinfo')
{
$plugins->run_hooks("admin_tools_php_info_phpinfo");
// Log admin action
log_admin_action();
phpinfo();
exit;
}
$page->add_breadcrumb_item($lang->php_info, "index.php?module=tools-php_info");
$plugins->run_hooks("admin_tools_php_info_begin");
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_php_info_start");
$page->output_header($lang->php_info);
echo "<iframe src=\"index.php?module=tools-php_info&amp;action=phpinfo\" width=\"100%\" height=\"500\" frameborder=\"0\">{$lang->browser_no_iframe_support}</iframe>";
$page->output_footer();
}

View File

@@ -0,0 +1,767 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->recount_rebuild, "index.php?module=tools-recount_rebuild");
$plugins->run_hooks("admin_tools_recount_rebuild");
/**
* Rebuild forum counters
*/
function acp_rebuild_forum_counters()
{
global $db, $mybb, $lang;
$query = $db->simple_select("forums", "COUNT(*) as num_forums");
$num_forums = $db->fetch_field($query, 'num_forums');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('forumcounters', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("forums", "fid", '', array('order_by' => 'fid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($forum = $db->fetch_array($query))
{
$update['parentlist'] = make_parent_list($forum['fid']);
$db->update_query("forums", $update, "fid='{$forum['fid']}'");
rebuild_forum_counters($forum['fid']);
}
check_proceed($num_forums, $end, ++$page, $per_page, "forumcounters", "do_rebuildforumcounters", $lang->success_rebuilt_forum_counters);
}
/**
* Rebuild thread counters
*/
function acp_rebuild_thread_counters()
{
global $db, $mybb, $lang;
$query = $db->simple_select("threads", "COUNT(*) as num_threads");
$num_threads = $db->fetch_field($query, 'num_threads');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('threadcounters', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("threads", "tid", '', array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($thread = $db->fetch_array($query))
{
rebuild_thread_counters($thread['tid']);
}
check_proceed($num_threads, $end, ++$page, $per_page, "threadcounters", "do_rebuildthreadcounters", $lang->success_rebuilt_thread_counters);
}
/**
* Rebuild poll counters
*/
function acp_rebuild_poll_counters()
{
global $db, $mybb, $lang;
$query = $db->simple_select("polls", "COUNT(*) as num_polls");
$num_polls = $db->fetch_field($query, 'num_polls');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('pollcounters', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("polls", "pid", '', array('order_by' => 'pid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($poll = $db->fetch_array($query))
{
rebuild_poll_counters($poll['pid']);
}
check_proceed($num_polls, $end, ++$page, $per_page, "pollcounters", "do_rebuildpollcounters", $lang->success_rebuilt_poll_counters);
}
/**
* Recount user posts
*/
function acp_recount_user_posts()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('userposts', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("forums", "fid", "usepostcounts = 0");
while($forum = $db->fetch_array($query))
{
$fids[] = $forum['fid'];
}
if(is_array($fids))
{
$fids = implode(',', $fids);
}
if($fids)
{
$fids = " AND p.fid NOT IN($fids)";
}
else
{
$fids = "";
}
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT COUNT(p.pid) AS post_count
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
WHERE p.uid='{$user['uid']}' AND t.visible > 0 AND p.visible > 0{$fids}
");
$num_posts = $db->fetch_field($query2, "post_count");
$db->update_query("users", array("postnum" => (int)$num_posts), "uid='{$user['uid']}'");
}
check_proceed($num_users, $end, ++$page, $per_page, "userposts", "do_recountuserposts", $lang->success_rebuilt_user_post_counters);
}
/**
* Recount user threads
*/
function acp_recount_user_threads()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('userthreads', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("forums", "fid", "usethreadcounts = 0");
while($forum = $db->fetch_array($query))
{
$fids[] = $forum['fid'];
}
if(is_array($fids))
{
$fids = implode(',', $fids);
}
if($fids)
{
$fids = " AND t.fid NOT IN($fids)";
}
else
{
$fids = "";
}
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT COUNT(t.tid) AS thread_count
FROM ".TABLE_PREFIX."threads t
WHERE t.uid='{$user['uid']}' AND t.visible > 0 AND t.closed NOT LIKE 'moved|%'{$fids}
");
$num_threads = $db->fetch_field($query2, "thread_count");
$db->update_query("users", array("threadnum" => (int)$num_threads), "uid='{$user['uid']}'");
}
check_proceed($num_users, $end, ++$page, $per_page, "userthreads", "do_recountuserthreads", $lang->success_rebuilt_user_thread_counters);
}
/**
* Recount reputation values
*/
function acp_recount_reputation()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('reputation', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT SUM(reputation) as total_rep
FROM ".TABLE_PREFIX."reputation
WHERE uid='{$user['uid']}'
");
$total_rep = $db->fetch_field($query2, "total_rep");
$db->update_query("users", array("reputation" => (int)$total_rep), "uid='{$user['uid']}'");
}
check_proceed($num_users, $end, ++$page, $per_page, "reputation", "do_recountreputation", $lang->success_rebuilt_reputation);
}
/**
* Recount warnings for users
*/
function acp_recount_warning()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('warning', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT SUM(points) as warn_lev
FROM ".TABLE_PREFIX."warnings
WHERE uid='{$user['uid']}' AND expired='0'
");
$warn_lev = $db->fetch_field($query2, "warn_lev");
$db->update_query("users", array("warningpoints" => (int)$warn_lev), "uid='{$user['uid']}'");
}
check_proceed($num_users, $end, ++$page, $per_page, "warning", "do_recountwarning", $lang->success_rebuilt_warning);
}
/**
* Recount private messages (total and unread) for users
*/
function acp_recount_private_messages()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('privatemessages', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
require_once MYBB_ROOT."inc/functions_user.php";
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
update_pm_count($user['uid']);
}
check_proceed($num_users, $end, ++$page, $per_page, "privatemessages", "do_recountprivatemessages", $lang->success_rebuilt_private_messages);
}
/**
* Recount referrals for users
*/
function acp_recount_referrals()
{
global $db, $mybb, $lang;
$query = $db->simple_select("users", "COUNT(uid) as num_users");
$num_users = $db->fetch_field($query, 'num_users');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('referral', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($user = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT COUNT(uid) as num_referrers
FROM ".TABLE_PREFIX."users
WHERE referrer='{$user['uid']}'
");
$num_referrers = $db->fetch_field($query2, "num_referrers");
$db->update_query("users", array("referrals" => (int)$num_referrers), "uid='{$user['uid']}'");
}
check_proceed($num_users, $end, ++$page, $per_page, "referral", "do_recountreferral", $lang->success_rebuilt_referral);
}
/**
* Recount thread ratings
*/
function acp_recount_thread_ratings()
{
global $db, $mybb, $lang;
$query = $db->simple_select("threads", "COUNT(*) as num_threads");
$num_threads = $db->fetch_field($query, 'num_threads');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('threadrating', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$query = $db->simple_select("threads", "tid", '', array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($thread = $db->fetch_array($query))
{
$query2 = $db->query("
SELECT COUNT(tid) as num_ratings, SUM(rating) as total_rating
FROM ".TABLE_PREFIX."threadratings
WHERE tid='{$thread['tid']}'
");
$recount = $db->fetch_array($query2);
$db->update_query("threads", array("numratings" => (int)$recount['num_ratings'], "totalratings" => (int)$recount['total_rating']), "tid='{$thread['tid']}'");
}
check_proceed($num_threads, $end, ++$page, $per_page, "threadrating", "do_recountthreadrating", $lang->success_rebuilt_thread_ratings);
}
/**
* Rebuild thumbnails for attachments
*/
function acp_rebuild_attachment_thumbnails()
{
global $db, $mybb, $lang;
$query = $db->simple_select("attachments", "COUNT(aid) as num_attachments");
$num_attachments = $db->fetch_field($query, 'num_attachments');
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$per_page = $mybb->get_input('attachmentthumbs', MyBB::INPUT_INT);
$start = ($page-1) * $per_page;
$end = $start + $per_page;
$uploadspath = $mybb->settings['uploadspath'];
if(my_substr($uploadspath, 0, 1) == '.')
{
$uploadspath = MYBB_ROOT . $mybb->settings['uploadspath'];
}
require_once MYBB_ROOT."inc/functions_image.php";
$query = $db->simple_select("attachments", "*", '', array('order_by' => 'aid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
while($attachment = $db->fetch_array($query))
{
$ext = my_strtolower(my_substr(strrchr($attachment['filename'], "."), 1));
if($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe")
{
$thumbname = str_replace(".attach", "_thumb.$ext", $attachment['attachname']);
$thumbnail = generate_thumbnail($uploadspath."/".$attachment['attachname'], $uploadspath, $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);
if($thumbnail['code'] == 4)
{
$thumbnail['filename'] = "SMALL";
}
$db->update_query("attachments", array("thumbnail" => $thumbnail['filename']), "aid='{$attachment['aid']}'");
}
}
check_proceed($num_attachments, $end, ++$page, $per_page, "attachmentthumbs", "do_rebuildattachmentthumbs", $lang->success_rebuilt_attachment_thumbnails);
}
/**
* @param int $current
* @param int $finish
* @param int $next_page
* @param int $per_page
* @param string $name
* @param string $name2
* @param string $message
*/
function check_proceed($current, $finish, $next_page, $per_page, $name, $name2, $message)
{
global $page, $lang;
if($finish >= $current)
{
flash_message($message, 'success');
admin_redirect("index.php?module=tools-recount_rebuild");
}
else
{
$page->output_header();
$form = new Form("index.php?module=tools-recount_rebuild", 'post');
echo $form->generate_hidden_field("page", $next_page);
echo $form->generate_hidden_field($name, $per_page);
echo $form->generate_hidden_field($name2, $lang->go);
echo "<div class=\"confirm_action\">\n";
echo "<p>{$lang->confirm_proceed_rebuild}</p>\n";
echo "<br />\n";
echo "<script type=\"text/javascript\">
$(function() {
var button = $(\"#proceed_button\");
if(button.length > 0) {
button.val(\"{$lang->automatically_redirecting}\");
button.attr(\"disabled\", true);
button.css(\"color\", \"#aaa\");
button.css(\"borderColor\", \"#aaa\");
var parent_form = button.closest('form');
if (parent_form.length > 0) {
parent_form.submit();
}
}
});
</script>";
echo "<p class=\"buttons\">\n";
echo $form->generate_submit_button($lang->proceed, array('class' => 'button_yes', 'id' => 'proceed_button'));
echo "</p>\n";
echo "</div>\n";
$form->end();
$page->output_footer();
exit;
}
}
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_recount_rebuild_start");
if($mybb->request_method == "post")
{
require_once MYBB_ROOT."inc/functions_rebuild.php";
if(!isset($mybb->input['page']) || $mybb->get_input('page', MyBB::INPUT_INT) < 1)
{
$mybb->input['page'] = 1;
}
$plugins->run_hooks("admin_tools_do_recount_rebuild");
if(isset($mybb->input['do_rebuildforumcounters']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_forum_counters");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("forum");
}
$per_page = $mybb->get_input('forumcounters', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['forumcounters'] = 50;
}
acp_rebuild_forum_counters();
}
elseif(isset($mybb->input['do_rebuildthreadcounters']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_thread_counters");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("thread");
}
$per_page = $mybb->get_input('threadcounters', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['threadcounters'] = 500;
}
acp_rebuild_thread_counters();
}
elseif(isset($mybb->input['do_recountuserposts']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_user_posts");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("userposts");
}
$per_page = $mybb->get_input('userposts', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['userposts'] = 500;
}
acp_recount_user_posts();
}
elseif(isset($mybb->input['do_recountuserthreads']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_user_threads");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("userthreads");
}
$per_page = $mybb->get_input('userthreads', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['userthreads'] = 500;
}
acp_recount_user_threads();
}
elseif(isset($mybb->input['do_rebuildattachmentthumbs']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_attachment_thumbs");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("attachmentthumbs");
}
$per_page = $mybb->get_input('attachmentthumbs', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['attachmentthumbs'] = 500;
}
acp_rebuild_attachment_thumbnails();
}
elseif(isset($mybb->input['do_recountreputation']))
{
$plugins->run_hooks("admin_tools_recount_recount_reputation");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("reputation");
}
$per_page = $mybb->get_input('reputation', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['reputation'] = 500;
}
acp_recount_reputation();
}
elseif(isset($mybb->input['do_recountwarning']))
{
$plugins->run_hooks("admin_tools_recount_recount_warning");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("warning");
}
$per_page = $mybb->get_input('warning', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['warning'] = 500;
}
acp_recount_warning();
}
elseif(isset($mybb->input['do_recountprivatemessages']))
{
$plugins->run_hooks("admin_tools_recount_recount_private_messages");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("privatemessages");
}
$per_page = $mybb->get_input('privatemessages', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['privatemessages'] = 500;
}
acp_recount_private_messages();
}
elseif(isset($mybb->input['do_recountreferral']))
{
$plugins->run_hooks("admin_tools_recount_recount_referral");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("referral");
}
$per_page = $mybb->get_input('referral', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['referral'] = 500;
}
acp_recount_referrals();
}
elseif(isset($mybb->input['do_recountthreadrating']))
{
$plugins->run_hooks("admin_tools_recount_recount_thread_ratings");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("threadrating");
}
$per_page = $mybb->get_input('threadrating', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['threadrating'] = 500;
}
acp_recount_thread_ratings();
}
elseif(isset($mybb->input['do_rebuildpollcounters']))
{
$plugins->run_hooks("admin_tools_recount_rebuild_poll_counters");
if($mybb->input['page'] == 1)
{
// Log admin action
log_admin_action("poll");
}
$per_page = $mybb->get_input('pollcounters', MyBB::INPUT_INT);
if(!$per_page || $per_page <= 0)
{
$mybb->input['pollcounters'] = 500;
}
acp_rebuild_poll_counters();
}
else
{
$plugins->run_hooks("admin_tools_recount_rebuild_stats");
$cache->update_stats();
// Log admin action
log_admin_action("stats");
flash_message($lang->success_rebuilt_forum_stats, 'success');
admin_redirect("index.php?module=tools-recount_rebuild");
}
}
$page->output_header($lang->recount_rebuild);
$sub_tabs['recount_rebuild'] = array(
'title' => $lang->recount_rebuild,
'link' => "index.php?module=tools-recount_rebuild",
'description' => $lang->recount_rebuild_desc
);
$page->output_nav_tabs($sub_tabs, 'recount_rebuild');
$form = new Form("index.php?module=tools-recount_rebuild", "post");
$form_container = new FormContainer($lang->recount_rebuild);
$form_container->output_row_header($lang->name);
$form_container->output_row_header($lang->data_per_page, array('width' => 50));
$form_container->output_row_header("&nbsp;");
$form_container->output_cell("<label>{$lang->rebuild_forum_counters}</label><div class=\"description\">{$lang->rebuild_forum_counters_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("forumcounters", 50, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildforumcounters")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->rebuild_thread_counters}</label><div class=\"description\">{$lang->rebuild_thread_counters_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("threadcounters", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildthreadcounters")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->rebuild_poll_counters}</label><div class=\"description\">{$lang->rebuild_poll_counters_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("pollcounters", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildpollcounters")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_user_posts}</label><div class=\"description\">{$lang->recount_user_posts_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("userposts", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountuserposts")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_user_threads}</label><div class=\"description\">{$lang->recount_user_threads_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("userthreads", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountuserthreads")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->rebuild_attachment_thumbs}</label><div class=\"description\">{$lang->rebuild_attachment_thumbs_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("attachmentthumbs", 20, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildattachmentthumbs")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_stats}</label><div class=\"description\">{$lang->recount_stats_desc}</div>");
$form_container->output_cell($lang->na);
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountstats")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_reputation}</label><div class=\"description\">{$lang->recount_reputation_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("reputation", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountreputation")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_warning}</label><div class=\"description\">{$lang->recount_warning_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("warning", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountwarning")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_private_messages}</label><div class=\"description\">{$lang->recount_private_messages_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("privatemessages", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountprivatemessages")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_referrals}</label><div class=\"description\">{$lang->recount_referrals_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("referral", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountreferral")));
$form_container->construct_row();
$form_container->output_cell("<label>{$lang->recount_thread_ratings}</label><div class=\"description\">{$lang->recount_thread_ratings_desc}</div>");
$form_container->output_cell($form->generate_numeric_field("threadrating", 500, array('style' => 'width: 150px;', 'min' => 0)));
$form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountthreadrating")));
$form_container->construct_row();
$plugins->run_hooks("admin_tools_recount_rebuild_output_list");
$form_container->end();
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,296 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->spam_logs, "index.php?module=tools-spamlog");
$sub_tabs['spam_logs'] = array(
'title' => $lang->spam_logs,
'link' => "index.php?module=tools-spamlog",
'description' => $lang->spam_logs_desc
);
$sub_tabs['prune_spam_logs'] = array(
'title' => $lang->prune_spam_logs,
'link' => "index.php?module=tools-spamlog&amp;action=prune",
'description' => $lang->prune_spam_logs_desc
);
$plugins->run_hooks("admin_tools_spamlog_begin");
if($mybb->input['action'] == 'prune')
{
if(!is_super_admin($mybb->user['uid']))
{
flash_message($lang->cannot_perform_action_super_admin_general, 'error');
admin_redirect("index.php?module=tools-spamlog");
}
$plugins->run_hooks("admin_tools_spamlog_prune");
if($mybb->request_method == 'post')
{
$is_today = false;
$mybb->input['older_than'] = $mybb->get_input('older_than', MyBB::INPUT_INT);
if($mybb->input['older_than'] <= 0)
{
$is_today = true;
$mybb->input['older_than'] = 1;
}
$where = 'dateline < '.(TIME_NOW-($mybb->input['older_than']*86400));
// Searching for entries in a specific module
if($mybb->input['filter_username'])
{
$where .= " AND username='".$db->escape_string($mybb->input['filter_username'])."'";
}
// Searching for entries in a specific module
if($mybb->input['filter_email'])
{
$where .= " AND email='".$db->escape_string($mybb->input['filter_email'])."'";
}
$query = $db->delete_query("spamlog", $where);
$num_deleted = $db->affected_rows();
$plugins->run_hooks("admin_tools_spamlog_prune_commit");
// Log admin action
log_admin_action($mybb->input['older_than'], $mybb->input['filter_username'], $mybb->input['filter_email'], $num_deleted);
$success = $lang->success_pruned_spam_logs;
if($is_today == true && $num_deleted > 0)
{
$success .= ' '.$lang->note_logs_locked;
}
elseif($is_today == true && $num_deleted == 0)
{
flash_message($lang->note_logs_locked, 'error');
admin_redirect('index.php?module=tools-spamlog');
}
flash_message($success, 'success');
admin_redirect('index.php?module=tools-spamlog');
}
$page->add_breadcrumb_item($lang->prune_spam_logs, 'index.php?module=tools-spamlog&amp;action=prune');
$page->output_header($lang->prune_spam_logs);
$page->output_nav_tabs($sub_tabs, 'prune_spam_logs');
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = 'selected="selected"';
$ordersel[$mybb->input['order']] = 'selected="selected"';
$form = new Form("index.php?module=tools-spamlog&amp;action=prune", "post");
$form_container = new FormContainer($lang->prune_spam_logs);
$form_container->output_row($lang->spam_username, "", $form->generate_text_box('filter_username', $mybb->input['filter_username'], array('id' => 'filter_username')), 'filter_username');
$form_container->output_row($lang->spam_email, "", $form->generate_text_box('filter_email', $mybb->input['filter_email'], array('id' => 'filter_email')), 'filter_email');
if(!$mybb->input['older_than'])
{
$mybb->input['older_than'] = '30';
}
$form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_numeric_field('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 50px', 'min' => 0))." {$lang->days}", 'older_than');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->prune_spam_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_spamlog_start");
$page->output_header($lang->spam_logs);
$page->output_nav_tabs($sub_tabs, 'spam_logs');
$perpage = $mybb->get_input('perpage', MyBB::INPUT_INT);
if(!$perpage)
{
$perpage = 20;
}
$where = '1=1';
$additional_criteria = array();
// Searching for entries witha specific username
if($mybb->input['username'])
{
$where .= " AND username='".$db->escape_string($mybb->input['username'])."'";
$additional_criteria[] = "username=".urlencode($mybb->input['username']);
}
// Searching for entries with a specific email
if($mybb->input['email'])
{
$where .= " AND email='".$db->escape_string($mybb->input['email'])."'";
$additional_criteria[] = "email=".urlencode($mybb->input['email']);
}
// Searching for entries with a specific IP
if($mybb->input['ipaddress'] > 0)
{
$where .= " AND ipaddress=".$db->escape_binary(my_inet_pton($mybb->input['ipaddress']));
$additional_criteria[] = "ipaddress=".urlencode($mybb->input['ipaddress']);
}
if($additional_criteria)
{
$additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
}
else
{
$additional_criteria = '';
}
// Order?
switch($mybb->input['sortby'])
{
case "username":
$sortby = "username";
break;
case "email":
$sortby = "email";
break;
case "ipaddress":
$sortby = "ipaddress";
break;
default:
$sortby = "dateline";
}
$order = $mybb->input['order'];
if($order != "asc")
{
$order = "desc";
}
$query = $db->simple_select("spamlog", "COUNT(sid) AS count", $where);
$rescount = $db->fetch_field($query, "count");
// Figure out if we need to display multiple pages.
if($mybb->input['page'] != "last")
{
$pagecnt = $mybb->get_input('page', MyBB::INPUT_INT);
}
$logcount = (int)$rescount;
$pages = $logcount / $perpage;
$pages = ceil($pages);
if($mybb->input['page'] == "last")
{
$pagecnt = $pages;
}
if($pagecnt > $pages)
{
$pagecnt = 1;
}
if($pagecnt)
{
$start = ($pagecnt-1) * $perpage;
}
else
{
$start = 0;
$pagecnt = 1;
}
$table = new Table;
$table->construct_header($lang->spam_username, array('width' => '20%'));
$table->construct_header($lang->spam_email, array("class" => "align_center", 'width' => '20%'));
$table->construct_header($lang->spam_ip, array("class" => "align_center", 'width' => '20%'));
$table->construct_header($lang->spam_date, array("class" => "align_center", 'width' => '20%'));
$table->construct_header($lang->spam_confidence, array("class" => "align_center", 'width' => '20%'));
$query = $db->simple_select("spamlog", "*", $where, array('order_by' => $sortby, 'order_dir' => $order, 'limit_start' => $start, 'limit' => $perpage));
while($row = $db->fetch_array($query))
{
$username = htmlspecialchars_uni($row['username']);
$email = htmlspecialchars_uni($row['email']);
$ip_address = my_inet_ntop($db->unescape_binary($row['ipaddress']));
$dateline = '';
if($row['dateline'] > 0)
{
$dateline = my_date('relative', $row['dateline']);
}
$confidence = '0%';
$data = @my_unserialize($row['data']);
if(is_array($data) && !empty($data))
{
if(isset($data['confidence']))
{
$confidence = (double)$data['confidence'].'%';
}
}
$search_sfs = "<div class=\"float_right\"><a href=\"http://www.stopforumspam.com/ipcheck/{$ip_address}\" target=\"_blank\" rel=\"noopener\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->search_ip_on_sfs}\" alt=\"{$lang->search}\" /></a></div>";
$table->construct_cell($username);
$table->construct_cell($email);
$table->construct_cell("{$search_sfs}<div>{$ip_address}</div>");
$table->construct_cell($dateline);
$table->construct_cell($confidence);
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_spam_logs, array("colspan" => "5"));
$table->construct_row();
}
$table->output($lang->spam_logs);
// Do we need to construct the pagination?
if($rescount > $perpage)
{
echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-spamlog&amp;perpage={$perpage}{$additional_criteria}&amp;sortby={$mybb->input['sortby']}&amp;order={$order}")."<br />";
}
// Fetch filter options
$sortbysel[$mybb->input['sortby']] = "selected=\"selected\"";
$ordersel[$mybb->input['order']] = "selected=\"selected\"";
$sort_by = array(
'dateline' => $lang->spam_date,
'username' => $lang->spam_username,
'email' => $lang->spam_email,
'ipaddress' => $lang->spam_ip,
);
$order_array = array(
'asc' => $lang->asc,
'desc' => $lang->desc
);
$form = new Form("index.php?module=tools-spamlog", "post");
$form_container = new FormContainer($lang->filter_spam_logs);
$form_container->output_row($lang->spam_username, "", $form->generate_text_box('username', htmlspecialchars_uni($mybb->get_input('username')), array('id' => 'username')), 'suername');
$form_container->output_row($lang->spam_email, "", $form->generate_text_box('email', $mybb->input['email'], array('id' => 'email')), 'email');
$form_container->output_row($lang->spam_ip, "", $form->generate_text_box('ipaddress', $mybb->input['ipaddress'], array('id' => 'ipaddress')), 'ipaddress');
$form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order');
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $perpage, array('id' => 'perpage', 'min' => 1)), 'perpage');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->filter_spam_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}

View File

@@ -0,0 +1,290 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
if($mybb->input['action'] == "do_graph")
{
$range = array(
'start' => $mybb->get_input('start', MyBB::INPUT_INT),
'end' => $mybb->get_input('end', MyBB::INPUT_INT)
);
create_graph($mybb->input['type'], $range);
die;
}
$page->add_breadcrumb_item($lang->statistics, "index.php?module=tools-statistics");
$sub_tabs['overall_statistics'] = array(
'title' => $lang->overall_statistics,
'link' => "index.php?module=tools-statistics",
'description' => $lang->overall_statistics_desc
);
$plugins->run_hooks("admin_tools_statistics_begin");
if(!$mybb->input['action'])
{
$query = $db->simple_select("stats", "COUNT(*) as total");
if($db->fetch_field($query, "total") == 0)
{
flash_message($lang->error_no_statistics_available_yet, 'error');
admin_redirect("index.php?module=tools");
}
$per_page = 20;
$plugins->run_hooks("admin_tools_statistics_overall_begin");
// Do we have date range criteria?
if($mybb->input['from_year'])
{
$start_dateline = mktime(0, 0, 0, $mybb->get_input('from_month', MyBB::INPUT_INT), $mybb->get_input('from_day', MyBB::INPUT_INT), $mybb->get_input('from_year', MyBB::INPUT_INT));
$end_dateline = mktime(23, 59, 59, $mybb->get_input('to_month', MyBB::INPUT_INT), $mybb->get_input('to_day', MyBB::INPUT_INT), $mybb->get_input('to_year', MyBB::INPUT_INT));
$range = "&amp;start={$start_dateline}&amp;end={$end_dateline}";
}
// Otherwise default to the last 30 days
if(!$mybb->input['from_year'] || $start_dateline > TIME_NOW || $end_dateline > mktime(23, 59, 59))
{
$start_dateline = TIME_NOW-(60*60*24*30);
$end_dateline = TIME_NOW;
list($mybb->input['from_day'], $mybb->input['from_month'], $mybb->input['from_year']) = explode('-', date('j-n-Y', $start_dateline));
list($mybb->input['to_day'], $mybb->input['to_month'], $mybb->input['to_year']) = explode('-', date('j-n-Y', $end_dateline));
$range = "&amp;start={$start_dateline}&amp;end={$end_dateline}";
}
$last_dateline = 0;
if($mybb->input['page'] && $mybb->input['page'] > 1)
{
$mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($mybb->input['page']*$per_page)-$per_page;
}
else
{
$mybb->input['page'] = 1;
$start = 0;
}
$query = $db->simple_select("stats", "*", "dateline >= '".(int)$start_dateline."' AND dateline <= '".(int)$end_dateline."'", array('order_by' => 'dateline', 'order_dir' => 'asc'));
$stats = array();
while($stat = $db->fetch_array($query))
{
if($last_dateline)
{
$stat['change_users'] = ($stat['numusers'] - $stats[$last_dateline]['numusers']);
$stat['change_threads'] = ($stat['numthreads'] - $stats[$last_dateline]['numthreads']);
$stat['change_posts'] = ($stat['numposts'] - $stats[$last_dateline]['numposts']);
}
$stats[$stat['dateline']] = $stat;
$last_dateline = $stat['dateline'];
}
if(empty($stats))
{
flash_message($lang->error_no_results_found_for_criteria, 'error');
}
krsort($stats, SORT_NUMERIC);
$page->add_breadcrumb_item($lang->overall_statistics, "index.php?module=tools-statistics");
$page->output_header($lang->statistics." - ".$lang->overall_statistics);
$page->output_nav_tabs($sub_tabs, 'overall_statistics');
// Date range fields
$form = new Form("index.php?module=tools-statistics", "post", "overall");
echo "<fieldset><legend>{$lang->date_range}</legend>\n";
echo "{$lang->from} ".$form->generate_date_select('from', $mybb->input['from_day'], $mybb->input['from_month'], $mybb->input['from_year']);
echo " {$lang->to} ".$form->generate_date_select('to', $mybb->input['to_day'], $mybb->input['to_month'], $mybb->input['to_year']);
echo " ".$form->generate_submit_button($lang->view);
echo "</fieldset>\n";
$form->end();
if(!empty($stats))
{
echo "<fieldset><legend>{$lang->users}</legend>\n";
echo "<img src=\"index.php?module=tools-statistics&amp;action=do_graph&amp;type=users{$range}\" />\n";
echo "</fieldset>\n";
echo "<fieldset><legend>{$lang->threads}</legend>\n";
echo "<img src=\"index.php?module=tools-statistics&amp;action=do_graph&amp;type=threads{$range}\" />\n";
echo "</fieldset>\n";
echo "<fieldset><legend>{$lang->posts}</legend>\n";
echo "<img src=\"index.php?module=tools-statistics&amp;action=do_graph&amp;type=posts{$range}\" />\n";
echo "</fieldset>\n";
$total_rows = count($stats);
$pages = ceil($total_rows / $per_page);
if($mybb->input['page'] > $pages)
{
$mybb->input['page'] = 1;
$start = 0;
}
$table = new Table;
$table->construct_header($lang->date);
$table->construct_header($lang->users);
$table->construct_header($lang->threads);
$table->construct_header($lang->posts);
$query = $db->simple_select("stats", "*", "dateline >= '".(int)$start_dateline."' AND dateline <= '".(int)$end_dateline."'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit_start' => $start, 'limit' => $per_page));
while($stat = $db->fetch_array($query))
{
$table->construct_cell("<strong>".date($mybb->settings['dateformat'], $stat['dateline'])."</strong>");
$table->construct_cell(my_number_format($stat['numusers'])." <small>".generate_growth_string($stats[$stat['dateline']]['change_users'])."</small>");
$table->construct_cell(my_number_format($stat['numthreads'])." <small>".generate_growth_string($stats[$stat['dateline']]['change_threads'])."</small>");
$table->construct_cell(my_number_format($stat['numposts'])." <small>".generate_growth_string($stats[$stat['dateline']]['change_posts'])."</small>");
$table->construct_row();
}
$table->output($lang->overall_statistics);
$url_range = "&amp;from_month=".$mybb->get_input('from_month', MyBB::INPUT_INT)."&amp;from_day=".$mybb->get_input('from_day', MyBB::INPUT_INT)."&amp;from_year=".$mybb->get_input('from_year', MyBB::INPUT_INT);
$url_range .= "&amp;to_month=".$mybb->get_input('to_month', MyBB::INPUT_INT)."&amp;to_day=".$mybb->get_input('to_day', MyBB::INPUT_INT)."&amp;to_year=".$mybb->get_input('to_year', MyBB::INPUT_INT);
echo draw_admin_pagination($mybb->input['page'], $per_page, $total_rows, "index.php?module=tools-statistics{$url_range}&amp;page={page}");
}
$page->output_footer();
}
/**
* @param int $number
*
* @return string
*/
function generate_growth_string($number)
{
global $lang, $cp_style;
if($number === null)
{
return "";
}
$number = (int)$number;
$friendly_number = my_number_format(abs($number));
if($number > 0)
{
$growth_string = "(<img src=\"./styles/{$cp_style}/images/icons/increase.png\" alt=\"{$lang->increase}\" title=\"{$lang->increase}\" style=\"vertical-align: middle; margin-top: -2px;\" /> {$friendly_number})";
}
elseif($number == 0)
{
$growth_string = "(<img src=\"./styles/{$cp_style}/images/icons/no_change.png\" alt=\"{$lang->no_change}\" title=\"{$lang->no_change}\" style=\"vertical-align: middle; margin-top: -2px;\" /> {$friendly_number})";
}
else
{
$growth_string = "(<img src=\"./styles/{$cp_style}/images/icons/decrease.png\" alt=\"{$lang->decrease}\" title=\"{$lang->decrease}\" style=\"vertical-align: middle; margin-top: -2px;\" /> {$friendly_number})";
}
return $growth_string;
}
/**
* @param string $type users, threads, posts
* @param array $range
*/
function create_graph($type, $range=null)
{
global $db;
// Do we have date range criteria?
if($range['end'] || $range['start'])
{
$start = (int)$range['start'];
$end = (int)$range['end'];
}
// Otherwise default to the last 30 days
else
{
$start = TIME_NOW-(60*60*24*30);
$end = TIME_NOW;
}
$allowed_types = array('users', 'threads', 'posts');
if(!in_array($type, $allowed_types))
{
die;
}
require_once MYBB_ROOT.'inc/class_graph.php';
$points = $stats = $datelines = array();
if($start == 0)
{
$query = $db->simple_select("stats", "dateline,num{$type}", "dateline <= '".(int)$end."'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => 2));
while($stat = $db->fetch_array($query))
{
$stats[] = $stat['num'.$type];
$datelines[] = $stat['dateline'];
$x_labels[] = date("m/j", $stat['dateline']);
}
$points[$datelines[0]] = 0;
$points[$datelines[1]] = $stats[0]-$stats[1];
ksort($points, SORT_NUMERIC);
}
elseif($end == 0)
{
$query = $db->simple_select("stats", "dateline,num{$type}", "dateline >= '".(int)$start."'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 2));
while($stat = $db->fetch_array($query))
{
$stats[] = $stat['num'.$type];
$datelines[] = $stat['dateline'];
$x_labels[] = date("m/j", $stat['dateline']);
}
$points[$datelines[0]] = 0;
$points[$datelines[1]] = $stats[1]-$stats[0];
ksort($points, SORT_NUMERIC);
}
else
{
$query = $db->simple_select("stats", "dateline,num{$type}", "dateline >= '".(int)$start."' AND dateline <= '".(int)$end."'", array('order_by' => 'dateline', 'order_dir' => 'asc'));
while($stat = $db->fetch_array($query))
{
$points[$stat['dateline']] = $stat['num'.$type];
$datelines[] = $stat['dateline'];
$x_labels[] = date("m/j", $stat['dateline']);
}
}
sort($datelines, SORT_NUMERIC);
// Find our year(s) label
$start_year = date('Y', $datelines[0]);
$last_year = date('Y', $datelines[count($datelines)-1]);
if(($last_year - $start_year) == 0)
{
$bottom_label = $start_year;
}
else
{
$bottom_label = $start_year." - ".$last_year;
}
// Create the graph outline
$graph = new Graph();
$graph->add_points(array_values($points));
$graph->add_x_labels($x_labels);
$graph->set_bottom_label($bottom_label);
$graph->render();
$graph->output();
}

View File

@@ -0,0 +1,981 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->system_health, "index.php?module=tools-system_health");
$sub_tabs['system_health'] = array(
'title' => $lang->system_health,
'link' => "index.php?module=tools-system_health",
'description' => $lang->system_health_desc
);
$sub_tabs['utf8_conversion'] = array(
'title' => $lang->utf8_conversion,
'link' => "index.php?module=tools-system_health&amp;action=utf8_conversion",
'description' => $lang->utf8_conversion_desc2
);
$sub_tabs['template_check'] = array(
'title' => $lang->check_templates,
'link' => "index.php?module=tools-system_health&amp;action=check_templates",
'description' => $lang->check_templates_desc
);
$plugins->run_hooks("admin_tools_system_health_begin");
if($mybb->input['action'] == "do_check_templates" && $mybb->request_method == "post")
{
$query = $db->simple_select("templates", "*", "", array("order_by" => "sid, title", "order_dir" => "ASC"));
if(!$db->num_rows($query))
{
flash_message($lang->error_invalid_input, 'error');
admin_redirect("index.php?module=tools-system_health");
}
$plugins->run_hooks("admin_tools_system_health_template_do_check_start");
$t_cache = array();
while($template = $db->fetch_array($query))
{
if(check_template($template['template']) == true)
{
$t_cache[$template['sid']][] = $template;
}
}
if(empty($t_cache))
{
flash_message($lang->success_templates_checked, 'success');
admin_redirect("index.php?module=tools-system_health");
}
$plugins->run_hooks("admin_tools_system_health_template_do_check");
$page->add_breadcrumb_item($lang->check_templates);
$page->output_header($lang->check_templates);
$page->output_nav_tabs($sub_tabs, 'template_check');
$page->output_inline_error(array($lang->check_templates_info_desc));
$templatesets = array(
-2 => array(
"title" => "MyBB Master Templates"
)
);
$query = $db->simple_select("templatesets", "*");
while($set = $db->fetch_array($query))
{
$templatesets[$set['sid']] = $set;
}
$count = 0;
foreach($t_cache as $sid => $templates)
{
if(!$done_set[$sid])
{
$table = new Table();
$table->construct_header($templatesets[$sid]['title'], array("colspan" => 2));
$done_set[$sid] = 1;
++$count;
}
if($sid == -2)
{
// Some cheeky clown has altered the master templates!
$table->construct_cell($lang->error_master_templates_altered, array("colspan" => 2));
$table->construct_row();
}
foreach($templates as $template)
{
if($sid == -2)
{
$table->construct_cell($template['title'], array('colspan' => 2));
}
else
{
$popup = new PopupMenu("template_{$template['tid']}", $lang->options);
$popup->add_item($lang->full_edit, "index.php?module=style-templates&amp;action=edit_template&amp;title=".urlencode($template['title'])."&amp;sid={$sid}");
$table->construct_cell("<a href=\"index.php?module=style-templates&amp;action=edit_template&amp;title=".urlencode($template['title'])."&amp;sid={$sid}&amp;from=diff_report\">{$template['title']}</a>", array('width' => '80%'));
$table->construct_cell($popup->fetch(), array("class" => "align_center"));
}
$table->construct_row();
}
if($done_set[$sid] && !$done_output[$sid])
{
$done_output[$sid] = 1;
if($count == 1)
{
$table->output($lang->check_templates);
}
else
{
$table->output();
}
}
}
$page->output_footer();
}
if($mybb->input['action'] == "check_templates")
{
$page->add_breadcrumb_item($lang->check_templates);
$page->output_header($lang->check_templates);
$plugins->run_hooks("admin_tools_system_health_template_check");
$page->output_nav_tabs($sub_tabs, 'template_check');
if($errors)
{
$page->output_inline_error($errors);
}
$form = new Form("index.php?module=tools-system_health", "post", "check_set");
echo $form->generate_hidden_field("action", "do_check_templates");
$form_container = new FormContainer($lang->check_templates);
$form_container->output_row($lang->check_templates_title, "", $lang->check_templates_info);
$form_container->end();
$buttons = array();
$buttons[] = $form->generate_submit_button($lang->proceed);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if($mybb->input['action'] == "utf8_conversion")
{
if($db->type == "sqlite" || $db->type == "pgsql")
{
flash_message($lang->error_not_supported, 'error');
admin_redirect("index.php?module=tools-system_health");
}
$plugins->run_hooks("admin_tools_system_health_utf8_conversion");
if($mybb->request_method == "post" || ($mybb->input['do'] == "all" && !empty($mybb->input['table'])))
{
if(!empty($mybb->input['mb4']) && version_compare($db->get_version(), '5.5.3', '<'))
{
flash_message($lang->error_utf8mb4_version, 'error');
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
}
@set_time_limit(0);
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
if(!$db->table_exists($db->escape_string($mybb->input['table'])))
{
$db->set_table_prefix($old_table_prefix);
flash_message($lang->error_invalid_table, 'error');
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
}
$db->set_table_prefix($old_table_prefix);
$page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&amp;action=utf8_conversion");
$page->output_header($lang->system_health." - ".$lang->utf8_conversion);
$sub_tabs['system_health'] = array(
'title' => $lang->system_health,
'link' => "index.php?module=tools-system_health",
'description' => $lang->system_health_desc
);
$sub_tabs['utf8_conversion'] = array(
'title' => $lang->utf8_conversion,
'link' => "index.php?module=tools-system_health&amp;action=utf8_conversion",
'description' => $lang->utf8_conversion_desc2
);
$page->output_nav_tabs($sub_tabs, 'utf8_conversion');
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
$table = new Table;
$table1 = $db->show_create_table($db->escape_string($mybb->input['table']));
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table1, $matches);
$charset = $matches[1];
if(!empty($mybb->input['mb4']))
{
$table->construct_cell("<strong>".$lang->sprintf($lang->converting_to_utf8mb4, $mybb->input['table'], $charset)."</strong>");
}
else
{
$table->construct_cell("<strong>".$lang->sprintf($lang->converting_to_utf8, $mybb->input['table'], $charset)."</strong>");
}
$table->construct_row();
$table->construct_cell($lang->please_wait);
$table->construct_row();
$table->output($converting_table." {$mybb->input['table']}");
$db->set_table_prefix($old_table_prefix);
$page->output_footer(false);
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
flush();
$types = array(
'text' => 'blob',
'mediumtext' => 'mediumblob',
'longtext' => 'longblob',
'char' => 'varbinary',
'varchar' => 'varbinary',
'tinytext' => 'tinyblob'
);
$blob_types = array( 'blob', 'tinyblob', 'mediumblog', 'longblob', 'text', 'tinytext', 'mediumtext', 'longtext' );
// Get next table in list
$convert_to_binary = '';
$convert_to_utf8 = '';
$comma = '';
if(!empty($mybb->input['mb4']))
{
$character_set = 'utf8mb4';
$collation = 'utf8mb4_general_ci';
}
else
{
$character_set = 'utf8';
$collation = 'utf8_general_ci';
}
// Set table default charset
$db->write_query("ALTER TABLE {$mybb->input['table']} DEFAULT CHARACTER SET {$character_set} COLLATE {$collation}");
// Fetch any fulltext keys
if($db->supports_fulltext($mybb->input['table']))
{
$table_structure = $db->show_create_table($mybb->input['table']);
switch($db->type)
{
case "mysql":
case "mysqli":
preg_match_all("#FULLTEXT KEY `?([a-zA-Z0-9_]+)`? \(([a-zA-Z0-9_`,']+)\)#i", $table_structure, $matches);
if(is_array($matches))
{
foreach($matches[0] as $key => $matched)
{
$db->write_query("ALTER TABLE {$mybb->input['table']} DROP INDEX {$matches[1][$key]}");
$fulltext_to_create[$matches[1][$key]] = $matches[2][$key];
}
}
}
}
// Find out which columns need converting and build SQL statements
$query = $db->query("SHOW FULL COLUMNS FROM {$mybb->input['table']}");
while($column = $db->fetch_array($query))
{
list($type) = explode('(', $column['Type']);
if(array_key_exists($type, $types))
{
// Build the actual strings for converting the columns
$names = "CHANGE `{$column['Field']}` `{$column['Field']}` ";
if(($db->type == 'mysql' || $db->type == 'mysqli') && in_array($type, $blob_types))
{
if($column['Null'] == 'YES')
{
$attributes = 'NULL';
}
else
{
$attributes = 'NOT NULL';
}
}
else
{
$attributes = " DEFAULT ";
if($column['Default'] == 'NULL')
{
$attributes .= "NULL ";
}
else
{
$attributes .= "'".$db->escape_string($column['Default'])."' ";
if($column['Null'] == 'YES')
{
$attributes .= 'NULL';
}
else
{
$attributes .= 'NOT NULL';
}
}
}
$convert_to_binary .= $comma.$names.preg_replace('/'.$type.'/i', $types[$type], $column['Type']).' '.$attributes;
$convert_to_utf8 .= "{$comma}{$names}{$column['Type']} CHARACTER SET {$character_set} COLLATE {$collation} {$attributes}";
$comma = ',';
}
}
if(!empty($convert_to_binary))
{
// This converts the columns to UTF-8 while also doing the same for data
$db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_binary}");
$db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_utf8}");
}
// Any fulltext indexes to recreate?
if(is_array($fulltext_to_create))
{
foreach($fulltext_to_create as $name => $fields)
{
$db->create_fulltext_index($mybb->input['table'], $fields, $name);
}
}
$db->set_table_prefix($old_table_prefix);
$plugins->run_hooks("admin_tools_system_health_utf8_conversion_commit");
// Log admin action
log_admin_action($mybb->input['table']);
flash_message($lang->sprintf($lang->success_table_converted, $mybb->input['table']), 'success');
if($mybb->input['do'] == "all")
{
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
$tables = $db->list_tables($mybb->config['database']['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4') && $mybb->input['table'] != $tablename)
{
continue;
}
elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8' && $mybb->input['table'] != $tablename)
{
continue;
}
$mybb_tables[$key] = $tablename;
}
}
asort($mybb_tables);
reset($mybb_tables);
$is_next = false;
$nexttable = "";
foreach($mybb_tables as $key => $tablename)
{
if($is_next == true)
{
$nexttable = $tablename;
break;
}
else if($mybb->input['table'] == $tablename)
{
$is_next = true;
}
}
$db->set_table_prefix($old_table_prefix);
if($nexttable)
{
$nexttable = $db->escape_string($nexttable);
$mb4 = '';
if(!empty($mybb->input['mb4']))
{
$mb4 = "&amp;mb4=1";
}
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion&do=all&table={$nexttable}{$mb4}");
exit;
}
}
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
exit;
}
if($mybb->input['table'] || $mybb->input['do'] == "all")
{
if(!empty($mybb->input['mb4']) && version_compare($db->get_version(), '5.5.3', '<'))
{
flash_message($lang->error_utf8mb4_version, 'error');
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
}
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
if($mybb->input['do'] != "all" && !$db->table_exists($db->escape_string($mybb->input['table'])))
{
$db->set_table_prefix($old_table_prefix);
flash_message($lang->error_invalid_table, 'error');
admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
}
if($mybb->input['do'] == "all")
{
$tables = $db->list_tables($mybb->config['database']['database']);
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4'))
{
continue;
}
elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8')
{
continue;
}
$mybb_tables[$key] = $tablename;
}
}
if(is_array($mybb_tables))
{
asort($mybb_tables);
reset($mybb_tables);
$nexttable = current($mybb_tables);
$table = $db->show_create_table($db->escape_string($nexttable));
$mybb->input['table'] = $nexttable;
}
else
{
$db->set_table_prefix($old_table_prefix);
flash_message($lang->success_all_tables_already_converted, 'success');
admin_redirect("index.php?module=tools-system_health");
}
}
else
{
$table = $db->show_create_table($db->escape_string($mybb->input['table']));
}
$page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&amp;action=utf8_conversion");
$db->set_table_prefix($old_table_prefix);
$page->output_header($lang->system_health." - ".$lang->utf8_conversion);
$sub_tabs['system_health'] = array(
'title' => $lang->system_health,
'link' => "index.php?module=tools-system_health",
'description' => $lang->system_health_desc
);
$sub_tabs['utf8_conversion'] = array(
'title' => $lang->utf8_conversion,
'link' => "index.php?module=tools-system_health&amp;action=utf8_conversion",
'description' => $lang->utf8_conversion_desc2
);
$page->output_nav_tabs($sub_tabs, 'utf8_conversion');
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
$charset = $matches[1];
$mb4 = '';
if(!empty($mybb->input['mb4']))
{
$mb4 = "&amp;mb4=1";
}
$form = new Form("index.php?module=tools-system_health&amp;action=utf8_conversion{$mb4}", "post", "utf8_conversion");
echo $form->generate_hidden_field("table", $mybb->input['table']);
if($mybb->input['do'] == "all")
{
echo $form->generate_hidden_field("do", "all");
}
$table = new Table;
if(!empty($mybb->input['mb4']))
{
$table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf8mb4, $charset)."</strong>");
$lang->notice_process_long_time .= "<br /><br /><strong>{$lang->notice_mb4_warning}</strong>";
}
else
{
if($mybb->input['do'] == "all")
{
$table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf, $charset)."</strong>");
}
else
{
$table->construct_cell("<strong>".$lang->sprintf($lang->convert_to_utf8, $mybb->input['table'], $charset)."</strong>");
}
}
$table->construct_row();
$table->construct_cell($lang->notice_process_long_time);
$table->construct_row();
if($mybb->input['do'] == "all")
{
$table->output($lang->convert_tables);
$buttons[] = $form->generate_submit_button($lang->convert_database_tables);
}
else
{
$table->output($lang->convert_table.": {$mybb->input['table']}");
$buttons[] = $form->generate_submit_button($lang->convert_database_table);
}
$form->output_submit_wrapper($buttons);
$form->end();
$db->set_table_prefix($old_table_prefix);
$page->output_footer();
exit;
}
if(!$mybb->config['database']['encoding'])
{
flash_message($lang->error_db_encoding_not_set, 'error');
admin_redirect("index.php?module=tools-system_health");
}
$tables = $db->list_tables($mybb->config['database']['database']);
$old_table_prefix = $db->table_prefix;
$db->set_table_prefix('');
$encodings = array();
foreach($tables as $key => $tablename)
{
if(substr($tablename, 0, strlen($old_table_prefix)) == $old_table_prefix)
{
$table = $db->show_create_table($tablename);
preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
$encodings[$key] = fetch_iconv_encoding($matches[1]);
$mybb_tables[$key] = $tablename;
}
}
$db->set_table_prefix($old_table_prefix);
$page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&amp;action=utf8_conversion");
$page->output_header($lang->system_health." - ".$lang->utf8_conversion);
$page->output_nav_tabs($sub_tabs, 'utf8_conversion');
asort($mybb_tables);
$unique = array_unique($encodings);
$convert_utf8 = $convert_utf8mb4 = false;
foreach($unique as $encoding)
{
if($encoding == 'utf-8')
{
$convert_utf8mb4 = true;
}
elseif($encoding != 'utf8mb4')
{
$convert_utf8 = true;
}
}
if(count($unique) > 1)
{
$page->output_error("<p><em>{$lang->warning_multiple_encodings}</em></p>");
}
if(in_array('utf8mb4', $unique) && $mybb->config['database']['encoding'] != 'utf8mb4')
{
$page->output_error("<p><em>{$lang->warning_utf8mb4_config}</em></p>");
}
$table = new Table;
$table->construct_header($lang->table);
$table->construct_header($lang->status_utf8, array("class" => "align_center"));
$table->construct_header($lang->status_utf8mb4, array("class" => "align_center"));
$all_utf8 = $all_utf8mb4 = '-';
if($convert_utf8)
{
$all_utf8 = "<strong><a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;do=all\">{$lang->convert_all}</a></strong>";
}
if($convert_utf8mb4)
{
$all_utf8mb4 = "<strong><a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;do=all&amp;mb4=1\">{$lang->convert_all}</a></strong>";
}
$table->construct_cell("<strong>{$lang->all_tables}</strong>");
$table->construct_cell($all_utf8, array("class" => "align_center", 'width' => '15%'));
$table->construct_cell($all_utf8mb4, array("class" => "align_center", 'width' => '25%'));
$table->construct_row();
$db_version = $db->get_version();
foreach($mybb_tables as $key => $tablename)
{
if($encodings[$key] != 'utf-8' && $encodings[$key] != 'utf8mb4')
{
$status = "<a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;table={$tablename}\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>";
}
else
{
$status = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />";
}
if(version_compare($db_version, '5.5.3', '<'))
{
$utf8mb4 = $lang->not_available;
}
elseif($encodings[$key] == 'utf8mb4')
{
$utf8mb4 = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />";
}
elseif($encodings[$key] == 'utf-8')
{
$utf8mb4 = "<a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;table={$tablename}&amp;mb4=1\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>";
}
else
{
$utf8mb4 = "-";
}
$table->construct_cell("<strong>{$tablename}</strong>");
$table->construct_cell($status, array("class" => "align_center", 'width' => '15%'));
$table->construct_cell($utf8mb4, array("class" => "align_center", 'width' => '25%'));
$table->construct_row();
}
$table->output("<div>{$lang->utf8_conversion}</div>");
$page->output_footer();
}
if(!$mybb->input['action'])
{
$page->output_header($lang->system_health);
$plugins->run_hooks("admin_tools_system_health_start");
$page->output_nav_tabs($sub_tabs, 'system_health');
$table = new Table;
$table->construct_header($lang->totals, array("colspan" => 2));
$table->construct_header($lang->attachments, array("colspan" => 2));
$query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused, SUM(downloads*filesize) as bandwidthused", "visible='1' AND pid > '0'");
$attachs = $db->fetch_array($query);
$table->construct_cell("<strong>{$lang->total_database_size}</strong>", array('width' => '25%'));
$table->construct_cell(get_friendly_size($db->fetch_size()), array('width' => '25%'));
$table->construct_cell("<strong>{$lang->attachment_space_used}</strong>", array('width' => '200'));
$table->construct_cell(get_friendly_size((int)$attachs['spaceused']), array('width' => '200'));
$table->construct_row();
if($attachs['spaceused'] > 0)
{
$attach_average_size = round($attachs['spaceused']/$attachs['numattachs']);
$bandwidth_average_usage = round($attachs['bandwidthused']);
}
else
{
$attach_average_size = 0;
$bandwidth_average_usage = 0;
}
$table->construct_cell("<strong>{$lang->total_cache_size}</strong>", array('width' => '25%'));
$table->construct_cell(get_friendly_size($cache->size_of()), array('width' => '25%'));
$table->construct_cell("<strong>{$lang->estimated_attachment_bandwidth_usage}</strong>", array('width' => '25%'));
$table->construct_cell(get_friendly_size($bandwidth_average_usage), array('width' => '25%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->max_upload_post_size}</strong>", array('width' => '200'));
$table->construct_cell(@ini_get('upload_max_filesize').' / '.@ini_get('post_max_size'), array('width' => '200'));
$table->construct_cell("<strong>{$lang->average_attachment_size}</strong>", array('width' => '25%'));
$table->construct_cell(get_friendly_size($attach_average_size), array('width' => '25%'));
$table->construct_row();
$table->output($lang->stats);
$table->construct_header($lang->task);
$table->construct_header($lang->run_time, array("width" => 200, "class" => "align_center"));
$task_cache = $cache->read("tasks");
$nextrun = $task_cache['nextrun'];
$query = $db->simple_select("tasks", "*", "nextrun >= '{$nextrun}' AND enabled='1'", array("order_by" => "nextrun", "order_dir" => "asc", 'limit' => 3));
while($task = $db->fetch_array($query))
{
$task['title'] = htmlspecialchars_uni($task['title']);
$next_run = my_date('normal', $task['nextrun'], "", 2);
$table->construct_cell("<strong>{$task['title']}</strong>");
$table->construct_cell($next_run, array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_tasks, array('colspan' => 2));
$table->construct_row();
}
$table->output($lang->next_3_tasks);
if(isset($mybb->admin['permissions']['tools']['backupdb']) && $mybb->admin['permissions']['tools']['backupdb'] == 1)
{
$backups = array();
$dir = MYBB_ADMIN_DIR.'backups/';
$handle = opendir($dir);
while(($file = readdir($handle)) !== false)
{
if(filetype(MYBB_ADMIN_DIR.'backups/'.$file) == 'file')
{
$ext = get_extension($file);
if($ext == 'gz' || $ext == 'sql')
{
$backups[@filemtime(MYBB_ADMIN_DIR.'backups/'.$file)] = array(
"file" => $file,
"time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file),
"type" => $ext
);
}
}
}
$count = count($backups);
krsort($backups);
$table = new Table;
$table->construct_header($lang->name);
$table->construct_header($lang->backup_time, array("width" => 200, "class" => "align_center"));
$backupscnt = 0;
foreach($backups as $backup)
{
++$backupscnt;
if($backupscnt == 4)
{
break;
}
$time = "-";
if($backup['time'])
{
$time = my_date('relative', $backup['time']);
}
$table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=dlbackup&amp;file={$backup['file']}\">{$backup['file']}</a>");
$table->construct_cell($time, array("class" => "align_center"));
$table->construct_row();
}
if($count == 0)
{
$table->construct_cell($lang->no_backups, array('colspan' => 2));
$table->construct_row();
}
$table->output($lang->existing_db_backups);
}
if(is_writable(MYBB_ROOT.'inc/settings.php'))
{
$message_settings = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_settings = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if(is_writable(MYBB_ROOT.'inc/config.php'))
{
$message_config = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_config = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
$uploadspath = $mybb->settings['uploadspath'];
if(my_substr($uploadspath, 0, 1) == '.')
{
$uploadspath = MYBB_ROOT . $mybb->settings['uploadspath'];
}
if(is_writable($uploadspath))
{
$message_upload = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_upload = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
$avataruploadpath = $mybb->settings['avataruploadpath'];
if(my_substr($avataruploadpath, 0, 1) == '.')
{
$avataruploadpath = MYBB_ROOT . $mybb->settings['avataruploadpath'];
}
if(is_writable($avataruploadpath))
{
$message_avatar = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_avatar = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if(is_writable(MYBB_ROOT.'inc/languages/'))
{
$message_language = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_language = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if(is_writable(MYBB_ROOT.$config['admin_dir'].'/backups/'))
{
$message_backup = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_backup = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if(is_writable(MYBB_ROOT.'/cache/'))
{
$message_cache = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_cache = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if(is_writable(MYBB_ROOT.'/cache/themes/'))
{
$message_themes = "<span style=\"color: green;\">{$lang->writable}</span>";
}
else
{
$message_themes = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
++$errors;
}
if($errors)
{
$page->output_error("<p><em>{$errors} {$lang->error_chmod}</span></strong> {$lang->chmod_info} <a href=\"https://docs.mybb.com/1.8/administration/security/file-permissions\" target=\"_blank\" rel=\"noopener\">MyBB Docs</a>.</em></p>");
}
else
{
$page->output_success("<p><em>{$lang->success_chmod}</em></p>");
}
$table = new Table;
$table->construct_header($lang->file);
$table->construct_header($lang->location, array("colspan" => 2, 'width' => 250));
$table->construct_cell("<strong>{$lang->config_file}</strong>");
$table->construct_cell("./inc/config.php");
$table->construct_cell($message_config);
$table->construct_row();
$table->construct_cell("<strong>{$lang->settings_file}</strong>");
$table->construct_cell("./inc/settings.php");
$table->construct_cell($message_settings);
$table->construct_row();
$table->construct_cell("<strong>{$lang->file_upload_dir}</strong>");
$table->construct_cell($mybb->settings['uploadspath']);
$table->construct_cell($message_upload);
$table->construct_row();
$table->construct_cell("<strong>{$lang->avatar_upload_dir}</strong>");
$table->construct_cell($mybb->settings['avataruploadpath']);
$table->construct_cell($message_avatar);
$table->construct_row();
$table->construct_cell("<strong>{$lang->language_files}</strong>");
$table->construct_cell("./inc/languages");
$table->construct_cell($message_language);
$table->construct_row();
$table->construct_cell("<strong>{$lang->backup_dir}</strong>");
$table->construct_cell('./'.$config['admin_dir'].'/backups');
$table->construct_cell($message_backup);
$table->construct_row();
$table->construct_cell("<strong>{$lang->cache_dir}</strong>");
$table->construct_cell('./cache');
$table->construct_cell($message_cache);
$table->construct_row();
$table->construct_cell("<strong>{$lang->themes_dir}</strong>");
$table->construct_cell('./cache/themes');
$table->construct_cell($message_themes);
$table->construct_row();
$plugins->run_hooks("admin_tools_system_health_output_chmod_list");
$table->output($lang->chmod_files_and_dirs);
$page->output_footer();
}

View File

@@ -0,0 +1,776 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
require_once MYBB_ROOT."/inc/functions_task.php";
$page->add_breadcrumb_item($lang->task_manager, "index.php?module=tools-tasks");
$plugins->run_hooks("admin_tools_tasks_begin");
/**
* Validates a string or array of values
*
* @param string|array $value Comma-separated list or array of values
* @param int $min Minimum value
* @param int $max Maximum value
* @param string $return_type Set "string" to return in a comma-separated list, or "array" to return in an array
* @return string|array String or array of valid values OR false if string/array is invalid
*/
function check_time_values($value, $min, $max, $return_type)
{
// If the values aren't in an array form, make them into an array
if(!is_array($value))
{
// Empty value == *
if($value === '')
{
return ($return_type == 'string') ? '*' : array('*');
}
$implode = 1;
$value = explode(',', $value);
}
// If * is in the array, always return with * because it overrides all
if(in_array('*', $value))
{
return ($return_type == 'string') ? '*' : array('*');
}
// Validate each value in array
foreach($value as $time)
{
if($time < $min || $time > $max)
{
return false;
}
}
// Return based on return type
if($return_type == 'string')
{
$value = implode(',', $value);
}
return $value;
}
if($mybb->input['action'] == "add")
{
$plugins->run_hooks("admin_tools_tasks_add");
if($mybb->request_method == "post")
{
if(!trim($mybb->input['title']))
{
$errors[] = $lang->error_missing_title;
}
if(!trim($mybb->input['description']))
{
$errors[] = $lang->error_missing_description;
}
$file = $mybb->get_input('file');
$file = basename($file, '.php');
if(!file_exists(MYBB_ROOT."inc/tasks/".$file.".php"))
{
$errors[] = $lang->error_invalid_task_file;
}
$mybb->input['minute'] = check_time_values($mybb->input['minute'], 0, 59, 'string');
if($mybb->input['minute'] === false)
{
$errors[] = $lang->error_invalid_minute;
}
$mybb->input['hour'] = check_time_values($mybb->input['hour'], 0, 59, 'string');
if($mybb->input['hour'] === false)
{
$errors[] = $lang->error_invalid_hour;
}
if($mybb->input['day'] != "*" && $mybb->input['day'] != '')
{
$mybb->input['day'] = check_time_values($mybb->input['day'], 1, 31, 'string');
if($mybb->input['day'] === false)
{
$errors[] = $lang->error_invalid_day;
}
$mybb->input['weekday'] = array('*');
}
else
{
$mybb->input['weekday'] = check_time_values($mybb->input['weekday'], 0, 6, 'array');
if($mybb->input['weekday'] === false)
{
$errors[] = $lang->error_invalid_weekday;
}
$mybb->input['day'] = '*';
}
$mybb->input['month'] = check_time_values($mybb->input['month'], 1, 12, 'array');
if($mybb->input['month'] === false)
{
$errors[] = $lang->error_invalid_month;
}
if(!$errors)
{
$new_task = array(
"title" => $db->escape_string($mybb->input['title']),
"description" => $db->escape_string($mybb->input['description']),
"file" => $db->escape_string($file),
"minute" => $db->escape_string($mybb->input['minute']),
"hour" => $db->escape_string($mybb->input['hour']),
"day" => $db->escape_string($mybb->input['day']),
"month" => $db->escape_string(implode(',', $mybb->input['month'])),
"weekday" => $db->escape_string(implode(',', $mybb->input['weekday'])),
"enabled" => $mybb->get_input('enabled', MyBB::INPUT_INT),
"logging" => $mybb->get_input('logging', MyBB::INPUT_INT)
);
$new_task['nextrun'] = fetch_next_run($new_task);
$tid = $db->insert_query("tasks", $new_task);
$plugins->run_hooks("admin_tools_tasks_add_commit");
$cache->update_tasks();
// Log admin action
log_admin_action($tid, $mybb->input['title']);
flash_message($lang->success_task_created, 'success');
admin_redirect("index.php?module=tools-tasks");
}
}
$page->add_breadcrumb_item($lang->add_new_task);
$page->output_header($lang->scheduled_tasks." - ".$lang->add_new_task);
$sub_tabs['scheduled_tasks'] = array(
'title' => $lang->scheduled_tasks,
'link' => "index.php?module=tools-tasks"
);
$sub_tabs['add_task'] = array(
'title' => $lang->add_new_task,
'link' => "index.php?module=tools-tasks&amp;action=add",
'description' => $lang->add_new_task_desc
);
$sub_tabs['task_logs'] = array(
'title' => $lang->view_task_logs,
'link' => "index.php?module=tools-tasks&amp;action=logs"
);
$page->output_nav_tabs($sub_tabs, 'add_task');
$form = new Form("index.php?module=tools-tasks&amp;action=add", "post", "add");
if($errors)
{
$page->output_inline_error($errors);
}
else
{
$mybb->input['minute'] = '*';
$mybb->input['hour'] = '*';
$mybb->input['day'] = '*';
$mybb->input['weekday'] = '*';
$mybb->input['month'] = '*';
}
$form_container = new FormContainer($lang->add_new_task);
$form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
$form_container->output_row($lang->short_description." <em>*</em>", "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
$task_list = array();
$task_files = scandir(MYBB_ROOT."inc/tasks/");
foreach($task_files as $task_file)
{
if(is_file(MYBB_ROOT."inc/tasks/{$task_file}") && get_extension($task_file) == "php")
{
$file_id = preg_replace("#\.".get_extension($task_file)."$#i", "$1", $task_file);
$task_list[$file_id] = $task_file;
}
}
$form_container->output_row($lang->task_file." <em>*</em>", $lang->task_file_desc, $form->generate_select_box("file", $task_list, $mybb->input['file'], array('id' => 'file')), 'file');
$form_container->output_row($lang->time_minutes, $lang->time_minutes_desc, $form->generate_text_box('minute', $mybb->input['minute'], array('id' => 'minute')), 'minute');
$form_container->output_row($lang->time_hours, $lang->time_hours_desc, $form->generate_text_box('hour', $mybb->input['hour'], array('id' => 'hour')), 'hour');
$form_container->output_row($lang->time_days_of_month, $lang->time_days_of_month_desc, $form->generate_text_box('day', $mybb->input['day'], array('id' => 'day')), 'day');
$options = array(
"*" => $lang->every_weekday,
"0" => $lang->sunday,
"1" => $lang->monday,
"2" => $lang->tuesday,
"3" => $lang->wednesday,
"4" => $lang->thursday,
"5" => $lang->friday,
"6" => $lang->saturday
);
$form_container->output_row($lang->time_weekdays, $lang->time_weekdays_desc, $form->generate_select_box('weekday[]', $options, $mybb->input['weekday'], array('id' => 'weekday', 'multiple' => true, 'size' => 8)), 'weekday');
$options = array(
"*" => $lang->every_month,
"1" => $lang->january,
"2" => $lang->february,
"3" => $lang->march,
"4" => $lang->april,
"5" => $lang->may,
"6" => $lang->june,
"7" => $lang->july,
"8" => $lang->august,
"9" => $lang->september,
"10" => $lang->october,
"11" => $lang->november,
"12" => $lang->december
);
$form_container->output_row($lang->time_months, $lang->time_months_desc, $form->generate_select_box('month[]', $options, $mybb->input['month'], array('id' => 'month', 'multiple' => true, 'size' => 13)), 'month');
$form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $mybb->input['logging'], true));
$form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $mybb->input['enabled'], true));
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->save_task);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if($mybb->input['action'] == "edit")
{
$query = $db->simple_select("tasks", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
$task = $db->fetch_array($query);
// Does the task not exist?
if(!$task['tid'])
{
flash_message($lang->error_invalid_task, 'error');
admin_redirect("index.php?module=tools-tasks");
}
$plugins->run_hooks("admin_tools_tasks_edit");
if($mybb->request_method == "post")
{
if(!trim($mybb->input['title']))
{
$errors[] = $lang->error_missing_title;
}
if(!trim($mybb->input['description']))
{
$errors[] = $lang->error_missing_description;
}
$file = $mybb->get_input('file');
$file = basename($file, '.php');
if(!file_exists(MYBB_ROOT."inc/tasks/".$file.".php"))
{
$errors[] = $lang->error_invalid_task_file;
}
$mybb->input['minute'] = check_time_values($mybb->input['minute'], 0, 59, 'string');
if($mybb->input['minute'] === false)
{
$errors[] = $lang->error_invalid_minute;
}
$mybb->input['hour'] = check_time_values($mybb->input['hour'], 0, 59, 'string');
if($mybb->input['hour'] === false)
{
$errors[] = $lang->error_invalid_hour;
}
if($mybb->input['day'] != "*" && $mybb->input['day'] != '')
{
$mybb->input['day'] = check_time_values($mybb->input['day'], 1, 31, 'string');
if($mybb->input['day'] === false)
{
$errors[] = $lang->error_invalid_day;
}
$mybb->input['weekday'] = array('*');
}
else
{
$mybb->input['weekday'] = check_time_values($mybb->input['weekday'], 0, 6, 'array');
if($mybb->input['weekday'] === false)
{
$errors[] = $lang->error_invalid_weekday;
}
$mybb->input['day'] = '*';
}
$mybb->input['month'] = check_time_values($mybb->input['month'], 1, 12, 'array');
if($mybb->input['month'] === false)
{
$errors[] = $lang->error_invalid_month;
}
if(!$errors)
{
$enable_confirmation = false;
// Check if we need to ask the user to confirm turning on the task
if(($task['file'] == "backupdb" || $task['file'] == "checktables") && $task['enabled'] == 0 && $mybb->input['enabled'] == 1)
{
$mybb->input['enabled'] = 0;
$enable_confirmation = true;
}
$updated_task = array(
"title" => $db->escape_string($mybb->input['title']),
"description" => $db->escape_string($mybb->input['description']),
"file" => $db->escape_string($file),
"minute" => $db->escape_string($mybb->input['minute']),
"hour" => $db->escape_string($mybb->input['hour']),
"day" => $db->escape_string($mybb->input['day']),
"month" => $db->escape_string(implode(',', $mybb->input['month'])),
"weekday" => $db->escape_string(implode(',', $mybb->input['weekday'])),
"enabled" => $mybb->get_input('enabled', MyBB::INPUT_INT),
"logging" => $mybb->get_input('logging', MyBB::INPUT_INT)
);
$updated_task['nextrun'] = fetch_next_run($updated_task);
$plugins->run_hooks("admin_tools_tasks_edit_commit");
$db->update_query("tasks", $updated_task, "tid='{$task['tid']}'");
$cache->update_tasks();
// Log admin action
log_admin_action($task['tid'], $mybb->input['title']);
flash_message($lang->success_task_updated, 'success');
if($enable_confirmation == true)
{
admin_redirect("index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
}
else
{
admin_redirect("index.php?module=tools-tasks");
}
}
}
$page->add_breadcrumb_item($lang->edit_task);
$page->output_header($lang->scheduled_tasks." - ".$lang->edit_task);
$sub_tabs['edit_task'] = array(
'title' => $lang->edit_task,
'description' => $lang->edit_task_desc,
'link' => "index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}"
);
$page->output_nav_tabs($sub_tabs, 'edit_task');
$form = new Form("index.php?module=tools-tasks&amp;action=edit", "post");
if($errors)
{
$page->output_inline_error($errors);
$task_data = $mybb->input;
}
else
{
$task_data = $task;
$task_data['weekday'] = explode(',', $task['weekday']);
$task_data['month'] = explode(',', $task['month']);
}
$form_container = new FormContainer($lang->edit_task);
echo $form->generate_hidden_field("tid", $task['tid']);
$form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $task_data['title'], array('id' => 'title')), 'title');
$form_container->output_row($lang->short_description." <em>*</em>", "", $form->generate_text_box('description', $task_data['description'], array('id' => 'description')), 'description');
$task_list = array();
$task_files = scandir(MYBB_ROOT."inc/tasks/");
foreach($task_files as $task_file)
{
if(is_file(MYBB_ROOT."inc/tasks/{$task_file}") && get_extension($task_file) == "php")
{
$file_id = preg_replace("#\.".get_extension($task_file)."$#i", "$1", $task_file);
$task_list[$file_id] = $task_file;
}
}
$form_container->output_row($lang->task." <em>*</em>", $lang->task_file_desc, $form->generate_select_box("file", $task_list, $task_data['file'], array('id' => 'file')), 'file');
$form_container->output_row($lang->time_minutes, $lang->time_minutes_desc, $form->generate_text_box('minute', $task_data['minute'], array('id' => 'minute')), 'minute');
$form_container->output_row($lang->time_hours, $lang->time_hours_desc, $form->generate_text_box('hour', $task_data['hour'], array('id' => 'hour')), 'hour');
$form_container->output_row($lang->time_days_of_month, $lang->time_days_of_month_desc, $form->generate_text_box('day', $task_data['day'], array('id' => 'day')), 'day');
$options = array(
"*" => $lang->every_weekday,
"0" => $lang->sunday,
"1" => $lang->monday,
"2" => $lang->tuesday,
"3" => $lang->wednesday,
"4" => $lang->thursday,
"5" => $lang->friday,
"6" => $lang->saturday
);
$form_container->output_row($lang->time_weekdays, $lang->time_weekdays_desc, $form->generate_select_box('weekday[]', $options, $task_data['weekday'], array('id' => 'weekday', 'multiple' => true)), 'weekday');
$options = array(
"*" => $lang->every_month,
"1" => $lang->january,
"2" => $lang->february,
"3" => $lang->march,
"4" => $lang->april,
"5" => $lang->may,
"6" => $lang->june,
"7" => $lang->july,
"8" => $lang->august,
"9" => $lang->september,
"10" => $lang->october,
"11" => $lang->november,
"12" => $lang->december
);
$form_container->output_row($lang->time_months, $lang->time_months_desc, $form->generate_select_box('month[]', $options, $task_data['month'], array('id' => 'month', 'multiple' => true)), 'month');
$form_container->output_row($lang->enable_logging." <em>*</em>", "", $form->generate_yes_no_radio("logging", $task_data['logging'], true));
$form_container->output_row($lang->enabled." <em>*</em>", "", $form->generate_yes_no_radio("enabled", $task_data['enabled'], true));
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->save_task);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}
if($mybb->input['action'] == "delete")
{
$query = $db->simple_select("tasks", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
$task = $db->fetch_array($query);
// Does the task not exist?
if(!$task['tid'])
{
flash_message($lang->error_invalid_task, 'error');
admin_redirect("index.php?module=tools-tasks");
}
// User clicked no
if($mybb->input['no'])
{
admin_redirect("index.php?module=tools-tasks");
}
$plugins->run_hooks("admin_tools_tasks_delete");
if($mybb->request_method == "post")
{
// Delete the task & any associated task log entries
$db->delete_query("tasks", "tid='{$task['tid']}'");
$db->delete_query("tasklog", "tid='{$task['tid']}'");
// Fetch next task run
$plugins->run_hooks("admin_tools_tasks_delete_commit");
$cache->update_tasks();
// Log admin action
log_admin_action($task['tid'], $task['title']);
flash_message($lang->success_task_deleted, 'success');
admin_redirect("index.php?module=tools-tasks");
}
else
{
$page->output_confirm_action("index.php?module=tools-tasks&amp;action=delete&amp;tid={$task['tid']}", $lang->confirm_task_deletion);
}
}
if($mybb->input['action'] == "enable" || $mybb->input['action'] == "disable")
{
if(!verify_post_check($mybb->input['my_post_key']))
{
flash_message($lang->invalid_post_verify_key2, 'error');
admin_redirect("index.php?module=tools-tasks");
}
$query = $db->simple_select("tasks", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
$task = $db->fetch_array($query);
// Does the task not exist?
if(!$task['tid'])
{
flash_message($lang->error_invalid_task, 'error');
admin_redirect("index.php?module=tools-tasks");
}
if($mybb->input['action'] == "enable")
{
$plugins->run_hooks("admin_tools_tasks_enable");
}
else
{
$plugins->run_hooks("admin_tools_tasks_disable");
}
if($mybb->input['action'] == "enable")
{
if($task['file'] == "backupdb" || $task['file'] == "checktables")
{
// User clicked no
if($mybb->input['no'])
{
admin_redirect("index.php?module=tools-tasks");
}
if($mybb->request_method == "post")
{
$nextrun = fetch_next_run($task);
$db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'");
$plugins->run_hooks("admin_tools_tasks_enable_commit");
$cache->update_tasks();
// Log admin action
log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
flash_message($lang->success_task_enabled, 'success');
admin_redirect("index.php?module=tools-tasks");
}
else
{
$page->output_confirm_action("index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}", $lang->confirm_task_enable);
}
}
else
{
$nextrun = fetch_next_run($task);
$db->update_query("tasks", array("nextrun" => $nextrun, "enabled" => 1), "tid='{$task['tid']}'");
$plugins->run_hooks("admin_tools_tasks_enable_commit");
$cache->update_tasks();
// Log admin action
log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
flash_message($lang->success_task_enabled, 'success');
admin_redirect("index.php?module=tools-tasks");
}
}
else
{
$db->update_query("tasks", array("enabled" => 0), "tid='{$task['tid']}'");
$plugins->run_hooks("admin_tools_tasks_disable_commit");
$cache->update_tasks();
// Log admin action
log_admin_action($task['tid'], $task['title'], $mybb->input['action']);
flash_message($lang->success_task_disabled, 'success');
admin_redirect("index.php?module=tools-tasks");
}
}
if($mybb->input['action'] == "run")
{
if(!verify_post_check($mybb->input['my_post_key']))
{
flash_message($lang->invalid_post_verify_key2, 'error');
admin_redirect("index.php?module=tools-tasks");
}
ignore_user_abort(true);
@set_time_limit(0);
$plugins->run_hooks("admin_tools_tasks_run");
$query = $db->simple_select("tasks", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
$task = $db->fetch_array($query);
// Does the task not exist?
if(!$task['tid'])
{
flash_message($lang->error_invalid_task, 'error');
admin_redirect("index.php?module=tools-tasks");
}
run_task($task['tid']);
$plugins->run_hooks("admin_tools_tasks_run_commit");
// Log admin action
log_admin_action($task['tid'], $task['title']);
flash_message($lang->success_task_run, 'success');
admin_redirect("index.php?module=tools-tasks");
}
if($mybb->input['action'] == "logs")
{
$plugins->run_hooks("admin_tools_tasks_logs");
$page->output_header($lang->task_logs);
$sub_tabs['scheduled_tasks'] = array(
'title' => $lang->scheduled_tasks,
'link' => "index.php?module=tools-tasks"
);
$sub_tabs['add_task'] = array(
'title' => $lang->add_new_task,
'link' => "index.php?module=tools-tasks&amp;action=add"
);
$sub_tabs['task_logs'] = array(
'title' => $lang->view_task_logs,
'link' => "index.php?module=tools-tasks&amp;action=logs",
'description' => $lang->view_task_logs_desc
);
$page->output_nav_tabs($sub_tabs, 'task_logs');
$table = new Table;
$table->construct_header($lang->task);
$table->construct_header($lang->date, array("class" => "align_center", "width" => 200));
$table->construct_header($lang->data, array("width" => "60%"));
$query = $db->simple_select("tasklog", "COUNT(*) AS log_count");
$log_count = $db->fetch_field($query, "log_count");
$start = 0;
$per_page = 50;
$current_page = 1;
if($mybb->input['page'] > 0)
{
$current_page = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($current_page-1)*$per_page;
$pages = $log_count / $per_page;
$pages = ceil($pages);
if($current_page > $pages)
{
$start = 0;
$current_page = 1;
}
}
$pagination = draw_admin_pagination($current_page, $per_page, $log_count, "index.php?module=tools-tasks&amp;action=logs&amp;page={page}");
$query = $db->query("
SELECT l.*, t.title
FROM ".TABLE_PREFIX."tasklog l
LEFT JOIN ".TABLE_PREFIX."tasks t ON (t.tid=l.tid)
ORDER BY l.dateline DESC
LIMIT {$start}, {$per_page}
");
while($log_entry = $db->fetch_array($query))
{
$log_entry['title'] = htmlspecialchars_uni($log_entry['title']);
$log_entry['data'] = htmlspecialchars_uni($log_entry['data']);
$date = my_date('relative', $log_entry['dateline']);
$table->construct_cell("<a href=\"index.php?module=tools-tasks&amp;action=edit&amp;tid={$log_entry['tid']}\">{$log_entry['title']}</a>");
$table->construct_cell($date, array("class" => "align_center"));
$table->construct_cell($log_entry['data']);
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_task_logs, array("colspan" => "3"));
$table->construct_row();
}
$table->output($lang->task_logs);
echo $pagination;
$page->output_footer();
}
if(!$mybb->input['action'])
{
$page->output_header($lang->task_manager);
$sub_tabs['scheduled_tasks'] = array(
'title' => $lang->scheduled_tasks,
'link' => "index.php?module=tools-tasks",
'description' => $lang->scheduled_tasks_desc
);
$sub_tabs['add_task'] = array(
'title' => $lang->add_new_task,
'link' => "index.php?module=tools-tasks&amp;action=add"
);
$sub_tabs['task_logs'] = array(
'title' => $lang->view_task_logs,
'link' => "index.php?module=tools-tasks&amp;action=logs"
);
$plugins->run_hooks("admin_tools_tasks_start");
$page->output_nav_tabs($sub_tabs, 'scheduled_tasks');
$table = new Table;
$table->construct_header($lang->task);
$table->construct_header($lang->next_run, array("class" => "align_center", "width" => 200));
$table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
$query = $db->simple_select("tasks", "*", "", array("order_by" => "title", "order_dir" => "asc"));
while($task = $db->fetch_array($query))
{
$task['title'] = htmlspecialchars_uni($task['title']);
$task['description'] = htmlspecialchars_uni($task['description']);
$next_run = my_date('normal', $task['nextrun'], "", 2);
if($task['enabled'] == 1)
{
$icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.png\" alt=\"({$lang->alt_enabled})\" title=\"{$lang->alt_enabled}\" style=\"vertical-align: middle;\" /> ";
}
else
{
$icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.png\" alt=\"({$lang->alt_disabled})\" title=\"{$lang->alt_disabled}\" style=\"vertical-align: middle;\" /> ";
}
$table->construct_cell("<div class=\"float_right\"><a href=\"index.php?module=tools-tasks&amp;action=run&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}\"><img src=\"styles/{$page->style}/images/icons/run_task.png\" title=\"{$lang->run_task_now}\" alt=\"{$lang->run_task}\" /></a></div><div>{$icon}<strong><a href=\"index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}\">{$task['title']}</a></strong><br /><small>{$task['description']}</small></div>");
$table->construct_cell($next_run, array("class" => "align_center"));
$popup = new PopupMenu("task_{$task['tid']}", $lang->options);
$popup->add_item($lang->edit_task, "index.php?module=tools-tasks&amp;action=edit&amp;tid={$task['tid']}");
if($task['enabled'] == 1)
{
$popup->add_item($lang->run_task, "index.php?module=tools-tasks&amp;action=run&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
$popup->add_item($lang->disable_task, "index.php?module=tools-tasks&amp;action=disable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
}
else
{
$popup->add_item($lang->enable_task, "index.php?module=tools-tasks&amp;action=enable&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}");
}
$popup->add_item($lang->delete_task, "index.php?module=tools-tasks&amp;action=delete&amp;tid={$task['tid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_task_deletion}')");
$table->construct_cell($popup->fetch(), array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_tasks, array('colspan' => 3));
$table->construct_row();
}
$table->output($lang->scheduled_tasks);
$page->output_footer();
}

View File

@@ -0,0 +1,486 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item($lang->warning_logs, "index.php?module=tools-warninglog");
$plugins->run_hooks("admin_tools_warninglog_begin");
// Revoke a warning
if($mybb->input['action'] == "do_revoke" && $mybb->request_method == "post")
{
$query = $db->simple_select("warnings", "*", "wid='".$mybb->get_input('wid', MyBB::INPUT_INT)."'");
$warning = $db->fetch_array($query);
if(!$warning['wid'])
{
flash_message($lang->error_invalid_warning, 'error');
admin_redirect("index.php?module=tools-warninglog");
}
else if($warning['daterevoked'])
{
flash_message($lang->error_already_revoked, 'error');
admin_redirect("index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
}
$user = get_user($warning['uid']);
$plugins->run_hooks("admin_tools_warninglog_do_revoke");
if(!trim($mybb->input['reason']))
{
$warn_errors[] = $lang->error_no_revoke_reason;
$mybb->input['action'] = "view";
}
else
{
// Warning is still active, lower users point count
if($warning['expired'] != 1)
{
$new_warning_points = $user['warningpoints']-$warning['points'];
if($new_warning_points < 0)
{
$new_warning_points = 0;
}
// Update user
$updated_user = array(
"warningpoints" => $new_warning_points
);
}
// Update warning
$updated_warning = array(
"expired" => 1,
"daterevoked" => TIME_NOW,
"revokedby" => $mybb->user['uid'],
"revokereason" => $db->escape_string($mybb->input['reason'])
);
$plugins->run_hooks("admin_tools_warninglog_do_revoke_commit");
if($warning['expired'] != 1)
{
$db->update_query("users", $updated_user, "uid='{$warning['uid']}'");
}
$db->update_query("warnings", $updated_warning, "wid='{$warning['wid']}'");
flash_message($lang->redirect_warning_revoked, 'success');
admin_redirect("index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
}
}
// Detailed view of a warning
if($mybb->input['action'] == "view")
{
$query = $db->query("
SELECT w.*, t.title AS type_title, u.username, p.subject AS post_subject
FROM ".TABLE_PREFIX."warnings w
LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=w.pid)
WHERE w.wid='".$mybb->get_input('wid', MyBB::INPUT_INT)."'
");
$warning = $db->fetch_array($query);
if(!$warning['wid'])
{
flash_message($lang->error_invalid_warning, 'error');
admin_redirect("index.php?module=tools-warninglog");
}
$user = get_user((int)$warning['uid']);
$plugins->run_hooks("admin_tools_warninglog_view");
$page->add_breadcrumb_item($lang->warning_details, "index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
$page->output_header($lang->warning_details);
$user_link = build_profile_link(htmlspecialchars_uni($user['username']), $user['uid'], "_blank");
if(is_array($warn_errors))
{
$page->output_inline_error($warn_errors);
$mybb->input['reason'] = htmlspecialchars_uni($mybb->input['reason']);
}
$table = new Table;
$post_link = "";
if($warning['post_subject'])
{
if(!is_object($parser))
{
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
}
$warning['post_subject'] = $parser->parse_badwords($warning['post_subject']);
$warning['post_subject'] = htmlspecialchars_uni($warning['post_subject']);
$post_link = get_post_link($warning['pid']);
$table->construct_cell("<strong>{$lang->warned_user}</strong><br /><br />{$user_link}");
$table->construct_cell("<strong>{$lang->post}</strong><br /><br /><a href=\"{$mybb->settings['bburl']}/{$post_link}\" target=\"_blank\">{$warning['post_subject']}</a>");
$table->construct_row();
}
else
{
$table->construct_cell("<strong>{$lang->warned_user}</strong><br /><br />{$user_link}", array('colspan' => 2));
$table->construct_row();
}
$issuedby = build_profile_link(htmlspecialchars_uni($warning['username']), $warning['issuedby'], "_blank");
$notes = nl2br(htmlspecialchars_uni($warning['notes']));
$date_issued = my_date('relative', $warning['dateline']);
if($warning['type_title'])
{
$warning_type = $warning['type_title'];
}
else
{
$warning_type = $warning['title'];
}
$warning_type = htmlspecialchars_uni($warning_type);
if($warning['points'] > 0)
{
$warning['points'] = "+{$warning['points']}";
}
$points = $lang->sprintf($lang->warning_points, $warning['points']);
if($warning['expired'] != 1)
{
if($warning['expires'] == 0)
{
$expires = $lang->never;
}
else
{
$expires = my_date('relative', $warning['expires']);
}
$status = $lang->warning_active;
}
else
{
if($warning['daterevoked'])
{
$expires = $status = $lang->warning_revoked;
}
else if($warning['expires'])
{
$expires = $status = $lang->already_expired;
}
}
$table->construct_cell("<strong>{$lang->warning}</strong><br /><br />{$warning_type} {$points}", array('width' => '50%'));
$table->construct_cell("<strong>{$lang->date_issued}</strong><br /><br />{$date_issued}", array('width' => '50%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->issued_by}</strong><br /><br />{$issuedby}", array('width' => '50%'));
$table->construct_cell("<strong>{$lang->expires}</strong><br /><br />{$expires}", array('width' => '50%'));
$table->construct_row();
$table->construct_cell("<strong>{$lang->warning_note}</strong><br /><br />{$notes}", array('colspan' => 2));
$table->construct_row();
$table->output("<div class=\"float_right\" style=\"font-weight: normal;\">{$status}</div>".$lang->warning_details);
if(!$warning['daterevoked'])
{
$form = new Form("index.php?module=tools-warninglog", "post");
$form_container = new FormContainer($lang->revoke_warning);
echo $form->generate_hidden_field('action', 'do_revoke');
echo $form->generate_hidden_field('wid', $warning['wid']);
$form_container->output_row("", $lang->revoke_warning_desc, $form->generate_text_area('reason', $mybb->input['reason'], array('id' => 'reason')), 'reason');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->revoke_warning);
$form->output_submit_wrapper($buttons);
$form->end();
}
else
{
$date_revoked = my_date('relative', $warning['daterevoked']);
$revoked_user = get_user($warning['revokedby']);
$revoked_by = build_profile_link(htmlspecialchars_uni($revoked_user['username']), $revoked_user['uid'], "_blank");
$revoke_reason = nl2br(htmlspecialchars_uni($warning['revokereason']));
$revoke_table = new Table;
$revoke_table->construct_cell("<strong>{$lang->revoked_by}</strong><br /><br />{$revoked_by}", array('width' => '50%'));
$revoke_table->construct_cell("<strong>{$lang->date_revoked}</strong><br /><br />{$date_revoked}", array('width' => '50%'));
$revoke_table->construct_row();
$revoke_table->construct_cell("<strong>{$lang->reason}</strong><br /><br />{$revoke_reason}", array('colspan' => 2));
$revoke_table->construct_row();
$revoke_table->output($lang->warning_is_revoked);
}
$page->output_footer();
}
if(!$mybb->input['action'])
{
$plugins->run_hooks("admin_tools_warninglog_start");
$page->output_header($lang->warning_logs);
$sub_tabs['warning_logs'] = array(
'title' => $lang->warning_logs,
'link' => "index.php?module=tools-warninglog",
'description' => $lang->warning_logs_desc
);
$page->output_nav_tabs($sub_tabs, 'warning_logs');
// Filter options
$where_sql = '';
if(!empty($mybb->input['filter']['username']))
{
$search_user = get_user_by_username($mybb->input['filter']['username']);
$mybb->input['filter']['uid'] = (int)$search_user['uid'];
$mybb->input['filter']['uid'] = $db->fetch_field($query, "uid");
}
if($mybb->input['filter']['uid'])
{
$search['uid'] = (int)$mybb->input['filter']['uid'];
$where_sql .= " AND w.uid='{$search['uid']}'";
if(!isset($mybb->input['search']['username']))
{
$user = get_user($mybb->input['search']['uid']);
$mybb->input['search']['username'] = $user['username'];
}
}
if(!empty($mybb->input['filter']['mod_username']))
{
$mod_user = get_user_by_username($mybb->input['filter']['mod_username']);
$mybb->input['filter']['mod_uid'] = (int)$mod_user['uid'];
}
if($mybb->input['filter']['mod_uid'])
{
$search['mod_uid'] = (int)$mybb->input['filter']['mod_uid'];
$where_sql .= " AND w.issuedby='{$search['mod_uid']}'";
if(!isset($mybb->input['search']['mod_username']))
{
$mod_user = get_user($mybb->input['search']['uid']);
$mybb->input['search']['mod_username'] = $mod_user['username'];
}
}
if($mybb->input['filter']['reason'])
{
$search['reason'] = $db->escape_string_like($mybb->input['filter']['reason']);
$where_sql .= " AND (w.notes LIKE '%{$search['reason']}%' OR t.title LIKE '%{$search['reason']}%' OR w.title LIKE '%{$search['reason']}%')";
}
$sortbysel = array();
switch($mybb->input['filter']['sortby'])
{
case "username":
$sortby = "u.username";
$sortbysel['username'] = ' selected="selected"';
break;
case "expires":
$sortby = "w.expires";
$sortbysel['expires'] = ' selected="selected"';
break;
case "issuedby":
$sortby = "i.username";
$sortbysel['issuedby'] = ' selected="selected"';
break;
default: // "dateline"
$sortby = "w.dateline";
$sortbysel['dateline'] = ' selected="selected"';
}
$order = $mybb->input['filter']['order'];
$ordersel = array();
if($order != "asc")
{
$order = "desc";
$ordersel['desc'] = ' selected="selected"';
}
else
{
$ordersel['asc'] = ' selected="selected"';
}
// Expire any warnings past their expiration date
require_once MYBB_ROOT.'inc/datahandlers/warnings.php';
$warningshandler = new WarningsHandler('update');
$warningshandler->expire_warnings();
// Pagination stuff
$sql = "
SELECT COUNT(wid) as count
FROM
".TABLE_PREFIX."warnings w
LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
WHERE 1=1
{$where_sql}
";
$query = $db->query($sql);
$total_warnings = $db->fetch_field($query, 'count');
$view_page = 1;
if(isset($mybb->input['page']) && $mybb->get_input('page', MyBB::INPUT_INT) > 0)
{
$view_page = $mybb->get_input('page', MyBB::INPUT_INT);
}
$per_page = 20;
if(isset($mybb->input['filter']['per_page']) && (int)$mybb->input['filter']['per_page'] > 0)
{
$per_page = (int)$mybb->input['filter']['per_page'];
}
$start = ($view_page-1) * $per_page;
$pages = ceil($total_warnings / $per_page);
if($view_page > $pages)
{
$start = 0;
$view_page = 1;
}
// Build the base URL for pagination links
$url = 'index.php?module=tools-warninglog';
if(is_array($mybb->input['filter']) && count($mybb->input['filter']))
{
foreach($mybb->input['filter'] as $field => $value)
{
$value = urlencode($value);
$url .= "&amp;filter[{$field}]={$value}";
}
}
// The actual query
$sql = "
SELECT
w.wid, w.title as custom_title, w.points, w.dateline, w.issuedby, w.expires, w.expired, w.daterevoked, w.revokedby,
t.title,
u.uid, u.username, u.usergroup, u.displaygroup,
i.uid as mod_uid, i.username as mod_username, i.usergroup as mod_usergroup, i.displaygroup as mod_displaygroup
FROM ".TABLE_PREFIX."warnings w
LEFT JOIN ".TABLE_PREFIX."users u on (w.uid=u.uid)
LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
LEFT JOIN ".TABLE_PREFIX."users i ON (i.uid=w.issuedby)
WHERE 1=1
{$where_sql}
ORDER BY {$sortby} {$order}
LIMIT {$start}, {$per_page}
";
$query = $db->query($sql);
$table = new Table;
$table->construct_header($lang->warned_user, array('width' => '15%'));
$table->construct_header($lang->warning, array("class" => "align_center", 'width' => '25%'));
$table->construct_header($lang->date_issued, array("class" => "align_center", 'width' => '20%'));
$table->construct_header($lang->expires, array("class" => "align_center", 'width' => '20%'));
$table->construct_header($lang->issued_by, array("class" => "align_center", 'width' => '15%'));
$table->construct_header($lang->options, array("class" => "align_center", 'width' => '5%'));
while($row = $db->fetch_array($query))
{
if(!$row['username'])
{
$row['username'] = $lang->guest;
}
$trow = alt_trow();
$username = format_name(htmlspecialchars_uni($row['username']), $row['usergroup'], $row['displaygroup']);
if(!$row['uid'])
{
$username_link = $username;
}
else
{
$username_link = build_profile_link($username, $row['uid'], "_blank");
}
$mod_username = format_name(htmlspecialchars_uni($row['mod_username']), $row['mod_usergroup'], $row['mod_displaygroup']);
$mod_username_link = build_profile_link($mod_username, $row['mod_uid'], "_blank");
$issued_date = my_date('relative', $row['dateline']);
$revoked_text = '';
if($row['daterevoked'] > 0)
{
$revoked_date = my_date('relative', $row['daterevoked']);
$revoked_text = "<br /><small><strong>{$lang->revoked}</strong> {$revoked_date}</small>";
}
if($row['expires'] > 0)
{
$expire_date = my_date('relative', $row['expires']);
}
else
{
$expire_date = $lang->never;
}
$title = $row['title'];
if(empty($row['title']))
{
$title = $row['custom_title'];
}
$title = htmlspecialchars_uni($title);
if($row['points'] > 0)
{
$points = '+'.$row['points'];
}
$table->construct_cell($username_link);
$table->construct_cell("{$title} ({$points})");
$table->construct_cell($issued_date, array("class" => "align_center"));
$table->construct_cell($expire_date.$revoked_text, array("class" => "align_center"));
$table->construct_cell($mod_username_link);
$table->construct_cell("<a href=\"index.php?module=tools-warninglog&amp;action=view&amp;wid={$row['wid']}\">{$lang->view}</a>", array("class" => "align_center"));
$table->construct_row();
}
if($table->num_rows() == 0)
{
$table->construct_cell($lang->no_warning_logs, array("colspan" => "6"));
$table->construct_row();
}
$table->output($lang->warning_logs);
// Do we need to construct the pagination?
if($total_warnings > $per_page)
{
echo draw_admin_pagination($view_page, $per_page, $total_warnings, $url)."<br />";
}
$sort_by = array(
'expires' => $lang->expiry_date,
'dateline' => $lang->issued_date,
'username' => $lang->warned_user,
'issuedby' => $lang->issued_by
);
$order_array = array(
'asc' => $lang->asc,
'desc' => $lang->desc
);
$form = new Form("index.php?module=tools-warninglog", "post");
$form_container = new FormContainer($lang->filter_warning_logs);
$form_container->output_row($lang->filter_warned_user, "", $form->generate_text_box('filter[username]', $mybb->input['filter']['username'], array('id' => 'filter_username')), 'filter_username');
$form_container->output_row($lang->filter_issued_by, "", $form->generate_text_box('filter[mod_username]', $mybb->input['filter']['mod_username'], array('id' => 'filter_mod_username')), 'filter_mod_username');
$form_container->output_row($lang->filter_reason, "", $form->generate_text_box('filter[reason]', $mybb->input['filter']['reason'], array('id' => 'filter_reason')), 'filter_reason');
$form_container->output_row($lang->sort_by, "", $form->generate_select_box('filter[sortby]', $sort_by, $mybb->input['filter']['sortby'], array('id' => 'filter_sortby'))." {$lang->in} ".$form->generate_select_box('filter[order]', $order_array, $order, array('id' => 'filter_order'))." {$lang->order}", 'filter_order');
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('filter[per_page]', $per_page, array('id' => 'filter_per_page', 'min' => 1)), 'filter_per_page');
$form_container->end();
$buttons[] = $form->generate_submit_button($lang->filter_warning_logs);
$form->output_submit_wrapper($buttons);
$form->end();
$page->output_footer();
}