xmlapi::xmlapi_query()   F
last analyzed

Complexity

Conditions 30
Paths 8743

Size

Total Lines 127

Duplication

Lines 10
Ratio 7.87 %

Importance

Changes 0
Metric Value
cc 30
nc 8743
nop 2
dl 10
loc 127
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
* cPanel XMLAPI Client Class
4
*
5
* This class allows for easy interaction with cPanel's XML-API allow functions within the XML-API to be called
6
* by calling funcions within this class
7
*
8
* LICENSE:
9
*
10
* Copyright (c) 2012, cPanel, Inc.
11
* All rights reserved.
12
*
13
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
14
* that the following conditions are met:
15
*
16
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
17
*   following disclaimer.
18
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
19
*   following disclaimer in the documentation and/or other materials provided with the distribution.
20
* * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
21
*   products derived from this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*
32
* Version: 1.0.13
33
* Last updated: 19 November 2012
34
*
35
* Changes
36
*
37
* 1.0.13:
38
* Tidy
39
*
40
* 1.0.12:
41
* github#2 - [Bugfix]: typo related to environment variable XMLAPI_USE_SSL
42
*
43
* 1.0.11:
44
* [Feature]: Remove value requirement for park()'s 'topdomain' argument
45
*  (Case 51116)
46
*
47
* 1.0.10:
48
* github#1 - [Bugfix]: setresellerpackagelimits() does not properly prepare
49
*  input arguments for query (Case 51076)
50
*
51
* 1.0.9:
52
* added input argument to servicestatus method which allows single service
53
*  filtering (Case 50804)
54
*
55
* 1.0.8:
56
* correct unpark bug as reported by Randall Kent
57
*
58
* 1.0.7:
59
* Corrected typo for setrellerlimits where xml_query incorrectly called xml-api's setresellerips
60
*
61
* 1.0.6:
62
* Changed 'user' URL parameter for API1/2 calls to 'cpanel_xmlapi_user'/'cpanel_jsonapi_user' to resolve conflicts with API2 functions that use 'user' as a parameter
63
* Relocated exmaple script to Example subdirectory
64
* Modified example scripts to take remote server IP and root password from environment variables REMOTE_HOST and REMOTE_PASSWORD, respectively
65
* Created subdirectory Tests for PHPUnit tests
66
* Add PHPUnit test BasicParseTest.php
67
*
68
* 1.0.5:
69
* fix bug where api1_query and api2_query would not return JSON data
70
*
71
* 1.0.4:
72
* set_port will now convert non-int values to ints
73
*
74
* 1.0.3:
75
* Fixed issue with set_auth_type using incorrect logic for determining acceptable auth types
76
* Suppress non-UTF8 encoding when using curl
77
*
78
* 1.0.2:
79
* Increased curl buffer size to 128kb from 16kb
80
* Fix double encoding issue in terminateresellers()
81
*
82
* 1.0.1:
83
* Fixed use of wrong variable name in curl error checking
84
* adjust park() to use api2 rather than API1
85
*
86
* 1.0
87
* Added in 11.25 functions
88
* Changed the constructor to allow for either the "DEFINE" config setting method or using parameters
89
* Removed used of the gui setting
90
* Added fopen support
91
* Added auto detection for fopen or curl (uses curl by default)
92
* Added ability to return in multiple formats: associative array, simplexml, xml, json
93
* Added PHP Documentor documentation for all necessary functions
94
* Changed submission from GET to POST
95
*
96
*
97
* @copyright 2012 cPanel, Inc
98
* @license http://sdk.cpanel.net/license/bsd.html
99
* @version 1.0.13
100
* @link http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/XmlApi
101
* @since File available since release 0.1
102
**/
103
104
/**
105
* The base XML-API class
106
*
107
* The XML-API class allows for easy execution of cPanel XML-API calls.  The goal of this project is to create
108
* an open source library that can be used for multiple types of applications.  This class relies on PHP5 compiled
109
* with both curl and simplexml support.
110
*
111
* Making Calls with this class are done in the following steps:
112
*
113
* 1.) Instaniating the class:
114
* $xmlapi = new xmlapi($host);
115
*
116
* 2.) Setting access credentials within the class via either set_password or set_hash:
117
* $xmlapi->set_hash("username", $accessHash);
118
* $xmlapi->set_password("username", "password");
119
*
120
* 3.) Execute a function
121
* $xmlapi->listaccts();
122
*
123
* @category Cpanel
124
* @package xmlapi
125
* @copyright 2012 cPanel, Inc.
126
* @license http://sdk.cpanel.net/license/bsd.html
127
* @version Release: 1.0.13
128
* @link http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/XmlApi
129
* @since Class available since release 0.1
130
**/
131
132
class xmlapi
133
{
134
    // should debugging statements be printed?
135
    private $debug			= false;
136
137
    // The host to connect to
138
    private $host				=	'127.0.0.1';
139
140
    // the port to connect to
141
    private $port				=	'2087';
142
143
    // should be the literal strings http or https
144
    private $protocol		=	'https';
145
146
    // output that should be given by the xml-api
147
    private $output		=	'simplexml';
148
149
    // literal strings hash or password
150
    private $auth_type 	= null;
151
152
    //  the actual password or hash
153
    private $auth 			= null;
154
155
    // username to authenticate as
156
    private $user				= null;
157
158
    // The HTTP Client to use
159
160
    private $http_client		= 'curl';
161
162
    /**
163
    * Instantiate the XML-API Object
164
    * All parameters to this function are optional and can be set via the accessor functions or constants
165
    * This defaults to password auth, however set_hash can be used to use hash authentication
166
    *
167
    * @param string $host The host to perform queries on
168
    * @param string $user The username to authenticate as
169
    * @param string $password The password to authenticate with
170
    * @return Xml_Api object
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...
171
    */
172
    public function __construct($host = null, $user = null, $password = null )
173
    {
174
        // Check if debugging must be enabled
175
        if ( (defined('XMLAPI_DEBUG')) && (XMLAPI_DEBUG == '1') ) {
176
             $this->debug = true;
177
        }
178
179
        // Check if raw xml output must be enabled
180
        if ( (defined('XMLAPI_RAW_XML')) && (XMLAPI_RAW_XML == '1') ) {
181
             $this->raw_xml = true;
0 ignored issues
show
Bug introduced by
The property raw_xml does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
182
        }
183
184
        /**
185
        * Authentication
186
        * This can either be passed at this point or by using the set_hash or set_password functions
187
        **/
188
189
        if ( ( defined('XMLAPI_USER') ) && ( strlen(XMLAPI_USER) > 0 ) ) {
190
            $this->user = XMLAPI_USER;
191
192
            // set the authtype to pass and place the password in $this->pass
193
            if ( ( defined('XMLAPI_PASS') ) && ( strlen(XMLAPI_PASS) > 0 ) ) {
194
                $this->auth_type = 'pass';
195
                $this->auth = XMLAPI_PASS;
196
            }
197
198
            // set the authtype to hash and place the hash in $this->auth
199
            if ( ( defined('XMLAPI_HASH') ) && ( strlen(XMLAPI_HASH) > 0 ) ) {
200
                $this->auth_type = 'hash';
201
                $this->auth = preg_replace("/(\n|\r|\s)/", '', XMLAPI_HASH);
202
            }
203
204
            // Throw warning if XMLAPI_HASH and XMLAPI_PASS are defined
205
            if ( ( ( defined('XMLAPI_HASH') ) && ( strlen(XMLAPI_HASH) > 0 ) )
206
                && ( ( defined('XMLAPI_PASS') ) && ( strlen(XMLAPI_PASS) > 0 ) ) ) {
207
                error_log('warning: both XMLAPI_HASH and XMLAPI_PASS are defined, defaulting to XMLAPI_HASH');
208
            }
209
210
211
            // Throw a warning if XMLAPI_HASH and XMLAPI_PASS are undefined and XMLAPI_USER is defined
212
            if ( !(defined('XMLAPI_HASH') ) || !defined('XMLAPI_PASS') ) {
213
                error_log('warning: XMLAPI_USER set but neither XMLAPI_HASH or XMLAPI_PASS have not been defined');
214
            }
215
216
        }
217
218
        if ( ( $user != null ) && ( strlen( $user ) < 9 ) ) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
219
            $this->user = $user;
220
        }
221
222
        if ($password != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $password of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
223
            $this->set_password($password);
224
        }
225
226
        /**
227
        * Connection
228
        *
229
        * $host/XMLAPI_HOST should always be equal to either the IP of the server or it's hostname
230
        */
231
232
        // Set the host, error if not defined
233
        if ($host == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $host of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
234
            if ( (defined('XMLAPI_HOST')) && (strlen(XMLAPI_HOST) > 0) ) {
235
                $this->host = XMLAPI_HOST;
236
            } else {
237
                throw new Exception("No host defined");
238
            }
239
        } else {
240
            $this->host = $host;
241
        }
242
243
        // disabling SSL is probably a bad idea.. just saying.
244
        if ( defined('XMLAPI_USE_SSL' ) && (XMLAPI_USE_SSL == '0' ) ) {
245
            $this->protocol = "http";
246
        }
247
248
        // Detemine what the default http client should be.
249
        if ( function_exists('curl_setopt') ) {
250
            $this->http_client = "curl";
251
        } elseif ( ini_get('allow_url_fopen') ) {
252
            $this->http_client = "fopen";
253
        } else {
254
            throw new Exception('allow_url_fopen and curl are neither available in this PHP configuration');
255
        }
256
257
    }
258
259
    /**
260
    * Accessor Functions
261
    **/
262
    /**
263
    * Return whether the debug option is set within the object
264
    *
265
    * @return boolean
266
    * @see set_debug()
267
    */
268
    public function get_debug()
269
    {
270
        return $this->debug;
271
    }
272
273
    /**
274
    * Turn on debug mode
275
    *
276
    * Enabling this option will cause this script to print debug information such as
277
    * the queries made, the response XML/JSON and other such pertinent information.
278
    * Calling this function without any parameters will enable debug mode.
279
    *
280
    * @param bool $debug turn on or off debug mode
281
    * @see get_debug()
282
    */
283
    public function set_debug( $debug = 1 )
284
    {
285
        $this->debug = $debug;
0 ignored issues
show
Documentation Bug introduced by
The property $debug was declared of type boolean, but $debug is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
286
    }
287
288
    /**
289
    * Get the host being connected to
290
    *
291
    * This function will return the host being connected to
292
    * @return string host
293
    * @see set_host()
294
    */
295
    public function get_host()
296
    {
297
        return $this->host;
298
    }
299
300
    /**
301
    * Set the host to query
302
    *
303
    * Setting this will set the host to be queried
304
    * @param string $host The host to query
305
    * @see get_host()
306
    */
