source: branches/stable/cgi-bin/newnode.cgi@ 498

Last change on this file since 498 was 445, checked in by Kris Deugau, 14 years ago

/branches/stable

Bring /branches/stable up to date with /trunk. See #13.

  • 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-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
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.