| [139] | 1 | #!/usr/bin/perl | 
|---|
|  | 2 | # ipdb/cgi-bin/newcity.cgi | 
|---|
|  | 3 | # Add new city to database | 
|---|
|  | 4 | ### | 
|---|
|  | 5 | # SVN revision info | 
|---|
|  | 6 | # $Date: 2007-11-27 17:18:27 +0000 (Tue, 27 Nov 2007) $ | 
|---|
|  | 7 | # SVN revision $Rev: 370 $ | 
|---|
|  | 8 | # Last update by $Author: kdeugau $ | 
|---|
|  | 9 | ### | 
|---|
|  | 10 | # Copyright (C) 2004,2005 - Kris Deugau | 
|---|
|  | 11 |  | 
|---|
|  | 12 | use strict; | 
|---|
|  | 13 | use warnings; | 
|---|
|  | 14 | #use CGI::Carp qw(fatalsToBrowser); | 
|---|
|  | 15 | use DBI; | 
|---|
|  | 16 | use CommonWeb qw(:ALL); | 
|---|
| [142] | 17 | use MyIPDB; | 
|---|
| [139] | 18 | #use POSIX qw(ceil); | 
|---|
|  | 19 | use NetAddr::IP; | 
|---|
|  | 20 |  | 
|---|
|  | 21 | use Sys::Syslog; | 
|---|
|  | 22 |  | 
|---|
|  | 23 | openlog "IPDB","pid","local2"; | 
|---|
|  | 24 |  | 
|---|
|  | 25 | # Collect the username from HTTP auth.  If undefined, we're in a test environment. | 
|---|
|  | 26 | my $authuser; | 
|---|
|  | 27 | if (!defined($ENV{'REMOTE_USER'})) { | 
|---|
|  | 28 | $authuser = '__temptest'; | 
|---|
|  | 29 | } else { | 
|---|
|  | 30 | $authuser = $ENV{'REMOTE_USER'}; | 
|---|
|  | 31 | } | 
|---|
|  | 32 |  | 
|---|
|  | 33 | my %webvar = parse_post(); | 
|---|
|  | 34 | cleanInput(\%webvar); | 
|---|
|  | 35 |  | 
|---|
| [142] | 36 | my ($dbh,$errstr) = connectDB_My; | 
|---|
| [139] | 37 | my $sth; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | print "Content-type: text/html\n\n"; | 
|---|
|  | 40 |  | 
|---|
|  | 41 | if ($webvar{pop} eq 'on') { | 
|---|
| [370] | 42 | $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')"); | 
|---|
| [139] | 43 | } else { | 
|---|
| [370] | 44 | $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')"); | 
|---|
| [139] | 45 | } | 
|---|
|  | 46 | $sth->execute; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | if ($sth->err) { | 
|---|
|  | 49 | print "Error adding city to database: ".$sth->errstr; | 
|---|
| [214] | 50 | mailNotify('kdeugau@vianet.ca',"IPDB city add failure", | 
|---|
|  | 51 | "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr); | 
|---|
| [139] | 52 | syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr; | 
|---|
|  | 53 | } else { | 
|---|
|  | 54 | print "City added.  Closing this window should refresh the page."; | 
|---|
|  | 55 | syslog "notice", "$authuser added city/location '$webvar{pop}'". | 
|---|
|  | 56 | (($webvar{pop} eq 'on') ? ' as POP location' : ''); | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | finish($dbh); | 
|---|