307
    public function set_host( $host )
308
    {
309
        $this->host = $host;
310
    }
311
312
    /**
313
    * Get the port to connect to
314
    *
315
    * This will return which port the class is connecting to
316
    * @return int $port
317
    * @see set_port()
318
    */
319
    public function get_port()
320
    {
321
        return $this->port;
322
    }
323
324
    /**
325
    * Set the port to connect to
326
    *
327
    * This will allow a user to define which port needs to be connected to.
328
    * The default port set within the class is 2087 (WHM-SSL) however other ports are optional
329
    * this function will automatically set the protocol to http if the port is equal to:
330
    *    - 2082
331
    *    - 2086
332
    *    - 2095
333
    *    - 80
334
    * @param int $port the port to connect to
335
    * @see set_protocol()
336
    * @see get_port()
337
    */
338
    public function set_port( $port )
339
    {
340
        if ( !is_int( $port ) ) {
341
            $port = intval($port);
342
        }
343
344
        if ($port < 1 || $port > 65535) {
345
            throw new Exception('non integer or negative integer passed to set_port');
346
        }
347
348
        // Account for ports that are non-ssl
349
        if ($port == '2086' || $port == '2082' || $port == '80' || $port == '2095') {
350
            $this->set_protocol('http');
351
        }
352
353
        $this->port = $port;
0 ignored issues
show
Documentation Bug introduced by
The property $port was declared of type string, but $port is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
354
    }
355
356
    /**
357
    * Return the protocol being used to query
358
    *
359
    * This will return the protocol being connected to
360
    * @return string
361
    * @see set_protocol()
362
    */
363
    public function get_protocol()
364
    {
365
        return $this->protocol;
366
    }
367
368
    /**
369
    * Set the protocol to use to query
370
    *
371
    * This will allow you to set the protocol to query cpsrvd with.  The only to acceptable values
372
    * to be passed to this function are 'http' or 'https'.  Anything else will cause the class to throw
373
    * an Exception.
374
    * @param string $proto the protocol to use to connect to cpsrvd
375
    * @see get_protocol()
376
    */
377
    public function set_protocol( $proto )
378
    {
379
        if ($proto != 'https' && $proto != 'http') {
380
            throw new Exception('https and http are the only protocols that can be passed to set_protocol');
381
        }
382
        $this->protocol = $proto;
383
    }
384
385
    /**
386
    * Return what format calls with be returned in
387
    *
388
    * This function will return the currently set output format
389
    * @see set_output()
390
    * @return string
391
    */
392
    public function get_output()
393
    {
394
        return $this->output;
395
    }
396
397
    /**
398
    * Set the output format for call functions
399
    *
400
    * This class is capable of returning data in numerous formats including:
401
    *   - json
402
    *   - xml
403
    *   - {@link http://php.net/simplexml SimpleXML}
404
    *   - {@link http://us.php.net/manual/en/language.types.array.php Associative Arrays}
405
    *
406
    * These can be set by passing this class any of the following values:
407
    *   - json - return JSON string
408
    *   - xml - return XML string
409
    *   - simplexml - return SimpleXML object
410
    *   - array - Return an associative array
411
    *
412
    * Passing any value other than these to this class will cause an Exception to be thrown.
413
    * @param string $output the output type to be set
414
    * @see get_output()
415
    */
416
    public function set_output( $output )
417
    {
418
        if ($output != 'json' && $output != 'xml' && $output != 'array' && $output != 'simplexml') {
419
            throw new Exception('json, xml, array and simplexml are the only allowed values for set_output');
420
        }
421
        $this->output = $output;
422
    }
423
424
    /**
425
    * Return the auth_type being used
426
    *
427
    * This function will return a string containing the auth type in use
428
    * @return string auth type
429
    * @see set_auth_type()
430
    */
431
    public function get_auth_type()
432
    {
433
        return $this->auth_type;
434
    }
435
436
    /**
437
    * Set the auth type
438
    *
439
    * This class is capable of authenticating with both hash auth and password auth
440
    * This function will allow you to manually set which auth_type you are using.
441
    *
442
    * the only accepted parameters for this function are "hash" and "pass" anything else will cuase
443
    * an exception to be thrown
444
    *
445
    * @see set_password()
446
    * @see set_hash()
447
    * @see get_auth_type()
448
    * @param string auth_type the auth type to be set
449
    */
450
    public function set_auth_type( $auth_type )
451
    {
452
        if ($auth_type != 'hash' && $auth_type != 'pass') {
453
            throw new Exception('the only two allowable auth types arehash and path');
454
        }
455
        $this->auth_type = $auth_type;
456
    }
457
458
    /**
459
    * Set the password to be autenticated with
460
    *
461
    * This will set the password to be authenticated with, the auth_type will be automatically adjusted
462
    * when this function is used
463
    *
464
    * @param string $pass the password to authenticate with
465
    * @see set_hash()
466
    * @see set_auth_type()
467
    * @see set_user()
468
    */
469
    public function set_password( $pass )
470
    {
471
        $this->auth_type = 'pass';
472
        $this->auth = $pass;
473
    }
474
475
    /**
476
    * Set the hash to authenticate with
477
    *
478
    * This will set the hash to authenticate with, the auth_type will automatically be set when this function
479
    * is used.  This function will automatically strip the newlines from the hash.
480
    * @param string $hash the hash to autenticate with
481
    * @see set_password()
482
    * @see set_auth_type()
483
    * @see set_user()
484
    */
485
    public function set_hash( $hash )
486
    {
487
        $this->auth_type = 'hash';
488
        $this->auth = preg_replace("/(\n|\r|\s)/", '', $hash);
489
    }
490
491
    /**
492
    * Return the user being used for authtication
493
    *
494
    * This will return the username being authenticated against.
495
    *
496
    * @return string
497
    */
498
    public function get_user()
499
    {
500
        return $this->user;
501
    }
502
503
    /**
504
    * Set the user to authenticate against
505
    *
506
    * This will set the user being authenticated against.
507
    * @param string $user username
508
    * @see set_password()
509
    * @see set_hash()
510
    * @see get_user()
511
    */
512
    public function set_user( $user )
513
    {
514
        $this->user = $user;
515
    }
516
517
    /**
518
    * Set the user and hash to be used for authentication
519
    *
520
    * This function will allow one to set the user AND hash to be authenticated with
521
    *
522
    * @param string $user username
523
    * @param string $hash WHM Access Hash
524
    * @see set_hash()
525
    * @see set_user()
526
    */
527
    public function hash_auth( $user, $hash )
528
    {
529
        $this->set_hash( $hash );
530
        $this->set_user( $user );
531
    }
532
533
    /**
534
    * Set the user and password to be used for authentication
535
    *
536
    * This function will allow one to set the user AND password to be authenticated with
537
    * @param string $user username
538
    * @param string $pass password
539
    * @see set_pass()
540
    * @see set_user()
541
    */
542
    public function password_auth( $user, $pass )
543
    {
544
        $this->set_password( $pass );
545
        $this->set_user( $user );
546
    }
547
548
    /**
549
    * Return XML format
550
    *
551
    * this function will cause call functions to return XML format, this is the same as doing:
552
    *   set_output('xml')
553
    *
554
    * @see set_output()
555
    */
556
    public function return_xml()
557
    {
558
        $this->set_output('xml');
559
    }
560
561
    /**
562
    * Return simplexml format
563
    *
564
    * this function will cause all call functions to return simplexml format, this is the same as doing:
565
    *   set_output('simplexml')
566
    *
567
    * @see set_output()
568
    */
569
    public function return_object()
570
    {
571
        $this->set_output('simplexml');
572
    }
573
574
    /**
575
    * Set the HTTP client to use
576
    *
577
    * This class is capable of two types of HTTP Clients:
578
    *   - curl
579
    *   - fopen
580
    *
581
    * When using allow url fopen the class will use get_file_contents to perform the query
582
    * The only two acceptable parameters for this function are 'curl' and 'fopen'.
583
    * This will default to fopen, however if allow_url_fopen is disabled inside of php.ini
584
    * it will switch to curl
585
    *
586
     * @param string client The http client to use
587
    * @see get_http_client()
588
    */
589
590
    public function set_http_client( $client )
591
    {
592
        if ( ( $client != 'curl' ) && ( $client != 'fopen' ) ) {
593
            throw new Exception('only curl and fopen and allowed http clients');
594
        }
595
        $this->http_client = $client;
596
    }
597
598
    /**
599
    * Get the HTTP Client in use
600
    *
601
    * This will return a string containing the HTTP client currently in use
602
    *
603
    * @see set_http_client()
604
    * @return string
605
    */
606
    public function get_http_client()
607
    {
608
        return $this->http_client;
609
    }
610
611
     /*
612
    *	Query Functions
613
    *	--
614
    *	This is where the actual calling of the XML-API, building API1 & API2 calls happens
615
    */
616
617
    /**
618
    * Perform an XML-API Query
619
    *
620
    * This function will perform an XML-API Query and return the specified output format of the call being made
621
    *
622
    * @param string $function The XML-API call to execute
623
    * @param array $vars An associative array of the parameters to be passed to the XML-API Calls
624
    * @return mixed
625
    */
626
    public function xmlapi_query( $function, $vars = array() )
