Skip to content

Commit

Permalink
bug fix: fix opendkim on config rest
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Jan 6, 2024
1 parent 0e59955 commit f895bd5
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 131 deletions.
30 changes: 17 additions & 13 deletions CyberCP/secMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from loginSystem.models import Administrator


class secMiddleware:
HIGH = 0
LOW = 1
Expand Down Expand Up @@ -52,7 +53,7 @@ def __call__(self, request):

if request.method == 'POST':
try:
#logging.writeToFile(request.body)
# logging.writeToFile(request.body)
data = json.loads(request.body)
for key, value in data.items():
if request.path.find('gitNotify') > -1:
Expand All @@ -78,7 +79,8 @@ def __call__(self, request):
continue

if key == 'backupDestinations':
if re.match('^[a-z|0-9]+:[a-z|0-9|\.]+\/?[A-Z|a-z|0-9|\.]*$', value) == None and value != 'local':
if re.match('^[a-z|0-9]+:[a-z|0-9|\.]+\/?[A-Z|a-z|0-9|\.]*$',
value) == None and value != 'local':
logging.writeToFile(request.body)
final_dic = {'error_message': "Data supplied is not accepted.",
"errorMessage": "Data supplied is not accepted."}
Expand All @@ -87,14 +89,14 @@ def __call__(self, request):

if request.build_absolute_uri().find(
'api/remoteTransfer') > -1 or request.build_absolute_uri().find(
'api/verifyConn') > -1 or request.build_absolute_uri().find(
'webhook') > -1 or request.build_absolute_uri().find(
'saveSpamAssassinConfigurations') > -1 or request.build_absolute_uri().find(
'docker') > -1 or request.build_absolute_uri().find(
'cloudAPI') > -1 or request.build_absolute_uri().find(
'verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1:
'api/verifyConn') > -1 or request.build_absolute_uri().find(
'webhook') > -1 or request.build_absolute_uri().find(
'saveSpamAssassinConfigurations') > -1 or request.build_absolute_uri().find(
'docker') > -1 or request.build_absolute_uri().find(
'cloudAPI') > -1 or request.build_absolute_uri().find(
'verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1:
continue
if key == 'CLAMAV_VIRUS' or key == "Rspamdserver" or key == 'smtpd_milters' or key == 'non_smtpd_milters' or key == 'key' or key == 'cert' or key == 'recordContentAAAA' or key == 'backupDestinations' or key == 'ports' \
if key == 'scriptUrl' or key == 'CLAMAV_VIRUS' or key == "Rspamdserver" or key == 'smtpd_milters' or key == 'non_smtpd_milters' or key == 'key' or key == 'cert' or key == 'recordContentAAAA' or key == 'backupDestinations' or key == 'ports' \
or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' \
or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' \
or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' \
Expand All @@ -106,7 +108,7 @@ def __call__(self, request):
")") > -1 \
or value.find("'") > -1 or value.find("[") > -1 or value.find("]") > -1 or value.find(
"{") > -1 or value.find("}") > -1 \
or value.find(":") > -1 or value.find("<") >-1 or value.find(">") > -1:
or value.find(":") > -1 or value.find("<") > -1 or value.find(">") > -1:
logging.writeToFile(request.body)
final_dic = {
'error_message': "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >.",
Expand Down Expand Up @@ -143,9 +145,11 @@ def __call__(self, request):
response['X-Frame-Options'] = "sameorigin"
response['Content-Security-Policy'] = "script-src 'self' https://www.jsdelivr.com"
response['Content-Security-Policy'] = "connect-src *;"
response['Content-Security-Policy'] = "font-src 'self' 'unsafe-inline' https://www.jsdelivr.com https://fonts.googleapis.com"
response['Content-Security-Policy'] = "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://www.jsdelivr.com https://cdnjs.cloudflare.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net"
#response['Content-Security-Policy'] = "default-src 'self' cyberpanel.cloud *.cyberpanel.cloud"
response[
'Content-Security-Policy'] = "font-src 'self' 'unsafe-inline' https://www.jsdelivr.com https://fonts.googleapis.com"
response[
'Content-Security-Policy'] = "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://www.jsdelivr.com https://cdnjs.cloudflare.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net"
# response['Content-Security-Policy'] = "default-src 'self' cyberpanel.cloud *.cyberpanel.cloud"
response['X-Content-Type-Options'] = "nosniff"
response['Referrer-Policy'] = "same-origin"

Expand Down
6 changes: 3 additions & 3 deletions baseTemplate/templates/baseTemplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,6 @@
title="{% trans 'DKIM Manager' %}"><span>{% trans "DKIM Manager" %}</span></a>
</li>
{% endif %}
<li><a href="{% url 'EmailDebugger' %}"
title="{% trans 'Email Debugger' %}"><span>{% trans "Email Debugger" %}</span></a>
</li>

{% if admin or createEmail %}
<li><a href="/snappymail/index.php" title="{% trans 'Access Webmail' %}"
Expand Down Expand Up @@ -1039,6 +1036,9 @@
<div class="sidebar-submenu">

<ul>
<li><a href="{% url 'EmailDebugger' %}"
title="{% trans 'Email Debugger' %}"><span>{% trans "Email Debugger" %}</span></a>
</li>
<li><a href="{% url 'mailQueue' %}"
title="{% trans 'Mail Queue' %}"><span>{% trans "Mail Queue" %}</span></a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion baseTemplate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
url(r'^design', views.design, name='design'),
url(r'^getthemedata', views.getthemedata, name='getthemedata'),

#url(r'^upgrade',views.upgrade, name='upgrade'),
url(r'^upgrade',views.upgrade, name='upgrade'),

url(r'^UpgradeStatus',views.upgradeStatus, name='UpgradeStatus'),
url(r'^upgradeVersion',views.upgradeVersion, name='upgradeVersion'),
Expand Down
2 changes: 1 addition & 1 deletion baseTemplate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def upgrade(request):

vers = version.objects.get(pk=1)

from upgrade import Upgrade
from plogical.upgrade import Upgrade

Upgrade.initiateUpgrade(vers.currentVersion, vers.build)

Expand Down
39 changes: 39 additions & 0 deletions mailServer/mailserverManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,39 @@ def setup_postfix_dovecot_config(self):

return 1

def installOpenDKIMNew(self):
try:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Installing opendkim..,40')

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
command = 'yum -y install opendkim'
elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'dnf install opendkim -y'
else:
command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install opendkim'

os.system(command)

if ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'dnf install opendkim-tools -y'
ProcessUtilities.executioner(command)

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
command = 'apt install opendkim-tools -y'
ProcessUtilities.executioner(command)

command = 'mkdir -p /etc/opendkim/keys/'
ProcessUtilities.executioner(command)


except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'%s [installOpenDKIM][404]' % (str(msg)), 10)
return 0

