Example #1
0
    def post(self):
        # 由于get的传参方式会将&隐藏所以我们尝试该传输参数的方式
        data = request.values
        keyword = data.get('keyword')
        page = int(data.get('page'))

        if keyword:
            if "&" in keyword:
                # 将查找关键字变为多条件合并查找;&分割关键字
                keyword_list = keyword.split('&')
                article_obj = WechatArticleList.query
                article_obj = article_obj
                all_filter = []
                for per_keyword in keyword_list:
                    find_filter = []
                    per_keyword = per_keyword.strip()
                    find_filter.append(WechatArticleList.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.author.like("%" + per_keyword + "%"))
                    # find_filter.append(WechatArticleList.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.digest.like("%" + per_keyword + "%"))
                    all_filter.append(or_(*find_filter))
                article_obj = article_obj.filter(and_(*all_filter))
                article_obj = article_obj.order_by(WechatArticleList.publish_time.desc())
            else:

                # 将查找关键字变为多条件或查找;|分割关键字
                keyword_list = keyword.split('|')
                find_filter = []
                for per_keyword in keyword_list:
                    per_keyword = per_keyword.strip()
                    find_filter.append(WechatArticleList.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.author.like("%" + per_keyword + "%"))
                    # find_filter.append(WechatArticleList.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.digest.like("%" + per_keyword + "%"))

                article_obj = WechatArticleList.query.filter(or_(*find_filter
                                                                 )).order_by(
                    WechatArticleList.publish_time.desc())
            limit = current_app.config['FRONT_ARTICLES']
            start = (page - 1) * limit
            end = start + limit
            articles = article_obj.slice(start, end)
            count = article_obj.count()
            pages = int(count / limit) + 1
            if count > 0:
                article_data = anaysis(articles)
                return field.layui_success(message='共查询到 {} 条相关信息'.format(count), data=article_data, count=pages)
            else:
                return field.layui_success(message='没有找到相关信息!', count=0)
Example #2
0
def tag_articles():
    cat_id = request.args.get('cat_id')
    rule = rules()
    cat = WechatTag.query.get(cat_id)
    # article_obj = []
    # for account in cat.accounts:
    #     article = WechatArticle.query.filter_by(__biz=account.account_id).filter(rule).order_by(WechatArticle.publish_time.desc())
    #     article_obj += article
    # article_obj = list(filter(lambda x:x.publish_time, article_obj))
    # article_obj.sort(key=lambda x:x.publish_time if x.publish_time else x.spider_time, reverse=True)  #时间排序
    # page = int(request.args.get('page'))
    # limit = config.config['production'].FRONT_ARTICLES
    # start = (page - 1) * limit
    # end = start + limit
    # articles = article_obj[start:end]  #切片查询
    # pages = int(len(article_obj) / limit) + 1
    # article_data = anaysis(articles)
    article = WechatArticle.query.filter(WechatArticle.__biz.in_(set([i.account_id for i in cat.accounts]))).filter(
        rule).filter(WechatArticle.is_hide == 0).order_by(WechatArticle.publish_time.desc())
    page = int(request.args.get('page'))
    limit = current_app.config['FRONT_ARTICLES']
    start = (page - 1) * limit
    end = start + limit
    data = article.slice(start, end)  # 切片查询
    pages = int(article.count() / limit) + 1
    article_data = anaysis(data)
    return field.layui_success(message='', data=article_data, count=pages)