627
    {
628
        // Check to make sure all the data needed to perform the query is in place
629
        if (!$function) {
630
            throw new Exception('xmlapi_query() requires a function to be passed to it');
631
        }
632
633
        if ($this->user == null) {
634
            throw new Exception('no user has been set');
635
        }
636
637
        if ($this->auth ==null) {
638
            throw new Exception('no authentication information has been set');
639
        }
640
641
        // Build the query:
642
643
        $query_type = '/xml-api/';
644
645
        if ($this->output == 'json') {
646
            $query_type = '/json-api/';
647
        }
648
649
        $args = http_build_query($vars, '', '&');
650
        $url =  $this->protocol . '://' . $this->host . ':' . $this->port . $query_type . $function;
651
652
        if ($this->debug) {
653
            error_log('URL: ' . $url);
654
            error_log('DATA: ' . $args);
655
        }
656
657
        // Set the $auth string
658
659
        $authstr = '';
0 ignored issues
show
Unused Code introduced by
$authstr 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...
660
        if ($this->auth_type == 'hash') {
661
            $authstr = 'Authorization: WHM ' . $this->user . ':' . $this->auth . "\r\n";
662
        } elseif ($this->auth_type == 'pass') {
663
            $authstr = 'Authorization: Basic ' . base64_encode($this->user .':'. $this->auth) . "\r\n";
664
        } else {
665
            throw new Exception('invalid auth_type set');
666
        }
667
668
        if ($this->debug) {
669
            error_log("Authentication Header: " . $authstr ."\n");
670
        }
671
672
        // Perform the query (or pass the info to the functions that actually do perform the query)
673
674
        $response = '';
675 View Code Duplication
        if ($this->http_client == 'curl') {
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...
676
            $response = $this->curl_query($url, $args, $authstr);
677
        } elseif ($this->http_client == 'fopen') {
678
            $response = $this->fopen_query($url, $args, $authstr);
679
        }
680
681
		// fix #1
682
		$aMatch = array();
683
		if ($response && false !== stripos($response, '<html>') &&
684
			preg_match('/HTTP-EQUIV[\s]?=[\s]?"refresh"/i', $response) &&
685
			preg_match('/<meta [^>]+url[\s]?=[\s]?([^">]+)/i', $response, $aMatch) &&
686
			!empty($aMatch[1]) && 0 === strpos(trim($aMatch[1]), 'http'))
687
		{
688
			$url =  trim($aMatch[1]) . $query_type . $function;
689
			if ($this->debug) {
690
				error_log('new URL: ' . $url);
691
			}
692
693 View Code Duplication
			if ($this->http_client == 'curl') {
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...
694
				$response = $this->curl_query($url, $args, $authstr);
695
			} elseif ($this->http_client == 'fopen') {
696
				$response = $this->fopen_query($url, $args, $authstr);
697
			}
698
		}
699
		// ---
700
701
        /*
702
        *	Post-Query Block
703
        * Handle response, return proper data types, debug, etc
704
        */
705
706
        // print out the response if debug mode is enabled.
707
        if ($this->debug) {
708
            error_log("RESPONSE:\n " . $response);
709
        }
710
711
        // The only time a response should contain <html> is in the case of authentication error
712
        // cPanel 11.25 fixes this issue, but if <html> is in the response, we'll error out.
713
714
        if (stristr($response, '<html>') == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($response, '<html>') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
715
            if (stristr($response, 'Login Attempt Failed') == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($response, 'Login Attempt Failed') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
716
                error_log("Login Attempt Failed");
717
718
                return;
719
            }
720
            if (stristr($response, 'action="/login/"') == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($response, 'action="/login/"') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
721
                error_log("Authentication Error");
722
723
                return;
724
            }
725
726
            return;
727
        }
728
729
730
        // perform simplexml transformation (array relies on this)
731
        if ( ($this->output == 'simplexml') || $this->output == 'array') {
732
            $response = simplexml_load_string($response, null, LIBXML_NOERROR | LIBXML_NOWARNING);
733
            if (!$response) {
734
                    error_log("Some error message here");
735
736
                    return;
737
            }
738
            if ($this->debug) {
739
                error_log("SimpleXML var_dump:\n" . print_r($response, true));
740
            }
741
        }
742
743
        // perform array tranformation
744
        if ($this->output == 'array') {
745
            $response = $this->unserialize_xml($response);
746
            if ($this->debug) {
747
                error_log("Associative Array var_dump:\n" . print_r($response, true));
748
            }
749
        }
750
751
        return $response;
752
    }
753
754
    private function curl_query( $url, $postdata, $authstr )
755
    {
756
        $curl = curl_init();
757
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
758
        // Return contents of transfer on curl_exec
759
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
760
        // Allow self-signed certs
761
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
762
        // Set the URL
763
        curl_setopt($curl, CURLOPT_URL, $url);
764
        // Increase buffer size to avoid "funny output" exception
765
        curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072);
766
767
        // Pass authentication header
768
        $header[0] =$authstr .
0 ignored issues
show
Coding Style Comprehensibility introduced by
$header was never initialized. Although not strictly required by PHP, it is generally a good practice to add $header = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
769
            "Content-Type: application/x-www-form-urlencoded\r\n" .
770
            "Content-Length: " . strlen($postdata) . "\r\n" . "\r\n" . $postdata;
771
772
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
773
774
        curl_setopt($curl, CURLOPT_POST, 1);
775
776
        $result = curl_exec($curl);
777
        if ($result == false) {
778
            throw new Exception("curl_exec threw error \"" . curl_error($curl) . "\" for " . $url . "?" . $postdata );
779
        }
780
        curl_close($curl);
781
782
        return $result;
783
    }
784
785
    private function fopen_query( $url, $postdata, $authstr )
786
    {
787
        if ( !(ini_get('allow_url_fopen') ) ) {
788
            throw new Exception('fopen_query called on system without allow_url_fopen enabled in php.ini');
789
        }
790
791
        $opts = array(
792
            'http' => array(
793
                'allow_self_signed' => true,
794
                'method' => 'POST',
795
                'header' => $authstr .
796
                    "Content-Type: application/x-www-form-urlencoded\r\n" .
797
                    "Content-Length: " . strlen($postdata) . "\r\n" .
798
                    "\r\n" . $postdata
799
            )
800
        );
801
        $context = stream_context_create($opts);
802
803
        return file_get_contents($url, false, $context);
804
    }
805
806
807
    /*
808
    * Convert simplexml to associative arrays
809
    *
810
    * This function will convert simplexml to associative arrays.
811
    */
812
    private function unserialize_xml($input, $callback = null, $recurse = false)
813
    {
814
        // Get input, loading an xml string with simplexml if its the top level of recursion
815
        $data = ( (!$recurse) && is_string($input) ) ? simplexml_load_string($input) : $input;
816
        // Convert SimpleXMLElements to array
817
        if ($data instanceof SimpleXMLElement) {
818
            $data = (array) $data;
819
        }
820
        // Recurse into arrays
821
        if (is_array($data)) {
822
            foreach ($data as &$item) {
823
                $item = $this->unserialize_xml($item, $callback, true);
824
            }
825
        }
826
        // Run callback and return
827
        return (!is_array($data) && is_callable($callback)) ? call_user_func($callback, $data) : $data;
828
    }
829
830
831
    /* TO DO:
832
      Implement API1 and API2 query functions!!!!!
833
    */
834
    /**
835
    * Call an API1 function
836
    *
837
    * This function allows you to call API1 from within the XML-API,  This allowes a user to peform actions
838
    * such as adding ftp accounts, etc
839
    *
840
    * @param string $user The username of the account to perform API1 actions on
841
    * @param string $module The module of the API1 call to use
842
    * @param string $function The function of the API1 call
843
    * @param array $args The arguments for the API1 function, this should be a non-associative array
844
    * @return mixed
845
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CallingAPIFunctions XML API Call documentation
846
    * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiRef/WebHome API1 & API2 Call documentation
847
    * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiBasics/CallingApiOne API1 Documentation
848
    */
849
    public function api1_query($user, $module, $function, $args = array() )
850
    {
851 View Code Duplication
        if ( !isset($module) || !isset($function) || !isset($user) ) {
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...
852
            error_log("api1_query requires that a module and function are passed to it");
853
854
            return false;
855
        }
856
857
        if (!is_array($args)) {
858
            error_log('api1_query requires that it is passed an array as the 4th parameter');
859
860
            return false;
861
        }
862
863
        $cpuser = 'cpanel_xmlapi_user';
864
        $module_type = 'cpanel_xmlapi_module';
865
        $func_type = 'cpanel_xmlapi_func';
866
        $api_type = 'cpanel_xmlapi_apiversion';
867
868 View Code Duplication
        if ( $this->get_output() == 'json' ) {
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...
869
            $cpuser = 'cpanel_jsonapi_user';
870
            $module_type = 'cpanel_jsonapi_module';
871
            $func_type = 'cpanel_jsonapi_func';
872
            $api_type = 'cpanel_jsonapi_apiversion';
873
        }
874
875
        $call = array(
876
                $cpuser => $user,
877
                $module_type => $module,
878
                $func_type => $function,
879
                $api_type => '1'
880
            );
881
        for ($int = 0; $int < count($args);  $int++) {
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...
882
            $call['arg-' . $int] = $args[$int];
883
        }
884
885
        return $this->xmlapi_query('cpanel', $call);
886
    }
887
888
    /**
889
    * Call an API2 Function
890
    *
891
    * This function allows you to call an API2 function, this is the modern API for cPanel and should be used in preference over
892
    * API1 when possible
893
    *
894
    * @param string $user The username of the account to perform API2 actions on
895
    * @param string $module The module of the API2 call to use
896
    * @param string $function The function of the API2 call
897
    * @param array $args An associative array containing the arguments for the API2 call
898
    * @return mixed
899
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CallingAPIFunctions XML API Call documentation
900
    * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiRef/WebHome API1 & API2 Call documentation
901
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ApiTwo Legacy API2 Documentation
902
    * @link http://docs.cpanel.net/twiki/bin/view/DeveloperResources/ApiBasics/CallingApiTwo API2 Documentation
903
    */
904
905
    public function api2_query($user, $module, $function, $args = array())
906
    {
907 View Code Duplication
        if (!isset($user) || !isset($module) || !isset($function) ) {
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...
908
            error_log("api2_query requires that a username, module and function are passed to it");
909
910
            return false;
911
        }
912
        if (!is_array($args)) {
913
            error_log("api2_query requires that an array is passed to it as the 4th parameter");
914
915
            return false;
916
        }
917
918
        $cpuser = 'cpanel_xmlapi_user';
919
        $module_type = 'cpanel_xmlapi_module';
920
        $func_type = 'cpanel_xmlapi_func';
921
        $api_type = 'cpanel_xmlapi_apiversion';
922
923 View Code Duplication
        if ( $this->get_output() == 'json' ) {
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...
924
            $cpuser = 'cpanel_jsonapi_user';
925
            $module_type = 'cpanel_jsonapi_module';
926
            $func_type = 'cpanel_jsonapi_func';
927
            $api_type = 'cpanel_jsonapi_apiversion';
928
        }
929
930
        $args[$cpuser] = $user;
931
        $args[$module_type] = $module;
932
        $args[$func_type] = $function;
933
        $args[$api_type] = '2';
934
935
        return $this->xmlapi_query('cpanel', $args);
936
    }
937
938
    ####
939
    #  XML API Functions
940
    ####
941
942
    /**
943
    * Return a list of available XML-API calls
944
    *
945
    * This function will return an array containing all applications available within the XML-API
946
    *
947
    * @return mixed
948
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListAvailableCalls XML API Call documentation
949
    */
950
    public function applist()
951
    {
952
        return $this->xmlapi_query('applist');
953
    }
954
955
    ####
956
    # Account functions
957
    ####
