import os
import re
import json
import time
import threading
import requests
#import execjs

from core.const import failed_soup
from core.soup import Soup
from core.utils import check_soup
import datetime
from core.vul_filter import processing_file
from selenium import webdriver

soup = Soup('https://www.intel.com/content/www/us/en/security-center/default.html')


def parse(soup):
    if check_soup(soup.html):
        return [failed_soup, failed_soup, failed_soup, failed_soup, failed_soup]
    div = soup.html.find('div', class_='table-responsive')
    td = div.select('div tr td')
    print(td[2].get_text())


# Intel站 输出最新标题和最新更新时间 为确定其更新与否 只需返回最上层的漏洞更新日期即可
def Intel_update_checker():
    soup = Soup('https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + (td[0].select('div a'))[0].get('href')


# CNNVD漏洞预警 返回最新文章地址及时间
def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    # print(soup.header)
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(((sub[0].select('div a'))[0]).get('href'))
            posts_time.append(sub[1].get_text())

        # print(len(posts_time), len(posts_address))
        return posts_address, posts_time
        # print(subdiv)


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


# Cookie是动态的所以暂时搁置对CNVD的Coding
def CNVD_update_checker_ERR():
    # Cookie和user-agent相关所以需要手动修改请求头
    header = {  # 'Upgrade-Insecure-Requests': '1',
        'Cookie': '__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b;JSESSIONID=9F5034F8F05C962FD9193EB14B2A091D;__jsl_clearance=1591151886.029|0|O7hmYtY7baM3UwXmh%2BAxXCqcwD0%3D',
        # 'Host': 'www.cnvd.org.cn', 'Accept-Encoding': 'gzip, deflate, br',
        # 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        # 'Connection': 'keep-alive',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'}
    soup = Soup('https://www.cnvd.org.cn/webinfo/list?type=14', header=header)
    # soup.header['Upgrade-Insecure-Requests']='1'
    # soup.header['Cookie']='__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b; __jsl_clearance=1591065994.349|0|QA3ffs2Ye8hD9txZPdNIy3Eg5LA%3D'
    # soup=soup.make_soup()
    print(soup.req_header)
    print(soup.html)
    if check_soup(soup.html):
        return None
    table = soup.html.find('div', class_='blkContainerPblk')
    # print(table)
    tr = table.select('table tbody tr')
    print(tr)
    name = tr[0].get_text()
    print(name)


# 对H3C更新情况进行检查
def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding='utf-8')
    if check_soup(soup.html):
        return None
    # print(soup.html)
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    # print(div)
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\[|\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    # print(updatetime)
    return title, updatetime, 'http://www.h3c.com' + url


# Lenovo网页的漏洞数据不是随主html页面一起返回 没能找到返回所在的包 暂时搁置
def Lenovo_update_checker():
    soup = Soup('https://support.lenovo.com/us/en/product_security/home')
    print(soup.html)
    if check_soup(soup.html):
        return None
    div = soup.html.find_all('div', class_='right-area')
    # print(div)


# 返回字典列表，其中每个字典代表时间命中的一条漏洞信息，待解析
def Dell_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    ret = requests.get('https://www.dell.com/support/security/zh-cn/Security/Article?articleType=advisory')
    # ret.encoding='utf-8'
    j = json.loads(ret.text)
    output = []
    for ji in j:
        fp = re.findall('\d+-\d+-\d\d', ji['FirstPublished'])[0]
        if fp in days:
            ji.pop('IsAuthRequired')
            ji.pop('ArticleId')
            ji.pop('CVEIdentifier')
            ji.pop('Severity')
            ji.pop('AccessLevel')
            ji.pop('Source')
            ji.pop('Type')
            ji.pop('IsDell')
            ji.pop('SeverityOrder')
            output.append(ji)
    # print(re.findall('\d+-\d+-\d\d',j[0]['FirstPublished']))
    # for ji in j:
    #   print(ji['FirstPublished']+'   '+ji['LastPublished'])
    # print(j[0])
    return output


# HPE原安全公告地址被更换，故在此采用新版的安全公告地址
# https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=date%20descending&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1
# 该网站也是不把结果包含在初始html应答中，且对结果数据的请求需要认证 待fix
def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    # soup=Soup(f"https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=date%20descending&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[{lastday.year}%2F{lastday.month}%2F{lastday.day}%4016%3A00%3A00..{today.year}%2F{today.month}%2F{today.day}%4016%3A00%3A00]&hpe=1")
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1')
    if check_soup(soup.html):
        return None
    print(soup.html)
    # table=soup.html.find('table',class_='coveo-result-list-container coveo-table-layout-container')
    # print(table)


# 返回HPE的title和时间字符串
def HPE_update_checker():
    url = 'https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
          '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 '
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get(url)
    time.sleep(15)
    div = browser.find_element_by_id('resultList-container')
    text = div.text
    text = re.split('\n', text)
    text = text[0]
    print(text)
    browser.quit()


# 返回华为最新更新漏洞条目
def HUAWEI_update_checker():
    soup = Soup('https://www.huawei.com/cn/psirt/all-bulletins')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='col-sm-7 col-sm-offset-1')
    h3 = div.select('div div div li')
    # print(h3)
    title = (h3[0].select('li a'))[0].get_text()
    title = re.sub('\r\n\s+', '', title)
    updatetime = (h3[0].select('li span'))[0].get_text()
    url = (h3[0].select('li a'))[0].get('href')
    return title, updatetime, 'https://www.huawei.com' + url
    # print(div)


# 返回CNVD是否有最新报告及是否与产品线相关
def CNVD_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get('https://www.cnvd.org.cn/webinfo/list?type=14')
    time.sleep(12)
    # html = browser.page_source
    input = browser.find_element_by_class_name('tlist')
    input = input.find_element_by_tag_name('tbody')
    input = input.find_element_by_class_name('current')
    title = input.text
    href = input.find_element_by_tag_name('a').get_attribute('href')
    # print(input.text + '    ' + input.find_element_by_tag_name('a').get_attribute('href'))
    update_time = re.findall('\d+-\d+-\d\d', title)[0]
    title = re.split(' ', title)[0]
    browser.quit()
    report = '无安全公告更新'
    if update_time in days:
        report = CNVD_report_checker(href)
        if len(report) == 0:
            report = '最新公告与产品线无关'
    return report


def CNVD_report_checker(href):
    pf = processing_file()
    browser = webdriver.Firefox()
    browser.get(href)
    time.sleep(12)
    report = browser.find_element_by_class_name('blkContainerSblk')
    text = report.text
    browser.quit()
    return pf.exec_filtering_CNVD_report(text)


# 返回LENOVO最新更新公告名称 初次公开时间和更新时间
def lenovo_update_checker():
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get('https://support.lenovo.com/us/en/product_security/home')
    time.sleep(10)
    div = browser.find_element_by_id('detailBody')
    table = div.find_element_by_tag_name('table')
    text = table.text
    text = re.split('\n', text)
    text = text[5]
    timere = '\d\d\d\d-\d\d-\d\d'
    updatetime = re.findall(timere, text)
    firstpublished = updatetime[0]
    lastupdated = updatetime[1]
    title = re.sub('LEN\S+\s', '', text)
    title = re.sub('\sCVE.+', '', title)
    browser.quit()
    return title, firstpublished, lastupdated

'''
# 在运行的过程中始终报错 不能像浏览器一样得出预期结果 故舍弃
def getCookieFromJs():
    url = 'https://www.cnvd.org.cn/webinfo/list?type=14'
    os.environ["EXECJS_RUNTIME"] = "Node.js"
    print(execjs.get().name)
    req = requests.get(url).text
    print(req)
    req = re.sub('<script>', '', req)
    req = re.sub('</script>', '', req)
    # req='function a(){'+req+'}'
    # print(req)
    jsfunction = execjs.compile(req)
    jsfunction.call('_1r')
    # jsfunction=execjs.compile('function a() {'+req+' }')

    # jsfunction.call('a')
    # print(req)
'''

def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))

    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(), '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
        '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看')
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


