def run(self, codeurl, newtask = False): #import pdb;pdb.set_trace() url = urllib.unquote(codeurl) if url.startswith('https:/'): url = url[7:len(url)] if url.startswith('http:/'): url = url[6:len(url)] codeurl = urllib.quote(url) if newtask and www.is_url_format(url):#判断是否重新检测 stu = create_task(codeurl,url) return stu else: recheck = '0' if not www.is_url_format(url): raise web.redirect('/') result_count = {'safe':0,'warning':0,'danger':0,'unknown':0} exist_job = Db_rds.hgetall(config.TASK_INFO+codeurl) #判断是否旧版本数据,如果是,加入调度 print exist_job if not exist_job or (exist_job.get('code',config.Engine_old_num) == config.Engine_old_num and exist_job.get('task_statu',1) ==1): create_task(codeurl,url,True) status = 'ing' url_result = {} else: recheck = '1' db = Db_mongo.check_result url_result = db.result.find_one({'url':codeurl}) status = 'done' if not url_result: status = 'ing' url_result = {} create_task(codeurl,url,False) elif len(url_result.get('result',{}))< config.Engine_num: status = 'ing' if exist_job and exist_job.get('task_statu',1) == '0': status = 'ing' if url_result: result = url_result.get('result',{}) for i in result: e_result = result.get(i,{}) r = e_result.get('c_result','') if r == 'safe': result_count['safe'] += 1 elif r == 'warning': result_count['warning'] += 1 elif r == 'danger': result_count['danger'] += 1 else: result_count['unknown'] += 1 checktime = result.get('check_time','') if checktime: howlong = time.teime - time.mktime(checktime.timetuple()) if howlong < config.TASK_REPEAT_LIMIT: recheck = '0' now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') return render.report(url,url_result,config.Engines,config.Safe_type,config.Engine_num,status,now,result_count,recheck)
def check(url,codeurl,eng,timeout): engine = getattr(__import__('modules.%s'%eng),eng) result = engine.check(url) s_result = {'codeurl':url,'c_time':datetime.datetime.now(),'result':result,'engine':eng} if not Db_rds.rpush(a_config.TASK_RESULT,s_result): create_task(codeurl,url) else: Queue_rds.lpop(a_config.TASK_ENGINE+eng) num = Db_rds.hget(a_config.TASK_INFO+codeurl,'code') Db_rds.hset(a_config.TASK_INFO+codeurl,'code',int(num)+1) if int(num)+1 == int(a_config.Engine_num): Db_rds.hset(a_config.TASK_INFO+codeurl,'task_statu',1)
def run(self, codeurl, newtask=False): #import pdb;pdb.set_trace() url = urllib.unquote(codeurl) if url.startswith('https:/'): url = url[7:len(url)] if url.startswith('http:/'): url = url[6:len(url)] codeurl = urllib.quote(url) if newtask and www.is_url_format(url): #判断是否重新检测 stu = create_task(codeurl, url) return stu else: recheck = '0' if not www.is_url_format(url): raise web.redirect('/') result_count = {'safe': 0, 'warning': 0, 'danger': 0, 'unknown': 0} exist_job = Db_rds.hgetall(config.TASK_INFO + codeurl) #判断是否旧版本数据,如果是,加入调度 print exist_job if not exist_job or (exist_job.get( 'code', config.Engine_old_num) == config.Engine_old_num and exist_job.get('task_statu', 1) == 1): create_task(codeurl, url, True) status = 'ing' url_result = {} else: recheck = '1' db = Db_mongo.check_result url_result = db.result.find_one({'url': codeurl}) status = 'done' if not url_result: status = 'ing' url_result = {} create_task(codeurl, url, False) elif len(url_result.get('result', {})) < config.Engine_num: status = 'ing' if exist_job and exist_job.get('task_statu', 1) == '0': status = 'ing' if url_result: result = url_result.get('result', {}) for i in result: e_result = result.get(i, {}) r = e_result.get('c_result', '') if r == 'safe': result_count['safe'] += 1 elif r == 'warning': result_count['warning'] += 1 elif r == 'danger': result_count['danger'] += 1 else: result_count['unknown'] += 1 checktime = result.get('check_time', '') if checktime: howlong = time.teime - time.mktime( checktime.timetuple()) if howlong < config.TASK_REPEAT_LIMIT: recheck = '0' now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') return render.report(url, url_result, config.Engines, config.Safe_type, config.Engine_num, status, now, result_count, recheck)