add git configurations

This commit is contained in:
Usman Nasir
2020-03-16 19:14:39 +05:00
parent 49087440a9
commit a994c82efc
8 changed files with 313 additions and 28 deletions

View File

@@ -16,6 +16,16 @@ from dockerManager.models import Containers
from re import M, I, compile from re import M, I, compile
class ACLManager: class ACLManager:
@staticmethod
def fetchIP():
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
return ipData.split('\n', 1)[0]
except BaseException:
return "192.168.100.1"
@staticmethod @staticmethod
def validateInput(value, regex = None): def validateInput(value, regex = None):
if regex == None: if regex == None:

View File

@@ -1,9 +0,0 @@
import re
verifer = re.compile(r'[a-zA-Z0-9_-]+')
if verifer.match('Helloworld'):
print ('hello world')
else:
print('not hello world')

View File

@@ -5832,6 +5832,10 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
$scope.remoteResult = response.data.remoteResult; $scope.remoteResult = response.data.remoteResult;
$scope.totalCommits = response.data.totalCommits; $scope.totalCommits = response.data.totalCommits;
$scope.home = response.data.home; $scope.home = response.data.home;
$scope.webHookURL = response.data.webHookURL;
$scope.autoCommitCurrent = response.data.autoCommitCurrent;
$scope.autoPushCurrent = response.data.autoPushCurrent;
$scope.emailLogsCurrent = response.data.emailLogsCurrent;
} else { } else {
$scope.gitTracking = false; $scope.gitTracking = false;
$scope.gitEnable = true; $scope.gitEnable = true;
@@ -6658,5 +6662,57 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
} }
}; };
$scope.saveGitConfigurations = function () {
$scope.cyberpanelLoading = false;
url = "/websites/saveGitConfigurations";
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
autoCommit: $scope.autoCommit,
autoPush: $scope.autoPush,
emailLogs: $scope.emailLogs,
};
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: 'Successfully saved.',
type: 'success'
});
} 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'
});
}
};
}); });
/* Java script code to git tracking ends here */ /* Java script code to git tracking ends here */

View File

@@ -5832,6 +5832,10 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
$scope.remoteResult = response.data.remoteResult; $scope.remoteResult = response.data.remoteResult;
$scope.totalCommits = response.data.totalCommits; $scope.totalCommits = response.data.totalCommits;
$scope.home = response.data.home; $scope.home = response.data.home;
$scope.webHookURL = response.data.webHookURL;
$scope.autoCommitCurrent = response.data.autoCommitCurrent;
$scope.autoPushCurrent = response.data.autoPushCurrent;
$scope.emailLogsCurrent = response.data.emailLogsCurrent;
} else { } else {
$scope.gitTracking = false; $scope.gitTracking = false;
$scope.gitEnable = true; $scope.gitEnable = true;
@@ -6658,5 +6662,57 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
} }
}; };
$scope.saveGitConfigurations = function () {
$scope.cyberpanelLoading = false;
url = "/websites/saveGitConfigurations";
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
autoCommit: $scope.autoCommit,
autoPush: $scope.autoPush,
emailLogs: $scope.emailLogs,
};
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: 'Successfully saved.',
type: 'success'
});
} 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'
});
}
};
}); });
/* Java script code to git tracking ends here */ /* Java script code to git tracking ends here */

View File

