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

Last change on this file was 635, checked in by Dominic Hargreaves, 13 years ago

licence tastic

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/perl
2#
3# Copyright (c) 2006 Dominic Hargreaves
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8# and/or sell copies of the Software, and to permit persons to whom the
9# Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21#
22use strict;
23use warnings;
24
25use MIME::Lite;
26use Email::Valid;
27use CGI::Fast qw/:standard -debug/;
28
29# Find our private perl libraries
30use FindBin;
31use lib "$FindBin::Bin/../perllib";
32use NPEMap;
33
34my $returnBaseURL = '';
35
36my $cgi;
37# Process incoming requests
38REQUEST: while ($cgi = new CGI::Fast) {
39
40    # If we're given return URL parameters, basic sanity check to stop
41    # funny business
42    my $returnlink = '<a href="' . $returnBaseURL . '/">Go back</a>';
43
44    # Input validation
45    unless (defined $cgi->param('comment')) {
46        print_html_err ("Please supply a comment", $returnlink);
47        next REQUEST;
48    }
49
50    if (defined $cgi->param('email') and ($cgi->param('email') ne '') and !(Email::Valid->address($cgi->param('email')))) {
51        print_html_err ("Invalid email address supplied", $returnlink);
52        next REQUEST;
53    }
54
55    my $type = $cgi->param('type') || 'none';
56    my $from = $cgi->param('email') || 'webmaster@npemap.org.uk';
57    my $comment = $cgi->param('comment');
58    my $subject = "[$type] comment from npemap.org.uk ";
59
60    my $msg = MIME::Lite->new(
61        From => $from,
62        To => 'webmaster@npemap.org.uk',
63        Subject => $subject,
64        'X-HTTP-User-Agent' => $ENV{'HTTP_USER_AGENT'} || 'unset',
65        'X-HTTP-Remote-Addr' => $ENV{'REMOTE_ADDR'} || 'unset',
66        Data => $comment);
67   
68    unless ($msg->send) {
69        print_html_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.', $returnlink);
70        next REQUEST;
71    }
72
73    print "Content-type: text/html\n\n";
74    print "<html><head><title>Thanks</title></head>";
75    print "<body><p>Thanks for submitting your comment.</p><P><a href='/'>Home</a></p></body></html>";
76
77
78}
Note: See TracBrowser for help on using the repository browser.