b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file b2antispam.php

Documentation is available at b2antispam.php

  1. <?php
  2. /**
  3.  * Antispam blacklist handling
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package admin
  10.  */
  11.  
  12. /**
  13.  * Includes:
  14.  */
  15. require_once (dirname(__FILE__).'/_header.php');
  16. require_once (dirname(__FILE__).'/'.$admin_dirout.'/'.$core_subdir.'/_functions_antispam.php');
  17.  
  18. $admin_tab 'antispam';
  19. $admin_pagetitle T_('Antispam');
  20.  
  21. param'action''string' );
  22. param'confirm''string' );
  23. param'keyword''string' );
  24. param'disp_blacklist''integer');
  25.  
  26. require(dirname(__FILE__).'/_menutop.php');
  27. require(dirname(__FILE__).'/_menutop_end.php');
  28.  
  29. // Check permission:
  30. $current_User->check_perm'spamblacklist''view'true );
  31.  
  32. switch$action )
  33. {
  34.     case 'ban':
  35.         // Check permission:
  36.         $current_User->check_perm'spamblacklist''edit'true );
  37.  
  38.         $keyword substr$keyword080 );
  39.         param'delhits''integer');
  40.         param'delcomments''integer');
  41.         param'blacklist''integer');
  42.         param'report''integer');
  43.  
  44.         // Check if the string is too short,
  45.         // it has to be a minimum of 5 characters to avoid being too generic
  46.         ifstrlen($keyword)
  47.         {
  48.             echo '<div class="panelinfo">';
  49.             printf'<p>'.T_('The keyword [%s] is too short, it has to be a minimum of 5 characters!').'</p>'htmlspecialchars($keyword) );
  50.             echo '</div>';
  51.             break;
  52.         }
  53.  
  54.         if$delhits && $deluxe_ban )
  55.         {    // Delete all banned hit-log entries
  56.             echo '<div class="panelinfo">';
  57.             printf'<h3>'.T_('Deleting log-hits matching [%s]...').'</h3>'htmlspecialchars($keyword) );
  58.             // Stats entries first
  59.             $sql 'DELETE FROM T_hitlog
  60.                             WHERE referingURL LIKE '.$DB->quote('%'.$keyword.'%');
  61.             $DB->query($sql);
  62.             echo '</div>';
  63.         }
  64.  
  65.         if$delcomments && $deluxe_ban )
  66.         // Then all banned comments
  67.             echo '<div class="panelinfo">';
  68.             printf'<h3>'.T_('Deleting comments matching [%s]...').'</h3>'htmlspecialchars($keyword) );
  69.             $sql 'DELETE FROM T_comments
  70.                             WHERE comment_author LIKE '.$DB->quote('%'.$keyword.'%').'
  71.                                  OR comment_author_url LIKE '.$DB->quote('%'.$keyword.'%').'
  72.                          OR comment_content LIKE '.$DB->quote('%'.$keyword.'%');
  73.             $DB->query($sql);
  74.             echo '</div>';
  75.         }
  76.  
  77.         if$blacklist )
  78.         {    // Local blacklist:
  79.             echo '<div class="panelinfo">';
  80.             printf'<h3>'.T_('Blacklisting the keyword [%s]...').'</h3>'htmlspecialchars($keyword) );
  81.             // Insert into DB:
  82.             antispam_create$keyword );
  83.             echo '</div>';
  84.         }
  85.  
  86.         if$report && $report_abuse )
  87.         // Report this keyword as abuse:
  88.             b2evonet_report_abuse$keyword );
  89.         }
  90.  
  91.         if!$delhits || $delcomments || $blacklist || $report ) )
  92.         {    // Nothing to do, ask user:
  93.             ?>
  94.             <div class="panelblock">
  95.                 <form action="b2antispam.php" method="post">
  96.                 <input type="hidden" name="confirm" value="confirm" />
  97.                 <input type="hidden" name="keyword" value="<?php echo format_to_output$keyword'formvalue' ?>" />
  98.                 <input type="hidden" name="action" value="ban" />
  99.                 <h2><?php echo T_('Confirm ban &amp; delete'?></h2>
  100.  
  101.                 <?php
  102.                 if$deluxe_ban )
  103.                 {    // We can we autodelete junk, check for junk:
  104.                     // Check for potentially affected log hits:
  105.                     $sql 'SELECT visitID, UNIX_TIMESTAMP(visitTime) AS visitTime, referingURL,
  106.                                                  baseDomain, hit_blog_ID, visitURL, hit_remote_addr
  107.                                       FROM T_hitlog
  108.                                      WHERE referingURL LIKE '.$DB->quote('%'.$keyword.'%').'
  109.                                      ORDER BY hit_remote_addr ASC, baseDomain ASC, visitTime DESC';
  110.                     $res_affected_hits $DB->get_results$sqlARRAY_A );
  111.                     if$DB->num_rows == )
  112.                     {    // No matching hits.
  113.                         printf'<p><strong>'.T_('No log-hits match the keyword [%s].').'</strong></p>'htmlspecialchars($keyword) );
  114.                     }
  115.                     else
  116.                     {
  117.                     ?>
  118.                         <p><strong><input type="checkbox" name="delhits" value="1" checked="checked" />
  119.                         <?php printf T_('Delete the following %d referer hits:')$DB->num_rows ?>
  120.                         </strong></p>
  121.                         <table class="grouped" cellspacing="0">
  122.                             <thead>
  123.                             <tr>
  124.                                 <th><?php echo T_('Date'?></th>
  125.                                 <th><?php echo T_('Referer'?></th>
  126.                                 <th><?php echo T_('Ref. IP'?></th>
  127.                                 <th><?php echo T_('Target Blog'?></th>
  128.                                 <th><?php echo T_('Target URL'?></th>
  129.                             </tr>
  130.                             </thead>
  131.                             <tbody>
  132.                             <?php
  133.                             $count 0;
  134.                             foreach$res_affected_hits as $row_stats )
  135.                             {  ?>
  136.                    <tr <?php if($count%== 1echo 'class="odd"' ?>>
  137.                                 <td class="firstcol"><?php stats_time(?></td>
  138.                                 <td><a href="<?php stats_referer(?>"><?php stats_basedomain(?></a></td>
  139.                                 <td><?php stats_hit_remote_addr(?></td>
  140.                                 <td><?php stats_blog_name(?></td>
  141.                                 <td><a href="<?php stats_req_URI(?>"><?php stats_req_URI(?></a></td>
  142.                             </tr>
  143.                             <?php
  144.               $count++;
  145.               // End stat loop ?>
  146.               </tbody>
  147.                         </table>
  148.                     <?php
  149.                     }
  150.  
  151.                     // Check for potentially affected comments:
  152.                     $sql 'SELECT comment_ID, comment_date, comment_author, comment_author_url,
  153.                                                     comment_author_IP, comment_content
  154.                                     FROM T_comments
  155.                                     WHERE comment_author LIKE '.$DB->quote('%'.$keyword.'%').'
  156.                                          OR comment_author_url LIKE '.$DB->quote('%'.$keyword.'%').'
  157.                                  OR comment_content LIKE '.$DB->quote('%'.$keyword.'%').'
  158.                                     ORDER BY comment_author_IP ASC, comment_author_url ASC, comment_date DESC';
  159.                     $res_affected_comments $DB->get_results$sqlARRAY_A );
  160.                     if$DB->num_rows == )
  161.                     {    // No matching hits.
  162.                         printf'<p><strong>'.T_('No comments match the keyword [%s].').'</strong></p>'htmlspecialchars($keyword) );
  163.                     }
  164.                     else
  165.                     {
  166.                     ?>
  167.                         <p><strong><input type="checkbox" name="delcomments" value="1" checked="checked" />
  168.                         <?php printf T_('Delete the following %d comments:')count($res_affected_comments) ) ?>
  169.                         </strong></p>
  170.                         <table class="grouped" cellspacing="0">
  171.                             <thead>
  172.                             <tr>
  173.                                 <th><?php echo T_('Date'?></th>
  174.                                 <th><?php echo T_('Author'?></th>
  175.                                 <th><?php echo T_('Auth. URL'?></th>
  176.                                 <th><?php echo T_('Auth. IP'?></th>
  177.                                 <th><?php echo T_('Content starts with...'?></th>
  178.                             </tr>
  179.                             </thead>
  180.                             <tbody>
  181.                             <?php
  182.                             $count 0;
  183.               foreach$res_affected_comments as $row_stats )
  184.                             // TODO: new Comment( $row_stats ) ?>
  185.                    <tr <?php if($count%== 1echo 'class="odd"' ?>>
  186.                                 <td class="firstcol"><?php echo mysql2date(locale_datefmt().' '.locale_timefmt()$row_stats['comment_date')?></td>
  187.                                 <td><?php echo $row_stats['comment_author'?></a></td>
  188.                                 <td><?php echo $row_stats['comment_author_url'?></td>
  189.                                 <td><?php echo $row_stats['comment_author_IP'?></td>
  190.                                 <td><?php
  191.                                 $comment_content strip_tags$row_stats['comment_content');
  192.                                 if strlen($comment_content70 )
  193.                                 {
  194.                                     // Trail off (truncate and add '...') after 70 chars
  195.                                     echo substr($comment_content070"...";
  196.                                 }
  197.                                 else
  198.                                 {
  199.                                     echo $comment_content;
  200.                                 }
  201.                                 ?></td>
  202.                             </tr>
  203.                             <?php
  204.               $count++;
  205.               // End stat loop ?>
  206.                             </tbody>
  207.                         </table>
  208.                     <?php
  209.                     }
  210.                 }
  211.  
  212.                 // Check if the string is already in the blacklist:
  213.                 ifantispam_check($keyword) )
  214.                 // Already there:
  215.                     printf'<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>'htmlspecialchars($keyword) );
  216.                 }
  217.                 else
  218.                 // Not in blacklist
  219.                   ?>
  220.                     <p><strong><input type="checkbox" name="blacklist" value="1" checked="checked" />
  221.                     <?php printf T_('Blacklist the keyword [%s] locally.')htmlspecialchars($keyword) ) ?>
  222.                     </strong></p>
  223.  
  224.                     <?php if$report_abuse )
  225.                     ?>
  226.                         <p>
  227.                         <strong><input type="checkbox" name="report" value="1" checked="checked" />
  228.                         <?php printf T_('Report the keyword [%s] as abuse to b2evolution.net.')htmlspecialchars($keyword) ) ?>
  229.                         </strong>
  230.                         [<a href="http://b2evolution.net/about/terms.html"><?php echo T_('Terms of service'?></a>]
  231.                         </p>
  232.                     <?php
  233.                     }
  234.                 }
  235.                 ?>
  236.  
  237.                 <input type="submit" value="<?php echo T_('Perform selected operations'?>" class="search" />
  238.                 </form>
  239.             </div>
  240.             <?php
  241.         }
  242.         break;
  243.  
  244.  
  245.     case 'remove':
  246.         // Remove a domain from ban list:
  247.  
  248.         // Check permission:
  249.         $current_User->check_perm'spamblacklist''edit'true );
  250.  
  251.         param'hit_ID''integer'true );    // Required!
  252.         ?>
  253.         <div class="panelinfo">
  254.             <p><?php printfT_('Removing entry #%d from the ban list...')$hit_ID?></p>
  255.             <?php
  256.             antispam_delete$hit_ID );
  257.             ?>
  258.         </div>
  259.         <?php
  260.         break;
  261.  
  262.  
  263.     case 'report':
  264.         // Report an entry as abuse to centralized blacklist:
  265.  
  266.         // Check permission:
  267.         $current_User->check_perm'spamblacklist''edit'true );
  268.  
  269.         // Report this keyword as abuse:
  270.         b2evonet_report_abuse$keyword );
  271.         break;
  272.  
  273.  
  274.     case 'poll':
  275.         // request abuse list from central blacklist:
  276.  
  277.         // Check permission:
  278.         $current_User->check_perm'spamblacklist''edit'true );
  279.  
  280.         b2evonet_poll_abuse);
  281.         break;
  282. }
  283.  
  284.  
  285. // ADD KEYWORD FORM:
  286. if$current_User->check_perm'spamblacklist''edit' ) )
  287. ?>
  288.     <div class="panelblock">
  289.         <form action="b2antispam.php" method="get" class="fform">
  290.             <input type="hidden" name="action" value="ban" />
  291.             <input type="hidden" name="type" value="keyword" />
  292.             <label for="keyword"><strong><?php echo T_('Add a banned keyword'?>:</strong></label>
  293.             <input type="text" name="keyword" id="keyword" size="30" maxlength="80" value="<?php echo format_to_output$keyword'formvalue')?>" />
  294.             <input type="submit" value="<?php echo T_('Check &amp; ban...'?>" class="search" />
  295.         </form>
  296.     </div>
  297. <?php
  298. }
  299. ?>
  300.  
  301.  
  302. <div class="panelblock">
  303.     <h2><?php echo T_('Banned domains blacklist'?></h2>
  304.     <p class="center"><?php echo T_('Any URL containing one of the following keywords will be banned from posts, comments and logs.');
  305.     if$current_User->check_perm'spamblacklist''edit' ) )
  306.     {
  307.         echo '<br />'.T_'If a keyword restricts legitimate domains, click on the green tick to stop banning with this keyword.');
  308.     }
  309.     ?></p>
  310.     <?php list_antiSpam(?>
  311.     <?php if$current_User->check_perm'spamblacklist''edit' ) )
  312.     ?>
  313.         <p class="center">
  314.             [<a href="b2antispam.php?action=poll"><?php echo T_('Request abuse update from centralized blacklist!'?></a>]
  315.             [<a href="http://b2evolution.net/about/terms.html"><?php echo T_('Terms of service'?></a>]
  316.         </p>
  317.     <?php }
  318.  
  319.  
  320.     if$disp_blacklist && (count($res_stats100) )
  321.     {    // We haven't requested the list
  322.         echo '<p class="center"><strong>'.sprintfT_('The blacklist contains more than 100 items. [<a %s>Click here to display</a>].'),
  323.                     'href="b2antispam.php?disp_blacklist=1"' ).'</strong></p>';
  324.     }
  325.     else
  326.     {    // The list is short enough to be displayed without being annoying
  327.         $disp_blacklist 1;
  328.     }
  329.  
  330.     if$disp_blacklist )
  331.     {    // Blacklist display is requested:
  332.      ?>
  333.         <table class="grouped" cellspacing="0">
  334.             <?php
  335.             $count 0;
  336.         ifcount($res_stats) ) foreach$res_stats as $row_stats )
  337.             {  ?>
  338.             <tr <?php if($count%== 1echo 'class="odd"' ?>>
  339.                 <td class="firstcol">
  340.                     <?php if$current_User->check_perm'spamblacklist''edit' ) )
  341.                     ?>
  342.                     <a href="b2antispam.php?action=remove&amp;hit_ID=<?php antiSpam_ID(?>" title="<?php echo T_('Allow keyword back (Remove it from the blacklist)'?>"><img src="img/tick.gif" width="13" height="13" class="middle" alt="<?php echo T_('Allow Back'?>" /></a>
  343.                     <?php }
  344.                     antiSpam_domain40 );
  345.                     ?>
  346.                 </td>
  347.                 <td><?php antispam_source()?></td>
  348.                 <td><?php
  349.                         if( (antispam_source(false,true== 'local')
  350.                             && $current_User->check_perm'spamblacklist''edit' ) )
  351.                         {
  352.                         ?>
  353.                         [<a href="b2antispam.php?action=report&amp;keyword=<?php echo urlencodeantiSpam_domain(false) ) ?>" title="<?php echo T_('Report abuse to centralized ban blacklist!'?>"><?php echo T_('Report'?></a>]
  354.                     <?php ?>
  355.                     [<a href="b2antispam.php?action=ban&amp;keyword=<?php echo urlencodeantiSpam_domain(false) ) ?>" title="<?php echo T_('Check hit-logs and comments for this keyword!'?>"><?php echo T_('Re-check'?></a>]
  356.                 </td>
  357.             </tr>
  358.             <?php
  359.         $count++;
  360.         // End stat loop ?>
  361.         </table>
  362.         <?php
  363.     }
  364.     ?>
  365. </div>
  366. <?php
  367. requiredirname(__FILE__).'/_footer.php' );
  368. ?>

Documentation generated on Tue, 20 May 2008 01:51:12 +0200 by phpDocumentor 1.4.2