source: trunk/cgi-bin/newnode.cgi@ 419

Last change on this file since 419 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/newnode.cgi
3# Add new wifi tower or fibre demarc switch ("node") 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) 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;
19use Sys::Syslog;
20
21# don't remove! required for GNU/FHS-ish install from tarball
22##uselib##
23
24use MyIPDB;
25
26openlog "IPDB","pid","$IPDB::syslog_facility";
27
28# Collect the username from HTTP auth. If undefined, we're in a test environment.
29my $authuser;
30if (!defined($ENV{'REMOTE_USER'})) {
31 $authuser = '__temptest';
32} else {
33 $authuser = $ENV{'REMOTE_USER'};
34}
35
36my %webvar = parse_post();
37cleanInput(\%webvar);
38
39my ($dbh,$errstr) = connectDB_My;
40my $sth;
41
42print "Content-type: text/html\n\n";
43
44$sth = $dbh->prepare("insert into nodes (node_type,node_name,node_ip)".
45 " values ('$webvar{type}','$webvar{nodename}','$webvar{nodeip}')");
46$sth->execute;
47
48if ($sth->err) {
49 print "Error adding node to database: ".$sth->errstr;
50 mailNotify($dbh, 'f:nno', "IPDB node add failure",
51 "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr);
52 syslog "err", "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
53} else {
54 print "Node added. Closing this window should refresh the page.";
55 syslog "notice", "$authuser added node '$webvar{nodename}'";
56}
57
58finish($dbh);
Note: See TracBrowser for help on using the repository browser.