mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00

- 重命名 Common -> common,WebScan -> webscan,遵循 Go 包命名约定 - 修复模块路径大小写不匹配导致的编译错误 - 清理依赖项,优化 go.mod 文件 - 添加 Docker 测试环境配置文件 - 新增镜像拉取脚本以处理网络超时问题 - 成功编译生成 fscan v2.2.1 可执行文件 该修复解决了 Linux 系统下包名大小写敏感导致的模块解析失败问题。
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// ServiceDictionary 服务字典管理器
|
|
type ServiceDictionary struct {
|
|
mu sync.RWMutex
|
|
userDict map[string][]string
|
|
passwords []string
|
|
initialized bool
|
|
}
|
|
|
|
// NewServiceDictionary 创建服务字典管理器
|
|
func NewServiceDictionary() *ServiceDictionary {
|
|
return &ServiceDictionary{
|
|
userDict: getDefaultUserDict(),
|
|
passwords: getDefaultPasswords(),
|
|
initialized: true,
|
|
}
|
|
}
|
|
|
|
// getDefaultUserDict 获取默认用户字典
|
|
func getDefaultUserDict() map[string][]string {
|
|
// 返回常量的深拷贝
|
|
result := make(map[string][]string)
|
|
for service, users := range DefaultUserDict {
|
|
usersCopy := make([]string, len(users))
|
|
copy(usersCopy, users)
|
|
result[service] = usersCopy
|
|
}
|
|
return result
|
|
}
|
|
|
|
// getDefaultPasswords 获取默认密码字典
|
|
func getDefaultPasswords() []string {
|
|
// 返回常量的副本
|
|
result := make([]string, len(DefaultPasswords))
|
|
copy(result, DefaultPasswords)
|
|
return result
|
|
}
|
|
|
|
// GetAllUserDicts 获取所有服务的用户字典
|
|
func (sd *ServiceDictionary) GetAllUserDicts() map[string][]string {
|
|
sd.mu.RLock()
|
|
defer sd.mu.RUnlock()
|
|
|
|
result := make(map[string][]string)
|
|
for service, users := range sd.userDict {
|
|
usersCopy := make([]string, len(users))
|
|
copy(usersCopy, users)
|
|
result[service] = usersCopy
|
|
}
|
|
return result
|
|
}
|
|
|
|
// GetPasswords 获取默认密码字典
|
|
func (sd *ServiceDictionary) GetPasswords() []string {
|
|
sd.mu.RLock()
|
|
defer sd.mu.RUnlock()
|
|
|
|
// 返回副本,避免外部修改
|
|
result := make([]string, len(sd.passwords))
|
|
copy(result, sd.passwords)
|
|
return result
|
|
}
|
|
|
|
|
|
// 全局服务字典实例
|
|
var (
|
|
globalServiceDict *ServiceDictionary
|
|
serviceDictOnce sync.Once
|
|
)
|
|
|
|
// GetGlobalServiceDict 获取全局服务字典实例
|
|
func GetGlobalServiceDict() *ServiceDictionary {
|
|
serviceDictOnce.Do(func() {
|
|
globalServiceDict = NewServiceDictionary()
|
|
})
|
|
return globalServiceDict
|
|
} |