29 function HCU_JsonDecode($pJsonString, $pBolOnEmptyArray=
true, $pBolAssoc=
true) {
30 $dataReturn = ($pBolOnEmptyArray ? Array() :
'');
33 if (is_string($pJsonString)) {
34 $pJsonString = trim($pJsonString);
35 $dataReturn = json_decode($pJsonString, $pBolAssoc);
36 switch (json_last_error()) {
40 case JSON_ERROR_DEPTH:
41 case JSON_ERROR_STATE_MISMATCH:
42 case JSON_ERROR_CTRL_CHAR:
43 case JSON_ERROR_SYNTAX:
46 throw new exception(
'Json decode error');
50 throw new Exception(
'Invalid Data Type');
52 }
catch (Throwable $t){
54 $dataReturn = ($pBolOnEmptyArray ? ($pBolAssoc ? Array() : (object) Array()) :
'');
55 }
catch (Exception $e) {
57 $dataReturn = ($pBolOnEmptyArray ? ($pBolAssoc ? Array() : (object) Array()) :
'');
73 function HCU_JsonEncode($pJsonArray) {
79 $dataReturn = json_encode($pJsonArray);
80 switch (json_last_error()) {
84 case JSON_ERROR_DEPTH:
85 case JSON_ERROR_STATE_MISMATCH:
86 case JSON_ERROR_CTRL_CHAR:
87 case JSON_ERROR_SYNTAX:
94 }
catch (Throwable $t){
97 }
catch (Exception $e) {
122 function HCU_MFADecode($pJsonAry) {
123 $retMfaArray = Array(
125 "answers" => Array(),
132 $mfaQuestKey =
'answers';
133 $mfaChallengeKey =
'challenge';
138 if (HCU_array_key_exists($mfaQuestKey, $pJsonAry)) {
140 if (is_array($pJsonAry[$mfaQuestKey])) {
141 $retMfaArray[
'mfacount'] = count($pJsonAry[$mfaQuestKey]);
142 $retMfaArray[
'answers'] = $pJsonAry[$mfaQuestKey];
145 if (HCU_array_key_exists($mfaChallengeKey, $pJsonAry)) {
147 $retMfaArray[
'challenge'] = intval($pJsonAry[$mfaChallengeKey]);
149 if (HCU_array_key_exists(
"authcode", $pJsonAry)) {
151 $retMfaArray[
'authcode'] = $pJsonAry[
"authcode"];
153 if (HCU_array_key_exists(
"authexpires", $pJsonAry)) {
155 $retMfaArray[
'authexpires'] = intval($pJsonAry[
"authexpires"]);
157 if (HCU_array_key_exists(
"mfadate", $pJsonAry)) {
159 $retMfaArray[
'mfadate'] = intval($pJsonAry[
"mfadate"]);
161 }
catch (Exception $e) {
163 $retMfaArray = Array(
165 "answers" => Array(),
186 function PrepareMfaQuestString($pMfaQuestAry) {
188 $allowedKeys = Array(
"answers",
"challenge",
"authcode",
"authexpires",
"mfadate");
192 return json_encode(array_intersect_key($pMfaQuestAry, array_flip($allowedKeys)));
211 function HCU_array_key_exists($pNeedleKey, $pAryHaystack) {
214 if (is_array($pAryHaystack)) {
215 $retVal = array_key_exists($pNeedleKey, $pAryHaystack);
235 function HCU_array_key_value($pNeedleKey, $pAryHaystack) {
238 if (HCU_array_key_exists($pNeedleKey, $pAryHaystack)) {
240 return $pAryHaystack[$pNeedleKey];
259 function HCU_array_item_count($pNeedleKey, $pAryHaystack) {
261 if (HCU_array_key_value($pNeedleKey, $pAryHaystack)) {
262 return count($pAryHaystack[$pNeedleKey]);
295 function HCU_setcookie_env( $pEnvSet, $pCookieName, $pCookieValue=
'', $pExpire=0) {
298 if (HCU_array_key_exists(
'ticket', $pEnvSet)) {
299 $domain = HCU_array_key_value(
'domain', $pEnvSet[
'ticket']);
300 $secure = HCU_array_key_value(
'require_encryption', $pEnvSet);
305 $retBaked = HCU_setcookie(HCU_array_key_value(
'logger', $pEnvSet), $pCookieName, $pCookieValue, $pExpire, $path, $domain, $secure);
322 function HCU_setcookie($logger, $name, $value=
"", $expire=0, $path=
"", $domain=
"", $secure=1, $httponly=
false) {
329 if ($secure && !HCU_http_encrypted()) {
330 $logger->error(
"Setting cookie {$name}={$value} expire={$expire} path={$path} domain={$domain}");
335 $ret = setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
337 $logger->error(
"Failed to set cookie: {$name}");
346 function getOpenSSLKey($key_suffix, $bit_size=
'256') {
350 if ($bit_size !=
'256')
351 throw new exception(
"Invalid key size. Supported: [256] bits.", 3);
353 $hashKeyBilbo = GetOpenSSLKeyBilbo() . $key_suffix;
354 $hashKeyBugs = GetOpenSSLKeyBugs() . $key_suffix;
357 $defaultKey = hash_hmac(
'sha256', $hashKeyBilbo, $hashKeyBugs, $raw_output);
372 function getEncryptionAuthHash($message, $key_suffix, $auth_hash_algo, $auth_hash_binary) {
373 if ($auth_hash_algo !=
'sha1' && $auth_hash_algo !=
'sha256') {
374 throw new exception(
"Invalid hash algorithm: ". $auth_hash_algo, 2);
376 $hashKeyBilbo = GetOpenSSLKeyBilbo() . $key_suffix;
377 return hash_hmac($auth_hash_algo, $message, $hashKeyBilbo, $auth_hash_binary);
434 function hcuOpenSSLEncrypt($message,
436 $method=
'aes-256-cbc',
437 $auth_hash_algo=
'sha1',
438 $auth_hash_binary=
true,
440 $context=
"default") {
443 if ($auth_hash_algo !=
'sha1' && $auth_hash_algo !=
'sha256') {
444 throw new exception(
"Invalid hash algorithm: ". $auth_hash_algo, 2);
451 $ivsize = openssl_cipher_iv_length($method);
453 $iv = openssl_random_pseudo_bytes($ivsize);
455 $iv = mb_substr($iv, 0, $ivsize,
'8bit');
462 if($context ==
"connect_chkfree" ||
463 $context ==
"connect_ezcard" ||
464 $context ==
"connect_certegy" ||
465 $context ==
"connect_digital" ||
466 $context ==
"connect_ipay" ||
467 $context ==
"connect_vsoft" ||
468 $context ==
"connect_mvi" ||
469 $context ==
"connect_smo") {
473 $openssl_options = OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING;
474 $encryptionKey = $key_suffix;
475 }
else if ($context ==
"credentials") {
477 $openssl_options = OPENSSL_RAW_DATA;
478 $encryptionKey = $key_suffix;
481 $openssl_options = OPENSSL_RAW_DATA;
482 $encryptionKey = getOpenSSLKey($key_suffix);
486 $ciphertext = openssl_encrypt($message,
494 $defaultCipher = $iv . $ciphertext;
495 $defaultHash = getEncryptionAuthHash($defaultCipher,
499 $defaultResp = array(
"message" => $defaultCipher,
"hash" => $defaultHash);
503 case "connect_chkfree":
504 case "connect_ezcard":
505 case "connect_certegy":
506 case "connect_digital":
508 case "connect_vsoft":
511 $connectCipher = $ciphertext;
512 $returnArray = array(
"message" => $connectCipher,
"iv" => $iv);
516 $credentialCipher = $ciphertext;
517 $returnArray = array(
"message" => $credentialCipher,
"iv" => $iv);
523 $returnArray= $defaultResp;
536 function EncryptPayloadData( $message, $key )
538 $method =
'aes-256-cbc';
540 $nonceSize = openssl_cipher_iv_length( $method );
541 $nonce = openssl_random_pseudo_bytes( $nonceSize );
543 $ciphertext = openssl_encrypt( $message, $method, $key, OPENSSL_RAW_DATA, $nonce );
545 $decrypttext = openssl_decrypt($ciphertext, $method, $key, OPENSSL_RAW_DATA, $nonce );
547 $returnString = base64_encode( $nonce ) .
"|" . base64_encode( $ciphertext );
549 return $returnString;
605 function hcuOpenSSLDecrypt($message,
608 $method=
'aes-256-cbc',
609 $auth_hash_algo=
"sha1",
610 $auth_hash_binary=
true,
612 $context=
"default") {
614 $hashKeyBilbo = GetOpenSSLKeyBilbo() . $key_suffix;
615 $ivsize = openssl_cipher_iv_length($method);
617 $iv = mb_substr($iv, 0, $ivsize,
'8bit');
624 $openssl_options = OPENSSL_RAW_DATA;
625 $encryptionKey = getOpenSSLKey($key_suffix);
626 $ciphertext = $message;
629 case "connect_chkfree":
630 case "connect_ezcard":
631 case "connect_certegy":
632 case "connect_digital":
634 case "connect_vsoft":
636 $openssl_options = OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING;
637 $encryptionKey = $key_suffix;
641 $encryptionKey = $key_suffix;
643 throw new exception(
"IV cannot be empty for Credentials.", 3);
650 $expectedHash = getEncryptionAuthHash($message,
654 if (md5($expectedHash) !== md5($hash))
655 throw new exception(
"Hash doesn't match!", 2);
658 $iv = mb_substr($message, 0, $ivsize,
'8bit');
659 $ciphertext = mb_substr($message, $ivsize,
null,
'8bit');
663 return openssl_decrypt($ciphertext,
679 function DecryptPayloadData( $encodedMessage, $key )
681 $method =
'aes-256-cbc';
684 $encodedMessage = str_replace(
" ",
"+", $encodedMessage );
686 $parts = explode(
"|", $encodedMessage );
688 $nonce = base64_decode( $parts[0] );
689 $encryptedMessage = base64_decode( $parts[1] );
692 $result = openssl_decrypt( $encryptedMessage, $method, $key, OPENSSL_RAW_DATA, $nonce );
693 }
catch (Exception $e) {
694 $result =
"Decryption failure";
704 function HCU_http_encrypted() {
705 return !!((!empty($_SERVER[
'HTTP_X_FORWARDED_PROTO']) &&
706 $_SERVER[
'HTTP_X_FORWARDED_PROTO'] ==
'https') ||
707 (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on'));
742 function FindMemberAccountsWoMIR($pDbh, $pCu, $pMemberAcct) {
744 $retAry = Array(
"code" =>
"000",
"errors" => Array(),
"data" => Array());
746 $admLibrary= dirname(__FILE__) .
"/../../admcom/library";
751 require_once (
"$admLibrary/MbrExHcuMIR.i");
754 $dms_ok = array(
'accountnumber' =>
'digits',
755 'firstname' =>
'string',
756 'middlename' =>
'string',
757 'lastname' =>
'string',
759 'homephone' =>
'string',
760 'workphone' =>
'string',
761 'cellphone' =>
'string',
764 'address1' =>
'string',
765 'address2' =>
'string',
775 $sql =
"SELECT user_id, trim(accountnumber) as accountnumber 776 FROM " . prep_save($pCu, 10) .
"useraccounts 777 WHERE accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 781 $sqlRs = db_query($sql, $pDbh);
783 throw new ErrorException(
"SQL failed ($sql).");
786 if (db_num_rows($sqlRs) > 0) {
789 $retAry[
'code'] =
"102";
791 $dRecord = db_fetch_assoc($sqlRs);
793 $retData[
'accounts'] = Array();
797 $sql =
"SELECT trim(accountnumber) as accountnumber, trim(accounttype) as accounttype, 798 certnumber, deposittype, trim(description) as description, may_deposit, may_withdraw 799 FROM " . prep_save($pCu, 10) .
"accountbalance 800 WHERE accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 801 ORDER BY accounttype; ";
802 $sqlRs = db_query($sql, $pDbh);
804 if (db_num_rows($sqlRs) > 0) {
806 while ($dRecord = db_fetch_assoc($sqlRs)) {
807 $acctList[] = $dRecord;
809 $retData[
'accounts'][
'deposit'] = $acctList;
814 $sql =
"SELECT trim(accountnumber) as accountnumber, trim(loannumber) as loannumber, 815 trim(description) as description, may_payment, may_addon 816 FROM " . prep_save($pCu, 10) .
"loanbalance 817 WHERE accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 818 ORDER BY loannumber; ";
819 $sqlRs = db_query($sql, $pDbh);
821 if (db_num_rows($sqlRs) > 0) {
823 while ($dRecord = db_fetch_assoc($sqlRs)) {
824 $acctList[] = $dRecord;
826 $retData[
'accounts'][
'loan'] = $acctList;
830 $retAry[
'code'] =
"001";
833 $retAry[
'data'] = $retData;
836 }
catch (ErrorException $err) {
837 $retAry[
'code'] =
'999';
838 $retAry[
'errors'] =
'An unexpected error occurred' . $err->getMessage();
896 function SpoofFindMemberAccounts($pDbh, $pCu, $pMemberAcct) {
898 $retAry = Array(
"code" =>
"000",
"errors" => Array(),
"data" => Array());
900 $admLibrary= dirname(__FILE__) .
"/../../admcom/library";
905 require_once (
"$admLibrary/MbrExHcuMIR.i");
908 $dms_ok = array(
'accountnumber' =>
'digits',
909 'firstname' =>
'string',
910 'middlename' =>
'string',
911 'lastname' =>
'string',
913 'homephone' =>
'string',
914 'workphone' =>
'string',
915 'cellphone' =>
'string',
918 'address1' =>
'string',
919 'address2' =>
'string',
929 $sql =
"SELECT user_id, trim(accountnumber) as accountnumber, parms 930 FROM " . prep_save($pCu, 10) .
"extkey 931 WHERE providermode = 'HcuMIR' 932 AND accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 936 $sqlRs = db_query($sql, $pDbh);
938 throw new ErrorException(
"SQL failed ($sql).");
941 if (db_num_rows($sqlRs) > 0) {
943 $retAry[
'code'] =
"101";
945 $dRecord = db_fetch_assoc($sqlRs);
948 $payload = $HcuMIRi->parms_parse($dRecord[
'parms']);
951 $payload[
"dob"] = date(
"m/d/Y", strtotime( $payload[
"dob"] ) );
953 $retData[
'mir'] = $payload;
954 $retData[
'accounts'] = Array();
958 $sql =
"SELECT trim(accountnumber) as accountnumber, trim(accounttype) as accounttype, 959 certnumber, deposittype, trim(description) as description, may_deposit, may_withdraw 960 FROM " . prep_save($pCu, 10) .
"accountbalance 961 WHERE accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 962 ORDER BY accounttype; ";
963 $sqlRs = db_query($sql, $pDbh);
965 if (db_num_rows($sqlRs) > 0) {
967 while ($dRecord = db_fetch_assoc($sqlRs)) {
968 $acctList[] = $dRecord;
970 $retData[
'accounts'][
'deposit'] = $acctList;
975 $sql =
"SELECT trim(accountnumber) as accountnumber, trim(loannumber) as loannumber, 976 trim(description) as description, may_payment, may_addon 977 FROM " . prep_save($pCu, 10) .
"loanbalance 978 WHERE accountnumber = '" . prep_save($pMemberAcct, 12) .
"' 979 ORDER BY loannumber; ";
980 $sqlRs = db_query($sql, $pDbh);
982 if (db_num_rows($sqlRs) > 0) {
984 while ($dRecord = db_fetch_assoc($sqlRs)) {
985 $acctList[] = $dRecord;
987 $retData[
'accounts'][
'loan'] = $acctList;
991 $retAry[
'code'] =
"001";
994 $retAry[
'data'] = $retData;
997 }
catch (ErrorException $err) {
998 $retAry[
'code'] =
'999';
999 $retAry[
'errors'] =
'An unexpected error occurred' . $err->getMessage();
1027 function HCU_PayloadEncode($pCu, $pMessage, $pJson =
false) {
1030 $eMessage = $pMessage;
1033 $eJson = html_entity_decode($eMessage, ENT_QUOTES);
1034 $eJson = trim($eMessage);
1036 if ($eJson ==
"") {
throw new Exception(
"Payload not found."); }
1037 $eMessage = HCU_JsonDecode($eJson);
1040 if (!is_array($eMessage)) {
throw new Exception(
"Payload not found."); }
1041 if (!count($eMessage)) {
throw new Exception(
"Payload not found."); }
1043 foreach ($eMessage as $key => $value) {
1044 $eEncode[$key] = $value;
1047 $eEncode = HCU_JsonEncode($eEncode);
1048 $eEncrypt = hcuOpenSSLEncrypt($eEncode, $pCu);
1049 $eGlue = GetPayloadGlue();
1051 $eReturn = $eEncrypt[
'message'] . $eGlue . $eEncrypt[
'hash'];
1052 $eReturn = base64_encode($eReturn);
1067 function HCU_PayloadDecode($pCu, $pMessage, $pJson =
false) {
1068 $dMessage = base64_decode($pMessage);
1069 $dEncode = explode(
"|*|*|*|", $dMessage);
1071 $dMessage = $dEncode[0];
1072 $dHash = $dEncode[1];
1074 $dDecrypt = hcuOpenSSLDecrypt($dMessage, $dHash, $pCu);
1075 $dReturn = $pJson ? $dDecrypt : HCU_JsonDecode($dDecrypt);
1091 function GetHculiveUrl($pHbEnv) {
1099 $cu = strtoupper(HCU_array_key_value(
"Cu", $pHbEnv));
1102 throw new ErrorException(
"CU Code Not Set");
1106 $dbh = HCU_array_key_value(
"dbh", $pHbEnv);
1108 if (db_connection_status($dbh) !== PGSQL_CONNECTION_OK) {
1110 throw new ErrorException(
"Bad Database Connection");
1115 $sql =
"SELECT cu, liveserver 1117 WHERE cu = '" . prep_save($cu, 10) .
"' ";
1118 $rs = db_query($sql, $dbh);
1121 $row = db_fetch_assoc($rs);
1124 $retVal = HCU_array_key_value(
"liveserver", $row);
1127 }
catch (ErrorException $err) {
1159 function GetTransferConfirmCode( $pEnv, $pWhich, $pTranInfo ) {
1166 $n1hex = dechex( $pTranInfo[
"id"] );
1167 $n1len = strlen( $n1hex );
1169 $n2hex = dechex( strtotime( $pTranInfo[
"posted_date"] ) );
1170 $n2len = strlen( $n2hex );
1172 $n3hex = dechex( $pTranInfo[
"posted_by"] );
1173 $n3len = strlen( $n3hex );
1175 $intermediateCode =
"P" . $n1len . $n1hex . $n2len . $n2hex . $n3len . $n3hex;
1180 $n1hex = dechex( $pTranInfo[
"id"] );
1181 $n1len = strlen( $n1hex );
1183 $n2hex = dechex( strtotime( $pTranInfo[
"approved_date"] ) );
1184 $n2len = strlen( $n2hex );
1186 $n3hex = dechex( $pTranInfo[
"approved_by"] );
1187 $n3len = strlen( $n3hex );
1189 $intermediateCode =
"A" . $n1len . $n1hex . $n2len . $n2hex . $n3len . $n3hex;
1194 $n1hex = dechex( $pTranInfo[
"id"] );
1195 $n1len = strlen( $n1hex );
1197 $n2hex = dechex( strtotime( $pTranInfo[
"processed_date"] ) );
1198 $n2len = dechex( strlen( $n2hex ) );
1201 if ( $pTranInfo[
"processed_by"] ==
"*immed*" ||
1202 $pTranInfo[
"processed_by"] ==
"*sched*" ) {
1204 $whoProcessed = dechex( $pTranInfo[
"posted_by"] );
1205 $leadingCode = ( $pTranInfo[
"processed_by"] ==
"*immed*" ) ?
"I" :
"S";
1208 $whoProcessed = $pTranInfo[
"processed_by"] ;
1212 $intermediateCode = $leadingCode . $n1len . $n1hex . $n2len . $n2hex . $whoProcessed;
1215 throw new Exception (
"Bad call to create confirmation code" );
1220 $upperCode = strtoupper( $intermediateCode );
1223 $aryConfirmId = str_split( $upperCode, 4 );
1224 $confirmId = implode(
"-", $aryConfirmId );
1226 }
catch(Exception $ex) {
1227 $logInfo = array(
"message" => $ex->getMessage(),
"code" => $ex->getCode() );
1228 $pEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
1269 function SendTransaction( $pHBEnv, $pOpCode, $pTxnValues ) {
1270 $retStatusAry = Array(
1271 "status" => Array(
"code"=>
'000',
"errors" => Array() ),
1275 $logger = $pHBEnv[
'SYSENV'][
'logger'];
1279 if ($pHBEnv[
'live']) {
1289 $pTxnValues[
'pkt-type'] = PACKET_REQUEST_TRN;
1291 case "MEMBERACTIVATE":
1292 $pTxnValues[
'pkt-type'] = PACKET_REQUEST_MA;
1294 case "ESTMTACTIVATE":
1295 $pTxnValues[
'pkt-type'] = PACKET_REQUEST_ES;
1298 $pTxnValues[
'pkt-type'] = PACKET_REQUEST_ES;
1302 throw new Exception (
"No Operation Selection");
1304 $reqResult = PostTransactionRequest($pHBEnv, $pTxnValues);
1305 if ($reqResult[
'code'] ==
'999') {
1306 throw new Exception (
"Unexpected Error");
1310 $retStatusAry[
'status'][
'code'] = HCU_array_key_value(
"code", $reqResult[
'data']);
1313 if ($retStatusAry[
'status'][
'code'] !=
'000') {
1314 $retStatusAry[
'status'][
'errors'][] = HCU_array_key_value(
"desc", $reqResult[
'data']);
1316 $retStatusAry[
'data'] = HCU_array_key_value(
"data", $reqResult);
1330 if (HCU_array_key_value(
'code', $retStatusAry[
'data']) ==
'000') {
1334 $userData = Array(
"accountnumbers" => Array(HCU_array_key_value(
"member", $pTxnValues)));
1336 if (HCU_array_key_value(
"member", $pTxnValues) != HCU_array_key_value(
"ref5", $pTxnValues)) {
1339 $userData[
'accountnumbers'][] = HCU_array_key_value(
"ref5", $pTxnValues);
1346 if (HCU_array_key_value(
"tauth", $pTxnValues) !=
'' && HCU_array_key_value(
"member", $pTxnValues) != HCU_array_key_value(
"tauth", $pTxnValues)) {
1347 $userData[
'accountnumbers'][] = HCU_array_key_value(
"tauth", $pTxnValues);
1350 $updResp = SetbackMemberStamps($pHBEnv, $pHBEnv[
'Uid'], $userData);
1354 case "MEMBERACTIVATE":
1375 }
catch (Exception $e) {
1377 $retStatusAry[
'status'][
'code'] =
'999';
1378 $retStatusAry[
'status'][
'errors'] =
'Unexpected Error';
1379 $retStatusAry[
'data'] = Array();
1383 return $retStatusAry;
1395 function ReverseTransferConfirmCode( $pEnv, $pCUCode, $pConfirmCode ) {
1398 $condensedCode = strtoupper( str_replace(
"-",
"", $pConfirmCode ) );
1401 $which = substr( $condensedCode, 0, 1 );
1404 $n1len = hexdec( substr( $condensedCode, $currOffset, 1 ) );
1407 throw new Exception (
"Bad value when reversing confirmation code" );
1411 $transId = hexdec( substr( $condensedCode, $currOffset, $n1len ) );
1413 $currOffset += $n1len;
1415 $n2len = hexdec( substr( $condensedCode, $currOffset, 1 ) );
1418 throw new Exception (
"Bad value when reversing confirmation code" );
1422 $txnStamp = hexdec( substr( $condensedCode, $currOffset, $n2len ) );
1423 $txnString = date(
"m/d/Y h:ia", $txnStamp );
1425 $currOffset += $n2len;
1426 $n3len = hexdec( substr( $condensedCode, $currOffset, 1 ) );
1429 throw new Exception (
"Bad value when reversing confirmation code" );
1443 $userId = hexdec( substr( $condensedCode, $currOffset, $n3len ) );
1446 throw new Exception (
"Bad user id when reversing confirmation code" );
1450 $sql =
"SELECT user_name 1451 FROM {$pEnv["Cu
"]}user 1452 WHERE user_id = $userId";
1453 $rs = db_query( $sql, $pEnv[
"dbh"] );
1454 list( $username ) = db_fetch_array( $rs );
1455 db_free_result( $rs );
1458 if ( $which ==
"P" ) {
1459 $operation =
"Posted";
1460 }
else if ( $which ==
"A" ) {
1461 $operation =
"Accepted";
1462 }
else if ( $which ==
"I" ) {
1463 $operation =
"Immediate Posted";
1464 }
else if ( $which ==
"S" ) {
1465 $operation =
"Scheduled Posted";
1471 $adminUsername = substr( $condensedCode, $currOffset, $n3len );
1473 $operation =
"Processed";
1475 $username = $adminUsername;
1478 throw new Exception (
"Bad call to reverse confirmation code" );
1482 $returnParts = array(
"operation" => $operation,
1483 "date" => $txnString,
1485 "name" => $username );
1487 }
catch(Exception $ex) {
1488 $returnParts =
false;
1491 return $returnParts;
1496 function GetCreditUnionTimezone( $pDbh, $pCu ) {
1498 $sql =
"select rtrim(tz) from cuadmin where cu= '$pCu'";
1499 $sth = db_query( $sql, $pDbh );
1500 if ( $sth ) { list($tz) = db_fetch_array( $sth, 0 ); }
1501 $tz = (
"$tz" ==
"" ?
"Mountain" : $tz);
1502 if (strpos(
"$tz",
"/") ===
false) { $tz =
"US/$tz"; }
1516 function GetDateFormatTimezone($pEpoch, $pFormat, $pTz) {
1520 throw new Exception (
"No Date to Format");
1525 $myDateTime = DateTime::createFromFormat($srcFormat, $pEpoch);
1527 $myDateTime->setTimezone(
new DateTimeZone($pTz));
1529 $formatted = $myDateTime->format($pFormat);
1530 }
catch (exception $e) {
1552 function HCU_AcctIdExplode($pAcctId) {
1553 $retAcctAry = Array(
"valid" =>
false,
"original" => $pAcctId,
"type" =>
"",
"acctnumber" =>
"",
"segment3" =>
"",
"segment4" =>
"");
1555 $acctIdType = substr($pAcctId, 0, 1);
1557 switch (strtoupper($acctIdType)) {
1560 if (substr_count($pAcctId,
"|") === 3) {
1561 list($retAcctAry[
'type'], $retAcctAry[
'acctnumber'], $retAcctAry[
'segment3'], $retAcctAry[
'segment4']) = explode(
"|", $pAcctId);
1562 $retAcctAry[
'valid'] =
true;
1571 if (substr_count($pAcctId,
"|") === 2) {
1572 list($retAcctAry[
'type'], $retAcctAry[
'acctnumber'], $retAcctAry[
'segment3']) = explode(
"|", $pAcctId);
1573 $retAcctAry[
'valid'] =
true;
1579 if (substr_count($pAcctId,
"|") === 2) {
1580 list($retAcctAry[
'type'], $retAcctAry[
'acctnumber'], $retAcctAry[
'segment3']) = explode(
"|", $pAcctId);
1581 $retAcctAry[
'valid'] =
true;
1604 function GetAwsCertFile($pCertSecretId, $pEncFileBaseDir, $pOutBaseDir) {
1606 $retCertFileLocation =
'';
1609 $getCertPy =
"/opt/odyssey/tools/bin/aws_get_certificate.py";
1614 $encFileLocation = $pEncFileBaseDir . $pCertSecretId;
1615 if (!is_readable($encFileLocation)) {
1616 throw new Exception(
"Encrypted file not found.");
1619 $expectedFileLocation = $pOutBaseDir . $pCertSecretId;
1628 if (is_readable($expectedFileLocation)) {
1629 return $expectedFileLocation;
1634 $certPyArgs =
" '" . escapeshellarg($encFileLocation) .
"' '" . escapeshellarg($pCertSecretId).
"'";
1637 $shellPyCmd =
"python3 " . escapeshellcmd($getCertPy) .
" " . $certPyArgs;
1639 $execResults = exec($shellPyCmd);
1642 if (is_readable($expectedFileLocation)) {
1644 $retCertFileLocation = $expectedFileLocation;
1647 }
catch (Exception $ex ) {
1650 $retCertFileLocation =
'';
1653 return $retCertFileLocation;
1674 function Load_HB_ENVc($dbh, $CU, $MEMBER, &$HB_ENV, $CFGFLAG = 0) {
1676 $username = trim($MEMBER);
1677 $live = $HB_ENV[
'live'];
1679 # on first (method MFA) login, MEMBER will have username 1680 # after that, (method SSO) MEMBER will have USERID 1682 # AuthMode=MFQ Multi-factor w/questions 1683 $qby =
"cuuser.user_name ilike '" . prep_save($MEMBER) .
"' ";
1689 $sqluser =
"SELECT cuuser.user_id as user_id, trim(cuuser.user_name) as user_name, 1690 trim(cuuser.passwd) as password, forcechange, forceremain, failedremain, 1691 pwchange, trim(email) as email, egenl_flag, trim(confidence) as confidence, 1692 cuuser.user_id as cuuser_id, 1693 cuuser.group_id as cuuser_group_id, lastlogin, failedlogin, msg_tx, 1694 userflags & {$GLOBALS['MEM_FORCE_RESET']}::int4 as mem_force_reset, userflags, 1695 histdays, gracelimit, trmemomaxlen, mfaquest, primary_account 1697 FROM {$CU}user as cuuser 1698 JOIN cuadmin on cuadmin.cu = '" . prep_save($CU) .
"' 1701 $mbr_sth = db_query($sqluser, $dbh);
1702 $HB_ENV[
'rowfound'] = db_num_rows($mbr_sth);
1703 if ($HB_ENV[
'rowfound']) {
1704 $drow = db_fetch_array($mbr_sth, 0);
1705 $HB_ENV[
'Cu'] = $CU;
1706 $HB_ENV[
'cu'] = $CU;
1707 $HB_ENV[
'chome'] = strtolower($CU);
1708 $HB_ENV[
'Cauth'] = trim($drow[
'user_id']);
1709 $HB_ENV[
'Uid'] = $drow[
'user_id'];
1710 $HB_ENV[
'Cn'] = $drow[
'user_name'];
1711 $HB_ENV[
'username'] = $drow[
'user_name'];
1712 $HB_ENV[
'user_name'] = $drow[
'user_name'];
1713 $HB_ENV[
'confidence'] = $drow[
'confidence'];
1715 $HB_ENV[
'Ml'] = $drow[
'email'];
1716 $HB_ENV[
'savemail'] = $drow[
'email'];
1717 $HB_ENV[
'egenl_flag'] = urlencode($drow[
'egenl_flag']);
1718 $HB_ENV[
'password'] = $drow[
'password'];
1719 $HB_ENV[
'userflags'] = $drow[
'userflags'];
1720 $HB_ENV[
'failedremain'] = $drow[
'failedremain'];
1721 $HB_ENV[
'Ffchg'] = $drow[
'forcechange'];
1722 $HB_ENV[
'Ffremain'] = $drow[
'forceremain'];
1723 $HB_ENV[
'dbforceremain'] = $drow[
'forceremain'];
1724 $HB_ENV[
'Ffreset'] = (is_null($drow[
'mem_force_reset']) ? 0 : $drow[
'mem_force_reset']);
1726 $HB_ENV[
'Fmsg_tx'] = (is_null($drow[
'msg_tx']) ? 0 : $drow[
'msg_tx']);
1727 $HB_ENV[
'cfgflag'] = $CFGFLAG; #
set cfgflag
if CFGFLAG
if passed
1728 $HB_ENV[
'Fverifyml'] = ($drow[
'msg_tx'] & 512);
1729 # mammoth data calls use Clw; odyssey switched to livewait so define both 1730 $HB_ENV[
'Clw'] = ((is_null($HB_ENV[
'livewait']) || $HB_ENV[
'livewait'] == 0) ? 300 : $HB_ENV[
'livewait']);
1731 $HB_ENV[
'lastupdate'] = (empty($drow[
'lastupdate']) ?
"Unknown" : urlencode(trim($drow[
'lastupdate'])));
1732 $HB_ENV[
'pwchange'] = (is_null($drow[
'pwchange']) ? date(
'Ymd') : $drow[
'pwchange']);
1734 $HB_ENV[
'HCUPOST'] = array(); #
set empty parameter array
1735 if ($HB_ENV[
'flagset2'] & $GLOBALS[
'CU2_ALIAS_REQ']) {
1745 $HB_ENV[
'alias'] = $alias; #
this shouldn
't be needed - oh but it is 1746 # alias is always allowed 1747 # required means must start with non-digit 1748 $HB_ENV['Fset
'] = $HB_ENV['flagset
']; 1749 $HB_ENV['Fset2
'] = $HB_ENV['flagset2
']; 1750 $HB_ENV['Fset3
'] = $HB_ENV['flagset3
']; 1752 // * Create the MFA Quest Array (or set empty if Legacy, which shouldn't happen in Odyssey...)
1753 $HB_ENV[
'MFA'] = ($HB_ENV[
'cver'] ==
'L' ? array() : HCU_MFADecode(HCU_JsonDecode($drow[
'mfaquest'])));
1754 $HB_ENV[
'mfaquest'] = $drow[
'mfaquest'];
1755 $HB_ENV[
'savecqid'] = $HB_ENV[
'MFA'][
'challenge'];
1756 $HB_ENV[
'chcount'] = $HB_ENV[
'MFA'][
'mfacount'];
1759 if ($HB_ENV[
'Ffchg'] ==
'Y') {
1760 $FORCEUPDATE += 1; #password
1762 if ($HB_ENV[
'Fverifyml'] == 512 || $HB_ENV[
'Ml'] ==
'') {
1763 $FORCEUPDATE += 2; # email
1766 if (intval($HB_ENV[
'flagset3'] & $GLOBALS[
'CU3_MFA_AUTHCODE']) == 0 &&
1767 ( $HB_ENV[
'Ffreset'] == 2 || $HB_ENV[
'chcount'] < $HB_ENV[
'cu_chgqst_count'] )) {
1768 $FORCEUPDATE += 4; #challenge questions
1771 if (($HB_ENV[
'flagset2'] & $GLOBALS[
'CU2_ALIAS_REQ']) && !Check_Member_UseAlias($HB_ENV[
'user_name'])) {
1775 if (intval($HB_ENV[
'flagset3'] & $GLOBALS[
'CU3_MFA_AUTHCODE']) > 0 && $HB_ENV[
'Ffreset'] == 2) {
1776 $FORCEUPDATE += 16; #phone numbers
1779 $HB_ENV[
'forceupdate'] = $FORCEUPDATE;
1780 $HB_ENV[
'allowupdate'] = 11; # password, email, and user_name update always allowed
1781 $HB_ENV[
'allowupdate'] += (intval($HB_ENV[
'flagset3'] & $GLOBALS[
'CU3_MFA_AUTHCODE']) == 0 ? 4 : 0); # can
't update Challenge Questions if SAC in use 1782 $HB_ENV['allowupdate
'] += (intval($HB_ENV['flagset3
'] & $GLOBALS['CU3_MFA_AUTHCODE
']) == 0 ? 0 : 16); # can only update contact phone if SAC in use 1784 $HB_ENV['requpdate
'] = 0; # assume at first this is not a 'getsettings
' request 1786 if ($HB_ENV['failedremain
'] <= 0 || 1787 ( ($HB_ENV['forceupdate
'] & 29) > 0 && $HB_ENV['Ffremain
'] <= 0 ) 1790 $HB_ENV['lockedacct
'] = 1; 1792 $HB_ENV['lockedacct
'] = 0; 1795 # eventually this will come from a new column in cuadmin 1797 $HB_ENV['AppTimeout
'] = intval($HB_ENV['SYSENV
']['ticket
']['expires
'] * .8); 1798 $lastlogin = (trim(HCU_array_key_value('lastlogin
', $drow)) == '' ? 'None
' : $drow['lastlogin
']); 1800 $HB_ENV['Fplog
'] = ($lastlogin == 'None
' ? '' : (strftime("%D %R", mktime( 1801 substr($lastlogin, 11, 2), substr($lastlogin, 14, 2), substr($lastlogin, 17, 2), substr($lastlogin, 5, 2), substr($lastlogin, 8, 2), substr($lastlogin, 0, 4))))); 1802 $failedlogin = (trim(HCU_array_key_value('failedlogin
', $drow)) == '' ? 'None
' : $drow['failedlogin
']); 1803 $HB_ENV['Fflog
'] = ($failedlogin == 'None
' ? '' : (strftime("%D %R", mktime( 1804 substr($failedlogin, 11, 2), substr($failedlogin, 14, 2), substr($failedlogin, 17, 2), substr($failedlogin, 5, 2), substr($failedlogin, 8, 2), substr($failedlogin, 0, 4))))); 1819 function hcuIsAppPhone($pHbEnv) {
1821 $platForm = HCU_array_key_value("platform", $pHbEnv);
1823 $appList = array("APP", "ADA");
1825 if (in_array($platForm, $appList)) {