Example #3
0
    def get(self):
        # 不在使用GET的请求方式
        keyword = request.args.get('keyword')

        if keyword:
            if "amp" in keyword:
                # 将查找关键字变为多条件合并查找;&分割关键字
                keyword_list = (keyword.strip()).split('amp')
                article_obj = WechatArticleList.query
                for per_keyword in keyword_list:
                    find_filter = []
                    per_keyword = per_keyword
                    find_filter.append(WechatArticleList.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.author.like("%" + per_keyword + "%"))
                    # find_filter.append(WechatArticleList.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.digest.like("%" + per_keyword + "%"))
                article_obj = article_obj.filter(WechatArticleList.title.like("%" + "聚合" + "%"))
                # article_obj = article_obj.filter(or_(*find_filter)).filter(WechatArticleList.title.like("%" + "聚合" + "%"))
                article_obj = article_obj.order_by(WechatArticleList.publish_time.desc())
            else:

                # 将查找关键字变为多条件或查找;|分割关键字
                keyword_list = (keyword.strip()).split('|')
                find_filter = []
                for per_keyword in keyword_list:
                    per_keyword = per_keyword
                    find_filter.append(WechatArticleList.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.author.like("%" + per_keyword + "%"))
                    # find_filter.append(WechatArticleList.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticleList.digest.like("%" + per_keyword + "%"))

                article_obj = WechatArticleList.query.filter(or_(*find_filter
                                                                 )).order_by(WechatArticleList.publish_time.desc())

            page = int(request.args.get('page'))
            limit = current_app.config['FRONT_ARTICLES']
            start = (page - 1) * limit
            end = start + limit
            articles = article_obj.slice(start, end)
            count = article_obj.count()
            pages = int(count / limit) + 1
            if count > 0:
                article_data = anaysis(articles)
                return field.layui_success(message='共查询到 {} 条相关信息'.format(count), data=article_data, count=pages)
            else:
                return field.layui_success(message='没有找到相关信息!', count=0)
Example #4
0
 def post(self):
     file = request.files['file']
     filename = file.filename
     content = file.read()
     if not file:
         return field.params_error(message='未接收到文件')
     if not allowed_file(file.filename,
                         ALLOWED_EXTENSIONS=config.ALLOWED_PIC_EXTENSIONS):
         return field.params_error(message='图片格式不合法')
     if not file_len(content):
         return field.params_error(message='图片大小超过{}M'.format(
             int(config.ALLOWED_PIC_LEN / 1024 / 1024)))
     new_name = rename(filename)
     if config.STORE_TYPE == 'github':  # github存储
         git = GithubTools()
         code, link = git.create_file(
             '{}{}'.format(config.PATH, '/' + new_name), content)
         if code:
             image = Images(name=new_name, link=link, type='github')
             db.session.add(image)
             db.session.commit()
             return field.layui_success(message='上传成功,请拷贝链接使用',
                                        data={
                                            'link': link,
                                            'id': image.id
                                        })
         else:
             return field.params_error(message=link)
     elif config.STORE_TYPE == 'server':  # 本地存储
         img = open(os.path.join(config.LOCAL_STORAGE_PATH, new_name), 'wb')
         img.write(content)
         img.close()
         link = request.url_root + 'static/images/' + new_name
         image = Images(name=new_name, link=link, type='server')
         db.session.add(image)
         db.session.commit()
         return field.layui_success(message='上传成功,请拷贝链接使用',
                                    data={
                                        'link': link,
                                        'id': image.id
                                    })
     else:
         return field.params_error('配置文件中STORE_TYPE字段设置不正确')
Example #5
0
    def get(self):
        cat_id = request.args.get('cat_id')

        cat = WechatTag.query.get(cat_id)
        article = WechatArticleList.query.filter(
            getattr(WechatArticleList, '__biz').in_(set([i.account_id for i in cat.accounts]))).order_by(
            WechatArticleList.publish_time.desc())
        page = int(request.args.get('page'))
        limit = current_app.config['FRONT_ARTICLES']
        start = (page - 1) * limit
        end = start + limit
        data = article.slice(start, end)  # 切片查询
        pages = int(article.count() / limit) + 1
        article_data = anaysis(data)
        return field.layui_success(message='', data=article_data, count=pages)
Example #6
0
    def post(self):

        data = request.values
        keys = list(data.keys())
        keys.remove('page')
        keys.remove('limit')

        page = int(request.form.get('page'))
        limit = int(request.form.get('limit'))
        start = (page - 1) * limit
        end = start + limit

        iport_obj = IPort.query.order_by(IPort.create_time.asc())

        if keys:
            print(data.get('name'))
            iport_search = iport_obj.filter(
                and_(
                    IPort.port.like("%" + data.get('port', '') + "%"),
                    IPort.finger_name.like("%" + data.get('name', '') + "%"),
                )).filter(IPort.flag == '1')

        else:

            iport_search = iport_obj.filter(IPort.flag == '1')

        ips = iport_search.slice(start, end)
        count = iport_search.count()
        ips_list = []
        for ips in ips:
            ip_dict = {}
            ip_dict['id'] = ips.id
            ip_dict['ips'] = ips.SIPS.ips
            ip_dict['ip'] = ips.living_port.ip
            ip_dict['port'] = ips.port
            ip_dict['finger'] = ips.finger
            ip_dict['finger_name'] = ips.finger_name
            ip_dict['finger_state'] = ips.finger_state
            ip_dict['finger_product'] = ips.finger_product
            ip_dict['finger_version'] = ips.finger_version
            ip_dict['finger_extrainfo'] = ips.finger_extrainfo
            ip_dict['finger_cpe'] = ips.finger_cpe

            ip_dict['status'] = ips.status
            ip_dict['scan_time'] = str(ips.scan_time)
            ip_dict['create_time'] = str(ips.create_time)
            ips_list.append(ip_dict)
        return field.layui_success(data=ips_list, count=count, message='查询成功')
Example #7
0
    def post(self):
        page = int(request.form.get('page'))
        limit = int(request.form.get('limit'))
        start = (page - 1) * limit
        end = start + limit

        ips_obj = IPS.query.order_by(IPS.create_time.asc())
        ips = ips_obj.slice(start, end)
        count = ips_obj.count()
        ips_list = []
        for ips in ips:
            ip_dict = {}
            ip_dict['id'] = ips.id
            ip_dict['ips'] = ips.ips
            ip_dict['status'] = ips.status
            ip_dict['scan_time'] = str(ips.scan_time)
            ip_dict['create_time'] = str(ips.create_time)
            ips_list.append(ip_dict)
        return field.layui_success(data=ips_list, count=count)
Example #8
0
    def post(self):
        data = request.values
        keys = list(data.keys())
        keys.remove('page')
        keys.remove('limit')

        page = int(request.form.get('page'))
        limit = int(request.form.get('limit'))
        start = (page - 1) * limit
        end = start + limit

        livingip_obj = LivingIP.query.order_by(LivingIP.create_time.asc())
        print(keys)
        if keys:

            if data.get('all') == '1':
                livingip_search = livingip_obj.filter(
                    and_(LivingIP.ip.like("%" + data.get('ip', '') + "%"),
                         ))
            else:
                livingip_search = livingip_obj.filter(
                    and_(LivingIP.ip.like("%" + data.get('ip', '') + "%"),

                         )).filter(LivingIP.flag == '1')
        else:
            livingip_search = livingip_obj.filter(LivingIP.flag == '1')

        ips = livingip_search.slice(start, end)
        count = livingip_search.count()
        ips_list = []
        for ips in ips:
            ip_dict = {}
            ip_dict['id'] = ips.id
            ip_dict['ips'] = ips.IPS.ips
            ip_dict['ip'] = ips.ip
            ip_dict['status'] = ips.flag
            ip_dict['scan_time'] = str(ips.scan_time)
            ip_dict['create_time'] = str(ips.create_time)
            ips_list.append(ip_dict)
        return field.layui_success(data=ips_list, count=count, message='查询成功')
Example #9
0
def account_articles():
    id = request.args.get('id')
    flag = request.args.get('flag')
    rule = rules()
    if id:
        article_obj = WechatArticle.query.filter_by(__biz=id).filter(rule).filter(WechatArticle.is_hide == 0).order_by(
            WechatArticle.publish_time.desc())
    else:
        article_obj = WechatArticle.query.filter(rule).filter(WechatArticle.is_hide == 0).order_by(
            WechatArticle.publish_time.desc())

    page = int(request.args.get('page'))
    limit = current_app.config['FRONT_ARTICLES']
    start = (page - 1) * limit
    end = start + limit
    articles = article_obj.slice(start, end)
    pages = int(article_obj.count() / limit) + 1
    if flag:
        article_data = anaysis(articles, flag=flag)
    else:
        article_data = anaysis(articles)
    return field.layui_success(message='', data=article_data, count=pages)
