diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 69899237a..63e5aae11 100755 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -67,7 +67,7 @@ class secMiddleware: final_json = json.dumps(final_dic) return HttpResponse(final_json) - if 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('filemanager') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1: + if 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('filemanager') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1: continue if 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' or key == 'fileContent': continue diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index e4ee8fd6f..98b1ebee3 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -120,6 +120,7 @@ urlpatterns = [ ### Manage GIT url(r'^(?P(.*))/manageGIT$', views.manageGIT, name='manageGIT'), + url(r'^(?P(.*))/webhook$', views.webhook, name='webhook'), url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'), url(r'^initRepo$', views.initRepo, name='initRepo'), url(r'^setupRemote$', views.setupRemote, name='setupRemote'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 12cbb0227..ee245b14e 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -859,5 +859,13 @@ def fetchGitLogs(request): userID = request.session['userID'] wm = WebsiteManager() return wm.fetchGitLogs(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + +@csrf_exempt +def webhook(request, domain): + try: + wm = WebsiteManager() + return wm.webhook(domain, json.loads(request.body)) except KeyError: return redirect(loadLoginPage) \ No newline at end of file diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 44af28b0c..0c96b9906 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -10,7 +10,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging -from websiteFunctions.models import Websites, ChildDomains +from websiteFunctions.models import Websites, ChildDomains, GitLogs from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex @@ -2714,7 +2714,6 @@ StrictHostKeyChecking no except BaseException as msg: return HttpResponse(str(msg)) - def startCloning(self, userID=None, data=None): try: @@ -3026,7 +3025,7 @@ StrictHostKeyChecking no ## - webHookURL = 'https://%s/websites/%s/webhook' % (ACLManager.fetchIP(), self.domain) + webHookURL = 'https://%s:8090/websites/%s/webhook' % (ACLManager.fetchIP(), self.domain) data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits, 'home': home, @@ -3846,7 +3845,6 @@ StrictHostKeyChecking no json_data = json.dumps(data_ret) return HttpResponse(json_data) - def getLogsInJson(self, logs): json_data = "[" checker = 0 @@ -3902,6 +3900,40 @@ StrictHostKeyChecking no 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) + + def webhook(self,domain, data=None): + try: + + self.domain = domain + self.folder = '/home/%s/public_html' % (domain) + + ### set default ssh key + + web = Websites.objects.get(domain=self.domain) + externalApp = web.externalApp + + ## Check if remote exists + + command = 'git -C %s pull' % (self.folder) + commandStatus = ProcessUtilities.outputExecutioner(command , externalApp) + + if commandStatus.find('Already up to date') == -1: + message = '[Webhook Fired] Status: %s.' % (commandStatus) + GitLogs(owner=web, type='INFO', message=message).save() + data_ret = {'status': 1, 'commandStatus': commandStatus} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + message = '[Webhook Fired] Status: %s.' % (commandStatus) + GitLogs(owner=web, type='ERROR', message=message).save() + data_ret = {'status': 0, 'error_message': 'Pull not required.', 'commandStatus': commandStatus} + 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)