inital commit
This commit is contained in:
8
webroot/forum/admin/modules/home/index.html
Normal file
8
webroot/forum/admin/modules/home/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
377
webroot/forum/admin/modules/home/index.php
Normal file
377
webroot/forum/admin/modules/home/index.php
Normal file
@@ -0,0 +1,377 @@
|
||||
<?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.");
|
||||
}
|
||||
|
||||
$plugins->run_hooks("admin_home_index_begin");
|
||||
|
||||
$sub_tabs['dashboard'] = array(
|
||||
'title' => $lang->dashboard,
|
||||
'link' => "index.php",
|
||||
'description' => $lang->dashboard_description
|
||||
);
|
||||
|
||||
$sub_tabs['version_check'] = array(
|
||||
'title' => $lang->version_check,
|
||||
'link' => "index.php?module=home&action=version_check",
|
||||
'description' => $lang->version_check_description
|
||||
);
|
||||
|
||||
if($mybb->input['action'] == "version_check")
|
||||
{
|
||||
$plugins->run_hooks("admin_home_version_check_start");
|
||||
|
||||
$current_version = rawurlencode($mybb->version_code);
|
||||
|
||||
$updated_cache = array(
|
||||
"last_check" => TIME_NOW
|
||||
);
|
||||
|
||||
require_once MYBB_ROOT."inc/class_xml.php";
|
||||
$contents = fetch_remote_file("https://mybb.com/version_check.php");
|
||||
|
||||
if(!$contents)
|
||||
{
|
||||
flash_message($lang->error_communication, 'error');
|
||||
admin_redirect('index.php');
|
||||
}
|
||||
|
||||
$plugins->run_hooks("admin_home_version_check");
|
||||
|
||||
$page->add_breadcrumb_item($lang->version_check, "index.php?module=home-version_check");
|
||||
$page->output_header($lang->version_check);
|
||||
$page->output_nav_tabs($sub_tabs, 'version_check');
|
||||
|
||||
$contents = trim($contents);
|
||||
|
||||
$parser = new XMLParser($contents);
|
||||
$tree = $parser->get_tree();
|
||||
|
||||
$latest_code = (int)$tree['mybb']['version_code']['value'];
|
||||
$latest_version = "<strong>".htmlspecialchars_uni($tree['mybb']['latest_version']['value'])."</strong> (".$latest_code.")";
|
||||
if($latest_code > $mybb->version_code)
|
||||
{
|
||||
$latest_version = "<span style=\"color: #C00;\">".$latest_version."</span>";
|
||||
$version_warn = 1;
|
||||
$updated_cache['latest_version'] = $latest_version;
|
||||
$updated_cache['latest_version_code'] = $latest_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
$latest_version = "<span style=\"color: green;\">".$latest_version."</span>";
|
||||
}
|
||||
|
||||
if($version_warn)
|
||||
{
|
||||
$page->output_error("<p><em>{$lang->error_out_of_date}</em> {$lang->update_forum}</p>");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->output_success("<p><em>{$lang->success_up_to_date}</em></p>");
|
||||
}
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->your_version);
|
||||
$table->construct_header($lang->latest_version);
|
||||
|
||||
$table->construct_cell("<strong>".$mybb->version."</strong> (".$mybb->version_code.")");
|
||||
$table->construct_cell($latest_version);
|
||||
$table->construct_row();
|
||||
|
||||
$table->output($lang->version_check);
|
||||
|
||||
require_once MYBB_ROOT."inc/class_feedparser.php";
|
||||
|
||||
$feed_parser = new FeedParser();
|
||||
$feed_parser->parse_feed("http://feeds.feedburner.com/MyBBDevelopmentBlog");
|
||||
|
||||
$updated_cache['news'] = array();
|
||||
|
||||
if($feed_parser->error == '')
|
||||
{
|
||||
require_once MYBB_ROOT . '/inc/class_parser.php';
|
||||
$post_parser = new postParser();
|
||||
|
||||
foreach($feed_parser->items as $item)
|
||||
{
|
||||
$description = $item['description'];
|
||||
$content = $item['content'];
|
||||
|
||||
$description = $post_parser->parse_message($description, array(
|
||||
'allow_html' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$content = $post_parser->parse_message($content, array(
|
||||
'allow_html' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$description = preg_replace('#<img(.*)/>#', '', $description);
|
||||
$content = preg_replace('#<img(.*)/>#', '', $content);
|
||||
|
||||
if(!isset($updated_cache['news'][2]))
|
||||
{
|
||||
$updated_cache['news'][] = array(
|
||||
'title' => htmlspecialchars_uni($item['title']),
|
||||
'description' => $description,
|
||||
'link' => htmlspecialchars_uni($item['link']),
|
||||
'author' => htmlspecialchars_uni($item['author']),
|
||||
'dateline' => $item['date_timestamp'],
|
||||
);
|
||||
}
|
||||
|
||||
$stamp = '';
|
||||
if($item['date_timestamp'])
|
||||
{
|
||||
$stamp = my_date('relative', $item['date_timestamp']);
|
||||
}
|
||||
|
||||
$link = htmlspecialchars_uni($item['link']);
|
||||
|
||||
$table->construct_cell("<span style=\"font-size: 16px;\"><strong>".htmlspecialchars_uni($item['title'])."</strong></span><br /><br />{$content}<strong><span style=\"float: right;\">{$stamp}</span><br /><br /><a href=\"{$link}\" target=\"_blank\" rel=\"noopener\">» {$lang->read_more}</a></strong>");
|
||||
$table->construct_row();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->construct_cell("{$lang->error_fetch_news} <!-- error code: {$feed_parser->error} -->");
|
||||
$table->construct_row();
|
||||
}
|
||||
|
||||
$cache->update("update_check", $updated_cache);
|
||||
|
||||
$table->output($lang->latest_mybb_announcements);
|
||||
$page->output_footer();
|
||||
}
|
||||
elseif(!$mybb->input['action'])
|
||||
{
|
||||
$plugins->run_hooks("admin_home_index_start");
|
||||
|
||||
if($mybb->request_method == "post" && isset($mybb->input['adminnotes']))
|
||||
{
|
||||
// Update Admin Notes cache
|
||||
$update_cache = array(
|
||||
"adminmessage" => $mybb->input['adminnotes']
|
||||
);
|
||||
|
||||
$cache->update("adminnotes", $update_cache);
|
||||
|
||||
$plugins->run_hooks("admin_home_index_start_begin");
|
||||
|
||||
flash_message($lang->success_notes_updated, 'success');
|
||||
admin_redirect("index.php");
|
||||
}
|
||||
|
||||
$page->add_breadcrumb_item($lang->dashboard);
|
||||
$page->output_header($lang->dashboard);
|
||||
|
||||
$sub_tabs['dashboard'] = array(
|
||||
'title' => $lang->dashboard,
|
||||
'link' => "index.php",
|
||||
'description' => $lang->dashboard_description
|
||||
);
|
||||
|
||||
$page->output_nav_tabs($sub_tabs, 'dashboard');
|
||||
|
||||
// Load stats cache
|
||||
$stats = $cache->read("stats");
|
||||
|
||||
$serverload = get_server_load();
|
||||
|
||||
// Get the number of users
|
||||
$query = $db->simple_select("users", "COUNT(uid) AS numusers");
|
||||
$users = my_number_format($db->fetch_field($query, "numusers"));
|
||||
|
||||
// Get the number of users awaiting validation
|
||||
$awaitingusers = $cache->read('awaitingactivation');
|
||||
|
||||
if(!empty($awaitingusers['users']))
|
||||
{
|
||||
$awaitingusers = (int)$awaitingusers['users'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$awaitingusers = 0;
|
||||
}
|
||||
|
||||
if($awaitingusers < 1)
|
||||
{
|
||||
$awaitingusers = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$awaitingusers = my_number_format($awaitingusers);
|
||||
}
|
||||
|
||||
// Get the number of new users for today
|
||||
$timecut = TIME_NOW - 86400;
|
||||
$query = $db->simple_select("users", "COUNT(uid) AS newusers", "regdate > '$timecut'");
|
||||
$newusers = my_number_format($db->fetch_field($query, "newusers"));
|
||||
|
||||
// Get the number of active users today
|
||||
$query = $db->simple_select("users", "COUNT(uid) AS activeusers", "lastvisit > '$timecut'");
|
||||
$activeusers = my_number_format($db->fetch_field($query, "activeusers"));
|
||||
|
||||
// Get the number of threads
|
||||
$threads = my_number_format($stats['numthreads']);
|
||||
|
||||
// Get the number of unapproved threads
|
||||
$unapproved_threads = my_number_format($stats['numunapprovedthreads']);
|
||||
|
||||
// Get the number of new threads for today
|
||||
$query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '$timecut' AND visible='1' AND closed NOT LIKE 'moved|%'");
|
||||
$newthreads = my_number_format($db->fetch_field($query, "newthreads"));
|
||||
|
||||
// Get the number of posts
|
||||
$posts = my_number_format($stats['numposts']);
|
||||
|
||||
// Get the number of unapproved posts
|
||||
if($stats['numunapprovedposts'] < 0)
|
||||
{
|
||||
$stats['numunapprovedposts'] = 0;
|
||||
}
|
||||
|
||||
$unapproved_posts = my_number_format($stats['numunapprovedposts']);
|
||||
|
||||
// Get the number of new posts for today
|
||||
$query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '$timecut' AND visible='1'");
|
||||
$newposts = my_number_format($db->fetch_field($query, "newposts"));
|
||||
|
||||
// Get the number of reported post
|
||||
$query = $db->simple_select("reportedcontent", "COUNT(*) AS reported_posts", "type = 'post' OR type = ''");
|
||||
$reported_posts = my_number_format($db->fetch_field($query, "reported_posts"));
|
||||
|
||||
// If report medium is MCP...
|
||||
if($mybb->settings['reportmethod'] == "db")
|
||||
{
|
||||
// Get the number of reported posts that haven't been marked as read yet
|
||||
$query = $db->simple_select("reportedcontent", "COUNT(*) AS new_reported_posts", "reportstatus='0' AND (type = 'post' OR type = '')");
|
||||
$new_reported_posts = my_number_format($db->fetch_field($query, "new_reported_posts"));
|
||||
}
|
||||
|
||||
// Get the number and total file size of attachments
|
||||
$query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused", "visible='1' AND pid > '0'");
|
||||
$attachs = $db->fetch_array($query);
|
||||
$attachs['spaceused'] = get_friendly_size($attachs['spaceused']);
|
||||
$approved_attachs = my_number_format($attachs['numattachs']);
|
||||
|
||||
// Get the number of unapproved attachments
|
||||
$query = $db->simple_select("attachments", "COUNT(*) AS numattachs", "visible='0' AND pid > '0'");
|
||||
$unapproved_attachs = my_number_format($db->fetch_field($query, "numattachs"));
|
||||
|
||||
// Fetch the last time an update check was run
|
||||
$update_check = $cache->read("update_check");
|
||||
|
||||
// If last update check was greater than two weeks ago (14 days) show an alert
|
||||
if(isset($update_check['last_check']) && $update_check['last_check'] <= TIME_NOW-60*60*24*14)
|
||||
{
|
||||
$lang->last_update_check_two_weeks = $lang->sprintf($lang->last_update_check_two_weeks, "index.php?module=home&action=version_check");
|
||||
$page->output_error("<p>{$lang->last_update_check_two_weeks}</p>");
|
||||
}
|
||||
|
||||
// If the update check contains information about a newer version, show an alert
|
||||
if(isset($update_check['latest_version_code']) && $update_check['latest_version_code'] > $mybb->version_code)
|
||||
{
|
||||
$lang->new_version_available = $lang->sprintf($lang->new_version_available, "MyBB {$mybb->version}", "<a href=\"https://mybb.com/download\" target=\"_blank\" rel=\"noopener\">MyBB {$update_check['latest_version']}</a>");
|
||||
$page->output_error("<p><em>{$lang->new_version_available}</em></p>");
|
||||
}
|
||||
|
||||
$plugins->run_hooks("admin_home_index_output_message");
|
||||
|
||||
$adminmessage = $cache->read("adminnotes");
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->mybb_server_stats, array("colspan" => 2));
|
||||
$table->construct_header($lang->forum_stats, array("colspan" => 2));
|
||||
|
||||
$table->construct_cell("<strong>{$lang->mybb_version}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell($mybb->version, array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$lang->threads}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$threads}</strong> {$lang->threads}<br /><strong>{$newthreads}</strong> {$lang->new_today}<br /><a href=\"index.php?module=forum-moderation_queue&type=threads\"><strong>{$unapproved_threads}</strong> {$lang->unapproved}</a>", array('width' => '25%'));
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell("<strong>{$lang->php_version}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell(PHP_VERSION, array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$lang->posts}</strong>", array('width' => '25%'));
|
||||
if($mybb->settings['reportmethod'] == "db")
|
||||
{
|
||||
$table->construct_cell("<strong>{$posts}</strong> {$lang->posts}<br /><strong>{$newposts}</strong> {$lang->new_today}<br /><a href=\"index.php?module=forum-moderation_queue&type=posts\"><strong>{$unapproved_posts}</strong> {$lang->unapproved}</a><br /><strong>{$reported_posts}</strong> {$lang->reported_posts}<br /><strong>{$new_reported_posts}</strong> {$lang->unread_reports}", array('width' => '25%'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->construct_cell("<strong>{$posts}</strong> {$lang->posts}<br /><strong>{$newposts}</strong> {$lang->new_today}<br /><a href=\"index.php?module=forum-moderation_queue&type=posts\"><strong>{$unapproved_posts}</strong> {$lang->unapproved}</a><br /><strong>{$reported_posts}</strong> {$lang->reported_posts}", array('width' => '25%'));
|
||||
}
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell("<strong>{$lang->sql_engine}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell($db->short_title." ".$db->get_version(), array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$lang->users}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell("<a href=\"index.php?module=user-users\"><strong>{$users}</strong> {$lang->registered_users}</a><br /><strong>{$activeusers}</strong> {$lang->active_users}<br /><strong>{$newusers}</strong> {$lang->registrations_today}<br /><a href=\"index.php?module=user-awaiting_activation\"><strong>{$awaitingusers}</strong> {$lang->awaiting_activation}</a>", array('width' => '25%'));
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell("<strong>{$lang->server_load}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell($serverload, array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$lang->attachments}</strong>", array('width' => '25%'));
|
||||
$table->construct_cell("<strong>{$approved_attachs}</strong> {$lang->attachments}<br /><a href=\"index.php?module=forum-moderation_queue&type=attachments\"><strong>{$unapproved_attachs}</strong> {$lang->unapproved}</a><br /><strong>{$attachs['spaceused']}</strong> {$lang->used}", array('width' => '25%'));
|
||||
$table->construct_row();
|
||||
|
||||
$table->output($lang->dashboard);
|
||||
|
||||
echo '
|
||||
<div class="float_right" style="width: 48%;">';
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->admin_notes_public);
|
||||
|
||||
$form = new Form("index.php", "post");
|
||||
$table->construct_cell($form->generate_text_area("adminnotes", $adminmessage['adminmessage'], array('style' => 'width: 99%; height: 200px;')));
|
||||
$table->construct_row();
|
||||
|
||||
$table->output($lang->admin_notes);
|
||||
|
||||
$buttons[] = $form->generate_submit_button($lang->save_notes);
|
||||
$form->output_submit_wrapper($buttons);
|
||||
$form->end();
|
||||
|
||||
echo '</div>
|
||||
<div class="float_left" style="width: 48%;">';
|
||||
|
||||
// Latest news widget
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->news_description);
|
||||
|
||||
if(!empty($update_check['news']) && is_array($update_check['news']))
|
||||
{
|
||||
foreach($update_check['news'] as $news_item)
|
||||
{
|
||||
$posted = my_date('relative', $news_item['dateline']);
|
||||
$table->construct_cell("<strong><a href=\"{$news_item['link']}\" target=\"_blank\" rel=\"noopener\">{$news_item['title']}</a></strong><br /><span class=\"smalltext\">{$posted}</span>");
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell($news_item['description']);
|
||||
$table->construct_row();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->construct_cell($lang->no_announcements);
|
||||
$table->construct_row();
|
||||
}
|
||||
|
||||
$table->output($lang->latest_mybb_announcements);
|
||||
echo '</div>';
|
||||
|
||||
$page->output_footer();
|
||||
}
|
||||
190
webroot/forum/admin/modules/home/module_meta.php
Normal file
190
webroot/forum/admin/modules/home/module_meta.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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 home_meta()
|
||||
{
|
||||
global $page, $lang, $plugins;
|
||||
|
||||
$sub_menu = array();
|
||||
$sub_menu['10'] = array("id" => "dashboard", "title" => $lang->dashboard, "link" => "index.php?module=home-dashboard");
|
||||
$sub_menu['20'] = array("id" => "preferences", "title" => $lang->preferences, "link" => "index.php?module=home-preferences");
|
||||
$sub_menu['30'] = array("id" => "docs", "title" => $lang->mybb_documentation, "link" => "https://docs.mybb.com");
|
||||
$sub_menu['40'] = array("id" => "credits", "title" => $lang->mybb_credits, "link" => "https://mybb.com/credits");
|
||||
$sub_menu = $plugins->run_hooks("admin_home_menu", $sub_menu);
|
||||
|
||||
$page->add_menu_item($lang->home, "home", "index.php", 1, $sub_menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function home_action_handler($action)
|
||||
{
|
||||
global $page, $db, $lang, $plugins;
|
||||
|
||||
$page->active_module = "home";
|
||||
|
||||
$actions = array(
|
||||
'preferences' => array('active' => 'preferences', 'file' => 'preferences.php'),
|
||||
'version_check' => array('active' => 'version_check', 'file' => 'version_check.php'),
|
||||
'dashboard' => array('active' => 'dashboard', 'file' => 'index.php')
|
||||
);
|
||||
|
||||
if(!isset($actions[$action]))
|
||||
{
|
||||
$page->active_action = "dashboard";
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->active_action = $actions[$action]['active'];
|
||||
}
|
||||
|
||||
$actions = $plugins->run_hooks("admin_home_action_handler", $actions);
|
||||
|
||||
if($page->active_action == "dashboard")
|
||||
{
|
||||
// Quick Access
|
||||
$sub_menu = array();
|
||||
$sub_menu['10'] = array("id" => "add_forum", "title" => $lang->add_new_forum, "link" => "index.php?module=forum-management&action=add", "module" => "forum", "action" => "management");
|
||||
$sub_menu['20'] = array("id" => "search", "title" => $lang->search_for_users, "link" => "index.php?module=user-users&action=search", "module" => "user", "action" => "users");
|
||||
$sub_menu['30'] = array("id" => "themes", "title" => $lang->themes, "link" => "index.php?module=style-themes", "module" => "style", "action" => "themes");
|
||||
$sub_menu['40'] = array("id" => "templates", "title" => $lang->templates, "link" => "index.php?module=style-templates", "module" => "style", "action" => "templates");
|
||||
$sub_menu['50'] = array("id" => "plugins", "title" => $lang->plugins, "link" => "index.php?module=config-plugins", "module" => "config", "action" => "plugins");
|
||||
$sub_menu['60'] = array("id" => "backupdb", "title" => $lang->database_backups, "link" => "index.php?module=tools-backupdb", "module" => "tools", "action" => "backupdb");
|
||||
|
||||
foreach($sub_menu as $id => $sub)
|
||||
{
|
||||
if(!check_admin_permissions(array("module" => $sub['module'], "action" => $sub['action']), false))
|
||||
{
|
||||
unset($sub_menu[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
$sub_menu = $plugins->run_hooks("admin_home_menu_quick_access", $sub_menu);
|
||||
|
||||
if(!empty($sub_menu))
|
||||
{
|
||||
$sidebar = new SidebarItem($lang->quick_access);
|
||||
$sidebar->add_menu_items($sub_menu, $page->active_action);
|
||||
$page->sidebar .= $sidebar->get_markup();
|
||||
}
|
||||
|
||||
// Online Administrators in the last 30 minutes
|
||||
$timecut = TIME_NOW-60*30;
|
||||
$query = $db->simple_select("adminsessions", "uid, ip, useragent", "lastactive > {$timecut}");
|
||||
$online_users = "<ul class=\"menu online_admins\">";
|
||||
$online_admins = array();
|
||||
|
||||
// If there's only 1 user online, it has to be us.
|
||||
if($db->num_rows($query) == 1)
|
||||
{
|
||||
$user = $db->fetch_array($query);
|
||||
global $mybb;
|
||||
|
||||
// Are we on a mobile device?
|
||||
// Stolen from http://stackoverflow.com/a/10989424
|
||||
$user_type = "desktop";
|
||||
if(is_mobile($user["useragent"]))
|
||||
{
|
||||
$user_type = "mobile";
|
||||
}
|
||||
|
||||
$online_admins[$mybb->user['username']] = array(
|
||||
"uid" => $mybb->user['uid'],
|
||||
"username" => $mybb->user['username'],
|
||||
"ip" => $user["ip"],
|
||||
"type" => $user_type
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$uid_in = array();
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
$uid_in[] = $user['uid'];
|
||||
|
||||
$user_type = "desktop";
|
||||
if(is_mobile($user['useragent']))
|
||||
{
|
||||
$user_type = "mobile";
|
||||
}
|
||||
|
||||
$online_admins[$user['uid']] = array(
|
||||
"ip" => $user['ip'],
|
||||
"type" => $user_type
|
||||
);
|
||||
}
|
||||
|
||||
$query = $db->simple_select("users", "uid, username", "uid IN(".implode(',', $uid_in).")", array('order_by' => 'username'));
|
||||
while($user = $db->fetch_array($query))
|
||||
{
|
||||
$online_admins[$user['username']] = array(
|
||||
"uid" => $user['uid'],
|
||||
"username" => $user['username'],
|
||||
"ip" => $online_admins[$user['uid']]['ip'],
|
||||
"type" => $online_admins[$user['uid']]['type']
|
||||
);
|
||||
unset($online_admins[$user['uid']]);
|
||||
}
|
||||
}
|
||||
|
||||
$done_users = array();
|
||||
|
||||
asort($online_admins);
|
||||
|
||||
foreach($online_admins as $user)
|
||||
{
|
||||
if(!isset($done_users["{$user['uid']}.{$user['ip']}"]))
|
||||
{
|
||||
if($user['type'] == "mobile")
|
||||
{
|
||||
$class = " class=\"mobile_user\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = "";
|
||||
}
|
||||
$ip_address = my_inet_ntop($db->unescape_binary($user['ip']));
|
||||
$online_users .= "<li title=\"{$lang->ipaddress} {$ip_address}\"{$class}>".build_profile_link(htmlspecialchars_uni($user['username']).' ('.$ip_address.')', $user['uid'], "_blank")."</li>";
|
||||
$done_users["{$user['uid']}.{$user['ip']}"] = 1;
|
||||
}
|
||||
}
|
||||
$online_users .= "</ul>";
|
||||
$sidebar = new SidebarItem($lang->online_admins);
|
||||
$sidebar->set_contents($online_users);
|
||||
|
||||
$page->sidebar .= $sidebar->get_markup();
|
||||
}
|
||||
|
||||
if(isset($actions[$action]))
|
||||
{
|
||||
$page->active_action = $actions[$action]['active'];
|
||||
return $actions[$action]['file'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->active_action = "dashboard";
|
||||
return "index.php";
|
||||
}
|
||||
}
|
||||
|
||||
192
webroot/forum/admin/modules/home/preferences.php
Normal file
192
webroot/forum/admin/modules/home/preferences.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?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->preferences_and_personal_notes, "index.php?module=home-preferences");
|
||||
|
||||
$plugins->run_hooks("admin_home_preferences_begin");
|
||||
|
||||
if($mybb->input['action'] == "recovery_codes")
|
||||
{
|
||||
$page->add_breadcrumb_item($lang->recovery_codes, "index.php?module=home-preferences&action=recovery_codes");
|
||||
|
||||
// First: regenerate the codes
|
||||
$codes = generate_recovery_codes();
|
||||
$db->update_query("adminoptions", array("recovery_codes" => $db->escape_string(my_serialize($codes))), "uid='{$mybb->user['uid']}'");
|
||||
|
||||
// And now display them
|
||||
$page->output_header($lang->recovery_codes);
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->recovery_codes);
|
||||
|
||||
$table->construct_cell("{$lang->recovery_codes_warning} <strong><a href=\"javascript:window.print()\">{$lang->print_recovery_codes}</a></strong>");
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell(implode("<br />", $codes));
|
||||
$table->construct_row();
|
||||
|
||||
$table->output($lang->recovery_codes);
|
||||
|
||||
$page->output_footer();
|
||||
}
|
||||
|
||||
if(!$mybb->input['action'])
|
||||
{
|
||||
require_once MYBB_ROOT."inc/3rdparty/2fa/GoogleAuthenticator.php";
|
||||
$auth = new PHPGangsta_GoogleAuthenticator;
|
||||
|
||||
$plugins->run_hooks("admin_home_preferences_start");
|
||||
|
||||
if($mybb->request_method == "post")
|
||||
{
|
||||
$query = $db->simple_select("adminoptions", "permissions, defaultviews, authsecret, recovery_codes", "uid='{$mybb->user['uid']}'");
|
||||
$adminopts = $db->fetch_array($query);
|
||||
|
||||
$secret = $adminopts['authsecret'];
|
||||
// Was the option changed? empty = disabled so ==
|
||||
if($mybb->input['2fa'] == empty($secret))
|
||||
{
|
||||
// 2FA was enabled -> create secret and log
|
||||
if($mybb->input['2fa'])
|
||||
{
|
||||
$secret = $auth->createSecret();
|
||||
// We don't want to close this session now
|
||||
$db->update_query("adminsessions", array("authenticated" => 1), "sid='".$db->escape_string($mybb->cookies['adminsid'])."'");
|
||||
log_admin_action("enabled");
|
||||
}
|
||||
// 2FA was disabled -> clear secret
|
||||
else
|
||||
{
|
||||
$secret = "";
|
||||
$adminopts['recovery_codes'] = "";
|
||||
log_admin_action("disabled");
|
||||
}
|
||||
}
|
||||
|
||||
$sqlarray = array(
|
||||
"notes" => $db->escape_string($mybb->input['notes']),
|
||||
"cpstyle" => $db->escape_string($mybb->input['cpstyle']),
|
||||
"cplanguage" => $db->escape_string($mybb->input['cplanguage']),
|
||||
"permissions" => $db->escape_string($adminopts['permissions']),
|
||||
"defaultviews" => $db->escape_string($adminopts['defaultviews']),
|
||||
"uid" => $mybb->user['uid'],
|
||||
"codepress" => $mybb->get_input('codepress', MyBB::INPUT_INT), // It's actually CodeMirror but for compatibility purposes lets leave it codepress
|
||||
"authsecret" => $db->escape_string($secret),
|
||||
"recovery_codes" => $db->escape_string($adminopts['recovery_codes']),
|
||||
);
|
||||
|
||||
$db->replace_query("adminoptions", $sqlarray, "uid");
|
||||
|
||||
$plugins->run_hooks("admin_home_preferences_start_commit");
|
||||
|
||||
flash_message($lang->success_preferences_updated, 'success');
|
||||
admin_redirect("index.php?module=home-preferences");
|
||||
}
|
||||
|
||||
$page->output_header($lang->preferences_and_personal_notes);
|
||||
|
||||
$sub_tabs['preferences'] = array(
|
||||
'title' => $lang->preferences_and_personal_notes,
|
||||
'link' => "index.php?module=home-preferences",
|
||||
'description' => $lang->prefs_and_personal_notes_description
|
||||
);
|
||||
|
||||
$page->output_nav_tabs($sub_tabs, 'preferences');
|
||||
|
||||
$query = $db->simple_select("adminoptions", "notes, cpstyle, cplanguage, codepress, authsecret", "uid='".$mybb->user['uid']."'", array('limit' => 1));
|
||||
$admin_options = $db->fetch_array($query);
|
||||
|
||||
$form = new Form("index.php?module=home-preferences", "post");
|
||||
$dir = @opendir(MYBB_ADMIN_DIR."/styles");
|
||||
|
||||
$folders = array();
|
||||
while($folder = readdir($dir))
|
||||
{
|
||||
if($folder != "." && $folder != ".." && @file_exists(MYBB_ADMIN_DIR."/styles/$folder/main.css"))
|
||||
{
|
||||
$folders[$folder] = ucfirst($folder);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
ksort($folders);
|
||||
$setting_code = $form->generate_select_box("cpstyle", $folders, $admin_options['cpstyle']);
|
||||
|
||||
$languages = array_merge(array('' => $lang->use_default), $lang->get_languages(1));
|
||||
$language_code = $form->generate_select_box("cplanguage", $languages, $admin_options['cplanguage']);
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->global_preferences);
|
||||
|
||||
$table->construct_cell("<strong>{$lang->acp_theme}</strong><br /><small>{$lang->select_acp_theme}</small><br /><br />{$setting_code}");
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell("<strong>{$lang->acp_language}</strong><br /><small>{$lang->select_acp_language}</small><br /><br />{$language_code}");
|
||||
$table->construct_row();
|
||||
|
||||
$table->construct_cell("<strong>{$lang->codemirror}</strong><br /><small>{$lang->use_codemirror_desc}</small><br /><br />".$form->generate_on_off_radio('codepress', $admin_options['codepress']));
|
||||
$table->construct_row();
|
||||
|
||||
// If 2FA is enabled we need to display a link to the recovery codes page
|
||||
if(!empty($admin_options['authsecret']))
|
||||
{
|
||||
$lang->use_2fa_desc .= "<br />".$lang->recovery_codes_desc." ".$lang->recovery_codes_warning;
|
||||
}
|
||||
|
||||
$table->construct_cell("<strong>{$lang->my2fa}</strong><br /><small>{$lang->use_2fa_desc}</small><br /><br />".$form->generate_on_off_radio('2fa', (int)!empty($admin_options['authsecret'])));
|
||||
$table->construct_row();
|
||||
|
||||
if(!empty($admin_options['authsecret']))
|
||||
{
|
||||
$qr = $auth->getQRCodeGoogleUrl($mybb->user['username']."@".str_replace(" ", "", $mybb->settings['bbname']), $admin_options['authsecret']);
|
||||
$table->construct_cell("<strong>{$lang->my2fa_qr}</strong><br /><img src=\"{$qr}\"");
|
||||
$table->construct_row();
|
||||
}
|
||||
|
||||
$table->output($lang->preferences);
|
||||
|
||||
$table->construct_header($lang->notes_not_shared);
|
||||
|
||||
$table->construct_cell($form->generate_text_area("notes", $admin_options['notes'], array('style' => 'width: 99%; height: 300px;')));
|
||||
$table->construct_row();
|
||||
|
||||
$table->output($lang->personal_notes);
|
||||
|
||||
$buttons[] = $form->generate_submit_button($lang->save_notes_and_prefs);
|
||||
$form->output_submit_wrapper($buttons);
|
||||
|
||||
$form->end();
|
||||
|
||||
$page->output_footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate 10 random recovery codes, each with a length of 6 and without duplicates
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function generate_recovery_codes()
|
||||
{
|
||||
$t = array();
|
||||
while(count($t) < 10)
|
||||
{
|
||||
$g = random_str(6);
|
||||
if(!in_array($g, $t))
|
||||
{
|
||||
$t[] = $g;
|
||||
}
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
Reference in New Issue
Block a user