configure email for sending comment notifications

This commit is contained in:
Milan
2020-04-26 22:21:03 +02:00
parent ad9e27418a
commit d3fe389af3
2 changed files with 34 additions and 30 deletions

View File

@@ -21,8 +21,6 @@ my $r = shift;
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::getFromScriptLocation(); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug};
my $request = { my $request = {
url => $ENV{QUERY_STRING}, url => $ENV{QUERY_STRING},
params => { params => {
@@ -51,14 +49,15 @@ $comment->{content} =~ s/(^|\s)((www\.)(.*?))(\s|$|\<)/$1\<a href\=\"http\:\/\/$
if ( comments::check( $dbh, $config, $comment ) ) { if ( comments::check( $dbh, $config, $comment ) ) {
my $nslookup = nslookup(); my $nslookup = nslookup();
#if (is_blocked($nslookup)==1){ if (is_blocked($nslookup)==1){
# send_mail($comment, $nslookup, 'blocked'); send_mail($comment, $nslookup, 'blocked');
# return; return;
#}; };
$comment->{comment_id} = comments::insert( $dbh, $config, $comment ); $comment->{comment_id} = comments::insert( $dbh, $config, $comment );
if ( $comment->{comment_id} > 0 ) { if ( $comment->{comment_id} > 0 ) {
comments::update_comment_count( $dbh, $config, $comment ); comments::update_comment_count( $dbh, $config, $comment );
send_mail( $comment, $nslookup, 'new' ); send_mail( $config, $comment, $nslookup, 'new' );
} }
} }
@@ -67,18 +66,16 @@ sub is_blocked {
my $user_agent = $ENV{HTTP_USER_AGENT}; my $user_agent = $ENV{HTTP_USER_AGENT};
my $block = 0; # add lock settings here
$block = 1 # return 1 if
if ( $user_agent eq 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0) Gecko/20100101 Firefox/35.0' ) # ( $user_agent eq 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0) Gecko/20100101 Firefox/35.0' )
&& ( $nslookup =~ /alicedsl/ ); # && ( $nslookup =~ /alicedsl/ );
$block = 1 return 0;
if $user_agent eq
'Mozilla/5.0 (Linux; Android 8.0.0; ANE-LX1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Mobile Safari/537.36';
return $block;
} }
sub send_mail { sub send_mail {
my $config = shift;
my $comment = shift; my $comment = shift;
my $nslookup = shift; my $nslookup = shift;
my $status = shift || 'new'; my $status = shift || 'new';
@@ -87,10 +84,12 @@ sub send_mail {
my $user_agent = $ENV{HTTP_USER_AGENT} || ''; my $user_agent = $ENV{HTTP_USER_AGENT} || '';
my $cookie = $ENV{HTTP_COOKIE} || ''; my $cookie = $ENV{HTTP_COOKIE} || '';
my $from = 'no-reply@localhost'; my $locations = $config->{locations};
my $to = 'info@localhost'; my $base_domain = $locations->{base_domain};
my $from = $locations->{email};
my $to = $locations->{email};
my $subject = "$status comment from '$comment->{author}': $comment->{content}"; my $subject = "$status comment from '$comment->{author}': $comment->{content}";
my $content = "$status comment my $content = qq!$status comment
FROM: '$comment->{author}' FROM: '$comment->{author}'
EMAIL: $comment->{email} EMAIL: $comment->{email}
@@ -98,17 +97,17 @@ EMAIL: $comment->{email}
CONTENT: '$comment->{content}' CONTENT: '$comment->{content}'
view event view event
https://localhost/programm/sendung/$comment->{event_id}.html#comments $base_domain/programm/sendung/$comment->{event_id}.html#comments
"; !;
if ( $status eq 'new' ) { if ( $status eq 'new' ) {
$content .= " $content .= qq!
manage comments: manage comments:
https://localhost/agenda/planung/comment.cgi?project_id=1&studio_id=1 $base_domain/agenda/planung/comment.cgi?project_id=1&studio_id=1
lock this comment lock this comment
https://localhost/agenda/planung/comment.cgi?event_id=$comment->{event_id}&comment_id=$comment->{comment_id}&set_lock_status=blocked $base_domain/agenda/planung/comment.cgi?event_id=$comment->{event_id}&comment_id=$comment->{comment_id}&set_lock_status=blocked
"; !;
} }
$content .= qq{ $content .= qq{
@@ -174,12 +173,12 @@ sub check_params {
$comment->{content} = $params->{'content'} || ''; $comment->{content} = $params->{'content'} || '';
$comment->{content} = escape_text( $comment->{content} ); $comment->{content} = escape_text( $comment->{content} );
$comment->{content} = substr( $comment->{content}, 0, 1000 ); $comment->{content} = substr( $comment->{content}, 0, 1000 );
log::error( $config, 'add_comment.cgi: missing body' ) if ( $comment->{content} eq '' ); log::error( $config, 'add_comment.cgi: missing body' ) if $comment->{content} eq '';
$comment->{author} = $params->{'author'} || ''; $comment->{author} = $params->{'author'} || '';
$comment->{author} = escape_text( $comment->{author} ); $comment->{author} = escape_text( $comment->{author} );
$comment->{author} = substr( $comment->{author}, 0, 40 ); $comment->{author} = substr( $comment->{author}, 0, 40 );
log::error( $config, 'add_comment.cgi: missing name' ) if ( $comment->{author} eq '' ); log::error( $config, 'add_comment.cgi: missing name' ) if $comment->{author} eq '';
$comment->{email} = $params->{'email'} || ''; $comment->{email} = $params->{'email'} || '';
$comment->{email} = escape_text( $comment->{email} ); $comment->{email} = escape_text( $comment->{email} );
@@ -190,16 +189,18 @@ sub check_params {
$comment->{title} = substr( $comment->{title}, 0, 80 ); $comment->{title} = substr( $comment->{title}, 0, 80 );
$comment->{ip} = $ENV{REMOTE_ADDR} || ''; $comment->{ip} = $ENV{REMOTE_ADDR} || '';
log::error( $config, 'missing ip' ) if ( $comment->{ip} eq '' ); log::error( $config, 'missing ip' ) if $comment->{ip} eq '';
$comment->{ip} = Digest::MD5::md5_base64( $comment->{ip} ); $comment->{ip} = Digest::MD5::md5_base64( $comment->{ip} );
my $today = time::datetime_to_array( time::time_to_datetime() ); my $today = time::datetime_to_array( time::time_to_datetime() );
my $date = time::datetime_to_array( $comment->{event_start} ); my $date = time::datetime_to_array( $comment->{event_start} );
my $delta_days = time::days_between( $today, $date ); my $delta_days = time::days_between( $today, $date );
log::error( $config, 'add_comment.cgi: no comments allowed, yet' ) log::error( $config, 'add_comment.cgi: no comments allowed, yet' )
if ( $delta_days > $config->{permissions}->{no_new_comments_before} ); if $delta_days > $config->{permissions}->{no_new_comments_before};
log::error( $config, 'add_comment.cgi: no comments allowed anymore' ) log::error( $config, 'add_comment.cgi: no comments allowed anymore' )
if ( $delta_days < -1 * $config->{permissions}->{no_new_comments_after} ); if $delta_days < -1 * $config->{permissions}->{no_new_comments_after};
return { return {
template => $template, template => $template,

View File

@@ -11,6 +11,7 @@ Define LOG_DIR /home/radio/log
# default project from database # default project from database
project Corax project Corax
domain ${DOMAIN}
<filter> <filter>
# projects_to_exclude project1 # projects_to_exclude project1
@@ -80,6 +81,8 @@ project Corax
# multi language support # multi language support
admin_pot_dir ${BASE_DIR}/agenda/planung/pot/ admin_pot_dir ${BASE_DIR}/agenda/planung/pot/
email info@${DOMAIN}
</locations> </locations>
<permissions> <permissions>