source: branches/stable/cgi-bin/CustIDCK.pm@ 113

Last change on this file since 113 was 113, checked in by Kris Deugau, 19 years ago

/branches/stable

First-pass patch to avoid just hanging if the billing host to check
customer IDs against fails.

  • Property svn:keywords set to Date Rev Author
File size: 1.9 KB
Line 
1# ipdb/cgi-bin/CustIDCK.pm
2# External Customer ID checker stub
3###
4# SVN revision info
5# $Date: 2004-12-31 16:50:32 +0000 (Fri, 31 Dec 2004) $
6# SVN revision $Rev: 113 $
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
18$VERSION = 1.00;
19@ISA = qw(Exporter);
20@EXPORT = ();
21@EXPORT_OK = qw ( &custid_exist );
22
23# this is really an example stub, and should be replaced by
24# the local admin on installation
25sub custid_exist {
26 my $custid = shift;
27
28 return 1 if $custid =~ /^STAFF$/;
29 return 1 if $custid =~ /^6750400$/; # just in case some later change might block this
30 return 1 if $custid =~ /^\d{7}$/;
31 return 1 if $custid =~ /^\d{10}$/;
32
33# some example code for a database check
34 # Try to catch failures to connect. If the remote server is up but
35 # not responding (this has HAPPENED) we need to break out rather than hanging.
36 eval {
37 local $SIG{ALRM} = sub { die "failed connection to billing!!" };
38 alarm 3; # 3-second timeout. This may be too aggressive.
39 my $dbh = DBI->connect ("DBI:Pg:host=billing;dbname=custids", "cidcheck", "c1dch4ck");
40 alarm 0; # cancel the alarm
41 };
42 alarm 0; # avoid race conditions. May not be needed here. (Hah!)
43 if ($@ && $@ !~ /failed connection to billing!!/) {
44 $CustIDCK::Error = 1;
45 $CustIDCK::ErrMsg = "Failed connection to billing DB host! Unable to verify CustIDs.";
46 return 0;
47 }
48
49 my $sth = $dbh->prepare("SELECT custid FROM custid WHERE custid = '$custid';");
50 $sth->execute;
51 if ($dbh->err) {
52 $CustIDCK::Error = 1;
53 $CustIDCK::ErrMsg = $dbh->errstr();
54 $sth->finish;
55 $dbh->disconnect;
56 return 0;
57 }
58 my $hr = $sth->fetchrow_hashref();
59 my $status = 0;
60 $status = 1 if ( $hr->{custid} );
61 $sth->finish;
62 $dbh->disconnect;
63 return $status;
64
65 return 0;
66 # Stubs for error messages
67 $CustIDCK::Error = 1 if 1 == 0;
68 $CustIDCK::ErrMsg = "bad foo-frob: 1 == 0";
69}
Note: See TracBrowser for help on using the repository browser.