958
959
    /**
960
    * Create a cPanel Account
961
    *
962
    * This function will allow one to create an account, the $acctconf parameter requires that the follow
963
    * three associations are defined:
964
    *	- username
965
    *	- password
966
    *	- domain
967
    *
968
    * Failure to prive these will cause an error to be logged.  Any other key/value pairs as defined by the createaccount call
969
    * documentation are allowed parameters for this call.
970
    *
971
    * @param array $acctconf
972
    * @return mixed
973
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CreateAccount XML API Call documentation
974
    */
975
976 View Code Duplication
    public function createacct($acctconf)
0 ignored issues
show
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...
977
    {
978
        if (!is_array($acctconf)) {
979
            error_log("createacct requires that first parameter passed to it is an array");
980
981
            return false;
982
        }
983
        if (!isset($acctconf['username']) || !isset($acctconf['password']) || !isset($acctconf['domain'])) {
984
            error_log("createacct requires that username, password & domain elements are in the array passed to it");
985
986
            return false;
987
        }
988
989
        return $this->xmlapi_query('createacct', $acctconf);
990
    }
991
992
    /**
993
    * Change a cPanel Account's Password
994
    *
995
    * This function will allow you to change the password of a cpanel account
996
    *
997
    * @param string $username The username to change the password of
998
    * @param string $pass The new password for the cPanel Account
999
    * @return mixed
1000
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ChangePassword XML API Call documentation
1001
    */
1002
    public function passwd($username, $pass)
1003
    {
1004
        if (!isset($username) || !isset($pass)) {
1005
            error_log("passwd requires that an username and password are passed to it");
1006
1007
            return false;
1008
        }
1009
1010
        return $this->xmlapi_query('passwd', array('user' => $username, 'pass' => $pass));
1011
    }
1012
1013
    /**
1014
    * Limit an account's monthly bandwidth usage
1015
    *
1016
    * This function will set an account's bandwidth limit.
1017
    *
1018
    * @param string $username The username of the cPanel account to modify
1019
    * @param int $bwlimit The new bandwidth limit in megabytes
1020
    * @return mixed
1021
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/LimitBandwidth XML API Call documentation
1022
    */
1023
    public function limitbw($username, $bwlimit)
1024
    {
1025
        if (!isset($username) || !isset($bwlimit)) {
1026
            error_log("limitbw requires that an username and bwlimit are passed to it");
1027
1028
            return false;
1029
        }
1030
1031
        return $this->xmlapi_query('limitbw', array('user' => $username, 'bwlimit' => $bwlimit));
1032
    }
1033
1034
    /**
1035
    * List accounts on Server
1036
    *
1037
    * This call will return a list of account on a server, either no parameters or both parameters may be passed to this function.
1038
    *
1039
    * @param string $searchtype Type of account search to use, allowed values: domain, owner, user, ip or package
1040
    * @param string $search the string to search against
1041
    * @return mixed
1042
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListAccounts XML API Call documentation
1043
    */
1044
    public function listaccts($searchtype = null, $search = null)
1045
    {
1046
        if ($search) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $search of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
1047
            return $this->xmlapi_query('listaccts', array('searchtype' => $searchtype, 'search' => $search ));
1048
        }
1049
1050
        return $this->xmlapi_query('listaccts');
1051
    }
1052
1053
    /**
1054
    * Modify a cPanel account
1055
    *
1056
    * This call will allow you to change limitations and information about an account.  See the XML API call documentation for a list of
1057
    * acceptable values for args.
1058
    *
1059
    * @param string $username The username to modify
1060
    * @param array $args the new values for the modified account (see {@link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ModifyAccount modifyacct documentation})
1061
    * @return mixed
1062
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ModifyAccount XML API Call documentation
1063
    */
1064
    public function modifyacct($username, $args = array())
1065
    {
1066
        if (!isset($username)) {
1067
            error_log("modifyacct requires that username is passed to it");
1068
1069
            return false;
1070
        }
1071
        $args['user'] = $username;
1072
        if (sizeof($args) < 2) {
1073
            error_log("modifyacct requires that at least one attribute is passed to it");
1074
1075
            return false;
1076
        }
1077
1078
        return $this->xmlapi_query('modifyacct', $args);
1079
    }
1080
1081
    /**
1082
    * Edit a cPanel Account's Quota
1083
    *
1084
    * This call will allow you to change a cPanel account's quota
1085
    *
1086
    * @param string $username The username of the account to modify the quota.
1087
    * @param int $quota the new quota in megabytes
1088
    * @return mixed
1089
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/EditQuota XML API Call documentation
1090
    */
1091
    public function editquota($username, $quota)
1092
    {
1093
        if (!isset($username) || !isset($quota)) {
1094
            error_log("editquota requires that an username and quota are passed to it");
1095
1096
            return false;
1097
        }
1098
1099
        return $this->xmlapi_query('editquota', array('user' => $username, 'quota' => $quota));
1100
    }
1101
1102
    /**
1103
    * Return a summary of the account's information
1104
    *
1105
    * This call will return a brief report of information about an account, such as:
1106
    *	- Disk Limit
1107
    *	- Disk Used
1108
    *	- Domain
1109
    *	- Account Email
1110
    *	- Theme
1111
    * 	- Start Data
1112
    *
1113
    * Please see the XML API Call documentation for more information on what is returned by this call
1114
    *
1115
    * @param string $username The username to retrieve a summary of
1116
    * @return mixed
1117
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ShowAccountInformation XML API Call documenation
1118
    */
1119
    public function accountsummary($username)
1120
    {
1121
        if (!isset($username)) {
1122
            error_log("accountsummary requires that an username is passed to it");
1123
1124
            return false;
1125
        }
1126
1127
        return $this->xmlapi_query('accountsummary', array('user' => $username));
1128
    }
1129
1130
    /**
1131
    * Suspend a User's Account
1132
    *
1133
    * This function will suspend the specified cPanel users account.
1134
    * The $reason parameter is optional, but can contain a string of any length
1135
    *
1136
    * @param string $username The username to suspend
1137
    * @param string $reason The reason for the suspension
1138
    * @return mixed
1139
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SuspendAccount XML API Call documentation
1140
    */
1141
    public function suspendacct($username, $reason = null)
1142
    {
1143
        if (!isset($username)) {
1144
            error_log("suspendacct requires that an username is passed to it");
1145
1146
            return false;
1147
        }
1148
        if ($reason) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $reason of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
1149
            return $this->xmlapi_query('suspendacct', array('user' => $username, 'reason' => $reason ));
1150
        }
1151
1152
        return $this->xmlapi_query('suspendacct', array('user' => $username));
1153
    }
1154
1155
    /**
1156
    * List suspended accounts on a server
1157
    *
1158
    * This function will return an array containing all the suspended accounts on a server
1159
    *
1160
    * @return mixed
1161
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListSuspended XML API Call documentation
1162
    */
1163
    public function listsuspended()
1164
    {
1165
        return $this->xmlapi_query('listsuspended');
1166
    }
1167
1168
    /**
1169
    * Remove an Account
1170
    *
1171
    * This XML API call will remove an account on the server
1172
    * The $keepdns parameter is optional, when enabled this will leave the DNS zone on the server
1173
    *
1174
    * @param string $username The usename to delete
1175
    * @param bool $keepdns When pass a true value, the DNS zone will be retained
1176
    * @return mixed
1177
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/TerminateAccount
1178
    */
1179 View Code Duplication
    public function removeacct($username, $keepdns = false)
0 ignored issues
show
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...
1180
    {
1181
        if (!isset($username)) {
1182
            error_log("removeacct requires that a username is passed to it");
1183
1184
            return false;
1185
        }
1186
        if ($keepdns) {
1187
            return $this->xmlapi_query('removeacct', array('user' => $username, 'keepdns' => '1'));
1188
        }
1189
1190
        return $this->xmlapi_query('removeacct', array('user' => $username));
1191
    }
1192
1193
    /**
1194
    * Unsuspend an Account
1195
    *
1196
    * This XML API call will unsuspend an account
1197
    *
1198
    * @param string $username The username to unsuspend
1199
    * @return mixed
1200
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/UnsuspendAcount XML API Call documentation
1201
     */
1202
    public function unsuspendacct($username)
1203
    {
1204
        if (!isset($username)) {
1205
            error_log("unsuspendacct requires that a username is passed to it");
1206
1207
            return false;
1208
        }
1209
1210
        return $this->xmlapi_query('unsuspendacct', array('user' => $username));
1211
    }
1212
1213
    /**
1214
    * Change an Account's Package
1215
    *
1216
    * This XML API will change the package associated account.
1217
    *
1218
    * @param string $username the username to change the package of
1219
    * @param string $pkg The package to change the account to.
1220
    * @return mixed
1221
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ChangePackage XML API Call documentation
1222
    */
1223
    public function changepackage($username, $pkg)
1224
    {
1225
        if (!isset($username) || !isset($pkg)) {
1226
            error_log("changepackage requires that username and pkg are passed to it");
1227
1228
            return false;
1229
        }
1230
1231
        return $this->xmlapi_query('changepackage', array('user' => $username, 'pkg' => $pkg));
1232
    }
1233
1234
    /**
1235
    * Return the privileges a reseller has in WHM
1236
    *
1237
    * This will return a list of the privileges that a reseller has to WHM
1238
    * @return mixed
1239
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ViewPrivileges XML API Call documentation
1240
    */
1241
    public function myprivs()
1242
    {
1243
        return $this->xmlapi_query('myprivs');
1244
    }
1245
1246
1247
    /**
1248
    * Display Data about a Virtual Host
1249
    *
1250
    * This function will return information about a specific domain.  This data is essentially a representation of the data
1251
    * Contained in the httpd.conf VirtualHost for the domain.
1252
    *
1253
    * @return mixed
1254
    * @param string $domain The domain to fetch information for
1255
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DomainUserData
1256
    */
1257
1258 View Code Duplication
    public function domainuserdata( $domain )
0 ignored issues
show
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...
1259
    {
1260
        if (!isset( $domain ) ) {
1261
            error_log("domainuserdata requires that domain is passed to it");
1262
1263
            return false;
1264
        }
1265
1266
        return $this->xmlapi_query("domainuserdata", array( 'domain' => $domain ) );
1267
    }
1268
1269
    /**
1270
    * Change a site's IP Address
1271
    *
1272
    * This function will allow you to change the IP address that a domain listens on.
1273
    * In order to properly call this function Either $user or $domain parameters must be defined
1274
    * @param string $ip The $ip address to change the account or domain to
1275
    * @param string $user The username to change the IP of
1276
    * @param string $domain The domain to change the IP of
1277
    * @return mixed
1278
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetSiteIp XML API Call documentation
1279
    */
1280
    public function setsiteip ( $ip, $user = null, $domain = null )
