-
{% trans "Issue SSL For Hostname" %}
+
{% 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 "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 @@
@@ -112,7 +112,7 @@