Файл: RootPanel 1.7.0 FreeCode/RootPanel 1.7.0 FreeCode/_rootinc/ventrilo.inc.php
Строк: 330
<?
class Ventrilo
{
public $controller = true;
public $user = null;
public $password = null;
public $reseller_id = null;
public $error = null;
public function startup(&$controller) {
$this->controller =& $controller;
}
public function Ventrilo($user,$password,$reseller_id) {
$this->user=$user;
$this->password=$password;
$this->reseller_id=$reseller_id;
}
public function createAccount($slots, $location_id, $uniqueid, $email, $pwd) {
$parameters = array(
'reseller_id' => $this->reseller_id,
'slots' => $slots,
'location_id' => $location_id,
'uniqueid' => $uniqueid,
'email' => $email,
'password' => $pwd
);
$api = new API_Client();
$result = $api->get_xml_response('reseller',"vent_auto_setup",$parameters,$this->user,$this->password);
if ($this->findError($result) == false) {
return $result[ip].":".$result[port];
} else {
$this->error = $result;
return false;
}
}
public function suspendAccount($uniqueid) {
$parameters = array(
'reseller_id' => $this->reseller_id,
'uniqueid' => $uniqueid
);
$api = new API_Client();
$result = $api->get_xml_response('reseller',"suspendServerByUniqueid",$parameters,$this->user,$this->password);
if ($this->findError($result) == false) {
$this->adjustSlotsCount(1,$uniqueid);
return true;
} else {
$this->error = $result;
return false;
}
}
public function unSuspendAccount($slots,$uniqueid) {
$parameters = array(
'reseller_id' => $this->reseller_id,
'uniqueid' => $uniqueid
);
$api = new API_Client();
$result = $api->get_xml_response('reseller',"unsuspendServerByUniqueid",$parameters,$this->user,$this->password);
if ($this->findError($result) == false) {
$this->adjustSlotsCount($slots,$uniqueid);
return true;
} else {
$this->error = $result;
return false;
}
}
public function adjustSlotsCount($slots,$uniqueid) {
$parameters = array(
'reseller_id' => $this->reseller_id,
'slots' => $slots,
'uniqueid' => $uniqueid
);
$api = new API_Client();
$result = $api->get_xml_response('reseller',"adjustVentriloSlotCountByUniqueId",$parameters,$this->user,$this->password);
if ($this->findError($result) == false) {
return true;
} else {
$this->error = $result;
return false;
}
}
public function terminateAccount($uniqueid) {
$parameters = array(
'reseller_id' => $this->reseller_id,
'uniqueid' => $uniqueid
);
$api = new API_Client();
$result = $api->get_xml_response('reseller',"deleteServerByUniqueid",$parameters,$this->user,$this->password);
if ($this->findError($result) == false) {
return true;
} else {
$this->error = $result;
return false;
}
}
public function findError($result)
{
if(stristr($result, 'Error')) {
return true;
} else {
return false;
}
}
}
/**
* API Client Class. Used for Ventrilo Resellers to communicate with the
* Darkstar Communications Reseller API Interface via XML Command Calls.
*
* @version PHP 5.
* @author Brett Guarnieri / Nobis Tech.
* @updated February 11, 2008.
*
*/
class API_Client
{
/**
* XML Parser Object.
*
* @var Object
*/
public $parser;
/**
* Constructor class. Inherently brings forth the Parser class. Calls it.
*
* @return <void>
*/
public function API_Client()
{
/**
* Define the parser with a new API_Parser call.
*/
$this->parser = new API_Parser;
}
/**
* Sends our message to the API Server.
*
* @param <String> $xml_data
* @param <Int> $r_id
* @param <String> $r_key
*
* @return <String>
*/
public function send_message($xml_data, $r_id, $r_key)
{
// @ Create our XML Signature.
$xml_signature = base64_encode($this->__CalcHmacSha1($xml_data, $r_key));
// @ Encode data.
$xml_data = base64_encode($xml_data);
// @ Post Data
$post_data = array(
'remote_id' => $r_id,
'xml_request' => $xml_data,
'xml_signature' => $xml_signature
);
// @ Get curl response.
return $this->get_curl_response($post_data, "http://api.darkstarllc.com/api.php");
}
/**
* Get our curl response and send it.
*
* @param <String> $post_vars
* @param <String> $url
*
* @return <String>
*/
public function get_curl_response($post_vars, $url)
{
/**
* Initiate and set options.
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
/**
* Execute and send response.
*/
$response = curl_exec($ch);
return($response);
if (curl_errno($ch))
print curl_error($ch);
}
/**
* Calculate the HmacSha1 Hash Key.
*
* @param <String> $data
* @param <String> $key
*
* @return <String>
*/
public function __CalcHmacSha1($data, $key)
{
/**
* Check for errors.
*/
$error_function_name = "__CalcHmacSha1()";
/**
* The $data and $key variables must be populated.
*/
$blocksize = 64;
$hashfunc = 'sha1';
if (strlen($key) > $blocksize)
$key = pack('H*', $hashfunc($key));
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
/**
* Return packed data.
*/
$hmac = pack('H*', $hashfunc(($key^$opad).pack('H*', $hashfunc(($key^$ipad).$data))));
return $hmac;
}
/**
* Function to create the XML message to be sent.
*
* @param <String> $class
* @param <String> $func
* @param <Array> $params
* @param <Int> $r_id
* @param <String> $r_key
*
* @return <Array>
*/
public function get_xml_response($class, $func, $params, $r_id, $r_key)
{
/**
* Create our Parser class from api.xml.php.
*/
$parser = new API_Parser;
/**
* This is required no matter what
*/
$xml_msg = "<?xml version="1.0" encoding="UTF-8"?>rn";
/**
* Method String
*/
$xml_msg .= "<" . $func . " xmlns="http://api.darkstarllc.com/schemas/" . $class . "">rn";
/**
* Remote ID
*/
$xml_msg .= "<remoteid>" . $r_id . "</remoteid>rn";
/**
* Parameters
*/
$xml_msg .= "<parameters>rn";
foreach ($params as $key=>$value)
{
/**
* Array
*/
if(is_array($params[$key]))
{
$xml_msg .= "<" . $key . ">rn";
foreach($params[$key] AS $loop_key=>$loop_val)
{
$xml_msg .= "<" . $loop_key . ">";
$xml_msg .= $loop_val;
$xml_msg .= "</" . $loop_key . ">rn";
}
$xml_msg .= "</" . $key . ">rn";
}
/**
* Non-Array
*/
{
$xml_msg .= "<" . $key . ">";
$xml_msg .= $value;
$xml_msg .= "</" . $key . ">rn";
}
}
$xml_msg .= "</parameters>rn";
/**
* End the request
*/
$xml_msg .= "</" . $func . ">rn";
/**
* Get the results of the request
*/
$response = $this->send_message($xml_msg, $r_id, $r_key);
$response = ereg_replace("t","",$response);
if (stristr($response, "Specified API class not found or is un-supported"))
return ("Error - " . $response);
if (stristr($response, "Specified API function was not found or is un-supported"))
return ("Error - " . $response);
/**
* And, finally, process the info and return an array
*/
$xml = $parser->parse($response);
if ($xml[0]['name'] == "ERROR")
return ("Error - ".$xml[0]['tagData']);
/**
* Make sure that the message is a response
*/
if ((!($xml[0]['name'] == "RESPONSE")))// || (!(isset($xml[0]['name']))) || ($xml[0]['name']==""))
return ("Error - Invalid return - Response expected");
/**
* Make sure we have a paramter set
*/
if (!($xml[0][children][0]['name'] == "PARAMETERS"))
return ("Error - Invalid return - Paramaters expected");
/**
* Check to see if we got an error
*/
if (stristr($xml[0][children][0][children][0]['name'], "ERROR"))
return ("Error - " . $xml[0][children][0][children][0][tagData]);
$result_set = array();
if (count($xml[0][children][0][children]) > 0)
foreach ($xml[0][children][0][children] as $key)
$result_set[strtolower($key['name'])] = $key['tagData'];
return ($result_set);
}
}
/**
* This is the class to handle the actual parsing of XML data.
* Used in the API system for Darkstar's Reseller Customers.
*
* @author Brett Guarnieri / Nobis Tech.
* @updated February 11, 2008.
*
*/
class API_Parser
{
/**
* Output of data.
*
* @var <Array>
*/
public $arrOutput = array();
/**
* PHP XML Parser Resource Object
*
* @var <Resource>
*/
public $resParser;
/**
* Our raw XML Data.
*
* @var <String>
*/
public $strXmlData;
/**
* Constructor. Does not do anything.
*/
public function API_Parser() { }
/**
* Parses our XML code into useable data.
*
* @param <String> $strInputXML
*
* @return <String>
*/
public function parse($strInputXML)
{
/**
* Setup parser.
*/
$this->resParser = xml_parser_create();
xml_set_object($this->resParser,$this);
xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
xml_set_character_data_handler($this->resParser, "tagData");
/**
* Gather and free data.
*/
$this->strXmlData = xml_parse($this->resParser,$strInputXML );
if(!$this->strXmlData)
{
$data = xml_error_string(xml_get_error_code($this->resParser)) ." at line ". xml_get_current_line_number($this->resParser) .".";
xml_parser_free($this->resParser);
return $data;
}
/**
* Free/Return.
*/
xml_parser_free($this->resParser);
return $this->arrOutput;
}
/**
* Open's XML Tag.
*
* @param <Resource> $parser
* @param <String> $name
* @param <String> $attrs
*
* @return <Void>
*/
public function tagOpen($parser, $name, $attrs)
{
$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($this->arrOutput,$tag);
}
/**
* Handles the data in the tag.
*
* @param <Resource> $parser
* @param <String> $tagData
*
* @return <Void>
*/
public function tagData($parser, $tagData)
{
if(trim($tagData)) {
if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $tagData;
}
else {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] = $tagData;
}
}
}
/**
* Closes the tag.
*
* @param <Resource> $parser
* @param <String> $name
*
* @return <Void>
*/
public function tagClosed($parser, $name)
{
$this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
array_pop($this->arrOutput);
}
}
?>