return 1

def configureOpenDKIM(self):
try:

Expand Down Expand Up @@ -1440,6 +1473,7 @@ def configureOpenDKIM(self):
return 1

except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(f'Error in configureOpenDKIM {str(msg)}')
return 0

def fixCyberPanelPermissions(self):
Expand Down Expand Up @@ -1652,6 +1686,11 @@ def ResetEmailConfigurations(self):

logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Restoreing OpenDKIM configurations..,70')

if self.installOpenDKIMNew() == 0:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Install OpenDKIM failed. [404].')
return 0

if self.configureOpenDKIM() == 0:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'configureOpenDKIM failed. [404].')
return 0
Expand Down
57 changes: 55 additions & 2 deletions plogical/mailUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,51 @@ def fixCyberPanelPermissions(self):

###

def installOpenDKIMNew(self):
try:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Installing opendkim..,40')

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:

command = 'yum -y erase opendkim*'
os.system(command)

command = 'yum -y install opendkim'
elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8:

command = 'yum -y erase opendkim*'
os.system(command)

command = 'dnf install opendkim -y'
else:

command = 'apt-get -y purge opendkim'
os.system(command)

command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install opendkim'

os.system(command)

if ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'dnf install opendkim-tools -y'
ProcessUtilities.executioner(command)

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
command = 'apt install opendkim-tools -y'
ProcessUtilities.executioner(command)

command = 'mkdir -p /etc/opendkim/keys/'
ProcessUtilities.executioner(command)


except BaseException as msg:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'%s [installOpenDKIM][404]' % (str(msg)), 10)
return 0

return 1

def ResetEmailConfigurations(self):
try:
### Check if remote or local mysql
Expand Down Expand Up @@ -2121,6 +2166,11 @@ def ResetEmailConfigurations(self):
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Restoring OpenDKIM configurations..,70')

if self.installOpenDKIMNew() == 0:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Install OpenDKIM failed. [404].')
return 0

if self.configureOpenDKIM() == 0:
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'configureOpenDKIM failed. [404].')
Expand Down Expand Up @@ -2159,6 +2209,9 @@ def ResetEmailConfigurations(self):

self.fixCyberPanelPermissions()

command = 'touch /home/cyberpanel/postfix'
ProcessUtilities.executioner(command)

logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')

except BaseException as msg:
Expand Down Expand Up @@ -2203,11 +2256,11 @@ def configureOpenDKIM(self):
writeToFile.write(configData)
writeToFile.close()

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
data = open(openDKIMConfigurePath, 'r').readlines()
writeToFile = open(openDKIMConfigurePath, 'w')
for items in data:
if items.find('Socket') > -1 and items.find('local:') and items[0] != '#':
if items.find('Socket') > -1 and items.find('local:') > -1:
writeToFile.writelines('Socket inet:8891@localhost\n')
else:
writeToFile.writelines(items)
Expand Down
Loading

0 comments on commit f895bd5

Please sign in to comment.