# 多线程版本比非多线程版本快一些
def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()

    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
                           '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start()
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
        '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看')
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


c68540fde76e5fe4b72d294aecd687e018bac2b6
<mask token>


def Intel_update_checker():
    soup = Soup(
        'https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + td[0].select(
            'div a')[0].get('href')


def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(sub[0].select('div a')[0].get('href'))
            posts_time.append(sub[1].get_text())
        return posts_address, posts_time


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


<mask token>


def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding=
        'utf-8')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\\[|\\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    return title, updatetime, 'http://www.h3c.com' + url


<mask token>


def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1'
        )
    if check_soup(soup.html):
        return None
    print(soup.html)


<mask token>


def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))
    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ',
        CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()
    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start(
        )
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ',
        Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())

<mask token>


def parse(soup):
    if check_soup(soup.html):
        return [failed_soup, failed_soup, failed_soup, failed_soup, failed_soup
            ]
    div = soup.html.find('div', class_='table-responsive')
    td = div.select('div tr td')
    print(td[2].get_text())


def Intel_update_checker():
    soup = Soup(
        'https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + td[0].select(
            'div a')[0].get('href')


def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(sub[0].select('div a')[0].get('href'))
            posts_time.append(sub[1].get_text())
        return posts_address, posts_time


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


<mask token>


