[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/tools/ -> adminlog.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  $page->add_breadcrumb_item($lang->admin_logs, "index.php?module=tools-adminlog");
  19  
  20  $sub_tabs['admin_logs'] = array(
  21      'title' => $lang->admin_logs,
  22      'link' => "index.php?module=tools-adminlog",
  23      'description' => $lang->admin_logs_desc
  24  );
  25  $sub_tabs['prune_admin_logs'] = array(
  26      'title' => $lang->prune_admin_logs,
  27      'link' => "index.php?module=tools-adminlog&amp;action=prune",
  28      'description' => $lang->prune_admin_logs_desc
  29  );
  30  
  31  $plugins->run_hooks("admin_tools_adminlog_begin");
  32  
  33  if($mybb->input['action'] == 'prune')
  34  {
  35      $plugins->run_hooks("admin_tools_adminlog_prune");
  36  
  37      if(!is_super_admin($mybb->user['uid']))
  38      {
  39          flash_message($lang->cannot_perform_action_super_admin_general, 'error');
  40          admin_redirect("index.php?module=tools-adminlog");
  41      }
  42      if($mybb->request_method == 'post')
  43      {
  44          $where = 'dateline < '.(TIME_NOW-(intval($mybb->input['older_than'])*86400));
  45  
  46          // Searching for entries by a particular user
  47          if($mybb->input['uid'])
  48          {
  49              $where .= " AND uid='".intval($mybb->input['uid'])."'";
  50          }
  51  
  52          // Searching for entries in a specific module
  53          if($mybb->input['filter_module'])
  54          {
  55              $where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'";
  56          }
  57  
  58          $query = $db->delete_query("adminlog", $where);
  59          $num_deleted = $db->affected_rows();
  60  
  61          $plugins->run_hooks("admin_tools_adminlog_prune_commit");
  62  
  63          // Log admin action
  64          log_admin_action($mybb->input['older_than'], $mybb->input['uid'], $mybb->input['filter_module'], $num_deleted);
  65  
  66          flash_message($lang->success_pruned_admin_logs, 'success');
  67          admin_redirect("index.php?module=tools-adminlog");
  68      }
  69      $page->add_breadcrumb_item($lang->prune_admin_logs, "index.php?module=tools-adminlog&amp;action=prune");
  70      $page->output_header($lang->prune_admin_logs);
  71      $page->output_nav_tabs($sub_tabs, 'prune_admin_logs');
  72  
  73      // Fetch filter options
  74      $sortbysel[$mybb->input['sortby']] = 'selected="selected"';
  75      $ordersel[$mybb->input['order']] = 'selected="selected"';
  76  
  77      $user_options[''] = $lang->all_administrators;
  78      $user_options['0'] = '----------';
  79  
  80      $query = $db->query("
  81          SELECT DISTINCT l.uid, u.username
  82          FROM ".TABLE_PREFIX."adminlog l
  83          LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
  84          ORDER BY u.username ASC
  85      ");
  86      while($user = $db->fetch_array($query))
  87      {
  88          $user_options[$user['uid']] = $user['username'];
  89      }
  90  
  91      $module_options = array();
  92      $module_options[''] = $lang->all_modules;
  93      $module_options['0'] = '----------';
  94      $query = $db->query("
  95          SELECT DISTINCT l.module
  96          FROM ".TABLE_PREFIX."adminlog l
  97          ORDER BY l.module ASC
  98      ");
  99      while($module = $db->fetch_array($query))
 100      {
 101          $module_options[$module['module']] = str_replace(' ', ' -&gt; ', ucwords(str_replace('/', ' ', $module['module'])));
 102      }
 103  
 104      $form = new Form("index.php?module=tools-adminlog&amp;action=prune", "post");
 105      $form_container = new FormContainer($lang->prune_administrator_logs);
 106      $form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->input['filter_module'], array('id' => 'filter_module')), 'filter_module');
 107      $form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
 108      if(!$mybb->input['older_than'])
 109      {
 110          $mybb->input['older_than'] = '30';
 111      }
 112      $form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_text_box('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 30px'))." {$lang->days}", 'older_than');
 113      $form_container->end();
 114      $buttons[] = $form->generate_submit_button($lang->prune_administrator_logs);
 115      $form->output_submit_wrapper($buttons);
 116      $form->end();
 117  
 118      $page->output_footer();
 119  }
 120  
 121  if(!$mybb->input['action'])
 122  {
 123      $plugins->run_hooks("admin_tools_adminlog_start");
 124  
 125      $page->output_header($lang->admin_logs);
 126      $page->output_nav_tabs($sub_tabs, 'admin_logs');
 127  
 128      $perpage = intval($mybb->input['perpage']);
 129      if(!$perpage)
 130      {
 131          $perpage = $mybb->settings['threadsperpage'];
 132      }
 133  
 134      $where = '';
 135  
 136      // Searching for entries by a particular user
 137      if($mybb->input['uid'])
 138      {
 139          $where .= " AND l.uid='".intval($mybb->input['uid'])."'";
 140      }
 141  
 142      // Searching for entries in a specific module
 143      if($mybb->input['filter_module'])
 144      {
 145          $where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'";
 146      }
 147  
 148      // Order?
 149      switch($mybb->input['sortby'])
 150      {
 151          case "username":
 152              $sortby = "u.username";
 153              break;
 154          default:
 155              $sortby = "l.dateline";
 156      }
 157      $order = $mybb->input['order'];
 158      if($order != 'asc')
 159      {
 160          $order = 'desc';
 161      }
 162  
 163      $query = $db->query("
 164          SELECT COUNT(l.dateline) AS count
 165          FROM ".TABLE_PREFIX."adminlog l
 166          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
 167          WHERE 1=1 {$where}
 168      ");
 169      $rescount = $db->fetch_field($query, "count");
 170  
 171      // Figure out if we need to display multiple pages.
 172      if($mybb->input['page'] != "last")
 173      {
 174          $pagecnt = intval($mybb->input['page']);
 175      }
 176  
 177      $postcount = intval($rescount);
 178      $pages = $postcount / $perpage;
 179      $pages = ceil($pages);
 180  
 181      if($mybb->input['page'] == "last")
 182      {
 183          $pagecnt = $pages;
 184      }
 185  
 186      if($pagecnt > $pages)
 187      {
 188          $pagecnt = 1;
 189      }
 190  
 191      if($pagecnt)
 192      {
 193          $start = ($pagecnt-1) * $perpage;
 194      }
 195      else
 196      {
 197          $start = 0;
 198          $pagecnt = 1;
 199      }
 200  
 201      $table = new Table;
 202      $table->construct_header($lang->username, array('width' => '10%'));
 203      $table->construct_header($lang->date, array('class' => 'align_center', 'width' => '15%'));
 204      $table->construct_header($lang->information, array('class' => 'align_center', 'width' => '65%'));
 205      $table->construct_header($lang->ipaddress, array('class' => 'align_center', 'width' => '10%'));
 206  
 207      $query = $db->query("
 208          SELECT l.*, u.username, u.usergroup, u.displaygroup
 209          FROM ".TABLE_PREFIX."adminlog l
 210          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
 211          WHERE 1=1 {$where}
 212          ORDER BY {$sortby} {$order}
 213          LIMIT {$start}, {$perpage}
 214      ");
 215      while($logitem = $db->fetch_array($query))
 216      {
 217          $information = '';
 218          $logitem['dateline'] = date("jS M Y, G:i", $logitem['dateline']);
 219          $trow = alt_trow();
 220          $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']);
 221          $logitem['profilelink'] = build_profile_link($username, $logitem['uid'], "_blank");
 222          $logitem['data'] = unserialize($logitem['data']);
 223  
 224          // Get detailed information from meta
 225          $information = get_admin_log_action($logitem);
 226  
 227          $table->construct_cell($logitem['profilelink']);
 228          $table->construct_cell($logitem['dateline'], array('class' => 'align_center'));
 229          $table->construct_cell($information);
 230          $table->construct_cell($logitem['ipaddress'], array('class' => 'align_center'));
 231          $table->construct_row();
 232      }
 233  
 234      if($table->num_rows() == 0)
 235      {
 236          $table->construct_cell($lang->no_adminlogs, array('colspan' => '4'));
 237          $table->construct_row();
 238      }
 239  
 240      $table->output($lang->admin_logs);
 241  
 242      // Do we need to construct the pagination?
 243      if($rescount > $perpage)
 244      {
 245          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 />";
 246      }
 247  
 248      // Fetch filter options
 249      $sortbysel[$mybb->input['sortby']] = 'selected="selected"';
 250      $ordersel[$mybb->input['order']] = 'selected="selected"';
 251  
 252      $user_options[''] = $lang->all_administrators;
 253      $user_options['0'] = '----------';
 254  
 255      $query = $db->query("
 256          SELECT DISTINCT l.uid, u.username
 257          FROM ".TABLE_PREFIX."adminlog l
 258          LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
 259          ORDER BY u.username ASC
 260      ");
 261      while($user = $db->fetch_array($query))
 262      {
 263          $user_options[$user['uid']] = $user['username'];
 264      }
 265  
 266      $module_options = array();
 267      $module_options[''] = $lang->all_modules;
 268      $module_options['0'] = '----------';
 269      $query = $db->query("
 270          SELECT DISTINCT l.module
 271          FROM ".TABLE_PREFIX."adminlog l
 272          ORDER BY l.module ASC
 273      ");
 274      while($module = $db->fetch_array($query))
 275      {
 276          $module_options[$module['module']] = str_replace(' ', ' -&gt; ', ucwords(str_replace('/', ' ', $module['module'])));
 277      }
 278  
 279      $sort_by = array(
 280          'dateline' => $lang->date,
 281          'username' => $lang->username
 282      );
 283  
 284      $order_array = array(
 285          'asc' => $lang->asc,
 286          'desc' => $lang->desc
 287      );
 288  
 289      $form = new Form("index.php?module=tools-adminlog", "post");
 290      $form_container = new FormContainer($lang->filter_administrator_logs);
 291      $form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->input['filter_module'], array('id' => 'filter_module')), 'filter_module');
 292      $form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
 293      $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');
 294      $form_container->output_row($lang->results_per_page, "", $form->generate_text_box('perpage', $perpage, array('id' => 'perpage')), 'perpage');
 295  
 296      $form_container->end();
 297      $buttons[] = $form->generate_submit_button($lang->filter_administrator_logs);
 298      $form->output_submit_wrapper($buttons);
 299      $form->end();
 300  
 301      $page->output_footer();
 302  }
 303  
 304  /**
 305   * Returns language-friendly string describing $logitem
 306   * @param array The log item (one row from mybb_adminlogs)
 307   * @return string The description
 308   */
 309  function get_admin_log_action($logitem)
 310  {
 311      global $lang, $plugins, $mybb;
 312  
 313      $logitem['module'] = str_replace('/', '-', $logitem['module']);
 314      list($module, $action) = explode('-', $logitem['module']);
 315      $lang_string = 'admin_log_'.$module.'_'.$action.'_'.$logitem['action'];
 316  
 317      // Specific page overrides
 318      switch($lang_string)
 319      {
 320          // == CONFIG ==
 321          case 'admin_log_config_banning_add': // Banning IP/Username/Email
 322          case 'admin_log_config_banning_delete': // Removing banned IP/username/emails
 323              switch($logitem['data'][2])
 324              {
 325                  case 1:
 326                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_ip';
 327                      break;
 328                  case 2:
 329                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_username';
 330                      break;
 331                  case 3:
 332                      $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_email';
 333                      break;
 334              }
 335              break;
 336  
 337          case 'admin_log_config_help_documents_add': // Help documents and sections
 338          case 'admin_log_config_help_documents_edit':
 339          case 'admin_log_config_help_documents_delete':
 340              $lang_string .= "_{$logitem['data'][2]}"; // adds _section or _document
 341              break;
 342  
 343          case 'admin_log_config_languages_edit': // Editing language variables
 344              $logitem['data'][1] = basename($logitem['data'][1]);
 345              if($logitem['data'][2] == 1)
 346              {
 347                  $lang_string = 'admin_log_config_languages_edit_admin';
 348              }
 349              break;
 350  
 351          case 'admin_log_config_mycode_toggle_status': // Custom MyCode toggle activation
 352              if($logitem['data'][2] == 1)
 353              {
 354                  $lang_string .= '_enabled';
 355              }
 356              else
 357              {
 358                  $lang_string .= '_disabled';
 359              }
 360              break;
 361          case 'admin_log_config_plugins_activate': // Installing plugin
 362              if($logitem['data'][1])
 363              {
 364                  $lang_string .= '_install';
 365              }
 366              break;
 367          case 'admin_log_config_plugins_deactivate': // Uninstalling plugin
 368              if($logitem['data'][1])
 369              {
 370                  $lang_string .= '_uninstall';
 371              }
 372              break;
 373          // == FORUM ==
 374          case 'admin_log_forum_attachments_delete': // Deleting attachments
 375              if($logitem['data'][2])
 376              {
 377                  $lang_string .= '_post';
 378              }
 379              break;
 380          case 'admin_log_forum_management_copy': // Forum copy
 381              if($logitem['data'][4])
 382              {
 383                  $lang_string .= '_with_permissions';
 384              }
 385              break;
 386          case 'admin_log_forum_management_': // add mod, permissions, forum orders
 387              // first parameter already set with action
 388              $lang_string .= $logitem['data'][0];
 389              if($logitem['data'][0] == 'orders' && $logitem['data'][1])
 390              {
 391                  $lang_string .= '_sub'; // updating forum orders in a subforum
 392              }
 393              break;
 394          case 'admin_log_forum_moderation_queue_': //moderation queue
 395              // first parameter already set with action
 396              $lang_string .= $logitem['data'][0];
 397              break;
 398          // == HOME ==
 399          // == STYLE ==
 400          case 'admin_log_style_templates_delete_template': // deleting templates
 401              // global template set
 402              if($logitem['data'][2] == -1)
 403              {
 404                  $lang_string .= '_global';
 405              }
 406              break;
 407          case 'admin_log_style_templates_edit_template': // editing templates
 408              // global template set
 409              if($logitem['data'][2] == -1)
 410              {
 411                  $lang_string .= '_global';
 412              }
 413              break;
 414          // == TOOLS ==
 415          case 'admin_log_tools_adminlog_prune': // Admin Log Pruning
 416              if($logitem['data'][1] && !$logitem['data'][2])
 417              {
 418                  $lang_string = 'admin_log_tools_adminlog_prune_user';
 419              }
 420              elseif($logitem['data'][2] && !$logitem['data'][1])
 421              {
 422                  $lang_string = 'admin_log_tools_adminlog_prune_module';
 423              }
 424              elseif($logitem['data'][1] && $logitem['data'][2])
 425              {
 426                  $lang_string = 'admin_log_tools_adminlog_prune_user_module';
 427              }
 428              break;
 429          case 'admin_log_tools_modlog_prune': // Moderator Log Pruning
 430              if($logitem['data'][1] && !$logitem['data'][2])
 431              {
 432                  $lang_string = 'admin_log_tools_modlog_prune_user';
 433              }
 434              elseif($logitem['data'][2] && !$logitem['data'][1])
 435              {
 436                  $lang_string = 'admin_log_tools_modlog_prune_forum';
 437              }
 438              elseif($logitem['data'][1] && $logitem['data'][2])
 439              {
 440                  $lang_string = 'admin_log_tools_modlog_prune_user_forum';
 441              }
 442              break;
 443          case 'admin_log_tools_backupdb_backup': // Create backup
 444              if($logitem['data'][0] == 'download')
 445              {
 446                  $lang_string = 'admin_log_tools_backupdb_backup_download';
 447              }
 448              $logitem['data'][1] = '...'.substr($logitem['data'][1], -20);
 449              break;
 450          case 'admin_log_tools_backupdb_dlbackup': // Download backup
 451              $logitem['data'][0] = '...'.substr($logitem['data'][0], -20);
 452              break;
 453          case 'admin_log_tools_backupdb_delete': // Delete backup
 454              $logitem['data'][0] = '...'.substr($logitem['data'][0], -20);
 455              break;
 456          case 'admin_log_tools_optimizedb_': // Optimize DB
 457              $logitem['data'][0] = @implode(', ', unserialize($logitem['data'][0]));
 458              break;
 459          case 'admin_log_tools_recount_rebuild_': // Recount and rebuild
 460              $detail_lang_string = $lang_string.$logitem['data'][0];
 461              if(isset($lang->$detail_lang_string))
 462              {
 463                  $lang_string = $detail_lang_string;
 464              }
 465              break;
 466          // == USERS ==
 467          case 'admin_log_user_admin_permissions_edit': // default/group/user admin permissions
 468              if($logitem['data'][0] > 0)
 469              {
 470                  // User
 471                  $lang_string .= '_user';
 472              }
 473              elseif($logitem['data'][0] < 0)
 474              {
 475                  // Group
 476                  $logitem['data'][0] = abs($logitem['data'][0]);
 477                  $lang_string .= '_group';
 478              }
 479              break;
 480          case 'admin_log_user_banning_': // banning
 481              if($logitem['data'][2] == 0)
 482              {
 483                  $lang_string = 'admin_log_user_banning_add_permanent';
 484              }
 485              else
 486              {
 487                  $logitem['data'][2] = my_date($mybb->settings['dateformat'], $logitem['data'][2]);
 488                  $lang_string = 'admin_log_user_banning_add_temporary';
 489              }
 490              break;
 491          case 'admin_log_user_users_inline_banned':
 492              if($logitem['data'][1] == 0)
 493              {
 494                  $lang_string = 'admin_log_user_users_inline_banned_perm';
 495              }
 496              else
 497              {
 498                  $logitem['data'][1] = my_date($mybb->settings['dateformat'], $logitem['data'][1]);
 499                  $lang_string = 'admin_log_user_users_inline_banned_temp';
 500              }
 501              break;
 502      }
 503  
 504      $plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string);
 505      $plugins->run_hooks("admin_tools_get_admin_log_action", $plugin_array);
 506  
 507      if(isset($lang->$lang_string))
 508      {
 509          array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string
 510          $string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']);
 511          if(!$string)
 512          {
 513              $string = $lang->$lang_string; // Fall back to the one in the language pack
 514          }
 515      }
 516      else
 517      {
 518          // Build a default string
 519          $string = $logitem['module'].' - '.$logitem['action'];
 520          if(is_array($logitem['data']) && count($logitem['data']) > 0)
 521          {
 522              $string .= '('.implode(', ', $logitem['data']).')';
 523          }
 524      }
 525      return $string;
 526  }
 527  
 528  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1