ts3admin::serverGroupDelete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 2
eloc 3
nc 2
nop 2
1
<?PHP
2
/**
3
 *                         ts3admin.class.php
4
 *                         ------------------                    
5
 *   begin                : 18. December 2009
6
 *   copyright            : (C) 2009-2015 Par0noid Solutions
7
 *   email                : [email protected]
8
 *   version              : 0.8.0.0
9
 *   last modified        : 22. October 2015
10
 *
11
 *
12
 *  This file is a powerful library for querying TeamSpeak3 servers.
13
 *  
14
 *  This program is free software: you can redistribute it and/or modify
15
 *  it under the terms of the GNU General Public License as published by
16
 *  the Free Software Foundation, either version 3 of the License, or
17
 *  (at your option) any later version.
18
 *  
19
 *  This program is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *  
24
 *  You should have received a copy of the GNU General Public License
25
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 */
27
28
/** 
29
 * The ts3admin.class.php is a powerful library that offers functions to communicate with Teamspeak 3 Servers from your website!
30
 * 
31
 * You can do everything, your creativity knows no bounds!
32
 * That library is faster than all other librarys because its optimized to find the shortest way to your information.
33
 * No unneeded PHP 5 OOP Stuff, just the basics!
34
 * There are a lot of professional developers and some big companys using my library.
35
 * The best thing is that you can use it for free under the terms of the GNU General Public License v3.
36
 * Take a look on the project website where you can find code examples, a manual and some other stuff.
37
 * 
38
 * @author      Par0noid Solutions <[email protected]>
39
 * @version     0.8.0.0
40
 * @copyright   Copyright (c) 2009-2015, Stefan Z.
41
 * @package		ts3admin
42
 * @link        http://ts3admin.info
43
 */
44
class ts3admin {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
45
46
//*******************************************************************************************	
47
//****************************************** Vars *******************************************
48
//*******************************************************************************************
49
50
/**
51
  * runtime is an private handle and configuration storage
52
  *
53
  * @author     Par0noid Solutions
54
  */
55
	private $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '');
56
57
58
//*******************************************************************************************	
59
//************************************ Public Functions *************************************
60
//******************************************************************************************
61
62
/**
63
  * banAddByIp
64
  *
65
  * Adds a new ban rule on the selected virtual server.
66
  *
67
  *	<b>Output:</b>
68
  * <pre>
69
  * Array
70
  * {
71
  *  [banid] => 109
72
  * }
73
  * </pre>
74
  *
75
  * @author     Par0noid Solutions
76
  * @param		string	$ip			clientIp
77
  * @param		integer	$time		bantime in seconds (0=unlimited)
78
  * @param		string	$banreason	Banreason [optional]
79
  * @return     array banId
80
  */
81 View Code Duplication
	function banAddByIp($ip, $time, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
83
		
84
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
85
86
		return $this->getData('array', 'banadd ip='.$ip.' time='.$time.$msg);
87
	}
88
89
/**
90
  * banAddByUid
91
  *
92
  *	Adds a new ban rule on the selected virtual server.
93
  *
94
  * <b>Output:</b>
95
  * <pre>
96
  * Array
97
  * {
98
  *  [banid] => 110
99
  * }
100
  * </pre>
101
  *
102
  * @author     Par0noid Solutions
103
  * @param		string	$uid		clientUniqueId
104
  * @param		integer	$time		bantime in seconds (0=unlimited)
105
  * @param		string	$banreason	Banreason [optional]
106
  * @return     array banId
107
  */
108 View Code Duplication
	function banAddByUid($uid, $time, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
110
		
111
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
112
		
113
		return $this->getData('array', 'banadd uid='.$uid.' time='.$time.$msg);
114
	}
115
116
/**
117
  * banAddByName
118
  *
119
  *	Adds a new ban rule on the selected virtual server.
120
  *
121
  * <b>Output:</b>
122
  * <pre>
123
  * Array
124
  * {
125
  *  [banid] => 111
126
  * }
127
  * </pre>
128
  *
129
  * @author     Par0noid Solutions
130
  * @param		string	$name		clientName
131
  * @param		integer	$time		bantime in seconds (0=unlimited)
132
  * @param		string	$banreason	Banreason [optional]
133
  * @return     array banId
134
  */
135 View Code Duplication
	function banAddByName($name, $time, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
136
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
137
		
138
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = NULL; }
139
										
140
		return $this->getData('array', 'banadd name='.$this->escapeText($name).' time='.$time.$msg);
141
	}
142
143
/**
144
  * banClient
145
  * 
146
  * 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.
147
  *
148
  * <b>Output:</b>
149
  * <pre>
150
  * Array
151
  * {
152
  *  [1] => 129
153
  *  [2] => 130
154
  * }
155
  * </pre>
156
  *
157
  * @author     Par0noid Solutions
158
  * @param		integer $clid		clientId
159
  * @param		integer $time		bantime in seconds (0=unlimited)
160
  * @param		string	$banreason	Banreason [optional]
161
  * @return     array banIds
162
  */
163
	function banClient($clid, $time, $banreason = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
164
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
165
		
166
		if(!empty($banreason)) { $msg = ' banreason='.$this->escapeText($banreason); } else { $msg = ''; }
167
		
168
		$result = $this->getData('plain', 'banclient clid='.$clid.' time='.$time.$msg);
169
		
170
		if($result['success']) {
171
			return $this->generateOutput(true, $result['errors'], $this->splitBanIds($result['data']));
172
		}else{
173
			return $this->generateOutput(false, $result['errors'], false);
174
		}
175
	}
176
177
/**
178
  * banDelete
179
  * 
180
  * Deletes the ban rule with ID banid from the server.
181
  *
182
  * @author     Par0noid Solutions
183
  * @param		integer $banID	banID
184
  * @return     boolean success
185
  */
186
	function banDelete($banID) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
187
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
188
		return $this->getData('boolean', 'bandel banid='.$banID);
189
	}
190
191
/**
192
  * banDeleteAll
193
  * 
194
  * Deletes all active ban rules from the server.
195
  *
196
  * @author     Par0noid Solutions
197
  * @return     boolean success
198
  */
199
	function banDeleteAll() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
200
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
201
		return $this->getData('boolean', 'bandelall');
202
	}
203
204
/**
205
  * banList
206
  * 
207
  * Displays a list of active bans on the selected virtual server.
208
  * 
209
  * <b>Output:</b>
210
  * <pre>
211
  * Array
212
  * {
213
  *  [banid] => 131
214
  *  [ip] => 1.2.3.4
215
  *  [name] => eugen
216
  *  [uid] => IYAntAcZHgVC7s3n3DNWmuJB/aM=
217
  *  [created] => 1286660391
218
  *  [duration] => 0
219
  *  [invokername] => Par0noid
220
  *  [invokercldbid] => 2086
221
  *  [invokeruid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
222
  *  [reason] => insult
223
  *  [enforcements] => 0
224
  * }
225
  * </pre>
226
  *
227
  * @author     Par0noid Solutions
228
  * @return     array banlist
229
  */
230
	function banList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
231
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
232
		return $this->getData('multi', 'banlist');
233
	}
234
235
/**
236
  * bindingList
237
  * 
238
  * Displays a list of IP addresses used by the server instance on multi-homed machines.
239
  *
240
  * <b>Output:</b>
241
  * <pre>
242
  * Array
243
  * {
244
  *  [ip] => 0.0.0.0
245
  * }
246
  * </pre>
247
  *
248
  * @author     Par0noid Solutions
249
  * @return     array bindingList
250
  */
251
	function bindingList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
252
		return $this->getData('multi', 'bindinglist');
253
	}
254
255
/**
256
  * channelAddPerm
257
  * 
258
  * 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.
259
  * 
260
  * <b>Input-Array like this:</b>
261
  * <pre>
262
  * $permissions = array();
263
  * $permissions['permissionID'] = 'permissionValue';
264
  * //or you could use Permission Name
265
  * $permissions['permissionName'] = 'permissionValue';
266
  * </pre>
267
  *
268
  * @author     Par0noid Solutions
269
  * @param		integer	$cid			channelId
270
  * @param		array	$permissions	permissions
271
  * @return     boolean success
272
  */
273 View Code Duplication
	function channelAddPerm($cid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
275
		
276
		if(count($permissions) > 0) {
277
			//Permissions given
278
			
279
			//Errorcollector
280
			$errors = array();
281
			
282
			//Split Permissions to prevent query from overload
283
			$permissions = array_chunk($permissions, 50, true);
284
			
285
			//Action for each splitted part of permission
286
			foreach($permissions as $permission_part)
287
			{
288
				//Create command_string for each command that we could use implode later
289
				$command_string = array();
290
				
291
				foreach($permission_part as $key => $value)
292
				{
293
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
294
				}
295
				
296
				$result = $this->getData('boolean', 'channeladdperm cid='.$cid.' '.implode('|', $command_string));
297
				
298
				if(!$result['success'])
299
				{
300
					foreach($result['errors'] as $error)
301
					{
302
						$errors[] = $error;
303
					}
304
				}
305
			}
306
			
307
			if(count($errors) == 0)
308
			{
309
				return $this->generateOutput(true, array(), true);
310
			}else{
311
				return $this->generateOutput(false, $errors, false);
312
			}
313
			
314
		}else{
315
			// No permissions given
316
			$this->addDebugLog('no permissions given');
317
			return $this->generateOutput(false, array('Error: no permissions given'), false);
318
		}
319
	}
320
321
/**
322
  * channelClientAddPerm
323
  * 
324
  * 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.
325
  * 
326
  * <b>Input-Array like this:</b>
327
  * <pre>
328
  * $permissions = array();
329
  * $permissions['permissionID'] = 'permissionValue';
330
  * //or you could use Permission Name
331
  * $permissions['permissionName'] = 'permissionValue';
332
  * </pre>
333
  *
334
  * @author     Par0noid Solutions
335
  * @param		integer		$cid			channelID
336
  * @param		integer		$cldbid			clientDBID
337
  * @param		array		$permissions	permissions
338
  * @return     boolean success
339
  */
340 View Code Duplication
	function channelClientAddPerm($cid, $cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
341
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
342
		
343
		if(count($permissions) > 0) {
344
			//Permissions given
345
				
346
			//Errorcollector
347
			$errors = array();
348
				
349
			//Split Permissions to prevent query from overload
350
			$permissions = array_chunk($permissions, 50, true);
351
				
352
			//Action for each splitted part of permission
353
			foreach($permissions as $permission_part)
354
			{
355
				//Create command_string for each command that we could use implode later
356
				$command_string = array();
357
		
358
				foreach($permission_part as $key => $value)
359
				{
360
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
361
				}
362
		
363
				$result = $this->getData('boolean', 'channelclientaddperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $command_string));
364
		
365
				if(!$result['success'])
366
				{
367
					foreach($result['errors'] as $error)
368
					{
369
						$errors[] = $error;
370
					}
371
				}
372
			}
373
				
374
			if(count($errors) == 0)
375
			{
376
				return $this->generateOutput(true, array(), true);
377
			}else{
378
				return $this->generateOutput(false, $errors, false);
379
			}
380
				
381
		}else{
382
			// No permissions given
383
			$this->addDebugLog('no permissions given');
384
			return $this->generateOutput(false, array('Error: no permissions given'), false);
385
		}
386
	}
387
388
/**
389
  * channelClientDelPerm
390
  * 
391
  * 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.
392
  *
393
  * <b>Input-Array like this:</b>
394
  * <pre>
395
  * $permissions = array();
396
  * $permissions[] = 'permissionID';
397
  * $permissions[] = 'permissionName';
398
  * //or
399
  * $permissions = array('permissionID', 'permissionName', 'permissionID');
400
  * </pre>
401
  *
402
  * @author     Par0noid Solutions
403
  * @param		integer		$cid				channelID
404
  * @param		integer		$cldbid				clientDBID
405
  * @param		array		$permissions		permissions
406
  * @return     boolean success
407
  */
408
	function channelClientDelPerm($cid, $cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
409
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
410
		$permissionArray = array();
411
		
412
		if(count($permissions) > 0) {
413
			foreach($permissions AS $value) {
414
				$permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$value;
415
			}
416
			return $this->getData('boolean', 'channelclientdelperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $permissionArray));
417
		}else{
418
			$this->addDebugLog('no permissions given');
419
			return $this->generateOutput(false, array('Error: no permissions given'), false);
420
		}
421
	}
422
423
/**
424
  * channelClientPermList
425
  * 
426
  * Displays a list of permissions defined for a client in a specific channel.
427
  *
428
  * <b>Output:</b>
429
  * <pre>
430
  * Array
431
  * {
432
  *  [cid] => 250 (only in first result)
433
  *  [cldbid] => 2086 (only in first result)
434
  *  [permid] => 12876 (if permsid = false)
435
  *  [permsid] => b_client_info_view (if permsid = true)
436
  *  [permvalue] => 1
437
  *  [permnegated] => 0
438
  *  [permskip] => 0
439
  * }
440
  * </pre>
441
  *
442
  * @author     Par0noid Solutions
443
  * @param		integer		$cid		channelID
444
  * @param		integer		$cldbid		clientDBID
445
  * @param		boolean		$permsid	displays permissionName instead of permissionID
446
  * @return     array	channelclientpermlist
447
  */
448
	function channelClientPermList($cid, $cldbid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
449
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
450
		return $this->getData('multi', 'channelclientpermlist cid='.$cid.' cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
451
	}
452
453
/**
454
  * channelCreate
455
  * 
456
  * 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.
457
  * 
458
  * <b style="color:red">Hint:</b> don't forget to set channel_flag_semi_permanent = 1 or channel_flag_permanent = 1
459
  * 
460
  * <b style="color:red">Hint:</b> you'll get an error if you want to create a channel without channel_name
461
  * 
462
  * <b>Input-Array like this:</b>
463
  * <pre>
464
  * $data = array();
465
  * 
466
  * $data['setting'] = 'value';
467
  * $data['setting'] = 'value';
468
  * </pre>
469
  * 
470
  * <b>Output:</b>
471
  * <pre>
472
  * Array
473
  * {
474
  *  [cid] => 257
475
  * }
476
  * </pre>
477
  *
478
  * @author     Par0noid Solutions
479
  * @param		array $data properties
480
  * @return     array channelInfo
481
  */
482 View Code Duplication
	function channelCreate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
483
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
484
		
485
		$propertiesString = '';
486
		
487
		foreach($data as $key => $value) {
488
			$propertiesString .= ' '.$key.'='.$this->escapeText($value);
489
		}
490
		
491
		return $this->getData('array', 'channelcreate '.$propertiesString);
492
	}
493
494
/**
495
  * channelDelete
496
  * 
497
  * 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.
498
  *
499
  * @author     Par0noid Solutions
500
  * @param		integer $cid channelID
501
  * @param		integer $force {1|0} (default: 1)
502
  * @return     boolean success
503
  */
504
	function channelDelete($cid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
505
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
506
		return $this->getData('boolean', 'channeldelete cid='.$cid.' force='.$force);
507
	}
508
509
/**
510
  * channelDelPerm
511
  * 
512
  * 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.
513
  *
514
  * <b>Input-Array like this:</b>
515
  * <pre>
516
  * $permissions = array();
517
  * $permissions[] = 'permissionID';
518
  * //or you could use
519
  * $permissions[] = 'permissionName';
520
  * </pre>
521
  *
522
  * @author     Par0noid Solutions
523
  * @param		integer		$cid				channelID
524
  * @param		array		$permissions		permissions
525
  * @return     boolean	success
526
  */
527
	function channelDelPerm($cid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
528
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
529
		$permissionArray = array();
530
		
531
		if(count($permissions) > 0) {
532
			foreach($permissions AS $value) {
533
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
534
			}
535
			return $this->getData('boolean', 'channeldelperm cid='.$cid.' '.implode('|', $permissionArray));
536
		}else{
537
			$this->addDebugLog('no permissions given');
538
			return $this->generateOutput(false, array('Error: no permissions given'), false);
539
		}
540
	}
541
542
/**
543
  * channelEdit
544
  * 
545
  * 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.
546
  *
547
  * <b>Input-Array like this:</b>
548
	<pre>
549
	$data = array();
550
		
551
	$data['setting'] = 'value';
552
	$data['setting'] = 'value';
553
	</pre>
554
  *
555
  * @author     Par0noid Solutions
556
  * @param		integer	$cid	$channelID
557
  * @param		array	$data	edited settings
558
  * @return     boolean success
559
  */
560 View Code Duplication
	function channelEdit($cid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
561
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
562
		
563
		$settingsString = '';
564
		
565
		foreach($data as $key => $value) {
566
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
567
		}
568
569
		return $this->getData('boolean', 'channeledit cid='.$cid.$settingsString);
570
	}
571
572
/**
573
  * channelFind
574
  * 
575
  * displays a list of channels matching a given name pattern.
576
  *
577
  * <b>Output:</b>
578
  * <pre>
579
  * Array
580
  * {
581
  *  [cid] => 2
582
  *  [channel_name] => Lobby
583
  * }
584
  * </pre>
585
  *
586
  * @author     Par0noid Solutions
587
  * @param		string	$pattern	channelName
588
  * @return     array channelList 
589
  */
590
	function channelFind($pattern) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
591
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
592
		return $this->getData('multi', 'channelfind pattern='.$this->escapeText($pattern));
593
	}
594
595
/**
596
  * channelGroupAdd
597
  * 
598
  * 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.
599
  *
600
  * <b>groupDbTypes:</b>
601
  *	<ol start="0">
602
  *		<li>template group (used for new virtual servers)</li>
603
  *		<li>regular group (used for regular clients)</li>
604
  *		<li>global query group (used for ServerQuery clients)</li>
605
  *	</ol>
606
  *
607
  * <b>Output:</b>
608
  * <pre>
609
  * Array
610
  * {
611
  *  [cgid] => 86
612
  * }
613
  * </pre>
614
  *
615
  * @author     Par0noid Solutions
616
  * @param		integer	$name	groupName
617
  * @param		integer	$type   groupDbType [optional] (default: 1)
618
  * @return     boolean success
619
  */
620
	function channelGroupAdd($name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
621
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
622
		return $this->getData('array', 'channelgroupadd name='.$this->escapeText($name).' type='.$type);
623
	}
624
625
/**
626
  * channelGroupAddPerm
627
  * 
628
  * 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.
629
  *
630
  * <b>Input-Array like this:</b>
631
  * <pre>
632
  * $permissions = array();
633
  * $permissions['permissionID'] = 'permissionValue';
634
  * //or you could use:
635
  * $permissions['permissionName'] = 'permissionValue';
636
  * </pre>
637
  *
638
  * @author     Par0noid Solutions
639
  * @param		integer		$cgid			channelGroupID
640
  * @param		array		$permissions	permissions
641
  * @return     boolean success
642
  */
643 View Code Duplication
	function channelGroupAddPerm($cgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
644
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
645
		
646
		if(count($permissions) > 0) {
647
			//Permissions given
648
		
649
			//Errorcollector
650
			$errors = array();
651
		
652
			//Split Permissions to prevent query from overload
653
			$permissions = array_chunk($permissions, 50, true);
654
		
655
			//Action for each splitted part of permission
656
			foreach($permissions as $permission_part)
657
			{
658
				//Create command_string for each command that we could use implode later
659
				$command_string = array();
660
		
661
				foreach($permission_part as $key => $value)
662
				{
663
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
664
				}
665
		
666
				$result = $this->getData('boolean', 'channelgroupaddperm cgid='.$cgid.' '.implode('|', $command_string));
667
		
668
				if(!$result['success'])
669
				{
670
					foreach($result['errors'] as $error)
671
					{
672
						$errors[] = $error;
673
					}
674
				}
675
			}
676
		
677
			if(count($errors) == 0) {
678
				return $this->generateOutput(true, array(), true);
679
			}else{
680
				return $this->generateOutput(false, $errors, false);
681
			}
682
		
683
		}else{
684
			// No permissions given
685
			$this->addDebugLog('no permissions given');
686
			return $this->generateOutput(false, array('Error: no permissions given'), false);
687
		}
688
	}
689
690
/**
691
  * channelGroupClientList
692
  * 
693
  * 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
694
  *
695
  * <b>Output:</b>
696
  * <pre>
697
  * Array
698
  * {
699
  *  [cid] => 2
700
  *  [cldbid] => 9
701
  *  [cgid] => 9
702
  * }
703
  * </pre>
704
  *
705
  * @author     Par0noid Solutions
706
  * @param		integer $cid		channelID [optional]
707
  * @param		integer $cldbid		clientDBID [optional]
708
  * @param		integer $cgid		channelGroupID [optional]
709
  * @return     array channelGroupClientList
710
  */
711
	function channelGroupClientList($cid = NULL, $cldbid = NULL, $cgid = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
712
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
713
		
714
		return $this->getData('multi', 'channelgroupclientlist'.(!empty($cid) ? ' cid='.$cid : '').(!empty($cldbid) ? ' cldbid='.$cldbid : '').(!empty($cgid) ? ' cgid='.$cgid : ''));
715
	}
716
717
/**
718
  * channelGroupCopy
719
  * 
720
  * 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.
721
  *
722
  * <b>groupDbTypes:</b>
723
  *	<ol start="0">
724
  *		<li>template group (used for new virtual servers)</li>
725
  *		<li>regular group (used for regular clients)</li>
726
  *		<li>global query group (used for ServerQuery clients)</li>
727
  *	</ol>
728
  *
729
  * <b>Output:</b>
730
  * <pre>
731
  * Array
732
  * {
733
  *  [cgid] => 86
734
  * }
735
  * </pre>
736
  *
737
  * @author     Par0noid Solutions
738
  * @param		integer	$scgid	sourceChannelGroupID
739
  * @param		integer	$tcgid	targetChannelGroupID 
740
  * @param		integer $name	groupName
741
  * @param		integer	$type	groupDbType
742
  * @return     array groupId
743
  */
744
	function channelGroupCopy($scgid, $tcgid, $name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
745
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
746
		return $this->getData('array', 'channelgroupcopy scgid='.$scgid.' tcgid='.$tcgid.' name='.$this->escapeText($name).' type='.$type);
747
	}
748
749
/**
750
  * channelGroupDelete
751
  * 
752
  * Deletes a channel group by ID. If force is set to 1, the channel group will be deleted even if there are clients within.
753
  *
754
  * @author     Par0noid Solutions
755
  * @param		integer $cgid	channelGroupID
756
  * @param		integer $force	forces deleting channelGroup (default: 1)
757
  * @return     boolean success
758
  */
759
	function channelGroupDelete($cgid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
760
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
761
		return $this->getData('boolean', 'channelgroupdel cgid='.$cgid.' force='.$force);
762
	}
763
764
/**
765
  * channelGroupDelPerm
766
  * 
767
  * 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.
768
  *
769
  * <b>Input-Array like this:</b>
770
  * <pre>
771
  * $permissions = array();
772
  * $permissions[] = 'permissionID';
773
  * $permissions[] = 'permissionName';
774
  * </pre>
775
  *
776
  * @author     Par0noid Solutions
777
  * @param		integer		$cgid				channelGroupID
778
  * @param		array		$permissions		permissions
779
  * @return     boolean success
780
  */
781
	function channelGroupDelPerm($cgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
782
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
783
		$permissionArray = array();
784
		
785
		if(count($permissions) > 0) {
786
			foreach($permissions AS $value) {
787
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
788
			}
789
			return $this->getData('boolean', 'channelgroupdelperm cgid='.$cgid.' '.implode('|', $permissionArray));
790
		}else{
791
			$this->addDebugLog('no permissions given');
792
			return $this->generateOutput(false, array('Error: no permissions given'), false);
793
		}
794
	}
795
796
/**
797
  * channelGroupList
798
  * 
799
  * Displays a list of channel groups available on the selected virtual server.
800
  * 
801
  * <b>Output:</b>
802
  * <pre>
803
  * Array
804
  * {
805
  *  [cgid] => 3
806
  *  [name] => Testname
807
  *  [type] => 0
808
  *  [iconid] => 100
809
  *  [savedb] => 1
810
  *  [sortid] => 0
811
  *  [namemode] => 0
812
  *  [n_modifyp] => 75
813
  *  [n_member_addp] => 50
814
  *  [n_member_removep] => 50
815
  * }
816
  * </pre>
817
  *
818
  * @author     Par0noid Solutions
819
  * @return     array channelGroupList
820
  */
821
	function channelGroupList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
822
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
823
		
824
		return $this->getData('multi', 'channelgrouplist');
825
	}