@@ -158,6 +158,89 @@
Attach Existing Repo Attach Existing Repo
</a> </a>
<a data-toggle="modal" data-target="#configureModal" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio">
Configure
</a>
<div id="configureModal" 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">&times;
</button>
<h4 class="modal-title">{% trans "Repo Settings" %}</h4>
</div>
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Auto Commit" %}</label>
<div class="col-sm-6">
<select ng-model="$parent.autoCommit" class="form-control">
<option>Never</option>
<option>Daily</option>
<option>Weekly</option>
</select>
</div>
<div class="current-pack ng-binding">Currently: {$ autoCommitCurrent $}</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Auto Push" %}</label>
<div class="col-sm-6">
<select ng-disabled="remote==0" ng-model="$parent.autoPush" class="form-control">
<option>Never</option>
<option>Daily</option>
<option>Weekly</option>
</select>
</div>
<div class="current-pack ng-binding">Currently: {$ autoPushCurrent $}</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "" %}</label>
<div class="col-sm-6">
<div class="checkbox">
<label>
<input ng-model="$parent.emailLogs" type="checkbox"
value="">
Email Logs
</label>
</div>
</div>
<div class="current-pack ng-binding">Currently: {$ emailLogsCurrent $}</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Webhook URL" %}</label>
<div class="col-sm-6">
<input name="webHookURL" type="text" class="form-control"
ng-model="webHookURL" readonly>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" ng-disabled="savingSettings"
class="btn btn-primary"
ng-click="saveGitConfigurations()">Save <img
ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</button>
<button type="button" ng-disabled="savingSettings"
class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<div id="attachExistingRepo" class="modal fade" role="dialog"> <div id="attachExistingRepo" class="modal fade" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
@@ -319,7 +402,7 @@
<a data-toggle="modal" data-target="#commitChanges" href="#" class="btn btn-info"> <a data-toggle="modal" data-target="#commitChanges" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio"> <input name="radio-toggle-1" type="radio">
Commit Changes Commit
</a> </a>
<div id="commitChanges" class="modal fade" role="dialog"> <div id="commitChanges" class="modal fade" role="dialog">
@@ -373,11 +456,11 @@
<a ng-click="gitPull()" ng-disabled="remote==0" href="#" class="btn btn-info"> <a ng-click="gitPull()" ng-disabled="remote==0" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio"> <input name="radio-toggle-1" type="radio">
Pull From Remote Pull
</a> </a>
<a ng-click="gitPush()" ng-disabled="remote==0" href="#" class="btn btn-info"> <a ng-click="gitPush()" ng-disabled="remote==0" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio"> <input name="radio-toggle-1" type="radio">
Push To Remote Push
</a> </a>
<a ng-click="fetchGitignore()" data-toggle="modal" data-target="#gitignore" href="#" <a ng-click="fetchGitignore()" data-toggle="modal" data-target="#gitignore" href="#"
class="btn btn-info"> class="btn btn-info">
@@ -433,7 +516,7 @@
<a data-toggle="modal" data-target="#removeGit" href="#" class="btn btn-info"> <a data-toggle="modal" data-target="#removeGit" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio"> <input name="radio-toggle-1" type="radio">
Remove Git Remove
</a> </a>
<div id="removeGit" class="modal fade" role="dialog"> <div id="removeGit" class="modal fade" role="dialog">
@@ -667,7 +750,8 @@
<label class="col-sm-2 control-label">{% trans "Select File" %}</label> <label class="col-sm-2 control-label">{% trans "Select File" %}</label>
<div class="col-sm-10" style="margin-bottom: 2%;"> <div class="col-sm-10" style="margin-bottom: 2%;">
<select ng-change="fetchChangesInFile()" ng-model="$parent.changeFile" class="form-control"> <select ng-change="fetchChangesInFile()"
ng-model="$parent.changeFile" class="form-control">
<option ng-repeat="file in files"> <option ng-repeat="file in files">
{$ file $} {$ file $}
</option> </option>
@@ -677,7 +761,8 @@
<div ng-hide='fileStatus' class="row"> <div ng-hide='fileStatus' class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="content-box"> <div class="content-box">
<table style="margin-top: 3%; margin-right: 0px; margin-left: 0px" class="table"> <table style="margin-top: 3%; margin-right: 0px; margin-left: 0px"
class="table">
<thead style="background-color: #f9fafe;"> <thead style="background-color: #f9fafe;">
<tr> <tr>
<th>#</th> <th>#</th>

View File

@@ -135,6 +135,7 @@ urlpatterns = [
url(r'^fetchCommits$', views.fetchCommits, name='fetchCommits'), url(r'^fetchCommits$', views.fetchCommits, name='fetchCommits'),
url(r'^fetchFiles$', views.fetchFiles, name='fetchFiles'), url(r'^fetchFiles$', views.fetchFiles, name='fetchFiles'),
url(r'^fetchChangesInFile$', views.fetchChangesInFile, name='fetchChangesInFile'), url(r'^fetchChangesInFile$', views.fetchChangesInFile, name='fetchChangesInFile'),
url(r'^saveGitConfigurations$', views.saveGitConfigurations, name='saveGitConfigurations'),
## Catch all for domains ## Catch all for domains

View File

@@ -845,3 +845,11 @@ def fetchChangesInFile(request):
return wm.fetchChangesInFile(userID, json.loads(request.body)) return wm.fetchChangesInFile(userID, json.loads(request.body))
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def saveGitConfigurations(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.saveGitConfigurations(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)

View File

@@ -3000,8 +3000,31 @@ StrictHostKeyChecking no
if self.folder == '/home/%s' % (self.domain): if self.folder == '/home/%s' % (self.domain):
home = 1 home = 1
## Fetch Configurations
gitConfFolder = '/home/cyberpanel/git'
gitConFile = '%s/%s' % (gitConfFolder, self.domain)
if os.path.exists(gitConFile):
gitConf = json.loads(open(gitConFile, 'r').read())
autoCommitCurrent = gitConf['autoCommit']
autoPushCurrent = gitConf['autoPush']
emailLogsCurrent = gitConf['emailLogs']
else:
autoCommitCurrent = 'Never'
autoPushCurrent = 'Never'
emailLogsCurrent = 'False'
##
webHookURL = 'https://%s/websites/%s/webhook' % (ACLManager.fetchIP(), self.domain)
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey,
'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits, 'home': home} 'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits, 'home': home,
'webHookURL': webHookURL, 'autoCommitCurrent': autoCommitCurrent,
'autoPushCurrent':autoPushCurrent, 'emailLogsCurrent': emailLogsCurrent}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3754,3 +3777,58 @@ StrictHostKeyChecking no
data_ret = {'status': 0, 'error_message': str(msg)} data_ret = {'status': 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 saveGitConfigurations(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
self.domain = data['domain']
self.folder = data['folder']
dic = {}
dic['autoCommit'] = data['autoCommit']
try:
dic['autoPush'] = data['autoPush']
except:
dic['autoCommit'] = 'Never'
try:
dic['emailLogs'] = data['emailLogs']
except:
dic['emailLogs'] = False
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)
if self.folderCheck():
pass
else:
return ACLManager.loadErrorJson()
##
gitConfFolder = '/home/cyberpanel/git'
gitConFile = '%s/%s' % (gitConfFolder, self.domain)
if not os.path.exists(gitConfFolder):
os.mkdir(gitConfFolder)
writeToFile = open(gitConFile, 'w')
writeToFile.write(json.dumps(dic))
writeToFile.close()
data_ret = {'status': 1}
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)