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

Last change on this file since 133 was 114, checked in by Kris Deugau, 20 years ago

/branches/stable

Second iteration of billing-failure detection.
Whoops, missed the arrangment of "my ..." declarations

  • Property svn:keywords set to Date Rev Author
File size: 1.9 KB
RevLine 
[56]1# ipdb/cgi-bin/CustIDCK.pm
2# External Customer ID checker stub
3###
4# SVN revision info
5# $Date: 2005-01-05 16:06:37 +0000 (Wed, 05 Jan 2005) $
6# SVN revision $Rev: 114 $
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
[113]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.
[114]36 my $dbh;
[113]37 eval {
38 local $SIG{ALRM} = sub { die "failed connection to billing!!" };
39 alarm 3; # 3-second timeout. This may be too aggressive.
[114]40 $dbh = DBI->connect ("DBI:Pg:host=billing;dbname=custids", "cidcheck", "c1dch4ck");
[113]41 alarm 0; # cancel the alarm
42 };
43 alarm 0; # avoid race conditions. May not be needed here. (Hah!)
44 if ($@ && $@ !~ /failed connection to billing!!/) {
45 $CustIDCK::Error = 1;
46 $CustIDCK::ErrMsg = "Failed connection to billing DB host! Unable to verify CustIDs.";
47 return 0;
48 }
49
[56]50 my $sth = $dbh->prepare("SELECT custid FROM custid WHERE custid = '$custid';");
51 $sth->execute;
52 if ($dbh->err) {
53 $CustIDCK::Error = 1;
54 $CustIDCK::ErrMsg = $dbh->errstr();
55 $sth->finish;
56 $dbh->disconnect;
57 return 0;
58 }
59 my $hr = $sth->fetchrow_hashref();
60 my $status = 0;
61 $status = 1 if ( $hr->{custid} );
62 $sth->finish;
63 $dbh->disconnect;
64 return $status;
65
66 return 0;
67 # Stubs for error messages
68 $CustIDCK::Error = 1 if 1 == 0;
69 $CustIDCK::ErrMsg = "bad foo-frob: 1 == 0";
70}
Note: See TracBrowser for help on using the repository browser.