def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding=
        'utf-8')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\\[|\\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    return title, updatetime, 'http://www.h3c.com' + url


<mask token>


def Dell_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    ret = requests.get(
        'https://www.dell.com/support/security/zh-cn/Security/Article?articleType=advisory'
        )
    j = json.loads(ret.text)
    output = []
    for ji in j:
        fp = re.findall('\\d+-\\d+-\\d\\d', ji['FirstPublished'])[0]
        if fp in days:
            ji.pop('IsAuthRequired')
            ji.pop('ArticleId')
            ji.pop('CVEIdentifier')
            ji.pop('Severity')
            ji.pop('AccessLevel')
            ji.pop('Source')
            ji.pop('Type')
            ji.pop('IsDell')
            ji.pop('SeverityOrder')
            output.append(ji)
    return output


def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1'
        )
    if check_soup(soup.html):
        return None
    print(soup.html)


def HPE_update_checker():
    url = (
        'https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 '
        )
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get(url)
    time.sleep(15)
    div = browser.find_element_by_id('resultList-container')
    text = div.text
    text = re.split('\n', text)
    text = text[0]
    print(text)
    browser.quit()


def HUAWEI_update_checker():
    soup = Soup('https://www.huawei.com/cn/psirt/all-bulletins')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='col-sm-7 col-sm-offset-1')
    h3 = div.select('div div div li')
    title = h3[0].select('li a')[0].get_text()
    title = re.sub('\r\n\\s+', '', title)
    updatetime = h3[0].select('li span')[0].get_text()
    url = h3[0].select('li a')[0].get('href')
    return title, updatetime, 'https://www.huawei.com' + url


def CNVD_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://www.cnvd.org.cn/webinfo/list?type=14')
    time.sleep(12)
    input = browser.find_element_by_class_name('tlist')
    input = input.find_element_by_tag_name('tbody')
    input = input.find_element_by_class_name('current')
    title = input.text
    href = input.find_element_by_tag_name('a').get_attribute('href')
    update_time = re.findall('\\d+-\\d+-\\d\\d', title)[0]
    title = re.split(' ', title)[0]
    browser.quit()
    report = '无安全公告更新'
    if update_time in days:
        report = CNVD_report_checker(href)
        if len(report) == 0:
            report = '最新公告与产品线无关'
    return report


def CNVD_report_checker(href):
    pf = processing_file()
    browser = webdriver.Firefox()
    browser.get(href)
    time.sleep(12)
    report = browser.find_element_by_class_name('blkContainerSblk')
    text = report.text
    browser.quit()
    return pf.exec_filtering_CNVD_report(text)


def lenovo_update_checker():
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://support.lenovo.com/us/en/product_security/home')
    time.sleep(10)
    div = browser.find_element_by_id('detailBody')
    table = div.find_element_by_tag_name('table')
    text = table.text
    text = re.split('\n', text)
    text = text[5]
    timere = '\\d\\d\\d\\d-\\d\\d-\\d\\d'
    updatetime = re.findall(timere, text)
    firstpublished = updatetime[0]
    lastupdated = updatetime[1]
    title = re.sub('LEN\\S+\\s', '', text)
    title = re.sub('\\sCVE.+', '', title)
    browser.quit()
    return title, firstpublished, lastupdated


<mask token>


def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))
    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ',
        CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()
    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start(
        )
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ',
        Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())

<mask token>
soup = Soup(
    'https://www.intel.com/content/www/us/en/security-center/default.html')


def parse(soup):
    if check_soup(soup.html):
        return [failed_soup, failed_soup, failed_soup, failed_soup, failed_soup
            ]
    div = soup.html.find('div', class_='table-responsive')
    td = div.select('div tr td')
    print(td[2].get_text())


