2022-11-15 00:14:17 +09:00
|
|
|
import Consola from 'consola';
|
2022-06-06 17:13:17 +02:00
|
|
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
|
|
|
|
|
|
function Post(req: NextApiRequest, res: NextApiResponse) {
|
2023-03-21 11:35:07 +08:00
|
|
|
const { tried, type = 'password' } = req.body;
|
|
|
|
|
// If the type of password is "edit", we run this branch to check the edit password
|
|
|
|
|
if (type === 'edit') {
|
2023-09-03 17:54:12 +02:00
|
|
|
if (tried === process.env.EDIT_MODE_PASSWORD) {
|
2023-07-26 13:17:00 +09:00
|
|
|
if (process.env.DISABLE_EDIT_MODE?.toLowerCase() === 'true') {
|
|
|
|
|
process.env.DISABLE_EDIT_MODE = 'false';
|
|
|
|
|
} else {
|
|
|
|
|
process.env.DISABLE_EDIT_MODE = 'true';
|
|
|
|
|
}
|
2023-03-21 11:35:07 +08:00
|
|
|
return res.status(200).json({
|
|
|
|
|
success: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (tried === process.env.PASSWORD) {
|
2022-06-06 17:13:17 +02:00
|
|
|
return res.status(200).json({
|
|
|
|
|
success: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-15 00:14:17 +09:00
|
|
|
Consola.warn(
|
2022-11-17 20:16:43 +09:00
|
|
|
`${new Date().toLocaleString()} : Wrong password attempt, from ${
|
2022-11-15 00:14:17 +09:00
|
|
|
req.headers['x-forwarded-for']
|
|
|
|
|
}`
|
|
|
|
|
);
|
2023-03-21 11:35:07 +08:00
|
|
|
return res.status(401).json({
|
2022-06-06 17:13:17 +02:00
|
|
|
success: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
|
return Post(req, res);
|
|
|
|
|
}
|
|
|
|
|
return res.status(405).json({
|
|
|
|
|
statusCode: 405,
|
|
|
|
|
message: 'Method not allowed',
|
|
|
|
|
});
|
|
|
|
|
};
|