better error reporting during installation

This commit is contained in:
Usman Nasir
2019-11-13 18:51:57 +05:00
parent bf8de20ed5
commit d28c766b33
3 changed files with 1156 additions and 92 deletions

1096
cyberpanel.sh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -200,7 +200,7 @@ class preFlightsChecks:
writeToFile.close()
except BaseException, msg:
preFlightsChecks.stdOut("[Failed:mountTemp] " + str(msg))
preFlightsChecks.stdOut('[ERROR] ' + str(msg))
return 0
@staticmethod
@@ -238,7 +238,7 @@ class preFlightsChecks:
fatal_message + ".", 1, do_exit, code)
return False
else:
preFlightsChecks.stdOut('%s ran successfully.' % (message), log)
preFlightsChecks.stdOut('Successfully ran: %s.' % (message), log)
break
return True
@@ -259,9 +259,9 @@ class preFlightsChecks:
os._exit(0)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + "[checkIfSeLinuxDisabled]")
logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]")
preFlightsChecks.stdOut("SELinux Check OK.")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + "[checkIfSeLinuxDisabled]")
logging.InstallLog.writeToFile('[ERROR] ' + "SELinux Check OK. [checkIfSeLinuxDisabled]")
preFlightsChecks.stdOut('[ERROR] ' + "SELinux Check OK.")
return 1
def checkPythonVersion(self):
@@ -375,8 +375,8 @@ class preFlightsChecks:
command = "./" + filename
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
except:
logging.InstallLog.writeToFile("Exception during CyberPanel install")
preFlightsChecks.stdOut("Exception during CyberPanel install")
logging.InstallLog.writeToFile("[ERROR] Exception during CyberPanel install")
preFlightsChecks.stdOut("[ERROR] Exception during CyberPanel install")
os._exit(os.EX_SOFTWARE)
else:
@@ -450,7 +450,7 @@ class preFlightsChecks:
else:
pass
except:
logging.InstallLog.writeToFile("fix_selinux_issue problem")
logging.InstallLog.writeToFile("[ERROR] fix_selinux_issue problem")
def install_psmisc(self):
self.stdOut("Install psmisc")
@@ -702,7 +702,7 @@ class preFlightsChecks:
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_unzip]")
logging.InstallLog.writeToFile('[ERROR] '+ str(msg) + " [install_unzip]")
def install_zip(self):
self.stdOut("Install zip")
@@ -714,7 +714,7 @@ class preFlightsChecks:
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_zip]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_zip]")
def download_install_phpmyadmin(self):
try:
@@ -754,7 +754,7 @@ class preFlightsChecks:
'chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin', 1, 0, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [download_install_phpmyadmin]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [download_install_phpmyadmin]")
return 0
###################################################### Email setup
@@ -855,11 +855,8 @@ enabled=1"""
except:
pass
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_postfix_davecot]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_postfix_davecot]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_postfix_davecot]")
return 0
return 1
@@ -984,11 +981,8 @@ enabled=1"""
logging.InstallLog.writeToFile("Authentication for Postfix and Dovecot set.")
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_email_Passwords]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_email_Passwords]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR]' + str(msg) + " [setup_email_Passwords]")
return 0
return 1
@@ -1008,7 +1002,7 @@ enabled=1"""
fd.write(line)
fd.close()
except IOError as err:
self.stdOut("Error converting: " + filename + " from centos defaults to ubuntu defaults: " + str(err), 1,
self.stdOut("[ERROR] Error converting: " + filename + " from centos defaults to ubuntu defaults: " + str(err), 1,
1, os.EX_OSERR)
def setup_postfix_davecot_config(self, mysql):
@@ -1241,12 +1235,8 @@ enabled=1"""
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
logging.InstallLog.writeToFile("Postfix and Dovecot configured")
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_postfix_davecot_config]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_postfix_davecot_config]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_postfix_davecot_config]")
return 0
return 1
@@ -1321,12 +1311,8 @@ imap_folder_list_limit = 0
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [downoad_and_install_rainloop]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [downoad_and_install_rainloop]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [downoad_and_install_rainloop]")
return 0
return 1
@@ -1343,7 +1329,7 @@ imap_folder_list_limit = 0
status = subprocess.check_output(shlex.split('ufw status'))
preFlightsChecks.stdOut("ufw current status: " + status + "...will be removed")
except BaseException, msg:
preFlightsChecks.stdOut("Expected access to ufw not available, do not need to remove it", 1)
preFlightsChecks.stdOut("[ERROR] Expected access to ufw not available, do not need to remove it", 1)
return True
try:
preFlightsChecks.call('apt-get -y remove ufw', self.distro, '[remove_ufw]', 'Remove ufw firewall ' +
@@ -1403,10 +1389,10 @@ imap_folder_list_limit = 0
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installFirewalld]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installFirewalld]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installFirewalld]")
return 0
return 1
@@ -1481,7 +1467,7 @@ imap_folder_list_limit = 0
logging.InstallLog.writeToFile("LSCPD successfully installed!")
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [installLSCPD]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installLSCPD]")
def setupComodoRules(self):
try:
@@ -1567,7 +1553,7 @@ imap_folder_list_limit = 0
return 1
except BaseException, msg:
logging.InstallLog.writeToFile("[Failed:setupComodoRules] " + str(msg))
logging.InstallLog.writeToFile("[ERROR]" + str(msg))
return 0
def setupPort(self):
@@ -1664,11 +1650,8 @@ imap_folder_list_limit = 0
logging.InstallLog.writeToFile("LSCPD Daemon Set!")
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupLSCPDDaemon]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupLSCPDDaemon]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupLSCPDDaemon]")
return 0
return 1
@@ -1724,11 +1707,8 @@ imap_folder_list_limit = 0
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_cron]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_cron]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_cron]")
return 0
def install_default_keys(self):
@@ -1740,11 +1720,9 @@ imap_folder_list_limit = 0
command = "ssh-keygen -f /root/.ssh/cyberpanel -t rsa -N ''"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_default_keys]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_default_keys]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_default_keys]")
return 0
def install_rsync(self):
@@ -1755,11 +1733,9 @@ imap_folder_list_limit = 0
command = 'apt-get -y install rsync'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_rsync]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [install_rsync]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [install_rsync]")
return 0
def test_Requests(self):
@@ -1802,7 +1778,7 @@ imap_folder_list_limit = 0
os.remove(pathToRemoveGarbageFile)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [modSecPreReqs]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [modSecPreReqs]")
return 0
def installOpenDKIM(self):
@@ -1821,11 +1797,8 @@ imap_folder_list_limit = 0
command = 'mkdir -p /etc/opendkim/keys/'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installOpenDKIM]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installOpenDKIM]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installOpenDKIM]")
return 0
return 1
@@ -1887,11 +1860,9 @@ milter_default_action = accept
command = "systemctl start postfix"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [configureOpenDKIM]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [configureOpenDKIM]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [configureOpenDKIM]")
return 0
return 1
@@ -1929,7 +1900,7 @@ milter_default_action = accept
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupPHPAndComposer]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupPHPAndComposer]")
return 0
@staticmethod
@@ -2023,7 +1994,7 @@ milter_default_action = accept
preFlightsChecks.call(command, distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [setupVirtualEnv]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setupVirtualEnv]")
return 0
@staticmethod
@@ -2049,7 +2020,7 @@ milter_default_action = accept
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableDNS]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableDNS]")
return 0
@staticmethod
@@ -2075,7 +2046,7 @@ milter_default_action = accept
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]")
return 0
@staticmethod
@@ -2101,7 +2072,7 @@ milter_default_action = accept
writeToFile.close()
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]")
return 0
@staticmethod