Example #10
0
def search():
    if request.method == 'GET':
        # 不在使用GET的请求方式
        keyword = request.args.get('keyword')
        print(keyword)
        if keyword:
            if "amp" in keyword:
                # 将查找关键字变为多条件合并查找;&分割关键字
                keyword_list = (keyword.strip()).split('amp')
                article_obj = WechatArticle.query
                for per_keyword in keyword_list:
                    find_filter = []
                    per_keyword = per_keyword
                    find_filter.append(WechatArticle.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.author.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.digest.like("%" + per_keyword + "%"))
                article_obj = article_obj.filter(WechatArticle.title.like("%" + "聚合" + "%"))
                # article_obj = article_obj.filter(or_(*find_filter)).filter(WechatArticle.title.like("%" + "聚合" + "%"))
                article_obj = article_obj.order_by(WechatArticle.publish_time.desc())
            else:

                # 将查找关键字变为多条件或查找;|分割关键字
                keyword_list = (keyword.strip()).split('|')
                find_filter = []
                for per_keyword in keyword_list:
                    per_keyword = per_keyword
                    find_filter.append(WechatArticle.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.author.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.digest.like("%" + per_keyword + "%"))

                article_obj = WechatArticle.query.filter(or_(*find_filter
                                                             )).order_by(WechatArticle.publish_time.desc())

            page = int(request.args.get('page'))
            limit = current_app.config['FRONT_ARTICLES']
            start = (page - 1) * limit
            end = start + limit
            articles = article_obj.slice(start, end)
            count = article_obj.count()
            pages = int(count / limit) + 1
            if count > 0:
                article_data = anaysis(articles)
                return field.layui_success(message='共查询到 {} 条相关信息'.format(count), data=article_data, count=pages)
            else:
                return field.layui_success(message='没有找到相关信息!', count=0)
    else:
        # 由于get的传参方式会将&隐藏所以我们尝试该传输参数的方式
        data = request.values
        keyword = data.get('keyword')
        page = int(data.get('page'))
        print(keyword)
        if keyword:
            if "&" in keyword:
                # 将查找关键字变为多条件合并查找;&分割关键字
                keyword_list = keyword.split('&')
                article_obj = WechatArticle.query
                article_obj = article_obj.filter(WechatArticle.is_hide == 0)
                all_filter = []
                for per_keyword in keyword_list:
                    find_filter = []
                    per_keyword = per_keyword.strip()
                    find_filter.append(WechatArticle.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.author.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.digest.like("%" + per_keyword + "%"))
                    all_filter.append(or_(*find_filter))
                article_obj = article_obj.filter(and_(*all_filter))
                article_obj = article_obj.order_by(WechatArticle.publish_time.desc())
            else:

                # 将查找关键字变为多条件或查找;|分割关键字
                keyword_list = keyword.split('|')
                find_filter = []
                for per_keyword in keyword_list:
                    per_keyword = per_keyword.strip()
                    find_filter.append(WechatArticle.title.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.author.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.account.like("%" + per_keyword + "%"))
                    find_filter.append(WechatArticle.digest.like("%" + per_keyword + "%"))

                article_obj = WechatArticle.query.filter(or_(*find_filter
                                                             )).filter(WechatArticle.is_hide == 0).order_by(
                    WechatArticle.publish_time.desc())
            limit = current_app.config['FRONT_ARTICLES']
            start = (page - 1) * limit
            end = start + limit
            articles = article_obj.slice(start, end)
            count = article_obj.count()
            pages = int(count / limit) + 1
            # 添加用户关键字记录
            visitor_id = session.get(current_app.config['VISITOR'])
            keyword_search = HotSearch(search=keyword, page=page, visitor_id=visitor_id, count=count)
            db.session.add(keyword_search)
            db.session.commit()
            if count > 0:
                article_data = anaysis(articles)
                return field.layui_success(message='共查询到 {} 条相关信息'.format(count), data=article_data, count=pages)
            else:
                return field.layui_success(message='没有找到相关信息!', count=0)