Skip to content

Commit 54c3a4f

Browse files
author
Delta-Kronecker
committed
feat: cloudflare port expansion, reality files, archive fix, clean_failed_subs toggle
1 parent 4ec6c5d commit 54c3a4f

5 files changed

Lines changed: 109 additions & 2 deletions

File tree

data/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"validation": {
33

4+
"clean_failed_subs": false,
45
"num_workers": 1000,
56
"global_timeout_sec": 20000,
67
"xray_start_timeout_ms": 8000,

src/geoip.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,97 @@ func enrichResultsWithGeoIP(results []configResult, settings GeoSettings) []conf
643643

644644
return results
645645
}
646+
647+
// ── Cloudflare port expansion ────────────────────────────────────────────────
648+
649+
var cfPorts = []string{
650+
"443", "8443", "2053", "2083", "2087", "2096",
651+
"80", "8080", "8880", "2052", "2082", "2086", "2095",
652+
}
653+
654+
func expandCloudflarePorts(lines []string) []string {
655+
seen := make(map[string]bool, len(lines))
656+
var result []string
657+
658+
for _, line := range lines {
659+
proto := detectProto(line)
660+
if proto != "vless" && proto != "trojan" {
661+
if !seen[line] {
662+
seen[line] = true
663+
result = append(result, line)
664+
}
665+
continue
666+
}
667+
if !isWSTransport(line, proto) {
668+
if !seen[line] {
669+
seen[line] = true
670+
result = append(result, line)
671+
}
672+
continue
673+
}
674+
675+
host := extractServerHost(line, proto)
676+
if host == "" {
677+
if !seen[line] {
678+
seen[line] = true
679+
result = append(result, line)
680+
}
681+
continue
682+
}
683+
684+
ip := resolveHost(host)
685+
if ip == "" || !isCloudflareIP(ip) {
686+
if !seen[line] {
687+
seen[line] = true
688+
result = append(result, line)
689+
}
690+
continue
691+
}
692+
693+
// Cloudflare WS config — expand to all ports
694+
for _, port := range cfPorts {
695+
expanded := replacePort(line, port)
696+
if expanded != "" && !seen[expanded] {
697+
seen[expanded] = true
698+
result = append(result, expanded)
699+
}
700+
}
701+
}
702+
703+
expanded := len(result) - len(lines)
704+
if expanded > 0 {
705+
fmt.Printf(" Cloudflare: expanded %d configs to %d port variants\n", len(lines), len(result))
706+
}
707+
return result
708+
}
709+
710+
func replacePort(line, newPort string) string {
711+
hashIdx := strings.LastIndex(line, "#")
712+
suffix := ""
713+
if hashIdx != -1 {
714+
suffix = line[hashIdx:]
715+
line = line[:hashIdx]
716+
}
717+
718+
qIdx := strings.Index(line, "?")
719+
var base, query string
720+
if qIdx != -1 {
721+
base = line[:qIdx]
722+
query = line[qIdx:]
723+
} else {
724+
base = line
725+
}
726+
727+
atIdx := strings.LastIndex(base, "@")
728+
if atIdx == -1 {
729+
return ""
730+
}
731+
afterAt := base[atIdx+1:]
732+
colonIdx := strings.LastIndex(afterAt, ":")
733+
if colonIdx == -1 {
734+
return ""
735+
}
736+
host := afterAt[:colonIdx]
737+
rewritten := base[:atIdx+1] + host + ":" + newPort + query + suffix
738+
return rewritten
739+
}

src/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func main() {
6969
fmt.Printf(" Loaded %d sources from sub.txt\n", len(subURLs))
7070
var failedURLs []string
7171
allConfigs, failedLinks, failedURLs = fetchAllFromSubs(subURLs)
72-
if len(failedURLs) > 0 {
72+
if len(failedURLs) > 0 && cfg.Validation.CleanFailedSubs {
7373
cleanSubFile("data/sub.txt", failedURLs)
7474
}
7575
} else {
@@ -78,6 +78,8 @@ func main() {
7878
}
7979
fmt.Printf(" Total fetched: %d | Failed sources: %d\n", len(allConfigs), len(failedLinks))
8080

81+
allConfigs = expandCloudflarePorts(allConfigs)
82+
8183
if gLog != nil {
8284
gLog.logStart(len(allConfigs), len(failedLinks))
8385
}

src/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ type GeoSettings struct {
2727
}
2828

2929
type ValidationSettings struct {
30-
NumWorkers int `json:"num_workers"`
30+
CleanFailedSubs bool `json:"clean_failed_subs"`
31+
NumWorkers int `json:"num_workers"`
3132
GlobalTimeoutSec float64 `json:"global_timeout_sec"`
3233
XrayStartTimeoutMs int `json:"xray_start_timeout_ms"`
3334
XrayStartIntervalMs int `json:"xray_start_interval_ms"`

src/writer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ func injectClashProxies(baseContent string, proxyEntries []string, proxyNames []
8484
// ── prepareOutputDirs ─────────────────────────────────────────────────────────
8585

8686
func prepareOutputDirs() error {
87+
archiveDir := filepath.Join("config", "archive")
88+
tmpArchive := filepath.Join("config", ".archive_tmp")
89+
if _, err := os.Stat(archiveDir); err == nil {
90+
os.Rename(archiveDir, tmpArchive)
91+
}
8792
os.RemoveAll("config")
93+
if _, err := os.Stat(tmpArchive); err == nil {
94+
os.MkdirAll(archiveDir, 0755)
95+
os.Rename(tmpArchive, archiveDir)
96+
}
8897
dirs := []string{
8998
"config",
9099
cfg.Output.ProtocolsDir,

0 commit comments

Comments
 (0)