mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
git manager: set/view repo remote
This commit is contained in:
@@ -370,8 +370,4 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -5826,6 +5826,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
|
|||||||
$scope.branches = response.data.finalBranches;
|
$scope.branches = response.data.finalBranches;
|
||||||
$scope.deploymentKey = response.data.deploymentKey;
|
$scope.deploymentKey = response.data.deploymentKey;
|
||||||
$scope.remote = response.data.remote;
|
$scope.remote = response.data.remote;
|
||||||
|
$scope.remoteResult = response.data.remoteResult;
|
||||||
} else {
|
} else {
|
||||||
$scope.gitTracking = false;
|
$scope.gitTracking = false;
|
||||||
$scope.gitEnable = true;
|
$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() {
|
function getCreationStatus() {
|
||||||
|
|
||||||
url = "/websites/installWordpressStatus";
|
url = "/websites/installWordpressStatus";
|
||||||
|
|||||||
@@ -40,7 +40,95 @@
|
|||||||
Init Repo
|
Init Repo
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<form action="/" class="form-horizontal bordered-row">
|
<table ng-hide="gitEnable" style="margin-top: 2%" class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Branch</th>
|
||||||
|
<th>Remote</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Manage</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control">
|
||||||
|
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
|
||||||
|
</select></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
<button data-toggle="modal" data-target="#settings" style="margin-left: 2%"
|
||||||
|
type="button" class="btn btn-primary">
|
||||||
|
{% trans "View/Setup Remote" %}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div id="settings" class="modal fade" role="dialog">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
|
||||||
|
<!-- Modal content-->
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal">×
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title">{% trans "Setup Remote" %}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<form name="containerSettingsForm" action="/" class="form-horizontal">
|
||||||
|
<div ng-hide="installationDetailsForm" class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">{% trans "Git Host" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input placeholder="Ex. github.com or gitlab.com"
|
||||||
|
name="gitHost" type="text" class="form-control"
|
||||||
|
ng-model="$parent.gitHost" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div ng-hide="installationDetailsForm" class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">{% trans "Username" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input name="gitUsername" type="text" class="form-control"
|
||||||
|
ng-model="$parent.gitUsername" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div ng-hide="installationDetailsForm" class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">{% trans "Repo Name" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input name="gitReponame" type="text" class="form-control"
|
||||||
|
ng-model="$parent.gitReponame" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<div class="col-sm-12">
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Current Remote" %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<textarea rows="2"
|
||||||
|
class="form-control">{$ remoteResult $}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
||||||
@@ -70,33 +158,22 @@
|
|||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<table ng-hide="gitEnable" style="margin-top: 2%" class="table">
|
</div>
|
||||||
<thead>
|
<div class="modal-footer">
|
||||||
<tr>
|
<button type="button" ng-disabled="savingSettings"
|
||||||
<th>Branch</th>
|
|
||||||
<th>Remote</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th>Manage</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control">
|
|
||||||
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
|
|
||||||
</select></td>
|
|
||||||
<td>
|
|
||||||
<button ng-hide="remote==1" style="margin-left: 2%" type="button"
|
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
ng-click="initRepo()">
|
ng-click="setupRemote()">Save <img id="cyberpanelLoading"
|
||||||
Setup Remote
|
src="/static/images/loading.gif"
|
||||||
|
style="display: none;">
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" ng-disabled="savingSettings"
|
||||||
<button ng-hide="remote==0" style="margin-left: 2%" type="button"
|
class="btn btn-default" data-dismiss="modal">
|
||||||
class="btn btn-primary"
|
Close
|
||||||
ng-click="initRepo()">
|
|
||||||
View Remote
|
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ urlpatterns = [
|
|||||||
url(r'^(?P<domain>(.*))/manageGIT$', views.manageGIT, name='manageGIT'),
|
url(r'^(?P<domain>(.*))/manageGIT$', views.manageGIT, name='manageGIT'),
|
||||||
url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'),
|
url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'),
|
||||||
url(r'^initRepo$', views.initRepo, name='initRepo'),
|
url(r'^initRepo$', views.initRepo, name='initRepo'),
|
||||||
|
url(r'^setupRemote$', views.setupRemote, name='setupRemote'),
|
||||||
## Catch all for domains
|
## Catch all for domains
|
||||||
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
|
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
|
||||||
url(r'^(?P<domain>(.*))$', views.domain, name='domain'),
|
url(r'^(?P<domain>(.*))$', views.domain, name='domain'),
|
||||||
|
|||||||
@@ -741,3 +741,11 @@ def initRepo(request):
|
|||||||
return wm.initRepo(userID, json.loads(request.body))
|
return wm.initRepo(userID, json.loads(request.body))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
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)
|
||||||
@@ -2990,6 +2990,7 @@ StrictHostKeyChecking no
|
|||||||
remote = 1
|
remote = 1
|
||||||
if remoteResult.find('origin') == -1:
|
if remoteResult.find('origin') == -1:
|
||||||
remote = 0
|
remote = 0
|
||||||
|
remoteResult = 'Remote currently not set.'
|
||||||
|
|
||||||
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult}
|
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -3035,3 +3036,59 @@ StrictHostKeyChecking no
|
|||||||
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user