Changeset 803


Ignore:
Timestamp:
Apr 14, 2014, 8:29:20 PM (11 years ago)
Author:
chronos
Message:
  • Added: Do not log new referrals if client IP was previously blocked as spam source.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Referrer/Referrer.php

    r766 r803  
    44{
    55        var $Excludes;
    6        
     6
    77  function __construct($System)
    88  {
     
    1414    $this->Description = 'Log HTTP referrer URLs.';
    1515    $this->Dependencies = array();
    16    
     16
    1717    $this->Excludes = array();
    1818  }
    19  
     19
    2020  function Start()
    2121  {
     
    3030    ));
    3131  }
    32  
     32
    3333  function Log()
    3434  {
    35     if(array_key_exists('HTTP_REFERER', $_SERVER)) 
     35    if(array_key_exists('HTTP_REFERER', $_SERVER))
    3636    {
    3737      $Referrer = addslashes($_SERVER['HTTP_REFERER']);
     
    4040      if(!in_array($HostName, $this->Excludes))
    4141      {
     42        if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole';
     43          else $IP = addslashes($_SERVER['REMOTE_ADDR']);
     44
     45        // Check if client IP is not blocked as spam source
     46        $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Referrer` WHERE `LastIP` = "'.$IP.'" AND (`Visible` = 0)');
     47        $DbRow = $DbResult->fetch_row();
     48        if($DbRow[0] == 0) $Visible = '1';
     49          else $Visible = '0';
     50
     51        // Check if host name is already stored and need just to update hit counter
    4252        $DbResult = $this->System->Database->query('SELECT `Id` FROM `Referrer` WHERE `Web` = "'.$HostName.'"');
    4353        if($DbResult->num_rows > 0)
     
    4555          $DbRow = $DbResult->fetch_assoc();
    4656          $this->System->Database->query('UPDATE `Referrer` SET `Hits` = `Hits` + 1, `DateLast` = NOW(), `LastURL` = "'.
    47             addslashes($Referrer).'" WHERE `Id` = '.$DbRow['Id']);
    48         } else $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`) '.
    49                 'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1)');
     57           addslashes($Referrer).'", `LastIP` = "'.$IP.'" WHERE `Id` = '.$DbRow['Id']);
     58        } else $this->System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`, `LastIP`, `Visible`) '.
     59                  'VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1, "'.$IP.'", '.$Visible.')');
    5060      }
    5161    }
    52   } 
     62  }
    5363}
    54  
     64
    5565class PageReferrer extends Page
    5666{
     
    6171      'alt="wowpreklad" title="Otevřený projekt překládání celé hry World of Warcraft" '.
    6272      'class="banner" height="60" width="468" /></a>';
    63  
     73
    6474    $BannerSmall = '<a href="http://'.$this->System->Config['Web']['Host'].$this->System->Link('/').'">'.
    6575      '<img src="http://'.$this->System->Config['Web']['Host'].$this->System->Link('/banners/wowpreklad_small.jpg').'" '.
     
    6878
    6979    $Output = '<strong>'.T('Banners').':</strong><br />';
    70  
     80
    7181    $Output .= $Banner.' &nbsp;&nbsp;<textarea rows="2" cols="30">'.htmlspecialchars($Banner).'</textarea><br />';
    7282    $Output .= $BannerSmall.' &nbsp;&nbsp;<textarea rows="2" cols="30">'.htmlspecialchars($BannerSmall).'</textarea><br />';
    73        
     83
    7484    $MonthAge = 3;
    7585    $YesNo = array('Ne', 'Ano');
    7686                $Output .= '<br/><strong>'.T('Servers referring to us').':</strong> <br />
    77         <div style="font-size: 10px;">Seznam je automaticky aktualizován a zobrazeny jsou servery, ze kterých přišli uživatelé během posledních třech měsíců řazený sestupně dle nejnovějších.</div><br />';   
    78        
    79         if(!$this->System->User->Licence(LICENCE_ADMIN)) $Where = ' WHERE (`Show`=1) AND (`Parent` IS NULL)';
     87        <div style="font-size: 10px;">Seznam je automaticky aktualizován a zobrazeny jsou servery, ze kterých přišli uživatelé během posledních třech měsíců řazený sestupně dle nejnovějších.</div><br />';
     88
     89        if(!$this->System->User->Licence(LICENCE_ADMIN)) $Where = ' WHERE (`Visible`=1) AND (`Parent` IS NULL)';
    8090        else $Where = '';
    8191        $Query = 'SELECT *, (SELECT Web FROM `Referrer` AS T4 WHERE T4.Id = T3.Parent) AS ParentName '.
     
    8797                        '`Referrer` AS `T2` '.$Where.') AS `T3` '.
    8898                        'WHERE (`T3`.`MaxDateLast` > (NOW() - INTERVAL '.$MonthAge.' MONTH))';
    89        
    90        
     99
     100
    91101        $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS T');
    92102        $DbRow = $DbResult->fetch_row();
    93103        $PageList = GetPageList($DbRow[0]);
    94        
     104
    95105        $Output .= $PageList['Output'].
    96106        '<table class="BaseTable">';
    97        
     107
    98108        $TableColumns = array(
    99109                        array('Name' => 'Web', 'Title' => T('Address')),
     
    103113        if($this->System->User->Licence(LICENCE_ADMIN))
    104114        {
    105                 $TableColumns[] = array('Name' => 'Show', 'Title' => T('Visible'));
     115                $TableColumns[] = array('Name' => 'Visible', 'Title' => T('Visible'));
    106116                $TableColumns[] = array('Name' => 'Parent', 'Title' => T('Parent'));
    107117                $TableColumns[] = array('Name' => 'Description', 'Title' => T('Comment'));
     118      $TableColumns[] = array('Name' => 'LastIP', 'Title' => T('Last IP address'));
    108119                $TableColumns[] = array('Name' => 'Action', 'Title' => T('Actions'));
    109120        }
    110121        $Order = GetOrderTableHeader($TableColumns, 'MaxDateLast', 1);
    111122        $Output .= $Order['Output'];
    112        
     123
    113124        $Query .= $Order['SQL'].$PageList['SQLLimit'];
    114        
     125
    115126        $DbResult = $this->Database->query($Query);
    116127        while($Line = $DbResult->fetch_assoc())
     
    122133                {
    123134                        $Output .=
    124                         '<td>'.$YesNo[$Line['Show']].'</td>'.
     135                        '<td>'.$YesNo[$Line['Visible']].'</td>'.
    125136                        '<td>'.$Line['ParentName'].'</td>'.
    126137                        '<td>'.$Line['Description'].'</td>'.
    127                         '<td><a href="?action=edit&amp;id='.$Line['Id'].'">'.T('Modify').'</a></td>';
     138        '<td>'.$Line['LastIP'].'</td>'.
     139                        '<td><a href="?action=edit&amp;id='.$Line['Id'].'">'.T('Modify').'</a> '.
     140        '<a href="?action=spam&amp;id='.$Line['Id'].'">'.T('Spam').'</a></td>';
    128141                }
    129142                $Output .= '</tr>';
     
    131144        $Output .= '</table>';
    132145        $Output .= $PageList['Output'];
    133         return($Output);         
     146        return($Output);
    134147  }
    135148
     
    154167  }
    155168
     169  function Spam()
     170  {
     171    if($this->System->User->Licence(LICENCE_ADMIN))
     172    {
     173      if(array_key_exists('id', $_GET))
     174      {
     175        $DbResult = $this->Database->select('Referrer', '*', 'Id='.$_GET['id']);
     176        if($DbResult->num_rows > 0)
     177        {
     178          $Item = $DbResult->fetch_assoc();
     179          $this->Database->update('Referrer', 'Id='.$_GET['id'], array('Visible' => 0, 'Description' => 'Spam'));
     180          $Output = ShowMessage(T('Set as spam'), MESSAGE_CRITICAL);
     181          $Output .= $this->ShowList();
     182        } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     183      } else $Output = ShowMessage(T('Item not specified'), MESSAGE_CRITICAL);
     184    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     185    return($Output);
     186  }
     187
    156188  function Edit()
    157189  {
     
    164196              {
    165197                      $Item = $DbResult->fetch_assoc();
    166                       if($Item['Show'] == 1) $Show = ' checked ';
    167                       else $Show = '';
     198                      if($Item['Visible'] == 1) $Visible = ' checked ';
     199                      else $Visible = '';
    168200                $Output = '<form action="?action=editsave&amp;id='.$_GET['id'].'" method="post"><table>'.
    169201                  '<tr><td>'.T('Web').'</td><td>'.$Item['Web'].'</td></tr>'.
    170                         '<tr><td>'.T('Visible').'</td><td><input type="checkbox" name="Show" '.$Show.'/></td></tr>'.
     202                        '<tr><td>'.T('Visible').'</td><td><input type="checkbox" name="Visible" '.$Visible.'/></td></tr>'.
    171203                        '<tr><td>'.T('Description').'</td><td><input type="text" name="Description" value="'.$Item['Description'].'"/></td></tr>'.
    172204                  '<tr><td>'.T('Parent item').'</td><td>'.$this->SelectParentItem($Item['Parent'], $Item['Id']).'</td></tr>'.
     205            '<tr><td>'.T('Last IP address').'</td><td><input type="text" name="LastIP" value="'.$Item['LastIP'].'"/></td></tr>'.
    173206                  '<tr><td colspan="2"><input type="submit" value="Uložit"/></td></tr></table></form>';
    174207              } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     
    181214  {
    182215          if($this->System->User->Licence(LICENCE_ADMIN))
    183           {             
     216          {
    184217                  if($_POST['Parent'] == '') $_POST['Parent'] = null;
    185                   $_POST['Show'] = array_key_exists('Show', $_POST);
     218                  $_POST['Visible'] = array_key_exists('Visible', $_POST);
    186219            $DbResult = $this->Database->update('Referrer', 'Id='.$_GET['id'], array(
    187                   'Show' => $_POST['Show'],
     220                  'Visible' => $_POST['VisNadřazená položka
     221Last IP address ible'], 'LastIP' => $_POST['LastIP'],
    188222                  'Parent' => $_POST['Parent'], 'Description' => $_POST['Description']));
    189223            $_SERVER['QUERY_STRING'] = '';
     
    200234    {
    201235      if($_GET['action'] == 'edit') $Output = $this->Edit();
     236      else if($_GET['action'] == 'spam') $Output = $this->Spam();
    202237      else if($_GET['action'] == 'editsave') $Output = $this->EditSave();
    203       else $Output = $this->ShowList();         
     238      else $Output = $this->ShowList();
    204239    } else $Output = $this->ShowList();
    205240    return($Output);
  • trunk/admin/UpdateTrace.php

    r795 r803  
    23472347  ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`Language`) REFERENCES `Language` (`Id`),
    23482348  ADD CONSTRAINT `User_ibfk_2` FOREIGN KEY (`Team`) REFERENCES `Team` (`Id`);");
    2349  
     2349
    23502350  $Manager->Execute('INSERT INTO `DbVersion` (`Id` ,`Revision`) VALUES ("1", "498")');
    23512351  $Manager->Execute('INSERT INTO `Language` (`Id` ,`Name` ,`Enabled`)VALUES (NULL , "Angličtina", 0);');
     
    24792479
    24802480function UpdateTo506($Manager)
    2481 {     
     2481{
    24822482  global $System;
    2483  
     2483
    24842484  $DbResult = $System->Database->query('SELECT `TablePrefix` FROM `Group`');
    24852485  while($Group = $DbResult->fetch_assoc())
     
    25142514
    25152515function UpdateTo510($Manager)
    2516 {     
     2516{
    25172517  $Manager->Execute('ALTER TABLE `News` ADD `Title` VARCHAR( 255 ) NOT NULL AFTER `Time`');
    25182518  $Manager->Execute('UPDATE `News` SET `Title` = (SELECT `Name` FROM `User` AS `T` WHERE `T`.`ID` = `User`)');
     
    25202520
    25212521function UpdateTo524($Manager)
    2522 {     
     2522{
    25232523  $Manager->Execute('ALTER TABLE `User` ADD `PreferredVersion` INT NULL DEFAULT NULL');
    25242524  $Manager->Execute('ALTER TABLE `User` ADD INDEX ( `PreferredVersion` )');
     
    25342534  while($DbRow = $DbResult->fetch_row())
    25352535  {
    2536     $Manager->Execute("ALTER TABLE `".$DbRow[0]."` CONVERT TO CHARACTER SET utf8"); 
    2537   } 
     2536    $Manager->Execute("ALTER TABLE `".$DbRow[0]."` CONVERT TO CHARACTER SET utf8");
     2537  }
    25382538}
    25392539
     
    25592559
    25602560function UpdateTo543($Manager)
    2561 { 
     2561{
    25622562  $Manager->Execute('ALTER TABLE `Group` ADD INDEX ( `Name` )');
    25632563}
    25642564
    25652565function UpdateTo567($Manager)
    2566 { 
     2566{
    25672567  $Manager->Execute('ALTER TABLE `Log` ADD `URL` VARCHAR( 255 ) NOT NULL ;');
    25682568}
    25692569
    25702570function UpdateTo574($Manager)
    2571 { 
     2571{
    25722572  $Manager->Execute('CREATE TABLE IF NOT EXISTS `WikiPage` (
    25732573                `Id` int(11) NOT NULL AUTO_INCREMENT,
     
    25972597
    25982598function UpdateTo585($Manager)
    2599 { 
     2599{
    26002600  $Manager->Execute('CREATE TABLE IF NOT EXISTS `APIToken` (
    26012601    `Id` int(11) NOT NULL AUTO_INCREMENT,
     
    26132613        $Manager->Execute("INSERT INTO `LogType` (`Id` ,`Name` ,`Color` ,`Description`)
    26142614VALUES (NULL , 'Nenalezené', 'teal', 'Nenalezené stránky');");
    2615 } 
     2615}
    26162616
    26172617function UpdateTo604($Manager)
     
    26462646`Code` = "en" WHERE `Language`.`Name` ="Angličitna";');
    26472647  $Manager->Execute('UPDATE `Language` SET `Code` = "cs" WHERE `Language`.`Name` ="Čeština";');
    2648   $Manager->Execute('UPDATE `Language` SET `Code` = "sk" WHERE `Language`.`Name` ="Slovenština";');   
     2648  $Manager->Execute('UPDATE `Language` SET `Code` = "sk" WHERE `Language`.`Name` ="Slovenština";');
    26492649}
    26502650
     
    26622662`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT ;');
    26632663  $Manager->Execute('ALTER TABLE `Server` ADD `CheckIP` VARCHAR( 16 ) NOT NULL ,
    2664 ADD `CheckPort` INT NOT NULL ;');   
     2664ADD `CheckPort` INT NOT NULL ;');
    26652665}
    26662666
     
    26732673function UpdateTo666($Manager)
    26742674{
    2675         $Manager->Execute('INSERT INTO `ExportOutputType` (`Id` ,`Name`) VALUES (\'10\' ,  \'Instalace - Instalační soubor pro klienta\');');   
    2676         $Manager->Execute('INSERT INTO `ExportVersion` (`Id` ,`ExportType` ,`ClientVersion`)VALUES (NULL ,  \'10\',  \'84\');');   
     2675        $Manager->Execute('INSERT INTO `ExportOutputType` (`Id` ,`Name`) VALUES (\'10\' ,  \'Instalace - Instalační soubor pro klienta\');');
     2676        $Manager->Execute('INSERT INTO `ExportVersion` (`Id` ,`ExportType` ,`ClientVersion`)VALUES (NULL ,  \'10\',  \'84\');');
    26772677}
    26782678
    26792679function UpdateTo678($Manager)
    26802680{
    2681         $Manager->Execute('INSERT INTO `ExportVersion` (`Id` ,`ExportType` ,`ClientVersion`)VALUES (NULL ,  \'10\',  \'11\');');   
     2681        $Manager->Execute('INSERT INTO `ExportVersion` (`Id` ,`ExportType` ,`ClientVersion`)VALUES (NULL ,  \'10\',  \'11\');');
    26822682}
    26832683
     
    26862686        $Manager->Execute('CREATE TABLE IF NOT EXISTS `ExportGroupItem` (`Id` int(11) NOT NULL AUTO_INCREMENT,'.
    26872687  '`Export` int(11) NOT NULL,`GroupItem` int(11) NOT NULL, PRIMARY KEY (`Id`), KEY `Export` (`Export`),'.
    2688   ' KEY `GroupItem` (`GroupItem`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;');   
     2688  ' KEY `GroupItem` (`GroupItem`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;');
    26892689        $Manager->Execute('ALTER TABLE `ExportGroupItem`'.
    26902690  'ADD CONSTRAINT `ExportGroupItem_ibfk_1` FOREIGN KEY (`Export`) REFERENCES `Export` (`Id`),'.
    2691   'ADD CONSTRAINT `ExportGroupItem_ibfk_2` FOREIGN KEY (`GroupItem`) REFERENCES `GroupItem` (`Id`);');   
     2691  'ADD CONSTRAINT `ExportGroupItem_ibfk_2` FOREIGN KEY (`GroupItem`) REFERENCES `GroupItem` (`Id`);');
    26922692}
    26932693
     
    27112711function UpdateTo716($Manager)
    27122712{
    2713         $Manager->Execute('ALTER TABLE  `Export` ADD  `Featured` TINYINT NOT NULL');   
     2713        $Manager->Execute('ALTER TABLE  `Export` ADD  `Featured` TINYINT NOT NULL');
    27142714}
    27152715
    27162716function UpdateTo725($Manager)
    27172717{
    2718         $Manager->Execute('ALTER TABLE `UserOnline` ADD `StayLoggedHash` VARCHAR( 40 ) NOT NULL ;');   
     2718        $Manager->Execute('ALTER TABLE `UserOnline` ADD `StayLoggedHash` VARCHAR( 40 ) NOT NULL ;');
    27192719}
    27202720
    27212721function UpdateTo731($Manager)
    27222722{
    2723         $Manager->Execute('ALTER TABLE  `ExportTask` ADD  `Progress` TINYINT NOT NULL ;');   
     2723        $Manager->Execute('ALTER TABLE  `ExportTask` ADD  `Progress` TINYINT NOT NULL ;');
    27242724}
    27252725
    27262726function UpdateTo732($Manager)
    27272727{
    2728         $Manager->Execute('ALTER TABLE  `ExportTask` CHANGE  `Progress`  `Progress` DOUBLE( 4, 2 ) NOT NULL ;');   
     2728        $Manager->Execute('ALTER TABLE  `ExportTask` CHANGE  `Progress`  `Progress` DOUBLE( 4, 2 ) NOT NULL ;');
    27292729}
    27302730
     
    28002800}
    28012801
     2802function UpdateTo803($Manager)
     2803{
     2804  $Manager->Execute('ALTER TABLE `Referrer` CHANGE `Show` `Visible` INT( 11 ) NOT NULL DEFAULT "1";');
     2805  $Manager->Execute('ALTER TABLE `Referrer` ADD `LastIP` VARCHAR( 16 ) NOT NULL ;');
     2806}
     2807
    28022808$Updates = array(
    28032809        498 => array('Revision' => 506, 'Function' => 'UpdateTo506'),
     
    28152821        609 => array('Revision' => 610, 'Function' => 'UpdateTo610'),
    28162822        610 => array('Revision' => 639, 'Function' => 'UpdateTo639'),
    2817         639 => array('Revision' => 646 , 'Function' => 'UpdateTo646'),
    2818         646 => array('Revision' => 666 , 'Function' => 'UpdateTo666'),
    2819         666 => array('Revision' => 678 , 'Function' => 'UpdateTo678'),
    2820         678 => array('Revision' => 695 , 'Function' => 'UpdateTo695'),
    2821         695 => array('Revision' => 712 , 'Function' => 'UpdateTo712'),
    2822         712 => array('Revision' => 716 , 'Function' => 'UpdateTo716'),
    2823         716 => array('Revision' => 725 , 'Function' => 'UpdateTo725'),
    2824         725 => array('Revision' => 731 , 'Function' => 'UpdateTo731'),
    2825         731 => array('Revision' => 732 , 'Function' => 'UpdateTo732'),
    2826         732 => array('Revision' => 748 , 'Function' => 'UpdateTo748'),
    2827   748 => array('Revision' => 787 , 'Function' => 'UpdateTo787'),
     2823        639 => array('Revision' => 646, 'Function' => 'UpdateTo646'),
     2824        646 => array('Revision' => 666, 'Function' => 'UpdateTo666'),
     2825        666 => array('Revision' => 678, 'Function' => 'UpdateTo678'),
     2826        678 => array('Revision' => 695, 'Function' => 'UpdateTo695'),
     2827        695 => array('Revision' => 712, 'Function' => 'UpdateTo712'),
     2828        712 => array('Revision' => 716, 'Function' => 'UpdateTo716'),
     2829        716 => array('Revision' => 725, 'Function' => 'UpdateTo725'),
     2830        725 => array('Revision' => 731, 'Function' => 'UpdateTo731'),
     2831        731 => array('Revision' => 732, 'Function' => 'UpdateTo732'),
     2832        732 => array('Revision' => 748, 'Function' => 'UpdateTo748'),
     2833  748 => array('Revision' => 787, 'Function' => 'UpdateTo787'),
     2834  787 => array('Revision' => 803, 'Function' => 'UpdateTo803'),
    28282835);
  • trunk/includes/Version.php

    r802 r803  
    66// and system will need database update.
    77
    8 $Revision = 802; // Subversion revision
    9 $DatabaseRevision = 787; // Database structure revision
    10 $ReleaseTime = '2014-04-04';
     8$Revision = 803; // Subversion revision
     9$DatabaseRevision = 803; // Database structure revision
     10$ReleaseTime = '2014-04-14';
Note: See TracChangeset for help on using the changeset viewer.