1281
    {
1282
        if ( !isset($ip) ) {
1283
            error_log("setsiteip requires that ip is passed to it");
1284
1285
            return false;
1286
        }
1287
1288
        if ($user == null && $domain == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
Bug introduced by
It seems like you are loosely comparing $domain of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
1289
            error_log("setsiteip requires that either domain or user is passed to it");
1290
1291
            return false;
1292
        }
1293
1294
        if ($user == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
1295
            return $this->xmlapi_query( "setsiteip", array( "ip" => $ip, "domain" => $domain ) );
1296
        } else {
1297
            return $this->xmlapi_query( "setsiteip", array( "ip" => $ip, "user" => $user ) );
1298
        }
1299
    }
1300
1301
    ####
1302
    # DNS Functions
1303
    ####
1304
1305
    // This API function lets you create a DNS zone.
1306
    /**
1307
    * Add a DNS Zone
1308
    *
1309
    * This XML API function will create a DNS Zone.  This will use the "standard" template when
1310
    * creating the zone.
1311
    *
1312
    * @param string $domain The DNS Domain that you wish to create a zone for
1313
    * @param string $ip The IP you want the domain to resolve to
1314
    * @return mixed
1315
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddDNSZone XML API Call documentation
1316
    */
1317 View Code Duplication
    public function adddns($domain, $ip)
0 ignored issues
show
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...
1318
    {
1319
        if (!isset($domain) || !isset($ip)) {
1320
            error_log("adddns require that domain, ip are passed to it");
1321
1322
            return false;
1323
        }
1324
1325
        return $this->xmlapi_query('adddns', array('domain' => $domain, 'ip' => $ip));
1326
    }
1327
1328
    /**
1329
    * Add a record to a zone
1330
    *
1331
    * This will append a record to a DNS Zone.  The $args argument to this function
1332
    * must be an associative array containing information about the DNS zone, please
1333
    * see the XML API Call documentation for more info
1334
    *
1335
    * @param string $zone The DNS zone that you want to add the record to
1336
    * @param array $args Associative array representing the record to be added
1337
    * @return mixed
1338
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddZoneRecord XML API Call documentation
1339
    */
1340
    public function addzonerecord( $zone, $args )
1341
    {
1342
        if (!is_array($args)) {
1343
            error_log("addzonerecord requires that $args passed to it is an array");
1344
1345
            return;
1346
        }
1347
1348
        $args['zone'] = $zone;
1349
1350
        return $this->xmlapi_query('addzonerecord', $args);
1351
    }
1352
1353
    /**
1354
    * Edit a Zone Record
1355
    *
1356
    * This XML API Function will allow you to edit an existing DNS Zone Record.
1357
    * This works by passing in the line number of the record you wish to edit.
1358
    * Line numbers can be retrieved with dumpzone()
1359
    *
1360
    * @param string $zone The zone to edit
1361
    * @param int $line The line number of the zone to edit
1362
    * @param array $args An associative array representing the zone record
1363
    * @return mixed
1364
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/EditZoneRecord XML API Call documentation
1365
    * @see dumpzone()
1366
    */
1367
1368
    public function editzonerecord( $zone, $line, $args )
1369
    {
1370
        if (!is_array($args)) {
1371
            error_log("editzone requires that $args passed to it is an array");
1372
1373
            return;
1374
        }
1375
1376
        $args['domain'] = $zone;
1377
        $args['Line'] = $line;
1378
1379
        return $this->xmlapi_query('editzonerecord', $args);
1380
    }
1381
1382
    /**
1383
    * Retrieve a DNS Record
1384
    *
1385
    * This function will return a data structure representing a DNS record, to
1386
    * retrieve all lines see dumpzone.
1387
    * @param string $zone The zone that you want to retrieve a record from
1388
    * @param string $line The line of the zone that you want to retrieve
1389
    * @return mixed
1390
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/GetZoneRecord XML API Call documentation
1391
    */
1392
    public function getzonerecord( $zone, $line )
1393
    {
1394
        return $this->xmlapi_query('getzonerecord', array( 'domain' => $zone, 'Line' => $line ) );
1395
    }
1396
1397
    /**
1398
    * Remove a DNS Zone
1399
    *
1400
    * This function will remove a DNS Zone from the server
1401
    *
1402
    * @param string $domain The domain to be remove
1403
    * @return mixed
1404
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DeleteDNSZone XML API Call documentation
1405
    */
1406 View Code Duplication
    public function killdns($domain)
0 ignored issues
show
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...
1407
    {
1408
        if (!isset($domain)) {
1409
            error_log("killdns requires that domain is passed to it");
1410
1411
            return false;
1412
        }
1413
1414
        return $this->xmlapi_query('killdns', array('domain' => $domain));
1415
    }
1416
1417
    /**
1418
    * Return a List of all DNS Zones on the server
1419
    *
1420
    * This XML API function will return an array containing all the DNS Zones on the server
1421
    *
1422
    * @return mixed
1423
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListDNSZone XML API Call documentation
1424
    */
1425
    public function listzones()
1426
    {
1427
        return $this->xmlapi_query('listzones');
1428
    }
1429
1430
    /**
1431
    * Return all records in a zone
1432
    *
1433
    * This function will return all records within a zone.
1434
    * @param string $domain The domain to return the records from.
1435
    * @return mixed
1436
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListOneZone XML API Call documentation
1437
    * @see editdnsrecord()
1438
    * @see getdnsrecord()
1439
    */
1440 View Code Duplication
    public function dumpzone($domain)
0 ignored issues
show
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...
1441
    {
1442
        if (!isset($domain)) {
1443
            error_log("dumpzone requires that a domain is passed to it");
1444
1445
            return false;
1446
        }
1447
1448
        return $this->xmlapi_query('dumpzone', array('domain' => $domain));
1449
    }
1450
1451
    /**
1452
    * Return a Nameserver's IP
1453
    *
1454
    * This function will return a nameserver's IP
1455
    *
1456
    * @param string $nameserver The nameserver to lookup
1457
    * @return mixed
1458
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/LookupIP XML API Call documentation
1459
    */
1460
    public function lookupnsip($nameserver)
1461
    {
1462
        if (!isset($nameserver)) {
1463
            error_log("lookupnsip requres that a nameserver is passed to it");
1464
1465
            return false;
1466
        }
1467
1468
        return $this->xmlapi_query('lookupnsip', array('nameserver' => $nameserver));
1469
    }
1470
1471
    /**
1472
    * Remove a line from a zone
1473
    *
1474
    * This function will remove the specified line from a zone
1475
    * @param string $zone The zone to remove a line from
1476
    * @param int $line The line to remove from the zone
1477
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/RemoveZone XML API Call documentation
1478
    */
1479 View Code Duplication
    public function removezonerecord($zone, $line)
0 ignored issues
show
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...
1480
    {
1481
        if ( !isset($zone) || !isset($line) ) {
1482
            error_log("removezone record requires that a zone and line number is passed to it");
1483
1484
            return false;
1485
        }
1486
1487
        return $this->xmlapi_query('removezonerecord', array('zone' => $zone, 'Line' => $line) );
1488
    }
1489
1490
    /**
1491
    * Reset a zone
1492
    *
1493
    * This function will reset a zone removing all custom records.  Subdomain records will be readded by scanning the userdata datastore.
1494
    * @param string $domain the domain name of the zone to reset
1495
    * @return mixed
1496
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ResetZone XML API Call documentation
1497
    */
1498 View Code Duplication
    public function resetzone($domain)
0 ignored issues
show
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...
1499
    {
1500
        if ( !isset($domain) ) {
1501
            error_log("resetzone requires that a domain name is passed to it");
1502
1503
            return false;
1504
        }
1505
1506
        return $this->xmlapi_query('resetzone', array('domain' => $domain));
1507
    }
1508
1509
    ####
1510
    # Package Functions
1511
    ####
1512
1513
    /**
1514
    * Add a new package
1515
    *
1516
    * This function will allow you to add a new package
1517
    * This function should be passed an associative array containing elements that define package parameters.
1518
    * These variables map directly to the parameters for the XML-API Call, please refer to the link below for a complete
1519
    * list of possible variable.  The "name" element is required.
1520
    * @param array $pkg an associative array containing package parameters
1521
    * @return mixed
1522
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddPackage XML API Call documentation
1523
    */
1524
    public function addpkg($pkg)
1525
    {
1526
        if (!isset($pkg['name'])) {
1527
            error_log("addpkg requires that name is defined in the array passed to it");
1528
1529
            return false;
1530
        }
1531
1532
        return $this->xmlapi_query('addpkg', $pkg);
1533
    }
1534
1535
    /**
1536
    * Remove a package
1537
    *
1538
    * This function allow you to delete a package
1539
    * @param string $pkgname The package you wish to delete
1540
    * @return mixed
1541
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DeletePackage XML API Call documentation
1542
    */
1543
    public function killpkg($pkgname)
1544
    {
1545
        if (!isset($pkgname)) {
1546
            error_log("killpkg requires that the package name is passed to it");
1547
1548
            return false;
1549
        }
1550
1551
        return $this->xmlapi_query('killpkg', array('pkg' => $pkgname));
1552
    }
1553
1554
    /**
1555
    * Edit a package
1556
    *
1557
    * This function allows you to change a package's paremeters.  This is passed an associative array defining
1558
    * the parameters for the package.  The keys within this array map directly to the XML-API call, please see the link
1559
    * below for a list of possible keys within this package.  The name element is required.
1560
    * @param array $pkg An associative array containing new parameters for the package
1561
    * @return mixed
1562
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/EditPackage XML API Call documentation
1563
    */
1564
    public function editpkg($pkg)
1565
    {
1566
        if (!isset($pkg['name'])) {
1567
            error_log("editpkg requires that name is defined in the array passed to it");
1568
1569
            return false;
1570
        }
1571
1572
        return $this->xmlapi_query('editpkg', $pkg);
1573
    }
1574
1575
    /**
1576
    * List Packages
1577
    *
1578
    * This function will list all packages available to the user
1579
    * @return mixed
1580
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListPackages XML API Call documentation
1581
    */
1582
    public function listpkgs()
1583
    {
1584
        return $this->xmlapi_query('listpkgs');
1585
    }
1586
1587
    ####
1588
    # Reseller functions
1589
    ####
1590
1591
    /**
1592
    * Make a user a reseller
1593
    *
1594
    * This function will allow you to mark an account as having reseller privileges
1595
    * @param string $username The username of the account you wish to add reseller privileges to
1596
    * @param int $makeowner Boolean 1 or 0 defining whether the account should own itself or not
1597
    * @see setacls()
1598
    * @see setresellerlimits()
1599
    * @return mixed
1600
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddResellerPrivileges XML API Call documentation
1601
    */
