complete mailscanner

This commit is contained in:
Usman Nasir
2020-05-28 16:19:30 +05:00
parent dcb2b654cf
commit 009969a0ea
7 changed files with 676 additions and 12 deletions

View File

@@ -60,6 +60,7 @@
} }
</style> </style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]--> <!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
<title>{% block title %}Page Title{% endblock %}</title> <title>{% block title %}Page Title{% endblock %}</title>
@@ -72,7 +73,20 @@
<script src="https://code.angularjs.org/1.6.5/angular.min.js"></script> <script src="https://code.angularjs.org/1.6.5/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBase.css' %}" <!-- HELPERS -->
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBase.css' %}">
<!-- ELEMENTS -->
<!-- ICONS -->
<!-- WIDGETS -->
<!-- SNIPPETS -->
<!-- APPLICATIONS -->
<!-- Admin theme -->
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBaseTheme.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/assets/finalBase/finalBaseTheme.css' %}">

View File

@@ -1287,4 +1287,287 @@ app.controller('mailQueue', function($scope,$http) {
}; };
}); });
/* Java script code to manage mail queue ends here */ /* Java script code to manage mail queue ends here */
app.controller('MailScanner', function($scope, $http, $timeout, $window) {
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
$scope.installSpamAssassin = function(){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/emailPremium/installMailScanner";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.status === 1){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
getRequestStatus();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = false;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
};
function getRequestStatus(){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/emailPremium/installStatusSpamAssassin";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.abort === 0){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus,1000);
}
else{
// Notifications
$timeout.cancel();
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.requestData = response.data.requestStatus;
if(response.data.installed === 0) {
$scope.installationFailed = false;
$scope.errorMessage = response.data.error_message;
}else{
$scope.SpamAssassinSuccessfullyInstalled = false;
$timeout(function() { $window.location.reload(); }, 3000);
}
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
///// SpamAssassin configs
var report_safe = false;
$('#report_safe').change(function() {
report_safe = $(this).prop('checked');
});
fetchSpamAssassinSettings();
function fetchSpamAssassinSettings(){
$scope.SpamAssassinLoading = false;
$('#report_safe').bootstrapToggle('off');
url = "/emailPremium/fetchSpamAssassinSettings";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.SpamAssassinLoading = true;
if(response.data.fetchStatus === 1){
if(response.data.installed === 1) {
if (response.data.report_safe === 1) {
$('#report_safe').bootstrapToggle('on');
}
$scope.required_hits = response.data.required_hits;
$scope.rewrite_header = response.data.rewrite_header;
$scope.required_score = response.data.required_score;
}
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinLoading = true;
}
}
/////
/// Save SpamAssassin Changes
$scope.failedToSave = true;
$scope.successfullySaved = true;
$scope.saveSpamAssassinConfigurations = function () {
$scope.failedToSave = true;
$scope.successfullySaved = true;
$scope.SpamAssassinLoading = false;
$scope.couldNotConnect = true;
url = "/emailPremium/saveSpamAssassinConfigurations";
var data = {
report_safe:report_safe,
required_hits:$scope.required_hits,
rewrite_header:$scope.rewrite_header,
required_score:$scope.required_score
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.saveStatus === 1){
$scope.failedToSave = true;
$scope.successfullySaved = false;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
else{
$scope.errorMessage = response.data.error_message;
$scope.failedToSave = false;
$scope.successfullySaved = true;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
}
function cantLoadInitialDatas(response) {
$scope.failedToSave = true;
$scope.successfullySaved = false;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
};
});

View File

@@ -17,7 +17,7 @@
<div ng-controller="MailScanner" class="example-box-wrapper"> <div ng-controller="MailScanner" class="example-box-wrapper">
<div class="panel panel-body"> <div class="panel panel-body">
<h3 class="content-box-header"> <h3 class="content-box-header">
{% trans "SpamAssassin" %} <img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif"> {% trans "MailScanner" %} <img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif">
</h3> </h3>
<div class="content-box-wrapper"> <div class="content-box-wrapper">
@@ -66,7 +66,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-sm-12 text-center"> <div class="col-sm-12 text-center">
<h3><img <h3><img
src="{% static 'firewall/icons/firewall.png' %}"> {% trans "Winter is coming, but so is SpamAssassin." %} src="{% static 'firewall/icons/firewall.png' %}"> {% trans "Winter is coming, but so is MailScanner." %}
<img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif"> <img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif">
</h3> </h3>
</div> </div>
@@ -83,12 +83,13 @@
{% else %} {% else %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;"> <div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h4 class="mb-10">{% trans "MailScanner is not installed " %} <h4 class="mb-10">{% trans "MailScanner is installed. " %}
</h4> </h4>
<button ng-click="installSpamAssassin()" class="btn btn-alt btn-hover btn-blue-alt"> <a href="https://{{ ipAddress }}:8090/mailwatch/mailscanner/">
<span>{% trans "Install Now." %}</span> <button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Access Now." %}</span>
<i class="glyph-icon icon-arrow-right"></i> <i class="glyph-icon icon-arrow-right"></i>
</button> </button></a>
</div> </div>
{% endif %} {% endif %}

View File

@@ -39,6 +39,7 @@ urlpatterns = [
url(r'^flushQueue$', views.flushQueue, name='flushQueue'), url(r'^flushQueue$', views.flushQueue, name='flushQueue'),
url(r'^delete$', views.delete, name='delete'), url(r'^delete$', views.delete, name='delete'),
url(r'^MailScanner$', views.MailScanner, name='MailScanner'), url(r'^MailScanner$', views.MailScanner, name='MailScanner'),
url(r'^installMailScanner$', views.installMailScanner, name='installMailScanner'),
url(r'^(?P<domain>(.*))$', views.emailLimits, name='emailLimits'), url(r'^(?P<domain>(.*))$', views.emailLimits, name='emailLimits'),

View File

@@ -1182,10 +1182,42 @@ def MailScanner(request):
checkIfMailScannerInstalled = 0 checkIfMailScannerInstalled = 0
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
if mailUtilities.checkIfMailScannerInstalled() == 1: if mailUtilities.checkIfMailScannerInstalled() == 1:
checkIfMailScannerInstalled = 1 checkIfMailScannerInstalled = 1
return render(request, 'emailPremium/MailScanner.html',{'checkIfMailScannerInstalled': checkIfMailScannerInstalled})
return render(request, 'emailPremium/MailScanner.html',{'checkIfMailScannerInstalled': checkIfMailScannerInstalled, 'ipAddress': ipAddress})
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def installMailScanner(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()
try:
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
execPath = execPath + " installMailScanner"
ProcessUtilities.popenExecutioner(execPath)
final_json = json.dumps({'status': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'status': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

View File

@@ -449,6 +449,9 @@ milter_default_action = accept
def installSpamAssassin(install, SpamAssassin): def installSpamAssassin(install, SpamAssassin):
try: try:
if os.path.exists(mailUtilities.spamassassinInstallLogPath):
os.remove(mailUtilities.spamassassinInstallLogPath)
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'sudo yum install spamassassin -y' command = 'sudo yum install spamassassin -y'
else: else:
@@ -477,6 +480,51 @@ milter_default_action = accept
writeToFile.close() writeToFile.close()
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]") logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]")
@staticmethod
def installMailScanner(install, SpamAssassin):
try:
if os.path.exists(mailUtilities.spamassassinInstallLogPath):
os.remove(mailUtilities.spamassassinInstallLogPath)
if mailUtilities.checkIfSpamAssassinInstalled():
command = 'chmod +x /usr/local/CyberCP/CPScripts/mailscannerinstaller.sh'
ProcessUtilities.executioner(command)
command = '/usr/local/CyberCP/CPScripts/mailscannerinstaller.sh'
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 MailScanner.]")
return 0
else:
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
writeToFile.writelines("MailScanner Installed.[200]\n")
writeToFile.close()
return 1
else:
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
writeToFile.writelines("Please install SpamAssassin from CyberPanel before installing MailScanner.[404]\n")
writeToFile.close()
except BaseException as msg:
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
writeToFile.writelines("Can not be installed.[404]\n")
writeToFile.close()
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]")
@staticmethod @staticmethod
def checkIfSpamAssassinInstalled(): def checkIfSpamAssassinInstalled():
try: try:
@@ -670,7 +718,7 @@ milter_default_action = accept
def checkIfMailScannerInstalled(): def checkIfMailScannerInstalled():
try: try:
path = "/usr/local/CyberCP/public/mailscanner" path = "/usr/local/CyberCP/public/mailwatch"
if os .path.exists(path): if os .path.exists(path):
return 1 return 1
@@ -711,6 +759,8 @@ def main():
mailUtilities.savePolicyServerStatus(args.install) mailUtilities.savePolicyServerStatus(args.install)
elif args.function == 'installSpamAssassin': elif args.function == 'installSpamAssassin':
mailUtilities.installSpamAssassin("install", "SpamAssassin") mailUtilities.installSpamAssassin("install", "SpamAssassin")
elif args.function == 'installMailScanner':
mailUtilities.installMailScanner("install", "installMailScanner")
elif args.function == 'AfterEffects': elif args.function == 'AfterEffects':
mailUtilities.AfterEffects(args.domain) mailUtilities.AfterEffects(args.domain)

View File

@@ -1287,4 +1287,287 @@ app.controller('mailQueue', function($scope,$http) {
}; };
}); });
/* Java script code to manage mail queue ends here */ /* Java script code to manage mail queue ends here */
app.controller('MailScanner', function($scope, $http, $timeout, $window) {
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
$scope.installSpamAssassin = function(){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/emailPremium/installMailScanner";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.status === 1){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
getRequestStatus();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = true;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = false;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
};
function getRequestStatus(){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
url = "/emailPremium/installStatusSpamAssassin";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.abort === 0){
$scope.SpamAssassinNotifyBox = true;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = false;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus,1000);
}
else{
// Notifications
$timeout.cancel();
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = true;
$scope.requestData = response.data.requestStatus;
if(response.data.installed === 0) {
$scope.installationFailed = false;
$scope.errorMessage = response.data.error_message;
}else{
$scope.SpamAssassinSuccessfullyInstalled = false;
$timeout(function() { $window.location.reload(); }, 3000);
}
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinNotifyBox = false;
$scope.SpamAssassinInstallBox = false;
$scope.SpamAssassinLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.SpamAssassinSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
///// SpamAssassin configs
var report_safe = false;
$('#report_safe').change(function() {
report_safe = $(this).prop('checked');
});
fetchSpamAssassinSettings();
function fetchSpamAssassinSettings(){
$scope.SpamAssassinLoading = false;
$('#report_safe').bootstrapToggle('off');
url = "/emailPremium/fetchSpamAssassinSettings";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.SpamAssassinLoading = true;
if(response.data.fetchStatus === 1){
if(response.data.installed === 1) {
if (response.data.report_safe === 1) {
$('#report_safe').bootstrapToggle('on');
}
$scope.required_hits = response.data.required_hits;
$scope.rewrite_header = response.data.rewrite_header;
$scope.required_score = response.data.required_score;
}
}
}
function cantLoadInitialDatas(response) {
$scope.SpamAssassinLoading = true;
}
}
/////
/// Save SpamAssassin Changes
$scope.failedToSave = true;
$scope.successfullySaved = true;
$scope.saveSpamAssassinConfigurations = function () {
$scope.failedToSave = true;
$scope.successfullySaved = true;
$scope.SpamAssassinLoading = false;
$scope.couldNotConnect = true;
url = "/emailPremium/saveSpamAssassinConfigurations";
var data = {
report_safe:report_safe,
required_hits:$scope.required_hits,
rewrite_header:$scope.rewrite_header,
required_score:$scope.required_score
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.saveStatus === 1){
$scope.failedToSave = true;
$scope.successfullySaved = false;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
else{
$scope.errorMessage = response.data.error_message;
$scope.failedToSave = false;
$scope.successfullySaved = true;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
}
function cantLoadInitialDatas(response) {
$scope.failedToSave = true;
$scope.successfullySaved = false;
$scope.SpamAssassinLoading = true;
$scope.couldNotConnect = true;
}
};
});