2 $monLibrary= dirname(__FILE__) .
"/../library";
3 require_once(
"$monLibrary/cu_top.i");
4 require_once(
"$monLibrary/ck_hticket.i");
6 $dms_ok=array(
'Hu'=>
'string',
'Cn'=>
'string',
'Pass'=>
'string',
7 'Showtab'=>
'string',
'Clw'=>
'string',
8 'pktstamp'=>
'string',
'cutoff'=>
'string',
'dowhat'=>
'string',
9 'holds2'=>
'string',
'fileit'=>
'string',
'truncit'=>
'string',
10 'showsplit'=>
'string',
'action'=>
'string',
'R1'=>
'string',
11 'R2'=>
'string',
'R3'=>
'string',
'R4'=>
'string',
12 'R5'=>
'string',
'Amt'=>
'string',
'Fs'=>
'string',
16 if (!CheckPerm($dbh, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
19 header(
"Location: /hcuadm/hcu_noperm.prg");
24 #error_reporting (E_ALL); 25 error_reporting (E_ERROR | E_WARNING | E_PARSE);
26 echo
"<html><LINK REL=stylesheet HREF='dms.css' TYPE='text/css'>";
27 $action = (empty($action) ?
"Show" : $action);
28 $thirty = mktime() - (30*86400);
29 $thirty = date(
"Ymd",$thirty);
30 define_syslog_variables();
31 #syslog(LOG_ERR,"Packetdump action is $action"); 32 $host = substr($_SERVER[
'SERVER_NAME'], 0,strpos($_SERVER[
'SERVER_NAME'],
"."));
36 # show forms for fetch/post 37 $sql =
"select cu, liveserver, histdays 40 and liveserver not ilike '%pgload%' 43 $sth = db_query($sql,$dbh);
44 $options =
"<select name=Fs>\n";
45 for ($row=0;list($cu, $fetcher, $histdays, $fset2) = db_fetch_array($sth,$row); $row++) {
47 $seltext = ($cu == $Fs ?
' selected' :
'');
48 $options .=
"<OPTION VALUE='$cu|$fetcher|$histdays|$fset2' $seltext>$cu</OPTION>\n";
50 $options .=
"</select>\n";
54 <head><title>Packet Dump</title></head>
55 <body bgcolor=#FFFFFF onLoad=
"self.focus()">
56 <div align=
'center' class=
'usu'>$host Live Packet Tester</div>
57 <div align=
'right' class=
'dtl'><a href=
"javascript:window.close()">Close Window</a></div>
58 <table width=98% cellpadding=2><tr>
59 <td valign=top align=center width=25%>
60 <form action=
"$PHP_SELF?action='fetch'">
62 <tr><td
class=
'bar' colspan=2 align=center>Fetch a Packet</td></tr>
63 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
64 <td>$options</td></tr>
65 <tr><td
class=
'dtl' align=
"right">Member: </td>
66 <td><input type=text name=
"Cn" size=10></td></tr>
67 <tr><td
class=
'dtl' align=
"right">Password: </td>
68 <td><input type=password name=
"Pass" size=10 MAXLENGTH=
"20"></td></tr>
69 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
70 <td><input type=text name=
"Showtab" size=10></td></tr>
71 <tr><td
class=
'dtl' align=
"right">Query Delay: </td>
72 <td><input type=text name=
"Clw" size=10 value=1></td></tr>
73 <tr><td
class=
'dtl' align=
"right">Last Packet Stamp: </td>
74 <td><input type=text name=
"pktstamp" size=10 value=1></td>
76 <tr><td
class=
'dtl' align=
"right">Earliest Date: </td>
77 <td><input type=text name=
"cutoff" size=10 value=
'$thirty'></td>
79 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
80 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
81 <input type=radio name=
"dowhat" value=
"D"> <nobr>Load Database<br>
82 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
84 <tr><td
class=
'dtl' align=
"right">Include Holds </td>
85 <td><input type=checkbox name=
"holds2" value=
"512"></td>
87 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw packet to file: </td>
88 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
90 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
91 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
93 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
94 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
96 <tr><td colspan=2 align=
"center">
97 <input type=submit name=
"action" value=
"Fetch" class=
'bar'>
101 </td><td valign=top align=center width=25%>
102 <form action=
"$PHP_SELF?action='retrieve'">
103 <table cellpadding=2>
104 <tr><td
class=
'bar' colspan=2 align=center>Cross-Accounts</td></tr>
105 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
106 <td>$options</td></tr>
107 <tr><td
class=
'dtl' align=
"right">Member: </td>
108 <td><input type=text name=
"Cn" size=10></td></tr>
109 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
110 <td><input type=text name=
"Showtab" size=10></td></tr>
111 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
112 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
113 <input type=radio name=
"dowhat" value=
"D"> <nobr>Load Database<br>
114 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
116 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw packet to file: </td>
117 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
119 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
120 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
122 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
123 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
125 <tr><td colspan=2 align=
"center">
126 <input type=submit name=
"action" value=
"Retrieve" class=
'bar'></td></tr>
129 </td><td valign=top align=center width=25%>
130 <form action=
"$PHP_SELF?action='mir'">
131 <table cellpadding=2>
132 <tr><td
class=
'bar' colspan=2 align=center>Member Info</td></tr>
133 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
134 <td>$options</td></tr>
135 <tr><td
class=
'dtl' align=
"right">Member: </td>
136 <td><input type=text name=
"Cn" size=10></td></tr>
137 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
138 <td><input type=text name=
"Showtab" size=10></td></tr>
139 <tr><td
class=
'dtl' align=
"right">Display Packet: </td>
140 <td><font size=-2><input type=radio name=
"dowhat" value=
"S" checked> Display Only<br>
141 <input type=radio name=
"dowhat" value=
"C"> <nobr>Count Columns</font></td>
143 <tr><td
class=
'dtl' align=
"right" valign=
"top">Save raw<br>packet to file: </td>
144 <td><input type=checkbox name=
"fileit" value=
"OK"></td>
146 <tr><td
class=
'dtl' align=
"right">Truncate packet file: </td>
147 <td><input type=checkbox name=
"truncit" value=
"OK"></td>
149 <tr><td
class=
'dtl' align=
"right">Show Split Data: </td>
150 <td><input type=checkbox name=
"showsplit" value=
"OK"></td>
152 <tr><td colspan=2 align=
"center">
153 <input type=submit name=
"action" value=
"Mir" class=
'bar'></td></tr>
156 </td><td valign=top align=center width=*>
157 <form action=
"$PHP_SELF?action='post'">
158 <table cellpadding=2>
159 <tr><td
class=
'bar' colspan=2 align=center>Post a Packet</td></tr>
160 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
161 <td>$options</td></tr>
162 <tr><td
class=
'dtl' align=
"right">Member: </td>
163 <td><input type=text name=
"Cn" size=10></td></tr>
164 <tr><td
class=
'dtl' align=
"right">Transaction Code: </td>
165 <td><select name=
"Tc">
177 <tr><td
class=
'dtl' align=
"right">Ref 1 (From Sfx): </td>
178 <td><input type=text name=
"R1" size=10 value=1></td></tr>
179 <tr><td
class=
'dtl' align=
"right">Ref 2 (To Sfx): </td>
180 <td><input type=text name=
"R2" size=10 value=1></td></tr>
181 <tr><td class=
'dtl' align=
"right">Ref 3 (email): </td>
182 <td><input type=text name=
"R3" size=10 value=1></td></tr>
183 <tr><td class=
'dtl' align=
"right">Ref 4 (To misc): </td>
184 <td><input type=text name=
"R4" size=10 value=1></td></tr>
185 <tr><td class=
'dtl' align=
"right">Ref 5 (To Mem): </td>
186 <td><input type=text name=
"R5" size=10 value=1></td></tr>
187 <tr><td class=
'dtl' align=
"right">Amount: </td>
188 <td><input type=text name=
"Amt" size=10></td></tr>
189 <tr><td colspan=2 align=
"center">
190 <input type=submit name=
"action" value=
"Post" class=
'bar'></td></tr>
194 </tr></table></body></html>
198 $dms_ok=array(
'Fs'=>
'string',
'cutoff'=>
'string',
'Cn'=>
'digits',
199 'Pass'=>
'string',
'ShowHolds'=>
'string',
'Showtab'=>
'string',
200 'URL'=>
'string',
'holds2'=>
'string',
'Clw'=>
'digits',
'pktstamp'=>
'string',
201 'cutoff'=>
'string',
'dowhat'=>
'string',
'fileit'=>
'string',
202 'truncit'=>
'string',
'showsplit'=>
'string');
207 list($Cu,$Fs, $histdays, $fset2) = explode(
"|",
"$Fs",4);
208 if (empty($cutoff)) { $cutoff =
"$thirty"; }
209 if (empty($histdays)) { $histdays = 0; }
210 if (empty($fset2)) { $fset2 = 0; }
212 $ShowHolds = ($fset2 & $CU2_SHOWHOLD);
213 if ($holds2) {$ShowHolds = $CU2_SHOWHOLD; }
214 print
"<html><head><title>Packet Fetch</title></head><body bgcolor=#FFFFFF> 215 Fetching packet using parameters<ul> 216 <li>Credit Union: $Cu</li> 218 <li>Password: $Pass</li> 219 <li>Show Holds: $ShowHolds</li> 220 <li>Show Tabs: $Showtab</li> 221 <li>Fetched from: $Fs</li> 223 <li>Wait between calls: $Clw</li> 224 <li>Last Packet Stamp: $pktstamp</li> 225 <li>Requested Cutoff: $cutoff</li> 227 if ($dowhat ==
"D") {
228 stuff_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit,$cutoff, $histdays, $fset2, $showsplit, $holds2);
229 } elseif ($dowhat ==
"C") {
230 valid_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit,$cutoff, $histdays, $fset2, $showsplit, $holds2);
232 fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit,$cutoff, $histdays, $showsplit, $holds2);
239 $dms_ok=array(
'Fs'=>
'string',
'Cn'=>
'digits',
'Showtab'=>
'string',
240 'dowhat'=>
'string',
'fileit'=>
'string',
'truncit'=>
'string',
241 'showsplit'=>
'string');
244 list($Cu,$Fs, $histdays) = explode(
"|",
"$Fs",3);
245 print
"<html><head><title>Cross-Account Retrieve</title></head><body bgcolor=#FFFFFF> 246 Retrieving Cross-Account Authorizations using parameters<ul> 247 <li>Credit Union: $Cu</li> 249 <li>Show Tabs: $Showtab</li> 250 <li>Fetched from: $Fs</li> 252 if ($dowhat ==
"D") {
253 stuff_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
254 } elseif ($dowhat ==
"C") {
255 valid_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
257 fetch_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit);
264 $dms_ok = array(
'Fs' =>
'string',
'Cn' =>
'digits',
'Showtab' =>
'string',
265 'dowhat' =>
'string',
'fileit' =>
'string',
'truncit' =>
'string',
266 'showsplit' =>
'string');
269 list($Cu, $Fs, $histdays) = explode(
"|",
"$Fs", 3);
270 print
"<html><head><title>Member Info Retrieve</title></head><body bgcolor=#FFFFFF> 271 Retrieving Member Info using parameters<ul> 272 <li>Credit Union: $Cu</li> 274 <li>Show Tabs: $Showtab</li> 275 <li>Fetched from: $Fs</li> 277 if ($dowhat ==
"C") {
278 valid_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit);
280 fetch_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit);
288 $dms_ok=array(
'Fs'=>
'string',
'Cn'=>
'digits',
'Showtab'=>
'string',
289 'TC'=>
'string',
'Amt'=>
'string',
'R2'=>
'string',
'R3'=>
'string',
290 'R4'=>
'string',
'R5'=>
'string');
293 list($Cu,$Fs,$histdays) = explode(
"|",
"$Fs",3);
294 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
295 $R3 = (trim($R3) ==
"" ?
"NULL" : $R3);
296 $R4 = (trim($R4) ==
"" ?
"NULL" : $R4);
297 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
298 print
"<html><head><title>Packet Post</title></head><body bgcolor=#FFFFFF> 299 Posting packet using parameters<ul> 300 <li>Credit Union: $Cu</li> 302 <li>Posted to: $Fs</li> 303 <li>Txn Code: $Tc</li> 309 <li>Amount: $Amt</li> 310 <li>URL: $Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt</li> 312 post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt);
316 function fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit,$cutoff, $histdays, $showsplit, $holds2) {
318 if ($Pass ===
'0') {$Pass =
'00';}
319 if (
"$pktstamp"==
"") {
320 # read last pktstamp from database. Calculate new threshold as 321 # now - pktinterval; if pktstamp > threshold, return (use existing) 325 $sql =
"select pktstamp, pktdate, livewait 326 from cuusers u, cuadmin a 328 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
329 $sth = db_query($sql,$dbh);
330 list($pktstamp, $pktdate,$Clw) = db_fetch_array($sth,0);
331 db_free_result($sth);
334 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
335 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
336 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
338 $threshold = mktime() - $Clw;
339 $fs = date(
"D M j Y H:i:s T",$pktstamp);
340 $ft = date(
"D M j Y H:i:s T",$threshold);
341 if ($pktstamp > $threshold) {
342 print
"Too soon to ask again<br> 344 Threshold: $ft<br></body></html>";
347 # if the last packet was fairly recent only fetch 7 days 348 # "recent" defined as 3 times the packet timeout setting 349 $threshold = mktime() - (3 * $Clw);
350 if (empty($cutoff)) { $cutoff =
"$thirty"; }
351 if (empty($histdays)) { $histdays = 0; }
352 # 1072940400 is the timestamp for 20040101 353 if ($pktstamp >1072940400 && $histdays > 0 && $cutoff == $thirty) {
354 # calculate cutoff as pktstamp - interval($histdays days) 355 if ($pktstamp > $threshold) {
356 # last packet age is less than 3 times the packet timeout setting 357 # set cutoff for 7 days 358 $cutoff = date(
"Ymd",mktime()-604800);
360 $cutoff = date(
"Ymd",$pktstamp-(86400 * $histdays));
365 $urlSep = (strpos($Fs,
'?') ===
false ?
'?' :
'&');
366 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
367 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
369 $URL.=
"&pass=" . urlencode($Pass);
371 $rqx =
"$Fs{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
373 $rqx .=
"&pass=" . urlencode($Pass);
375 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
378 #if ($packet = file_get_contents("/home/ubuntu/packetdump.txt")){ 379 # $fd = @fopen ("$Fs$URL", "r"); 382 # stream_set_timeout($fd,100); 383 # while ($buff = fread ($fd, 1500)) { 387 # add feature here to log (and optionally truncate first) packet to a temp file 389 if ($fileit ==
"OK") {
390 if($truncit ==
"OK") {
391 $fp=fopen(
"/tmp/packetdump.txt",
"w");
393 $fp=fopen(
"/tmp/packetdump.txt",
"a");
397 if ($showsplit ==
'OK') {
398 $pktpattern=
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
399 $pktpattern=
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
401 $inqpattern=
'/<\/*Inquiry>/i';
402 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 403 preg_match_all(
"$pktpattern",preg_replace($inqpattern,
"",$packet),$pktshow);
405 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
406 array_walk($pktshow,
'showquoted');
408 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
410 # $packet = preg_replace("/ ?\t ?/","\t",$packet); 411 if (
"$Showtab" !=
"") { $packet = preg_replace(
"/\t/",
"$Showtab",$packet);}
412 $packet = HTMLSpecialChars($packet);
413 print
"<br>URL: $URL<br><pre>$packet</pre></body></html>";
415 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
420 function stuff_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2) {
423 if (
"$pktstamp" ==
"") {
424 # read last pktstamp from database. Calculate new threshold as 425 # now - pktinterval; if pktstamp > threshold, return (use existing) 427 $sql =
"select pktstamp, pktdate, livewait 428 from cuusers u, cuadmin a 430 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
431 $sth = db_query($sql, $dbh);
432 list($pktstamp, $pktdate, $Clw) = db_fetch_array($sth, 0);
433 db_free_result($sth);
436 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
437 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
438 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
440 $threshold = mktime() - $Clw;
442 $fs = date(
"D M j Y H:i:s T", $pktstamp);
443 $ft = date(
"D M j Y H:i:s T", $threshold);
444 if ($pktstamp > $threshold) {
445 print
"Too soon to ask again<br> 447 Threshold: $ft<br></body></html>";
449 # if the last packet was fairly recent only fetch 7 days 450 # "recent" defined as 3 times the packet timeout setting 451 $threshold = mktime() - (3 * $Clw);
452 if (empty($cutoff)) {
455 if (empty($histdays)) {
458 # 1072940400 is the timestamp for 20040101 459 if ($pktstamp > 1072940400 && $histdays > 0 && $cutoff == $thirty) {
460 # calculate cutoff as pktstamp - interval($histdays days) 461 if ($pktstamp > $threshold) {
462 # last packet age is less than 3 times the packet timeout setting 463 # set cutoff for 7 days 464 $cutoff = date(
"Ymd", mktime() - 604800);
466 $cutoff = date(
"Ymd", $pktstamp - (86400 * $histdays));
469 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
470 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
472 $URL.=
"&pass=" . urlencode($Pass);
475 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
484 if ($fileit ==
"OK") {
485 if ($truncit ==
"OK") {
486 $fp = fopen(
"/tmp/packetdump.txt",
"w");
488 $fp = fopen(
"/tmp/packetdump.txt",
"a");
490 fwrite($fp, $packet);
493 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/';
494 $pktpieces = array();
495 $pktpattern =
'/<([^<>\/]*)>(.*)<\/\\1>/Us';
496 $inqpattern =
'/<\/*Inquiry>/i';
497 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 498 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktpieces);
500 if ($showsplit ==
'OK') {
502 # use a different array so we don't change the actual data 504 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
505 $pktpattern =
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
507 $inqpattern =
'/<\/*Inquiry>/i';
508 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 509 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktshow);
511 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
512 array_walk($pktshow,
'showquoted');
514 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
516 array_shift($pktpieces);
517 foreach ($pktpieces[0] as $pos => $tag) {
518 $tags[(strtolower($tag))] = $pos;
520 array_shift($pktpieces);
521 list($mem, $pcutoff) = explode(
"\t", $pktpieces[0][($tags[
'parameters'])]);
522 # if the packet presents a cutoff date, let it override our request 523 $cutoff = (
"$pcutoff" ==
"" ? $cutoff : $pcutoff);
524 list($mem, $statcode, $statdesc) = explode(
"\t", $pktpieces[0][($tags[
'status'])]);
525 list($pktstamp, $pktdate) = explode(
"\t", $pktpieces[0][($tags[
'time'])]);
526 print
"<br>URL: $URL<br>";
529 Description: $statdesc<br> 530 Cutoff: (requested) $cutoff (returned) $pcutoff<br>";
531 if (trim($mem) != $Cn) {
533 $statdesc =
"Returned packet doesn't match request!";
536 # check the return status to decide what to do here 537 # 101 New Data -- process packet, update pktstamp 538 # 201 System Unavailable, New Data -- process packet, update pktstamp 539 # 100 No New Data -- update pktstamp 540 # 200 System Unavailable, No New Data -- return immediately 541 # 202 System Unavailable, No Data -- return immediately 542 # 999 Calling error or Invalid Parms -- return immediately 549 # Need to refresh the db data. Start parsing that packet... 550 foreach ($tags as $tag => $pos) {
553 case "accountbalance":
555 case "accounthistory":
559 $$tag = explode(
"\n", $pktpieces[0][$pos]);
561 # newlines around data on multiline components 562 # causes empty items in array. 563 # Pop the empty off the end 564 # new regex leaves newline at top as well, 565 # so shift it off also 573 # stuff each piece in the db 574 # set pktstamp to 1 so if we die in the middle next query will force reload 576 $sql =
"update cuusers set pktstamp = 1, 577 pktdate = '" . date(
"D M j Y H:i:s T") .
"' 578 where cu = '" . $Cu .
"' 579 and user_name = '" . $Cn .
"'";
580 $sth = db_query($sql, $dbh);
582 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
583 if ($holds2 || ($fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) {
586 foreach ($tblist as $tbl) {
589 case "accountbalance":
592 $sql =
"delete from ${Cu}${tbl} 593 where accountnumber='" . $Cn .
"'";
594 $sth = db_query($sql, $dbh);
596 case "accounthistory":
598 $sql =
"delete from ${Cu}${tbl} 599 where accountnumber='" . $Cn .
"' 600 and date >= '" . $cutoff .
"'";
601 $sth = db_query($sql, $dbh);
605 print
"<font color='blue'>Loading " .
sizeof($$tbl) .
" records for $tbl...</font><br>\n";
609 foreach ($$tbl as $line) {
611 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
612 $line = preg_replace(
"/ $/",
"", $line);
613 $line = preg_replace(
"/\\0/",
"", $line);
614 $sth = db_query(
"copy ${Cu}${tbl} from stdin with null as ''", $dbh);
615 pg_put_line($dbh,
"$line\n");
616 pg_put_line($dbh,
"\\.\n");
617 if (!(@pg_end_copy($dbh))) {
618 $copyerr =
"Error writing previous line";
621 if (
"$Showtab" !=
"") {
622 $line = preg_replace(
"/\t/",
"$Showtab", $line);
624 $line = HTMLSpecialChars($line);
627 print
"<font color='red'>$copyerr</font>\n<br>";
636 $sql =
"update cuusers set pktstamp = $pktstamp, 637 pktdate = '" . $pktdate .
"' 638 where cu = '" . $Cu .
"' 639 and user_name = '" . $Cn .
"'";
640 $sth = db_query($sql, $dbh);
642 print
"FAILED setting pktstamp for $Cu:$Cn" . pg_errormessage() .
"\n<br>";
649 print
"Status: $statcode Date: $pktdate Description: $statdesc<br>\n";
651 print
"Status: $statcode Date: 1 Description: $statdesc<br>\n";
655 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
659 function valid_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $fileit, $truncit, $cutoff, $histdays, $fset2, $showsplit, $holds2) {
662 if (
"$pktstamp" ==
"") {
663 # read last pktstamp from database. Calculate new threshold as 664 # now - pktinterval; if pktstamp > threshold, return (use existing) 666 $sql =
"select pktstamp, pktdate, livewait 667 from cuusers u, cuadmin a 669 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
670 $sth = db_query($sql, $dbh);
671 list($pktstamp, $pktdate, $Clw) = db_fetch_array($sth, 0);
672 db_free_result($sth);
675 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
676 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
677 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
679 $threshold = mktime() - $Clw;
681 $fs = date(
"D M j Y H:i:s T", $pktstamp);
682 $ft = date(
"D M j Y H:i:s T", $threshold);
683 if ($pktstamp > $threshold) {
684 print
"Too soon to ask again<br> 686 Threshold: $ft<br></body></html>";
688 # if the last packet was fairly recent only fetch 7 days 689 # "recent" defined as 3 times the packet timeout setting 690 $threshold = mktime() - (3 * $Clw);
691 if (empty($cutoff)) {
694 if (empty($histdays)) {
697 # 1072940400 is the timestamp for 20040101 698 if ($pktstamp > 1072940400 && $histdays > 0 && $cutoff == $thirty) {
699 # calculate cutoff as pktstamp - interval($histdays days) 700 if ($pktstamp > $threshold) {
701 # last packet age is less than 3 times the packet timeout setting 702 # set cutoff for 7 days 703 $cutoff = date(
"Ymd", mktime() - 604800);
705 $cutoff = date(
"Ymd", $pktstamp - (86400 * $histdays));
708 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
709 $URL =
"{$delim}member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
711 $URL.=
"&pass=" . urlencode($Pass);
714 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
723 if ($fileit ==
"OK") {
724 if ($truncit ==
"OK") {
725 $fp = fopen(
"/tmp/packetdump.txt",
"w");
727 $fp = fopen(
"/tmp/packetdump.txt",
"a");
729 fwrite($fp, $packet);
732 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/';
733 $pktpieces = array();
734 $pktpattern =
'/<([^<>\/]*)>(.*)<\/\\1>/Us';
735 $inqpattern =
'/<\/*Inquiry>/i';
736 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 737 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktpieces);
739 if ($showsplit ==
'OK') {
741 # use a different array so we don't change the actual data 743 $pktpattern =
'/<([^<>\/]*)?>\n?([^<]*)?/'; # current code chokes on <
744 $pktpattern =
'/<([^<>\/]*)>\n*(.*)<\/\\1>/Us';
746 $inqpattern =
'/<\/*Inquiry>/i';
747 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 748 preg_match_all(
"$pktpattern", preg_replace($inqpattern,
"", $packet), $pktshow);
750 print
"Split Results: using pattern $pktpattern<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
751 array_walk($pktshow,
'showquoted');
753 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
755 array_shift($pktpieces);
756 foreach ($pktpieces[0] as $pos => $tag) {
757 $tags[(strtolower($tag))] = $pos;
759 array_shift($pktpieces);
760 list($mem, $pcutoff) = explode(
"\t", $pktpieces[0][($tags[
'parameters'])]);
761 # if the packet presents a cutoff date, let it override our request 762 $cutoff = (
"$pcutoff" ==
"" ? $cutoff : $pcutoff);
763 list($mem, $statcode, $statdesc) = explode(
"\t", $pktpieces[0][($tags[
'status'])]);
764 list($pktstamp, $pktdate) = explode(
"\t", $pktpieces[0][($tags[
'time'])]);
765 print
"<br>URL: $URL<br>";
768 Description: $statdesc<br> 769 Cutoff: (requested) $cutoff (returned) $pcutoff<br>";
770 if (trim($mem) != $Cn) {
772 $statdesc =
"Returned packet doesn't match request!";
775 # check the return status to decide what to do here 776 # 101 New Data -- process packet, update pktstamp 777 # 201 System Unavailable, New Data -- process packet, update pktstamp 778 # 100 No New Data -- update pktstamp 779 # 200 System Unavailable, No New Data -- return immediately 780 # 202 System Unavailable, No Data -- return immediately 781 # 999 Calling error or Invalid Parms -- return immediately 787 # Need to refresh the db data. Start parsing that packet... 788 foreach ($tags as $tag => $pos) {
791 case "accountbalance":
793 case "accounthistory":
797 $$tag = explode(
"\n", $pktpieces[0][$pos]);
799 # newlines around data on multiline components 800 # causes empty items in array. 801 # Pop the empty off the end 802 # new regex leaves newline at top as well, 803 # so shift it off also 812 $expected{
'accountbalance'} = 10;
813 $expected{
'accounthistory'} = 10;
814 $expected{
'loanbalance'} = 14;
815 $expected{
'loanhistory'} = 9;
816 $expected{
'messages'} = 4;
817 $expected{
'holds'} = 9;
821 $tblist = array(
"accountbalance",
"loanbalance",
"accounthistory",
"loanhistory",
"messages");
822 if ($holds2 || ($fset2 & $CU2_SHOWHOLD) == $CU2_SHOWHOLD) {
825 foreach ($tblist as $tbl) {
826 # print "<font color='blue'>Counting " . sizeof($$tbl) . " records for $tbl...</font><br>\n"; 832 foreach ($$tbl as $line) {
833 $line = preg_replace(
"/ ?\t ?/",
"\t", $line);
834 $line = preg_replace(
"/ $/",
"", $line);
835 $line = preg_replace(
"/\\0/",
"", $line);
836 $count = (count(explode(
"\t", $line)));
837 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
838 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
839 if (
"$Showtab" !=
"") {
840 $line = preg_replace(
"/\t/",
"$Showtab", $line);
842 $line = HTMLSpecialChars($line);
846 print
"<font color='blue'>Counted " .
sizeof($$tbl) .
" records for $tbl... (Expected: " . $expected{$tbl} .
")</font> Min: $mincnt Max: $maxcnt<br><br>\n";
855 print
"Status: $statcode Date: $pktdate Description: $statdesc<br>\n";
857 print
"Status: $statcode Date: 1 Description: $statdesc<br>\n";
861 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
866 function fetch_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit) {
868 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
869 $URL =
"{$delim}member=$Cn&type=X&f=xxxx";
871 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
881 # add feature here to log (and optionally truncate first) packet to a temp file 883 if ($fileit ==
"OK") {
884 if ($truncit ==
"OK") {
885 $fp = fopen(
"/tmp/packetdump.txt",
"w");
887 $fp = fopen(
"/tmp/packetdump.txt",
"a");
889 fwrite($fp, $packet);
892 if (
"$Showtab" !=
"") {
893 $packet = preg_replace(
"/\t/",
"$Showtab", $packet);
895 $packet = HTMLSpecialChars($packet);
896 print
"<br>URL: $URL<br><pre>$packet</pre></body></html>";
898 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
902 function fetch_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit) {
903 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
904 $URL =
"{$delim}member=$Cn&type=MIR&f=xxxx";
906 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
916 # add feature here to log (and optionally truncate first) packet to a temp file 918 if ($fileit ==
"OK") {
919 if ($truncit ==
"OK") {
920 $fp = fopen(
"/tmp/packetdump.txt",
"w");
922 $fp = fopen(
"/tmp/packetdump.txt",
"a");
924 fwrite($fp, $packet);
927 if (
"$Showtab" !=
"") {
928 $packet = preg_replace(
"/\t/",
"$Showtab", $packet);
930 $packet = HTMLSpecialChars($packet);
931 print
"<br>URL: $URL<br><pre>$packet</pre></body></html>";
933 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
936 function stuff_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
939 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
940 $URL =
"{$delim}member=$Cn&type=X&f=xxxx";
943 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
947 # $switchfrom should be set 948 # from ((cuadmin.flagset & $CU_PKT_SWITCH) == $CU_PKT_SWITCH) 949 # but for now no one gets switch account info in the pkt so I'll skip 950 # the call to the cuadmin table-- 958 if ($fileit ==
"OK") {
959 if ($truncit ==
"OK") {
960 $fp = fopen(
"/tmp/packetdump.txt",
"w");
962 $fp = fopen(
"/tmp/packetdump.txt",
"a");
964 fwrite($fp, $packet);
967 if (
"$Showtab" !=
"") {
968 $pkt = preg_replace(
"/\t/",
"$Showtab", $pkt);
970 $pkt = HTMLSpecialChars($pkt);
971 print
"<br>URL: $URL<br><pre>$pkt</pre><br>";
974 $pktpieces = array();
976 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
977 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
978 if (trim($mem) != $Cn) {
979 return array(999, 1,
"Unable to retrieve a packet");
982 # check the return status to decide what to do here 983 # 101 New Data -- process packet, update pktstamp 984 # 200 System Unavailable, No New Data -- return immediately 985 # 001 Invalid Account Number -- return immediately 986 # 999 Calling error or Invalid Parms -- return immediately 992 # Need to refresh the db data. Start parsing that packet... 993 # find out what we have in the database... 995 $sql =
"select trim(accountnumber), trim(tomember), 996 trim(accounttype), deposittype, description, misc1, id 997 from culivetx where cu = '$Cu' and accountnumber = '$Cn'";
998 if ($switchfrom ==
'A') {
999 $sql .=
" and deposittype not in ('W','w')";
1002 $sth = db_query($sql, $dbh);
1004 for ($row = 0; $rec = db_fetch_row($sth, $row); $row++) {
1005 $db_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]\t$rec[6]";
1008 # make an array from the stuff in the packet 1010 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si", $packet, $pktpieces);
1011 $txaccount = explode(
"\n", $pktpieces[1]);
1012 array_pop($txaccount);
1015 foreach ($txaccount as $line) {
1017 $rec = explode(
"\t", $line);
1018 $tx_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]";
1021 $inserts = array_diff(array_keys($tx_keys), array_keys($db_keys));
1022 $deletes = array_diff(array_keys($db_keys), array_keys($tx_keys));
1023 $updates = array_intersect(array_keys($tx_keys), array_keys($db_keys));
1025 if ($showsplit ==
'OK') {
1027 $pktshow = $txaccount;
1029 print
"Packet Contains:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1030 array_walk($pktshow,
'showquoted');
1032 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1033 $pktshow = $db_keys;
1034 print
"Database Has:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1035 array_walk($pktshow,
'showquoted');
1037 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1038 $pktshow = $inserts;
1039 print
"Insert keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1040 array_walk($pktshow,
'showquoted');
1042 $pktshow = $updates;
1043 print
"Update keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1044 array_walk($pktshow,
'showquoted');
1046 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1047 $pktshow = $deletes;
1048 print
"Delete keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1049 array_walk($pktshow,
'showquoted');
1054 foreach ($updates as $line) {
1055 $rec = explode(
"\t", $db_keys[
"$line"]);
1056 $trec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1057 # don't update descriptions on switchacct records. 1058 # If the member changes the description we want it to 'stick'. 1060 if ($trec[3] !=
'W' && $trec[3] !=
'w' &&
1061 ($rec[0] != $trec[4] || $rec[1] != $trec[5])) {
1062 $sql .=
"update culivetx set description = '" .
1063 prep_save($trec[4]) .
"', 1064 misc1 = '" . prep_save($trec[5]) .
"' where id = ${rec[2]};\n";
1068 foreach ($inserts as $key => $line) {
1069 $rec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1071 # switchfrom is A when switchaccts are maintained in admin. Only insert the 1072 # switchacct records coming from the core if that's where we expect to get 'em. 1074 if ($switchfrom !=
'A' || ($rec[3] !=
'W' && $rec[3] !=
'w')) {
1075 $sql .=
"insert into culivetx (cu, accountnumber, tomember, 1076 accounttype, deposittype, description, misc1) values ( 1077 '$Cu','${rec[0]}','${rec[1]}', '${rec[2]}', '${rec[3]}', 1078 '" . prep_save($rec[4]) .
"', '" . prep_save($rec[5]) .
"');\n";
1082 foreach ($deletes as $key => $line) {
1083 $rec = explode(
"\t", $db_keys[
"$line"]);
1084 $sql .=
"delete from culivetx where id = ${rec[2]};\n";
1086 if ($showsplit ==
'OK') {
1087 print
"SQL: <br>++++++++++++++++++++++++++++++++++++++++<br>";
1090 print
"Will execute SQL <pre>$sql</pre>\n";
1092 print
"No SQL to execute\n";
1096 $sth = db_query($sql, $dbh);
1098 $err = pg_last_error();
1100 syslog(LOG_ERR,
"FAILED $err setting txaccounts for $Cu:$Cn\n$sql");
1103 db_free_result($sth);
1105 if ($errstat == 0) {
1106 return array(
"$statcode",
"$u",
"$statdesc");
1108 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1114 return array(
"$statcode", 1,
"$statdesc");
1117 return array(999, 1, $php_errormsg);
1121 function valid_xac($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
1124 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1125 $URL =
"{$delim}member=$Cn&type=X&f=xxx";
1127 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1128 if ($packet !=
'') {
1137 if ($fileit ==
"OK") {
1138 if ($truncit ==
"OK") {
1139 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1141 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1143 fwrite($fp, $packet);
1147 $pktpieces = array();
1149 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
1150 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1151 if (trim($mem) != $Cn) {
1152 return array(999, 1,
"Unable to retrieve a packet");
1155 # check the return status to decide what to do here 1156 # 101 New Data -- process packet, update pktstamp 1157 # 200 System Unavailable, No New Data -- return immediately 1158 # 001 Invalid Account Number -- return immediately 1159 # 999 Calling error or Invalid Parms -- return immediately 1163 switch ($statcode) {
1165 # Need to refresh the db data. Start parsing that packet... 1166 # find out what we have in the database... 1168 $sql =
"select trim(accountnumber), trim(tomember), 1169 trim(accounttype), deposittype, description, misc1, id 1170 from culivetx where cu = '$Cu' and accountnumber = '$Cn'";
1171 if ($switchfrom ==
'A') {
1172 $sql .=
" and deposittype not in ('W','w')";
1175 $sth = db_query($sql, $dbh);
1177 for ($row = 0; $rec = db_fetch_row($sth, $row); $row++) {
1178 $db_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]\t$rec[6]";
1181 # make an array from the stuff in the packet 1183 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si", $packet, $pktpieces);
1184 $txaccount = explode(
"\n", $pktpieces[1]);
1185 array_pop($txaccount);
1191 foreach ($txaccount as $line) {
1192 $count = (count(explode(
"\t", $line)));
1193 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
1194 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
1196 $rec = explode(
"\t", $line);
1197 $tx_keys[
"$rec[0]\t$rec[1]\t$rec[2]\t$rec[3]"] =
"$rec[4]\t$rec[5]";
1198 if (
"$Showtab" !=
"") {
1199 $line = preg_replace(
"/\t/",
"$Showtab", $line);
1201 $line = HTMLSpecialChars($line);
1206 print
"<font color='blue'>Counted " .
sizeof($txaccount) .
" Cross-Account records...(Expected: 6)</font> Min: $mincnt Max: $maxcnt<br><br>\n";
1208 $inserts = array_diff(array_keys($tx_keys), array_keys($db_keys));
1209 $deletes = array_diff(array_keys($db_keys), array_keys($tx_keys));
1210 $updates = array_intersect(array_keys($tx_keys), array_keys($db_keys));
1212 if ($showsplit ==
'OK') {
1214 $pktshow = $txaccount;
1216 print
"Packet Contains:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1217 array_walk($pktshow,
'showquoted');
1219 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1220 $pktshow = $db_keys;
1221 print
"Database Has:<br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1222 array_walk($pktshow,
'showquoted');
1224 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1225 $pktshow = $inserts;
1226 print
"Insert keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1227 array_walk($pktshow,
'showquoted');
1229 $pktshow = $updates;
1230 print
"Update keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1231 array_walk($pktshow,
'showquoted');
1233 print
"++++++++++++++++++++++++++++++++++++++++\n</pre>";
1234 $pktshow = $deletes;
1235 print
"Delete keys: <br><pre>++++++++++++++++++++++++++++++++++++++++\n";
1236 array_walk($pktshow,
'showquoted');
1241 foreach ($updates as $line) {
1242 $rec = explode(
"\t", $db_keys[
"$line"]);
1243 $trec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1244 # don't update descriptions on switchacct records. 1245 # If the member changes the description we want it to 'stick'. 1247 if ($trec[3] !=
'W' && $trec[3] !=
'w' &&
1248 ($rec[0] != $trec[4] || $rec[1] != $trec[5])) {
1249 $sql .=
"update culivetx set description = '" .
1250 prep_save($trec[4]) .
"', 1251 misc1 = '${trec[5]}' where id = ${rec[2]};\n";
1255 foreach ($inserts as $line) {
1256 $rec = array_merge(explode(
"\t", $line), explode(
"\t", $tx_keys[
"$line"]));
1258 # switchfrom is A when switchaccts are maintained in admin. Only insert the 1259 # switchacct records coming from the core if that's where we expect to get 'em. 1261 if ($switchfrom !=
'A' || ($rec[3] !=
'W' && $rec[3] !=
'w')) {
1262 $sql .=
"insert into culivetx (cu, accountnumber, tomember, 1263 accounttype, deposittype, description, misc1) values ( 1264 '$Cu','${rec[0]}','${rec[1]}', '${rec[2]}', '${rec[3]}', 1265 '" . prep_save($rec[4]) .
"', '${rec[5]}');\n";
1269 foreach ($deletes as $line) {
1270 $rec = explode(
"\t", $db_keys[
"$line"]);
1271 $sql .=
"delete from culivetx where id = ${rec[2]};\n";
1273 if ($showsplit ==
'OK') {
1274 print
"SQL: <br>++++++++++++++++++++++++++++++++++++++++<br>";
1282 if ($errstat == 0) {
1283 return array(
"$statcode",
"$u",
"$statdesc");
1285 return array(
"$statcode", 1,
"Error loading member data. Please contact Credit Union");
1291 return array(
"$statcode", 1,
"$statdesc");
1294 return array(999, 1, $php_errormsg);
1297 function valid_mir($Fs, $Cu, $Cn, $Showtab, $fileit, $truncit, $showsplit) {
1300 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1301 $URL =
"{$delim}member=$Cn&type=MIR&f=xxx";
1303 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1304 if ($packet !=
'') {
1312 if ($fileit ==
"OK") {
1313 if ($truncit ==
"OK") {
1314 $fp = fopen(
"/tmp/packetdump.txt",
"w");
1316 $fp = fopen(
"/tmp/packetdump.txt",
"a");
1318 fwrite($fp, $packet);
1322 $pktpieces = array();
1324 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s", $packet, $pktpieces) ? $pktpieces[1] :
"");
1325 list($mem, $statcode, $statdesc) = explode(
"\t", $status);
1326 if (trim($mem) != $Cn) {
1327 return array(999, 1,
"Unable to retrieve a packet");
1330 # check the return status to decide what to do here 1331 # 101 New Data -- process packet, update pktstamp 1332 # 200 System Unavailable, No New Data -- return immediately 1333 # 001 Invalid Account Number -- return immediately 1334 # 999 Calling error or Invalid Parms -- return immediately 1338 switch ($statcode) {
1340 # New data. Start parsing that packet... 1341 # make an array from the stuff in the packet 1343 preg_match(
"/<info>\n?(.*)<\/info>/si", $packet, $pktpieces);
1344 $mir = explode(
"\n", $pktpieces[1]);
1350 foreach ($mir as $line) {
1351 $count = (count(explode(
"\t", $line)));
1352 $mincnt = (($count < $mincnt || $mincnt == 0) ? $count : $mincnt);
1353 $maxcnt = ($count > $maxcnt ? $count : $maxcnt);
1354 if (
"$Showtab" !=
"") {
1355 $line = preg_replace(
"/\t/",
"$Showtab", $line);
1357 $line = HTMLSpecialChars($line);
1362 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";
1368 return array(
"$statcode", 1,
"$statdesc");
1371 return array(999, 1, $php_errormsg);
1374 function post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt) {
1377 $delim = (strpos($Fs,
'?')===
false ?
'?' :
'&');
1378 $URL =
"{$delim}member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt";
1380 list ($open_fail, $pipe_err, $packet) = get_data($rqx);
1381 if ($packet !=
'') {
1390 $packet = HTMLSpecialChars($packet);
1391 print
"<pre>$packet</pre></body></html>";
1393 print
"Couldn't get a packet!<br>$php_errormsg<br>";
1394 print
"URL=$Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt<br>";
1398 function showquoted(&$val) {
1399 if (is_array($val)) {
1400 array_walk($val,
'showquoted');
1403 $val = htmlentities($val);
1405 function get_data($rqx) {
1406 # returns open_fail as 0 no error or 1 fopen/popen failed 1407 # pipe_err as termination code from piped command (always zero if fopen?) 1408 # packet as data returned from core 1418 $pipe=1; # force use of popen but allow
for easy recoding
1421 $fd=popen(
"/usr/bin/curl -k -N --silent '$rqx'",
"r");
1425 while ($buff = fread ($fd, 1500)) {
1428 $pipe_err=pclose($fd);
1430 return array($open_fail,$pipe_err,$packet);
1432 $fd = @fopen(
"$rqx",
"r");
1436 $pkti = stream_get_meta_data($fd);
1437 while ((!feof($fd)) && (!$pkti[
'timed_out'])) {
1438 $packet .= fread($fd, 4096);
1439 $pkti = stream_get_meta_data($fd);
1442 if ($pkti[
'timed_out']) {
1446 return array($open_fail,$pipe_err,$packet);