826
827
/**
828
  * channelGroupPermList
829
  * 
830
  * Displays a list of permissions assigned to the channel group specified with cgid.
831
  * If the permsid option is specified, the output will contain the permission names instead of the internal IDs.
832
  * 
833
  * <b>Output:</b>
834
  * <pre>
835
  * Array
836
  * {
837
  *  [permid] => 8471 (displayed if permsid is false)
838
  *  [permsid] => i_channel_create_modify_with_codec_latency_factor_min (displayed if permsid is true)
839
  *  [permvalue] => 1
840
  *  [permnegated] => 0
841
  *  [permskip] => 0
842
  * }
843
  * </pre>
844
  *
845
  * @author     Par0noid Solutions
846
  * @param		integer		$cgid		channelGroupID
847
  * @param		boolean		$permsid	permsid
848
  * @return		array	channelGroupPermlist
849
  */
850
  	function channelGroupPermList($cgid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
851
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
852
		return $this->getData('multi', 'channelgrouppermlist cgid='.$cgid.($permsid ? ' -permsid' : ''));
853
	}
854
855
/**
856
  * channelGroupRename
857
  * 
858
  * Changes the name of a specified channel group.
859
  *
860
  * @author     Par0noid Solutions
861
  * @param		integer $cgid groupID
862
  * @param		integer $name groupName
863
  * @return     boolean success
864
  */
865
	function channelGroupRename($cgid, $name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
866
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
867
		return $this->getData('boolean', 'channelgrouprename cgid='.$cgid.' name='.$this->escapeText($name));
868
	}
869
870
/**
871
  * channelInfo
872
  *
873
  *	Displays detailed configuration information about a channel including ID, topic, description, etc.
874
875
  * <b>Output:</b>
876
  * <pre>
877
  * Array
878
  * {
879
  *  [pid] => 0
880
  *  [channel_name] => Test
881
  *  [channel_topic] => 
882
  *  [channel_description] => 
883
  *  [channel_password] => cc97Pm4oOYq0J9fXDAgiWv/qScQ=
884
  *  [channel_codec] => 2
885
  *  [channel_codec_quality] => 7
886
  *  [channel_maxclients] => -1
887
  *  [channel_maxfamilyclients] => -1
888
  *  [channel_order] => 1
889
  *  [channel_flag_permanent] => 1
890
  *  [channel_flag_semi_permanent] => 0
891
  *  [channel_flag_default] => 0
892
  *  [channel_flag_password] => 0
893
  *  [channel_codec_latency_factor] => 1
894
  *  [channel_codec_is_unencrypted] => 1
895
  *  [channel_flag_maxclients_unlimited] => 1
896
  *  [channel_flag_maxfamilyclients_unlimited] => 0
897
  *  [channel_flag_maxfamilyclients_inherited] => 1
898
  *  [channel_filepath] => files\\virtualserver_1\\channel_2
899
  *  [channel_needed_talk_power] => 0
900
  *  [channel_forced_silence] => 0
901
  *  [channel_name_phonetic] => 
902
  *  [channel_icon_id] => 0
903
  *  [seconds_empty] => 61 (If it's a temporary channel with a channel delete delay)
904
  * }
905
  * </pre>
906
  *
907
  * @author     Par0noid Solutions
908
  * @param		integer $cid channelID
909
  * @return     array channelInfo
910
  */
911
	function channelInfo($cid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
912
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
913
		return $this->getData('array', 'channelinfo cid='.$cid);
914
	}
915
916
/**
917
  * channelList
918
  * 
919
  * 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.
920
  *
921
  * <b>Possible parameters:</b> [-topic] [-flags] [-voice] [-limits] [-icon]
922
  *
923
  * <b>Output: (without parameters)</b>
924
  * <pre>
925
  * Array
926
  * {
927
  *  [cid] => 2
928
  *  [pid] => 0
929
  *  [channel_order] => 1
930
  *  [channel_name] => Test
931
  *  [total_clients] => 0
932
  *  [channel_needed_subscribe_power] => 0
933
  * }
934
  * </pre>
935
  * <b>Output: (from parameters)</b>
936
  * <pre>
937
  * Array
938
  * {
939
  *  [-topic] => [channel_topic] => Default Channel has no topic
940
  *  [-flags] => [channel_flag_default] => 1
941
  *  [-flags] => [channel_flag_password] => 0
942
  *  [-flags] => [channel_flag_permanent] => 1
943
  *  [-flags] => [channel_flag_semi_permanent] => 0
944
  *  [-voice] => [channel_codec] => 2
945
  *  [-voice] => [channel_codec_quality] => 7
946
  *  [-voice] => [channel_needed_talk_power] => 0
947
  *  [-limits] => [total_clients_family] => 1
948
  *  [-limits] => [channel_maxclients] => -1
949
  *  [-limits] => [channel_maxfamilyclients] => -1
950
  *  [-icon] => [channel_icon_id] => 0
951
  * }
952
  * </pre>
953
  * <b>Usage:</b>
954
  * <pre>
955
  * $ts3->channelList(); //No parameters
956
  * $ts3->channelList("-flags"); //Single parameter
957
  * $ts3->channelList("-topic -flags -voice -limits -icon"); //Multiple parameters / all
958
  * </pre>
959
  *
960
  * @author     Par0noid Solutions
961
  * @param		string		$params		additional parameters [optional]
962
  * @return		array	channelList
963
  */
964
	function channelList($params = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
965
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
966
		if(!empty($params)) { $params = ' '.$params; }
967
		
968
		return $this->getData('multi', 'channellist'.$params);
969
	}
970
971
/**
972
  * channelMove
973
  * 
974
  * 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.
975
  *
976
  * @author     Par0noid Solutions
977
  * @param		integer $cid	channelID
978
  * @param		integer $cpid	channelParentID
979
  * @param		integer $order	channelSortOrder
980
  * @return     boolean success
981
  */
982
	function channelMove($cid, $cpid, $order = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
983
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
984
		return $this->getData('boolean', 'channelmove cid='.$cid.' cpid='.$cpid.($order != null ? ' order='.$order : ''));
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $order of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
985
	}
986
987
/**
988
  * channelPermList
989
  * 
990
  * Displays a list of permissions defined for a channel.
991
  *
992
  * <b>Output:</b>
993
  * <pre>
994
  * Array
995
  * {
996
  *  [cid] => 2 (only in first result)
997
  *  [permid] => 8471 (if permsid = false)
998
  *  [permsid] => i_channel_needed_delete_power (if permsid = true)
999
  *  [permvalue] => 1
1000
  *  [permnegated] => 0
1001
  *  [permskip] => 0
1002
  * }
1003
  * </pre>
1004
  *
1005
  * @author     Par0noid Solutions
1006
  * @param		integer		$cid		channelID
1007
  * @param		boolean		$permsid	displays permissionName instead of permissionID [optional]
1008
  * @return     array channelpermlist
1009
  */
1010
	function channelPermList($cid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1011
		if(!$this->runtime['selected']) { return $this->checkSelected(); }	
1012
		return $this->getData('multi', 'channelpermlist cid='.$cid.($permsid ? ' -permsid' : ''));
1013
	}
1014
1015
/**
1016
  * clientAddPerm
1017
  * 
1018
  * 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.
1019
  *
1020
  * <b>Input-Array like this:</b>
1021
  * <pre>
1022
  * $permissions = array();
1023
  * $permissions['permissionID'] = array('permissionValue', 'permskip');
1024
  * //or you could use Permission Name
1025
  * $permissions['permissionName'] = array('permissionValue', 'permskip');
1026
  * </pre>
1027
  *
1028
  * @author     Par0noid Solutions
1029
  * @param		integer	$cldbid			clientDBID
1030
  * @param		array	$permissions	permissions
1031
  * @return     boolean success
1032
  */
1033
	function clientAddPerm($cldbid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1034
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1035
		
1036
		if(count($permissions) > 0) {
1037
			//Permissions given
1038
				
1039
			//Errorcollector
1040
			$errors = array();
1041
				
1042
			//Split Permissions to prevent query from overload
1043
			$permissions = array_chunk($permissions, 50, true);
1044
				
1045
			//Action for each splitted part of permission
1046
			foreach($permissions as $permission_part)
1047
			{
1048
				//Create command_string for each command that we could use implode later
1049
				$command_string = array();
1050
		
1051
				foreach($permission_part as $key => $value)
1052
				{
1053
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$this->escapeText($value[0]).' permskip='.$this->escapeText($value[1]);
1054
				}
1055
		
1056
				$result = $this->getData('boolean', 'clientaddperm cldbid='.$cldbid.' '.implode('|', $command_string));
1057
		
1058
				if(!$result['success'])
1059
				{
1060
					foreach($result['errors'] as $error)
1061
					{
1062
						$errors[] = $error;
1063
					}
1064
				}
1065
			}
1066
				
1067
			if(count($errors) == 0)
1068
			{
1069
				return $this->generateOutput(true, array(), true);
1070
			}else{
1071
				return $this->generateOutput(false, $errors, false);
1072
			}
1073
		}else{
1074
			// No permissions given
1075
			$this->addDebugLog('no permissions given');
1076
			return $this->generateOutput(false, array('Error: no permissions given'), false);
1077
		}
1078
	}
1079
1080
/**
1081
 * clientAvatar
1082
 *
1083
 * Will return the base64 encoded binary of the clients avatar
1084
 * 
1085
 * <pre>
1086
 * $result = $tsAdmin->clientAvatar($uid);
1087
 * You can display it like: echo '<img src="data:image/png;base64,'.$result["data"].'" />';
1088
 * </pre>
1089
 *
1090
 * @author  Par0noid Solutions
1091
 * @param  string  $uid  clientUID
1092
 * @return array  base64 image
1093
 */
1094
	function clientAvatar($uid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1095
	  if(!$this->runtime['selected']) { return $this->checkSelected(); }
1096
1097
	  if(empty($uid))
1098
	  {
1099
		return $this->generateOutput(false, array('Error: empty uid'), false);
1100
	  }
1101
1102
	  $newChars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
1103
	  $auid = '';
1104
1105
	  for ($i = 0; $i <= 19; $i++) {
1106
			  $char = ord(substr(base64_decode($uid), $i, 1));
1107
			  $auid .= $newChars[($char & 0xF0) >> 4];
1108
			  $auid .= $newChars[$char & 0x0F];
1109
	  }
1110
1111
	  $init = $this->ftInitDownload('/avatar_'.$auid, 0, '');
1112
1113
	  if(!$init["success"])
1114
	  {
1115
		return $this->generateOutput(false, array('Error: init failed'), false);
1116
	  }
1117
	  
1118
	  $download = $this->ftDownloadFile($init);
1119
1120
	  if(is_array($download))
1121
	  {
1122
		return $download;
1123
	  }else{
1124
		return $this->generateOutput(true, false, base64_encode($download));
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1125
	  }
1126
1127
	}
1128
	
1129
/**
1130
  * clientDbDelete
1131
  * 
1132
  * Deletes a clients properties from the database.
1133
  *
1134
  * @author     Par0noid Solutions
1135
  * @param		integer $cldbid	clientDBID
1136
  * @return     boolean success
1137
  */
1138
	function clientDbDelete($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1139
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1140
		return $this->getData('boolean', 'clientdbdelete cldbid='.$cldbid);
1141
	}