1602 View Code Duplication
    public function setupreseller($username, $makeowner = true)
0 ignored issues
show
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...
1603
    {
1604
        if (!isset($username)) {
1605
            error_log("setupreseller requires that username is passed to it");
1606
1607
            return false;
1608
        }
1609
        if ($makeowner) {
1610
            return $this->xmlapi_query('setupreseller', array('user' => $username, 'makeowner' => '1'));
1611
        }
1612
1613
        return $this->xmlapi_query('setupreseller', array('user' => $username, 'makeowner' => '0'));
1614
    }
1615
1616
    /**
1617
    * Create a New ACL List
1618
    *
1619
    * This function allows you to create a new privilege set for reseller accounts.  This is passed an
1620
    * Associative Array containing the configuration information for this variable.  Please see the XML API Call documentation
1621
    * For more information.  "acllist" is a required element within this array
1622
    * @param array $acl an associative array describing the parameters for the ACL to be create
1623
    * @return mixed
1624
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CreateResellerACLList XML API Call documentation
1625
    */
1626
    public function saveacllist($acl)
1627
    {
1628
        if (!isset($acl['acllist'])) {
1629
            error_log("saveacllist requires that acllist is defined in the array passed to it");
1630
1631
            return false;
1632
        }
1633
1634
        return $this->xmlapi_query('saveacllist', $acl);
1635
    }
1636
1637
1638
    /**
1639
    * List available saved ACLs
1640
    *
1641
    * This function will return a list of Saved ACLs for reseller accounts
1642
    * @return mixed
1643
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListCurrentResellerACLLists XML API Call documentation
1644
    */
1645
    public function listacls()
1646
    {
1647
        return $this->xmlapi_query('listacls');
1648
    }
1649
1650
    /**
1651
    * List Resellers
1652
    *
1653
    * This function will return a list of resellers on the server
1654
    * @return mixed
1655
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListResellerAccounts XML API Call documentation
1656
    */
1657
    public function listresellers()
1658
    {
1659
        return $this->xmlapi_query('listresellers');
1660
    }
1661
1662
    /**
1663
    * Get a reseller's statistics
1664
    *
1665
    * This function will return general information on a reseller and all it's account individually such as disk usage and bandwidth usage
1666
    *
1667
    * @param string $username The reseller to be checked
1668
    * @return mixed
1669
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListResellersAccountsInformation XML API Call documentation
1670
    */
1671 View Code Duplication
    public function resellerstats($username)
0 ignored issues
show
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...
1672
    {
1673
        if (!isset($username)) {
1674
            error_log("resellerstats requires that a username is passed to it");
1675
1676
            return false;
1677
        }
1678
1679
        return $this->xmlapi_query('resellerstats', array('reseller' => $username));
1680
    }
1681
1682
    /**
1683
    * Remove Reseller Privileges
1684
    *
1685
    * This function will remove an account's reseller privileges, this does not remove the account.
1686
    *
1687
    * @param string $username The username to remove reseller privileges from
1688
    * @return mixed
1689
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/RemoveResellerPrivileges XML API Call documentation
1690
    */
1691
    public function unsetupreseller($username)
1692
    {
1693
        if (!isset($username)) {
1694
            error_log("unsetupreseller requires that a username is passed to it");
1695
1696
            return false;
1697
        }
1698
1699
        return $this->xmlapi_query('unsetupreseller', array('user' => $username));
1700
    }
1701
1702
    /**
1703
    * Set a reseller's privileges
1704
    *
1705
    * This function will allow you to set what parts of WHM a reseller has access to.  This is passed an associative array
1706
    * containing the privleges that this reseller should have access to.  These map directly to the parameters passed to the XML API Call
1707
    * Please view the XML API Call documentation for more information.  "reseller" is the only required element within this array
1708
    * @param array $acl An associative array containing all the ACL information for the reseller
1709
    * @return mixed
1710
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellersACLList XML API Call documentation
1711
    */
1712 View Code Duplication
    public function setacls($acl)
0 ignored issues
show
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...
1713
    {
1714
        if (!isset($acl['reseller'])) {
1715
            error_log("setacls requires that reseller is defined in the array passed to it");
1716
1717
            return false;
1718
        }
1719
1720
        return $this->xmlapi_query('setacls', $acl);
1721
    }
1722
1723
    /**
1724
    * Terminate a Reseller's Account
1725
    *
1726
    * This function will terminate a reseller's account and all accounts owned by the reseller
1727
    *
1728
    * @param string $reseller the name of the reseller to terminate
1729
    * @param boolean $terminatereseller Passing this as true will terminate the the reseller's account as well as all the accounts owned by the reseller
1730
    * @return mixed
1731
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/TerminateResellerandAccounts XML API Call documentation
1732
    *
1733
    **/
1734
    public function terminatereseller($reseller, $terminatereseller = true)
1735
    {
1736
        if (!isset($reseller)) {
1737
            error_log("terminatereseller requires that username is passed to it");
1738
1739
            return false;
1740
        }
1741
        $verify = 'I understand this will irrevocably remove all the accounts owned by the reseller ' . $reseller;
1742
        if ($terminatereseller) {
1743
            return $this->xmlapi_query('terminatereseller', array('reseller' => $reseller, 'terminatereseller' => '1', 'verify' => $verify));
1744
        }
1745
1746
        return $this->xmlapi_query('terminatereseller', array('reseller' => $reseller, 'terminatereseller' => '0', 'verify' => $verify));
1747
    }
1748
1749
    /**
1750
    * Set a reseller's dedicated IP addresses
1751
    *
1752
    * This function will set a reseller's dedicated IP addresses.  If an IP is not passed to this function,
1753
    * it will reset the reseller to use the server's main shared IP address.
1754
    * @param string $user The username of the reseller to change dedicated IPs for
1755
    * @param string $ip The IP to assign to the  reseller, this can be a comma-seperated list of IPs to allow for multiple IP addresses
1756
    * @return mixed
1757
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellerIps XML API Call documentation
1758
    */
1759 View Code Duplication
    public function setresellerips($user, $ip = null)
0 ignored issues
show
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...
1760
    {
1761
        if (!isset($user) ) {
1762
            error_log("setresellerips requires that a username is passed to it");
1763
1764
            return false;
1765
        }
1766
        $params = array("user" => $user);
1767
        if ($ip != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $ip of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1768
            $params['ip'] = $ip;
1769
        }
1770
1771
        return $this->xmlapi_query('setresellerips',$params);
1772
    }
1773
1774
    /**
1775
    * Set Accounting Limits for a reseller account
1776
    *
1777
    * This function allows you to define limits for reseller accounts not included with in access control such as
1778
    * the number of accounts a reseller is allowed to create, the amount of disk space to use.
1779
    * This function is passed an associative array defining these limits, these map directly to the parameters for the XML API
1780
    * Call, please refer to the XML API Call documentation for more information.  The only required parameters is "user"
1781
    *
1782
    * @param array $reseller_cfg An associative array containing configuration information for the specified reseller
1783
    * @return mixed
1784
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellerLimits XML API Call documentation
1785
    *
1786
    */
1787
    public function setresellerlimits( $reseller_cfg )
1788
    {
1789
        if ( !isset($reseller_cfg['user'] ) ) {
1790
            error_log("setresellerlimits requires that a user is defined in the array passed to it");
1791
1792
            return false;
1793
        }
1794
1795
        return $this->xmlapi_query('setresellerlimits',$reseller_cfg);
1796
    }
1797
1798
    /**
1799
    * Set a reseller's main IP
1800
    *
1801
    * This function will allow you to set a reseller's main IP.  By default all accounts created by this reseller
1802
    * will be created on this IP
1803
    * @param string $reseller the username of the reseller to change the main IP of
1804
    * @param string $ip The ip you would like this reseller to create accounts on by default
1805
    * @return mixed
1806
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellerMainIp XML API Call documentation
1807
    */
1808 View Code Duplication
    public function setresellermainip($reseller, $ip)
0 ignored issues
show
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...
1809
    {
1810
        if ( !isset($reseller) || !isset($ip) ) {
1811
            error_log("setresellermainip requires that an reseller and ip are passed to it");
1812
1813
            return false;
1814
        }
1815
1816
        return $this->xmlapi_query("setresellermainip", array('user' => $reseller, 'ip' => $ip));
1817
    }
1818
1819
    /**
1820
    * Set reseller package limits
1821
    *
1822
    * This function allows you to define which packages a reseller has access to use
1823
    * @param string $user The reseller you wish to define package limits for
1824
    * @param boolean $no_limit Whether or not you wish this reseller to have packages limits
1825
    * @param string $package if $no_limit is false, then the package you wish to modify privileges for
1826
    * @param boolean $allowed if $no_limit is false, then defines if the reseller should have access to the package or not
1827
    * @param int $number if $no_limit is false, then defines the number of account a reseller can create of a specific package
1828
    * @return mixed
1829
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellerPkgLimit XML API Call documentation
1830
    */
1831
    public function setresellerpackagelimits($user, $no_limit, $package = null, $allowed = null, $number = null)
1832
    {
1833
        if (!isset($user) || !isset($no_limit) ) {
1834
            error_log("setresellerpackagelimits requires that a username and no_limit are passed to it by default");
1835
1836
            return false;
1837
        }
1838
        if ($no_limit) {
1839
            return $this->xmlapi_query("setresellerpackagelimits", array( 'user' => $user, "no_limit" => '1') );
1840
        } else {
1841
            if ( is_null($package) || is_null($allowed) ) {
1842
                error_log('setresellerpackagelimits requires that package and allowed are passed to it if no_limit eq 0');
1843
1844
                return false;
1845
            }
1846
            $params = array(
1847
                'user' => $user,
1848
                'no_limit' => '0',
1849
                'package' => $package,
1850
            );
1851
            if ($allowed) {
1852
                $params['allowed'] = 1;
1853
            } else {
1854
                $params['allowed'] = 0;
1855
            }
1856
            if ( !is_null($number) ) {
1857
                $params['number'] = $number;
1858
            }
1859
1860
            return $this->xmlapi_query('setresellerpackagelimits', $params);
1861
        }
1862
    }
1863
1864
    /**
1865
    * Suspend a reseller and all accounts owned by a reseller
1866
    *
1867
    * This function, when called will suspend a reseller account and all account owned by said reseller
1868
    * @param string $reseller The reseller account to be suspended
1869
    * @param string $reason (optional) The reason for suspending the reseller account
1870
    * @return mixed
1871
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SuspendReseller XML API Call documentation
1872
    */
1873 View Code Duplication
    public function suspendreseller($reseller, $reason = null)
