mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +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>
|
||||
@@ -1093,3 +1093,78 @@ class CloudManager:
|
||||
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:
|
||||
return self.ajaxPre(0, str(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)
|
||||
|
||||
@@ -5410,96 +5410,3 @@ 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 "ウルドゥー語"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import os.path
|
||||
import sys
|
||||
import django
|
||||
import mimetypes
|
||||
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
django.setup()
|
||||
@@ -24,12 +25,13 @@ import docker
|
||||
import docker.utils
|
||||
import requests
|
||||
|
||||
|
||||
# Use default socket to connect
|
||||
class ContainerManager:
|
||||
def __init__(self, name = None):
|
||||
def __init__(self, name=None):
|
||||
self.name = name
|
||||
|
||||
def submitInstallDocker(self, userID = None, data = None):
|
||||
def submitInstallDocker(self, userID=None, data=None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'createContainer') == 0:
|
||||
@@ -51,7 +53,7 @@ class ContainerManager:
|
||||
cmd = shlex.split(command)
|
||||
res4 = subprocess.call(cmd)
|
||||
|
||||
if res == 0 and res2 == 0 and res3 == 0 and res4 ==0:
|
||||
if res == 0 and res2 == 0 and res3 == 0 and res4 == 0:
|
||||
data_ret = {'installDockerStatus': 1, 'error_message': 'None'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
@@ -65,7 +67,7 @@ class ContainerManager:
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def createContainer(self, request = None, userID = None, data = None):
|
||||
def createContainer(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
@@ -85,19 +87,19 @@ class ContainerManager:
|
||||
name = image
|
||||
|
||||
try:
|
||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
||||
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||
except docker.errors.ImageNotFound:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
return render(request,'dockerManager/images.html',{"type":admin.type,
|
||||
'image':image,
|
||||
'tag':tag})
|
||||
return render(request, 'dockerManager/images.html', {"type": admin.type,
|
||||
'image': image,
|
||||
'tag': tag})
|
||||
|
||||
envList = {};
|
||||
if 'Env' in inspectImage['Config']:
|
||||
for item in inspectImage['Config']['Env']:
|
||||
if '=' in item:
|
||||
splitedItem = item.split('=',1)
|
||||
splitedItem = item.split('=', 1)
|
||||
print splitedItem
|
||||
envList[splitedItem[0]] = splitedItem[1]
|
||||
else:
|
||||
@@ -112,14 +114,15 @@ class ContainerManager:
|
||||
if image is None or image is '' or tag is None or tag is '':
|
||||
return redirect(loadImages)
|
||||
|
||||
Data = {"ownerList": adminNames, "image":image, "name":name, "tag":tag, "portConfig": portConfig, "envList":envList}
|
||||
Data = {"ownerList": adminNames, "image": image, "name": name, "tag": tag, "portConfig": portConfig,
|
||||
"envList": envList}
|
||||
|
||||
return render(request, 'dockerManager/runContainer.html', Data)
|
||||
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def loadContainerHome(self, request = None, userID = None, data = None):
|
||||
def loadContainerHome(self, request=None, userID=None, data=None):
|
||||
name = self.name
|
||||
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
@@ -168,14 +171,12 @@ class ContainerManager:
|
||||
data['cpuUsage'] = round(cpu_delta / system_delta * 100.0 * cpu_count, 3)
|
||||
else:
|
||||
data['memoryUsage'] = 0
|
||||
data['cpuUsage'] = 0;
|
||||
data['cpuUsage'] = 0
|
||||
|
||||
return render(request, 'dockerManager/viewContainer.html', data)
|
||||
|
||||
def listContainers(self, request = None, userID = None, data = None):
|
||||
def listContainers(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadError()
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
|
||||
@@ -214,18 +215,18 @@ class ContainerManager:
|
||||
return render(request, 'dockerManager/listContainers.html', {"pagination": pagination,
|
||||
"unlistedContainers": unlistedContainers,
|
||||
"adminNames": adminNames,
|
||||
"showUnlistedContainer":showUnlistedContainer})
|
||||
"showUnlistedContainer": showUnlistedContainer})
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def getContainerLogs(self, userID = None, data = None):
|
||||
def getContainerLogs(self, userID=None, data=None):
|
||||
try:
|
||||
name = data['name']
|
||||
|
||||
# Check if container is registered in database or unlisted
|
||||
if Containers.objects.filter(name=name).exists():
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('containerLogStatus',0)
|
||||
return ACLManager.loadErrorJson('containerLogStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -239,16 +240,16 @@ class ContainerManager:
|
||||
|
||||
|
||||
except BaseException, msg:
|
||||
data_ret = {'containerLogStatus': 0, 'containerLog':'Error', 'error_message': str(msg)}
|
||||
data_ret = {'containerLogStatus': 0, 'containerLog': 'Error', 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def submitContainerCreation(self, userID = None, data = None):
|
||||
def submitContainerCreation(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadErrorJson('createContainerStatus',0)
|
||||
return ACLManager.loadErrorJson('createContainerStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -260,7 +261,7 @@ class ContainerManager:
|
||||
memory = data['memory']
|
||||
envList = data['envList']
|
||||
|
||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
||||
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||
portConfig = {}
|
||||
|
||||
# Formatting envList for usage
|
||||
@@ -281,12 +282,12 @@ class ContainerManager:
|
||||
## Create Configurations
|
||||
admin = Administrator.objects.get(userName=dockerOwner)
|
||||
|
||||
containerArgs = {'image':image+":"+tag,
|
||||
'detach':True,
|
||||
'name':name,
|
||||
'ports':portConfig,
|
||||
containerArgs = {'image': image + ":" + tag,
|
||||
'detach': True,
|
||||
'name': name,
|
||||
'ports': portConfig,
|
||||
'publish_all_ports': True,
|
||||
'environment':envDict}
|
||||
'environment': envDict}
|
||||
|
||||
containerArgs['mem_limit'] = memory * 1048576; # Converts MB to bytes ( 0 * x = 0 for unlimited memory)
|
||||
|
||||
@@ -321,12 +322,12 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def submitInstallImage(self, userID = None, data = None):
|
||||
def submitInstallImage(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadErrorJson('installImageStatus',0)
|
||||
return ACLManager.loadErrorJson('installImageStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -335,7 +336,7 @@ class ContainerManager:
|
||||
tag = data['tag']
|
||||
|
||||
try:
|
||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
||||
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||
data_ret = {'installImageStatus': 0, 'error_message': "Image already installed"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
@@ -350,7 +351,6 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
data_ret = {'installImageStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
@@ -361,7 +361,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def submitContainerDeletion(self, userID = None, data = None, called = False):
|
||||
def submitContainerDeletion(self, userID=None, data=None, called=False):
|
||||
try:
|
||||
name = data['name']
|
||||
# Check if container is registered in database or unlisted
|
||||
@@ -434,11 +434,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def getContainerList(self, userID = None, data = None):
|
||||
def getContainerList(self, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadErrorJson('listContainerStatus',0)
|
||||
return ACLManager.loadErrorJson('listContainerStatus', 0)
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
pageNumber = int(data['page'])
|
||||
@@ -464,7 +464,7 @@ class ContainerManager:
|
||||
checker = 0
|
||||
|
||||
for items in containers:
|
||||
dic = {'name': items.name,'admin': items.admin.userName, 'tag':items.tag, 'image':items.image}
|
||||
dic = {'name': items.name, 'admin': items.admin.userName, 'tag': items.tag, 'image': items.image}
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
@@ -476,12 +476,12 @@ class ContainerManager:
|
||||
|
||||
return json_data
|
||||
|
||||
def doContainerAction(self, userID = None, data = None):
|
||||
def doContainerAction(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
name = data['name']
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('containerActionStatus',0)
|
||||
return ACLManager.loadErrorJson('containerActionStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -525,11 +525,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def getContainerStatus(self, userID = None, data = None):
|
||||
def getContainerStatus(self, userID=None, data=None):
|
||||
try:
|
||||
name = data['name']
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('containerStatus',0)
|
||||
return ACLManager.loadErrorJson('containerStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -555,11 +555,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def exportContainer(self, request = None, userID = None, data = None):
|
||||
def exportContainer(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
name = request.GET.get('name')
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('containerStatus',0)
|
||||
return ACLManager.loadErrorJson('containerStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -577,7 +577,7 @@ class ContainerManager:
|
||||
|
||||
eFile = container.export() # Export with default chunk size
|
||||
response = HttpResponse(eFile, content_type='application/force-download')
|
||||
response['Content-Disposition'] = 'attachment; filename="'+ name +'.tar"'
|
||||
response['Content-Disposition'] = 'attachment; filename="' + name + '.tar"'
|
||||
return response
|
||||
|
||||
except BaseException, msg:
|
||||
@@ -585,11 +585,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def getContainerTop(self, userID = None, data = None):
|
||||
def getContainerTop(self, userID=None, data=None):
|
||||
try:
|
||||
name = data['name']
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('containerTopStatus',0)
|
||||
return ACLManager.loadErrorJson('containerTopStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -612,7 +612,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data_ret = {'containerTopStatus': 1, 'error_message': 'None', 'processes':top}
|
||||
data_ret = {'containerTopStatus': 1, 'error_message': 'None', 'processes': top}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@@ -621,12 +621,12 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def assignContainer(self, userID = None, data = None):
|
||||
def assignContainer(self, userID=None, data=None):
|
||||
try:
|
||||
# Todo: add check only for super user i.e. main admin
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadErrorJson('assignContainerStatus',0)
|
||||
return ACLManager.loadErrorJson('assignContainerStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -662,11 +662,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def searchImage(self, userID = None, data = None):
|
||||
def searchImage(self, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadErrorJson('searchImageStatus',0)
|
||||
return ACLManager.loadErrorJson('searchImageStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -691,8 +691,7 @@ class ContainerManager:
|
||||
else:
|
||||
image['name2'] = image['name']
|
||||
|
||||
|
||||
data_ret = {'searchImageStatus': 1, 'error_message': 'None', 'matches':matches}
|
||||
data_ret = {'searchImageStatus': 1, 'error_message': 'None', 'matches': matches}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@@ -701,7 +700,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def images(self, request = None, userID = None, data = None):
|
||||
def images(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
@@ -737,17 +736,17 @@ class ContainerManager:
|
||||
images[name]['tags'].extend(tags)
|
||||
else:
|
||||
names.append(name)
|
||||
images[name] = {"name":name,
|
||||
"name2":name2,
|
||||
"tags":tags}
|
||||
images[name] = {"name": name,
|
||||
"name2": name2,
|
||||
"tags": tags}
|
||||
print "======"
|
||||
print images
|
||||
return render(request, 'dockerManager/images.html', {"images":images, "test":'asds'})
|
||||
return render(request, 'dockerManager/images.html', {"images": images, "test": ''})
|
||||
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def manageImages(self, request = None, userID = None, data = None):
|
||||
def manageImages(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
@@ -768,14 +767,14 @@ class ContainerManager:
|
||||
else:
|
||||
names.append(name)
|
||||
tags = []
|
||||
images[name] = {"name":name,
|
||||
"tags":image.tags}
|
||||
return render(request, 'dockerManager/manageImages.html', {"images":images})
|
||||
images[name] = {"name": name,
|
||||
"tags": image.tags}
|
||||
return render(request, 'dockerManager/manageImages.html', {"images": images})
|
||||
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def getImageHistory(self, userID = None, data = None):
|
||||
def getImageHistory(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
name = data['name']
|
||||
@@ -797,9 +796,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
|
||||
data_ret = {'imageHistoryStatus': 1, 'error_message': 'None', 'history':image.history()}
|
||||
data_ret = {'imageHistoryStatus': 1, 'error_message': 'None', 'history': image.history()}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@@ -808,7 +805,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def removeImage(self, userID = None, data = None):
|
||||
def removeImage(self, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if admin.acl.adminStatus != 1:
|
||||
@@ -833,8 +830,6 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
|
||||
data_ret = {'removeImageStatus': 1, 'error_message': 'None'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
@@ -864,11 +859,11 @@ class ContainerManager:
|
||||
return delStatus
|
||||
|
||||
print env
|
||||
containerArgs = {'image':image+":"+tag,
|
||||
'detach':True,
|
||||
'name':name,
|
||||
'ports':port,
|
||||
'environment':env,
|
||||
containerArgs = {'image': image + ":" + tag,
|
||||
'detach': True,
|
||||
'name': name,
|
||||
'ports': port,
|
||||
'environment': env,
|
||||
'publish_all_ports': True,
|
||||
'mem_limit': memory * 1048576}
|
||||
|
||||
@@ -883,11 +878,11 @@ class ContainerManager:
|
||||
except BaseException, msg:
|
||||
return str(msg)
|
||||
|
||||
def saveContainerSettings(self, userID = None, data = None):
|
||||
def saveContainerSettings(self, userID=None, data=None):
|
||||
try:
|
||||
name = data['name']
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('saveSettingsStatus',0)
|
||||
return ACLManager.loadErrorJson('saveSettingsStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -916,7 +911,7 @@ class ContainerManager:
|
||||
|
||||
try:
|
||||
container.update(mem_limit=memory * 1048576,
|
||||
restart_policy = rPolicy)
|
||||
restart_policy=rPolicy)
|
||||
except docker.errors.APIError as err:
|
||||
data_ret = {'saveSettingsStatus': 0, 'error_message': str(err)}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -941,7 +936,8 @@ class ContainerManager:
|
||||
'image': con.image,
|
||||
'tag': con.tag,
|
||||
'env': envDict,
|
||||
'ports': json.loads(con.ports), # No filter needed now as its ports are filtered when adding to database
|
||||
'ports': json.loads(con.ports),
|
||||
# No filter needed now as its ports are filtered when adding to database
|
||||
'memory': con.memory
|
||||
}
|
||||
|
||||
@@ -963,11 +959,11 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def recreateContainer(self, userID = None, data = None):
|
||||
def recreateContainer(self, userID=None, data=None):
|
||||
try:
|
||||
name = data['name']
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadErrorJson('saveSettingsStatus',0)
|
||||
return ACLManager.loadErrorJson('saveSettingsStatus', 0)
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
@@ -992,7 +988,8 @@ class ContainerManager:
|
||||
'image': con.image,
|
||||
'tag': con.tag,
|
||||
'env': json.loads(con.env),
|
||||
'ports': json.loads(con.ports), # No filter needed now as its ports are filtered when adding to database
|
||||
'ports': json.loads(con.ports),
|
||||
# No filter needed now as its ports are filtered when adding to database
|
||||
'memory': con.memory
|
||||
}
|
||||
|
||||
@@ -1011,7 +1008,7 @@ class ContainerManager:
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def getTags(self, userID = None, data = None):
|
||||
def getTags(self, userID=None, data=None):
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
@@ -1027,13 +1024,14 @@ class ContainerManager:
|
||||
image2 = "library/" + image
|
||||
|
||||
print image
|
||||
registryData = requests.get('https://registry.hub.docker.com/v2/repositories/'+image2+'/tags', {'page':page}).json()
|
||||
registryData = requests.get('https://registry.hub.docker.com/v2/repositories/' + image2 + '/tags',
|
||||
{'page': page}).json()
|
||||
|
||||
tagList = []
|
||||
for tag in registryData['results']:
|
||||
tagList.append(tag['name'])
|
||||
|
||||
data_ret = {'getTagsStatus': 1, 'list': tagList, 'next':registryData['next'], 'error_message': None}
|
||||
data_ret = {'getTagsStatus': 1, 'list': tagList, 'next': registryData['next'], 'error_message': None}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except BaseException, msg:
|
||||
|
||||
@@ -498,6 +498,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
def disableRuleFile(fileName, packName):
|
||||
try:
|
||||
|
||||
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
@@ -510,6 +511,14 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
|
||||
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"
|
||||
|
||||
except BaseException, msg:
|
||||
@@ -521,6 +530,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
def enableRuleFile(fileName, packName):
|
||||
try:
|
||||
|
||||
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||
confData = open(confFile).readlines()
|
||||
conf = open(confFile, 'w')
|
||||
@@ -532,6 +542,13 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
||||
conf.writelines(items)
|
||||
|
||||
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
|
||||
@@ -356,3 +384,226 @@ class mysqlUtilities:
|
||||
subprocess.call(shlex.split(command))
|
||||
logging.CyberCPLogFileWriter.writeToFile(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