source: branches/htmlform/cgi-bin/CustIDCK.pm@ 909

Last change on this file since 909 was 503, checked in by Kris Deugau, 13 years ago

/branches/htmlform

Checkpoint, clearing out references to printError()
All ACL checks that generate error pages should now be converted
to use the new aclerror template. See #15.
Fix a minor bug in CustIDCK.pm - calls to custid_check are being
treated as an object call for some reason.

  • Property svn:keywords set to Date Rev Author
File size: 2.5 KB
RevLine 
[56]1# ipdb/cgi-bin/CustIDCK.pm
2# External Customer ID checker stub
3###
4# SVN revision info
5# $Date: 2011-09-26 22:05:01 +0000 (Mon, 26 Sep 2011) $
6# SVN revision $Rev: 503 $
7# Last update by $Author: kdeugau $
8###
9
10package CustIDCK;
11
12use strict;
13use warnings;
14use Exporter;
15use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
16use DBI;
17
[310]18# Supposed to provide cross-Perl-version signal handling.
19# Not part of stock Debian Perl, use dh-make-perl or just
20# install straight from CPAN.
21# Not part of stock RHEL/CentOS, use cpan2perl, cpanflute,
22# or just install straight from CPAN.
23use Sys::SigAction;
24
[56]25$VERSION = 1.00;
26@ISA = qw(Exporter);
27@EXPORT = ();
28@EXPORT_OK = qw ( &custid_exist );
29
30# this is really an example stub, and should be replaced by
31# the local admin on installation
32sub custid_exist {
[503]33 my $self = shift;
[56]34 my $custid = shift;
35
36 return 1 if $custid =~ /^STAFF$/;
[417]37 return 1 if $custid =~ /^5554242$/; # just in case some later change might block this
[56]38 return 1 if $custid =~ /^\d{7}$/;
39 return 1 if $custid =~ /^\d{10}$/;
40
41# some example code for a database check
[113]42 # Try to catch failures to connect. If the remote server is up but
43 # not responding (this has HAPPENED) we need to break out rather than hanging.
[114]44 my $dbh;
[113]45 eval {
[310]46 my $h = Sys::SigAction::set_sig_handler( 'ALRM',
47 sub { die "failed connection to apex!!"; } );
48
[113]49 alarm 3; # 3-second timeout. This may be too aggressive.
[151]50
51 eval {
[318]52 $dbh = DBI->connect ("DBI:Pg:host=billing;dbname=custids", "cidcheck", "c1dch4ck");
53 die "failed connection to billing!!" if !$dbh;
[151]54# Not certain if this is needed here. It doesn't seem to be.
55# $dbh->ping; # Gotta do this to "force" a "failure". NRGH.
56 };
[113]57 alarm 0; # cancel the alarm
[151]58 $dbh->ping; # Gotta do this to "force" a "failure". NRGH.
[113]59 };
60 alarm 0; # avoid race conditions. May not be needed here. (Hah!)
[318]61 if ($@ && $@ !~ /failed connection to billing!!/) {
[113]62 $CustIDCK::Error = 1;
[318]63 $CustIDCK::ErrMsg = "Failed connection to billing DB host! Unable to verify CustIDs.";
[113]64 return 0;
65 }
66
[151]67 # We should have a valid DB connection by now.
68 my $sth = $dbh->prepare("SELECT custid FROM custid WHERE custid = '$custid'");
[56]69 $sth->execute;
70 if ($dbh->err) {
71 $CustIDCK::Error = 1;
72 $CustIDCK::ErrMsg = $dbh->errstr();
73 $sth->finish;
74 $dbh->disconnect;
75 return 0;
76 }
77 my $hr = $sth->fetchrow_hashref();
78 my $status = 0;
79 $status = 1 if ( $hr->{custid} );
80 $sth->finish;
81 $dbh->disconnect;
82 return $status;
83
84 return 0;
85 # Stubs for error messages
86 $CustIDCK::Error = 1 if 1 == 0;
87 $CustIDCK::ErrMsg = "bad foo-frob: 1 == 0";
88}
Note: See TracBrowser for help on using the repository browser.