diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 40f60639f..16a3a68c0 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -14,10 +14,135 @@ from flask import request class firewall_api: + __isFirewalld = False + __isUfw = False + def __init__(self): - pass + if os.path.exists('/usr/sbin/firewalld'): + self.__isFirewalld = True + if os.path.exists('/usr/sbin/ufw'): + self.__isUfw = True + + def firewallReload(self): + if self.__isUfw: + public.execShell('/usr/sbin/ufw reload') + return + if self.__isFirewalld: + public.execShell('firewall-cmd --reload') + else: + public.execShell('/etc/init.d/iptables save') + public.execShell('/etc/init.d/iptables restart') ##### ----- start ----- ### + # 添加屏蔽IP + def addDropAddressApi(self): + import re + port = request.form.get('port', '').strip() + ps = request.form.get('ps', '').strip() + + rep = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$" + if not re.search(rep, port): + return public.returnJson(False, 'FIREWALL_IP_FORMAT') + address = port + if public.M('firewall').where("port=?", (address,)).count() > 0: + return public.returnJson(False, 'FIREWALL_IP_EXISTS') + if self.__isUfw: + public.ExecShell('ufw deny from ' + address + ' to any') + else: + if self.__isFirewalld: + public.ExecShell( + 'firewall-cmd --permanent --add-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'') + else: + public.ExecShell('iptables -I INPUT -s ' + + address + ' -j DROP') + + public.writeLog("TYPE_FIREWALL", 'FIREWALL_DROP_IP', (address,)) + addtime = time.strftime('%Y-%m-%d %X', time.localtime()) + public.M('firewall').add('port,ps,addtime', (address, ps, addtime)) + self.firewallReload() + return public.returnJson(True, 'ADD_SUCCESS') + + # 删除IP屏蔽 + def delDropAddressApi(self): + port = request.form.get('port', '').strip() + ps = request.form.get('ps', '').strip() + sid = request.form.get('id', '').strip() + address = port + if self.__isUfw: + public.execShell('ufw delete deny from ' + address + ' to any') + else: + if self.__isFirewalld: + public.execShell( + 'firewall-cmd --permanent --remove-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'') + else: + public.execShell('iptables -D INPUT -s ' + + address + ' -j DROP') + + public.writeLog("TYPE_FIREWALL", 'FIREWALL_ACCEPT_IP', (address,)) + public.M('firewall').where("id=?", (sid,)).delete() + + self.firewallReload() + return public.returnJson(True, 'DEL_SUCCESS') + + # 添加放行端口 + def addAcceptPort(self): + import re + import time + port = request.form.get('port', '').strip() + ps = request.form.get('ps', '').strip() + sid = request.form.get('id', '').strip() + + rep = "^\d{1,5}(:\d{1,5})?$" + if not re.search(rep, port): + return public.returnJson(False, 'PORT_CHECK_RANGE') + + if public.M('firewall').where("port=?", (port,)).count() > 0: + return public.returnJson(False, 'FIREWALL_PORT_EXISTS') + if self.__isUfw: + public.execShell('ufw allow ' + port + '/tcp') + else: + if self.__isFirewalld: + # self.__Obj.AddAcceptPort(port) + port = port.replace(':', '-') + public.execShell( + 'firewall-cmd --permanent --zone=public --add-port=' + port + '/tcp') + else: + public.execShell( + 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT') + public.writeLog("TYPE_FIREWALL", 'FIREWALL_ACCEPT_PORT', (port,)) + addtime = time.strftime('%Y-%m-%d %X', time.localtime()) + public.M('firewall').add('port,ps,addtime', (port, ps, addtime)) + + self.firewallReload() + return public.returnJson(True, 'ADD_SUCCESS') + + # 删除放行端口 + def delAcceptPort(self, get): + port = request.form.get('port', '').strip() + sid = request.form.get('id', '').strip() + + try: + if(port == web.ctx.host.split(':')[1]): + return public.returnJson(False, 'FIREWALL_PORT_PANEL') + if self.__isUfw: + public.execShell('ufw delete allow ' + port + '/tcp') + else: + if self.__isFirewalld: + public.execShell( + 'firewall-cmd --permanent --zone=public --remove-port=' + port + '/tcp') + public.execShell( + 'firewall-cmd --permanent --zone=public --remove-port=' + port + '/udp') + else: + public.execShell( + 'iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT') + public.writeLog("TYPE_FIREWALL", 'FIREWALL_DROP_PORT', (port,)) + public.M('firewall').where("id=?", (sid,)).delete() + + self.firewallReload() + return public.returnJson(True, 'DEL_SUCCESS') + except: + return public.returnJson(False, 'DEL_ERROR') + def getWwwPathApi(self): path = public.getLogsDir() return public.getJson({'path': path}) diff --git a/class/core/site_api.py b/class/core/site_api.py index fa1be9fcf..a915e3b72 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -486,7 +486,7 @@ class site_api: data = {} data['siteStatus'] = False public.restartWeb() - return public.getJson(data) + return public.returnJson(True, '添加成功') def deleteWSLogs(self, webname): assLogPath = public.getLogsDir() + '/' + webname + '.log' diff --git a/plugins/qbittorrent/workers/qbittorrent_worker.py b/plugins/qbittorrent/workers/qbittorrent_worker.py index 0ab94082a..33cef7608 100755 --- a/plugins/qbittorrent/workers/qbittorrent_worker.py +++ b/plugins/qbittorrent/workers/qbittorrent_worker.py @@ -211,11 +211,27 @@ class downloadBT(Thread): os.system(cmd_m3u8) self.execShell('chown -R ' + FILE_OWN + ':' + FILE_GROUP + ' ' + m3u8_dir) - print self.query("insert into pl_download_list (`info_hash`) values('1221')") + + self.add_hash() else: print self.debug('m3u8 exists:' + tofile) # self.unlock(md5file) + def add_hash(self): + ct = formatTime() + print self.sign_torrent + total_size = str(self.sign_torrent['total_size']) + shash = self.sign_torrent['hash'] + sname = self.sign_torrent['name'] + + sql = "select id from pl_hash_list where info_hash='" + shash + "'" + info = self.query(sql) + if len(info[0]) > 0: + sid = str(info[0][0]) + print self.query("insert into pl_hash_file (`pid`,`name`,`m3u8`,`length`,`create_time`) values('" + sid + "','" + sname + "','" + 'dd' + "','" + total_size + "','" + ct + "')") + else: + print self.query("insert into pl_hash_list (`name`,`info_hash`,`data_hash`,`length`,`create_time`) values('" + sname + "','" + shash + "','da12','" + total_size + "','" + ct + "')") + def file_arr(self, path, filters=['.DS_Store']): file_list = [] flist = os.listdir(path) @@ -271,6 +287,7 @@ class downloadBT(Thread): print "completed torrents count:", tlen if tlen > 0: for torrent in torrents: + self.sign_torrent = torrent # print torrent path = torrent['save_path'] + torrent['name'] try: diff --git a/route/static/app/files.js b/route/static/app/files.js index 834b8a08e..4cfe630ee 100755 --- a/route/static/app/files.js +++ b/route/static/app/files.js @@ -449,7 +449,7 @@ function getFiles(Path) { "; } } - var dirInfo = '('+lan.files.get_size.replace('{1}',rdata.DIR.length+'').replace('{2}',rdata.DIR.length+'')+''+(toSize(totalSize))+''+lan.files.get+')'; + var dirInfo = '('+lan.files.get_size.replace('{1}',rdata.DIR.length+'').replace('{2}',rdata.DIR.length+'')+''+(toSize(totalSize))+'获取)'; $("#DirInfo").html(dirInfo); if(getCookie("rank")=="a"){ var tablehtml = '