diff --git a/api/views.py b/api/views.py index 75215e71c..d167e8576 100644 --- a/api/views.py +++ b/api/views.py @@ -8,22 +8,16 @@ from plogical.virtualHostUtilities import virtualHostUtilities from plogical import hashPassword from plogical.installUtilities import installUtilities from packages.models import Package -import shutil -from plogical.mysqlUtilities import mysqlUtilities -from databases.models import Databases from baseTemplate.views import renderBase from random import randint from websiteFunctions.models import Websites,ChildDomains import os -import signal -from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging -from shutil import rmtree from baseTemplate.models import version import subprocess import shlex import re -from dns.models import Domains,Records from plogical.mailUtilities import mailUtilities +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging # Create your views here. @@ -35,7 +29,6 @@ def verifyConn(request): adminUser = data['adminUser'] adminPass = data['adminPass'] - admin = Administrator.objects.get(userName=adminUser) if hashPassword.check_password(admin.password, adminPass): @@ -66,6 +59,9 @@ def createWebsite(request): websiteOwner = data['websiteOwner'] ownerPassword = data['ownerPassword'] externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:7] + data['ssl'] = 0 + data['dkimCheck'] = 0 + data['openBasedir'] = 1 phpSelection = "PHP 7.0" diff --git a/backup/views.py b/backup/views.py index 0872c947a..0487c3382 100644 --- a/backup/views.py +++ b/backup/views.py @@ -1139,9 +1139,7 @@ def submitRemoteBackups(request): if data['getVersion'] == 1: - Version = version.objects.get(pk=1) - - if data['currentVersion'] == Version.currentVersion and data['build'] >= 0: + if float(data['currentVersion']) >= 1.6 and data['build'] >= 0: pass else: data_ret = {'status': 0, diff --git a/firewall/templates/firewall/modSecurity.html b/firewall/templates/firewall/modSecurity.html index d842ba6cf..c5cb679aa 100644 --- a/firewall/templates/firewall/modSecurity.html +++ b/firewall/templates/firewall/modSecurity.html @@ -10,7 +10,7 @@
-

{% trans "ModSecurity Configurations!" %}

+

{% trans "ModSecurity Configurations!" %} - {% trans "ModSec Docs" %}

{% trans "On this page you can configure ModSecurity settings." %}

diff --git a/firewall/templates/firewall/modSecurityRules.html b/firewall/templates/firewall/modSecurityRules.html index 57ca3d59f..404ac9708 100644 --- a/firewall/templates/firewall/modSecurityRules.html +++ b/firewall/templates/firewall/modSecurityRules.html @@ -10,7 +10,7 @@
-

{% trans "ModSecurity Rules!" %}

+

{% trans "ModSecurity Rules!" %} - {% trans "ModSec Docs" %}

{% trans "On this page you can add/delete ModSecurity rules." %}

diff --git a/firewall/templates/firewall/modSecurityRulesPacks.html b/firewall/templates/firewall/modSecurityRulesPacks.html index fcfa238ad..4f4649449 100644 --- a/firewall/templates/firewall/modSecurityRulesPacks.html +++ b/firewall/templates/firewall/modSecurityRulesPacks.html @@ -10,7 +10,7 @@
-

{% trans "ModSecurity Rules Packages!" %}

+

{% trans "ModSecurity Rules Packages!" %} - {% trans "ModSec Docs" %}

{% trans "Install/Un-install ModSecurity rules packages." %}

diff --git a/firewall/templates/firewall/secureSSH.html b/firewall/templates/firewall/secureSSH.html index 35099113c..9fddc38ad 100644 --- a/firewall/templates/firewall/secureSSH.html +++ b/firewall/templates/firewall/secureSSH.html @@ -10,7 +10,7 @@
-

{% trans "Secure SSH" %}

+

{% trans "Secure SSH" %} - {% trans "SSH Docs" %}

{% trans "Secure or harden SSH Configurations." %}