1142
1143
/**
1144
  * clientDbEdit
1145
  * 
1146
  * Changes a clients settings using given properties.
1147
  *
1148
  * <b>Input-Array like this:</b>
1149
  * <pre>
1150
  * $data = array();
1151
  * 
1152
  * $data['property'] = 'value';
1153
  * $data['property'] = 'value';
1154
  * </pre>
1155
  *
1156
  * @author     Par0noid Solutions
1157
  * @param		integer		$cldbid		clientDBID
1158
  * @param		array		$data	 	clientProperties
1159
  * @return     boolean success
1160
  */
1161 View Code Duplication
	function clientDbEdit($cldbid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1162
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1163
		
1164
		$settingsString = '';
1165
		
1166
		foreach($data as $key => $value) {
1167
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1168
		}
1169
		
1170
		return $this->getData('boolean', 'clientdbedit cldbid='.$cldbid.$settingsString);
1171
	}
1172
1173
/**
1174
  * clientDbFind
1175
  * 
1176
  * 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.
1177
  *
1178
  * <b>Output:</b>
1179
  * <pre>
1180
  * Array
1181
  * {
1182
  *  [cldbid] => 2
1183
  * }
1184
  *	</pre>
1185
  *
1186
  * @author     Par0noid Solutions
1187
  * @param		string	$pattern	clientName
1188
  * @param		boolean	$uid		set true to add -uid param [optional]
1189
  * @return     array clientList 
1190
  */
1191
	function clientDbFind($pattern, $uid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1192
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1193
		return $this->getData('multi', 'clientdbfind pattern='.$this->escapeText($pattern).($uid ? ' -uid' : ''));
1194
	}
1195
1196
/**
1197
  * clientDbInfo
1198
  *
1199
  * Displays detailed database information about a client including unique ID, creation date, etc.
1200
  *
1201
  * <b>Output:</b>
1202
  * <pre>
1203
  * Array
1204
  * {
1205
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1206
  *  [client_nickname] => par0noid
1207
  *  [client_database_id] => 2
1208
  *  [client_created] => 1361027850
1209
  *  [client_lastconnected] => 1361027850
1210
  *  [client_totalconnections] => 1
1211
  *  [client_flag_avatar] => 
1212
  *  [client_description] => 
1213
  *  [client_month_bytes_uploaded] => 0
1214
  *  [client_month_bytes_downloaded] => 0
1215
  *  [client_total_bytes_uploaded] => 0
1216
  *  [client_total_bytes_downloaded] => 0
1217
  *  [client_icon_id] => 0
1218
  *  [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
1219
  *  [client_lastip] => 127.0.0.1
1220
  * }
1221
  * </pre>
1222
  *
1223
  * @author     Par0noid Solutions
1224
  * @param		integer		$cldbid		clientDBID
1225
  * @return     array	clientDbInfo
1226
  */
1227
	function clientDbInfo($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1228
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1229
		return $this->getData('array', 'clientdbinfo cldbid='.$cldbid);
1230
	}
1231
1232
/**
1233
  * clientDbList
1234
  * 
1235
  * Displays a list of client identities known by the server including their database ID, last nickname, etc.
1236
  *
1237
  * <b>Possible params:</b> [start={offset}] [duration={limit}] [-count]
1238
  *
1239
  * <b>Output:</b>
1240
  * <pre>
1241
  * Array
1242
  * {
1243
  *  [count] => 1 (if count parameter is set)
1244
  *  [cldbid] => 2
1245
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1246
  *  [client_nickname] => par0noid
1247
  *  [client_created] => 1361027850
1248
  *  [client_lastconnected] => 1361027850
1249
  *  [client_totalconnections] => 1
1250
  *  [client_description] => 
1251
  *  [client_lastip] => 127.0.0.1
1252
  * }
1253
  * </pre>
1254
  *
1255
  * @author     Par0noid Solutions
1256
  * @param		integer	$start		offset [optional] (Default: 0)
1257
  * @param		integer	$duration	limit [optional] (Default: -1)
1258
  * @param		boolean	$count		set true to add -count param [optional]
1259
  * @return     array clientdblist
1260
  */
1261
	function clientDbList($start = 0, $duration = -1, $count = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1262
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1263
		return $this->getData('multi', 'clientdblist start='.$start.' duration='.$duration.($count ? ' -count' : ''));
1264
	}
1265
1266
/**
1267
  * clientDelPerm
1268
  * 
1269
  * 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.
1270
  *
1271
  * <b>Input-Array like this:</b>
1272
  * <pre>
1273
  * $permissions = array();
1274
  * $permissions['permissionID'] = 'permissionValue';
1275
  * //or you could use Permission Name
1276
  * $permissions['permissionName'] = 'permissionValue';
1277
  * </pre>
1278
  *
1279
  * @author     Par0noid Solutions
1280
  * @param		integer		$cldbid				clientDBID
1281
  * @param		array		$permissionIds		permissionIDs
1282
  * @return     boolean success
1283
  */
1284
	function clientDelPerm($cldbid, $permissionIds) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1285
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1286
		
1287
		$permissionArray = array();
1288
		
1289
		if(count($permissionIds) > 0) {
1290
			foreach($permissionIds AS $value) {
1291
				$permissionArray[] = (is_numeric($value) ? 'permid=' : 'permsid=').$value;
1292
			}
1293
			return $this->getData('boolean', 'clientdelperm cldbid='.$cldbid.' '.implode('|', $permissionArray));
1294
		}else{
1295
			$this->addDebugLog('no permissions given');
1296
			return $this->generateOutput(false, array('Error: no permissions given'), false);
1297
		}
1298
	}
1299
1300
/**
1301
  * clientEdit
1302
  * 
1303
  * Changes a clients settings using given properties.
1304
  *
1305
  * <b>Input-Array like this:</b>
1306
  * <pre>
1307
  * $data = array();
1308
  *	
1309
  * $data['property'] = 'value';
1310
  * $data['property'] = 'value';
1311
  * </pre>
1312
  *
1313
  * @author     Par0noid Solutions
1314
  * @param		integer	$clid 			clientID
1315
  * @param		array	$data			clientProperties
1316
  * @return     boolean success
1317
  */
1318 View Code Duplication
	function clientEdit($clid, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1319
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1320
		
1321
		$settingsString = '';
1322
		
1323
		foreach($data as $key => $value) {
1324
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1325
		}
1326
		
1327
		return $this->getData('boolean', 'clientedit clid='.$clid.$settingsString);
1328
	}
1329
1330
/**
1331
  * clientFind
1332
  * 
1333
  * Displays a list of clients matching a given name pattern.
1334
  *
1335
  * <b>Output:</b>
1336
  * <pre>
1337
  * Array
1338
  * {
1339
  *  [clid] => 18
1340
  *  [client_nickname] => par0noid
1341
  * }
1342
  * </pre>
1343
  *
1344
  * @author     Par0noid Solutions
1345
  * @param		string	$pattern	clientName
1346
  * @return     array clienList
1347
  */
1348
	function clientFind($pattern) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1349
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1350
		return $this->getData('multi', 'clientfind pattern='.$this->escapeText($pattern));
1351
	}
1352
1353
/**
1354
  * clientGetDbIdFromUid
1355
  * 
1356
  * Displays the database ID matching the unique identifier specified by cluid.
1357
  *
1358
  *	<b>Output:</b>
1359
  * <pre>
1360
  * Array
1361
  * {
1362
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1363
  *  [cldbid] => 2
1364
  * }
1365
  * </pre>
1366
  *
1367
  * @author     Par0noid Solutions
1368
  * @param		string	$cluid	clientUID
1369
  * @return     array clientInfo
1370
  */
1371
	function clientGetDbIdFromUid($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1372
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1373
		return $this->getData('array', 'clientgetdbidfromuid cluid='.$cluid);
1374
	}
1375
1376
/**
1377
  * clientGetIds
1378
  * 
1379
  * Displays all client IDs matching the unique identifier specified by cluid.
1380
  *
1381
  * <b>Output:</b>
1382
  * <pre>
1383
  * Array
1384
  * {
1385
  *  [cluid] => nUixbdf/XakrrmsdffO30R/D8Gc=
1386
  *  [clid] => 7
1387
  *  [name] => Par0noid
1388
  * }
1389
  * </pre>
1390
  *
1391
  * @author     Par0noid Solutions
1392
  * @param		string	$cluid	clientUID
1393
  * @return     array clientList 
1394
  */
1395
	function clientGetIds($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1396
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1397
		return $this->getData('multi', 'clientgetids cluid='.$cluid);
1398
	}
1399
1400
/**
1401
  * clientGetNameFromDbid
1402
  * 
1403
  * Displays the unique identifier and nickname matching the database ID specified by cldbid.
1404
  *
1405
  *	<b>Output:</b>
1406
  * <pre>
1407
  * Array
1408
  * {
1409
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1410
  *  [cldbid] => 2
1411
  *  [name] => Par0noid
1412
  * }
1413
  * </pre>
1414
  *
1415
  * @author     Par0noid Solutions
1416
  * @param		integer	$cldbid	clientDBID
1417
  * @return     array clientInfo
1418
  */
1419
	function clientGetNameFromDbid($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1420
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1421
		return $this->getData('array', 'clientgetnamefromdbid cldbid='.$cldbid);
1422
	}
1423
	
1424
/**
1425
  * clientGetNameFromUid
1426
  * 
1427
  * Displays the database ID and nickname matching the unique identifier specified by cluid.
1428
  *
1429
  *	<b>Output:</b>
1430
  * <pre>
1431
  * Array
1432
  * {
1433
  *  [cluid] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1434
  *  [cldbid] => 2
1435
  *  [name] => Par0noid
1436
  * }
1437
  * </pre>
1438
  *
1439
  * @author     Par0noid Solutions
1440
  * @param		string	$cluid	clientUID
1441
  * @return     array clientInfo
1442
  */
1443
	function clientGetNameFromUid($cluid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1444
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1445
		return $this->getData('array', 'clientgetnamefromuid cluid='.$cluid);
1446
	}
1447
1448
/**
1449
  * clientInfo
1450
  * 
1451
  * Displays detailed configuration information about a client including unique ID, nickname, client version, etc.
1452
  *
1453
  * <b>Output:</b>
1454
  * <pre>
1455
  * Array
1456
  * {
1457
  *  [cid] => 2
1458
  *  [client_idle_time] => 4445369
1459
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1460
  *  [client_nickname] => par0noid
1461
  *  [client_version] => 3.0.9.2 [Build: 1351504843]
1462
  *  [client_platform] => Windows
1463
  *  [client_input_muted] => 1
1464
  *  [client_output_muted] => 1
1465
  *  [client_outputonly_muted] => 0
1466
  *  [client_input_hardware] => 1
1467
  *  [client_output_hardware] => 1
1468
  *  [client_default_channel] => 
1469
  *  [client_meta_data] => 
1470
  *  [client_is_recording] => 0
1471
  *  [client_login_name] => 
1472
  *  [client_database_id] => 2
1473
  *  [client_channel_group_id] => 5
1474
  *  [client_servergroups] => 6
1475
  *  [client_created] => 1361027850
1476
  *  [client_lastconnected] => 1361027850
1477
  *  [client_totalconnections] => 1
1478
  *  [client_away] => 0
1479
  *  [client_away_message] => 
1480
  *  [client_type] => 0
1481
  *  [client_flag_avatar] => 
1482
  *  [client_talk_power] => 75
1483
  *  [client_talk_request] => 0
1484
  *  [client_talk_request_msg] => 
1485
  *  [client_description] => 
1486
  *  [client_is_talker] => 0
1487
  *  [client_month_bytes_uploaded] => 0
1488
  *  [client_month_bytes_downloaded] => 0
1489
  *  [client_total_bytes_uploaded] => 0
1490
  *  [client_total_bytes_downloaded] => 0
1491
  *  [client_is_priority_speaker] => 0
1492
  *  [client_nickname_phonetic] => 
1493
  *  [client_needed_serverquery_view_power] => 75
1494
  *  [client_default_token] => 
1495
  *  [client_icon_id] => 0
1496
  *  [client_is_channel_commander] => 0
1497
  *  [client_country] => 
1498
  *  [client_channel_group_inherited_channel_id] => 2
1499
  *  [client_base64HashClientUID] => jneilbgomklpfnkjclkoggokfdmdlhnbbpmdpagh
1500
  *  [connection_filetransfer_bandwidth_sent] => 0
1501
  *  [connection_filetransfer_bandwidth_received] => 0
1502
  *  [connection_packets_sent_total] => 12130
1503
  *  [connection_bytes_sent_total] => 542353
1504
  *  [connection_packets_received_total] => 12681
1505
  *  [connection_bytes_received_total] => 592935
1506
  *  [connection_bandwidth_sent_last_second_total] => 82
1507
  *  [connection_bandwidth_sent_last_minute_total] => 92
1508
  *  [connection_bandwidth_received_last_second_total] => 84
1509
  *  [connection_bandwidth_received_last_minute_total] => 88
1510
  *  [connection_connected_time] => 5908749
1511
  *  [connection_client_ip] => 127.0.0.1
1512
  * } 
1513
  * </pre>
1514
  *
1515
  * @author     Par0noid Solutions
1516
  * @param		integer	$clid	clientID
1517
  * @return     array	clientInformation
1518
  */
1519
	function clientInfo($clid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1520
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1521
		return $this->getData('array', 'clientinfo clid='.$clid);
1522
	}
1523
1524
/**
1525
  * clientKick
1526
  * 
1527
  * 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.
1528
  *
1529
  * @author     Par0noid Solutions
1530
  * @param		integer $clid		clientID
1531
  * @param		string	$kickMode	kickMode (server or channel) (Default: servera)
1532
  * @param		string	$kickmsg 	kick reason [optional]
1533
  * @return     boolean success
1534
  */
1535
	function clientKick($clid, $kickMode = "server", $kickmsg = "") {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1536
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1537
		
1538
		if(in_array($kickMode, array('server', 'channel'))) {
1539
		
1540
			if($kickMode == 'server') { $from = '5'; }
1541
			if($kickMode == 'channel') { $from = '4'; }
1542
			
1543
			if(!empty($kickmsg)) { $msg = ' reasonmsg='.$this->escapeText($kickmsg); } else{ $msg = ''; }
1544
			
1545
			return $this->getData('boolean', 'clientkick clid='.$clid.' reasonid='.$from.$msg);
0 ignored issues
show
Bug introduced by
The variable $from does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1546
		}else{
1547
			$this->addDebugLog('invalid kickMode');
1548
			return $this->generateOutput(false, array('Error: invalid kickMode'), false);
1549
		}
1550
	}
1551
1552
/**
1553
  * clientList
1554
  * 
1555
  * 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.
1556
  *
1557
  * <b>Possible params:</b> [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country] [-ip] [-badges]
1558
  *
1559
  * <b>Output: (without parameters)</b>
1560
  * <pre>
1561
  * Array
1562
  * {
1563
  *  [clid] => 1
1564
  *  [cid] => 1
1565
  *  [client_database_id] => 2
1566
  *  [client_nickname] => Par0noid
1567
  *  [client_type] => 0
1568
  *  [-uid] => [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
1569
  *  [-away] => [client_away] => 0
1570
  *  [-away] => [client_away_message] => 
1571
  *  [-voice] => [client_flag_talking] => 0
1572
  *  [-voice] => [client_input_muted] => 0
1573
  *  [-voice] => [client_output_muted] => 0
1574
  *  [-voice] => [client_input_hardware] => 0
1575
  *  [-voice] => [client_output_hardware] => 0
1576
  *  [-voice] => [client_talk_power] => 0
1577
  *  [-voice] => [client_is_talker] => 0
1578
  *  [-voice] => [client_is_priority_speaker] => 0
1579
  *  [-voice] => [client_is_recording] => 0
1580
  *  [-voice] => [client_is_channel_commander] => 0
1581
  *  [-times] => [client_idle_time] => 1714
1582
  *  [-times] => [client_created] => 1361027850
1583
  *  [-times] => [client_lastconnected] => 1361042955
1584
  *  [-groups] => [client_servergroups] => 6,7
1585
  *  [-groups] => [client_channel_group_id] => 8
1586
  *  [-groups] => [client_channel_group_inherited_channel_id] => 1
1587
  *  [-info] => [client_version] => 3.0.9.2 [Build: 1351504843]
1588
  *  [-info] => [client_platform] => Windows
1589
  *  [-icon] => [client_icon_id] => 0
1590
  *  [-country] => [client_country] => 
1591
  *  [-ip] => [connection_client_ip] => 127.0.0.1
1592
  *  [-badges] => [client_badges] => Overwolf=0
1593
  * }
1594
  * 
1595
  * <b>Usage:</b>
1596
  * 
1597
  * $ts3->clientList(); //No parameters
1598
  * $ts3->clientList("-uid"); //Single parameter
1599
  * $ts3->clientList("-uid -away -voice -times -groups -info -country -icon -ip -badges"); //Multiple parameters
1600
  * </pre>
1601
  *
1602
  * @author     Par0noid Solutions
1603
  * @param		string	$params	additional parameters [optional]
1604
  * @return     array clientList 
1605
  */
1606
	function clientList($params = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1607
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1608
		
1609
		if(!empty($params)) { $params = ' '.$params; }
1610
		
1611
		return $this->getData('multi', 'clientlist'.$params);
1612
	}
1613
1614
/**
1615
  * clientMove
1616
  * 
1617
  * 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.
1618
  *
1619
  * @author     Par0noid Solutions
1620
  * @param		integer $clid	clientID
1621
  * @param		integer $cid	channelID
1622
  * @param		string	$cpw	channelPassword [optional]
1623
  * @return     boolean success
1624
  */
