[system] / trunk / webwork / system / cgi / cgi-scripts / feedback.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/cgi/cgi-scripts/feedback.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (download) (as text) (annotate)
Mon Jun 18 15:21:51 2001 UTC (12 years ago) by sam
File size: 7280 byte(s)
another setup script test (changed #! lines)

    1 #!/usr/local/bin/webwork-perl
    2 
    3 # $Id$
    4 
    5 # feedback.pl: Mail feedback to a specified user, with the URL of the
    6 #              referring page automagically included.  Reject bogus
    7 #              destination addresses.
    8 #
    9 # Usage: invoke as http://site/cgi-bin/feedback.pl?address1,address2,...
   10 
   11 use lib '.'; use webworkInit; # WeBWorKInitLine
   12 use Global;
   13 use CGI qw(:standard);
   14 use CGI::Carp qw(fatalsToBrowser);
   15 use HTML::Entities ();
   16 use Net::SMTP;
   17 
   18 $ENV{'PATH'} = '';  # try to avoid PATH attacks
   19 
   20 # log access
   21   &Global::log_info('', query_string);
   22 
   23 
   24 # local configuration stuff
   25 
   26 $BGCOLOR       = '#ffffff';
   27 $LOGFILE       = &Global::getWebworkLogsDirectory() . "webwork-feedback.log";
   28 
   29 # if path = '/send' we're processing a filled-out form
   30 my $ADDR;  # define 'globally' so that it can be used by subroutines
   31 if (path_info() eq '/send') {
   32 
   33     # Bad destinations shouldn't make it this far, since we already checked
   34     # for bad "To:" when generating the feedback form.  However, it's still
   35     # possible that some evildoer has submitted a bogus form, so we check
   36     # again...
   37   foreach  $ADDR (split(/\s*,\s*/, param('To'))) {
   38       &check_destination($ADDR);
   39 
   40       &user_error('You didn\'t enter any comments.')
   41     if (param('comments') eq '');
   42       &user_error('You didn\'t enter an e-mail address.')
   43     unless (param('email') =~/\@/);
   44 
   45       my $smtp = Net::SMTP->new($Global::smtpServer, Timeout=>10) ||
   46     &internal_error("Couldn't contact SMTP server.");
   47       $smtp->mail($Global::webmaster);
   48 
   49     if ( $smtp->recipient($ADDR)) {  # this one's okay, keep going
   50           $smtp->data(&output(0,$ADDR) . access_link($ADDR) ) ||
   51         &internal_error("Unknown problem sending message data to SMTP server.");
   52       } else {      # we have a problem  with this address
   53         $smtp->reset;
   54           &internal_error("SMTP server doesn't like this address: <$ADDR>.");
   55     }
   56       $smtp->quit;
   57       &log("Mail sent to: " . $ADDR . "     from: " .param('email') );
   58   }
   59 #    &log("Mail sent to: " . param('To') . "     from: " .param('email') );
   60     &thank_you;
   61 
   62 } else {
   63 
   64 # No path info: we're generating a form to be filled-out
   65 
   66     $To = $ENV{'QUERY_STRING'};
   67     $To = $Global::webmaster if ($To eq '');
   68     &check_destination($To);
   69     &generate_form;
   70 }
   71 
   72 exit(0);
   73 
   74 ############################## Subroutines #################################
   75 
   76 sub internal_error {
   77     my $msg = join " ", @_;
   78     &log("ERROR: $msg");
   79     print header,
   80       start_html('-title' => "Internal Error", -bgcolor=>"$BGCOLOR"),
   81   h1('Internal Error'),
   82   b(HTML::Entities::encode($msg)),
   83   p,
   84   "Your message could not be sent.  Please notify ",
   85   "&lt;", a({href=>"mailto:$Global::webmaster"}, $Global::webmaster), "&gt;. ",
   86   br,
   87   "We apologize for the inconvenience.",
   88   end_html;
   89     exit(1);
   90 }
   91 
   92 sub user_error {
   93     my $msg = join " ", @_;
   94     print header,
   95   start_html('-title' => 'User error', -BGCOLOR=>"$BGCOLOR"),
   96   h1('User error'),
   97   p,
   98   b(HTML::Entities::encode($msg)),
   99   p,
  100         "Please hit the &quot;<B>Back</B>&quot; button on your browser to ",
  101   "try again, or notify ", br,
  102   "&lt;", a({href=>"mailto:$Global::webmaster"}, $Global::webmaster), "&gt; ",
  103   "if you believe this message is in error.",
  104   end_html;
  105     exit(1);
  106 }
  107 
  108 sub check_destination {
  109     my($address_list) = @_;
  110 
  111     my (@address) = split(/\+*,\+*/, $address_list);
  112     for (@address) {
  113        &internal_error("Sorry, I'm not allowed to send mail to <$_>.")
  114            if !/$Global::legalAddress/;
  115     }
  116 }
  117 
  118 #http://webwork.math.rochester.edu/cgi-bin/development/processProblem7.pl?probSetKey=51823&probNum=7&Mode=HTML_tth&course=mth161dev&user=gage&key=NQ18Kry70j*.8Lsok3ulG^QHAp3zRG0hjHE5emT4
  119 sub access_link {
  120    my $ADDR = shift;
  121    my $url = param('referring_url');
  122    $USER = $ADDR; #param('To');
  123    $USER =~s/@.*$//;    # determine the user (the recipient of this message) from the mail message.  This method may change.
  124    $url =~ s/\?.*$//;
  125    my $warning_limit = $^W; $^W=0;
  126    $url .= '?probSetKey='.param('probSetKey').'&probNum='.param('probNum').'&Mode='.param('Mode').'&course='.param('course')."&user=$USER&key=".param('key');
  127    $^W= $warning_limit;
  128    "Access Link " . $url . "\n";
  129 }
  130 
  131 sub log {
  132     my $msg = $_[0];
  133     open(LOGFILE, ">> $LOGFILE") || &internal_error("Can't write to $LOGFILE"); # warn("Can't write to $LOGFILE\n");
  134     print LOGFILE 'Date: ', scalar(localtime), "\n";
  135     print LOGFILE $msg;
  136     print LOGFILE "\n------\n";
  137     close(LOGFILE);
  138 }
  139 
  140 sub thank_you {
  141     print header,
  142     start_html( '-title'=>'Thank You', -BGCOLOR=>"$BGCOLOR"),
  143     h1('Your message has been mailed.'),
  144     "To: ", param('To'),
  145     '<pre><br><br>',&output(0,param('To') ),'</pre>',
  146     end_html;
  147 }
  148 
  149 sub generate_form {
  150 
  151     my $list = "," . $To;
  152     $list =~ s/,/<li>/g;
  153 
  154     print header,
  155     start_html('-title'=>'WeBWorK - Feedback', -bgcolor=>"$BGCOLOR"),
  156     img({align=>'LEFT', alt=>"", src=>$Global::headerImgUrl}),
  157     p({align=>'right'}),
  158     br({clear=>'ALL'}),
  159     hr,
  160     h1('WeBWorK Feedback Gateway'),
  161     start_form('POST', url() . '/send'),
  162         hidden('To', $To),
  163         hidden('name'),
  164             hidden('id'),
  165         hidden('referring_url', referer()),
  166         hidden('probSetKey'),
  167         hidden('setnum'),
  168         hidden('probNum'),
  169         hidden('course'),
  170         hidden('section'),
  171         hidden('recitation'),
  172         hidden('Mode'),
  173         hidden('user'),
  174         hidden('key'),
  175         strong("To: "), kbd($To), br,
  176             strong("From: "), param('name'), br,
  177         p,
  178         textfield(-name=>'email',-default => ' ', -size=>'32',-override=>1), ' ', b('E-mail'), i(' (must be filled in!)'),br,
  179         p,
  180         b('Your comments:'), ' ', i('(must be filled in!)'), br,
  181         textarea('comments', '', 15, 70),
  182         p,
  183         b(submit('submit', 'Submit Your Comments')),
  184     end_form,
  185     end_html;
  186 }
  187 
  188 sub output {
  189     my $suppress_output = $_[0];
  190     my $addr = $_[1];
  191     my $msg;
  192 
  193     $msg =
  194        # message header
  195        "From: "           . param('email')   . " (" . param('name') . ")\n" .
  196        "To: "             . $addr      . "\n" .
  197        "Reply-To: "       . param('email')   . "\n" .
  198        "X-Remote-Host: "  . remote_host      . " (" . remote_addr . ")\n" .
  199        "Subject: WeBWorK Feedback from " . param('course'). "/" . param('user'). "\n" .
  200        "\n" .
  201 
  202        # message body: student data
  203        "User:           " . param('user')    . "\n" .
  204        "Name:           " . param('name')    . "\n" .
  205        "Student ID:     " . param('id')      . "\n" .
  206        "Course:         " . param('course')  . "\n" .
  207        "Section:        " . param('section') . "\n" .
  208        "Recitation:     " . param('recitation') . "\n" .
  209        "PSVN:           " . param('probSetKey')    . "\n" .
  210        "Set number:     " . param('setnum')  . "\n" .
  211        "Problem number: " . param('probNum') . "\n" .
  212        "Mode:           " . param('Mode')    . "\n" .
  213        "Key:            " . param('key')     . "\n" .
  214        #   "DataMunger URL: $munger"         . "\n" .
  215        "\n";
  216 
  217     # for logs: don't log actual message, just student info
  218     return $msg if $suppress_output;
  219 
  220     # message body: message
  221     $msg .= "Allegedly from: " . param('email') . "\n" .
  222       "Comments:\n-------\n" . param('comments') . "\n";
  223 
  224     return $msg;
  225 }
  226 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9