Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: iosAPI.class.php
<?php /** * 2020-02-11 */ if ( version_compare('5.1.0', PHP_VERSION) >= 0 ) { die(sprintf('PHP %s required instead of %s', '5.1.0', PHP_VERSION)); } class iosAPI { const TRANSPORT_ASIS = 0; const TRANSPORT_XML = 1; const TRANSPORT_JSON = 2; const TRANSPORT_INI = 3; const LF = "\r\n"; public $Trace = false; public $Debug = 0; public $ip; private $Version = 1; private $Protocol = self::TRANSPORT_XML; private $URL; private $user; private $pass; private $ce; public function __construct() { } public function setParams($URL, $user, $pass, $Debug = 0) { // $URL = 'https://user.infinity-box.com/'; // $user = 'gsmsalman'; // $pass = 'E2In8hE5e*UI5h1dwE'; // $Debug = 0; if ( strlen($URL) == 0 ) { throw new Exception('Wrong URL'); } if ( strlen($user) == 0 ) { throw new Exception('Wrong Username'); } if ( strlen($pass) == 0 ) { throw new Exception('Wrong Password'); } $this->URL = $URL; $this->user = $user; $this->pass = $this->PreparePassword($pass); $this->Debug = $Debug; $this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $this->ce = new Cryptography($this->user, $this->pass); } public function VersionApi() { $p['Operation'] = 'VersionApi'; return $this->SendRequest($p); } public function ProductList($p = array()) { $p['Operation'] = 'ProductList'; return $this->SendRequest($p); } public function Order($p) { $p['CheckIsOrderExist'] = 0; $p['Operation'] = 'Order'; return $this->SendRequest($p); } public function OrderAdd($p) { return $this->Order($p); } /* // replaced with order_get() public function OrderCheck($p) { $p['Operation'] = 'OrderCheck'; return $this->SendRequest($p); } */ public function order_get($p) { $p['Operation'] = 'order_get'; return $this->SendRequest($p); } public function UserExist($User) { $p['User'] = $User; $p['Operation'] = 'UserExist'; return $this->SendRequest($p); } public function Balance() { $p['Operation'] = 'Balance'; return $this->SendRequest($p); } public function CreditMoveTo($Receiver, $Quantity, $NoteForSender = '', $NoteForReceiver = '') { $p['Operation'] = 'CreditMoveTo'; $p['Receiver'] = $Receiver; $p['Quantity'] = $Quantity; $p['NoteForSender'] = $NoteForSender; $p['NoteForReceiver'] = $NoteForReceiver; return $this->SendRequest($p); } public function SL3JobAdd($Imei, $Hash) { $p['Operation'] = 'SL3JobAdd'; $p['IMEI'] = $Imei; $p['Hash'] = $Hash; return $this->SendRequest($p); } public function SL3JobCheck($Imei) { $p['Operation'] = 'SL3JobCheck'; $p['IMEI'] = $Imei; return $this->SendRequest($p); } private static function ReqestPOST($URL, $Request = array()) { $r = ''; $Request = http_build_query($Request); $context_options = array ( 'http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($Request) . "\r\n", 'content' => $Request ) ); $c = stream_context_create($context_options); $fp = @fopen($URL, 'r', false, $c); if ( $fp !== false ) { $r = stream_get_contents($fp); fclose($fp); } else { $r = error_get_last(); } return $r; } public function SendRequest($p = array()) { if ( isset($p['Protocol']) ) { $this->Protocol = $p['Protocol']; } if ( isset($p['Transport']) ) { $this->Protocol = $p['Transport']; } // inner parameters $Request = $p; $Request['Debug'] = $this->Debug; $Request['Rnd'] = rand(); $Request['Challenge'] = $Request['Rnd']; $Request['ApiVersion'] = $this->Version; $Request['Login'] = $this->user; $Request = $this->PreparePostData($Request); //d($Request); if ( !extension_loaded('curl') ) { $r = self::ReqestPOST($this->URL, $Request); if ( is_array($r) ) { $r = array('Error' => 255, 'Message' => isset($r['message']) ? $r['message'] : ''); } else { $r = $this->DecryptResponse($r); } return $r; } $h = curl_init(); curl_setopt($h, CURLOPT_HEADER, false); curl_setopt($h, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($h, CURLOPT_FOLLOWLOCATION, true); curl_setopt($h, CURLOPT_RETURNTRANSFER, true); curl_setopt($h, CURLOPT_URL, $this->URL); curl_setopt($h, CURLOPT_POST, true); curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($h, CURLOPT_SSL_VERIFYHOST, false); //curl_setopt($h, CURLOPT_COOKIEJAR, 'cookie.txt'); //curl_setopt($h, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt($h, CURLOPT_POST, true); curl_setopt($h, CURLOPT_POSTFIELDS, $Request); $r = curl_exec($h); $Error = curl_error($h); curl_close($h); $this->Log($r); if ( strlen($Error) > 0 ) { $r = array('Error' => 255, 'Message' => $Error); } else { $r = $this->DecryptResponse($r); } return $r; } private function Log($Msg) { if ( !$this->Trace ) { return; } @file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'iosAPI.log', print_r($Msg, true), FILE_APPEND); } private function DecryptResponse($Response) { $ResponseArray = explode(self::LF, $Response); echo count($ResponseArray); die; if ( count($ResponseArray) == 2 ) { //2 lines of text: cryptogram + signature $Response = strtoupper($ResponseArray[0]); $Response = pack("H*", $Response); $Response = $this->ce->encryptDecrypt($Response, Cryptography::MODE_DECRYPT); $signature = $this->ce->getSignature($Response); $signature = unpack("H*", $signature); $signature = $signature[1]; } // convert answer back to array return $this->TransportDecode($Response); } private function PreparePassword($Password) { return strtoupper( sha1($Password) ); } private function PreparePostData(array $p) { $RawRequest = $this->TransportEncode($p) . self::LF; $RawRequest = Cryptography::padForEncryption($RawRequest); $EncryptedRequest = $this->ce->encryptDecrypt($RawRequest, Cryptography::MODE_ENCRYPT); $EncryptedRequest = unpack("H*", $EncryptedRequest); $EncryptedRequest = strtoupper( $EncryptedRequest[1] ); $signature = $this->ce->getSignature($RawRequest); $signature = unpack("H*", $signature); $signature = strtoupper( $signature[1] ); // outer parameters $r['Protocol'] = $this->Protocol; $r['ApiVersion'] = $this->Version; $r['Login'] = $this->user; $r['Request'] = $EncryptedRequest; $r['Signature'] = $signature; $r['IP'] = $this->ip; $this->Log($p); $this->Log($r); return $r; } /** * return array */ private function TransportDecode($Buffer) { switch ( $this->Protocol ) { case self::TRANSPORT_XML: $r = $this->XMLToArray($Buffer); break; case self::TRANSPORT_JSON: $r = json_decode($Buffer, true); break; default: case self::TRANSPORT_INI: $r = $this->INIToArray($Buffer); break; } // back compatibility with old error messages if ( $r == false ) { $r = $this->INIToArray($Buffer); } return $r; } private function TransportEncode(array $Buffer) { switch ( $this->Protocol ) { case self::TRANSPORT_XML: return $this->ArrayToXML($Buffer); case self::TRANSPORT_JSON: return json_encode($Buffer); default: case self::TRANSPORT_INI: return $this->ArrayToINI($Buffer); } } private function ArrayToINI(array $Array) { $r = ''; foreach ($Array as $Key => $Value) { $r .= $Key . '=' . $Value . self::LF; } return trim($r); } private function INIToArray($INI) { return parse_ini_string($INI); } private function ArrayToXML($Array) { return ARRAYtoXML($Array, 'xREQUEST'); } private function XMLToArray($XML) { //$Array = XMLtoARRAY($XML); return isset($Array['xREQUEST']) ? $Array['xREQUEST'] : array(); } } class Cryptography { const MODE_ENCRYPT = 1; const MODE_DECRYPT = 2; const KEY_SIZE = 24; const BLOCK_SIZE = 8; const IV_SIZE = 8; private $_username; private $_password; public function __construct($username, $password) { $this->_username = $username; $this->_password = $password; } public function getKey() { return substr($this->getSignature('Key' . $this->_password . $this->_username . 'Key') . $this->getSignature($this->_password), 0, self::KEY_SIZE); } public function getIV() { return substr($this->getSignature('IV' . $this->_username . $this->_password . 'IV') . $this->getSignature($this->_username), 0, self::IV_SIZE); } public function assertLenIsMultiple($point, $name, $value, $expectedMultiple) { if (strlen($value) % $expectedMultiple !== 0) { throw new Exception(sprintf('[%s]: Parameter "%s" must be a multiple of %d, but "%d" found', $point, $name, $expectedMultiple, strlen($value))); } } public function encryptDecrypt($value, $mode) { $this->assertLenIsMultiple('encryptDecrypt', 'value', $value, self::BLOCK_SIZE); switch ( $mode ) { case self::MODE_ENCRYPT: return openssl_encrypt($value, 'DES-EDE3-CBC', $this->getKey(), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->getIV()); case self::MODE_DECRYPT: return openssl_decrypt($value, 'DES-EDE3-CBC', $this->getKey(), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->getIV()); default: throw new Exception('Invalid encryption mode: ' . $mode); } } public function getSignature($value) { return sha1($value, true); } public static function padForEncryption($data) { if ( strlen($data) % self::BLOCK_SIZE != 0 ) { $data .= str_repeat(' ', self::BLOCK_SIZE - (strlen($data) % self::BLOCK_SIZE)); } return $data; } } if ( !function_exists('parse_ini_string') ) { function parse_ini_string($str, $ProcessSections = false){ $lines = explode("\n", $str); $r = array(); $inSect = false; foreach($lines as $line){ $line = trim($line); if ( !$line || $line[0] == "#" || $line[0] == ";" ) continue; if ( $line[0] == "[" && $endIdx = strpos($line, "]") ) { $inSect = substr($line, 1, $endIdx-1); continue; } if ( !strpos($line, '=') ) // (We don't use "=== false" because value 0 is not valid as well) continue; $tmp = explode("=", $line, 2); if ( $ProcessSections && $inSect ) $r[$inSect][trim($tmp[0])] = ltrim($tmp[1]); else $r[trim($tmp[0])] = ltrim($tmp[1]); } return $r; } } function ARRAYtoXML($Array, $RootNodeName = NULL) { $XML = XML_serialize($Array, 0, NULL); if ( !is_null($RootNodeName) ) { $XML = "<" . $RootNodeName . ">\r\n" . $XML . "</" . $RootNodeName . ">"; } return $XML; } /*function XMLtoARRAY($XML) { return XML_unserialize($XML); }*/ function XML_serialize($data, $level = 0, $prior_key = NULL) { if ( $level == 0 ){ ob_start(); } while(list($key, $value) = each($data)) if(!strpos($key, ' attr')) if(is_array($value) and array_key_exists(0, $value)) { XML_serialize($value, $level, $key); } else { $tag = $prior_key ? $prior_key : $key; echo str_repeat("\t", $level),'<',$tag; if(array_key_exists("$key attr", $data)) { while(list($attr_name, $attr_value) = each($data["$key attr"])) echo ' ',$attr_name,'="',htmlspecialchars($attr_value),'"'; reset($data["$key attr"]); } if(is_null($value)) echo " />\n"; elseif(!is_array($value)) echo '>',htmlspecialchars($value),"</$tag>\n"; else echo ">\n",XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n"; } reset($data); if ( $level == 0 ) { $str = ob_get_contents(); ob_end_clean(); return $str; } } function XML_unserialize($XML) { $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); xml_parse_into_struct($xml_parser, $XML, $vals, $index); xml_parser_free($xml_parser); $params = array(); $level = array(); $alreadyused = array(); $x = 0; foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (in_array($xml_elem['tag'], $alreadyused)) { ++$x; $xml_elem['tag'] = $xml_elem['tag'].$x; } $level[$xml_elem['level']] = $xml_elem['tag']; $alreadyused[] = $xml_elem['tag']; } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while ($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; ++$start_level; } if ( !isset($xml_elem['value']) ) { $xml_elem['value'] = ''; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; eval($php_stmt); continue; } } return $params; }