force sync from /var/www/html/panel: 2025-09-08T20:36:30Z
This commit is contained in:
commit
4f717c9ee8
18119 changed files with 2566034 additions and 0 deletions
274
ControlPanel/protocol/TeamSpeak3/Transport/Abstract.php
Executable file
274
ControlPanel/protocol/TeamSpeak3/Transport/Abstract.php
Executable file
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TeamSpeak 3 PHP Framework
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package TeamSpeak3
|
||||
* @author Sven 'ScP' Paulsen
|
||||
* @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class TeamSpeak3_Transport_Abstract
|
||||
* @brief Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport.
|
||||
*/
|
||||
abstract class TeamSpeak3_Transport_Abstract
|
||||
{
|
||||
/**
|
||||
* Stores user-provided configuration settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $config = null;
|
||||
|
||||
/**
|
||||
* Stores the stream resource of the connection.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $stream = null;
|
||||
|
||||
/**
|
||||
* Stores an optional stream session for the connection.
|
||||
*
|
||||
* @var session
|
||||
*/
|
||||
protected $session = null;
|
||||
|
||||
/**
|
||||
* Stores the TeamSpeak3_Adapter_Abstract object using this transport.
|
||||
*
|
||||
* @var TeamSpeak3_Adapter_Abstract
|
||||
*/
|
||||
protected $adapter = null;
|
||||
|
||||
/**
|
||||
* The TeamSpeak3_Transport_Abstract constructor.
|
||||
*
|
||||
* @param array $config
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return TeamSpeak3_Transport_Abstract
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
if(!array_key_exists("host", $config))
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("config must have a key for 'host' which specifies the server host name");
|
||||
}
|
||||
|
||||
if(!array_key_exists("port", $config))
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("config must have a key for 'port' which specifies the server port number");
|
||||
}
|
||||
|
||||
if(!array_key_exists("timeout", $config))
|
||||
{
|
||||
$config["timeout"] = 10;
|
||||
}
|
||||
|
||||
if(!array_key_exists("blocking", $config))
|
||||
{
|
||||
$config["blocking"] = 1;
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit pending data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return array("config");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnects to the remote server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* The TeamSpeak3_Transport_Abstract destructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
|
||||
{
|
||||
$this->adapter->__destruct();
|
||||
}
|
||||
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a remote server.
|
||||
*
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return void
|
||||
*/
|
||||
abstract public function connect();
|
||||
|
||||
/**
|
||||
* Disconnects from a remote server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function disconnect();
|
||||
|
||||
/**
|
||||
* Reads data from the stream.
|
||||
*
|
||||
* @param integer $length
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return TeamSpeak3_Helper_String
|
||||
*/
|
||||
abstract public function read($length = 4096);
|
||||
|
||||
/**
|
||||
* Writes data to the stream.
|
||||
*
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
abstract public function send($data);
|
||||
|
||||
/**
|
||||
* Returns the underlying stream resource.
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration variables in this adapter.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig($key = null, $default = null)
|
||||
{
|
||||
if($key !== null)
|
||||
{
|
||||
return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the TeamSpeak3_Adapter_Abstract object using this transport.
|
||||
*
|
||||
* @param TeamSpeak3_Adapter_Abstract $adapter
|
||||
* @return void
|
||||
*/
|
||||
public function setAdapter(TeamSpeak3_Adapter_Abstract $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TeamSpeak3_Adapter_Abstract object using this transport.
|
||||
*
|
||||
* @return TeamSpeak3_Adapter_Abstract
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAdapterType()
|
||||
{
|
||||
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
|
||||
{
|
||||
$string = TeamSpeak3_Helper_String::factory(get_class($this->adapter));
|
||||
|
||||
return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString();
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns header/meta data from stream pointer.
|
||||
*
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return array
|
||||
*/
|
||||
public function getMetaData()
|
||||
{
|
||||
if($this->stream === null)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("unable to retrieve header/meta data from stream pointer");
|
||||
}
|
||||
|
||||
return stream_get_meta_data($this->stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the transport is connected.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return (is_resource($this->stream)) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks a stream until data is available for reading if the stream is connected
|
||||
* in non-blocking mode.
|
||||
*
|
||||
* @param integer $time
|
||||
* @return void
|
||||
*/
|
||||
protected function waitForReadyRead($time = 0)
|
||||
{
|
||||
if(!$this->isConnected() || $this->config["blocking"]) return;
|
||||
|
||||
do
|
||||
{
|
||||
$read = array($this->stream);
|
||||
$null = null;
|
||||
|
||||
if($time)
|
||||
{
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
|
||||
}
|
||||
|
||||
$time = $time+$this->config["timeout"];
|
||||
}
|
||||
while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
|
||||
}
|
||||
}
|
||||
29
ControlPanel/protocol/TeamSpeak3/Transport/Exception.php
Executable file
29
ControlPanel/protocol/TeamSpeak3/Transport/Exception.php
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TeamSpeak 3 PHP Framework
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package TeamSpeak3
|
||||
* @author Sven 'ScP' Paulsen
|
||||
* @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class TeamSpeak3_Transport_Exception
|
||||
* @brief Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
|
||||
*/
|
||||
class TeamSpeak3_Transport_Exception extends TeamSpeak3_Exception {}
|
||||
212
ControlPanel/protocol/TeamSpeak3/Transport/TCP.php
Executable file
212
ControlPanel/protocol/TeamSpeak3/Transport/TCP.php
Executable file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TeamSpeak 3 PHP Framework
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package TeamSpeak3
|
||||
* @author Sven 'ScP' Paulsen
|
||||
* @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class TeamSpeak3_Transport_TCP
|
||||
* @brief Class for connecting to a remote server through TCP.
|
||||
*/
|
||||
class TeamSpeak3_Transport_TCP extends TeamSpeak3_Transport_Abstract
|
||||
{
|
||||
/**
|
||||
* Connects to a remote server.
|
||||
*
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
if($this->stream !== null) return;
|
||||
|
||||
$host = strval($this->config["host"]);
|
||||
$port = strval($this->config["port"]);
|
||||
$timeout = intval($this->config["timeout"]);
|
||||
$blocking = intval($this->config["blocking"]);
|
||||
|
||||
if(empty($this->config["ssh"]))
|
||||
{
|
||||
$address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
|
||||
$options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));
|
||||
|
||||
$this->stream = @stream_socket_client($address, $errno, $errstr, $this->config["timeout"], STREAM_CLIENT_CONNECT, stream_context_create($options));
|
||||
|
||||
if($this->stream === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
|
||||
}
|
||||
|
||||
if(!empty($this->config["tls"]))
|
||||
{
|
||||
stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session = @ssh2_connect($host, $port);
|
||||
|
||||
if($this->session === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("failed to establish secure shell connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
|
||||
}
|
||||
|
||||
if(!@ssh2_auth_password($this->session, $this->config["username"], $this->config["password"]))
|
||||
{
|
||||
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid loginname or password", 0x208);
|
||||
}
|
||||
|
||||
$this->stream = @ssh2_shell($this->session, "raw");
|
||||
|
||||
if($this->stream === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("failed to open a secure shell on server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
@stream_set_timeout($this->stream, $timeout);
|
||||
@stream_set_blocking($this->stream, $blocking ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from a remote server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
if($this->stream === null) return;
|
||||
|
||||
$this->stream = null;
|
||||
|
||||
if(is_resource($this->session))
|
||||
{
|
||||
@ssh2_disconnect($this->session);
|
||||
}
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the stream.
|
||||
*
|
||||
* @param integer $length
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return TeamSpeak3_Helper_String
|
||||
*/
|
||||
public function read($length = 4096)
|
||||
{
|
||||
$this->connect();
|
||||
$this->waitForReadyRead();
|
||||
|
||||
$data = @stream_get_contents($this->stream, $length);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
|
||||
|
||||
if($data === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
|
||||
}
|
||||
|
||||
return new TeamSpeak3_Helper_String($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a single line of data from the stream.
|
||||
*
|
||||
* @param string $token
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return TeamSpeak3_Helper_String
|
||||
*/
|
||||
public function readLine($token = "\n")
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
$line = TeamSpeak3_Helper_String::factory("");
|
||||
|
||||
while(!$line->endsWith($token))
|
||||
{
|
||||
$this->waitForReadyRead();
|
||||
|
||||
$data = @fgets($this->stream, 4096);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
|
||||
|
||||
if($data === FALSE)
|
||||
{
|
||||
if($line->count())
|
||||
{
|
||||
$line->append($token);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$line->append($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $line->trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the stream.
|
||||
*
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function send($data)
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
@fwrite($this->stream, $data);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a line of data to the stream.
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $separator
|
||||
* @return void
|
||||
*/
|
||||
public function sendLine($data, $separator = "\n")
|
||||
{
|
||||
$size = strlen($data);
|
||||
$pack = 4096;
|
||||
|
||||
for($seek = 0 ;$seek < $size;)
|
||||
{
|
||||
$rest = $size-$seek;
|
||||
$pack = $rest < $pack ? $rest : $pack;
|
||||
$buff = substr($data, $seek, $pack);
|
||||
$seek = $seek+$pack;
|
||||
|
||||
if($seek >= $size) $buff .= $separator;
|
||||
|
||||
$this->send($buff);
|
||||
}
|
||||
}
|
||||
}
|
||||
110
ControlPanel/protocol/TeamSpeak3/Transport/UDP.php
Executable file
110
ControlPanel/protocol/TeamSpeak3/Transport/UDP.php
Executable file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* TeamSpeak 3 PHP Framework
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package TeamSpeak3
|
||||
* @author Sven 'ScP' Paulsen
|
||||
* @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class TeamSpeak3_Transport_UDP
|
||||
* @brief Class for connecting to a remote server through UDP.
|
||||
*/
|
||||
class TeamSpeak3_Transport_UDP extends TeamSpeak3_Transport_Abstract
|
||||
{
|
||||
/**
|
||||
* Connects to a remote server.
|
||||
*
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
if($this->stream !== null) return;
|
||||
|
||||
$host = strval($this->config["host"]);
|
||||
$port = strval($this->config["port"]);
|
||||
|
||||
$address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
|
||||
$timeout = (int) $this->config["timeout"];
|
||||
|
||||
$this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
|
||||
|
||||
if($this->stream === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
|
||||
}
|
||||
|
||||
@stream_set_timeout($this->stream, $timeout);
|
||||
@stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from a remote server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
if($this->stream === null) return;
|
||||
|
||||
$this->stream = null;
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the stream.
|
||||
*
|
||||
* @param integer $length
|
||||
* @throws TeamSpeak3_Transport_Exception
|
||||
* @return TeamSpeak3_Helper_String
|
||||
*/
|
||||
public function read($length = 4096)
|
||||
{
|
||||
$this->connect();
|
||||
$this->waitForReadyRead();
|
||||
|
||||
$data = @fread($this->stream, $length);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
|
||||
|
||||
if($data === FALSE)
|
||||
{
|
||||
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
|
||||
}
|
||||
|
||||
return new TeamSpeak3_Helper_String($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the stream.
|
||||
*
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function send($data)
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
@stream_socket_sendto($this->stream, $data);
|
||||
|
||||
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue