-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcpanel.py
More file actions
1160 lines (839 loc) · 41.4 KB
/
cpanel.py
File metadata and controls
1160 lines (839 loc) · 41.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Python library for WHM API 1
https://documentation.cpanel.net/display/SDK/Guide+to+WHM+API+1
** Note: there are many more WHM/Cpanel functions available that are not implemented below.
@author Benton Snyder
@website http://bensnyde.me
@email benton@bensnyde.me
@created 7/24/13
@updated 9/28/20
"""
import base64
import httplib
import urllib
import json
class Cpanel:
def __init__(self, base_url, username, password):
self.base_url = base_url
self.headers = {
'Authorization': 'Basic ' + base64.b64encode(f"{self.username}:{self.password}".encode()).decode('ascii')
}
def __cQuery(self, resource, kwargs={}):
"""Query WHM API
Parameters
resource: str api resource uri
kwargs: dict args
Returns
JSON response
"""
try:
kwargs['api.version'] = 1
conn = httplib.HTTPSConnection(self.base_url, 2087)
conn.request('GET', f'/json-api/{resource}?{urllib.urlencode(kwargs)}', headers=self.headers)
response = conn.getresponse()
data = json.loads(response.read())
conn.close()
return data
except:
logging.exception(f"Error fetching {resource}")
def createAccount(self, username, domain, kwargs):
"""Create Cpanel Account
This function creates a hosting account and sets up its associated domain information.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+createacct
"""
kwargs['username'] = username
kwargs['domain'] = domain
return self.__cQuery('createacct', kwargs)
def changeAccountPassword(self, username, password, update_db_password=True):
"""Set Cpanel Account Password
This function changes the password of a domain owner (cPanel) or reseller (WHM) account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+passwd
"""
return self.__cQuery('passwd', {
'user': username,
'pass': password,
'db_pass_update': update_db_password
})
def limitAccountBandwidth(self, username, bwlimit):
"""Set Cpanel Account Bandwidth Limit
This function modifies the bandwidth usage (transfer) limit for a specific account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+limitbw
"""
return self.__cQuery('limitbw', {
'user': username,
'bwlimit': bwlimit
})
def listAccounts(self, kwargs={}):
"""List Cpanel Accounts
This function lists all accounts on the server, and also allows you to search for a specific account or set of accounts.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listaccts
"""
return self.__cQuery('listaccts', kwargs)
def modifyAccount(self, username, kwargs={}):
"""Edit Cpanel Account
This function modifies settings for an account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+modifyacct
"""
kwargs['user'] = username
return self.__cQuery('modifyacct', kwargs)
def changeAccountDiskQuota(self, username, quota):
"""Set Cpanel Account Disk Quota
This function changes an account's disk space usage quota.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+editquota
"""
return self.__cQuery('editquota', {
'user': username,
'quota': quota
})
def getAccountSummary(self, username):
"""Get Cpanel Account Summary
This function displays pertinent information about a specific account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+accountsummary
"""
return self.__cQuery('accountsummary', {
'user': username
})
def suspendAccount(self, username, reason=""):
"""Suspend Cpanel Account
This function will allow you to prevent a cPanel user from accessing his or her account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+suspendacct
"""
return self.__cQuery('suspendacct', {
'user': username,
'reason': reason
})
def listSuspendedAccounts(self):
"""List Suspended Cpanel Accounts
This function will generate a list of suspended accounts.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listsuspended
"""
return self.__cQuery('listsuspended')
def terminateAccount(self, username, keep_dns=False):
"""Terminate Cpanel Account
This function permanently removes a cPanel account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+removeacct
"""
return self.__cQuery('removeacct', {
'user': username,
'keepdns': keep_dns
})
def unsuspendAccount(self, username):
"""Unsuspend Cpanel Account
This function will unsuspend a suspended account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+unsuspendacct
"""
return self.__cQuery('unsuspendacct', {
'user': username
})
def changeAccountPackage(self, username, package):
"""Change Cpanel Account Package
This function changes the hosting package associated with a cPanel account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+changepackage
"""
return self.__cQuery('changepackage', {
'user': username,
'pkg': package
})
def getDomainUserdata(self, domain):
"""Get User Data By Domain
This function lets you obtain user data for a specific domain.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+domainuserdata
"""
return self.__cQuery('domainuserdata', {
'domain': domain
})
def changeDomainIpAddress(self, domain, ip_address):
"""Set Domain's IP Address
This function allows you to change the IP address of a website hosted on your server
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setsiteip
"""
return self.__cQuery('setsiteip', {
'domain': domain,
'ip=': ip_address
})
def changeAccountIpAddress(self, username, ip_address):
"""Set Cpanel Account IP Address
This function allows you to change the IP address of a user account hosted on your server
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setsiteip
"""
return self.__cQuery('setsiteip', {
'user': username,
'ip': ip_address
})
def restoreAccountBackup(self, username, backup_type="daily", all_services=True, ip=True, mail=True, mysql=True, subs=True):
"""Restore Cpanel Account From Backup
This function allows you to restore a user's account from a backup file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restoreaccount
"""
if backup_type not in ["daily", "weekly", "monthly"]:
raise Exception("Invalid backup_type.")
return self.__cQuery('restoreaccount', {
'user': username,
'type': backup_type,
'all': all_services
})
def setAccountDigestAuthentication(self, username, password, enable_digest=True):
"""Toggle Cpanel Account's Digest Authentication
This function enables or disables Digest Authentication for a user account.
http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/SetDigestAuth -
"""
return self.__cQuery('set_digest_auth', {
'user': username,
'password': password,
'enabledigest': enable_digest
})
def getAccountDigestAuthentication(self, username):
"""Get Cpanel Account's Digest Authentication
This function will check whether a cPanel user has digest authentication enabled.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+set_digest_auth
"""
return self.__cQuery('has_digest_auth', {
'user': username
})
def getPrivileges(self):
"""Get Privileges
This function will generate a list of features you are allowed to use in WHM. Each feature will display either a 1 or 0.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+myprivs
"""
return self.__cQuery('myprivs')
def restoreAccountBackupQueued(self, username, restore_point, give_ip=False, mysql=True, subdomains=True, mail_config=True):
"""Start Restore Cpanel Account From Backup Job
This function allows you to restore a user's account from a backup file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_add_task
"""
return self.__cQuery('restore_queue_add_task', {
'user': username,
'restore_point': restore_point,
'give_ip': give_ip,
'mysql': mysql,
'subdomains': subdomains,
'mail_config': mail_config
})
def activateRestoreQueue(self):
"""Activate Restore Job Queue
This function allows you to activate the restore queue and start a process to restore all queued accounts.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_activate
"""
return self.__cQuery('restore_queue_activate')
def getRestoreQueueState(self):
"""Get Restore Job Queue State
This function allows you to see if the queue is actively in the restoration process for certain accounts.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_is_active
"""
return self.__cQuery('restore_queue_is_active')
def getRestoreQueueActive(self):
"""Get Active Jobs From Restore Queue
This function allows you to list all accounts currently in the restoration process.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_list_active
"""
return self.__cQuery('restore_queue_list_active')
def getRestoreQueueCompleted(self):
"""Get Completed Jobs From Restore Queue
This function allows you to list all completed restorations, successful restores, failed restores, and the restore log.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_list_completed
"""
return self.__cQuery('restore_queue_list_completed')
def clearRestoreQueuePendingTask(self, username):
"""Clear A Pending Job From Restore Queue
This function allows you to clear a single pending account from the Restoration Queue.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_pending_task
"""
return self.__cQuery('restore_queue_clear_pending_task', {
'user': username
})
def clearRestoreQueuePendingTasks(self):
"""Clear All Pending Jobs From Restore Queue
This function allows you to clear all pending accounts from the restore queue.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_all_pending_tasks
"""
return self.__cQuery('restore_queue_clear_all_pending_tasks')
def clearRestoreQueueCompletedTask(self, username):
"""Clear A Completed Job From Restore Queue
This function allows you to clear a single completed account from the Restoration Queue. The account
may have completed successfully, or the account may have failed to successfully complete.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_completed_task
"""
return self.__cQuery('restore_queue_clear_completed_task', {
'user': username
})
def clearRestoreQueueCompletedTasks(self):
"""Clear All Completed Jobs From Restore Queue
This function allows you to clear all successfully completed accounts from the Restoration Queue.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_all_completed_tasks
"""
return self.__cQuery('restore_queue_clear_all_completed_tasks')
def clearRestoreQueueFailedTasks(self):
"""Clear Failed Jobs From Restore Queue
This function allows you to clear all failed tasks from the Restoration Queue.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_all_failed_tasks
"""
return self.__cQuery('restore_queue_clear_all_failed_tasks')
def clearRestoreQueueAll(self):
"""Clear All Jobs From Restore Queue
This function allows you to clear all open, unresolved, or pending tasks from the Restoration Queue.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restore_queue_clear_all_tasks
"""
return self.__cQuery('restore_queue_clear_all_tasks')
def getBackupConfig(self):
"""Get Backup Configuration
This function allows you to receive detailed data from your backup destination configuration file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_config_get
"""
return self.__cQuery('backup_config_get')
def setBackupConfig(self, *args):
"""Set Backup Configuration
This function allows you to save the data from the backup configuration page and put the data in /var/cpanel/bakcups/config
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_config_set
"""
return self.__cQuery('backup_config_set')
def setBackupConfigAllUsers(self, state=True):
"""Set Backup Config For All Users
This function allows you to choose which Backup Configuration to use, and enable or disable backups for all users.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_skip_users_all
"""
return self.__cQuery('backup_skip_users_all', {
'state': state
})
def getBackupConfigAllUsers(self):
"""Get Backup Config For All Users
This function allows you to retrieve the value from the status log file in the backup_skip_users_all api call.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_skip_users_all_status
"""
return self.__cQuery('backup_skip_users_all_status')
def getBackupListFiles(self):
"""Get Backed Up Files
This function allows you to find all backup files available on the server. This
function also returns a list of users and dates so that the Restore Account(s) feature in WHM can show them.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_set_list
"""
return self.__cQuery('backup_set_list')
def getBackupListDates(self):
"""Get Backed Up File Dates
This function allows you to retrieve a list of all dates with a backup file saved.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_date_list
"""
return self.__cQuery('backup_date_list')
def getBackupsByDate(self, date):
"""Get Backups By Date
This function returns a list all users with a backup file saved on a specific date that you choose.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_user_list
"""
return self.__cQuery('backup_user_list', {
'restore_point': date
})
def validateBackupDestination(self, destination_id, disable_on_fail=False):
"""Validate Backup Destination
This function allows you to run a validation routine on a specified backup destination.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_validate
"""
return self.__cQuery('backup_destination_validate', {
'id': destination_id,
'disableonfail': disable_on_fail
})
def addBackupDestination(self, backup_type, kwargs):
"""Add Backup Destination
This function allows you to create a backup destination and save it to a config file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_add
"""
if backup_type not in ["FTP", "Local", "SFTP", "WebDav", "Custom"]:
raise Exception("Invalid backup_type")
kwargs['type'] = backup_type
return self.__cQuery('backup_destination_add', kwargs)
def setBackupDestination(self, destination_id, kwargs):
"""Set Backup Destination
This function allows you to modify the setup and data for a backup destination.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_set
"""
kwargs['id'] = destination_id
return self.__cQuery('backup_destination_set', kwargs)
def deleteBackupDestination(self, destination_id):
"""Delete Backup Destination
This function allows you to remove the backup destination config file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_delete
"""
return self.__cQuery('backup_destination_delete', {
'id': destination_id
})
def getBackupDestinationDetails(self, destination_id):
"""Get Backup Destination Details
This function allows you to retrieve detailed data for a specific backup destination from the backup destination config file.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_get
"""
return self.__cQuery('backup_destination_get', {
'id': destination_id
})
def listBackupDestionations(self):
"""List Backup Destinations
This function allows you to list all backup destinations, including their configuration information.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+backup_destination_list
"""
return self.__cQuery('backup_destination_list')
def addPackage(self, name, kwargs):
"""Add Hosting Package
This function adds a new hosting package.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+addpkg
"""
kwargs['name'] = name
return self.__cQuery('addpkg', kwargs)
def deletePackage(self, name):
"""Delete Hosting Package
This function deletes a specific hosting package.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+killpkg
"""
return self.__cQuery('killpkg', {
'pkg': name
})
def editPackage(self, name, kwargs):
"""Edit Hosting Package
This function edits all aspects of a specific hosting package.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+editpkg
"""
kwargs['name'] = name
return self.__cQuery('editpkg', kwargs)
def listPackages(self):
"""List Hosting Packages
This function lists all hosting packages available for use by the WHM user who is currently logged in.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listpkgs
"""
return self.__cQuery('listpkgs')
def listFeatures(self):
"""List WHM Features
This function will retrieve a list of available features.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+getfeaturelist
"""
return self.__cQuery('getfeaturelist')
def restartService(self, service):
"""Restart Service
This function restarts a service (daemon) on the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+restartservice
"""
return self.__cQuery('restartservice', {
'service': service
})
def getServiceStatus(self, service):
"""Get Service Status
This function tells you which services (daemons) are installed and enabled on, and monitored by, your server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+servicestatus
"""
return self.__cQuery('servicestatus', {
'service': service
})
def configureService(self, service, enabled=True, monitored=True):
"""Configure Service
This function allows you to enable or disable a service, and enable or disable monitoring of that
service in the same manner as the WHM Service Manager.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+configureservice
"""
return self.__cQuery('configureservice', {
'service': service,
'enabled': enabled,
'monitored': monitored
})
def getSSLDetails(self, domain):
"""Get SSL Details
This function displays the SSL certificate, private key, and CA bundle/intermediate certificate associated with a specified domain.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+fetchsslinfo
"""
return self.__cQuery('fetchsslinfo', {
'domain': domain
})
def generateSSL(self, xemail, host, country, state, city, co, cod, email, password):
"""Generate SSL Certificate
This function generates an SSL certificate.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+generatessl
"""
return self.__cQuery('generatessl', {
'xemail': xemail,
'host': host,
'country': country,
'state': state,
'city': city,
'co': co,
'cod': cod,
'email': email,
'pass': password
})
def installSSL(self, username, domain, cert, key, cab, ip):
"""Install SSL Certificate
This function installs an SSL certificate.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+installssl
"""
return self.__cQuery('installssl', {
'user': username,
'domain': domain,
'cert': cert,
'key': key,
'cab': cab,
'ip': ip
})
def listSSL(self):
"""List SSL Certificates
This function will list all domains on the server that have SSL certificates installed.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listcrts
"""
return self.__cQuery('listcrts')
def setPrimaryDomain(self, servername, vtype="std"):
"""Set Cpanel Account's Primary Domain
This function allows WHM users to set the primary domain on an IP address and port (ssl or std)
for their accounts' sites. The primary domain refers to the virtual host that will be served when
the IP address is accessed directly.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+set_primary_servername
"""
return self.__cQuery('set_primary_servername', {
'servername': servername,
'type': vtype
})
def checkSNI(self):
"""Check For SNI
This function allows WHM users to see if the server supports SNI, which allows for multiple SSL certificates per IP address and port number.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+is_sni_supported
"""
return self.__cQuery('is_sni_supported')
def installServiceSSL(self, service, crt, key, cabundle):
"""Install SSL Certificate to System Service
This function allows WHM users to install a new certificate on a service.
These services are ftp, exim, dovecot, courier, and cpanel.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+install_service_ssl_certificate
"""
return self.__cQuery('install_service_ssl_certificate', {
'service': service,
'crt': crt,
'key': key,
'cabundle': cabundle
})
def regenerateServiceSSL(self, service):
"""Regenerate System Service's SSL Certificate
This function allows WHM users to regenerate a self-signed certificate and assign the certificate to a service.
These services are ftp, exim, dovecot, courier, and cpanel.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+reset_service_ssl_certificate
"""
return self.__cQuery('reset_service_ssl_certificate', {
'service': service
})
def getServiceSSL(self):
"""Get System Service's SSL Certificate
This function allows WHM users to retrieve a list of services and their corresponding certificates.
These services are ftp, exim, dovecot, courier, and cpanel.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+fetch_service_ssl_components
"""
return self.__cQuery('fetch_service_ssl_components')
def demoteReseller(self, username):
"""Demote Reseller
This function removes reseller status from an account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+unsetupreseller
"""
return self.__cQuery('unsetupreseller', {
'user': username
})
def promoteReseller(self, username, make_owner=False):
"""Promote Reseller
This function gives reseller status to an existing account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setupreseller
"""
return self.__cQuery('setupreseller', {
'user': username,
'makeowner': make_owner
})
def createResellerACL(self, acllist, kwargs):
"""Create Reseller ACL
This function creates a new reseller ACL list.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+saveacllist
"""
kwargs['acllist'] = acllist
return self.__cQuery('saveacllist', kwargs)
def listResellerACL(self):
"""List Reseller ACL
This function lists the saved reseller ACL lists on the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listacls
"""
return self.__cQuery('listacls')
def listResellers(self):
"""List Resellers
This function lists the usernames of all resellers on the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listresellers
"""
return self.__cQuery('listresellers')
def getResellerDetails(self, reseller):
"""Get Reseller Details
This function shows account statistics for a specific reseller's accounts.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+resellerstats
"""
return self.__cQuery('resellerstats', {
'reseller': reseller
})
def getResellerIPs(self, username):
"""Get Reseller IP Addresses
This function will retrieve a list of IP Addresses that are available to a specified reseller.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+getresellerips
"""
return self.__cQuery('getresellerips', {
'user': username
})
def setResellerACL(self, reseller, kwargs):
"""Set Reseller ACL
This function specifies the ACL for a reseller, or modifies specific ACL items for a reseller.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setacls
"""
kwargs['reseller'] = reseller
return self.__cQuery('setacls', kwargs)
def deleteReseller(self, reseller, terminate_reseller=True):
"""Delete Reseller
This function will terminate a reseller's main account, as well as all accounts owned by the reseller.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+terminatereseller
"""
return self.__cQuery('terminatereseller', {
'reseller': reseller,
'terminatereseller': terminate_reseller,
'verify': '%20all%20the%20accounts%20owned%20by%20the%20reseller%20%s' % reseller
})
def allocateResellerIP(self, username, kwargs):
"""Allocate IP Addresses To Reseller
This function will add IP addresses to a reseller account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresellerips
"""
kwargs['user'] = username
return self.__cQuery('setresellerips', kwargs)
def setResellerResourceLimits(self, username, kwargs):
"""Set Reseller Resource Limits
This function allows you to specify the amount of bandwidth and disk space a reseller is able to use.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresellerlimits
"""
kwargs['user'] = username
return self.__cQuery('setresellerlimits', kwargs)
def setResellerPackage(self, username, kwargs):
"""Set Reseller Package
This function allows you to control which packages resellers are able to use.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresellerpackagelimit
"""
kwargs['user'] = username
return self.__cQuery('setresellerpackagelimit', kwargs)
def setResellerMainIP(self, username, ip):
"""Set Reseller Primary IP Address
This function will assign a main, shared IP address to a reseller.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresellermainip
"""
return self.__cQuery('setresellermainip', {
'user': username,
'ip': ip
})
def suspendReseller(self, username, reason=""):
"""Suspend Reseller
This function will allow you to suspend a reseller's account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+suspendreseller
"""
return self.__cQuery('suspendreseller', {
'user': username,
'reason': reason
})
def unsuspendReseller(self, username):
"""Unsuspend Reseller
This function allows you to unsuspend a reseller's account.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+unsuspendreseller
"""
return self.__cQuery('unsuspendreseller', {
'user': username
})
def setResellerNameservers(self, username, nameservers=""):
"""Set Reseller Nameserver Records
This function allows you to define a reseller's nameservers.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresellernameservers
"""
return self.__cQuery('setresellernameservers', {
'user': username,
'nameservers': nameservers
})
def listResellerAccounts(self, username):
"""List Reseller's Owned Accounts
This function lists the total number of accounts owned by a reseller, as well as
how many suspended accounts the reseller owns, and what the reseller's account creation limit is, if any.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+acctcounts
"""
return self.__cQuery('acctcounts', {
'user': username
})
def getServerHostname(self):
"""Get Server Hostname
This function lists the server's hostname.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+gethostname
"""
return self.__cQuery('gethostname')
def getServerVersion(self):
"""Get Server Version
This function will display the version of cPanel & WHM running on the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+version
"""
return self.__cQuery('version')
def getServerLoads(self):
"""Get Server Loads
This function will display your server's load average.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+loadavg
"""
return self.__cQuery('loadavg')
def getServerLoadsDetailed(self):
"""Get Detailed Server Loads
This function will calculate and return the system's load average.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+systemloadavg
"""
return self.__cQuery('systemloadavg')
def rebootServer(self, force=False):
"""Reboot Server
This function can restart a server gracefully or forcefully.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+reboot
"""
return self.__cQuery('reboot', {
'force': force
})
def addServerIP(self, ips, netmask):
"""Add IP Address to Server
Add new IP address(es) to WebHost Manager.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+addips
"""
return self.__cQuery('addips', {
'ips': ips,
'netmask': netmask
})
def deleteServerIP(self, ip, *args):
"""Delete IP Address From Server
This function deletes an IP address from the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+delip
"""
return self.__cQuery('delip', {
'ip': ip
})
def listServerIPs(self):
"""List Server IP Addresses
This function lists all IP addresses bound to network interfaces on the server.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listips
"""
return self.__cQuery('listips')
def setServerHostname(self, hostname):
"""Set Server Hostname
This function lets you change the server's hostname.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+sethostname
"""
return self.__cQuery('sethostname', {
'hostname': hostname
})
def setServerResolvers(self, nameserver1, nameserver2="", nameserver3=""):
"""Set Server DNS Resolvers
This function configures the nameservers that your server will use to resolve domain names.
https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+setresolvers
"""
return self.__cQuery('setresolvers', {
'nameserver1': nameserver1,
'nameserver2': nameserver2,