Advertisement
johnburn

[fortumo.php] Decoded for: [email protected]

Jul 19th, 2011
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.47 KB | None | 0 0
  1. <?php
  2. class fortumo {
  3.     public function fortumo() {
  4.         global $db;
  5.         global $config_table_prefix;
  6.         $arr = fetchAssoc("select `processor_table`, `processor_ret_table` from " . TABLE_PAYMENT_PROCESSORS . " where `processor_code` like 'fortumo'");
  7.         $this->table = $config_table_prefix . $arr['processor_table'];
  8.         $this->ret_table = $config_table_prefix . $arr['processor_ret_table'];
  9.         $this->name = "fortumo";
  10.     }
  11.     public function gettable() {
  12.         global $db;
  13.         global $config_table_prefix;
  14.         $table = $config_table_prefix . fetchRow("select `processor_table` from " . TABLE_PAYMENT_PROCESSORS . " where `processor_code` like 'fortumo'");
  15.         return $table;
  16.     }
  17.     public function settable($table) {
  18.         $this->table = $table;
  19.     }
  20.     public function setamount($str) {
  21.         $amount = number_format($str, 2, ".", "");
  22.         $this->post['amount'] = $amount;
  23.         $this->amount = $amount;
  24.     }
  25.     public function init($key = "") {
  26.         global $config_live_site;
  27.         $this->pending = 0;
  28.         if ($key) {
  29.             $this->user_key = $key;
  30.         } else if (isset($_GET['ukey']) && $_GET['ukey']) {
  31.             $this->user_key = $_GET['ukey'];
  32.         } else if (isset($_GET['message']) && $_GET['message']) {
  33.             $this->user_key = getKey();
  34.         } else {
  35.             $this->user_key = randCode();
  36.         }
  37.         $this->postback_url = $config_live_site . "/payment_return/fortumo.php";
  38.         $this->pay_settings = getSettings();
  39.         setTest($this->pay_settings['test']);
  40.         $this->fortumo_keys = array("message", "sender", "country", "price", "currency", "service_id", "message_id", "keyword", "shortcode", "operator", "billing_type", "status", "test", "sig");
  41.     }
  42.     public function randcode() {
  43.         return random_string(6);
  44.     }
  45.     public function random_string($len = 5, $str = "") {
  46.         $i = 1;
  47.         while ($i <= $len) {
  48.             $ord = rand(49, 104);
  49.             if (49 <= $ord && $ord <= 57 || 97 <= $ord && $ord <= 104) {
  50.                 $str.= chr($ord);
  51.             } else {
  52.                 $str.= random_string(1);
  53.             }
  54.             ++$i;
  55.         }
  56.         return $str;
  57.     }
  58.     public function getkey() {
  59.         if (!$_GET['message'] || !$_GET['keyword']) {
  60.             return "";
  61.         }
  62.         $msg = urldecode($_GET['message']);
  63.         $keyword = urldecode($_GET['keyword']);
  64.         return trim(substr($msg, strlen($keyword)));
  65.     }
  66.     public function getuserkey() {
  67.         return $this->user_key;
  68.     }
  69.     public function getpost() {
  70.     }
  71.     public function setdebug($val) {
  72.         $this->debug = $val;
  73.     }
  74.     public function setformtitle($val) {
  75.         $this->formTitle = $val;
  76.     }
  77.     public function setinvoiceno($val) {
  78.         $this->invoice_no = $val;
  79.     }
  80.     public function settest($value) {
  81.         if ($value == 1) {
  82.             $this->test = "true";
  83.             return 1;
  84.         }
  85.         $this->test = "false";
  86.         return 1;
  87.     }
  88.     public function getsettings() {
  89.         global $db;
  90.         $result = fetchAssoc("select * from " . $this->table);
  91.         return $result;
  92.     }
  93.     public function getform() {
  94.         $form = "<form method=\"post\" name=\"payment_form\" id=\"payment_form\" action=\"/payment_return/fortumo.php?ukey=%s\">\n<input type=\"submit\" name=\"submit_payment\" value=\"%s\">\n</form>";
  95.         $str = sprintf($form, $this->user_key, $this->formTitle);
  96.         return $str;
  97.     }
  98.     public function info() {
  99.         $i = $this->info();
  100.         $str = getVal("fortumo_info");
  101.         $key = $this->pay_settings['keyword'] . " " . $this->user_key;
  102.         $str = str_replace("::KEY::", $key, $str);
  103.         $str = str_replace("::SHORT_CODE::", $this->pay_settings['short_code'], $str);
  104.         global $db;
  105.         $amount = fetchRow("select `amount` from " . TABLE_PAYMENT_ACTIONS . " where ukey='" . $this->user_key . "'");
  106.         $str = str_replace("::AMOUNT::", $amount, $str);
  107.         return $str;
  108.     }
  109.     public function process() {
  110.         $i = $this->info();
  111.         $failed_info = getVal("fortumo_failed");
  112.         $success_info = getVal("fortumo_success");
  113.         if (!in_array($_SERVER['REMOTE_ADDR'], array("81.20.151.38", "81.20.148.122", "209.20.83.207"))) {
  114.             log("validateData: ERROR: Invalid IP:" . $_SERVER['REMOTE_ADDR']);
  115.             echo $failed_info;
  116.             return 0;
  117.         }
  118.         $secret = $this->pay_settings['secret'];
  119.         if (!empty($secret) && !check_signature($_GET, $secret)) {
  120.             log("validateData: ERROR: Invalid signature!");
  121.             echo $failed_info;
  122.             return 0;
  123.         }
  124.         echo $success_info;
  125.         $success = 0;
  126.         $success = saveToDB();
  127.         if (!$success) {
  128.             log("saveToDB: ERROR: Cannot save to db!");
  129.         }
  130.         logIt($success);
  131.         return 1;
  132.     }
  133.     public function check_signature($params_array, $secret) {
  134.         ksort($params_array);
  135.         $str = "";
  136.         foreach($params_array as $k => $v) {
  137.             if ($k != "sig" && $k != "mode") {
  138.                 $str.= "{$k}={$v}";
  139.             }
  140.         }
  141.         $str.= $secret;
  142.         $signature = md5($str);
  143.         return $params_array['sig'] == $signature;
  144.     }
  145.     public function savetodb() {
  146.         global $db;
  147.         $addtosql = "";
  148.         $entirepost = "";
  149.         foreach($_GET as $key => $val) {
  150.             if (in_array($key, $this->fortumo_keys)) {
  151.                 $addtosql.= $key . "='" . $val . "',";
  152.             }
  153.             $entirepost.= "[" . $key . "]=\\'" . $val . "\\',";
  154.         }
  155.         $addtosql = rtrim($addtosql, ",");
  156.         $res_upd = query("update " . TABLE_PAYMENT_ACTIONS . " SET completed='1' where ukey='" . $this->user_key . "'");
  157.         $timestamp = date("Y-m-d H:i:s");
  158.         $res = query("INSERT INTO " . $this->ret_table . " SET date='{$timestamp}', entirepost='" . $entirepost . "', " . $addtosql . ",ukey='" . $this->user_key . "'");
  159.         return 1;
  160.     }
  161.     public function logit($success) {
  162.         if (!$this->debug) {
  163.         } else {
  164.             $content = "-----------------------------------\n" . date("r") . "\n";
  165.             $content.= "RECEIVED values:\n";
  166.             foreach($_GET as $key => $val) {
  167.                 $content.= escape($key) . "=" . escape($val) . "\n";
  168.             }
  169.             $content.= "-----------------------------------\n";
  170.             global $config_abs_path;
  171.             $file = $config_abs_path . "/log/fortumo_transaction";
  172.             if (!$success) {
  173.                 $file = $config_abs_path . "/log/fortumo_error";
  174.             }
  175.             $handle = fopen($file, "a");
  176.             fwrite($handle, $content);
  177.             fclose($handle);
  178.         }
  179.     }
  180.     public function log($msg) {
  181.         if (!$this->debug) {
  182.         } else {
  183.             $content = "-----------------------------------\n" . date("r") . "\n";
  184.             $content.= $msg . "\n";
  185.             $content.= "-----------------------------------\n";
  186.             global $config_abs_path;
  187.             $file = $config_abs_path . "/log/fortumo_debug";
  188.             $handle = fopen($file, "a");
  189.             fwrite($handle, $content);
  190.             fclose($handle);
  191.         }
  192.     }
  193.     public function geterror() {
  194.         return $this->error;
  195.     }
  196.     public function adderror($str) {
  197.         $this->error.= $str;
  198.     }
  199.     public function seterror($str) {
  200.         $this->error = $str;
  201.     }
  202.     public function gettmp() {
  203.         return $this->tmp;
  204.     }
  205.     public function check_form() {
  206.         global $lng;
  207.         $array_required = array("paypal_email", "paypal_currency");
  208.         foreach($array_required as $field) {
  209.             if (!isset($_POST[$field])) {
  210.                 addError($lng['settings']['errors']["required_" . $field] . "<br />");
  211.             }
  212.         }
  213.         if (getError() != "") {
  214.             if ($_POST['paypal_demo'] == "on") {
  215.                 $this->tmp['paypal_demo'] = 1;
  216.             } else {
  217.                 $this->tmp['paypal_demo'] = 0;
  218.             }
  219.             $array_fields = array("paypal_email", "paypal_currency", "paypal_pay_title");
  220.             foreach($array_fields as $field) {
  221.                 if (isset($_POST[$field])) {
  222.                     $this->tmp[$field] = clean($_POST[$field]);
  223.                 }
  224.             }
  225.         }
  226.     }
  227.     public function savesettings() {
  228.         global $lng;
  229.         $this->error = "";
  230.         $this->tmp = array();
  231.         $this->clean = array();
  232.         check_form();
  233.         if (getError() != "") {
  234.             return 0;
  235.         }
  236.         global $config_demo;
  237.         if ($config_demo == 1) {
  238.             addError($lng['general']['errors']['demo'] . "<br />");
  239.         }
  240.         global $db;
  241.         $this->clean['test'] = checkbox_value("test");
  242.         $sql = "update " . $this->table . " set test = " . $this->clean['test'];
  243.         $array_fields = array("keyword", "short_code", "secret", "currency");
  244.         foreach($array_fields as $field) {
  245.             if (isset($_POST[$field])) {
  246.                 $this->clean[$field] = escape($_POST[$field]);
  247.             } else {
  248.                 $this->clean[$field] = "";
  249.             }
  250.             $sql.= ", `{$field}` = '" . $this->clean[$field] . "'";
  251.         }
  252.         query($sql);
  253.         return 1;
  254.     }
  255.     public function correctsettings() {
  256.         return 1;
  257.     }
  258.     public function getpending() {
  259.         return $this->pending;
  260.     }
  261. }
  262. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement