-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathi-mscp_keyhelp_migration.py
1950 lines (1745 loc) · 131 KB
/
i-mscp_keyhelp_migration.py
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
#!/usr/bin/python3
from __future__ import division
import os
import paramiko
import re
import requests
import subprocess
import sys
import time
import inquirer
from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException
from tqdm import tqdm
import _global_config
_global_config.init()
_global_config.createNeededScriptFolders()
# General
loggingFolder = _global_config.loggingFolder
logFile = _global_config.logFile
keyhelpDefaultHostingplan = _global_config.keyhelpDefaultHostingplan
keyhelpCreateRandomPassword = _global_config.keyhelpCreateRandomPassword
keyhelpSendloginCredentials = _global_config.keyhelpSendloginCredentials
keyhelpCreateSystemDomain = _global_config.keyhelpCreateSystemDomain
keyhelpDisableDnsForDomain = _global_config.keyhelpDisableDnsForDomain
keyhelpUpdatePasswordWithApi = _global_config.keyhelpUpdatePasswordWithApi
if keyhelpDisableDnsForDomain == 'ask':
keyhelpDisableDnsForDomain = str(keyhelpDisableDnsForDomain)
elif not keyhelpDisableDnsForDomain or keyhelpDisableDnsForDomain:
keyhelpSetDisableDnsForDomain = _global_config.keyhelpDisableDnsForDomain
else:
keyhelpSetDisableDnsForDomain = True
# KeyHelp
apiServerFqdn = _global_config.apiServerFqdn
apiKey = _global_config.apiKey
apiTimeout = _global_config.apiTimeout
keyhelpMinPasswordLenght = _global_config.keyhelpMinPasswordLenght
apiServerFqdnVerify = _global_config.apiServerFqdnVerify
keyhelpConfigfile = _global_config.keyhelpConfigfile
usingExistingKeyHelpUser = False
keyhelpAddDataStatus = False
# i-MSCP
imscpServerFqdn = _global_config.imscpServerFqdn
imscpSshUsername = _global_config.imscpSshUsername
imscpSshPort = _global_config.imscpSshPort
imscpSshTimeout = _global_config.imscpSshTimeout
imscpRootPassword = _global_config.imscpRootPassword
imscpRoundcubeContactImport = _global_config.imscpRoundcubeContactImport
imscpSshPublicKey = _global_config.imscpSshPublicKey
imscpDbDumpFolder = _global_config.imscpDbDumpFolder
if not apiServerFqdnVerify:
from urllib3.exceptions import InsecureRequestWarning
# Suppress only the single warning from urllib3 needed.
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
apiUrl = 'https://' + apiServerFqdn + '/api/v1/'
apiEndpointServer = 'server'
apiEndpointClients = 'clients'
apiEndpointHostingplans = 'hosting-plans'
apiEndpointDomains = 'domains'
apiEndpointCertificates = 'certificates'
apiEndPointEmails = 'emails'
apiEndpointDatabases = 'databases'
apiEndpointFtpusers = 'ftp-users'
apiEndpointDns = 'dns'
apiEndpointDirProtection = 'directory-protections'
headers = {
'X-API-Key': apiKey
}
class TqdmWrap(tqdm):
def viewBar(self, a, b):
self.total = int(b)
self.update(int(a - self.n)) # update pbar with increment
if __name__ == "__main__":
os.system('cls' if os.name == 'nt' else 'clear')
if not sys.version_info >= (3, 5, 3):
print('Python version too low. You need min. 3.5.3')
print('Your version is: ' + str(sys.version_info))
exit(1)
print('Starting migration i-MSCP to KeyHelp\n')
if os.path.exists(logFile):
os.remove(logFile)
##### Start get KeyHelp information #####
from _keyhelp import KeyhelpGetData, KeyHelpAddDataToServer
keyhelpInputData = KeyhelpGetData()
try:
responseApi = requests.get(apiUrl + apiEndpointServer + '/', headers=headers, timeout=apiTimeout,
verify=apiServerFqdnVerify)
try:
apiGetData = responseApi.json()
except ValueError:
print('ERROR - Check whether the KeyHelp API is activated!\n')
exit(1)
if responseApi.status_code == 200:
# print (responseApi.text)
if not keyhelpInputData.getServerDatabaseCredentials(keyhelpConfigfile):
exit(1)
_global_config.write_log('Debug KeyHelp informations:\nKeyHelp API Login successfull\n')
print('KeyHelp API Login successfull.')
keyhelpInputData.getServerInformations(apiGetData)
print('Checking whether Default hostingplan "' + keyhelpDefaultHostingplan + '" exist.')
if keyhelpInputData.checkExistDefaultHostingplan(keyhelpDefaultHostingplan):
migration_actions = ['a new KeyHelp account']
keyhelpInputData.getAllKeyHelpUsernames()
migration_actions = migration_actions + keyhelpInputData.keyhelpUsernames
questions = [
inquirer.List('keyhelpAction',
message="How do you want to migrate the i-MSCP account? Add to => ",
choices=migration_actions,
carousel=True
),
]
answers = inquirer.prompt(questions)
if answers['keyhelpAction'] == 'a new KeyHelp account':
while not keyhelpInputData.keyhelpDataComplete():
while not keyhelpInputData.checkExistKeyhelpUsername(
input("Enter a new KeyHelp username: ")):
continue
if keyhelpCreateRandomPassword:
print('Password is generated automatically!')
keyhelpInputData.keyhelpCreateRandomPassword(keyhelpMinPasswordLenght)
else:
while not keyhelpInputData.KeyhelpPassword(input(
"Enter a KeyHelp password (min. " + str(
keyhelpMinPasswordLenght) + " Chars): "), keyhelpMinPasswordLenght):
continue
while not keyhelpInputData.KeyhelpEmailaddress(input("Enter an email address: ")):
continue
while not keyhelpInputData.KeyhelpSurname(input("Enter a first name: ")):
continue
while not keyhelpInputData.KeyhelpName(input("Enter a last name: ")):
continue
while not keyhelpInputData.KeyhelpHostingplan(input(
"Which hosting plan should be used (Enter to use the default hosting plan)? ")):
continue
else:
keyhelpInputData.keyhelpData['kusername'] = str(answers['keyhelpAction'])
usingExistingKeyHelpUser = True
print('All KeyHelp data are now complete.\n\n')
if answers['keyhelpAction'] == 'a new KeyHelp account':
_global_config.write_log('Debug KeyHelp informations:\n' + str(keyhelpInputData.keyhelpData) + '\n')
else:
_global_config.write_log(
'Debug KeyHelp informations:\nUsing KeyHelp informations of exting account: ' + str(
answers['keyhelpAction']) + '\n')
_global_config.write_log('======================= End data for KeyHelp =======================\n\n\n')
else:
exit(1)
else:
_global_config.write_log("KeyHelp API Message: %i - %s, Message %s" % (
responseApi.status_code, responseApi.reason, apiGetData['message']) + "\n")
print("KeyHelp API Message: %i - %s, Message %s" % (
responseApi.status_code, responseApi.reason, apiGetData['message']))
exit(1)
except requests.Timeout as e:
_global_config.write_log("KeyHelp API Message: " + str(e) + "\n")
print("KeyHelp API Message: " + str(e))
exit(1)
##### Start get i-MSCP information #####
from _imscp import imscpGetData
imscpInputData = imscpGetData()
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
while not imscpInputData.imscpDataComplete():
imscpInputData.getImscpMySqlCredentials(client)
while not imscpInputData.getImscpUserWebData(input("Enter the i-MSCP user name (first domain): "), client):
continue
print('All i-MSCP data are now complete.\n')
_global_config.write_log('\nDebug i-MSCP informations:\n' + str(imscpInputData.imscpData) + '\n')
_global_config.write_log('i-MSCP sub domains:\n' + str(imscpInputData.imscpDomainSubDomains) + '\n')
_global_config.write_log('i-MSCP alias domains:\n' + str(imscpInputData.imscpDomainAliases) + '\n')
_global_config.write_log('i-MSCP alias sub domains:\n' + str(imscpInputData.imscpAliasSubDomains) + '\n')
_global_config.write_log('i-MSCP catchall emailadresses domain (catchall):\n' + str(
imscpInputData.imscpDomainEmailAddressNormalCatchAll) + '\n')
_global_config.write_log(
'i-MSCP emailadresses domain (normal):\n' + str(imscpInputData.imscpDomainEmailAddressNormal) + '\n')
_global_config.write_log('i-MSCP emailadresses domain (normal forward):\n' + str(
imscpInputData.imscpDomainEmailAddressNormalForward) + '\n')
_global_config.write_log(
'i-MSCP emailadresses domain (forward):\n' + str(imscpInputData.imscpDomainEmailAddressForward) + '\n')
_global_config.write_log('i-MSCP catch emailadresses sub domain (catchall):\n' + str(
imscpInputData.imscpDomainSubEmailAddressNormalCatchAll) + '\n')
_global_config.write_log(
'i-MSCP emailadresses sub domain (normal):\n' + str(imscpInputData.imscpDomainSubEmailAddressNormal) + '\n')
_global_config.write_log('i-MSCP emailadresses sub domain (normal forward):\n' + str(
imscpInputData.imscpDomainSubEmailAddressNormalForward) + '\n')
_global_config.write_log('i-MSCP emailadresses sub domain (forward):\n' + str(
imscpInputData.imscpDomainSubEmailAddressForward) + '\n')
_global_config.write_log('i-MSCP catchall emailadresses alias domains (catchall):\n' + str(
imscpInputData.imscpAliasEmailAddressNormalCatchAll) + '\n')
_global_config.write_log(
'i-MSCP emailadresses alias domains (normal):\n' + str(imscpInputData.imscpAliasEmailAddressNormal) + '\n')
_global_config.write_log('i-MSCP emailadresses alias domains (normal forward):\n' + str(
imscpInputData.imscpAliasEmailAddressNormalForward) + '\n')
_global_config.write_log('i-MSCP emailadresses alias domains (forward):\n' + str(
imscpInputData.imscpAliasEmailAddressForward) + '\n')
_global_config.write_log('i-MSCP catchall emailadresses alias sub domains (catchall):\n' + str(
imscpInputData.imscpAliasSubEmailAddressNormalCatchAll) + '\n')
_global_config.write_log('i-MSCP emailadresses alias sub domains (normal):\n' + str(
imscpInputData.imscpAliasSubEmailAddressNormal) + '\n')
_global_config.write_log('i-MSCP emailadresses alias sub domains (normal forward):\n' + str(
imscpInputData.imscpAliasSubEmailAddressNormalForward) + '\n')
_global_config.write_log('i-MSCP emailadresses alias sub domains (forward):\n' + str(
imscpInputData.imscpAliasSubEmailAddressForward) + '\n')
if imscpRoundcubeContactImport:
_global_config.write_log('i-MSCP roundcube users:\n' + str(imscpInputData.imscpRoundcubeUsers) + '\n')
_global_config.write_log('i-MSCP roundcube identities:\n' + str(imscpInputData.imscpRoundcubeIdentities) + '\n')
_global_config.write_log('i-MSCP roundcube contacts:\n' + str(imscpInputData.imscpRoundcubeContacts) + '\n')
_global_config.write_log('i-MSCP roundcube contactgroups:\n' + str(imscpInputData.imscpRoundcubeContactgroups) + '\n')
_global_config.write_log('i-MSCP roundcube contactgroup to contact:\n' + str(imscpInputData.imscpRoundcubeContact2Contactgroup) + '\n')
else:
_global_config.write_log('i-MSCP roundcube contacts:\nImport of i-MSCP roundcube is disabled for this server.')
_global_config.write_log('i-MSCP domain databases:\n' + str(imscpInputData.imscpDomainDatabaseNames) + '\n')
_global_config.write_log(
'i-MSCP domain database usernames:\n' + str(imscpInputData.imscpDomainDatabaseUsernames) + '\n')
_global_config.write_log('i-MSCP domain FTP users):\n' + str(imscpInputData.imscpFtpUserNames) + '\n')
_global_config.write_log('i-MSCP SSL certs:\n' + str(imscpInputData.imscpSslCerts) + '\n')
_global_config.write_log('i-MSCP HTACCESS users:\n' + str(imscpInputData.imscpDomainHtAcccessUsers) + '\n')
_global_config.write_log('i-MSCP domain dns:\n' + str(imscpInputData.imscpDnsEntries) + '\n')
_global_config.write_log('i-MSCP domain alias dns:\n' + str(imscpInputData.imscpDnsAliasEntries) + '\n')
if os.path.exists(
loggingFolder + '/' + imscpInputData.imscpData['iUsernameDomainIdna'] + '_get_data_from_imscp.log'):
os.remove(
loggingFolder + '/' + imscpInputData.imscpData['iUsernameDomainIdna'] + '_get_data_from_imscp.log')
if os.path.exists(logFile):
os.rename(logFile, loggingFolder + '/' + imscpInputData.imscpData[
'iUsernameDomainIdna'] + '_get_data_from_imscp.log')
except AuthenticationException:
print('Authentication failed, please verify your credentials!')
exit(1)
except SSHException as sshException:
print("Unable to establish SSH connection: %s" % sshException)
exit(1)
except BadHostKeyException as badHostKeyException:
print("Unable to verify server's host key: %s" % badHostKeyException)
exit(1)
finally:
client.close()
print('\nWe are ready to start. Check the logfile "' + imscpInputData.imscpData[
'iUsernameDomainIdna'] + '_get_data_from_imscp.log".')
if _global_config.ask_Yes_No('Do you want to start now [y/n]? '):
keyhelpAddData = KeyHelpAddDataToServer()
if not usingExistingKeyHelpUser:
print('Adding User "' + keyhelpInputData.keyhelpData['kusername'] + '" to Keyhelp')
keyhelpAddData.addKeyHelpDataToApi(apiEndpointClients, keyhelpInputData.keyhelpData)
keyhelpAddDataStatus = keyhelpAddData.status
else:
print('Using KeyHelp user "' + keyhelpInputData.keyhelpData['kusername'] + '" for migration')
if keyhelpAddDataStatus or usingExistingKeyHelpUser:
if not usingExistingKeyHelpUser:
addedKeyHelpUserId = keyhelpAddData.keyhelpApiReturnData['keyhelpUserId']
# Check whether the system user was added by KeyHelp
loop_starts = time.time()
while True:
now = time.time()
sys.stdout.write('\rWaiting since {0} seconds for Keyhelp. KeyHelp user was not added yet!'.format(
int(now - loop_starts)))
sys.stdout.flush()
time.sleep(1)
getUid = os.system('id ' + str(keyhelpInputData.keyhelpData['kusername'].lower()) + ' > /dev/null 2>&1')
if getUid == 0:
break
print('\r\nKeyHelpUser "' + keyhelpInputData.keyhelpData['kusername'] + '" added successfully.')
else:
if keyhelpInputData.getIdKeyhelpUsername(keyhelpInputData.keyhelpData['kusername']):
addedKeyHelpUserId = keyhelpInputData.keyhelpUserId
else:
exit(1)
print('Adding first domain "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '" to KeyHelpUser "' +
keyhelpInputData.keyhelpData['kusername'] + '".')
if keyhelpDisableDnsForDomain == 'ask':
if _global_config.ask_Yes_No('Do you want to active the dns zone for this domain [y/n]? '):
keyhelpSetDisableDnsForDomain = False
else:
keyhelpSetDisableDnsForDomain = True
keyhelpAddApiData = imscpInputData.imscpData
keyhelpAddApiData['keyhelpSetDisableDnsForDomain'] = keyhelpSetDisableDnsForDomain
keyhelpAddApiData['addedKeyHelpUserId'] = addedKeyHelpUserId
keyhelpAddData.addKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
keyHelpParentDomainId = keyhelpAddData.keyhelpApiReturnData['keyhelpDomainId']
domainParentId = imscpInputData.imscpData['iUsernameDomainId']
print('Domain "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '" added successfully.')
# Adding domain user dns entries if dns is activated
if not keyhelpSetDisableDnsForDomain:
print('\nStart adding domain dns entries.')
if bool(imscpInputData.imscpDnsEntries):
if keyhelpInputData.getDnsData(keyHelpParentDomainId,
imscpInputData.imscpData['iUsernameDomainIdna']):
# print(str(keyhelpInputData.keyhelpDomainDnsData))
# exit()
keyhelpAddData.updateKeyHelpDnsToApi(apiEndpointDns, keyhelpInputData.keyhelpDomainDnsData,
imscpInputData.imscpDnsEntries, keyHelpParentDomainId,
imscpInputData.imscpData['iUsernameDomainIdna'],
'domain')
if keyhelpAddData.status:
print('Domain dns for "' + imscpInputData.imscpData[
'iUsernameDomainIdna'] + '" updated successfully.')
else:
print('No DNS data for the domain "' + imscpInputData.imscpData[
'iUsernameDomainIdna'] + '" available.')
# Adding ftp users
if bool(imscpInputData.imscpFtpUserNames):
print('\nStart adding FTP users.')
for ftpUserKey, ftpUserValue in imscpInputData.imscpFtpUserNames.items():
# print(ftpUserKey, '->', ftpUserValue)
keyhelpAddApiData = {'iFtpUsername': str(ftpUserValue.get('iFtpUsername')),
'iFtpUserPassword': str(ftpUserValue.get('iFtpUserPassword')),
'iFtpUserHomeDir': imscpInputData.imscpData['iUsernameDomainIdna'],
'iOldFtpUserHomeDir': str(ftpUserValue.get('iFtpUserHomeDir')),
'addedKeyHelpUserId': addedKeyHelpUserId,
'iFtpInitialPassword': keyhelpAddData.keyhelpCreateRandomFtpPassword(
keyhelpMinPasswordLenght),
'kdatabaseRoot': keyhelpInputData.keyhelpData['kdatabaseRoot'],
'kdatabaseRootPassword': keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']}
keyhelpAddData.addKeyHelpDataToApi(apiEndpointFtpusers, keyhelpAddApiData)
if keyhelpAddData.status:
print('FTP user "' + keyhelpAddApiData['iFtpUsername'] + '" added successfully.\n')
else:
_global_config.write_log('ERROR "' + keyhelpAddApiData['iFtpUsername'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iFtpUsername'] + '" failed to add.\n')
else:
print('No FTP users to add.\n')
# Adding htaccess users
if bool(imscpInputData.imscpDomainHtAcccessUsers):
print('\nStart adding HTACCESS users.')
for HtAccessUserKey, HtAccessUserValue in imscpInputData.imscpDomainHtAcccessUsers.items():
# print(HtAccessUserKey, '->', HtAccessUserValue)
keyhelpAddApiData = {'iHtAccessUsername': str(HtAccessUserValue.get('iHtAccessUsername')),
'iHtAccessPassword': str(HtAccessUserValue.get('iHtAccessPassword')),
'iHtAccessPath': '/home/users/' + str(
keyhelpInputData.keyhelpData['kusername'].lower()) + '/www/' + str(
imscpInputData.imscpData['iUsernameDomainIdna']),
'iHtAccessAuthName': 'Migrated from i-MSCP - ' + str(
HtAccessUserValue.get('iHtAccessUsername')),
'addedKeyHelpUserId': addedKeyHelpUserId,
'kdatabaseRoot': keyhelpInputData.keyhelpData['kdatabaseRoot'],
'kdatabaseRootPassword': keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']}
if keyhelpUpdatePasswordWithApi:
keyhelpAddApiData['iHtAccessPath'] = str(imscpInputData.imscpData['iUsernameDomainIdna']) + '/'
keyhelpAddData.addKeyHelpDataToApi(apiEndpointDirProtection, keyhelpAddApiData)
if keyhelpAddData.status:
print('Directory protection "' + keyhelpAddApiData['iHtAccessUsername'] + '" added successfully.')
keyhelpAddApiData['keyhelpDirProtectionId'] = keyhelpAddData.keyhelpApiReturnData[
'keyhelpDirProtectionId']
else:
_global_config.write_log(
'ERROR Directory protection "' + keyhelpAddApiData['iHtAccessUsername'] + '" failed to add.')
print(
'ERROR Directory protection "' + keyhelpAddApiData['iHtAccessUsername'] + '" failed to add.\n')
else:
keyhelpAddData.addHtAccessUsersFromImscp(keyhelpAddApiData)
print('Directory protection "' + keyhelpAddApiData['iHtAccessUsername'] + '" added successfully.\n')
else:
print('No HTACCESS users to add.\n')
if bool(imscpInputData.imscpSslCerts['domainid-' + imscpInputData.imscpData['iUsernameDomainId']]):
# Adding SSL cert if exist
print('\nAdding SSL cert for domain "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '".')
for imscpSslKey, imscpSslValue in imscpInputData.imscpSslCerts[
'domainid-' + imscpInputData.imscpData['iUsernameDomainId']].items():
# print(imscpSslKey, '->', imscpSslValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'keyhelpDomainId': keyhelpAddData.keyhelpApiReturnData[
'keyhelpDomainId'],
'iSslDomainIdna': imscpInputData.imscpData['iUsernameDomainIdna'],
'iSslPrivateKey': imscpSslValue.get('iSslPrivateKey'),
'iSslCertificate': imscpSslValue.get('iSslCertificate'),
'iSslCaBundle': imscpSslValue.get('iSslCaBundle'),
'iSslHstsMaxAge': imscpSslValue.get('iSslHstsMaxAge')}
if imscpSslValue.get('iSslAllowHsts') == 'on':
keyhelpAddApiData['iSslAllowHsts'] = 'true'
else:
keyhelpAddApiData['iSslAllowHsts'] = 'false'
if imscpSslValue.get('iSslHstsIncludeSubdomains') == 'on':
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'true'
else:
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'false'
keyhelpAddData.addKeyHelpDataToApi(apiEndpointCertificates, keyhelpAddApiData)
if keyhelpAddData.status:
print('SSL cert for domain "' + keyhelpAddApiData['iSslDomainIdna'] + '" added successfully.')
print('Update "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
keyhelpAddApiData['keyhelpSslId'] = keyhelpAddData.keyhelpApiReturnData[
'keyhelpSslId']
keyhelpAddData.updateKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" updated succesfully with SSL cert.')
else:
_global_config.write_log(
'ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
print('ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.\n')
else:
_global_config.write_log(
'ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.')
print('ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.\n')
print('\nAdding email addresses for domain "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '".')
# Adding i-MSCP domain normal email addresses
for imscpEmailsDomainsArrayKey, imscpEmailsDomainsArrayValue in \
imscpInputData.imscpDomainEmailAddressNormal.items():
# print(imscpEmailsDomainsArrayKey, '->', imscpEmailsDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpDomainEmailAddressNormalCatchAll):
for domKey, domValue in imscpInputData.imscpDomainEmailAddressNormalCatchAll.items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData['kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsDomainsArrayValue.get('iEmailMailQuota')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsDomainsArrayValue.get('iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP domain normal forward email addresses
for imscpEmailsDomainsArrayKey, imscpEmailsDomainsArrayValue in \
imscpInputData.imscpDomainEmailAddressNormalForward.items():
# print(imscpEmailsDomainsArrayKey, '->', imscpEmailsDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': True, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpDomainEmailAddressNormalCatchAll):
for domKey, domValue in imscpInputData.imscpDomainEmailAddressNormalCatchAll.items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData['kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsDomainsArrayValue.get('iEmailMailQuota')
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsDomainsArrayValue.get('iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsDomainsArrayValue.get('iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP domain forward email addresses
for imscpEmailsDomainsArrayKey, imscpEmailsDomainsArrayValue in \
imscpInputData.imscpDomainEmailAddressForward.items():
# print(imscpEmailsDomainsArrayKey, '->', imscpEmailsDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': False}
if bool(imscpInputData.imscpDomainEmailAddressNormalCatchAll):
for domKey, domValue in imscpInputData.imscpDomainEmailAddressNormalCatchAll.items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
# 5MB for only Forward
keyhelpAddApiData['iEmailMailQuota'] = '5242880'
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsDomainsArrayValue.get('iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsDomainsArrayValue.get('iEmailAddress')
# False because there is no need to update the password with an old one
keyhelpAddApiData['iEmailMailPassword'] = False
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding sub domains for domain
for imscpSubDomainsKey, imscpSubDomainsValue in imscpInputData.imscpDomainSubDomains.items():
# print(imscpSubDomainsKey, '->', imscpSubDomainsValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'iParentDomainId': keyHelpParentDomainId,
'iFirstDomainIdna': imscpInputData.imscpData['iUsernameDomainIdna']}
subDomainId = imscpSubDomainsValue.get('iSubDomainId')
keyhelpAddApiData['iSubDomainIdna'] = imscpSubDomainsValue.get('iSubDomainIdna')
keyhelpAddApiData['iSubDomainData'] = imscpSubDomainsValue.get('iSubDomainData')
print('\nAdding i-MSCP sub domain "' + keyhelpAddApiData['iSubDomainIdna'] + '" to domain "' +
imscpInputData.imscpData['iUsernameDomainIdna'] + '".')
if keyhelpDisableDnsForDomain == 'ask':
if _global_config.ask_Yes_No('Do you want to active the dns zone for this domain [y/n]? '):
keyhelpSetDisableDnsForDomain = False
else:
keyhelpSetDisableDnsForDomain = True
keyhelpAddApiData['keyhelpSetDisableDnsForDomain'] = keyhelpSetDisableDnsForDomain
iSubDomainIdna = imscpSubDomainsValue.get('iSubDomainIdna')
keyhelpAddData.addKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Sub domain "' + keyhelpAddApiData['iSubDomainIdna'] + '" added successfully.')
if bool(imscpInputData.imscpSslCerts['subid-' + subDomainId]):
# Adding SSL cert if exist
print(
'\nAdding SSL cert for sub domain "' + keyhelpAddApiData['iSubDomainIdna'] + '".')
for imscpSslKey, imscpSslValue in imscpInputData.imscpSslCerts[
'subid-' + subDomainId].items():
# print(imscpSslKey, '->', imscpSslValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'keyhelpDomainId': keyhelpAddData.keyhelpApiReturnData[
'keyhelpDomainId'],
'iSslDomainIdna': iSubDomainIdna,
'iSslPrivateKey': imscpSslValue.get('iSslPrivateKey'),
'iSslCertificate': imscpSslValue.get('iSslCertificate'),
'iSslCaBundle': imscpSslValue.get('iSslCaBundle'),
'iSslHstsMaxAge': imscpSslValue.get('iSslHstsMaxAge')}
if imscpSslValue.get('iSslAllowHsts') == 'on':
keyhelpAddApiData['iSslAllowHsts'] = 'true'
else:
keyhelpAddApiData['iSslAllowHsts'] = 'false'
if imscpSslValue.get('iSslHstsIncludeSubdomains') == 'on':
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'true'
else:
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'false'
keyhelpAddData.addKeyHelpDataToApi(apiEndpointCertificates, keyhelpAddApiData)
if keyhelpAddData.status:
print('SSL cert for domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" added successfully.')
print('Update "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
keyhelpAddApiData['keyhelpSslId'] = keyhelpAddData.keyhelpApiReturnData[
'keyhelpSslId']
keyhelpAddData.updateKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" updated succesfully with SSL cert.')
else:
_global_config.write_log(
'ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
print(
'ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.\n')
else:
_global_config.write_log(
'ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.')
print(
'ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.\n')
print('\nAdding email addresses for sub domain "' + iSubDomainIdna + '".')
# Adding i-MSCP sub domain normal email addresses
for imscpEmailsSubDomainsArrayKey, imscpEmailsSubDomainsArrayValue in \
imscpInputData.imscpDomainSubEmailAddressNormal['subid-' + subDomainId].items():
# print(imscpEmailsSubDomainsArrayKey, '->', imscpEmailsSubDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpDomainSubEmailAddressNormalCatchAll['subid-' + subDomainId]):
for domKey, domValue in imscpInputData.imscpDomainSubEmailAddressNormalCatchAll[
'subid-' + subDomainId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailQuota')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsSubDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP sub domain normal forward email addresses
for imscpEmailsSubDomainsArrayKey, imscpEmailsSubDomainsArrayValue in \
imscpInputData.imscpDomainSubEmailAddressNormalForward['subid-' + subDomainId].items():
# print(imscpEmailsSubDomainsArrayKey, '->', imscpEmailsSubDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': True, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpDomainSubEmailAddressNormalCatchAll['subid-' + subDomainId]):
for domKey, domValue in imscpInputData.imscpDomainSubEmailAddressNormalCatchAll[
'subid-' + subDomainId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailQuota')
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsSubDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP sub domain forward email addresses
for imscpEmailsSubDomainsArrayKey, imscpEmailsSubDomainsArrayValue in \
imscpInputData.imscpDomainSubEmailAddressForward['subid-' + subDomainId].items():
# print(imscpEmailsSubDomainsArrayKey, '->', imscpEmailsSubDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': False}
if bool(imscpInputData.imscpDomainSubEmailAddressNormalCatchAll['subid-' + subDomainId]):
for domKey, domValue in imscpInputData.imscpDomainSubEmailAddressNormalCatchAll[
'subid-' + subDomainId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
# 5MB for only Forward
keyhelpAddApiData['iEmailMailQuota'] = '5242880'
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsSubDomainsArrayValue.get(
'iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsSubDomainsArrayValue.get('iEmailAddress')
# False because there is no need to update the password with an old one
keyhelpAddApiData['iEmailMailPassword'] = False
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
else:
_global_config.write_log('ERROR "' + keyhelpAddApiData['iSubDomainIdna'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iSubDomainIdna'] + '" failed to add.\n')
else:
_global_config.write_log(
'ERROR "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '" failed to add.')
print('ERROR "' + imscpInputData.imscpData['iUsernameDomainIdna'] + '" failed to add.\n')
# Adding i-MSCP alias domains
for imscpDomainAliasesKey, imscpDomainAliasesValue in imscpInputData.imscpDomainAliases.items():
# print(imscpDomainAliasesKey, '->', imscpDomainAliasesValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'iFirstDomainIdna': imscpInputData.imscpData['iUsernameDomainIdna']}
aliasDomainParentId = imscpDomainAliasesValue.get('iAliasDomainId')
aliasDomainParentName = imscpDomainAliasesValue.get('iAliasDomainIdna')
keyhelpAddApiData['iAliasDomainIdna'] = imscpDomainAliasesValue.get('iAliasDomainIdna')
keyhelpAddApiData['iAliasDomainData'] = imscpDomainAliasesValue.get('iAliasDomainData')
print('\nAdding i-MSCP alias domain "' + keyhelpAddApiData['iAliasDomainIdna'] + '" to KeyHelpUser "' +
keyhelpInputData.keyhelpData['kusername'] + '".')
if keyhelpDisableDnsForDomain == 'ask':
if _global_config.ask_Yes_No('Do you want to active the dns zone for this domain [y/n]? '):
keyhelpSetDisableDnsForDomain = False
else:
keyhelpSetDisableDnsForDomain = True
keyhelpAddApiData['keyhelpSetDisableDnsForDomain'] = keyhelpSetDisableDnsForDomain
keyhelpAddData.addKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
keyHelpParentDomainId = keyhelpAddData.keyhelpApiReturnData['keyhelpDomainId']
print('Domain "' + keyhelpAddApiData['iAliasDomainIdna'] + '" added successfully.')
# Adding domain alias user dns entries if dns is activated
if not keyhelpSetDisableDnsForDomain:
print('\nStart adding domain alias dns entries.')
if bool(imscpInputData.imscpDnsAliasEntries['aliasid-' + aliasDomainParentId]):
if keyhelpInputData.getDnsData(keyHelpParentDomainId,
keyhelpAddApiData['iAliasDomainIdna']):
keyhelpAddData.updateKeyHelpDnsToApi(apiEndpointDns,
keyhelpInputData.keyhelpDomainDnsData,
imscpInputData.imscpDnsAliasEntries[
'aliasid-' + aliasDomainParentId],
keyHelpParentDomainId,
keyhelpAddApiData['iAliasDomainIdna'],
'domainAlias')
if keyhelpAddData.status:
print('Domain alias dns for "' + keyhelpAddApiData[
'iAliasDomainIdna'] + '" updated successfully.')
else:
print('No DNS data for the domain alias "' + keyhelpAddApiData[
'iAliasDomainIdna'] + '" available.')
if bool(imscpInputData.imscpSslCerts['aliasid-' + aliasDomainParentId]):
# Adding SSL cert if exist
print(
'Adding SSL cert for alias domain "' + aliasDomainParentName + '".')
for imscpSslKey, imscpSslValue in imscpInputData.imscpSslCerts[
'aliasid-' + aliasDomainParentId].items():
# print(imscpSslKey, '->', imscpSslValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'keyhelpDomainId': keyhelpAddData.keyhelpApiReturnData[
'keyhelpDomainId'],
'iSslDomainIdna': aliasDomainParentName,
'iSslPrivateKey': imscpSslValue.get('iSslPrivateKey'),
'iSslCertificate': imscpSslValue.get('iSslCertificate'),
'iSslCaBundle': imscpSslValue.get('iSslCaBundle'),
'iSslHstsMaxAge': imscpSslValue.get('iSslHstsMaxAge')}
if imscpSslValue.get('iSslAllowHsts') == 'on':
keyhelpAddApiData['iSslAllowHsts'] = 'true'
else:
keyhelpAddApiData['iSslAllowHsts'] = 'false'
if imscpSslValue.get('iSslHstsIncludeSubdomains') == 'on':
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'true'
else:
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'false'
keyhelpAddData.addKeyHelpDataToApi(apiEndpointCertificates, keyhelpAddApiData)
if keyhelpAddData.status:
print('SSL cert for domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" added successfully.')
print('Update "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
keyhelpAddApiData['keyhelpSslId'] = keyhelpAddData.keyhelpApiReturnData[
'keyhelpSslId']
keyhelpAddData.updateKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" updated succesfully with SSL cert.')
else:
_global_config.write_log(
'ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
print(
'ERROR updating "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.\n')
else:
_global_config.write_log(
'ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.')
print(
'ERROR SSL cert for "' + keyhelpAddApiData['iSslDomainIdna'] + '" failed to add.\n')
print('\nAdding email addresses for alias domain "' + aliasDomainParentName + '".')
# Adding i-MSCP alias domain normal email addresses
for imscpEmailsAliasDomainsArrayKey, imscpEmailsAliasDomainsArrayValue in \
imscpInputData.imscpAliasEmailAddressNormal['aliasid-' + aliasDomainParentId].items():
# print(imscpEmailsAliasDomainsArrayKey, '->', imscpEmailsAliasDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpAliasEmailAddressNormalCatchAll):
for domKey, domValue in imscpInputData.imscpAliasEmailAddressNormalCatchAll[
'aliasid-' + aliasDomainParentId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsAliasDomainsArrayValue.get('iEmailMailQuota')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsAliasDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsAliasDomainsArrayValue.get(
'iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP alias domain normal forward email addresses
for imscpEmailsAliasDomainsArrayKey, imscpEmailsAliasDomainsArrayValue in \
imscpInputData.imscpAliasEmailAddressNormalForward[
'aliasid-' + aliasDomainParentId].items():
# print(imscpEmailsAliasDomainsArrayKey, '->', imscpEmailsAliasDomainsArrayValue)
keyhelpAddApiData = {'emailStoreForward': True, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpAliasEmailAddressNormalCatchAll['aliasid-' + aliasDomainParentId]):
for domKey, domValue in imscpInputData.imscpAliasEmailAddressNormalCatchAll[
'aliasid-' + aliasDomainParentId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
keyhelpAddApiData['kdatabaseRoot'] = keyhelpInputData.keyhelpData['kdatabaseRoot']
keyhelpAddApiData['kdatabaseRootPassword'] = keyhelpInputData.keyhelpData[
'kdatabaseRootPassword']
keyhelpAddApiData['iEmailMailQuota'] = imscpEmailsAliasDomainsArrayValue.get('iEmailMailQuota')
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsAliasDomainsArrayValue.get(
'iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsAliasDomainsArrayValue.get('iEmailAddress')
keyhelpAddApiData['iEmailMailPassword'] = imscpEmailsAliasDomainsArrayValue.get(
'iEmailMailPassword')
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding i-MSCP alias domain forward email addresses
for imscpEmailsAliasDomainsKey, imscpEmailsAliasDomainsValue in \
imscpInputData.imscpAliasEmailAddressForward['aliasid-' + aliasDomainParentId].items():
# print(imscpEmailsAliasDomainsKey, '->', imscpEmailsAliasDomainsValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': False}
if bool(imscpInputData.imscpAliasEmailAddressNormalCatchAll['aliasid-' + aliasDomainParentId]):
for domKey, domValue in imscpInputData.imscpAliasEmailAddressNormalCatchAll[
'aliasid-' + aliasDomainParentId].items():
keyhelpAddApiData['iEmailCatchall'] = domValue.get('iEmailAddress')
# 5MB for only Forward
keyhelpAddApiData['iEmailMailQuota'] = '5242880'
keyhelpAddApiData['iEmailMailForward'] = imscpEmailsAliasDomainsValue.get(
'iEmailMailForward')
keyhelpAddApiData['iEmailAddress'] = imscpEmailsAliasDomainsValue.get('iEmailAddress')
# False because there is no need to update the password with an old one
keyhelpAddApiData['iEmailMailPassword'] = False
keyhelpAddApiData['iEmailMailInitialPassword'] = \
keyhelpAddData.keyhelpCreateRandomEmailPassword(keyhelpMinPasswordLenght)
keyhelpAddData.addKeyHelpDataToApi(apiEndPointEmails, keyhelpAddApiData)
if keyhelpAddData.status:
print(
'Email address "' + keyhelpAddApiData['iEmailAddress'] + '" added successfully.')
else:
_global_config.write_log(
'ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.')
print('ERROR "' + keyhelpAddApiData['iEmailAddress'] + '" failed to add.\n')
# Adding sub domains for alias domain
for imscpAliasSubDomainsKey, imscpAliasSubDomainsValue in \
imscpInputData.imscpAliasSubDomains['aliasid-' + aliasDomainParentId].items():
# print(imscpAliasSubDomainsKey, '->', imscpAliasSubDomainsValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'iParentDomainId': keyHelpParentDomainId,
'iFirstDomainIdna': imscpInputData.imscpData['iUsernameDomainIdna']}
aliasSubDomainId = imscpAliasSubDomainsValue.get('iAliasSubDomainId')
keyhelpAddApiData['iAliasSubDomainIdna'] = imscpAliasSubDomainsValue.get(
'iAliasSubDomainIdna')
keyhelpAddApiData['iAliasSubDomainData'] = imscpAliasSubDomainsValue.get(
'iAliasSubDomainData')
iAliasSubDomainIdna = imscpAliasSubDomainsValue.get('iAliasSubDomainIdna')
print('\nAdding i-MSCP alias sub domain "' + keyhelpAddApiData[
'iAliasSubDomainIdna'] + '" to alias domain "' + aliasDomainParentName + '".')
if keyhelpDisableDnsForDomain == 'ask':
if _global_config.ask_Yes_No('Do you want to active the dns zone for this domain [y/n]? '):
keyhelpSetDisableDnsForDomain = False
else:
keyhelpSetDisableDnsForDomain = True
keyhelpAddApiData['keyhelpSetDisableDnsForDomain'] = keyhelpSetDisableDnsForDomain
keyhelpAddData.addKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Alias sub domain "' + keyhelpAddApiData[
'iAliasSubDomainIdna'] + '" added successfully.')
if bool(imscpInputData.imscpSslCerts['aliassubid-' + aliasSubDomainId]):
# Adding SSL cert if exist
print(
'\nAdding SSL cert for sub alias domain "' + iAliasSubDomainIdna + '".')
for imscpSslKey, imscpSslValue in imscpInputData.imscpSslCerts[
'aliassubid-' + aliasSubDomainId].items():
# print(imscpSslKey, '->', imscpSslValue)
keyhelpAddApiData = {'addedKeyHelpUserId': addedKeyHelpUserId,
'keyhelpDomainId': keyhelpAddData.keyhelpApiReturnData[
'keyhelpDomainId'],
'iSslDomainIdna': iAliasSubDomainIdna,
'iSslPrivateKey': imscpSslValue.get('iSslPrivateKey'),
'iSslCertificate': imscpSslValue.get('iSslCertificate'),
'iSslCaBundle': imscpSslValue.get('iSslCaBundle'),
'iSslHstsMaxAge': imscpSslValue.get('iSslHstsMaxAge')}
if imscpSslValue.get('iSslAllowHsts') == 'on':
keyhelpAddApiData['iSslAllowHsts'] = 'true'
else:
keyhelpAddApiData['iSslAllowHsts'] = 'false'
if imscpSslValue.get('iSslHstsIncludeSubdomains') == 'on':
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'true'
else:
keyhelpAddApiData['iSslHstsIncludeSubdomains'] = 'false'
keyhelpAddData.addKeyHelpDataToApi(apiEndpointCertificates, keyhelpAddApiData)
if keyhelpAddData.status:
print('SSL cert for domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" added successfully.')
print('Update "' + keyhelpAddApiData['iSslDomainIdna'] + '" with SSL cert.')
keyhelpAddApiData['keyhelpSslId'] = keyhelpAddData.keyhelpApiReturnData[
'keyhelpSslId']
keyhelpAddData.updateKeyHelpDataToApi(apiEndpointDomains, keyhelpAddApiData)
if keyhelpAddData.status:
print('Domain "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" updated succesfully with SSL cert.')
else:
_global_config.write_log(
'ERROR updating "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" with SSL cert.')
print(
'ERROR updating "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" with SSL cert.\n')
else:
_global_config.write_log(
'ERROR SSL cert for "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" failed to add.')
print(
'ERROR SSL cert for "' + keyhelpAddApiData[
'iSslDomainIdna'] + '" failed to add.\n')
print('\nAdding email addresses for alias sub domain "' + iAliasSubDomainIdna + '".')
# Adding i-MSCP alias sub domain normal email addresses
for imscpEmailsAliasSubDomainsKey, imscpEmailsAliasSubDomainsValue in \
imscpInputData.imscpAliasSubEmailAddressNormal[
'aliassubid-' + aliasSubDomainId].items():
# print(imscpEmailsAliasSubDomainsKey, '->', imscpEmailsAliasSubDomainsValue)
keyhelpAddApiData = {'emailStoreForward': False, 'iEmailCatchall': '',
'addedKeyHelpUserId': addedKeyHelpUserId, 'emailNeedRsync': True}
if bool(imscpInputData.imscpAliasSubEmailAddressNormalCatchAll[
'aliassubid-' + aliasSubDomainId]):
for domKey, domValue in imscpInputData.imscpAliasSubEmailAddressNormalCatchAll[
'aliassubid-' + aliasSubDomainId].items():