4 $stx = db_query(
"select liveserver from cuadmin where cu = '$cu'",$dbx);
5 list($fetcher) = db_fetch_array($stx,0);
20 $client_source = ($client_source_override !=
'' ? $client_source_override :
'CLS');
23 # if we don't have a fetcher value, something is too wrong to continue 26 if (trim($fetcher)==
'') {
27 # give an error and bail 28 print
"<html><head><title>" . $MC->msg(
'Login Canceled') .
29 "</title></head><BODY><CENTER><H1>" .
30 $MC->msg(
'Feature Not Set') .
"</H1><br>" .
31 $MC->msg(
'Contact CU Details') .
36 function get_data($rqx) {
37 # returns open_fail as 0 no error or 1 fopen/popen failed 38 # pipe_err as termination code from piped command (always zero if fopen?) 39 # packet as data returned from core 44 global $client_source;
50 $pipe=1; # force use of popen but allow
for easy recoding
52 $opts =
"--connect-timeout 5 --retry 3 --retry-delay 2";
54 $opts .=
' --max-time 180';
58 if ($client_source !=
'') {
59 $rqx .=
"&SRC={$client_source}";
63 $fd=popen(
"/usr/bin/curl -k -N --silent $opts '$rqx'",
"r");
67 while ($buff = fread ($fd, 1500)) {
70 $pipe_err=pclose($fd);
72 return array($open_fail,$pipe_err,$packet);
74 $fd = @fopen(
"$rqx",
"r");
78 $pkti = stream_get_meta_data($fd);
79 while ((!feof($fd)) && (!$pkti[
'timed_out'])) {
80 $packet .= fread($fd, 4096);
81 $pkti = stream_get_meta_data($fd);
84 if ($pkti[
'timed_out']) {
88 return array($open_fail,$pipe_err,$packet);
92 function get_data_post($postdata) {
95 # returns open_fail as 0 no error or 1 fopen/popen failed 96 # pipe_err as termination code from piped command (always zero if fopen?) 97 # packet as data returned from core 107 $pipe=1; # force use of popen but allow
for easy recoding
108 $opts =
"--connect-timeout 5 --retry 3 --retry-delay 2";
110 $opts .=
' --max-time 180';
116 $fd=popen(
"/usr/bin/curl -k -N --silent $opts -d '$postdata' '$fetcher'",
"r");
120 while ($buff = fread ($fd, 1500)) {
123 $pipe_err=pclose($fd);
125 return array($open_fail,$pipe_err,$packet);
130 $params = array(
'http' => array(
'method' =>
'POST',
'content' => $postdata));
131 $ctx = stream_context_create($params);
134 $fd = @fopen($fetcher,
'r',
false, $ctx);
138 $pkti = stream_get_meta_data($fd);
139 while ((!feof($fd)) && (!$pkti[
'timed_out'])) {
140 $packet .= fread($fd, 4096);
141 $pkti = stream_get_meta_data($fd);
144 if ($pkti[
'timed_out']) {
148 return array($open_fail,$pipe_err,$packet);
154 function fetch_packet($Cu,$Cn,$Clw) {
157 # set environment for programs. 163 global $CU2_SHOWHOLD;
167 $R3=(trim($Ml) ==
"" || $Ml==
"no\@email.com" ?
"NULL" : urlencode(trim($Ml)));
168 $FETCHER =
"$fetcher";
169 # syslog(LOG_INFO,"fetcher: $fetcher"); 171 $PKTINTERVAL = ((is_null($Clw) || $Clw == 0) ? 300 : $Clw);
173 # read last pktstamp from database. Calculate new threshold as 174 # now - pktinterval; if pktstamp > threshold, return (use existing) 176 $dbh = db_pconnect();
177 $sql =
"select pktstamp, pktdate, coalesce(pktattempt,1), lastlogin from cuusers 178 where cu = '" . $Cu .
"' and user_name = '" . $Cn .
"'";
179 $sth = db_query($sql,$dbh);
180 list($pktstamp, $pktdate, $pktattempt, $lastlogin) = db_fetch_array($sth,0);
181 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
182 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
183 $lastlogin = (empty($lastlogin) ?
'NULL' : urlencode(trim($lastlogin)));
185 $threshold = mktime() - $PKTINTERVAL;
187 if (abs($pktstamp) > $threshold || $pktattempt > $threshold) {
return array(0,$pktdate,
"Too soon to ask again"); }
191 $sql =
"update cuusers set pktattempt=" . time() .
" 192 where cu = '" . $Cu .
"' and user_name = '" . $Cn .
"'";
193 $sth = db_query($sql,$dbh);
195 $pktstamp = ($pktstamp < 0 ? 1 : $pktstamp);
197 #$fs = date("D M j Y H:i:s T",$pktstamp); 198 #$ft = date("D M j Y H:i:s T",$threshold); 200 #syslog(LOG_INFO,"packetstamp: $pktstamp"); 201 # Calculate a cutoff date to determine how much data to retrieve 203 # if this feature is turned off in cuadmin, the cutoff is very old 205 $cutoff =
"20000101";
208 # if the last packet is newer than 20000101 and history days is set 209 # calculate a newer cutoff to reduce the packet size 211 if ($pktstamp > 946710000 && $Fhdays > 0 ) {
213 # If the last packet was fairly recent, only fetch 7 days 214 # "recent" defined as 3 times the packet timeout setting 216 $throttle = mktime() - (3 * $Clw);
217 if ($pktstamp > $throttle) {
218 $cutoff = date(
"Ymd",mktime()-604800);
220 $cutoff = date(
"Ymd",$pktstamp-(86400 * $Fhdays));
223 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
224 $rqx =
"{$FETCHER}{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff&ref3=$R3&lastlogin=$lastlogin";
226 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
228 if (trim(
"$packet") ==
"") {
229 if ($open_fail == 1) {
230 trigger_error(
"$Cu:$Cn Inquiry open failed", E_USER_ERROR);
232 trigger_error(
"$Cu:$Cn Inquiry empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
234 return array(999, 1,
"Unable to retrieve data");
236 if (preg_match(
"/<inquiry>/si",$packet) &&
237 !preg_match(
"/<\/inquiry>/si",$packet)) {
238 trigger_error(
"$Cu:$Cn Inquiry short packet response(pipe_err $pipe_err)", E_USER_ERROR);
239 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
240 @fwrite($fp,
"$Cu:$Cn Inquiry short packet\n${rqx}\n");
241 @fwrite($fp,
"$packet\n");
243 return array(999, 1,
"Unable to retrieve data");
246 $pktpieces = array();
248 $parameters = (preg_match(
"/<parameters>\n?(.*)\n?<\/parameters>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
249 list($mem, $pcutoff) = explode(
"\t",$parameters);
251 # if the packet presents a cutoff date, let it override our request 252 $cutoff = (trim($pcutoff) ==
"" ? trim($cutoff) : trim($pcutoff));
253 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
254 $member = (preg_match(
"/<member>\n?(.*)\n?<\/member>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
255 list($mem, $statcode, $statdesc) = explode(
"\t",$status);
256 if (
"$member" >
"") {list($mem) = explode(
"\t",$member);}
257 if (trim(
"$mem") !=
"$Cn") {
258 trigger_error(
"$Cu possibly out-of-sync ($member:$mem:$Cn)", E_USER_ERROR);
260 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
261 @fwrite($fp,
".${mem}:${Cn}. mismatch for $Cu\n");
262 @fwrite($fp,
"${rqx}\n");
263 @fwrite($fp,
"${packet}\n");
264 @fwrite($fp,
"${p}\n");
266 return array(999, 1,
"Unable to retrieve data");
268 $time = (preg_match(
"/<time>\n?(.*)<\/time>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
269 if ($time >
"" ) { list($pktstamp, $pktdate) = explode (
"\t",$time);}
271 # check the return status to decide what to do here 273 # 101 New Data -- process packet, update pktstamp 274 # 201 System Unavailable, New Data -- process packet, update pktstamp 275 # 100 No New Data -- update pktstamp 276 # 200 System Unavailable, No New Data -- return immediately 277 # 202 System Unavailable, No Data -- return immediately 278 # 001 Invalid Account Number -- return immediately 279 # 002 Invalid Password -- change to 001 Invalid Account and return 280 # 003 Closed Account -- change to 001 Invalid Account and return 281 # 999 Calling error or Invalid Parms -- return immediately 287 # Need to refresh the db data. Start parsing that packet... 288 # just in case a packet is in process, check the db first, 289 # if the timestamp is negative and new, return instead 291 $sql =
"select pktstamp, pktdate from cuusers 292 where cu = '" . $Cu .
"' and user_name = '" . $Cn .
"'";
293 $sth = db_query($sql,$dbh);
294 list($ps, $pd) = db_fetch_array($sth,0);
295 $ps = (empty($ps) ? 1 : $ps);
296 $pd = (empty($pd) ? date(
"D M j Y H:i:s T") : $pd);
297 if (abs($ps) > $threshold) {
return array(0,$pd,
"Too soon to ask again"); }
299 # set pktstamp to negative of current pktstamp so if we die 300 # in the middle next query will force reload 302 $sql =
"update cuusers set pktstamp = " . mktime() * -1 .
", 303 pktdate = '" . date(
"D M j Y H:i:s T") .
"' 304 where cu = '" . $Cu .
"' 305 and user_name = '" . $Cn .
"'";
306 $sth = db_query($sql,$dbh);
308 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
309 if (($Fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) { $tblist[]=
"holds"; }
310 foreach($tblist as $tbl) {
311 preg_match(
"/<$tbl>\n?(.*)<\/$tbl>/si",$packet,$pktpieces);
312 $$tbl = explode (
"\n",$pktpieces[1]);
315 # stuff each piece in the db 317 $sql =
"delete from ${Cu}${tbl} 318 where accountnumber='" . $Cn .
"'";
319 if ($tbl ==
"accounthistory" || $tbl ==
"loanhistory"){
320 $sql .=
" and date >= '$cutoff'";
322 $sth = db_query($sql,$dbh);
325 if ($tbl ==
"loanhistory") {
326 $cql =
"copy ${Cu}${tbl} (AccountNumber, LoanNumber, TraceNumber, 327 Date, PrincipleAmount, InterestAmount, Description, 329 if (($Fset2 & $CU2_ESCHEMA) == $CU2_ESCHEMA)
330 $cql .=
", Fee, Escrow";
331 $cql .=
") from stdin with null as ''";
333 $cql =
"copy ${Cu}${tbl} from stdin with null as ''";
336 $sth = db_query($cql,$dbh);
340 while (list ($key, $line) = each ($$tbl)) {
341 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
342 $line = preg_replace(
"/ $/",
"",$line);
343 $line = preg_replace(
"/\\0/",
" ",$line);
344 @pg_put_line($dbh,
"$line\n");
346 if (!@pg_put_line($dbh,
"\\.\n")) {$pgerr .= @pg_last_error($dbh);}
347 if (!@pg_end_copy($dbh)) {
349 # define_syslog_variables(); 350 # syslog(LOG_ERR,"FAILED copying $tbl for $Cu:$Cn Statcode $statcode Cutoff $cutoff Error: $pgerr Browser " . $_SERVER['HTTP_USER_AGENT'] . "\n"); 351 $fp=@fopen(
"/tmp/packetdump.txt",
"a");
352 @fwrite($fp,
".${Cn}:${Cu}. copy failed\n");
353 @fwrite($fp,
"${rqx}\n");
354 @fwrite($fp,$packet);
356 while (list ($key, $line) = each ($$tbl)) {
357 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
358 $line = preg_replace(
"/ $/",
"",$line);
359 $line = preg_replace(
"/\\0/",
" ",$line);
360 @fwrite($fp,
"$line\n");
370 $sql =
"update cuusers set pktstamp = $pktstamp, 371 pktdate = '" . $pktdate .
"', 372 pktattempt = " . time() .
" 373 where cu = '" . $Cu .
"' 374 and user_name = '" . $Cn .
"'";
375 $sth = db_query($sql,$dbh);
377 #syslog(LOG_ERR,"FAILED setting pktstamp for $Cu:$Cn\n$sql"); 383 return array(
"$statcode",
"$pktdate",
"$statdesc");
385 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
391 $statdesc =
'INVALID ACCOUNT NUMBER';
394 return array(
"$statcode", 1,
"$statdesc");
398 function fetch_mir($Cu,$Cn) {
401 # set environment for programs. 405 $FETCHER =
"$fetcher";
406 # syslog(LOG_INFO,"fetcher: $fetcher"); 409 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
410 $rqx =
"{$FETCHER}{$delim}member=$Cn&type=MIR&f=xxxx";
412 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
414 if (trim(
"$packet") ==
"") {
415 if ($open_fail == 1) {
416 trigger_error(
"$Cu:$Cn MIR open failed", E_USER_ERROR);
418 trigger_error(
"$Cu:$Cn MIR empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
420 $mirinfo[status][status]=999;
421 $mirinfo[status][asofdate]=1;
422 $mirinfo[status][reason]=
"Unable to retrieve data";
425 if (preg_match(
"/<memberinfo>/si",$packet) &&
426 !preg_match(
"/<\/memberinfo>/si",$packet)) {
427 trigger_error(
"$Cu:$Cn MIR short packet response(pipe_err $pipe_err)", E_USER_ERROR);
428 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
429 @fwrite($fp,
"$Cu:$Cn MIR short packet\n${rqx}\n");
430 @fwrite($fp,
"$packet\n");
432 $mirinfo[status][status]=999;
433 $mirinfo[status][asofdate]=1;
434 $mirinfo[status][reason]=
"Unable to retrieve data";
438 $pktpieces = array();
440 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
441 $member = (preg_match(
"/<member>\n?(.*)\n?<\/member>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
442 list($mem, $statcode, $statdesc) = explode(
"\t",$status);
443 if (
"$member" >
"") {list($mem) = explode(
"\t",$member);}
444 if (trim(
"$mem") !=
"$Cn") {
445 trigger_error(
"$Cu possibly out-of-sync ($mem:$Cn)", E_USER_ERROR);
446 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
447 @fwrite($fp,
".${mem}:${Cn}. mismatch for $Cu\n");
448 @fwrite($fp,
"${rqx}\n");
449 @fwrite($fp,
"${packet}\n");
450 @fwrite($fp,
"${p}\n");
452 $mirinfo[status][status]=999;
453 $mirinfo[status][asofdate]=1;
454 $mirinfo[status][reason]=
"Unable to retrieve data";
458 # check the return status to decide what to do here 460 # 101 New Data -- process packet 461 # 201 System Unavailable, New Data -- can't use stale for MIR 462 # -- change to 200 and return 463 # 100 No New Data -- return immediately 464 # 200 System Unavailable, No New Data -- return immediately 465 # 202 System Unavailable, No Data -- return immediately 466 # 001 Invalid Account Number -- return immediately 467 # 002 Invalid Password -- change to 001 Invalid Account and return 468 # 003 Closed Account -- change to 001 Invalid Account and return 469 # 999 Calling error or Invalid Parms -- return immediately 474 # New data. Start parsing that packet... 476 $tblist = array(
"info");
477 foreach($tblist as $tbl) {
478 preg_match(
"/<$tbl>\n?(.*)<\/$tbl>/si",$packet,$pktpieces);
479 $$tbl = explode (
"\n",$pktpieces[1]);
484 # format and return array ala new cu_data functions 485 while (list ($key, $line) = each ($$tbl)) {
486 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
487 $line = preg_replace(
"/ $/",
"",$line);
488 $line = preg_replace(
"/\\0/",
" ",$line);
489 list($AccountNumber, $FirstName,$MiddleName,$LastName,$Email,$HomePhone,$WorkPhone,$CellPhone,$Fax,$SSN,$Address1,$Address2,$City,$State,$Zip,$CC,$DOB) = explode(
"\t",$line);
491 $mirinfo[status][status]=$statcode;
492 $mirinfo[status][asofdate]= date(
"D M j Y H:i:s T");
493 $mirinfo[status][reason]=$statdesc;
495 $mirinfo[$tbl][
'AccountNumber']=$AccountNumber;
496 $mirinfo[$tbl][
'FirstName']=$FirstName;
497 $mirinfo[$tbl][
'MiddleName']=$MiddleName;
498 $mirinfo[$tbl][
'LastName']=$LastName;
499 $mirinfo[$tbl][
'Email']=$Email;
500 $mirinfo[$tbl][
'HomePhone']=$HomePhone;
501 $mirinfo[$tbl][
'WorkPhone']=$WorkPhone;
502 $mirinfo[$tbl][
'CellPhone']=$CellPhone;
503 $mirinfo[$tbl][
'Fax']=$Fax;
504 $mirinfo[$tbl][
'SSN']=$SSN;
505 $mirinfo[$tbl][
'Address1']=$Address1;
506 $mirinfo[$tbl][
'Address2']=$Address2;
507 $mirinfo[$tbl][
'City']=$City;
508 $mirinfo[$tbl][
'State']=$State;
509 $mirinfo[$tbl][
'Zip']=$Zip;
510 $mirinfo[$tbl][
'CC']=$CC;
511 $mirinfo[$tbl][
'DOB']=$DOB;
518 $mirinfo[status][status]=
'201';
519 $mirinfo[status][asofdate]= date(
"D M j Y H:i:s T");
520 $mirinfo[status][reason]=
"Unusable Stale Data";
526 $mirinfo[status][status]=$statcode;
527 $mirinfo[status][asofdate]= date(
"D M j Y H:i:s T");
528 $mirinfo[status][reason]=$statdesc;
533 $mirinfo[status][status]=
'001';
534 $mirinfo[status][asofdate]= 1;
535 $mirinfo[status][reason]=
'INVALID ACCOUNT NUMBER';
540 $mirinfo[status][status]=$statcode;
541 $mirinfo[status][asofdate]= 1;
542 $mirinfo[status][reason]=$statdesc;
559 function post_application($userresp_table, $apprespid, $purpose, $appemail, $appdata, $appmember=
'NULL') {
561 global $fetcher, $dbh;
571 $packetdata =
"member={$appmember}&type=$purpose&tran_code=NULL&ref1=" . urlencode($appdata) .
"&ref2=NULL&ref3=" . urlencode($appemail).
"&ref4=NULL&ref5=NULL&amount=0.00";
585 list ($open_fail, $pipe_err, $packet) = get_data_post($rqx);
587 if (trim($packet) ==
"") {
588 if ($open_fail == 1) {
589 trigger_error(
"$Cu:$Cn Transaction open failed", E_USER_ERROR);
591 trigger_error(
"$Cu:$Cn Transaction empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
597 $ret_statdesc =
"We are unable to contact your Credit Union at this time. You may still save the application and submit it later.";
601 $pkgpattern =
"/<status>\n?(.*)\n?<\/status>/si";
603 preg_match(
"$pkgpattern",$packet,$pktpieces);
604 list($returned_loan_app_id, $statcode, $statdesc) = explode(
"\t",$pktpieces[1]);
606 $ret_stat = trim($statcode);
607 $ret_statdesc = trim($statdesc);
609 switch (trim($statcode)) {
616 $ret_statdesc =
"Loan was successfully submitted.";
617 $sql_set =
"respcoreloanappid = " . intval($returned_loan_app_id) .
", 618 respsubmiton = now(), 620 resplastinquire = now(), 621 respstatusdesc = '" . prep_save ($ret_statdesc) .
"' ";
634 $sql_set =
"respstatus = '$statcode', 635 respstatusdesc = '" . prep_save($statdesc) .
"' ";
652 $sql_set =
"respstatus = '$statcode', 653 resplastinquire = now(), 654 respstatusdesc = '" . prep_save($statdesc) .
"' ";
659 $ret_statdesc =
"We are currently having problems communicating with the credit union. Please save your application and try to submit again later. <br>$statdesc";
662 if ($sql_set !=
'') {
664 $sql =
"UPDATE $userresp_table 666 WHERE respid = " . intval($apprespid);
667 if (!$resp_rs = db_query($sql, $dbh)) {
669 $ret_statdesc =
"An unknown error occurred. Please try again.";
677 return array($ret_stat, $ret_statdesc);
697 function GetEalertsData($pDbh, $pHbEnv, $pFetcher, $pFormData) {
699 $retData = Array(
'status' =>
'',
'desc' =>
'',
'data' =>
'');
700 $packetDataTag =
'DataBase64';
704 $packetdata =
"member={$pHbEnv['Cn']}&type=OTHER&product=EALERTS&ref3=" . urlencode($pHbEnv[
'Ml']) .
"&options[]=" . base64_encode($pFormData);
709 list ($open_fail, $pipe_err, $packet) = get_data_post($rqx);
710 if (trim($packet) ==
"") {
715 if ($open_fail == 1) {
716 trigger_error(
"$Cu:$Cn Ealerts open failed", E_USER_ERROR);
718 trigger_error(
"$Cu:$Cn Ealerts empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
723 $retData[
'status'] =
"999";
724 $retData[
'desc'] =
"We are unable to contact your Credit Union at this time. You may still save the application and submit it later.";
731 $statusLine = GetPktSegment(
'status', $packet);
732 list($cumember, $statcode, $statdesc) = explode(
"\t", $statusLine);
736 $memberLine = GetPktSegment(
'member', $packet);
737 list($coremember, $coreproduct) = explode(
"\t", $memberLine);
739 $retData[
'status'] = trim($statcode);
740 $retData[
'desc'] = trim($statdesc);
743 if ($coremember != $pHbEnv[
'Cn']) {
745 $retData[
'status'] =
"999";
746 $retData[
'desc'] =
"Unable to retrieve data";
748 trigger_error(
"$Cu possibly out-of-sync ($member:$mem:$Cn) EAlert", E_USER_ERROR);
749 $fp = @fopen(
"/tmp/packetnew.txt",
"a");
750 @fwrite($fp,
".${mem}:${Cn}. mismatch for $Cu Ealert\n");
751 @fwrite($fp,
"${rqx}\n");
752 @fwrite($fp,
"${packet}\n");
753 @fwrite($fp,
"${p}\n");
757 switch (trim($statcode)) {
762 $retData[
'data'] = GetPktSegment($packetDataTag, $packet);
766 $retData[
'status'] =
"999";
767 $retData[
'desc'] =
"We are currently having problems communicating with the credit union. Please save your application and try to submit again later. <br>$statdesc";
777 function post_packet($Mem, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt) {
782 $FETCHER =
"$fetcher";
784 $Clw = ((is_null($Clw) || $Clw == 0) ? 300 : $Clw);
785 $pktpieces = array();
787 $R1 = (trim($R1) ==
"" ?
"NULL" : $R1);
788 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
789 $R3 = (trim($R3) ==
"" ?
"NULL" : urlencode($R3));
790 $R4 = (trim($R4) ==
"" ?
"NULL" : urlencode($R4));
791 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
793 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
794 $rqx =
"{$FETCHER}{$delim}member=$Mem&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt";
796 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
798 if (trim(
"$packet") ==
"") {
799 if ($open_fail == 1) {
800 trigger_error(
"$Cu:$Cn Transaction open failed", E_USER_ERROR);
802 trigger_error(
"$Cu:$Cn Transaction empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
804 return array(999, 1,
"Unable to retrieve data");
807 $pkgpattern =
"/<status>\n?(.*)\n?<\/status>/si";
809 preg_match(
"$pkgpattern",$packet,$pktpieces);
810 list($mem, $statcode, $statdesc) = explode(
"\t",$pktpieces[1]);
811 # update packetstamp so next query gets new data 812 # 10/30/09 ONLY if pktstamp is within (3*Clw) -- avoid leaving holes by 813 # getting short packets when they haven't gotten a good full packet 814 $tstamp = mktime()-(2*$Clw);
815 $onlyif = mktime()-(3*$Clw);
816 $dbh = db_pconnect();
817 $sql =
"update cuusers set pktstamp = $tstamp, 818 pktdate = '" . date(
"D M j Y H:i:s T") .
"', 820 where cu = '" . $Cu .
"' 821 and ((user_name = '" . $Cn .
"' and pktstamp > $onlyif)";
822 if ($R5 <>
"NULL" && $R5 <> $Cn) {
823 $sql .=
" or (user_name = '" . $R5 .
"' and pktstamp > $tstamp)";
826 $sth = db_query($sql,$dbh);
828 #syslog(LOG_ERR,"FAILED setting pktstamp for $Cu:$Cn\n$sql"); 830 return array($statcode, $statdesc);
832 function post_exp_pkt($Mem, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo) {
837 $FETCHER =
"$fetcher";
839 $Clw = ((is_null($Clw) || $Clw == 0) ? 300 : $Clw);
840 $pktpieces = array();
842 $R1 = (trim($R1) ==
"" ?
"NULL" : $R1);
843 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
844 $R2 = (trim($R2) ==
"-" ?
"NULL" : $R2);
845 $R3 = (trim($R3) ==
"" ?
"NULL" : urlencode($R3));
846 $R4 = (trim($R4) ==
"" ?
"NULL" : urlencode($R4));
847 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
848 $tauth = (trim($tauth) ==
"" ?
"$Cn" : trim($tauth));
849 $tmemo = (trim($tmemo) ==
"" ?
"NULL" : urlencode(trim($tmemo)));
851 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
852 $rqx =
"{$FETCHER}{$delim}member=$Mem&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt&tauth=$tauth&tmemo=$tmemo";
854 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
856 if (trim(
"$packet") ==
"") {
857 if ($open_fail == 1) {
858 trigger_error(
"$Cu:$Cn Transaction open failed", E_USER_ERROR);
860 trigger_error(
"$Cu:$Cn Transaction empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
862 return array(999, 1,
"Unable to retrieve data");
865 $pkgpattern =
"/<status>\n?(.*)\n?<\/status>/si";
867 preg_match(
"$pkgpattern",$packet,$pktpieces);
868 list($mem, $statcode, $statdesc) = explode(
"\t",$pktpieces[1]);
869 # update packetstamp so next query gets new data 870 # 10/30/09 ONLY if pktstamp is within (3*Clw) -- avoid leaving holes by 871 # getting short packets when they haven't gotten a good full packet 872 $tstamp = mktime()-(2*$Clw);
873 $onlyif = mktime()-(3*$Clw);
874 $dbh = db_pconnect();
875 $sql =
"update cuusers set pktstamp = $tstamp, 876 pktdate = '" . date(
"D M j Y H:i:s T") .
"', 878 where cu = '" . $Cu .
"' 879 and ((user_name = '" . $Cn .
"' and pktstamp > $onlyif)";
880 if ($R5 <>
"NULL" && $R5 <> $Cn) {
881 $sql .=
" or (user_name = '" . $R5 .
"' and pktstamp > $tstamp)";
884 $sth = db_query($sql,$dbh);
886 #syslog(LOG_ERR,"FAILED setting pktstamp for $Cu:$Cn\n$sql"); 888 return array($statcode, $statdesc);
890 function post_pkt_track($Mem, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo) {
895 $FETCHER =
"$fetcher";
897 $Clw = ((is_null($Clw) || $Clw == 0) ? 300 : $Clw);
898 $pktpieces = array();
900 $R1 = (trim($R1) ==
"" ?
"NULL" : $R1);
901 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
902 $R2 = (trim($R2) ==
"-" ?
"NULL" : $R2);
903 $R3 = (trim($R3) ==
"" ?
"NULL" : urlencode($R3));
904 $R4 = (trim($R4) ==
"" ?
"NULL" : urlencode($R4));
905 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
906 $tauth = (trim($tauth) ==
"" ?
"$Cn" : trim($tauth));
907 $tmemo = (trim($tmemo) ==
"" ?
"NULL" : urlencode(trim($tmemo)));
909 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
910 $rqx =
"{$FETCHER}{$delim}member=$Mem&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt&tauth=$tauth&tmemo=$tmemo";
912 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
914 if (trim(
"$packet") ==
"") {
915 if ($open_fail == 1) {
916 trigger_error(
"$Cu:$Cn Transaction open failed", E_USER_ERROR);
917 track_pkt($Cu,$Cn,$Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo,
'F',
'999',
'Transaction open failed');
919 trigger_error(
"$Cu:$Cn Transaction empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
920 track_pkt($Cu,$Cn,$Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo,
'F',
'999',
'Transaction empty packet response (pipe_err ' . $pipe_err .
')');
922 return array(999, 1,
"Unable to retrieve data");
925 $pkgpattern =
"/<status>\n?(.*)\n?<\/status>/si";
927 preg_match(
"$pkgpattern",$packet,$pktpieces);
928 list($mem, $statcode, $statdesc) = explode(
"\t",$pktpieces[1]);
930 $pf = ($statcode !=
'000' ?
'F' :
'P');
931 list($confcode) = track_pkt($Cu,$Cn,$Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo,$pf,$statcode,$statdesc);
933 # update packetstamp so next query gets new data 934 # 10/30/09 ONLY if pktstamp is within (3*Clw) -- avoid leaving holes by 935 # getting short packets when they haven't gotten a good full packet 936 $tstamp = mktime()-(2*$Clw);
937 $onlyif = mktime()-(3*$Clw);
938 $dbh = db_pconnect();
939 $sql =
"update cuusers set pktstamp = $tstamp, 940 pktdate = '" . date(
"D M j Y H:i:s T") .
"', 942 where cu = '" . $Cu .
"' 943 and ((user_name = '" . $Cn .
"' and pktstamp > $onlyif)";
944 if ($R5 <>
"NULL" && $R5 <> $Cn) {
945 $sql .=
" or (user_name = '" . $R5 .
"' and pktstamp > $tstamp)";
948 $sth = db_query($sql,$dbh);
950 #syslog(LOG_ERR,"FAILED setting pktstamp for $Cu:$Cn\n$sql"); 952 return array($statcode, $statdesc, $confcode);
954 function track_pkt($Cu,$Cn,$Tc, $R1, $R2, $R3, $R4, $R5, $Amt, $tauth, $tmemo,$pf,$statcode,$statdesc) {
956 $sql =
"insert into cutransactionlog (cu, accountnumber, transactioncode, r1fsfx, r2tsfx, r3email, 957 r4misc1, r5tmem, memberto, amount, date, tauth, tmemo, corestatus, corecode, coremsg, ipaddr) 958 values ('$Cu','$Cn','$Tc','$R1','$R2', '" . prep_save($R3) .
"','$R4','$R5','$R5',$Amt,now(), '$tauth','" 959 . prep_save($tmemo) .
"','$pf','$statcode','" . prep_save($statdesc) .
"','{$_SERVER['REMOTE_ADDR']}'); ";
960 $sql.=
"select currval('cutransactionlog_id_seq'); ";
962 $sth = db_query($sql, $dbh);
966 trigger_error(
"$Cu:$Cn Track transaction failed ($sql)", E_USER_ERROR);
970 list($tid) = db_fetch_array($sth,0);
974 # confirmation code is julian day . (seconds since midnight as 7digits) 975 # then converted to hex and formatted as 2-2-2-2 to minimize hex swearing 979 $tid=sprintf(
'%08s',dechex(($condate[
'yday'] + 1 .
981 $condate[
'hours'] * 3600 +
982 $condate[
'minutes'] * 60 +
983 $condate[
'seconds'] )))));
984 $tid = sprintf(
'%s-%s-%s-%s',substr($tid,0,2),substr($tid,2,2),substr($tid,4,2),substr($tid,6,2));
990 function fetch_user($Cu, $Cn, $pwd, $insflag) {
993 global $CU2_SHOWHOLD;
996 global $MEM_LOGIN_FAILED_PWD;
998 if ($pwd ===
'0') {$pwd =
'00';}
1000 $R3 = (trim($Ml) ==
"" || $Ml ==
"no\@email.com" ?
"NULL" : urlencode(trim($Ml)));
1001 $FETCHER = $GLOBALS[
'fetcher'];
1003 #syslog(LOG_ERR,"Fetch User from $FETCHER with $Cu $Cn $pwd $insflag"); 1004 $dbh = db_pconnect();
1005 $sql =
"select coalesce(retrylimit,5) as retry, 1006 coalesce(gracelimit,5) as grace, flagset, flagset2 1007 from cuadmin where cu = '$Cu'";
1008 $sth = db_query($sql, $dbh);
1009 list($retry, $grace, $Fset, $Fset2) = db_fetch_array($sth, 0);
1011 $retry = ($retry <= 0 ? 5 : $retry);
1012 $grace = ($grace <= 0 ? 5 : $grace);
1013 $msg_tx = (($Fset & 32) == 32 ? 512 : 0);
1015 # define_syslog_variables(); 1016 #syslog(LOG_INFO,"$FETCHER?member=$Cn&type=I&if_mod_since=1&pass=$pwd"); 1017 $delim = (strpos($FETCHER,
'?') ===
false ?
'?' :
'&');
1018 $rqx =
"{$FETCHER}{$delim}member=$Cn&type=I&if_mod_since=1&cutoff=20060101&pass=" . urlencode($pwd) .
"&ref3=$R3";
1020 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1022 if (trim(
"$packet") ==
"") {
1023 if ($open_fail == 1) {
1024 trigger_error(
"$Cu:$Cn Inquiry open failed", E_USER_ERROR);
1026 trigger_error(
"$Cu:$Cn Inquiry empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
1028 return array(999, 1,
"Unable to retrieve data");
1031 if (preg_match(
"/<inquiry>/si", $packet) &&
1032 !preg_match(
"/<\/inquiry>/si", $packet)) {
1033 trigger_error(
"$Cu:$Cn Inquiry short packet response(curl_err $curl_err)", E_USER_ERROR);
1034 $fp = @fopen(
"/tmp/packetnew.txt",
"a");
1035 @fwrite($fp,
"$Cu:$Cn Inquiry short packet\n${rqx}\n");
1036 @fwrite($fp,
"$packet\n");
1038 return array(999, 1,
"Unable to retrieve data");
1041 $pktpieces = array();
1043 $parameters = (preg_match(
"/<parameters>\n?(.*)\n?<\/parameters>/si", $packet, $pktpieces) ? $pktpieces[1] :
"");
1044 list($mem, $pcutoff) = explode(
"\t", $parameters);
1046 # if the packet presents a cutoff date, let it override our request 1047 $cutoff = (trim($pcutoff) ==
"" ?
"20060101" : trim($pcutoff));
1048 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si", $packet, $pktpieces) ? $pktpieces[1] :
"");
1049 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1050 if (trim($mem) != $Cn) {
1051 return array(999, 1,
"Unable to retrieve data");
1053 $time = (preg_match(
"/<time>\n?(.*)\n?<\/time>/si", $packet, $pktpieces) ? $pktpieces[1] :
"");
1054 list($pktstamp, $pktdate) = explode(
"\t", $time);
1055 $member = (preg_match(
"/<member>\n?(.*)\n?<\/member>/si", $packet, $pktpieces) ? $pktpieces[1] :
"");
1056 list($pktuser, $pktpwd) = explode(
"\t", $member);
1057 $pktpwd = trim($pktpwd);
1059 # check the return status to decide what to do here 1060 # 101 New Data -- process packet, update pktstamp 1061 # 201 System Unavailable, New Data -- ignore packet, couldn't verify 1062 # password with core system 1063 # 100 No New Data -- update pktstamp 1064 # 200 System Unavailable, No New Data -- return immediately 1065 # 202 System Unavailable, No Data -- return immediately 1066 # 002 Invalid Password -- If insflag is set, insert user record 1067 # so we can lockout 'brute force' hack attempts 1068 # 003 Closed Account -- change to 001 Invalid Account and return 1069 # 001 Invalid Account Number -- return immediately 1070 # 999 Calling error or Invalid Parms -- return immediately 1073 switch ($statcode) {
1075 # Need to refresh the db data. Start parsing that packet... 1076 # Insert the user record 1077 # or update an existing 'NULL PASSWORD' record 1078 # set pktstamp to 1 so if we die in the middle next query will force reload 1080 $salt = compute_salt(0);
1081 $hashpwd = crypt($pwd, $salt);
1082 $hashpwd = crypt($pwd);
1084 if ($insflag == 1) {
1085 $sql =
"insert into cuusers ( 1086 cu, user_name, passwd, pktstamp, pktdate, 1087 forcechange, forceremain, failedremain, pwchange, msg_tx) 1089 '$Cu', '$Cn', '$hashpwd'," . mktime() * -1 .
", '" .
1090 date(
"D M j Y H:i:s T") .
"', 1091 'Y',$grace, $retry, now(),$msg_tx)";
1093 $sql =
"update cuusers set passwd = '$hashpwd', 1094 pktstamp = " . mktime() * -1 .
", 1095 pktdate = '" . date(
"D M j Y H:i:s T") .
"', 1096 forcechange = 'Y', forceremain = $grace, 1097 failedremain = $retry, pwchange = now(), 1099 where cu = '$Cu' and user_name = '$Cn'";
1101 $sth = db_query($sql, $dbh);
1103 $pg_error = pg_errormessage();
1104 # syslog(LOG_INFO,"$pg_error : $sql"); 1107 #syslog(LOG_INFO,"User inserted: $sql"); 1110 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
1111 if (($Fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) {
1112 $tblist[] =
"holds";
1114 foreach ($tblist as $tbl) {
1115 preg_match(
"/<$tbl>\n?(.*)<\/$tbl>/si", $packet, $pktpieces);
1116 $$tbl = explode(
"\n", $pktpieces[1]);
1119 # stuff each piece in the db 1121 $sql =
"delete from ${Cu}${tbl} 1122 where accountnumber='$Cn'";
1123 if ($tbl ==
"accounthistory" || $tbl ==
"loanhistory") {
1124 $sql .=
" and date >= '$cutoff'";
1126 $sth = db_query($sql, $dbh);
1128 if (
sizeof($$tbl)) {
1130 if ($tbl ==
"loanhistory") {
1131 $cql =
"copy ${Cu}${tbl} (AccountNumber, LoanNumber, TraceNumber, 1132 Date, PrincipleAmount, InterestAmount, Description, 1134 if (($Fset2 & $CU2_ESCHEMA) == $CU2_ESCHEMA)
1135 $cql .=
", Fee, Escrow";
1136 $cql .=
") from stdin with null as ''";
1138 $cql =
"copy ${Cu}${tbl} from stdin with null as ''";
1141 $sth = db_query($cql, $dbh);
1145 while (list ($key, $line) = each($$tbl)) {
1146 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
1147 $line = preg_replace(
"/ $/",
"", $line);
1148 $line = preg_replace(
"/\\0/",
" ", $line);
1149 @pg_put_line($dbh,
"$line\n");
1151 @pg_put_line($dbh,
"\\.\n");
1152 if (!@pg_end_copy($dbh)) {
1154 # define_syslog_variables(); 1155 # syslog(LOG_ERR,"FAILED copying $tbl for $Cu:$Cn Statcode $statcode Cutoff $cutoff Error " . pg_last_error($dbh) . "\n"); 1162 if ($errstat == 0) {
1163 $sql =
"update cuusers set pktstamp = $pktstamp, 1164 pktdate = '" . $pktdate .
"' 1165 where cu = '" . $Cu .
"' 1166 and user_name = '" . $Cn .
"'";
1167 $sth = db_query($sql, $dbh);
1169 #syslog(LOG_ERR,"FAILED setting pktstamp for $Cu:$Cn\n$sql"); 1175 if ($errstat == 0) {
1176 return array(
"$statcode",
"$pktdate",
"$statdesc");
1178 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1182 # fetching user data for the first time but the pin doesn't match 1183 # If the insflag is set, insert a user record so the login lockout 1184 # feature can prevent brute force pin-cracking 1185 # Otherwise, just return the 001 message and the login 1186 # program will handle the lockout stuff 1188 # syslog(LOG_ERR,"Got 002 with $Cu $Cn $pwd $insflag"); 1189 if ($insflag == 1) {
1191 $sql =
"insert into cuusers ( 1192 cu, user_name, passwd, pktstamp, pktdate, 1193 forcechange, forceremain, failedremain, pwchange, userflags) 1195 '$Cu', '$Cn', 'NULL PASSWORD',1, '" . date(
"D M j Y H:i:s T") .
"', 1196 'Y',$grace, $retry, now(), {$MEM_LOGIN_FAILED_PWD})";
1197 $sth = db_query($sql, $dbh);
1199 $pg_error = pg_errormessage();
1200 #syslog(LOG_INFO,"$pg_error : $sql"); 1203 #syslog(LOG_INFO,"Bad 1st Password but User inserted: $sql"); 1208 $statdesc =
'INVALID ACCOUNT NUMBER';
1211 return array(
"$statcode", 1,
"$statdesc");
1216 function fetch_XA() {
1217 # this function not currently in use 9/22/11 MH 1219 # set environment for programs. 1225 $FETCHER =
"$fetcher";
1228 $dbh = db_pconnect();
1230 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
1231 $rqx =
"{$FETCHER}{$delim}member=$Cn&type=X";
1232 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1234 if (trim(
"$packet") ==
"") {
1235 if ($open_fail == 1) {
1236 trigger_error(
"$Cu:$Cn XA open failed", E_USER_ERROR);
1238 trigger_error(
"$Cu:$Cn XA empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
1240 return array(999, 1,
"Unable to retrieve data");
1243 if (preg_match(
"/<crossaccount>/si",$packet) &&
1244 !preg_match(
"/<\/crossaccount>/si",$packet)) {
1245 trigger_error(
"$Cu:$Cn CrossAccount short packet response(curl_err $curl_err)", E_USER_ERROR);
1246 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
1247 @fwrite($fp,
"$Cu:$Cn CrossAccount short packet\n${rqx}\n");
1248 @fwrite($fp,
"$packet\n");
1250 return array(999, 1,
"Unable to retrieve data");
1254 $pktpieces = array();
1256 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
1257 list($mem, $statcode, $statdesc) = explode(
"\t",$status);
1258 if (trim($mem) != $Cn) {
1259 return array(999, 1,
"Unable to retrieve data");
1262 # check the return status to decide what to do here 1264 # 101 New Data -- process packet, update pktstamp 1265 # 200 System Unavailable, No New Data -- return immediately 1266 # 001 Invalid Account Number -- return immediately 1267 # 003 Invalid Account Number -- return immediately 1268 # 999 Calling error or Invalid Parms -- return immediately 1272 switch ($statcode) {
1274 # Need to refresh the db data. Start parsing that packet... 1276 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si",$packet,$pktpieces);
1277 $txaccount = explode (
"\n",$pktpieces[1]);
1278 array_pop($txaccount);
1280 # stuff each piece in the db 1283 $sql =
"delete from ${Cu}txaccount 1284 where accountnumber='$Cn'";
1285 $sth = db_query($sql,$dbh);
1287 if (
sizeof($txaccount)) {
1289 $sth = db_query(
"copy ${Cu}txaccount from stdin with null as ''",$dbh);
1291 while (list ($key, $line) = each ($txaccount)) {
1292 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
1293 $line = preg_replace(
"/ $/",
"",$line);
1294 $line = preg_replace(
"/\\0/",
" ",$line);
1295 @pg_put_line($dbh,
"$line\n");
1297 @pg_put_line($dbh,
"\\.\n");
1298 if (!@pg_end_copy($dbh)) {
1300 # define_syslog_variables(); 1301 # syslog(LOG_ERR,"FAILED copying txaccounts for $Cu:$Cn Statcode $statcode Error " . pg_last_error($dbh) . "\n"); 1305 if($errstat == 0 ) {
1306 return array(
"$statcode",
"$u",
"$statdesc");
1308 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1313 $statdesc =
'INVALID ACCOUNT NUMBER';
1317 return array(
"$statcode", 1,
"$statdesc");
1323 function fetch_XS($switchfrom, $Cu, $Cn, $fetcher) {
1325 # set environment for programs. 1328 $FETCHER =
"$fetcher";
1331 $R3=(trim($Ml) ==
"" || $Ml==
"no\@email.com" ?
"NULL" : urlencode(trim($Ml)));
1333 #define_syslog_variables(); 1334 #syslog(LOG_ERR,"fetch_XS($switchfrom) for $Cu:$Cn"); 1336 $dbh = db_pconnect();
1338 $delim = (strpos($FETCHER,
'?')===
false ?
'?' :
'&');
1339 $rqx =
"{$FETCHER}{$delim}member=$Cn&type=X&ref3=$R3&f=xxxxxxxxxxxxxxxxxxxxxxxxxxx";
1341 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1343 if (trim(
"$packet") ==
"") {
1344 if ($open_fail == 1) {
1345 trigger_error(
"$Cu:$Cn XA open failed", E_USER_ERROR);
1347 trigger_error(
"$Cu:$Cn XA empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
1349 return array(999, 1,
"Unable to retrieve data");
1352 if (preg_match(
"/<crossaccount>/si",$packet) &&
1353 !preg_match(
"/<\/crossaccount>/si",$packet)) {
1354 trigger_error(
"$Cu:$Cn CrossAccount short packet response(curl_err $curl_err)", E_USER_ERROR);
1355 $fp=@fopen(
"/tmp/packetnew.txt",
"a");
1356 @fwrite($fp,
"$Cu:$Cn CrossAccount short packet\n${rqx}\n");
1357 @fwrite($fp,
"$packet\n");
1359 return array(999, 1,
"Unable to retrieve data");
1363 $pktpieces = array();
1365 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si",$packet,$pktpieces) ? $pktpieces[1] :
"");
1366 list($mem, $statcode, $statdesc) = explode(
"\t",$status);
1367 if (trim($mem) != $Cn) {
1368 return array(999, 1,
"Unable to retrieve data");
1371 # check the return status to decide what to do here 1373 # 101 New Data -- process packet, update pktstamp 1374 # 200 System Unavailable, No New Data -- return immediately 1375 # 001 Invalid Account Number -- return immediately 1376 # 003 Closed Account -- change to 001 and return immediately 1377 # 999 Calling error or Invalid Parms -- return immediately 1381 switch ($statcode) {
1383 # Need to refresh the db data. Start parsing that packet... 1385 # find out what we have in the database... 1387 $sql =
"select trim(accountnumber), trim(tomember), 1388 trim(accounttype), deposittype, description, misc1, id 1389 from culivetx where cu = '$Cu' and accountnumber = '$Cn'";
1390 if ($switchfrom ==
'A') {
1391 $sql .=
" and deposittype not in ('W','w')";
1394 $sth = db_query($sql,$dbh);
1396 for ($row=0; $rec = db_fetch_row($sth, $row); $row++) {
1397 $db_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]\t$rec[6]";
1400 # make an array from the stuff in the packet 1402 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si",$packet,$pktpieces);
1403 $txaccount = explode (
"\n",$pktpieces[1]);
1404 array_pop($txaccount);
1408 while (list ($key, $line) = each ($txaccount)) {
1409 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
1411 $rec = explode(
"\t",$line);
1412 if (
sizeof($rec) < 5) {
1416 $tx_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]";
1419 $inserts = array_diff(array_keys($tx_keys), array_keys($db_keys));
1420 $deletes = array_diff(array_keys($db_keys), array_keys($tx_keys));
1421 $updates = array_intersect(array_keys($tx_keys), array_keys($db_keys));
1425 while (list ($key, $line) = each ($updates)) {
1426 $rec = explode(
"\t",$db_keys[
"$line"]);
1427 $trec = array_merge(explode(
"\t",$line),explode(
"\t",$tx_keys[
"$line"]));
1428 # don't update descriptions 1429 # If the member changes the description we want it to 'stick'. 1430 # so only update if the misc1 value changed on a cross-account 1431 # nothing to update on switch-accounts, if they ever come from the core 1433 if ($trec[3] !=
'W' && $trec[3] !=
'w' && $rec[1] != $trec[5]) {
1434 $sql .=
"update culivetx set 1435 misc1 = '${trec[5]}' where id = ${rec[2]};\n";
1440 while (list ($key, $line) = each ($inserts)) {
1441 $rec = array_merge(explode(
"\t",$line),explode(
"\t",$tx_keys[
"$line"]));
1443 # switchfrom is A when switchaccts are maintained in admin. Only insert the 1444 # switchacct records coming from the core if that's where we expect to get 'em. 1446 if ($switchfrom !=
'A' || ($rec[3] !=
'W' && $rec[3] !=
'w')) {
1447 $sql .=
"insert into culivetx (cu, accountnumber, tomember, 1448 accounttype, deposittype, description, misc1) values ( 1449 '$Cu','${rec[0]}','${rec[1]}', '${rec[2]}', '${rec[3]}', 1450 '" . prep_save($rec[4]) .
"', '${rec[5]}');\n";
1455 while (list ($key, $line) = each ($deletes)) {
1456 $rec = explode(
"\t",$db_keys[
"$line"]);
1457 $sql .=
"delete from culivetx where id = ${rec[2]};\n";
1461 $sth = db_query($sql,$dbh);
1463 $err = pg_last_error();
1465 # syslog(LOG_ERR,"FAILED $err setting txaccounts for $Cu:$Cn\n$sql"); 1468 db_free_result($sth);
1470 if($errstat == 0 ) {
1471 return array(
"$statcode",
"$u",
"$statdesc");
1473 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1478 $statdesc =
'INVALID ACCOUNT NUMBER';
1482 return array(
"$statcode", 1,
"$statdesc");
1486 function fetch_estatement($HB_ENV, $Command, $eStatementID =
'') {
1488 $FETCHER = $GLOBALS[
'fetcher'];
1492 # throw error 999 missing / invalid parameters if: 1493 # missing $HB_ENV['Cn'] or $HB_ENV['Cu'] 1494 # Command not in (ETOC, ESTM) 1495 # Command == ESTM and empty(eStatementID) 1497 if (empty($HB_ENV[
'Cn']) || empty($HB_ENV[
'Cu']) ||
1498 ($Command ==
'ESTM' && empty($eStatementID))) {
1499 throw new Exception(
'Missing Parameters',
'999');
1502 if ($Command !=
'ESTM' && $Command !=
'ETOC') {
1503 throw new Exception(
'Invalid Command',
'999');
1506 $delim = (strpos($FETCHER,
'?') ===
false ?
'?' :
'&');
1507 $Ml = (trim($HB_ENV[
'Ml']) ==
"" || $HB_ENV[
'Ml'] ==
"no\@email.com" ?
"NULL" : urlencode(trim($HB_ENV[
'Ml'])));
1508 $Cauth = (trim($HB_ENV[
'Cauth']) ==
"" ? $HB_ENV[
'Cn'] : $HB_ENV[
'Cauth']);
1510 # https://208.53.36.134/hculive/hculive2me.mp?member=555&type=ETOC&ref3=nobody@nowhere.com 1511 # https://208.53.36.134/hculive/hculive2me.mp?member=555&type=ESTM&ref1=2015-02&ref3=nobody@nowhere.com 1512 $rqx =
"{$FETCHER}{$delim}member={$HB_ENV['Cn']}&type=$Command&f=xxxx";
1513 if ($Command ==
'ESTM')
1514 $rqx .=
"&ref1={$eStatementID}";
1515 $rqx .=
"&ref3=" . urlencode($HB_ENV[
'Ml']) .
"&tauth=$Cauth";
1517 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1519 if (trim(
"$packet") ==
"") {
1520 if ($open_fail == 1) {
1521 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['Cn']} Estmt open failed", E_USER_ERROR);
1523 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['Cn']} Estmt empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
1525 throw new Exception(
'Unable to retrieve data',
'999');
1535 $pktpieces = array();
1537 # find something besides preg_match -- won't work with large data 1538 # do the preg_match on just the first 2k - <status> and <member> should 1539 # always be in the beginning of the packet 1541 $pktheader = substr($packet,0,2048);
1542 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si", $pktheader, $pktpieces) ? $pktpieces[1] :
"");
1543 $member = (preg_match(
"/<member>\n?(.*)\n?<\/member>/si", $pktheader, $pktpieces) ? $pktpieces[1] :
"");
1544 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1545 if (
"$member" >
"") {
1546 list($mem) = explode(
"\t", $member);
1548 if (trim(
"$mem") != $HB_ENV[
'Cn']) {
1549 trigger_error(
"{$HB_ENV['Cu']} possibly out-of-sync ($mem:{$HB_ENV['Cn']})", E_USER_ERROR);
1550 throw new Exception(
'Unable to retrieve data',
'999');
1553 # check the return status to decide what to do here 1554 # 101 New Data -- process packet 1555 # 201 System Unavailable, New Data -- can't use stale for EStatement 1556 # -- change to 200 and return 1557 # 100 No New Data -- return immediately 1558 # 200 System Unavailable, No New Data -- return immediately 1559 # 202 System Unavailable, No Data -- return immediately 1560 # 001 Invalid Account Number -- return immediately 1561 # 002 Invalid Password -- change to 001 Invalid Account and return 1562 # 003 Closed Account -- change to 001 Invalid Account and return 1563 # 010 Member not enrolled for E-statements 1564 # 012 Statement not found 1565 # 999 Calling error or Invalid Parms -- return immediately 1568 switch (sprintf(
'%03d',$statcode)) {
1570 # New data. Start parsing that packet... 1571 if ($Command ==
'ETOC') {
1572 $stPtrn =
'<EStatementTOC>';
1573 $ePtrn =
'</EStatementTOC>';
1574 } elseif ($Command ==
'ESTM') {
1575 $stPtrn =
'<EStatement>';
1576 $ePtrn =
'</EStatement>';
1578 # probably redundant since we checked $Command above.... 1579 throw new Exception(
'Invalid Command',
'999');
1582 if (stripos($packet, $stPtrn) ===
false ||
1583 stripos($packet, $ePtrn, stripos($packet, $stPtrn)) ===
false) {
1584 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['$Cn']} EStatement short packet response(pipe_err $pipe_err)", E_USER_ERROR);
1585 throw new Exception(
"$Command Unable to retrieve data",
'999');
1593 $estmt[status][status] =
"000";
1594 $estmt[status][asofdate] = date(
"D M j Y H:i:s T");
1595 $estmt[status][reason] = $statdesc;
1597 if ($Command ==
'ETOC') {
1598 $tblist = array(
"TOC");
1599 foreach ($tblist as $tbl) {
1600 # find a different way to do this, as large data will foul it up 1601 preg_match(
"/<$tbl>\n?(.*)<\/$tbl>/si", $packet, $pktpieces);
1602 $$tbl = explode(
"\n", $pktpieces[1]);
1605 if (
sizeof($$tbl)) {
1607 # format and return array ala new cu_data functions 1608 while (list ($key, $line) = each($$tbl)) {
1609 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
1610 $line = preg_replace(
"/ $/",
"", $line);
1611 $line = preg_replace(
"/\\0/",
" ", $line);
1612 list($Member, $ID, $sType, $PeriodEnd, $Description, $Format) = explode(
"\t", $line);
1614 $estmt[$tbl][$tblidx][
'Member'] = $Member;
1615 $estmt[$tbl][$tblidx][
'ID'] = $ID;
1616 $estmt[$tbl][$tblidx][
'Type'] = $sType;
1617 $estmt[$tbl][$tblidx][
'PeriodEnd'] = $PeriodEnd;
1618 $estmt[$tbl][$tblidx][
'Description'] = $Description;
1619 $estmt[$tbl][$tblidx][
'Format'] = $Format;
1625 # presumably ESTM - parse <member> into TOC and pop off <data>...</data> 1626 $start = stripos($packet,
"<MEMBER>");
1627 $end = stripos($packet,
"</MEMBER>");
1628 if($start ===
false || $end ===
false) {
1629 $estmt[
'TOC']=array();
1631 $start += 8; # move past the <MEMBER> tag
1632 $line = substr($packet,$start,$end-$start);
1633 $line = trim($line);
1634 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
1635 $line = preg_replace(
"/ $/",
"", $line);
1636 $line = preg_replace(
"/\\0/",
" ", $line);
1637 list($Member, $ID, $sType, $PeriodEnd, $Description, $Format) = explode(
"\t", $line);
1639 $estmt[TOC][0][
'Member'] = $Member;
1640 $estmt[TOC][0][
'ID'] = $ID;
1641 $estmt[TOC][0][
'Type'] = $sType;
1642 $estmt[TOC][0][
'PeriodEnd'] = $PeriodEnd;
1643 $estmt[TOC][0][
'Description'] = $Description;
1644 $estmt[TOC][0][
'Format'] = $Format;
1647 $start = stripos($packet,
"<DATA>");
1648 $end = strripos($packet,
"</DATA>");
1649 if($start ===
false || $end ===
false) {
1652 $start += 6; # move past the <DATA> tag
1653 $estmt[
'data'] = substr($packet,$start,$end-$start);
1658 # 001 Invalid Account Number 1659 # 002 Invalid Password -- change to 001 Invalid Account 1660 # 003 Closed Account -- change to 001 Invalid Account 1664 throw new Exception(
'INVALID ACCOUNT NUMBER',
'001');
1668 # 201 System Unavailable, New Data -- can't use stale for EStatement 1669 throw new Exception(
'Unusable Stale Data', $statcode);
1673 # 200 System Unavailable, No New Data 1674 # 202 System Unavailable, No Data 1675 # 010 Member not enrolled for E-statements 1676 # 012 Statement not found 1677 # 999 Calling error or Invalid Parms 1685 throw new Exception($statdesc, $statcode);
1688 }
catch (Exception $e) {
1689 $code = $e->getCode();
1690 $reason = $e->getMessage();
1692 $estmt[status][status] = sprintf(
'%03d',$code);
1693 $estmt[status][asofdate] = date(
"D M j Y H:i:s T");
1694 $estmt[status][reason] = $reason;
1713 function GetPktSegment($pSegment, $pContent) {
1714 $startTag =
"<{$pSegment}>";
1715 $endTag =
"</{$pSegment}>";
1717 $startTagPos = stripos($pContent, $startTag);
1718 $endTagPos = stripos($pContent, $endTag);
1720 if ($startTagPos !== FALSE && $endTagPos !== FALSE) {
1721 $startTagPos += strlen($startTag);
1723 $retData = substr($pContent, $startTagPos, ($endTagPos - $startTagPos));
1726 $retData = ltrim($retData,
"\n\r");
1734 include_once(
'cu_pass.i');