View File

@@ -87,11 +87,8 @@ class InstallCyberPanel:
command = 'chown -R lsadm:lsadm ' + confPath
install.preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
except OSError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]")
return 0
except ValueError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installLiteSpeed]")
except BaseException, msg:
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installLiteSpeed]")
return 0
return 1
@@ -121,7 +118,7 @@ class InstallCyberPanel:
InstallCyberPanel.stdOut("OpenLiteSpeed Configurations fixed!", 1)
except IOError, msg:
logging.InstallLog.writeToFile(str(msg) + " [fix_ols_configs]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [fix_ols_configs]")
return 0
return self.reStartLiteSpeed()
@@ -145,7 +142,7 @@ class InstallCyberPanel:
InstallCyberPanel.stdOut("Default port is now 80 for OpenLiteSpeed!", 1)
except IOError, msg:
logging.InstallLog.writeToFile(str(msg) + " [changePortTo80]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [changePortTo80]")
return 0
return self.reStartLiteSpeed()
@@ -213,7 +210,7 @@ class InstallCyberPanel:
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [setup_mariadb_repo]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [setup_mariadb_repo]")
return 0
def installMySQL(self, mysql):
@@ -325,7 +322,7 @@ class InstallCyberPanel:
writeDataToFile.write(line.replace('utf8mb4', 'utf8'))
writeDataToFile.close()
except IOError as err:
self.stdOut("Error in setting: " + fileName + ": " + str(err), 1, 1, os.EX_OSERR)
self.stdOut("[ERROR] Error in setting: " + fileName + ": " + str(err), 1, 1, os.EX_OSERR)
os.system('systemctl restart mysql')
@@ -369,7 +366,7 @@ class InstallCyberPanel:
try:
os.mkdir("/etc/ssl/private")
except:
logging.InstallLog.writeToFile("Could not create directory for FTP SSL")
logging.InstallLog.writeToFile("[ERROR] Could not create directory for FTP SSL")
command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem'
@@ -396,7 +393,7 @@ class InstallCyberPanel:
os.mkdir('/etc/pure-ftpd/auth')
os.mkdir('/etc/pure-ftpd/db')
except OSError as err:
self.stdOut("Error creating extra pure-ftpd directories: " + str(err), ". Should be ok", 1)
self.stdOut("[ERROR] Error creating extra pure-ftpd directories: " + str(err), ". Should be ok", 1)
data = open(ftpdPath+"/pureftpd-mysql.conf","r").readlines()
@@ -431,7 +428,7 @@ class InstallCyberPanel:
InstallCyberPanel.stdOut("PureFTPD configured!", 1)
except IOError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installPureFTPDConfigurations]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installPureFTPDConfigurations]")
return 0
def installPowerDNS(self):
@@ -448,12 +445,12 @@ class InstallCyberPanel:
os.rename('/etc/resolv.conf', 'etc/resolved.conf')
except OSError as e:
if e.errno != errno.EEXIST and e.errno != errno.ENOENT:
InstallCyberPanel.stdOut("Unable to rename /etc/resolv.conf to install PowerDNS: " +
InstallCyberPanel.stdOut("[ERROR] Unable to rename /etc/resolv.conf to install PowerDNS: " +
str(e), 1, 1, os.EX_OSERR)
try:
os.remove('/etc/resolv.conf')
except OSError as e1:
InstallCyberPanel.stdOut("Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
InstallCyberPanel.stdOut("[ERROR] Unable to remove existing /etc/resolv.conf to install PowerDNS: " +
str(e1), 1, 1, os.EX_OSERR)
@@ -463,7 +460,7 @@ class InstallCyberPanel:
f.write('nameserver 8.8.8.8')
f.close()
except IOError as e:
InstallCyberPanel.stdOut("Unable to create /etc/resolv.conf: " + str(e) +
InstallCyberPanel.stdOut("[ERROR] Unable to create /etc/resolv.conf: " + str(e) +
". This may need to be fixed manually as 'echo \"nameserver 8.8.8.8\"> "
"/etc/resolv.conf'", 1, 1, os.EX_OSERR)
@@ -485,7 +482,7 @@ class InstallCyberPanel:
install.preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
except BaseException, msg:
logging.InstallLog.writeToFile(str(msg) + " [powerDNS]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [powerDNS]")
def installPowerDNSConfigurations(self, mysqlPassword, mysql):
try:
@@ -530,7 +527,7 @@ class InstallCyberPanel:
InstallCyberPanel.stdOut("PowerDNS configured!", 1)
except IOError, msg:
logging.InstallLog.writeToFile(str(msg) + " [installPowerDNSConfigurations]")
logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [installPowerDNSConfigurations]")
return 0
return 1