mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
docker manager
This commit is contained in:
@@ -24,7 +24,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
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 = True
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
@@ -110,15 +110,15 @@ DATABASES = {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'cyberpanel',
|
||||
'USER': 'cyberpanel',
|
||||
'PASSWORD': 'a9AwLb7zY7ZwCd',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '',
|
||||
'PASSWORD': 'Bz9gF7Hr7X4RtD',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT':'3307'
|
||||
},
|
||||
'rootdb': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'mysql',
|
||||
'USER': 'root',
|
||||
'PASSWORD': '3bL8X7wGo0kT3b',
|
||||
'PASSWORD': 'sXm5VlRaAsXkDd',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '',
|
||||
},
|
||||
|
||||
@@ -21,7 +21,6 @@ urlpatterns = [
|
||||
url(r'^', include('loginSystem.urls')),
|
||||
url(r'^packages/',include('packages.urls')),
|
||||
url(r'^websites/',include('websiteFunctions.urls')),
|
||||
url(r'^docker/',include('dockerManager.urls')),
|
||||
url(r'^tuning/',include('tuning.urls')),
|
||||
url(r'^ftp/',include('ftp.urls')),
|
||||
url(r'^serverstatus/',include('serverStatus.urls')),
|
||||
@@ -41,4 +40,5 @@ urlpatterns = [
|
||||
url(r'^plugins/',include('pluginHolder.urls')),
|
||||
url(r'^emailMarketing/', include('emailMarketing.urls')),
|
||||
url(r'^cloudAPI/', include('cloudAPI.urls')),
|
||||
url(r'^docker/', include('dockerManager.urls')),
|
||||
]
|
||||
|
||||
@@ -570,7 +570,7 @@ def changeAdminPassword(request):
|
||||
firstName="Cyber", lastName="Panel", acl=acl, token=token)
|
||||
admin.save()
|
||||
|
||||
vers = version(currentVersion="1.7", build=6)
|
||||
vers = version(currentVersion="1.7", build=7)
|
||||
vers.save()
|
||||
|
||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
||||
|
||||
@@ -666,9 +666,9 @@
|
||||
<script src="{% static 'managePHP/managePHP.js' %}"></script>
|
||||
<script src="{% static 'baseTemplate/bootstrap-toggle.min.js' %}"></script>
|
||||
<script src="{% static 'firewall/firewall.js' %}"></script>
|
||||
<script src="{% static 'dockerManager/dockerManager.js' %}"></script>
|
||||
<script src="{% static 'manageSSL/manageSSL.js' %}"></script>
|
||||
<script src="{% static 'manageServices/manageServices.js' %}"></script>
|
||||
<script src="{% static 'dockerManager/dockerManager.js' %}"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1089,6 +1089,81 @@ class CloudManager:
|
||||
|
||||
finalData = mysqlUtilities.restartMySQL()
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def fetchDatabasesMYSQL(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.')
|
||||
|
||||
finalData = mysqlUtilities.fetchDatabases()
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def fetchTables(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.')
|
||||
|
||||
finalData = mysqlUtilities.fetchTables(self.data)
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def deleteTable(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.')
|
||||
|
||||
finalData = mysqlUtilities.deleteTable(self.data)
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def fetchTableData(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.')
|
||||
|
||||
finalData = mysqlUtilities.fetchTableData(self.data)
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
return self.ajaxPre(0, str(msg))
|
||||
|
||||
def fetchStructure(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.')
|
||||
|
||||
finalData = mysqlUtilities.fetchStructure(self.data)
|
||||
|
||||
finalData = json.dumps(finalData)
|
||||
return HttpResponse(finalData)
|
||||
except BaseException, msg:
|
||||
|
||||
@@ -229,6 +229,16 @@ def router(request):
|
||||
return cm.applyMySQLChanges(request)
|
||||
elif controller == 'restartMySQL':
|
||||
return cm.restartMySQL(request)
|
||||
elif controller == 'fetchDatabasesMYSQL':
|
||||
return cm.fetchDatabasesMYSQL(request)
|
||||
elif controller == 'fetchTables':
|
||||
return cm.fetchTables(request)
|
||||
elif controller == 'deleteTable':
|
||||
return cm.deleteTable(request)
|
||||
elif controller == 'fetchTableData':
|
||||
return cm.fetchTableData(request)
|
||||
elif controller == 'fetchStructure':
|
||||
return cm.fetchStructure(request)
|
||||
else:
|
||||
return cm.ajaxPre(0, 'This function is not available in your version of CyberPanel.')
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Installed Images" %} <img id="imageLoading" src="/static/images/loading.gif" style="display: none;">
|
||||
{{ test }}
|
||||
{% trans "Locally Available Images" %} <img id="imageLoading" src="/static/images/loading.gif" style="display: none;">
|
||||
</h3><br>
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<div id="page-title">
|
||||
<h2 id="domainNamePage">{% trans "Manage Images" %}
|
||||
<a class="pull-right btn btn-primary" href="{% url "containerImage" %}">Create</a>
|
||||
<a class="pull-right btn btn-primary" href="{% url "containerImage" %}">Create Container</a>
|
||||
</h2>
|
||||
<p>{% trans "On this page you can manage docker images." %}</p>
|
||||
</div>
|
||||
@@ -112,7 +112,7 @@
|
||||
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="imageList">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name (Installed)</th>
|
||||
<th>Name (Locally Available)</th>
|
||||
<th>Tags</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
|
||||
@@ -4,14 +4,11 @@ from __future__ import unicode_literals
|
||||
from django.shortcuts import render,redirect
|
||||
from loginSystem.models import Administrator
|
||||
from loginSystem.views import loadLoginPage
|
||||
from django.http import HttpResponse
|
||||
from plogical.container import ContainerManager
|
||||
from dockerManager.pluginManager import pluginManager
|
||||
from decorators import preDockerRun
|
||||
from plogical.acl import ACLManager
|
||||
import json
|
||||
import requests
|
||||
import docker
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
@@ -1345,9 +1345,9 @@ class FirewallManager:
|
||||
if fileName == 'categories.conf':
|
||||
continue
|
||||
|
||||
if fileName.endswith('dis'):
|
||||
if fileName.endswith('bak'):
|
||||
status = 0
|
||||
fileName = fileName.rstrip('.dis')
|
||||
fileName = fileName.rstrip('.bak')
|
||||
elif fileName.endswith('conf'):
|
||||
status = 1
|
||||
else:
|
||||
|
||||
@@ -780,7 +780,7 @@ class preFlightsChecks:
|
||||
|
||||
os.chdir(self.path)
|
||||
|
||||
command = "wget http://cyberpanel.sh/CyberPanel.1.7.6.tar.gz"
|
||||
command = "wget http://cyberpanel.sh/CyberPanel.1.7.7.tar.gz"
|
||||
#command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
|
||||
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
||||
'CyberPanel Download',
|
||||
@@ -789,7 +789,7 @@ class preFlightsChecks:
|
||||
##
|
||||
|
||||
count = 0
|
||||
command = "tar zxf CyberPanel.1.7.6.tar.gz"
|
||||
command = "tar zxf CyberPanel.1.7.7.tar.gz"
|
||||
#command = "tar zxf CyberPanelTemp.tar.gz"
|
||||
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
||||
'Extract CyberPanel',1, 1, os.EX_OSERR)
|
||||
|
||||
@@ -5409,97 +5409,4 @@ msgstr "Web サイト "
|
||||
|
||||
#: websiteFunctions/templates/websiteFunctions/suspendWebsite.html:73
|
||||
msgid "Successfully "
|
||||
msgstr "成功しました "
|
||||
|
||||
#~ msgid "CPU Status"
|
||||
#~ msgstr "CPU の状態"
|
||||
|
||||
#~ msgid "Fullscreen"
|
||||
#~ msgstr "フルスクリーン"
|
||||
|
||||
#~ msgid "System Status"
|
||||
#~ msgstr "システムの状態"
|
||||
|
||||
#~ msgid "Update started..."
|
||||
#~ msgstr "更新を開始..."
|
||||
|
||||
#~ msgid "Update finished..."
|
||||
#~ msgstr "更新を終了..."
|
||||
|
||||
#~ msgid "Account Type"
|
||||
#~ msgstr "アカウント種別"
|
||||
|
||||
#~ msgid "User Accounts Limit"
|
||||
#~ msgstr "ユーザーアカウントの制限"
|
||||
|
||||
#~ msgid "Only Numbers"
|
||||
#~ msgstr "数字のみ"
|
||||
|
||||
#~ msgid "Username should be lowercase alphanumeric."
|
||||
#~ msgstr "ユーザー名は小文字の英数字である必要があります。"
|
||||
|
||||
#~ msgid "Must contain one number and one special character."
|
||||
#~ msgstr "1 つの数字と 1 つの特殊文字を含める必要があります。"
|
||||
|
||||
#~ msgid "Cannot create website. Error message:"
|
||||
#~ msgstr "Web サイトを作成できません。エラーメッセージ:"
|
||||
|
||||
#~ msgid "Website with domain"
|
||||
#~ msgstr "ドメインを持つ Web サイト"
|
||||
|
||||
#~ msgid " is Successfully Created"
|
||||
#~ msgstr " 作成されました"
|
||||
|
||||
#~ msgid "Installation successful. To complete the setup visit:"
|
||||
#~ msgstr "インストールに成功しました。 セットアップを完了するには:"
|
||||
|
||||
#, fuzzy
|
||||
#~| msgid "Username"
|
||||
#~ msgid "Admin Username"
|
||||
#~ msgstr "ユーザー名"
|
||||
|
||||
#, fuzzy
|
||||
#~| msgid "Password"
|
||||
#~ msgid "Admin Password"
|
||||
#~ msgstr "パスワード"
|
||||
|
||||
#, fuzzy
|
||||
#~| msgid "Database Name"
|
||||
#~ msgid "Database prefix"
|
||||
#~ msgstr "データベース名"
|
||||
|
||||
#~ msgid "Daily"
|
||||
#~ msgstr "日次"
|
||||
|
||||
#~ msgid "Weekly"
|
||||
#~ msgstr "週次"
|
||||
|
||||
#~ msgid "HTTP Statistics"
|
||||
#~ msgstr "HTTP の統計情報"
|
||||
|
||||
#~ msgid "Available/Max Connections"
|
||||
#~ msgstr "利用可能/最大 接続数"
|
||||
|
||||
#~ msgid "Available/Max SSL Connections"
|
||||
#~ msgstr "利用可能/最大 SSL 接続数"
|
||||
|
||||
#~ msgid "Requests Processing"
|
||||
#~ msgstr "リクエスト処理数"
|
||||
|
||||
#~ msgid "Total Requests"
|
||||
#~ msgstr "合計リクエスト数"
|
||||
|
||||
#~ msgid "IPV6"
|
||||
#~ msgstr "IPv6"
|
||||
|
||||
#~ msgid "Normal User"
|
||||
#~ msgstr "通常のユーザー"
|
||||
|
||||
#~ msgid "Edit Virtual Host Main Configurations"
|
||||
#~ msgstr "仮想ホストのメイン設定の編集"
|
||||
|
||||
#~ msgid "Configuration saved. Restart LiteSpeed put them in effect."
|
||||
#~ msgstr "設定が保存されました。 LiteSpeed を再起動して有効にします。"
|
||||
|
||||
#~ msgid "Urdu"
|
||||
#~ msgstr "ウルドゥー語"
|
||||
msgstr "成功しました "
|
||||
@@ -156,7 +156,7 @@ def loadLoginPage(request):
|
||||
firstName="Cyber",lastName="Panel", acl=acl, token=token)
|
||||
admin.save()
|
||||
|
||||
vers = version(currentVersion="1.7", build=6)
|
||||
vers = version(currentVersion="1.7", build=7)
|
||||
vers.save()
|
||||
|
||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
||||
|
||||
135
plogical/acl.py
135
plogical/acl.py
@@ -8,12 +8,12 @@ from loginSystem.models import Administrator, ACL
|
||||
from django.shortcuts import HttpResponse
|
||||
from packages.models import Package
|
||||
from websiteFunctions.models import Websites, ChildDomains
|
||||
from dockerManager.models import Containers
|
||||
from dns.models import Domains
|
||||
import json
|
||||
from subprocess import call, CalledProcessError
|
||||
from shlex import split
|
||||
from CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||
from dockerManager.models import Containers
|
||||
|
||||
class ACLManager:
|
||||
|
||||
@@ -364,73 +364,6 @@ class ACLManager:
|
||||
|
||||
return websiteNames
|
||||
|
||||
|
||||
@staticmethod
|
||||
def findAllContainers(currentACL, userID):
|
||||
containerName = []
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
allContainers = Containers.objects.all()
|
||||
for items in allContainers:
|
||||
containerName.append(items.name)
|
||||
else:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
containers = admin.containers_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
|
||||
for items in containers:
|
||||
containerName.append(items.name)
|
||||
|
||||
for items in admins:
|
||||
cons = items.containers_set.all()
|
||||
for con in cons:
|
||||
containerName.append(con.name)
|
||||
|
||||
return containerName
|
||||
|
||||
|
||||
@staticmethod
|
||||
def findContainersObjects(currentACL, userID):
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
return Containers.objects.all()
|
||||
else:
|
||||
|
||||
containerList = []
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
containers = admin.containers_set.all()
|
||||
|
||||
for items in containers:
|
||||
containerList.append(items)
|
||||
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
|
||||
for items in admins:
|
||||
cons = items.containers_set.all()
|
||||
for con in cons:
|
||||
containerList.append(web)
|
||||
|
||||
return containerList
|
||||
|
||||
|
||||
@staticmethod
|
||||
def checkContainerOwnership(name, userID):
|
||||
try:
|
||||
container = Containers.objects.get(name=name)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
return 1
|
||||
elif container.admin == admin:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
except:
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def findWebsiteObjects(currentACL, userID):
|
||||
|
||||
@@ -518,6 +451,72 @@ class ACLManager:
|
||||
logging.writeToFile(str(msg) + ' [ACLManager.executeCall]')
|
||||
return 0, str(msg)
|
||||
|
||||
@staticmethod
|
||||
def checkContainerOwnership(name, userID):
|
||||
return 1
|
||||
try:
|
||||
container = Containers.objects.get(name=name)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
return 1
|
||||
elif container.admin == admin:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
except:
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def findAllContainers(currentACL, userID):
|
||||
containerName = []
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
allContainers = Containers.objects.all()
|
||||
for items in allContainers:
|
||||
containerName.append(items.name)
|
||||
else:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
containers = admin.containers_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
|
||||
for items in containers:
|
||||
containerName.append(items.name)
|
||||
|
||||
for items in admins:
|
||||
cons = items.containers_set.all()
|
||||
for con in cons:
|
||||
containerName.append(con.name)
|
||||
|
||||
|
||||
return containerName
|
||||
|
||||
@staticmethod
|
||||
def findContainersObjects(currentACL, userID):
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
return Containers.objects.all()
|
||||
else:
|
||||
|
||||
containerList = []
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
containers = admin.containers_set.all()
|
||||
|
||||
for items in containers:
|
||||
containerList.append(items)
|
||||
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
|
||||
for items in admins:
|
||||
cons = items.containers_set.all()
|
||||
for con in cons:
|
||||
containerList.append(web)
|
||||
|
||||
return containerList
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -498,17 +498,26 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
def disableRuleFile(fileName, packName):
|
||||
try:
|
||||
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
|
||||
for items in confData:
|
||||
if items.find('modsec/'+packName) > -1 and items.find(fileName) > -1:
|
||||
conf.write("#" + items)
|
||||
else:
|
||||
conf.writelines(items)
|
||||
for items in confData:
|
||||
if items.find('modsec/'+packName) > -1 and items.find(fileName) > -1:
|
||||
conf.write("#" + items)
|
||||
else:
|
||||
conf.writelines(items)
|
||||
|
||||
conf.close()
|
||||
conf.close()
|
||||
|
||||
else:
|
||||
path = '/usr/local/lsws/conf/comodo_litespeed/'
|
||||
completePath = path + fileName
|
||||
completePathBak = path + fileName + '.bak'
|
||||
|
||||
command = 'mv ' + completePath + ' ' + completePathBak
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
print "1,None"
|
||||
|
||||
@@ -521,17 +530,25 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
def enableRuleFile(fileName, packName):
|
||||
try:
|
||||
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
|
||||
for items in confData:
|
||||
if items.find('modsec/' + packName) > -1 and items.find(fileName) > -1:
|
||||
conf.write(items.lstrip('#'))
|
||||
else:
|
||||
conf.writelines(items)
|
||||
for items in confData:
|
||||
if items.find('modsec/' + packName) > -1 and items.find(fileName) > -1:
|
||||
conf.write(items.lstrip('#'))
|
||||
else:
|
||||
conf.writelines(items)
|
||||
|
||||
conf.close()
|
||||
conf.close()
|
||||
else:
|
||||
path = '/usr/local/lsws/conf/comodo_litespeed/'
|
||||
completePath = path + fileName
|
||||
completePathBak = path + fileName + '.bak'
|
||||
|
||||
command = 'mv ' + completePathBak + ' ' + completePath
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
print "1,None"
|
||||
|
||||
|
||||
@@ -12,9 +12,37 @@ import MySQLdb as mysql
|
||||
import json
|
||||
from random import randint
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
import MySQLdb.cursors as cursors
|
||||
from math import ceil
|
||||
|
||||
class mysqlUtilities:
|
||||
|
||||
@staticmethod
|
||||
def getPagination(records, toShow):
|
||||
pages = float(records) / float(toShow)
|
||||
|
||||
pagination = []
|
||||
counter = 1
|
||||
|
||||
if pages <= 1.0:
|
||||
pages = 1
|
||||
pagination.append(counter)
|
||||
else:
|
||||
pages = ceil(pages)
|
||||
finalPages = int(pages) + 1
|
||||
|
||||
for i in range(1, finalPages):
|
||||
pagination.append(counter)
|
||||
counter = counter + 1
|
||||
|
||||
return pagination
|
||||
|
||||
@staticmethod
|
||||
def recordsPointer(page, toShow):
|
||||
finalPageNumber = ((page * toShow)) - toShow
|
||||
endPageNumber = finalPageNumber + toShow
|
||||
return endPageNumber, finalPageNumber
|
||||
|
||||
@staticmethod
|
||||
def setupConnection():
|
||||
try:
|
||||
@@ -25,7 +53,7 @@ class mysqlUtilities:
|
||||
password = data.split('\n', 1)[0]
|
||||
password = password.strip('\n').strip('\r')
|
||||
|
||||
conn = mysql.connect(user='root', passwd=password)
|
||||
conn = mysql.connect(user='root', passwd=password, cursorclass=cursors.SSCursor)
|
||||
cursor = conn.cursor()
|
||||
|
||||
return conn, cursor
|
||||
@@ -355,4 +383,227 @@ class mysqlUtilities:
|
||||
command = 'sudo mv /etc/my.cnf.bak /etc/my.cnf'
|
||||
subprocess.call(shlex.split(command))
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return 0, str(msg)
|
||||
return 0, str(msg)
|
||||
|
||||
@staticmethod
|
||||
def fetchDatabases():
|
||||
try:
|
||||
|
||||
connection, cursor = mysqlUtilities.setupConnection()
|
||||
|
||||
if connection == 0:
|
||||
return 0
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
|
||||
cursor.execute("SHOW DATABASES")
|
||||
result = cursor.fetchall()
|
||||
|
||||
counter = 1
|
||||
json_data = "["
|
||||
checker = 0
|
||||
|
||||
for items in result:
|
||||
if items[0] == 'information_schema' or items[0] == 'mysql' or items[0] == 'performance_schema' or items[
|
||||
0] == 'performance_schema':
|
||||
continue
|
||||
|
||||
dic = {
|
||||
'id': counter,
|
||||
'database': items[0]
|
||||
|
||||
}
|
||||
counter = counter + 1
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
|
||||
json_data = json_data + ']'
|
||||
data['databases'] = json_data
|
||||
return data
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[fetchDatabases]")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def fetchTables(name):
|
||||
try:
|
||||
|
||||
connection, cursor = mysqlUtilities.setupConnection()
|
||||
|
||||
if connection == 0:
|
||||
return 0
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
|
||||
cursor.execute("use " + name['databaseName'])
|
||||
cursor.execute("SHOW TABLE STATUS")
|
||||
result = cursor.fetchall()
|
||||
|
||||
counter = 1
|
||||
json_data = "["
|
||||
checker = 0
|
||||
|
||||
for items in result:
|
||||
|
||||
dic = {
|
||||
'Name': items[0],
|
||||
'Engine': items[1],
|
||||
'Version': items[2],
|
||||
'rowFormat': items[3],
|
||||
'rows': items[4],
|
||||
'Collation': items[14]
|
||||
}
|
||||
counter = counter + 1
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
json_data = json_data + ']'
|
||||
data['tables'] = json_data
|
||||
return data
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[fetchDatabases]")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def deleteTable(name):
|
||||
try:
|
||||
|
||||
connection, cursor = mysqlUtilities.setupConnection()
|
||||
|
||||
if connection == 0:
|
||||
return 0
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
|
||||
cursor.execute("use " + name['databaseName'])
|
||||
cursor.execute("DROP TABLE " + name['tableName'])
|
||||
|
||||
return data
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[fetchDatabases]")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def fetchTableData(name):
|
||||
try:
|
||||
|
||||
connection, cursor = mysqlUtilities.setupConnection()
|
||||
|
||||
if connection == 0:
|
||||
return 0
|
||||
|
||||
recordsToShow = int(name['recordsToShow'])
|
||||
page = int(name['currentPage'])
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
|
||||
##
|
||||
|
||||
cursor.execute("use " + name['databaseName'])
|
||||
cursor.execute("select count(*) from " + name['tableName'])
|
||||
rows = cursor.fetchall()[0][0]
|
||||
|
||||
|
||||
##
|
||||
|
||||
cursor.execute("desc " + name['tableName'])
|
||||
result = cursor.fetchall()
|
||||
|
||||
data['completeData'] = '<thead><tr>'
|
||||
|
||||
for items in result:
|
||||
data['completeData'] = data['completeData'] + '<th>' + items[0] + '</th>'
|
||||
|
||||
data['completeData'] = data['completeData'] + '</tr></thead>'
|
||||
|
||||
data['completeData'] = data['completeData'] + '<tbody>'
|
||||
|
||||
##
|
||||
|
||||
data['pagination'] = mysqlUtilities.getPagination(rows, recordsToShow)
|
||||
endPageNumber, finalPageNumber = mysqlUtilities.recordsPointer(page, recordsToShow)
|
||||
|
||||
cursor.execute("select * from " + name['tableName'])
|
||||
result = cursor.fetchall()
|
||||
|
||||
for items in result[finalPageNumber:endPageNumber]:
|
||||
data['completeData'] = data['completeData'] + '<tr>'
|
||||
for it in items:
|
||||
data['completeData'] = data['completeData'] + '<td>' + str(it) + '</td>'
|
||||
data['completeData'] = data['completeData'] + '</tr>'
|
||||
|
||||
data['completeData'] = data['completeData'] + '</tbody>'
|
||||
|
||||
##
|
||||
|
||||
return data
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[fetchTableData]")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def fetchStructure(name):
|
||||
try:
|
||||
|
||||
connection, cursor = mysqlUtilities.setupConnection()
|
||||
|
||||
if connection == 0:
|
||||
return 0
|
||||
|
||||
cursor.execute("use " + name['databaseName'])
|
||||
cursor.execute("desc " + name['tableName'])
|
||||
result = cursor.fetchall()
|
||||
|
||||
## Columns List
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
|
||||
for items in result:
|
||||
|
||||
dic = {
|
||||
'Name': items[0],
|
||||
'Type': items[1],
|
||||
'Null': items[2],
|
||||
'Key': items[3],
|
||||
'Default': items[4],
|
||||
'Extra': items[5]
|
||||
}
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
json_data = json_data + ']'
|
||||
|
||||
data['columns'] = json_data
|
||||
|
||||
##
|
||||
|
||||
return data
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[showStatus]")
|
||||
return 0
|
||||
@@ -12,6 +12,8 @@ ConfigArgParse==0.13.0
|
||||
configobj==4.7.2
|
||||
cryptography==2.2.2
|
||||
decorator==3.4.0
|
||||
docker==3.6.0
|
||||
docker-pycreds==0.4.0
|
||||
Django==1.11
|
||||
docutils==0.14
|
||||
enum34==1.1.6
|
||||
|
||||
Reference in New Issue
Block a user