2 $monLibrary= dirname(__FILE__) .
"/../library";
3 require_once(
"$monLibrary/cu_top.i");
4 require_once(
"$monLibrary/ck_hticket.i");
7 $dms_ok=array(
'Hu'=>
'string',
'Cn'=>
'string',
'Pass'=>
'string',
8 'Showtab'=>
'string',
'Clw'=>
'string',
9 'pktstamp'=>
'string',
'cutoff'=>
'string',
10 'action'=>
'string',
'R1'=>
'string',
11 'R2'=>
'string',
'R3'=>
'string',
'R4'=>
'string',
12 'R5'=>
'string',
'Amt'=>
'string',
'Fs'=>
'string',
16 $SYSENV = LoadSystemEnv(
'admin');
17 require(
"db." . $SYSENV[
'db'][
'platform'] .
".i");
19 $dbh = db_pconnect($SYSENV[
'db']);
20 if (!CheckPerm($dbh, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
23 header(
"Location: /hcuadm/hcu_noperm.prg");
27 #error_reporting (E_ALL); 28 error_reporting (E_ERROR | E_WARNING | E_PARSE);
29 echo
"<html><LINK REL=stylesheet HREF='/monitor/css/cudp.css' TYPE='text/css'>";
30 $action = (empty($action) ?
"Show" : $action);
31 $thirty = mktime() - (30*86400);
32 $thirty = date(
"Ymd",$thirty);
34 #define_syslog_variables(); 35 #syslog(LOG_ERR,"Packetdump action is $action"); 36 $host = substr($_SERVER[
'SERVER_NAME'], 0,strpos($_SERVER[
'SERVER_NAME'],
"."));
40 # show forms for fetch/post 41 $sql =
"select cu, liveserver, histdays 44 and vendor = 'CUPRODIGY' 47 $sth = db_query($sql,$dbh);
48 $options =
"<select name=Fs>\n";
49 for ($row=0;list($cu, $fetcher, $histdays) = db_fetch_array($sth,$row); $row++) {
51 $options .=
"<OPTION VALUE='$cu|$fetcher|$histdays'>$cu</OPTION>\n";
53 $options .=
"</select>\n";
57 <head><title>Packet Dump</title></head><body bgcolor=#FFFFFF>
58 <div align=
'center' class=
'usu'>CUDP Live Packet Tester</div>
59 <table width=98% cellpadding=2><tr>
60 <td valign=top align=center width=34%>
61 <form action=
"$PHP_SELF?action='fetch'">
63 <tr><td
class=
'bar' colspan=2 align=center>Fetch a Packet</td></tr>
64 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
65 <td>$options</td></tr>
66 <tr><td
class=
'dtl' align=
"right">Member: </td>
67 <td><input type=text name=
"Cn" size=10></td></tr>
68 <tr><td
class=
'dtl' align=
"right">Password: </td>
69 <td><input type=password name=
"Pass" size=10 MAXLENGTH=
"8"></td></tr>
70 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
71 <td><input type=text name=
"Showtab" size=10></td></tr>
72 <tr><td
class=
'dtl' align=
"right">Query Delay: </td>
73 <td><input type=text name=
"Clw" size=10 value=1></td></tr>
74 <tr><td
class=
'dtl' align=
"right">Last Packet Stamp: </td>
75 <td><input type=text name=
"pktstamp" size=10 value=1></td>
77 <tr><td
class=
'dtl' align=
"right">Earliest Date: </td>
78 <td><input type=text name=
"cutoff" size=10 value=
'$thirty'></td>
79 <tr><td
class=
'dtl' align=
"right">Count Columns: </td>
80 <td><input type=checkbox name=
"validresp" value=
"OK"></td>
82 <tr><td colspan=2 align=
"center">
83 <input type=submit name=
"action" value=
"Fetch" class=
'bar'>
87 </td><td valign=top align=center width=33%>
88 <form action=
"$PHP_SELF?action='retrieve'">
90 <tr><td
class=
'bar' colspan=2 align=center>Cross-Accounts</td></tr>
91 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
92 <td>$options</td></tr>
93 <tr><td
class=
'dtl' align=
"right">Member: </td>
94 <td><input type=text name=
"Cn" size=10></td></tr>
95 <tr><td
class=
'dtl' align=
"right">Show Tabs as: </td>
96 <td><input type=text name=
"Showtab" size=10></td></tr>
97 <tr><td
class=
'dtl' align=
"right">Count Columns: </td>
98 <td><input type=checkbox name=
"validresp" value=
"OK"></td>
100 <tr><td colspan=2 align=
"center">
101 <input type=submit name=
"action" value=
"Retrieve" class=
'bar'></td></tr>
104 </td><td valign=top align=center width=*>
105 <form action=
"$PHP_SELF?action='post'">
106 <table cellpadding=2>
107 <tr><td
class=
'bar' colspan=2 align=center>Post a Packet</td></tr>
108 <tr><td
class=
'dtl' align=
"right">Fetcher: </td>
109 <td>$options</td></tr>
110 <tr><td
class=
'dtl' align=
"right">Member: </td>
111 <td><input type=text name=
"Cn" size=10></td></tr>
112 <tr><td
class=
'dtl' align=
"right">Transaction Code: </td>
113 <td><select name=
"Tc">
125 <tr><td
class=
'dtl' align=
"right">Ref 1 (From Sfx): </td>
126 <td><input type=text name=
"R1" size=10 value=1></td></tr>
127 <tr><td
class=
'dtl' align=
"right">Ref 2 (To Sfx): </td>
128 <td><input type=text name=
"R2" size=10 value=1></td></tr>
129 <tr><td class=
'dtl' align=
"right">Ref 3 (email): </td>
130 <td><input type=text name=
"R3" size=10 value=1></td></tr>
131 <tr><td class=
'dtl' align=
"right">Ref 4 (To misc): </td>
132 <td><input type=text name=
"R4" size=10 value=1></td></tr>
133 <tr><td class=
'dtl' align=
"right">Ref 5 (To Mem): </td>
134 <td><input type=text name=
"R5" size=10 value=1></td></tr>
135 <tr><td class=
'dtl' align=
"right">Amount: </td>
136 <td><input type=text name=
"Amt" size=10></td></tr>
137 <tr><td colspan=2 align=
"center">
138 <input type=submit name=
"action" value=
"Post" class=
'bar'></td></tr>
142 </tr></table></body></html>
148 list($Cu,$Fs, $histdays) = explode(
"|",
"$Fs",3);
149 if (empty($cutoff)) { $cutoff =
'$thirty'; }
150 if (empty($histdays)) { $histdays = 0; }
151 print
"<html><head><title>Packet Fetch</title></head><body bgcolor=#FFFFFF> 152 Fetching packet using parameters<ul> 153 <li>Credit Union: $Cu</li> 155 <li>Password: $Pass</li> 156 <li>Show Tabs: $Showtab</li> 157 <li>Fetched from: $Fs</li> 159 <li>Wait between calls: $Clw</li> 160 <li>Last Packet Stamp: $pktstamp</li> 161 <li>Requested Cutoff: $cutoff</li> 163 if ($validresp ==
"OK") {
164 valid_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $cutoff, $histdays);
166 fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $cutoff, $histdays);
173 list($Cu,$Fs, $histdays) = explode(
"|",
"$Fs",3);
174 print
"<html><head><title>Cross-Account Retrieve</title></head><body bgcolor=#FFFFFF> 175 Retrieving Cross-Account Authorizations using parameters<ul> 176 <li>Credit Union: $Cu</li> 178 <li>Show Tabs: $Showtab</li> 179 <li>Fetched from: $Fs</li> 181 if ($validresp ==
"OK") {
182 valid_xac($Fs, $Cu, $Cn, $Showtab);
184 fetch_xac($Fs, $Cu, $Cn, $Showtab);
191 list($Cu,$Fs,$histdays) = explode(
"|",
"$Fs",3);
192 $R2 = (trim($R2) ==
"" ?
"NULL" : $R2);
193 $R3 = (trim($R3) ==
"" ?
"NULL" : $R3);
194 $R4 = (trim($R4) ==
"" ?
"NULL" : $R4);
195 $R5 = (trim($R5) ==
"" ?
"NULL" : $R5);
196 print
"<html><head><title>Packet Post</title></head><body bgcolor=#FFFFFF> 197 Posting packet using parameters<ul> 198 <li>Credit Union: $Cu</li> 200 <li>Posted to: $Fs</li> 201 <li>Txn Code: $Tc</li> 207 <li>Amount: $Amt</li> 208 <li>URL: $Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt</li> 210 post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt);
216 function fetch_packet($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $cutoff, $histdays) {
218 if (
"$pktstamp"==
"") {
219 # read last pktstamp from database. Calculate new threshold as 220 # now - pktinterval; if pktstamp > threshold, return (use existing) 222 $sql =
"select pktstamp, pktdate, livewait 223 from cuusers u, cuadmin a 225 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
226 $sth = db_query($sql,$dbh);
227 list($pktstamp, $pktdate,$Clw) = db_fetch_array($sth,0);
228 db_free_result($sth);
231 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
232 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
233 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
235 $threshold = mktime() - $Clw;
236 $fs = date(
"D M j Y H:i:s T",$pktstamp);
237 $ft = date(
"D M j Y H:i:s T",$threshold);
238 if ($pktstamp > $threshold) {
239 print
"Too soon to ask again<br> 241 Threshold: $ft<br></body></html>";
244 # if the last packet was fairly recent only fetch 7 days 245 # "recent" defined as 3 times the packet timeout setting 246 $threshold = mktime() - (3 * $Clw);
247 if (empty($cutoff)) { $cutoff =
'$thirty'; }
248 if (empty($histdays)) { $histdays = 0; }
249 # 1072940400 is the timestamp for 20040101 250 if ($pktstamp >1072940400 && $histdays > 0 && $cutoff == $thirty) {
251 # calculate cutoff as pktstamp - interval($histdays days) 252 if ($pktstamp > $threshold) {
253 # last packet age is less than 3 times the packet timeout setting 254 # set cutoff for 7 days 255 $cutoff = date(
"Ymd",mktime()-604800);
257 $cutoff = date(
"Ymd",$pktstamp-(86400 * $histdays));
260 $URL=
"?member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
264 $fd = @fopen (
"$Fs$URL",
"r");
267 while ($buff = fread ($fd, 1500)) {
271 # add feature here to log (and optionally truncate first) packet to a temp file 273 # $packet = preg_replace("/ ?\t ?/","\t",$packet); 274 if (
"$Showtab" !=
"") { $packet = preg_replace(
"/\t/",
"$Showtab",$packet);}
275 $packet = HTMLSpecialChars($packet);
276 print
"<br>URL: $URL<br><pre>$packet</pre></body></html>";
278 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
284 function fetch_xac($Fs, $Cu, $Cn, $Showtab) {
286 $URL=
"?member=$Cn&type=X";
288 $fd = @fopen (
"$Fs$URL",
"r");
291 while ($buff = fread ($fd, 1500)) {
295 # add feature here to log (and optionally truncate first) packet to a temp file 298 if (
"$Showtab" !=
"") { $packet = preg_replace(
"/\t/",
"$Showtab",$packet);}
299 $packet = HTMLSpecialChars($packet);
300 print
"<br>URL: $URL<br><pre>$packet</pre></body></html>";
302 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
306 function post_packet($Fs, $Cn, $Tc, $R1, $R2, $R3, $R4, $R5, $Amt) {
309 $URL =
"?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt";
310 $fd = @fopen (
"$Fs$URL",
"r");
313 while ($buff = fread ($fd, 1500)) {
317 $packet = HTMLSpecialChars($packet);
318 print
"<pre>$packet</pre></body></html>";
321 print
"Couldn't get a packet!<br>$php_errormsg<br>";
322 print
"URL=$Fs?member=$Cn&type=T&tran_code=$Tc&ref1=$R1&ref2=$R2&ref3=$R3&ref4=$R4&ref5=$R5&amount=$Amt<br>";
326 function showquoted(&$val) {
327 if (is_array($val)) {
328 array_walk($val,
'showquoted');
331 $val = htmlentities($val);
334 function valid_packet ($Fs, $Cu, $Cn, $Clw, $pktstamp, $Showtab, $Pass, $cutoff, $histdays) {
337 if (
"$pktstamp"==
"") {
338 # read last pktstamp from database. Calculate new threshold as 339 # now - pktinterval; if pktstamp > threshold, return (use existing) 341 $sql =
"select pktstamp, pktdate, livewait 342 from cuusers u, cuadmin a 344 and a.cu = '" . $Cu .
"' and u.user_name = '" . $Cn .
"'";
345 $sth = db_query($sql,$dbh);
346 list($pktstamp, $pktdate,$Clw) = db_fetch_array($sth,0);
347 db_free_result($sth);
350 $pktstamp = (empty($pktstamp) ? 1 : $pktstamp);
351 $pktdate = (empty($pktdate) ? date(
"D M j Y H:i:s T") : $pktdate);
352 $Clw = (($Clw == 0 || is_null($Clw)) ? 300 : $Clw);
354 $threshold = mktime() - $Clw;
356 $fs = date(
"D M j Y H:i:s T",$pktstamp);
357 $ft = date(
"D M j Y H:i:s T",$threshold);
358 if ($pktstamp > $threshold) {
359 print
"Too soon to ask again<br> 361 Threshold: $ft<br></body></html>";
363 # if the last packet was fairly recent only fetch 7 days 364 # "recent" defined as 3 times the packet timeout setting 365 $threshold = mktime() - (3 * $Clw);
366 if (empty($cutoff)) { $cutoff =
'$thirty'; }
367 if (empty($histdays)) { $histdays = 0; }
368 # 1072940400 is the timestamp for 20040101 369 if ($pktstamp >1072940400 && $histdays > 0 && $cutoff == $thirty) {
370 # calculate cutoff as pktstamp - interval($histdays days) 371 if ($pktstamp > $threshold) {
372 # last packet age is less than 3 times the packet timeout setting 373 # set cutoff for 7 days 374 $cutoff = date(
"Ymd",mktime()-604800);
376 $cutoff = date(
"Ymd",$pktstamp-(86400 * $histdays));
379 $URL=
"?member=$Cn&type=I&if_mod_since=$pktstamp&cutoff=$cutoff";
383 $fd = @fopen (
"$Fs$URL",
"r");
386 while ($buff = fread ($fd, 1500)) {
390 $pktpattern=
'/<([^<>\/]*)?>\n?([^<]*)?/';
391 $pktpieces = array();
392 $pktpattern=
'/<([^<>\/]*)>(.*)<\/\\1>/Us';
393 $inqpattern=
'/<\/*Inquiry>/i';
394 # ugly hack, but appears to work. Strip <Inquiry></Inquiry> to remove nesting 395 preg_match_all(
"$pktpattern",preg_replace($inqpattern,
"",$packet),$pktpieces);
397 array_shift($pktpieces);
398 foreach ($pktpieces[0] as $pos => $tag) {
399 $tags[(strtolower($tag))] = $pos;
401 array_shift($pktpieces);
402 list($mem, $pcutoff) = explode(
"\t",$pktpieces[0][($tags[
'parameters'])]);
403 # if the packet presents a cutoff date, let it override our request 404 $cutoff = (
"$pcutoff" ==
"" ? $cutoff : $pcutoff);
405 list($mem, $statcode, $statdesc) = explode(
"\t",$pktpieces[0][($tags[
'status'])]);
406 list($pktstamp, $pktdate) = explode (
"\t",$pktpieces[0][($tags[
'time'])]);
407 print
"<br>URL: $URL<br>";
410 Description: $statdesc<br> 411 Cutoff: (requested) $cutoff (returned) $pcutoff<br>";
412 if (trim($mem) != $Cn) {
414 $statdesc =
"Returned packet doesn't match request!";
417 # check the return status to decide what to do here 419 # 101 New Data -- process packet, update pktstamp 420 # 201 System Unavailable, New Data -- process packet, update pktstamp 421 # 100 No New Data -- update pktstamp 422 # 200 System Unavailable, No New Data -- return immediately 423 # 202 System Unavailable, No Data -- return immediately 424 # 999 Calling error or Invalid Parms -- return immediately 427 foreach ($tags as $tag => $pos) {
430 case "accountbalance":
432 case "accounthistory":
436 $$tag = explode (
"\n",$pktpieces[0][$pos]);
438 # newlines around data on multiline components 439 # causes empty items in array. 440 # Pop the empty off the end 441 # new regex leaves newline at top as well, 442 # so shift it off also 453 $expected{
'accountbalance'}=10;
454 $expected{
'accounthistory'}=10;
455 $expected{
'loanbalance'}=14;
456 $expected{
'loanhistory'}=9;
457 $expected{
'messages'}=4;
458 $expected{
'holds'}=9;
461 foreach(array(
"accountbalance",
"loanbalance",
462 "accounthistory",
"loanhistory",
"messages",
"holds") as $tbl ){
464 # print "<font color='blue'>Counting " . sizeof($$tbl) . " records for $tbl...</font><br>\n"; 470 foreach ($$tbl as $line) {
471 $line = preg_replace(
"/ ?\t ?/",
"\t",$line);
472 $line = preg_replace(
"/ $/",
"",$line);
473 $line = preg_replace(
"/\\0/",
"",$line);
474 $count=(count(explode(
"\t",$line)));
475 $mincnt=(($count < $mincnt || $mincnt==0) ? $count : $mincnt);
476 $maxcnt=($count > $maxcnt ? $count : $maxcnt);
477 if (
"$Showtab" !=
"") {
478 $line = preg_replace(
"/\t/",
"$Showtab",$line);
480 $line = HTMLSpecialChars($line);
484 print
"<font color='blue'>Counted " .
sizeof($$tbl) .
" records for $tbl... (Expected: " . $expected{$tbl} .
")</font> Min: $mincnt Max: $maxcnt<br><br>\n";
488 print
"Status: $statcode Date: $pktdate Description: $statdesc<br>\n";
491 print
"Couldn't get a packet!<br>$php_errormsg</body></html>";
496 function valid_xac ($Fs, $Cu, $Cn, $Showtab) {
498 $URL=
"?member=$Cn&type=X&f=xxx";
499 $fd = @fopen (
"$Fs$URL",
"r");
502 while ($buff = fread ($fd, 1500)) {
507 $pktpieces = array();
509 $status = (preg_match(
"/<status>\n?(.*)<\/status>/s",$packet,$pktpieces) ? $pktpieces[1] :
"");
510 list($mem, $statcode, $statdesc) = explode(
"\t",$status);
511 if (trim($mem) != $Cn) {
512 return array(999, 1,
"Unable to retrieve a packet");
515 # check the return status to decide what to do here 517 # 101 New Data -- process packet, update pktstamp 518 # 200 System Unavailable, No New Data -- return immediately 519 # 001 Invalid Account Number -- return immediately 520 # 999 Calling error or Invalid Parms -- return immediately 525 # make an array from the stuff in the packet 527 preg_match(
"/<txaccount>\n?(.*)<\/txaccount>/si",$packet,$pktpieces);
528 $txaccount = explode (
"\n",$pktpieces[1]);
529 array_pop($txaccount);
535 foreach ($txaccount as $line) {
536 $count=(count(explode(
"\t",$line)));
537 $mincnt=(($count < $mincnt || $mincnt==0) ? $count : $mincnt);
538 $maxcnt=($count > $maxcnt ? $count : $maxcnt);
539 if (
"$Showtab" !=
"") {
540 $line = preg_replace(
"/\t/",
"$Showtab",$line);
542 $line = HTMLSpecialChars($line);
547 print
"<font color='blue'>Counted " .
sizeof($txaccount) .
" Cross-Account records...(Expected: 6)</font> Min: $mincnt Max: $maxcnt<br><br>\n";
549 return array(
"$statcode",
"$u",
"$statdesc");
552 return array(999,1,$php_errormsg);