diff --git a/dockerManager/templates/dockerManager/viewContainer.html b/dockerManager/templates/dockerManager/viewContainer.html index 69f1e8f8c..d92739e90 100755 --- a/dockerManager/templates/dockerManager/viewContainer.html +++ b/dockerManager/templates/dockerManager/viewContainer.html @@ -370,8 +370,4 @@ - - - - {% endblock %} diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 6069105ad..509085a75 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -5826,6 +5826,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { $scope.branches = response.data.finalBranches; $scope.deploymentKey = response.data.deploymentKey; $scope.remote = response.data.remote; + $scope.remoteResult = response.data.remoteResult; } else { $scope.gitTracking = false; $scope.gitEnable = true; @@ -5909,6 +5910,63 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { }; + $scope.setupRemote = function () { + + $scope.cyberpanelLoading = false; + + url = "/websites/setupRemote"; + + + var data = { + domain: $("#domain").text(), + folder: $scope.folder, + gitHost: $scope.gitHost, + gitUsername: $scope.gitUsername, + gitReponame: $scope.gitReponame, + }; + + 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: 'Remote successfully set.', + 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"; @@ -5981,4 +6039,4 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { } }); -/* Java script code to git tracking ends here */ \ No newline at end of file +/* Java script code to git tracking ends here */ diff --git a/websiteFunctions/templates/websiteFunctions/manageGIT.html b/websiteFunctions/templates/websiteFunctions/manageGIT.html index 3c6f25c5f..defdfa350 100755 --- a/websiteFunctions/templates/websiteFunctions/manageGIT.html +++ b/websiteFunctions/templates/websiteFunctions/manageGIT.html @@ -40,36 +40,6 @@ Init Repo -
- -
- -
- - - - - - - - - - - - -
{% trans "Deployment Key" %}
-
-
- -
-
-
-
-
- -
- @@ -86,17 +56,124 @@ diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 1eea24555..b31ffb8b7 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -122,7 +122,7 @@ urlpatterns = [ url(r'^(?P(.*))/manageGIT$', views.manageGIT, name='manageGIT'), url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'), url(r'^initRepo$', views.initRepo, name='initRepo'), - + url(r'^setupRemote$', views.setupRemote, name='setupRemote'), ## Catch all for domains url(r'^(?P(.*))/(?P(.*))$', views.launchChild, name='launchChild'), url(r'^(?P(.*))$', views.domain, name='domain'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 3e0fce68f..dc59d27dc 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -739,5 +739,13 @@ def initRepo(request): userID = request.session['userID'] wm = WebsiteManager() return wm.initRepo(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + +def setupRemote(request): + try: + userID = request.session['userID'] + wm = WebsiteManager() + return wm.setupRemote(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 d4ad3612f..1806cd6c0 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2990,6 +2990,7 @@ StrictHostKeyChecking no remote = 1 if remoteResult.find('origin') == -1: remote = 0 + remoteResult = 'Remote currently not set.' data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult} json_data = json.dumps(data_ret) @@ -3035,3 +3036,59 @@ StrictHostKeyChecking no data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data) + + def setupRemote(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + self.domain = data['domain'] + self.folder = data['folder'] + self.gitHost = data['gitHost'] + self.gitUsername = data['gitUsername'] + self.gitReponame = data['gitReponame'] + + if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('status', 0) + + if self.folderCheck(): + pass + else: + return ACLManager.loadErrorJson() + + ## Check if remote exists + + command = 'git -C %s remote -v' % (self.folder) + remoteResult = ProcessUtilities.outputExecutioner(command) + + ## Set new remote + + if remoteResult.find('origin') == -1: + command = 'git -C %s remote add origin git@%s:%s/%s.git' % (self.folder, self.gitHost, self.gitUsername, self.gitReponame) + else: + command = 'git -C %s remote set-url origin git@%s:%s/%s.git' % ( + self.folder, self.gitHost, self.gitUsername, self.gitReponame) + + possibleError = ProcessUtilities.outputExecutioner(command) + + ## Check if set correctly. + + command = 'git -C %s remote -v' % (self.folder) + remoteResult = ProcessUtilities.outputExecutioner(command) + + if remoteResult.find(self.gitUsername) > -1: + data_ret = {'status': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 0, 'error_message': possibleError} + 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)
- - +