mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
feature: finish git webhooks
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -120,6 +120,7 @@ urlpatterns = [
|
||||
### Manage GIT
|
||||
|
||||
url(r'^(?P<domain>(.*))/manageGIT$', views.manageGIT, name='manageGIT'),
|
||||
url(r'^(?P<domain>(.*))/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'),
|
||||
|
||||
@@ -861,3 +861,11 @@ def fetchGitLogs(request):
|
||||
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)
|
||||
@@ -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
|
||||
@@ -3906,3 +3904,37 @@ StrictHostKeyChecking no
|
||||
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)
|
||||
return HttpResponse(json_data)
|
||||
Reference in New Issue
Block a user