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

Last change on this file since 948 was 906, checked in by Kris Deugau, 7 years ago

/trunk

Bulk addition of "add 'the directory the script is in' to @INC" for Perls
that have dropped '.' from @INC

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