def Intel_update_checker():
    soup = Soup(
        'https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + td[0].select(
            'div a')[0].get('href')


def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(sub[0].select('div a')[0].get('href'))
            posts_time.append(sub[1].get_text())
        return posts_address, posts_time


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


def CNVD_update_checker_ERR():
    header = {'Cookie':
        '__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b;JSESSIONID=9F5034F8F05C962FD9193EB14B2A091D;__jsl_clearance=1591151886.029|0|O7hmYtY7baM3UwXmh%2BAxXCqcwD0%3D'
        , 'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'
        }
    soup = Soup('https://www.cnvd.org.cn/webinfo/list?type=14', header=header)
    print(soup.req_header)
    print(soup.html)
    if check_soup(soup.html):
        return None
    table = soup.html.find('div', class_='blkContainerPblk')
    tr = table.select('table tbody tr')
    print(tr)
    name = tr[0].get_text()
    print(name)


def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding=
        'utf-8')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\\[|\\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    return title, updatetime, 'http://www.h3c.com' + url


def Lenovo_update_checker():
    soup = Soup('https://support.lenovo.com/us/en/product_security/home')
    print(soup.html)
    if check_soup(soup.html):
        return None
    div = soup.html.find_all('div', class_='right-area')


def Dell_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    ret = requests.get(
        'https://www.dell.com/support/security/zh-cn/Security/Article?articleType=advisory'
        )
    j = json.loads(ret.text)
    output = []
    for ji in j:
        fp = re.findall('\\d+-\\d+-\\d\\d', ji['FirstPublished'])[0]
        if fp in days:
            ji.pop('IsAuthRequired')
            ji.pop('ArticleId')
            ji.pop('CVEIdentifier')
            ji.pop('Severity')
            ji.pop('AccessLevel')
            ji.pop('Source')
            ji.pop('Type')
            ji.pop('IsDell')
            ji.pop('SeverityOrder')
            output.append(ji)
    return output


def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1'
        )
    if check_soup(soup.html):
        return None
    print(soup.html)


def HPE_update_checker():
    url = (
        'https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 '
        )
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get(url)
    time.sleep(15)
    div = browser.find_element_by_id('resultList-container')
    text = div.text
    text = re.split('\n', text)
    text = text[0]
    print(text)
    browser.quit()


def HUAWEI_update_checker():
    soup = Soup('https://www.huawei.com/cn/psirt/all-bulletins')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='col-sm-7 col-sm-offset-1')
    h3 = div.select('div div div li')
    title = h3[0].select('li a')[0].get_text()
    title = re.sub('\r\n\\s+', '', title)
    updatetime = h3[0].select('li span')[0].get_text()
    url = h3[0].select('li a')[0].get('href')
    return title, updatetime, 'https://www.huawei.com' + url


def CNVD_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://www.cnvd.org.cn/webinfo/list?type=14')
    time.sleep(12)
    input = browser.find_element_by_class_name('tlist')
    input = input.find_element_by_tag_name('tbody')
    input = input.find_element_by_class_name('current')
    title = input.text
    href = input.find_element_by_tag_name('a').get_attribute('href')
    update_time = re.findall('\\d+-\\d+-\\d\\d', title)[0]
    title = re.split(' ', title)[0]
    browser.quit()
    report = '无安全公告更新'
    if update_time in days:
        report = CNVD_report_checker(href)
        if len(report) == 0:
            report = '最新公告与产品线无关'
    return report


def CNVD_report_checker(href):
    pf = processing_file()
    browser = webdriver.Firefox()
    browser.get(href)
    time.sleep(12)
    report = browser.find_element_by_class_name('blkContainerSblk')
    text = report.text
    browser.quit()
    return pf.exec_filtering_CNVD_report(text)


def lenovo_update_checker():
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://support.lenovo.com/us/en/product_security/home')
    time.sleep(10)
    div = browser.find_element_by_id('detailBody')
    table = div.find_element_by_tag_name('table')
    text = table.text
    text = re.split('\n', text)
    text = text[5]
    timere = '\\d\\d\\d\\d-\\d\\d-\\d\\d'
    updatetime = re.findall(timere, text)
    firstpublished = updatetime[0]
    lastupdated = updatetime[1]
    title = re.sub('LEN\\S+\\s', '', text)
    title = re.sub('\\sCVE.+', '', title)
    browser.quit()
    return title, firstpublished, lastupdated


