diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index c2d8ad3a1..6069105ad 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -5825,6 +5825,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { $scope.gitEnable = false; $scope.branches = response.data.finalBranches; $scope.deploymentKey = response.data.deploymentKey; + $scope.remote = response.data.remote; } else { $scope.gitTracking = false; $scope.gitEnable = true; @@ -5853,6 +5854,61 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { }; + $scope.initRepo = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/initRepo"; + + + var data = { + domain: $("#domain").text(), + folder: $scope.folder + + }; + + 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: 'Repo initiated.', + type: 'success' + }); + $scope.fetchFolderDetails(); + } 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' + }); + + + } + + }; + function getCreationStatus() { url = "/websites/installWordpressStatus"; diff --git a/websiteFunctions/templates/websiteFunctions/manageGIT.html b/websiteFunctions/templates/websiteFunctions/manageGIT.html index e83db9cc8..3c6f25c5f 100755 --- a/websiteFunctions/templates/websiteFunctions/manageGIT.html +++ b/websiteFunctions/templates/websiteFunctions/manageGIT.html @@ -85,7 +85,20 @@ - + + + + + + diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 2765eaae6..1eea24555 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -121,6 +121,7 @@ urlpatterns = [ url(r'^(?P(.*))/manageGIT$', views.manageGIT, name='manageGIT'), url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'), + url(r'^initRepo$', views.initRepo, name='initRepo'), ## Catch all for domains url(r'^(?P(.*))/(?P(.*))$', views.launchChild, name='launchChild'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index dbaa51c35..3e0fce68f 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -731,5 +731,13 @@ def fetchFolderDetails(request): userID = request.session['userID'] wm = WebsiteManager() return wm.fetchFolderDetails(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + +def initRepo(request): + try: + userID = request.session['userID'] + wm = WebsiteManager() + return wm.initRepo(userID, 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 779a7717f..d4ad3612f 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2947,8 +2947,8 @@ StrictHostKeyChecking no ## Find git branches - command = 'git --git-dir=%s/.git branch' % (self.folder) - branches = ProcessUtilities.outputExecutioner(command).split('\n') + command = 'git -C %s branch' % (self.folder) + branches = ProcessUtilities.outputExecutioner(command).split('\n')[:-1] ## Fetch key @@ -2975,7 +2975,59 @@ StrictHostKeyChecking no command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp) deploymentKey = ProcessUtilities.outputExecutioner(command, website.externalApp) - data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey} + if deploymentKey.find('No such file or directory') > -1: + command = "ssh-keygen -f /home/%s/.ssh/%s -t rsa -N ''" % (self.domain, website.externalApp) + ProcessUtilities.executioner(command, website.externalApp) + + command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp) + deploymentKey = ProcessUtilities.outputExecutioner(command, website.externalApp) + + ## Find Remote if any + + command = 'git -C %s remote -v' % (self.folder) + remoteResult = ProcessUtilities.outputExecutioner(command) + + remote = 1 + if remoteResult.find('origin') == -1: + remote = 0 + + data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def initRepo(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + self.domain = data['domain'] + self.folder = data['folder'] + + if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('status', 0) + + if self.folderCheck(): + pass + else: + return ACLManager.loadErrorJson() + + command = 'git -C %s init' % (self.folder) + result = ProcessUtilities.outputExecutioner(command) + + if result.find('Initialized empty Git repository in') > -1: + data_ret = {'status': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 0, 'error_message': result} json_data = json.dumps(data_ret) return HttpResponse(json_data)