diff --git a/install/install.py b/install/install.py index fc6f8df4a..03044f7d6 100644 --- a/install/install.py +++ b/install/install.py @@ -687,8 +687,8 @@ class preFlightsChecks: count = 0 while (1): - #command = "wget http://cyberpanel.net/CyberPanel.1.6.4.tar.gz" - command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz" + command = "wget http://cyberpanel.net/CyberPanel.1.7.0.tar.gz" + #command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz" res = subprocess.call(shlex.split(command)) if res == 1: @@ -707,8 +707,8 @@ class preFlightsChecks: count = 0 while(1): - #command = "tar zxf CyberPanel.1.6.4.tar.gz" - command = "tar zxf CyberPanelTemp.tar.gz" + command = "tar zxf CyberPanel.1.7.0.tar.gz" + #command = "tar zxf CyberPanelTemp.tar.gz" res = subprocess.call(shlex.split(command)) @@ -1271,7 +1271,7 @@ class preFlightsChecks: count = 0 while(1): - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/postfix/key.pem -out /etc/postfix/cert.pem' + 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/postfix/key.pem -out /etc/postfix/cert.pem' cmd = shlex.split(command) @@ -1293,7 +1293,7 @@ class preFlightsChecks: while(1): - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/dovecot/key.pem -out /etc/dovecot/cert.pem' + 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/dovecot/key.pem -out /etc/dovecot/cert.pem' cmd = shlex.split(command) @@ -2048,6 +2048,10 @@ class preFlightsChecks: break ###### + command = 'systemctl restart dbus' + cmd = shlex.split(command) + subprocess.call(cmd) + count = 0 @@ -2908,4 +2912,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index cbb45a334..ba4d15a07 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -762,7 +762,7 @@ class InstallCyberPanel: count = 0 while(1): - command = 'openssl req -newkey rsa:2048 -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' + 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' res = subprocess.call(shlex.split(command)) if res == 1: @@ -1128,7 +1128,7 @@ class InstallCyberPanel: count = 0 while(1): - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem' + 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 /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem' cmd = shlex.split(command) res = subprocess.call(cmd) diff --git a/install/pure-ftpd-one/pure-ftpd.conf b/install/pure-ftpd-one/pure-ftpd.conf index 58490b30a..1c0af0529 100644 --- a/install/pure-ftpd-one/pure-ftpd.conf +++ b/install/pure-ftpd-one/pure-ftpd.conf @@ -29,6 +29,6 @@ AltLog clf:/var/log/pureftpd.log CreateHomeDir yes MaxDiskUsage 99 CustomerProof yes -TLS 2 +TLS 1 PassivePortRange 40110 40210 diff --git a/install/pure-ftpd/pure-ftpd.conf b/install/pure-ftpd/pure-ftpd.conf index 58490b30a..1c0af0529 100644 --- a/install/pure-ftpd/pure-ftpd.conf +++ b/install/pure-ftpd/pure-ftpd.conf @@ -29,6 +29,6 @@ AltLog clf:/var/log/pureftpd.log CreateHomeDir yes MaxDiskUsage 99 CustomerProof yes -TLS 2 +TLS 1 PassivePortRange 40110 40210 diff --git a/loginSystem/templates/loginSystem/login.html b/loginSystem/templates/loginSystem/login.html index d6f0db03b..5e41e782b 100755 --- a/loginSystem/templates/loginSystem/login.html +++ b/loginSystem/templates/loginSystem/login.html @@ -67,7 +67,7 @@
-

CyberPanel v 1.6

+

CyberPanel v 1.7