1625
	function clientMove($clid, $cid, $cpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1626
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1627
		return $this->getData('boolean', 'clientmove clid='.$clid.' cid='.$cid.(!empty($cpw) ? ' cpw='.$this->escapeText($cpw) : ''));
1628
	}
1629
1630
/**
1631
  * clientPermList
1632
  * 
1633
  * Displays a list of permissions defined for a client.
1634
  *
1635
  * <b>Output:</b>
1636
  * <pre>
1637
  * Array
1638
  * {
1639
  *  [permid] => 20654 //with permsid = false
1640
  *  [permsid] => b_client_ignore_bans //with permsid = true
1641
  *  [permvalue] => 1
1642
  *  [permnegated] => 0
1643
  *  [permskip] => 0
1644
  * }
1645
  * </pre>
1646
  *
1647
  * @author     Par0noid Solutions
1648
  * @param		intege		$cldbid 	clientDBID
1649
  * @param		boolean		$permsid	set true to add -permsid param [optional]
1650
  * @return     array clientPermList
1651
  */
1652
	function clientPermList($cldbid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1653
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
1654
		return $this->getData('multi', 'clientpermlist cldbid='.$cldbid.($permsid ? ' -permsid' : ''));
1655
	}
1656
1657
/**
1658
  * clientPoke
1659
  * 
1660
  * Sends a poke message to the client specified with clid.
1661
  *
1662
  * @author     Par0noid Solutions
1663
  * @param		integer $clid	clientID
1664
  * @param		string 	$msg 	pokeMessage
1665
  * @return     boolean success
1666
  */
1667
	function clientPoke($clid, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1668
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1669
		return $this->getData('boolean', 'clientpoke clid='.$clid.' msg='.$this->escapeText($msg));
1670
	}
1671
1672
/**
1673
  * clientSetServerQueryLogin
1674
  * 
1675
  * Updates your own ServerQuery login credentials using a specified username. The password will be auto-generated.
1676
  * 
1677
  * <b>Output:</b>
1678
  * <pre>
1679
  * Array
1680
  * {
1681
  *  [client_login_password] => +r\/TQqvR
1682
  * }
1683
  * </pre>
1684
  *
1685
  * @author     Par0noid Solutions
1686
  * @param		string	$username	username
1687
  * @return     array userInfomation
1688
  */
1689
	function clientSetServerQueryLogin($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1690
		return $this->getData('array', 'clientsetserverquerylogin client_login_name='.$this->escapeText($username));
1691
	}
1692
1693
/**
1694
  * clientUpdate
1695
  * 
1696
  * Change your ServerQuery clients settings using given properties.
1697
  * 
1698
  * <b>Input-Array like this:</b>
1699
  * <pre>
1700
  * $data = array();
1701
  * $data['property'] = 'value';
1702
  * $data['property'] = 'value';
1703
  * </pre>
1704
  *
1705
  * @author     Par0noid Solutions
1706
  * @param		array	$data	clientProperties
1707
  * @return     boolean success
1708
  */
1709
	function clientUpdate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1710
		$settingsString = '';
1711
		
1712
		foreach($data as $key => $value) {
1713
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
1714
		}
1715
		
1716
		return $this->getData('boolean', 'clientupdate '.$settingsString);
1717
	}
1718
1719
/**
1720
  * complainAdd
1721
  *
1722
  * Submits a complaint about the client with database ID tcldbid to the server.
1723
  *
1724
  * @author     Par0noid Solutions
1725
  * @param		integer $tcldbid	targetClientDBID
1726
  * @param		string	$msg		complainMessage
1727
  * @return     boolean success
1728
  */
1729
	function complainAdd($tcldbid, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1730
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1731
		return $this->getData('boolean', 'complainadd tcldbid='.$tcldbid.' message='.$this->escapeText($msg));
1732
	}
1733
1734
/**
1735
  * complainDelete
1736
  * 
1737
  * Deletes the complaint about the client with ID tcldbid submitted by the client with ID fcldbid from the server.
1738
  *
1739
  * @author     Par0noid Solutions
1740
  * @param		integer $tcldbid targetClientDBID
1741
  * @param		integer $fcldbid fromClientDBID
1742
  * @return     boolean success
1743
  */
1744
	function complainDelete($tcldbid, $fcldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1745
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1746
		return $this->getData('boolean', 'complaindel tcldbid='.$tcldbid.' fcldbid='.$fcldbid);
1747
	}
1748
1749
/**
1750
  * complainDeleteAll
1751
  * 
1752
  * Deletes all complaints about the client with database ID tcldbid from the server.
1753
  *
1754
  * @author     Par0noid Solutions
1755
  * @param		integer $tcldbid targetClientDBID
1756
  * @return     boolean success
1757
  */
1758
	function complainDeleteAll($tcldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1759
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1760
		return $this->getData('boolean', 'complaindelall tcldbid='.$tcldbid);
1761
	}
1762
1763
/**
1764
  * complainList
1765
  * 
1766
  * Displays a list of complaints on the selected virtual server. If tcldbid is specified, only complaints about the targeted client will be shown.
1767
  *
1768
  * <b>Output:</b>
1769
  * <pre>
1770
  * Array
1771
  * {
1772
  *  [tcldbid] => 2
1773
  *  [tname] => par0noid
1774
  *  [fcldbid] => 1
1775
  *  [fname] => serveradmin from 127.0.0.1:6814
1776
  *  [message] => Steals crayons
1777
  *  [timestamp] => 1361044090
1778
  * }
1779
  * </pre>
1780
  *
1781
  * @author     Par0noid Solutions
1782
  * @param		string $tcldbid	targetClientDBID [optional]
1783
  * @return     array complainList
1784
  */
1785
	function complainList($tcldbid = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1786
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1787
		if(!empty($tcldbid)) { $tcldbid = ' tcldbid='.$tcldbid; }
1788
		return $this->getData('multi', 'complainlist'.$tcldbid);
1789
	}
1790
1791
/**
1792
  * execOwnCommand
1793
  * 
1794
  * executes a command that isn't defined in class and returns data like your propose
1795
  * 
1796
  * <b>Modes:</b>
1797
  * <ul>
1798
  * 	<li><b>0:</b> execute -> return boolean</li>
1799
  * 	<li><b>1:</b> execute -> return normal array</li>
1800
  * 	<li><b>2:</b> execute -> return multidimensional array</li>
1801
  * 	<li><b>3:</b> execute -> return plaintext serverquery</li>
1802
  * </ul>
1803
  *
1804
  * @author     Par0noid Solutions
1805
  * @param		string	$mode		executionMode
1806
  * @param		string	$command	command
1807
  * @return     mixed result
1808
  */
1809
	function execOwnCommand($mode, $command) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1810
		if($mode == '0') {
1811
			return $this->getData('boolean', $command);
1812
		}
1813
		if($mode == '1') {
1814
			return $this->getData('array', $command);
1815
		}
1816
		if($mode == '2') {
1817
			return $this->getData('multi', $command);
1818
		}
1819
		if($mode == '3') {
1820
			return $this->getData('plain', $command);
1821
		}
1822
	}
1823
1824
/**
1825
  * ftCreateDir
1826
  * 
1827
  * Creates new directory in a channels file repository.
1828
  *
1829
  * @author     Par0noid Solutions
1830
  * @param		string	$cid		channelId
1831
  * @param		string	$cpw		channelPassword (leave blank if not needed)
1832
  * @param		string	$dirname	dirPath
1833
  * @return     boolean success
1834
  */
1835
	function ftCreateDir($cid, $cpw = null, $dirname) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1836
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1837
		return $this->getData('boolean', 'ftcreatedir cid='.$cid.' cpw='.$this->escapeText($cpw).' dirname='.$this->escapeText($dirname));
1838
	}
1839
1840
/**
1841
  * ftDeleteFile
1842
  * 
1843
  * Deletes one or more files stored in a channels file repository.
1844
  *
1845
  * <b>Input-Array like this:</b>
1846
  * <pre>
1847
  * $files = array();
1848
  *	
1849
  * $files[] = '/pic1.jpg';
1850
  * $files[] = '/dokumente/test.txt';
1851
  * $files[] = '/dokumente';
1852
  * </pre>
1853
  *
1854
  * @author     Par0noid Solutions
1855
  * @param		string	$cid	channelID
1856
  * @param		string	$cpw	channelPassword (leave blank if not needed)
1857
  * @param		array	$files	files
1858
  * @return     boolean success
1859
  */
1860 View Code Duplication
	function ftDeleteFile($cid, $cpw = '', $files) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1861
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1862
		$fileArray = array();
1863
		
1864
		if(count($files) > 0) {
1865
			foreach($files AS $file) {
1866
				$fileArray[] = 'name='.$this->escapeText($file);
1867
			}
1868
			return $this->getData('boolean', 'ftdeletefile cid='.$cid.' cpw='.$this->escapeText($cpw).' '.implode('|', $fileArray));
1869
		}else{
1870
			$this->addDebugLog('no files given');
1871
			return $this->generateOutput(false, array('Error: no files given'), false);
1872
		}
1873
	}
1874
1875
/**
1876
  * ftDownloadFile
1877
  * 
1878
  * Ddownloads a file and returns its contents
1879
  *
1880
  * @author     Par0noid Solutions
1881
  * @param		array	$data	return of ftInitDownload
1882
  * @return     array downloadedFile
1883
  */
1884
	function ftDownloadFile($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1885
		$errnum = null;
1886
		$errstr = null;
1887
  		$this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
1888
  		if($this->runtime['fileSocket']) {
1889
  			$this->ftSendKey($data['data']['ftkey']);
1890
  			$content = $this->ftRead($data['data']['size']);
1891
  			@fclose($this->runtime['fileSocket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1892
  			$this->runtime['fileSocket'] = '';
1893
  			return $content;
1894 View Code Duplication
  		}else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1895
  			$this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
1896
  			return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
1897
  		}
1898
	}
1899
	
1900
/**
1901
  * ftGetFileInfo
1902
  * 
1903
  * Displays detailed information about one or more specified files stored in a channels file repository.
1904
  * 
1905
  *
1906
  * @author     Par0noid Solutions
1907
  * @param		string	$cid	channelID
1908
  * @param		string	$cpw	channelPassword (leave blank if not needed)
1909
  * @param		string 	$file	path to file
1910
  * @return     boolean success
1911
  */
1912
	function ftGetFileInfo($cid, $cpw = '', $file) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1913
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1914
1915
		return $this->getData('multi', 'ftgetfileinfo cid='.$cid.' cpw='.$this->escapeText($cpw).' name='.$this->escapeText($file));
1916
	}
1917
1918
/**
1919
  * ftGetFileList
1920
  *
1921
  * Displays a list of files and directories stored in the specified channels file repository.
1922
  *
1923
  * <b>Output:</b>
1924
  * <pre>
1925
  * Array
1926
  * {
1927
  *  [cid] => 231
1928
  *  [path] => /
1929
  *  [name] => Documents
1930
  *  [size] => 0
1931
  *  [datetime] => 1286633633
1932
  *  [type] => 0
1933
  * }
1934
  * </pre>
1935
  *
1936
  * @author     Par0noid Solutions
1937
  * @param		string	$cid	channelID
1938
  * @param		string	$cpw	channelPassword (leave blank if not needed)
1939
  * @param		string	$path	filePath
1940
  * @return     array	fileList
1941
  */
1942
	function ftGetFileList($cid, $cpw = '', $path) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1943
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1944
		return $this->getData('multi', 'ftgetfilelist cid='.$cid.' cpw='.$this->escapeText($cpw).' path='.$this->escapeText($path));
1945
	}
1946
	
1947
/**
1948
  * ftInitDownload
1949
  * 
1950
  * 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.
1951
  *
1952
  * <b>Output:</b>
1953
  * <pre>
1954
  * Array
1955
  * {
1956
  *  [clientftfid] => 89
1957
  *  [serverftfid] => 3
1958
  *  [ftkey] => jSzWiRmFGdZnoJzW7BSDYJRUWB2WAUhb
1959
  *  [port] => 30033
1960
  *  [size] => 94
1961
  * }
1962
  * </pre>
1963
  *
1964
  * @author     Par0noid Solutions
1965
  * @param		string	$name			filePath
1966
  * @param		string	$cid			channelID
1967
  * @param		string	$cpw			channelPassword (leave blank if not needed)
1968
  * @param		integer	$seekpos		seekpos (default = 0) [optional]
1969
  * @return     array	initDownloadFileInfo
1970
  */	
1971
	function ftInitDownload($name, $cid, $cpw = '', $seekpos = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1972
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
1973
		return $this->getData('array', 'ftinitdownload clientftfid='.rand(1,99).' name='.$this->escapeText($name).' cid='.$cid.' cpw='.$this->escapeText($cpw).' seekpos='.$seekpos);
1974
	}
1975
1976
/**
1977
  * ftInitUpload
1978
  * 
1979
  * 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.
1980
  *
1981
  * <b>Output:</b>
1982
  * <pre>
1983
  * Array
1984
  * {
1985
  *  [clientftfid] => 84
1986
  *  [serverftfid] => 41
1987
  *  [ftkey] => HCnXpunOdAorqj3dGqfiuLszX18O0PHP
1988
  *  [port] => 30033
1989
  *  [seekpos] => 0
1990
  * }
1991
  * </pre>
1992
  *
1993
  * @author     Par0noid Solutions
1994
  * @param		string	$filename	filePath
1995
  * @param		string	$cid		channelID
1996
  * @param		integer	$size		fileSize in bytes
1997
  * @param		string	$cpw		channelPassword (leave blank if not needed)
1998
  * @param		boolean	$overwrite	overwrite	[optional] (default = 0)
1999
  * @param		boolean	$resume		resume		[optional] (default = 0)
2000
  * @return     array	initUploadFileInfo
2001
  */	
2002
	function ftInitUpload($filename, $cid, $size, $cpw = '', $overwrite = false, $resume = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2003
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2004
		
2005
		if($overwrite) { $overwrite = ' overwrite=1'; }else{ $overwrite = ' overwrite=0'; }
2006
		if($resume) { $resume = ' resume=1'; }else{ $resume = ' resume=0'; }
2007
		
2008
		return $this->getData('array', 'ftinitupload clientftfid='.rand(1,99).' name='.$this->escapeText($filename).' cid='.$cid.' cpw='.$this->escapeText($cpw).' size='.($size + 1).$overwrite.$resume);
2009
	}
2010
	
2011
/**
2012
  * ftList
2013
  * 
2014
  * 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
2015
  *
2016
  * <b>Output:</b>
2017
  * <pre>
2018
  * Array
2019
  * {
2020
  *  [clid] => 1
2021
  *  [cldbid] => 2019
2022
  *  [path] => files/virtualserver_11/channel_231
2023
  *  [name] => 1285412348878.png
2024
  *  [size] => 1161281
2025
  *  [sizedone] => 275888
2026
  *  [clientftfid] => 15
2027
  *  [serverftfid] => 52
2028
  *  [sender] => 0
2029
  *  [status] => 1
2030
  *  [current_speed] => 101037.4453
2031
  *  [average_speed] => 101037.4453
2032
  *  [runtime] => 2163
2033
  * }
2034
  * </pre>
2035
  *
2036
  * @author     Par0noid Solutions
2037
  * @return     array	fileTransferList
2038
  */
2039
	function ftList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2040
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2041
		return $this->getData('multi', 'ftlist');
2042
	}
2043
2044
/**
2045
  * ftRenameFile
2046
  * 
2047
  * 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.
2048
  *
2049
  * @author     Par0noid Solutions
2050
  * @param		integer	$cid		channelID
2051
  * @param		string	$cpw		channelPassword (leave blank if not needed)
2052
  * @param		string	$oldname	oldFilePath
2053
  * @param		string	$newname	newFilePath
2054
  * @param		string  $tcid		targetChannelID [optional]
2055
  * @param		string  $tcpw		targetChannelPassword [optional]
2056
  * @return     boolean success
2057
  */
2058
	function ftRenameFile($cid, $cpw = null, $oldname, $newname, $tcid = null,  $tcpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2059
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2060
		$newTarget = ($tcid != null ? ' tcid='.$tcid.' '.$tcpw : '');
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $tcid of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
2061
		return $this->getData('boolean', 'ftrenamefile cid='.$cid.' cpw='.$cpw.' oldname='.$this->escapeText($oldname).' newname='.$this->escapeText($newname).$newTarget);
2062
	}
2063
2064
/**
2065
  * ftStop
2066
  * 
2067
  * Stops the running file transfer with server-side ID serverftfid.
2068
  *
2069
  * @author     Par0noid Solutions
2070
  * @param		integer	$serverftfid	serverFileTransferID
2071
  * @param		boolean	$delete			delete incomplete file [optional] (default: true) 
2072
  * @return     boolean success
2073
  */
2074
	function ftStop($serverftfid, $delete = true) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2075
		if(!$this->runtime['selected']) { return $this->checkSelected(); }		
2076
		return $this->getData('boolean', 'ftstop serverftfid='.$serverftfid.' delete='.($delete ? '1' : '0'));
2077
	}
2078
2079
/**
2080
  * ftUploadFile
2081
  * 
2082
  * Uploads a file to server
2083
  * To check if upload was successful, you have to search for this file in fileList after
2084
  *
2085
  * @author     Par0noid Solutions
2086
  * @param		array	$data			return of ftInitUpload
2087
  * @param		string	$uploadData		data which should be uploaded
2088
  * @return     array response
2089
  */
2090
	function ftUploadFile($data, $uploadData) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2091
  		$this->runtime['fileSocket'] = @fsockopen($this->runtime['host'], $data['data']['port'], $errnum, $errstr, $this->runtime['timeout']);
2092
  		if($this->runtime['fileSocket']) {
2093
  			$this->ftSendKey($data['data']['ftkey'], "\n");
2094
  			$this->ftSendData($uploadData);
2095
  			@fclose($this->runtime['fileSocket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2096
  			$this->runtime['fileSocket'] = '';
2097
  			return $this->generateOutput(true, array(), true);
2098 View Code Duplication
  		}else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2099
  			$this->addDebugLog('fileSocket returns '.$errnum. ' | '.$errstr);
2100
  			return $this->generateOutput(false, array('Error in fileSocket: '.$errnum. ' | '.$errstr), false);
2101
  		}
2102
	}
2103
2104
/**
2105
  * gm
2106
  * 
2107
  * Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance.
2108
  *
2109
  * @author     Par0noid Solutions
2110
  * @param		string	$msg	message
2111
  * @return     boolean success
2112
  */
2113
	function gm($msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2114 View Code Duplication
		if(empty($msg)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2115
			$this->addDebugLog('empty message given');
2116
			return $this->generateOutput(false, array('Error: empty message given'), false);
2117
		}
2118
		return $this->getData('boolean', 'gm msg='.$this->escapeText($msg));
2119
	}
2120
2121
/**
2122
  * hostInfo
2123
  * 
2124
  * Displays detailed connection information about the server instance including uptime, number of virtual servers online, traffic information, etc.
2125
  *
2126
  * <b>Output:</b>
2127
  * <pre>
2128
  * Array
2129
  * {
2130
  *  [instance_uptime] => 19038
2131
  *  [host_timestamp_utc] => 1361046825
2132
  *  [virtualservers_running_total] => 1
2133
  *  [virtualservers_total_maxclients] => 32
2134
  *  [virtualservers_total_clients_online] => 1
2135
  *  [virtualservers_total_channels_online] => 2
2136
  *  [connection_filetransfer_bandwidth_sent] => 0
2137
  *  [connection_filetransfer_bandwidth_received] => 0
2138
  *  [connection_filetransfer_bytes_sent_total] => 0
2139
  *  [connection_filetransfer_bytes_received_total] => 0
2140
  *  [connection_packets_sent_total] => 24853
2141
  *  [connection_bytes_sent_total] => 1096128
2142
  *  [connection_packets_received_total] => 25404
2143
  *  [connection_bytes_received_total] => 1153918
2144
  *  [connection_bandwidth_sent_last_second_total] => 82
2145
  *  [connection_bandwidth_sent_last_minute_total] => 81
2146
  *  [connection_bandwidth_received_last_second_total] => 84
2147
  *  [connection_bandwidth_received_last_minute_total] => 87
2148
  * }
2149
  * </pre>
2150
  *
2151
  * @author     Par0noid Solutions
2152
  * @return     array hostInformation
2153
  */
2154
	function hostInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2155
		return $this->getData('array', 'hostinfo');
2156
	}
2157
2158
/**
2159
  * instanceEdit
2160
  * 
2161
  * Changes the server instance configuration using given properties.
2162
  *
2163
  * <b>Input-Array like this:</b>
2164
  * <pre>
2165
  * $data = array();
2166
  *	
2167
  * $data['setting'] = 'value';
2168
  * $data['setting'] = 'value';
2169
  * </pre>
2170
  *
2171
  * @author     Par0noid Solutions
2172
  * @param		array	$data	instanceProperties
2173
  * @return     boolean success
2174
  */
2175
	function instanceEdit($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2176
		if(count($data) > 0) {
2177
			$settingsString = '';
2178
			
2179
			foreach($data as $key => $val) {
2180
				$settingsString .= ' '.$key.'='.$this->escapeText($val);
2181
			}
2182
			return $this->getData('boolean', 'instanceedit '.$settingsString);
2183
		}else{
2184
			$this->addDebugLog('empty array entered');
2185
			return $this->generateOutput(false, array('Error: You can \'t give an empty array'), false);
2186
		}
2187
	}
2188
2189
/**
2190
  * instanceInfo
2191
  * 
2192
  * Displays the server instance configuration including database revision number, the file transfer port, default group IDs, etc.
2193
  *
2194
  * <b>Output:</b>
2195
  * <pre>
2196
  * Array
2197
  * {
2198
  *  [serverinstance_database_version] => 20
2199
  *  [serverinstance_filetransfer_port] => 30033
2200
  *  [serverinstance_max_download_total_bandwidth] => 18446744073709551615
2201
  *  [serverinstance_max_upload_total_bandwidth] => 18446744073709551615
2202
  *  [serverinstance_guest_serverquery_group] => 1
2203
  *  [serverinstance_serverquery_flood_commands] => 10
2204
  *  [serverinstance_serverquery_flood_time] => 3
2205
  *  [serverinstance_serverquery_ban_time] => 600
2206
  *  [serverinstance_template_serveradmin_group] => 3
2207
  *  [serverinstance_template_serverdefault_group] => 5
2208
  *  [serverinstance_template_channeladmin_group] => 1
2209
  *  [serverinstance_template_channeldefault_group] => 4
2210
  *  [serverinstance_permissions_version] => 15
2211
  * }
2212
  * </pre>
2213
  *
2214
  * @author     Par0noid Solutions
2215
  * @return     array instanceInformation
2216
  */
2217
	function instanceInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2218
		return $this->getData('array', 'instanceinfo');
2219
	}
2220
2221
/**
2222
  * logAdd
2223
  * 
2224
  * 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.
2225
  *
2226
  * @author     Par0noid Solutions
2227
  * @param		integer	$logLevel	loglevel between 1 and 4
2228
  * @param		string	$logMsg		logMessage
2229
  * @return     boolean success
2230
  */
2231
	function logAdd($logLevel, $logMsg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2232
		if($logLevel >=1 and $logLevel <= 4) { 
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
2233
			if(!empty($logMsg)) {
2234
				return $this->getData('boolean', 'logadd loglevel='.$logLevel.' logmsg='.$this->escapeText($logMsg));
2235
			}else{
2236
				$this->addDebugLog('logMessage empty!');
2237
				return $this->generateOutput(false, array('Error: logMessage empty!'), false);
2238
			}
2239
		}else{
2240
			$this->addDebugLog('invalid logLevel!');
2241
			return $this->generateOutput(false, array('Error: invalid logLevel!'), false);
2242
		}
2243
	}
2244
2245
/**
2246
  * login
2247
  * 
2248
  * Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials.
2249
  *
2250
  * @author     Par0noid Solutions
2251
  * @param		string	$username	username
2252
  * @param		string	$password	password
2253
  * @return     boolean success
2254
  */
2255
	function login($username, $password) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2256
		return $this->getData('boolean', 'login '.$this->escapeText($username).' '.$this->escapeText($password));
2257
	}
2258
2259
/**
2260
  * logout
2261
  * 
2262
  * Deselects the active virtual server and logs out from the server instance.
2263
  *
2264
  * @author     Par0noid Solutions
2265
  * @return     boolean success
2266
  */
2267
	function logout() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2268
		$this->runtime['selected'] = false;
2269
		return $this->getData('boolean', 'logout');
2270
	}
2271
2272
/**
2273
  * logView
2274
  * 
2275
  * 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.
2276
  * 
2277
  * <b>Output:</b>
2278
  * <pre>
2279
  * Array
2280
  * {
2281
  *  [last_pos] => 0
2282
  *  [file_size] => 1085
2283
  *  [l] => 2012-01-10 20:34:31.379260|INFO    |ServerLibPriv |   | TeamSpeak 3 Server 3.0.1 (2011-11-17 07:34:30)
2284
  * }
2285
  * {
2286
  *  [l] => 2012-01-10 20:34:31.380260|INFO    |DatabaseQuery |   | dbPlugin name:    SQLite3 plugin, Version 2, (c)TeamSpeak Systems GmbH
2287
  * }
2288
  * {
2289
  *  [l] => 2012-01-10 20:34:31.380260|INFO    |DatabaseQuery |   | dbPlugin version: 3.7.3
2290
  * }
2291
  * </pre>
2292
  *
2293
  * @author     Par0noid Solutions
2294
  * @param		integer	$lines	between 1 and 100
2295
  * @param		integer	$reverse	{1|0} [optional]
2296
  * @param		integer	$instance	{1|0} [optional]
2297
  * @param		integer	$begin_pos	{1|0} [optional]
2298
  * @return     multidimensional-array logEntries
0 ignored issues
show
Documentation introduced by
The doc-type multidimensional-array could not be parsed: Unknown type name "multidimensional-array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2299
  */
2300
	function logView($lines, $reverse = 0, $instance = 0, $begin_pos = 0) {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2301
		if($lines >=1 and $lines <=100) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
2302
			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));
2303
		}else{
2304
			$this->addDebugLog('please choose a limit between 1 and 100');
2305
			$this->generateOutput(false, array('Error: please choose a limit between 1 and 100'), false);
0 ignored issues
show
Unused Code introduced by
The call to the method ts3admin::generateOutput() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
2306
		}
2307
	}
2308
2309
/**
2310
  * permIdGetByName
2311
  * 
2312
  * Displays the database ID of one or more permissions specified by permsid.
2313
  *
2314
  * <b>Input-Array like this:</b>
2315
  * <pre>
2316
  * $permissions = array();
2317
  * $permissions[] = 'permissionName';
2318
  * </pre>
2319
  * <b>Output:</b>
2320
  * <pre>
2321
  * Array
2322
  * {
2323
  *  [permsid] => b_serverinstance_help_view
2324
  *  [permid] => 4353
2325
  * }
2326
  * </pre>
2327
  *
2328
  * @author     Par0noid Solutions
2329
  * @param		string	$permsids		permNames
2330
  * @return     array	permissionList 
2331
  */
2332
	function permIdGetByName($permsids) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2333
		$permissionArray = array();
2334
		
2335
		if(count($permsids) > 0) {
2336
			foreach($permsids AS $value) {
0 ignored issues
show
Bug introduced by
The expression $permsids of type string is not traversable.
Loading history...
2337
				$permissionArray[] = 'permsid='.$value;
2338
			}
2339
			return $this->getData('multi', 'permidgetbyname '.$this->escapeText(implode('|', $permissionArray)));
2340
		}else{
2341
			$this->addDebugLog('no permissions given');
2342
			return $this->generateOutput(false, array('Error: no permissions given'), false);
2343
		}
2344
		
2345
	}
2346
2347
2348
/**
2349
  * permissionList
2350
  * 
2351
  * Displays a list of permissions available on the server instance including ID, name and description.
2352
  * If the new parameter is set the permissionlist will return with the new output format.
2353
  *
2354
  * <b>Output: (with new parameter)</b>
2355
  * <pre>
2356
  * [0] => Array
2357
  *     (
2358
  *         [num] => 1
2359
  *         [group_id_end] => 0
2360
  *         [pcount] => 0
2361
  *     )
2362
  *
2363
  * [1] => Array
2364
  *     (
2365
  *         [num] => 2
2366
  *         [group_id_end] => 7
2367
  *         [pcount] => 7
2368
  *         [permissions] => Array
2369
  *             (
2370
  *                 [0] => Array
2371
  *                     (
2372
  *                         [permid] => 1
2373
  *                         [permname] => b_serverinstance_help_view
2374
  *                         [permdesc] => Retrieve information about ServerQuery commands
2375
  *                         [grantpermid] => 32769
2376
  *                     )
2377
  *
2378
  *                 [1] => Array
2379
  *                     (
2380
  *                         [permid] => 2
2381
  *                         [permname] => b_serverinstance_version_view
2382
  *                         [permdesc] => Retrieve global server version (including platform and build number)
2383
  *                         [grantpermid] => 32770
2384
  *                     )
2385
  *
2386
  *                 [2] => Array
2387
  *                     (
2388
  *                         [permid] => 3
2389
  *                         [permname] => b_serverinstance_info_view
2390
  *                         [permdesc] => Retrieve global server information
2391
  *                         [grantpermid] => 32771
2392
  *                     )
2393
  *
2394
  *                 [3] => Array
2395
  *                     (
2396
  *                         [permid] => 4
2397
  *                         [permname] => b_serverinstance_virtualserver_list
2398
  *                         [permdesc] => List virtual servers stored in the database
2399
  *                         [grantpermid] => 32772
2400
  *                     )
2401
  *
2402
  *                 [4] => Array
2403
  *                     (
2404
  *                         [permid] => 5
2405
  *                         [permname] => b_serverinstance_binding_list
2406
  *                         [permdesc] => List active IP bindings on multi-homed machines
2407
  *                         [grantpermid] => 32773
2408
  *                     )
2409
  *
2410
  *                [5] => Array
2411
  *                     (
2412
  *                         [permid] => 6
2413
  *                         [permname] => b_serverinstance_permission_list
2414
  *                         [permdesc] => List permissions available available on the server instance
2415
  *                         [grantpermid] => 32774
2416
  *                     )
2417
  *
2418
  *                 [6] => Array
2419
  *                     (
2420
  *                         [permid] => 7
2421
  *                         [permname] => b_serverinstance_permission_find
2422
  *                         [permdesc] => Search permission assignments by name or ID
2423
  *                         [grantpermid] => 32775
2424
  *                     )
2425
  *
2426
  *             )
2427
  *
2428
  *     )
2429
  * </pre>
2430
  *
2431
  * @author     Par0noid Solutions
2432
  * @param		boolean		$new		[optional] add new parameter
2433
  * @return     array permissionList
2434
  */
2435
	function permissionList($new = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2436
		if($new === true) {
2437
			$groups = array();
2438
			$permissions = array();
2439
			
2440
			$response = $this->getElement('data', $this->getData('multi', 'permissionlist -new'));
0 ignored issues
show
Bug introduced by
It seems like $this->getData('multi', 'permissionlist -new') targeting ts3admin::getData() can also be of type null; however, ts3admin::getElement() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
2441
			
2442
			$gc = 1;
2443
			
2444
			foreach($response as $field) {
2445
				if(isset($field['group_id_end'])) {
2446
					$groups[] = array('num' => $gc, 'group_id_end' => $field['group_id_end']);
2447
					$gc++;
2448
				}else{
2449
					$permissions[] = $field;
2450
				}
2451
			}
2452
			
2453
			$counter = 0;
2454
			
2455
			for($i = 0; $i < count($groups); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2456
				$rounds = $groups[$i]['group_id_end'] - $counter;
2457
				$groups[$i]['pcount'] = $rounds;
2458
				for($j = 0; $j < $rounds; $j++) {
2459
					$groups[$i]['permissions'][] = array('permid' => ($counter + 1), 'permname' => $permissions[$counter]['permname'], 'permdesc' => $permissions[$counter]['permdesc'], 'grantpermid' => ($counter + 32769));
2460
					$counter++;
2461
				}
2462
			}
2463
			
2464
			return $groups;
2465
			
2466
		}else{
2467
			return $this->getData('multi', 'permissionlist');
2468
		}
2469
	}
2470
2471
/**
2472
  * permOverview
2473
  * 
2474
  * 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.
2475
  *
2476
  * <b>Output:</b>
2477
  * <pre>
2478
  * Array
2479
  * {
2480
  *  [t] => 0
2481
  *  [id1] => 2
2482
  *  [id2] => 0
2483
  *  [p] => 16777
2484
  *  [v] => 1
2485
  *  [n] => 0
2486
  *  [s] => 0
2487
  * }
2488
  * </pre>
2489
  *
2490
  * @author     Par0noid Solutions
2491
  * @param		integer		$cid		cchannelId
2492
  * @param		integer 	$cldbid		clientDbId
2493
  * @param		integer 	$permid		permId (Default: 0)
2494
  * @param		string	 	$permsid	permName
2495
  * @return     array permOverview
2496
  */
2497
	function permOverview($cid, $cldbid, $permid='0', $permsid=false ) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2498
        if(!$this->runtime['selected']) { return $this->checkSelected(); } 
2499
        if($permsid) { $additional = ' permsid='.$permsid; }else{ $additional = ''; } 
0 ignored issues
show
Bug Best Practice introduced by
The expression $permsid of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2500
         
2501
        return $this->getData('multi', 'permoverview cid='.$cid.' cldbid='.$cldbid.' permid='.$permid.$additional); 
2502
    }
2503
 
2504
/**
2505
  * quit closes the connection to host 
2506
  *
2507
  * @author     Par0noid Solutions
2508
  * @return 	none
2509
  */
2510
	private function quit() {
2511
		$this->logout();
2512
		@fputs($this->runtime['socket'], "quit\n");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2513
		@fclose($this->runtime['socket']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2514
	}
2515
2516
/**
2517
  * selectServer
2518
  * 
2519
  * 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.
2520
  *
2521
  * @author     Par0noid Solutions
2522
  * @param		integer	$value		Port or ID
2523
  * @param		string	$type		value type ('port', 'serverId') (default='port')
2524
  * @param		boolean	$virtual	set true to add -virtual param [optional]
2525
  * @return     boolean success
2526
  */
2527
	function selectServer($value, $type = 'port', $virtual = false) { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2528
        if(in_array($type, array('port', 'serverId'))) { 
2529
            if($type == 'port') { 
2530
                if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; } 
2531
                $res = $this->getData('boolean', 'use port='.$value.$virtual); 
2532
                if($res['success']) { 
2533
                    $this->runtime['selected'] = true; 
2534
                } 
2535
                return $res; 
2536
            }else{ 
2537
                if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; } 
2538
                $res = $this->getData('boolean', 'use sid='.$value.$virtual); 
2539
                if($res['success']) { 
2540
                    $this->runtime['selected'] = true; 
2541
                } 
2542
                return $res; 
2543
            } 
2544
        }else{ 
2545
            $this->addDebugLog('wrong value type'); 
2546
            return $this->generateOutput(false, array('Error: wrong value type'), false); 
2547
        } 
2548
    }
