Merge branch 'v2.0.1' of https://github.com/usmannasir/cyberpanel into v2.0.1

This commit is contained in:
hennaboy
2020-05-28 16:05:52 +01:00
8 changed files with 801 additions and 5 deletions

View File

@@ -877,6 +877,9 @@
<li><a href="{% url 'emailMarketing' %}"
title="{% trans 'Email Marketing' %}"><span>{% trans "Email Marketing" %}</span></a>
</li>
<li><a href="{% url 'MailScanner' %}"
title="{% trans 'MailScanner' %}"><span>{% trans "MailScanner" %}</span></a>
</li>
</ul>
</div><!-- .sidebar-submenu -->

View File

@@ -13,6 +13,4 @@ urlpatterns = [
url(r'^UpgradeStatus',views.upgradeStatus, name='UpgradeStatus'),
url(r'^upgradeVersion',views.upgradeVersion, name='upgradeVersion'),
]

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

@@ -0,0 +1,107 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "MailScanner - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "MailScanner" %}</h2>
<p>{% trans "Install/Access MailScanner" %}</p>
</div>
<div ng-controller="MailScanner" class="example-box-wrapper">
<div class="panel panel-body">
<h3 class="content-box-header">
{% trans "MailScanner" %} <img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif">
</h3>
<div class="content-box-wrapper">
<div class="row">
{% if checkIfMailScannerInstalled == 0 %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h4 class="mb-10">{% trans "MailScanner is not installed " %}
</h4>
<button ng-click="installSpamAssassin()" class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Install Now." %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button>
</div>
<!------ SpamAssassin Install Log box ----------------->
<div ng-hide="SpamAssassinNotifyBox" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="failedToStartInallation" class="alert alert-danger">
<p>{% trans "Failed to start installation, Error message: " %} {$ errorMessage
$}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect. Please refresh this page." %} </p>
</div>
<div ng-hide="installationFailed" class="alert alert-danger">
<p>{% trans "Installation failed." %} {$ errorMessage $}</p>
</div>
<div ng-hide="SpamAssassinSuccessfullyInstalled" class="alert alert-success">
<p>{% trans "SpamAssassin successfully installed, refreshing page in 3 seconds.." %}</p>
</div>
</div>
</div>
<div ng-hide="SpamAssassinInstallBox" class="col-md-12">
<form action="/" id="" class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12 text-center">
<h3><img
src="{% static 'firewall/icons/firewall.png' %}"> {% trans "Winter is coming, but so is MailScanner." %}
<img ng-hide="SpamAssassinLoading" src="/static/images/loading.gif">
</h3>
</div>
<div style="margin-top: 2%;" class="col-sm-12">
<textarea ng-model="requestData" rows="15"
class="form-control">{{ requestData }}</textarea>
</div>
</div>
</form>
</div>
<!----- SpamAssassin Install Log box ----------------->
{% else %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h4 class="mb-10">{% trans "MailScanner is installed. " %}
</h4>
<a href="https://{{ ipAddress }}:8090/mailwatch/mailscanner/">
<button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Access Now." %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

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

View File

@@ -1166,4 +1166,58 @@ def delete(request):
except KeyError as msg:
dic = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(dic)
return HttpResponse(json_data)
return HttpResponse(json_data)
## MailScanner
def MailScanner(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
checkIfMailScannerInstalled = 0
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
if mailUtilities.checkIfMailScannerInstalled() == 1:
checkIfMailScannerInstalled = 1
return render(request, 'emailPremium/MailScanner.html',{'checkIfMailScannerInstalled': checkIfMailScannerInstalled, 'ipAddress': ipAddress})
except KeyError:
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):
try:
if os.path.exists(mailUtilities.spamassassinInstallLogPath):
os.remove(mailUtilities.spamassassinInstallLogPath)
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
command = 'sudo yum install spamassassin -y'
else:
@@ -477,6 +480,51 @@ milter_default_action = accept
writeToFile.close()
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
def checkIfSpamAssassinInstalled():
try:
@@ -666,6 +714,22 @@ milter_default_action = accept
str(msg) + " [savePolicyServerStatus]")
print("0," + str(msg))
@staticmethod
def checkIfMailScannerInstalled():
try:
path = "/usr/local/CyberCP/public/mailwatch"
if os .path.exists(path):
return 1
else:
return 0
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(
str(msg) + " [checkIfMailScannerInstalled]")
return 0
def main():
@@ -695,6 +759,8 @@ def main():
mailUtilities.savePolicyServerStatus(args.install)
elif args.function == 'installSpamAssassin':
mailUtilities.installSpamAssassin("install", "SpamAssassin")
elif args.function == 'installMailScanner':
mailUtilities.installMailScanner("install", "installMailScanner")
elif args.function == 'AfterEffects':
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;
}
};
});