def remCronbyLine(externalApp, line): try: line -= 1 if ProcessUtilities.decideDistro() == ProcessUtilities.centos: cronPath = "/var/spool/cron/" + externalApp else: cronPath = "/var/spool/cron/crontabs/" + externalApp data = open(cronPath, 'r').readlines() counter = 0 writeToFile = open(cronPath, 'w') for items in data: if counter == line: removedLine = items continue else: writeToFile.writelines(items) counter = counter + 1 print "1," + removedLine except BaseException, msg: print "0," + str(msg)
def createDKIMRecords(domain): try: import tldextract extractDomain = tldextract.extract(domain) topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix zone = Domains.objects.get(name=topLevelDomain) path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt" command = "sudo cat " + path output = subprocess.check_output(shlex.split(command)) leftIndex = output.index('(') + 2 rightIndex = output.rindex(')') - 1 record = Records(domainOwner=zone, domain_id=zone.id, name="default._domainkey." + topLevelDomain, type="TXT", content=output[leftIndex:rightIndex], ttl=3600, prio=0, disabled=0, auth=1) record.save() if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( "We had errors while creating DKIM record for: " + domain + ". Error message: " + str(msg))
def installSpamAssassin(install, SpamAssassin): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo yum install spamassassin -y' else: command = 'sudo apt-get install spamassassin spamc -y' cmd = shlex.split(command) with open(mailUtilities.spamassassinInstallLogPath, 'w') as f: res = subprocess.call(cmd, stdout=f) if res == 1: writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') writeToFile.writelines("Can not be installed.[404]\n") writeToFile.close() logging.CyberCPLogFileWriter.writeToFile( "[Could not Install SpamAssassin.]") return 0 else: writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') writeToFile.writelines("SpamAssassin Installed.[200]\n") writeToFile.close() return 1 except BaseException, msg: writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') writeToFile.writelines("Can not be installed.[404]\n") writeToFile.close() logging.CyberCPLogFileWriter.writeToFile( str(msg) + "[installSpamAssassin]")
def unInstallPHPExtension(extension, extensions): try: mailUtilities.checkHome() if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo rpm --nodeps -e ' + extension + ' -v' else: command = 'sudo apt-get remove -y ' + extension cmd = shlex.split(command) try: with open(phpUtilities.installLogPath, 'w') as f: subprocess.call(cmd, stdout=f) writeToFile = open(phpUtilities.installLogPath, 'a') writeToFile.writelines("PHP Extension Removed.\n") writeToFile.close() installUtilities.installUtilities.reStartLiteSpeed() return 1 except: writeToFile = open(phpUtilities.installLogPath, 'a') writeToFile.writelines("Can not un-install Extension.\n") writeToFile.close() logging.CyberCPLogFileWriter.writeToFile("[Could not Install]") installUtilities.installUtilities.reStartLiteSpeed() return 0 except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + "[unInstallPHPExtension]")
def installModSec(): try: mailUtilities.checkHome() if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo yum install ols-modsecurity -y' else: command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install ols-modsecurity -y' cmd = shlex.split(command) with open(modSec.installLogPath, 'w') as f: res = subprocess.call(cmd, stdout=f) if res == 1: writeToFile = open(modSec.installLogPath, 'a') writeToFile.writelines("Can not be installed.[404]\n") writeToFile.close() logging.CyberCPLogFileWriter.writeToFile("[Could not Install]") return 0 else: writeToFile = open(modSec.installLogPath, 'a') writeToFile.writelines("ModSecurity Installed.[200]\n") writeToFile.close() return 1 except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + "[installModSec]")
def getWebsiteCron(externalApp): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: cronPath = "/var/spool/cron/" + externalApp else: cronPath = "/var/spool/cron/crontabs/" + externalApp try: f = open(cronPath, 'r').read() print f except BaseException, msg: print "0,CyberPanel," + str(msg) return 1 except BaseException, msg: print "0,CyberPanel," + str(msg)
def saveCronChanges(externalApp, finalCron, line): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: cronPath = "/var/spool/cron/" + externalApp else: cronPath = "/var/spool/cron/crontabs/" + externalApp with open(cronPath, 'r') as file: data = file.readlines() data[line] = finalCron + '\n' with open(cronPath, 'w') as file: file.writelines(data) print "1,None" except BaseException, msg: print "0," + str(msg)
def configureSpamAssassin(): try: if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: confFile = "/etc/mail/spamassassin/local.cf" confData = open(confFile).readlines() conf = open(confFile, 'w') for items in confData: if items.find('report_safe') > -1 or items.find( 'rewrite_header') > -1 or items.find( 'required_score') > -1 or items.find( 'required_hits') > -1: conf.write(items.strip('#').strip(' ')) else: conf.write(items) conf.close() command = "groupadd spamd" ProcessUtilities.normalExecutioner(command) command = "useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd" ProcessUtilities.normalExecutioner(command) ## command = "chown spamd:spamd /var/log/spamassassin" ProcessUtilities.normalExecutioner(command) command = "systemctl enable spamassassin" ProcessUtilities.normalExecutioner(command) command = "systemctl start spamassassin" ProcessUtilities.normalExecutioner(command) ## Configuration to postfix postfixConf = '/etc/postfix/master.cf' data = open(postfixConf, 'r').readlines() writeToFile = open(postfixConf, 'w') checker = 1 for items in data: if items.find('smtp') > -1 and items.find( 'inet') > -1 and items.find( 'smtpd') > -1 and checker == 1: writeToFile.writelines( items.strip('\n') + ' -o content_filter=spamassassin\n') checker = 0 else: writeToFile.writelines(items) writeToFile.writelines( 'spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}' ) writeToFile.close() command = 'systemctl restart postfix' ProcessUtilities.normalExecutioner(command) print "1,None" return except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [configureSpamAssassin]") print "0," + str(msg) return
def createDNSRecord(zone, name, type, value, priority, ttl): try: if zone.type == 'MASTER': getSOA = Records.objects.get(domainOwner=zone, type='SOA') soaContent = getSOA.content.split(' ') soaContent[2] = str(int(soaContent[2]) + 1) getSOA.content = " ".join(soaContent) getSOA.save() if type == 'NS': if Records.objects.filter(name=name, type=type, content=value).count() == 0: record = Records(domainOwner=zone, domain_id=zone.id, name=name, type=type, content=value, ttl=ttl, prio=priority, disabled=0, auth=1) record.save() if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) return if type == 'TXT': if Records.objects.filter(name=name, type=type, content=value).count() == 0: record = Records(domainOwner=zone, domain_id=zone.id, name=name, type=type, content=value, ttl=ttl, prio=priority, disabled=0, auth=1) record.save() if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) return if type == 'MX': record = Records(domainOwner=zone, domain_id=zone.id, name=name, type=type, content=value, ttl=ttl, prio=priority, disabled=0, auth=1) record.save() if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) return if Records.objects.filter(name=name, type=type).count() == 0: record = Records(domainOwner=zone, domain_id=zone.id, name=name, type=type, content=value, ttl=ttl, prio=priority, disabled=0, auth=1) record.save() if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDNSRecord]")
def dnsTemplate(domain, admin): try: ipFile = "/etc/cyberpanel/machineIP" f = open(ipFile) ipData = f.read() ipAddress = ipData.split('\n', 1)[0] import tldextract extractDomain = tldextract.extract(domain) topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix subDomain = extractDomain.subdomain if len(subDomain) == 0: if Domains.objects.filter(name=topLevelDomain).count() == 0: try: pdns = PDNSStatus.objects.get(pk=1) if pdns.type == 'MASTER': zone = Domains(admin=admin, name=topLevelDomain, type="MASTER") zone.save() for items in SlaveServers.objects.all(): record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="NS", content=items.slaveServer, ttl=3600, prio=0, disabled=0, auth=1) record.save() else: zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE") except: zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE") zone.save() if zone.type == 'NATIVE': record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="NS", content='hostmaster.%s' % (topLevelDomain), ttl=3600, prio=0, disabled=0, auth=1) record.save() if os.path.exists(DNS.defaultNameServersPath): defaultNS = open(DNS.defaultNameServersPath, 'r').readlines() for items in defaultNS: record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="NS", content=items, ttl=3600, prio=0, disabled=0, auth=1) record.save() else: record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="NS", content='ns1.%s' % (topLevelDomain), ttl=3600, prio=0, disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="NS", content='ns2.%s' % (topLevelDomain), ttl=3600, prio=0, disabled=0, auth=1) record.save() content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600" soaRecord = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="SOA", content=content, ttl=3600, prio=0, disabled=0, auth=1) soaRecord.save() ## Main A record. record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="A", content=ipAddress, ttl=3600, prio=0, disabled=0, auth=1) record.save() # CNAME Records. cNameValue = "www." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=cNameValue, type="CNAME", content=topLevelDomain, ttl=3600, prio=0, disabled=0, auth=1) record.save() cNameValue = "ftp." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=cNameValue, type="CNAME", content=topLevelDomain, ttl=3600, prio=0, disabled=0, auth=1) record.save() ## MX Record. mxValue = "mail." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="MX", content=mxValue, ttl=3600, prio="10", disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name=mxValue, type="A", content=ipAddress, ttl=3600, prio=0, disabled=0, auth=1) record.save() ## TXT Records for mail record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="TXT", content="v=spf1 a mx ip4:" + ipAddress + " ~all", ttl=3600, prio=0, disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name="_dmarc." + topLevelDomain, type="TXT", content="v=DMARC1; p=none", ttl=3600, prio=0, disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name="_domainkey." + topLevelDomain, type="TXT", content="t=y; o=~;", ttl=3600, prio=0, disabled=0, auth=1) record.save() else: if Domains.objects.filter(name=topLevelDomain).count() == 0: try: pdns = PDNSStatus.objects.get(pk=1) if pdns.type == 'MASTER': zone = Domains(admin=admin, name=topLevelDomain, type="MASTER") else: zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE") except: zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE") content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600" soaRecord = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="SOA", content=content, ttl=3600, prio=0, disabled=0, auth=1) soaRecord.save() ## Main A record. record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="A", content=ipAddress, ttl=3600, prio=0, disabled=0, auth=1) record.save() # CNAME Records. cNameValue = "www." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=cNameValue, type="CNAME", content=topLevelDomain, ttl=3600, prio=0, disabled=0, auth=1) record.save() cNameValue = "ftp." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=cNameValue, type="CNAME", content=topLevelDomain, ttl=3600, prio=0, disabled=0, auth=1) record.save() ## MX Record. mxValue = "mail." + topLevelDomain record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="MX", content=mxValue, ttl=3600, prio="10", disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name=mxValue, type="A", content=ipAddress, ttl=3600, prio=0, disabled=0, auth=1) record.save() ## TXT Records for mail record = Records(domainOwner=zone, domain_id=zone.id, name=topLevelDomain, type="TXT", content="v=spf1 a mx ip4:" + ipAddress + " ~all", ttl=3600, prio=0, disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name="_dmarc." + topLevelDomain, type="TXT", content="v=DMARC1; p=none", ttl=3600, prio=0, disabled=0, auth=1) record.save() record = Records(domainOwner=zone, domain_id=zone.id, name="_domainkey." + topLevelDomain, type="TXT", content="t=y; o=~;", ttl=3600, prio=0, disabled=0, auth=1) record.save() ## Creating sub-domain level record. zone = Domains.objects.get(name=topLevelDomain) actualSubDomain = subDomain + "." + topLevelDomain ## Main A record. DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600) # CNAME Records. cNameValue = "www." + actualSubDomain DNS.createDNSRecord(zone, cNameValue, "CNAME", actualSubDomain, 0, 3600) if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'sudo systemctl restart pdns' ProcessUtilities.executioner(command) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( "We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
def savePHPConfigBasic(phpVers, allow_url_fopen, display_errors, file_uploads, allow_url_include, memory_limit, max_execution_time, upload_max_filesize, max_input_time, post_max_size): try: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: path = "/usr/local/lsws/ls" + phpVers + "/etc/php.ini" else: initial = phpVers[3] final = phpVers[4] completeName = str(initial) + '.' + str(final) path = "/usr/local/lsws/ls" + phpVers + "/etc/php/" + completeName + "/litespeed/php.ini" logging.CyberCPLogFileWriter.writeToFile(path) data = open(path, 'r').readlines() writeToFile = open(path, 'w') for items in data: if items.find("allow_url_fopen") > -1 and items.find("=") > -1: writeToFile.writelines(allow_url_fopen + "\n") elif items.find("display_errors") > -1 and items.find( "=") > -1: writeToFile.writelines(display_errors + "\n") elif items.find("file_uploads") > -1 and items.find( "=") > -1 and not items.find("max_file_uploads") > -1: writeToFile.writelines(file_uploads + "\n") elif items.find("allow_url_include") > -1 and items.find( "=") > -1: writeToFile.writelines(allow_url_include + "\n") elif items.find("memory_limit") > -1 and items.find("=") > -1: writeToFile.writelines("memory_limit = " + memory_limit + "\n") elif items.find("max_execution_time") > -1 and items.find( "=") > -1: writeToFile.writelines("max_execution_time = " + max_execution_time + "\n") elif items.find("upload_max_filesize") > -1 and items.find( "=") > -1: writeToFile.writelines("upload_max_filesize = " + upload_max_filesize + "\n") elif items.find("max_input_time") > -1 and items.find( "=") > -1: writeToFile.writelines("max_input_time = " + max_input_time + "\n") elif items.find("post_max_size") > -1 and items.find("=") > -1: writeToFile.writelines("post_max_size = " + post_max_size + "\n") else: writeToFile.writelines(items) writeToFile.close() installUtilities.installUtilities.reStartLiteSpeed() print "1,None" except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [savePHPConfigBasic]") print "0," + str(msg)