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

Last change on this file since 394 was 394, checked in by Kris Deugau, 15 years ago

/branches/stable

Basic support for network node references: Add, view, edit nodes and

referencess

Probably excludes a bunch of real use-cases for various reasons

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.4 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-02-19 18:10:34 +0000 (Fri, 19 Feb 2010) $
7# SVN revision $Rev: 394 $
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);
17use MyIPDB;
18#use POSIX qw(ceil);
19use NetAddr::IP;
20
21use Sys::Syslog;
22
23openlog "IPDB","pid","local2";
24
25# Collect the username from HTTP auth. If undefined, we're in a test environment.
26my $authuser;
27if (!defined($ENV{'REMOTE_USER'})) {
28 $authuser = '__temptest';
29} else {
30 $authuser = $ENV{'REMOTE_USER'};
31}
32
33my %webvar = parse_post();
34cleanInput(\%webvar);
35
36my ($dbh,$errstr) = connectDB_My;
37my $sth;
38
39print "Content-type: text/html\n\n";
40
41$sth = $dbh->prepare("insert into nodes (node_type,node_name,node_ip)".
42 " values ('$webvar{type}','$webvar{nodename}','$webvar{nodeip}')");
43$sth->execute;
44
45if ($sth->err) {
46 print "Error adding node to database: ".$sth->errstr;
47 mailNotify('noc@example.com',"IPDB node add failure",
48 "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr);
49 syslog "err", "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
50} else {
51 print "Node added. Closing this window should refresh the page.";
52 syslog "notice", "$authuser added node '$webvar{nodename}'";
53}
54
55finish($dbh);
Note: See TracBrowser for help on using the repository browser.