mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
port docker manager to ubuntu
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,48 +3,64 @@
|
||||
{% block title %}{% trans "Install Docker - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Install Docker" %}</h2>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-controller="installDocker" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Install Docker" %} <img ng-hide="installDockerStatus" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
{% if conErr == 1%}
|
||||
|
||||
{% if status == 1 %}
|
||||
{% trans "Unable to connect to docker daemon, please try restarting docker from service page" %}
|
||||
{% else %}
|
||||
{% trans "You do not have sufficient permissions to access this page" %}
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p>{% trans "Docker is currently not installed on this server. To manage containers, you must first install it." %}</p>
|
||||
<br>
|
||||
{% if status == 1 %}
|
||||
<button class="btn btn-primary" ng-click="installDocker()">Install Docker</button>
|
||||
{% else %}
|
||||
{% trans "You do not have permissions to install Docker. Please contact your system administrator" %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Install Docker" %}</h2>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-controller="installDocker" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Install Docker" %} <img ng-hide="installDockerStatus"
|
||||
src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
{% if conErr == 1 %}
|
||||
|
||||
{% if status == 1 %}
|
||||
{% trans "Unable to connect to docker daemon, please try restarting docker from service page" %}
|
||||
{% else %}
|
||||
{% trans "You do not have sufficient permissions to access this page" %}
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p>{% trans "Docker is currently not installed on this server. To manage containers, you must first install it." %}</p>
|
||||
<!------ LSWS Switch box ----------------->
|
||||
|
||||
<div style="margin-top: 2%" ng-hide="installBoxGen" class="col-md-12">
|
||||
|
||||
<form action="/" id="" class="form-horizontal bordered-row">
|
||||
<div class="form-group">
|
||||
<div style="margin-top: 2%;" class="col-sm-12">
|
||||
<textarea ng-model="requestData" rows="15"
|
||||
class="form-control">{{ requestData }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<!----- LSWS Switch box ----------------->
|
||||
<br>
|
||||
{% if status == 1 %}
|
||||
<button ng-hide="dockerInstallBTN" class="btn btn-primary" ng-click="installDocker()">Install Docker</button>
|
||||
{% else %}
|
||||
{% trans "You do not have permissions to install Docker. Please contact your system administrator" %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render,redirect
|
||||
from django.shortcuts import render, redirect, HttpResponse
|
||||
from loginSystem.models import Administrator
|
||||
from loginSystem.views import loadLoginPage
|
||||
from plogical.container import ContainerManager
|
||||
from dockerManager.pluginManager import pluginManager
|
||||
from decorators import preDockerRun
|
||||
from plogical.acl import ACLManager
|
||||
import json
|
||||
@@ -22,7 +21,7 @@ def dockerPermission(request, userID, context):
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
else:
|
||||
return None
|
||||
return 0
|
||||
|
||||
@preDockerRun
|
||||
def loadDockerHome(request):
|
||||
@@ -41,22 +40,18 @@ def installDocker(request):
|
||||
userID = request.session['userID']
|
||||
perm = dockerPermission(request, userID, 'loadDockerHome')
|
||||
if perm: return perm
|
||||
result = pluginManager.preDockerInstallation(request) # Later change to preInstallInstallation
|
||||
|
||||
if result != 200:
|
||||
return result
|
||||
cm = ContainerManager(userID, 'submitInstallDocker')
|
||||
cm.start()
|
||||
|
||||
cm = ContainerManager()
|
||||
coreResult = cm.submitInstallDocker(userID, json.loads(request.body))
|
||||
data_ret = {'status': 1, 'error_message': 'None'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
result = pluginManager.postDockerInstallation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
return coreResult
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@preDockerRun
|
||||
def installImage(request):
|
||||
@@ -332,6 +327,7 @@ def manageImages(request):
|
||||
def getImageHistory(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
perm = dockerPermission(request, userID, 'loadDockerHome')
|
||||
if perm: return perm
|
||||
|
||||
|
||||
@@ -780,8 +780,8 @@ class preFlightsChecks:
|
||||
|
||||
os.chdir(self.path)
|
||||
|
||||
command = "wget http://cyberpanel.sh/CyberPanel.1.7.7.tar.gz"
|
||||
#command = "wget http://cyberpanel.sh/CyberPanelTemp.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',
|
||||
1, 1, os.EX_OSERR)
|
||||
@@ -789,8 +789,8 @@ class preFlightsChecks:
|
||||
##
|
||||
|
||||
count = 0
|
||||
command = "tar zxf CyberPanel.1.7.7.tar.gz"
|
||||
#command = "tar zxf CyberPanelTemp.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)
|
||||
|
||||
@@ -2667,27 +2667,15 @@ class preFlightsChecks:
|
||||
return 0
|
||||
|
||||
def installPYDNS(self):
|
||||
try:
|
||||
count = 0
|
||||
while (1):
|
||||
command = "pip install pydns"
|
||||
|
||||
res = subprocess.call(shlex.split(command))
|
||||
|
||||
if preFlightsChecks.resFailed(self.distro, res):
|
||||
count = count + 1
|
||||
preFlightsChecks.stdOut(
|
||||
"Trying to install pydns, trying again, try number: " + str(count))
|
||||
if count == 3:
|
||||
logging.InstallLog.writeToFile(
|
||||
"Failed to install pydns! [installTLDExtract]")
|
||||
else:
|
||||
logging.InstallLog.writeToFile("pydns successfully installed! [pip]")
|
||||
preFlightsChecks.stdOut("pydns successfully installed! [pip]")
|
||||
break
|
||||
except OSError, msg:
|
||||
logging.InstallLog.writeToFile(str(msg) + " [installTLDExtract]")
|
||||
return 0
|
||||
command = "pip install pydns"
|
||||
preFlightsChecks.call(command, self.distro, '[installPYDNS]',
|
||||
'Install PYDNS',
|
||||
1, 0, os.EX_OSERR)
|
||||
def installDockerPY(self):
|
||||
command = "pip install docker"
|
||||
preFlightsChecks.call(command, self.distro, '[installDockerPY]',
|
||||
'Install DockerPY',
|
||||
1, 0, os.EX_OSERR)
|
||||
|
||||
def installOpenDKIM(self):
|
||||
try:
|
||||
@@ -3289,6 +3277,7 @@ def main():
|
||||
checks.installCertBot()
|
||||
checks.test_Requests()
|
||||
checks.installPYDNS()
|
||||
checks.installDockerPY()
|
||||
checks.download_install_CyberPanel(installCyberPanel.InstallCyberPanel.mysqlPassword, mysql)
|
||||
checks.setupCLI()
|
||||
checks.setup_cron()
|
||||
|
||||
@@ -453,7 +453,6 @@ class ACLManager:
|
||||
|
||||
@staticmethod
|
||||
def checkContainerOwnership(name, userID):
|
||||
return 1
|
||||
try:
|
||||
container = Containers.objects.get(name=name)
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
@@ -513,7 +512,7 @@ class ACLManager:
|
||||
for items in admins:
|
||||
cons = items.containers_set.all()
|
||||
for con in cons:
|
||||
containerList.append(web)
|
||||
containerList.append(con)
|
||||
|
||||
return containerList
|
||||
|
||||
|
||||
@@ -18,54 +18,88 @@ import subprocess
|
||||
import shlex
|
||||
import time
|
||||
from dockerManager.models import Containers
|
||||
from django.http import StreamingHttpResponse
|
||||
from wsgiref.util import FileWrapper
|
||||
from math import ceil
|
||||
import docker
|
||||
import docker.utils
|
||||
import requests
|
||||
from processUtilities import ProcessUtilities
|
||||
from serverStatus.serverStatusUtil import ServerStatusUtil
|
||||
import threading as multi
|
||||
|
||||
|
||||
# Use default socket to connect
|
||||
class ContainerManager:
|
||||
def __init__(self, name=None):
|
||||
self.name = name
|
||||
class ContainerManager(multi.Thread):
|
||||
|
||||
def submitInstallDocker(self, userID=None, data=None):
|
||||
def __init__(self, name=None, function=None):
|
||||
multi.Thread.__init__(self)
|
||||
self.name = name
|
||||
self.function = function
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if self.function == 'submitInstallDocker':
|
||||
self.submitInstallDocker()
|
||||
elif self.function == 'restartGunicorn':
|
||||
command = 'sudo systemctl restart gunicorn.socket'
|
||||
ProcessUtilities.executioner(command)
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile( str(msg) + ' [ContainerManager.run]')
|
||||
|
||||
@staticmethod
|
||||
def executioner(command, statusFile):
|
||||
try:
|
||||
res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile)
|
||||
if res == 1:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return 0
|
||||
|
||||
def submitInstallDocker(self):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(self.name)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'createContainer') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
command = 'sudo yum install -y docker'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Starting Docker Installation..\n", 1)
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = 'sudo yum install -y docker'
|
||||
else:
|
||||
command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker.io'
|
||||
|
||||
if not ServerStatusUtil.executioner(command, statusFile):
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Failed to install Docker. [404]\n", 1)
|
||||
return 0
|
||||
|
||||
|
||||
command = 'sudo groupadd docker'
|
||||
cmd = shlex.split(command)
|
||||
res2 = subprocess.call(cmd)
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
command = 'sudo usermod -aG docker cyberpanel'
|
||||
cmd = shlex.split(command)
|
||||
res3 = subprocess.call(cmd)
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
command = 'sudo service docker start'
|
||||
cmd = shlex.split(command)
|
||||
res4 = subprocess.call(cmd)
|
||||
command = 'sudo systemctl enable docker'
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
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)
|
||||
else:
|
||||
data_ret = {'installDockerStatus': 0, 'error_message': 'Failed to install. Manual install required.'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
command = 'sudo systemctl start docker'
|
||||
ServerStatusUtil.executioner(command, statusFile)
|
||||
|
||||
return HttpResponse(res)
|
||||
cm = ContainerManager(self.name, 'restartGunicorn')
|
||||
cm.start()
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
||||
"Docker successfully installed.[200]\n", 1)
|
||||
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
|
||||
|
||||
def createContainer(self, request=None, userID=None, data=None):
|
||||
try:
|
||||
@@ -779,9 +813,6 @@ class ContainerManager:
|
||||
|
||||
name = data['name']
|
||||
|
||||
if ACLManager.checkContainerOwnership(name, userID) != 1:
|
||||
return ACLManager.loadError()
|
||||
|
||||
client = docker.from_env()
|
||||
dockerAPI = docker.APIClient()
|
||||
|
||||
@@ -808,6 +839,7 @@ class ContainerManager:
|
||||
def removeImage(self, userID=None, data=None):
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if admin.acl.adminStatus != 1:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ class modSec:
|
||||
|
||||
mailUtilities.checkHome()
|
||||
|
||||
command = 'sudo yum install ols-modsecurity -y'
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = 'sudo yum install ols-modsecurity -y'
|
||||
else:
|
||||
command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install ols-modsecurity -y'
|
||||
|
||||
cmd = shlex.split(command)
|
||||
|
||||
|
||||
@@ -599,6 +599,40 @@ WantedBy=multi-user.target"""
|
||||
except:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def dockerMigrations():
|
||||
try:
|
||||
connection, cursor = Upgrade.setupConnection('cyberpanel')
|
||||
|
||||
|
||||
query = """CREATE TABLE `dockerManager_containers` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`cid` varchar(64) NOT NULL,
|
||||
`image` varchar(50) NOT NULL,
|
||||
`tag` varchar(50) NOT NULL,
|
||||
`memory` int(11) NOT NULL,
|
||||
`ports` longtext NOT NULL,
|
||||
`env` longtext NOT NULL,
|
||||
`startOnReboot` int(11) NOT NULL,
|
||||
`admin_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`),
|
||||
KEY `dockerManager_contai_admin_id_58fb62b7_fk_loginSyst` (`admin_id`),
|
||||
CONSTRAINT `dockerManager_contai_admin_id_58fb62b7_fk_loginSyst` FOREIGN KEY (`admin_id`) REFERENCES `loginSystem_administrator` (`id`)
|
||||
)"""
|
||||
try:
|
||||
cursor.execute(query)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
connection.close()
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def enableServices():
|
||||
try:
|
||||
@@ -854,6 +888,7 @@ WantedBy=multi-user.target"""
|
||||
|
||||
Upgrade.mailServerMigrations()
|
||||
Upgrade.emailMarketingMigrationsa()
|
||||
Upgrade.dockerMigrations()
|
||||
|
||||
##
|
||||
|
||||
|
||||
BIN
static/images/docker.png
Normal file
BIN
static/images/docker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@@ -394,6 +394,7 @@ app.controller('servicesManager', function ($scope, $http) {
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
console.log(response.data)
|
||||
|
||||
if (response.data.status.litespeed) {
|
||||
$scope.olsStatus = "Running";
|
||||
@@ -409,8 +410,18 @@ app.controller('servicesManager', function ($scope, $http) {
|
||||
$scope.olsStop = false;
|
||||
}
|
||||
|
||||
// Update SQL stats
|
||||
if (response.data.status.docker) {
|
||||
$scope.dockerStatus = "Running";
|
||||
$scope.dockerStart = false;
|
||||
$scope.dockerStop = true;
|
||||
}
|
||||
else {
|
||||
$scope.dockerStatus = "Stopped";
|
||||
$scope.dockerStart = true;
|
||||
$scope.dockerStop = false;
|
||||
}
|
||||
|
||||
// Update SQL stats
|
||||
if (response.data.status.mysql) {
|
||||
$scope.sqlStatus = "Running";
|
||||
$scope.sqlStats = true;
|
||||
@@ -468,7 +479,7 @@ app.controller('servicesManager', function ($scope, $http) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
getServiceStatus();
|
||||
|
||||
$scope.serviceAction = function (serviceName, action) {
|
||||
|
||||
Reference in New Issue
Block a user