mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
refactor: 重命名common/core为common/base并移除LegacyParser中间层
- 重命名common/core包为common/base,解决与根目录core包名冲突问题 - 移除common/parsers/LegacyParser.go向后兼容层,简化代码架构 - 将SimpleParseIP/SimpleParsePort等函数重命名为ParseIP/ParsePort - 更新所有相关引用和导入路径 - 删除41行冗余代码,提升代码可维护性
This commit is contained in:
parent
0a60d76f71
commit
8c3039506f
@ -1,6 +1,6 @@
|
||||
package common
|
||||
|
||||
import "github.com/shadow1ng/fscan/common/core"
|
||||
import "github.com/shadow1ng/fscan/common/base"
|
||||
|
||||
/*
|
||||
Ports.go - 端口常量(向后兼容层)
|
||||
@ -10,6 +10,6 @@ Ports.go - 端口常量(向后兼容层)
|
||||
|
||||
// 向后兼容的端口常量 - 引用Core包中的定义
|
||||
var (
|
||||
WebPorts = core.WebPorts // Web服务端口组
|
||||
MainPorts = core.MainPorts // 主要服务端口组
|
||||
WebPorts = base.WebPorts // Web服务端口组
|
||||
MainPorts = base.MainPorts // 主要服务端口组
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package base
|
||||
|
||||
/*
|
||||
Constants.go - 核心常量定义
|
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package base
|
||||
|
||||
import (
|
||||
"sync"
|
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package base
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -15,7 +15,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/shadow1ng/fscan/common/core"
|
||||
"github.com/shadow1ng/fscan/common/base"
|
||||
"github.com/shadow1ng/fscan/common/logging"
|
||||
"github.com/shadow1ng/fscan/common/output"
|
||||
)
|
||||
@ -24,21 +24,21 @@ import (
|
||||
// 核心类型导出 - 直接从core模块导出
|
||||
// =============================================================================
|
||||
|
||||
type HostInfo = core.HostInfo
|
||||
type ScanPlugin = core.ScanPlugin
|
||||
type HostInfo = base.HostInfo
|
||||
type ScanPlugin = base.ScanPlugin
|
||||
|
||||
// 插件类型常量
|
||||
const (
|
||||
PluginTypeService = core.PluginTypeService
|
||||
PluginTypeWeb = core.PluginTypeWeb
|
||||
PluginTypeLocal = core.PluginTypeLocal
|
||||
PluginTypeBrute = core.PluginTypeBrute
|
||||
PluginTypePoc = core.PluginTypePoc
|
||||
PluginTypeScan = core.PluginTypeScan
|
||||
PluginTypeService = base.PluginTypeService
|
||||
PluginTypeWeb = base.PluginTypeWeb
|
||||
PluginTypeLocal = base.PluginTypeLocal
|
||||
PluginTypeBrute = base.PluginTypeBrute
|
||||
PluginTypePoc = base.PluginTypePoc
|
||||
PluginTypeScan = base.PluginTypeScan
|
||||
)
|
||||
|
||||
// 全局插件管理器
|
||||
var PluginManager = core.LegacyPluginManager
|
||||
var PluginManager = base.LegacyPluginManager
|
||||
|
||||
// =============================================================================
|
||||
// 核心功能导出 - 直接调用对应模块
|
||||
@ -46,7 +46,7 @@ var PluginManager = core.LegacyPluginManager
|
||||
|
||||
// 插件系统
|
||||
func RegisterPlugin(name string, plugin ScanPlugin) {
|
||||
if err := core.RegisterPlugin(name, plugin); err != nil {
|
||||
if err := base.RegisterPlugin(name, plugin); err != nil {
|
||||
LogError("Failed to register plugin " + name + ": " + err.Error())
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/shadow1ng/fscan/common/core"
|
||||
"github.com/shadow1ng/fscan/common/base"
|
||||
"github.com/shadow1ng/fscan/common/logging"
|
||||
)
|
||||
|
||||
@ -35,11 +35,11 @@ var startTimeInit = time.Now()
|
||||
// =============================================================================
|
||||
|
||||
var (
|
||||
ScanMode string // 直接映射到core.ScanMode
|
||||
ThreadNum int // 直接映射到core.ThreadNum
|
||||
Timeout int64 // 直接映射到core.Timeout
|
||||
DisablePing bool // 直接映射到core.DisablePing
|
||||
LocalMode bool // 直接映射到core.LocalMode
|
||||
ScanMode string // 直接映射到base.ScanMode
|
||||
ThreadNum int // 直接映射到base.ThreadNum
|
||||
Timeout int64 // 直接映射到base.Timeout
|
||||
DisablePing bool // 直接映射到base.DisablePing
|
||||
LocalMode bool // 直接映射到base.LocalMode
|
||||
)
|
||||
|
||||
// =============================================================================
|
||||
@ -47,10 +47,10 @@ var (
|
||||
// =============================================================================
|
||||
|
||||
var (
|
||||
Username string // 直接映射到core.Username
|
||||
Password string // 直接映射到core.Password
|
||||
Userdict map[string][]string // 直接映射到core.Userdict
|
||||
Passwords []string // 直接映射到core.Passwords
|
||||
Username string // 直接映射到base.Username
|
||||
Password string // 直接映射到base.Password
|
||||
Userdict map[string][]string // 直接映射到base.Userdict
|
||||
Passwords []string // 直接映射到base.Passwords
|
||||
)
|
||||
|
||||
// =============================================================================
|
||||
@ -58,8 +58,8 @@ var (
|
||||
// =============================================================================
|
||||
|
||||
var (
|
||||
HttpProxy string // 直接映射到core.HttpProxy
|
||||
Socks5Proxy string // 直接映射到core.Socks5Proxy
|
||||
HttpProxy string // 直接映射到base.HttpProxy
|
||||
Socks5Proxy string // 直接映射到base.Socks5Proxy
|
||||
)
|
||||
|
||||
// =============================================================================
|
||||
@ -67,9 +67,9 @@ var (
|
||||
// =============================================================================
|
||||
|
||||
var (
|
||||
NoColor bool // 直接映射到core.NoColor
|
||||
Language string // 直接映射到core.Language
|
||||
LogLevel string // 直接映射到core.LogLevel
|
||||
NoColor bool // 直接映射到base.NoColor
|
||||
Language string // 直接映射到base.Language
|
||||
LogLevel string // 直接映射到base.LogLevel
|
||||
)
|
||||
|
||||
// =============================================================================
|
||||
@ -77,8 +77,8 @@ var (
|
||||
// =============================================================================
|
||||
|
||||
var (
|
||||
PortMap map[int][]string // 直接映射到core.PortMap
|
||||
DefaultMap []string // 直接映射到core.DefaultMap
|
||||
PortMap map[int][]string // 直接映射到base.PortMap
|
||||
DefaultMap []string // 直接映射到base.DefaultMap
|
||||
)
|
||||
|
||||
// =============================================================================
|
||||
@ -96,50 +96,50 @@ var (
|
||||
|
||||
// SyncFromCore 从core包同步配置到common包(读操作)
|
||||
func SyncFromCore() {
|
||||
ScanMode = core.ScanMode
|
||||
ThreadNum = core.ThreadNum
|
||||
Timeout = core.Timeout
|
||||
DisablePing = core.DisablePing
|
||||
LocalMode = core.LocalMode
|
||||
ScanMode = base.ScanMode
|
||||
ThreadNum = base.ThreadNum
|
||||
Timeout = base.Timeout
|
||||
DisablePing = base.DisablePing
|
||||
LocalMode = base.LocalMode
|
||||
|
||||
Username = core.Username
|
||||
Password = core.Password
|
||||
Userdict = core.Userdict
|
||||
Passwords = core.Passwords
|
||||
Username = base.Username
|
||||
Password = base.Password
|
||||
Userdict = base.Userdict
|
||||
Passwords = base.Passwords
|
||||
|
||||
HttpProxy = core.HttpProxy
|
||||
Socks5Proxy = core.Socks5Proxy
|
||||
HttpProxy = base.HttpProxy
|
||||
Socks5Proxy = base.Socks5Proxy
|
||||
|
||||
NoColor = core.NoColor
|
||||
Language = core.Language
|
||||
LogLevel = core.LogLevel
|
||||
NoColor = base.NoColor
|
||||
Language = base.Language
|
||||
LogLevel = base.LogLevel
|
||||
|
||||
PortMap = core.PortMap
|
||||
DefaultMap = core.DefaultMap
|
||||
PortMap = base.PortMap
|
||||
DefaultMap = base.DefaultMap
|
||||
}
|
||||
|
||||
// SyncToCore 同步common包配置到core包(写操作)
|
||||
func SyncToCore() {
|
||||
core.ScanMode = ScanMode
|
||||
core.ThreadNum = ThreadNum
|
||||
core.Timeout = Timeout
|
||||
core.DisablePing = DisablePing
|
||||
core.LocalMode = LocalMode
|
||||
base.ScanMode = ScanMode
|
||||
base.ThreadNum = ThreadNum
|
||||
base.Timeout = Timeout
|
||||
base.DisablePing = DisablePing
|
||||
base.LocalMode = LocalMode
|
||||
|
||||
core.Username = Username
|
||||
core.Password = Password
|
||||
core.Userdict = Userdict
|
||||
core.Passwords = Passwords
|
||||
base.Username = Username
|
||||
base.Password = Password
|
||||
base.Userdict = Userdict
|
||||
base.Passwords = Passwords
|
||||
|
||||
core.HttpProxy = HttpProxy
|
||||
core.Socks5Proxy = Socks5Proxy
|
||||
base.HttpProxy = HttpProxy
|
||||
base.Socks5Proxy = Socks5Proxy
|
||||
|
||||
core.NoColor = NoColor
|
||||
core.Language = Language
|
||||
core.LogLevel = LogLevel
|
||||
base.NoColor = NoColor
|
||||
base.Language = Language
|
||||
base.LogLevel = LogLevel
|
||||
|
||||
core.PortMap = PortMap
|
||||
core.DefaultMap = DefaultMap
|
||||
base.PortMap = PortMap
|
||||
base.DefaultMap = DefaultMap
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@ -179,7 +179,7 @@ const (
|
||||
|
||||
func init() {
|
||||
// 初始化core包配置
|
||||
core.InitGlobalConfig()
|
||||
base.InitGlobalConfig()
|
||||
|
||||
// 从core包同步初始配置
|
||||
SyncFromCore()
|
||||
|
@ -1,41 +0,0 @@
|
||||
package parsers
|
||||
|
||||
/*
|
||||
LegacyParser.go - 简化的向后兼容解析器
|
||||
|
||||
现在直接使用简化的解析函数,大幅减少代码复杂度,
|
||||
同时保持与现有代码的完全兼容性。
|
||||
*/
|
||||
|
||||
// ParseIP 解析各种格式的IP地址(兼容原函数签名)
|
||||
// 参数:
|
||||
// - host: 主机地址(可以是单个IP、IP范围、CIDR或常用网段简写)
|
||||
// - filename: 包含主机地址的文件名
|
||||
// - nohosts: 需要排除的主机地址列表
|
||||
//
|
||||
// 返回:
|
||||
// - []string: 解析后的IP地址列表
|
||||
// - error: 解析过程中的错误
|
||||
func ParseIP(host string, filename string, nohosts ...string) ([]string, error) {
|
||||
return SimpleParseIP(host, filename, nohosts...)
|
||||
}
|
||||
|
||||
// ParsePort 解析端口配置字符串为端口号列表(兼容原函数签名)
|
||||
// 参数:
|
||||
// - ports: 端口配置字符串
|
||||
//
|
||||
// 返回:
|
||||
// - []int: 解析后的端口号列表
|
||||
func ParsePort(ports string) []int {
|
||||
return SimpleParsePort(ports)
|
||||
}
|
||||
|
||||
// ParsePortsFromString 从字符串解析端口列表(兼容原函数签名)
|
||||
// 参数:
|
||||
// - portsStr: 端口字符串,支持单个端口、端口范围、端口组
|
||||
//
|
||||
// 返回:
|
||||
// - []int: 解析后的端口号列表,已去重并排序
|
||||
func ParsePortsFromString(portsStr string) []int {
|
||||
return SimpleParsePortsFromString(portsStr)
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestParsePort 测试端口解析功能
|
||||
func TestParsePort(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected []int
|
||||
}{
|
||||
{
|
||||
name: "Simple ports",
|
||||
input: "80,443,22",
|
||||
expected: []int{22, 80, 443}, // sorted
|
||||
},
|
||||
{
|
||||
name: "Port range",
|
||||
input: "80-85",
|
||||
expected: []int{80, 81, 82, 83, 84, 85},
|
||||
},
|
||||
{
|
||||
name: "Mixed ports and ranges",
|
||||
input: "22,80-82,443",
|
||||
expected: []int{22, 80, 81, 82, 443}, // sorted
|
||||
},
|
||||
{
|
||||
name: "Predefined group",
|
||||
input: "web",
|
||||
expected: []int{80, 443, 8080, 8443}, // subset of web ports
|
||||
},
|
||||
{
|
||||
name: "Empty string",
|
||||
input: "",
|
||||
expected: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := ParsePort(tt.input)
|
||||
|
||||
// For predefined groups, we just check if common ports are included
|
||||
if tt.name == "Predefined group" {
|
||||
hasExpectedPorts := false
|
||||
for _, expectedPort := range tt.expected {
|
||||
for _, resultPort := range result {
|
||||
if resultPort == expectedPort {
|
||||
hasExpectedPorts = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasExpectedPorts {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasExpectedPorts {
|
||||
t.Errorf("ParsePort(%s) does not contain expected common web ports %v", tt.input, tt.expected)
|
||||
}
|
||||
} else {
|
||||
if !reflect.DeepEqual(result, tt.expected) {
|
||||
t.Errorf("ParsePort(%s) = %v, expected %v", tt.input, result, tt.expected)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseIP 测试IP解析功能
|
||||
func TestParseIP(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected int // expected number of IPs
|
||||
}{
|
||||
{
|
||||
name: "Single IP",
|
||||
input: "192.168.1.1",
|
||||
expected: 1,
|
||||
},
|
||||
{
|
||||
name: "CIDR notation",
|
||||
input: "192.168.1.0/30",
|
||||
expected: 4, // 192.168.1.0-3
|
||||
},
|
||||
{
|
||||
name: "IP range",
|
||||
input: "192.168.1.1-192.168.1.3",
|
||||
expected: 3,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := ParseIP(tt.input, "", "")
|
||||
if err != nil {
|
||||
t.Errorf("ParseIP(%s) returned error: %v", tt.input, err)
|
||||
return
|
||||
}
|
||||
if len(result) != tt.expected {
|
||||
t.Errorf("ParseIP(%s) returned %d IPs, expected %d", tt.input, len(result), tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestParsePortsFromString 测试端口字符串解析功能
|
||||
func TestParsePortsFromString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected []int
|
||||
}{
|
||||
{
|
||||
name: "Valid ports",
|
||||
input: "80,443,22",
|
||||
expected: []int{22, 80, 443}, // sorted
|
||||
},
|
||||
{
|
||||
name: "Empty string",
|
||||
input: "",
|
||||
expected: []int{},
|
||||
},
|
||||
{
|
||||
name: "With spaces",
|
||||
input: " 80 , 443 , 22 ",
|
||||
expected: []int{22, 80, 443},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := ParsePortsFromString(tt.input)
|
||||
if !reflect.DeepEqual(result, tt.expected) {
|
||||
t.Errorf("ParsePortsFromString(%s) = %v, expected %v", tt.input, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ Simple.go - 简化版本的解析器函数
|
||||
// 简化的IP/主机解析函数
|
||||
// =============================================================================
|
||||
|
||||
// SimpleParseIP 简化版本的IP解析函数
|
||||
// 保持与 ParseIP 的接口兼容性,但使用更简单的实现
|
||||
func SimpleParseIP(host string, filename string, nohosts ...string) ([]string, error) {
|
||||
// ParseIP 解析各种格式的IP地址
|
||||
// 支持单个IP、IP范围、CIDR和文件输入
|
||||
func ParseIP(host string, filename string, nohosts ...string) ([]string, error) {
|
||||
var hosts []string
|
||||
|
||||
// 如果提供了文件名,从文件读取主机列表
|
||||
@ -68,9 +68,9 @@ func SimpleParseIP(host string, filename string, nohosts ...string) ([]string, e
|
||||
// 简化的端口解析函数
|
||||
// =============================================================================
|
||||
|
||||
// SimpleParsePort 简化版本的端口解析函数
|
||||
// ParsePort 解析端口配置字符串为端口号列表
|
||||
// 保持与 ParsePort 的接口兼容性
|
||||
func SimpleParsePort(ports string) []int {
|
||||
func ParsePort(ports string) []int {
|
||||
if ports == "" {
|
||||
return nil
|
||||
}
|
||||
@ -108,10 +108,10 @@ func SimpleParsePort(ports string) []int {
|
||||
return result
|
||||
}
|
||||
|
||||
// SimpleParsePortsFromString 简化版本的端口字符串解析
|
||||
// ParsePortsFromString 从字符串解析端口列表
|
||||
// 保持与 ParsePortsFromString 的接口兼容性
|
||||
func SimpleParsePortsFromString(portsStr string) []int {
|
||||
return SimpleParsePort(portsStr)
|
||||
func ParsePortsFromString(portsStr string) []int {
|
||||
return ParsePort(portsStr)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user