Skip to content
Permalink
Browse files
bug fix: add path to git commands
  • Loading branch information
usmannasir committed Mar 9, 2020
1 parent bf255dc commit 91af4622715f80e200ae107e1572004bf20dcaef
Showing 5 changed files with 134 additions and 4 deletions.
@@ -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";
@@ -85,7 +85,20 @@ <h3 class="title-hero">
<select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control">
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
</select></td>
<td></td>
<td>
<button ng-hide="remote==1" style="margin-left: 2%" type="button"
class="btn btn-primary"
ng-click="initRepo()">
Setup Remote
</button>

<button ng-hide="remote==0" style="margin-left: 2%" type="button"
class="btn btn-primary"
ng-click="initRepo()">
View Remote
</button>

</td>
<td></td>
<td></td>
</tr>
@@ -121,6 +121,7 @@

url(r'^(?P<domain>(.*))/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<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
@@ -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)
@@ -2947,8 +2947,8 @@ def fetchFolderDetails(self, userID=None, data=None):

## 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 @@ def fetchFolderDetails(self, userID=None, data=None):
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)

0 comments on commit 91af462

Please sign in to comment.