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

Last change on this file since 864 was 622, checked in by Kris Deugau, 10 years ago

/trunk

Minor log cleanup in newcity.cgi

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 2.0 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: 2014-10-01 21:00:52 +0000 (Wed, 01 Oct 2014) $
7# SVN revision $Rev: 622 $
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 CGI::Simple;
16use HTML::Template;
17use DBI;
18#use POSIX qw(ceil);
19use NetAddr::IP;
20
21use Sys::Syslog;
22
23# don't remove! required for GNU/FHS-ish install from tarball
24##uselib##
25
26use MyIPDB;
27
28openlog "IPDB","pid","$IPDB::syslog_facility";
29
30# Collect the username from HTTP auth. If undefined, we're in a test environment.
31my $authuser;
32if (!defined($ENV{'REMOTE_USER'})) {
33 $authuser = '__temptest';
34} else {
35 $authuser = $ENV{'REMOTE_USER'};
36}
37
38# Set up the CGI object...
39my $q = new CGI::Simple;
40# ... and get query-string params as well as POST params if necessary
41$q->parse_query_string;
42
43# Convenience; saves changing all references to %webvar
44##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
45my %webvar = $q->Vars;
46
47my ($dbh,$errstr) = connectDB_My;
48my $sth;
49
50$ENV{HTML_TEMPLATE_ROOT} = '../templates';
51
52my $page = HTML::Template->new(filename => "newcity.tmpl");
53$webvar{pop} = '' if !$webvar{pop}; # shut up some warnings
54
55if ($webvar{city}) {
56 if ($webvar{pop} eq 'on') {
57 $sth = $dbh->prepare("insert into cities (city,routing) values (?,'y')");
58 } else {
59 $sth = $dbh->prepare("insert into cities (city,routing) values (?,'n')");
60 }
61##fixme: don't allow duplicate cities
62 $sth->execute($webvar{city});
63 $page->param(city => $webvar{city});
64 if ($sth->err) {
65 $page->param(err => $sth->errstr);
66 my $msg = "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
67 mailNotify($dbh, 'f:nci', "IPDB city add failure", $msg);
68 syslog "err", $msg;
69 } else {
70 syslog "notice", "$authuser added city/location '$webvar{pop}'".
71 (($webvar{pop} eq 'on') ? ' as POP location' : '');
72 }
73}
74
75print "Content-type: text/html\n\n";
76
77print $page->output;
78
79finish($dbh);
Note: See TracBrowser for help on using the repository browser.