Файл: _rootinc/gproxy.inc.php
Строк: 84
<?
class GPROXY
{
public $apikey = null;
public $error = null;
public function init($apikey)
{
$this->apikey = $apikey;
}
public function send($params)
{
while (list($k,$v) = @each($params)) {
$req = $req."$k=".urlencode($v)."&";
}
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, "http://p1.globatel.ru/api/api.php");
curl_setopt($fp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fp, CURLOPT_POST, true);
curl_setopt($fp, CURLOPT_POSTFIELDS, $req);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_FAILONERROR, false);
curl_setopt($fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($fp);
if (curl_errno($fp)) {
$this->error = "cURL Error ".curl_errno($fp).": ".curl_error($fp);
curl_close($fp);
return false;
} else {
curl_close($fp);
return $this->parseResult($result);
}
}
public function createProxy($use_xml,$template,$login,$pwd)
{
$params["skey"] = $this->apikey;
$params["do"] = "setproxy";
$params["use_xml"] = "$use_xml";
$params["template"] = $template;
$params["login"] = $login;
$params["pwd"] = $pwd;
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return $result[result];
} else if ($result[status] == "ERROR") {
$this->error = "createProxy: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "createProxy: no output";
return false;
}
}
public function suspendProxy($order_id)
{
$params["skey"] = $this->apikey;
$params["do"] = "pauseorder";
$params["order_id"] = $order_id;
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return true;
} else if ($result[status] == "ERROR") {
$this->error = "suspendProxy: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "suspendProxy: no output";
return false;
}
}
public function unSuspendProxy($order_id)
{
$params["skey"] = $this->apikey;
$params["do"] = "resumeorder";
$params["order_id"] = $order_id;
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return true;
} else if ($result[status] == "ERROR") {
$this->error = "unSuspendProxy: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "unSuspendProxy: no output";
return false;
}
}
public function deleteProxy($order_id)
{
$params["skey"] = $this->apikey;
$params["do"] = "removeproxy";
$params["order_id"] = $order_id;
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return true;
} else if ($result[status] == "ERROR") {
$this->error = "deleteProxy: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "deleteProxy: no output";
return false;
}
}
public function getProxyList($order_id)
{
$params["skey"] = $this->apikey;
$params["do"] = "getproxylist";
$params["order_id"] = $order_id;
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return $result;
} else if ($result[status] == "ERROR") {
$this->error = "getProxyList: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "getProxyList: no output";
return false;
}
}
public function getPackages()
{
$params["skey"] = $this->apikey;
$params["do"] = "gettemplates";
$result = $this->send($params);
if ($result[status] == "SUCCESS") {
return $result[result];
} else if ($result[status] == "ERROR") {
$this->error = "getPackages: ERROR (".$result[errorMsg].")";
return false;
} else {
$this->error = "getPackages: no output";
return false;
}
}
public function parseResult($result)
{
$resultt = @mb_split("rn",$result);
if (count($resultt) > 1) {
$res[status] = "SUCCESS";
$i = 0;
while (list($k,$result_line) = @each($resultt)) {
$i++;
$result_line = @mb_split(";",$result_line);
$j = 0;
while (list($k,$result_one) = @each($result_line)) {
$j++;
if ($i == 1) {
$rows[$j] = $result_one;
} else {
$row = $rows[$j];
$res[result][$i-2][$row] = $result_one;
}
}
}
} else {
if (preg_match("/^ERROR/i",$resultt[0])) {
$resultt[0] = mb_split("|",$resultt[0]);
$res[status] = "ERROR";
$res[errorMsg] = $resultt[0][1];
}
else if (preg_match("/^OK/i",$resultt[0])) {
$res[status] = "SUCCESS";
}
else if (intval($resultt[0]) > 0) {
$res[status] = "SUCCESS";
$res[result] = intval($resultt[0]);
}
}
$res[response] = $result;
return $res;
}
}
?>