2 header(
"Expires: Sat 20 May 1995 03:32:38 GMT");
3 header(
"Pragma: no-cache");
4 header(
"Cache-Control: no-cache, must-revalidate");
6 $monLibrary= dirname(__FILE__) .
"/../library";
7 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
8 require_once(
"$monLibrary/cu_top.i");
9 require_once(
"$monLibrary/ck_hticket.i");
10 require_once(
"$sharedLibrary/xml_processing.i");
12 $dms_ok = array(
'Hu' =>
'string',
'Cn' =>
'string',
'Pass' =>
'string',
13 'Showtab' =>
'string',
'Clw' =>
'string',
14 'pktstamp' =>
'string',
'cutoff' =>
'string',
'dowhat' =>
'string',
15 'holds2' =>
'string',
'fileit' =>
'string',
'truncit' =>
'string',
16 'showsplit' =>
'string',
'action' =>
'string',
'R1' =>
'string',
17 'R2' =>
'string',
'R3' =>
'string',
'R4' =>
'string',
18 'R5' =>
'string',
'Amt' =>
'string',
'Fs' =>
'string',
23 if (!CheckPerm($dbh, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
26 header(
"Location: /hcuadm/hcu_noperm.prg");
30 #error_reporting (E_ALL); 31 error_reporting(E_ERROR | E_WARNING | E_PARSE);
32 echo
"<html><LINK REL=stylesheet HREF='/monitor/css/dms.css' TYPE='text/css'>";
33 $action = (empty($action) ?
"Show" : $action);
34 $thirty = mktime() - (30 * 86400);
35 $thirty = date(
"Ymd", $thirty);
36 #syslog(LOG_ERR,"Packetdump action is $action"); 37 $host = substr($_SERVER[
'SERVER_NAME'], 0, strpos($_SERVER[
'SERVER_NAME'],
"."));
38 $Fs = isset($Fs) ? $Fs :
'';
42 # show forms for fetch/post 43 $sql =
"select cu, liveserver, histdays, flagset2 46 and liveserver not ilike '%pgload%' 49 $sth = db_query($sql, $dbh);
50 $options =
"<select name=Fs>\n";
51 for ($row = 0; list($cu, $fetcher, $histdays, $fset2) = db_fetch_array($sth, $row); $row++) {
53 $seltext = ($cu == $Fs ?
' selected' :
'');
54 $options .=
"<OPTION VALUE='$cu|$fetcher|$histdays|$fset2' $seltext>$cu</OPTION>\n";
56 $options .=
"</select>\n";
60 <head><title>Packet Dump</title></head>
61 <body bgcolor=#FFFFFF onLoad=
"self.focus()">
62 <div align=
'center' class=
'usu'>$host Live Packet Tester</div>
63 <div align=
'right' class=
'dtl'><a href=
"javascript:window.close()">Close Window</a></div>
64 <table width=98% cellpadding=2><tr>
65 <td valign=top align=center width=20%>
66 <form action=
"{$_SERVER['PHP_SELF']}?action='fetch'">
68 <tr><td
class=
'bar' colspan=2 align=center>Fetch a Packet</td></tr>
69 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
70 <td>$options</td></tr>
71 <tr><td
class=
'dtl' align=
"right">Member: </td>
72 <td><input type=text name=
"Cn" size=10></td></tr>
73 <tr><td
class=
'dtl' align=
"right">Password: </td>
74 <td><input type=password name=
"Pass" size=10 MAXLENGTH=
"20"></td></tr>
75 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
76 <td><input type=text name=
"Showtab" size=10></td></tr>
77 <tr><td
class=
'dtl' align=
"right">Query Delay: </td>
78 <td><input type=text name=
"Clw" size=10 value=1></td></tr>
79 <tr><td
class=
'dtl' align=
"right">Last Packet Stamp: </td>
80 <td><input type=text name=
"pktstamp" size=10 value=1></td>
82 <tr><td
class=
'dtl' align=
"right">Earliest Date: </td>
83 <td><input type=text name=
"cutoff" size=10 value=
'$thirty'></td>
85 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
86 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
87 <input type=radio name=
"dowhat" value=
"D"> <nobr>Load Database<br>
88 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
90 <tr><td
class=
'dtl' align=
"right">Include Holds </td>
91 <td><input type=checkbox name=
"holds2" value=
"512"></td>
93 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw packet to file: </td>
94 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
96 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
97 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
99 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
100 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
102 <tr><td colspan=2 align=
"center">
103 <input type=submit name=
"action" value=
"Fetch" class=
'bar'>
107 </td><td valign=top align=center width=20%>
108 <form action=
"{$_SERVER['PHP_SELF']}?action='retrieve'">
109 <table cellpadding=2>
110 <tr><td
class=
'bar' colspan=2 align=center>Cross-Accounts</td></tr>
111 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
112 <td>$options</td></tr>
113 <tr><td
class=
'dtl' align=
"right">Member: </td>
114 <td><input type=text name=
"Cn" size=10></td></tr>
115 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
116 <td><input type=text name=
"Showtab" size=10></td></tr>
117 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
118 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
119 <input type=radio name=
"dowhat" value=
"D"> <nobr>Load Database<br>
120 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
122 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw<br>packet to file: </td>
123 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
125 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
126 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
128 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
129 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
131 <tr><td colspan=2 align=
"center">
132 <input type=submit name=
"action" value=
"Retrieve" class=
'bar'></td></tr>
135 </td><td valign=top align=center width=20%>
136 <form action=
"{$_SERVER['PHP_SELF']}?action='mir'">
137 <table cellpadding=2>
138 <tr><td
class=
'bar' colspan=2 align=center>Member Info</td></tr>
139 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
140 <td>$options</td></tr>
141 <tr><td
class=
'dtl' align=
"right">Member: </td>
142 <td><input type=text name=
"Cn" size=10></td></tr>
143 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
144 <td><input type=text name=
"Showtab" size=10></td></tr>
145 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
146 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
147 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
149 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw<br>packet to file: </td>
150 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
152 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
153 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
155 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
156 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
158 <tr><td colspan=2 align=
"center">
159 <input type=submit name=
"action" value=
"Mir" class=
'bar'></td></tr>
162 </td><td valign=top align=center width=20%>
163 <form action=
"{$_SERVER['PHP_SELF']}?action='estm'">
164 <table cellpadding=2>
165 <tr><td
class=
'bar' colspan=2 align=center>Core Estatements</td></tr>
166 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
167 <td>$options</td></tr>
168 <tr><td
class=
'dtl' align=
"right">Member: </td>
169 <td><input type=text name=
"Cn" size=10></td></tr>
170 <tr><td
class=
'dtl' align=
"right">Statement ID: </td>
171 <td><input type=text name=
"stId" size=10></td></tr>
172 <tr><td colspan=2 align=
"center">
173 <input type=submit name=
"action" value=
"Estm" class=
'bar'></td></tr>
176 </td><td valign=top align=center width=*>
177 <form action=
"{$_SERVER['PHP_SELF']}?action='post'">
178 <table cellpadding=2>
179 <tr><td
class=
'bar' colspan=2 align=center>Post a Packet</td></tr>
180 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
181 <td>$options</td></tr>
182 <tr><td
class=
'dtl' align=
"right">Member: </td>
183 <td><input type=text name=
"Cn" size=10></td></tr>
184 <tr><td
class=
'dtl' align=
"right">Transaction Code: </td>
185 <td><select name=
"Tc">
197 <tr><td
class=
'dtl' align=
"right">Ref 1 (From Sfx): </td>
198 <td><input type=text name=
"R1" size=10 value=1></td></tr>
199 <tr><td
class=
'dtl' align=
"right">Ref 2 (To Sfx): </td>
200 <td><input type=text name=
"R2" size=10 value=1></td></tr>
201 <tr><td class=
'dtl' align=
"right">Ref 3 (email): </td>
202 <td><input type=text name=
"R3" size=10 value=1></td></tr>
203 <tr><td class=
'dtl' align=
"right">Ref 4 (To misc): </td>
204 <td><input type=text name=
"R4" size=10 value=1></td></tr>
205 <tr><td class=
'dtl' align=
"right">Ref 5 (To Mem): </td>
206 <td><input type=text name=
"R5" size=10 value=1></td></tr>
207 <tr><td class=
'dtl' align=
"right">Amount: </td>
208 <td><input type=text name=
"Amt" size=10></td></tr>
209 <tr><td colspan=2 align=
"center">
210 <input type=submit name=
"action" value=
"Post" class=
'bar'></td></tr>
214 </tr></table></body></html>
218 $dms_ok = array(
'Fs' =>
'string',
'cutoff' =>
'string',
'Cn' =>
'digits',
219 'Pass' =>
'string',
'ShowHolds' =>
'string',
'Showtab' =>
'string',
220 'URL' =>
'string',
'holds2' =>
'string',
'Clw' =>
'digits',
'pktstamp' =>
'string',
221 'cutoff' =>
'string',
'dowhat' =>
'string',
'fileit' =>
'string',
222 'truncit' =>
'string',
'showsplit' =>
'string');
227 list($Cu, $Fs, $histdays, $fset2) = explode(
"|",
"$Fs", 4);
228 if (empty($cutoff)) {
231 if (empty($histdays)) {
238 $ShowHolds = ($fset2 & $CU2_SHOWHOLD);
240 $ShowHolds = $CU2_SHOWHOLD;
242 print
"<html><head><title>Packet Fetch</title></head><body bgcolor=#FFFFFF> 243 Fetching packet using parameters<ul> 244 <li>Credit Union: $Cu</li> 246 <li>Password: $Pass</li> 247 <li>Show Holds: $ShowHolds</li> 248 <li>Show Tabs: $Showtab</li> 249 <li>Fetched from: $Fs</li> 251 <li>Wait between calls: $Clw</li> 252 <li>Last Packet Stamp: $pktstamp</li> 253 <li>Requested Cutoff: $cutoff</li> 255 if ($dowhat ==
"D") {
256 stuff_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2);
257 } elseif ($dowhat ==
"C") {
258 valid_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2);
260 fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $showsplit, $holds2);
267 $dms_ok = array(
'Fs' =>
'string',
'Cn' =>
'digits',
'Showtab' =>
'string',
268 'dowhat' =>
'string',
'fileit' =>
'string',
'truncit' =>
'string',
269 'showsplit' =>
'string');
272 list($Cu, $Fs, $histdays) = explode(
"|",
"$Fs", 3);
273 print
"<html><head><title>Cross-Account Retrieve</title></head><body bgcolor=#FFFFFF> 274 Retrieving Cross-Account Authorizations using parameters<ul> 275 <li>Credit Union: $Cu</li> 277 <li>Show Tabs: $Showtab</li> 278 <li>Fetched from: $Fs</li> 280 if ($dowhat ==
"D") {
281 stuff_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
282 } elseif ($dowhat ==
"C") {
283 valid_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
285 fetch_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit);
292 $dms_ok = array(
'Fs' =>
'string',
'Cn' =>
'digits',
'Showtab' =>
'string',
293 'dowhat' =>
'string',
'fileit' =>
'string',
'truncit' =>
'string',
294 'showsplit' =>
'string');
297 list($Cu, $Fs, $histdays) = explode(
"|",
"$Fs", 3);
298 print
"<html><head><title>Member Info Retrieve</title></head><body bgcolor=#FFFFFF> 299 Retrieving Member Info using parameters<ul> 300 <li>Credit Union: $Cu</li> 302 <li>Show Tabs: $Showtab</li> 303 <li>Fetched from: $Fs</li> 305 if ($dowhat ==
"C") {
306 valid_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
308 fetch_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit);
315 $dms_ok = array(
'Fs' =>
'string',
'Cn' =>
'digits',
'stId' =>
'string');
318 list($Cu, $Fs, $histdays) = explode(
"|",
"$Fs", 3);
324 print
"<html><head><title>Core Estatement Retrieve</title></head><body bgcolor=#FFFFFF> 325 Retrieving Estatement using parameters<ul> 326 <li>Credit Union: $Cu</li> 328 <li>Statement ID: $stId</li> 329 <li>Cmd: $Command</li> 330 <li>Fetched from: $Fs</li> 332 $result = fetch_estatement(array(
'Cu'=>$Cu,
'Cn'=>$Cn),$Command,$stId);
333 $showit = print_r($result,
true);
334 print
"<h4>Response(s):</h4>";
335 print
"<pre>$showit</pre>";
342 $dms_ok = array(
'Fs' =>
'string',
'Cn' =>
'digits',
'Showtab' =>
'string',
343 'TC' =>
'string',
'Amt' =>
'string',
'R2' =>
'string',
'R3' =>
'string',
344 'R4' =>
'string',
'R5' =>
'string');
347 list($Cu, $Fs, $histdays) = explode(
"|",
"$Fs", 3);
348 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
349 $R3 = (trim($R3) ==
"" ?
"NULL" : $R3);
350 $R4 = (trim($R4) ==
"" ?
"NULL" : $R4);
351 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
352 print
"<html><head><title>Packet Post</title></head><body bgcolor=#FFFFFF> 353 Posting packet using parameters<ul> 354 <li>Credit Union: $Cu</li> 356 <li>Posted to: $Fs</li> 357 <li>Txn Code: $Tc</li> 363 <li>Amount: $Amt</li> 364 <li>URL: $Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt</li> 366 post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt);
375 function checkForXmlParseErrors($xmlstr) {
377 libxml_use_internal_errors(
true);
378 $xmlLoaded = simplexml_load_string($xmlstr);
380 if ($xmlLoaded ===
false) {
381 $errors = libxml_get_errors();
382 list($errors, $isError) = modifyXmlErrorsForLogging($errors, $xmlstr);
385 print
"<h4>XML parsing: encountered '" . count($errors) .
"' error(s)</h4>";
386 print
"<textarea rows='20' cols='120' readonly>";
388 foreach($errors as $error) {
389 print
"\n" . ++$count .
". [" . $error[
"level"] .
"] ";
390 print $error[
"message"] .
" (code: " . $error[
"code"] .
")\n\n";
391 print
"Context (line " . $error[
"line"] .
", column " . $error[
"column"] .
"):\n";
392 print
"---> '" . $error[
"context"] .
"'\n\n";
399 function fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $showsplit, $holds2) {
401 if ($Pass ===
'0') {$Pass =
'00';}
402 if (
"$pktstamp" ==
"") {
403 # read last pktstamp from database. Calculate new threshold as 404 # now - pktinterval; if pktstamp > threshold, return (use existing) 408 $sql =
"select pktstamp, pktdate, livewait 409 from cuusers u, cuadmin a 411 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
412 $sth = db_query($sql, $dbh);
413 list($pktstamp, $pktdate, $Clw) = db_fetch_array($sth, 0);
414 db_free_result($sth);
417 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
418 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
419 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
421 $threshold = mktime() - $Clw;
422 $fs = date(
"D M j Y H:i:s T", $pktstamp);
423 $ft = date(
"D M j Y H:i:s T", $threshold);
424 if ($pktstamp > $threshold) {
425 print
"Too soon to ask again<br> 427 Threshold: $ft<br></body></html>";
430 # if the last packet was fairly recent only fetch 7 days 431 # "recent" defined as 3 times the packet timeout setting 432 $threshold = mktime() - (3 * $Clw);
433 if (empty($cutoff)) {
436 if (empty($histdays)) {
439 # 1072940400 is the timestamp for 20040101 440 if ($pktstamp > 1072940400 && $histdays > 0 && $cutoff == $thirty) {
441 # calculate cutoff as pktstamp - interval($histdays days) 442 if ($pktstamp > $threshold) {
443 # last packet age is less than 3 times the packet timeout setting 444 # set cutoff for 7 days 445 $cutoff = date(
"Ymd", mktime() - 604800);
447 $cutoff = date(
"Ymd", $pktstamp - (86400 * $histdays));
450 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
451 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
453 $URL.=
"&pass=" . urlencode($Pass);
455 $rqx =
"$Fs{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
457 $rqx .=
"&pass=" . urlencode($Pass);
459 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
461 checkForXmlParseErrors($packet);
463 #if ($packet = file_get_contents("/home/ubuntu/packetdump.txt")){ 464 # $fd = @fopen ("$Fs$URL", "r"); 467 # stream_set_timeout($fd,100); 468 # while ($buff = fread ($fd, 1500)) { 472 # add feature here to log (and optionally truncate first) packet to a temp file 474 if ($fileit ==
"OK") {
475 if ($truncit ==
"OK") {
476 $fp = fopen(
"/tmp/packetdump.txt",
"w");
478 $fp = fopen(
"/tmp/packetdump.txt",
"a");
480 fwrite($fp, $packet);
482 if ($showsplit ==
'OK') {
483 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
484 $pktpattern =
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
486 $inqpattern =
'/<\/*Inquiry>/i';
487 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 488 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktshow);
490 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
491 array_walk($pktshow,
'showquoted');
493 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
495 # $packet = preg_replace("/ ?\t ?/","\t",$packet); 496 if (
"$Showtab" !=
"") {
497 $packet = preg_replace(
"/\t/",
"$Showtab", $packet);
499 $packet = HTMLSpecialChars($packet);
500 print
"<h4>Response(s):</h4>";
501 print
"URL: $URL<br><pre>$packet</pre></body></html>";
503 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
508 function stuff_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2) {
511 if (
"$pktstamp" ==
"") {
512 # read last pktstamp from database. Calculate new threshold as 513 # now - pktinterval; if pktstamp > threshold, return (use existing) 515 $sql =
"select pktstamp, pktdate, livewait 516 from cuusers u, cuadmin a 518 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
519 $sth = db_query($sql, $dbh);
520 list($pktstamp, $pktdate, $Clw) = db_fetch_array($sth, 0);
521 db_free_result($sth);
524 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
525 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
526 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
528 $threshold = mktime() - $Clw;
530 $fs = date(
"D M j Y H:i:s T", $pktstamp);
531 $ft = date(
"D M j Y H:i:s T", $threshold);
532 if ($pktstamp > $threshold) {
533 print
"Too soon to ask again<br> 535 Threshold: $ft<br></body></html>";
537 # if the last packet was fairly recent only fetch 7 days 538 # "recent" defined as 3 times the packet timeout setting 539 $threshold = mktime() - (3 * $Clw);
540 if (empty($cutoff)) {
543 if (empty($histdays)) {
546 # 1072940400 is the timestamp for 20040101 547 if ($pktstamp > 1072940400 && $histdays > 0 && $cutoff == $thirty) {
548 # calculate cutoff as pktstamp - interval($histdays days) 549 if ($pktstamp > $threshold) {
550 # last packet age is less than 3 times the packet timeout setting 551 # set cutoff for 7 days 552 $cutoff = date(
"Ymd", mktime() - 604800);
554 $cutoff = date(
"Ymd", $pktstamp - (86400 * $histdays));
557 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
558 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
560 $URL.=
"&pass=" . urlencode($Pass);
563 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
572 if ($fileit ==
"OK") {
573 if ($truncit ==
"OK") {
574 $fp = fopen(
"/tmp/packetdump.txt",
"w");
576 $fp = fopen(
"/tmp/packetdump.txt",
"a");
578 fwrite($fp, $packet);
581 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/';
582 $pktpieces = array();
583 $pktpattern =
'/<([^<>\/]*)>(.*)<\/\\1>/Us';
584 $inqpattern =
'/<\/*Inquiry>/i';
585 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 586 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktpieces);
588 if ($showsplit ==
'OK') {
590 # use a different array so we don't change the actual data 592 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
593 $pktpattern =
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
595 $inqpattern =
'/<\/*Inquiry>/i';
596 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 597 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktshow);
599 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
600 array_walk($pktshow,
'showquoted');
602 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
604 array_shift($pktpieces);
605 foreach ($pktpieces[0] as $pos => $tag) {
606 $tags[(strtolower($tag))] = $pos;
608 array_shift($pktpieces);
609 list($mem, $pcutoff) = explode(
"\t", $pktpieces[0][($tags[
'parameters'])]);
610 # if the packet presents a cutoff date, let it override our request 611 $cutoff = (
"$pcutoff" ==
"" ? $cutoff : $pcutoff);
612 list($mem, $statcode, $statdesc) = explode(
"\t", $pktpieces[0][($tags[
'status'])]);
613 list($pktstamp, $pktdate) = explode(
"\t", $pktpieces[0][($tags[
'time'])]);
614 print
"<br>URL: $URL<br>";
617 Description: $statdesc<br> 618 Cutoff: (requested) $cutoff (returned) $pcutoff<br>";
619 if (trim($mem) != $Cn) {
621 $statdesc =
"Returned packet doesn't match request!";
624 # check the return status to decide what to do here 625 # 101 New Data -- process packet, update pktstamp 626 # 201 System Unavailable, New Data -- process packet, update pktstamp 627 # 100 No New Data -- update pktstamp 628 # 200 System Unavailable, No New Data -- return immediately 629 # 202 System Unavailable, No Data -- return immediately 630 # 999 Calling error or Invalid Parms -- return immediately 637 # Need to refresh the db data. Start parsing that packet... 638 foreach ($tags as $tag => $pos) {
641 case "accountbalance":
643 case "accounthistory":
647 $$tag = explode(
"\n", $pktpieces[0][$pos]);
649 # newlines around data on multiline components 650 # causes empty items in array. 651 # Pop the empty off the end 652 # new regex leaves newline at top as well, 653 # so shift it off also 661 # stuff each piece in the db 662 # set pktstamp to 1 so if we die in the middle next query will force reload 664 $sql =
"update cuusers set pktstamp = 1, 665 pktdate = '" . date(
"D M j Y H:i:s T") .
"' 666 where cu = '" . $Cu .
"' 667 and user_name = '" . $Cn .
"'";
668 $sth = db_query($sql, $dbh);
670 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
671 if ($holds2 || ($fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) {
674 foreach ($tblist as $tbl) {
677 case "accountbalance":
680 $sql =
"delete from ${Cu}${tbl} 681 where accountnumber='" . $Cn .
"'";
682 $sth = db_query($sql, $dbh);
684 case "accounthistory":
686 $sql =
"delete from ${Cu}${tbl} 687 where accountnumber='" . $Cn .
"' 688 and date >= '" . $cutoff .
"'";
689 $sth = db_query($sql, $dbh);
693 print
"<font color='blue'>Loading " .
sizeof($$tbl) .
" records for $tbl...</font><br>\n";
697 foreach ($$tbl as $line) {
699 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
700 $line = preg_replace(
"/ $/",
"", $line);
701 $line = preg_replace(
"/\\0/",
"", $line);
702 $sth = db_query(
"copy ${Cu}${tbl} from stdin with null as ''", $dbh);
703 pg_put_line($dbh,
"$line\n");
704 pg_put_line($dbh,
"\\.\n");
705 if (!(@pg_end_copy($dbh))) {
706 $copyerr =
"Error writing previous line";
709 if (
"$Showtab" !=
"") {
710 $line = preg_replace(
"/\t/",
"$Showtab", $line);
712 $line = HTMLSpecialChars($line);
715 print
"<font color='red'>$copyerr</font>\n<br>";
724 $sql =
"update cuusers set pktstamp = $pktstamp, 725 pktdate = '" . $pktdate .
"' 726 where cu = '" . $Cu .
"' 727 and user_name = '" . $Cn .
"'";
728 $sth = db_query($sql, $dbh);
730 print
"FAILED setting pktstamp for $Cu:$Cn" . pg_errormessage() .
"\n<br>";
737 print
"Status: $statcode Date: $pktdate Description: $statdesc<br>\n";
739 print
"Status: $statcode Date: 1 Description: $statdesc<br>\n";
743 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
748 function valid_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2) {
751 if (
"$pktstamp" ==
"") {
752 # read last pktstamp from database. Calculate new threshold as 753 # now - pktinterval; if pktstamp > threshold, return (use existing) 755 $sql =
"select pktstamp, pktdate, livewait 756 from cuusers u, cuadmin a 758 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
759 $sth = db_query($sql, $dbh);
760 list($pktstamp, $pktdate, $Clw) = db_fetch_array($sth, 0);
761 db_free_result($sth);
764 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
765 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
766 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
768 $threshold = mktime() - $Clw;
770 $fs = date(
"D M j Y H:i:s T", $pktstamp);
771 $ft = date(
"D M j Y H:i:s T", $threshold);
772 if ($pktstamp > $threshold) {
773 print
"Too soon to ask again<br> 775 Threshold: $ft<br></body></html>";
777 # if the last packet was fairly recent only fetch 7 days 778 # "recent" defined as 3 times the packet timeout setting 779 $threshold = mktime() - (3 * $Clw);
780 if (empty($cutoff)) {
783 if (empty($histdays)) {
786 # 1072940400 is the timestamp for 20040101 787 if ($pktstamp > 1072940400 && $histdays > 0 && $cutoff == $thirty) {
788 # calculate cutoff as pktstamp - interval($histdays days) 789 if ($pktstamp > $threshold) {
790 # last packet age is less than 3 times the packet timeout setting 791 # set cutoff for 7 days 792 $cutoff = date(
"Ymd", mktime() - 604800);
794 $cutoff = date(
"Ymd", $pktstamp - (86400 * $histdays));
797 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
798 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
800 $URL.=
"&pass=" . urlencode($Pass);
803 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
812 if ($fileit ==
"OK") {
813 if ($truncit ==
"OK") {
814 $fp = fopen(
"/tmp/packetdump.txt",
"w");
816 $fp = fopen(
"/tmp/packetdump.txt",
"a");
818 fwrite($fp, $packet);
821 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/';
822 $pktpieces = array();
823 $pktpattern =
'/<([^<>\/]*)>(.*)<\/\\1>/Us';
824 $inqpattern =
'/<\/*Inquiry>/i';
825 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 826 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktpieces);
828 if ($showsplit ==
'OK') {
830 # use a different array so we don't change the actual data 832 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
833 $pktpattern =
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
835 $inqpattern =
'/<\/*Inquiry>/i';
836 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 837 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktshow);
839 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
840 array_walk($pktshow,
'showquoted');
842 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
844 array_shift($pktpieces);
845 foreach ($pktpieces[0] as $pos => $tag) {
846 $tags[(strtolower($tag))] = $pos;
848 array_shift($pktpieces);
849 list($mem, $pcutoff) = explode(
"\t", $pktpieces[0][($tags[
'parameters'])]);
850 # if the packet presents a cutoff date, let it override our request 851 $cutoff = (
"$pcutoff" ==
"" ? $cutoff : $pcutoff);
852 list($mem, $statcode, $statdesc) = explode(
"\t", $pktpieces[0][($tags[
'status'])]);
853 list($pktstamp, $pktdate) = explode(
"\t", $pktpieces[0][($tags[
'time'])]);
854 print
"<br>URL: $URL<br>";
857 Description: $statdesc<br> 858 Cutoff: (requested) $cutoff (returned) $pcutoff<br>";
859 if (trim($mem) != $Cn) {
861 $statdesc =
"Returned packet doesn't match request!";
864 # check the return status to decide what to do here 865 # 101 New Data -- process packet, update pktstamp 866 # 201 System Unavailable, New Data -- process packet, update pktstamp 867 # 100 No New Data -- update pktstamp 868 # 200 System Unavailable, No New Data -- return immediately 869 # 202 System Unavailable, No Data -- return immediately 870 # 999 Calling error or Invalid Parms -- return immediately 876 # Need to refresh the db data. Start parsing that packet... 877 foreach ($tags as $tag => $pos) {
880 case "accountbalance":
882 case "accounthistory":
886 $$tag = explode(
"\n", $pktpieces[0][$pos]);
888 # newlines around data on multiline components 889 # causes empty items in array. 890 # Pop the empty off the end 891 # new regex leaves newline at top as well, 892 # so shift it off also 901 $expected{
'accountbalance'} = 10;
902 $expected{
'accounthistory'} = 10;
903 $expected{
'loanbalance'} = 14;
904 $expected{
'loanhistory'} = 9;
905 $expected{
'messages'} = 4;
906 $expected{
'holds'} = 9;
910 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
911 if ($holds2 || ($fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) {
914 foreach ($tblist as $tbl) {
915 # print "<font color='blue'>Counting " . sizeof($$tbl) . " records for $tbl...</font><br>\n"; 921 foreach ($$tbl as $line) {
922 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
923 $line = preg_replace(
"/ $/",
"", $line);
924 $line = preg_replace(
"/\\0/",
"", $line);
925 $count = (count(explode(
"\t", $line)));
926 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
927 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
928 if (
"$Showtab" !=
"") {
929 $line = preg_replace(
"/\t/",
"$Showtab", $line);
931 $line = HTMLSpecialChars($line);
935 print
"<font color='blue'>Counted " .
sizeof($$tbl) .
" records for $tbl... (Expected: " . $expected{$tbl} .
")</font> Min: $mincnt Max: $maxcnt<br><br>\n";
944 print
"Status: $statcode Date: $pktdate Description: $statdesc<br>\n";
946 print
"Status: $statcode Date: 1 Description: $statdesc<br>\n";
950 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
955 function fetch_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit) {
957 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
958 $URL =
"{$delim}member=$Cn&type=X&f=xxxx";
960 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
962 checkForXmlParseErrors($packet);
971 # add feature here to log (and optionally truncate first) packet to a temp file 973 if ($fileit ==
"OK") {
974 if ($truncit ==
"OK") {
975 $fp = fopen(
"/tmp/packetdump.txt",
"w");
977 $fp = fopen(
"/tmp/packetdump.txt",
"a");
979 fwrite($fp, $packet);
982 if (
"$Showtab" !=
"") {
983 $packet = preg_replace(
"/\t/",
"$Showtab", $packet);
985 $packet = HTMLSpecialChars($packet);
986 print
"<h4>Response(s):</h4>";
987 print
"URL: $URL<br><pre>$packet</pre></body></html>";
989 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
993 function fetch_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit) {
994 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
995 $URL =
"{$delim}member=$Cn&type=MIR&f=xxxx";
997 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
999 checkForXmlParseErrors($packet);
1007 # add feature here to log (and optionally truncate first) packet to a temp file 1009 if ($fileit ==
"OK") {
1010 if ($truncit ==
"OK") {
1011 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1013 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1015 fwrite($fp, $packet);
1018 if (
"$Showtab" !=
"") {
1019 $packet = preg_replace(
"/\t/",
"$Showtab", $packet);
1021 $packet = HTMLSpecialChars($packet);
1022 print
"<h4>Response(s):</h4>";
1023 print
"URL: $URL<br><pre>$packet</pre></body></html>";
1025 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
1029 function stuff_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
1032 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1033 $URL =
"{$delim}member=$Cn&type=X&f=xxxx";
1036 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1037 if ($packet !=
'') {
1040 # $switchfrom should be set 1041 # from ((cuadmin.flagset & $CU_PKT_SWITCH) == $CU_PKT_SWITCH) 1042 # but for now no one gets switch account info in the pkt so I'll skip 1043 # the call to the cuadmin table-- 1051 if ($fileit ==
"OK") {
1052 if ($truncit ==
"OK") {
1053 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1055 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1057 fwrite($fp, $packet);
1060 if (
"$Showtab" !=
"") {
1061 $pkt = preg_replace(
"/\t/",
"$Showtab", $pkt);
1063 $pkt = HTMLSpecialChars($pkt);
1064 print
"<br>URL: $URL<br><pre>$pkt</pre><br>";
1067 $pktpieces = array();
1069 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
1070 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1071 if (trim($mem) != $Cn) {
1072 return array(999, 1,
"Unable to retrieve a packet");
1075 # check the return status to decide what to do here 1076 # 101 New Data -- process packet, update pktstamp 1077 # 200 System Unavailable, No New Data -- return immediately 1078 # 001 Invalid Account Number -- return immediately 1079 # 999 Calling error or Invalid Parms -- return immediately 1083 switch ($statcode) {
1085 # Need to refresh the db data. Start parsing that packet... 1086 # find out what we have in the database... 1088 $sql =
"select trim(accountnumber), trim(tomember), 1089 trim(accounttype), deposittype, description, misc1, id 1090 from culivetx where cu = '$Cu' and accountnumber = '$Cn'";
1091 if ($switchfrom ==
'A') {
1092 $sql .=
" and deposittype not in ('W','w')";
1095 $sth = db_query($sql, $dbh);
1097 for ($row = 0; $rec = db_fetch_row($sth, $row); $row++) {
1098 $db_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]\t$rec[6]";
1101 # make an array from the stuff in the packet 1103 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si", $packet, $pktpieces);
1104 $txaccount = explode(
"\n", $pktpieces[1]);
1105 array_pop($txaccount);
1108 foreach ($txaccount as $line) {
1110 $rec = explode(
"\t", $line);
1111 $tx_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]";
1114 $inserts = array_diff(array_keys($tx_keys), array_keys($db_keys));
1115 $deletes = array_diff(array_keys($db_keys), array_keys($tx_keys));
1116 $updates = array_intersect(array_keys($tx_keys), array_keys($db_keys));
1118 if ($showsplit ==
'OK') {
1120 $pktshow = $txaccount;
1122 print
"Packet Contains:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1123 array_walk($pktshow,
'showquoted');
1125 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1126 $pktshow = $db_keys;
1127 print
"Database Has:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1128 array_walk($pktshow,
'showquoted');
1130 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1131 $pktshow = $inserts;
1132 print
"Insert keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1133 array_walk($pktshow,
'showquoted');
1135 $pktshow = $updates;
1136 print
"Update keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1137 array_walk($pktshow,
'showquoted');
1139 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1140 $pktshow = $deletes;
1141 print
"Delete keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1142 array_walk($pktshow,
'showquoted');
1147 foreach ($updates as $line) {
1148 $rec = explode(
"\t", $db_keys[
"$line"]);
1149 $trec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1150 # don't update descriptions on switchacct records. 1151 # If the member changes the description we want it to 'stick'. 1153 if ($trec[3] !=
'W' && $trec[3] !=
'w' &&
1154 ($rec[0] != $trec[4] || $rec[1] != $trec[5])) {
1155 $sql .=
"update culivetx set description = '" .
1156 prep_save($trec[4]) .
"', 1157 misc1 = '" . prep_save($trec[5]) .
"' where id = ${rec[2]};\n";
1161 foreach ($inserts as $line) {
1162 $rec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1164 # switchfrom is A when switchaccts are maintained in admin. Only insert the 1165 # switchacct records coming from the core if that's where we expect to get 'em. 1167 if ($switchfrom !=
'A' || ($rec[3] !=
'W' && $rec[3] !=
'w')) {
1168 $sql .=
"insert into culivetx (cu, accountnumber, tomember, 1169 accounttype, deposittype, description, misc1) values ( 1170 '$Cu','${rec[0]}','${rec[1]}', '${rec[2]}', '${rec[3]}', 1171 '" . prep_save($rec[4]) .
"', '" . prep_save($rec[5]) .
"');\n";
1175 foreach ($deletes as $line) {
1176 $rec = explode(
"\t", $db_keys[
"$line"]);
1177 $sql .=
"delete from culivetx where id = ${rec[2]};\n";
1179 if ($showsplit ==
'OK') {
1180 print
"SQL: <br>++++++++++++++++++++++++++++++++++++++++<br>";
1183 print
"Will execute SQL <pre>$sql</pre>\n";
1185 print
"No SQL to execute\n";
1189 $sth = db_query($sql, $dbh);
1191 $err = pg_last_error();
1193 syslog(LOG_ERR,
"FAILED $err setting txaccounts for $Cu:$Cn\n$sql");
1196 db_free_result($sth);
1198 if ($errstat == 0) {
1199 return array(
"$statcode",
"$u",
"$statdesc");
1201 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1207 return array(
"$statcode", 1,
"$statdesc");
1210 return array(999, 1, $php_errormsg);
1214 function valid_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
1217 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1218 $URL =
"{$delim}member=$Cn&type=X&f=xxx";
1220 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1221 if ($packet !=
'') {
1230 if ($fileit ==
"OK") {
1231 if ($truncit ==
"OK") {
1232 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1234 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1236 fwrite($fp, $packet);
1240 $pktpieces = array();
1242 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
1243 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1244 if (trim($mem) != $Cn) {
1245 return array(999, 1,
"Unable to retrieve a packet");
1248 # check the return status to decide what to do here 1249 # 101 New Data -- process packet, update pktstamp 1250 # 200 System Unavailable, No New Data -- return immediately 1251 # 001 Invalid Account Number -- return immediately 1252 # 999 Calling error or Invalid Parms -- return immediately 1256 switch ($statcode) {
1258 # Need to refresh the db data. Start parsing that packet... 1259 # find out what we have in the database... 1261 $sql =
"select trim(accountnumber), trim(tomember), 1262 trim(accounttype), deposittype, description, misc1, id 1263 from culivetx where cu = '$Cu' and accountnumber = '$Cn'";
1264 if ($switchfrom ==
'A') {
1265 $sql .=
" and deposittype not in ('W','w')";
1268 $sth = db_query($sql, $dbh);
1270 for ($row = 0; $rec = db_fetch_row($sth, $row); $row++) {
1271 $db_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]\t$rec[6]";
1274 # make an array from the stuff in the packet 1276 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si", $packet, $pktpieces);
1277 $txaccount = explode(
"\n", $pktpieces[1]);
1278 array_pop($txaccount);
1284 foreach ($txaccount as $line) {
1285 $count = (count(explode(
"\t", $line)));
1286 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
1287 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
1289 $rec = explode(
"\t", $line);
1290 $tx_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]";
1291 if (
"$Showtab" !=
"") {
1292 $line = preg_replace(
"/\t/",
"$Showtab", $line);
1294 $line = HTMLSpecialChars($line);
1299 print
"<font color='blue'>Counted " .
sizeof($txaccount) .
" Cross-Account records...(Expected: 6)</font> Min: $mincnt Max: $maxcnt<br><br>\n";
1301 $inserts = array_diff(array_keys($tx_keys), array_keys($db_keys));
1302 $deletes = array_diff(array_keys($db_keys), array_keys($tx_keys));
1303 $updates = array_intersect(array_keys($tx_keys), array_keys($db_keys));
1305 if ($showsplit ==
'OK') {
1307 $pktshow = $txaccount;
1309 print
"Packet Contains:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1310 array_walk($pktshow,
'showquoted');
1312 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1313 $pktshow = $db_keys;
1314 print
"Database Has:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1315 array_walk($pktshow,
'showquoted');
1317 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1318 $pktshow = $inserts;
1319 print
"Insert keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1320 array_walk($pktshow,
'showquoted');
1322 $pktshow = $updates;
1323 print
"Update keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1324 array_walk($pktshow,
'showquoted');
1326 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1327 $pktshow = $deletes;
1328 print
"Delete keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1329 array_walk($pktshow,
'showquoted');
1334 foreach ($updates as $line) {
1335 $rec = explode(
"\t", $db_keys[
"$line"]);
1336 $trec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1337 # don't update descriptions on switchacct records. 1338 # If the member changes the description we want it to 'stick'. 1340 if ($trec[3] !=
'W' && $trec[3] !=
'w' &&
1341 ($rec[0] != $trec[4] || $rec[1] != $trec[5])) {
1342 $sql .=
"update culivetx set description = '" .
1343 prep_save($trec[4]) .
"', 1344 misc1 = '${trec[5]}' where id = ${rec[2]};\n";
1348 foreach ($inserts as $line) {
1349 $rec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1351 # switchfrom is A when switchaccts are maintained in admin. Only insert the 1352 # switchacct records coming from the core if that's where we expect to get 'em. 1354 if ($switchfrom !=
'A' || ($rec[3] !=
'W' && $rec[3] !=
'w')) {
1355 $sql .=
"insert into culivetx (cu, accountnumber, tomember, 1356 accounttype, deposittype, description, misc1) values ( 1357 '$Cu','${rec[0]}','${rec[1]}', '${rec[2]}', '${rec[3]}', 1358 '" . prep_save($rec[4]) .
"', '${rec[5]}');\n";
1362 foreach ($deletes as $line) {
1363 $rec = explode(
"\t", $db_keys[
"$line"]);
1364 $sql .=
"delete from culivetx where id = ${rec[2]};\n";
1366 if ($showsplit ==
'OK') {
1367 print
"SQL: <br>++++++++++++++++++++++++++++++++++++++++<br>";
1375 if ($errstat == 0) {
1376 return array(
"$statcode",
"$u",
"$statdesc");
1378 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1384 return array(
"$statcode", 1,
"$statdesc");
1387 return array(999, 1, $php_errormsg);
1391 function valid_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
1394 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1395 $URL =
"{$delim}member=$Cn&type=MIR&f=xxx";
1397 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1398 if ($packet !=
'') {
1406 if ($fileit ==
"OK") {
1407 if ($truncit ==
"OK") {
1408 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1410 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1412 fwrite($fp, $packet);
1416 $pktpieces = array();
1418 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
1419 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1420 if (trim($mem) != $Cn) {
1421 return array(999, 1,
"Unable to retrieve a packet");
1424 # check the return status to decide what to do here 1425 # 101 New Data -- process packet, update pktstamp 1426 # 200 System Unavailable, No New Data -- return immediately 1427 # 001 Invalid Account Number -- return immediately 1428 # 999 Calling error or Invalid Parms -- return immediately 1432 switch ($statcode) {
1434 # New data. Start parsing that packet... 1435 # make an array from the stuff in the packet 1437 preg_match(
"/<info>\n?(.*)<\/info>/si", $packet, $pktpieces);
1438 $mir = explode(
"\n", $pktpieces[1]);
1444 foreach ($mir as $line) {
1445 $count = (count(explode(
"\t", $line)));
1446 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
1447 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
1448 if (
"$Showtab" !=
"") {
1449 $line = preg_replace(
"/\t/",
"$Showtab", $line);
1451 $line = HTMLSpecialChars($line);
1456 print
"<font color='blue'>Counted " .
sizeof($mir) .
" Member Info records...<br>(Expected 17: AccountNumber, FirstName, MiddleName, LastName, Email, HomePhone, WorkPhone, CellPhone, Fax, SSN, Address1, Address2, City, State, Zip, CC, DOB)</font><br> Min: $mincnt Max: $maxcnt<br><br>\n";
1462 return array(
"$statcode", 1,
"$statdesc");
1465 return array(999, 1, $php_errormsg);
1469 function post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt) {
1472 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1473 $URL =
"{$delim}member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt";
1475 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1476 if ($packet !=
'') {
1485 $packet = HTMLSpecialChars($packet);
1486 print
"<h4>Response(s):</h4>";
1487 print
"<pre>$packet</pre></body></html>";
1489 print
"Couldn't get a packet!<br>$php_errormsg<br>";
1490 print
"URL=$Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt<br>";
1494 function showquoted(&$val) {
1495 if (is_array($val)) {
1496 array_walk($val,
'showquoted');
1499 $val = htmlentities($val);
1501 function get_data($rqx) {
1502 # returns open_fail as 0 no error or 1 fopen/popen failed 1503 # pipe_err as termination code from piped command (always zero if fopen?) 1504 # packet as data returned from core 1514 $pipe=1; # force use of popen but allow
for easy recoding
1518 $fd=popen(
"/usr/bin/curl -k -N --silent -1 '$rqx'",
"r");
1522 while ($buff = fread ($fd, 1500)) {
1525 $pipe_err=pclose($fd);
1532 return array($open_fail,$pipe_err,$packet);
1534 $fd = @fopen(
"$rqx",
"r");
1538 $pkti = stream_get_meta_data($fd);
1539 while ((!feof($fd)) && (!$pkti[
'timed_out'])) {
1540 $packet .= fread($fd, 4096);
1541 $pkti = stream_get_meta_data($fd);
1544 if ($pkti[
'timed_out']) {
1548 return array($open_fail,$pipe_err,$packet);
1552 function fetch_estatement($HB_ENV, $Command, $eStatementID =
'') {
1554 $FETCHER = $GLOBALS[
'Fs'];
1558 # throw error 999 missing / invalid parameters if: 1559 # missing $HB_ENV['Cn'] or $HB_ENV['Cu'] 1560 # Command not in (ETOC, ESTM) 1561 # Command == ESTM and empty(eStatementID) 1563 if (empty($HB_ENV[
'Cn']) || empty($HB_ENV[
'Cu']) ||
1564 ($Command ==
'ESTM' && empty($eStatementID))) {
1565 throw new Exception(
'Missing Parameters',
'999');
1568 if ($Command !=
'ESTM' && $Command !=
'ETOC') {
1569 throw new Exception(
'Invalid Command',
'999');
1572 $delim = (strpos($FETCHER,
'?') ===
false ?
'?' :
'&');
1573 $Ml = (trim($HB_ENV[
'Ml']) ==
"" || $HB_ENV[
'Ml'] ==
"no\@email.com" ?
"NULL" : urlencode(trim($HB_ENV[
'Ml'])));
1575 # https://208.53.36.134/hculive/hculive2me.mp?member=555&type=ETOC&ref3=nobody@nowhere.com 1576 # https://208.53.36.134/hculive/hculive2me.mp?member=555&type=ESTM&ref1=2015-02&ref3=nobody@nowhere.com 1577 $rqx =
"{$FETCHER}{$delim}member={$HB_ENV['Cn']}&type=$Command&f=xxxx";
1578 if ($Command ==
'ESTM')
1579 $rqx .=
"&ref1={$eStatementID}";
1580 $rqx .=
"&ref3=" . urlencode($HB_ENV[
'Ml']) .
"&tauth={$HB_ENV['Cn']}";
1582 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1584 if (trim(
"$packet") ==
"") {
1585 if ($open_fail == 1) {
1586 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['Cn']} Estmt open failed", E_USER_ERROR);
1588 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['Cn']} Estmt empty packet response (pipe_err $pipe_err)", E_USER_ERROR);
1590 throw new Exception(
'Unable to retrieve data',
'999');
1600 checkForXmlParseErrors($packet);
1601 $pktpieces = array();
1603 # find something besides preg_match -- won't work with large data 1604 # do the preg_match on just the first 2k - <status> and <member> should 1605 # always be in the beginning of the packet 1607 $pktheader = substr($packet,0,2048);
1608 $status = (preg_match(
"/<status>\n?(.*)\n?<\/status>/si", $pktheader, $pktpieces) ? $pktpieces[1] :
"");
1609 $member = (preg_match(
"/<member>\n?(.*)\n?<\/member>/si", $pktheader, $pktpieces) ? $pktpieces[1] :
"");
1610 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1611 if (
"$member" >
"") {
1612 list($mem) = explode(
"\t", $member);
1614 if (trim(
"$mem") != $HB_ENV[
'Cn']) {
1615 trigger_error(
"{$HB_ENV['Cu']} possibly out-of-sync ($mem:{$HB_ENV['Cn']})", E_USER_ERROR);
1616 throw new Exception(
'Unable to retrieve data',
'999');
1619 # check the return status to decide what to do here 1620 # 101 New Data -- process packet 1621 # 201 System Unavailable, New Data -- can't use stale for EStatement 1622 # -- change to 200 and return 1623 # 100 No New Data -- return immediately 1624 # 200 System Unavailable, No New Data -- return immediately 1625 # 202 System Unavailable, No Data -- return immediately 1626 # 001 Invalid Account Number -- return immediately 1627 # 002 Invalid Password -- change to 001 Invalid Account and return 1628 # 003 Closed Account -- change to 001 Invalid Account and return 1629 # 010 Member not enrolled for E-statements 1630 # 012 Statement not found 1631 # 999 Calling error or Invalid Parms -- return immediately 1634 switch (sprintf(
'%03d',$statcode)) {
1636 # New data. Start parsing that packet... 1637 if ($Command ==
'ETOC') {
1638 $stPtrn =
'<EStatementTOC>';
1639 $ePtrn =
'</EStatementTOC>';
1640 } elseif ($Command ==
'ESTM') {
1641 $stPtrn =
'<EStatement>';
1642 $ePtrn =
'</EStatement>';
1644 # probably redundant since we checked $Command above.... 1645 throw new Exception(
'Invalid Command',
'999');
1648 if (stripos($packet, $stPtrn) ===
false ||
1649 stripos($packet, $ePtrn, stripos($packet, $stPtrn)) ===
false) {
1650 trigger_error(
"{$HB_ENV['Cu']}:{$HB_ENV['$Cn']} EStatement short packet response(pipe_err $pipe_err)", E_USER_ERROR);
1651 throw new Exception(
"$Command Unable to retrieve data",
'999');
1659 $estmt[status][status] =
"000";
1660 $estmt[status][asofdate] = date(
"D M j Y H:i:s T");
1661 $estmt[status][reason] = $statdesc;
1663 if ($Command ==
'ETOC') {
1664 $tblist = array(
"TOC");
1665 foreach ($tblist as $tbl) {
1666 # find a different way to do this, as large data will foul it up 1667 preg_match(
"/<$tbl>\n?(.*)<\/$tbl>/si", $packet, $pktpieces);
1668 $$tbl = explode(
"\n", $pktpieces[1]);
1671 if (
sizeof($$tbl)) {
1673 # format and return array ala new cu_data functions 1674 foreach ($$tbl as $line) {
1675 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
1676 $line = preg_replace(
"/ $/",
"", $line);
1677 $line = preg_replace(
"/\\0/",
" ", $line);
1678 list($Member, $ID, $sType, $PeriodEnd, $Description, $Format) = explode(
"\t", $line);
1680 $estmt[$tbl][$tblidx][
'Member'] = $Member;
1681 $estmt[$tbl][$tblidx][
'ID'] = $ID;
1682 $estmt[$tbl][$tblidx][
'Type'] = $sType;
1683 $estmt[$tbl][$tblidx][
'PeriodEnd'] = $PeriodEnd;
1684 $estmt[$tbl][$tblidx][
'Description'] = $Description;
1685 $estmt[$tbl][$tblidx][
'Format'] = $Format;
1691 # presumably ESTM - parse <member> into TOC and pop off <data>...</data> 1692 $start = stripos($packet,
"<MEMBER>");
1693 $end = stripos($packet,
"</MEMBER>");
1694 if($start ===
false || $end ===
false) {
1695 $estmt[
'TOC']=array();
1697 $start += 8; # move past the <MEMBER> tag
1698 $line = substr($packet,$start,$end-$start);
1699 $line = trim($line);
1700 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
1701 $line = preg_replace(
"/ $/",
"", $line);
1702 $line = preg_replace(
"/\\0/",
" ", $line);
1703 list($Member, $ID, $sType, $PeriodEnd, $Description, $Format) = explode(
"\t", $line);
1705 $estmt[TOC][0][
'Member'] = $Member;
1706 $estmt[TOC][0][
'ID'] = $ID;
1707 $estmt[TOC][0][
'Type'] = $sType;
1708 $estmt[TOC][0][
'PeriodEnd'] = $PeriodEnd;
1709 $estmt[TOC][0][
'Description'] = $Description;
1710 $estmt[TOC][0][
'Format'] = $Format;
1713 $start = stripos($packet,
"<DATA>");
1714 $end = strripos($packet,
"</DATA>");
1715 if($start ===
false || $end ===
false) {
1718 $start += 6; # move past the <DATA> tag
1719 $estmt[
'data'] = substr($packet,$start,$end-$start);
1724 # 001 Invalid Account Number 1725 # 002 Invalid Password -- change to 001 Invalid Account 1726 # 003 Closed Account -- change to 001 Invalid Account 1730 throw new Exception(
'INVALID ACCOUNT NUMBER',
'001');
1734 # 201 System Unavailable, New Data -- can't use stale for EStatement 1735 throw new Exception(
'Unusable Stale Data', $statcode);
1739 # 200 System Unavailable, No New Data 1740 # 202 System Unavailable, No Data 1741 # 010 Member not enrolled for E-statements 1742 # 012 Statement not found 1743 # 999 Calling error or Invalid Parms 1751 throw new Exception($statdesc, $statcode);
1754 }
catch (Exception $e) {
1755 $code = $e->getCode();
1756 $reason = $e->getMessage();
1758 $estmt[status][status] = sprintf(
'%03d',$code);
1759 $estmt[status][asofdate] = date(
"D M j Y H:i:s T");
1760 $estmt[status][reason] = $reason;