| [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-26 21:00:00 +0000 (Mon, 26 Jul 2010) $ | 
|---|
|  | 7 | # SVN revision $Rev: 445 $ | 
|---|
|  | 8 | # Last update by $Author: kdeugau $ | 
|---|
|  | 9 | ### | 
|---|
| [445] | 10 | # Copyright (C) 2004-2010 - Kris Deugau | 
|---|
| [139] | 11 |  | 
|---|
|  | 12 | use strict; | 
|---|
|  | 13 | use warnings; | 
|---|
|  | 14 | #use CGI::Carp qw(fatalsToBrowser); | 
|---|
|  | 15 | use DBI; | 
|---|
|  | 16 | use CommonWeb qw(:ALL); | 
|---|
|  | 17 | #use POSIX qw(ceil); | 
|---|
|  | 18 | use NetAddr::IP; | 
|---|
|  | 19 |  | 
|---|
|  | 20 | use Sys::Syslog; | 
|---|
|  | 21 |  | 
|---|
| [445] | 22 | # don't remove!  required for GNU/FHS-ish install from tarball | 
|---|
|  | 23 | ##uselib## | 
|---|
| [139] | 24 |  | 
|---|
| [445] | 25 | use MyIPDB; | 
|---|
|  | 26 |  | 
|---|
|  | 27 | openlog "IPDB","pid","$IPDB::syslog_facility"; | 
|---|
|  | 28 |  | 
|---|
| [139] | 29 | # Collect the username from HTTP auth.  If undefined, we're in a test environment. | 
|---|
|  | 30 | my $authuser; | 
|---|
|  | 31 | if (!defined($ENV{'REMOTE_USER'})) { | 
|---|
|  | 32 | $authuser = '__temptest'; | 
|---|
|  | 33 | } else { | 
|---|
|  | 34 | $authuser = $ENV{'REMOTE_USER'}; | 
|---|
|  | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | my %webvar = parse_post(); | 
|---|
|  | 38 | cleanInput(\%webvar); | 
|---|
|  | 39 |  | 
|---|
| [158] | 40 | my ($dbh,$errstr) = connectDB_My; | 
|---|
| [139] | 41 | my $sth; | 
|---|
|  | 42 |  | 
|---|
|  | 43 | print "Content-type: text/html\n\n"; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | if ($webvar{pop} eq 'on') { | 
|---|
| [355] | 46 | $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')"); | 
|---|
| [139] | 47 | } else { | 
|---|
| [355] | 48 | $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')"); | 
|---|
| [139] | 49 | } | 
|---|
|  | 50 | $sth->execute; | 
|---|
|  | 51 |  | 
|---|
|  | 52 | if ($sth->err) { | 
|---|
|  | 53 | print "Error adding city to database: ".$sth->errstr; | 
|---|
| [445] | 54 | mailNotify($dbh, 'f:nci', "IPDB city add failure", | 
|---|
| [210] | 55 | "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr); | 
|---|
| [139] | 56 | syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr; | 
|---|
|  | 57 | } else { | 
|---|
|  | 58 | print "City added.  Closing this window should refresh the page."; | 
|---|
|  | 59 | syslog "notice", "$authuser added city/location '$webvar{pop}'". | 
|---|
|  | 60 | (($webvar{pop} eq 'on') ? ' as POP location' : ''); | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | finish($dbh); | 
|---|