mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-02-01 20:29:06 +01:00
gdrive2
This commit is contained in:
@@ -1141,4 +1141,25 @@ app.controller('restoreRemoteBackupsInc', function ($scope, $http, $timeout) {
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
app.controller('createV2Backups', function ($scope, $http, $timeout){
|
||||
$scope.cyberpanelLoading = true;
|
||||
$scope.selectbackuptype = function () {
|
||||
|
||||
$scope.cyberpanelLoading = false;
|
||||
|
||||
var backuptype = $scope.v2backuptype
|
||||
if (backuptype === 'GDrive')
|
||||
{
|
||||
$scope.cyberpanelLoading = true;
|
||||
$('#GdriveModal').modal('show');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$scope.setupAccount = function(){
|
||||
window.open("https://platform.cyberpersons.com/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup');
|
||||
};
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Create Incremental Backup" %}{% endblock %}
|
||||
{% block title %}{% trans "Create V2 Backup" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
@@ -9,219 +9,74 @@
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Backup Website" %} - <a target="_blank" href="https://cyberpanel.net/docs/2-create-restore-incremental-backups/"
|
||||
style="height: 23px;line-height: 21px;"
|
||||
class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Backup Docs" %}</span></a>
|
||||
</h2>
|
||||
<p>{% trans "This page can be used to create incremental backups for your websites." %}</p>
|
||||
|
||||
<div ng-controller="createV2Backups" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Backup V2" %} <img ng-hide="cyberpanelLoading"
|
||||
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 "Select Backup Type" %} </label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="selectbackuptype()" ng-model="v2backuptype" class="form-control">
|
||||
<option >SFTP</option>
|
||||
<option >GDrive</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<div id="GdriveModal" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog modal-lg">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×
|
||||
</button>
|
||||
<h4 class="modal-title">{% trans "Set up account" %}</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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>habbi test v2 backup</h1>
|
||||
|
||||
{# <div ng-controller="createIncrementalBackups" class="panel">#}
|
||||
{# <div class="panel-body">#}
|
||||
{# <h3 class="title-hero">#}
|
||||
{# {% trans "Backup Website" %} <img ng-hide="cyberpanelLoading"#}
|
||||
{# 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 "Select Website" %} </label>#}
|
||||
{# <div class="col-sm-6">#}
|
||||
{# <select ng-change="fetchDetails()" ng-model="websiteToBeBacked" class="form-control">#}
|
||||
{# {% for items in websiteList %}#}
|
||||
{# <option>{{ items }}</option>#}
|
||||
{# {% endfor %}#}
|
||||
{# </select>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# <div ng-hide="destination" class="form-group">#}
|
||||
{# <label class="col-sm-3 control-label">{% trans "Destination" %}</label>#}
|
||||
{# <div class="col-sm-6">#}
|
||||
{# <select ng-change="destinationSelection()" ng-model="backupDestinations"#}
|
||||
{# class="form-control">#}
|
||||
{# {% for items in destinations %}#}
|
||||
{# <option>{{ items }}</option>#}
|
||||
{# {% endfor %}#}
|
||||
{# </select>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# <div ng-hide="destination" class="form-group">#}
|
||||
{# <label class="col-sm-3 control-label">{% trans "Backup Content" %}</label>#}
|
||||
{# <div class="col-sm-9">#}
|
||||
{# <div class="checkbox">#}
|
||||
{# <label>#}
|
||||
{# <input ng-model="websiteData" type="checkbox" value="">#}
|
||||
{# Data#}
|
||||
{# </label>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <label class="col-sm-3 control-label"></label>#}
|
||||
{# <div class="col-sm-9">#}
|
||||
{# <div class="checkbox">#}
|
||||
{# <label>#}
|
||||
{# <input ng-model="websiteDatabases" type="checkbox" value="">#}
|
||||
{# Databases#}
|
||||
{# </label>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <label class="col-sm-3 control-label"></label>#}
|
||||
{# <div class="col-sm-9">#}
|
||||
{# <div class="checkbox">#}
|
||||
{# <label>#}
|
||||
{# <input ng-model="websiteEmails" type="checkbox" value="">#}
|
||||
{# Emails#}
|
||||
{# </label>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <!---#}
|
||||
{# <label class="col-sm-3 control-label"></label>#}
|
||||
{# <div class="col-sm-9">#}
|
||||
{# <div class="checkbox">#}
|
||||
{# <label>#}
|
||||
{# <input ng-model="websiteSSLs" type="checkbox" value="">#}
|
||||
{# SSL Certificates#}
|
||||
{# </label>#}
|
||||
{# </div>#}
|
||||
{# </div> -->#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{##}
|
||||
{# <!---- if Backup is running ----->#}
|
||||
{##}
|
||||
{# <div ng-hide="runningBackup" class="form-group">#}
|
||||
{# <div class="col-sm-12">#}
|
||||
{# <div class="col-sm-12">#}
|
||||
{# <textarea ng-model="status" class="form-control" rows="10"></textarea>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{##}
|
||||
{# <!---- if Backup is running------>#}
|
||||
{##}
|
||||
{# <div ng-hide="backupButton" class="form-group">#}
|
||||
{# <label class="col-sm-3 control-label"></label>#}
|
||||
{# <div class="col-sm-4">#}
|
||||
{# <button type="button" ng-click="createBackup()"#}
|
||||
{# class="btn btn-primary btn-lg btn-block">{% trans "Create Backup" %}</button>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{##}
|
||||
{# <!------ List of records --------------->#}
|
||||
{##}
|
||||
{# <div class="form-group">#}
|
||||
{##}
|
||||
{# <div class="col-sm-12">#}
|
||||
{##}
|
||||
{# <table class="table">#}
|
||||
{# <thead>#}
|
||||
{# <tr>#}
|
||||
{# <th>{% trans "ID" %}</th>#}
|
||||
{# <th>{% trans "Date" %}</th>#}
|
||||
{# <th>{% trans "Restore" %}</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.date"></td>#}
|
||||
{# <td>#}
|
||||
{# <a ng-click="restore(record.id)" data-toggle="modal" data-target="#settings"#}
|
||||
{# ng-click='deleteCLPackage()'#}
|
||||
{# class="btn btn-border btn-alt border-green btn-link font-green"#}
|
||||
{# title=""><span>Restore Points</span></a>#}
|
||||
{# <div id="settings" class="modal fade" role="dialog">#}
|
||||
{# <div class="modal-dialog modal-lg">#}
|
||||
{##}
|
||||
{# <!-- Modal content-->#}
|
||||
{# <div class="modal-content">#}
|
||||
{# <div class="modal-header">#}
|
||||
{# <button type="button" class="close" data-dismiss="modal">#}
|
||||
{# ×#}
|
||||
{# </button>#}
|
||||
{# <h4 class="modal-title">Restore Points#}
|
||||
{# <img ng-hide="cyberpanelLoading"#}
|
||||
{# src="{% static 'images/loading.gif' %}">#}
|
||||
{# </h4>#}
|
||||
{# </div>#}
|
||||
{# <div class="modal-body">#}
|
||||
{##}
|
||||
{# <table class="table">#}
|
||||
{# <thead>#}
|
||||
{# <tr>#}
|
||||
{# <th>{% trans "Job ID" %}</th>#}
|
||||
{# <th>{% trans "Snapshot ID" %}</th>#}
|
||||
{# <th>{% trans "Type" %}</th>#}
|
||||
{# <th>{% trans "Destination" %}</th>#}
|
||||
{# <th>{% trans "Action" %}</th>#}
|
||||
{# </tr>#}
|
||||
{# </thead>#}
|
||||
{# <tbody>#}
|
||||
{# <tr ng-repeat="job in jobs track by $index">#}
|
||||
{# <td ng-bind="job.id"></td>#}
|
||||
{# <td ng-bind="job.snapshotid"></td>#}
|
||||
{# <td ng-bind="job.type"></td>#}
|
||||
{# <td ng-bind="job.destination"></td>#}
|
||||
{# <td>#}
|
||||
{# <a ng-click="restorePoint(job.id, 0)" class="btn btn-border btn-alt border-green btn-link font-green"#}
|
||||
{# title=""><span>Restore</span></a>#}
|
||||
{# </td>#}
|
||||
{# </tr>#}
|
||||
{# </tbody>#}
|
||||
{# </table>#}
|
||||
{##}
|
||||
{# <div ng-hide="restoreSt" class="form-group">#}
|
||||
{# <div class="col-sm-12">#}
|
||||
{# <div class="col-sm-12">#}
|
||||
{# <textarea ng-model="status"#}
|
||||
{# class="form-control"#}
|
||||
{# rows="7"></textarea>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# </div>#}
|
||||
{# <div class="modal-footer">#}
|
||||
{# <button type="button" ng-disabled="savingSettings"#}
|
||||
{# class="btn btn-default" data-dismiss="modal">#}
|
||||
{# Close#}
|
||||
{# </button>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </td>#}
|
||||
{# <a href="">#}
|
||||
{# <td ng-click="deleteBackup(record.id)"><img#}
|
||||
{# src="{% static 'images/delete.png' %}"></td>#}
|
||||
{# </a>#}
|
||||
{# </tr>#}
|
||||
{# </tbody>#}
|
||||
{# </table>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# <!------ List of records --------------->#}
|
||||
{##}
|
||||
{##}
|
||||
{# </form>#}
|
||||
{##}
|
||||
{##}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -24,5 +24,6 @@ urlpatterns = [
|
||||
url(r'^addWebsite$', views.add_website, name='addWebsite'),
|
||||
### V2 Backups URls
|
||||
url(r'^createV2Backup$', views.createV2Backup, name='createV2Backup'),
|
||||
url(r'^createV2BackupSetup$', views.createV2BackupSetup, name='createV2BackupSetup'),
|
||||
|
||||
]
|
||||
@@ -6,8 +6,11 @@ from pathlib import Path
|
||||
from random import randint
|
||||
|
||||
from django.shortcuts import HttpResponse, redirect
|
||||
|
||||
from backup.backupManager import BackupManager
|
||||
from loginSystem.models import Administrator
|
||||
from loginSystem.views import loadLoginPage
|
||||
from plogical.Backupsv2 import CPBackupsV2
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
from plogical.acl import ACLManager
|
||||
from plogical.httpProc import httpProc
|
||||
@@ -709,17 +712,47 @@ def add_website(request):
|
||||
|
||||
def createV2Backup(request):
|
||||
try:
|
||||
#user_id, current_acl = _get_user_acl(request)
|
||||
# if ACLManager.currentContextPermission(current_acl, 'createBackup') == 0:
|
||||
# return ACLManager.loadError()
|
||||
user_id, current_acl = _get_user_acl(request)
|
||||
if ACLManager.currentContextPermission(current_acl, 'createBackup') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
# websites = ACLManager.findAllSites(current_acl, user_id)
|
||||
#
|
||||
# destinations = _get_destinations(local=True)
|
||||
proc = httpProc(request, 'IncBackups/createV2Backup.html', 'createBackup')
|
||||
proc = httpProc(request, 'IncBackups/createV2Backup.html')
|
||||
return proc.render()
|
||||
|
||||
# return def_renderer(request, 'IncBackups/createV2Backup.html', 'createBackup')
|
||||
|
||||
except BaseException as msg:
|
||||
final_json = json.dumps({'status': 0, 'error_message': str(msg)})
|
||||
logging.writeToFile(str(msg))
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def createV2BackupSetup(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
req_data={}
|
||||
req_data['token'] = request.GET.get('t')
|
||||
req_data['refresh_token'] = request.GET.get('r')
|
||||
req_data['token_uri'] = request.GET.get('to')
|
||||
req_data['scopes'] = request.GET.get('s')
|
||||
req_data['accountname'] = request.GET.get('n')
|
||||
|
||||
cpbuv2 = CPBackupsV2(
|
||||
{'domain': 'cyberpanel.net', 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
|
||||
'BackupEmails': 1, 'BackendName': 'testremote'})
|
||||
|
||||
# RcloneData = {"name": 'testremote', "host": "staging.cyberpanel.net", "user": "abcds2751", "port": "22",
|
||||
# "password": "hosting", }
|
||||
cpbuv2.SetupRcloneBackend(CPBackupsV2.GDrive, req_data)
|
||||
cpbuv2.InitiateBackup()
|
||||
|
||||
# wm = BackupManager()
|
||||
# return wm.gDriveSetup(userID, request)
|
||||
|
||||
final_dic = {'status': 1}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
@@ -28,6 +28,7 @@ class CPBackupsV2:
|
||||
### RCLONE BACKEND TYPES
|
||||
SFTP = 1
|
||||
LOCAL = 2
|
||||
GDrive = 3
|
||||
|
||||
RUSTIC_PATH = '/usr/bin/rustic'
|
||||
RCLONE_CONFIG = '/root/.config/rclone/rclone.conf'
|
||||
@@ -66,6 +67,22 @@ pass = {ObsecurePassword}
|
||||
command = f"echo '{content}' > {self.ConfigFilePath}"
|
||||
ProcessUtilities.executioner(command, self.website.externalApp, True)
|
||||
|
||||
command = f"chmod 600 {self.ConfigFilePath}"
|
||||
ProcessUtilities.executioner(command, self.website.externalApp)
|
||||
elif type == CPBackupsV2.GDrive:
|
||||
## config = {"name":, "host":, "user":, "port":, "path":, "password":,}
|
||||
command = f'rclone obscure {config["password"]}'
|
||||
ObsecurePassword = ProcessUtilities.outputExecutioner(command).rstrip('\n')
|
||||
|
||||
content = f'''[{config["name"]}]
|
||||
type = sftp
|
||||
host = {config["host"]}
|
||||
user = {config["user"]}
|
||||
pass = {ObsecurePassword}
|
||||
'''
|
||||
command = f"echo '{content}' > {self.ConfigFilePath}"
|
||||
ProcessUtilities.executioner(command, self.website.externalApp, True)
|
||||
|
||||
command = f"chmod 600 {self.ConfigFilePath}"
|
||||
ProcessUtilities.executioner(command, self.website.externalApp)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user