feat: RSS of cve.mitre.org (#4599)

This commit is contained in:
fengkx
2020-04-29 14:08:32 +08:00
committed by GitHub
parent 87e9c8782c
commit d48150562f
4 changed files with 41 additions and 0 deletions

View File

@@ -4,6 +4,12 @@ pageClass: routes
# Programming
## cve.mitre.org
### Search Result
<Route author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['keyword'] >
## GitHub
::: tip

View File

@@ -18,6 +18,12 @@ pageClass: routes
> AlgoCasts 需要付费订阅, RSS 仅做更新提醒, 不含付费内容.
## cve.mitre.org
### 搜索结果
<Route author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['关键词'] >
## Dockone
### 周报

View File

@@ -2607,4 +2607,7 @@ router.get('/unit-image/films/:type?', require('./routes/unit-image/films'));
// digic-picture
router.get('/digic-pictures/:menu/:tags?', require('./routes/digic-pictures/index'));
// cve.mitre.org
router.get('/cve/search/:keyword', require('./routes/cve/search'));
module.exports = router;

26
lib/routes/cve/search.js Normal file
View File

@@ -0,0 +1,26 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx, next) => {
const { keyword } = ctx.params;
const link = `https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=${keyword}`;
const body = await got(link).text();
const $ = cheerio.load(body);
const rows = $('#TableWithRules').find('tbody').first().find('tr').get().slice(0, 10);
const item = rows.map((row) => {
const [cveName, description] = $(row).find('td').get().map($);
return {
title: cveName.text(),
link: 'https://cve.mitre.org' + cveName.find('a').first().attr('href'),
description: description.text(),
guid: this.link,
};
});
ctx.state.data = {
title: `CVE search result ${keyword}`,
link,
description: this.title,
item,
};
await next();
};