diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php index 38c91c167..fbbe80d50 100644 --- a/include/picture_comment.inc.php +++ b/include/picture_comment.inc.php @@ -2,10 +2,10 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) -// | file : $RCSfile$ +// | file : $Id$ // | last update : $Date$ // | last modifier : $Author$ // | revision : $Revision$ @@ -29,6 +29,33 @@ * This file is included by the picture page to manage user comments * */ + +if (!function_exists('hash_hmac')) +{ +function hash_hmac($algo, $data, $key, $raw_output=false) +{ + /* md5 and sha1 only */ + $algo=strtolower($algo); + $p=array('md5'=>'H32','sha1'=>'H40'); + if ( !isset($p[$algo]) or !function_exists($algo) ) + { + $algo = 'md5'; + } + if(strlen($key)>64) $key=pack($p[$algo],$algo($key)); + if(strlen($key)<64) $key=str_pad($key,64,chr(0)); + + $ipad=substr($key,0,64) ^ str_repeat(chr(0x36),64); + $opad=substr($key,0,64) ^ str_repeat(chr(0x5C),64); + + $ret = $algo($opad.pack($p[$algo],$algo($ipad.$data))); + if ($raw_output) + { + $ret = pack('H*', $ret); + } + return $ret; +} +} + //returns string action to perform on a new comment: validate, moderate, reject function user_comment_check($action, $comment, $picture) { @@ -137,6 +164,15 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) ) $comment_action='reject'; } + $key = explode(':', @$_POST['key']); + if ( count($key)!=2 + or $key[0]>time() or $key[0]0 ) { // anti-flood system $reference_date = time() - $conf['anti-flood_time']; @@ -316,7 +352,12 @@ SELECT id,author,date,image_id,content if (!$user['is_the_guest'] or ($user['is_the_guest'] and $conf['comments_forall'])) { - $template->assign_block_vars('comments.add_comment', array()); + $key = time(); + $key .= ':'.hash_hmac('md5', $key, $conf['secret_key']); + $template->assign_block_vars('comments.add_comment', + array( + 'key' => $key + )); // display author field if the user is not logged in if ($user['is_the_guest']) { diff --git a/install/config.sql b/install/config.sql index 53753a8d4..9c4dbc743 100644 --- a/install/config.sql +++ b/install/config.sql @@ -23,6 +23,7 @@ INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('history_admin',' INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('history_guest','true','keep a history of guest visits on your website'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('login_history','true','keep a history of user logins on your website'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('allow_user_registration','true','allow visitors to register?'); +INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('secret_key', MD5(RAND()), 'a secret key specific to the gallery for internal use'); -- Notification by mail INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nbm_send_mail_as','','Send mail as param value for notification by mail'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('nbm_send_detailed_content','true','Send detailed content for notification by mail'); diff --git a/install/db/43-database.php b/install/db/43-database.php new file mode 100644 index 000000000..1e51bb99e --- /dev/null +++ b/install/db/43-database.php @@ -0,0 +1,51 @@ + diff --git a/template/yoga/picture.tpl b/template/yoga/picture.tpl index 02453e9af..f42fc83ae 100644 --- a/template/yoga/picture.tpl +++ b/template/yoga/picture.tpl @@ -190,7 +190,8 @@ - + +