BlaquuTM

Untitled

Aug 19th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 162.47 KB | None | 0 0
  1. <?PHP
  2. /*
  3. * ts3admin.class.php
  4. * ------------------
  5. * created : 18. December 2009
  6. * last modified : 07. February 2017
  7. * version : 1.0.2.1
  8. * website : http://ts3admin.info
  9. * copyright : (C) 2017 Stefan Zehnpfennig
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * @file
  26. * The ts3admin.class is a powerful api for communication with Teamspeak 3 Servers from your website! Your creativity knows no bounds!
  27. *
  28. * @author Stefan Zehnpfennig
  29. * @copyright Copyright (c) 2017, Stefan Zehnpfennig
  30. * @version 1.0.2.1
  31. * @package ts3admin
  32. *
  33. */
  34.  
  35. /**
  36. * \class ts3admin
  37. * \brief The ts3admin.class
  38. */
  39. class ts3admin {
  40.  
  41. //*******************************************************************************************
  42. //****************************************** Vars *******************************************
  43. //*******************************************************************************************
  44.  
  45. /**
  46. * runtime is an private handle and configuration storage
  47. *
  48. * @author Stefan Zehnpfennig
  49. */
  50. public $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '', 'bot_clid' => '', 'bot_name' => '');
  51.  
  52. //*******************************************************************************************
  53. //*************************************** Constants *****************************************
  54. //*******************************************************************************************
  55.  
  56. const HostMessageMode_NONE = 0;
  57. const HostMessageMode_LOG = 1;
  58. const HostMessageMode_MODAL = 2;
  59. const HostMessageMode_MODALQUIT = 3;
  60.  
  61. const HostBannerMode_NOADJUST = 0;
  62. const HostBannerMode_IGNOREASPECT = 1;
  63. const HostBannerMode_KEEPASPECT = 2;
  64.  
  65. const CODEC_SPEEX_NARROWBAND = 0;
  66. const CODEC_SPEEX_WIDEBAND = 1;
  67. const CODEC_SPEEX_ULTRAWIDEBAND = 2;
  68. const CODEC_CELT_MONO = 3;
  69. const CODEC_OPUS_VOICE = 4;
  70. const CODEC_OPUS_MUSIC = 5;
  71.  
  72. const CODEC_CRYPT_INDIVIDUAL = 0;
  73. const CODEC_CRYPT_DISABLED = 1;
  74. const CODEC_CRYPT_ENABLED = 2;
  75.  
  76. const TextMessageTarget_CLIENT = 1;
  77. const TextMessageTarget_CHANNEL = 2;
  78. const TextMessageTarget_SERVER = 3;
  79.  
  80. const LogLevel_ERROR = 1;
  81. const LogLevel_WARNING = 2;
  82. const LogLevel_DEBUG = 3;
  83. const LogLevel_INFO = 4;
  84.  
  85. const REASON_KICK_CHANNEL = 4;
  86. const REASON_KICK_SERVER = 5;
  87.  
  88. const PermGroupDBTypeTemplate = 0;
  89. const PermGroupDBTypeRegular = 1;
  90. const PermGroupDBTypeQuery = 2;
  91.  
  92. const PermGroupTypeServerGroup = 0;
  93. const PermGroupTypeGlobalClient = 1;
  94. const PermGroupTypeChannel = 2;
  95. const PermGroupTypeChannelGroup = 3;
  96. const PermGroupTypeChannelClient = 4;
  97.  
  98. const TokenServerGroup = 0;
  99. const TokenChannelGroup = 1;
  100.  
  101. //*******************************************************************************************
  102. //************************************ Public Functions *************************************
  103. //******************************************************************************************
  104.  
  105. /**
  106. * banAddByIp
  107. *
  108. * Adds a new ban rule on the selected virtual server.
  109. *
  110. * <b>Output:</b>
  111. * <pre>
  112. * Array
  113. * {
  114. * [banid] => 109
  115. * }
  116. * </pre>
  117. *
  118. * @author Stefan Zehnpfennig
  119. * @param string $ip clientIp
  120. * @param integer $time bantime in seconds (0=unlimited/default) [optional]
  121. * @param string $banreason Banreason [optional]
  122. * @return array banId
  123. */
  124. function banAddByIp($ip, $time = 0, $banreason = NULL) {
  125. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  126.  
  127. if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
  128.  
  129. return $this->getData('array', 'banadd ip='.$ip.' time='.$time.$msg);
  130. }
  131.  
  132. /**
  133. * banAddByUid
  134. *
  135. * Adds a new ban rule on the selected virtual server.
  136. *
  137. * <b>Output:</b>
  138. * <pre>
  139. * Array
  140. * {
  141. * [banid] => 110
  142. * }
  143. * </pre>
  144. *
  145. * @author Stefan Zehnpfennig
  146. * @param string $uid clientUniqueId
  147. * @param integer $time bantime in seconds (0=unlimited/default) [optional]
  148. * @param string $banreason Banreason [optional]
  149. * @return array banId
  150. */
  151. function banAddByUid($uid, $time = 0, $banreason = NULL) {
  152. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  153.  
  154. if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
  155.  
  156. return $this->getData('array', 'banadd uid='.$uid.' time='.$time.$msg);
  157. }
  158.  
  159. /**
  160. * banAddByName
  161. *
  162. * Adds a new ban rule on the selected virtual server.
  163. *
  164. * <b>Output:</b>
  165. * <pre>
  166. * Array
  167. * {
  168. * [banid] => 111
  169. * }
  170. * </pre>
  171. *
  172. * @author Stefan Zehnpfennig
  173. * @param string $name clientName
  174. * @param integer $time bantime in seconds (0=unlimited/default) [optional]
  175. * @param string $banreason Banreason [optional]
  176. * @return array banId
  177. */
  178. function banAddByName($name, $time = 0, $banreason = NULL) {
  179. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  180.  
  181. if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
  182.  
  183. return $this->getData('array', 'banadd name='.$this->escapeText($name).' time='.$time.$msg);
  184. }
  185.  
  186. /**
  187. * banClient
  188. *
  189. * Bans the client specified with ID clid from the server. Please note that this will create two separate ban rules for the targeted clients IP address and his unique identifier.
  190. *
  191. * <b>Output:</b>
  192. * <pre>
  193. * Array
  194. * {
  195. * [1] => 129
  196. * [2] => 130
  197. * }
  198. * </pre>
  199. *
  200. * @author Stefan Zehnpfennig
  201. * @param integer $clid clientId
  202. * @param integer $time bantime in seconds (0=unlimited/default) [optional]
  203. * @param string $banreason Banreason [optional]
  204. * @return array banIds
  205. */
  206. function banClient($clid, $time = 0, $banreason = NULL) {
  207. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  208.  
  209. if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = ''; }
  210.  
  211. $result = $this->getData('plain', 'banclient clid='.$clid.' time='.$time.$msg);
  212.  
  213. if($result['success']) {
  214. return $this->generateOutput(true, $result['errors'], $this->splitBanIds($result['data']));
  215. }else{
  216. return $this->generateOutput(false, $result['errors'], false);
  217. }
  218. }
  219.  
  220. /**
  221. * banDelete
  222. *
  223. * Deletes the ban rule with ID banid from the server.
  224. *
  225. * @author Stefan Zehnpfennig
  226. * @param integer $banID banID
  227. * @return boolean success
  228. */
  229. function banDelete($banID) {
  230. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  231. return $this->getData('boolean', 'bandel banid='.$banID);
  232. }
  233.  
  234. /**
  235. * banDeleteAll
  236. *
  237. * Deletes all active ban rules from the server.
  238. *
  239. * @author Stefan Zehnpfennig
  240. * @return boolean success
  241. */
  242. function banDeleteAll() {
  243. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  244. return $this->getData('boolean', 'bandelall');
  245. }
  246.  
  247. /**
  248. * banList
  249. *
  250. * Displays a list of active bans on the selected virtual server.
  251. *
  252. * <b>Output:</b>
  253. * <pre>
  254. * Array
  255. * {
  256. * [banid] => 131
  257. * [ip] => 1.2.3.4
  258. * [name] => eugen
  259. * [uid] => IYAntAcZHgVC7s3n3DNWmuJB/aM=
  260. * [created] => 1286660391
  261. * [duration] => 0
  262. * [invokername] => Par0noid
  263. * [invokercldbid] => 2086
  264. * [invokeruid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  265. * [reason] => insult
  266. * [enforcements] => 0
  267. * }
  268. * </pre>
  269. *
  270. * @author Stefan Zehnpfennig
  271. * @return array banlist
  272. */
  273. function banList() {
  274. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  275. return $this->getData('multi', 'banlist');
  276. }
  277.  
  278. /**
  279. * bindingList
  280. *
  281. * Displays a list of IP addresses used by the server instance on multi-homed machines.
  282. *
  283. * <b>Output:</b>
  284. * <pre>
  285. * Array
  286. * {
  287. * [ip] => 0.0.0.0
  288. * }
  289. * </pre>
  290. *
  291. * @author Stefan Zehnpfennig
  292. * @param integer $subsystem (1: voice, 2: query, 3: filetransfer)
  293. * @return array bindingList
  294. */
  295. function bindingList($subsystem = 0) {
  296. return $this->getData('multi', 'bindinglist'.($subsystem == 1 ? ' subsystem=voice' : '').($subsystem == 2 ? ' subsystem=query' : '').($subsystem == 3 ? ' subsystem=filetransfer' : ''));
  297. }
  298.  
  299. /**
  300. * channelAddPerm
  301. *
  302. * Adds a set of specified permissions to a channel. Multiple permissions can be added by providing the two parameters of each permission. A permission can be specified by permid or permsid.
  303. *
  304. * <b>Input-Array like this:</b>
  305. * <pre>
  306. * $permissions = array();
  307. * $permissions['permissionID'] = 'permissionValue';
  308. * //or you could use Permission Name
  309. * $permissions['permissionName'] = 'permissionValue';
  310. * </pre>
  311. *
  312. * @author Stefan Zehnpfennig
  313. * @param integer $cid channelId
  314. * @param array $permissions permissions
  315. * @return boolean success
  316. */
  317. function channelAddPerm($cid, $permissions) {
  318. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  319.  
  320. if(count($permissions) > 0) {
  321. //Permissions given
  322.  
  323. //Errorcollector
  324. $errors = array();
  325.  
  326. //Split Permissions to prevent query from overload
  327. $permissions = array_chunk($permissions, 50, true);
  328.  
  329. //Action for each splitted part of permission
  330. foreach($permissions as $permission_part)
  331. {
  332. //Create command_string for each command that we could use implode later
  333. $command_string = array();
  334.  
  335. foreach($permission_part as $key => $value)
  336. {
  337. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
  338. }
  339.  
  340. $result = $this->getData('boolean', 'channeladdperm cid='.$cid.' '.implode('|', $command_string));
  341.  
  342. if(!$result['success'])
  343. {
  344. foreach($result['errors'] as $error)
  345. {
  346. $errors[] = $error;
  347. }
  348. }
  349. }
  350.  
  351. if(count($errors) == 0)
  352. {
  353. return $this->generateOutput(true, array(), true);
  354. }else{
  355. return $this->generateOutput(false, $errors, false);
  356. }
  357.  
  358. }else{
  359. // No permissions given
  360. $this->addDebugLog('no permissions given');
  361. return $this->generateOutput(false, array('Error: no permissions given'), false);
  362. }
  363. }
  364.  
  365. /**
  366. * channelClientAddPerm
  367. *
  368. * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by providing the three parameters of each permission. A permission can be specified by permid or permsid.
  369. *
  370. * <b>Input-Array like this:</b>
  371. * <pre>
  372. * $permissions = array();
  373. * $permissions['permissionID'] = 'permissionValue';
  374. * //or you could use Permission Name
  375. * $permissions['permissionName'] = 'permissionValue';
  376. * </pre>
  377. *
  378. * @author Stefan Zehnpfennig
  379. * @param integer $cid channelID
  380. * @param integer $cldbid clientDBID
  381. * @param array $permissions permissions
  382. * @return boolean success
  383. */
  384. function channelClientAddPerm($cid, $cldbid, $permissions) {
  385. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  386.  
  387. if(count($permissions) > 0) {
  388. //Permissions given
  389.  
  390. //Errorcollector
  391. $errors = array();
  392.  
  393. //Split Permissions to prevent query from overload
  394. $permissions = array_chunk($permissions, 50, true);
  395.  
  396. //Action for each splitted part of permission
  397. foreach($permissions as $permission_part)
  398. {
  399. //Create command_string for each command that we could use implode later
  400. $command_string = array();
  401.  
  402. foreach($permission_part as $key => $value)
  403. {
  404. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
  405. }
  406.  
  407. $result = $this->getData('boolean', 'channelclientaddperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $command_string));
  408.  
  409. if(!$result['success'])
  410. {
  411. foreach($result['errors'] as $error)
  412. {
  413. $errors[] = $error;
  414. }
  415. }
  416. }
  417.  
  418. if(count($errors) == 0)
  419. {
  420. return $this->generateOutput(true, array(), true);
  421. }else{
  422. return $this->generateOutput(false, $errors, false);
  423. }
  424.  
  425. }else{
  426. // No permissions given
  427. $this->addDebugLog('no permissions given');
  428. return $this->generateOutput(false, array('Error: no permissions given'), false);
  429. }
  430. }
  431.  
  432. /**
  433. * channelClientDelPerm
  434. *
  435. * Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
  436. *
  437. * <b>Input-Array like this:</b>
  438. * <pre>
  439. * $permissions = array();
  440. * $permissions[] = 'permissionID';
  441. * $permissions[] = 'permissionName';
  442. * //or
  443. * $permissions = array('permissionID', 'permissionName', 'permissionID');
  444. * </pre>
  445. *
  446. * @author Stefan Zehnpfennig
  447. * @param integer $cid channelID
  448. * @param integer $cldbid clientDBID
  449. * @param array $permissions permissions
  450. * @return boolean success
  451. */
  452. function channelClientDelPerm($cid, $cldbid, $permissions) {
  453. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  454. $permissionArray = array();
  455.  
  456. if(count($permissions) > 0) {
  457. foreach($permissions AS $value) {
  458. $permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$value;
  459. }
  460. return $this->getData('boolean', 'channelclientdelperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $permissionArray));
  461. }else{
  462. $this->addDebugLog('no permissions given');
  463. return $this->generateOutput(false, array('Error: no permissions given'), false);
  464. }
  465. }
  466.  
  467. /**
  468. * channelClientPermList
  469. *
  470. * Displays a list of permissions defined for a client in a specific channel.
  471. *
  472. * <b>Output:</b>
  473. * <pre>
  474. * Array
  475. * {
  476. * [cid] => 250 (only in first result)
  477. * [cldbid] => 2086 (only in first result)
  478. * [permid] => 12876 (if permsid = false)
  479. * [permsid] => b_client_info_view (if permsid = true)
  480. * [permvalue] => 1
  481. * [permnegated] => 0
  482. * [permskip] => 0
  483. * }
  484. * </pre>
  485. *
  486. * @author Stefan Zehnpfennig
  487. * @param integer $cid channelID
  488. * @param integer $cldbid clientDBID
  489. * @param boolean $permsid displays permissionName instead of permissionID
  490. * @return array channelclientpermlist
  491. */
  492. function channelClientPermList($cid, $cldbid, $permsid = false) {
  493. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  494. return $this->getData('multi', 'channelclientpermlist cid='.$cid.' cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
  495. }
  496.  
  497. /**
  498. * channelCreate
  499. *
  500. * Creates a new channel using the given properties and displays its ID. Note that this command accepts multiple properties which means that you're able to specifiy all settings of the new channel at once.
  501. *
  502. * <b style="color:red">Hint:</b> don't forget to set channel_flag_semi_permanent = 1 or channel_flag_permanent = 1
  503. *
  504. * <b style="color:red">Hint:</b> you'll get an error if you want to create a channel without channel_name
  505. *
  506. * <b style="color:red">Hint:</b> to set the parent channel you've to use cpid instead of pid
  507. *
  508. * <b>Input-Array like this:</b>
  509. * <pre>
  510. * $data = array();
  511. *
  512. * $data['setting'] = 'value';
  513. * $data['setting'] = 'value';
  514. * </pre>
  515. *
  516. * <b>Output:</b>
  517. * <pre>
  518. * Array
  519. * {
  520. * [cid] => 257
  521. * }
  522. * </pre>
  523. *
  524. * <b>Possible properties:</b> CHANNEL_NAME, CHANNEL_TOPIC, CHANNEL_DESCRIPTION, CHANNEL_PASSWORD, CHANNEL_CODEC, CHANNEL_CODEC_QUALITY, CHANNEL_MAXCLIENTS, CHANNEL_MAXFAMILYCLIENTS, CHANNEL_ORDER, CHANNEL_FLAG_PERMANENT, CHANNEL_FLAG_SEMI_PERMANENT, CHANNEL_FLAG_TEMPORARY, CHANNEL_FLAG_DEFAULT, CHANNEL_FLAG_MAXCLIENTS_UNLIMITED, CHANNEL_FLAG_MAXFAMILYCLIENTS_UNLIMITED, CHANNEL_FLAG_MAXFAMILYCLIENTS_INHERITED, CHANNEL_NEEDED_TALK_POWER, CHANNEL_NAME_PHONETIC, CHANNEL_ICON_ID, CHANNEL_CODEC_IS_UNENCRYPTED, CPID
  525. *
  526. * @author Stefan Zehnpfennig
  527. * @param array $data properties
  528. * @return array channelInfo
  529. */
  530. function channelCreate($data) {
  531. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  532.  
  533. $propertiesString = '';
  534.  
  535. foreach($data as $key => $value) {
  536. $propertiesString .= ' '.strtolower($key).'='.$this->escapeText($value);
  537. }
  538.  
  539. return $this->getData('array', 'channelcreate '.$propertiesString);
  540. }
  541.  
  542. /**
  543. * channelDelete
  544. *
  545. * Deletes an existing channel by ID. If force is set to 1, the channel will be deleted even if there are clients within. The clients will be kicked to the default channel with an appropriate reason message.
  546. *
  547. * @author Stefan Zehnpfennig
  548. * @param integer $cid channelID
  549. * @param integer $force {1|0} (default: 1)
  550. * @return boolean success
  551. */
  552. function channelDelete($cid, $force = 1) {
  553. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  554. return $this->getData('boolean', 'channeldelete cid='.$cid.' force='.$force);
  555. }
  556.  
  557. /**
  558. * channelDelPerm
  559. *
  560. * Removes a set of specified permissions from a channel. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
  561. *
  562. * <b>Input-Array like this:</b>
  563. * <pre>
  564. * $permissions = array();
  565. * $permissions[] = 'permissionID';
  566. * //or you could use
  567. * $permissions[] = 'permissionName';
  568. * </pre>
  569. *
  570. * @author Stefan Zehnpfennig
  571. * @param integer $cid channelID
  572. * @param array $permissions permissions
  573. * @return boolean success
  574. */
  575. function channelDelPerm($cid, $permissions) {
  576. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  577. $permissionArray = array();
  578.  
  579. if(count($permissions) > 0) {
  580. foreach($permissions AS $value) {
  581. $permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
  582. }
  583. return $this->getData('boolean', 'channeldelperm cid='.$cid.' '.implode('|', $permissionArray));
  584. }else{
  585. $this->addDebugLog('no permissions given');
  586. return $this->generateOutput(false, array('Error: no permissions given'), false);
  587. }
  588. }
  589.  
  590. /**
  591. * channelEdit
  592. *
  593. * Changes a channels configuration using given properties. Note that this command accepts multiple properties which means that you're able to change all settings of the channel specified with cid at once.
  594. *
  595. * <b>Input-Array like this:</b>
  596. <pre>
  597. $data = array();
  598.  
  599. $data['setting'] = 'value';
  600. $data['setting'] = 'value';
  601. </pre>
  602. *
  603. * <b>Possible properties:</b> Take a look at channelCreate function
  604. *
  605. * @author Stefan Zehnpfennig
  606. * @param integer $cid $channelID
  607. * @param array $data edited settings
  608. * @return boolean success
  609. */
  610. function channelEdit($cid, $data) {
  611. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  612.  
  613. $settingsString = '';
  614.  
  615. foreach($data as $key => $value) {
  616. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value);
  617. }
  618.  
  619. return $this->getData('boolean', 'channeledit cid='.$cid.$settingsString);
  620. }
  621.  
  622. /**
  623. * channelFind
  624. *
  625. * displays a list of channels matching a given name pattern.
  626. *
  627. * <b>Output:</b>
  628. * <pre>
  629. * Array
  630. * {
  631. * [cid] => 2
  632. * [channel_name] => Lobby
  633. * }
  634. * </pre>
  635. *
  636. * @author Stefan Zehnpfennig
  637. * @param string $pattern channelName
  638. * @return array channelList
  639. */
  640. function channelFind($pattern) {
  641. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  642. return $this->getData('multi', 'channelfind pattern='.$this->escapeText($pattern));
  643. }
  644.  
  645. /**
  646. * channelGetIconByChannelID
  647. *
  648. * Will return the base64 encoded binary of the channelIcon
  649. *
  650. * <pre>
  651. * $result = $tsAdmin->channelGetIconByChannelID($channelID);
  652. * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
  653. * </pre>
  654. *
  655. * @author Stefan Zehnpfennig
  656. * @param string $channelID channelID
  657. * @return array base64 image
  658. */
  659. function channelGetIconByChannelID($channelID) {
  660. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  661.  
  662. if(empty($channelID))
  663. {
  664. return $this->generateOutput(false, array('Error: empty channelID'), false);
  665. }
  666.  
  667. $channel = $this->channelInfo($channelID);
  668.  
  669. if(!$channel["success"])
  670. {
  671. return $this->generateOutput(false, $channel["error"], false);
  672. }
  673.  
  674. return $this->getIconByID($channel["data"]["channel_icon_id"]);
  675. }
  676.  
  677. /**
  678. * channelGroupAdd
  679. *
  680. * Creates a new channel group using a given name and displays its ID. The optional type parameter can be used to create ServerQuery groups and template groups.
  681. *
  682. * <b>groupDbTypes:</b>
  683. * <ol start="0">
  684. * <li>template group (used for new virtual servers)</li>
  685. * <li>regular group (used for regular clients)</li>
  686. * <li>global query group (used for ServerQuery clients)</li>
  687. * </ol>
  688. *
  689. * <b>Output:</b>
  690. * <pre>
  691. * Array
  692. * {
  693. * [cgid] => 86
  694. * }
  695. * </pre>
  696. *
  697. * @author Stefan Zehnpfennig
  698. * @param integer $name groupName
  699. * @param integer $type groupDbType [optional] (default: 1)
  700. * @return boolean success
  701. */
  702. function channelGroupAdd($name, $type = 1) {
  703. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  704. return $this->getData('array', 'channelgroupadd name='.$this->escapeText($name).' type='.$type);
  705. }
  706.  
  707. /**
  708. * channelGroupAddClient
  709. *
  710. * Sets the channel group of a client to the ID specified with cgid.
  711. *
  712. * @author Stefan Zehnpfennig
  713. * @param integer $cgid groupID
  714. * @param integer $cid channelID
  715. * @param integer $cldbid clientDBID
  716. * @return boolean success
  717. */
  718. function channelGroupAddClient($cgid, $cid, $cldbid) {
  719. return $this->setclientchannelgroup($cgid, $cid, $cldbid);
  720. }
  721.  
  722. /**
  723. * channelGroupAddPerm
  724. *
  725. * Adds a set of specified permissions to a channel group. Multiple permissions can be added by providing the two parameters of each permission. A permission can be specified by permid or permsid.
  726. *
  727. * <b>Input-Array like this:</b>
  728. * <pre>
  729. * $permissions = array();
  730. * $permissions['permissionID'] = 'permissionValue';
  731. * //or you could use:
  732. * $permissions['permissionName'] = 'permissionValue';
  733. * </pre>
  734. *
  735. * @author Stefan Zehnpfennig
  736. * @param integer $cgid channelGroupID
  737. * @param array $permissions permissions
  738. * @return boolean success
  739. */
  740. function channelGroupAddPerm($cgid, $permissions) {
  741. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  742.  
  743. if(count($permissions) > 0) {
  744. //Permissions given
  745.  
  746. //Errorcollector
  747. $errors = array();
  748.  
  749. //Split Permissions to prevent query from overload
  750. $permissions = array_chunk($permissions, 50, true);
  751.  
  752. //Action for each splitted part of permission
  753. foreach($permissions as $permission_part)
  754. {
  755. //Create command_string for each command that we could use implode later
  756. $command_string = array();
  757.  
  758. foreach($permission_part as $key => $value)
  759. {
  760. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
  761. }
  762.  
  763. $result = $this->getData('boolean', 'channelgroupaddperm cgid='.$cgid.' '.implode('|', $command_string));
  764.  
  765. if(!$result['success'])
  766. {
  767. foreach($result['errors'] as $error)
  768. {
  769. $errors[] = $error;
  770. }
  771. }
  772. }
  773.  
  774. if(count($errors) == 0) {
  775. return $this->generateOutput(true, array(), true);
  776. }else{
  777. return $this->generateOutput(false, $errors, false);
  778. }
  779.  
  780. }else{
  781. // No permissions given
  782. $this->addDebugLog('no permissions given');
  783. return $this->generateOutput(false, array('Error: no permissions given'), false);
  784. }
  785. }
  786.  
  787. /**
  788. * channelGroupClientList
  789. *
  790. * Displays all the client and/or channel IDs currently assigned to channel groups. All three parameters are optional so you're free to choose the most suitable combination for your requirement
  791. *
  792. * <b>Output:</b>
  793. * <pre>
  794. * Array
  795. * {
  796. * [cid] => 2
  797. * [cldbid] => 9
  798. * [cgid] => 9
  799. * }
  800. * </pre>
  801. *
  802. * @author Stefan Zehnpfennig
  803. * @param integer $cid channelID [optional]
  804. * @param integer $cldbid clientDBID [optional]
  805. * @param integer $cgid channelGroupID [optional]
  806. * @return array channelGroupClientList
  807. */
  808. function channelGroupClientList($cid = NULL, $cldbid = NULL, $cgid = NULL) {
  809. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  810.  
  811. return $this->getData('multi', 'channelgroupclientlist'.(!empty($cid) ? ' cid='.$cid : '').(!empty($cldbid) ? ' cldbid='.$cldbid : '').(!empty($cgid) ? ' cgid='.$cgid : ''));
  812. }
  813.  
  814. /**
  815. * channelGroupCopy
  816. *
  817. * Creates a copy of the channel group specified with scgid. If tcgid is set to 0, the server will create a new group. To overwrite an existing group, simply set tcgid to the ID of a designated target group. If a target group is set, the name parameter will be ignored. The type parameter can be used to create ServerQuery groups and template groups.
  818. *
  819. * <b>groupDbTypes:</b>
  820. * <ol start="0">
  821. * <li>template group (used for new virtual servers)</li>
  822. * <li>regular group (used for regular clients)</li>
  823. * <li>global query group (used for ServerQuery clients)</li>
  824. * </ol>
  825. *
  826. * <b>Output:</b>
  827. * <pre>
  828. * Array
  829. * {
  830. * [cgid] => 86
  831. * }
  832. * </pre>
  833. *
  834. * @author Stefan Zehnpfennig
  835. * @param integer $scgid sourceChannelGroupID
  836. * @param integer $tcgid targetChannelGroupID
  837. * @param integer $name groupName
  838. * @param integer $type groupDbType
  839. * @return array groupId
  840. */
  841. function channelGroupCopy($scgid, $tcgid, $name, $type = 1) {
  842. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  843. return $this->getData('array', 'channelgroupcopy scgid='.$scgid.' tcgid='.$tcgid.' name='.$this->escapeText($name).' type='.$type);
  844. }
  845.  
  846. /**
  847. * channelGroupDelete
  848. *
  849. * Deletes a channel group by ID. If force is set to 1, the channel group will be deleted even if there are clients within.
  850. *
  851. * @author Stefan Zehnpfennig
  852. * @param integer $cgid channelGroupID
  853. * @param integer $force forces deleting channelGroup (default: 1)
  854. * @return boolean success
  855. */
  856. function channelGroupDelete($cgid, $force = 1) {
  857. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  858. return $this->getData('boolean', 'channelgroupdel cgid='.$cgid.' force='.$force);
  859. }
  860.  
  861. /**
  862. * channelGroupDelPerm
  863. *
  864. * Removes a set of specified permissions from the channel group. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
  865. *
  866. * <b>Input-Array like this:</b>
  867. * <pre>
  868. * $permissions = array();
  869. * $permissions[] = 'permissionID';
  870. * $permissions[] = 'permissionName';
  871. * </pre>
  872. *
  873. * @author Stefan Zehnpfennig
  874. * @param integer $cgid channelGroupID
  875. * @param array $permissions permissions
  876. * @return boolean success
  877. */
  878. function channelGroupDelPerm($cgid, $permissions) {
  879. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  880. $permissionArray = array();
  881.  
  882. if(count($permissions) > 0) {
  883. foreach($permissions AS $value) {
  884. $permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
  885. }
  886. return $this->getData('boolean', 'channelgroupdelperm cgid='.$cgid.' '.implode('|', $permissionArray));
  887. }else{
  888. $this->addDebugLog('no permissions given');
  889. return $this->generateOutput(false, array('Error: no permissions given'), false);
  890. }
  891. }
  892.  
  893. /**
  894. * channelGroupGetIconByCGID
  895. *
  896. * Will return the base64 encoded binary of the channelGroupIcon
  897. *
  898. * <pre>
  899. * $result = $tsAdmin->channelGroupGetIconByCGID($channelGroupID);
  900. * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
  901. * </pre>
  902. *
  903. * @author Stefan Zehnpfennig
  904. * @param string $channelGroupID channelGroupID
  905. * @return array base64 image
  906. */
  907. function channelGroupGetIconByCGID($channelGroupID) {
  908. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  909.  
  910. if(empty($channelGroupID))
  911. {
  912. return $this->generateOutput(false, array('Error: empty channelGroupID'), false);
  913. }
  914.  
  915. $channelGroupList = $this->channelGroupList();
  916.  
  917. if(!$channelGroupList["success"])
  918. {
  919. return $this->generateOutput(false, $channelGroupList["error"], false);
  920. }
  921.  
  922. $cgid = -1;
  923. $iconID = 0;
  924.  
  925. foreach($channelGroupList['data'] as $group)
  926. {
  927. if($group['cgid'] == $channelGroupID)
  928. {
  929. $cgid = $group['cgid'];
  930. $iconID = $group['iconid'];
  931. break;
  932. }
  933. }
  934.  
  935. if($cgid == -1)
  936. {
  937. return $this->generateOutput(false, array('Error: invalid channelGroupID'), false);
  938. }
  939.  
  940. if($iconID == '0')
  941. {
  942. return $this->generateOutput(false, array('Error: channelGroup has no icon'), false);
  943. }
  944.  
  945. return $this->getIconByID($iconID);
  946. }
  947.  
  948. /**
  949. * channelGroupList
  950. *
  951. * Displays a list of channel groups available on the selected virtual server.
  952. *
  953. * <b>Output:</b>
  954. * <pre>
  955. * Array
  956. * {
  957. * [cgid] => 3
  958. * [name] => Testname
  959. * [type] => 0
  960. * [iconid] => 100
  961. * [savedb] => 1
  962. * [sortid] => 0
  963. * [namemode] => 0
  964. * [n_modifyp] => 75
  965. * [n_member_addp] => 50
  966. * [n_member_removep] => 50
  967. * }
  968. * </pre>
  969. *
  970. * @author Stefan Zehnpfennig
  971. * @return array channelGroupList
  972. */
  973. function channelGroupList() {
  974. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  975.  
  976. return $this->getData('multi', 'channelgrouplist');
  977. }
  978.  
  979. /**
  980. * channelGroupPermList
  981. *
  982. * Displays a list of permissions assigned to the channel group specified with cgid.
  983. * If the permsid option is specified, the output will contain the permission names instead of the internal IDs.
  984. *
  985. * <b>Output:</b>
  986. * <pre>
  987. * Array
  988. * {
  989. * [permid] => 8471 (displayed if permsid is false)
  990. * [permsid] => i_channel_create_modify_with_codec_latency_factor_min (displayed if permsid is true)
  991. * [permvalue] => 1
  992. * [permnegated] => 0
  993. * [permskip] => 0
  994. * }
  995. * </pre>
  996. *
  997. * @author Stefan Zehnpfennig
  998. * @param integer $cgid channelGroupID
  999. * @param boolean $permsid permsid
  1000. * @return array channelGroupPermlist
  1001. */
  1002. function channelGroupPermList($cgid, $permsid = false) {
  1003. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1004. return $this->getData('multi', 'channelgrouppermlist cgid='.$cgid.($permsid ? ' -permsid' : ''));
  1005. }
  1006.  
  1007. /**
  1008. * channelGroupRename
  1009. *
  1010. * Changes the name of a specified channel group.
  1011. *
  1012. * @author Stefan Zehnpfennig
  1013. * @param integer $cgid groupID
  1014. * @param integer $name groupName
  1015. * @return boolean success
  1016. */
  1017. function channelGroupRename($cgid, $name) {
  1018. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1019. return $this->getData('boolean', 'channelgrouprename cgid='.$cgid.' name='.$this->escapeText($name));
  1020. }
  1021.  
  1022. /**
  1023. * channelInfo
  1024. *
  1025. * Displays detailed configuration information about a channel including ID, topic, description, etc.
  1026.  
  1027. * <b>Output:</b>
  1028. * <pre>
  1029. * Array
  1030. * {
  1031. * [pid] => 0
  1032. * [channel_name] => Test
  1033. * [channel_topic] =>
  1034. * [channel_description] =>
  1035. * [channel_password] => cc97Pm4oOYq0J9fXDAgiWv/qScQ=
  1036. * [channel_codec] => 2
  1037. * [channel_codec_quality] => 7
  1038. * [channel_maxclients] => -1
  1039. * [channel_maxfamilyclients] => -1
  1040. * [channel_order] => 1
  1041. * [channel_flag_permanent] => 1
  1042. * [channel_flag_semi_permanent] => 0
  1043. * [channel_flag_default] => 0
  1044. * [channel_flag_password] => 0
  1045. * [channel_codec_latency_factor] => 1
  1046. * [channel_codec_is_unencrypted] => 1
  1047. * [channel_security_salt] =>
  1048. * [channel_delete_delay] => 0
  1049. * [channel_flag_maxclients_unlimited] => 1
  1050. * [channel_flag_maxfamilyclients_unlimited] => 0
  1051. * [channel_flag_maxfamilyclients_inherited] => 1
  1052. * [channel_filepath] => files\\virtualserver_1\\channel_2
  1053. * [channel_needed_talk_power] => 0
  1054. * [channel_forced_silence] => 0
  1055. * [channel_name_phonetic] =>
  1056. * [channel_icon_id] => 0
  1057. * [channel_flag_private] => 0
  1058. * [seconds_empty] => 61 (If it's a temporary channel with a channel delete delay)
  1059. * }
  1060. * </pre>
  1061. *
  1062. * @author Stefan Zehnpfennig
  1063. * @param integer $cid channelID
  1064. * @return array channelInfo
  1065. */
  1066. function channelInfo($cid) {
  1067. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1068. return $this->getData('array', 'channelinfo cid='.$cid);
  1069. }
  1070.  
  1071. /**
  1072. * channelClientList
  1073. *
  1074. * Displays a list of clients online on a virtual server in a specific channel including their ID, nickname, status flags, etc. The output can be modified using several command options. Please note that the output will only contain clients which are currently in channels you're able to subscribe to.
  1075. *
  1076. * <b>Possible params:</b> [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country] [-ip] [-badges]
  1077. *
  1078. * <b>Output:</b>
  1079. * <pre>
  1080. * Array
  1081. * {
  1082. * [clid] => 1
  1083. * [cid] => 3
  1084. * [client_database_id] => 2
  1085. * [client_nickname] => Par0noid
  1086. * [client_type] => 0
  1087. * [-uid] => [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1088. * [-away] => [client_away] => 0
  1089. * [-away] => [client_away_message] =>
  1090. * [-voice] => [client_flag_talking] => 0
  1091. * [-voice] => [client_input_muted] => 0
  1092. * [-voice] => [client_output_muted] => 0
  1093. * [-voice] => [client_input_hardware] => 0
  1094. * [-voice] => [client_output_hardware] => 0
  1095. * [-voice] => [client_talk_power] => 0
  1096. * [-voice] => [client_is_talker] => 0
  1097. * [-voice] => [client_is_priority_speaker] => 0
  1098. * [-voice] => [client_is_recording] => 0
  1099. * [-voice] => [client_is_channel_commander] => 0
  1100. * [-times] => [client_idle_time] => 1714
  1101. * [-times] => [client_created] => 1361027850
  1102. * [-times] => [client_lastconnected] => 1361042955
  1103. * [-groups] => [client_servergroups] => 6,7
  1104. * [-groups] => [client_channel_group_id] => 8
  1105. * [-groups] => [client_channel_group_inherited_channel_id] => 1
  1106. * [-info] => [client_version] => 3.0.9.2 [Build: 1351504843]
  1107. * [-info] => [client_platform] => Windows
  1108. * [-icon] => [client_icon_id] => 0
  1109. * [-country] => [client_country] =>
  1110. * [-ip] => [connection_client_ip] => 127.0.0.1
  1111. * [-badges] => [client_badges] => Overwolf=0
  1112. * }
  1113. *
  1114. * <b>Usage:</b>
  1115. *
  1116. * $ts3->channelClientList(3); //No parameters
  1117. * $ts3->channelClientList(3, "-uid"); //Single parameter
  1118. * $ts3->channelClientList(3, "-uid -away -voice -times -groups -info -country -icon -ip -badges"); //Multiple parameters
  1119. * </pre>
  1120. *
  1121. * @author Stefan Zehnpfennig
  1122. * @param string $cid channelID
  1123. * @param string $params additional parameters [optional]
  1124. * @return array clientList
  1125. */
  1126. function channelClientList($cid, $params = null) {
  1127. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1128.  
  1129. if(!empty($params)) { $params = ' '.$params; }
  1130.  
  1131. $result = $this->getData('multi', 'clientlist'.$params);
  1132.  
  1133. if($result['success'])
  1134. {
  1135. $clients = array();
  1136.  
  1137. if(count($result['data']) > 0)
  1138. {
  1139. foreach($result['data'] as $client)
  1140. {
  1141. if($client['cid'] == $cid)
  1142. {
  1143. $clients[] = $client;
  1144. }
  1145. }
  1146. }
  1147.  
  1148. return $this->generateOutput(true, null, $clients);
  1149. }
  1150. else
  1151. {
  1152. return $result;
  1153. }
  1154. }
  1155.  
  1156. /**
  1157. * channelList
  1158. *
  1159. * Displays a list of channels created on a virtual server including their ID, order, name, etc. The output can be modified using several command options.
  1160. *
  1161. * <b>Possible parameters:</b> [-topic] [-flags] [-voice] [-limits] [-icon] [-seconds_empty]
  1162. *
  1163. * <b>Output: (without parameters)</b>
  1164. * <pre>
  1165. * Array
  1166. * {
  1167. * [cid] => 2
  1168. * [pid] => 0
  1169. * [channel_order] => 1
  1170. * [channel_name] => Test
  1171. * [total_clients] => 0
  1172. * [channel_needed_subscribe_power] => 0
  1173. * }
  1174. * </pre>
  1175. * <b>Output: (from parameters)</b>
  1176. * <pre>
  1177. * Array
  1178. * {
  1179. * [-topic] => [channel_topic] => Default Channel has no topic
  1180. * [-flags] => [channel_flag_default] => 1
  1181. * [-flags] => [channel_flag_password] => 0
  1182. * [-flags] => [channel_flag_permanent] => 1
  1183. * [-flags] => [channel_flag_semi_permanent] => 0
  1184. * [-voice] => [channel_codec] => 2
  1185. * [-voice] => [channel_codec_quality] => 7
  1186. * [-voice] => [channel_needed_talk_power] => 0
  1187. * [-limits] => [total_clients_family] => 1
  1188. * [-limits] => [channel_maxclients] => -1
  1189. * [-limits] => [channel_maxfamilyclients] => -1
  1190. * [-icon] => [channel_icon_id] => 0
  1191. * [-seconds_empty] => [seconds_empty] => -1
  1192. * }
  1193. * </pre>
  1194. * <b>Usage:</b>
  1195. * <pre>
  1196. * $ts3->channelList(); //No parameters
  1197. * $ts3->channelList("-flags"); //Single parameter
  1198. * $ts3->channelList("-topic -flags -voice -limits -icon"); //Multiple parameters / all
  1199. * </pre>
  1200. *
  1201. * @author Stefan Zehnpfennig
  1202. * @param string $params additional parameters [optional]
  1203. * @return array channelList
  1204. */
  1205. function channelList($params = null) {
  1206. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1207. if(!empty($params)) { $params = ' '.$params; }
  1208.  
  1209. return $this->getData('multi', 'channellist'.$params);
  1210. }
  1211.  
  1212. /**
  1213. * channelMove
  1214. *
  1215. * Moves a channel to a new parent channel with the ID cpid. If order is specified, the channel will be sorted right under the channel with the specified ID. If order is set to 0, the channel will be sorted right below the new parent.
  1216. *
  1217. * @author Stefan Zehnpfennig
  1218. * @param integer $cid channelID
  1219. * @param integer $cpid channelParentID
  1220. * @param integer $order channelSortOrder
  1221. * @return boolean success
  1222. */
  1223. function channelMove($cid, $cpid, $order = null) {
  1224. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1225. return $this->getData('boolean', 'channelmove cid='.$cid.' cpid='.$cpid.($order != null ? ' order='.$order : ''));
  1226. }
  1227.  
  1228. /**
  1229. * channelPermList
  1230. *
  1231. * Displays a list of permissions defined for a channel.
  1232. *
  1233. * <b>Output:</b>
  1234. * <pre>
  1235. * Array
  1236. * {
  1237. * [cid] => 2 (only in first result)
  1238. * [permid] => 8471 (if permsid = false)
  1239. * [permsid] => i_channel_needed_delete_power (if permsid = true)
  1240. * [permvalue] => 1
  1241. * [permnegated] => 0
  1242. * [permskip] => 0
  1243. * }
  1244. * </pre>
  1245. *
  1246. * @author Stefan Zehnpfennig
  1247. * @param integer $cid channelID
  1248. * @param boolean $permsid displays permissionName instead of permissionID [optional]
  1249. * @return array channelpermlist
  1250. */
  1251. function channelPermList($cid, $permsid = false) {
  1252. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1253. return $this->getData('multi', 'channelpermlist cid='.$cid.($permsid ? ' -permsid' : ''));
  1254. }
  1255.  
  1256. /**
  1257. * clientAddPerm
  1258. *
  1259. * Adds a set of specified permissions to a client. Multiple permissions can be added by providing the three parameters of each permission. A permission can be specified by permid or permsid.
  1260. *
  1261. * <b>Input-Array like this:</b>
  1262. * <pre>
  1263. * $permissions = array();
  1264. * $permissions['permissionID'] = array('permissionValue', 'permskip');
  1265. * //or you could use Permission Name
  1266. * $permissions['permissionName'] = array('permissionValue', 'permskip');
  1267. * </pre>
  1268. *
  1269. * @author Stefan Zehnpfennig
  1270. * @param integer $cldbid clientDBID
  1271. * @param array $permissions permissions
  1272. * @return boolean success
  1273. */
  1274. function clientAddPerm($cldbid, $permissions) {
  1275. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1276.  
  1277. if(count($permissions) > 0) {
  1278. //Permissions given
  1279.  
  1280. //Errorcollector
  1281. $errors = array();
  1282.  
  1283. //Split Permissions to prevent query from overload
  1284. $permissions = array_chunk($permissions, 50, true);
  1285.  
  1286. //Action for each splitted part of permission
  1287. foreach($permissions as $permission_part)
  1288. {
  1289. //Create command_string for each command that we could use implode later
  1290. $command_string = array();
  1291.  
  1292. foreach($permission_part as $key => $value)
  1293. {
  1294. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$this->escapeText($value[0]).' permskip='.$this->escapeText($value[1]);
  1295. }
  1296.  
  1297. $result = $this->getData('boolean', 'clientaddperm cldbid='.$cldbid.' '.implode('|', $command_string));
  1298.  
  1299. if(!$result['success'])
  1300. {
  1301. foreach($result['errors'] as $error)
  1302. {
  1303. $errors[] = $error;
  1304. }
  1305. }
  1306. }
  1307.  
  1308. if(count($errors) == 0)
  1309. {
  1310. return $this->generateOutput(true, array(), true);
  1311. }else{
  1312. return $this->generateOutput(false, $errors, false);
  1313. }
  1314. }else{
  1315. // No permissions given
  1316. $this->addDebugLog('no permissions given');
  1317. return $this->generateOutput(false, array('Error: no permissions given'), false);
  1318. }
  1319. }
  1320.  
  1321. /**
  1322. * clientAvatar
  1323. *
  1324. * Will return the base64 encoded binary of the clients avatar
  1325. *
  1326. * <pre>
  1327. * $result = $tsAdmin->clientAvatar($uid);
  1328. * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
  1329. * </pre>
  1330. *
  1331. * @author Stefan Zehnpfennig
  1332. * @param string $uid clientUID
  1333. * @return array base64 image
  1334. */
  1335. function clientAvatar($uid) {
  1336. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1337.  
  1338. if(empty($uid))
  1339. {
  1340. return $this->generateOutput(false, array('Error: empty uid'), false);
  1341. }
  1342.  
  1343. $newChars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
  1344. $auid = '';
  1345.  
  1346. for ($i = 0; $i <= 19; $i++) {
  1347. $char = ord(substr(base64_decode($uid), $i, 1));
  1348. $auid .= $newChars[($char & 0xF0) >> 4];
  1349. $auid .= $newChars[$char & 0x0F];
  1350. }
  1351.  
  1352. $check = $this->ftgetfileinfo(0, '', '/avatar_'.$auid);
  1353.  
  1354. if(!$check["success"])
  1355. {
  1356. return $this->generateOutput(false, array('Error: avatar does not exist'), false);
  1357. }
  1358.  
  1359. $init = $this->ftInitDownload('/avatar_'.$auid, 0, '');
  1360.  
  1361. if(!$init["success"])
  1362. {
  1363. return $this->generateOutput(false, array('Error: init failed'), false);
  1364. }
  1365.  
  1366. $download = $this->ftDownloadFile($init);
  1367.  
  1368. if(is_array($download))
  1369. {
  1370. return $download;
  1371. }else{
  1372. return $this->generateOutput(true, false, base64_encode($download));
  1373. }
  1374.  
  1375. }
  1376.  
  1377. /**
  1378. * clientDbDelete
  1379. *
  1380. * Deletes a clients properties from the database.
  1381. *
  1382. * @author Stefan Zehnpfennig
  1383. * @param integer $cldbid clientDBID
  1384. * @return boolean success
  1385. */
  1386. function clientDbDelete($cldbid) {
  1387. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1388. return $this->getData('boolean', 'clientdbdelete cldbid='.$cldbid);
  1389. }
  1390.  
  1391. /**
  1392. * clientDbEdit
  1393. *
  1394. * Changes a clients settings using given properties.
  1395. *
  1396. * <b>Input-Array like this:</b>
  1397. * <pre>
  1398. * $data = array();
  1399. *
  1400. * $data['property'] = 'value';
  1401. * $data['property'] = 'value';
  1402. * </pre>
  1403. *
  1404. * @author Stefan Zehnpfennig
  1405. * @param integer $cldbid clientDBID
  1406. * @param array $data clientProperties
  1407. * @return boolean success
  1408. */
  1409. function clientDbEdit($cldbid, $data) {
  1410. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1411.  
  1412. $settingsString = '';
  1413.  
  1414. foreach($data as $key => $value) {
  1415. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value);
  1416. }
  1417.  
  1418. return $this->getData('boolean', 'clientdbedit cldbid='.$cldbid.$settingsString);
  1419. }
  1420.  
  1421. /**
  1422. * clientDbFind
  1423. *
  1424. * Displays a list of client database IDs matching a given pattern. You can either search for a clients last known nickname or his unique identity by using the -uid option.
  1425. *
  1426. * <b>Output:</b>
  1427. * <pre>
  1428. * Array
  1429. * {
  1430. * [cldbid] => 2
  1431. * }
  1432. * </pre>
  1433. *
  1434. * @author Stefan Zehnpfennig
  1435. * @param string $pattern clientName
  1436. * @param boolean $uid set true to add -uid param [optional]
  1437. * @return array clientList
  1438. */
  1439. function clientDbFind($pattern, $uid = false) {
  1440. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1441. return $this->getData('multi', 'clientdbfind pattern='.$this->escapeText($pattern).($uid ? ' -uid' : ''));
  1442. }
  1443.  
  1444. /**
  1445. * clientDbInfo
  1446. *
  1447. * Displays detailed database information about a client including unique ID, creation date, etc.
  1448. *
  1449. * <b>Output:</b>
  1450. * <pre>
  1451. * Array
  1452. * {
  1453. * [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1454. * [client_nickname] => par0noid
  1455. * [client_database_id] => 2
  1456. * [client_created] => 1361027850
  1457. * [client_lastconnected] => 1361027850
  1458. * [client_totalconnections] => 1
  1459. * [client_flag_avatar] =>
  1460. * [client_description] =>
  1461. * [client_month_bytes_uploaded] => 0
  1462. * [client_month_bytes_downloaded] => 0
  1463. * [client_total_bytes_uploaded] => 0
  1464. * [client_total_bytes_downloaded] => 0
  1465. * [client_icon_id] => 0
  1466. * [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
  1467. * [client_lastip] => 127.0.0.1
  1468. * }
  1469. * </pre>
  1470. *
  1471. * @author Stefan Zehnpfennig
  1472. * @param integer $cldbid clientDBID
  1473. * @return array clientDbInfo
  1474. */
  1475. function clientDbInfo($cldbid) {
  1476. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1477. return $this->getData('array', 'clientdbinfo cldbid='.$cldbid);
  1478. }
  1479.  
  1480. /**
  1481. * clientDbList
  1482. *
  1483. * Displays a list of client identities known by the server including their database ID, last nickname, etc.
  1484. *
  1485. * <b>Possible params:</b> [start={offset}] [duration={limit}] [-count]
  1486. *
  1487. * <b>Output:</b>
  1488. * <pre>
  1489. * Array
  1490. * {
  1491. * [count] => 1 (if count parameter is set)
  1492. * [cldbid] => 2
  1493. * [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1494. * [client_nickname] => par0noid
  1495. * [client_created] => 1361027850
  1496. * [client_lastconnected] => 1361027850
  1497. * [client_totalconnections] => 1
  1498. * [client_description] =>
  1499. * [client_lastip] => 127.0.0.1
  1500. * }
  1501. * </pre>
  1502. *
  1503. * @author Stefan Zehnpfennig
  1504. * @param integer $start offset [optional] (Default: 0)
  1505. * @param integer $duration limit [optional] (Default: -1)
  1506. * @param boolean $count set true to add -count param [optional]
  1507. * @return array clientdblist
  1508. */
  1509. function clientDbList($start = 0, $duration = -1, $count = false) {
  1510. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1511. return $this->getData('multi', 'clientdblist'.($start != 0 ? ' start='.$start : '').($duration != -1 ? ' duration='.$duration : '').($count ? ' -count' : ''));
  1512. }
  1513.  
  1514. /**
  1515. * clientDelPerm
  1516. *
  1517. * Removes a set of specified permissions from a client. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
  1518. *
  1519. * <b>Input-Array like this:</b>
  1520. * <pre>
  1521. * $permissions = array();
  1522. * $permissions['permissionID'] = 'permissionValue';
  1523. * //or you could use Permission Name
  1524. * $permissions['permissionName'] = 'permissionValue';
  1525. * </pre>
  1526. *
  1527. * @author Stefan Zehnpfennig
  1528. * @param integer $cldbid clientDBID
  1529. * @param array $permissionIds permissionIDs
  1530. * @return boolean success
  1531. */
  1532. function clientDelPerm($cldbid, $permissionIds) {
  1533. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1534.  
  1535. $permissionArray = array();
  1536.  
  1537. if(count($permissionIds) > 0) {
  1538. foreach($permissionIds AS $value) {
  1539. $permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
  1540. }
  1541. return $this->getData('boolean', 'clientdelperm cldbid='.$cldbid.' '.implode('|', $permissionArray));
  1542. }else{
  1543. $this->addDebugLog('no permissions given');
  1544. return $this->generateOutput(false, array('Error: no permissions given'), false);
  1545. }
  1546. }
  1547.  
  1548. /**
  1549. * clientEdit
  1550. *
  1551. * Changes a clients settings using given properties.
  1552. *
  1553. * <b>Input-Array like this:</b>
  1554. * <pre>
  1555. * $data = array();
  1556. *
  1557. * $data['property'] = 'value';
  1558. * $data['property'] = 'value';
  1559. * </pre>
  1560. *
  1561. * <b>Possible properties:</b> CLIENT_NICKNAME, CLIENT_IS_TALKER, CLIENT_DESCRIPTION, CLIENT_IS_CHANNEL_COMMANDER, CLIENT_ICON_ID
  1562. *
  1563. * @author Stefan Zehnpfennig
  1564. * @param integer $clid clientID
  1565. * @param array $data clientProperties
  1566. * @return boolean success
  1567. */
  1568. function clientEdit($clid, $data) {
  1569. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1570.  
  1571. $settingsString = '';
  1572.  
  1573. foreach($data as $key => $value) {
  1574. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value);
  1575. }
  1576.  
  1577. return $this->getData('boolean', 'clientedit clid='.$clid.$settingsString);
  1578. }
  1579.  
  1580. /**
  1581. * clientFind
  1582. *
  1583. * Displays a list of clients matching a given name pattern.
  1584. *
  1585. * <b>Output:</b>
  1586. * <pre>
  1587. * Array
  1588. * {
  1589. * [clid] => 18
  1590. * [client_nickname] => par0noid
  1591. * }
  1592. * </pre>
  1593. *
  1594. * @author Stefan Zehnpfennig
  1595. * @param string $pattern clientName
  1596. * @return array clienList
  1597. */
  1598. function clientFind($pattern) {
  1599. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1600. return $this->getData('multi', 'clientfind pattern='.$this->escapeText($pattern));
  1601. }
  1602.  
  1603. /**
  1604. * clientGetDbIdFromUid
  1605. *
  1606. * Displays the database ID matching the unique identifier specified by cluid.
  1607. *
  1608. * <b>Output:</b>
  1609. * <pre>
  1610. * Array
  1611. * {
  1612. * [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1613. * [cldbid] => 2
  1614. * }
  1615. * </pre>
  1616. *
  1617. * @author Stefan Zehnpfennig
  1618. * @param string $cluid clientUID
  1619. * @return array clientInfo
  1620. */
  1621. function clientGetDbIdFromUid($cluid) {
  1622. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1623. return $this->getData('array', 'clientgetdbidfromuid cluid='.$cluid);
  1624. }
  1625.  
  1626. /**
  1627. * clientGetIds
  1628. *
  1629. * Displays all client IDs matching the unique identifier specified by cluid.
  1630. *
  1631. * <b>Output:</b>
  1632. * <pre>
  1633. * Array
  1634. * {
  1635. * [cluid] => nUixbdf/XakrrmsdffO30R/D8Gc=
  1636. * [clid] => 7
  1637. * [name] => Par0noid
  1638. * }
  1639. * </pre>
  1640. *
  1641. * @author Stefan Zehnpfennig
  1642. * @param string $cluid clientUID
  1643. * @return array clientList
  1644. */
  1645. function clientGetIds($cluid) {
  1646. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1647. return $this->getData('multi', 'clientgetids cluid='.$cluid);
  1648. }
  1649.  
  1650. /**
  1651. * clientGetNameFromDbid
  1652. *
  1653. * Displays the unique identifier and nickname matching the database ID specified by cldbid.
  1654. *
  1655. * <b>Output:</b>
  1656. * <pre>
  1657. * Array
  1658. * {
  1659. * [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1660. * [cldbid] => 2
  1661. * [name] => Par0noid
  1662. * }
  1663. * </pre>
  1664. *
  1665. * @author Stefan Zehnpfennig
  1666. * @param integer $cldbid clientDBID
  1667. * @return array clientInfo
  1668. */
  1669. function clientGetNameFromDbid($cldbid) {
  1670. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1671. return $this->getData('array', 'clientgetnamefromdbid cldbid='.$cldbid);
  1672. }
  1673.  
  1674. /**
  1675. * clientGetNameFromUid
  1676. *
  1677. * Displays the database ID and nickname matching the unique identifier specified by cluid.
  1678. *
  1679. * <b>Output:</b>
  1680. * <pre>
  1681. * Array
  1682. * {
  1683. * [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1684. * [cldbid] => 2
  1685. * [name] => Par0noid
  1686. * }
  1687. * </pre>
  1688. *
  1689. * @author Stefan Zehnpfennig
  1690. * @param string $cluid clientUID
  1691. * @return array clientInfo
  1692. */
  1693. function clientGetNameFromUid($cluid) {
  1694. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1695. return $this->getData('array', 'clientgetnamefromuid cluid='.$cluid);
  1696. }
  1697.  
  1698. /**
  1699. * clientInfo
  1700. *
  1701. * Displays detailed configuration information about a client including unique ID, nickname, client version, etc.
  1702. *
  1703. * <b>Output:</b>
  1704. * <pre>
  1705. * Array
  1706. * {
  1707. * [cid] => 2
  1708. * [client_idle_time] => 4445369
  1709. * [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1710. * [client_nickname] => par0noid
  1711. * [client_version] => 3.0.9.2 [Build: 1351504843]
  1712. * [client_platform] => Windows
  1713. * [client_input_muted] => 1
  1714. * [client_output_muted] => 1
  1715. * [client_outputonly_muted] => 0
  1716. * [client_input_hardware] => 1
  1717. * [client_output_hardware] => 1
  1718. * [client_default_channel] =>
  1719. * [client_meta_data] =>
  1720. * [client_is_recording] => 0
  1721. * [client_version_sign] => ldWL49uDKC3N9uxdgWRMTOzUabc1nBqUiOa+Nal5HvdxJiN4fsTnmmPo5tvglN7WqoVoFfuuKuYq1LzodtEtCg==
  1722. * [client_security_hash] =>
  1723. * [client_login_name] =>
  1724. * [client_database_id] => 2
  1725. * [client_channel_group_id] => 5
  1726. * [client_servergroups] => 6
  1727. * [client_created] => 1361027850
  1728. * [client_lastconnected] => 1361027850
  1729. * [client_totalconnections] => 1
  1730. * [client_away] => 0
  1731. * [client_away_message] =>
  1732. * [client_type] => 0
  1733. * [client_flag_avatar] =>
  1734. * [client_talk_power] => 75
  1735. * [client_talk_request] => 0
  1736. * [client_talk_request_msg] =>
  1737. * [client_description] =>
  1738. * [client_is_talker] => 0
  1739. * [client_month_bytes_uploaded] => 0
  1740. * [client_month_bytes_downloaded] => 0
  1741. * [client_total_bytes_uploaded] => 0
  1742. * [client_total_bytes_downloaded] => 0
  1743. * [client_is_priority_speaker] => 0
  1744. * [client_nickname_phonetic] =>
  1745. * [client_needed_serverquery_view_power] => 75
  1746. * [client_default_token] =>
  1747. * [client_icon_id] => 0
  1748. * [client_is_channel_commander] => 0
  1749. * [client_country] =>
  1750. * [client_channel_group_inherited_channel_id] => 2
  1751. * [client_badges] => Overwolf=0
  1752. * [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
  1753. * [connection_filetransfer_bandwidth_sent] => 0
  1754. * [connection_filetransfer_bandwidth_received] => 0
  1755. * [connection_packets_sent_total] => 12130
  1756. * [connection_bytes_sent_total] => 542353
  1757. * [connection_packets_received_total] => 12681
  1758. * [connection_bytes_received_total] => 592935
  1759. * [connection_bandwidth_sent_last_second_total] => 82
  1760. * [connection_bandwidth_sent_last_minute_total] => 92
  1761. * [connection_bandwidth_received_last_second_total] => 84
  1762. * [connection_bandwidth_received_last_minute_total] => 88
  1763. * [connection_connected_time] => 5908749
  1764. * [connection_client_ip] => 127.0.0.1
  1765. * }
  1766. * </pre>
  1767. *
  1768. * @author Stefan Zehnpfennig
  1769. * @param integer $clid clientID
  1770. * @return array clientInformation
  1771. */
  1772. function clientInfo($clid) {
  1773. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1774. return $this->getData('array', 'clientinfo clid='.$clid);
  1775. }
  1776.  
  1777. /**
  1778. * clientKick
  1779. *
  1780. * Kicks one or more clients specified with clid from their currently joined channel or from the server, depending on reasonid. The reasonmsg parameter specifies a text message sent to the kicked clients. This parameter is optional and may only have a maximum of 40 characters.
  1781. *
  1782. * @author Stefan Zehnpfennig
  1783. * @param integer $clid clientID
  1784. * @param string $kickMode kickMode (server or channel) (Default: server)
  1785. * @param string $kickmsg kick reason [optional]
  1786. * @return boolean success
  1787. */
  1788. function clientKick($clid, $kickMode = "server", $kickmsg = "") {
  1789. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1790.  
  1791. if(in_array($kickMode, array('server', 'channel'))) {
  1792.  
  1793. if($kickMode == 'server') { $from = '5'; }
  1794. if($kickMode == 'channel') { $from = '4'; }
  1795.  
  1796. if(!empty($kickmsg)) { $msg = ' reasonmsg='.$this->escapeText($kickmsg); } else{ $msg = ''; }
  1797.  
  1798. return $this->getData('boolean', 'clientkick clid='.$clid.' reasonid='.$from.$msg);
  1799. }else{
  1800. $this->addDebugLog('invalid kickMode');
  1801. return $this->generateOutput(false, array('Error: invalid kickMode'), false);
  1802. }
  1803. }
  1804.  
  1805. /**
  1806. * clientList
  1807. *
  1808. * Displays a list of clients online on a virtual server including their ID, nickname, status flags, etc. The output can be modified using several command options. Please note that the output will only contain clients which are currently in channels you're able to subscribe to.
  1809. *
  1810. * <b>Possible params:</b> [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country] [-ip] [-badges]
  1811. *
  1812. * <b>Output:</b>
  1813. * <pre>
  1814. * Array
  1815. * {
  1816. * [clid] => 1
  1817. * [cid] => 1
  1818. * [client_database_id] => 2
  1819. * [client_nickname] => Par0noid
  1820. * [client_type] => 0
  1821. * [-uid] => [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  1822. * [-away] => [client_away] => 0
  1823. * [-away] => [client_away_message] =>
  1824. * [-voice] => [client_flag_talking] => 0
  1825. * [-voice] => [client_input_muted] => 0
  1826. * [-voice] => [client_output_muted] => 0
  1827. * [-voice] => [client_input_hardware] => 0
  1828. * [-voice] => [client_output_hardware] => 0
  1829. * [-voice] => [client_talk_power] => 0
  1830. * [-voice] => [client_is_talker] => 0
  1831. * [-voice] => [client_is_priority_speaker] => 0
  1832. * [-voice] => [client_is_recording] => 0
  1833. * [-voice] => [client_is_channel_commander] => 0
  1834. * [-times] => [client_idle_time] => 1714
  1835. * [-times] => [client_created] => 1361027850
  1836. * [-times] => [client_lastconnected] => 1361042955
  1837. * [-groups] => [client_servergroups] => 6,7
  1838. * [-groups] => [client_channel_group_id] => 8
  1839. * [-groups] => [client_channel_group_inherited_channel_id] => 1
  1840. * [-info] => [client_version] => 3.0.9.2 [Build: 1351504843]
  1841. * [-info] => [client_platform] => Windows
  1842. * [-icon] => [client_icon_id] => 0
  1843. * [-country] => [client_country] =>
  1844. * [-ip] => [connection_client_ip] => 127.0.0.1
  1845. * [-badges] => [client_badges] => Overwolf=0
  1846. * }
  1847. *
  1848. * <b>Usage:</b>
  1849. *
  1850. * $ts3->clientList(); //No parameters
  1851. * $ts3->clientList("-uid"); //Single parameter
  1852. * $ts3->clientList("-uid -away -voice -times -groups -info -country -icon -ip -badges"); //Multiple parameters
  1853. * </pre>
  1854. *
  1855. * @author Stefan Zehnpfennig
  1856. * @param string $params additional parameters [optional]
  1857. * @return array clientList
  1858. */
  1859. function clientList($params = null) {
  1860. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1861.  
  1862. if(!empty($params)) { $params = ' '.$params; }
  1863.  
  1864. return $this->getData('multi', 'clientlist'.$params);
  1865. }
  1866.  
  1867. /**
  1868. * clientMove
  1869. *
  1870. * Moves one or more clients specified with clid to the channel with ID cid. If the target channel has a password, it needs to be specified with cpw. If the channel has no password, the parameter can be omitted.
  1871. *
  1872. * @author Stefan Zehnpfennig
  1873. * @param integer $clid clientID
  1874. * @param integer $cid channelID
  1875. * @param string $cpw channelPassword [optional]
  1876. * @return boolean success
  1877. */
  1878. function clientMove($clid, $cid, $cpw = null) {
  1879. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1880. return $this->getData('boolean', 'clientmove clid='.$clid.' cid='.$cid.(!empty($cpw) ? ' cpw='.$this->escapeText($cpw) : ''));
  1881. }
  1882.  
  1883. /**
  1884. * clientPermList
  1885. *
  1886. * Displays a list of permissions defined for a client.
  1887. *
  1888. * <b>Output:</b>
  1889. * <pre>
  1890. * Array
  1891. * {
  1892. * [permid] => 20654 //with permsid = false
  1893. * [permsid] => b_client_ignore_bans //with permsid = true
  1894. * [permvalue] => 1
  1895. * [permnegated] => 0
  1896. * [permskip] => 0
  1897. * }
  1898. * </pre>
  1899. *
  1900. * @author Stefan Zehnpfennig
  1901. * @param intege $cldbid clientDBID
  1902. * @param boolean $permsid set true to add -permsid param [optional]
  1903. * @return array clientPermList
  1904. */
  1905. function clientPermList($cldbid, $permsid = false) {
  1906. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1907. return $this->getData('multi', 'clientpermlist cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
  1908. }
  1909.  
  1910. /**
  1911. * clientPoke
  1912. *
  1913. * Sends a poke message to the client specified with clid.
  1914. *
  1915. * @author Stefan Zehnpfennig
  1916. * @param integer $clid clientID
  1917. * @param string $msg pokeMessage
  1918. * @return boolean success
  1919. */
  1920. function clientPoke($clid, $msg) {
  1921. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1922. return $this->getData('boolean', 'clientpoke clid='.$clid.' msg='.$this->escapeText($msg));
  1923. }
  1924.  
  1925. /**
  1926. * clientSetServerQueryLogin
  1927. *
  1928. * Updates your own ServerQuery login credentials using a specified username. The password will be auto-generated.
  1929. *
  1930. * <b>Output:</b>
  1931. * <pre>
  1932. * Array
  1933. * {
  1934. * [client_login_password] => +r\/TQqvR
  1935. * }
  1936. * </pre>
  1937. *
  1938. * @author Stefan Zehnpfennig
  1939. * @param string $username username
  1940. * @return array userInfomation
  1941. */
  1942. function clientSetServerQueryLogin($username) {
  1943. return $this->getData('array', 'clientsetserverquerylogin client_login_name='.$this->escapeText($username));
  1944. }
  1945.  
  1946. /**
  1947. * clientUpdate
  1948. *
  1949. * Change your ServerQuery clients settings using given properties.
  1950. *
  1951. * <b>Input-Array like this:</b>
  1952. * <pre>
  1953. * $data = array();
  1954. * $data['property'] = 'value';
  1955. * $data['property'] = 'value';
  1956. * </pre>
  1957. *
  1958. * @author Stefan Zehnpfennig
  1959. * @param array $data clientProperties
  1960. * @return boolean success
  1961. */
  1962. function clientUpdate($data) {
  1963. $settingsString = '';
  1964.  
  1965. foreach($data as $key => $value) {
  1966. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value);
  1967. }
  1968.  
  1969. return $this->getData('boolean', 'clientupdate '.$settingsString);
  1970. }
  1971.  
  1972. /**
  1973. * complainAdd
  1974. *
  1975. * Submits a complaint about the client with database ID tcldbid to the server.
  1976. *
  1977. * @author Stefan Zehnpfennig
  1978. * @param integer $tcldbid targetClientDBID
  1979. * @param string $msg complainMessage
  1980. * @return boolean success
  1981. */
  1982. function complainAdd($tcldbid, $msg) {
  1983. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1984. return $this->getData('boolean', 'complainadd tcldbid='.$tcldbid.' message='.$this->escapeText($msg));
  1985. }
  1986.  
  1987. /**
  1988. * complainDelete
  1989. *
  1990. * Deletes the complaint about the client with ID tcldbid submitted by the client with ID fcldbid from the server.
  1991. *
  1992. * @author Stefan Zehnpfennig
  1993. * @param integer $tcldbid targetClientDBID
  1994. * @param integer $fcldbid fromClientDBID
  1995. * @return boolean success
  1996. */
  1997. function complainDelete($tcldbid, $fcldbid) {
  1998. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  1999. return $this->getData('boolean', 'complaindel tcldbid='.$tcldbid.' fcldbid='.$fcldbid);
  2000. }
  2001.  
  2002. /**
  2003. * complainDeleteAll
  2004. *
  2005. * Deletes all complaints about the client with database ID tcldbid from the server.
  2006. *
  2007. * @author Stefan Zehnpfennig
  2008. * @param integer $tcldbid targetClientDBID
  2009. * @return boolean success
  2010. */
  2011. function complainDeleteAll($tcldbid) {
  2012. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2013. return $this->getData('boolean', 'complaindelall tcldbid='.$tcldbid);
  2014. }
  2015.  
  2016. /**
  2017. * complainList
  2018. *
  2019. * Displays a list of complaints on the selected virtual server. If tcldbid is specified, only complaints about the targeted client will be shown.
  2020. *
  2021. * <b>Output:</b>
  2022. * <pre>
  2023. * Array
  2024. * {
  2025. * [tcldbid] => 2
  2026. * [tname] => par0noid
  2027. * [fcldbid] => 1
  2028. * [fname] => serveradmin from 127.0.0.1:6814
  2029. * [message] => Steals crayons
  2030. * [timestamp] => 1361044090
  2031. * }
  2032. * </pre>
  2033. *
  2034. * @author Stefan Zehnpfennig
  2035. * @param string $tcldbid targetClientDBID [optional]
  2036. * @return array complainList
  2037. */
  2038. function complainList($tcldbid = null) {
  2039. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2040. if(!empty($tcldbid)) { $tcldbid = ' tcldbid='.$tcldbid; }
  2041. return $this->getData('multi', 'complainlist'.$tcldbid);
  2042. }
  2043.  
  2044.  
  2045. /**
  2046. * customInfo
  2047. *
  2048. * Displays a list of custom properties for the client specified with cldbid.
  2049. *
  2050. * <b>Output:</b>
  2051. * <pre>
  2052. * Array
  2053. * {
  2054. * [0] => Array
  2055. * {
  2056. * [cldbid] => 1
  2057. * [ident] => abc
  2058. * [value] => def
  2059. * }
  2060. * [1] => Array
  2061. * {
  2062. * [ident] => ghi
  2063. * [value] => jkl
  2064. * }
  2065. * }
  2066. * </pre>
  2067. *
  2068. * @author Stefan Zehnpfennig
  2069. * @param string $cldbid clientDBID
  2070. * @return array customInfos
  2071. */
  2072. function customInfo($cldbid) {
  2073. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2074. return $this->getData('multi', 'custominfo cldbid='.$cldbid);
  2075. }
  2076.  
  2077. /**
  2078. * customSearch
  2079. *
  2080. * Searches for custom client properties specified by ident and value. The value parameter can include regular characters and SQL wildcard characters (e.g. %).
  2081. *
  2082. * <b>Output: (ident=abc, pattern=%)</b>
  2083. * <pre>
  2084. * Array
  2085. * {
  2086. * [0] => Array
  2087. * {
  2088. * [cldbid] => 1
  2089. * [ident] => abc
  2090. * [value] => def
  2091. * }
  2092. * [1] => Array
  2093. * {
  2094. * [cldbid] => 2
  2095. * [ident] => abc
  2096. * [value] => def
  2097. * }
  2098. * }
  2099. * </pre>
  2100. *
  2101. * @author Stefan Zehnpfennig
  2102. * @param string $ident customIdent
  2103. * @param string $pattern searchpattern
  2104. * @return array customSearchInfos
  2105. */
  2106. function customSearch($ident, $pattern) {
  2107. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2108. return $this->getData('multi', 'customsearch ident='.$this->escapeText($ident).' pattern='.$this->escapeText($pattern));
  2109. }
  2110.  
  2111. /**
  2112. * execOwnCommand
  2113. *
  2114. * executes a command that isn't defined in class and returns data like your propose
  2115. *
  2116. * <b>Modes:</b>
  2117. * <ul>
  2118. * <li><b>0:</b> execute -> return boolean</li>
  2119. * <li><b>1:</b> execute -> return normal array</li>
  2120. * <li><b>2:</b> execute -> return multidimensional array</li>
  2121. * <li><b>3:</b> execute -> return plaintext serverquery</li>
  2122. * </ul>
  2123. *
  2124. * @author Stefan Zehnpfennig
  2125. * @param string $mode executionMode
  2126. * @param string $command command
  2127. * @return mixed result
  2128. */
  2129. function execOwnCommand($mode, $command) {
  2130. if($mode == '0') {
  2131. return $this->getData('boolean', $command);
  2132. }
  2133. if($mode == '1') {
  2134. return $this->getData('array', $command);
  2135. }
  2136. if($mode == '2') {
  2137. return $this->getData('multi', $command);
  2138. }
  2139. if($mode == '3') {
  2140. return $this->getData('plain', $command);
  2141. }
  2142. }
  2143.  
  2144. /**
  2145. * ftCreateDir
  2146. *
  2147. * Creates new directory in a channels file repository.
  2148. *
  2149. * @author Stefan Zehnpfennig
  2150. * @param string $cid channelId
  2151. * @param string $cpw channelPassword (leave blank if not needed)
  2152. * @param string $dirname dirPath
  2153. * @return boolean success
  2154. */
  2155. function ftCreateDir($cid, $cpw = null, $dirname) {
  2156. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2157. return $this->getData('boolean', 'ftcreatedir cid='.$cid.' cpw='.$this->escapeText($cpw).' dirname='.$this->escapeText($dirname));
  2158. }
  2159.  
  2160. /**
  2161. * ftDeleteFile
  2162. *
  2163. * Deletes one or more files stored in a channels file repository.
  2164. *
  2165. * <b>Input-Array like this:</b>
  2166. * <pre>
  2167. * $files = array();
  2168. *
  2169. * $files[] = '/pic1.jpg';
  2170. * $files[] = '/dokumente/test.txt';
  2171. * $files[] = '/dokumente';
  2172. * </pre>
  2173. *
  2174. * @author Stefan Zehnpfennig
  2175. * @param string $cid channelID
  2176. * @param string $cpw channelPassword (leave blank if not needed)
  2177. * @param array $files files
  2178. * @return boolean success
  2179. */
  2180. function ftDeleteFile($cid, $cpw = '', $files) {
  2181. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2182. $fileArray = array();
  2183.  
  2184. if(count($files) > 0) {
  2185. foreach($files AS $file) {
  2186. $fileArray[] = 'name='.$this->escapeText($file);
  2187. }
  2188. return $this->getData('boolean', 'ftdeletefile cid='.$cid.' cpw='.$this->escapeText($cpw).' '.implode('|', $fileArray));
  2189. }else{
  2190. $this->addDebugLog('no files given');
  2191. return $this->generateOutput(false, array('Error: no files given'), false);
  2192. }
  2193. }
  2194.  
  2195. /**
  2196. * ftDownloadFile
  2197. *
  2198. * Ddownloads a file and returns its contents
  2199. *
  2200. * @author Stefan Zehnpfennig
  2201. * @param array $data return of ftInitDownload
  2202. * @return array downloadedFile
  2203. */
  2204. function ftDownloadFile($data) {
  2205. $errnum = null;
  2206. $errstr = null;
  2207. $this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
  2208. if($this->runtime['fileSocket']) {
  2209. $this->ftSendKey($data['data']['ftkey']);
  2210. $content = $this->ftRead($data['data']['size']);
  2211. @fclose($this->runtime['fileSocket']);
  2212. $this->runtime['fileSocket'] = '';
  2213. return $content;
  2214. }else{
  2215. $this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
  2216. return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
  2217. }
  2218. }
  2219.  
  2220. /**
  2221. * ftGetFileInfo
  2222. *
  2223. * Displays detailed information about one or more specified files stored in a channels file repository.
  2224. *
  2225. * <b>Output:</b>
  2226. * <pre>
  2227. * Array
  2228. * {
  2229. * [cid] => 0
  2230. * [name] => /icon_1947482249
  2231. * [size] => 744
  2232. * [datetime] => 1286633633
  2233. * }
  2234. * </pre>
  2235. *
  2236. * @author Stefan Zehnpfennig
  2237. * @param string $cid channelID
  2238. * @param string $cpw channelPassword (leave blank if not needed)
  2239. * @param string $file path to file
  2240. * @return boolean success
  2241. */
  2242. function ftGetFileInfo($cid, $cpw = '', $file) {
  2243. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2244.  
  2245. return $this->getData('multi', 'ftgetfileinfo cid='.$cid.' cpw='.$this->escapeText($cpw).' name='.$this->escapeText($file));
  2246. }
  2247.  
  2248. /**
  2249. * ftGetFileList
  2250. *
  2251. * Displays a list of files and directories stored in the specified channels file repository.
  2252. *
  2253. * <b>Output:</b>
  2254. * <pre>
  2255. * Array
  2256. * {
  2257. * [cid] => 231
  2258. * [path] => /
  2259. * [name] => Documents
  2260. * [size] => 0
  2261. * [datetime] => 1286633633
  2262. * [type] => 0
  2263. * }
  2264. * </pre>
  2265. *
  2266. * @author Stefan Zehnpfennig
  2267. * @param string $cid channelID
  2268. * @param string $cpw channelPassword (leave blank if not needed)
  2269. * @param string $path filePath
  2270. * @return array fileList
  2271. */
  2272. function ftGetFileList($cid, $cpw = '', $path) {
  2273. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2274. return $this->getData('multi', 'ftgetfilelist cid='.$cid.' cpw='.$this->escapeText($cpw).' path='.$this->escapeText($path));
  2275. }
  2276.  
  2277. /**
  2278. * ftInitDownload
  2279. *
  2280. * Initializes a file transfer download. clientftfid is an arbitrary ID to identify the file transfer on client-side. On success, the server generates a new ftkey which is required to start downloading the file through TeamSpeak 3's file transfer interface. Since version 3.0.13 there is an optional proto parameter. The client can request a protocol version with it. Currently only 0 and 1 are supported which only differ in the way they handle some timings. The server will reply which protocol version it will support. The server will reply with an ip parameter if it determines the filetransfer subsystem is not reachable by the ip that is currently being used for the query connection.
  2281. *
  2282. * <b>Output:</b>
  2283. * <pre>
  2284. * Array
  2285. * {
  2286. * [clientftfid] => 89
  2287. * [serverftfid] => 3
  2288. * [ftkey] => jSzWiRmFGdZnoJzW7BSDYJRUWB2WAUhb
  2289. * [port] => 30033
  2290. * [size] => 94
  2291. * }
  2292. * </pre>
  2293. *
  2294. * @author Stefan Zehnpfennig
  2295. * @param string $name filePath
  2296. * @param string $cid channelID
  2297. * @param string $cpw channelPassword (leave blank if not needed)
  2298. * @param integer $seekpos seekpos (default = 0) [optional]
  2299. * @param integer $proto proto (default = NULL) [optional]
  2300. * @return array initDownloadFileInfo
  2301. */
  2302. function ftInitDownload($name, $cid, $cpw = '', $seekpos = 0, $proto = null) {
  2303. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2304. return $this->getData('array', 'ftinitdownload clientftfid='.rand(1,65535).' name='.$this->escapeText($name).' cid='.$cid.' cpw='.$this->escapeText($cpw).' seekpos='.$seekpos.($proto !== null ? ' proto='.$proto: ''));
  2305. }
  2306.  
  2307. /**
  2308. * ftInitUpload
  2309. *
  2310. * Initializes a file transfer upload. clientftfid is an arbitrary ID to identify the file transfer on client-side. On success, the server generates a new ftkey which is required to start uploading the file through TeamSpeak 3's file transfer interface. Since version 3.0.13 there is an optional proto parameter. The client can request a protocol version with it. Currently only 0 and 1 are supported which only differ in the way they handle some timings. The server will reply which protocol version it will support. The server will reply with an ip parameter if it determines the filetransfer subsystem is not reachable by the ip that is currently being used for the query connection
  2311. *
  2312. * <b>Output:</b>
  2313. * <pre>
  2314. * Array
  2315. * {
  2316. * [clientftfid] => 84
  2317. * [serverftfid] => 41
  2318. * [ftkey] => HCnXpunOdAorqj3dGqfiuLszX18O0PHP
  2319. * [port] => 30033
  2320. * [seekpos] => 0
  2321. * }
  2322. * </pre>
  2323. *
  2324. * @author Stefan Zehnpfennig
  2325. * @param string $filename filePath
  2326. * @param string $cid channelID
  2327. * @param integer $size fileSize in bytes
  2328. * @param string $cpw channelPassword (leave blank if not needed)
  2329. * @param boolean $overwrite overwrite [optional] (default = 0)
  2330. * @param boolean $resume resume [optional] (default = 0)
  2331. * @param integer $proto proto (default = NULL) [optional]
  2332. * @return array initUploadFileInfo
  2333. */
  2334. function ftInitUpload($filename, $cid, $size, $cpw = '', $overwrite = false, $resume = false, $proto = null) {
  2335. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2336.  
  2337. if($overwrite) { $overwrite = ' overwrite=1'; }else{ $overwrite = ' overwrite=0'; }
  2338. if($resume) { $resume = ' resume=1'; }else{ $resume = ' resume=0'; }
  2339.  
  2340. return $this->getData('array', 'ftinitupload clientftfid='.rand(1,65535).' name='.$this->escapeText($filename).' cid='.$cid.' cpw='.$this->escapeText($cpw).' size='.($size + 1).$overwrite.$resume.($proto !== null ? ' proto='.$proto: ''));
  2341. }
  2342.  
  2343. /**
  2344. * ftList
  2345. *
  2346. * Displays a list of running file transfers on the selected virtual server. The output contains the path to which a file is uploaded to, the current transfer rate in bytes per second, etc
  2347. *
  2348. * <b>Output:</b>
  2349. * <pre>
  2350. * Array
  2351. * {
  2352. * [clid] => 1
  2353. * [cldbid] => 2019
  2354. * [path] => files/virtualserver_11/channel_231
  2355. * [name] => 1285412348878.png
  2356. * [size] => 1161281
  2357. * [sizedone] => 275888
  2358. * [clientftfid] => 15
  2359. * [serverftfid] => 52
  2360. * [sender] => 0
  2361. * [status] => 1
  2362. * [current_speed] => 101037.4453
  2363. * [average_speed] => 101037.4453
  2364. * [runtime] => 2163
  2365. * }
  2366. * </pre>
  2367. *
  2368. * @author Stefan Zehnpfennig
  2369. * @return array fileTransferList
  2370. */
  2371. function ftList() {
  2372. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2373. return $this->getData('multi', 'ftlist');
  2374. }
  2375.  
  2376. /**
  2377. * ftRenameFile
  2378. *
  2379. * Renames a file in a channels file repository. If the two parameters tcid and tcpw are specified, the file will be moved into another channels file repository.
  2380. *
  2381. * @author Stefan Zehnpfennig
  2382. * @param integer $cid channelID
  2383. * @param string $cpw channelPassword (leave blank if not needed)
  2384. * @param string $oldname oldFilePath
  2385. * @param string $newname newFilePath
  2386. * @param string $tcid targetChannelID [optional]
  2387. * @param string $tcpw targetChannelPassword [optional]
  2388. * @return boolean success
  2389. */
  2390. function ftRenameFile($cid, $cpw = null, $oldname, $newname, $tcid = null, $tcpw = null) {
  2391. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2392. $newTarget = ($tcid != null ? ' tcid='.$tcid.' '.$tcpw : '');
  2393. return $this->getData('boolean', 'ftrenamefile cid='.$cid.' cpw='.$cpw.' oldname='.$this->escapeText($oldname).' newname='.$this->escapeText($newname).$newTarget);
  2394. }
  2395.  
  2396. /**
  2397. * ftStop
  2398. *
  2399. * Stops the running file transfer with server-side ID serverftfid.
  2400. *
  2401. * @author Stefan Zehnpfennig
  2402. * @param integer $serverftfid serverFileTransferID
  2403. * @param boolean $delete delete incomplete file [optional] (default: true)
  2404. * @return boolean success
  2405. */
  2406. function ftStop($serverftfid, $delete = true) {
  2407. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2408. return $this->getData('boolean', 'ftstop serverftfid='.$serverftfid.' delete='.($delete ? '1' : '0'));
  2409. }
  2410.  
  2411. /**
  2412. * ftUploadFile
  2413. *
  2414. * Uploads a file to server
  2415. * To check if upload was successful, you have to search for this file in fileList after
  2416. *
  2417. * @author Stefan Zehnpfennig
  2418. * @param array $data return of ftInitUpload
  2419. * @param string $uploadData data which should be uploaded
  2420. * @return array response
  2421. */
  2422. function ftUploadFile($data, $uploadData) {
  2423. $this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
  2424. if($this->runtime['fileSocket']) {
  2425. $this->ftSendKey($data['data']['ftkey']);
  2426. $this->ftSendData($uploadData);
  2427. @fclose($this->runtime['fileSocket']);
  2428. $this->runtime['fileSocket'] = '';
  2429. return $this->generateOutput(true, array(), true);
  2430. }else{
  2431. $this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
  2432. return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
  2433. }
  2434. }
  2435.  
  2436. /**
  2437. * getIconByID
  2438. *
  2439. * Will return the base64 encoded binary of the icon
  2440. *
  2441. * <pre>
  2442. * $result = $tsAdmin->getIconByID($iconId);
  2443. * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
  2444. * </pre>
  2445. *
  2446. * @author Stefan Zehnpfennig
  2447. * @param string $iconID IconID
  2448. * @return array base64 image
  2449. */
  2450. function getIconByID($iconID) {
  2451. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2452.  
  2453. if(empty($iconID) or $iconID == 0)
  2454. {
  2455. return $this->generateOutput(false, array('Error: empty iconID'), false);
  2456. }
  2457.  
  2458. if($iconID == 100 OR $iconID == 200 OR $iconID == 300 OR $iconID == 500 OR $iconID == 600)
  2459. {
  2460. return $this->generateOutput(false, array('Error: you can\'t download teamspeak default icons'), false);
  2461. }
  2462.  
  2463. if($iconID < 0)
  2464. {
  2465. $iconID = sprintf('%u', $iconID & 0xffffffff);
  2466. }
  2467.  
  2468. $check = $this->ftgetfileinfo(0, '', '/icon_'.$iconID);
  2469.  
  2470. if(!$check["success"])
  2471. {
  2472. return $this->generateOutput(false, array('Error: icon does not exist'), false);
  2473. }
  2474.  
  2475. $init = $this->ftInitDownload('/icon_'.$iconID, 0, '');
  2476.  
  2477. if(!$init["success"])
  2478. {
  2479. return $this->generateOutput(false, array('Error: init failed'), false);
  2480. }
  2481.  
  2482. $download = $this->ftDownloadFile($init);
  2483.  
  2484. if(is_array($download))
  2485. {
  2486. return $download;
  2487. }else{
  2488. return $this->generateOutput(true, false, base64_encode($download));
  2489. }
  2490. }
  2491.  
  2492. /**
  2493. * gm
  2494. *
  2495. * Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance.
  2496. *
  2497. * @author Stefan Zehnpfennig
  2498. * @param string $msg message
  2499. * @return boolean success
  2500. */
  2501. function gm($msg) {
  2502. if(empty($msg)) {
  2503. $this->addDebugLog('empty message given');
  2504. return $this->generateOutput(false, array('Error: empty message given'), false);
  2505. }
  2506. return $this->getData('boolean', 'gm msg='.$this->escapeText($msg));
  2507. }
  2508.  
  2509. /**
  2510. * hostInfo
  2511. *
  2512. * Displays detailed connection information about the server instance including uptime, number of virtual servers online, traffic information, etc.
  2513. *
  2514. * <b>Output:</b>
  2515. * <pre>
  2516. * Array
  2517. * {
  2518. * [instance_uptime] => 19038
  2519. * [host_timestamp_utc] => 1361046825
  2520. * [virtualservers_running_total] => 1
  2521. * [virtualservers_total_maxclients] => 32
  2522. * [virtualservers_total_clients_online] => 1
  2523. * [virtualservers_total_channels_online] => 2
  2524. * [connection_filetransfer_bandwidth_sent] => 0
  2525. * [connection_filetransfer_bandwidth_received] => 0
  2526. * [connection_filetransfer_bytes_sent_total] => 0
  2527. * [connection_filetransfer_bytes_received_total] => 0
  2528. * [connection_packets_sent_total] => 24853
  2529. * [connection_bytes_sent_total] => 1096128
  2530. * [connection_packets_received_total] => 25404
  2531. * [connection_bytes_received_total] => 1153918
  2532. * [connection_bandwidth_sent_last_second_total] => 82
  2533. * [connection_bandwidth_sent_last_minute_total] => 81
  2534. * [connection_bandwidth_received_last_second_total] => 84
  2535. * [connection_bandwidth_received_last_minute_total] => 87
  2536. * }
  2537. * </pre>
  2538. *
  2539. * @author Stefan Zehnpfennig
  2540. * @return array hostInformation
  2541. */
  2542. function hostInfo() {
  2543. return $this->getData('array', 'hostinfo');
  2544. }
  2545.  
  2546. /**
  2547. * instanceEdit
  2548. *
  2549. * Changes the server instance configuration using given properties.
  2550. *
  2551. * <b>Input-Array like this:</b>
  2552. * <pre>
  2553. * $data = array();
  2554. *
  2555. * $data['setting'] = 'value';
  2556. * $data['setting'] = 'value';
  2557. * </pre>
  2558. *
  2559. * <b>Possible properties:</b> SERVERINSTANCE_GUEST_SERVERQUERY_GROUP, SERVERINSTANCE_TEMPLATE_SERVERADMIN_GROUP, SERVERINSTANCE_FILETRANSFER_PORT, SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWITDH, SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWITDH, SERVERINSTANCE_TEMPLATE_SERVERDEFAULT_GROUP, SERVERINSTANCE_TEMPLATE_CHANNELDEFAULT_GROUP, SERVERINSTANCE_TEMPLATE_CHANNELADMIN_GROUP, SERVERINSTANCE_SERVERQUERY_FLOOD_COMMANDS, SERVERINSTANCE_SERVERQUERY_FLOOD_TIME, SERVERINSTANCE_SERVERQUERY_FLOOD_BAN_TIME
  2560. *
  2561. * @author Stefan Zehnpfennig
  2562. * @param array $data instanceProperties
  2563. * @return boolean success
  2564. */
  2565. function instanceEdit($data) {
  2566. if(count($data) > 0) {
  2567. $settingsString = '';
  2568.  
  2569. foreach($data as $key => $val) {
  2570. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($val);
  2571. }
  2572. return $this->getData('boolean', 'instanceedit '.$settingsString);
  2573. }else{
  2574. $this->addDebugLog('empty array entered');
  2575. return $this->generateOutput(false, array('Error: You can \'t give an empty array'), false);
  2576. }
  2577. }
  2578.  
  2579. /**
  2580. * instanceInfo
  2581. *
  2582. * Displays the server instance configuration including database revision number, the file transfer port, default group IDs, etc.
  2583. *
  2584. * <b>Output:</b>
  2585. * <pre>
  2586. * Array
  2587. * {
  2588. * [serverinstance_database_version] => 20
  2589. * [serverinstance_filetransfer_port] => 30033
  2590. * [serverinstance_max_download_total_bandwidth] => 18446744073709551615
  2591. * [serverinstance_max_upload_total_bandwidth] => 18446744073709551615
  2592. * [serverinstance_guest_serverquery_group] => 1
  2593. * [serverinstance_serverquery_flood_commands] => 10
  2594. * [serverinstance_serverquery_flood_time] => 3
  2595. * [serverinstance_serverquery_ban_time] => 600
  2596. * [serverinstance_template_serveradmin_group] => 3
  2597. * [serverinstance_template_serverdefault_group] => 5
  2598. * [serverinstance_template_channeladmin_group] => 1
  2599. * [serverinstance_template_channeldefault_group] => 4
  2600. * [serverinstance_permissions_version] => 15
  2601. * }
  2602. * </pre>
  2603. *
  2604. * @author Stefan Zehnpfennig
  2605. * @return array instanceInformation
  2606. */
  2607. function instanceInfo() {
  2608. return $this->getData('array', 'instanceinfo');
  2609. }
  2610.  
  2611. /**
  2612. * logAdd
  2613. *
  2614. * Writes a custom entry into the servers log. Depending on your permissions, you'll be able to add entries into the server instance log and/or your virtual servers log. The loglevel parameter specifies the type of the entry.
  2615. *
  2616. * @author Stefan Zehnpfennig
  2617. * @param integer $logLevel loglevel between 1 and 4
  2618. * @param string $logMsg logMessage
  2619. * @return boolean success
  2620. */
  2621. function logAdd($logLevel, $logMsg) {
  2622. if($logLevel >=1 and $logLevel <= 4) {
  2623. if(!empty($logMsg)) {
  2624. return $this->getData('boolean', 'logadd loglevel='.$logLevel.' logmsg='.$this->escapeText($logMsg));
  2625. }else{
  2626. $this->addDebugLog('logMessage empty!');
  2627. return $this->generateOutput(false, array('Error: logMessage empty!'), false);
  2628. }
  2629. }else{
  2630. $this->addDebugLog('invalid logLevel!');
  2631. return $this->generateOutput(false, array('Error: invalid logLevel!'), false);
  2632. }
  2633. }
  2634.  
  2635. /**
  2636. * login
  2637. *
  2638. * Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials.
  2639. *
  2640. * @author Stefan Zehnpfennig
  2641. * @param string $username username
  2642. * @param string $password password
  2643. * @return boolean success
  2644. */
  2645. function login($username, $password) {
  2646. return $this->getData('boolean', 'login '.$this->escapeText($username).' '.$this->escapeText($password));
  2647. }
  2648.  
  2649. /**
  2650. * logout
  2651. *
  2652. * Deselects the active virtual server and logs out from the server instance.
  2653. *
  2654. * @author Stefan Zehnpfennig
  2655. * @return boolean success
  2656. */
  2657. function logout() {
  2658. $this->runtime['selected'] = false;
  2659. return $this->getData('boolean', 'logout');
  2660. }
  2661.  
  2662. /**
  2663. * logView
  2664. *
  2665. * Displays a specified number of entries from the servers log. If instance is set to 1, the server will return lines from the master logfile (ts3server_0.log) instead of the selected virtual server logfile.
  2666. *
  2667. * <b>Output:</b>
  2668. * <pre>
  2669. * Array
  2670. * {
  2671. * [last_pos] => 0
  2672. * [file_size] => 1085
  2673. * [l] => 2012-01-10 20:34:31.379260|INFO |ServerLibPriv | | TeamSpeak 3 Server 3.0.1 (2011-11-17 07:34:30)
  2674. * }
  2675. * {
  2676. * [l] => 2012-01-10 20:34:31.380260|INFO |DatabaseQuery | | dbPlugin name: SQLite3 plugin, Version 2, (c)TeamSpeak Systems GmbH
  2677. * }
  2678. * {
  2679. * [l] => 2012-01-10 20:34:31.380260|INFO |DatabaseQuery | | dbPlugin version: 3.7.3
  2680. * }
  2681. * </pre>
  2682. *
  2683. * @author Stefan Zehnpfennig
  2684. * @param integer $lines between 1 and 100
  2685. * @param integer $reverse {1|0} [optional]
  2686. * @param integer $instance {1|0} [optional]
  2687. * @param integer $begin_pos {1|0} [optional]
  2688. * @return multidimensional-array logEntries
  2689. */
  2690. function logView($lines, $reverse = 0, $instance = 0, $begin_pos = 0) {
  2691. if($lines >=1 and $lines <=100) {
  2692. return $this->getData('multi', 'logview lines='.$lines.' reverse='.($reverse == 0 ? '0' : '1').' instance='.($instance == 0 ? '0' : '1').' begin_pos='.($begin_pos == 0 ? '0' : $begin_pos));
  2693. }else{
  2694. $this->addDebugLog('please choose a limit between 1 and 100');
  2695. $this->generateOutput(false, array('Error: please choose a limit between 1 and 100'), false);
  2696. }
  2697. }
  2698.  
  2699. /**
  2700. * messageAdd
  2701. *
  2702. * Sends an offline message to the client specified by cluid.
  2703. *
  2704. * @author Stefan Zehnpfennig
  2705. * @param string $cluid clientUID
  2706. * @param string $subject Subject of the message
  2707. * @param string $message Text of the message
  2708. * @return boolean success
  2709. */
  2710. function messageAdd($cluid, $subject, $message) {
  2711. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2712. return $this->getData('boolean', 'messageadd cluid='.$cluid.' subject='.$this->escapeText($subject).' message='.$this->escapeText($message));
  2713. }
  2714.  
  2715. /**
  2716. * messageDelete
  2717. *
  2718. * Deletes an existing offline message with ID msgid from your inbox.
  2719. *
  2720. * @author Stefan Zehnpfennig
  2721. * @param string $messageID messageID
  2722. * @return boolean success
  2723. */
  2724. function messageDelete($messageID) {
  2725. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2726. return $this->getData('boolean', 'messagedel msgid='.$messageID);
  2727. }
  2728.  
  2729. /**
  2730. * messageGet
  2731. *
  2732. * Displays an existing offline message with ID msgid from your inbox. Please note that this does not automatically set the flag_read property of the message.
  2733. *
  2734. * @author Stefan Zehnpfennig
  2735. * @param string $messageID messageID
  2736. * @return array messageInformation
  2737. */
  2738. function messageGet($messageID) {
  2739. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2740. return $this->getData('array', 'messageget msgid='.$messageID);
  2741. }
  2742.  
  2743. /**
  2744. * messageList
  2745. *
  2746. * Displays a list of offline messages you've received. The output contains the senders unique identifier, the messages subject, etc.
  2747. *
  2748. * @author Stefan Zehnpfennig
  2749. * @return array messageInformation
  2750. */
  2751. function messageList() {
  2752. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2753. return $this->getData('array', 'messagelist');
  2754. }
  2755.  
  2756. /**
  2757. * messageUpdateFlag
  2758. *
  2759. * Updates the flag_read property of the offline message specified with msgid. If flag is set to 1, the message will be marked as read.
  2760. *
  2761. * @author Stefan Zehnpfennig
  2762. * @param string $messageID messageID
  2763. * @param integer $flag flag {1|0}
  2764. * @return array messageInformation
  2765. */
  2766. function messageUpdateFlag($messageID, $flag = 1) {
  2767. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2768. return $this->getData('boolean', 'messageupdateflag msgid='.$messageID.' flag='.$flag);
  2769. }
  2770.  
  2771. /**
  2772. * uploadIcon
  2773. *
  2774. * Uploads an icon to the server
  2775. *
  2776. * <b>Output:</b>
  2777. * <pre>
  2778. * Array
  2779. * {
  2780. * [cid] => 0
  2781. * [name] => /icon_1947482249
  2782. * [size] => 744
  2783. * [datetime] => 1286633633
  2784. * }
  2785. * </pre>
  2786. *
  2787. * @author Stefan Zehnpfennig
  2788. * @param string $filepath Path to your file
  2789. * @param string $iconID [optional] Desired IconID (Must be higher than 1.000.000.000, and lower than 2.147.483.647)
  2790. * @return array ftGetFileInfo
  2791. */
  2792. function uploadIcon($filepath, $iconID = -1) {
  2793. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2794.  
  2795. if($iconID == -1)
  2796. {
  2797. $iconID = mt_rand(1000000000, 2147483647);
  2798. }
  2799.  
  2800. if($iconID <= 1000000000 and $iconID <= 2147483647)
  2801. {
  2802. return $this->generateOutput(false, array('Error: Must be higher than 1.000.000.000, and lower than 2.147.483.647'), false);
  2803. }
  2804.  
  2805. if(!file_exists($filepath))
  2806. {
  2807. return $this->generateOutput(false, array('Error: file does not exist'), false);
  2808. }
  2809.  
  2810. $data = null;
  2811.  
  2812. try {
  2813. $data = file_get_contents($filepath);
  2814. } catch (Exception $e) {
  2815. return $this->generateOutput(false, array('Error: can\'t read file - '.$e->getMessage()), false);
  2816. }
  2817.  
  2818. $size = filesize($filepath);
  2819.  
  2820. $init = $this->ftInitUpload('/icon_'.$iconID, 0, $size, '', true);
  2821.  
  2822. if(!$this->succeeded($init))
  2823. {
  2824. return $this->generateOutput(false, $init['error'], false);
  2825. }
  2826.  
  2827. $result = $this->ftUploadFile($init, $data);
  2828.  
  2829. if($this->succeeded($result))
  2830. {
  2831. return $this->ftGetFileInfo(0, '', '/icon_'.$iconID);
  2832. //return $this->generateOutput(true, null, array('iconid' => $iconID, 'size' => $size));
  2833. }
  2834. else
  2835. {
  2836. return $result;
  2837. }
  2838. }
  2839.  
  2840. /**
  2841. * permFind
  2842. *
  2843. * Displays detailed information about all assignments of the permission specified with permid. The output is similar to permoverview which includes the type and the ID of the client, channel or group associated with the permission. A permission can be specified by permid or permsid.
  2844. *
  2845. * <b>Output:</b>
  2846. * <pre>
  2847. * Array
  2848. * {
  2849. * [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
  2850. * }
  2851. * </pre>
  2852. *
  2853. * @author Stefan Zehnpfennig
  2854. * @param mixed $perm permid or permsid
  2855. * @return array permissionInfoList
  2856. */
  2857. function permFind($perm) {
  2858. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2859. return $this->getData('multi', 'permfind '.(is_int($perm) || ctype_digit($perm) ? 'permid=' : 'permsid=').$perm);
  2860. }
  2861.  
  2862.  
  2863. /**
  2864. * permGet
  2865. *
  2866. * Displays the current value of the permission specified with permid or permsid for your own connection. This can be useful when you need to check your own privileges.
  2867. *
  2868. * The perm parameter can be used as permid or permsid, it will switch the mode automatically.
  2869. *
  2870. * <b>Output:</b>
  2871. * <pre>
  2872. * Array
  2873. * {
  2874. * [permsid] => i_channel_create_modify_with_codec_maxquality
  2875. * [permid] => 96
  2876. * [permvalue] => 10
  2877. * }
  2878. * </pre>
  2879. *
  2880. * @author Stefan Zehnpfennig
  2881. * @param mixed $perm permid or permsid
  2882. * @return array permissionInfo
  2883. */
  2884. function permGet($perm) {
  2885. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  2886. return $this->getData('array', 'permget '.(is_int($perm) || ctype_digit($perm) ? 'permid=' : 'permsid=').$perm);
  2887. }
  2888.  
  2889. /**
  2890. * permIdGetByName
  2891. *
  2892. * Displays the database ID of one or more permissions specified by permsid.
  2893. *
  2894. * <b>Input-Array like this:</b>
  2895. * <pre>
  2896. * $permissions = array();
  2897. * $permissions[] = 'permissionName';
  2898. * </pre>
  2899. * <b>Output:</b>
  2900. * <pre>
  2901. * Array
  2902. * {
  2903. * [permsid] => b_serverinstance_help_view
  2904. * [permid] => 4353
  2905. * }
  2906. * </pre>
  2907. *
  2908. * @author Stefan Zehnpfennig
  2909. * @param string $permsids permNames
  2910. * @return array permissionList
  2911. */
  2912. function permIdGetByName($permsids) {
  2913. $permissionArray = array();
  2914.  
  2915. if(count($permsids) > 0) {
  2916. foreach($permsids AS $value) {
  2917. $permissionArray[] = 'permsid='.$value;
  2918. }
  2919. return $this->getData('multi', 'permidgetbyname '.$this->escapeText(implode('|', $permissionArray)));
  2920. }else{
  2921. $this->addDebugLog('no permissions given');
  2922. return $this->generateOutput(false, array('Error: no permissions given'), false);
  2923. }
  2924.  
  2925. }
  2926.  
  2927.  
  2928. /**
  2929. * permissionList
  2930. *
  2931. * Displays a list of permissions available on the server instance including ID, name and description.
  2932. * If the new parameter is set the permissionlist will return with the new output format.
  2933. *
  2934. * <b>Output: (with new parameter)</b>
  2935. * <pre>
  2936. * [0] => Array
  2937. * (
  2938. * [num] => 1
  2939. * [group_id_end] => 0
  2940. * [pcount] => 0
  2941. * )
  2942. *
  2943. * [1] => Array
  2944. * (
  2945. * [num] => 2
  2946. * [group_id_end] => 7
  2947. * [pcount] => 7
  2948. * [permissions] => Array
  2949. * (
  2950. * [0] => Array
  2951. * (
  2952. * [permid] => 1
  2953. * [permname] => b_serverinstance_help_view
  2954. * [permdesc] => Retrieve information about ServerQuery commands
  2955. * [grantpermid] => 32769
  2956. * )
  2957. *
  2958. * [1] => Array
  2959. * (
  2960. * [permid] => 2
  2961. * [permname] => b_serverinstance_version_view
  2962. * [permdesc] => Retrieve global server version (including platform and build number)
  2963. * [grantpermid] => 32770
  2964. * )
  2965. *
  2966. * [2] => Array
  2967. * (
  2968. * [permid] => 3
  2969. * [permname] => b_serverinstance_info_view
  2970. * [permdesc] => Retrieve global server information
  2971. * [grantpermid] => 32771
  2972. * )
  2973. *
  2974. * [3] => Array
  2975. * (
  2976. * [permid] => 4
  2977. * [permname] => b_serverinstance_virtualserver_list
  2978. * [permdesc] => List virtual servers stored in the database
  2979. * [grantpermid] => 32772
  2980. * )
  2981. *
  2982. * [4] => Array
  2983. * (
  2984. * [permid] => 5
  2985. * [permname] => b_serverinstance_binding_list
  2986. * [permdesc] => List active IP bindings on multi-homed machines
  2987. * [grantpermid] => 32773
  2988. * )
  2989. *
  2990. * [5] => Array
  2991. * (
  2992. * [permid] => 6
  2993. * [permname] => b_serverinstance_permission_list
  2994. * [permdesc] => List permissions available available on the server instance
  2995. * [grantpermid] => 32774
  2996. * )
  2997. *
  2998. * [6] => Array
  2999. * (
  3000. * [permid] => 7
  3001. * [permname] => b_serverinstance_permission_find
  3002. * [permdesc] => Search permission assignments by name or ID
  3003. * [grantpermid] => 32775
  3004. * )
  3005. *
  3006. * )
  3007. *
  3008. * )
  3009. * </pre>
  3010. *
  3011. * @author Stefan Zehnpfennig
  3012. * @param boolean $new [optional] add new parameter
  3013. * @return array permissionList
  3014. */
  3015. function permissionList($new = false) {
  3016. if($new === true) {
  3017. $groups = array();
  3018. $permissions = array();
  3019.  
  3020. $response = $this->getElement('data', $this->getData('multi', 'permissionlist -new'));
  3021.  
  3022. $gc = 1;
  3023.  
  3024. foreach($response as $field) {
  3025. if(isset($field['group_id_end'])) {
  3026. $groups[] = array('num' => $gc, 'group_id_end' => $field['group_id_end']);
  3027. $gc++;
  3028. }else{
  3029. $permissions[] = $field;
  3030. }
  3031. }
  3032.  
  3033. $counter = 0;
  3034.  
  3035. for($i = 0; $i < count($groups); $i++) {
  3036. $rounds = $groups[$i]['group_id_end'] - $counter;
  3037. $groups[$i]['pcount'] = $rounds;
  3038. for($j = 0; $j < $rounds; $j++) {
  3039. $groups[$i]['permissions'][] = array('permid' => ($counter + 1), 'permname' => $permissions[$counter]['permname'], 'permdesc' => $permissions[$counter]['permdesc'], 'grantpermid' => ($counter + 32769));
  3040. $counter++;
  3041. }
  3042. }
  3043.  
  3044. return $groups;
  3045.  
  3046. }else{
  3047. return $this->getData('multi', 'permissionlist');
  3048. }
  3049. }
  3050.  
  3051. /**
  3052. * permOverview
  3053. *
  3054. * Displays all permissions assigned to a client for the channel specified with cid. If permid is set to 0, all permissions will be displayed. A permission can be specified by permid or permsid.
  3055. *
  3056. * If you set the permsid parameter, the permid parameter will be ignored.
  3057. *
  3058. * <b>Output:</b>
  3059. * <pre>
  3060. * Array
  3061. * {
  3062. * [t] => 0
  3063. * [id1] => 2
  3064. * [id2] => 0
  3065. * [p] => 16777
  3066. * [v] => 1
  3067. * [n] => 0
  3068. * [s] => 0
  3069. * }
  3070. * </pre>
  3071. *
  3072. * @author Stefan Zehnpfennig
  3073. * @param integer $cid cchannelId
  3074. * @param integer $cldbid clientDbId
  3075. * @param integer $permid permId (Default: 0)
  3076. * @param string $permsid permName
  3077. * @return array permOverview
  3078. */
  3079. function permOverview($cid, $cldbid, $permid='0', $permsid=false ) {
  3080. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3081. if($permsid) { $additional = ' permsid='.$permsid; }else{ $additional = ''; }
  3082.  
  3083. return $this->getData('multi', 'permoverview cid='.$cid.' cldbid='.$cldbid.($permsid == false ? ' permid='.$permid : '').$additional);
  3084. }
  3085.  
  3086. /**
  3087. * permReset
  3088. *
  3089. * Restores the default permission settings on the selected virtual server and creates a new initial administrator token. Please note that in case of an error during the permreset call - e.g. when the database has been modified or corrupted - the virtual server will be deleted from the database.
  3090. *
  3091. * <b>Output:</b>
  3092. * <pre>
  3093. * Array
  3094. * {
  3095. * [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
  3096. * }
  3097. * </pre>
  3098. *
  3099. * @author Stefan Zehnpfennig
  3100. * @return array token
  3101. */
  3102. function permReset() {
  3103. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3104. return $this->getData('array', 'permreset');
  3105. }
  3106.  
  3107. /**
  3108. * privilegekeyAdd
  3109. *
  3110. * Create a new token. If tokentype is set to 0, the ID specified with tokenid1 will be a server group ID. Otherwise, tokenid1 is used as a channel group ID and you need to provide a valid channel ID using tokenid2. The tokencustomset parameter allows you to specify a set of custom client properties. This feature can be used when generating tokens to combine a website account database with a TeamSpeak user. The syntax of the value needs to be escaped using the ServerQuery escape patterns and has to follow the general syntax of:
  3111. * ident=ident1 value=value1|ident=ident2 value=value2|ident=ident3 value=value3
  3112. *
  3113. * <b>Input-Array like this:</b>
  3114. * <pre>
  3115. * $customFieldSet = array();
  3116. *
  3117. * $customFieldSet['ident'] = 'value';
  3118. * $customFieldSet['ident'] = 'value';
  3119. * </pre>
  3120. *
  3121. * @author Stefan Zehnpfennig
  3122. * @param integer $tokentype token type
  3123. * @param integer $tokenid1 groupID
  3124. * @param integer $tokenid2 channelID
  3125. * @param string $description token description [optional]
  3126. * @param array $customFieldSet customFieldSet [optional]
  3127. * @return array tokenInformation
  3128. */
  3129. function privilegekeyAdd($tokentype, $tokenid1, $tokenid2, $description ='', $customFieldSet = array()) {
  3130. return $this->tokenAdd($tokentype, $tokenid1, $tokenid2, $description, $customFieldSet);
  3131. }
  3132.  
  3133. /**
  3134. * privilegekeyDelete
  3135. *
  3136. * Deletes an existing token matching the token key specified with token.
  3137. *
  3138. * @author Stefan Zehnpfennig
  3139. * @param string $token token
  3140. * @return boolean success
  3141. */
  3142. function privilegekeyDelete($token) {
  3143. return $this->tokenDelete($token);
  3144. }
  3145.  
  3146. /**
  3147. * privilegekeyList
  3148. *
  3149. * Displays a list of privilege keys available including their type and group IDs. Tokens can be used to gain access to specified server or channel groups. A privilege key is similar to a client with administrator privileges that adds you to a certain permission group, but without the necessity of a such a client with administrator privileges to actually exist. It is a long (random looking) string that can be used as a ticket into a specific server group.
  3150. *
  3151. * <b>Output:</b>
  3152. * <pre>
  3153. * Array
  3154. * {
  3155. * [token] => GdqedxSEDle3e9+LtR3o9dO09bURH+vymvF5hOJg
  3156. * [token_type] => 0
  3157. * [token_id1] => 71
  3158. * [token_id2] => 0
  3159. * [token_created] => 1286625908
  3160. * [token_description] => for you
  3161. * }
  3162. * </pre>
  3163. *
  3164. * @author Stefan Zehnpfennig
  3165. * @return array tokenListist
  3166. */
  3167. function privilegekeyList() {
  3168. return $this->tokenList();
  3169. }
  3170.  
  3171. /**
  3172. * privilegekeyUse
  3173. *
  3174. * Use a token key gain access to a server or channel group. Please note that the server will automatically delete the token after it has been used.
  3175. *
  3176. * @author Stefan Zehnpfennig
  3177. * @param string $token token
  3178. * @return boolean success
  3179. */
  3180. function privilegekeyUse($token) {
  3181. return $this->tokenUse($token);
  3182. }
  3183.  
  3184. /**
  3185. * quit closes the connection to host
  3186. *
  3187. * @author Stefan Zehnpfennig
  3188. * @return none
  3189. */
  3190. private function quit() {
  3191. $this->logout();
  3192. @fputs($this->runtime['socket'], "quit\n");
  3193. @fclose($this->runtime['socket']);
  3194. }
  3195. /**
  3196. * loadQueryData
  3197. *
  3198. * Loads the query current nickname and current clid
  3199. *
  3200. * @author toxiicdev (@toxiicdev.net)
  3201. */
  3202. private function loadQueryData()
  3203. {
  3204. $whoAmI = $this->getElement('data', $this->whoAmI());
  3205. $this->runtime['bot_name'] = $whoAmI['client_nickname'];
  3206.  
  3207. $clients = $this->clientList();
  3208. foreach($clients['data'] as $client)
  3209. {
  3210. if(strstr($this->runtime['bot_name'], $client['client_nickname']))
  3211. {
  3212. $this->runtime['bot_clid'] = $client['clid'];
  3213. break;
  3214. }
  3215. }
  3216. }
  3217.  
  3218. /**
  3219. * selectServer
  3220. *
  3221. * Selects the virtual server specified with sid or port to allow further interaction. The ServerQuery client will appear on the virtual server and acts like a real TeamSpeak 3 Client, except it's unable to send or receive voice data. If your database contains multiple virtual servers using the same UDP port, use will select a random virtual server using the specified port.
  3222. *
  3223. * @author Stefan Zehnpfennig
  3224. * @param integer $value Port or ID
  3225. * @param string $type value type ('port', 'serverId') (default='port')
  3226. * @param boolean $virtual set true to add -virtual param [optional]
  3227. * @return boolean success
  3228. */
  3229. function selectServer($value, $type = 'port', $virtual = false) {
  3230. if(in_array($type, array('port', 'serverId'))) {
  3231. if($type == 'port') {
  3232. if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; }
  3233. $res = $this->getData('boolean', 'use port='.$value.$virtual);
  3234. if($res['success']) {
  3235. $this->runtime['selected'] = true;
  3236. $this->loadQueryData();
  3237. }
  3238. return $res;
  3239. }else{
  3240. if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; }
  3241. $res = $this->getData('boolean', 'use sid='.$value.$virtual);
  3242. if($res['success']) {
  3243. $this->runtime['selected'] = true;
  3244. $this->loadQueryData();
  3245. }
  3246. return $res;
  3247. }
  3248. }else{
  3249. $this->addDebugLog('wrong value type');
  3250. return $this->generateOutput(false, array('Error: wrong value type'), false);
  3251. }
  3252. }
  3253.  
  3254. /**
  3255. * sendMessage
  3256. *
  3257. * Sends a text message a specified target. The type of the target is determined by targetmode while target specifies the ID of the recipient, whether it be a virtual server, a channel or a client.
  3258. * <b>Hint:</b> You can just write to the channel the query client is in. See link in description for details.
  3259. *
  3260. * <b>Modes:</b>
  3261. * <ul>
  3262. * <li><b>1:</b> send to client</li>
  3263. * <li><b>2:</b> send to channel</li>
  3264. * <li><b>3:</b> send to server</li>
  3265. * </ul>
  3266. * <b>Targets:</b>
  3267. * <ul>
  3268. * <li>clientID</li>
  3269. * <li>channelID</li>
  3270. * <li>serverID</li>
  3271. * </ul>
  3272. *
  3273. * @author Stefan Zehnpfennig
  3274. * @param integer $mode
  3275. * @param integer $target
  3276. * @param string $msg Message
  3277. * @see http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client
  3278. * @return boolean success
  3279. */
  3280. function sendMessage($mode, $target, $msg) {
  3281. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3282. return $this->getData('boolean', 'sendtextmessage targetmode='.$mode.' target='.$target.' msg='.$this->escapeText($msg));
  3283. }
  3284.  
  3285. /**
  3286. * serverCreate
  3287. *
  3288. * Creates a new virtual server using the given properties and displays its ID, port and initial administrator privilege key. If virtualserver_port is not specified, the server will test for the first unused UDP port. The first virtual server will be running on UDP port 9987 by default. Subsequently started virtual servers will be running on increasing UDP port numbers.
  3289. *
  3290. * <b>Input-Array like this:</b>
  3291. * <pre>
  3292. * $data = array();
  3293. *
  3294. * $data['setting'] = 'value';
  3295. * $data['setting'] = 'value';
  3296. * </pre>
  3297. *
  3298. * <b>Output:</b>
  3299. * <pre>
  3300. * Array
  3301. * {
  3302. * [sid] => 2
  3303. * [virtualserver_port] => 9988
  3304. * [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
  3305. * }
  3306. * </pre>
  3307. *
  3308. * <b>Possible properties:</b> VIRTUALSERVER_NAME, VIRTUALSERVER_WELCOMEMESSAGE, VIRTUALSERVER_MAXCLIENTS, VIRTUALSERVER_PASSWORD, VIRTUALSERVER_HOSTMESSAGE, VIRTUALSERVER_HOSTMESSAGE_MODE, VIRTUALSERVER_DEFAULT_SERVER_GROUP, VIRTUALSERVER_DEFAULT_CHANNEL_GROUP, VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP, VIRTUALSERVER_MAX_DOWNLOAD_TOTAL_BANDWIDTH, VIRTUALSERVER_MAX_UPLOAD_TOTAL_BANDWIDTH, VIRTUALSERVER_HOSTBANNER_URL, VIRTUALSERVER_HOSTBANNER_GFX_URL, VIRTUALSERVER_HOSTBANNER_GFX_INTERVAL, VIRTUALSERVER_COMPLAIN_AUTOBAN_COUNT, VIRTUALSERVER_COMPLAIN_AUTOBAN_TIME, VIRTUALSERVER_COMPLAIN_REMOVE_TIME, VIRTUALSERVER_MIN_CLIENTS_IN_CHANNEL_BEFORE_FORCED_SILENCE, VIRTUALSERVER_PRIORITY_SPEAKER_DIMM_MODIFICATOR, VIRTUALSERVER_ANTIFLOOD_POINTS_TICK_REDUCE, VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_COMMAND_BLOCK, VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_IP_BLOCK, VIRTUALSERVER_HOSTBANNER_MODE, VIRTUALSERVER_HOSTBUTTON_TOOLTIP, VIRTUALSERVER_HOSTBUTTON_GFX_URL, VIRTUALSERVER_HOSTBUTTON_URL, VIRTUALSERVER_DOWNLOAD_QUOTA, VIRTUALSERVER_UPLOAD_QUOTA, VIRTUALSERVER_MACHINE_ID, VIRTUALSERVER_PORT, VIRTUALSERVER_AUTOSTART, VIRTUALSERVER_STATUS, VIRTUALSERVER_LOG_CLIENT, VIRTUALSERVER_LOG_QUERY, VIRTUALSERVER_LOG_CHANNEL, VIRTUALSERVER_LOG_PERMISSIONS, VIRTUALSERVER_LOG_SERVER, VIRTUALSERVER_LOG_FILETRANSFER, VIRTUALSERVER_MIN_CLIENT_VERSION, VIRTUALSERVER_MIN_ANDROID_VERSION, VIRTUALSERVER_MIN_IOS_VERSION, VIRTUALSERVER_MIN_WINPHONE_VERSION, VIRTUALSERVER_NEEDED_IDENTITY_SECURITY_LEVEL, VIRTUALSERVER_NAME_PHONETIC, VIRTUALSERVER_ICON_ID, VIRTUALSERVER_RESERVED_SLOTS, VIRTUALSERVER_WEBLIST_ENABLED, VIRTUALSERVER_CODEC_ENCRYPTION_MODE
  3309. *
  3310. * @author Stefan Zehnpfennig
  3311. * @param array $data serverSettings [optional]
  3312. * @return array serverInfo
  3313. */
  3314. function serverCreate($data = array()) {
  3315. $settingsString = '';
  3316.  
  3317. if(count($data) == 0) { $data['virtualserver_name'] = 'Teamspeak 3 Server'; }
  3318.  
  3319.  
  3320. foreach($data as $key => $value) {
  3321. if(!empty($value)) { $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value); }
  3322. }
  3323.  
  3324. return $this->getData('array', 'servercreate'.$settingsString);
  3325. }
  3326.  
  3327. /**
  3328. * serverDelete
  3329. *
  3330. * Deletes the virtual server specified with sid. Please note that only virtual servers in stopped state can be deleted.
  3331. *
  3332. * @author Stefan Zehnpfennig
  3333. * @param integer $sid serverID
  3334. * @return boolean success
  3335. */
  3336. function serverDelete($sid) {
  3337. $this->serverStop($sid);
  3338. return $this->getdata('boolean', 'serverdelete sid='.$sid);
  3339. }
  3340.  
  3341. /**
  3342. * serverEdit
  3343. *
  3344. * Changes the selected virtual servers configuration using given properties. Note that this command accepts multiple properties which means that you're able to change all settings of the selected virtual server at once.
  3345. *
  3346. * <b>Input-Array like this:</b>
  3347. * <pre>
  3348. * $data = array();
  3349. *
  3350. * $data['setting'] = 'value';
  3351. * $data['setting'] = 'value';
  3352. * </pre>
  3353. *
  3354. * <b>Possible properties:</b> Take a look at serverCreate function
  3355. *
  3356. * @author Stefan Zehnpfennig
  3357. * @param array $data serverSettings
  3358. * @return boolean success
  3359. */
  3360. function serverEdit($data) {
  3361. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3362.  
  3363. $settingsString = '';
  3364.  
  3365. foreach($data as $key => $value) {
  3366. $settingsString .= ' '.strtolower($key).'='.$this->escapeText($value);
  3367. }
  3368.  
  3369. return $this->getData('boolean', 'serveredit'.$settingsString);
  3370. }
  3371.  
  3372. /**
  3373. * serverGroupAdd
  3374. *
  3375. * Creates a new server group using the name specified with name and displays its ID. The optional type parameter can be used to create ServerQuery groups and template groups. For detailed information, see
  3376. *
  3377. * <b>Output:</b>
  3378. * <pre>
  3379. * Array
  3380. * {
  3381. * [sgid] => 86
  3382. * }
  3383. * </pre>
  3384. *
  3385. * @author Stefan Zehnpfennig
  3386. * @param integer $name groupName
  3387. * @param integer $type groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
  3388. * @return array groupId
  3389. */
  3390. function serverGroupAdd($name, $type = 1) {
  3391. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3392. return $this->getData('array', 'servergroupadd name='.$this->escapeText($name).' type='.$type);
  3393. }
  3394.  
  3395. /**
  3396. * serverGroupAddClient
  3397. *
  3398. * Adds a client to the server group specified with sgid. Please note that a client cannot be added to default groups or template groups.
  3399. *
  3400. * @author Stefan Zehnpfennig
  3401. * @param integer $sgid serverGroupId
  3402. * @param integer $cldbid clientDBID
  3403. * @return boolean success
  3404. */
  3405. function serverGroupAddClient($sgid, $cldbid) {
  3406. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3407. return $this->getData('boolean', 'servergroupaddclient sgid='.$sgid.' cldbid='.$cldbid);
  3408. }
  3409.  
  3410. /**
  3411. * serverGroupAddPerm
  3412. *
  3413. * Adds a set of specified permissions to the server group specified with sgid. Multiple permissions can be added by providing the four parameters of each permission. A permission can be specified by permid or permsid.
  3414. *
  3415. * <b>Input-Array like this:</b>
  3416. * <pre>
  3417. * $permissions = array();
  3418. * $permissions['permissionID'] = array('permissionValue', 'permskip', 'permnegated');
  3419. * //or you could use
  3420. * $permissions['permissionName'] = array('permissionValue', 'permskip', 'permnegated');
  3421. * </pre>
  3422. *
  3423. * @author Stefan Zehnpfennig
  3424. * @param integer $sgid serverGroupID
  3425. * @param array $permissions permissions
  3426. * @return boolean success
  3427. */
  3428. function serverGroupAddPerm($sgid, $permissions) {
  3429. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3430.  
  3431. if(count($permissions) > 0) {
  3432. //Permissions given
  3433.  
  3434. //Errorcollector
  3435. $errors = array();
  3436.  
  3437. //Split Permissions to prevent query from overload
  3438. $permissions = array_chunk($permissions, 50, true);
  3439.  
  3440. //Action for each splitted part of permission
  3441. foreach($permissions as $permission_part)
  3442. {
  3443. //Create command_string for each command that we could use implode later
  3444. $command_string = array();
  3445.  
  3446. foreach($permission_part as $key => $value)
  3447. {
  3448. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
  3449. }
  3450.  
  3451. $result = $this->getData('boolean', 'servergroupaddperm sgid='.$sgid.' '.implode('|', $command_string));
  3452.  
  3453. if(!$result['success'])
  3454. {
  3455. foreach($result['errors'] as $error)
  3456. {
  3457. $errors[] = $error;
  3458. }
  3459. }
  3460. }
  3461.  
  3462. if(count($errors) == 0)
  3463. {
  3464. return $this->generateOutput(true, array(), true);
  3465. }else{
  3466. return $this->generateOutput(false, $errors, false);
  3467. }
  3468.  
  3469. }else{
  3470. // No permissions given
  3471. $this->addDebugLog('no permissions given');
  3472. return $this->generateOutput(false, array('Error: no permissions given'), false);
  3473. }
  3474. }
  3475.  
  3476. /**
  3477. * serverGroupAutoAddPerm
  3478. *
  3479. * Adds a set of specified permissions to *ALL* regular server groups on all virtual servers. The target groups will be identified by the value of their i_group_auto_update_type permission specified with sgtype. Multiple permissions can be added at once. A permission can be specified by permid or permsid. The known values for sgtype are: 10: Channel Guest 15: Server Guest 20: Query Guest 25: Channel Voice 30: Server Normal 35: Channel Operator 40: Channel Admin 45: Server Admin 50: Query Admin
  3480. *
  3481. * <b>Input-Array like this:</b>
  3482. * <pre>
  3483. * $permissions = array();
  3484. * $permissions['permissionID'] = array('permissionValue', 'permskip', 'permnegated');
  3485. * //or you could use
  3486. * $permissions['permissionName'] = array('permissionValue', 'permskip', 'permnegated');
  3487. * </pre>
  3488. *
  3489. * @author Stefan Zehnpfennig
  3490. * @param integer $sgtype serverGroupType
  3491. * @param array $permissions permissions
  3492. * @return boolean success
  3493. */
  3494. function serverGroupAutoAddPerm($sgtype, $permissions) {
  3495. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3496.  
  3497. if(count($permissions) > 0) {
  3498. //Permissions given
  3499.  
  3500. //Errorcollector
  3501. $errors = array();
  3502.  
  3503. //Split Permissions to prevent query from overload
  3504. $permissions = array_chunk($permissions, 50, true);
  3505.  
  3506. //Action for each splitted part of permission
  3507. foreach($permissions as $permission_part)
  3508. {
  3509. //Create command_string for each command that we could use implode later
  3510. $command_string = array();
  3511.  
  3512. foreach($permission_part as $key => $value)
  3513. {
  3514. $command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
  3515. }
  3516.  
  3517. $result = $this->getData('boolean', 'servergroupautoaddperm sgtype='.$sgtype.' '.implode('|', $command_string));
  3518.  
  3519. if(!$result['success'])
  3520. {
  3521. foreach($result['errors'] as $error)
  3522. {
  3523. $errors[] = $error;
  3524. }
  3525. }
  3526. }
  3527.  
  3528. if(count($errors) == 0)
  3529. {
  3530. return $this->generateOutput(true, array(), true);
  3531. }else{
  3532. return $this->generateOutput(false, $errors, false);
  3533. }
  3534.  
  3535. }else{
  3536. // No permissions given
  3537. $this->addDebugLog('no permissions given');
  3538. return $this->generateOutput(false, array('Error: no permissions given'), false);
  3539. }
  3540. }
  3541.  
  3542. /**
  3543. * serverGroupAutoDeletePerm
  3544. *
  3545. * Removes a set of specified permissions from *ALL* regular server groups on all virtual servers. The target groups will be identified by the value of their i_group_auto_update_type permission specified with sgtype. Multiple permissions can be removed at once. A permission can be specified by permid or permsid. The known values for sgtype are: 10: Channel Guest 15: Server Guest 20: Query Guest 25: Channel Voice 30: Server Normal 35: Channel Operator 40: Channel Admin 45: Server Admin 50: Query Admin
  3546. *
  3547. * <b>Input-Array like this:</b>
  3548. * <pre>
  3549. * $permissions = array();
  3550. * $permissions[] = 'permissionID';
  3551. * //or you could use
  3552. * $permissions[] = 'permissionName';
  3553. * </pre>
  3554. *
  3555. * @author Stefan Zehnpfennig
  3556. * @param integer $sgtype serverGroupType
  3557. * @param array $permissions permissions
  3558. * @return boolean success
  3559. */
  3560. function serverGroupAutoDeletePerm($sgtype, $permissions) {
  3561. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3562. $permissionArray = array();
  3563.  
  3564. if(count($permissions) > 0) {
  3565. foreach($permissions AS $value) {
  3566. $permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$this->escapeText($value);
  3567. }
  3568. return $this->getData('boolean', 'servergroupautodelperm sgtype='.$sgtype.' '.implode('|', $permissionArray));
  3569. }else{
  3570. $this->addDebugLog('no permissions given');
  3571. return $this->generateOutput(false, array('Error: no permissions given'), false);
  3572. }
  3573. }
  3574.  
  3575. /**
  3576. * serverGroupClientList
  3577. *
  3578. * Displays the IDs of all clients currently residing in the server group specified with sgid. If you're using the optional -names option, the output will also contain the last known nickname and the unique identifier of the clients.
  3579. *
  3580. * <b>Possible params:</b> -names
  3581. *
  3582. * <b>Output: (with -names param)</b>
  3583. * <pre>
  3584. * Array
  3585. * {
  3586. * [cldbid] => 2017
  3587. * [client_nickname] => Par0noid //with -names parameter
  3588. * [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
  3589. * }
  3590. * </pre>
  3591. *
  3592. * @author Stefan Zehnpfennig
  3593. * @param integer $sgid groupId
  3594. * @param boolean $names set true to add -names param [optional]
  3595. * @return multidimensional-array serverGroupClientList
  3596. */
  3597. function serverGroupClientList($sgid, $names = false) {
  3598. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3599. if($names) { $names = ' -names'; }else{ $names = ''; }
  3600. return $this->getData('multi', 'servergroupclientlist sgid='.$sgid.$names);
  3601. }
  3602.  
  3603. /**
  3604. * serverGroupCopy
  3605. *
  3606. * Creates a copy of the server group specified with ssgid. If tsgid is set to 0, the server will create a new group. To overwrite an existing group, simply set tsgid to the ID of a designated target group. If a target group is set, the name parameter will be ignored.
  3607. *
  3608. * <b>Output:</b>
  3609. * <pre>
  3610. * Array
  3611. * {
  3612. * [sgid] => 86
  3613. * }
  3614. * </pre>
  3615. *
  3616. * @author Stefan Zehnpfennig
  3617. * @param integer $ssgid sourceGroupID
  3618. * @param integer $tsgid targetGroupID
  3619. * @param integer $name groupName
  3620. * @param integer $type groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
  3621. * @return array groupId
  3622. */
  3623. function serverGroupCopy($ssgid, $tsgid, $name, $type = 1) {
  3624. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3625. return $this->getData('array', 'servergroupcopy ssgid='.$ssgid.' tsgid='.$tsgid.' name='.$this->escapeText($name).' type='.$type);
  3626. }
  3627.  
  3628. /**
  3629. * serverGroupDelete
  3630. *
  3631. * Deletes the server group specified with sgid. If force is set to 1, the server group will be deleted even if there are clients within.
  3632. *
  3633. * @author Stefan Zehnpfennig
  3634. * @param integer $sgid serverGroupID
  3635. * @param integer $force forces deleting group (Default: 1)
  3636. * @return boolean success
  3637. */
  3638. function serverGroupDelete($sgid, $force = 1) {
  3639. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3640. return $this->getData('boolean', 'servergroupdel sgid='.$sgid.' force='.$force);
  3641. }
  3642.  
  3643. /**
  3644. * serverGroupDeleteClient
  3645. *
  3646. * Removes a client specified with cldbid from the server group specified with sgid.
  3647. *
  3648. * @author Stefan Zehnpfennig
  3649. * @param integer $sgid groupID
  3650. * @param integer $cldbid clientDBID
  3651. * @return boolean success
  3652. */
  3653. function serverGroupDeleteClient($sgid, $cldbid) {
  3654. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3655. return $this->getData('boolean', 'servergroupdelclient sgid='.$sgid.' cldbid='.$cldbid);
  3656. }
  3657.  
  3658. /**
  3659. * serverGroupDeletePerm
  3660. *
  3661. * Removes a set of specified permissions from the server group specified with sgid. Multiple permissions can be removed at once. A permission can be specified by permid or permsid.
  3662. *
  3663. * <b>Input-Array like this:</b>
  3664. * <pre>
  3665. * $permissions = array();
  3666. * $permissions[] = 'permissionID';
  3667. * //or you could use
  3668. * $permissions[] = 'permissionName';
  3669. * </pre>
  3670. *
  3671. * @author Stefan Zehnpfennig
  3672. * @param integer $sgid serverGroupID
  3673. * @param array $permissionIds permissionIds
  3674. * @return boolean success
  3675. */
  3676. function serverGroupDeletePerm($sgid, $permissionIds) {
  3677. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3678. $permissionArray = array();
  3679.  
  3680. if(count($permissionIds) > 0) {
  3681. foreach($permissionIds AS $value) {
  3682. $permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$this->escapeText($value);
  3683. }
  3684. return $this->getData('boolean', 'servergroupdelperm sgid='.$sgid.' '.implode('|', $permissionArray));
  3685. }else{
  3686. $this->addDebugLog('no permissions given');
  3687. return $this->generateOutput(false, array('Error: no permissions given'), false);
  3688. }
  3689. }
  3690.  
  3691. /**
  3692. * serverGroupGetIconBySGID
  3693. *
  3694. * Will return the base64 encoded binary of the serverGroupIcon
  3695. *
  3696. * <pre>
  3697. * $result = $tsAdmin->serverGroupGetIconBySGID($serverGroupID);
  3698. * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
  3699. * </pre>
  3700. *
  3701. * @author Stefan Zehnpfennig
  3702. * @param string $serverGroupID serverGroupID
  3703. * @return array base64 image
  3704. */
  3705. function serverGroupGetIconBySGID($serverGroupID) {
  3706. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3707.  
  3708. if(empty($serverGroupID))
  3709. {
  3710. return $this->generateOutput(false, array('Error: empty serverGroupID'), false);
  3711. }
  3712.  
  3713. $serverGroupList = $this->serverGroupList();
  3714.  
  3715. if(!$serverGroupList["success"])
  3716. {
  3717. return $this->generateOutput(false, $serverGroupList["error"], false);
  3718. }
  3719.  
  3720. $sgid = -1;
  3721. $iconID = 0;
  3722.  
  3723. foreach($serverGroupList['data'] as $group)
  3724. {
  3725. if($group['sgid'] == $serverGroupID)
  3726. {
  3727. $sgid = $group['sgid'];
  3728. $iconID = $group['iconid'];
  3729. break;
  3730. }
  3731. }
  3732.  
  3733. if($sgid == -1)
  3734. {
  3735. return $this->generateOutput(false, array('Error: invalid serverGroupID'), false);
  3736. }
  3737.  
  3738. if($iconID == '0')
  3739. {
  3740. return $this->generateOutput(false, array('Error: serverGroup has no icon'), false);
  3741. }
  3742.  
  3743. return $this->getIconByID($iconID);
  3744. }
  3745.  
  3746. /**
  3747. * serverGroupList
  3748. *
  3749. * Displays a list of server groups available. Depending on your permissions, the output may also contain global ServerQuery groups and template groups.
  3750. *
  3751. * <b>Output:</b>
  3752. * <pre>
  3753. * Array
  3754. * {
  3755. * [sgid] => 1
  3756. * [name] => Guest Server Query
  3757. * [type] => 2
  3758. * [iconid] => 0
  3759. * [savedb] => 0
  3760. * }
  3761. * </pre>
  3762. *
  3763. * @author Stefan Zehnpfennig
  3764. * @return array serverGroupList
  3765. */
  3766. function serverGroupList() {
  3767. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3768. return $this->getData('multi', 'servergrouplist');
  3769. }
  3770.  
  3771. /**
  3772. * serverGroupPermList
  3773. *
  3774. * Displays a list of permissions assigned to the server group specified with sgid. If the permsid option is specified, the output will contain the permission names instead of the internal IDs.
  3775. *
  3776. * <b>Output:</b>
  3777. * <pre>
  3778. * Array
  3779. * {
  3780. * [permid] => 12876 (if permsid = false)
  3781. * [permsid] => b_client_info_view (if permsid = true)
  3782. * [permvalue] => 1
  3783. * [permnegated] => 0
  3784. * [permskip] => 0
  3785. * }
  3786. * </pre>
  3787. *
  3788. * @author Stefan Zehnpfennig
  3789. * @param integer $sgid serverGroupID
  3790. * @param boolean $permsid set true to add -permsid param [optional]
  3791. * @return array serverGroupPermList
  3792. */
  3793. function serverGroupPermList($sgid, $permsid = false) {
  3794. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3795. if($permsid) { $additional = ' -permsid'; }else{ $additional = ''; }
  3796. return $this->getData('multi', 'servergrouppermlist sgid='.$sgid.$additional);
  3797. }
  3798.  
  3799. /**
  3800. * serverGroupRename
  3801. *
  3802. * Changes the name of the server group specified with sgid.
  3803. *
  3804. * @author Stefan Zehnpfennig
  3805. * @param integer $sgid serverGroupID
  3806. * @param integer $name groupName
  3807. * @return boolean success
  3808. */
  3809. function serverGroupRename($sgid, $name) {
  3810. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3811. return $this->getData('boolean', 'servergrouprename sgid='.$sgid.' name='.$this->escapeText($name));
  3812. }
  3813.  
  3814. /**
  3815. * serverGroupsByClientID
  3816. *
  3817. * Displays all server groups the client specified with cldbid is currently residing in.
  3818. *
  3819. * <b>Output:</b>
  3820. * <pre>
  3821. * Array
  3822. * {
  3823. * [name] => Guest
  3824. * [sgid] => 73
  3825. * [cldbid] => 2
  3826. * }
  3827. * </pre>
  3828. *
  3829. * @author Stefan Zehnpfennig
  3830. * @param integer $cldbid clientDBID
  3831. * @return array serverGroupsByClientId
  3832. */
  3833. function serverGroupsByClientID($cldbid) {
  3834. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3835. return $this->getData('multi', 'servergroupsbyclientid cldbid='.$cldbid);
  3836. }
  3837.  
  3838. /**
  3839. * serverIdGetByPort
  3840. *
  3841. * Displays the database ID of the virtual server running on the UDP port specified by virtualserver_port.
  3842. *
  3843. * <b>Output:</b>
  3844. * <pre>
  3845. * Array
  3846. * {
  3847. * [server_id] => 1
  3848. * }
  3849. * </pre>
  3850. *
  3851. * @author Stefan Zehnpfennig
  3852. * @param integer $port serverPort
  3853. * @return array serverInfo
  3854. */
  3855. function serverIdGetByPort($port) {
  3856. return $this->getData('array', 'serveridgetbyport virtualserver_port='.$port);
  3857. }
  3858.  
  3859. /**
  3860. * serverInfo
  3861. *
  3862. * Displays detailed configuration information about the selected virtual server including unique ID, number of clients online, configuration, etc.
  3863. *
  3864. * <b>Output:</b>
  3865. * <pre>
  3866. * Array
  3867. * {
  3868. * [virtualserver_unique_identifier] => 1GvKR12fg/mY75flwN/u7pn7KIs=
  3869. * [virtualserver_name] => TeamSpeak ]I[ Server
  3870. * [virtualserver_welcomemessage] => Welcome to TeamSpeak, check [URL]www.teamspeak.com[/URL] for latest information
  3871. * [virtualserver_platform] => Windows
  3872. * [virtualserver_version] => 3.0.12.4 [Build: 1461597405]
  3873. * [virtualserver_maxclients] => 32
  3874. * [virtualserver_password] =>
  3875. * [virtualserver_clientsonline] => 2
  3876. * [virtualserver_channelsonline] => 1
  3877. * [virtualserver_created] => 0
  3878. * [virtualserver_uptime] => 6517
  3879. * [virtualserver_codec_encryption_mode] => 0
  3880. * [virtualserver_hostmessage] =>
  3881. * [virtualserver_hostmessage_mode] => 0
  3882. * [virtualserver_filebase] => files\\virtualserver_1
  3883. * [virtualserver_default_server_group] => 11
  3884. * [virtualserver_default_channel_group] => 12
  3885. * [virtualserver_flag_password] => 0
  3886. * [virtualserver_default_channel_admin_group] => 9
  3887. * [virtualserver_max_download_total_bandwidth] => 18446744073709551615
  3888. * [virtualserver_max_upload_total_bandwidth] => 18446744073709551615
  3889. * [virtualserver_hostbanner_url] =>
  3890. * [virtualserver_hostbanner_gfx_url] =>
  3891. * [virtualserver_hostbanner_gfx_interval] => 0
  3892. * [virtualserver_complain_autoban_count] => 5
  3893. * [virtualserver_complain_autoban_time] => 1200
  3894. * [virtualserver_complain_remove_time] => 3600
  3895. * [virtualserver_min_clients_in_channel_before_forced_silence] => 100
  3896. * [virtualserver_priority_speaker_dimm_modificator] => -18.0000
  3897. * [virtualserver_id] => 1
  3898. * [virtualserver_antiflood_points_tick_reduce] => 5
  3899. * [virtualserver_antiflood_points_needed_command_block] => 150
  3900. * [virtualserver_antiflood_points_needed_ip_block] => 250
  3901. * [virtualserver_client_connections] => 1
  3902. * [virtualserver_query_client_connections] => 54
  3903. * [virtualserver_hostbutton_tooltip] =>
  3904. * [virtualserver_hostbutton_url] =>
  3905. * [virtualserver_hostbutton_gfx_url] =>
  3906. * [virtualserver_queryclientsonline] => 1
  3907. * [virtualserver_download_quota] => 18446744073709551615
  3908. * [virtualserver_upload_quota] => 18446744073709551615
  3909. * [virtualserver_month_bytes_downloaded] => 0
  3910. * [virtualserver_month_bytes_uploaded] => 16045
  3911. * [virtualserver_total_bytes_downloaded] => 0
  3912. * [virtualserver_total_bytes_uploaded] => 16045
  3913. * [virtualserver_port] => 9987
  3914. * [virtualserver_autostart] => 1
  3915. * [virtualserver_machine_id] =>
  3916. * [virtualserver_needed_identity_security_level] => 8
  3917. * [virtualserver_log_client] => 0
  3918. * [virtualserver_log_query] => 0
  3919. * [virtualserver_log_channel] => 0
  3920. * [virtualserver_log_permissions] => 1
  3921. * [virtualserver_log_server] => 0
  3922. * [virtualserver_log_filetransfer] => 0
  3923. * [virtualserver_min_client_version] => 1445512488
  3924. * [virtualserver_name_phonetic] =>
  3925. * [virtualserver_icon_id] => 0
  3926. * [virtualserver_reserved_slots] => 0
  3927. * [virtualserver_total_packetloss_speech] => 0.0000
  3928. * [virtualserver_total_packetloss_keepalive] => 0.0000
  3929. * [virtualserver_total_packetloss_control] => 0.0000
  3930. * [virtualserver_total_packetloss_total] => 0.0000
  3931. * [virtualserver_total_ping] => 0.0000
  3932. * [virtualserver_ip] =>
  3933. * [virtualserver_weblist_enabled] => 1
  3934. * [virtualserver_ask_for_privilegekey] => 0
  3935. * [virtualserver_hostbanner_mode] => 0
  3936. * [virtualserver_channel_temp_delete_delay_default] => 0
  3937. * [virtualserver_min_android_version] => 1407159763
  3938. * [virtualserver_min_ios_version] => 1407159763
  3939. * [virtualserver_status] => online
  3940. * [connection_filetransfer_bandwidth_sent] => 0
  3941. * [connection_filetransfer_bandwidth_received] => 0
  3942. * [connection_filetransfer_bytes_sent_total] => 0
  3943. * [connection_filetransfer_bytes_received_total] => 0
  3944. * [connection_packets_sent_speech] => 0
  3945. * [connection_bytes_sent_speech] => 0
  3946. * [connection_packets_received_speech] => 0
  3947. * [connection_bytes_received_speech] => 0
  3948. * [connection_packets_sent_keepalive] => 12959
  3949. * [connection_bytes_sent_keepalive] => 531319
  3950. * [connection_packets_received_keepalive] => 12959
  3951. * [connection_bytes_received_keepalive] => 544277
  3952. * [connection_packets_sent_control] => 396
  3953. * [connection_bytes_sent_control] => 65555
  3954. * [connection_packets_received_control] => 397
  3955. * [connection_bytes_received_control] => 44930
  3956. * [connection_packets_sent_total] => 13355
  3957. * [connection_bytes_sent_total] => 596874
  3958. * [connection_packets_received_total] => 13356
  3959. * [connection_bytes_received_total] => 589207
  3960. * [connection_bandwidth_sent_last_second_total] => 81
  3961. * [connection_bandwidth_sent_last_minute_total] => 92
  3962. * [connection_bandwidth_received_last_second_total] => 83
  3963. * [connection_bandwidth_received_last_minute_total] => 88
  3964. * }
  3965. * </pre>
  3966. *
  3967. * @author Stefan Zehnpfennig
  3968. * @return array serverInformation
  3969. */
  3970. function serverInfo() {
  3971. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  3972. return $this->getData('array', 'serverinfo');
  3973. }
  3974.  
  3975. /**
  3976. * serverList
  3977. *
  3978. * Displays a list of virtual servers including their ID, status, number of clients online, etc. If you're using the -all option, the server will list all virtual servers stored in the database. This can be useful when multiple server instances with different machine IDs are using the same database. The machine ID is used to identify the server instance a virtual server is associated with. The status of a virtual server can be either online, offline, deploy running, booting up, shutting down and virtual online. While most of them are self-explanatory, virtual online is a bit more complicated. Please note that whenever you select a virtual server which is currently stopped, it will be started in virtual mode which means you are able to change its configuration, create channels or change permissions, but no regular TeamSpeak 3 Client can connect. As soon as the last ServerQuery client deselects the virtual server, its status will be changed back to offline.
  3979. *
  3980. * <b>Possible params:</b> [-uid] [-short] [-all] [-onlyoffline]
  3981. *
  3982. * <b>Output:</b>
  3983. * <pre>
  3984. * Array
  3985. * {
  3986. * [virtualserver_id] => 1 //displayed on -short
  3987. * [virtualserver_port] => 9987 //displayed on -short
  3988. * [virtualserver_status] => online //displayed on -short
  3989. * [virtualserver_clientsonline] => 2
  3990. * [virtualserver_queryclientsonline] => 1
  3991. * [virtualserver_maxclients] => 32
  3992. * [virtualserver_uptime] => 3045
  3993. * [virtualserver_name] => TeamSpeak ]I[ Server
  3994. * [virtualserver_autostart] => 1
  3995. * [virtualserver_machine_id] =>
  3996. * [-uid] => [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U=
  3997. * }
  3998. * </pre>
  3999. *
  4000. * @author Stefan Zehnpfennig
  4001. * @param string $options optional parameters
  4002. * @return array serverList
  4003. */
  4004. function serverList($options = NULL) {
  4005. return $this->getData('multi', 'serverlist'.(!empty($options) ? ' '.$options : ''));
  4006. }
  4007.  
  4008. /**
  4009. * serverProcessStop
  4010. *
  4011. * Stops the entire TeamSpeak 3 Server instance by shutting down the process.
  4012. *
  4013. * @author Stefan Zehnpfennig
  4014. * @return boolean success
  4015. */
  4016. function serverProcessStop() {
  4017. return $this->getData('boolean', 'serverprocessstop');
  4018. }
  4019.  
  4020. /**
  4021. * serverRequestConnectionInfo
  4022. *
  4023. * Displays detailed connection information about the selected virtual server including uptime, traffic information, etc.
  4024. *
  4025. * <b>Output:</b>
  4026. * <pre>
  4027. * Array
  4028. * {
  4029. * [connection_filetransfer_bandwidth_sent] => 0
  4030. * [connection_filetransfer_bandwidth_received] => 0
  4031. * [connection_filetransfer_bytes_sent_total] => 0
  4032. * [connection_filetransfer_bytes_received_total] => 0
  4033. * [connection_packets_sent_total] => 3333
  4034. * [connection_bytes_sent_total] => 149687
  4035. * [connection_packets_received_total] => 3333
  4036. * [connection_bytes_received_total] => 147653
  4037. * [connection_bandwidth_sent_last_second_total] => 123
  4038. * [connection_bandwidth_sent_last_minute_total] => 81
  4039. * [connection_bandwidth_received_last_second_total] => 352
  4040. * [connection_bandwidth_received_last_minute_total] => 87
  4041. * [connection_connected_time] => 3387
  4042. * [connection_packetloss_total] => 0.0000
  4043. * [connection_ping] => 0.0000
  4044. * }
  4045. * </pre>
  4046. *
  4047. * @author Stefan Zehnpfennig
  4048. * @return array serverRequestConnectionInfo
  4049. */
  4050. function serverRequestConnectionInfo() {
  4051. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4052. return $this->getData('array', 'serverrequestconnectioninfo');
  4053. }
  4054.  
  4055. /**
  4056. * serverSnapshotCreate
  4057. *
  4058. * Displays a snapshot of the selected virtual server containing all settings, groups and known client identities. The data from a server snapshot can be used to restore a virtual servers configuration, channels and permissions using the serversnapshotdeploy command.
  4059. *
  4060. * @author Stefan Zehnpfennig
  4061. * @return string snapshot
  4062. */
  4063. function serverSnapshotCreate() {
  4064. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4065. return $this->getData('plain', 'serversnapshotcreate');
  4066. }
  4067.  
  4068. /**
  4069. * serverSnapshotDeploy
  4070. *
  4071. * Restores the selected virtual servers configuration using the data from a previously created server snapshot. Please note that the TeamSpeak 3 Server does NOT check for necessary permissions while deploying a snapshot so the command could be abused to gain additional privileges.
  4072. *
  4073. * + added "-mapping" to the serversnapshotdeploy command. This optional parameters will add a mapping of the old and new channelid's in the return
  4074. *
  4075. * @author Stefan Zehnpfennig
  4076. * @param string $snapshot snapshot
  4077. * @param bool $mapping mapping [optional]
  4078. * @return boolean success
  4079. */
  4080. function serverSnapshotDeploy($snapshot, $mapping = false) {
  4081. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4082. return $this->getData('boolean', 'serversnapshotdeploy '.($mapping ? '-mapping ' : '').$snapshot);
  4083. }
  4084.  
  4085. /**
  4086. * serverStart
  4087. *
  4088. * Starts the virtual server specified with sid. Depending on your permissions, you're able to start either your own virtual server only or all virtual servers in the server instance.
  4089. *
  4090. * @author Stefan Zehnpfennig
  4091. * @param integer $sid serverID
  4092. * @return boolean success
  4093. */
  4094. function serverStart($sid) {
  4095. return $this->getdata('boolean', 'serverstart sid='.$sid);
  4096. }
  4097.  
  4098. /**
  4099. * serverStop
  4100. *
  4101. * Stops the virtual server specified with sid. Depending on your permissions, you're able to stop either your own virtual server only or all virtual servers in the server instance.
  4102. *
  4103. * @author Stefan Zehnpfennig
  4104. * @param integer $sid serverID
  4105. * @return boolean success
  4106. */
  4107. function serverStop($sid) {
  4108. return $this->getdata('boolean', 'serverstop sid='.$sid);
  4109. }
  4110.  
  4111. /**
  4112. * serverTemppasswordAdd
  4113. *
  4114. * Sets a new temporary server password specified with pw. The temporary password will be valid for the number of seconds specified with duration. The client connecting with this password will automatically join the channel specified with tcid. If tcid is set to 0, the client will join the default channel.
  4115. *
  4116. * @author Stefan Zehnpfennig
  4117. * @param string $pw temporary password
  4118. * @param string $duration durations in seconds
  4119. * @param string $desc description [optional]
  4120. * @param string $tcid cid user enters on connect (0 = Default channel) [optional]
  4121. * @param string $tcpw channelPW
  4122. * @return boolean success
  4123. */
  4124. function serverTempPasswordAdd($pw, $duration, $desc = 'none', $tcid = 0, $tcpw = null) {
  4125. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4126. return $this->getdata('boolean', 'servertemppasswordadd pw='.$this->escapeText($pw).' desc='.(!empty($desc) ? $this->escapeText($desc) : 'none').' duration='.$duration.' tcid='.$tcid.(!empty($tcpw) ? ' tcpw='.$this->escapeText($tcpw) : ''));
  4127. }
  4128.  
  4129. /**
  4130. * serverTemppasswordDel
  4131. *
  4132. * Deletes the temporary server password specified with pw.
  4133. *
  4134. * @author Stefan Zehnpfennig
  4135. * @param string $pw temporary password
  4136. * @return boolean success
  4137. */
  4138. function serverTempPasswordDel($pw) {
  4139. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4140. return $this->getdata('boolean', 'servertemppassworddel pw='.$this->escapeText($pw));
  4141. }
  4142.  
  4143. /**
  4144. * serverTemppasswordList
  4145. *
  4146. * Returns a list of active temporary server passwords. The output contains the clear-text password, the nickname and unique identifier of the creating client.
  4147. *
  4148. * <b>Output:</b>
  4149. * <pre>
  4150. * Array
  4151. * {
  4152. * [nickname] => serveradmin
  4153. * [uid] => 1
  4154. * [desc] => none
  4155. * [pw_clear] => test
  4156. * [start] => 1334996838
  4157. * [end] => 1335000438
  4158. * [tcid] => 0
  4159. * }
  4160. * </pre>
  4161. *
  4162. * @author Stefan Zehnpfennig
  4163. * @return array serverTemppasswordList
  4164. */
  4165. function serverTempPasswordList() {
  4166. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4167. return $this->getData('multi', 'servertemppasswordlist');
  4168. }
  4169.  
  4170.  
  4171. /**
  4172. * setClientChannelGroup
  4173. *
  4174. * Sets the channel group of a client to the ID specified with cgid.
  4175. *
  4176. * @author Stefan Zehnpfennig
  4177. * @param integer $cgid groupID
  4178. * @param integer $cid channelID
  4179. * @param integer $cldbid clientDBID
  4180. * @return boolean success
  4181. */
  4182. function setClientChannelGroup($cgid, $cid, $cldbid) {
  4183. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4184. return $this->getData('boolean', 'setclientchannelgroup cgid='.$cgid.' cid='.$cid.' cldbid='.$cldbid);
  4185. }
  4186.  
  4187. /**
  4188. * setName
  4189. *
  4190. * Sets your nickname in server query
  4191. *
  4192. * @author Stefan Zehnpfennig
  4193. * @param string $newName new name in server query
  4194. * @return boolean success
  4195. */
  4196. function setName($newName) {
  4197. return $this->getData('boolean', 'clientupdate client_nickname='.$this->escapeText($newName));
  4198. }
  4199.  
  4200. /**
  4201. * tokenAdd
  4202. *
  4203. * Create a new token. If tokentype is set to 0, the ID specified with tokenid1 will be a server group ID. Otherwise, tokenid1 is used as a channel group ID and you need to provide a valid channel ID using tokenid2. The tokencustomset parameter allows you to specify a set of custom client properties. This feature can be used when generating tokens to combine a website account database with a TeamSpeak user. The syntax of the value needs to be escaped using the ServerQuery escape patterns and has to follow the general syntax of:
  4204. * ident=ident1 value=value1|ident=ident2 value=value2|ident=ident3 value=value3
  4205. *
  4206. * <b>Input-Array like this:</b>
  4207. * <pre>
  4208. * $customFieldSet = array();
  4209. *
  4210. * $customFieldSet['ident'] = 'value';
  4211. * $customFieldSet['ident'] = 'value';
  4212. * </pre>
  4213. *
  4214. * @author Stefan Zehnpfennig
  4215. * @param integer $tokentype token type
  4216. * @param integer $tokenid1 groupID
  4217. * @param integer $tokenid2 channelID
  4218. * @param string $description token description [optional]
  4219. * @param array $customFieldSet customFieldSet [optional]
  4220. * @return array tokenInformation
  4221. */
  4222. function tokenAdd($tokentype, $tokenid1, $tokenid2, $description ='', $customFieldSet = array()) {
  4223. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4224.  
  4225. if(!empty($description)) { $description = ' tokendescription=' . $this->escapeText($description); }
  4226.  
  4227. if($tokentype == '0') { $tokenid2 = '0'; }
  4228.  
  4229. if(count($customFieldSet)) {
  4230. $settingsString = array();
  4231.  
  4232. foreach($customFieldSet as $key => $value) {
  4233. $settingsString[] = 'ident='.$this->escapeText($key).'\svalue='.$this->escapeText($value);
  4234. }
  4235.  
  4236. $customFieldSet = ' tokencustomset='.implode('\p', $settingsString);
  4237. }else{
  4238. $customFieldSet = '';
  4239. }
  4240.  
  4241. return $this->getData('array', 'privilegekeyadd tokentype='.$tokentype.' tokenid1='.$tokenid1.' tokenid2='.$tokenid2.$description.$customFieldSet);
  4242. }
  4243.  
  4244. /**
  4245. * tokenDelete
  4246. *
  4247. * Deletes an existing token matching the token key specified with token.
  4248. *
  4249. * @author Stefan Zehnpfennig
  4250. * @param string $token token
  4251. * @return boolean success
  4252. */
  4253. function tokenDelete($token) {
  4254. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4255. return $this->getData('boolean', 'privilegekeydelete token='.$token);
  4256. }
  4257.  
  4258. /**
  4259. * tokenList
  4260. *
  4261. * Displays a list of privilege keys available including their type and group IDs. Tokens can be used to gain access to specified server or channel groups. A privilege key is similar to a client with administrator privileges that adds you to a certain permission group, but without the necessity of a such a client with administrator privileges to actually exist. It is a long (random looking) string that can be used as a ticket into a specific server group.
  4262. *
  4263. * <b>Output:</b>
  4264. * <pre>
  4265. * Array
  4266. * {
  4267. * [token] => GdqedxSEDle3e9+LtR3o9dO09bURH+vymvF5hOJg
  4268. * [token_type] => 0
  4269. * [token_id1] => 71
  4270. * [token_id2] => 0
  4271. * [token_created] => 1286625908
  4272. * [token_description] => for you
  4273. * }
  4274. * </pre>
  4275. *
  4276. * @author Stefan Zehnpfennig
  4277. * @return array tokenListist
  4278. */
  4279. function tokenList() {
  4280. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4281.  
  4282. return $this->getData('multi', 'privilegekeylist');
  4283. }
  4284.  
  4285. /**
  4286. * tokenUse
  4287. *
  4288. * Use a token key gain access to a server or channel group. Please note that the server will automatically delete the token after it has been used.
  4289. *
  4290. * @author Stefan Zehnpfennig
  4291. * @param string $token token
  4292. * @return boolean success
  4293. */
  4294. function tokenUse($token) {
  4295. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4296. return $this->getData('boolean', 'privilegekeyuse token='.$token);
  4297. }
  4298.  
  4299. /**
  4300. * version
  4301. *
  4302. * Displays the servers version information including platform and build number.
  4303. *
  4304. * <b>Output:</b>
  4305. * <pre>
  4306. * Array
  4307. * {
  4308. * [version] => 3.0.6.1
  4309. * [build] => 1340956745
  4310. * [platform] => Windows
  4311. * }
  4312. * </pre>
  4313. *
  4314. * @author Stefan Zehnpfennig
  4315. * @return array versionInformation
  4316. */
  4317. function version() {
  4318. return $this->getData('array', 'version');
  4319. }
  4320.  
  4321. /**
  4322. * whoAmI
  4323. *
  4324. * Displays information about your current ServerQuery connection including your loginname, etc.
  4325. *
  4326. * <b>Output:</b>
  4327. * <pre>
  4328. * Array
  4329. * {
  4330. * [virtualserver_status] => online
  4331. * [virtualserver_id] => 1
  4332. * [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U=
  4333. * [virtualserver_port] => 9987
  4334. * [client_id] => 5
  4335. * [client_channel_id] => 1
  4336. * [client_nickname] => serveradmin from 127.0.0.1:15208
  4337. * [client_database_id] => 1
  4338. * [client_login_name] => serveradmin
  4339. * [client_unique_identifier] => serveradmin
  4340. * [client_origin_server_id] => 0
  4341. * }
  4342. * </pre>
  4343. *
  4344. * @author Stefan Zehnpfennig
  4345. * @return array clientinformation
  4346. */
  4347. function whoAmI() {
  4348. return $this->getData('array', 'whoami');
  4349. }
  4350.  
  4351. //*******************************************************************************************
  4352. //************************************ Helper Functions ************************************
  4353. //*******************************************************************************************
  4354.  
  4355. /**
  4356. * checkSelected throws out 2 errors
  4357. *
  4358. * <b>Output:</b>
  4359. * <pre>
  4360. * Array
  4361. * {
  4362. * [success] => false
  4363. * [errors] => Array
  4364. * [data] => false
  4365. * }
  4366. * </pre>
  4367. *
  4368. * @author Stefan Zehnpfennig
  4369. * @return array error
  4370. */
  4371. private function checkSelected() {
  4372. $backtrace = debug_backtrace();
  4373. $this->addDebugLog('you can\'t use this function if no server is selected', $backtrace[1]['function'], $backtrace[0]['line']);
  4374. return $this->generateOutput(false, array('you can\'t use this function if no server is selected'), false);
  4375. }
  4376.  
  4377. /**
  4378. * convertSecondsToStrTime
  4379. *
  4380. * Converts seconds to a strTime (bsp. 5d 1h 23m 19s)
  4381. *
  4382. * @author Stefan Zehnpfennig
  4383. * @param integer $seconds time in seconds
  4384. * @return string strTime
  4385. */
  4386. public function convertSecondsToStrTime($seconds) {
  4387. $conv_time = $this->convertSecondsToArrayTime($seconds);
  4388. return $conv_time['days'].'d '.$conv_time['hours'].'h '.$conv_time['minutes'].'m '.$conv_time['seconds'].'s';
  4389. }
  4390.  
  4391. /**
  4392. * convertSecondsToArrayTime
  4393. *
  4394. * Converts seconds to a array: time
  4395. *
  4396. * <b>Output:</b>
  4397. * <pre>
  4398. * Array
  4399. * {
  4400. * [days] => 3
  4401. * [hours] => 9
  4402. * [minutes] => 45
  4403. * [seconds] => 17
  4404. * }
  4405. * </pre>
  4406. *
  4407. * @author Stefan Zehnpfennig
  4408. * @param integer $seconds time in seconds
  4409. * @return array time
  4410. */
  4411. public function convertSecondsToArrayTime($seconds) {
  4412. $conv_time = array();
  4413. $conv_time['days']=floor($seconds / 86400);
  4414. $conv_time['hours']=floor(($seconds - ($conv_time['days'] * 86400)) / 3600);
  4415. $conv_time['minutes']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600))) / 60);
  4416. $conv_time['seconds']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600)+($conv_time['minutes'] * 60))));
  4417. return $conv_time;
  4418. }
  4419.  
  4420. /**
  4421. * getElement
  4422. *
  4423. * Returns the given associated element from an array
  4424. * This can be used to get a result in a one line operation
  4425. *
  4426. * For example you got this array:
  4427. * <pre>
  4428. * Array
  4429. * {
  4430. * [success] => false
  4431. * [errors] => Array
  4432. * [data] => false
  4433. * }
  4434. * </pre>
  4435. * Now you can grab the element like this:
  4436. * <pre>
  4437. * $ts = new ts3admin('***', '***');
  4438. *
  4439. * if($ts->getElement('success', $ts->connect())) {
  4440. * //operation
  4441. * }
  4442. * </pre>
  4443. *
  4444. * @author Stefan Zehnpfennig
  4445. * @param string $element key of element
  4446. * @param array $array array
  4447. * @return mixed
  4448. */
  4449. public function getElement($element, $array) {
  4450. return $array[$element];
  4451. }
  4452.  
  4453. /**
  4454. * succeeded
  4455. *
  4456. * Succeeded will check the success element of a return array
  4457. * <pre>
  4458. * $ts = new ts3admin('***', '***');
  4459. *
  4460. * if($ts->succeeded($ts->connect())) {
  4461. * //operation
  4462. * }
  4463. * </pre>
  4464. *
  4465. * @author Stefan Zehnpfennig
  4466. * @param array $array result
  4467. * @return boolean
  4468. */
  4469. public function succeeded($array) {
  4470. if(isset($array['success'])) {
  4471. return $array['success'];
  4472. }else{
  4473. return false;
  4474. }
  4475. }
  4476.  
  4477.  
  4478.  
  4479. //*******************************************************************************************
  4480. //*********************************** Internal Functions ************************************
  4481. //*******************************************************************************************
  4482.  
  4483. /**
  4484. * __construct
  4485. *
  4486. * Note: When specifying a numerical IPv6 address (e.g. fe80::1), you must enclose the IP in square brackets—for example, [fe80::1]
  4487. *
  4488. * @author Stefan Zehnpfennig
  4489. * @param string $host ts3host
  4490. * @param integer $queryport ts3queryport
  4491. * @param integer $timeout socket timeout (default = 2) [optional]
  4492. * @return void
  4493. */
  4494. function __construct($host, $queryport, $timeout = 2) {
  4495. if($queryport >= 1 and $queryport <= 65536) {
  4496. if($timeout >= 1) {
  4497. $this->runtime['host'] = $host;
  4498. $this->runtime['queryport'] = $queryport;
  4499. $this->runtime['timeout'] = $timeout;
  4500. }else{
  4501. $this->addDebugLog('invalid timeout value');
  4502. }
  4503. }else{
  4504. $this->addDebugLog('invalid queryport');
  4505. }
  4506. }
  4507.  
  4508. /**
  4509. * __destruct
  4510. *
  4511. * @author Stefan Zehnpfennig
  4512. * @return void
  4513. */
  4514. function __destruct() {
  4515. $this->quit();
  4516. }
  4517.  
  4518. /**
  4519. * __call
  4520. *
  4521. * prevents your website from php errors if you want to execute a method which doesn't exists
  4522. *
  4523. * @author Stefan Zehnpfennig
  4524. * @param string $name method name
  4525. * @param array $args method arguments
  4526. * @return void
  4527. */
  4528. function __call($name, $args) {
  4529. $this->addDebugLog('Method '.$name.' doesn\'t exist', $name, 0);
  4530. return $this->generateOutput(false, array('Method '.$name.' doesn\'t exist'), false);
  4531. }
  4532.  
  4533. /**
  4534. * isConnected
  4535. *
  4536. * Checks if the connection is established
  4537. *
  4538. * @author Stefan Zehnpfennig
  4539. * @return boolean connected
  4540. */
  4541. public function isConnected() {
  4542. return !empty($this->runtime['socket']);
  4543. }
  4544.  
  4545. /**
  4546. * generateOutput
  4547. *
  4548. * Builds a method return as array
  4549. *
  4550. * @author Stefan Zehnpfennig
  4551. * @param boolean $success true/false
  4552. * @param array $errors all errors which occured while executing a method
  4553. * @param mixed $data parsed data from server
  4554. * @return array output
  4555. */
  4556. private function generateOutput($success, $errors, $data) {
  4557. return array('success' => $success, 'errors' => $errors, 'data' => $data);
  4558. }
  4559.  
  4560. /**
  4561. * unEscapeText
  4562. *
  4563. * Turns escaped chars to normals
  4564. *
  4565. * @author Stefan Zehnpfennig
  4566. * @param string $text text which should be escaped
  4567. * @return string text
  4568. */
  4569. private function unEscapeText($text) {
  4570. $escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/");
  4571. $unEscapedChars = array('', '', '', '', '', ' ', '|', '/');
  4572. $text = str_replace($escapedChars, $unEscapedChars, $text);
  4573. return $text;
  4574. }
  4575.  
  4576. /**
  4577. * escapeText
  4578. *
  4579. * Escapes chars that we can use it in the query
  4580. *
  4581. * @author Stefan Zehnpfennig
  4582. * @param string $text text which should be escaped
  4583. * @return string text
  4584. */
  4585. private function escapeText($text) {
  4586. $text = str_replace("\t", '\t', $text);
  4587. $text = str_replace("\v", '\v', $text);
  4588. $text = str_replace("\r", '\r', $text);
  4589. $text = str_replace("\n", '\n', $text);
  4590. $text = str_replace("\f", '\f', $text);
  4591. $text = str_replace(' ', '\s', $text);
  4592. $text = str_replace('|', '\p', $text);
  4593. $text = str_replace('/', '\/', $text);
  4594. return $text;
  4595. }
  4596.  
  4597. /**
  4598. * splitBanIds
  4599. *
  4600. * Splits banIds to array
  4601. *
  4602. * @author Stefan Zehnpfennig
  4603. * @param string $text plain text server response
  4604. * @return string text
  4605. */
  4606. private function splitBanIds($text) {
  4607. $data = array();
  4608. $text = str_replace(array("\n", "\r"), '', $text);
  4609. $ids = explode("banid=", $text);
  4610. unset($ids[0]);
  4611. return $ids;
  4612. }
  4613.  
  4614. //*******************************************************************************************
  4615. //************************************ Network Functions ************************************
  4616. //*******************************************************************************************
  4617.  
  4618. /**
  4619. * connect
  4620. *
  4621. * Connects to a ts3instance query port
  4622. *
  4623. * @author Stefan Zehnpfennig
  4624. * @return boolean success
  4625. */
  4626. function connect() {
  4627. if($this->isConnected()) {
  4628. $this->addDebugLog('Error: you are already connected!');
  4629. return $this->generateOutput(false, array('Error: the script is already connected!'), false);
  4630. }
  4631.  
  4632. $socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']);
  4633.  
  4634. if(!$socket)
  4635. {
  4636. $this->addDebugLog('Error: connection failed!');
  4637. return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);
  4638. }
  4639. else
  4640. {
  4641. if(strpos(fgets($socket), 'TS3') !== false)
  4642. {
  4643. $tmpVar = fgets($socket);
  4644. $this->runtime['socket'] = $socket;
  4645. return $this->generateOutput(true, array(), true);
  4646. }
  4647. else
  4648. {
  4649. $this->addDebugLog('host isn\'t a ts3 instance!');
  4650. return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);
  4651. }
  4652. }
  4653. }
  4654.  
  4655. /**
  4656. * getQueryClid
  4657. *
  4658. * Returns the server query client id
  4659. *
  4660. * @author toxiicdev (@toxiicdev.net)
  4661. * @return int value
  4662. */
  4663.  
  4664. public function getQueryClid()
  4665. {
  4666. return $this->runtime['bot_clid'];
  4667. }
  4668.  
  4669. /**
  4670. * executeCommand
  4671. *
  4672. * Executes a command and fetches the response
  4673. *
  4674. * @author Stefan Zehnpfennig
  4675. * @param string $command command which should be executed
  4676. * @param array $tracert array with information from first exec
  4677. * @return mixed data
  4678. */
  4679. private function executeCommand($command, $tracert = null) {
  4680. if(!$this->isConnected()) {
  4681. $this->addDebugLog('script isn\'t connected to server', $tracert[1]['function'], $tracert[0]['line']);
  4682. return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);
  4683. }
  4684.  
  4685. $data = '';
  4686.  
  4687. $splittedCommand = str_split($command, 1024);
  4688.  
  4689. $splittedCommand[(count($splittedCommand) - 1)] .= "\n";
  4690.  
  4691. foreach($splittedCommand as $commandPart)
  4692. {
  4693. if(!(@fputs($this->runtime['socket'], $commandPart)))
  4694. {
  4695. $this->runtime['socket'] = $this->runtime['bot_clid'] = '';
  4696. $this->addDebugLog('Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
  4697. return $this->generateOutput(false, array('Socket closed.'), false);
  4698. }
  4699. }
  4700. do {
  4701. $data .= @fgets($this->runtime['socket'], 4096);
  4702.  
  4703. if(empty($data))
  4704. {
  4705. $this->runtime['socket'] = $this->runtime['bot_clid'] = '';
  4706. $this->addDebugLog('Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
  4707. return $this->generateOutput(false, array('Socket closed.'), false);
  4708. }
  4709. else if(strpos($data, 'error id=3329 msg=connection') !== false) {
  4710. $this->runtime['socket'] = $this->runtime['bot_clid'] = '';
  4711. $this->addDebugLog('You got banned from server. Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
  4712. return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
  4713. }
  4714.  
  4715. } while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);
  4716.  
  4717. if(strpos($data, 'error id=0 msg=ok') === false) {
  4718. $splittedResponse = explode('error id=', $data);
  4719. $chooseEnd = count($splittedResponse) - 1;
  4720.  
  4721. $cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);
  4722.  
  4723. if($tracert != null)
  4724. $this->addDebugLog('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1]), $tracert[1]['function'], $tracert[0]['line']);
  4725.  
  4726. return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);
  4727. }else{
  4728. return $this->generateOutput(true, array(), $data);
  4729. }
  4730. }
  4731.  
  4732. /**
  4733. * readChatMessage
  4734. *
  4735. * Read chat message by its type (Result: http://bit.ly/2dtBXnT)
  4736. *
  4737. * IMPORTANT: Check always for message success, sometimes you can get an empty message
  4738. * and it will return empty data
  4739. *
  4740. * <b>Output:</b>
  4741. * <pre>
  4742. * Array
  4743. * {
  4744. * [invokerid] => 37
  4745. * [invokeruid] => /jl8QCHJWrHDKXgVtF+9FX7zg1E=
  4746. * [invokername] => toxiicdev.net
  4747. * [msg] => It's just a prank bro
  4748. * [targetmode] => 3
  4749. * }
  4750. * </pre>
  4751. * @author toxiicdev (@toxiicdev.net)
  4752. * @param string $type textserver|textchannel|textprivate
  4753. * @param boolean $keepalive default false
  4754. * @param int $cid channel id (required only for textchannel)
  4755. * @return array data
  4756. */
  4757. public function readChatMessage($type = 'textchannel', $keepalive = false, $cid = -1, $interval = 2)
  4758. {
  4759. $availTypes = array('textserver', 'textchannel', 'textprivate');
  4760. $rtnData = array('success' => 0, 'data' => array('invokerid' => '', 'invokeruid' => '', 'invokername' => '', 'msg' => '', 'targetmode' => ''));
  4761.  
  4762. if(!$this->isConnected()) {
  4763. die("Bot rozłączył się z serwerem");
  4764. $this->addDebugLog('script isn\'t connected to server');
  4765. return $rtnData;
  4766. }
  4767.  
  4768. if(!in_array($type, $availTypes)) {
  4769. $this->addDebugLog('Invalid passed read type');
  4770. return $rtnData;
  4771. }
  4772.  
  4773. if(!$this->runtime['selected']) { return $this->checkSelected(); }
  4774.  
  4775. if($type == 'textchannel')
  4776. {
  4777. $this->clientMove($this->getQueryClid(), $cid);
  4778. }
  4779.  
  4780. $this->executeCommand("servernotifyregister event=$type" . ($cid != -1 ? " id=$cid" : "") , null);
  4781. stream_set_timeout($this->runtime['socket'], $interval);
  4782. $data = fgets($this->runtime['socket'], 4096);
  4783.  
  4784. if(!empty($data))
  4785. {
  4786. $rtnData['success'] = 1;
  4787. $msgData = explode(" ", $data);
  4788. foreach($msgData as $param)
  4789. {
  4790. $paramData = explode("=", $param);
  4791. if(array_key_exists($paramData[0], $rtnData['data']))
  4792. {
  4793. $rtnData['data'][$paramData[0]] = $this->unescapeText(implode("=", array_slice($paramData, 1, count($paramData) -1)));
  4794. }
  4795. }
  4796. }
  4797. if(!$keepalive) $this->serverNotifyUnregister();
  4798.  
  4799. return $rtnData;
  4800. }
  4801. /**
  4802. * serverNotifyUnregister
  4803. *
  4804. * Unregisters server notify event
  4805. *
  4806. * @author toxiicdev (@toxiicdev.net)
  4807. */
  4808. public function serverNotifyUnregister()
  4809. {
  4810. $this->executeCommand("servernotifyunregister", null);
  4811. }
  4812. /**
  4813. * getData
  4814. *
  4815. * Parses data from query and returns an array
  4816. *
  4817. * @author Stefan Zehnpfennig
  4818. * @access private
  4819. * @param string $mode select return mode ('boolean', 'array', 'multi', 'plain')
  4820. * @param string $command command which should be executed
  4821. * @return mixed data
  4822. */
  4823. private function getData($mode, $command) {
  4824.  
  4825. $validModes = array('boolean', 'array', 'multi', 'plain');
  4826.  
  4827. if(!in_array($mode, $validModes)) {
  4828. $this->addDebugLog($mode.' is an invalid mode');
  4829. return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);
  4830. }
  4831.  
  4832. if(empty($command)) {
  4833. $this->addDebugLog('you have to enter a command');
  4834. return $this->generateOutput(false, array('Error: you have to enter a command'), false);
  4835. }
  4836.  
  4837. $fetchData = $this->executeCommand($command, debug_backtrace());
  4838.  
  4839.  
  4840. $fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);
  4841.  
  4842.  
  4843. if($fetchData['success']) {
  4844. if($mode == 'boolean') {
  4845. return $this->generateOutput(true, array(), true);
  4846. }
  4847.  
  4848. if($mode == 'array') {
  4849. if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
  4850. $datasets = explode(' ', $fetchData['data']);
  4851.  
  4852. $output = array();
  4853.  
  4854. foreach($datasets as $dataset) {
  4855. $dataset = explode('=', $dataset);
  4856.  
  4857. if(count($dataset) > 2) {
  4858. for($i = 2; $i < count($dataset); $i++) {
  4859. $dataset[1] .= '='.$dataset[$i];
  4860. }
  4861. $output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
  4862. }else{
  4863. if(count($dataset) == 1) {
  4864. $output[$this->unEscapeText($dataset[0])] = '';
  4865. }else{
  4866. $output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
  4867. }
  4868.  
  4869. }
  4870. }
  4871. return $this->generateOutput(true, array(), $output);
  4872. }
  4873. if($mode == 'multi') {
  4874. if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
  4875. $datasets = explode('|', $fetchData['data']);
  4876.  
  4877. $output = array();
  4878.  
  4879. foreach($datasets as $datablock) {
  4880. $datablock = explode(' ', $datablock);
  4881.  
  4882. $tmpArray = array();
  4883.  
  4884. foreach($datablock as $dataset) {
  4885. $dataset = explode('=', $dataset);
  4886. if(count($dataset) > 2) {
  4887. for($i = 2; $i < count($dataset); $i++) {
  4888. $dataset[1] .= '='.$dataset[$i];
  4889. }
  4890. $tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
  4891. }else{
  4892. if(count($dataset) == 1) {
  4893. $tmpArray[$this->unEscapeText($dataset[0])] = '';
  4894. }else{
  4895. $tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
  4896. }
  4897. }
  4898. }
  4899. $output[] = $tmpArray;
  4900. }
  4901. return $this->generateOutput(true, array(), $output);
  4902. }
  4903. if($mode == 'plain') {
  4904. return $fetchData;
  4905. }
  4906. }else{
  4907. return $this->generateOutput(false, $fetchData['errors'], false);
  4908. }
  4909. }
  4910.  
  4911. /**
  4912. * ftSendKey
  4913. *
  4914. * Sends down/upload-key to ftHost
  4915. *
  4916. * @author Stefan Zehnpfennig
  4917. * @param string $key
  4918. * @param string $additional
  4919. * @return none
  4920. */
  4921. private function ftSendKey($key, $additional = NULL) {
  4922. @fputs($this->runtime['fileSocket'], $key.$additional);
  4923. }
  4924.  
  4925. /**
  4926. * ftSendData
  4927. *
  4928. * Sends data to ftHost
  4929. *
  4930. * @author Stefan Zehnpfennig
  4931. * @param mixed $data
  4932. * @return none
  4933. */
  4934. private function ftSendData($data) {
  4935. $data = str_split($data, 4096);
  4936. foreach($data as $dat) {
  4937. @fputs($this->runtime['fileSocket'], $dat);
  4938. }
  4939. }
  4940.  
  4941. /**
  4942. * ftRead
  4943. *
  4944. * Reads data from ftHost
  4945. *
  4946. * @author Stefan Zehnpfennig
  4947. * @param int $size
  4948. * @return string data
  4949. */
  4950. private function ftRead($size) {
  4951. $data = '';
  4952. while(strlen($data) < $size) {
  4953. $data .= fgets($this->runtime['fileSocket'], 4096);
  4954. }
  4955. return $data;
  4956. }
  4957.  
  4958. //*******************************************************************************************
  4959. //************************************* Debug Functions *************************************
  4960. //*******************************************************************************************
  4961.  
  4962. /**
  4963. * getDebugLog
  4964. *
  4965. * Returns the debug log
  4966. *
  4967. * <b>Output:</b>
  4968. * <pre>
  4969. * Array
  4970. * {
  4971. * [0] => Error in login() on line 1908: ErrorID: 520 | Message: invalid loginname or password
  4972. * [1] => Error in selectServer() on line 2044: ErrorID: 1540 | Message: convert error
  4973. * }
  4974. * </pre>
  4975. *
  4976. * @author Stefan Zehnpfennig
  4977. * @return array debugLog
  4978. */
  4979. public function getDebugLog() {
  4980. return $this->runtime['debug'];
  4981. }
  4982.  
  4983. /**
  4984. * addDebugLog
  4985. *
  4986. * Adds an entry to debugLog
  4987. *
  4988. * @author Stefan Zehnpfennig
  4989. * @param string $text text which should added to debugLog
  4990. * @param string $methodName name of the executed method [optional]
  4991. * @param string $line line where error triggered [optional]
  4992. * @return array debugLog
  4993. */
  4994. private function addDebugLog($text, $methodName = '', $line = '') {
  4995. if(empty($methodName) and empty($line)) {
  4996. $backtrace = debug_backtrace();
  4997. $methodName = $backtrace[1]['function'];
  4998. $line = $backtrace[0]['line'];
  4999. }
  5000. $this->runtime['debug'][] = 'Error in '.$methodName.'() on line '.$line.': '.$text;
  5001. }
  5002. }
  5003.  
  5004. /** \mainpage ts3admin.class
  5005. *
  5006. * \section intro_sec Welcome
  5007. *
  5008. * The ts3admin.class is a powerful api for communication with Teamspeak 3 Servers from your website! Your creativity knows no bounds!
  5009. *
  5010. * <a href="http://ts3admin.info" />http://ts3admin.info</a>
  5011. */
  5012. ?>
Add Comment
Please, Sign In to add comment