#coding: utf-8 # + ------------------------------------------------------------------- # | 宝塔Linux面板 # + ------------------------------------------------------------------- # | Copyright (c) 2015-2016 宝塔软件(http:#bt.cn) All rights reserved. # + ------------------------------------------------------------------- # | Author: 黄文良 <287962566@qq.com> # + ------------------------------------------------------------------- import public,db,re,os,firewalls from BTPanel import session class ftp: __runPath = None def __init__(self): self.__runPath = '/www/server/pure-ftpd/bin' #添加FTP def AddUser(self,get): try: import files,time fileObj=files.files() if re.search("\W + ",get['ftp_username']): return {'status':False,'code':501,'msg':public.getMsg('FTP_USERNAME_ERR_T')} if len(get['ftp_username']) < 3: return {'status':False,'code':501,'msg':public.getMsg('FTP_USERNAME_ERR_LEN')} if not fileObj.CheckDir(get['path']): return {'status':False,'code':501,'msg':public.getMsg('FTP_USERNAME_ERR_DIR')} if public.M('ftps').where('name=?',(get.ftp_username.strip(),)).count(): return public.returnMsg(False,'FTP_USERNAME_ERR_EXISTS',(get.ftp_username,)) username = get['ftp_username'].replace(' ','') password = get['ftp_password'] get.path = get['path'].replace(' ','') get.path = get.path.replace("\\", "/") fileObj.CreateDir(get) os.system('chown www.www ' + get.path) public.ExecShell(self.__runPath + '/pure-pw useradd ' + username + ' -u www -d ' + get.path + '< 65535: return public.returnMsg(False,'PORT_CHECK_RANGE') file = '/www/server/pure-ftpd/etc/pure-ftpd.conf' conf = public.readFile(file) rep = u"\n#?\s*Bind\s+[0-9]+\.[0-9]+\.[0-9]+\.+[0-9]+,([0-9]+)" #preg_match(rep,conf,tmp) conf = re.sub(rep,"\nBind 0.0.0.0," + port,conf) public.writeFile(file,conf) public.ExecShell('/etc/init.d/pure-ftpd restart') public.WriteLog('TYPE_FTP', "FTP_PORT",(port,)) #添加防火墙 #data = ftpinfo(port=port,ps = 'FTP端口') get.port=port get.ps = public.getMsg('FTP_PORT_PS'); firewalls.firewalls().AddAcceptPort(get) session['port']=port return public.returnMsg(True, 'EDIT_SUCCESS') except Exception as ex: public.WriteLog('TYPE_FTP', 'FTP_PORT_ERR',(str(ex),)) return public.returnMsg(False,'EDIT_ERROR') #重载配置 def FtpReload(self): public.ExecShell(self.__runPath + '/pure-pw mkdb /www/server/pure-ftpd/etc/pureftpd.pdb')