Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Next update
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbenpai committed Mar 18, 2024
1 parent 745a9ab commit 582a793
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 6 deletions.
2 changes: 2 additions & 0 deletions web/api/routes/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CCrypto = require('../../../modules/CCrypto')

router
.get('/enc', async (req, res) => {
if (!req.query) return res.sendError(4)
const { query: { data } } = req;
if (!data) return res.sendError(4)
try {
Expand All @@ -12,6 +13,7 @@ router
}
})
.get('/dec', async (req, res) => {
if (!req.query) return res.sendError(4)
const { query: { data } } = req;
if (!data) return res.sendError(4)
try {
Expand Down
17 changes: 16 additions & 1 deletion web/pages/routes/alex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ router
.get('/', (_, res) => res.render('pages/alex/index.pug'))
.get('/cdn/img/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/alex/imgs/${req.params.file}`))
.get('/cdn/js/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/alex/js/${req.params.file}.js`))
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/alex/css/${req.params.file}.css`));
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/alex/css/${req.params.file}.css`))
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
17 changes: 16 additions & 1 deletion web/pages/routes/ben.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ router
))
.get('/cdn/img/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/ben/imgs/${req.params.file}`))
.get('/cdn/js/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/ben/js/${req.params.file}.js`))
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/ben/css/${req.params.file}.css`));
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/ben/css/${req.params.file}.css`))
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
17 changes: 16 additions & 1 deletion web/pages/routes/oblong.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ router
))
.get('/cdn/img/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/oblong/imgs/${req.params.file}`))
.get('/cdn/js/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/oblong/js/${req.params.file}.js`))
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/oblong/css/${req.params.file}.css`));
.get('/cdn/css/:file', (req, res) => res.sendFile(`${process.cwd()}/web/pages/assets/oblong/css/${req.params.file}.css`))
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
15 changes: 15 additions & 0 deletions web/security/routes/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,20 @@ router
break;
}
})
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
17 changes: 16 additions & 1 deletion web/security/routes/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ const router = require('express').Router();
router
.post('/new', (req, res) => {
res.status(204).end();
});
})
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
17 changes: 16 additions & 1 deletion web/security/routes/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ const router = require('express').Router();
router
.post('/new', (req, res) => {
res.status(204).end();
});
})
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
})

module.exports = router;
17 changes: 16 additions & 1 deletion web/security/routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ const Report = require('./report');
router
.use('/doc', Doc)
.use('/report', Report)
.use('/csp', CSP);
.use('/csp', CSP)
.use((req, res, next) => {
const { path } = req;
const methodUsed = req.method.toUpperCase();
let allowedMethods = router.stack.filter(r => r.route && r.route.path === path)
if (allowedMethods.length == 0) return next();
allowedMethods.map(r => r.route.stack[0])
allowedMethods = { ...allowedMethods[0] }
allowedMethods = allowedMethods.route.methods;
if (req.method === 'OPTIONS') return res.setHeader('Allow', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).setHeader('Access-Control-Allow-Methods', Object.keys(allowedMethods).map(m => m.toUpperCase()).join(', ')).status(204).send();
if (allowedMethods[methodUsed]) return next();
res.status(405).render(
`misc/405.pug`,
req.getErrPage(405, { path, allowedMethods, methodUsed })
);
});

module.exports = router;

0 comments on commit 582a793

Please sign in to comment.