Skip to content

Commit

Permalink
Merge branch 'v2.3.5-dev' of github.com:usmannasir/cyberpanel into v2…
Browse files Browse the repository at this point in the history
….3.5-dev
  • Loading branch information
usmannasir committed Dec 18, 2023
2 parents a534a37 + b0e952f commit f31fe6f
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 90 deletions.
88 changes: 14 additions & 74 deletions baseTemplate/templates/baseTemplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}">
Expand Down Expand Up @@ -824,6 +765,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' %}">
Expand All @@ -836,21 +789,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' %}">
Expand Down Expand Up @@ -1148,6 +1086,8 @@
</ul><!-- #sidebar-menu -->
</div>
</div>


<div id="page-content-wrapper">
<div id="page-content">

Expand Down
10 changes: 5 additions & 5 deletions cloudAPI/cloudManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,11 +1070,11 @@ def showStatus(self, request):

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.')
Expand Down
23 changes: 23 additions & 0 deletions databases/databaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ def deleteDatabase(self, request = None, userID = None):
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:

Expand Down Expand Up @@ -308,6 +329,8 @@ def generatePHPMYAdminData(userID):
except BaseException as msg:
print("0," + str(msg))



def main():

parser = argparse.ArgumentParser(description='CyberPanel Installer')
Expand Down
121 changes: 121 additions & 0 deletions databases/mysqlOptimizer.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit f31fe6f

Please sign in to comment.