diff --git a/CyberCP/settings.py b/CyberCP/settings.py index 031ca5f63..0c4fe719b 100755 --- a/CyberCP/settings.py +++ b/CyberCP/settings.py @@ -24,7 +24,7 @@ SECRET_KEY = 'xr%j*p!*$0d%(-(e%@-*hyoz4$f%y77coq0u)6pwmjg4)q&19f' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ['*'] diff --git a/databases/databaseManager.py b/databases/databaseManager.py index c2a17d05c..312f29acf 100755 --- a/databases/databaseManager.py +++ b/databases/databaseManager.py @@ -130,6 +130,14 @@ def OptimizeMySQL(self, request = None, userID = None): proc = httpProc(request, template, data, 'admin') return proc.render() + def Upgardemysql(self, request = None, userID = None): + data={} + data['mysqlversions']=['10.6','10.11'] + template = 'databases/Updatemysql.html' + proc = httpProc(request, template, data, 'admin') + return proc.render() + + def fetchDatabases(self, userID = None, data = None): try: diff --git a/databases/static/databases/databases.js b/databases/static/databases/databases.js index d924674ce..f36c839b9 100755 --- a/databases/static/databases/databases.js +++ b/databases/static/databases/databases.js @@ -836,4 +836,163 @@ app.controller('OptimizeMysql', function ($scope, $http) { }); } } -}) \ No newline at end of file +}) + + +app.controller('mysqlupdate', function ($scope, $http, $timeout) { + $scope.cyberPanelLoading = true; + $scope.dbLoading = true; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.Upgardemysql = function () { + $scope.dbLoading = false; + $scope.installform = true; + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + + url = "/dataBases/upgrademysqlnow"; + + var data = { + mysqlversion: $scope.version + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberhosting = true; + if (response.data.status === 1) { + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.statusfile = response.data.tempStatusPath + + $timeout(getRequestStatus, 1000); + + } else { + $scope.errorMessage = response.data.error_message; + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = true; + $scope.modsecLoading = true; + $scope.failedToStartInallation = false; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + } + + } + + function cantLoadInitialData(response) { + $scope.cyberhosting = true; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + } + + + function getRequestStatus() { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + url = "/dataBases/upgrademysqlstatus"; + + var data = { + statusfile: $scope.statusfile + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.abort === 0) { + + $scope.modSecNotifyBox = true; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = false; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } else { + // Notifications + $timeout.cancel(); + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = true; + + $scope.requestData = response.data.requestStatus; + + if (response.data.installed === 0) { + $scope.installationFailed = false; + $scope.errorMessage = response.data.error_message; + } else { + $scope.modSecSuccessfullyInstalled = false; + $timeout(function () { + $window.location.reload(); + }, 3000); + } + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.modSecNotifyBox = false; + $scope.modeSecInstallBox = false; + $scope.modsecLoading = true; + $scope.failedToStartInallation = true; + $scope.couldNotConnect = false; + $scope.modSecSuccessfullyInstalled = true; + $scope.installationFailed = true; + + + } + + } +}); \ No newline at end of file diff --git a/databases/templates/databases/Updatemysql.html b/databases/templates/databases/Updatemysql.html new file mode 100644 index 000000000..91dcf2ff1 --- /dev/null +++ b/databases/templates/databases/Updatemysql.html @@ -0,0 +1,99 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "List Databases - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + +
+
+

{% trans "Upgrade Mysql" %} + +

+

{% trans "On this page you can update mysql." %}

+
+
+
+

+ {% trans "Update Mysql" %} +

+
+ +
+ +
+ +
+ +
+
+
+ +
+ + +
+
+ + +
+ +
+ +
+

{% trans "Failed to start installation, Error message: " %} {$ errorMessage + $}

+
+ +
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+

{% trans "Installation failed." %} {$ errorMessage $}

+
+ +
+

{% trans "CSF successfully installed, refreshing page in 3 seconds.." %}

+
+
+
+ + +
+ + +
+
+

{% trans "In winter we must protect each other.." %} +

+
+
+ +
+
+ +
+ +
+
+
+
+ + + + + +{% endblock %} diff --git a/databases/templates/databases/mysqlmanager.html b/databases/templates/databases/mysqlmanager.html index c38ae4c89..2fb55c533 100644 --- a/databases/templates/databases/mysqlmanager.html +++ b/databases/templates/databases/mysqlmanager.html @@ -21,6 +21,9 @@

MySQL status

Optimize MySQL + + Upgrade MySQL +
diff --git a/databases/urls.py b/databases/urls.py index 8e82d52cc..683981300 100755 --- a/databases/urls.py +++ b/databases/urls.py @@ -9,6 +9,9 @@ url(r'^fetchDatabases', views.fetchDatabases, name='fetchDatabases'), url(r'^MysqlManager', views.MySQLManager, name='MysqlManager'), url(r'^OptimizeMySQL', views.OptimizeMySQL, name='OptimizeMySQL'), + url(r'^upgrademysqlnow', views.upgrademysqlnow, name='upgrademysqlnow'), + url(r'^UpgradeMySQL', views.UpgradeMySQL, name='UpgradeMySQL'), + url(r'^upgrademysqlstatus', views.upgrademysqlstatus, name='upgrademysqlstatus'), url(r'^getMysqlstatus', views.getMysqlstatus, name='getMysqlstatus'), url(r'^restartMySQL', views.restartMySQL, name='restartMySQL'), url(r'^generateRecommendations', views.generateRecommendations, name='generateRecommendations'), diff --git a/databases/views.py b/databases/views.py index b6d2328ab..b7a70760e 100755 --- a/databases/views.py +++ b/databases/views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- - +import time +from random import randint from django.shortcuts import redirect, HttpResponse from django.views.decorators.csrf import csrf_exempt @@ -252,6 +253,7 @@ def generateAccess(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + @csrf_exempt def fetchDetailsPHPMYAdmin(request): try: @@ -260,15 +262,13 @@ def fetchDetailsPHPMYAdmin(request): admin = Administrator.objects.get(id=userID) currentACL = ACLManager.loadedACL(userID) - - token = request.POST.get('token') username = request.POST.get('username') from plogical.httpProc import httpProc proc = httpProc(request, None, ) - #return proc.ajax(0, str(request.POST.get('token'))) + # return proc.ajax(0, str(request.POST.get('token'))) if username != admin.userName: return redirect(loadLoginPage) @@ -295,7 +295,6 @@ def fetchDetailsPHPMYAdmin(request): data['userName'] = mysqluser data['password'] = password - proc = httpProc(request, 'databases/AutoLogin.html', data, 'admin') return proc.render() @@ -370,6 +369,15 @@ def OptimizeMySQL(request): return redirect(loadLoginPage) +def UpgradeMySQL(request): + try: + userID = request.session['userID'] + dm = DatabaseManager() + return dm.Upgardemysql(request, userID) + except KeyError: + return redirect(loadLoginPage) + + def getMysqlstatus(request): try: userID = request.session['userID'] @@ -461,3 +469,73 @@ def applyMySQLChanges(request): except KeyError: return redirect(loadLoginPage) + + +def upgrademysqlnow(request): + try: + from plogical.virtualHostUtilities import virtualHostUtilities + userID = request.session['userID'] + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson('FilemanagerAdmin', 0) + + data = json.loads(request.body) + version =data['mysqlversion'] + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + + + + execPath = f"/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/mysqlUtilities.py UpgradeMariaDB --version {version} --tempStatusPath {tempStatusPath}" + ProcessUtilities.popenExecutioner(execPath) + time.sleep(2) + + data_ret = {'status': 1, 'error_message': "None", + 'tempStatusPath': tempStatusPath} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except KeyError: + return redirect(loadLoginPage) + + +def upgrademysqlstatus(request): + try: + data = json.loads(request.body) + statusfile = data['statusfile'] + installStatus = ProcessUtilities.outputExecutioner("sudo cat " + statusfile) + + if installStatus.find("[200]") > -1: + + command = 'sudo rm -f ' + statusfile + ProcessUtilities.executioner(command) + + final_json = json.dumps({ + 'error_message': "None", + 'requestStatus': installStatus, + 'abort': 1, + 'installed': 1, + }) + return HttpResponse(final_json) + elif installStatus.find("[404]") > -1: + command = 'sudo rm -f ' + statusfile + ProcessUtilities.executioner(command) + final_json = json.dumps({ + 'abort': 1, + 'installed': 0, + 'error_message': "None", + 'requestStatus': installStatus, + }) + return HttpResponse(final_json) + + else: + final_json = json.dumps({ + 'abort': 0, + 'error_message': "None", + 'requestStatus': installStatus, + }) + return HttpResponse(final_json) + except KeyError: + return redirect(loadLoginPage)