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