From d3fe389af3aa59508ffd1fcae0afef9221526131 Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 26 Apr 2020 22:21:03 +0200 Subject: [PATCH] configure email for sending comment notifications --- website/agenda/add_comment.cgi | 61 ++++++++++++++-------------- website/agenda/config/config.cgi.off | 3 ++ 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/website/agenda/add_comment.cgi b/website/agenda/add_comment.cgi index 4af930b..9112906 100755 --- a/website/agenda/add_comment.cgi +++ b/website/agenda/add_comment.cgi @@ -21,8 +21,6 @@ my $r = shift; ( my $cgi, my $params, my $error ) = params::get($r); my $config = config::getFromScriptLocation(); -my $debug = $config->{system}->{debug}; - my $request = { url => $ENV{QUERY_STRING}, params => { @@ -51,14 +49,15 @@ $comment->{content} =~ s/(^|\s)((www\.)(.*?))(\s|$|\<)/$1\{comment_id} = comments::insert( $dbh, $config, $comment ); if ( $comment->{comment_id} > 0 ) { 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 $block = 0; - $block = 1 - if ( $user_agent eq 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0) Gecko/20100101 Firefox/35.0' ) - && ( $nslookup =~ /alicedsl/ ); + # add lock settings here + # return 1 if + # ( $user_agent eq 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:35.0) Gecko/20100101 Firefox/35.0' ) + # && ( $nslookup =~ /alicedsl/ ); - $block = 1 - 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; + return 0; } sub send_mail { + my $config = shift; my $comment = shift; my $nslookup = shift; my $status = shift || 'new'; @@ -87,10 +84,12 @@ sub send_mail { my $user_agent = $ENV{HTTP_USER_AGENT} || ''; my $cookie = $ENV{HTTP_COOKIE} || ''; - my $from = 'no-reply@localhost'; - my $to = 'info@localhost'; - my $subject = "$status comment from '$comment->{author}': $comment->{content}"; - my $content = "$status comment + my $locations = $config->{locations}; + my $base_domain = $locations->{base_domain}; + my $from = $locations->{email}; + my $to = $locations->{email}; + my $subject = "$status comment from '$comment->{author}': $comment->{content}"; + my $content = qq!$status comment FROM: '$comment->{author}' EMAIL: $comment->{email} @@ -98,17 +97,17 @@ EMAIL: $comment->{email} CONTENT: '$comment->{content}' view event -https://localhost/programm/sendung/$comment->{event_id}.html#comments -"; +$base_domain/programm/sendung/$comment->{event_id}.html#comments +!; if ( $status eq 'new' ) { - $content .= " + $content .= qq! 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 -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{ @@ -174,12 +173,12 @@ sub check_params { $comment->{content} = $params->{'content'} || ''; $comment->{content} = escape_text( $comment->{content} ); $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} = escape_text( $comment->{author} ); $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} = escape_text( $comment->{email} ); @@ -190,16 +189,18 @@ sub check_params { $comment->{title} = substr( $comment->{title}, 0, 80 ); $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} ); my $today = time::datetime_to_array( time::time_to_datetime() ); my $date = time::datetime_to_array( $comment->{event_start} ); my $delta_days = time::days_between( $today, $date ); + 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' ) - if ( $delta_days < -1 * $config->{permissions}->{no_new_comments_after} ); + if $delta_days < -1 * $config->{permissions}->{no_new_comments_after}; return { template => $template, diff --git a/website/agenda/config/config.cgi.off b/website/agenda/config/config.cgi.off index 56a332f..478ce71 100755 --- a/website/agenda/config/config.cgi.off +++ b/website/agenda/config/config.cgi.off @@ -11,6 +11,7 @@ Define LOG_DIR /home/radio/log # default project from database project Corax +domain ${DOMAIN} # projects_to_exclude project1 @@ -80,6 +81,8 @@ project Corax # multi language support admin_pot_dir ${BASE_DIR}/agenda/planung/pot/ + + email info@${DOMAIN}