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

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

/branches/htmlform

Convert "new node" miniscript and page to template. See #3.
Update call from assign.tmpl to point to newcity.cgi.
Clean up errors and warnings from newnode.cgi in HTTPD error
log. See #31. (Also note newcity.cgi changes in r459 have
the same cleanups.)

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