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-07-26 21:00:00 +0000 (Mon, 26 Jul 2010) $
|
---|
7 | # SVN revision $Rev: 445 $
|
---|
8 | # Last update by $Author: kdeugau $
|
---|
9 | ###
|
---|
10 | # Copyright (C) 2010 - Kris Deugau
|
---|
11 |
|
---|
12 | use strict;
|
---|
13 | use warnings;
|
---|
14 | #use CGI::Carp qw(fatalsToBrowser);
|
---|
15 | use DBI;
|
---|
16 | use CommonWeb qw(:ALL);
|
---|
17 | #use POSIX qw(ceil);
|
---|
18 | use NetAddr::IP;
|
---|
19 | use Sys::Syslog;
|
---|
20 |
|
---|
21 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
22 | ##uselib##
|
---|
23 |
|
---|
24 | use MyIPDB;
|
---|
25 |
|
---|
26 | openlog "IPDB","pid","$IPDB::syslog_facility";
|
---|
27 |
|
---|
28 | # Collect the username from HTTP auth. If undefined, we're in a test environment.
|
---|
29 | my $authuser;
|
---|
30 | if (!defined($ENV{'REMOTE_USER'})) {
|
---|
31 | $authuser = '__temptest';
|
---|
32 | } else {
|
---|
33 | $authuser = $ENV{'REMOTE_USER'};
|
---|
34 | }
|
---|
35 |
|
---|
36 | my %webvar = parse_post();
|
---|
37 | cleanInput(\%webvar);
|
---|
38 |
|
---|
39 | my ($dbh,$errstr) = connectDB_My;
|
---|
40 | my $sth;
|
---|
41 |
|
---|
42 | print "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 |
|
---|
48 | if ($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 |
|
---|
58 | finish($dbh);
|
---|