2549
2550
/**
2551
  * sendMessage
2552
  * 
2553
  * 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.
2554
  * <b>Hint:</b> You can just write to the channel the query client is in. See link in description for details.
2555
  *
2556
  * <b>Modes:</b>
2557
  * <ul>
2558
  * 	<li><b>1:</b> send to client</li>
2559
  * 	<li><b>2:</b> send to channel</li>
2560
  * 	<li><b>3:</b> send to server</li>
2561
  * </ul>
2562
  * <b>Targets:</b>
2563
  * <ul>
2564
  * 	<li>clientID</li>
2565
  * 	<li>channelID</li>
2566
  * 	<li>serverID</li>
2567
  * </ul>
2568
  *
2569
  * @author     Par0noid Solutions
2570
  * @param		integer $mode
2571
  * @param		integer $target
2572
  * @param		string	$msg	Message
2573
  * @see		http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client http://forum.teamspeak.com/showthread.php/84280-Sendtextmessage-by-query-client
2574
  * @return     boolean	success
2575
  */
2576
	function sendMessage($mode, $target, $msg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2577
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2578
		return $this->getData('boolean', 'sendtextmessage targetmode='.$mode.' target='.$target.' msg='.$this->escapeText($msg));
2579
	}
2580
2581
/**
2582
  * serverCreate
2583
  * 
2584
  * 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.
2585
  * 
2586
  * <b>Input-Array like this:</b>
2587
  * <pre>
2588
  * $data = array();
2589
  *	
2590
  * $data['setting'] = 'value';
2591
  * $data['setting'] = 'value';
2592
  * </pre>
2593
  *
2594
  * <b>Output:</b>
2595
  * <pre>
2596
  * Array
2597
  * {
2598
  *  [sid] => 2
2599
  *  [virtualserver_port] => 9988
2600
  *  [token] => eKnFZQ9EK7G7MhtuQB6+N2B1PNZZ6OZL3ycDp2OW
2601
  * }
2602
  * </pre>
2603
  *
2604
  * @author     Par0noid Solutions
2605
  * @param		array	$data	serverSettings	[optional]
2606
  * @return     array serverInfo
2607
  */
2608
	function serverCreate($data = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2609
		$settingsString = '';
2610
		
2611
		if(count($data) == 0) {	$data['virtualserver_name'] = 'Teamspeak 3 Server'; }
2612
		
2613
		
2614
		foreach($data as $key => $value) {
2615
			if(!empty($value)) { $settingsString .= ' '.$key.'='.$this->escapeText($value); }
2616
		}
2617
		
2618
		return $this->getData('array', 'servercreate'.$settingsString);
2619
	}
2620
2621
/**
2622
  * serverDelete
2623
  * 
2624
  * Deletes the virtual server specified with sid. Please note that only virtual servers in stopped state can be deleted.
2625
  *
2626
  * @author     Par0noid Solutions
2627
  * @param		integer	$sid	serverID
2628
  * @return     boolean success
2629
  */
2630
	function serverDelete($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2631
		$this->serverStop($sid);
2632
		return $this->getdata('boolean', 'serverdelete sid='.$sid);
2633
	}
2634
2635
/**
2636
  * serverEdit
2637
  * 
2638
  * 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.
2639
  *
2640
  * <b>Input-Array like this:</b>
2641
  * <pre>
2642
  * $data = array();
2643
  *	
2644
  * $data['setting'] = 'value';
2645
  * $data['setting'] = 'value';
2646
  * </pre>
2647
  *
2648
  * @author     Par0noid Solutions
2649
  * @param		array	$data	serverSettings
2650
  * @return     boolean success
2651
  */
2652 View Code Duplication
	function serverEdit($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2653
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2654
		
2655
		$settingsString = '';
2656
		
2657
		foreach($data as $key => $value) {
2658
			$settingsString .= ' '.$key.'='.$this->escapeText($value);
2659
		}
2660
		
2661
		return $this->getData('boolean', 'serveredit'.$settingsString);
2662
	}
2663
2664
/**
2665
  * serverGroupAdd
2666
  * 
2667
  * 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
2668
  *
2669
  * <b>Output:</b>
2670
  * <pre>
2671
  * Array
2672
  * {
2673
  *  [sgid] => 86
2674
  * }
2675
  * </pre>
2676
  *
2677
  * @author     Par0noid Solutions
2678
  * @param		integer $name	groupName
2679
  * @param		integer	$type	groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
2680
  * @return     array groupId
2681
  */
2682
	function serverGroupAdd($name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2683
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2684
		return $this->getData('array', 'servergroupadd name='.$this->escapeText($name).' type='.$type);
2685
	}
2686
2687
/**
2688
  * serverGroupAddClient
2689
  * 
2690
  * Adds a client to the server group specified with sgid. Please note that a client cannot be added to default groups or template groups.
2691
  *
2692
  * @author     Par0noid Solutions
2693
  * @param		integer $sgid	serverGroupId
2694
  * @param		integer $cldbid	clientDBID
2695
  * @return     boolean success
2696
  */
2697
	function serverGroupAddClient($sgid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2698
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2699
		return $this->getData('boolean', 'servergroupaddclient sgid='.$sgid.' cldbid='.$cldbid);
2700
	}
2701
2702
/**
2703
  * serverGroupAddPerm
2704
  * 
2705
  * 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.
2706
  *
2707
  * <b>Input-Array like this:</b>
2708
  * <pre>
2709
  * $permissions = array();
2710
  * $permissions['permissionID'] = array('permissionValue', 'permskip', 'permnegated');
2711
  * //or you could use
2712
  * $permissions['permissionName'] = array('permissionValue', 'permskip', 'permnegated');
2713
  * </pre>
2714
  * 
2715
  * @author     Par0noid Solutions
2716
  * @param		integer $sgid	groupID
2717
  * @param		array	$permissions	permissions
2718
  * @return     boolean success
2719
  */
2720
	function serverGroupAddPerm($sgid, $permissions) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2721
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2722
		
2723
		if(count($permissions) > 0) {
2724
			//Permissions given
2725
				
2726
			//Errorcollector
2727
			$errors = array();
2728
				
2729
			//Split Permissions to prevent query from overload
2730
			$permissions = array_chunk($permissions, 50, true);
2731
				
2732
			//Action for each splitted part of permission
2733
			foreach($permissions as $permission_part)
2734
			{
2735
				//Create command_string for each command that we could use implode later
2736
				$command_string = array();
2737
		
2738
				foreach($permission_part as $key => $value)
2739
				{
2740
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
2741
				}
2742
		
2743
				$result = $this->getData('boolean', 'servergroupaddperm sgid='.$sgid.' '.implode('|', $command_string));
2744
		
2745
				if(!$result['success'])
2746
				{
2747
					foreach($result['errors'] as $error)
2748
					{
2749
						$errors[] = $error;
2750
					}
2751
				}
2752
			}
2753
				
2754
			if(count($errors) == 0)
2755
			{
2756
				return $this->generateOutput(true, array(), true);
2757
			}else{
2758
				return $this->generateOutput(false, $errors, false);
2759
			}
2760
				
2761
		}else{
2762
			// No permissions given
2763
			$this->addDebugLog('no permissions given');
2764
			return $this->generateOutput(false, array('Error: no permissions given'), false);
2765
		}
2766
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2767
		old code
2768
		
2769
        $error = false;
2770
        $results = array();
2771
        
2772
        if(count($permissions) > 0) {
2773
     		$new = array();
2774
 
2775
    		$i = 0;
2776
    		$k = 0;
2777
    		foreach($permissions as $ke => $va) {
2778
        		if($i > 149){ $i = 0; $k++; }else{ $i++; }
2779
        		$new[$k][$ke] = $va;
2780
    		}
2781
    		
2782
    		foreach($new as $perms) {
2783
    			$permissionArray = array();
2784
    			foreach($perms as $key => $value) {
2785
    				$permissionArray[] = 'permid='.$key.' permvalue='.$value[0].' permskip='.$value[1].' permnegated='.$value[2];
2786
    			}
2787
				$result = $this->getData('boolean', 'servergroupaddperm sgid='.$sgid.' '.implode('|', $permissionArray));
2788
				if(!$result['success']) { $error = true; }
2789
    			$results[] = $result;
2790
    		}
2791
    		
2792
    		if($error) {
2793
    			$returnErrors = array();
2794
    			foreach($results as $errorResult) {
2795
    				if(count($errorResult['errors']) > 0) {
2796
    					foreach($errorResult['errors'] as $errorResultError) {
2797
    						$returnErrors[] = $errorResultError;
2798
    					}
2799
    				}
2800
    			}
2801
    			return $this->generateOutput(false, $returnErrors, false);
2802
    		}else{
2803
    			return $this->generateOutput(true, array(), true);
2804
    		}
2805
        }else{
2806
            $this->addDebugLog('no permissions given');
2807
            return $this->generateOutput(false, array('Error: no permissions given'), false);
2808
        }*/
2809
		
2810
	}
2811
2812
/**
2813
  * serverGroupClientList
2814
  * 
2815
  * 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.
2816
  *
2817
  * <b>Possible params:</b> -names
2818
  *
2819
  * <b>Output: (with -names param)</b>
2820
  * <pre>
2821
  * Array
2822
  * {
2823
  *  [cldbid] => 2017
2824
  *  [client_nickname] => Par0noid //with -names parameter
2825
  *  [client_unique_identifier] => nUixbsq/XakrrmbqU8O30R/D8Gc=
2826
  * }
2827
  * </pre>
2828
  *
2829
  * @author     Par0noid Solutions
2830
  * @param		integer	$sgid		groupId
2831
  * @param		boolean	$names		set true to add -names param [optional]
2832
  * @return     multidimensional-array	serverGroupClientList
0 ignored issues
show
Documentation introduced by
The doc-type multidimensional-array could not be parsed: Unknown type name "multidimensional-array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2833
  */
2834
	function serverGroupClientList($sgid, $names = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2835
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2836
		if($names) { $names = ' -names'; }else{ $names = ''; }
2837
		return $this->getData('multi', 'servergroupclientlist sgid='.$sgid.$names);
2838
	}
2839
2840
/**
2841
  * serverGroupCopy
2842
  * 
2843
  * 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.
2844
  *
2845
  * <b>Output:</b>
2846
  * <pre>
2847
  * Array
2848
  * {
2849
  *  [sgid] => 86
2850
  * }
2851
  * </pre>
2852
  *
2853
  * @author     Par0noid Solutions
2854
  * @param		integer	$ssgid	sourceGroupID
2855
  * @param		integer	$tsgid	targetGroupID
2856
  * @param		integer $name	groupName
2857
  * @param		integer	$type	groupDbType (0 = template, 1 = normal, 2 = query | Default: 1)
2858
  * @return     array groupId
2859
  */
2860
	function serverGroupCopy($ssgid, $tsgid, $name, $type = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2861
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2862
		return $this->getData('array', 'servergroupcopy ssgid='.$ssgid.' tsgid='.$tsgid.' name='.$this->escapeText($name).' type='.$type);
2863
	}
2864
2865
/**
2866
  * serverGroupDelete
2867
  * 
2868
  * 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.
2869
  *
2870
  * @author     Par0noid Solutions
2871
  * @param		integer $sgid	serverGroupID
2872
  * @param		integer $force 	forces deleting group (Default: 1)
2873
  * @return     boolean success
2874
  */
2875
	function serverGroupDelete($sgid, $force = 1) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2876
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2877
		return $this->getData('boolean', 'servergroupdel sgid='.$sgid.' force='.$force);
2878
	}
2879
2880
/**
2881
  * serverGroupDeleteClient
2882
  * 
2883
  * Removes a client specified with cldbid from the server group specified with sgid.
2884
  *
2885
  * @author     Par0noid Solutions
2886
  * @param		integer $sgid	groupID
2887
  * @param		integer $cldbid	clientDBID
2888
  * @return     boolean success
2889
  */
2890
	function serverGroupDeleteClient($sgid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2891
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2892
		return $this->getData('boolean', 'servergroupdelclient sgid='.$sgid.' cldbid='.$cldbid);
2893
	}
2894
2895
/**
2896
  * serverGroupDeletePerm
2897
  * 
2898
  * 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.
2899
  *
2900
  * <b>Input-Array like this:</b>
2901
  * <pre>
2902
  * $permissions = array();
2903
  * $permissions[] = 'permissionID';
2904
  * //or you could use
2905
  * $permissions[] = 'permissionName';
2906
  * </pre>
2907
  *
2908
  * @author     Par0noid Solutions
2909
  * @param		integer		$sgid				serverGroupID
2910
  * @param		array		$permissionIds		permissionIds
2911
  * @return     boolean success
2912
  */
2913 View Code Duplication
	function serverGroupDeletePerm($sgid, $permissionIds) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2914
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2915
		$permissionArray = array();
2916
		
2917
		if(count($permissionIds) > 0) {
2918
			foreach($permissionIds AS $value) {
2919
				$permissionArray[] = is_numeric($value) ? 'permid='.$value : 'permsid='.$this->escapeText($value);
2920
			}
2921
			return $this->getData('boolean', 'servergroupdelperm sgid='.$sgid.' '.implode('|', $permissionArray));
2922
		}else{
2923
			$this->addDebugLog('no permissions given');
2924
			return $this->generateOutput(false, array('Error: no permissions given'), false);
2925
		}
2926
	}
2927
2928
/**
2929
  * serverGroupList
2930
  * 
2931
  * Displays a list of server groups available. Depending on your permissions, the output may also contain global ServerQuery groups and template groups.
2932
  *
2933
  * <b>Output:</b>
2934
  * <pre>
2935
  * Array
2936
  * {
2937
  *  [sgid] => 1
2938
  *  [name] => Guest Server Query
2939
  *  [type] => 2
2940
  *  [iconid] => 0
2941
  *  [savedb] => 0
2942
  * }
2943
  * </pre>
2944
  *
2945
  * @author     Par0noid Solutions
2946
  * @return     array serverGroupList
2947
  */
2948
	function serverGroupList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2949
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2950
		return $this->getData('multi', 'servergrouplist');
2951
	}
2952
2953
/**
2954
  * serverGroupPermList
2955
  * 
2956
  * 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.
2957
  *
2958
  * <b>Output:</b>
2959
  * <pre>
2960
  * Array
2961
  * {
2962
  *  [permid] => 12876 (if permsid = false)
2963
  *  [permsid] => b_client_info_view (if permsid = true)
2964
  *  [permvalue] => 1
2965
  *  [permnegated] => 0
2966
  *  [permskip] => 0
2967
  * }
2968
  * </pre>
2969
  *
2970
  * @author     Par0noid Solutions
2971
  * @param		integer	$sgid		serverGroupID
2972
  * @param		boolean	$permsid	set true to add -permsid param [optional]
2973
  * @return     array serverGroupPermList
2974
  */
2975
	function serverGroupPermList($sgid, $permsid = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2976
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2977
		if($permsid) { $additional = ' -permsid'; }else{ $additional = ''; }
2978
		return $this->getData('multi', 'servergrouppermlist sgid='.$sgid.$additional);
2979
	}
2980
2981
/**
2982
  * serverGroupRename
2983
  * 
2984
  * Changes the name of the server group specified with sgid.
2985
  *
2986
  * @author     Par0noid Solutions
2987
  * @param		integer $sgid	serverGroupID
2988
  * @param		integer $name	groupName
2989
  * @return     boolean success
2990
  */
2991
	function serverGroupRename($sgid, $name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
2992
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
2993
		return $this->getData('boolean', 'servergrouprename sgid='.$sgid.' name='.$this->escapeText($name));
2994
	}
2995
2996
/**
2997
  * serverGroupsByClientID
2998
  * 
2999
  * Displays all server groups the client specified with cldbid is currently residing in.
3000
  *
3001
  * <b>Output:</b>
3002
  * <pre>
3003
  * Array
3004
  * {
3005
  *  [name] => Guest
3006
  *  [sgid] => 73
3007
  *  [cldbid] => 2
3008
  * }
3009
  * </pre>
3010
  *
3011
  * @author     Par0noid Solutions
3012
  * @param		integer	$cldbid	clientDBID
3013
  * @return     array serverGroupsByClientId
3014
  */
3015
	function serverGroupsByClientID($cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3016
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3017
		return $this->getData('multi', 'servergroupsbyclientid cldbid='.$cldbid);
3018
	}
3019
3020
/**
3021
  * serverIdGetByPort
3022
  * 
3023
  * Displays the database ID of the virtual server running on the UDP port specified by virtualserver_port.
3024
  * 
3025
  * <b>Output:</b>
3026
  * <pre>
3027
  * Array
3028
  * {
3029
  *  [server_id] => 1
3030
  * }
3031
  * </pre>
3032
  *
3033
  * @author     Par0noid Solutions
3034
  * @param		integer $port	serverPort
3035
  * @return     array serverInfo
3036
  */
3037
	function serverIdGetByPort($port) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3038
		return $this->getData('array', 'serveridgetbyport virtualserver_port='.$port);
3039
	}
