def getLogsFromFile(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] == 1: pass else: return ACLManager.loadErrorJson('logstatus', 0) data = json.loads(request.body) type = data['type'] if type == "access": fileName = installUtilities.Server_root_path + "/logs/access.log" elif type == "error": fileName = installUtilities.Server_root_path + "/logs/error.log" elif type == "email": if ProcessUtilities.decideDistro() == ProcessUtilities.centos: fileName = "/var/log/maillog" else: fileName = "/var/log/mail.log" elif type == "ftp": if ProcessUtilities.decideDistro() == ProcessUtilities.centos: fileName = "/var/log/messages" else: fileName = "/var/log/syslog" elif type == "modSec": fileName = "/usr/local/lsws/logs/auditmodsec.log" elif type == "cyberpanel": fileName = "/home/cyberpanel/error-logs.txt" try: command = "sudo tail -50 " + fileName fewLinesOfLogFile = ProcessUtilities.outputExecutioner(command) status = { "status": 1, "logstatus": 1, "logsdata": fewLinesOfLogFile } final_json = json.dumps(status) return HttpResponse(final_json) except: status = {"status": 1, "logstatus": 1, "logsdata": 'Emtpy File.'} final_json = json.dumps(status) return HttpResponse(final_json) except KeyError, msg: status = { "status": 0, "logstatus": 0, "error": "Could not fetch data from log file, please see CyberCP main log file through command line." } logging.CyberCPLogFileWriter.writeToFile( str(msg) + "[getLogsFromFile]") final_json = json.dumps(status) return HttpResponse(final_json)
def test_addNewCron(self): ## Check cron creation data_ret = {'domain': 'cyberpanel.xyz', 'cronCommand': 'touch /home/cyberpanel.xyz/cron.txt' , 'hour': '*', 'minute': '*', 'month': '*', 'monthday': '*', 'weekday': '*'} response = self.MakeRequest('websites/addNewCron', data_ret) time.sleep(65) self.assertEqual(response['addNewCron'], 1) import os self.assertEqual(os.path.exists('/home/cyberpanel.xyz/cron.txt'), True) ## data_ret = {'domain': 'cyberpanel.xyz', 'line': 1} response = self.MakeRequest('websites/remCronbyLine', data_ret) self.assertEqual(response['remCronbyLine'], 1) if ProcessUtilities.decideDistro() == ProcessUtilities.centos: cronPath = "/var/spool/cron/cyberpa" else: cronPath = "/var/spool/cron/crontabs/cyberpa" exists = 0 if open(cronPath, 'r').read().find('cron.txt') > -1: exists = 1 self.assertEqual(exists, 0)
def submitInstallDocker(): try: statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Starting Docker Installation..\n", 1) if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo yum install -y docker' else: command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker.io' if not ServerStatusUtil.executioner(command, statusFile): logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Failed to install Docker. [404]\n", 1) return 0 command = 'sudo systemctl enable docker' ServerStatusUtil.executioner(command, statusFile) command = 'sudo systemctl start docker' ServerStatusUtil.executioner(command, statusFile) logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Docker successfully installed.[200]\n", 1) time.sleep(2) except BaseException, msg: logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
def fetchRam(self, request): try: request.session['userID'] = self.admin.pk currentACL = ACLManager.loadedACL(self.admin.pk) if currentACL['admin'] == 0: return self.ajaxPre( 0, 'Only administrators can see MySQL status.') #if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: # return self.ajaxPre(0, 'This feature is currently only available on CentOS.') from psutil import virtual_memory import math finalData = {} mem = virtual_memory() inGB = math.ceil(float(mem.total) / float(1024 * 1024 * 1024)) finalData['ramInGB'] = inGB if ProcessUtilities.decideDistro() == ProcessUtilities.centos: finalData['conf'] = subprocess.check_output( shlex.split('sudo cat /etc/my.cnf')) else: finalData['conf'] = subprocess.check_output( shlex.split('sudo cat /etc/mysql/my.cnf')) finalData['status'] = 1 finalData = json.dumps(finalData) return HttpResponse(finalData) except BaseException, msg: return self.ajaxPre(0, str(msg))
def getAdminStatus(request): try: val = request.session['userID'] currentACL = ACLManager.loadedACL(val) if os.path.exists('/home/cyberpanel/postfix'): currentACL['emailAsWhole'] = 1 else: currentACL['emailAsWhole'] = 0 if os.path.exists('/home/cyberpanel/pureftpd'): currentACL['ftpAsWhole'] = 1 else: currentACL['ftpAsWhole'] = 0 try: pdns = PDNSStatus.objects.get(pk=1) currentACL['dnsAsWhole'] = pdns.serverStatus except: if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: pdnsPath = '/etc/powerdns' else: pdnsPath = '/etc/pdns' if os.path.exists(pdnsPath): PDNSStatus(serverStatus=1).save() currentACL['dnsAsWhole'] = 1 else: currentACL['dnsAsWhole'] = 0 json_data = json.dumps(currentACL) return HttpResponse(json_data) except KeyError: return HttpResponse("Can not get admin Status")
def findPHPVersions(): if ProcessUtilities.decideDistro() == ProcessUtilities.centos: return [ 'PHP 5.3', 'PHP 5.4', 'PHP 5.5', 'PHP 5.6', 'PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3' ] else: return ['PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3']
def applyMySQLChanges(data): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo mv /etc/my.cnf /etc/my.cnf.bak' else: command = 'sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak' data['suggestedContent'] = data['suggestedContent'].replace('/var/lib/mysql/mysql.sock', '/var/run/mysqld/mysqld.sock') ProcessUtilities.executioner(command) ## Temp tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) writeToFile = open(tempPath, 'w') writeToFile.write(data['suggestedContent']) writeToFile.close() ## if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo mv ' + tempPath + ' /etc/my.cnf' else: command = 'sudo mv ' + tempPath + ' /etc/mysql/my.cnf' ProcessUtilities.executioner(command) return 1, None except BaseException, msg: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo mv /etc/my.cnf.bak /etc/my.cnf' else: command = 'sudo mv /etc/mysql/my.cnf.bak /etc/mysql//my.cnf' subprocess.call(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile(str(msg)) return 0, str(msg)
def setupNode(self): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: mesg = 'Clusters are only supported on Ubuntu 18.04. [404]' logging.statusWriter(self.data['tempStatusPath'], mesg) return 0 userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] == 0: mesg = 'Only administrators can create clusters. [404]' logging.statusWriter(self.data['tempStatusPath'], mesg) return 0 logging.statusWriter(self.data['tempStatusPath'], 'Setting up node in progress..') commands = self.data['commands'] for command in commands: try: result = subprocess.call(command, shell=True) if result != 0: logging.writeToFile(command + ' Failed.') except BaseException: logging.statusWriter(self.data['tempStatusPath'], command + ' Failed. [404]') return 0 try: FirewallUtilities.addRule('tcp', '2377', "0.0.0.0/0") fwRule = FirewallRules(name="Docker", port='2377', proto="tcp") fwRule.save() except: pass mesg = 'Node successfully configured. [200]' logging.statusWriter(self.data['tempStatusPath'], mesg) except BaseException, msg: logging.writeToFile(str(msg)) logging.statusWriter(self.data['tempStatusPath'], str(msg) + '. [404]')
def installCSF(): try: ## logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Downloading CSF..\n', 1) command = 'wget ' + CSF.csfURL ProcessUtilities.normalExecutioner(command) ## logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Extracting CSF..\n', 1) command = 'tar -xzf csf.tgz' ProcessUtilities.normalExecutioner(command) ## logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Installing CSF..\n', 1) os.chdir('csf') command = "chmod +x install.sh" ProcessUtilities.normalExecutioner(command) command = 'bash install.sh' ProcessUtilities.normalExecutioner(command) command = 'mv /etc/csf/ui/server.crt /etc/csf/ui/server.crt-bak' ProcessUtilities.normalExecutioner(command) command = 'mv /etc/csf/ui/server.key /etc/csf/ui/server.key-bak' ProcessUtilities.normalExecutioner(command) command = 'ln -s /usr/local/lscp/conf/cert.pem /etc/csf/ui/server.crt' ProcessUtilities.normalExecutioner(command) command = 'ln -s /usr/local/lscp/conf/key.pem /etc/csf/ui/server.key' ProcessUtilities.normalExecutioner(command) # install required packages for CSF perl and /usr/bin/host if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'yum install bind-utils net-tools perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph ipset -y' ProcessUtilities.normalExecutioner(command) elif ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'apt-get install dnsutils libwww-perl liblwp-protocol-https-perl libgd-graph-perl net-tools ipset -y' ProcessUtilities.normalExecutioner(command) command = 'ln -s /bin/systemctl /usr/bin/systemctl' ProcessUtilities.normalExecutioner(command) else: logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF required packages successfully Installed.[200]\n', 1) # Some initial configurations data = open('/etc/csf/csf.conf', 'r').readlines() writeToConf = open('/etc/csf/csf.conf', 'w') for items in data: if items.find('TCP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines( 'TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,1025,8090,40110:40210"\n') elif items.find('TCP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines( 'TCP_OUT = "20,21,22,25,43,53,80,110,113,443,587,993,995,8090,40110:40210"\n') elif items.find('UDP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('UDP_IN = "20,21,53"\n') elif items.find('UDP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('UDP_OUT = "20,21,53,113,123"\n') elif items.find('TESTING =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('TESTING = "0"\n') # setting RESTRICT_SYSLOG to "3" for use with option RESTRICT_SYSLOG_GROUP elif items.find('RESTRICT_SYSLOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RESTRICT_SYSLOG = "3"\n') # Send an email alert if an IP address is blocked by one of the [*] triggers: disabled elif items.find('LF_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_EMAIL_ALERT = "0"\n') # Set LF_PERMBLOCK_ALERT to "0" to disable this feature elif items.find('LF_PERMBLOCK_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_PERMBLOCK_ALERT = "0"\n') # Set LF_NETBLOCK_ALERT to "0" to disable this feature elif items.find('LF_NETBLOCK_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_NETBLOCK_ALERT = "0"\n') # Login Failure Blocking and Alerts # LF_TRIGGER_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_TRIGGER_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_TRIGGER_PERM = "1800"\n') # Enable login failure detection of sshd connections: 10 failures triggers elif items.find('LF_SSHD =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_SSHD = "10"\n') # LF_SSHD_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_SSHD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_SSHD_PERM = "1800"\n') # Enable login failure detection of ftp connections: 10 failures triggers elif items.find('LF_FTPD =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_FTPD = "10"\n') # LF_FTPD_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_FTPD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_FTPD_PERM = "1800"\n') # Enable login failure detection of SMTP AUTH connections: 10 failures triggers elif items.find('LF_SMTPAUTH =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_SMTPAUTH = "10"\n') # LF_SMTPAUTH_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_SMTPAUTH_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_SMTPAUTH_PERM = "1800"\n') # Enable login failure detection of pop3 connections: 10 failures triggers elif items.find('LF_POP3D =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_POP3D = "10"\n') # LF_POP3D_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_POP3D_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_POP3D_PERM = "1800"\n') # Enable login failure detection of imap connections: 10 failures triggers elif items.find('LF_IMAPD =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_IMAPD = "10"\n') # LF_IMAPD_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_IMAPD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_IMAPD_PERM = "1800"\n') # LF_HTACCESS_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_HTACCESS_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_HTACCESS_PERM = "1800"\n') # Enable failure detection of repeated Apache mod_security rule triggers: 10 failures triggers elif items.find('LF_MODSEC =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_MODSEC = "10"\n') # LF_MODSEC_PERM = "1800" => the IP is blocked temporarily for 30 minutes elif items.find('LF_MODSEC_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_MODSEC_PERM = "1800"\n') # MODSEC_LOG location elif items.find('MODSEC_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('MODSEC_LOG = "/usr/local/lsws/logs/auditmodsec.log"\n') # Send an email alert if anyone logs in successfully using SSH: Disabled elif items.find('LF_SSH_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_SSH_EMAIL_ALERT = "0"\n') # Send an email alert if anyone accesses webmin: Disabled not applicable elif items.find('LF_WEBMIN_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_WEBMIN_EMAIL_ALERT = "0"\n') # LF_QUEUE_ALERT disabled elif items.find('LF_QUEUE_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_QUEUE_ALERT = "0"\n') # LF_QUEUE_INTERVAL disabled elif items.find('LF_QUEUE_INTERVAL = "0"') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_TRIGGER_PERM = "1800"\n') # Relay Tracking. This allows you to track email that is relayed through the server. Disabled elif items.find('RT_RELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_RELAY_ALERT = "0"\n') # RT_[relay type]_LIMIT: the limit/hour afterwhich an email alert will be sent elif items.find('RT_RELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_RELAY_LIMIT = "500"\n') # RT_[relay type]_BLOCK: 0 = no block;1 = perm block;nn=temp block for nn secs elif items.find('RT_RELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_RELAY_BLOCK = "0"\n') # This option triggers for email authenticated by SMTP AUTH disabled elif items.find('RT_AUTHRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_AUTHRELAY_ALERT = "0"\n') # RT_AUTHRELAY_LIMIT set to 100 elif items.find('RT_AUTHRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_AUTHRELAY_LIMIT = "100"\n') # RT_AUTHRELAY_LIMIT set to 0 elif items.find('RT_AUTHRELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_AUTHRELAY_BLOCK = "0"\n') # This option triggers for email authenticated by POP before SMTP elif items.find('RT_POPRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_POPRELAY_ALERT = "0"\n') # This option triggers for email authenticated by POP before SMTP elif items.find('RT_POPRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_POPRELAY_LIMIT = "100"\n') # RT_POPRELAY_BLOCK disabled elif items.find('RT_POPRELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_POPRELAY_BLOCK = "0"\n') # This option triggers for email sent via /usr/sbin/sendmail or /usr/sbin/exim: Disabled elif items.find('RT_LOCALRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_LOCALRELAY_ALERT = "0"\n') # This option triggers for email sent via a local IP addresses elif items.find('RT_LOCALRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_LOCALRELAY_LIMIT = "100"\n') # This option triggers for email sent via a local IP addresses elif items.find('RT_LOCALHOSTRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_LOCALHOSTRELAY_ALERT = "0"\n') # This option triggers for email sent via a local IP addresses disabled elif items.find('RT_LOCALHOSTRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_LOCALHOSTRELAY_LIMIT = "100"\n') # If an RT_* event is triggered, then if the following contains the path to a script elif items.find('RT_ACTION') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('RT_ACTION = ""\n') # Send an email alert if an IP address is blocked due to connection tracking disabled elif items.find('CT_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('CT_EMAIL_ALERT = "0"\n') # User Process Tracking. Set to 0 to disable this feature elif items.find('PT_USERPROC =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_USERPROC = "0"\n') # This User Process Tracking option sends an alert if any user process exceeds the virtual memory usage set (MB) elif items.find('PT_USERMEM =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_USERMEM = "0"\n') # This User Process Tracking option sends an alert if any user process exceeds the RSS memory usage set (MB) - RAM used, not virtual. elif items.find('PT_USERRSS =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_USERRSS = "0"\n') # If this option is set then processes detected by PT_USERMEM, PT_USERTIME or PT_USERPROC are killed. Disabled elif items.find('PT_USERTIME =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_USERTIME = "0"\n') # If you want to disable email alerts if PT_USERKILL is triggered, then set this option to 0. Disabled elif items.find('PT_USERKILL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_USERKILL_ALERT = "0"\n') # Check the PT_LOAD_AVG minute Load Average (can be set to 1 5 or 15 and defaults to 5 if set otherwise) on the server every PT_LOAD seconds. Disabled elif items.find('PT_LOAD =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('PT_LOAD = "0"\n') # Enable LF_IPSET for CSF for more efficient ipables rules with ipset elif items.find('LF_IPSET =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('LF_IPSET = "1"\n') # HTACCESS_LOG is ins main error.log elif items.find('HTACCESS_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('HTACCESS_LOG = "/usr/local/lsws/logs/error.log"\n') # SYSLOG_CHECK Check whether syslog is running elif items.find('SYSLOG_CHECK =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('SYSLOG_CHECK = "300"\n') # CSF UI enable # elif items.find('UI = "0"') > -1 and items.find('=') > -1 and (items[0] != '#'): # writeToConf.writelines('UI = "1"\n') # elif items.find('UI_ALLOW') > -1 and items.find('=') > -1 and (items[0] != '#'): # writeToConf.writelines('UI_ALLOW = "0"\n') # elif items.find('UI_PORT =') > -1 and items.find('=') > -1 and (items[0] != '#'): # writeToConf.writelines('UI_PORT = "1025"\n') # elif items.find('UI_USER') > -1 and items.find('=') > -1 and (items[0] != '#'): # writeToConf.writelines('UI_USER = "******"\n') # elif items.find('UI_PASS') > -1 and items.find('=') > -1 and (items[0] != '#'): # writeToConf.writelines('UI_PASS = "******"\n') else: writeToConf.writelines(items) writeToConf.close() ## # Some Ubuntu initial configurations if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: data = open('/etc/csf/csf.conf', 'r').readlines() writeToConf = open('/etc/csf/csf.conf', 'w') for items in data: if items.find('SSHD_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('SSHD_LOG = "/var/log/auth.log"\n') elif items.find('SU_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('SU_LOG = "/var/log/auth.log"\n') elif items.find('SMTPAUTH_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('SMTPAUTH_LOG = "/var/log/mail.log"\n') elif items.find('POP3D_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('POP3D_LOG = "/var/log/mail.log"\n') elif items.find('IMAPD_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('IMAPD_LOG = "/var/log/mail.log"\n') elif items.find('IPTABLES_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('IPTABLES_LOG = "/var/log/kern.log"\n') elif items.find('SYSLOG_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'): writeToConf.writelines('SYSLOG_LOG = "/var/log/syslog"\n') else: writeToConf.writelines(items) writeToConf.close() ## command = 'csf -s' ProcessUtilities.normalExecutioner(command) command = 'sleep 5' ProcessUtilities.normalExecutioner(command) command = 'csf -ra' ProcessUtilities.normalExecutioner(command) logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF successfully Installed.[200]\n', 1) try: os.remove('csf.tgz') os.removedirs('csf') except: pass return 1 except BaseException, msg: try: os.remove('csf.tgz') os.removedirs('csf') except: pass writeToFile = open(CSF.installLogPath, 'a') writeToFile.writelines(str(msg) + " [404]") writeToFile.close() logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installCSF]")
def resFailed(res): if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu and res != 0: return True elif ProcessUtilities.decideDistro() == ProcessUtilities.centos and res == 1: return True return False