Files
code-center/src/modules/off/ban.ts
2025-12-06 18:48:46 +08:00

62 lines
1.4 KiB
TypeScript

// 常备黑的 http://web/ban/
// 禁止使用这些用户名注册
// 容易被黑客扫描, 也容易被滥用
//
export const bannedUserNames = [
"admin", // 常见管理员名
"user", // 常见用户名
"guest", // 常见访客名
"core", // 常见系统名
"config", // 配置相关
"system", // 系统相关
"setting", // 设置相关
"storage", // 存储相关
"logs", // 日志相关
"log", // 日志相关
"backup", // 备份相关
"backups", // 备份相关
"tmp", // 临时相关
"var", // 变量相关
"www", // 网站相关
"app", // 应用相关
]
/**
* 检查用户名是否在禁止列表中
* @param username
* @returns
*/
export const userIsBanned = (username: string): boolean => {
if (username.startsWith('.')) {
return true;
}
if (username.endsWith('.')) {
return true;
}
return bannedUserNames.includes(username.toLowerCase());
}
export const appIsBanned = (appname: string): boolean => {
if (appname.startsWith('.')) {
return true;
}
if (appname.endsWith('.')) {
return true;
}
return false;
}
export const userPathIsBanned = (appname: string): boolean => {
if (appname.startsWith('.')) {
return true;
}
if (appname.endsWith('.')) {
return true;
}
const bans = ['.php', '.json', '.yml', '.db', '.env', '.backup', 'database.sql', 'db.sql', 'backup.zip',];
if (bans.some(ban => appname.includes(ban))) {
return true;
}
return false;
}