source: trunk/cgi-bin/newcity.cgi@ 418

Last change on this file since 418 was 417, checked in by Kris Deugau, 14 years ago

/trunk

Rearrangements and tweaks toward releaseability:

  • Add Makefile to install halfway-sanely
  • Add .spec file
  • Shuffle "use IPDB;" and "use MyIPDB;" lines so that we can automagically insert a suitable "use lib..." line during 'make install'
  • Check copyright statements
  • Clear up some defaults, and place a number of "constants" in IPDB/MyIPDB rather than having them hardcoded all over the place (Still need to think of a sane way to do this for ipdb.psql's alloctype preseeding)
  • Tweak $VERSION identifier in IPDB.pm so it can be defined in the Makefile
  • Clean up some dangling bits from repository history conversion, remove unneeded "use ..." statements
  • Tweak rWHOIS export script to use more globals and "constants" from (My)IPDB.pm, and more Perl internals than system()-equivalents. Add a few fixme comments for longer-term flexibility improvements.
  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.5 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/newcity.cgi
3# Add new city to database
4###
5# SVN revision info
6# $Date: 2010-06-30 21:48:03 +0000 (Wed, 30 Jun 2010) $
7# SVN revision $Rev: 417 $
8# Last update by $Author: kdeugau $
9###
10# Copyright (C) 2004-2010 - Kris Deugau
11
12use strict;
13use warnings;
14#use CGI::Carp qw(fatalsToBrowser);
15use DBI;
16use CommonWeb qw(:ALL);
17#use POSIX qw(ceil);
18use NetAddr::IP;
19
20use Sys::Syslog;
21
22# don't remove! required for GNU/FHS-ish install from tarball
23##uselib##
24
25use MyIPDB;
26
27openlog "IPDB","pid","local2";
28
29# Collect the username from HTTP auth. If undefined, we're in a test environment.
30my $authuser;
31if (!defined($ENV{'REMOTE_USER'})) {
32 $authuser = '__temptest';
33} else {
34 $authuser = $ENV{'REMOTE_USER'};
35}
36
37my %webvar = parse_post();
38cleanInput(\%webvar);
39
40my ($dbh,$errstr) = connectDB_My;
41my $sth;
42
43print "Content-type: text/html\n\n";
44
45if ($webvar{pop} eq 'on') {
46 $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')");
47} else {
48 $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')");
49}
50$sth->execute;
51
52if ($sth->err) {
53 print "Error adding city to database: ".$sth->errstr;
54 mailNotify($dbh, 'f:nci', "IPDB city add failure",
55 "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);
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
63finish($dbh);
Note: See TracBrowser for help on using the repository browser.