Skip to content

Commit bad53db

Browse files
committed
made changes in updatemysql
1 parent 4a6aca8 commit bad53db

File tree

7 files changed

+179
-7
lines changed

7 files changed

+179
-7
lines changed

CyberCP/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
SECRET_KEY = 'xr%j*p!*$0d%(-(e%@-*hyoz4$f%y77coq0u)6pwmjg4)q&19f'
2525

2626
# SECURITY WARNING: don't run with debug turned on in production!
27-
DEBUG = False
27+
DEBUG = True
2828

2929
ALLOWED_HOSTS = ['*']
3030

databases/databaseManager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def OptimizeMySQL(self, request = None, userID = None):
130130
proc = httpProc(request, template, data, 'admin')
131131
return proc.render()
132132

133+
def Upgardemysql(self, request = None, userID = None):
134+
data={}
135+
data['mysqlversions']=['10.6','10.11']
136+
template = 'databases/Updatemysql.html'
137+
proc = httpProc(request, template, data, 'admin')
138+
return proc.render()
139+
140+
133141
def fetchDatabases(self, userID = None, data = None):
134142
try:
135143

databases/static/databases/databases.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,4 +836,61 @@ app.controller('OptimizeMysql', function ($scope, $http) {
836836
});
837837
}
838838
}
839-
})
839+
})
840+
841+
842+
app.controller('mysqlupdate', function ($scope, $http, $timeout) {
843+
$scope.cyberPanelLoading = true;
844+
$scope.dbLoading = true;
845+
$scope.installlogs = true;
846+
847+
$scope.Upgardemysql = function () {
848+
$scope.dbLoading = false;
849+
$scope.installform = true;
850+
851+
852+
url = "/dataBases/upgrademysqlnow";
853+
854+
var data = {
855+
mysqlversion: $scope.version
856+
};
857+
858+
var config = {
859+
headers: {
860+
'X-CSRFToken': getCookie('csrftoken')
861+
}
862+
};
863+
864+
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
865+
866+
867+
function ListInitialData(response) {
868+
$scope.cyberhosting = true;
869+
if (response.data.status === 1) {
870+
$scope.installlogs = false;
871+
872+
$timeout(getRequestStatus, 1000);
873+
874+
} else {
875+
new PNotify({
876+
title: 'Error!',
877+
text: response.data.error_message,
878+
type: 'error'
879+
});
880+
}
881+
882+
}
883+
884+
function cantLoadInitialData(response) {
885+
$scope.cyberhosting = true;
886+
new PNotify({
887+
title: 'Error!',
888+
text: 'Could not connect to server, please refresh this page.',
889+
type: 'error'
890+
});
891+
}
892+
}
893+
894+
895+
$scope.getRequestStatus
896+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{% extends "baseTemplate/index.html" %}
2+
{% load i18n %}
3+
{% block title %}{% trans "List Databases - CyberPanel" %}{% endblock %}
4+
{% block content %}
5+
6+
{% load static %}
7+
{% get_current_language as LANGUAGE_CODE %}
8+
<!-- Current language: {{ LANGUAGE_CODE }} -->
9+
10+
11+
<div class="container">
12+
<div id="page-title">
13+
<h2>{% trans "Upgrade Mysql" %}
14+
15+
</h2>
16+
<p>{% trans "On this page you can update mysql." %}</p>
17+
</div>
18+
<div ng-controller="mysqlupdate" class="panel">
19+
<div class="panel-body">
20+
<h3 class="content-box-header">
21+
{% trans "Update Mysql" %} <img ng-hide="dbLoading"
22+
src="{% static 'images/loading.gif' %}">
23+
</h3>
24+
<div class="example-box-wrapper">
25+
26+
<form name="websiteCreationForm" action="/"
27+
class="form-horizontal bordered-row panel-body">
28+
29+
<div ng-hide="installform" class="form-group">
30+
<label class="col-sm-3 control-label">{% trans "Mysql version" %} </label>
31+
<div class="col-sm-6">
32+
<select ng-model="version" class="form-control" required>
33+
{% for version in mysqlversions %}
34+
<option>{{ version }}</option>
35+
{% endfor %}
36+
</select>
37+
</div>
38+
</div>
39+
<div ng-hide="installform" class="form-group">
40+
<label class="col-sm-3 control-label"></label>
41+
<div class="col-sm-4">
42+
<button type="button" ng-click="Upgardemysql()"
43+
class="btn btn-primary btn-lg">{% trans "Update Mysql" %}</button>
44+
45+
</div>
46+
</div>
47+
48+
49+
<div ng-hide="installlogs" class="form-group">
50+
<textarea rows="30" style="width: 100%"></textarea>
51+
52+
</div>
53+
</form>
54+
</div>
55+
</div>
56+
</div>
57+
</div>
58+
59+
60+
</div>
61+
62+
63+
{% endblock %}

databases/templates/databases/mysqlmanager.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ <h3 style="display: inline-block;" class="content-box-header">MySQL status</h3>
2121
<a style="display: inline-block;" href="{% url 'OptimizeMySQL' %}" class="btn btn-primary">
2222
<i class="glyph-icon icon-database"></i> Optimize MySQL
2323
</a>
24+
<a style="display: inline-block;" href="{% url 'UpgradeMySQL' %}" class="btn btn-primary">
25+
<i class="glyph-icon icon-database"></i> Upgrade MySQL
26+
</a>
2427
</div>
2528

2629
<div class="content-box-header">

databases/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
url(r'^fetchDatabases', views.fetchDatabases, name='fetchDatabases'),
1010
url(r'^MysqlManager', views.MySQLManager, name='MysqlManager'),
1111
url(r'^OptimizeMySQL', views.OptimizeMySQL, name='OptimizeMySQL'),
12+
url(r'^upgrademysqlnow', views.upgrademysqlnow, name='upgrademysqlnow'),
13+
url(r'^UpgradeMySQL', views.UpgradeMySQL, name='UpgradeMySQL'),
1214
url(r'^getMysqlstatus', views.getMysqlstatus, name='getMysqlstatus'),
1315
url(r'^restartMySQL', views.restartMySQL, name='restartMySQL'),
1416
url(r'^generateRecommendations', views.generateRecommendations, name='generateRecommendations'),

databases/views.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
2+
import time
3+
from random import randint
34

45
from django.shortcuts import redirect, HttpResponse
56
from django.views.decorators.csrf import csrf_exempt
@@ -252,6 +253,7 @@ def generateAccess(request):
252253
json_data = json.dumps(data_ret)
253254
return HttpResponse(json_data)
254255

256+
255257
@csrf_exempt
256258
def fetchDetailsPHPMYAdmin(request):
257259
try:
@@ -260,15 +262,13 @@ def fetchDetailsPHPMYAdmin(request):
260262
admin = Administrator.objects.get(id=userID)
261263
currentACL = ACLManager.loadedACL(userID)
262264

263-
264-
265265
token = request.POST.get('token')
266266
username = request.POST.get('username')
267267

268268
from plogical.httpProc import httpProc
269269
proc = httpProc(request, None,
270270
)
271-
#return proc.ajax(0, str(request.POST.get('token')))
271+
# return proc.ajax(0, str(request.POST.get('token')))
272272

273273
if username != admin.userName:
274274
return redirect(loadLoginPage)
@@ -295,7 +295,6 @@ def fetchDetailsPHPMYAdmin(request):
295295
data['userName'] = mysqluser
296296
data['password'] = password
297297

298-
299298
proc = httpProc(request, 'databases/AutoLogin.html',
300299
data, 'admin')
301300
return proc.render()
@@ -370,6 +369,15 @@ def OptimizeMySQL(request):
370369
return redirect(loadLoginPage)
371370

372371

372+
def UpgradeMySQL(request):
373+
try:
374+
userID = request.session['userID']
375+
dm = DatabaseManager()
376+
return dm.Upgardemysql(request, userID)
377+
except KeyError:
378+
return redirect(loadLoginPage)
379+
380+
373381
def getMysqlstatus(request):
374382
try:
375383
userID = request.session['userID']
@@ -461,3 +469,34 @@ def applyMySQLChanges(request):
461469

462470
except KeyError:
463471
return redirect(loadLoginPage)
472+
473+
474+
def upgrademysqlnow(request):
475+
try:
476+
from plogical.virtualHostUtilities import virtualHostUtilities
477+
logging.writeToFile("----------------------habbi")
478+
userID = request.session['userID']
479+
480+
currentACL = ACLManager.loadedACL(userID)
481+
482+
if currentACL['admin'] == 1:
483+
pass
484+
else:
485+
return ACLManager.loadErrorJson('FilemanagerAdmin', 0)
486+
487+
data = json.loads(request.body)
488+
version =data['mysqlversion']
489+
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
490+
491+
492+
493+
execPath = f"/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/mysqlUtilities.py UpgradeMariaDB --version {version} --tempStatusPath {tempStatusPath}"
494+
ProcessUtilities.popenExecutioner(execPath)
495+
time.sleep(2)
496+
497+
data_ret = {'status': 1, 'error_message': "None",
498+
'tempStatusPath': tempStatusPath}
499+
json_data = json.dumps(data_ret)
500+
return HttpResponse(json_data)
501+
except KeyError:
502+
return redirect(loadLoginPage)

0 commit comments

Comments
 (0)