Skip to content

Commit

Permalink
feat: RSS of cve.mitre.org (DIYgod#4599)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengkx authored Apr 29, 2020
1 parent 87e9c87 commit d481505
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pageClass: routes

> AlgoCasts 需要付费订阅, RSS 仅做更新提醒, 不含付费内容.
## cve.mitre.org

### 搜索结果

<Route author="fengkx" example="/cve/search/PostgreSQL" path="/cve/search/:keyword" :paramsDesc="['关键词'] >

## Dockone

### 周报
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 26 additions & 0 deletions lib/routes/cve/search.js
Original file line number Diff line number Diff line change
@@ -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();
};

0 comments on commit d481505

Please sign in to comment.