mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
complete gDrive configuration interface
This commit is contained in:
@@ -64,7 +64,9 @@ class BackupManager:
|
||||
for items in gDriveAccts:
|
||||
gDriveAcctsList.append(items.name)
|
||||
|
||||
return render(request, 'backup/googleDrive.html', {'accounts': gDriveAcctsList})
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
return render(request, 'backup/googleDrive.html', {'accounts': gDriveAcctsList, 'websites': websitesName})
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
@@ -88,6 +90,7 @@ class BackupManager:
|
||||
gD = GDrive(owner=admin, name=gDriveData['name'],auth=json.dumps(gDriveData))
|
||||
gD.save()
|
||||
|
||||
|
||||
final_json = json.dumps({'status': 1, 'message': 'Successfully saved.'})
|
||||
return HttpResponse(final_json)
|
||||
except BaseException as msg:
|
||||
@@ -95,6 +98,164 @@ class BackupManager:
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def fetchgDriveSites(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
selectedAccount = data['selectedAccount']
|
||||
recordsToShow = int(data['recordsToShow'])
|
||||
page = int(str(data['page']).strip('\n'))
|
||||
|
||||
gD = GDrive.objects.get(name=selectedAccount)
|
||||
|
||||
websites = gD.gdrivesites_set.all()
|
||||
|
||||
from s3Backups.s3Backups import S3Backups
|
||||
|
||||
pagination = S3Backups.getPagination(len(websites), recordsToShow)
|
||||
endPageNumber, finalPageNumber = S3Backups.recordsPointer(page, recordsToShow)
|
||||
finalWebsites = websites[finalPageNumber:endPageNumber]
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
counter = 0
|
||||
|
||||
from plogical.backupSchedule import backupSchedule
|
||||
|
||||
for website in finalWebsites:
|
||||
|
||||
dic = {
|
||||
'name': website.domain
|
||||
}
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
counter = counter + 1
|
||||
|
||||
json_data = json_data + ']'
|
||||
|
||||
currently = gD.runTime
|
||||
|
||||
data_ret = {'status': 1, 'websites': json_data, 'pagination': pagination, 'currently': currently}
|
||||
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)
|
||||
|
||||
def addSitegDrive(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
selectedAccount = data['selectedAccount']
|
||||
selectedWebsite = data['selectedWebsite']
|
||||
|
||||
gD = GDrive.objects.get(name=selectedAccount)
|
||||
|
||||
gdSite = GDriveSites(owner=gD, domain=selectedWebsite)
|
||||
gdSite.save()
|
||||
|
||||
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)
|
||||
|
||||
def deleteAccountgDrive(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
selectedAccount = data['selectedAccount']
|
||||
|
||||
gD = GDrive.objects.get(name=selectedAccount)
|
||||
|
||||
gD.delete()
|
||||
|
||||
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)
|
||||
|
||||
def changeAccountFrequencygDrive(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
selectedAccount = data['selectedAccount']
|
||||
backupFrequency = data['backupFrequency']
|
||||
|
||||
gD = GDrive.objects.get(name=selectedAccount)
|
||||
gD.runTime = backupFrequency
|
||||
|
||||
gD.save()
|
||||
|
||||
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)
|
||||
|
||||
def deleteSitegDrive(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
selectedAccount = data['selectedAccount']
|
||||
website = data['website']
|
||||
|
||||
gD = GDrive.objects.get(name=selectedAccount)
|
||||
gDSite = GDriveSites.objects.get(owner=gD, domain=website)
|
||||
gDSite.delete()
|
||||
|
||||
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)
|
||||
|
||||
def restoreSite(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
@@ -1600,13 +1600,18 @@ app.controller('backupLogsScheduled', function ($scope, $http, $timeout) {
|
||||
app.controller('googleDrive', function ($scope, $http) {
|
||||
|
||||
$scope.cyberPanelLoading = true;
|
||||
$scope.driveHidden = true;
|
||||
|
||||
$scope.setupAccount = function(){
|
||||
window.open("https://platform.cyberpanel.net/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup');
|
||||
};
|
||||
|
||||
$scope.fetchPackageas = function () {
|
||||
$scope.cyberPanelLoading = false;
|
||||
$scope.currentPage = 1;
|
||||
$scope.recordsToShow = 10;
|
||||
|
||||
$scope.fetchWebsites = function () {
|
||||
|
||||
$scope.cyberpanelLoading = false;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
@@ -1614,10 +1619,65 @@ app.controller('googleDrive', function ($scope, $http) {
|
||||
}
|
||||
};
|
||||
|
||||
var data = {};
|
||||
var data = {
|
||||
selectedAccount: $scope.selectedAccount,
|
||||
page: $scope.currentPage,
|
||||
recordsToShow: $scope.recordsToShow
|
||||
};
|
||||
|
||||
|
||||
dataurl = "/CloudLinux/fetchPackages";
|
||||
dataurl = "/backup/fetchgDriveSites";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberpanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.driveHidden = false;
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Successfully fetched.',
|
||||
type: 'success'
|
||||
});
|
||||
$scope.websites = JSON.parse(response.data.websites);
|
||||
$scope.pagination = response.data.pagination;
|
||||
$scope.currently = response.data.currently;
|
||||
} 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'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$scope.addSite = function () {
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
var data = {
|
||||
selectedWebsite: $scope.selectedWebsite,
|
||||
selectedAccount: $scope.selectedAccount
|
||||
};
|
||||
|
||||
dataurl = "/backup/addSitegDrive";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
@@ -1625,7 +1685,12 @@ app.controller('googleDrive', function ($scope, $http) {
|
||||
function ListInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.packages = JSON.parse(response.data.data);
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Site successfully added.',
|
||||
type: 'success'
|
||||
});
|
||||
$scope.fetchWebsites();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
@@ -1647,5 +1712,146 @@ app.controller('googleDrive', function ($scope, $http) {
|
||||
|
||||
};
|
||||
|
||||
$scope.deleteAccount = function () {
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
var data = {
|
||||
selectedAccount: $scope.selectedAccount
|
||||
};
|
||||
|
||||
dataurl = "/backup/deleteAccountgDrive";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
|
||||
function ListInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Account successfully deleted.',
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.changeFrequency = function () {
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
var data = {
|
||||
selectedAccount: $scope.selectedAccount,
|
||||
backupFrequency: $scope.backupFrequency
|
||||
};
|
||||
|
||||
dataurl = "/backup/changeAccountFrequencygDrive";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
|
||||
function ListInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Changes successfully applied',
|
||||
type: 'success'
|
||||
});
|
||||
$scope.fetchWebsites();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.deleteSite = function (website) {
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
var data = {
|
||||
selectedAccount: $scope.selectedAccount,
|
||||
website: website
|
||||
};
|
||||
|
||||
dataurl = "/backup/deleteSitegDrive";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
|
||||
function ListInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Website Deleted.',
|
||||
type: 'success'
|
||||
});
|
||||
$scope.fetchWebsites();
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×
|
||||
</button>
|
||||
<h4 class="modal-title">{% trans "Repo Settings" %}</h4>
|
||||
<h4 class="modal-title">{% trans "Set up account" %}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
@@ -83,6 +83,86 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button ng-hide="driveHidden" type="button" ng-click="deleteAccount()"
|
||||
class="btn btn-danger">{% trans "Delete" %}</button>
|
||||
</div>
|
||||
|
||||
<div ng-hide="driveHidden" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Backup Frequency" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="changeFrequency()" ng-model="backupFrequency" class="form-control">
|
||||
<option>Never</option>
|
||||
<option>Daily</option>
|
||||
<option>Weekly</option>
|
||||
</select>
|
||||
</div>
|
||||
Currently: {$ currently $}
|
||||
</div>
|
||||
|
||||
<div ng-hide="driveHidden" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Add Sites for Backup" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="fetchWebsites()" ng-model="selectedWebsite" class="form-control">
|
||||
{% for items in websites %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button type="button" ng-click="addSite()"
|
||||
class="btn btn-primary">{% trans "Add Site" %}</button>
|
||||
</div>
|
||||
|
||||
<div ng-hide="driveHidden" class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-sm-9">
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<div class="form-group">
|
||||
<select ng-model="recordsToShow"
|
||||
ng-change="fetchWebsites()"
|
||||
class="form-control" id="example-select">
|
||||
<option>10</option>
|
||||
<option>50</option>
|
||||
<option>100</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table style="margin-top: 2%" class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sites</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="website in websites track by $index">
|
||||
<td ng-bind="website.name"></td>
|
||||
<td ><button type="button" ng-click="deleteSite(website.name)"
|
||||
class="btn btn-danger">{% trans "Delete" %}</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div style="margin-top: 2%" class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<select ng-model="currentPage" class="form-control"
|
||||
ng-change="fetchWebsites()">
|
||||
<option ng-repeat="page in pagination">{$ $index + 1
|
||||
$}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- end row -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -8,6 +8,11 @@ urlpatterns = [
|
||||
url(r'^restoreSite', views.restoreSite, name='restoreSite'),
|
||||
url(r'^gDrive$', views.gDrive, name='gDrive'),
|
||||
url(r'^gDriveSetup$', views.gDriveSetup, name='gDriveSetup'),
|
||||
url(r'^fetchgDriveSites$', views.fetchgDriveSites, name='fetchgDriveSites'),
|
||||
url(r'^addSitegDrive$', views.addSitegDrive, name='addSitegDrive'),
|
||||
url(r'^deleteAccountgDrive$', views.deleteAccountgDrive, name='deleteAccountgDrive'),
|
||||
url(r'^changeAccountFrequencygDrive$', views.changeAccountFrequencygDrive, name='changeAccountFrequencygDrive'),
|
||||
url(r'^deleteSitegDrive$', views.deleteSitegDrive, name='deleteSitegDrive'),
|
||||
|
||||
|
||||
url(r'^submitBackupCreation', views.submitBackupCreation, name='submitBackupCreation'),
|
||||
|
||||
@@ -46,6 +46,46 @@ def gDriveSetup(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchgDriveSites(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.fetchgDriveSites(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def addSitegDrive(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.addSitegDrive(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteAccountgDrive(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.deleteAccountgDrive(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def changeAccountFrequencygDrive(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.changeAccountFrequencygDrive(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteSitegDrive(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.deleteSitegDrive(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def restoreSite(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
@@ -87,8 +87,6 @@ class Administrator(models.Model):
|
||||
api = models.IntegerField(default=0)
|
||||
securityLevel = models.IntegerField(default=0)
|
||||
state = models.CharField(max_length=10, default='ACTIVE')
|
||||
#gDrive = models.TextField(max_length=65532, default='Inactive')
|
||||
|
||||
|
||||
initWebsitesLimit = models.IntegerField(default=0)
|
||||
acl = models.ForeignKey(ACL, default=1, on_delete=models.PROTECT)
|
||||
|
||||
@@ -64,12 +64,13 @@ class BackupJobLogs(models.Model):
|
||||
|
||||
class GDrive(models.Model):
|
||||
owner = models.ForeignKey(Administrator, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=50)
|
||||
name = models.CharField(max_length=50, unique=True)
|
||||
auth = models.TextField(max_length=65532, default='Inactive')
|
||||
runTime = models.CharField(max_length=20, default='NEVER')
|
||||
|
||||
class GDriveSites(models.Model):
|
||||
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)
|
||||
domain = models.CharField(max_length=200)
|
||||
domain = models.CharField(max_length=200, unique=True)
|
||||
|
||||
class GDriveJobLogs(models.Model):
|
||||
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)
|
||||
|
||||
Reference in New Issue
Block a user