<mask token>


def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))
    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ',
        CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()
    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start(
        )
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ',
        Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())

import os
import re
import json
import time
import threading
import requests
from core.const import failed_soup
from core.soup import Soup
from core.utils import check_soup
import datetime
from core.vul_filter import processing_file
from selenium import webdriver
soup = Soup(
    'https://www.intel.com/content/www/us/en/security-center/default.html')


def parse(soup):
    if check_soup(soup.html):
        return [failed_soup, failed_soup, failed_soup, failed_soup, failed_soup
            ]
    div = soup.html.find('div', class_='table-responsive')
    td = div.select('div tr td')
    print(td[2].get_text())


def Intel_update_checker():
    soup = Soup(
        'https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + td[0].select(
            'div a')[0].get('href')


def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(sub[0].select('div a')[0].get('href'))
            posts_time.append(sub[1].get_text())
        return posts_address, posts_time


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


def CNVD_update_checker_ERR():
    header = {'Cookie':
        '__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b;JSESSIONID=9F5034F8F05C962FD9193EB14B2A091D;__jsl_clearance=1591151886.029|0|O7hmYtY7baM3UwXmh%2BAxXCqcwD0%3D'
        , 'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'
        }
    soup = Soup('https://www.cnvd.org.cn/webinfo/list?type=14', header=header)
    print(soup.req_header)
    print(soup.html)
    if check_soup(soup.html):
        return None
    table = soup.html.find('div', class_='blkContainerPblk')
    tr = table.select('table tbody tr')
    print(tr)
    name = tr[0].get_text()
    print(name)


def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding=
        'utf-8')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\\[|\\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    return title, updatetime, 'http://www.h3c.com' + url


def Lenovo_update_checker():
    soup = Soup('https://support.lenovo.com/us/en/product_security/home')
    print(soup.html)
    if check_soup(soup.html):
        return None
    div = soup.html.find_all('div', class_='right-area')


def Dell_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    ret = requests.get(
        'https://www.dell.com/support/security/zh-cn/Security/Article?articleType=advisory'
        )
    j = json.loads(ret.text)
    output = []
    for ji in j:
        fp = re.findall('\\d+-\\d+-\\d\\d', ji['FirstPublished'])[0]
        if fp in days:
            ji.pop('IsAuthRequired')
            ji.pop('ArticleId')
            ji.pop('CVEIdentifier')
            ji.pop('Severity')
            ji.pop('AccessLevel')
            ji.pop('Source')
            ji.pop('Type')
            ji.pop('IsDell')
            ji.pop('SeverityOrder')
            output.append(ji)
    return output


def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1'
        )
    if check_soup(soup.html):
        return None
    print(soup.html)


def HPE_update_checker():
    url = (
        'https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 '
        )
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get(url)
    time.sleep(15)
    div = browser.find_element_by_id('resultList-container')
    text = div.text
    text = re.split('\n', text)
    text = text[0]
    print(text)
    browser.quit()


def HUAWEI_update_checker():
    soup = Soup('https://www.huawei.com/cn/psirt/all-bulletins')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='col-sm-7 col-sm-offset-1')
    h3 = div.select('div div div li')
    title = h3[0].select('li a')[0].get_text()
    title = re.sub('\r\n\\s+', '', title)
    updatetime = h3[0].select('li span')[0].get_text()
    url = h3[0].select('li a')[0].get('href')
    return title, updatetime, 'https://www.huawei.com' + url


def CNVD_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://www.cnvd.org.cn/webinfo/list?type=14')
    time.sleep(12)
    input = browser.find_element_by_class_name('tlist')
    input = input.find_element_by_tag_name('tbody')
    input = input.find_element_by_class_name('current')
    title = input.text
    href = input.find_element_by_tag_name('a').get_attribute('href')
    update_time = re.findall('\\d+-\\d+-\\d\\d', title)[0]
    title = re.split(' ', title)[0]
    browser.quit()
    report = '无安全公告更新'
    if update_time in days:
        report = CNVD_report_checker(href)
        if len(report) == 0:
            report = '最新公告与产品线无关'
    return report


def CNVD_report_checker(href):
    pf = processing_file()
    browser = webdriver.Firefox()
    browser.get(href)
    time.sleep(12)
    report = browser.find_element_by_class_name('blkContainerSblk')
    text = report.text
    browser.quit()
    return pf.exec_filtering_CNVD_report(text)


