plugins/admin/SecurityLog.php
changeset 1175 1e2c9819ede3
parent 1146 4a90e6e46937
child 1227 bdac73ed481e
equal deleted inserted replaced
1174:def792dd9b1b 1175:1e2c9819ede3
    36   if ( !$q )
    36   if ( !$q )
    37     $db->_die();
    37     $db->_die();
    38   $row = $db->fetchrow();
    38   $row = $db->fetchrow();
    39   $db->free_result();
    39   $db->free_result();
    40   $count = intval($row['num']);
    40   $count = intval($row['num']);
    41   $q = $db->sql_query('SELECT action,date_string,author,edit_summary,time_id,page_text FROM '.table_prefix.'logs WHERE log_type=\'security\' ORDER BY time_id DESC, action ASC;');
    41 
       
    42   $l = 'SELECT action,date_string,author,author_uid,u.username,edit_summary,time_id,page_text FROM '.table_prefix."logs AS l\n"
       
    43      . "  LEFT JOIN " . table_prefix . "users AS u\n"
       
    44      . "    ON ( u.user_id = l.author_uid OR u.user_id IS NULL )\n"
       
    45      . "  WHERE log_type='security'\n"
       
    46      . "  ORDER BY time_id DESC, action ASC;";
       
    47          
       
    48   $q = $db->sql_query($l);
    42   if ( !$q )
    49   if ( !$q )
    43     $db->_die();
    50     $db->_die();
    44    
    51    
    45   $html = paginate(
    52   $html = paginate(
    46       $q,
    53       $q,
    69   global $db, $session, $paths, $template, $plugins; // Common objects
    76   global $db, $session, $paths, $template, $plugins; // Common objects
    70   global $lang;
    77   global $lang;
    71   
    78   
    72   if ( $session->auth_level < USER_LEVEL_ADMIN )
    79   if ( $session->auth_level < USER_LEVEL_ADMIN )
    73   {
    80   {
    74     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author) VALUES(\'security\',\'seclog_unauth\',' . time() . ',"' . $db->escape($_SERVER['REMOTE_ADDR']) . '","' . $db->escape($session->username) . '");');
    81     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid) VALUES(\'security\',\'seclog_unauth\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', \'' . $db->escape($session->username) . '\', ' . $session->user_id . ');');
    75     if ( !$q )
    82     if ( !$q )
    76       $db->_die();
    83       $db->_die();
    77     die('Security log: unauthorized attempt to fetch. Call has been logged and reported to the administrators.');
    84     die('Security log: unauthorized attempt to fetch. Call has been logged and reported to the administrators.');
    78   }
    85   }
    79   
    86   
    92   // {
    99   // {
    93   //   $return .= '<tr><td class="row1" colspan="4">Logs are recorded but not displayed for privacy purposes in the demo.</td></tr>';
   100   //   $return .= '<tr><td class="row1" colspan="4">Logs are recorded but not displayed for privacy purposes in the demo.</td></tr>';
    94   // }
   101   // }
    95   // else
   102   // else
    96   // {
   103   // {
    97     if(is_int($num))
   104     $limit_clause = is_int($num) ? " LIMIT $num" : '';
    98     {
   105     $l = 'SELECT action,date_string,author,author_uid,u.username,edit_summary,time_id,page_text FROM '.table_prefix."logs AS l\n"
    99       $l = 'SELECT action,date_string,author,edit_summary,time_id,page_text FROM '.table_prefix.'logs WHERE log_type=\'security\' ORDER BY time_id DESC, action ASC LIMIT '.$num.';';
   106          . "  LEFT JOIN " . table_prefix . "users AS u\n"
   100     }
   107          . "    ON ( u.user_id = l.author_uid OR u.user_id IS NULL )\n"
   101     else
   108          . "  WHERE log_type='security'\n"
   102     {
   109          . "  ORDER BY time_id DESC, action ASC{$limit_clause};";
   103       $l = 'SELECT action,date_string,author,edit_summary,time_id,page_text FROM '.table_prefix.'logs WHERE log_type=\'security\' ORDER BY time_id DESC, action ASC;';
   110     
   104     }
       
   105     $q = $db->sql_query($l);
   111     $q = $db->sql_query($l);
   106     while($r = $db->fetchrow($q))
   112     while($r = $db->fetchrow($q))
   107     {
   113     {
   108       $return .= seclog_format_inner($r);
   114       $return .= seclog_format_inner($r);
   109     }
   115     }
   173     case "u_from_mod"      : $return .= $lang->get('acpsl_entry_u_from_mod'       , array('username' => $r['page_text'])); break;
   179     case "u_from_mod"      : $return .= $lang->get('acpsl_entry_u_from_mod'       , array('username' => $r['page_text'])); break;
   174     case "u_to_admin"      : $return .= $lang->get('acpsl_entry_u_to_admin'       , array('username' => $r['page_text'])); break;
   180     case "u_to_admin"      : $return .= $lang->get('acpsl_entry_u_to_admin'       , array('username' => $r['page_text'])); break;
   175     case "u_to_mod"        : $return .= $lang->get('acpsl_entry_u_to_mod'         , array('username' => $r['page_text'])); break;
   181     case "u_to_mod"        : $return .= $lang->get('acpsl_entry_u_to_mod'         , array('username' => $r['page_text'])); break;
   176     case "view_comment_ip" : $return .= $lang->get('acpsl_entry_view_comment_ip'  , array('username' => htmlspecialchars($r['page_text']))); break;
   182     case "view_comment_ip" : $return .= $lang->get('acpsl_entry_view_comment_ip'  , array('username' => htmlspecialchars($r['page_text']))); break;
   177   }
   183   }
   178   $return .= '</td><td class="'.$cls.'">'.enano_date(ED_DATE | ED_TIME, $r['time_id']).'</td><td class="'.$cls.'">'.$r['author'].'</td><td class="'.$cls.'" style="cursor: pointer;" onclick="ajaxReverseDNS(this);" title="' . $lang->get('acpsl_tip_reverse_dns') . '">'.$r['edit_summary'].'</td></tr>';
   184   $author_bit = '<span style="';
       
   185   $rank_info = $session->get_user_rank($r['author_uid']);
       
   186   $author_bit .= $rank_info['rank_style'];
       
   187   $author_bit .= '">';
       
   188   $author_bit .= $r['author_uid'] > 1 && !empty($r['username']) ? htmlspecialchars($r['username']) : htmlspecialchars($r['author']);
       
   189   $author_bit .= '</span>';
       
   190   $return .= '</td><td class="'.$cls.'">'.enano_date(ED_DATE | ED_TIME, $r['time_id']).'</td><td class="'.$cls.'">'.$author_bit.'</td><td class="'.$cls.'" style="cursor: pointer;" onclick="ajaxReverseDNS(this);" title="' . $lang->get('acpsl_tip_reverse_dns') . '">'.$r['edit_summary'].'</td></tr>';
   179   return $return;
   191   return $return;
   180 }
   192 }
   181 
   193 
   182 ?>
   194 ?>