mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-08-21 07:02:26 +02:00
Since version 7.7.0, we recommend yours update python to 3.12. [+] Using nginx technology to load static files improves access speed [+] Refactor homepage, website, FTP, and database using vue3 [+] Table loading changed to skeleton screen [+] Add Website statistics-v2 professional plug-in [+] Add Home page - top 5 resource occupancy [+] Add protection for Files management (requires Tamper-proof for Enterprise 3.7) [+] Website, FTP, Databases page add program status [+] Add FTP log analysis (only supports Centos) [+] Add password-free login to phpMyAdmin [+] Add Proxy Project in Website (Supported when web service uses Nginx) [+] Add WP Toolkit (Pro version only) [+] Redesigned Docker module [+] Add WP Toolkit Protection [+] Add WP Toolkit Backup and Restore [+] Add WP Toolkit Migrated [+] Add WP Toolkit Clone site (supports new domain and subdomain) [+] Add WP Toolkit Create site from backup of other panel [+] Add WP Toolkit support for Cron automatic backup (only save Local disk) [+] Add WP Toolkit operation log [+] Add Integrity check for WP Toolkit [+] Add WP Toolkit plug-in management and themes management [*] Optimize phpMyAdmin formula access method [*] Optimize Home page PHP display problem [*] Optimize jump to the login interface after the login expires [*] Optimize automatic renewal of SSL at some times [*] Optimize Let's Encrypt to increase application success rate [-] Fix Logs Audit cannot be opened [-] Fix apache URL rewrite issue [-] Fix phpmyadmin installation problem [-] Fix the problem that some servers cannot install software [-] Fix upload file error [-] Fix left menu hiding problem [-] Fix aaPanel Mobile QR code display problem [-] Fix problem that third-party plug-ins are not displayed in the App Store [-] Fix issue where the menu bar is blank when opening new tabs [-] Fixed panel not being accessible in some cases [-] Fix the issue where Curl warning caused the inability to apply for SSL [-] Fix Quota issues for Website, FTP, Databases [-] Fix file interface display problem on mobile terminal
118 lines
4.4 KiB
Python
118 lines
4.4 KiB
Python
# coding: utf-8
|
||
# -------------------------------------------------------------------
|
||
# aaPanel
|
||
# -------------------------------------------------------------------
|
||
# Copyright (c) 2015-2099 aaPanel(www.aapanel.com) All rights reserved.
|
||
# -------------------------------------------------------------------
|
||
# Author: wzz <wzz@aapanel.com>
|
||
# -------------------------------------------------------------------
|
||
|
||
# ------------------------------
|
||
# Docker模型
|
||
# ------------------------------
|
||
import public, os
|
||
from btdockerModelV2 import dk_public as dp
|
||
|
||
|
||
class dockerBase(object):
|
||
|
||
def __init__(self):
|
||
# self._db_path = "/www/server/panel/data/db/docker.db"
|
||
self._db_path = "/www/server/panel/data/docker.db"
|
||
self._backup_log = '/tmp/backup.log'
|
||
self._log_path = '/tmp/dockertmp.log'
|
||
self._rCmd_log = '/tmp/dockerRun.log'
|
||
self._url = "unix:///var/run/docker.sock"
|
||
self.compose_path = "{}/data/compose".format(public.get_panel_path())
|
||
self.aes_key = "btdockerModel_QWERAS"
|
||
self.moinitor_lock = "/tmp/bt_docker_monitor.lock"
|
||
|
||
def get_ws_log(self, get):
|
||
"""
|
||
获取日志,websocket
|
||
@param get:
|
||
@return:
|
||
"""
|
||
if not hasattr(get, "_ws"):
|
||
return True
|
||
|
||
import time
|
||
sum = 0
|
||
|
||
with open(get._log_path, "r") as file:
|
||
position = file.tell()
|
||
get._ws.send("{}\r\n".format(get.wsLogTitle))
|
||
|
||
while True:
|
||
current_position = file.tell()
|
||
line = file.readline()
|
||
if current_position > position:
|
||
file.seek(position)
|
||
new_content = file.read(current_position - position)
|
||
if "nohup" not in new_content:
|
||
for i in new_content.split('\n'):
|
||
if i == "": continue
|
||
get._ws.send(i.strip("\n") + "\r\n")
|
||
|
||
position = current_position
|
||
|
||
if "bt_successful" in line:
|
||
get._ws.send("bt_successful\r\n")
|
||
del get._ws
|
||
break
|
||
elif "bt_failed" in line:
|
||
get._ws.send("bt_failed\r\n")
|
||
del get._ws
|
||
break
|
||
|
||
if sum > 0:
|
||
sum = 0
|
||
else:
|
||
sum += 1
|
||
|
||
if sum >= 6000:
|
||
get._ws.send("\r\nNo response for more than 10 minutes!\r\n")
|
||
break
|
||
|
||
time.sleep(0.1)
|
||
|
||
return True
|
||
|
||
# 命令行创建 拉取容器
|
||
def run_cmd(self, get):
|
||
"""
|
||
命令行创建运行容器(docker run / docker pull),需要做危险命令校验,存在危险命令则不执行
|
||
@param get:
|
||
@return:
|
||
"""
|
||
import re
|
||
if not hasattr(get, 'cmd'):
|
||
return public.return_message(-1, 0, _("Please pass in cmd"))
|
||
|
||
if "docker run" not in get.cmd and "docker pull" not in get.cmd:
|
||
return public.return_message(-1, 0, _('Only docker run or docker pull commands can be executed'))
|
||
|
||
danger_cmd = ['rm', 'rmi', 'kill', 'stop', 'pause', 'unpause', 'restart', 'update', 'exec', 'init',
|
||
'shutdown', 'reboot', 'chmod', 'chown', 'dd', 'fdisk', 'killall', 'mkfs', 'mkswap', 'mount',
|
||
'swapoff', 'swapon', 'umount', 'userdel', 'usermod', 'passwd', 'groupadd', 'groupdel',
|
||
'groupmod', 'chpasswd', 'chage', 'usermod', 'useradd', 'userdel', 'pkill']
|
||
|
||
danger_symbol = ['&', '&&', '||', '|', ';']
|
||
|
||
for d in danger_cmd:
|
||
if get.cmd.startswith(d) or re.search(r'\s{}\s'.format(d), get.cmd):
|
||
return public.return_message(-1, 0, _( 'Dangerous command exists: [{}], execution is not allowed!'.format(d)))
|
||
|
||
for d in danger_symbol:
|
||
if d in get.cmd:
|
||
return public.return_message(-1, 0, _( 'Dangerous symbol exists: [{}], execution is not allowed!'.format(d)))
|
||
|
||
os.system("echo -n > {}".format(self._rCmd_log))
|
||
os.system("nohup {} >> {} 2>&1 && echo 'bt_successful' >> {} || echo 'bt_failed' >> {} &".format(
|
||
get.cmd,
|
||
self._rCmd_log,
|
||
self._rCmd_log,
|
||
self._rCmd_log,
|
||
))
|
||
return public.return_message(0, 0, _("The command has been executed!"))
|