function __genPseudoPasswd() { return _ml_strrev(md5(mt_rand(271, 3141) . time() . uniqid(mt_rand(314, 2718)))); }
function is_valid_credit_card_number($cc_number, $cc_type) { $cc_number = trim($cc_number); switch ($cc_type) { case "Visa": $valid = preg_match("/^4[0-9]{12}([0-9]{3})?\$/", $cc_number); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_002', 'error_code_short' => 'CCNUM_ERR_002'); } break; case "MasterCard": $valid = preg_match("/^5[1-5][0-9]{14}\$/", $cc_number); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_003', 'error_code_short' => 'CCNUM_ERR_003'); } break; case "Discover": $valid = preg_match("/^6011[0-9]{12}\$/", $cc_number); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_004', 'error_code_short' => 'CCNUM_ERR_004'); } break; case "Amex": $valid = preg_match("/^3[47][0-9]{13}\$/", $cc_number); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_005', 'error_code_short' => 'CCNUM_ERR_005'); } break; case "Maestro": $MaestroRules = array("490302,490309,18,1", "490335,490339,18,1", "491101,491102,16,1", "491174,491182,18,1", "493600,493699,19,1", "564182,564182,16,2", "633300,633300,16,0", "633301,633301,19,1", "633302,633349,16,0", "675900,675900,16,0", "675901,675901,19,1", "675902,675904,16,0", "675905,675905,19,1", "675906,675917,16,0", "675918,675918,19,1", "675919,675937,16,0", "675938,675940,18,1", "675941,675949,16,0", "675950,675962,19,1", "675963,675997,16,0", "675998,675998,19,1", "675999,675999,16,0"); $valid = $this->is_valid_debit_card_number($cc_number, $MaestroRules); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_007', 'error_code_short' => 'CCNUM_ERR_007'); } break; case "Solo": $SoloRules = array("633450,633453,16,0", "633454,633457,16,0", "633458,633460,16,0", "633461,633461,18,1", "633462,633472,16,0", "633473,633473,18,1", "633474,633475,16,0", "633476,633476,19,1", "633477,633477,16,0", "633478,633478,18,1", "633479,633480,16,0", "633481,633481,19,1", "633482,633489,16,0", "633490,633493,16,1", "633494,633494,18,1", "633495,633497,16,2", "633498,633498,19,1", "633499,633499,18,1", "676700,676700,16,0", "676701,676701,19,1", "676702,676702,16,0", "676703,676703,18,1", "676704,676704,16,0", "676705,676705,19,1", "676706,676707,16,2", "676708,676711,16,0", "676712,676715,16,0", "676716,676717,16,0", "676718,676718,19,1", "676719,676739,16,0", "676740,676740,18,1", "676741,676749,16,0", "676750,676762,19,1", "676763,676769,16,0", "676770,676770,19,1", "676771,676773,16,0", "676774,676774,18,1", "676775,676778,16,0", "676779,676779,18,1", "676780,676781,16,0", "676782,676782,18,1", "676783,676794,16,0", "676795,676795,18,1", "676796,676797,16,0", "676798,676798,19,1", "676799,676799,16,0"); $valid = $this->is_valid_debit_card_number($cc_number, $SoloRules); if (!$valid) { return array('error_code_full' => 'CCNUM_ERR_008', 'error_code_short' => 'CCNUM_ERR_008'); } break; default: $list = modApiFunc("Configuration", "getCreditCardSettings"); if (array_key_exists($cc_type, $list)) { // . // . return true; } else { return array('error_code_full' => 'CCTYPE_ERR_002', 'error_code_short' => 'CCTYPE_ERR_002'); } } $cc_number = _ml_strrev($cc_number); $numSum = 0; for ($i = 0; $i < _ml_strlen($cc_number); $i++) { $currentNum = _ml_substr($cc_number, $i, 1); // Double every second digit if ($i % 2 == 1) { $currentNum *= 2; } // Add digits of 2-digit numbers together if ($currentNum > 9) { $firstNum = $currentNum % 10; $secondNum = ($currentNum - $firstNum) / 10; $currentNum = $firstNum + $secondNum; } $numSum += $currentNum; } if (!($numSum % 10 == 0)) { return array('error_code_full' => 'CCNUM_ERR_006', 'error_code_short' => 'CCNUM_ERR_006'); } else { return true; } }
/** * Processes the SSL-request by `openssl-executable` * * @param $connection SSL-connection handler, which was opened by * `openssl-executable`. * * @return response from the remote server */ function openssl_process($connection) { $openssl_exec = $this->SSL_modules["openssl"]["exe_path"]; $exec_args = "-connect " . $this->host . ":" . $this->port; if ($this->ssl_cert != "") { $exec_args .= " -cert " . $this->ssl_cert; if ($this->ssl_key != "") { $exec_args .= " -key " . $this->ssl_key; } } $request = $this->prepareHTTPrequest(); $tmp_fname = _ml_strrev(md5(time() . uniqid(mt_rand(), true))); $ign_fp = $this->bouncer_dir . $tmp_fname; $req_fp = $this->bouncer_dir . _ml_strrev($tmp_fname); if (($th = @fopen($req_fp, "w")) == false) { $this->errno = 4; $this->errstr = "OpenSSL: Can't create temporary file"; } else { fwrite($th, $request); fclose($th); $cmd_line = $openssl_exec . " s_client " . $exec_args . " -quiet < " . $req_fp . " 2> " . $ign_fp; $fp = @popen($cmd_line, "r"); if ($fp == false) { $this->errno = 2; $this->errstr = "OpenSSL: can't execute application"; } else { stream_set_timeout($fp, $this->_timeout); $result = ""; while (!feof($fp)) { $result .= fread($fp, 65536); $fpi = stream_get_meta_data($fp); if ($fpi["timed_out"]) { $this->errno = 3; $this->errstr = "OpenSSL: response receiving timed out"; $result = ""; break; } } pclose($fp); @unlink($req_fp); @unlink($ign_fp); } } return $result; }