source: branches/htmlform/cgi-bin/newnode.cgi@ 450

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

/branches/htmlform

Switch all scripts to use CGI::Simple for HTML form data munging
instead of legacy CommonWeb.pm sub. Remove parse_post() sub from
CommonWeb.pm. See #15.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.7 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-27 17:15:56 +0000 (Tue, 27 Jul 2010) $
7# SVN revision $Rev: 447 $
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 CGI::Simple;
16use DBI;
17use CommonWeb qw(:ALL);
18#use POSIX qw(ceil);
19use NetAddr::IP;
20use Sys::Syslog;
21
22# don't remove! required for GNU/FHS-ish install from tarball
23##uselib##
24
25use MyIPDB;
26
27openlog "IPDB","pid","$IPDB::syslog_facility";
28
29# Collect the username from HTTP auth. If undefined, we're in a test environment.
30my $authuser;
31if (!defined($ENV{'REMOTE_USER'})) {
32 $authuser = '__temptest';
33} else {
34 $authuser = $ENV{'REMOTE_USER'};
35}
36
37# Set up the CGI object...
38my $q = new CGI::Simple;
39# ... and get query-string params as well as POST params if necessary
40$q->parse_query_string;
41
42# Convenience; saves changing all references to %webvar
43##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
44my %webvar = $q->Vars;
45
46my ($dbh,$errstr) = connectDB_My;
47my $sth;
48
49print "Content-type: text/html\n\n";
50
51$sth = $dbh->prepare("insert into nodes (node_type,node_name,node_ip)".
52 " values ('$webvar{type}','$webvar{nodename}','$webvar{nodeip}')");
53$sth->execute;
54
55if ($sth->err) {
56 print "Error adding node to database: ".$sth->errstr;
57 mailNotify($dbh, 'f:nno', "IPDB node add failure",
58 "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr);
59 syslog "err", "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
60} else {
61 print "Node added. Closing this window should refresh the page.";
62 syslog "notice", "$authuser added node '$webvar{nodename}'";
63}
64
65finish($dbh);
Note: See TracBrowser for help on using the repository browser.