Ignore:
Timestamp:
Jan 23, 2007, 2:22:52 AM (17 years ago)
Author:
rvelices
Message:
  • revert feature 564: log the login of each user; but add the possibility to be

done by a plugin

  • create a "standard" way to define PHP functions that we use but might not be

available in the current php version

  • when a comment is rejected (spam, anti-flood etc), put the content back to the

browser in case there is a real user behind it

  • now a comment can be entered only if the page was retrieved between 2 seconds

ago and 1 hour ago

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/picture_comment.inc.php

    r1737 r1744  
    3131 */
    3232
    33 if (!function_exists('hash_hmac'))
    34 {
    35 function hash_hmac($algo, $data, $key, $raw_output=false)
    36 {
    37   /* md5 and sha1 only */
    38   $algo=strtolower($algo);
    39   $p=array('md5'=>'H32','sha1'=>'H40');
    40   if ( !isset($p[$algo]) or !function_exists($algo) )
    41   {
    42     $algo = 'md5';
    43   }
    44   if(strlen($key)>64) $key=pack($p[$algo],$algo($key));
    45   if(strlen($key)<64) $key=str_pad($key,64,chr(0));
    46 
    47   $ipad=substr($key,0,64) ^ str_repeat(chr(0x36),64);
    48   $opad=substr($key,0,64) ^ str_repeat(chr(0x5C),64);
    49 
    50   $ret = $algo($opad.pack($p[$algo],$algo($ipad.$data)));
    51   if ($raw_output)
    52   {
    53     $ret = pack('H*', $ret);
    54   }
    55   return $ret;
    56 }
    57 }
    58 
    5933//returns string action to perform on a new comment: validate, moderate, reject
    6034function user_comment_check($action, $comment, $picture)
     
    167141  $key = explode(':', @$_POST['key']);
    168142  if ( count($key)!=2
    169         or $key[0]>time() or $key[0]<time()-1800 // 30 minutes expiration
     143        or $key[0]>time()-2 // page must have been retrieved more than 2 sec ago
     144        or $key[0]<time()-3600 // 60 minutes expiration
    170145        or hash_hmac('md5', $key[0], $conf['secret_key'])!=$key[1]
    171146      )
     
    258233  else
    259234  {
     235    set_status_header(403);
    260236    $template->assign_block_vars('information',
    261237          array('INFORMATION'=>l10n('comment_not_added') )
     
    355331    $key = time();
    356332    $key .= ':'.hash_hmac('md5', $key, $conf['secret_key']);
     333    $content = '';
     334    if ('reject'===@$comment_action)
     335    {
     336      $content = htmlspecialchars($comm['content']);
     337    }
    357338    $template->assign_block_vars('comments.add_comment',
    358339        array(
    359           'key' => $key
     340          'KEY' => $key,
     341          'CONTENT' => $content
    360342        ));
    361343    // display author field if the user is not logged in
Note: See TracChangeset for help on using the changeset viewer.