0 ignored issues
show
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...
1874
    {
1875
        if (!isset($reseller) ) {
1876
            error_log("suspendreseller requires that the reseller's username is passed to it");
1877
1878
            return false;
1879
        }
1880
        $params = array("user" => $reseller);
1881
        if ($reason) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $reason of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
1882
            $params['reason'] = $reason;
1883
        }
1884
1885
        return $this->xmlapi_query('suspendreseller', $params);
1886
    }
1887
1888
1889
    /**
1890
    * Unsuspend a Reseller Account
1891
    *
1892
    * This function will unsuspend a reseller account and all accounts owned by the reseller in question
1893
    * @param string $user The username of the reseller to be unsuspended
1894
    * @return mixed
1895
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/UnsuspendReseller XML API Call documentation
1896
    */
1897
    public function unsuspendreseller($user)
1898
    {
1899
        if (!isset($user) ) {
1900
            error_log("unsuspendreseller requires that a username is passed to it");
1901
1902
            return false;
1903
        }
1904
1905
        return $this->xmlapi_query('unsuspendreseller', array('user' => $user));
1906
    }
1907
1908
    /**
1909
    * Get the number of accounts owned by a reseller
1910
    *
1911
    * This function will return the number of accounts owned by a reseller account, along with information such as the number of active, suspended and accounting limits
1912
    * @param string $user The username of the reseller to get account information from
1913
    * @return mixed
1914
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AcctCounts XML API Call documentation
1915
    */
1916
    public function acctcounts($user)
1917
    {
1918
        if (!isset($user)) {
1919
            error_log('acctcounts requires that a username is passed to it');
1920
1921
            return false;
1922
        }
1923
1924
        return $this->xmlapi_query('acctcounts', array('user' => $user) );
1925
    }
1926
1927
    /**
1928
    * Set a reseller's nameservers
1929
    *
1930
    * This function allows you to change the nameservers that account created by a specific reseller account will use.
1931
    * If this function is not passed a $nameservers parameter, it will reset the nameservers for the reseller to the servers's default
1932
    * @param string $user The username of the reseller account to grab reseller accounts from
1933
    * @param string $nameservers A comma seperate list of nameservers
1934
    * @return mixed
1935
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResellerNameservers XML API Call documentation
1936
    */
1937 View Code Duplication
    public function setresellernameservers($user, $nameservers = null)
0 ignored issues
show
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...
1938
    {
1939
        if (!isset($user)) {
1940
            error_log("setresellernameservers requires that a username is passed to it");
1941
1942
            return false;
1943
        }
1944
        $params = array('user' => $user);
1945
        if ($nameservers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $nameservers of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
1946
            $params['nameservers'] = $nameservers;
1947
        }
1948
1949
        return $this->xmlapi_query('setresellernameservers', $params);
1950
    }
1951
1952
    ####
1953
    # Server information
1954
    ####
1955
1956
    /**
1957
    * Get a server's hostname
1958
    *
1959
    * This function will return a server's hostname
1960
    * @return mixed
1961
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DisplayServerHostname XML API Call documentation
1962
    */
1963
    public function gethostname()
1964
    {
1965
        return $this->xmlapi_query('gethostname');
1966
    }
1967
1968
    /**
1969
    * Get the version of cPanel running on the server
1970
    *
1971
    * This function will return the version of cPanel/WHM running on the remote system
1972
    * @return mixed
1973
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DisplaycPanelWHMVersion XML API Call documentation
1974
    */
1975
    public function version()
1976
    {
1977
        return $this->xmlapi_query('version');
1978
    }
1979
1980
1981
    /**
1982
    * Get Load Average
1983
    *
1984
    * This function will return the loadavg of the remote system
1985
    *
1986
    * @return mixed
1987
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/LoadAvg XML API Call documentation
1988
    */
1989
    public function loadavg()
1990
    {
1991
        return $this->xmlapi_query('loadavg');
1992
    }
1993
1994
    /**
1995
    * Get a list of languages on the remote system
1996
    *
1997
    * This function will return a list of available langauges for the cPanel interface
1998
    * @return mixed
1999
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/GetLangList XML API Call documentation
2000
    *
2001
    */
2002
    public function getlanglist()
2003
    {
2004
        return $this->xmlapi_query('getlanglist');
2005
    }
2006
2007
    ####
2008
    # Server administration
2009
    ####
2010
2011
    /**
2012
    * Reboot server
2013
    *
2014
    * This function will reboot the server
2015
    * @param boolean $force This will determine if the server should be given a graceful or forceful reboot
2016
    * @return mixed
2017
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/RebootServer XML API Call documentation
2018
    */
2019
    public function reboot($force = false)
2020
    {
2021
        if ($force) {
2022
            return $this->xmlapi_query('reboot', array('force' => '1'));
2023
        }
2024
2025
        return $this->xmlapi_query('reboot');
2026
    }
2027
2028
    /**
2029
    * Add an IP to a server
2030
    *
2031
    * This function will add an IP alias to your server
2032
    * @param string $ip The IP to be added
2033
    * @param string $netmask The netmask of the IP to be added
2034
    * @return mixed
2035
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/AddIPAddress XML API Call documentation
2036
    */
2037 View Code Duplication
    public function addip($ip, $netmask)
0 ignored issues
show
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...
2038
    {
2039
        if (!isset($ip) || !isset($netmask)) {
2040
            error_log("addip requires that an IP address and Netmask are passed to it");
2041
2042
            return false;
2043
        }
2044
2045
        return $this->xmlapi_query('addip', array('ip' => $ip, 'netmask' => $netmask));
2046
    }
2047
2048
    // This function allows you to delete an IP address from your server.
2049
    /**
2050
    * Delete an IP from a server
2051
    *
2052
    * Remove an IP from the server
2053
    * @param string $ip The IP to remove
2054
    * @param string $ethernetdev The ethernet device that the IP is bound to
2055
    * @param bool $skipifshutdown Whether the function should remove the IP even if the ethernet interface is down
2056
    * @return mixed
2057
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DeleteIPAddress XML API Call documentation
2058
    */
2059
    public function delip($ip, $ethernetdev = null, $skipifshutdown = false)
2060
    {
2061
        $args = array();
2062
        if (!isset($ip)) {
2063
            error_log("delip requires that an IP is defined in the array passed to it");
2064
2065
            return false;
2066
        }
2067
        $args['ip'] = $ip;
2068
        if ($ethernetdev) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $ethernetdev of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
2069
            $args['ethernetdev'] = $ethernetdev;
2070
        }
2071
        $args['skipifshutdown'] = ($skipifshutdown) ? '1' : '0';
2072
2073
        return $this->xmlapi_query('delip', $args);
2074
    }
2075
2076
    /**
2077
    * List IPs
2078
    *
2079
    * This should return a list of IPs on a server
2080
    * @return mixed
2081
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DeleteIPAddress XML API Call documentation
2082
    */
2083
    public function listips()
2084
    {
2085
        return $this->xmlapi_query('listips');
2086
    }
2087
2088
    /**
2089
    * Set Hostname
2090
    *
2091
    * This function will allow you to set the hostname of the server
2092
    * @param string $hostname the hostname that should be assigned to the serve
2093
    * @return mixed
2094
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetHostname XML API Call documentation
2095
    */
2096
    public function sethostname($hostname)
2097
    {
2098
        if (!isset($hostname)) {
2099
            error_log("sethostname requires that hostname is passed to it");
2100
2101
            return false;
2102
        }
2103
2104
        return $this->xmlapi_query('sethostname', array('hostname' => $hostname));
2105
    }
2106
2107
    /**
2108
    * Set the resolvers used by the server
2109
    *
2110
    * This function will set the resolvers in /etc/resolv.conf for the server
2111
    * @param string $nameserver1 The IP of the first nameserver to use
2112
    * @param string $nameserver2 The IP of the second namesever to use
2113
    * @param string $nameserver3 The IP of the third nameserver to use
2114
    * @param string $nameserver4 The IP of the forth nameserver to use
0 ignored issues
show
Documentation introduced by
There is no parameter named $nameserver4. Did you maybe mean $nameserver1?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2115
    * @return mixed
2116
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/SetResolvers XML API Call documentation
2117
    */
2118
    public function setresolvers($nameserver1, $nameserver2 = null, $nameserver3 = null)
2119
    {
2120
        $args = array();
2121
        if (!isset($nameserver1)) {
2122
            error_log("setresolvers requires that nameserver1 is defined in the array passed to it");
2123
2124
            return false;
2125
        }
2126
        $args['nameserver1'] = $nameserver1;
2127
        if ($nameserver2) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $nameserver2 of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
2128
            $args['nameserver2'] = $nameserver2;
2129
        }
2130
        if ($nameserver3) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $nameserver3 of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
2131
            $args['nameserver3'] = $nameserver3;
2132
        }
2133
2134
        return $this->xmlapi_query('setresolvers', $args);
2135
    }
2136
2137
    /**
2138
    * Display bandwidth Usage
2139
    *
2140
    * This function will return all bandwidth usage information for the server,
2141
    * The arguments for this can be passed in via an associative array, the elements of this array map directly to the
2142
    * parameters of the call, please see the XML API Call documentation for more information
2143
    * @param array $args The configuration for what bandwidth information to display
2144
    * @return mixed
2145
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ShowBw XML API Call documentation
2146
    */
2147
    public function showbw($args = null)
2148
    {
2149
        if (is_array($args)) {
2150
            return $this->xmlapi_query('showbw', $args);
2151
        }
2152
2153
        return $this->xmlapi_query('showbw');
2154
    }
2155
2156
    public function nvset($key, $value)
2157
    {
2158
        if (!isset($key) || !isset($value)) {
2159
            error_log("nvset requires that key and value are passed to it");
2160
2161
            return false;
2162
        }
2163
2164
        return $this->xmlapi_query('nvset', array('key' => $key, 'value' => $value));
2165
    }
2166
2167
    // This function allows you to retrieve and view a non-volatile variable's value.
2168
    public function nvget($key)
2169
    {
2170
        if (!isset($key)) {
2171
            error_log("nvget requires that key is passed to it");
2172
2173
            return false;
2174
        }
2175
2176
        return $this->xmlapi_query('nvget', array('key' => $key));
2177
    }
2178
2179
    ####
2180
    # Service functions
2181
    ####
2182
2183
    /**
2184
    * Restart a Service
2185
    *
2186
    * This function allows you to restart a service on the server
2187
    * @param string $service the service that you wish to restart please view the XML API Call documentation for acceptable values to this parameters
2188
    * @return mixed
2189
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/RestartService XML API Call documentation
2190
    */
2191
    public function restartsrv($service)