3040
3041
/**
3042
  * serverInfo
3043
  * 
3044
  * Displays detailed configuration information about the selected virtual server including unique ID, number of clients online, configuration, etc.
3045
  *	
3046
  * <b>Output:</b>
3047
  * <pre>
3048
  * Array
3049
  * {
3050
  *  [virtualserver_unique_identifier] => 2T3SRCPoWKojKlNMx6qxV7gOe8A=
3051
  *  [virtualserver_name] => TeamSpeak ]I[ Server
3052
  *  [virtualserver_welcomemessage] => Welcome to TeamSpeak
3053
  *  [virtualserver_platform] => Windows
3054
  *  [virtualserver_version] => 3.0.6.1 [Build: 1340956745]
3055
  *  [virtualserver_maxclients] => 32
3056
  *  [virtualserver_password] => 
3057
  *  [virtualserver_clientsonline] => 2
3058
  *  [virtualserver_channelsonline] => 2
3059
  *  [virtualserver_created] => 1361027787
3060
  *  [virtualserver_uptime] => 2804
3061
  *  [virtualserver_codec_encryption_mode] => 0
3062
  *  [virtualserver_hostmessage] => 
3063
  *  [virtualserver_hostmessage_mode] => 0
3064
  *  [virtualserver_filebase] => files\\virtualserver_1
3065
  *  [virtualserver_default_server_group] => 8
3066
  *  [virtualserver_default_channel_group] => 8
3067
  *  [virtualserver_flag_password] => 0
3068
  *  [virtualserver_default_channel_admin_group] => 5
3069
  *  [virtualserver_max_download_total_bandwidth] => 18446744073709551615
3070
  *  [virtualserver_max_upload_total_bandwidth] => 18446744073709551615
3071
  *  [virtualserver_hostbanner_url] => 
3072
  *  [virtualserver_hostbanner_gfx_url] => 
3073
  *  [virtualserver_hostbanner_gfx_interval] => 0
3074
  *  [virtualserver_complain_autoban_count] => 5
3075
  *  [virtualserver_complain_autoban_time] => 1200
3076
  *  [virtualserver_complain_remove_time] => 3600
3077
  *  [virtualserver_min_clients_in_channel_before_forced_silence] => 100
3078
  *  [virtualserver_priority_speaker_dimm_modificator] => -18.0000
3079
  *  [virtualserver_id] => 1
3080
  *  [virtualserver_antiflood_points_tick_reduce] => 5
3081
  *  [virtualserver_antiflood_points_needed_command_block] => 150
3082
  *  [virtualserver_antiflood_points_needed_ip_block] => 250
3083
  *  [virtualserver_client_connections] => 1
3084
  *  [virtualserver_query_client_connections] => 6
3085
  *  [virtualserver_hostbutton_tooltip] => 
3086
  *  [virtualserver_hostbutton_url] => 
3087
  *  [virtualserver_hostbutton_gfx_url] => 
3088
  *  [virtualserver_queryclientsonline] => 1
3089
  *  [virtualserver_download_quota] => 18446744073709551615
3090
  *  [virtualserver_upload_quota] => 18446744073709551615
3091
  *  [virtualserver_month_bytes_downloaded] => 0
3092
  *  [virtualserver_month_bytes_uploaded] => 0
3093
  *  [virtualserver_total_bytes_downloaded] => 0
3094
  *  [virtualserver_total_bytes_uploaded] => 0
3095
  *  [virtualserver_port] => 9987
3096
  *  [virtualserver_autostart] => 1
3097
  *  [virtualserver_machine_id] => 
3098
  *  [virtualserver_needed_identity_security_level] => 8
3099
  *  [virtualserver_log_client] => 0
3100
  *  [virtualserver_log_query] => 0
3101
  *  [virtualserver_log_channel] => 0
3102
  *  [virtualserver_log_permissions] => 1
3103
  *  [virtualserver_log_server] => 0
3104
  *  [virtualserver_log_filetransfer] => 0
3105
  *  [virtualserver_min_client_version] => 12369
3106
  *  [virtualserver_name_phonetic] => 
3107
  *  [virtualserver_icon_id] => 0
3108
  *  [virtualserver_reserved_slots] => 0
3109
  *  [virtualserver_total_packetloss_speech] => 0.0000
3110
  *  [virtualserver_total_packetloss_keepalive] => 0.0000
3111
  *  [virtualserver_total_packetloss_control] => 0.0000
3112
  *  [virtualserver_total_packetloss_total] => 0.0000
3113
  *  [virtualserver_total_ping] => 0.0000
3114
  *  [virtualserver_ip] => 
3115
  *  [virtualserver_weblist_enabled] => 1
3116
  *  [virtualserver_ask_for_privilegekey] => 0
3117
  *  [virtualserver_hostbanner_mode] => 0
3118
  *  [virtualserver_status] => online
3119
  *  [connection_filetransfer_bandwidth_sent] => 0
3120
  *  [connection_filetransfer_bandwidth_received] => 0
3121
  *  [connection_filetransfer_bytes_sent_total] => 0
3122
  *  [connection_filetransfer_bytes_received_total] => 0
3123
  *  [connection_packets_sent_speech] => 0
3124
  *  [connection_bytes_sent_speech] => 0
3125
  *  [connection_packets_received_speech] => 0
3126
  *  [connection_bytes_received_speech] => 0
3127
  *  [connection_packets_sent_keepalive] => 2055
3128
  *  [connection_bytes_sent_keepalive] => 84255
3129
  *  [connection_packets_received_keepalive] => 2055
3130
  *  [connection_bytes_received_keepalive] => 86309
3131
  *  [connection_packets_sent_control] => 90
3132
  *  [connection_bytes_sent_control] => 13343
3133
  *  [connection_packets_received_control] => 90
3134
  *  [connection_bytes_received_control] => 9176
3135
  *  [connection_packets_sent_total] => 2145
3136
  *  [connection_bytes_sent_total] => 97598
3137
  *  [connection_packets_received_total] => 2145
3138
  *  [connection_bytes_received_total] => 95485
3139
  *  [connection_bandwidth_sent_last_second_total] => 82
3140
  *  [connection_bandwidth_sent_last_minute_total] => 81
3141
  *  [connection_bandwidth_received_last_second_total] => 84
3142
  *  [connection_bandwidth_received_last_minute_total] => 87
3143
  * }
3144
  * </pre>
3145
  *
3146
  * @author     Par0noid Solutions
3147
  * @return     array serverInformation
3148
  */
3149
	function serverInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3150
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3151
		return $this->getData('array', 'serverinfo');
3152
	}
3153
3154
/**
3155
  * serverList
3156
  * 
3157
  * 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.
3158
  *
3159
  * <b>Possible params:</b> [-uid] [-short] [-all] [-onlyoffline]
3160
  *
3161
  * <b>Output:</b>
3162
  * <pre>
3163
  * Array
3164
  * {
3165
  *  [virtualserver_id] => 1 //displayed on -short
3166
  *  [virtualserver_port] => 9987 //displayed on -short
3167
  *  [virtualserver_status] => online //displayed on -short
3168
  *  [virtualserver_clientsonline] => 2
3169
  *  [virtualserver_queryclientsonline] => 1
3170
  *  [virtualserver_maxclients] => 32
3171
  *  [virtualserver_uptime] => 3045
3172
  *  [virtualserver_name] => TeamSpeak ]I[ Server
3173
  *  [virtualserver_autostart] => 1
3174
  *  [virtualserver_machine_id] =>
3175
  *  [-uid] => [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U= 
3176
  * }
3177
  * </pre>
3178
  *
3179
  * @author     Par0noid Solutions
3180
  * @param		string		$options		optional parameters
3181
  * @return     array serverList
3182
  */
3183
	function serverList($options = NULL) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3184
		return $this->getData('multi', 'serverlist'.(!empty($options) ? ' '.$options : ''));
3185
	}
3186
3187
/**
3188
  * serverProcessStop
3189
  * 
3190
  * Stops the entire TeamSpeak 3 Server instance by shutting down the process.
3191
  *
3192
  * @author     Par0noid Solutions
3193
  * @return     boolean success
3194
  */
3195
	function serverProcessStop() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3196
		return $this->getData('boolean', 'serverprocessstop');
3197
	}
3198
3199
/**
3200
  * serverRequestConnectionInfo
3201
  * 
3202
  * Displays detailed connection information about the selected virtual server including uptime, traffic information, etc.
3203
  *
3204
  * <b>Output:</b>
3205
  * <pre>
3206
  * Array
3207
  * {
3208
  *  [connection_filetransfer_bandwidth_sent] => 0
3209
  *  [connection_filetransfer_bandwidth_received] => 0
3210
  *  [connection_filetransfer_bytes_sent_total] => 0
3211
  *  [connection_filetransfer_bytes_received_total] => 0
3212
  *  [connection_packets_sent_total] => 3333
3213
  *  [connection_bytes_sent_total] => 149687
3214
  *  [connection_packets_received_total] => 3333
3215
  *  [connection_bytes_received_total] => 147653
3216
  *  [connection_bandwidth_sent_last_second_total] => 123
3217
  *  [connection_bandwidth_sent_last_minute_total] => 81
3218
  *  [connection_bandwidth_received_last_second_total] => 352
3219
  *  [connection_bandwidth_received_last_minute_total] => 87
3220
  *  [connection_connected_time] => 3387
3221
  *  [connection_packetloss_total] => 0.0000
3222
  *  [connection_ping] => 0.0000
3223
  * }
3224
  * </pre>
3225
  *
3226
  * @author     Par0noid Solutions
3227
  * @return     array serverRequestConnectionInfo
3228
  */
3229
	function serverRequestConnectionInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3230
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3231
		return $this->getData('array', 'serverrequestconnectioninfo');
3232
	}
3233
3234
/**
3235
  * serverSnapshotCreate
3236
  * 
3237
  * 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.
3238
  *
3239
  * @author     Par0noid Solutions
3240
  * @return     string snapshot
3241
  */
3242
	function serverSnapshotCreate() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3243
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3244
		return $this->getData('plain', 'serversnapshotcreate');
3245
	}
3246
3247
/**
3248
  * serverSnapshotDeploy
3249
  * 
3250
  * 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.
3251
  *
3252
  * @author     Par0noid Solutions
3253
  * @param		string	$snapshot	snapshot
3254
  * @return     boolean success
3255
  */
3256
	function serverSnapshotDeploy($snapshot) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3257
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3258
		return $this->getData('boolean', 'serversnapshotdeploy '.$snapshot);
3259
	}
3260
	
3261
/**
3262
  * serverStart
3263
  * 
3264
  * 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.
3265
  *
3266
  * @author     Par0noid Solutions
3267
  * @param		integer $sid	serverID
3268
  * @return     boolean success
3269
  */
3270
	function serverStart($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3271
		return $this->getdata('boolean', 'serverstart sid='.$sid);
3272
	}	
3273
3274
/**
3275
  * serverStop
3276
  * 
3277
  * 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.
3278
  *
3279
  * @author     Par0noid Solutions
3280
  * @param		integer $sid	serverID
3281
  * @return     boolean success
3282
  */
3283
	function serverStop($sid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3284
		return $this->getdata('boolean', 'serverstop sid='.$sid);
3285
	}
3286
3287
/**
3288
  * serverTemppasswordAdd
3289
  * 
3290
  * 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.
3291
  *
3292
  * @author     Par0noid Solutions
3293
  * @param		string	$pw				temporary password
3294
  * @param		string	$duration		durations in seconds
3295
  * @param		string	$desc			description [optional]
3296
  * @param		string	$tcid			cid user enters on connect (0 = Default channel) [optional]
3297
  * @param		string	$tcpw			channelPW
3298
  * @return     boolean success
3299
  */
3300
	function serverTempPasswordAdd($pw, $duration, $desc = 'none', $tcid = 0, $tcpw = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3301
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3302
		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) : ''));
3303
	}
3304
3305
/**
3306
  * serverTemppasswordDel
3307
  * 
3308
  * Deletes the temporary server password specified with pw.
3309
  * 
3310
  * @author     Par0noid Solutions
3311
  * @param		string	$pw		temporary password
3312
  * @return     boolean success
3313
  */	
3314
	function serverTempPasswordDel($pw) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3315
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3316
		return $this->getdata('boolean', 'servertemppassworddel pw='.$this->escapeText($pw));
3317
	}
3318
3319
/**
3320
  * serverTemppasswordList
3321
  * 
3322
  * Returns a list of active temporary server passwords. The output contains the clear-text password, the nickname and unique identifier of the creating client.
3323
  *
3324
  * <b>Output:</b>
3325
  * <pre>
3326
  * Array
3327
  * {
3328
  *  [nickname] => serveradmin
3329
  *  [uid] => 1
3330
  *  [desc] => none
3331
  *  [pw_clear] => test
3332
  *  [start] => 1334996838
3333
  *  [end] => 1335000438
3334
  *  [tcid] => 0
3335
  * }
3336
  * </pre>
3337
  *
3338
  * @author     Par0noid Solutions
3339
  * @return     array	serverTemppasswordList
3340
  */
3341
	function serverTempPasswordList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3342
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3343
		return $this->getData('multi', 'servertemppasswordlist');
3344
	}
3345
	
3346
3347
/**
3348
  *	setClientChannelGroup
3349
  *
3350
  * Sets the channel group of a client to the ID specified with cgid.
3351
  *
3352
  * @author     Par0noid Solutions
3353
  * @param		integer $cgid	groupID
3354
  * @param		integer $cid	channelID
3355
  * @param		integer $cldbid	clientDBID
3356
  * @return     boolean success
3357
  */
3358
	function setClientChannelGroup($cgid, $cid, $cldbid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3359
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3360
		return $this->getData('boolean', 'setclientchannelgroup cgid='.$cgid.' cid='.$cid.' cldbid='.$cldbid);
3361
	}
3362
3363
/**
3364
  * setName
3365
  * 
3366
  * Sets your nickname in server query
3367
  *
3368
  * @author     Par0noid Solutions
3369
  * @param		string	$newName	new name in server query
3370
  * @return     boolean success
3371
  */
3372
	function setName($newName) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3373
		return $this->getData('boolean', 'clientupdate client_nickname='.$this->escapeText($newName));
3374
	}
3375
3376
/**
3377
  * tokenAdd
3378
  * 
3379
  * 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:
3380
  * ident=ident1 value=value1|ident=ident2 value=value2|ident=ident3 value=value3
3381
  *
3382
  * <b>Input-Array like this:</b>
3383
  * <pre>
3384
  * $customFieldSet = array();
3385
  *	
3386
  * $customFieldSet['ident'] = 'value';
3387
  * $customFieldSet['ident'] = 'value';
3388
  * </pre>
3389
  *
3390
  * @author     Par0noid Solutions
3391
  * @param		integer	$tokentype				token type
3392
  * @param		integer	$tokenid1				groupID
3393
  * @param		integer	$tokenid2				channelID
3394
  * @param		string	$description			token description [optional]
3395
  * @param		array	$customFieldSet			customFieldSet [optional]
3396
  * @return     array	tokenInformation
3397
  */
3398
	function tokenAdd($tokentype, $tokenid1, $tokenid2, $description ='', $customFieldSet = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3399
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3400
		
3401
		if(!empty($description)) { $description = ' tokendescription=' . $this->escapeText($description); }
3402
3403
		if(count($customFieldSet)) {
3404
			$settingsString = array();
3405
		
3406
			foreach($customFieldSet as $key => $value) {
3407
				$settingsString[] = 'ident='.$this->escapeText($key).'\svalue='.$this->escapeText($value);
3408
			}
3409
			
3410
			$customFieldSet = ' tokencustomset='.implode('|', $settingsString);
3411
		}else{
3412
			$customFieldSet = '';
3413
		}
3414
		
3415
		return $this->getData('array', 'privilegekeyadd tokentype='.$tokentype.' tokenid1='.$tokenid1.' tokenid2='.$tokenid2.$description.$customFieldSet);
3416
	}
3417
3418
/**
3419
  * tokenDelete
3420
  * 
3421
  * Deletes an existing token matching the token key specified with token.
3422
  *
3423
  * @author     Par0noid Solutions
3424
  * @param		string	$token	token
3425
  * @return     boolean success
3426
  */
3427
	function tokenDelete($token) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3428
		if(!$this->runtime['selected']) { return $this->checkSelected(); }			
3429
		return $this->getData('boolean', 'privilegekeydelete token='.$token);
3430
	}
3431
3432
/**
3433
  * tokenList
3434
  * 
3435
  * 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.
3436
  *
3437
  * <b>Output:</b>
3438
  * <pre>
3439
  * Array
3440
  * {
3441
  *  [token] => GdqedxSEDle3e9+LtR3o9dO09bURH+vymvF5hOJg
3442
  *  [token_type] => 0
3443
  *  [token_id1] => 71
3444
  *  [token_id2] => 0
3445
  *  [token_created] => 1286625908
3446
  *  [token_description] => for you
3447
  * }
3448
  * </pre>
3449
  *
3450
  * @author     Par0noid Solutions
3451
  * @return     array tokenListist 
3452
  */
3453
	function tokenList() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3454
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
3455
3456
		return $this->getData('multi', 'privilegekeylist');
3457
	}
3458
3459
/**
3460
  * tokenUse
3461
  * 
3462
  * 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.
3463
  *
3464
  * @author     Par0noid Solutions
3465
  * @param		string	$token	token
3466
  * @return     boolean success
3467
  */
3468
	function tokenUse($token) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3469
		if(!$this->runtime['selected']) { return $this->checkSelected(); }			
3470
		return $this->getData('boolean', 'privilegekeyuse token='.$token);
3471
	}
3472
3473
/**
3474
  * version
3475
  * 
3476
  * Displays the servers version information including platform and build number.
3477
  *
3478
  * <b>Output:</b>
3479
  * <pre>
3480
  * Array
3481
  * {
3482
  *  [version] => 3.0.6.1
3483
  *  [build] => 1340956745
3484
  *  [platform] => Windows
3485
  * }
3486
  * </pre>
3487
  *
3488
  * @author     Par0noid Solutions
3489
  * @return     array versionInformation
3490
  */
3491
	function version() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3492
		return $this->getData('array', 'version');
3493
	}
3494
3495
/**
3496
  * whoAmI
3497
  * 
3498
  * Displays information about your current ServerQuery connection including your loginname, etc.
3499
  *
3500
  * <b>Output:</b>
3501
  * <pre>
3502
  * Array
3503
  * {
3504
  *  [virtualserver_status] => online
3505
  *  [virtualserver_id] => 1
3506
  *  [virtualserver_unique_identifier] => bYrybKl/APfKq7xzpIJ1Xb6C06U=
3507
  *  [virtualserver_port] => 9987
3508
  *  [client_id] => 5
3509
  *  [client_channel_id] => 1
3510
  *  [client_nickname] => serveradmin from 127.0.0.1:15208
3511
  *  [client_database_id] => 1
3512
  *  [client_login_name] => serveradmin
3513
  *  [client_unique_identifier] => serveradmin
3514
  *  [client_origin_server_id] => 0
3515
  * }
3516
  * </pre>
3517
  *
3518
  * @author     Par0noid Solutions
3519
  * @return     array clientinformation
3520
  */