def lenovo_update_checker():
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    options.add_argument('headless')
    browser.get('https://support.lenovo.com/us/en/product_security/home')
    time.sleep(10)
    div = browser.find_element_by_id('detailBody')
    table = div.find_element_by_tag_name('table')
    text = table.text
    text = re.split('\n', text)
    text = text[5]
    timere = '\\d\\d\\d\\d-\\d\\d-\\d\\d'
    updatetime = re.findall(timere, text)
    firstpublished = updatetime[0]
    lastupdated = updatetime[1]
    title = re.sub('LEN\\S+\\s', '', text)
    title = re.sub('\\sCVE.+', '', title)
    browser.quit()
    return title, firstpublished, lastupdated


<mask token>


def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))
    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ',
        CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()
    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
        '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start(
        )
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ',
        Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看'
        )
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())

import os
import re
import json
import time
import threading
import requests
#import execjs

from core.const import failed_soup
from core.soup import Soup
from core.utils import check_soup
import datetime
from core.vul_filter import processing_file
from selenium import webdriver

soup = Soup('https://www.intel.com/content/www/us/en/security-center/default.html')


def parse(soup):
    if check_soup(soup.html):
        return [failed_soup, failed_soup, failed_soup, failed_soup, failed_soup]
    div = soup.html.find('div', class_='table-responsive')
    td = div.select('div tr td')
    print(td[2].get_text())


# Intel站 输出最新标题和最新更新时间 为确定其更新与否 只需返回最上层的漏洞更新日期即可
def Intel_update_checker():
    soup = Soup('https://www.intel.com/content/www/us/en/security-center/default.html')
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='table-responsive')
        td = div.select('div tr td')
        title = td[0].get_text()
        updatetime = td[3].get_text()
        title = re.sub('\\xa0', ' ', title)
        title = re.sub('\\n', '', title)
        updatetime = re.sub('\\n', '', updatetime)
        return title, updatetime, 'https://www.intel.com' + (td[0].select('div a'))[0].get('href')


# CNNVD漏洞预警 返回最新文章地址及时间
def CNNVD_notice():
    soup = Soup('http://www.cnnvd.org.cn/web/cnnvdnotice/querylist.tag')
    # print(soup.header)
    if check_soup(soup.html):
        return None
    else:
        div = soup.html.find('div', class_='list_list')
        subdiv = div.select('div ul li')
        posts_address = []
        posts_time = []
        for sub in subdiv:
            sub = sub.select('li div')
            posts_address.append(((sub[0].select('div a'))[0]).get('href'))
            posts_time.append(sub[1].get_text())

        # print(len(posts_time), len(posts_address))
        return posts_address, posts_time
        # print(subdiv)


def CNNVD_update_checker(days_count):
    posts_address, posts_time = CNNVD_notice()
    today = datetime.date.today()
    days = [str(today)]
    output = []
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    for i in range(0, len(posts_time)):
        if posts_time[i] in days:
            output.append('http://www.cnnvd.org.cn' + posts_address[i])
    return output