2192
    {
2193
        if (!isset($service)) {
2194
            error_log("restartsrv requires that service is passed to it");
2195
2196
            return false;
2197
        }
2198
2199
        return $this->xmlapi_query('restartservice', array('service' => $service));
2200
    }
2201
2202
    /**
2203
    * Service Status
2204
    *
2205
    * This function will return the status of all services on the and whether they are running or not
2206
    * @param array $args A single service to filter for.
2207
    * @return mixed
2208
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ServiceStatus XML API Call documentation
2209
    */
2210
    public function servicestatus($args=array())
2211
     {
2212
        if (!empty($args) && !is_array($args)) {
2213
            $args = array('service'=>$args);
2214
        } elseif (!is_array($args)) {
2215
            $args = array();
2216
        }
2217
2218
        return $this->xmlapi_query('servicestatus', $args);
2219
     }
2220
2221
    /**
2222
    * Configure A Service
2223
    *
2224
    * This function will allow you to enabled or disable services along with their monitoring by chkservd
2225
    * @param string $service The service to be monitored
2226
    * @param bool $enabled Whether the service should be enabled or not
2227
    * @param bool $monitored Whether the service should be monitored or not
2228
    * @return mixed
2229
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ConfigureService XML API Call documentation
2230
    */
2231
    public function configureservice($service, $enabled = true, $monitored = true)
2232
    {
2233
        if (!isset($service)) {
2234
            error_log("configure service requires that a service is passed to it");
2235
2236
            return false;
2237
        }
2238
        $params = array('service' => $service);
2239
2240
        if ($enabled) {
2241
            $params['enabled'] = 1;
2242
        } else {
2243
            $params['enabled'] = 0;
2244
        }
2245
2246
        if ($monitored) {
2247
            $params['monitored'] = 1;
2248
        } else {
2249
            $params['monitored'] = 0;
2250
        }
2251
2252
        return $this->xmlapi_query('configureservice', $params);
2253
2254
    }
2255
2256
    ####
2257
    # SSL functions
2258
    ####
2259
2260
    /**
2261
    * Display information on an SSL host
2262
    *
2263
    * This function will return information on an SSL Certificate, CSR, cabundle and SSL key for a specified domain
2264
    * @param array $args Configuration information for the SSL certificate, please see XML API Call documentation for required values
2265
    * @return mixed
2266
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/FetchSSL XML API Call documentation
2267
    */
2268
    public function fetchsslinfo($args)
2269
    {
2270
        if ( (isset($args['domain']) && isset($args['crtdata'])) || (!isset($args['domain']) && !isset($args['crtdata'])) ) {
2271
            error_log("fetchsslinfo requires domain OR crtdata is passed to it");
2272
        }
2273
        if (isset($args['crtdata'])) {
2274
            // crtdata must be URL-encoded!
2275
            $args['crtdata'] = urlencode(trim($args['crtdata']));
2276
        }
2277
2278
        return $this->xmlapi_query('fetchsslinfo', $args);
2279
    }
2280
2281
    /**
2282
    * Generate an SSL Certificate
2283
    *
2284
    * This function will generate an SSL Certificate, the arguments for this map directly to the call for the XML API call.  Please consult the XML API Call documentation for more information
2285
    * @param array $args the configuration for the SSL Certificate being generated
2286
    * @return mixed
2287
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/GenerateSSL XML API Call documentation
2288
    */
2289
    public function generatessl($args)
2290
    {
2291
        if (!isset($args['xemail']) || !isset($args['host']) || !isset($args['country']) || !isset($args['state']) || !isset($args['city']) || !isset($args['co']) || !isset($args['cod']) || !isset($args['email']) || !isset($args['pass'])) {
2292
            error_log("generatessl requires that xemail, host, country, state, city, co, cod, email and pass are defined in the array passed to it");
2293
2294
            return false;
2295
        }
2296
2297
        return $this->xmlapi_query('generatessl', $args);
2298
    }
2299
2300
    /**
2301
    * Install an SSL certificate
2302
    *
2303
    * This function will allow you to install an SSL certificate that is uploaded via the $argument parameter to this call.  The arguments for this call map directly to the parameters for the XML API call,
2304
    * please consult the XML API Call documentation for more information.
2305
    * @param array $args The configuration for the SSL certificate
2306
    * @return mixed
2307
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/InstallSSL XML API Call documentation
2308
    */
2309
    public function installssl($args)
2310
    {
2311
        if (!isset($args['user']) || !isset($args['domain']) || !isset($args['cert']) || !isset($args['key']) || !isset($args['cab']) || !isset($args['ip'])) {
2312
            error_log("installssl requires that user, domain, cert, key, cab and ip are defined in the array passed to it");
2313
2314
            return false;
2315
        }
2316
2317
        return $this->xmlapi_query('installssl', $args);
2318
    }
2319
2320
    /**
2321
    * List SSL Certs
2322
    *
2323
    * This function will list all SSL certificates installed on the server
2324
    * @return mixed
2325
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListSSL XML API Call documentation
2326
    */
2327
    public function listcrts()
2328
    {
2329
        return $this->xmlapi_query('listcrts');
2330
    }
2331
2332
    ####
2333
    # cPanel API1 functions
2334
    # Note: A cPanel account username is required
2335
    # Some cPanel features must be enabled to be able to use some function (f.e. park, unpark)
2336
    ####
2337
2338
    // This API1 function adds a emailaccount for a specific user.
2339
    public function addpop($username, $args)
2340
    {
2341
        if (!isset($username) || !isset($args)) {
2342
            error_log("addpop requires that a user and args are passed to it");
2343
2344
            return false;
2345
        }
2346
        if (is_array($args) && (sizeof($args) < 3)) {
2347
            error_log("addpop requires that args at least contains an email_username, email_password and email_domain");
2348
2349
            return false;
2350
        }
2351
2352
        return $this->api1_query($username, 'Email', 'addpop', $args);
2353
    }
2354
2355
    // This API function displays a list of all parked domains for a specific user.
2356
    public function park($username, $newdomain, $topdomain)
2357
    {
2358
        $args = array();
2359
        if ( (!isset($username)) && (!isset($newdomain)) ) {
2360
            error_log("park requires that a username and new domain are passed to it");
2361
2362
            return false;
2363
        }
2364
        $args['domain'] = $newdomain;
2365
        if ($topdomain) {
2366
            $args['topdomain'] = $topdomain;
2367
        }
2368
2369
        return $this->api2_query($username, 'Park', 'park', $args);
2370
    }
2371
2372
    // This API function displays a list of all parked domains for a specific user.
2373
    public function unpark($username, $domain)
2374
    {
2375
        $args = array();
2376
        if ( (!isset($username)) && (!isset($domain)) ) {
2377
            error_log("unpark requires that a username and domain are passed to it");
2378
2379
            return false;
2380
        }
2381
        $args['domain'] = $domain;
2382
2383
        return $this->api2_query($username, 'Park', 'unpark', $args);
2384
    }
2385
2386
    ####
2387
    # cPanel API2 functions
2388
    # Note: A cPanel account username is required
2389
    # Some cPanel features must be enabled to be able to use some function
2390
    ####
2391
2392
    // This API2 function allows you to view the diskusage of a emailaccount.
2393 View Code Duplication
    public function getdiskusage($username, $args)
0 ignored issues
show
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...
2394
    {
2395
        if (!isset($username) || !isset($args)) {
2396
            error_log("getdiskusage requires that a username and args are passed to it");
2397
2398
            return false;
2399
        }
2400
        if (is_array($args) && (!isset($args['domain']) || !isset($args['login']))) {
2401
            error_log("getdiskusage requires that args at least contains an email_domain and email_username");
2402
2403
            return false;
2404
        }
2405
2406
        return $this->api2_query($username, 'Email', 'getdiskusage', $args);
2407
    }
2408
2409
    // This API2 function allows you to list ftp-users associated with a cPanel account including disk information.
2410 View Code Duplication
    public function listftpwithdisk($username)
0 ignored issues
show
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...
2411
    {
2412
        if (!isset($username)) {
2413
            error_log("listftpwithdisk requires that user is passed to it");
2414
2415
            return false;
2416
        }
2417
2418
        return $this->api2_query($username, 'Ftp', 'listftpwithdisk');
2419
    }
2420
2421
    // This API2 function allows you to list ftp-users associated with a cPanel account.
2422 View Code Duplication
    public function listftp($username)
0 ignored issues
show
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...
2423
    {
2424
        if (!isset($username)) {
2425
            error_log("listftp requires that user is passed to it");
2426
2427
            return false;
2428
        }
2429
2430
        return $this->api2_query($username, 'Ftp', 'listftp');
2431
    }
2432
2433
    // This API function displays a list of all parked domains for a specific user.
2434 View Code Duplication
    public function listparkeddomains($username, $domain = null)
0 ignored issues
show
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...
2435
    {
2436
        $args = array();
2437
        if (!isset($username)) {
2438
            error_log("listparkeddomains requires that a user is passed to it");
2439
2440
            return false;
2441
        }
2442
        if (isset($domain)) {
2443
            $args['regex'] = $domain;
2444
2445
            return $this->api2_query($username, 'Park', 'listparkeddomains', $args);
2446
        }
2447
2448
        return $this->api2_query($username, 'Park', 'listparkeddomains');
2449
    }
2450
2451
    // This API function displays a list of all addon domains for a specific user.
2452 View Code Duplication
    public function listaddondomains($username, $domain = null)
0 ignored issues
show
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...
2453
    {
2454
        $args = array();
2455
        if (!isset($username)) {
2456
            error_log("listaddondomains requires that a user is passed to it");
2457
2458
            return false;
2459
        }
2460
        if (isset($domain)) {
2461
            $args['regex'] = $domain;
2462
2463
            return $this->api2_query($username, 'AddonDomain', 'listaddondomains', $args);
2464
        }
2465
2466
        return $this->api2_query($username, 'Park', 'listaddondomains');
2467
    }
2468
2469
    // This API function displays a list of all selected stats for a specific user.
2470
    public function stat($username, $args = null)
2471
    {
2472
        if ( (!isset($username)) || (!isset($args)) ) {
2473
            error_log("stat requires that a username and options are passed to it");
2474
2475
            return false;
2476
        }
2477
        if (is_array($args)) {
2478
        $display = '';
2479
            foreach ($args as $value) {
2480
                $display .= $value . '|';
2481
            }
2482
            $values['display'] = substr($display, 0, -1);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2483
        } else {
2484
            $values['display'] = substr($args, 0, -1);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2485
        }
2486
2487
        return $this->api2_query($username, 'StatsBar', 'stat', $values);
2488
    }
2489
2490
}
2491