3521
	function whoAmI() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3522
		return $this->getData('array', 'whoami');
3523
	}
3524
3525
//*******************************************************************************************	
3526
//************************************ Helper Functions ************************************
3527
//*******************************************************************************************
3528
3529
/**
3530
  * checkSelected throws out 2 errors
3531
  *
3532
  * <b>Output:</b>
3533
  * <pre>
3534
  * Array
3535
  * {
3536
  *  [success] => false
3537
  *  [errors] => Array 
3538
  *  [data] => false
3539
  * }
3540
  * </pre>
3541
  *
3542
  * @author     Par0noid Solutions
3543
  * @return     array error
3544
  */
3545
	private function checkSelected() {
3546
		$backtrace = debug_backtrace();
3547
		$this->addDebugLog('you can\'t use this function if no server is selected', $backtrace[1]['function'], $backtrace[0]['line']);
3548
		return $this->generateOutput(false, array('you can\'t use this function if no server is selected'), false);
3549
	}
3550
3551
/**
3552
  * convertSecondsToStrTime
3553
  * 
3554
  * Converts seconds to a strTime (bsp. 5d 1h 23m 19s)
3555
  *
3556
  * @author     Par0noid Solutions
3557
  * @param		integer	$seconds	time in seconds
3558
  * @return     string strTime
3559
  */
3560
 	public function convertSecondsToStrTime($seconds) {
3561
		$conv_time = $this->convertSecondsToArrayTime($seconds);
3562
    	return $conv_time['days'].'d '.$conv_time['hours'].'h '.$conv_time['minutes'].'m '.$conv_time['seconds'].'s';
3563
	}
3564
3565
/**
3566
  * convertSecondsToArrayTime
3567
  * 
3568
  * Converts seconds to a array: time
3569
  *
3570
  * <b>Output:</b>
3571
  * <pre>
3572
  * Array
3573
  * {
3574
  *  [days] => 3
3575
  *  [hours] => 9
3576
  *  [minutes] => 45
3577
  *  [seconds] => 17
3578
  * }
3579
  * </pre>
3580
  *
3581
  * @author     Par0noid Solutions
3582
  * @param		integer	$seconds	time in seconds
3583
  * @return     array time
3584
  */
3585
 	public function convertSecondsToArrayTime($seconds) {
3586
		$conv_time = array();
3587
		$conv_time['days']=floor($seconds / 86400);
3588
		$conv_time['hours']=floor(($seconds - ($conv_time['days'] * 86400)) / 3600);
3589
		$conv_time['minutes']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600))) / 60);
3590
		$conv_time['seconds']=floor(($seconds - (($conv_time['days'] * 86400)+($conv_time['hours']*3600)+($conv_time['minutes'] * 60))));
3591
		return $conv_time;
3592
	}
3593
3594
/**
3595
  * getElement
3596
  * 
3597
  * Returns the given associated element from an array
3598
  * This can be used to get a result in a one line operation
3599
  * 
3600
  * For example you got this array:
3601
  * <pre>
3602
  * Array
3603
  * {
3604
  *  [success] => false
3605
  *  [errors] => Array 
3606
  *  [data] => false
3607
  * }
3608
  * </pre>
3609
  * Now you can grab the element like this:
3610
  * <pre>
3611
  * $ts = new ts3admin('***', '***');
3612
  * 
3613
  * if($ts->getElement('success', $ts->connect())) {
3614
  *  //operation
3615
  * }
3616
  * </pre>
3617
  *
3618
  * @author     Par0noid Solutions
3619
  * @param		string	$element	key of element
3620
  * @param		array	$array		array
3621
  * @return     mixed
3622
  */
3623
	public function getElement($element, $array) {
3624
		return $array[$element];
3625
	}
3626
3627
/**
3628
  * succeeded
3629
  * 
3630
  * Succeeded will check the success element of a return array
3631
  * <pre>
3632
  * $ts = new ts3admin('***', '***');
3633
  * 
3634
  * if($ts->succeeded($ts->connect())) {
3635
  *  //operation
3636
  * }
3637
  * </pre>
3638
  *
3639
  * @author     Par0noid Solutions
3640
  * @param		array	$array	result
3641
  * @return     boolean
3642
  */
3643
	public function succeeded($array) {
3644
		if(isset($array['success'])) {
3645
			return $array['success'];
3646
		}else{
3647
			return false;
3648
		}
3649
	}
3650
	
3651
	
3652
3653
//*******************************************************************************************	
3654
//*********************************** Internal Functions ************************************
3655
//*******************************************************************************************
3656
3657
/**
3658
 * __construct
3659
 * 
3660
 * @author	Par0noid Solutions
3661
 * @param	string	$host		ts3host
3662
 * @param	integer	$queryport	ts3queryport
3663
 * @param	integer	$timeout	socket timeout (default = 2) [optional]
3664
 * @return	void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
3665
*/
3666
	function __construct($host, $queryport, $timeout = 2) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3667
		if($queryport >= 1 and $queryport <= 65536) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
3668
			if($timeout >= 1) {
3669
				$this->runtime['host'] = $host;
3670
				$this->runtime['queryport'] = $queryport;
3671
				$this->runtime['timeout'] = $timeout;
3672
			}else{
3673
				$this->addDebugLog('invalid timeout value');
3674
			}
3675
		}else{
3676
			$this->addDebugLog('invalid queryport');
3677
		}
3678
	}
3679
3680
/**
3681
 * __destruct
3682
 * 
3683
 * @author	Par0noid Solutions
3684
 * @return	void
3685
*/
3686
	function __destruct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3687
		$this->quit();
3688
	}
3689
3690
/**
3691
 * __call
3692
 * 
3693
 * prevents your website from php errors if you want to execute a method which doesn't exists
3694
 * 
3695
 * @author	Par0noid Solutions
3696
 * @param	string	$name	method name
3697
 * @param	array	$args	method arguments
3698
 * @return	void
3699
*/
3700
	function __call($name, $args) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3701
		$this->addDebugLog('Method '.$name.' doesn\'t exist', $name, 0);
3702
		return $this->generateOutput(false, array('Method '.$name.' doesn\'t exist'), false);
3703
	}
3704
3705
/**
3706
  * isConnected
3707
  * 
3708
  * Checks if the connection is established
3709
  *
3710
  * @author     Par0noid Solutions
3711
  * @return     boolean connected
3712
  */
3713
	private function isConnected() {
3714
		if(empty($this->runtime['socket'])) {
3715
			return false;
3716
		}else{
3717
			return true;
3718
		}
3719
	}
3720
3721
/**
3722
  * generateOutput
3723
  * 
3724
  * Builds a method return as array
3725
  *
3726
  * @author     Par0noid Solutions
3727
  * @param		boolean		$success	true/false
3728
  * @param		array		$errors		all errors which occured while executing a method
3729
  * @param		mixed		$data		parsed data from server
3730
  * @return     array output
3731
  */
3732
	private function generateOutput($success, $errors, $data) {
3733
		return array('success' => $success, 'errors' => $errors, 'data' => $data);
3734
	}
3735
3736
/**
3737
  * unEscapeText
3738
  * 
3739
  * Turns escaped chars to normals
3740
  *
3741
  * @author     Par0noid Solutions
3742
  * @param		string	$text	text which should be escaped
3743
  * @return     string	text
3744
  */
3745
 	private function unEscapeText($text) {
3746
 		$escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/");
3747
 		$unEscapedChars = array('', '', '', '', '', ' ', '|', '/');
3748
		$text = str_replace($escapedChars, $unEscapedChars, $text);
3749
		return $text;
3750
	}
3751
3752
/**
3753
  * escapeText
3754
  * 
3755
  * Escapes chars that we can use it in the query
3756
  *
3757
  * @author     Par0noid Solutions
3758
  * @param		string	$text	text which should be escaped
3759
  * @return     string	text
3760
  */
3761
 	private function escapeText($text) {
3762
 		$text = str_replace("\t", '\t', $text);
3763
		$text = str_replace("\v", '\v', $text);
3764
		$text = str_replace("\r", '\r', $text);
3765
		$text = str_replace("\n", '\n', $text);
3766
		$text = str_replace("\f", '\f', $text);
3767
		$text = str_replace(' ', '\s', $text);
3768
		$text = str_replace('|', '\p', $text);
3769
		$text = str_replace('/', '\/', $text);
3770
		return $text;
3771
	}
3772
3773
/**
3774
  * splitBanIds
3775
  * 
3776
  * Splits banIds to array
3777
  *
3778
  * @author     Par0noid Solutions
3779
  * @param		string	$text	plain text server response
3780
  * @return     string	text
3781
  */
3782
 	private function splitBanIds($text) {
3783
		$data = array();
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3784
		$text = str_replace(array("\n", "\r"), '', $text);
3785
		$ids = explode("banid=", $text);
3786
		unset($ids[0]);
3787
		return $ids;
3788
	}
3789
3790
//*******************************************************************************************	
3791
//************************************ Network Functions ************************************
3792
//*******************************************************************************************
3793
3794
/**
3795
  * connect
3796
  * 
3797
  * Connects to a ts3instance query port
3798
  *
3799
  * @author     Par0noid Solutions
3800
  * @return		boolean success
3801
  */
3802
	function connect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
3803
		if($this->isConnected()) { 
3804
			$this->addDebugLog('Error: you are already connected!');
3805
			return $this->generateOutput(false, array('Error: the script is already connected!'), false);
3806
		}
3807
		$socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']);
3808
3809
		if(!$socket) {
3810
			$this->addDebugLog('Error: connection failed!');
3811
			return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);
3812
		}else{
3813
			if(strpos(fgets($socket), 'TS3') !== false) {
3814
				$tmpVar = fgets($socket);
0 ignored issues
show
Unused Code introduced by
$tmpVar is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3815
				$this->runtime['socket'] = $socket;
3816
				return $this->generateOutput(true, array(), true);
3817
			}else{
3818
				$this->addDebugLog('host isn\'t a ts3 instance!');
3819
				return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);
3820
			}
3821
		}
3822
	}
3823
3824
/**
3825
  * executeCommand
3826
  * 
3827
  * Executes a command and fetches the response
3828
  *
3829
  * @author     Par0noid Solutions
3830
  * @param		string	$command	command which should be executed
3831
  * @param		array	$tracert	array with information from first exec
3832
  * @return     mixed data
3833
  */
3834
	private function executeCommand($command, $tracert) {
3835
		if(!$this->isConnected()) {
3836
			$this->addDebugLog('script isn\'t connected to server', $tracert[1]['function'], $tracert[0]['line']);
3837
			return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);
3838
		}
3839
		
3840
		$data = '';
3841
3842
		
3843
		$splittedCommand = str_split($command, 1024);
3844
		
3845
		$splittedCommand[(count($splittedCommand) - 1)] .= "\n";
3846
		
3847
		foreach($splittedCommand as $commandPart) {
3848
			fputs($this->runtime['socket'], $commandPart);
3849
		}
3850
3851
		do {
3852
			$data .= fgets($this->runtime['socket'], 4096);
3853
			
3854
			if(strpos($data, 'error id=3329 msg=connection') !== false) {
3855
				$this->runtime['socket'] = '';
3856
				$this->addDebugLog('You got banned from server. Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
3857
				return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
3858
			}
3859
			
3860
		} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
3861
3862
		if(strpos($data, 'error id=0 msg=ok') === false) {
3863
			$splittedResponse = explode('error id=', $data);
3864
			$chooseEnd = count($splittedResponse) - 1;
3865
			
3866
			$cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);
3867
			
3868
			$this->addDebugLog('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1]), $tracert[1]['function'], $tracert[0]['line']);
3869
			
3870
			return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);
3871
		}else{
3872
			return $this->generateOutput(true, array(), $data);
3873
		}
3874
	}
3875
3876
/**
3877
 * getData
3878
 * 
3879
 * Parses data from query and returns an array
3880
 * 
3881
 * @author		Par0noid Solutions
3882
 * @access		private
3883
 * @param		string	$mode		select return mode ('boolean', 'array', 'multi', 'plain')
3884
 * @param		string	$command	command which should be executed
3885
 * @return		mixed data
3886
 */
3887
	private function getData($mode, $command) {
3888
	
3889
		$validModes = array('boolean', 'array', 'multi', 'plain');
3890
	
3891
		if(!in_array($mode, $validModes)) {
3892
			$this->addDebugLog($mode.' is an invalid mode');
3893
			return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);
3894
		}
3895
		
3896 View Code Duplication
		if(empty($command)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3897
			$this->addDebugLog('you have to enter a command');
3898
			return $this->generateOutput(false, array('Error: you have to enter a command'), false);
3899
		}
3900
		
3901
		$fetchData = $this->executeCommand($command, debug_backtrace());
3902
		
3903
		
3904
		$fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);
3905
		
3906
		
3907
		if($fetchData['success']) {
3908
			if($mode == 'boolean') {
3909
				return $this->generateOutput(true, array(), true);
3910
			}
3911
			
3912
			if($mode == 'array') {
3913
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
3914
				$datasets = explode(' ', $fetchData['data']);
3915
				
3916
				$output = array();
3917
				
3918 View Code Duplication
				foreach($datasets as $dataset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3919
					$dataset = explode('=', $dataset);
3920
					
3921
					if(count($dataset) > 2) {
3922
						for($i = 2; $i < count($dataset); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
3923
							$dataset[1] .= '='.$dataset[$i];
3924
						}
3925
						$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
3926
					}else{
3927
						if(count($dataset) == 1) {
3928
							$output[$this->unEscapeText($dataset[0])] = '';
3929
						}else{
3930
							$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
3931
						}
3932
						
3933
					}
3934
				}
3935
				return $this->generateOutput(true, array(), $output);
3936
			}
3937
			if($mode == 'multi') {
3938
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
3939
				$datasets = explode('|', $fetchData['data']);
3940
				
3941
				$output = array();
3942
				
3943
				foreach($datasets as $datablock) {
3944
					$datablock = explode(' ', $datablock);
3945
					
3946
					$tmpArray = array();
3947
					
3948 View Code Duplication
					foreach($datablock as $dataset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3949
						$dataset = explode('=', $dataset);
3950
						if(count($dataset) > 2) {
3951
							for($i = 2; $i < count($dataset); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
3952
								$dataset[1] .= '='.$dataset[$i];
3953
							}
3954
							$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
3955
						}else{
3956
							if(count($dataset) == 1) {
3957
								$tmpArray[$this->unEscapeText($dataset[0])] = '';
3958
							}else{
3959
								$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
3960
							}
3961
						}					
3962
					}
3963
					$output[] = $tmpArray;
3964
				}
3965
				return $this->generateOutput(true, array(), $output);
3966
			}
3967
			if($mode == 'plain') {
3968
				return $fetchData;
3969
			}
3970
		}else{
3971
			return $this->generateOutput(false, $fetchData['errors'], false);
3972
		}
3973
	}
3974
3975
/**
3976
  * ftSendKey
3977
  * 
3978
  * Sends down/upload-key to ftHost
3979
  * 
3980
  * @author     Par0noid Solutions
3981
  * @param		string	$key
3982
  * @param		string $additional
3983
  * @return     none
3984
 */
3985
	private function ftSendKey($key, $additional = NULL) {
3986
		fputs($this->runtime['fileSocket'], $key.$additional);
3987
	}
3988
3989
/**
3990
  * ftSendData
3991
  * 
3992
  * Sends data to ftHost
3993
  * 
3994
  * @author     Par0noid Solutions
3995
  * @param		mixed	$data
3996
  * @return     none
3997
 */
3998
	private function ftSendData($data) {
3999
		$data = str_split($data, 4096);
4000
		foreach($data as $dat) {
4001
			fputs($this->runtime['fileSocket'], $dat);
4002
		}
4003
	}
4004
4005
/**
4006
  * ftRead
4007
  * 
4008
  * Reads data from ftHost
4009
  * 
4010
  * @author     Par0noid Solutions
4011
  * @param		int	$size
4012
  * @return     string data
4013
 */
4014
	private function ftRead($size) {
4015
		$data = '';
4016
		while(strlen($data) < $size) {		
4017
			$data .= fgets($this->runtime['fileSocket'], 4096);
4018
		}
4019
		return $data;
4020
	}
4021
4022
//*******************************************************************************************	
4023
//************************************* Debug Functions *************************************
4024
//*******************************************************************************************
4025
4026
/**
4027
  * getDebugLog
4028
  * 
4029
  * Returns the debug log
4030
  *
4031
  * <b>Output:</b>
4032
  * <pre>
4033
  * Array
4034
  * {
4035
  *  [0] => Error in login() on line 1908: ErrorID: 520 | Message: invalid loginname or password
4036
  *  [1] => Error in selectServer() on line 2044: ErrorID: 1540 | Message: convert error
4037
  * }
4038
  * </pre>
4039
  *
4040
  * @author     Par0noid Solutions
4041
  * @return     array debugLog
4042
  */
4043
 	public function getDebugLog() {
4044
		return $this->runtime['debug'];
4045
	}
4046
4047
/**
4048
  * addDebugLog
4049
  * 
4050
  * Adds an entry to debugLog
4051
  *
4052
  * @author     Par0noid Solutions
4053
  * @param		string	$text			text which should added to debugLog
4054
  * @param		string	$methodName		name of the executed method [optional]
4055
  * @param		string	$line			line where error triggered [optional]
4056
  * @return     array debugLog
4057
  */
4058
	private function addDebugLog($text, $methodName = '', $line = '') {
4059
		if(empty($methodName) and empty($line)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
4060
			$backtrace = debug_backtrace();
4061
			$methodName = $backtrace[1]['function'];
4062
			$line = $backtrace[0]['line'];
4063
		}
4064
		$this->runtime['debug'][] = 'Error in '.$methodName.'() on line '.$line.': '.$text;	
4065
	}
4066
}
4067
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...