fix(route): Fix nosec (#14785)

* 迁移nosec路由

* 迁移nosec路由
This commit is contained in:
zcw159357 2024-03-18 03:36:46 +08:00 committed by GitHub
parent 527f44a565
commit d6805e5dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 8 deletions

View File

@ -1010,7 +1010,7 @@ router.get('/project-zero-issues', lazyloadRouteHandler('./routes/project-zero-i
router.get('/galaxylab', lazyloadRouteHandler('./routes/galaxylab/index'));
// NOSEC 安全讯息平台
router.get('/nosec/:keykind?', lazyloadRouteHandler('./routes/nosec/index'));
// router.get('/nosec/:keykind?', lazyloadRouteHandler('./routes/nosec/index'));
// discuz
// router.get('/discuz/:ver([7|x])/:cid([0-9]{2})/:link(.*)', lazyloadRouteHandler('./routes/discuz/discuz'));

View File

@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
const baseUrl = 'https://nosec.org/home/ajaxindexdata';
const keykinds = {
@ -12,15 +13,34 @@ const keykinds = {
tool: '安全工具',
};
module.exports = async (ctx) => {
export const route: Route = {
path: '/:keykind?',
categories: ['programming'],
example: '/nosec/hole',
parameters: { keykind: '对应文章分类' },
name: 'Posts',
maintainers: ['hellodword'],
description: ` | 分类 | 标识 |
| :------- | :--------- |
| | \`threaten\` |
| | \`security\` |
| | \`hole\` |
| | \`leakage\` |
| | \`speech\` |
| | \`skill\` |
| | \`tool\` |`,
handler,
};
async function handler(ctx) {
const csrfresponse = await got.get('https://nosec.org/home/index');
const $ = cheerio.load(csrfresponse.data);
const $ = load(csrfresponse.data);
const token = $('meta[name="csrf-token"]').attr('content');
const cookies = csrfresponse.headers['set-cookie'].toString();
const xsrf_token = cookies.match(/XSRF-TOKEN=[^\s;]+/)[0];
const laravel_session = cookies.match(/laravel_session[^\s;]+/)[0];
const keykind = ctx.params.keykind || '';
const keykind = ctx.req.param('keykind') || '';
let formdata;
let title;
let link;
@ -50,7 +70,7 @@ module.exports = async (ctx) => {
const data = response.data.data.threatData.data;
ctx.state.data = {
return {
// 源标题
title,
// 源链接
@ -70,4 +90,4 @@ module.exports = async (ctx) => {
author: item.username,
})),
};
};
};

View File

@ -0,0 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'NOSEC.org',
url: 'nosec.org',
};