forked from usmannasir/cyberpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·3881 lines (3048 loc) · 155 KB
/
install.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
import sys
import subprocess
import shutil
import installLog as logging
import argparse
import os
import shlex
from firewallUtilities import FirewallUtilities
import time
import string
import random
import socket
from os.path import *
from stat import *
import stat
from os import urandom
from random import choice
char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
'nums': '0123456789',
'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
}
def generate_pass(length=14):
"""Function to generate a password"""
password = []
while len(password) < length:
key = choice(char_set.keys())
a_char = urandom(1)
if a_char in char_set[key]:
if check_prev_char(password, char_set[key]):
continue
else:
password.append(a_char)
return ''.join(password)
def check_prev_char(password, current_char_set):
"""Function to ensure that there are no consecutive
UPPERCASE/lowercase/numbers/special-characters."""
index = len(password)
if index == 0:
return False
else:
prev_char = password[index - 1]
if prev_char in current_char_set:
return True
else:
return False
# There can not be peace without first a great suffering.
# distros
centos = 0
ubuntu = 1
def get_distro():
distro = -1
distro_file = ""
if exists("/etc/lsb-release"):
distro_file = "/etc/lsb-release"
with open(distro_file) as f:
for line in f:
if line == "DISTRIB_ID=Ubuntu\n":
distro = ubuntu
elif exists("/etc/os-release"):
distro_file = "/etc/os-release"
distro = centos
else:
logging.InstallLog.writeToFile("Can't find linux release file - fatal error")
preFlightsChecks.stdOut("Can't find linux release file - fatal error")
os._exit(os.EX_UNAVAILABLE)
if distro == -1:
logging.InstallLog.writeToFile("Can't find distro name in " + distro_file + " - fatal error")
preFlightsChecks.stdOut("Can't find distro name in " + distro_file + " - fatal error")
os._exit(os.EX_UNAVAILABLE)
return distro
def get_Ubuntu_release():
release = -1
if exists("/etc/lsb-release"):
distro_file = "/etc/lsb-release"
with open(distro_file) as f:
for line in f:
if line[:16] == "DISTRIB_RELEASE=":
release = float(line[16:])
if release == -1:
preFlightsChecks.stdOut("Can't find distro release name in " + distro_file + " - fatal error", 1, 1,
os.EX_UNAVAILABLE)
else:
logging.InstallLog.writeToFile("Can't find linux release file - fatal error")
preFlightsChecks.stdOut("Can't find linux release file - fatal error")
os._exit(os.EX_UNAVAILABLE)
return release
class preFlightsChecks:
cyberPanelMirror = "mirror.cyberpanel.net/pip"
def __init__(self, rootPath, ip, path, cwd, cyberPanelPath, distro):
self.ipAddr = ip
self.path = path
self.cwd = cwd
self.server_root_path = rootPath
self.cyberPanelPath = cyberPanelPath
self.distro = distro
@staticmethod
def stdOut(message, log=0, do_exit=0, code=os.EX_OK):
print("\n\n")
print ("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n")
print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + message + "\n")
print ("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n")
if log:
logging.InstallLog.writeToFile(message)
if do_exit:
sys.exit(code)
def mountTemp(self):
try:
command = "dd if=/dev/zero of=/usr/.tempdisk bs=100M count=15"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "mkfs.ext4 -F /usr/.tempdisk"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "mkdir -p /usr/.tmpbak/"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "cp -pr /tmp/* /usr/.tmpbak/"
subprocess.call(command, shell=True)
command = "mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "chmod 1777 /tmp"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "cp -pr /usr/.tmpbak/* /tmp/"
subprocess.call(command, shell=True)
command = "rm -rf /usr/.tmpbak"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
command = "mount --bind /tmp /var/tmp"
preFlightsChecks.call(command, self.distro, '[mountTemp]',
'mountTemp',
1, 0, os.EX_OSERR)
tmp = "/usr/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0\n"
varTmp = "/tmp /var/tmp none bind 0 0\n"
fstab = "/etc/fstab"
writeToFile = open(fstab, "a")
writeToFile.writelines(tmp)
writeToFile.writelines(varTmp)
writeToFile.close()
except BaseException, msg:
preFlightsChecks.stdOut("[Failed:mountTemp] " + str(msg))
return 0
@staticmethod
def pureFTPDServiceName(distro):
if distro == ubuntu:
return 'pure-ftpd'
return 'pure-ftpd'
@staticmethod
def resFailed(distro, res):
if distro == ubuntu and res != 0:
return True
elif distro == centos and res != 0:
return True
return False
@staticmethod
def call(command, distro, bracket, message, log=0, do_exit=0, code=os.EX_OK):
preFlightsChecks.stdOut(message + " " + bracket, log)
count = 0
while True:
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(distro, res):
count = count + 1
preFlightsChecks.stdOut(message + " failed, trying again, try number: " + str(count))
if count == 3:
fatal_message = ''
if do_exit:
fatal_message = '. Fatal error, see /var/log/installLogs.txt for full details'
preFlightsChecks.stdOut("[ERROR] We are not able to " + message + ' return code: ' + str(res) +
fatal_message + " " + bracket, 1, do_exit, code)
return False
else:
preFlightsChecks.stdOut(message + ' successful', log)
break
return True
def checkIfSeLinuxDisabled(self):
try:
command = "sestatus"
output = subprocess.check_output(shlex.split(command))
if output.find("disabled") > -1 or output.find("permissive") > -1:
logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]")
preFlightsChecks.stdOut("SELinux Check OK.")
return 1
else:
logging.InstallLog.writeToFile(
"SELinux is enabled, please disable SELinux and restart the installation!")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + "[checkIfSeLinuxDisabled]")
logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]")
preFlightsChecks.stdOut("SELinux Check OK.")
return 1
def checkPythonVersion(self):
if sys.version_info[0] == 2 and sys.version_info[1] == 7:
return 1
else:
preFlightsChecks.stdOut("You are running Unsupported python version, please install python 2.7")
os._exit(0)
def setup_account_cyberpanel(self):
try:
if self.distro == centos:
command = "yum install sudo -y"
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'Install sudo.',
1, 0, os.EX_OSERR)
##
count = 0
if self.distro == ubuntu:
# self.stdOut("Fix sudoers")
# try:
# fileName = '/etc/sudoers'
# data = open(fileName, 'r').readlines()
#
# writeDataToFile = open(fileName, 'w')
# for line in data:
# if line[:5] == '%sudo':
# writeDataToFile.write('%sudo ALL=(ALL:ALL) NOPASSWD: ALL\n')
# else:
# writeDataToFile.write(line)
# writeDataToFile.close()
# except IOError as err:
# self.stdOut("Error in fixing sudoers file: " + str(err), 1, 1, os.EX_OSERR)
self.stdOut("Add Cyberpanel user")
command = 'adduser --disabled-login --gecos "" cyberpanel'
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res != 0 and res != 9:
logging.InstallLog.writeToFile("Can not create cyberpanel user, error #" + str(res))
preFlightsChecks.stdOut("Can not create cyberpanel user, error #" + str(res))
os._exit(0)
if res == 0:
logging.InstallLog.writeToFile("CyberPanel user added")
preFlightsChecks.stdOut("CyberPanel user added")
else:
command = "useradd -s /bin/false cyberpanel"
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
# ##
#
# command = "usermod -aG wheel cyberpanel"
# preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
# 'add user cyberpanel',
# 1, 0, os.EX_OSERR)
###############################
# path = "/etc/sudoers"
#
# data = open(path, 'r').readlines()
#
# writeToFile = open(path, 'w')
#
# for items in data:
# if items.find("wheel ALL=(ALL) NOPASSWD: ALL") > -1:
# writeToFile.writelines("%wheel ALL=(ALL) NOPASSWD: ALL")
# else:
# writeToFile.writelines(items)
#
# writeToFile.close()
###############################
### Docker User/group
if self.distro == ubuntu:
command = 'adduser --disabled-login --gecos "" docker'
else:
command = "adduser docker"
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
command = 'groupadd docker'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
command = 'usermod -aG docker docker'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
command = 'usermod -aG docker cyberpanel'
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
###
command = "mkdir -p /etc/letsencrypt/live/"
preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]',
'add user cyberpanel',
1, 0, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile("[ERROR] setup_account_cyberpanel. " + str(msg))
def yum_update(self):
try:
count = 0
while (1):
command = 'yum update -y'
cmd = shlex.split(command)
res = subprocess.call(cmd)
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("YUM UPDATE FAILED, trying again, try number: " + str(count) + "\n")
if count == 3:
logging.InstallLog.writeToFile(
"YUM update failed to run, we are being optimistic that installer will still be able to complete installation. [yum_update]")
break
else:
logging.InstallLog.writeToFile("YUM UPDATE ran successfully.")
preFlightsChecks.stdOut("YUM UPDATE ran successfully.")
break
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [yum_update]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [yum_update]")
return 0
return 1
def installCyberPanelRepo(self):
self.stdOut("Install Cyberpanel repo")
cmd = []
count = 0
if self.distro == ubuntu:
try:
filename = "enable_lst_debain_repo.sh"
command = "wget http://rpms.litespeedtech.com/debian/" + filename
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res != 0:
logging.InstallLog.writeToFile(
"Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]:"
" Error #" + str(res))
preFlightsChecks.stdOut("Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]:"
" Error #" + str(res))
os._exit(os.EX_NOINPUT)
os.chmod(filename, S_IRWXU | S_IRWXG)
command = "./" + filename
cmd = shlex.split(command)
res = subprocess.call(cmd)
if res != 0:
logging.InstallLog.writeToFile("Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]:"
" Error #" + str(res))
preFlightsChecks.stdOut("Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]:"
" Error #" + str(res))
os._exit(os.EX_NOINPUT)
except OSError as err:
logging.InstallLog.writeToFile("Exception during CyberPanel install: " + str(err))
preFlightsChecks.stdOut("Exception during CyberPanel install: " + str(err))
os._exit(os.EX_OSERR)
except:
logging.InstallLog.writeToFile("Exception during CyberPanel install")
preFlightsChecks.stdOut("Exception during CyberPanel install")
os._exit(os.EX_SOFTWARE)
else:
while (1):
cmd.append("rpm")
cmd.append("-ivh")
cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm")
res = subprocess.call(cmd)
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to add CyberPanel official repository, trying again, try number: " + str(count) + "\n")
if count == 3:
logging.InstallLog.writeToFile(
"Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("CyberPanel Repo added!")
preFlightsChecks.stdOut("CyberPanel Repo added!")
break
def enableEPELRepo(self):
try:
cmd = []
count = 0
while (1):
cmd.append("yum")
cmd.append("-y")
cmd.append("install")
cmd.append("epel-release")
res = subprocess.call(cmd)
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to add EPEL repository, trying again, try number: " + str(count) + "\n")
if count == 3:
logging.InstallLog.writeToFile(
"Unable to add EPEL repository, exiting installer! [enableEPELRepo]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("EPEL Repo added!")
preFlightsChecks.stdOut("EPEL Repo added!")
break
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableEPELRepo]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableEPELRepo]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
return 0
return 1
def install_pip(self):
self.stdOut("Install pip")
count = 0
while (1):
if self.distro == ubuntu:
command = "apt-get -y install python-pip"
else:
command = "yum -y install python-pip"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install PIP, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install PIP, exiting installer! [install_pip]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("PIP successfully installed!")
preFlightsChecks.stdOut("PIP successfully installed!")
break
def install_python_dev(self):
self.stdOut("Install python development environment")
count = 0
while (1):
if self.distro == centos:
command = "yum -y install python-devel"
else:
command = "apt-get -y install python-dev"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"We are trying to install python development tools, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install python development tools, exiting installer! [install_python_dev]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("Python development tools successfully installed!")
preFlightsChecks.stdOut("Python development tools successfully installed!")
break
def install_gcc(self):
self.stdOut("Install gcc")
count = 0
while (1):
if self.distro == centos:
command = "yum -y install gcc"
else:
command = "apt-get -y install gcc"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install GCC, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install GCC, exiting installer! [install_gcc]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("GCC Successfully installed!")
preFlightsChecks.stdOut("GCC Successfully installed!")
break
def install_python_setup_tools(self):
count = 0
while (1):
command = "yum -y install python-setuptools"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
print("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "] " + "Unable to install Python setup tools, trying again, try number: " + str(
count) + "\n")
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install Python setup tools, exiting installer! [install_python_setup_tools]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("Python setup tools Successfully installed!")
print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + "Python setup tools Successfully installed!")
break
def install_python_requests(self):
try:
import requests
## Un-install ULRLIB3 and requests
command = "pip uninstall --yes urllib3"
res = subprocess.call(shlex.split(command))
command = "pip uninstall --yes requests"
res = subprocess.call(shlex.split(command))
## Install specific versions
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/urllib3-1.22.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to install urllib3 module, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install urllib3 module, exiting installer! [install_python_requests]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("urllib3 module Successfully installed!")
preFlightsChecks.stdOut("urllib3 module Successfully installed!")
break
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/requests-2.18.4.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to install requests module, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install requests module, exiting installer! [install_python_requests]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("Requests module Successfully installed!")
preFlightsChecks.stdOut("Requests module Successfully installed!")
break
except:
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/urllib3-1.22.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to install urllib3 module, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install urllib3 module, exiting installer! [install_python_requests]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("urllib3 module Successfully installed!")
preFlightsChecks.stdOut("urllib3 module Successfully installed!")
break
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/requests-2.18.4.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut(
"Unable to install requests module, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install requests module, exiting installer! [install_python_requests]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("Requests module Successfully installed!")
preFlightsChecks.stdOut("Requests module Successfully installed!")
break
def install_pexpect(self):
try:
import pexpect
command = "pip uninstall --yes pexpect"
res = subprocess.call(shlex.split(command))
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/pexpect-4.4.0.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install pexpect, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install pexpect, exiting installer! [install_pexpect]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("pexpect successfully installed!")
preFlightsChecks.stdOut("pexpect successfully installed!")
break
except:
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/pexpect-4.4.0.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install pexpect, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install pexpect, exiting installer! [install_pexpect]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("pexpect successfully installed!")
preFlightsChecks.stdOut("pexpect successfully installed!")
break
def install_django(self):
count = 0
while (1):
command = "pip install django==1.11"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install DJANGO, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install DJANGO, exiting installer! [install_django]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("DJANGO successfully installed!")
preFlightsChecks.stdOut("DJANGO successfully installed!")
break
def install_python_mysql_library(self):
self.stdOut("Install MySQL python library")
count = 0
while (1):
if self.distro == centos:
command = "yum -y install MySQL-python"
else:
command = "apt-get -y install libmysqlclient-dev"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install MySQL-python, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile(
"Unable to install MySQL-python, exiting installer! [install_python_mysql_library]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("MySQL-python successfully installed!")
preFlightsChecks.stdOut("MySQL-python successfully installed!")
break
if self.distro == ubuntu:
command = "pip install MySQL-python"
res = subprocess.call(shlex.split(command))
if res != 0:
logging.InstallLog.writeToFile(
"Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str(
res))
preFlightsChecks.stdOut(
"Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str(
res))
os._exit(os.EX_OSERR)
def install_gunicorn(self):
self.stdOut("Install Gunicorn")
count = 0
# while (1):
# if self.distro == ubuntu:
# command = "pip install gunicorn"
# else:
# command = "easy_install gunicorn"
# res = subprocess.call(shlex.split(command))
# if preFlightsChecks.resFailed(self.distro, res):
# count = count + 1
# preFlightsChecks.stdOut("Unable to install GUNICORN, trying again, try number: " + str(count))
# if count == 3:
# logging.InstallLog.writeToFile("Unable to install GUNICORN, exiting installer! [install_gunicorn]")
# preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
# os._exit(0)
# else:
# logging.InstallLog.writeToFile("GUNICORN successfully installed!")
# preFlightsChecks.stdOut("GUNICORN successfully installed!")
# break
def setup_gunicorn(self):
try:
os.chdir(self.cwd)
#
# ##
#
# logging.InstallLog.writeToFile("Configuring Gunicorn..")
#
# service = "/etc/systemd/system/gunicorn.service"
# socket = "/etc/systemd/system/gunicorn.socket"
# conf = "/etc/tmpfiles.d/gunicorn.conf"
#
# shutil.copy("gun-configs/gunicorn.service", service)
# shutil.copy("gun-configs/gunicorn.socket", socket)
# shutil.copy("gun-configs/gunicorn.conf", conf)
#
# logging.InstallLog.writeToFile("Gunicorn Configured!")
#
# ### Enable at system startup
#
# count = 0
#
# while (1):
# command = "systemctl enable gunicorn.socket"
# res = subprocess.call(shlex.split(command))
#
# if preFlightsChecks.resFailed(self.distro, res):
# count = count + 1
# preFlightsChecks.stdOut("Trying to enable Gunicorn at system startup, try number: " + str(count))
# if count == 3:
# logging.InstallLog.writeToFile(
# "Gunicorn will not start after system restart, you can manually enable using systemctl enable gunicorn.socket! [setup_gunicorn]")
# preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
# break
# else:
# logging.InstallLog.writeToFile("Gunicorn can now start after system restart!")
# preFlightsChecks.stdOut("Gunicorn can now start after system restart!")
# break
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_gunicorn]")
preFlightsChecks.stdOut("Not able to setup gunicorn, see install log.")
def install_psutil(self):
try:
import psutil
##
command = "pip uninstall --yes psutil"
res = subprocess.call(shlex.split(command))
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/psutil-5.4.3.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install psutil, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install psutil, exiting installer! [install_psutil]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("psutil successfully installed!")
preFlightsChecks.stdOut("psutil successfully installed!")
break
except:
count = 0
while (1):
command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/psutil-5.4.3.tar.gz"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install psutil, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install psutil, exiting installer! [install_psutil]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("psutil successfully installed!")
preFlightsChecks.stdOut("psutil successfully installed!")
break
def fix_selinux_issue(self):
try:
cmd = []
cmd.append("setsebool")
cmd.append("-P")
cmd.append("httpd_can_network_connect")
cmd.append("1")
res = subprocess.call(cmd)
if preFlightsChecks.resFailed(self.distro, res):
logging.InstallLog.writeToFile("fix_selinux_issue problem")
else:
pass
except:
logging.InstallLog.writeToFile("fix_selinux_issue problem")
def install_psmisc(self):
self.stdOut("Install psmisc")
count = 0
while (1):
if self.distro == centos:
command = "yum -y install psmisc"
else:
command = "apt-get -y install psmisc"
res = subprocess.call(shlex.split(command))
if preFlightsChecks.resFailed(self.distro, res):
count = count + 1
preFlightsChecks.stdOut("Unable to install psmisc, trying again, try number: " + str(count))
if count == 3:
logging.InstallLog.writeToFile("Unable to install psmisc, exiting installer! [install_psmisc]")
preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt")
os._exit(0)
else:
logging.InstallLog.writeToFile("psmisc successfully installed!")
preFlightsChecks.stdOut("psmisc successfully installed!")
break
def download_install_CyberPanel(self, mysqlPassword, mysql):
try:
## On OpenVZ there is an issue with requests module, which needs to upgrade requests module
if subprocess.check_output('systemd-detect-virt').find("openvz") > -1:
command = "pip install --upgrade requests"
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'Upgrade requests',
1, 0, os.EX_OSERR)
except:
pass
##
os.chdir(self.path)
command = "wget http://cyberpanel.sh/CyberPanel.1.9.0.tar.gz"
#command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'CyberPanel Download',
1, 1, os.EX_OSERR)
##
count = 0
command = "tar zxf CyberPanel.1.9.0.tar.gz"
#command = "tar zxf CyberPanelTemp.tar.gz"
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
'Extract CyberPanel',1, 1, os.EX_OSERR)
### update password:
passFile = "/etc/cyberpanel/mysqlPassword"
f = open(passFile)
data = f.read()
password = data.split('\n', 1)[0]
### Put correct mysql passwords in settings file!
logging.InstallLog.writeToFile("Updating settings.py!")
path = self.cyberPanelPath + "/CyberCP/settings.py"
data = open(path, "r").readlines()
writeDataToFile = open(path, "w")
counter = 0
for items in data:
if items.find('SECRET_KEY') > -1:
SK = "SECRET_KEY = '%s'\n" % (generate_pass(50))
writeDataToFile.writelines(SK)
continue
if mysql == 'Two':
if items.find("'PASSWORD':") > -1:
if counter == 0:
writeDataToFile.writelines(" 'PASSWORD': '" + mysqlPassword + "'," + "\n")
counter = counter + 1
else:
writeDataToFile.writelines(" 'PASSWORD': '" + password + "'," + "\n")