mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 13:25:51 +01:00
mysql changes
This commit is contained in:
@@ -217,65 +217,6 @@
|
||||
title="{% trans 'CPU Load Average' %}" data-placement="bottom">
|
||||
<span class="badge bg-red" id="load3">{$ three $}</span>
|
||||
</a>{% endcomment %}
|
||||
|
||||
{# <div class="dropdown" id="dashnav-btn">#}
|
||||
{# <a href="#" data-toggle="dropdown" data-placement="bottom"#}
|
||||
{# class="popover-button-header tooltip-button" title="{% trans 'Dashboard Quick Menu' %}">#}
|
||||
{# <i class="glyph-icon icon-linecons-cog"></i>#}
|
||||
{# </a>#}
|
||||
{# <div class="dropdown-menu float-right">#}
|
||||
{# <div class="box-sm">#}
|
||||
{# <div class="pad5T pad5B pad10L pad10R dashboard-buttons clearfix">#}
|
||||
{# <a href="{% url 'loadWebsitesHome' %}"#}
|
||||
{# class="btn vertical-button remove-border btn-info" title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-dashboard opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "Websites" %}#}
|
||||
{# </a>#}
|
||||
{# <a href="{% url 'packagesHome' %}"#}
|
||||
{# class="btn vertical-button remove-border btn-danger"#}
|
||||
{# title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-tags opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "Packages" %}#}
|
||||
{# </a>#}
|
||||
{# <a href="{% url 'dnsHome' %}" class="btn vertical-button remove-border btn-purple"#}
|
||||
{# title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-fire opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "DNS" %}#}
|
||||
{# </a>#}
|
||||
{# <a href="{% url 'loadFTPHome' %}"#}
|
||||
{# class="btn vertical-button remove-border btn-azure"#}
|
||||
{# title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-bar-chart-o opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "FTP" %}#}
|
||||
{# </a>#}
|
||||
{# <a href="{% url 'loadTuningHome' %}"#}
|
||||
{# class="btn vertical-button remove-border btn-yellow" title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-laptop opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "Tuning" %}#}
|
||||
{# </a>#}
|
||||
{# <a href="{% url 'serverStatusHome' %}"#}
|
||||
{# class="btn vertical-button remove-border btn-warning" title="{% trans '' %}">#}
|
||||
{# <span class="glyph-icon icon-separator-vertical pad0A medium">#}
|
||||
{# <i class="glyph-icon icon-code opacity-80 font-size-20"></i>#}
|
||||
{# </span>#}
|
||||
{# {% trans "Status" %}#}
|
||||
{# </a>#}
|
||||
{##}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
<a class="header-btn" target="_blank"
|
||||
href="https://www.youtube.com/channel/UCS6sgUWEhaFl1TO238Ck0xw?sub_confirmation=1"
|
||||
title="{% trans 'Youtube Channel' %}">
|
||||
@@ -821,6 +762,18 @@
|
||||
{% if admin %}
|
||||
|
||||
<li class="header"><span>{% trans "Server" %}</span></li>
|
||||
|
||||
<li >
|
||||
<a href="{% url 'MysqlManager' %}"
|
||||
title="{% trans 'Root File Manager' %}">
|
||||
<i class="glyph-icon icon-database"
|
||||
title="{% trans 'MySQL Manager' %}"
|
||||
data-original-title=".icon-cloud-upload" aria-describedby="tooltip896208"></i>
|
||||
<span>{% trans "MySQL Manager" %}</span>
|
||||
<span class="bs-label badge-warning">{% trans "NEW" %}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li id="sidebar-menu-item-root-file-manager">
|
||||
<a href="{% url 'Filemanager' %}"
|
||||
title="{% trans 'Root File Manager' %}">
|
||||
@@ -833,21 +786,6 @@
|
||||
|
||||
|
||||
|
||||
{# <li>#}
|
||||
{# <a href="#" title="{% trans 'Terminal' %}">#}
|
||||
{# <i class="glyph-icon icon-linecons-fire"></i>#}
|
||||
{# <span>{% trans "Web Terminal" %}</span>#}
|
||||
{# <span class="bs-label badge-yellow">{% trans "NEW" %}</span>#}
|
||||
{# </a>#}
|
||||
{# <div class="sidebar-submenu">#}
|
||||
{##}
|
||||
{# <ul>#}
|
||||
{# <li><a href="{% url 'terminal' %}"#}
|
||||
{# title="{% trans 'Web Based Terminal' %}"><span>{% trans "Terminal" %}</span></a>#}
|
||||
{# </li>#}
|
||||
{# </ul>#}
|
||||
{# </div><!-- .sidebar-submenu -->#}
|
||||
{# </li>#}
|
||||
|
||||
<li id="sidebar-menu-item-cloudlinux">
|
||||
<a href="#" title="{% trans 'CloudLinux' %}">
|
||||
@@ -1140,6 +1078,8 @@
|
||||
</ul><!-- #sidebar-menu -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="page-content-wrapper">
|
||||
<div id="page-content">
|
||||
|
||||
|
||||
@@ -1070,11 +1070,11 @@ class CloudManager:
|
||||
|
||||
def fetchRam(self, request):
|
||||
try:
|
||||
request.session['userID'] = self.admin.pk
|
||||
currentACL = ACLManager.loadedACL(self.admin.pk)
|
||||
|
||||
if currentACL['admin'] == 0:
|
||||
return self.ajaxPre(0, 'Only administrators can see MySQL status.')
|
||||
# request.session['userID'] = self.admin.pk
|
||||
# currentACL = ACLManager.loadedACL(self.admin.pk)
|
||||
#
|
||||
# if currentACL['admin'] == 0:
|
||||
# return self.ajaxPre(0, 'Only administrators can see MySQL status.')
|
||||
|
||||
# if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
# return self.ajaxPre(0, 'This feature is currently only available on CentOS.')
|
||||
|
||||
@@ -84,6 +84,27 @@ class DatabaseManager:
|
||||
proc = httpProc(request, template, {'websitesList': websitesName}, 'deleteDatabase')
|
||||
return proc.render()
|
||||
|
||||
def MySQLManager(self, request = None, userID = None):
|
||||
template = 'databases/mysqlmanager.html'
|
||||
proc = httpProc(request, template, None)
|
||||
return proc.render()
|
||||
def OptimizeMySQL(self, request = None, userID = None):
|
||||
from cloudAPI.cloudManager import CloudManager
|
||||
cm = CloudManager()
|
||||
result = cm.fetchRam(request)
|
||||
|
||||
data1 = json.loads(result.content)
|
||||
|
||||
|
||||
|
||||
data = {}
|
||||
data['ramInGB'] = data1.get('ramInGB')
|
||||
data['conf'] = data1.get('conf')
|
||||
|
||||
template = 'databases/OptimizeMySQL.html'
|
||||
proc = httpProc(request, template, data)
|
||||
return proc.render()
|
||||
|
||||
def fetchDatabases(self, userID = None, data = None):
|
||||
try:
|
||||
|
||||
@@ -308,6 +329,8 @@ class DatabaseManager:
|
||||
except BaseException as msg:
|
||||
print("0," + str(msg))
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||
|
||||
121
databases/mysqlOptimizer.py
Normal file
121
databases/mysqlOptimizer.py
Normal file
@@ -0,0 +1,121 @@
|
||||
|
||||
import math
|
||||
import random
|
||||
from textwrap import dedent
|
||||
|
||||
|
||||
|
||||
class MySQLOptimizer:
|
||||
defaults = {
|
||||
'mysql_dir': "/var/lib/mysql",
|
||||
|
||||
'log_error': "/var/lib/mysql/mysqld.log",
|
||||
'slow_query_log_file': "/var/lib/mysql/mysqld-slow.log",
|
||||
|
||||
'pid_file': "/var/lib/mysql/mysqld.pid",
|
||||
|
||||
'mysql_ram_gb': 1,
|
||||
|
||||
'query_cache_type': 0,
|
||||
'query_cache_size': 0,
|
||||
|
||||
'long_query_time': 2,
|
||||
'max_connections': 500,
|
||||
|
||||
'server_id': random.randint(100000, 999999)
|
||||
}
|
||||
|
||||
|
||||
@staticmethod
|
||||
def mycnf_innodb_log_file_size_MB(innodb_buffer_pool_size_GB):
|
||||
if innodb_buffer_pool_size_GB > 64:
|
||||
return '768M'
|
||||
if innodb_buffer_pool_size_GB > 24:
|
||||
return '512M'
|
||||
if innodb_buffer_pool_size_GB > 8:
|
||||
return '256M'
|
||||
if innodb_buffer_pool_size_GB > 2:
|
||||
return '128M'
|
||||
|
||||
return '64M'
|
||||
|
||||
@staticmethod
|
||||
def output_memory_gb(gb):
|
||||
|
||||
if math.fabs(math.ceil(gb) - gb) < 0.01:
|
||||
return str(int(gb)) + 'G'
|
||||
|
||||
return str(int(gb * 1024)) + 'M'
|
||||
|
||||
@staticmethod
|
||||
def mycnf_make(m):
|
||||
m['innodb_buffer_pool_size'] = MySQLOptimizer.output_memory_gb(float(m['mysql_ram_gb']) * 0.15)
|
||||
m['innodb_log_file_size'] = MySQLOptimizer.mycnf_innodb_log_file_size_MB(m['mysql_ram_gb'])
|
||||
return m
|
||||
|
||||
@staticmethod
|
||||
def output_my_cnf(_metaconf):
|
||||
return dedent("""
|
||||
[mysqld]
|
||||
|
||||
# GENERAL #
|
||||
user = mysql
|
||||
default-storage-engine = InnoDB
|
||||
#socket = {mysql_dir}/mysql.sock
|
||||
#pid-file = {pid_file}
|
||||
|
||||
# MyISAM #
|
||||
# key-buffer-size = 32M
|
||||
# myisam-recover = FORCE,BACKUP
|
||||
|
||||
# SAFETY #
|
||||
max-allowed-packet = 16M
|
||||
max-connect-errors = 1000000
|
||||
sql-mode = NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER
|
||||
sysdate-is-now = 1
|
||||
innodb-strict-mode = 1
|
||||
|
||||
# DATA STORAGE #
|
||||
datadir = {mysql_dir}
|
||||
|
||||
# SERVER ID #
|
||||
server-id = {server_id}
|
||||
|
||||
# CACHES AND LIMITS #
|
||||
max-connections = {max_connections}
|
||||
tmp-table-size = 32M
|
||||
max-heap-table-size = 32M
|
||||
query-cache-type = {query_cache_type}
|
||||
query-cache-size = {query_cache_size}
|
||||
thread-cache-size = 50
|
||||
open-files-limit = 65535
|
||||
table-definition-cache = 1024
|
||||
table-open-cache = 2048
|
||||
|
||||
# INNODB #
|
||||
innodb-flush-method = O_DIRECT
|
||||
innodb-log-files-in-group = 2
|
||||
innodb-log-file-size = {innodb_log_file_size}
|
||||
innodb-flush-log-at-trx-commit = 1
|
||||
innodb-file-per-table = 1
|
||||
innodb-buffer-pool-size = {innodb_buffer_pool_size}
|
||||
|
||||
# LOGGING #
|
||||
log-error = {log_error}
|
||||
slow-query-log = 1
|
||||
slow-query-log-file = {slow_query_log_file}
|
||||
log-queries-not-using-indexes = OFF
|
||||
long_query_time = 30
|
||||
|
||||
[mysqldump]
|
||||
max-allowed-packet = 16M
|
||||
|
||||
!includedir /etc/mysql/conf.d/
|
||||
!includedir /etc/mysql/mariadb.conf.d/
|
||||
|
||||
""".format(**MySQLOptimizer.mycnf_make(_metaconf)))
|
||||
|
||||
@staticmethod
|
||||
def generateRecommendations(detectedRam):
|
||||
MySQLOptimizer.defaults['mysql_ram_gb'] = int(float(detectedRam))
|
||||
return MySQLOptimizer.output_my_cnf(MySQLOptimizer.defaults)
|
||||
@@ -603,3 +603,211 @@ app.controller('phpMyAdmin', function ($scope, $http, $window) {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
app.controller('Mysqlmanager', function ($scope, $http, $compile, $window) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
$scope.mysql_status = 'test'
|
||||
|
||||
|
||||
$scope.getstatus = function () {
|
||||
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
url = "/dataBases/getMysqlstatus";
|
||||
|
||||
var data = {};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.uptime = response.data.uptime;
|
||||
$scope.connections = response.data.connections;
|
||||
$scope.Slow_queries = response.data.Slow_queries;
|
||||
$scope.processes = JSON.parse(response.data.processes);
|
||||
$timeout($scope.showStatus, 3000);
|
||||
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Successfully Fetched',
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: "cannot load",
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$scope.getstatus();
|
||||
});
|
||||
|
||||
|
||||
app.controller('OptimizeMysql', function ($scope, $http) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
|
||||
$scope.generateRecommendations = function () {
|
||||
$scope.cyberhosting = false;
|
||||
url = "/dataBases/generateRecommendations";
|
||||
|
||||
var data = {
|
||||
detectedRam: $("#detectedRam").text()
|
||||
};
|
||||
|
||||
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.suggestedContent = response.data.generatedConf;
|
||||
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberhosting = true;
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: 'Could not connect to server, please refresh this page.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
$scope.applyMySQLChanges = function () {
|
||||
$scope.cyberhosting = false;
|
||||
url = "/dataBases/applyMySQLChanges";
|
||||
|
||||
var encodedContent = encodeURIComponent($scope.suggestedContent);
|
||||
|
||||
var data = {
|
||||
suggestedContent: encodedContent
|
||||
};
|
||||
|
||||
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) {
|
||||
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Changes successfully applied.',
|
||||
type: 'success'
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberhosting = true;
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: 'Could not connect to server, please refresh this page.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
$scope.restartMySQL = function () {
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
url = "/dataBases/restartMySQL";
|
||||
|
||||
var data = {};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Successfully Done',
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberhosting = true;
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: 'Could not connect to server, please refresh this page.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
BIN
databases/static/databases/hourglass.png
Normal file
BIN
databases/static/databases/hourglass.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
databases/static/databases/link.png
Normal file
BIN
databases/static/databases/link.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
databases/static/databases/snail.png
Normal file
BIN
databases/static/databases/snail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
70
databases/templates/databases/OptimizeMySQL.html
Normal file
70
databases/templates/databases/OptimizeMySQL.html
Normal file
@@ -0,0 +1,70 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Mysql Manager - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container" ng-controller="OptimizeMysql">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Optimize MySQL" %} <img ng-hide="cyberPanelLoading"
|
||||
src="{% static 'images/loading.gif' %}"></h2>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
|
||||
|
||||
<button style="margin-bottom: 2%; display: inline" ng-click="generateRecommendations()" type="button"
|
||||
class="btn btn-success"><i
|
||||
class="mdi mdi-dns mr-1"></i>
|
||||
<span>Generate Recommendations</span>
|
||||
</button>
|
||||
|
||||
<button style="margin-bottom: 2%; display: inline" ng-click="applyMySQLChanges()" type="button"
|
||||
class="btn btn-danger"><i
|
||||
class="mdi mdi-dns mr-1"></i>
|
||||
<span>Apply Changes</span>
|
||||
</button>
|
||||
|
||||
<button style="margin-bottom: 2%; display: inline" ng-click="restartMySQL()" type="button"
|
||||
class="btn btn-info"><i
|
||||
class="mdi mdi-dns mr-1"></i>
|
||||
<span>Restart MySQL</span>
|
||||
</button>
|
||||
|
||||
<div class="right" style="float: right; display: inline">
|
||||
<strong> Detected Ram: <b id="detectedRam">{{ ramInGB }}</b></strong>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group mb-3">
|
||||
<label for="billing-town-city">Current contents of my.cnf</label>
|
||||
<textarea placeholder="{{ conf }}" rows="25"
|
||||
class="form-control">{{ conf }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group mb-3">
|
||||
<label for="billing-town-city">Suggested Content</label>
|
||||
<textarea placeholder="Click Generate Recommendations to generate recommentations."
|
||||
ng-model="suggestedContent" rows="25"
|
||||
class="form-control"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- end row -->
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
129
databases/templates/databases/mysqlmanager.html
Normal file
129
databases/templates/databases/mysqlmanager.html
Normal file
@@ -0,0 +1,129 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Mysql Manager - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container" ng-controller="Mysqlmanager">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "MySQL Manager" %} <img ng-hide="cyberPanelLoading"
|
||||
src="{% static 'images/loading.gif' %}"></h2>
|
||||
</div>
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
<div class="panel panel-body">
|
||||
<div class="row">
|
||||
<h3 style="display: inline-block;" class="content-box-header">MySQL status</h3>
|
||||
|
||||
<a style="display: inline-block;" href="{% url 'OptimizeMySQL' %}" class="btn btn-primary">
|
||||
<i class="glyph-icon icon-database"></i> Optimize MySQL
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="content-box-header">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<!-- project card -->
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<!-- project title-->
|
||||
<h4 style="display: inline" class="mt-0">
|
||||
<strong>MySQL Uptime</strong>
|
||||
</h4>
|
||||
<img style="float: right; display: inline; height: 46px"
|
||||
src="{% static 'databases/hourglass.png' %}">
|
||||
|
||||
|
||||
<h4 class="mt-5"><b>{$ uptime $}</b></h4>
|
||||
|
||||
<!-- project detail-->
|
||||
</div> <!-- end card-body-->
|
||||
</div> <!-- end card-->
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<!-- project card -->
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<!-- project title-->
|
||||
<h4 style="display: inline" class="mt-0">
|
||||
<strong>Connections</strong>
|
||||
</h4>
|
||||
<img style="float: right; display: inline; height: 46px"
|
||||
src="{% static 'databases/link.png' %}">
|
||||
|
||||
|
||||
<h4 class="mt-5"><b>{$ connections $}</b></h4>
|
||||
|
||||
<!-- project detail-->
|
||||
</div> <!-- end card-body-->
|
||||
</div> <!-- end card-->
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<!-- project card -->
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<!-- project title-->
|
||||
<h4 style="display: inline" class="mt-0">
|
||||
<strong>Slow Queries</strong>
|
||||
</h4>
|
||||
<img style="float: right; display: inline; height: 46px"
|
||||
src="{% static 'databases/snail.png' %}">
|
||||
|
||||
|
||||
<h4 class="mt-5"><b>{$ Slow_queries $}</b></h4>
|
||||
|
||||
<!-- project detail-->
|
||||
</div> <!-- end card-body-->
|
||||
</div> <!-- end card-->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
<div class="panel panel-body">
|
||||
<h3 class="content-box-header"> MySQL Processes</h3>
|
||||
<div class="content-box-header">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>User</th>
|
||||
<th>Database</th>
|
||||
<th>Command</th>
|
||||
<th>Time</th>
|
||||
<th>State</th>
|
||||
<th>Info</th>
|
||||
<th>Progress</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="process in processes">
|
||||
<td ng-bind="process.id"></td>
|
||||
<td ng-bind="process.user"></td>
|
||||
<td ng-bind="process.database"></td>
|
||||
<td ng-bind="process.command"></td>
|
||||
<td ng-bind="process.time"></td>
|
||||
<td ng-bind="process.state"></td>
|
||||
<td ng-bind="process.info"></td>
|
||||
<td ng-bind="process.progress"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -7,6 +7,12 @@ urlpatterns = [
|
||||
url(r'^submitDBCreation', views.submitDBCreation, name='submitDBCreation'),
|
||||
url(r'^deleteDatabase', views.deleteDatabase, name='deleteDatabase'),
|
||||
url(r'^fetchDatabases', views.fetchDatabases, name='fetchDatabases'),
|
||||
url(r'^MysqlManager', views.MySQLManager, name='MysqlManager'),
|
||||
url(r'^OptimizeMySQL', views.OptimizeMySQL, name='OptimizeMySQL'),
|
||||
url(r'^getMysqlstatus', views.getMysqlstatus, name='getMysqlstatus'),
|
||||
url(r'^restartMySQL', views.restartMySQL, name='restartMySQL'),
|
||||
url(r'^generateRecommendations', views.generateRecommendations, name='generateRecommendations'),
|
||||
url(r'^applyMySQLChanges', views.applyMySQLChanges, name='applyMySQLChanges'),
|
||||
|
||||
|
||||
url(r'^submitDatabaseDeletion', views.submitDatabaseDeletion, name='submitDatabaseDeletion'),
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
|
||||
from django.shortcuts import redirect, HttpResponse
|
||||
|
||||
from cloudAPI.cloudManager import CloudManager
|
||||
from loginSystem.views import loadLoginPage
|
||||
from .databaseManager import DatabaseManager
|
||||
from .mysqlOptimizer import MySQLOptimizer
|
||||
from .pluginManager import pluginManager
|
||||
import json
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
@@ -14,6 +17,8 @@ from plogical import randomPassword
|
||||
from cryptography.fernet import Fernet
|
||||
from plogical.mysqlUtilities import mysqlUtilities
|
||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def loadDatabaseHome(request):
|
||||
@@ -24,6 +29,7 @@ def loadDatabaseHome(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def createDatabase(request):
|
||||
try:
|
||||
result = pluginManager.preCreateDatabase(request)
|
||||
@@ -43,6 +49,7 @@ def createDatabase(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def submitDBCreation(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -63,6 +70,7 @@ def submitDBCreation(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def deleteDatabase(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -71,6 +79,7 @@ def deleteDatabase(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def fetchDatabases(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -79,6 +88,7 @@ def fetchDatabases(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def submitDatabaseDeletion(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -97,6 +107,7 @@ def submitDatabaseDeletion(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def listDBs(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -105,6 +116,7 @@ def listDBs(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def changePassword(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -124,6 +136,7 @@ def changePassword(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def remoteAccess(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -135,6 +148,7 @@ def remoteAccess(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def allowRemoteIP(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -146,6 +160,7 @@ def allowRemoteIP(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def phpMyAdmin(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
@@ -154,12 +169,12 @@ def phpMyAdmin(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def generateAccess(request):
|
||||
try:
|
||||
|
||||
|
||||
userID = request.session['userID']
|
||||
admin = Administrator.objects.get(id = userID)
|
||||
admin = Administrator.objects.get(id=userID)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
## if user ACL is admin login as root
|
||||
@@ -181,13 +196,12 @@ def generateAccess(request):
|
||||
|
||||
password = randomPassword.generate_pass()
|
||||
token = randomPassword.generate_pass()
|
||||
GlobalUserDB(username=admin.userName, password=password,token=token).save()
|
||||
GlobalUserDB(username=admin.userName, password=password, token=token).save()
|
||||
|
||||
data_ret = {'status': 1, 'token': token, 'username': admin.userName}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
keySavePath = '/home/cyberpanel/phpmyadmin_%s' % (admin.userName)
|
||||
try:
|
||||
GlobalUserDB.objects.get(username=admin.userName).delete()
|
||||
@@ -237,18 +251,17 @@ def generateAccess(request):
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def fetchDetailsPHPMYAdmin(request):
|
||||
try:
|
||||
|
||||
|
||||
userID = request.session['userID']
|
||||
admin = Administrator.objects.get(id = userID)
|
||||
admin = Administrator.objects.get(id=userID)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
token = request.GET.get('token')
|
||||
username = request.GET.get('username')
|
||||
|
||||
|
||||
if username != admin.userName:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -303,3 +316,86 @@ def fetchDetailsPHPMYAdmin(request):
|
||||
data_ret = {'status': 0, 'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def MySQLManager(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.MySQLManager(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def OptimizeMySQL(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.OptimizeMySQL(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def getMysqlstatus(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
finalData = mysqlUtilities.showStatus()
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def restartMySQL(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
finalData = mysqlUtilities.restartMySQL()
|
||||
|
||||
data = {}
|
||||
|
||||
data['status'] = finalData[0]
|
||||
data['error_message'] = finalData[1]
|
||||
json_data = json.dumps(data)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def generateRecommendations(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
data = json.loads(request.body)
|
||||
detectedRam = data['detectedRam']
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
data['generatedConf'] = MySQLOptimizer.generateRecommendations(detectedRam)
|
||||
|
||||
final_json = json.dumps(data)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def applyMySQLChanges(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
data = json.loads(request.body)
|
||||
logging.writeToFile("=-------------------------------------------")
|
||||
finalData = mysqlUtilities.applyMySQLChanges(data)
|
||||
|
||||
data = {}
|
||||
|
||||
data['status'] = finalData[0]
|
||||
data['error_message'] = finalData[1]
|
||||
|
||||
final_json = json.dumps(data)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import os,sys
|
||||
from urllib.parse import unquote
|
||||
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
import django
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
@@ -583,7 +585,8 @@ password=%s
|
||||
command = 'sudo mv /etc/my.cnf /etc/my.cnf.bak'
|
||||
else:
|
||||
command = 'sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak'
|
||||
data['suggestedContent'] = data['suggestedContent'].replace('/var/lib/mysql/mysql.sock', '/var/run/mysqld/mysqld.sock')
|
||||
decoded_content = unquote(data['suggestedContent'])
|
||||
data['suggestedContent'] = decoded_content.replace('/var/lib/mysql/mysql.sock', '/var/run/mysqld/mysqld.sock')
|
||||
|
||||
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
Reference in New Issue
Block a user