Changeset 238


Ignore:
Timestamp:
Oct 29, 2006, 7:35:19 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Make CGIs use shared error functions.

Location:
trunk/npemap.org.uk/cgi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/bad-postcode.fcgi

    r237 r238  
    99use DBI;
    1010use CGI::Fast qw/:standard -debug/;
    11 
    12 use vars qw($dbname $dbhost $dbuser $dbpass);
    1311
    1412# Find our private perl libraries
  • trunk/npemap.org.uk/cgi/get-distant-postcodes.fcgi

    r222 r238  
    1414use DBI;
    1515use CGI::Fast qw/:standard -debug/;
    16 
    17 use vars qw($dbname $dbhost $dbuser $dbpass);
    1816
    1917# Find our private perl libraries
  • trunk/npemap.org.uk/cgi/get-postcodes.fcgi

    r222 r238  
    99use DBI;
    1010use CGI::Fast qw/:standard -debug/;
    11 
    12 use vars qw($dbname $dbhost $dbuser $dbpass);
    1311
    1412# Find our private perl libraries
  • trunk/npemap.org.uk/cgi/interest.fcgi

    r222 r238  
    1111use Email::Valid;
    1212
    13 use vars qw($dbname $dbhost $dbuser $dbpass);
    14 
    1513# Find our private perl libraries
    1614use FindBin;
    1715use lib "$FindBin::Bin/../perllib";
    1816use NPEMap;
    19 
    20 sub print_err;
    2117
    2218my $returnlink='<a href="/">Go back</a>';
     
    3430    # In case the database went away, make sure we have a connection
    3531    unless ($dbh = setup_dbh()) {
    36         print_err('Error setting up database connection', $returnlink);
     32        print_html_err('Error setting up database connection', $returnlink);
    3733        next REQUEST;
    3834    }
     
    4036    # Input validation
    4137    unless (defined $cgi->param('email')) {
    42         print_err ("Email address not supplied", $returnlink);
     38        print_html_err ("Email address not supplied", $returnlink);
    4339        next REQUEST;
    4440    }
    4541
    4642    unless(Email::Valid->address($cgi->param('email'))) {
    47         print_err ("Sorry, your email address doesn't seem to be valid", $returnlink);
     43        print_html_err ("Sorry, your email address doesn't seem to be valid", $returnlink);
    4844        next REQUEST;
    4945    }
    5046
    5147    unless (defined $cgi->param('scotland') or defined $cgi->param('northernireland')) {
    52         print_err ("Interest in neither Scotland nor Northern Ireland shown", $returnlink);
     48        print_html_err ("Interest in neither Scotland nor Northern Ireland shown", $returnlink);
    5349        next REQUEST;
    5450    }
     
    5753    my $sth = $dbh->prepare('SELECT email FROM interest WHERE email = ?');
    5854    unless ($sth->execute($cgi->param('email'))) {
    59         print_err('Database error', $returnlink);
     55        print_html_err('Database error', $returnlink);
    6056        next REQUEST;
    6157    }
    6258
    6359    if ($sth->rows) {
    64         print_err('We already have a record of your interest. Please email us if you wish to change or remove this.', $returnlink);
     60        print_html_err('We already have a record of your interest. Please email us if you wish to change or remove this.', $returnlink);
    6561        next REQUEST;
    6662    }
     
    8480        next REQUEST;
    8581    } else {
    86         print_err("Database error when adding your data :(", $returnlink);
     82        print_html_err("Database error when adding your data :(", $returnlink);
    8783        next REQUEST;
    8884    }
     
    9187# No more requests to serve, so tidy up
    9288$dbh->disconnect;
    93 
    94 # Helper routines
    95 sub print_err($$) {
    96     my $err = shift;
    97     my $returnlink = shift;
    98     print "Content-type: text/html\n\n";
    99     print "<html><head><title>Error submitting</title></head>\n";
    100     print "<body><p>The following error occurred whilst submitting data:\n";
    101     print CGI::escapeHTML($err);
    102     print "</p><p>$returnlink</p>\n";
    103     print "</body></html>\n";
    104 }
  • trunk/npemap.org.uk/cgi/problem.fcgi

    r222 r238  
    1212use CGI::Fast qw/:standard -debug/;
    1313
    14 use vars qw($dbname $dbhost $dbuser $dbpass);
    15 
    1614# Find our private perl libraries
    1715use FindBin;
    1816use lib "$FindBin::Bin/../perllib";
    1917use NPEMap;
    20 
    21 sub print_err;
    2218
    2319# Set up database handler to try and make sure it's ready for the first
     
    3935    # In case the database went away, make sure we have a connection
    4036    unless ($dbh = setup_dbh()) {
    41         print_err('Error setting up database connection', $returnlink);
     37        print_html_err('Error setting up database connection', $returnlink);
    4238        next REQUEST;
    4339    }
     
    4541    # Input validation
    4642    unless (defined $cgi->param('comment')) {
    47         print_err ("Please supply a comment");
     43        print_html_err ("Please supply a comment", $returnlink);
    4844        next REQUEST;
    4945    }
    5046
    5147    if (defined $cgi->param('email') and ($cgi->param('email') ne '') and !(Email::Valid->address($cgi->param('email')))) {
    52         print_err ("Invalid email address supplied");
     48        print_html_err ("Invalid email address supplied", $returnlink);
    5349        next REQUEST;
    5450    }
     
    6662   
    6763    unless ($msg->send) {
    68         print_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.');
     64        print_html_err ('Sorry, there was an error sending your message. Please email webmaster@npemap.org.uk instead.', $returnlink);
    6965        next REQUEST;
    7066    }
     
    8076# No more requests to serve, so tidy up
    8177$dbh->disconnect;
    82 
    83 # Helper routines
    84 sub print_err($$) {
    85     my $err = shift;
    86     my $returnlink = shift;
    87     print "Content-type: text/html\n\n";
    88     print "<html><head><title>Error submitting</title></head>\n";
    89     print "<body><p>The following error occurred whilst submitting data:\n";
    90     print CGI::escapeHTML($err);
    91     print "</body></html>\n";
    92 }
  • trunk/npemap.org.uk/cgi/submit.fcgi

    r234 r238  
    1111use Geo::Postcode;
    1212
    13 use vars qw($dbname $dbhost $dbuser $dbpass);
    14 
    1513# Find our private perl libraries
    1614use FindBin;
     
    1816use NPEMap;
    1917use NPEMap::Postcodes;
    20 
    21 sub print_err;
    2218
    2319# Set up database handler to try and make sure it's ready for the first
     
    4743    # In case the database went away, make sure we have a connection
    4844    unless ($dbh = setup_dbh()) {
    49         print_err('Error setting up database connection', $returnlink);
     45        print_html_err('Error setting up database connection', $returnlink);
    5046        next REQUEST;
    5147    }
     
    5652    foreach my $field (@fields) {
    5753        unless (defined $cgi->param($field)) {
    58             print_err ("Parameter '$field' missing", $returnlink);
     54            print_html_err ("Parameter '$field' missing", $returnlink);
    5955            next REQUEST;
    6056        }
     
    6460    if (($cgi->param('easting') > 700000) or
    6561        ($cgi->param('easting') < 0)) {
    66         print_err ("Parameter 'easting' must be an integer between 0 and 700,000", $returnlink);
     62        print_html_err ("Parameter 'easting' must be an integer between 0 and 700,000", $returnlink);
    6763        next REQUEST;
    6864    } else {
     
    7369    if (($cgi->param('northing') > 1300000) or
    7470        ($cgi->param('northing') < 0)) {
    75         print_err("Parameter 'northing' must be an integer between 0 and 1,300,000", $returnlink);
     71        print_html_err("Parameter 'northing' must be an integer between 0 and 1,300,000", $returnlink);
    7672        next REQUEST;
    7773    } else {
     
    9187
    9288    unless ((length($trimmed_2)) == 1 or (length($trimmed_2) == 0) or (length($trimmed_2) == 3) or (!defined $trimmed_2)) {
    93         print_err("The postcode format is not valid", $returnlink);
     89        print_html_err("The postcode format is not valid", $returnlink);
    9490        next REQUEST;
    9591    }
     
    111107        $inward .= $fourth if defined $fourth;
    112108    } else {
    113         print_err("The postcode format is not valid", $returnlink);
     109        print_html_err("The postcode format is not valid", $returnlink);
    114110        next REQUEST;
    115111    }
     
    121117    $sth = $dbh->prepare('SELECT raw_postcode_outward FROM postcodes WHERE raw_postcode_outward = ? AND raw_postcode_inward = ? AND easting = ? AND northing = ? AND ip = ? AND NOT deleted');
    122118    unless ($sth->execute($cgi->param('postcode1'), $cgi->param('postcode2'), $easting, $northing, $ENV{'REMOTE_ADDR'})) {
    123         print_err('Database error when checking for duplicate data :(', $returnlink);
     119        print_html_err('Database error when checking for duplicate data :(', $returnlink);
    124120        next REQUEST;
    125121    }
    126122
    127123    if ($sth->rows) {
    128         print_err('You, or someone with the same IP address, have already submitted this postcode with these co-ordinates.', $returnlink);
     124        print_html_err('You, or someone with the same IP address, have already submitted this postcode with these co-ordinates.', $returnlink);
    129125        next REQUEST;
    130126    }
     
    142138    } else {
    143139        print STDERR "DB error: " . $dbh->errstr . "\n";
    144         print_err("Database error when adding your data :(", $returnlink);
     140        print_html_err("Database error when adding your data :(", $returnlink);
    145141        next REQUEST;
    146142    }
     
    152148# No more requests to serve, so tidy up
    153149$dbh->disconnect;
    154 
    155 # Helper routines
    156 sub print_err($$) {
    157     my $err = shift;
    158     my $returnlink = shift;
    159     print "Content-type: text/html\n\n";
    160     print "<html><head><title>Error submitting</title></head>\n";
    161     print "<body><p>The following error occurred whilst submitting data:\n";
    162     print CGI::escapeHTML($err);
    163     print "</p><p>Your input was:</p>\n<ul>";
    164     foreach my $field (@fields) {
    165         my $param = $cgi->param($field) || '';
    166         print "<li>$field: " . $param . "</li>\n";
    167     }
    168     print "</ul>\n";
    169     print "<p>$returnlink</p>\n";
    170     print "</body></html>\n";
    171 }
Note: See TracChangeset for help on using the changeset viewer.