# Cookie是动态的所以暂时搁置对CNVD的Coding
def CNVD_update_checker_ERR():
    # Cookie和user-agent相关所以需要手动修改请求头
    header = {  # 'Upgrade-Insecure-Requests': '1',
        'Cookie': '__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b;JSESSIONID=9F5034F8F05C962FD9193EB14B2A091D;__jsl_clearance=1591151886.029|0|O7hmYtY7baM3UwXmh%2BAxXCqcwD0%3D',
        # 'Host': 'www.cnvd.org.cn', 'Accept-Encoding': 'gzip, deflate, br',
        # 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        # 'Connection': 'keep-alive',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'}
    soup = Soup('https://www.cnvd.org.cn/webinfo/list?type=14', header=header)
    # soup.header['Upgrade-Insecure-Requests']='1'
    # soup.header['Cookie']='__jsluid_s=712cd7ef2bf6548dc3307a0af3acb55b; __jsl_clearance=1591065994.349|0|QA3ffs2Ye8hD9txZPdNIy3Eg5LA%3D'
    # soup=soup.make_soup()
    print(soup.req_header)
    print(soup.html)
    if check_soup(soup.html):
        return None
    table = soup.html.find('div', class_='blkContainerPblk')
    # print(table)
    tr = table.select('table tbody tr')
    print(tr)
    name = tr[0].get_text()
    print(name)


# 对H3C更新情况进行检查
def H3C_update_checker():
    soup = Soup('http://www.h3c.com/cn/Service/Service_Notice/', encoding='utf-8')
    if check_soup(soup.html):
        return None
    # print(soup.html)
    div = soup.html.find('div', class_='big_sj blueA blueA1')
    # print(div)
    title = div.select('div a')[0].get_text()
    updatetime = div.select('div span')[0].get_text()
    updatetime = re.sub('\[|\]', '', updatetime)
    url = div.select('div a')[0].get('href')
    # print(updatetime)
    return title, updatetime, 'http://www.h3c.com' + url


# Lenovo网页的漏洞数据不是随主html页面一起返回 没能找到返回所在的包 暂时搁置
def Lenovo_update_checker():
    soup = Soup('https://support.lenovo.com/us/en/product_security/home')
    print(soup.html)
    if check_soup(soup.html):
        return None
    div = soup.html.find_all('div', class_='right-area')
    # print(div)


# 返回字典列表，其中每个字典代表时间命中的一条漏洞信息，待解析
def Dell_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    ret = requests.get('https://www.dell.com/support/security/zh-cn/Security/Article?articleType=advisory')
    # ret.encoding='utf-8'
    j = json.loads(ret.text)
    output = []
    for ji in j:
        fp = re.findall('\d+-\d+-\d\d', ji['FirstPublished'])[0]
        if fp in days:
            ji.pop('IsAuthRequired')
            ji.pop('ArticleId')
            ji.pop('CVEIdentifier')
            ji.pop('Severity')
            ji.pop('AccessLevel')
            ji.pop('Source')
            ji.pop('Type')
            ji.pop('IsDell')
            ji.pop('SeverityOrder')
            output.append(ji)
    # print(re.findall('\d+-\d+-\d\d',j[0]['FirstPublished']))
    # for ji in j:
    #   print(ji['FirstPublished']+'   '+ji['LastPublished'])
    # print(j[0])
    return output


# HPE原安全公告地址被更换，故在此采用新版的安全公告地址
# https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=date%20descending&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1
# 该网站也是不把结果包含在初始html应答中，且对结果数据的请求需要认证 待fix
def HPE_update_checker_err(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    lastday = today - datetime.timedelta(days=days_count)
    # soup=Soup(f"https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=date%20descending&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[{lastday.year}%2F{lastday.month}%2F{lastday.day}%4016%3A00%3A00..{today.year}%2F{today.month}%2F{today.day}%4016%3A00%3A00]&hpe=1")
    soup = Soup(
        'https://support.hpe.com/hpesc/public/km/search#t=Documents&sort=relevancy&layout=table&numberOfResults=25&f:@kmdoctypedetails=[cv66000018]&f:@kmdoclanguagecode=[cv1871454,cv1871440]&f:@hpescuniversaldate=[2020%2F05%2F26%4016%3A00%3A00..2020%2F06%2F03%4016%3A00%3A00]&hpe=1')
    if check_soup(soup.html):
        return None
    print(soup.html)
    # table=soup.html.find('table',class_='coveo-result-list-container coveo-table-layout-container')
    # print(table)


# 返回HPE的title和时间字符串
def HPE_update_checker():
    url = 'https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
          '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 '
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get(url)
    time.sleep(15)
    div = browser.find_element_by_id('resultList-container')
    text = div.text
    text = re.split('\n', text)
    text = text[0]
    print(text)
    browser.quit()


# 返回华为最新更新漏洞条目
def HUAWEI_update_checker():
    soup = Soup('https://www.huawei.com/cn/psirt/all-bulletins')
    if check_soup(soup.html):
        return None
    div = soup.html.find('div', class_='col-sm-7 col-sm-offset-1')
    h3 = div.select('div div div li')
    # print(h3)
    title = (h3[0].select('li a'))[0].get_text()
    title = re.sub('\r\n\s+', '', title)
    updatetime = (h3[0].select('li span'))[0].get_text()
    url = (h3[0].select('li a'))[0].get('href')
    return title, updatetime, 'https://www.huawei.com' + url
    # print(div)


# 返回CNVD是否有最新报告及是否与产品线相关
def CNVD_update_checker(days_count):
    today = datetime.date.today()
    days = [str(today)]
    for i in range(1, days_count):
        days.append(str(today - datetime.timedelta(days=i)))
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get('https://www.cnvd.org.cn/webinfo/list?type=14')
    time.sleep(12)
    # html = browser.page_source
    input = browser.find_element_by_class_name('tlist')
    input = input.find_element_by_tag_name('tbody')
    input = input.find_element_by_class_name('current')
    title = input.text
    href = input.find_element_by_tag_name('a').get_attribute('href')
    # print(input.text + '    ' + input.find_element_by_tag_name('a').get_attribute('href'))
    update_time = re.findall('\d+-\d+-\d\d', title)[0]
    title = re.split(' ', title)[0]
    browser.quit()
    report = '无安全公告更新'
    if update_time in days:
        report = CNVD_report_checker(href)
        if len(report) == 0:
            report = '最新公告与产品线无关'
    return report


def CNVD_report_checker(href):
    pf = processing_file()
    browser = webdriver.Firefox()
    browser.get(href)
    time.sleep(12)
    report = browser.find_element_by_class_name('blkContainerSblk')
    text = report.text
    browser.quit()
    return pf.exec_filtering_CNVD_report(text)


# 返回LENOVO最新更新公告名称 初次公开时间和更新时间
def lenovo_update_checker():
    browser = webdriver.Firefox()
    options = webdriver.FirefoxOptions()
    # 向后兼容，或许之后Firefox也会出headless模式
    options.add_argument('headless')
    browser.get('https://support.lenovo.com/us/en/product_security/home')
    time.sleep(10)
    div = browser.find_element_by_id('detailBody')
    table = div.find_element_by_tag_name('table')
    text = table.text
    text = re.split('\n', text)
    text = text[5]
    timere = '\d\d\d\d-\d\d-\d\d'
    updatetime = re.findall(timere, text)
    firstpublished = updatetime[0]
    lastupdated = updatetime[1]
    title = re.sub('LEN\S+\s', '', text)
    title = re.sub('\sCVE.+', '', title)
    browser.quit()
    return title, firstpublished, lastupdated

'''
# 在运行的过程中始终报错 不能像浏览器一样得出预期结果 故舍弃
def getCookieFromJs():
    url = 'https://www.cnvd.org.cn/webinfo/list?type=14'
    os.environ["EXECJS_RUNTIME"] = "Node.js"
    print(execjs.get().name)
    req = requests.get(url).text
    print(req)
    req = re.sub('<script>', '', req)
    req = re.sub('</script>', '', req)
    # req='function a(){'+req+'}'
    # print(req)
    jsfunction = execjs.compile(req)
    jsfunction.call('_1r')
    # jsfunction=execjs.compile('function a() {'+req+' }')

    # jsfunction.call('a')
    # print(req)
'''

def vul_check(days_count):
    print('Intel最新更新公告: ', Intel_update_checker())
    print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))
    print('CNVD: ', CNVD_update_checker(days_count))

    print('H3C最新更新公告: ', H3C_update_checker())
    print('lenovo最新更新公告: ', lenovo_update_checker(), '请于 https://support.lenovo.com/us/en/product_security/home 查看')
    print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
        '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看')
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())


# 多线程版本比非多线程版本快一些
def multithread_vul_check(days_count):
    threading.Thread(print('Intel最新更新公告: ', Intel_update_checker())).start()
    threading.Thread(print(f'CNNVD在{days_count}天中更新的公告列表: ', CNNVD_update_checker(days_count))).start()
    threading.Thread(print('CNVD: ', CNVD_update_checker(days_count))).start()

    threading.Thread(print('H3C最新更新公告: ', H3C_update_checker())).start()
    threading.Thread(print('lenovo最新更新公告: ', lenovo_update_checker(),
                           '请于 https://support.lenovo.com/us/en/product_security/home 查看')).start()
    threading.Thread(print(f'Dell在{days_count}天中更新的公告列表: ', Dell_update_checker(days_count))).start()
    print('HPE最新更新公告: ')
    HPE_update_checker()
    print(
        'HPE公告详情情于 https://support.hpe.com/hpesc/public/km/search#t=All&sort=%40hpescuniversaldate%20descending&numberOfResults' \
        '=25&f:@kmdoclanguagecode=[cv1871454,cv1871440]&hpe=1 查看')
    print('HUAWEI最新更新公告: ', HUAWEI_update_checker())