Web Hosting Control Panel

    diff --git a/loginSystem/views.py b/loginSystem/views.py index e1bd6f2b4..df53c0fec 100644 --- a/loginSystem/views.py +++ b/loginSystem/views.py @@ -132,7 +132,7 @@ def loadLoginPage(request): firstName="Cyber",lastName="Panel") admin.save() - vers = version(currentVersion="1.6",build=4) + vers = version(currentVersion="1.7",build=0) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, diff --git a/manageSSL/templates/manageSSL/manageSSL.html b/manageSSL/templates/manageSSL/manageSSL.html index 3e4655055..342ba9157 100644 --- a/manageSSL/templates/manageSSL/manageSSL.html +++ b/manageSSL/templates/manageSSL/manageSSL.html @@ -10,7 +10,7 @@
    -

    {% trans "Manage SSL" %}

    +

    {% trans "Manage SSL" %} - {% trans "SSL Docs" %}

    {% trans "This page can be used to issue Let’s Encrypt SSL for existing websites on server." %}

    diff --git a/manageSSL/templates/manageSSL/sslForHostName.html b/manageSSL/templates/manageSSL/sslForHostName.html index 45b0b95c6..2a746175e 100644 --- a/manageSSL/templates/manageSSL/sslForHostName.html +++ b/manageSSL/templates/manageSSL/sslForHostName.html @@ -10,7 +10,7 @@
    -

    {% trans "Issue SSL For Hostname" %}

    +

    {% trans "Issue SSL For Hostname" %} - {% trans "SSL Docs" %}

    {% trans "Let’s Encrypt SSL for hostname to access CyberPanel on verified SSL." %}

    diff --git a/manageSSL/templates/manageSSL/sslForMailServer.html b/manageSSL/templates/manageSSL/sslForMailServer.html index 191306c5a..4c8876be5 100644 --- a/manageSSL/templates/manageSSL/sslForMailServer.html +++ b/manageSSL/templates/manageSSL/sslForMailServer.html @@ -10,7 +10,7 @@
    -

    {% trans "Issue SSL For MailServer" %}

    +

    {% trans "Issue SSL For MailServer" %} - {% trans "SSL Docs" %}

    {% trans "Let’s Encrypt SSL for MailServer (Postfix/Dovecot)." %}

    diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index cd091d931..1f78acbe6 100644 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -384,4 +384,4 @@ def issueSSLForDomain(domain, adminEmail, sslpath, aliasDomain = None): return [0, "220 Failed to install SSL for domain. [issueSSLForDomain]"] except BaseException,msg: - return [0, "347 "+ str(msg)+ " [issueSSLForDomain]"] + return [0, "347 "+ str(msg)+ " [issueSSLForDomain]"] \ No newline at end of file diff --git a/plogical/upgrade.py b/plogical/upgrade.py index fdd4d9bf2..043de6fae 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -1,22 +1,285 @@ import os +import os.path +import sys +import django +sys.path.append('/usr/local/CyberCP') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() import shlex import subprocess import shutil import requests import json import time +from baseTemplate.models import version class Upgrade: logPath = "/usr/local/lscp/logs/upgradeLog" + @staticmethod + def stdOut(message): + 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") + @staticmethod def downloadLink(): - url = "https://cyberpanel.net/version.txt" - r = requests.get(url, verify=True) - data = json.loads(r.text) - version_number = str(data['version']) - version_build = str(data['build']) - return ("Temp.tar.gz") + try: + url = "https://cyberpanel.net/version.txt" + r = requests.get(url, verify=True) + data = json.loads(r.text) + version_number = str(data['version']) + version_build = str(data['build']) + return (version_number + "." + version_build + ".tar.gz") + except BaseException, msg: + Upgrade.stdOut(str(msg) + ' [downloadLink]') + os._exit(0) + + @staticmethod + def setupVirtualEnv(): + try: + ## + count = 0 + while (1): + command = "yum install -y libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to install project dependant modules, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to install project dependant modules! [setupVirtualEnv]") + os._exit(0) + else: + Upgrade.stdOut("Project dependant modules installed successfully!!") + break + + ## + + + count = 0 + while (1): + command = "pip install virtualenv" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to install virtualenv, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed install virtualenv! [setupVirtualEnv]") + os._exit(0) + else: + Upgrade.stdOut("virtualenv installed successfully!") + break + + #### + + count = 0 + while (1): + command = "virtualenv --system-site-packages /usr/local/CyberCP" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to setup virtualenv, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to setup virtualenv! [setupVirtualEnv]") + os._exit(0) + else: + Upgrade.stdOut("virtualenv setuped successfully!") + break + + ## + + env_path = '/usr/local/CyberCP' + subprocess.call(['virtualenv', env_path]) + activate_this = os.path.join(env_path, 'bin', 'activate_this.py') + execfile(activate_this, dict(__file__=activate_this)) + + ## + + count = 0 + while (1): + command = "pip install --ignore-installed -r /usr/local/CyberCP/requirments.txt" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to install project dependant modules, trying again, try number: " + str(count)) + if count == 3: + Upgrade.InstallLog.writeToFile( + "Failed to install project dependant modules! [setupVirtualEnv]") + break + else: + Upgrade.stdOut("Project dependant modules installed successfully!!") + break + + command = "systemctl stop gunicorn.socket" + res = subprocess.call(shlex.split(command)) + + command = "virtualenv --system-site-packages /usr/local/CyberCP" + res = subprocess.call(shlex.split(command)) + + + except OSError, msg: + Upgrade.stdOut(str(msg) + " [setupVirtualEnv]") + os._exit(0) + + @staticmethod + def upgradeOpenLiteSpeed(): + try: + ## + count = 0 + while (1): + command = "yum upgrade -y openlitespeed" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to upgrade OpenLiteSpeed, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to upgrade OpenLiteSpeed! [upgradeOpenLiteSpeed]") + else: + Upgrade.stdOut("OpenLiteSpeed successfully upgraded!") + break + + ## + + except OSError, msg: + Upgrade.stdOut(str(msg) + " [upgradeOpenLiteSpeed]") + os._exit(0) + + + @staticmethod + def updateGunicornConf(): + try: + path = '/etc/systemd/system/gunicorn.service' + + cont = """[Unit] +Description=gunicorn daemon +Requires=gunicorn.socket +After=network.target + +[Service] +PIDFile=/run/gunicorn/pid +User=cyberpanel +Group=cyberpanel +RuntimeDirectory=gunicorn +WorkingDirectory=/usr/local/CyberCP +ExecStart=/usr/local/CyberCP/bin/gunicorn --pid /run/gunicorn/gucpid \ + --bind 127.0.0.1:5003 CyberCP.wsgi +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +PrivateTmp=true + +[Install] +WantedBy=multi-user.target""" + + writeToFile = open(path, 'w') + writeToFile.write(cont) + writeToFile.close() + + + command = 'systemctl daemon-reload' + subprocess.call(shlex.split(command)) + + command = 'systemctl restart gunicorn.socket' + subprocess.call(shlex.split(command)) + + except BaseException, msg: + Upgrade.stdOut(str(msg) + " [updateGunicornConf]") + os._exit(0) + + + @staticmethod + def fileManager(): + ## Copy File manager files + + count = 1 + while (1): + command = "rm -rf /usr/local/lsws/Example/html/FileManager" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to remove old File manager files, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to remove old File manager files! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Old File Manager files successfully removed!") + break + + count = 1 + while (1): + command = "mv /usr/local/CyberCP/install/FileManager /usr/local/lsws/Example/html" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to upgrade File manager, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to upgrade File manager! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("File manager successfully upgraded!") + break + + command = "chmod -R 777 /usr/local/lsws/Example/html/FileManager" + subprocess.call(shlex.split(command)) + + @staticmethod + def staticContent(): + count = 1 + while (1): + command = "rm -rf /usr/local/lscp/cyberpanel/static" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to remove old static content, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to remove old static content! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Static content successfully removed!") + break + + count = 1 + while (1): + command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to update static content, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to update static content! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Static content in place!") + break + + @staticmethod + def upgradeVersion(): + vers = version.objects.get(pk=1) + getVersion = requests.get('https://cyberpanel.net/version.txt') + latest = getVersion.json() + vers.currentVersion = latest['version'] + vers.build = latest['build'] + vers.save() @@ -25,83 +288,221 @@ class Upgrade: os.chdir("/usr/local") + ## Current Version + + Version = version.objects.get(pk=1) + + ## + versionNumbring = Upgrade.downloadLink() + if float(Version.currentVersion) < 1.6: + Upgrade.stdOut('Upgrades works for version 1.6 onwards.') + os._exit(0) + + ## RC Check + + rcCheck = 1 + + if os.path.exists('/usr/local/CyberCP/postfixSenderPolicy'): + rcCheck = 0 + ## Download latest version. - command = "wget https://cyberpanel.net/CyberPanel" + versionNumbring - subprocess.call(shlex.split(command)) + count = 0 + while (1): + command = "wget https://cyberpanel.net/CyberPanel." + versionNumbring + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Downloading latest version, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to download latest version! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Latest version successfully downloaded!") + break ## Backup settings file. + Upgrade.stdOut("Backing up settings file.") + shutil.copy("/usr/local/CyberCP/CyberCP/settings.py","/usr/local/settings.py") + Upgrade.stdOut("Settings file backed up.") + ## Remove Core Files - command = "rm -rf /usr/local/CyberCP" - subprocess.call(shlex.split(command)) + count = 1 + while (1): + command = "rm -rf /usr/local/CyberCP" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to remove old version, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to remove old version! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Old version successfully removed!") + break ## Extract Latest files - command = "tar zxf CyberPanel" + versionNumbring - subprocess.call(shlex.split(command)) + count = 1 + while (1): + command = "tar zxf CyberPanel." + versionNumbring + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to extract new version, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut("Failed to extract new version! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("New version successfully extracted!") + break ## Copy settings file - shutil.copy("/usr/local/settings.py", "/usr/local/CyberCP/CyberCP/") + Upgrade.stdOut('Restoring settings file!') + + + data = open("/usr/local/settings.py", 'r').readlines() + writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w') + + for items in data: + if items.find("'filemanager',") > -1: + writeToFile.writelines(items) + if Version.currentVersion == '1.6': + writeToFile.writelines(" 'emailPremium'\n") + else: + writeToFile.writelines(items) + + writeToFile.close() + + Upgrade.stdOut('Settings file restored!') ## Move static files - command = "rm -rf /usr/local/lscp/cyberpanel/static" - subprocess.call(shlex.split(command)) + Upgrade.staticContent() - command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel" - subprocess.call(shlex.split(command)) + ## Upgrade File Manager - ## Copy File manager files - - command = "rm -rf /usr/local/lsws/Example/html/FileManager" - subprocess.call(shlex.split(command)) - - command = "mv /usr/local/CyberCP/install/FileManager /usr/local/lsws/Example/html" - subprocess.call(shlex.split(command)) + Upgrade.fileManager() ## Install TLDExtract - command = "pip install tldextract" - subprocess.call(shlex.split(command)) + count = 1 + while (1): + command = "pip install tldextract" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to install tldextract, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut( + "Failed to install tldextract! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("tldextract successfully installed! [pip]") + break + + ## Install dnspython #command = "pip install dnspython" #subprocess.call(shlex.split(command)) - ## Change File manager permissions - - command = "chmod -R 777 /usr/local/lsws/Example/html/FileManager" - subprocess.call(shlex.split(command)) ## MailServer Model Changes - os.chdir('/usr/local/CyberCP') + if Version.currentVersion == '1.6' and rcCheck : + os.chdir('/usr/local/CyberCP') - command = "echo 'ALTER TABLE e_forwardings DROP PRIMARY KEY;ALTER TABLE e_forwardings ADD id INT AUTO_INCREMENT PRIMARY KEY;' | python manage.py dbshell" - subprocess.check_output(command, shell=True) + count = 1 + while (1): + command = "echo 'ALTER TABLE e_forwardings DROP PRIMARY KEY;ALTER TABLE e_forwardings ADD id INT AUTO_INCREMENT PRIMARY KEY;' | python manage.py dbshell" + res = subprocess.check_output(command, shell=True) - ## Restart Gunicorn + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to patch database for email forwarding, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut( + "Failed to patch database for email forwarding! [upgrade]") + os._exit(0) - command = "systemctl restart gunicorn.socket" + else: + Upgrade.stdOut("Database successfully patched for email forwarding!") + break + + count = 1 + while (1): + command = "python manage.py makemigrations emailPremium" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to setup migration file for email limits, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut( + "Failed to setup migration file for email limits! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Migrations file for email limits successfully prepared!") + break + + count = 1 + while (1): + command = "python manage.py migrate emailPremium" + res = subprocess.call(shlex.split(command)) + + if res == 1: + count = count + 1 + Upgrade.stdOut( + "Trying to execute migration file for email limits, trying again, try number: " + str(count)) + if count == 3: + Upgrade.stdOut( + "Failed to execute migration file for email limits! [upgrade]") + os._exit(0) + else: + Upgrade.stdOut("Migrations file for email limits successfully executed!") + break + + + Upgrade.stdOut('Setting up virtual enviroment for CyberPanel.') + Upgrade.setupVirtualEnv() + Upgrade.stdOut('Virtual enviroment for CyberPanel successfully installed.') + if Version.currentVersion == '1.6': + Upgrade.updateGunicornConf() + command = 'systemctl restart gunicorn.socket' subprocess.call(shlex.split(command)) + + ## Upgrade OpenLiteSpeed + + Upgrade.upgradeOpenLiteSpeed() time.sleep(3) ## Upgrade version - r = requests.post("http://localhost:5003/base/upgradeVersion") + Upgrade.upgradeVersion() - print("Upgrade Completed.") + Upgrade.stdOut("Upgrade Completed.") diff --git a/postfixSenderPolicy/accept_traffic.py b/postfixSenderPolicy/accept_traffic.py index b00724016..acc693693 100755 --- a/postfixSenderPolicy/accept_traffic.py +++ b/postfixSenderPolicy/accept_traffic.py @@ -34,15 +34,22 @@ class HandleRequest(multi.Thread): while True: Data = self.connection.recv(64) - # Wait for a connection - if os.path.exists(HandleRequest.cleaningPath): - readFromFile = open(HandleRequest.cleaningPath, 'r') - command = readFromFile.read() - cacheManager.handlePurgeRequest(command) - readFromFile.close() - os.remove(HandleRequest.cleaningPath) - cacheManager.flushCache() + + try: + if os.path.exists(HandleRequest.cleaningPath): + + readFromFile = open(HandleRequest.cleaningPath, 'r') + command = readFromFile.read() + + cacheManager.handlePurgeRequest(command) + + readFromFile.close() + + os.remove(HandleRequest.cleaningPath) + cacheManager.flushCache() + except: + pass if Data: if len(Data) < 64: @@ -62,16 +69,22 @@ class HandleRequest(multi.Thread): def manageRequest(self, completeData): try: + completeData = completeData.split('\n') for items in completeData: tempData = items.split('=') - if tempData[0] == 'sender': + if tempData[0] == 'sasl_username': + if len(tempData[1]) == 0: + self.connection.sendall('action=dunno\n\n') + return emailAddress = tempData[1] domainName = emailAddress.split('@')[1] elif tempData[0] == 'recipient': destination = tempData[1] + + if domainName in cacheManager.domains: domainObj = cacheManager.domains[domainName] emailObj = domainObj.findEmailOBJ(emailAddress) @@ -95,9 +108,11 @@ class HandleRequest(multi.Thread): #logging.writeToFile('Email Monthly Used: ' + str(emailObj.monthlyUsed)) if domainObj.limitStatus == 1 and emailObj.limitStatus == 1: + if domainObj.monthlyLimits <= domainObj.monthlyUsed or emailObj.monthlyLimits <= emailObj.monthlyUsed or emailObj.hourlyLimits <= emailObj.hourlyUsed: logging.writeToFile(emailAddress + ' either exceeded monthly or hourly sending limit.') self.connection.sendall('action=defer_if_permit Service temporarily unavailable\n\n') + return else: email = EUsers.objects.get(email=emailAddress) if emailObj.logStatus == 1: @@ -113,8 +128,10 @@ class HandleRequest(multi.Thread): logEntry = EmailLogs(email=email, destination=destination, timeStamp=time.strftime("%I-%M-%S-%a-%b-%Y")) logEntry.save() + emailObj.monthlyUsed = emailObj.monthlyUsed + 1 emailObj.hourlyUsed = emailObj.hourlyUsed + 1 + domainObj.monthlyUsed = domainObj.monthlyUsed + 1 self.connection.sendall('action=dunno\n\n') diff --git a/postfixSenderPolicy/cacheManager.py b/postfixSenderPolicy/cacheManager.py index cb1d19669..0bf33aa11 100755 --- a/postfixSenderPolicy/cacheManager.py +++ b/postfixSenderPolicy/cacheManager.py @@ -123,7 +123,6 @@ class cacheManager: @staticmethod def hourlyCleanUP(): try: - for domain, domainOBJ in cacheManager.domains.iteritems(): for email, emailOBJ in domainOBJ.emails.iteritems(): @@ -133,12 +132,8 @@ class cacheManager: dbEmail.hourlyUsed = 0 dbEmail.save() - emailID = EUsers.objects.get(email=email) - dbEmail = EmailLimits.objects.get(email=emailID) - dbEmail.hourlyUsed = 0 emailOBJ.hourlyUsed = 0 - dbEmail.save() except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.hourlyCleanUP]') diff --git a/postfixSenderPolicy/policyConstraint.py b/postfixSenderPolicy/policyConstraint.py index f5ed2ef99..4aadbc5dd 100644 --- a/postfixSenderPolicy/policyConstraint.py +++ b/postfixSenderPolicy/policyConstraint.py @@ -23,7 +23,6 @@ class policyConstraints: def findEmailOBJ(self, emailAddress): if emailAddress in self.emails: return self.emails[emailAddress] - else: email = EUsers.objects.get(email=emailAddress) emailLTS = EmailLimits.objects.get(email=email) diff --git a/postfixSenderPolicy/startServer.py b/postfixSenderPolicy/startServer.py index 4e5800f6f..b7b9bd7b3 100755 --- a/postfixSenderPolicy/startServer.py +++ b/postfixSenderPolicy/startServer.py @@ -50,13 +50,16 @@ class SetupConn: try: self.sock.listen(5) while True: - # Wait for a connection - if os.path.exists(SetupConn.cleaningPath): - readFromFile = open(SetupConn.cleaningPath, 'r') - command = readFromFile.read() - cacheManager.handlePurgeRequest(command) - readFromFile.close() - os.remove(SetupConn.cleaningPath) + try: + # Wait for a connection + if os.path.exists(SetupConn.cleaningPath): + readFromFile = open(SetupConn.cleaningPath, 'r') + command = readFromFile.read() + cacheManager.handlePurgeRequest(command) + readFromFile.close() + os.remove(SetupConn.cleaningPath) + except: + pass connection, client_address = self.sock.accept() background = handle.HandleRequest(connection) diff --git a/userManagment/templates/userManagment/createUser.html b/userManagment/templates/userManagment/createUser.html index 4b1e10944..e07d371a1 100644 --- a/userManagment/templates/userManagment/createUser.html +++ b/userManagment/templates/userManagment/createUser.html @@ -102,7 +102,7 @@
    - +
    {% trans "Username should be lowercase alphanumeric." %}
    @@ -112,7 +112,7 @@
    - +
    {% trans "Must contain one number and one special character." %}
    @@ -123,9 +123,7 @@
    -