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

Last change on this file since 920 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
RevLine 
[139]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###
[417]10# Copyright (C) 2004-2010 - Kris Deugau
[139]11
12use strict;
13use warnings;
14#use CGI::Carp qw(fatalsToBrowser);
[517]15use CGI::Simple;
16use HTML::Template;
[139]17use DBI;
18#use POSIX qw(ceil);
19use NetAddr::IP;
20
21use Sys::Syslog;
22
[417]23# don't remove! required for GNU/FHS-ish install from tarball
24##uselib##
25
[906]26# push "the directory the script is in" into @INC
27use FindBin;
28use lib "$FindBin::RealBin/";
29
[417]30use MyIPDB;
31
[431]32openlog "IPDB","pid","$IPDB::syslog_facility";
[139]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
[517]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;
[139]46
[517]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
[142]51my ($dbh,$errstr) = connectDB_My;
[139]52my $sth;
53
[517]54$ENV{HTML_TEMPLATE_ROOT} = '../templates';
[139]55
[517]56my $page = HTML::Template->new(filename => "newcity.tmpl");
[622]57$webvar{pop} = '' if !$webvar{pop}; # shut up some warnings
[139]58
[517]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}'".
[139]75 (($webvar{pop} eq 'on') ? ' as POP location' : '');
[517]76 }
[139]77}
78
[517]79print "Content-type: text/html\n\n";
80
81print $page->output;
82
[139]83finish($dbh);
Note: See TracBrowser for help on using the repository browser.