From e9f54cd223cf3d034409d6a986f64058bea48009 Mon Sep 17 00:00:00 2001 From: hwliang <287962566@qq.com> Date: Fri, 11 Jun 2021 16:33:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E7=BD=91=E7=AB=99=E6=A0=B9?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=99=90=E5=88=B6=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/firewalls.py | 1 - class/panelSite.py | 13 ++++++++----- class/public.py | 34 ++++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/class/firewalls.py b/class/firewalls.py index f49e216b..cf503d2a 100644 --- a/class/firewalls.py +++ b/class/firewalls.py @@ -305,7 +305,6 @@ def GetSshInfo(self,get): else: status = public.ExecShell("/etc/init.d/sshd status | grep -e 'stopped' -e '已停'|grep -v grep") - # return status; if len(status[0]) > 3: status = False else: diff --git a/class/panelSite.py b/class/panelSite.py index 7b336fee..b13f0fcd 100644 --- a/class/panelSite.py +++ b/class/panelSite.py @@ -478,7 +478,9 @@ def AddSite(self,get,multiple=None): get.path = self.__get_site_format_path(get.path) - if not public.check_site_path(get.path): return public.returnMsg(False,'请不要将网站根目录设置到系统关键目录中') + if not public.check_site_path(get.path): + a,c = public.get_sys_path() + return public.returnMsg(False,'请不要将网站根目录设置到以下关键目录中:
{}'.format("
".join(a+c))) try: siteMenu = json.loads(get.webname) except: @@ -514,7 +516,7 @@ def AddSite(self,get,multiple=None): #if siteMenu['count']: # domain = get.domain.replace(' ','') #表单验证 - if not files.files().CheckDir(self.sitePath) or not self.__check_site_path(self.sitePath): return public.returnMsg(False,'PATH_ERROR') + if not self.__check_site_path(self.sitePath): return public.returnMsg(False,'PATH_ERROR') if len(self.phpVersion) < 2: return public.returnMsg(False,'SITE_ADD_ERR_PHPEMPTY') reg = r"^([\w\-\*]{1,100}\.){1,4}([\w\-]{1,24}|[\w\-]{1,24}\.[\w\-]{1,24})$" if not re.match(reg, self.siteName): return public.returnMsg(False,'SITE_ADD_ERR_DOMAIN') @@ -2824,9 +2826,10 @@ def SetPath(self,get): Path = self.GetPath(get.path) if Path == "" or id == '0': return public.returnMsg(False, "DIR_EMPTY") - import files - if not files.files().CheckDir(Path) or not self.__check_site_path(Path): return public.returnMsg(False, "PATH_ERROR") - if not public.check_site_path(Path): return public.returnMsg(False,'请不要将网站根目录设置到系统关键目录中') + if not self.__check_site_path(Path): return public.returnMsg(False, "PATH_ERROR") + if not public.check_site_path(Path): + a,c = public.get_sys_path() + return public.returnMsg(False,'请不要将网站根目录设置到以下关键目录中:
{}'.format("
".join(a+c))) SiteFind = public.M("sites").where("id=?",(id,)).field('path,name').find() if SiteFind["path"] == Path: return public.returnMsg(False, "SITE_PATH_ERR_RE") diff --git a/class/public.py b/class/public.py index bcb47d0e..18ae3614 100644 --- a/class/public.py +++ b/class/public.py @@ -483,7 +483,7 @@ def serviceReload(): return ServiceReload() -def ExecShell(cmdstring, cwd=None, timeout=None, shell=True): +def ExecShell(cmdstring, timeout=None, shell=True): a = '' e = '' import subprocess,tempfile @@ -493,7 +493,19 @@ def ExecShell(cmdstring, cwd=None, timeout=None, shell=True): succ_f = tempfile.SpooledTemporaryFile(max_size=4096,mode='wb+',suffix='_succ',prefix='btex_' + rx ,dir='/dev/shm') err_f = tempfile.SpooledTemporaryFile(max_size=4096,mode='wb+',suffix='_err',prefix='btex_' + rx ,dir='/dev/shm') sub = subprocess.Popen(cmdstring, close_fds=True, shell=shell,bufsize=128,stdout=succ_f,stderr=err_f) - sub.wait() + if timeout: + s = 0 + d = 0.01 + while sub.poll() is None: + time.sleep(d) + s += d + if s >= timeout: + if not err_f.closed: err_f.close() + if not succ_f.closed: succ_f.close() + return 'Timed out' + else: + sub.wait() + err_f.seek(0) succ_f.seek(0) a = succ_f.read() @@ -501,7 +513,7 @@ def ExecShell(cmdstring, cwd=None, timeout=None, shell=True): if not err_f.closed: err_f.close() if not succ_f.closed: succ_f.close() except: - print(get_error_info()) + return '',get_error_info() try: #编码修正 if type(a) == bytes: a = a.decode('utf-8') @@ -3042,6 +3054,17 @@ def return_is_send_info(): return ret +def get_sys_path(): + ''' + @name 关键目录 + @author hwliang<2021-06-11> + @return tuple + ''' + a = ['/www','/usr','/','/dev','/home','/media','/mnt','/opt','/tmp','/var'] + c = ['/www/Recycle_bin/','/www/backup/','/www/php_session/','/www/wwwlogs/','/www/server/','/etc/','/usr/','/var/','/boot/','/proc/','/sys/','/tmp/','/root/','/lib/','/bin/','/sbin/','/run/','/lib64/','/lib32/','/srv/'] + return a,c + + def check_site_path(site_path): ''' @name 检查网站根目录是否为系统关键目录 @@ -3049,13 +3072,12 @@ def check_site_path(site_path): @param site_path 网站根目录全路径 @return bool ''' + a,error_paths = get_sys_path() site_path = site_path.strip() if site_path[-1] == '/': site_path = site_path[:-1] - if site_path in ['/www','/usr','/','/dev','/home','/media','/mnt','/opt','/tmp','/var']: + if site_path in a: return False - site_path += '/' - error_paths = ['/www/Recycle_bin/','/www/backup/','/www/php_session/','/www/wwwlogs/','/www/server/','/etc/','/usr/','/var/','/boot/','/proc/','/sys/','/tmp/','/root/','/lib/','/bin/','/sbin/','/run/','/lib64/','/lib32/','/srv/'] for ep in error_paths: if site_path.find(ep) == 0: return False return True \ No newline at end of file