| [139] | 1 | #!/usr/bin/perl
 | 
|---|
 | 2 | # ipdb/cgi-bin/newcity.cgi
 | 
|---|
 | 3 | # Add new city to database
 | 
|---|
 | 4 | ###
 | 
|---|
 | 5 | # SVN revision info
 | 
|---|
 | 6 | # $Date: 2010-07-27 17:15:56 +0000 (Tue, 27 Jul 2010) $
 | 
|---|
 | 7 | # SVN revision $Rev: 447 $
 | 
|---|
 | 8 | # Last update by $Author: kdeugau $
 | 
|---|
 | 9 | ###
 | 
|---|
| [417] | 10 | # Copyright (C) 2004-2010 - Kris Deugau
 | 
|---|
| [139] | 11 | 
 | 
|---|
 | 12 | use strict;
 | 
|---|
 | 13 | use warnings;
 | 
|---|
 | 14 | #use CGI::Carp qw(fatalsToBrowser);
 | 
|---|
| [447] | 15 | use CGI::Simple;
 | 
|---|
| [139] | 16 | use DBI;
 | 
|---|
 | 17 | use CommonWeb qw(:ALL);
 | 
|---|
 | 18 | #use POSIX qw(ceil);
 | 
|---|
 | 19 | use NetAddr::IP;
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | use Sys::Syslog;
 | 
|---|
 | 22 | 
 | 
|---|
| [417] | 23 | # don't remove!  required for GNU/FHS-ish install from tarball
 | 
|---|
 | 24 | ##uselib##
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | use MyIPDB;
 | 
|---|
 | 27 | 
 | 
|---|
| [431] | 28 | openlog "IPDB","pid","$IPDB::syslog_facility";
 | 
|---|
| [139] | 29 | 
 | 
|---|
 | 30 | # Collect the username from HTTP auth.  If undefined, we're in a test environment.
 | 
|---|
 | 31 | my $authuser;
 | 
|---|
 | 32 | if (!defined($ENV{'REMOTE_USER'})) {
 | 
|---|
 | 33 |   $authuser = '__temptest';
 | 
|---|
 | 34 | } else {
 | 
|---|
 | 35 |   $authuser = $ENV{'REMOTE_USER'};
 | 
|---|
 | 36 | }
 | 
|---|
 | 37 | 
 | 
|---|
| [447] | 38 | # Set up the CGI object...
 | 
|---|
 | 39 | my $q = new CGI::Simple;
 | 
|---|
 | 40 | # ... and get query-string params as well as POST params if necessary
 | 
|---|
 | 41 | $q->parse_query_string;
 | 
|---|
| [139] | 42 | 
 | 
|---|
| [447] | 43 | # Convenience;  saves changing all references to %webvar
 | 
|---|
 | 44 | ##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
 | 
|---|
 | 45 | my %webvar = $q->Vars;
 | 
|---|
 | 46 | 
 | 
|---|
| [142] | 47 | my ($dbh,$errstr) = connectDB_My;
 | 
|---|
| [139] | 48 | my $sth;
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | print "Content-type: text/html\n\n";
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | if ($webvar{pop} eq 'on') {
 | 
|---|
| [370] | 53 |   $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')");
 | 
|---|
| [139] | 54 | } else {
 | 
|---|
| [370] | 55 |   $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')");
 | 
|---|
| [139] | 56 | }
 | 
|---|
 | 57 | $sth->execute;
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | if ($sth->err) {
 | 
|---|
 | 60 |   print "Error adding city to database: ".$sth->errstr;
 | 
|---|
| [416] | 61 |   mailNotify($dbh, 'f:nci', "IPDB city add failure",
 | 
|---|
 | 62 |         "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);
 | 
|---|
| [139] | 63 |   syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
 | 
|---|
 | 64 | } else {
 | 
|---|
 | 65 |   print "City added.  Closing this window should refresh the page.";
 | 
|---|
 | 66 |   syslog "notice", "$authuser added city/location '$webvar{pop}'".
 | 
|---|
 | 67 |         (($webvar{pop} eq 'on') ? ' as POP location' : '');
 | 
|---|
 | 68 | }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | finish($dbh);
 | 
|---|