From 6d478e61cc7be71992c1af90ee45816032dbb623 Mon Sep 17 00:00:00 2001 From: neargle Date: Fri, 29 Sep 2017 19:45:37 +0800 Subject: [PATCH] =?UTF-8?q?Fixes=20#1=20=E5=B9=B6=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E8=B0=83=E7=94=A8=E6=94=AF=E5=87=BA?= =?UTF-8?q?=E5=92=8C=E9=81=BF=E5=85=8Dfilter=E4=B8=8E=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E9=87=8D=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/lib/QueryLogic.py | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/views/lib/QueryLogic.py b/views/lib/QueryLogic.py index 8a987ff7..7535b171 100644 --- a/views/lib/QueryLogic.py +++ b/views/lib/QueryLogic.py @@ -16,39 +16,39 @@ def querylogic(list): if len(list) > 1 or len(list[0].split(':')) > 1: for _ in list: if _.find(':') > -1: - if _.split(':')[0] == 'port': - query['port'] = int(_.split(':')[1]) - elif _.split(':')[0] == 'banner': + q_key, q_value = _.split(':', 1) + if q_key == 'port': + query['port'] = int(q_value) + elif q_key == 'banner': zhPattern = re.compile(u'[\u4e00-\u9fa5]+') - contents = _.split(':')[1] + contents = q_value match = zhPattern.search(contents) # 如果没有中文用全文索引 if match: - query['banner'] = {"$regex": _.split(':')[1], '$options': 'i'} + query['banner'] = {"$regex": q_value, '$options': 'i'} else: - text_query = mgo_text_split(_.split(':')[1]) + text_query = mgo_text_split(q_value) query['$text'] = {'$search': text_query, '$caseSensitive':True} - elif _.split(':')[0] == 'ip': - ip = _.split(':')[1] - query['ip'] = {"$regex": ip} - elif _.split(':')[0] == 'server': - query['server'] = _.split(':')[1].lower() - elif _.split(':')[0] == 'title': - query['webinfo.title'] = {"$regex": _.split(':')[1], '$options': 'i'} - elif _.split(':')[0] == 'tag': - query['webinfo.tag'] = _.split(':')[1].lower() - elif _.split(':')[0] == 'hostname': - query['hostname'] = {"$regex": _.split(':')[1], '$options': 'i'} - elif _.split(':')[0] == 'all': - filter = [] + elif q_key == 'ip': + query['ip'] = {"$regex": q_value} + elif q_key == 'server': + query['server'] = q_value.lower() + elif q_key == 'title': + query['webinfo.title'] = {"$regex": q_value, '$options': 'i'} + elif q_key == 'tag': + query['webinfo.tag'] = q_value.lower() + elif q_key == 'hostname': + query['hostname'] = {"$regex": q_value, '$options': 'i'} + elif q_key == 'all': + filter_lst = [] for i in ('ip', 'banner', 'port', 'time', 'webinfo.tag', 'webinfo.title', 'server', 'hostname'): - filter.append({i: {"$regex": _.split(':')[1], '$options': 'i'}}) - query['$or'] = filter + filter_lst.append({i: {"$regex": q_value, '$options': 'i'}}) + query['$or'] = filter_lst else: - query[_.split(':')[0]] = _.split(':')[1] + query[q_key] = q_value else: - filter = [] + filter_lst = [] for i in ('ip', 'banner', 'port', 'time', 'webinfo.tag', 'webinfo.title', 'server', 'hostname'): - filter.append({i: {"$regex": list[0], '$options': 'i'}}) - query['$or'] = filter + filter_lst.append({i: {"$regex": list[0], '$options': 'i'}}) + query['$or'] = filter_lst return query