source: trunk/npemap.org.uk/cgi/problem.fcgi @ 306

Last change on this file since 306 was 300, checked in by Dominic Hargreaves, 15 years ago

More cleanups

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2#
3# Copyright (c) 2006 Dominic Hargreaves
4# See accompanying file "LICENCE" for licence details
5
6use strict;
7use warnings;
8
9use MIME::Lite;
10use Email::Valid;
11use CGI::Fast qw/:standard -debug/;
12
13# Find our private perl libraries
14use FindBin;
15use lib "$FindBin::Bin/../perllib";
16use NPEMap;
17
18my $returnBaseURL = '';
19
20my $cgi;
21# Process incoming requests
22REQUEST: while ($cgi = new CGI::Fast) {
23
24    # If we're given return URL parameters, basic sanity check to stop
25    # funny business
26    my $returnlink = '<a href="' . $returnBaseURL . '/">Go back</a>';
27
28    # Input validation
29    unless (defined $cgi->param('comment')) {
30        print_html_err ("Please supply a comment", $returnlink);
31        next REQUEST;
32    }
33
34    if (defined $cgi->param('email') and ($cgi->param('email') ne '') and !(Email::Valid->address($cgi->param('email')))) {
35        print_html_err ("Invalid email address supplied", $returnlink);
36        next REQUEST;
37    }
38
39    my $type = $cgi->param('type') || 'none';
40    my $from = $cgi->param('email') || 'webmaster@npemap.org.uk';
41    my $comment = $cgi->param('comment');
42    my $subject = "[$type] comment from npemap.org.uk ";
43
44    my $msg = MIME::Lite->new(
45        From => $from,
46        To => 'webmaster@npemap.org.uk',
47        Subject => $subject,
48        'X-HTTP-User-Agent' => $ENV{'HTTP_USER_AGENT'} || 'unset',
49        'X-HTTP-Remote-Addr' => $ENV{'REMOTE_ADDR'} || 'unset',
50        Data => $comment);
51   
52    unless ($msg->send) {
53        print_html_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.', $returnlink);
54        next REQUEST;
55    }
56
57    print "Content-type: text/html\n\n";
58    print "<html><head><title>Thanks</title></head>";
59    print "<body><p>Thanks for submitting your comment.</p><P><a href='/'>Home</a></p></body></html>";
60
61
62}
Note: See TracBrowser for help on using the repository browser.