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

Last change on this file since 453 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
RevLine 
[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: 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);
[447]15use CGI::Simple;
[394]16use DBI;
17use CommonWeb qw(:ALL);
18#use POSIX qw(ceil);
19use NetAddr::IP;
20use Sys::Syslog;
21
[417]22# don't remove! required for GNU/FHS-ish install from tarball
23##uselib##
[394]24
[417]25use MyIPDB;
26
27openlog "IPDB","pid","$IPDB::syslog_facility";
28
[394]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
[447]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;
[394]41
[447]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
[394]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;
[416]57 mailNotify($dbh, 'f:nno', "IPDB node add failure",
[394]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.