feature: configure server mailer for CyberPanel notifications

This commit is contained in:
Usman Nasir
2020-03-17 20:51:45 +05:00
parent bae625a2d2
commit 88aee551c1
17 changed files with 2192 additions and 1625 deletions

View File

@@ -797,6 +797,8 @@
<div class="sidebar-submenu">
<ul>
<li><a href="{% url 'serverMail' %}"
title="{% trans 'Server Mail' %}"><span>{% trans "Server Mail" %}</span></a></li>
<li><a href="{% url 'accessLogs' %}"
title="{% trans 'Access Log' %}"><span>{% trans "Access Log" %}</span></a></li>
<li><a href="{% url 'errorLogs' %}"

View File

@@ -8,8 +8,29 @@ class CyberCPLogFileWriter:
fileName = "/home/cyberpanel/error-logs.txt"
@staticmethod
def SendEmail(sender, receivers, message):
def SendEmail(sender, receivers, message, subject=None, type=None):
try:
smtpPath = '/home/cyberpanel/smtpDetails'
if os.path.exists(smtpPath):
import json
mailSettings = json.loads(open(smtpPath, 'r').read())
smtpHost = mailSettings['smtpHost']
smtpPort = mailSettings['smtpPort']
smtpUserName = mailSettings['smtpUserName']
smtpPassword = mailSettings['smtpPassword']
smtpServer = smtplib.SMTP(str(smtpHost), int(smtpPort))
smtpServer.login(smtpUserName, smtpPassword)
##
if subject != None:
message = 'Subject: {}\n\n{}'.format(subject, message)
smtpServer.sendmail(smtpUserName, receivers, message)
else:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print("Successfully sent email")

View File

