Файл: _rootinc/teamspeak2.inc.php
Строк: 155
<?
class TeamSpeak2
{
public $user = null;
public $password = null;
public $fp=null;
public $error = null;
public $action = null;
public function TeamSpeak2($user,$password) {
$this->user=$user;
$this->password=$password;
}
public function send($postFields) {
$this->fp = curl_init();
curl_setopt($this->fp, CURLOPT_URL, "https://www.bargainvoice.com/teamspeak/reseller.php");
curl_setopt($this->fp, CURL_HTTP_VERSION_1_1, 1);
curl_setopt($this->fp, CURLOPT_POST, 1);
curl_setopt($this->fp, CURLOPT_POSTFIELDS, "Action=".$this->action."&".$postFields);
curl_setopt($this->fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->fp, CURLOPT_FAILONERROR, 0);
curl_setopt($this->fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($this->fp);
if (@curl_errno($this->fp)) {
$this->error = "cURL Error ".@curl_errno($this->fp).": ".@curl_error($this->fp);
return false;
}
curl_close($this->fp);
return $result;
}
public function parseData($msg) {
if (preg_match("/Error/i",$msg)) {
list($error,$errorMessage)=mb_split(": ", $msg);
$result["status"]=0;
$result["msg"]=$errorMessage;
return $result;
}
else if (preg_match("/OK/i",$msg)) {
if ($this->action == "Add") {
list($error,$errorMessage)=mb_split(": ", $msg);
list($clientUsername,$ipAddress,$freePort)=mb_split(";",$errorMessage);
$result["status"]=1;
$result["msg"]="Client Added";
$result["clientUsername"]=$clientUsername;
$result["ipAddress"]=$ipAddress;
$result["port"]=$freePort;
return $result;
} else {
list($error,$errorMessage)=mb_split(": ", $msg);
$result["status"]=1;
$result["msg"]=$errorMessage;
return $result;
}
} else {
$result["status"]=0;
$result["msg"]="Unknown Reply";
return $result;
}
}
public function createAccount($clientFirst, $clientLast, $clientEmail, $clientLocation, $clientSlots, $clientUsername, $clientPassword, $clientIdentifier) {
$this->action = "Add";
$result = $this->send("ResellerID=".$this->user."&ResellerPass=".$this->password."&clientFirst=".urlencode($clientFirst)."&clientLast=".urlencode($clientLast)."&clientEmail=".urlencode($clientEmail)."&clientLocation=".urlencode($clientLocation)."&clientSlots=$clientSlots&clientUsername=$clientUsername&clientPassword=".urlencode($clientPassword)."&clientIdentifier=$clientIdentifier&clientNotes=".urlencode("AutoCreatedByRootPanel")."&clientStatus=PAID");
$result = $this->parseData($result);
if ($result[status]) {
return $result[ipAddress].":".$result[port];
} else {
$this->error = $result[msg];
return false;
}
}
public function suspendAccount($clientUsername) {
$this->action = "Suspend";
$result = $this->send("ResellerID=".$this->user."&ResellerPass=".$this->password."&clientUsername=$clientUsername");
$result = $this->parseData($result);
if ($result[status]) {
$this->adjustSlotsCount($clientUsername,1);
return true;
} else {
$this->error = $result[msg];
return false;
}
}
public function unSuspendAccount($clientUsername,$slots) {
$this->action = "Unsuspend";
$result = $this->send("ResellerID=".$this->user."&ResellerPass=".$this->password."&clientUsername=$clientUsername");
$result = $this->parseData($result);
if ($result[status]) {
$this->adjustSlotsCount($clientUsername,$slots);
return true;
} else {
$this->error = $result[msg];
return false;
}
}
public function adjustSlotsCount($clientUsername,$clientSlots) {
$this->action = "ChangePackage";
$result = $this->send("ResellerID=".$this->user."&ResellerPass=".$this->password."&clientUsername=$clientUsername&clientSlots=$clientSlots");
$result = $this->parseData($result);
if ($result[status]) {
return true;
} else {
$this->error = $result[msg];
return false;
}
}
public function terminateAccount($clientUsername) {
$this->action = "Delete";
$result = $this->send("ResellerID=".$this->user."&ResellerPass=".$this->password."&clientUsername=$clientUsername");
$result = $this->parseData($result);
if ($result[status]) {
return true;
} else {
$this->error = $result[msg];
return false;
}
}
}
?>