[394] | 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: 2013-05-14 22:10:22 +0000 (Tue, 14 May 2013) $
|
---|
| 7 | # SVN revision $Rev: 593 $
|
---|
| 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);
|
---|
[593] | 15 | use CGI::Simple;
|
---|
| 16 | use HTML::Template;
|
---|
[394] | 17 | use DBI;
|
---|
| 18 | #use POSIX qw(ceil);
|
---|
| 19 | use NetAddr::IP;
|
---|
| 20 | use Sys::Syslog;
|
---|
| 21 |
|
---|
[445] | 22 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
| 23 | ##uselib##
|
---|
[394] | 24 |
|
---|
[445] | 25 | use MyIPDB;
|
---|
| 26 |
|
---|
| 27 | openlog "IPDB","pid","$IPDB::syslog_facility";
|
---|
| 28 |
|
---|
[394] | 29 | # Collect the username from HTTP auth. If undefined, we're in a test environment.
|
---|
| 30 | my $authuser;
|
---|
| 31 | if (!defined($ENV{'REMOTE_USER'})) {
|
---|
| 32 | $authuser = '__temptest';
|
---|
| 33 | } else {
|
---|
| 34 | $authuser = $ENV{'REMOTE_USER'};
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[593] | 37 | # Set up the CGI object...
|
---|
| 38 | my $q = new CGI::Simple;
|
---|
| 39 | # ... and get query-string params as well as POST params if necessary
|
---|
| 40 | $q->parse_query_string;
|
---|
[394] | 41 |
|
---|
[593] | 42 | # Convenience; saves changing all references to %webvar
|
---|
| 43 | ##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
|
---|
| 44 | my %webvar = $q->Vars;
|
---|
| 45 |
|
---|
[394] | 46 | my ($dbh,$errstr) = connectDB_My;
|
---|
| 47 | my $sth;
|
---|
| 48 |
|
---|
[593] | 49 | $ENV{HTML_TEMPLATE_ROOT} = '../templates';
|
---|
[394] | 50 |
|
---|
[593] | 51 | my $page = HTML::Template->new(filename => "newnode.tmpl");
|
---|
[394] | 52 |
|
---|
[593] | 53 | if ($webvar{nodename}) {
|
---|
| 54 | $sth = $dbh->prepare("insert into nodes (node_type,node_name,node_ip) values (?,?,?)");
|
---|
| 55 | $sth->execute($webvar{type}, $webvar{nodename}, $webvar{nodeip});
|
---|
| 56 | $page->param(nodename => $webvar{nodename});
|
---|
| 57 | if ($sth->err) {
|
---|
| 58 | $page->param(err => $sth->errstr);
|
---|
| 59 | my $msg = "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
|
---|
| 60 | mailNotify($dbh, 'f:nno', "IPDB node add failure", $msg);
|
---|
| 61 | syslog "err", $msg;
|
---|
| 62 | } else {
|
---|
| 63 | syslog "notice", "$authuser added node '$webvar{nodename}'";
|
---|
| 64 | }
|
---|
[394] | 65 | }
|
---|
| 66 |
|
---|
[593] | 67 | print "Content-type: text/html\n\n";
|
---|
| 68 |
|
---|
| 69 | print $page->output;
|
---|
| 70 |
|
---|
[394] | 71 | finish($dbh);
|
---|