3 require_once dirname(__FILE__).
'/hcuCommon.i';
8 define(
"URL_ENCDEC_CIPHER_MODE",
"aes-256-ecb");
10 define(
"URL_ENCDEC_AUTH_HASH_ALGO",
"sha256");
15 function check_mcrypt_exists_cufunc() {
16 if (!function_exists(
"mdecrypt_generic") && !function_exists(
"mcrypt_generic"))
17 throw new exception(
"MCRYPT library does not exist.");
20 function hcu_encrypturl_mcrypt($str, $key) {
21 check_mcrypt_exists_cufunc();
22 $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
24 $key = substr($key . str_repeat(chr(0), $key_size), 0, $key_size);
25 $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
27 # implements PKCS7 padding 29 $pad = $blocksize - ($len % $blocksize);
30 $str .= str_repeat(chr($pad), $pad);
32 return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $str, MCRYPT_MODE_ECB));
35 function hcu_encrypturl($str, $key, $cipher_method=URL_ENCDEC_CIPHER_MODE) {
37 $enc_resp_url = hcuOpenSSLEncrypt($str,
39 $method=$cipher_method,
40 $auth_hash_algo=URL_ENCDEC_AUTH_HASH_ALGO);
41 $ciphertext = $enc_resp_url[
"message"];
42 $hash_hmac = $enc_resp_url[
"hash"];
43 return bin2hex($hash_hmac.$ciphertext);
46 }
catch (Exception $ex) {
52 function hcu_decrypturl_mcrypt($str, $key) {
53 check_mcrypt_exists_cufunc();
54 $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
55 $key = substr($key . str_repeat(chr(0), $key_size), 0, $key_size);
58 if (ctype_xdigit($str)) {
59 $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, pack(
"H*",$str), MCRYPT_MODE_ECB);
67 $slast = ord(substr($str, -1));
71 $str = substr($str, 0, -$slast);
76 function hcu_decrypturl_openssl($str, $key, $cipher_method) {
78 if (ctype_xdigit($str)) {
80 $cipher_all = hex2bin($str);
82 if(URL_ENCDEC_AUTH_HASH_ALGO ==
"sha256") {
90 $encrypted_hash = substr($cipher_all, 0, $auth_hash_len);
91 $ciphertext = substr($cipher_all, $auth_hash_len);
93 return hcuOpenSSLDecrypt($ciphertext,
96 $method=$cipher_method,
97 $auth_hash_algo=URL_ENCDEC_AUTH_HASH_ALGO);
101 }
catch (Exception $ex) {
106 function hcu_decrypturl($str, $key, $cipher_method=URL_ENCDEC_CIPHER_MODE) {
108 $openssl_result = hcu_decrypturl_openssl($str, $key, $cipher_method);
109 if ($openssl_result == False) {
110 $mcrypt_result = hcu_decrypturl_mcrypt($str, $key);
111 return $mcrypt_result;
113 return $openssl_result;
115 }
catch (Exception $ex) {
120 function hcu_checkOffline($dbh,$HB_ENV) {
121 # returns boolean - does status allow current script to continue? 123 $live=$HB_ENV[
'live'];
124 $offline=$HB_ENV[
'offline'];
125 $allowReadonly=$HB_ENV[
'allowReadonly'];
127 switch (
"$offline") {
128 case "Y": # yes, offline
129 case "U": # offline but
"up-able" 132 case "N": # no, not offline
136 if ($allowReadonly && !($live)) {
181 function hcu_checkService ($p_dbh, $pRequestedService) {
185 $homecuTrustCU =
'HOMECU';
186 $homecuTrustID =
'HOMECUSERVICE';
188 $trustParms = Array(
"Cu" => $homecuTrustCU,
"trustedid" => $homecuTrustID);
189 $trustItems = cutd_read($p_dbh, $trustParms);
191 if ($trustItems[
'status'][
'Response'] ==
'true') {
192 if ($trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"]) {
193 if (is_array($trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"])) {
194 $homecuServices = $trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"];
196 foreach ($homecuServices as $itemService => $itemValue) {
198 if (strtoupper($pRequestedService) == strtoupper($itemService)) {
202 $bolRet = ($itemValue ==
'N' ? true :
false);
212 function hcu_checkServiceMsg ($p_dbh, $pRequestedService) {
215 $homecuTrustCU =
'HOMECU';
216 $homecuTrustID =
'HOMECUSERVICE';
218 $trustParms = Array(
"Cu" => $homecuTrustCU,
"trustedid" => $homecuTrustID);
219 $trustItems = cutd_read($p_dbh, $trustParms);
220 if ($trustItems[
'status'][
'Response'] ==
'true') {
221 if ($trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"]) {
222 if (is_array($trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"])) {
223 $homecuServices = $trustItems[
'data'][
"{$homecuTrustCU}|{$homecuTrustID}"];
224 $pRequestedService=strtoupper($pRequestedService);
225 $strMsg = $homecuServices[
"{$pRequestedService}_MSG"];
229 $strMsg = (trim($strMsg) ==
'' ?
"Service temporarily unavailable. Please try again later" : $strMsg);
232 function getcurl($cmd){
234 $fd=popen(
"$cmd",
"r");
237 $data = @fread($fd, 8192);
238 if (strlen($data) == 0) {
252 function ConvertFromUTF8( $stringIn ) {
255 $len = strlen( $stringIn );
256 for( $i = 0; $i < $len; $i++ ) {
257 $c = ord( $stringIn[$i] );
259 if ( $c >= 223 )
return $stringIn;
260 elseif ( $c >= 192 ) {
262 if ( ( $i + $bytes ) > $len )
return $stringIn;
267 $secondByte = ord( $stringIn[$i] );
270 $firstByteMasked = $firstByte & 0x1F;
273 $secondByteMasked = $secondByte & 0x3F;
276 $lowTwo = $firstByteMasked & 0x03;
277 $lowTwo = $lowTwo << 6;
278 $newSecond = $secondByteMasked | $lowTwo;
281 $newFirst = $firstByteMasked >> 2;
284 $final = $newFirst * 256 + ($newSecond >> 4) * 16 + ($newSecond & 0x0F);
285 $encodedBytes = sprintf(
"&#%d;", $final );
287 $stringOut .= $encodedBytes;
290 $stringOut .= chr( $c );
308 function returnBaseDirectory($pUrl){
310 $public_directory = dirname($pUrl);
312 $directory_array = explode(
'/', $public_directory);
317 $public_base = ($directory_array[0] !=
'' ? $directory_array[0] : $directory_array[1]);
325 function convertMicrosoftCharacters( $inputStr ) {
326 $search = array(chr(145),
337 $replace = array(
"'",
348 return str_replace($search, $replace, $inputStr);