@@ -9,6 +9,11 @@ from IncBackups.IncBackupsControl import IncJobs
from IncBackups.models import BackupJob
from random import randint
import argparse
import json
from websiteFunctions.models import GitLogs, Websites
from websiteFunctions.website import WebsiteManager
import time
try:
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.mailUtilities import mailUtilities
@@ -18,6 +23,7 @@ except:
class IncScheduler():
logPath = '/home/cyberpanel/incbackuplogs'
gitFolder = '/home/cyberpanel/git'
@staticmethod
def startBackup(type):
@@ -82,6 +88,76 @@ class IncScheduler():
except BaseException as msg:
logging.writeToFile(str(msg))
@staticmethod
def git(type):
try:
for website in os.listdir(IncScheduler.gitFolder):
finalText = ''
web = Websites.objects.get(domain=website)
message = '[%s Cron] Checking if %s has any pending commits on %s.' % (type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
finalText = '%s\n' % (message)
GitLogs(owner=web, type='INFO', message = message).save()
finalPathInside = '%s/%s' % (IncScheduler.gitFolder, website)
for file in os.listdir(finalPathInside):
if file.find('public_html') > -1:
finalPath = '/home/%s/public_html' % (website)
finalPathConf = '%s/%s' % (finalPathInside, file)
elif file.find('vmail') > -1:
finalPath = '/home/vmail/%s' % (website)
finalPathConf = '%s/%s' % (finalPathInside, file)
else:
finalPath = '/var/lib/mysql/%s' % (file)
finalPathConf = '%s/%s' % (finalPathInside, file)
gitConf = json.loads(open(finalPathConf, 'r').read())
data = {}
data['domain'] = website
data['folder'] = finalPath
data['commitMessage'] = 'Auto commit by CyberPanel %s cron on %s.' % (type, time.strftime('%m.%d.%Y_%H-%M-%S'))
if gitConf['autoCommit'] == type:
wm = WebsiteManager()
resp = wm.commitChanges(1, data)
logging.writeToFile(resp.content)
resp = json.loads(resp.content)
message = 'Folder: %s, Status: %s' % (finalPath, resp['commandStatus'])
finalText = '%s\n%s' % (finalText, message)
if resp['status'] == 1:
GitLogs(owner=web, type='INFO', message=message).save()
else:
GitLogs(owner=web, type='ERROR', message=message).save()
if gitConf['autoPush'] == type:
wm = WebsiteManager()
resp = wm.gitPush(1, data)
resp = json.loads(resp.content)
if resp['status'] == 1:
GitLogs(owner=web, type='INFO', message=resp['commandStatus']).save()
finalText = '%s\n%s' % (finalText, resp['commandStatus'])
else:
GitLogs(owner=web, type='ERROR', message=resp['commandStatus']).save()
finalText = '%s\n%s' % (finalText, resp['commandStatus'])
message = '[%s Cron] Finished checking for %s on %s.' % (type, website, time.strftime("%m.%d.%Y_%H-%M-%S"))
finalText = '%s\n%s' % (finalText, message)
logging.SendEmail(web.adminEmail, web.adminEmail, finalText, 'Git report for %s.' % (web.domain))
GitLogs(owner=web, type='INFO', message=message).save()
except BaseException as msg:
logging.writeToFile('%s. [IncScheduler.git:90]' % (str(msg)))
def main():
@@ -90,6 +166,7 @@ def main():
args = parser.parse_args()
IncScheduler.startBackup(args.function)
IncScheduler.git(args.function)
if __name__ == "__main__":

View File

@@ -0,0 +1,4 @@
import subprocess
command = 'git -C /home/usman/Backup/CyberCP commit -m "Auto commit by CyberPanel Daily cron on"'
print(subprocess.check_output(command, shell=True).decode("utf-8"))

View File

@@ -3,10 +3,8 @@
*/
/* Java script code to read access log file */
app.controller('readAccessLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -32,7 +30,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -42,9 +39,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -55,6 +50,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -64,8 +60,6 @@ app.controller('readAccessLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -92,7 +86,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -102,9 +95,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -115,6 +106,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -151,7 +143,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -161,9 +152,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -174,6 +163,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -186,16 +176,10 @@ app.controller('readAccessLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read error log file */
app.controller('readErrorLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -221,7 +205,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -231,9 +214,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -244,6 +225,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -253,8 +235,6 @@ app.controller('readErrorLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -281,7 +261,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -291,9 +270,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -304,6 +281,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -340,7 +318,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -350,9 +327,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -363,6 +338,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -375,14 +351,10 @@ app.controller('readErrorLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read ftp log file */
app.controller('readFTPLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -408,7 +380,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -418,9 +389,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -431,6 +400,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -440,8 +410,6 @@ app.controller('readFTPLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -468,7 +436,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -478,9 +445,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -491,6 +456,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -527,7 +493,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -537,9 +502,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -550,6 +513,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -562,14 +526,10 @@ app.controller('readFTPLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read email log file */
app.controller('readEmailLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -595,7 +555,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -605,9 +564,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -618,6 +575,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -627,8 +585,6 @@ app.controller('readEmailLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -655,7 +611,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -665,9 +620,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -678,6 +631,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -714,7 +668,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -724,9 +677,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -737,6 +688,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -749,14 +701,10 @@ app.controller('readEmailLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read modsec audit log file */
app.controller('modSecAuditLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -782,7 +730,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -792,9 +739,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -805,6 +750,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -814,8 +760,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -842,7 +786,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -852,9 +795,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -865,6 +806,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -900,7 +842,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -910,9 +851,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -923,6 +862,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -935,6 +875,71 @@ app.controller('modSecAuditLogs', function($scope,$http) {
});
/* Java script code to read modsec audit log ends here */
app.controller('serverMail', function ($scope, $http) {
$scope.cyberPanelLoading = true;
$scope.installationDetailsForm = true;
$scope.mailerSettings = function(){
if($scope.mailer === 'SMTP'){
$scope.installationDetailsForm = false;
}else {
$scope.installationDetailsForm = true;
}
};
$scope.saveSMTPSettings = function () {
$scope.cyberPanelLoading = false;
var url = "/serverlogs/saveSMTPSettings";
var data = {
mailer: $scope.mailer,
smtpHost: $scope.smtpHost,
smtpPort: $scope.smtpPort,
smtpUserName: $scope.smtpUserName,
smtpPassword: $scope.smtpPassword
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully saved.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.cyberPanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});

View File

@@ -0,0 +1,88 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Server Mail - 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 "Manage Server Mail" %}</h2>
<p>{% trans "On this page you can configure how CyberPanel send mails. (Notifications or Errors from CyberPanel)" %}</p>
</div>
<div ng-controller="serverMail" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Manage SMTP Hosts" %} <img ng-hide="cyberPanelLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row">
<!---- Create SMTP Host --->
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Mailer" %}</label>
<div class="col-sm-6">
<select ng-change="mailerSettings()" ng-model="mailer" class="form-control">
<option>Default</option>
<option>SMTP</option>
</select>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "SMTP Host" %}</label>
<div ng-init="smtpHost='{{ smtpHost }}'" class="col-sm-6">
<input type="text" class="form-control" ng-model="smtpHost" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
<div ng-init="smtpPort='{{ smtpPort }}'" class="col-sm-6">
<input type="text" class="form-control" ng-model="smtpPort" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Username" %}</label>
<div ng-init="smtpUserName='{{ smtpUserName }}'" class="col-sm-6">
<input type="text" class="form-control" ng-model="smtpUserName" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
<div ng-init="smtpPassword='{{ smtpPassword }}'" class="col-sm-6">
<input type="password" class="form-control" ng-model="smtpPassword" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="saveSMTPSettings()"
class="btn btn-primary btn-lg btn-block">{% trans "Save" %}</button>
</div>
</div>
<!---- Create SMTP Host --->
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -10,5 +10,6 @@ urlpatterns = [
url(r'^modSecAuditLogs', views.modSecAuditLogs, name='modSecAuditLogs'),
url(r'^getLogsFromFile',views.getLogsFromFile, name="getLogsFromFile"),
url(r'^clearLogFile',views.clearLogFile, name="clearLogFile"),
url(r'^serverMail$', views.serverMail, name="serverMail"),
url(r'^saveSMTPSettings$', views.saveSMTPSettings, name="saveSMTPSettings"),
]

View File

@@ -203,3 +203,90 @@ def clearLogFile(request):
data_ret = {'cleanStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def serverMail(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
smtpPath = '/home/cyberpanel/smtpDetails'
data = {}
if os.path.exists(smtpPath):
mailSettings = json.loads(open(smtpPath, 'r').read())
data['smtpHost'] = mailSettings['smtpHost']
data['smtpPort'] = mailSettings['smtpPort']
data['smtpUserName'] = mailSettings['smtpUserName']
data['smtpPassword'] = mailSettings['smtpPassword']
return render(request,'serverLogs/serverMail.html', data)
except KeyError as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
return redirect(loadLoginPage)
def saveSMTPSettings(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson('logstatus', 0)
data = json.loads(request.body)
mailer = data['mailer']
smtpPath = '/home/cyberpanel/smtpDetails'
if mailer != 'SMTP':
if os.path.exists(smtpPath):
os.remove(smtpPath)
else:
import smtplib
smtpHost = data['smtpHost']
smtpPort = data['smtpPort']
smtpUserName = data['smtpUserName']
smtpPassword = data['smtpPassword']
try:
verifyLogin = smtplib.SMTP(str(smtpHost), int(smtpPort))
verifyLogin.login(str(smtpUserName), str(smtpPassword))
writeToFile = open(smtpPath, 'w')
writeToFile.write(json.dumps(data))
writeToFile.close()
command = 'chmod 600 %s' % (smtpPath)
ProcessUtilities.executioner(command)
except smtplib.SMTPHeloError:
data_ret = {"status": 0, 'error_message': 'The server did not reply properly to the HELO greeting.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except smtplib.SMTPAuthenticationError:
data_ret = {"status": 0, 'error_message': 'Username and password combination not accepted.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except smtplib.SMTPException:
data_ret = {"status": 0, 'error_message': 'No suitable authentication method was found.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
status = {"status": 1}
final_json = json.dumps(status)
return HttpResponse(final_json)
except BaseException as msg:
status = {"status": 0, 'error_message': str(msg)}
final_json = json.dumps(status)
return HttpResponse(final_json)

189
static/serverLogs/serverLogs.js Executable file → Normal file
View File

@@ -3,10 +3,8 @@
*/
/* Java script code to read access log file */
app.controller('readAccessLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -32,7 +30,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -42,9 +39,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -55,6 +50,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -64,8 +60,6 @@ app.controller('readAccessLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -92,7 +86,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -102,9 +95,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -115,6 +106,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -151,7 +143,6 @@ app.controller('readAccessLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -161,9 +152,7 @@ app.controller('readAccessLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -174,6 +163,7 @@ app.controller('readAccessLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -186,16 +176,10 @@ app.controller('readAccessLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read error log file */
app.controller('readErrorLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -221,7 +205,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -231,9 +214,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -244,6 +225,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -253,8 +235,6 @@ app.controller('readErrorLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -281,7 +261,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -291,9 +270,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -304,6 +281,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -340,7 +318,6 @@ app.controller('readErrorLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -350,9 +327,7 @@ app.controller('readErrorLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -363,6 +338,7 @@ app.controller('readErrorLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -375,14 +351,10 @@ app.controller('readErrorLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read ftp log file */
app.controller('readFTPLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -408,7 +380,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -418,9 +389,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -431,6 +400,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -440,8 +410,6 @@ app.controller('readFTPLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -468,7 +436,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -478,9 +445,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -491,6 +456,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -527,7 +493,6 @@ app.controller('readFTPLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -537,9 +502,7 @@ app.controller('readFTPLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -550,6 +513,7 @@ app.controller('readFTPLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -562,14 +526,10 @@ app.controller('readFTPLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read email log file */
app.controller('readEmailLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -595,7 +555,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -605,9 +564,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -618,6 +575,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -627,8 +585,6 @@ app.controller('readEmailLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -655,7 +611,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -665,9 +620,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -678,6 +631,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -714,7 +668,6 @@ app.controller('readEmailLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -724,9 +677,7 @@ app.controller('readEmailLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -737,6 +688,7 @@ app.controller('readEmailLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -749,14 +701,10 @@ app.controller('readEmailLogs', function($scope,$http) {
});
/* Java script code to read log file ends here */
/* Java script code to read modsec audit log file */
app.controller('modSecAuditLogs', function ($scope, $http) {
$scope.logFileLoading = false;
@@ -782,7 +730,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus === 1) {
$scope.logFileLoading = true;
@@ -792,9 +739,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -805,6 +750,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -814,8 +760,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
$scope.fetchLogs = function () {
@@ -842,7 +786,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.logstatus == 1) {
$scope.logFileLoading = true;
@@ -852,9 +795,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = response.data.logsdata;
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -865,6 +806,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -900,7 +842,6 @@ app.controller('modSecAuditLogs', function($scope,$http) {
function ListInitialDatas(response) {
if (response.data.cleanStatus === 1) {
$scope.logFileLoading = true;
@@ -910,9 +851,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
$scope.logsData = "";
}
else{
} else {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
@@ -923,6 +862,7 @@ app.controller('modSecAuditLogs', function($scope,$http) {
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
@@ -935,6 +875,71 @@ app.controller('modSecAuditLogs', function($scope,$http) {
});
/* Java script code to read modsec audit log ends here */
app.controller('serverMail', function ($scope, $http) {
$scope.cyberPanelLoading = true;
$scope.installationDetailsForm = true;
$scope.mailerSettings = function(){
if($scope.mailer === 'SMTP'){
$scope.installationDetailsForm = false;
}else {
$scope.installationDetailsForm = true;
}
};
$scope.saveSMTPSettings = function () {
$scope.cyberPanelLoading = false;
var url = "/serverlogs/saveSMTPSettings";
var data = {
mailer: $scope.mailer,
smtpHost: $scope.smtpHost,
smtpPort: $scope.smtpPort,
smtpUserName: $scope.smtpUserName,
smtpPassword: $scope.smtpPassword
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully saved.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.cyberPanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});

View File

@@ -6714,5 +6714,62 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
}
};
$scope.currentPage = 1;
$scope.recordsToShow = 10;
$scope.fetchGitLogs = function () {
$scope.cyberpanelLoading = false;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
page: $scope.currentPage,
recordsToShow: $scope.recordsToShow
};
dataurl = "/websites/fetchGitLogs";
$http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully fetched.',
type: 'success'
});
$scope.logs = JSON.parse(response.data.logs);
$scope.pagination = response.data.pagination;
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});
/* Java script code to git tracking ends here */

View File

@@ -4,6 +4,7 @@
from django.db import models
from packages.models import Package
from loginSystem.models import Administrator
from datetime import datetime
# Create your models here.
@@ -47,3 +48,10 @@ class aliasDomains(models.Model):
master = models.ForeignKey(Websites, on_delete=models.CASCADE)
aliasDomain = models.CharField(max_length=75)
class GitLogs(models.Model):
owner = models.ForeignKey(Websites, on_delete=models.CASCADE)
date = models.DateTimeField(default=datetime.now, blank=True)
type = models.CharField(max_length=5)
message = models.TextField(max_length=65532)

View File

@@ -6714,5 +6714,62 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
}
};
$scope.currentPage = 1;
$scope.recordsToShow = 10;
$scope.fetchGitLogs = function () {
$scope.cyberpanelLoading = false;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
page: $scope.currentPage,
recordsToShow: $scope.recordsToShow
};
dataurl = "/websites/fetchGitLogs";
$http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully fetched.',
type: 'success'
});
$scope.logs = JSON.parse(response.data.logs);
$scope.pagination = response.data.pagination;
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});
/* Java script code to git tracking ends here */

View File

@@ -82,19 +82,22 @@
<div class="col-md-4 content-box-header">
<i class="p fa fa-lock btn-icon text-muted" data-toggle="tooltip" data-placement="right"
title="SSL">&emsp;</i>
<span><a ng-click="issueSSL(web.domain)" href="" style="text-transform: none">Issue SSL</a></span>
<span><a ng-click="issueSSL(web.domain)" href=""
style="text-transform: none">Issue SSL</a></span>
</div>
</div>
<div class="col-md-12">
<div class="col-md-4 content-box-header">
<i class="p fa fa-hdd-o btn-icon text-muted" data-toggle="tooltip" data-placement="right"
<i class="p fa fa-hdd-o btn-icon text-muted" data-toggle="tooltip"
data-placement="right"
title="Disk Usage">&emsp;</i>
<span ng-bind="web.diskUsed" style="text-transform: none"></span>
</div>
<div class="col-md-4 content-box-header">
<i class="p fa fa-cubes btn-icon text-muted" data-toggle="tooltip" data-placement="right"
<i class="p fa fa-cubes btn-icon text-muted" data-toggle="tooltip"
data-placement="right"
title="Packages">&emsp;</i>
<span ng-bind="web.package" style="text-transform: none"></span>
</div>
@@ -151,5 +154,6 @@
</div> <!-- end row -->
</div>
</div>
</div>
{% endblock %}

View File

@@ -185,19 +185,23 @@
<option>Weekly</option>
</select>
</div>
<div class="current-pack ng-binding">Currently: {$ autoCommitCurrent $}</div>
<div class="current-pack ng-binding">Currently: {$ autoCommitCurrent
$}
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Auto Push" %}</label>
<div class="col-sm-6">
<select ng-disabled="remote==0" ng-model="$parent.autoPush" class="form-control">
<select ng-disabled="remote==0" ng-model="$parent.autoPush"
class="form-control">
<option>Never</option>
<option>Daily</option>
<option>Weekly</option>
</select>
</div>
<div class="current-pack ng-binding">Currently: {$ autoPushCurrent $}</div>
<div class="current-pack ng-binding">Currently: {$ autoPushCurrent $}
</div>
</div>
<div class="form-group">
@@ -211,7 +215,8 @@
</label>
</div>
</div>
<div class="current-pack ng-binding">Currently: {$ emailLogsCurrent $}</div>
<div class="current-pack ng-binding">Currently: {$ emailLogsCurrent $}
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
@@ -462,6 +467,7 @@
<input name="radio-toggle-1" type="radio">
Push
</a>
<a ng-click="fetchGitignore()" data-toggle="modal" data-target="#gitignore" href="#"
class="btn btn-info">
<input name="radio-toggle-1" type="radio">
@@ -514,6 +520,81 @@
</div>
</div>
<a ng-click="fetchGitLogs()" data-toggle="modal" data-target="#gitLogs" href="#"
class="btn btn-info">
<input name="radio-toggle-1" type="radio">
Git Logs
</a>
<div id="gitLogs" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;
</button>
<h4 class="modal-title">{% trans "Git Logs" %} <img
ng-hide="cyberpanelLoading" src="{% static 'images/loading.gif' %}"></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-10">
</div>
<div class="col-sm-2">
<div class="form-group">
<select ng-model="recordsToShow"
ng-change="fetchGitLogs()"
class="form-control" id="example-select">
<option>10</option>
<option>50</option>
<option>100</option>
</select>
</div>
</div>
</div>
<table style="margin-top: 2%" class="table">
<thead>
<tr>
<th>Type</th>
<th>Date</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="log in logs track by $index">
<td ng-bind="log.type"></td>
<td ng-bind="log.date"></td>
<td ng-bind="log.message"></td>
</tr>
</tbody>
</table>
<div style="margin-top: 2%" class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-9">
</div>
<div class="col-md-3">
<div class="form-group">
<select ng-model="currentPage" class="form-control"
ng-change="fetchGitLogs()">
<option ng-repeat="page in pagination">{$ $index + 1
$}
</option>
</select>
</div>
</div>
</div> <!-- end row -->
</div>
</div>
</div>
</div>
</div>
</div>
<a data-toggle="modal" data-target="#removeGit" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio">
Remove

View File

@@ -136,6 +136,7 @@ urlpatterns = [
url(r'^fetchFiles$', views.fetchFiles, name='fetchFiles'),
url(r'^fetchChangesInFile$', views.fetchChangesInFile, name='fetchChangesInFile'),
url(r'^saveGitConfigurations$', views.saveGitConfigurations, name='saveGitConfigurations'),
url(r'^fetchGitLogs$', views.fetchGitLogs, name='fetchGitLogs'),
## Catch all for domains

View File

@@ -853,3 +853,11 @@ def saveGitConfigurations(request):
return wm.saveGitConfigurations(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def fetchGitLogs(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.fetchGitLogs(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)

View File

@@ -3284,7 +3284,7 @@ StrictHostKeyChecking no
command = 'git -C %s add -A' % (self.folder)
ProcessUtilities.outputExecutioner(command )
command = 'git -C %s commit -m "%s"' % (self.folder, self.commitMessage)
command = 'git -C %s commit -m "%s"' % (self.folder, self.commitMessage.replace('"', ''))
commandStatus = ProcessUtilities.outputExecutioner(command)
if commandStatus.find('nothing to commit') == -1:
@@ -3297,7 +3297,7 @@ StrictHostKeyChecking no
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
data_ret = {'status': 0, 'error_message': str(msg), 'commandStatus': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
@@ -3403,7 +3403,7 @@ StrictHostKeyChecking no
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
data_ret = {'status': 0, 'error_message': str(msg), 'commandStatus': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
@@ -3802,7 +3802,7 @@ StrictHostKeyChecking no
try:
dic['autoPush'] = data['autoPush']
except:
dic['autoCommit'] = 'Never'
dic['autoPush'] = 'Never'
try:
dic['emailLogs'] = data['emailLogs']
@@ -3845,3 +3845,64 @@ StrictHostKeyChecking no
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def getLogsInJson(self, logs):
json_data = "["
checker = 0
counter = 1
for items in logs:
dic = {'type': items.type, 'date': items.date.strftime('%m.%d.%Y_%H-%M-%S'), 'message': items.message}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
counter = counter + 1
json_data = json_data + ']'
return json_data
def fetchGitLogs(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
self.domain = data['domain']
self.folder = data['folder']
recordsToShow = int(data['recordsToShow'])
page = int(data['page'])
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)
if self.folderCheck():
pass
else:
return ACLManager.loadErrorJson()
website = Websites.objects.get(domain=self.domain)
logs = website.gitlogs_set.all().order_by('-id')
from s3Backups.s3Backups import S3Backups
pagination = S3Backups.getPagination(len(logs), recordsToShow)
endPageNumber, finalPageNumber = S3Backups.recordsPointer(page, recordsToShow)
jsonData = self.getLogsInJson(logs[finalPageNumber:endPageNumber])
data_ret = {'status': 1, 'logs': jsonData, 'pagination': pagination}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except IndexError:
data_ret = {'status': 0, 'error_message': 'Not a text file.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)