mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +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'
|
SECRET_KEY = 'xr%j*p!*$0d%(-(e%@-*hyoz4$f%y77coq0u)6pwmjg4)q&19f'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
@@ -110,15 +110,15 @@ DATABASES = {
|
|||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': 'cyberpanel',
|
'NAME': 'cyberpanel',
|
||||||
'USER': 'cyberpanel',
|
'USER': 'cyberpanel',
|
||||||
'PASSWORD': 'a9AwLb7zY7ZwCd',
|
'PASSWORD': 'Bz9gF7Hr7X4RtD',
|
||||||
'HOST': 'localhost',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': '',
|
'PORT':'3307'
|
||||||
},
|
},
|
||||||
'rootdb': {
|
'rootdb': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': 'mysql',
|
'NAME': 'mysql',
|
||||||
'USER': 'root',
|
'USER': 'root',
|
||||||
'PASSWORD': '3bL8X7wGo0kT3b',
|
'PASSWORD': 'sXm5VlRaAsXkDd',
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
'PORT': '',
|
'PORT': '',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ urlpatterns = [
|
|||||||
url(r'^', include('loginSystem.urls')),
|
url(r'^', include('loginSystem.urls')),
|
||||||
url(r'^packages/',include('packages.urls')),
|
url(r'^packages/',include('packages.urls')),
|
||||||
url(r'^websites/',include('websiteFunctions.urls')),
|
url(r'^websites/',include('websiteFunctions.urls')),
|
||||||
url(r'^docker/',include('dockerManager.urls')),
|
|
||||||
url(r'^tuning/',include('tuning.urls')),
|
url(r'^tuning/',include('tuning.urls')),
|
||||||
url(r'^ftp/',include('ftp.urls')),
|
url(r'^ftp/',include('ftp.urls')),
|
||||||
url(r'^serverstatus/',include('serverStatus.urls')),
|
url(r'^serverstatus/',include('serverStatus.urls')),
|
||||||
@@ -41,4 +40,5 @@ urlpatterns = [
|
|||||||
url(r'^plugins/',include('pluginHolder.urls')),
|
url(r'^plugins/',include('pluginHolder.urls')),
|
||||||
url(r'^emailMarketing/', include('emailMarketing.urls')),
|
url(r'^emailMarketing/', include('emailMarketing.urls')),
|
||||||
url(r'^cloudAPI/', include('cloudAPI.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)
|
firstName="Cyber", lastName="Panel", acl=acl, token=token)
|
||||||
admin.save()
|
admin.save()
|
||||||
|
|
||||||
vers = version(currentVersion="1.7", build=6)
|
vers = version(currentVersion="1.7", build=7)
|
||||||
vers.save()
|
vers.save()
|
||||||
|
|
||||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
||||||
|
|||||||
@@ -666,9 +666,9 @@
|
|||||||
<script src="{% static 'managePHP/managePHP.js' %}"></script>
|
<script src="{% static 'managePHP/managePHP.js' %}"></script>
|
||||||
<script src="{% static 'baseTemplate/bootstrap-toggle.min.js' %}"></script>
|
<script src="{% static 'baseTemplate/bootstrap-toggle.min.js' %}"></script>
|
||||||
<script src="{% static 'firewall/firewall.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 'manageSSL/manageSSL.js' %}"></script>
|
||||||
<script src="{% static 'manageServices/manageServices.js' %}"></script>
|
<script src="{% static 'manageServices/manageServices.js' %}"></script>
|
||||||
|
<script src="{% static 'dockerManager/dockerManager.js' %}"></script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1093,3 +1093,78 @@ class CloudManager:
|
|||||||
return HttpResponse(finalData)
|
return HttpResponse(finalData)
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return self.ajaxPre(0, str(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)
|
return cm.applyMySQLChanges(request)
|
||||||
elif controller == 'restartMySQL':
|
elif controller == 'restartMySQL':
|
||||||
return cm.restartMySQL(request)
|
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:
|
else:
|
||||||
return cm.ajaxPre(0, 'This function is not available in your version of CyberPanel.')
|
return cm.ajaxPre(0, 'This function is not available in your version of CyberPanel.')
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
<div class="panel">
|
<div class="panel">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<h3 class="title-hero">
|
<h3 class="title-hero">
|
||||||
{% trans "Installed Images" %} <img id="imageLoading" src="/static/images/loading.gif" style="display: none;">
|
{% trans "Locally Available Images" %} <img id="imageLoading" src="/static/images/loading.gif" style="display: none;">
|
||||||
{{ test }}
|
|
||||||
</h3><br>
|
</h3><br>
|
||||||
|
|
||||||
<div class="example-box-wrapper">
|
<div class="example-box-wrapper">
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<div id="page-title">
|
<div id="page-title">
|
||||||
<h2 id="domainNamePage">{% trans "Manage Images" %}
|
<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>
|
</h2>
|
||||||
<p>{% trans "On this page you can manage docker images." %}</p>
|
<p>{% trans "On this page you can manage docker images." %}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="imageList">
|
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="imageList">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name (Installed)</th>
|
<th>Name (Locally Available)</th>
|
||||||
<th>Tags</th>
|
<th>Tags</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -4,14 +4,11 @@ from __future__ import unicode_literals
|
|||||||
from django.shortcuts import render,redirect
|
from django.shortcuts import render,redirect
|
||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
from loginSystem.views import loadLoginPage
|
from loginSystem.views import loadLoginPage
|
||||||
from django.http import HttpResponse
|
|
||||||
from plogical.container import ContainerManager
|
from plogical.container import ContainerManager
|
||||||
from dockerManager.pluginManager import pluginManager
|
from dockerManager.pluginManager import pluginManager
|
||||||
from decorators import preDockerRun
|
from decorators import preDockerRun
|
||||||
from plogical.acl import ACLManager
|
from plogical.acl import ACLManager
|
||||||
import json
|
import json
|
||||||
import requests
|
|
||||||
import docker
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|||||||
@@ -1345,9 +1345,9 @@ class FirewallManager:
|
|||||||
if fileName == 'categories.conf':
|
if fileName == 'categories.conf':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if fileName.endswith('dis'):
|
if fileName.endswith('bak'):
|
||||||
status = 0
|
status = 0
|
||||||
fileName = fileName.rstrip('.dis')
|
fileName = fileName.rstrip('.bak')
|
||||||
elif fileName.endswith('conf'):
|
elif fileName.endswith('conf'):
|
||||||
status = 1
|
status = 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -780,7 +780,7 @@ class preFlightsChecks:
|
|||||||
|
|
||||||
os.chdir(self.path)
|
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"
|
#command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz"
|
||||||
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
||||||
'CyberPanel Download',
|
'CyberPanel Download',
|
||||||
@@ -789,7 +789,7 @@ class preFlightsChecks:
|
|||||||
##
|
##
|
||||||
|
|
||||||
count = 0
|
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"
|
#command = "tar zxf CyberPanelTemp.tar.gz"
|
||||||
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]',
|
||||||
'Extract CyberPanel',1, 1, os.EX_OSERR)
|
'Extract CyberPanel',1, 1, os.EX_OSERR)
|
||||||
|
|||||||
@@ -5410,96 +5410,3 @@ msgstr "Web サイト "
|
|||||||
#: websiteFunctions/templates/websiteFunctions/suspendWebsite.html:73
|
#: websiteFunctions/templates/websiteFunctions/suspendWebsite.html:73
|
||||||
msgid "Successfully "
|
msgid "Successfully "
|
||||||
msgstr "成功しました "
|
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)
|
firstName="Cyber",lastName="Panel", acl=acl, token=token)
|
||||||
admin.save()
|
admin.save()
|
||||||
|
|
||||||
vers = version(currentVersion="1.7", build=6)
|
vers = version(currentVersion="1.7", build=7)
|
||||||
vers.save()
|
vers.save()
|
||||||
|
|
||||||
package = Package(admin=admin, packageName="Default", diskSpace=1000,
|
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 django.shortcuts import HttpResponse
|
||||||
from packages.models import Package
|
from packages.models import Package
|
||||||
from websiteFunctions.models import Websites, ChildDomains
|
from websiteFunctions.models import Websites, ChildDomains
|
||||||
from dockerManager.models import Containers
|
|
||||||
from dns.models import Domains
|
from dns.models import Domains
|
||||||
import json
|
import json
|
||||||
from subprocess import call, CalledProcessError
|
from subprocess import call, CalledProcessError
|
||||||
from shlex import split
|
from shlex import split
|
||||||
from CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
from CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||||
|
from dockerManager.models import Containers
|
||||||
|
|
||||||
class ACLManager:
|
class ACLManager:
|
||||||
|
|
||||||
@@ -364,73 +364,6 @@ class ACLManager:
|
|||||||
|
|
||||||
return websiteNames
|
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
|
@staticmethod
|
||||||
def findWebsiteObjects(currentACL, userID):
|
def findWebsiteObjects(currentACL, userID):
|
||||||
|
|
||||||
@@ -518,6 +451,72 @@ class ACLManager:
|
|||||||
logging.writeToFile(str(msg) + ' [ACLManager.executeCall]')
|
logging.writeToFile(str(msg) + ' [ACLManager.executeCall]')
|
||||||
return 0, str(msg)
|
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 sys
|
||||||
import django
|
import django
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
django.setup()
|
django.setup()
|
||||||
@@ -24,12 +25,13 @@ import docker
|
|||||||
import docker.utils
|
import docker.utils
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
# Use default socket to connect
|
# Use default socket to connect
|
||||||
class ContainerManager:
|
class ContainerManager:
|
||||||
def __init__(self, name = None):
|
def __init__(self, name=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def submitInstallDocker(self, userID = None, data = None):
|
def submitInstallDocker(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
if ACLManager.currentContextPermission(currentACL, 'createContainer') == 0:
|
if ACLManager.currentContextPermission(currentACL, 'createContainer') == 0:
|
||||||
@@ -51,7 +53,7 @@ class ContainerManager:
|
|||||||
cmd = shlex.split(command)
|
cmd = shlex.split(command)
|
||||||
res4 = subprocess.call(cmd)
|
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'}
|
data_ret = {'installDockerStatus': 1, 'error_message': 'None'}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
@@ -65,7 +67,7 @@ class ContainerManager:
|
|||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return HttpResponse(str(msg))
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
def createContainer(self, request = None, userID = None, data = None):
|
def createContainer(self, request=None, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
@@ -85,19 +87,19 @@ class ContainerManager:
|
|||||||
name = image
|
name = image
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||||
except docker.errors.ImageNotFound:
|
except docker.errors.ImageNotFound:
|
||||||
val = request.session['userID']
|
val = request.session['userID']
|
||||||
admin = Administrator.objects.get(pk=val)
|
admin = Administrator.objects.get(pk=val)
|
||||||
return render(request,'dockerManager/images.html',{"type":admin.type,
|
return render(request, 'dockerManager/images.html', {"type": admin.type,
|
||||||
'image':image,
|
'image': image,
|
||||||
'tag':tag})
|
'tag': tag})
|
||||||
|
|
||||||
envList = {};
|
envList = {};
|
||||||
if 'Env' in inspectImage['Config']:
|
if 'Env' in inspectImage['Config']:
|
||||||
for item in inspectImage['Config']['Env']:
|
for item in inspectImage['Config']['Env']:
|
||||||
if '=' in item:
|
if '=' in item:
|
||||||
splitedItem = item.split('=',1)
|
splitedItem = item.split('=', 1)
|
||||||
print splitedItem
|
print splitedItem
|
||||||
envList[splitedItem[0]] = splitedItem[1]
|
envList[splitedItem[0]] = splitedItem[1]
|
||||||
else:
|
else:
|
||||||
@@ -112,14 +114,15 @@ class ContainerManager:
|
|||||||
if image is None or image is '' or tag is None or tag is '':
|
if image is None or image is '' or tag is None or tag is '':
|
||||||
return redirect(loadImages)
|
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)
|
return render(request, 'dockerManager/runContainer.html', Data)
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return HttpResponse(str(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
|
name = self.name
|
||||||
|
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
@@ -168,14 +171,12 @@ class ContainerManager:
|
|||||||
data['cpuUsage'] = round(cpu_delta / system_delta * 100.0 * cpu_count, 3)
|
data['cpuUsage'] = round(cpu_delta / system_delta * 100.0 * cpu_count, 3)
|
||||||
else:
|
else:
|
||||||
data['memoryUsage'] = 0
|
data['memoryUsage'] = 0
|
||||||
data['cpuUsage'] = 0;
|
data['cpuUsage'] = 0
|
||||||
|
|
||||||
return render(request, 'dockerManager/viewContainer.html', data)
|
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:
|
try:
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
|
||||||
return ACLManager.loadError()
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
|
|
||||||
@@ -212,20 +213,20 @@ class ContainerManager:
|
|||||||
pagination.append('<li><a href="\#">' + str(i) + '</a></li>')
|
pagination.append('<li><a href="\#">' + str(i) + '</a></li>')
|
||||||
|
|
||||||
return render(request, 'dockerManager/listContainers.html', {"pagination": pagination,
|
return render(request, 'dockerManager/listContainers.html', {"pagination": pagination,
|
||||||
"unlistedContainers": unlistedContainers,
|
"unlistedContainers": unlistedContainers,
|
||||||
"adminNames": adminNames,
|
"adminNames": adminNames,
|
||||||
"showUnlistedContainer":showUnlistedContainer})
|
"showUnlistedContainer": showUnlistedContainer})
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return HttpResponse(str(msg))
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
def getContainerLogs(self, userID = None, data = None):
|
def getContainerLogs(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
|
|
||||||
# Check if container is registered in database or unlisted
|
# Check if container is registered in database or unlisted
|
||||||
if Containers.objects.filter(name=name).exists():
|
if Containers.objects.filter(name=name).exists():
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('containerLogStatus',0)
|
return ACLManager.loadErrorJson('containerLogStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -239,16 +240,16 @@ class ContainerManager:
|
|||||||
|
|
||||||
|
|
||||||
except BaseException, msg:
|
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)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def submitContainerCreation(self, userID = None, data = None):
|
def submitContainerCreation(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadErrorJson('createContainerStatus',0)
|
return ACLManager.loadErrorJson('createContainerStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -260,7 +261,7 @@ class ContainerManager:
|
|||||||
memory = data['memory']
|
memory = data['memory']
|
||||||
envList = data['envList']
|
envList = data['envList']
|
||||||
|
|
||||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||||
portConfig = {}
|
portConfig = {}
|
||||||
|
|
||||||
# Formatting envList for usage
|
# Formatting envList for usage
|
||||||
@@ -281,19 +282,19 @@ class ContainerManager:
|
|||||||
## Create Configurations
|
## Create Configurations
|
||||||
admin = Administrator.objects.get(userName=dockerOwner)
|
admin = Administrator.objects.get(userName=dockerOwner)
|
||||||
|
|
||||||
containerArgs = {'image':image+":"+tag,
|
containerArgs = {'image': image + ":" + tag,
|
||||||
'detach':True,
|
'detach': True,
|
||||||
'name':name,
|
'name': name,
|
||||||
'ports':portConfig,
|
'ports': portConfig,
|
||||||
'publish_all_ports': True,
|
'publish_all_ports': True,
|
||||||
'environment':envDict}
|
'environment': envDict}
|
||||||
|
|
||||||
containerArgs['mem_limit'] = memory * 1048576; # Converts MB to bytes ( 0 * x = 0 for unlimited memory)
|
containerArgs['mem_limit'] = memory * 1048576; # Converts MB to bytes ( 0 * x = 0 for unlimited memory)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
container = client.containers.create(**containerArgs)
|
container = client.containers.create(**containerArgs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if "port is already allocated" in err: # We need to delete container if port is not available
|
if "port is already allocated" in err: # We need to delete container if port is not available
|
||||||
print "Deleting container"
|
print "Deleting container"
|
||||||
container.remove(force=True)
|
container.remove(force=True)
|
||||||
data_ret = {'createContainerStatus': 0, 'error_message': str(err)}
|
data_ret = {'createContainerStatus': 0, 'error_message': str(err)}
|
||||||
@@ -301,13 +302,13 @@ class ContainerManager:
|
|||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
con = Containers(admin=admin,
|
con = Containers(admin=admin,
|
||||||
name=name,
|
name=name,
|
||||||
tag=tag,
|
tag=tag,
|
||||||
image=image,
|
image=image,
|
||||||
memory=memory,
|
memory=memory,
|
||||||
ports=json.dumps(portConfig),
|
ports=json.dumps(portConfig),
|
||||||
env=json.dumps(envDict),
|
env=json.dumps(envDict),
|
||||||
cid=container.id)
|
cid=container.id)
|
||||||
|
|
||||||
con.save()
|
con.save()
|
||||||
|
|
||||||
@@ -321,12 +322,12 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def submitInstallImage(self, userID = None, data = None):
|
def submitInstallImage(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadErrorJson('installImageStatus',0)
|
return ACLManager.loadErrorJson('installImageStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -335,7 +336,7 @@ class ContainerManager:
|
|||||||
tag = data['tag']
|
tag = data['tag']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inspectImage = dockerAPI.inspect_image(image+":"+tag)
|
inspectImage = dockerAPI.inspect_image(image + ":" + tag)
|
||||||
data_ret = {'installImageStatus': 0, 'error_message': "Image already installed"}
|
data_ret = {'installImageStatus': 0, 'error_message': "Image already installed"}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
@@ -350,7 +351,6 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|
||||||
data_ret = {'installImageStatus': 1, 'error_message': "None"}
|
data_ret = {'installImageStatus': 1, 'error_message': "None"}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
@@ -361,7 +361,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def submitContainerDeletion(self, userID = None, data = None, called = False):
|
def submitContainerDeletion(self, userID=None, data=None, called=False):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
# Check if container is registered in database or unlisted
|
# Check if container is registered in database or unlisted
|
||||||
@@ -397,13 +397,13 @@ class ContainerManager:
|
|||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
container.stop() # Stop container
|
container.stop() # Stop container
|
||||||
container.kill() # INCASE graceful stop doesn't work
|
container.kill() # INCASE graceful stop doesn't work
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
container.remove() # Finally remove container
|
container.remove() # Finally remove container
|
||||||
except docker.errors.APIError as err:
|
except docker.errors.APIError as err:
|
||||||
data_ret = {'delContainerStatus': 0, 'error_message': str(err)}
|
data_ret = {'delContainerStatus': 0, 'error_message': str(err)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -434,11 +434,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def getContainerList(self, userID = None, data = None):
|
def getContainerList(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadErrorJson('listContainerStatus',0)
|
return ACLManager.loadErrorJson('listContainerStatus', 0)
|
||||||
|
|
||||||
currentACL = ACLManager.loadedACL(userID)
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
pageNumber = int(data['page'])
|
pageNumber = int(data['page'])
|
||||||
@@ -464,7 +464,7 @@ class ContainerManager:
|
|||||||
checker = 0
|
checker = 0
|
||||||
|
|
||||||
for items in containers:
|
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:
|
if checker == 0:
|
||||||
json_data = json_data + json.dumps(dic)
|
json_data = json_data + json.dumps(dic)
|
||||||
@@ -476,12 +476,12 @@ class ContainerManager:
|
|||||||
|
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def doContainerAction(self, userID = None, data = None):
|
def doContainerAction(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
name = data['name']
|
name = data['name']
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('containerActionStatus',0)
|
return ACLManager.loadErrorJson('containerActionStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -514,7 +514,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
time.sleep(3) # Wait 3 seconds for container to finish starting/stopping/restarting
|
time.sleep(3) # Wait 3 seconds for container to finish starting/stopping/restarting
|
||||||
status = container.status
|
status = container.status
|
||||||
data_ret = {'containerActionStatus': 1, 'error_message': 'None', 'status': status}
|
data_ret = {'containerActionStatus': 1, 'error_message': 'None', 'status': status}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -525,11 +525,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def getContainerStatus(self, userID = None, data = None):
|
def getContainerStatus(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('containerStatus',0)
|
return ACLManager.loadErrorJson('containerStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -555,11 +555,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def exportContainer(self, request = None, userID = None, data = None):
|
def exportContainer(self, request=None, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = request.GET.get('name')
|
name = request.GET.get('name')
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('containerStatus',0)
|
return ACLManager.loadErrorJson('containerStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -575,9 +575,9 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
eFile = container.export() # Export with default chunk size
|
eFile = container.export() # Export with default chunk size
|
||||||
response = HttpResponse(eFile, content_type='application/force-download')
|
response = HttpResponse(eFile, content_type='application/force-download')
|
||||||
response['Content-Disposition'] = 'attachment; filename="'+ name +'.tar"'
|
response['Content-Disposition'] = 'attachment; filename="' + name + '.tar"'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
@@ -585,11 +585,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def getContainerTop(self, userID = None, data = None):
|
def getContainerTop(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('containerTopStatus',0)
|
return ACLManager.loadErrorJson('containerTopStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -612,7 +612,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
@@ -621,12 +621,12 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def assignContainer(self, userID = None, data = None):
|
def assignContainer(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
# Todo: add check only for super user i.e. main admin
|
# Todo: add check only for super user i.e. main admin
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadErrorJson('assignContainerStatus',0)
|
return ACLManager.loadErrorJson('assignContainerStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -648,8 +648,8 @@ class ContainerManager:
|
|||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
con = Containers(admin=admin,
|
con = Containers(admin=admin,
|
||||||
name=name,
|
name=name,
|
||||||
cid=container.id)
|
cid=container.id)
|
||||||
|
|
||||||
con.save()
|
con.save()
|
||||||
|
|
||||||
@@ -662,11 +662,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def searchImage(self, userID = None, data = None):
|
def searchImage(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
return ACLManager.loadErrorJson('searchImageStatus',0)
|
return ACLManager.loadErrorJson('searchImageStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -691,8 +691,7 @@ class ContainerManager:
|
|||||||
else:
|
else:
|
||||||
image['name2'] = image['name']
|
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)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
@@ -701,7 +700,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def images(self, request = None, userID = None, data = None):
|
def images(self, request=None, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
@@ -737,17 +736,17 @@ class ContainerManager:
|
|||||||
images[name]['tags'].extend(tags)
|
images[name]['tags'].extend(tags)
|
||||||
else:
|
else:
|
||||||
names.append(name)
|
names.append(name)
|
||||||
images[name] = {"name":name,
|
images[name] = {"name": name,
|
||||||
"name2":name2,
|
"name2": name2,
|
||||||
"tags":tags}
|
"tags": tags}
|
||||||
print "======"
|
print "======"
|
||||||
print images
|
print images
|
||||||
return render(request, 'dockerManager/images.html', {"images":images, "test":'asds'})
|
return render(request, 'dockerManager/images.html', {"images": images, "test": ''})
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return HttpResponse(str(msg))
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
def manageImages(self, request = None, userID = None, data = None):
|
def manageImages(self, request=None, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
@@ -768,14 +767,14 @@ class ContainerManager:
|
|||||||
else:
|
else:
|
||||||
names.append(name)
|
names.append(name)
|
||||||
tags = []
|
tags = []
|
||||||
images[name] = {"name":name,
|
images[name] = {"name": name,
|
||||||
"tags":image.tags}
|
"tags": image.tags}
|
||||||
return render(request, 'dockerManager/manageImages.html', {"images":images})
|
return render(request, 'dockerManager/manageImages.html', {"images": images})
|
||||||
|
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return HttpResponse(str(msg))
|
return HttpResponse(str(msg))
|
||||||
|
|
||||||
def getImageHistory(self, userID = None, data = None):
|
def getImageHistory(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
name = data['name']
|
name = data['name']
|
||||||
@@ -797,9 +796,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
@@ -808,7 +805,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def removeImage(self, userID = None, data = None):
|
def removeImage(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
if admin.acl.adminStatus != 1:
|
if admin.acl.adminStatus != 1:
|
||||||
@@ -833,8 +830,6 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data_ret = {'removeImageStatus': 1, 'error_message': 'None'}
|
data_ret = {'removeImageStatus': 1, 'error_message': 'None'}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
@@ -844,12 +839,12 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
# Internal function for recreating containers
|
# Internal function for recreating containers
|
||||||
|
|
||||||
def doRecreateContainer(self, userID, data, con):
|
def doRecreateContainer(self, userID, data, con):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
unlisted = data['unlisted'] # Pass this as 1 if image is not known for container
|
unlisted = data['unlisted'] # Pass this as 1 if image is not known for container
|
||||||
image = data['image']
|
image = data['image']
|
||||||
tag = data['tag']
|
tag = data['tag']
|
||||||
env = data['env']
|
env = data['env']
|
||||||
@@ -864,13 +859,13 @@ class ContainerManager:
|
|||||||
return delStatus
|
return delStatus
|
||||||
|
|
||||||
print env
|
print env
|
||||||
containerArgs = {'image':image+":"+tag,
|
containerArgs = {'image': image + ":" + tag,
|
||||||
'detach':True,
|
'detach': True,
|
||||||
'name':name,
|
'name': name,
|
||||||
'ports':port,
|
'ports': port,
|
||||||
'environment':env,
|
'environment': env,
|
||||||
'publish_all_ports': True,
|
'publish_all_ports': True,
|
||||||
'mem_limit': memory * 1048576}
|
'mem_limit': memory * 1048576}
|
||||||
|
|
||||||
if con.startOnReboot == 1:
|
if con.startOnReboot == 1:
|
||||||
containerArgs['restart_policy'] = {"Name": "always"}
|
containerArgs['restart_policy'] = {"Name": "always"}
|
||||||
@@ -883,11 +878,11 @@ class ContainerManager:
|
|||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
return str(msg)
|
return str(msg)
|
||||||
|
|
||||||
def saveContainerSettings(self, userID = None, data = None):
|
def saveContainerSettings(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('saveSettingsStatus',0)
|
return ACLManager.loadErrorJson('saveSettingsStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -916,7 +911,7 @@ class ContainerManager:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
container.update(mem_limit=memory * 1048576,
|
container.update(mem_limit=memory * 1048576,
|
||||||
restart_policy = rPolicy)
|
restart_policy=rPolicy)
|
||||||
except docker.errors.APIError as err:
|
except docker.errors.APIError as err:
|
||||||
data_ret = {'saveSettingsStatus': 0, 'error_message': str(err)}
|
data_ret = {'saveSettingsStatus': 0, 'error_message': str(err)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
@@ -941,7 +936,8 @@ class ContainerManager:
|
|||||||
'image': con.image,
|
'image': con.image,
|
||||||
'tag': con.tag,
|
'tag': con.tag,
|
||||||
'env': envDict,
|
'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
|
'memory': con.memory
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -963,11 +959,11 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def recreateContainer(self, userID = None, data = None):
|
def recreateContainer(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||||
return ACLManager.loadErrorJson('saveSettingsStatus',0)
|
return ACLManager.loadErrorJson('saveSettingsStatus', 0)
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
dockerAPI = docker.APIClient()
|
dockerAPI = docker.APIClient()
|
||||||
@@ -992,7 +988,8 @@ class ContainerManager:
|
|||||||
'image': con.image,
|
'image': con.image,
|
||||||
'tag': con.tag,
|
'tag': con.tag,
|
||||||
'env': json.loads(con.env),
|
'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
|
'memory': con.memory
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1011,7 +1008,7 @@ class ContainerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
def getTags(self, userID = None, data = None):
|
def getTags(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
admin = Administrator.objects.get(pk=userID)
|
admin = Administrator.objects.get(pk=userID)
|
||||||
@@ -1027,13 +1024,14 @@ class ContainerManager:
|
|||||||
image2 = "library/" + image
|
image2 = "library/" + image
|
||||||
|
|
||||||
print 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 = []
|
tagList = []
|
||||||
for tag in registryData['results']:
|
for tag in registryData['results']:
|
||||||
tagList.append(tag['name'])
|
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)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
|
|||||||
@@ -498,17 +498,26 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
|||||||
def disableRuleFile(fileName, packName):
|
def disableRuleFile(fileName, packName):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||||
confData = open(confFile).readlines()
|
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||||
conf = open(confFile, 'w')
|
confData = open(confFile).readlines()
|
||||||
|
conf = open(confFile, 'w')
|
||||||
|
|
||||||
for items in confData:
|
for items in confData:
|
||||||
if items.find('modsec/'+packName) > -1 and items.find(fileName) > -1:
|
if items.find('modsec/'+packName) > -1 and items.find(fileName) > -1:
|
||||||
conf.write("#" + items)
|
conf.write("#" + items)
|
||||||
else:
|
else:
|
||||||
conf.writelines(items)
|
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"
|
print "1,None"
|
||||||
|
|
||||||
@@ -521,17 +530,25 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/owasp/rules/RESPONSE-999-EXCL
|
|||||||
def enableRuleFile(fileName, packName):
|
def enableRuleFile(fileName, packName):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
||||||
confData = open(confFile).readlines()
|
confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
|
||||||
conf = open(confFile, 'w')
|
confData = open(confFile).readlines()
|
||||||
|
conf = open(confFile, 'w')
|
||||||
|
|
||||||
for items in confData:
|
for items in confData:
|
||||||
if items.find('modsec/' + packName) > -1 and items.find(fileName) > -1:
|
if items.find('modsec/' + packName) > -1 and items.find(fileName) > -1:
|
||||||
conf.write(items.lstrip('#'))
|
conf.write(items.lstrip('#'))
|
||||||
else:
|
else:
|
||||||
conf.writelines(items)
|
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"
|
print "1,None"
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,37 @@ import MySQLdb as mysql
|
|||||||
import json
|
import json
|
||||||
from random import randint
|
from random import randint
|
||||||
from plogical.processUtilities import ProcessUtilities
|
from plogical.processUtilities import ProcessUtilities
|
||||||
|
import MySQLdb.cursors as cursors
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
class mysqlUtilities:
|
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
|
@staticmethod
|
||||||
def setupConnection():
|
def setupConnection():
|
||||||
try:
|
try:
|
||||||
@@ -25,7 +53,7 @@ class mysqlUtilities:
|
|||||||
password = data.split('\n', 1)[0]
|
password = data.split('\n', 1)[0]
|
||||||
password = password.strip('\n').strip('\r')
|
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()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
return conn, cursor
|
return conn, cursor
|
||||||
@@ -356,3 +384,226 @@ class mysqlUtilities:
|
|||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
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
|
configobj==4.7.2
|
||||||
cryptography==2.2.2
|
cryptography==2.2.2
|
||||||
decorator==3.4.0
|
decorator==3.4.0
|
||||||
|
docker==3.6.0
|
||||||
|
docker-pycreds==0.4.0
|
||||||
Django==1.11
|
Django==1.11
|
||||||
docutils==0.14
|
docutils==0.14
|
||||||
enum34==1.1.6
|
enum34==1.1.6
|
||||||
|
|||||||
Reference in New Issue
Block a user