mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +01:00
initial google drive setup
This commit is contained in:
@@ -489,7 +489,6 @@ app.controller('listCloudLinuxPackages', function ($scope, $http) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
app.controller('websiteContainerLimitCL', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ django.setup()
|
||||
import json
|
||||
from plogical.acl import ACLManager
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
from websiteFunctions.models import Websites, Backups, dest, backupSchedules, BackupJob, BackupJobLogs
|
||||
from websiteFunctions.models import Websites, Backups, dest, backupSchedules, BackupJob, BackupJobLogs, GDrive, GDriveSites, GDriveJobLogs
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
import subprocess
|
||||
import shlex
|
||||
@@ -52,14 +52,49 @@ class BackupManager:
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'addDeleteDestinations') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
return render(request, 'backup/googleDrive.html', {'websiteList': websitesName})
|
||||
gDriveAcctsList = []
|
||||
|
||||
gDriveAccts = admin.gdrive_set.all()
|
||||
|
||||
for items in gDriveAccts:
|
||||
gDriveAcctsList.append(items.name)
|
||||
|
||||
return render(request, 'backup/googleDrive.html', {'accounts': gDriveAcctsList})
|
||||
except BaseException as msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def gDriveSetup(self, userID = None, request = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'addDeleteDestinations') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
gDriveData = {}
|
||||
gDriveData['name'] = request.GET.get('n')
|
||||
gDriveData['token'] = request.GET.get('t')
|
||||
gDriveData['refresh_token'] = request.GET.get('r')
|
||||
gDriveData['token_uri'] = request.GET.get('to')
|
||||
gDriveData['client_id'] = request.GET.get('c')
|
||||
gDriveData['client_secret'] = request.GET.get('cl')
|
||||
gDriveData['scopes'] = request.GET.get('s')
|
||||
|
||||
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:
|
||||
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def restoreSite(self, request = None, userID = None, data = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
@@ -1534,6 +1534,7 @@ app.controller('remoteBackupControl', function ($scope, $http, $timeout) {
|
||||
///** Backup site ends **///
|
||||
|
||||
//*** Remote Backup site ****//
|
||||
|
||||
app.controller('backupLogsScheduled', function ($scope, $http, $timeout) {
|
||||
|
||||
$scope.cyberpanelLoading = true;
|
||||
@@ -1595,3 +1596,56 @@ app.controller('backupLogsScheduled', function ($scope, $http, $timeout) {
|
||||
});
|
||||
|
||||
///** Backup site ends **///
|
||||
|
||||
app.controller('googleDrive', function ($scope, $http) {
|
||||
|
||||
$scope.cyberPanelLoading = 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;
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
var data = {};
|
||||
|
||||
|
||||
dataurl = "/CloudLinux/fetchPackages";
|
||||
|
||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
|
||||
function ListInitialData(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.packages = JSON.parse(response.data.data);
|
||||
} 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'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -1,136 +1,99 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Set up Back up Destinations" %}{% endblock %}
|
||||
{% block title %}{% trans "Google Drive Backups - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Set up Back up Destinations" %} - <a target="_blank" href="http://go.cyberpanel.net/remote-backup" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Remote Backups" %}</span></a></h2>
|
||||
<p>{% trans "On this page you can set up your Back up destinations. (SFTP)" %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-controller="backupDestinations" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Set up Back up Destinations (SSH port should be 22 on backup server)" %} <img ng-hide="destinationLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "IP Address" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" ng-model="IPAddress" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "User" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input placeholder="{% trans "Backup server SSH User, leave empty for root." %}" type="text" class="form-control" ng-model="user" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input placeholder="" type="password" class="form-control" ng-model="password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input placeholder="{% trans "Backup server SSH Port, leave empty for 22." %}" type="text" class="form-control" ng-model="backupSSHPort" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<button type="button" ng-click="addDestination()" class="btn btn-primary btn-lg btn-block">{% trans "Add Destination" %}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!------ List of Destinations --------------->
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<div ng-hide="connectionFailed" class="alert alert-danger">
|
||||
<p>{% trans "Connection to" %} {$ IPAddress $} {% trans "failed. Please delete and re-add. " %} {$ errorMessage $} </p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="connectionSuccess" class="alert alert-success">
|
||||
<p>{% trans "Connection to" %} {$ IPAddress $} {% trans "successful." %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="canNotAddDestination" class="alert alert-danger">
|
||||
<p>{% trans "Cannot add destination. Error message:" %} {$ errorMessage $} </p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="destinationAdded" class="alert alert-success">
|
||||
<p>{% trans "Destination Added." %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="couldNotConnect" class="alert alert-danger">
|
||||
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
<div class="col-sm-12">
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "ID" %}</th>
|
||||
<th>{% trans "IP" %}</th>
|
||||
<th>{% trans "Check Connection" %}</th>
|
||||
<th>{% trans "Delete" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="record in records track by $index">
|
||||
<td ng-bind="record.id"></td>
|
||||
<td ng-bind="record.ip"></td>
|
||||
<td><button type="button" ng-click="checkConn(record.ip)" class="btn ra-100 btn-purple">{% trans "Check Connection" %}</button></td>
|
||||
<td ng-click="delDest(record.ip)"><img src="{% static 'images/delete.png' %}"></td>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!------ List of records --------------->
|
||||
|
||||
|
||||
</form>
|
||||
{% load static %}
|
||||
|
||||
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Set up Google Drive Backups" %} - <a target="_blank"
|
||||
href="http://go.cyberpanel.net/remote-backup"
|
||||
style="height: 23px;line-height: 21px;"
|
||||
class="btn btn-border btn-alt border-red btn-link font-red"
|
||||
title=""><span>{% trans "Remote Backups" %}</span></a>
|
||||
</h2>
|
||||
<p>{% trans "On this page you can set up and manage Google Drive Backups." %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-controller="googleDrive" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "On this page you can set up and manage Google Drive Backups." %} <img
|
||||
ng-hide="cyberPanelLoading" src="{% static 'images/loading.gif' %}"> <a
|
||||
class="btn btn-border btn-alt border-blue-alt btn-link font-blue-alt"
|
||||
href="#"
|
||||
title="" data-toggle="modal"
|
||||
data-target="#setupGdrive"><span>{% trans "Setup new Account" %}</span></a>
|
||||
<div id="setupGdrive" 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 "Repo Settings" %}</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 "Account Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="accountName" type="text" class="form-control"
|
||||
ng-model="accountName">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary"
|
||||
ng-click="setupAccount()">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>
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Drive Account" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="fetchWebsites()" ng-model="selectedAccount" class="form-control">
|
||||
{% for items in accounts %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -6,7 +6,8 @@ urlpatterns = [
|
||||
url(r'^getCurrentBackups', views.getCurrentBackups, name='getCurrentBackups'),
|
||||
url(r'^backupSite', views.backupSite, name='backupSite'),
|
||||
url(r'^restoreSite', views.restoreSite, name='restoreSite'),
|
||||
url(r'^gDrive', views.gDrive, name='gDrive'),
|
||||
url(r'^gDrive$', views.gDrive, name='gDrive'),
|
||||
url(r'^gDriveSetup$', views.gDriveSetup, name='gDriveSetup'),
|
||||
|
||||
|
||||
url(r'^submitBackupCreation', views.submitBackupCreation, name='submitBackupCreation'),
|
||||
|
||||
@@ -38,6 +38,14 @@ def gDrive(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def gDriveSetup(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
wm = BackupManager()
|
||||
return wm.gDriveSetup(userID, request)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def restoreSite(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
@@ -581,7 +581,7 @@
|
||||
title="{% trans 'Add Destination' %}"><span>{% trans "Add/Delete Destination" %}</span></a>
|
||||
</li>
|
||||
<li class="addDeleteDestinations"><a href="{% url 'gDrive' %}"
|
||||
title="{% trans 'Setup Google Drive' %}"><span>{% trans "Add/Delete Destination" %}</span></a>
|
||||
title="{% trans 'Setup Google Drive' %}"><span>{% trans "Setup Google Drive" %}</span></a>
|
||||
</li>
|
||||
<li class="scheDuleBackups"><a href="{% url 'scheduleBackup' %}"
|
||||
title="{% trans 'Schedule Back up' %}"><span>{% trans "Schedule Back up" %}</span></a>
|
||||
|
||||
@@ -61,3 +61,17 @@ class BackupJobLogs(models.Model):
|
||||
owner = models.ForeignKey(BackupJob, on_delete=models.CASCADE)
|
||||
status = models.IntegerField()
|
||||
message = models.TextField()
|
||||
|
||||
class GDrive(models.Model):
|
||||
owner = models.ForeignKey(Administrator, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=50)
|
||||
auth = models.TextField(max_length=65532, default='Inactive')
|
||||
|
||||
class GDriveSites(models.Model):
|
||||
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)
|
||||
domain = models.CharField(max_length=200)
|
||||
|
||||
class GDriveJobLogs(models.Model):
|
||||
owner = models.ForeignKey(GDrive, on_delete=models.CASCADE)
|
||||
status = models.IntegerField()
|
||||
message = models.TextField()
|
||||
Reference in New Issue
Block a user