26 lines
9.0 KiB
PHP
26 lines
9.0 KiB
PHP
<?PHP
|
|
/**
|
|
* @file
|
|
* TeamSpeak 3 PHP Framework
|
|
*
|
|
* $Id: TeamSpeak3.php 10/11/2013 11:35:21 scp@orilla $
|
|
*
|
|
* 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
|
|
* @version 1.1.23
|
|
* @author Sven 'ScP' Paulsen
|
|
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
|
|
*/
|
|
class TeamSpeak3{const READY="TS3";const GREET="Welcome";const ERROR="error";const EVENT="notify";const SCHID="selected";const LIB_VERSION="1.1.23";const SEPARATOR_LINE="\n";const SEPARATOR_LIST="|";const SEPARATOR_CELL=" ";const SEPARATOR_PAIR="=";const LOGLEVEL_CRITICAL=0x00;const LOGLEVEL_ERROR=0x01;const LOGLEVEL_WARNING=0x02;const LOGLEVEL_DEBUG=0x03;const LOGLEVEL_INFO=0x04;const LOGLEVEL_DEVEL=0x05;const TOKEN_SERVERGROUP=0x00;const TOKEN_CHANNELGROUP=0x01;const CODEC_SPEEX_NARROWBAND=0x00;const CODEC_SPEEX_WIDEBAND=0x01;const CODEC_SPEEX_ULTRAWIDEBAND=0x02;const CODEC_CELT_MONO=0x03;const CODEC_OPUS_VOICE=0x04;const CODEC_OPUS_MUSIC=0x05;const CODEC_CRYPT_INDIVIDUAL=0x00;const CODEC_CRYPT_DISABLED=0x01;const CODEC_CRYPT_ENABLED=0x02;const KICK_CHANNEL=0x04;const KICK_SERVER=0x05;const TEXTMSG_CLIENT=0x01;const TEXTMSG_CHANNEL=0x02;const TEXTMSG_SERVER=0x03;const PLUGINCMD_CHANNEL=0x01;const PLUGINCMD_SERVER=0x02;const PLUGINCMD_CLIENT=0x03;const PLUGINCMD_CHANNEL_SUBSCRIBED=0x04;const HOSTMSG_NONE=0x00;const HOSTMSG_LOG=0x01;const HOSTMSG_MODAL=0x02;const HOSTMSG_MODALQUIT=0x03;const HOSTBANNER_NO_ADJUST=0x00;const HOSTBANNER_IGNORE_ASPECT=0x01;const HOSTBANNER_KEEP_ASPECT=0x02;const CLIENT_TYPE_REGULAR=0x00;const CLIENT_TYPE_SERVERQUERY=0x01;const GROUP_DBTYPE_TEMPLATE=0x00;const GROUP_DBTYPE_REGULAR=0x01;const GROUP_DBTYPE_SERVERQUERY=0x02;const GROUP_NAMEMODE_HIDDEN=0x00;const GROUP_NAMEMODE_BEFORE=0x01;const GROUP_NAMEMODE_BEHIND=0x02;const GROUP_IDENTIFIY_STRONGEST=0x01;const GROUP_IDENTIFIY_WEAKEST=0x02;const PERM_TYPE_SERVERGROUP=0x00;const PERM_TYPE_CLIENT=0x01;const PERM_TYPE_CHANNEL=0x02;const PERM_TYPE_CHANNELGROUP=0x03;const PERM_TYPE_CHANNELCLIENT=0x04;const PERM_CAT_GLOBAL=0x10;const PERM_CAT_GLOBAL_INFORMATION=0x11;const PERM_CAT_GLOBAL_SERVER_MGMT=0x12;const PERM_CAT_GLOBAL_ADM_ACTIONS=0x13;const PERM_CAT_GLOBAL_SETTINGS=0x14;const PERM_CAT_SERVER=0x20;const PERM_CAT_SERVER_INFORMATION=0x21;const PERM_CAT_SERVER_ADM_ACTIONS=0x22;const PERM_CAT_SERVER_SETTINGS=0x23;const PERM_CAT_CHANNEL=0x30;const PERM_CAT_CHANNEL_INFORMATION=0x31;const PERM_CAT_CHANNEL_CREATE=0x32;const PERM_CAT_CHANNEL_MODIFY=0x33;const PERM_CAT_CHANNEL_DELETE=0x34;const PERM_CAT_CHANNEL_ACCESS=0x35;const PERM_CAT_GROUP=0x40;const PERM_CAT_GROUP_INFORMATION=0x41;const PERM_CAT_GROUP_CREATE=0x42;const PERM_CAT_GROUP_MODIFY=0x43;const PERM_CAT_GROUP_DELETE=0x44;const PERM_CAT_CLIENT=0x50;const PERM_CAT_CLIENT_INFORMATION=0x51;const PERM_CAT_CLIENT_ADM_ACTIONS=0x52;const PERM_CAT_CLIENT_BASICS=0x53;const PERM_CAT_CLIENT_MODIFY=0x54;const PERM_CAT_FILETRANSFER=0x60;const PERM_CAT_NEEDED_MODIFY_POWER=0xFF;const FILE_TYPE_DIRECTORY=0x00;const FILE_TYPE_REGULAR=0x01;const SNAPSHOT_STRING=0x00;const SNAPSHOT_BASE64=0x01;const SNAPSHOT_HEXDEC=0x02;const SPACER_SOLIDLINE=0x00;const SPACER_DASHLINE=0x01;const SPACER_DOTLINE=0x02;const SPACER_DASHDOTLINE=0x03;const SPACER_DASHDOTDOTLINE=0x04;const SPACER_CUSTOM=0x05;const SPACER_ALIGN_LEFT=0x00;const SPACER_ALIGN_RIGHT=0x01;const SPACER_ALIGN_CENTER=0x02;const SPACER_ALIGN_REPEAT=0x03;const REASON_NONE=0x00;const REASON_MOVE=0x01;const REASON_SUBSCRIPTION=0x02;const REASON_TIMEOUT=0x03;const REASON_CHANNEL_KICK=0x04;const REASON_SERVER_KICK=0x05;const REASON_SERVER_BAN=0x06;const REASON_SERVER_STOP=0x07;const REASON_DISCONNECT=0x08;const REASON_CHANNEL_UPDATE=0x09;const REASON_CHANNEL_EDIT=0x0A;const REASON_DISCONNECT_SHUTDOWN=0x0B; protected static $escape_patterns=array("\\"=>"\\\\","/"=>"\\/"," "=>"\\s","|"=>"\\p",";"=>"\\;","\a"=>"\\a","\b"=>"\\b","\f"=>"\\f","\n"=>"\\n","\r"=>"\\r","\t"=>"\\t","\v"=>"\\v"); public static function factory($uri){self::init();$uri=new TeamSpeak3_Helper_Uri($uri);$adapter=self::getAdapterName($uri->getScheme());$options=array("host"=>$uri->getHost(),"port"=>$uri->getPort(),"timeout"=>intval($uri->getQueryVar("timeout",10)),"blocking"=>intval($uri->getQueryVar("blocking",1)));self::loadClass($adapter);$object=new $adapter($options);if($object instanceof TeamSpeak3_Adapter_ServerQuery){$node=$object->getHost();if($uri->hasUser()&&$uri->hasPass()){$node->login($uri->getUser(),$uri->getPass());}if($uri->hasQueryVar("nickname")){$node->setPredefinedQueryName($uri->getQueryVar("nickname"));}if($uri->getFragment()=="use_offline_as_virtual"){$node->setUseOfflineAsVirtual(TRUE);}elseif($uri->hasQueryVar("use_offline_as_virtual")){$node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual")?TRUE:FALSE);}if($uri->getFragment()=="clients_before_channels"){$node->setLoadClientlistFirst(TRUE);}elseif($uri->hasQueryVar("clients_before_channels")){$node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels")?TRUE:FALSE);}if($uri->getFragment()=="no_query_clients"){$node->setExcludeQueryClients(TRUE);}elseif($uri->hasQueryVar("no_query_clients")){$node->setExcludeQueryClients($uri->getQueryVar("no_query_clients")?TRUE:FALSE);}if($uri->hasQueryVar("server_id")){$node=$node->serverGetById($uri->getQueryVar("server_id"));}elseif($uri->hasQueryVar("server_uid")){$node=$node->serverGetByUid($uri->getQueryVar("server_uid"));}elseif($uri->hasQueryVar("server_port")){$node=$node->serverGetByPort($uri->getQueryVar("server_port"));}elseif($uri->hasQueryVar("server_name")){$node=$node->serverGetByName($uri->getQueryVar("server_name"));}elseif($uri->hasQueryVar("server_tsdns")){$node=$node->serverGetByTSDNS($uri->getQueryVar("server_tsdns"));}if($node instanceof TeamSpeak3_Node_Server){if($uri->hasQueryVar("channel_id")){$node=$node->channelGetById($uri->getQueryVar("channel_id"));}elseif($uri->hasQueryVar("channel_name")){$node=$node->channelGetByName($uri->getQueryVar("channel_name"));}if($uri->hasQueryVar("client_id")){$node=$node->clientGetById($uri->getQueryVar("client_id"));}if($uri->hasQueryVar("client_uid")){$node=$node->clientGetByUid($uri->getQueryVar("client_uid"));}elseif($uri->hasQueryVar("client_name")){$node=$node->clientGetByName($uri->getQueryVar("client_name"));}}return $node;}return $object;} protected static function loadClass($class){if(class_exists($class,FALSE)||interface_exists($class,FALSE)){return;}if(preg_match("/[^a-z0-9\\/\\\\_.-]/i",$class)){ throw new LogicException("illegal characters in classname '".$class."'");}$file=self::getFilePath($class).".php";if(!file_exists($file)||!is_readable($file)){ throw new LogicException("file '".$file."' does not exist or is not readable");}if(class_exists($class,FALSE)||interface_exists($class,FALSE)){ throw new LogicException("class '".$class."' does not exist");}return include_once($file);} protected static function getFilePath($name){$path=str_replace("_",DIRECTORY_SEPARATOR,$name);$path=str_replace(__CLASS__,dirname(__FILE__),$path);return $path;} protected static function getAdapterName($name,$namespace="TeamSpeak3_Adapter_"){$path=self::getFilePath($namespace);$scan=scandir($path);foreach($scan as $node){$file=TeamSpeak3_Helper_String::factory($node)->toLower();if($file->startsWith($name)&&$file->endsWith(".php")){return $namespace.str_replace(".php","",$node);}} throw new TeamSpeak3_Adapter_Exception("adapter '".$name."' does not exist");} public static function autoload($class){if(substr($class,0,strlen(__CLASS__))!=__CLASS__)return;try{self::loadClass($class);return TRUE;}catch(Exception$e){return FALSE;}} public static function init(){if(version_compare(phpversion(),"5.2.1")==-1){ throw new LogicException("this particular software cannot be used with the installed version of PHP");}if(!function_exists("stream_socket_client")){ throw new LogicException("network functions are not available in this PHP installation");}if(!function_exists("spl_autoload_register")){ throw new LogicException("autoload functions are not available in this PHP installation");}if(!class_exists("TeamSpeak3_Helper_Profiler")){spl_autoload_register(array(__CLASS__,"autoload"));}TeamSpeak3_Helper_Profiler::start();} public static function getEscapePatterns(){return self::$escape_patterns;} public static function dump($var,$echo=TRUE){ob_start();var_dump($var);$output=ob_get_clean();$output=preg_replace("/\]\=\>\n(\s+)/m","] => ",$output);if(PHP_SAPI=="cli"){$output=PHP_EOL.PHP_EOL.$output.PHP_EOL;}else {$output="<pre>".htmlspecialchars($output,ENT_QUOTES)."</pre>";}if($echo)echo($output);return $output;}}?>
|