Skip to content

Commit 612f4cd

Browse files
committed
chore: bump version to 2.4.0
1 parent 5ae9b95 commit 612f4cd

File tree

10 files changed

+95
-11
lines changed

10 files changed

+95
-11
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ UA3F 是一个 HTTP Header 重写工具,作为一个 HTTP、SOCKS5、TPROXY、
6666

6767
## 使用
6868

69-
UA3F 支持 LuCI Web 页面,可以打开 Services -> UA3F 进行相关配置。
69+
UA3F 支持 OpenWrt LuCI Web 页面,可以打开 Services -> UA3F 进行相关配置。
7070

7171
快速使用教程详见:[猴子也能看懂的 UA3F 使用教程](https://sunbk201public.notion.site/UA3F-2a21f32cbb4b80669e04ec1f053d0333)
7272

73+
UA3F 支持 yaml 文件进行配置,通过 `-c` 参数指定配置文件路径, 通过 `-g` 参数生成模板配置文件,配置文件示例见 [docs/config.yaml](docs/config.yaml)
74+
7375
设备与系统信息正则表达式参考:
7476

7577
```regex
@@ -94,6 +96,8 @@ sudo -u shellcrash /usr/bin/ua3f
9496

9597
相关命令行启动参数:
9698

99+
- `-c <config path>`: 自定义配置文件路径
100+
- `-g`: 在当前目录生成模板配置文件 config.yaml
97101
- `-m <mode>`: 服务模式,支持 HTTP、SOCKS5、TPROXY、REDIRECT,默认 SOCKS5
98102
- `-b <bind addr>`: 自定义绑定监听地址,默认 127.0.0.1
99103
- `-p <port>`: 端口号,默认 1080

README_EN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ Three deployment methods are available:
5959

6060
## Usage
6161

62-
UA3F supports LuCI Web interface. Navigate to Services -> UA3F for configuration.
62+
UA3F supports OpenWrt LuCI Web interface. Navigate to Services -> UA3F for configuration.
6363

6464
For detailed tutorial, please visit: [UA3F User Guide](https://sunbk201public.notion.site/UA3F-2a21f32cbb4b80669e04ec1f053d0333)
6565

66+
UA3F supports configuration via a YAML file. You can specify the configuration file path using the `-c` option, and generate a template configuration file using the `-g` option. An example configuration file can be found at [docs/config.yaml](docs/config.yaml).
67+
6668
Device and system information regex reference:
6769

6870
```regex
@@ -87,6 +89,8 @@ sudo -u shellcrash /usr/bin/ua3f
8789

8890
Command line parameters:
8991

92+
- `-c <config path>`: Custom configuration file path
93+
- `-g`: Generate a template configuration file config.yaml in the current directory
9094
- `-m <mode>`: Server mode. Supports HTTP, SOCKS5, TPROXY, REDIRECT. Default: SOCKS5
9195
- `-b <bind addr>`: Custom bind address. Default: 127.0.0.1
9296
- `-p <port>`: Port number. Default: 1080

openwrt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include $(TOPDIR)/rules.mk
22

33
PKG_NAME:=UA3F
4-
PKG_VERSION:=2.3.0
4+
PKG_VERSION:=2.4.0
55
PKG_RELEASE:=1
66

77
# PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

openwrt/files/luci/view/ua3f/version.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<span style="display: inline-flex;">
22
<a href="https://github.com/SunBK201/UA3F" target="_blank">
3-
Version: <span id="ua3f-current-version">2.3.0</span>
3+
Version: <span id="ua3f-current-version">2.4.0</span>
44
</a>
55
<span id="ua3f-update-status" style="margin-left: 10px;"></span>
66
</span>

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
set -e
99

1010
project_name="ua3f"
11-
release_version="2.3.0"
11+
release_version="2.4.0"
1212
target=main.go
1313

1414
LINUX_ARCHS="amd64 arm arm64 mipsle mips64 riscv64 386 mipsle-softfloat mipsle-hardfloat armv7 armv8"

scripts/ipkg/CONTROL/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ua3f
2-
Version: 2.3.0-1
2+
Version: 2.4.0-1
33
Depends: luci-compat, ipset, iptables, iptables-mod-tproxy, iptables-mod-extra, iptables-mod-ipopt, iptables-mod-nfqueue, iptables-mod-conntrack-extra, kmod-nf-conntrack-netlink
44
Source: /feed/openwrt
55
SourceName: UA3F

scripts/ipkg/CONTROL/control-e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ua3f
2-
Version: 2.3.0-1
2+
Version: 2.4.0-1
33
Depends: luci-compat, ipset, iptables, iptables-mod-tproxy, iptables-mod-extra, iptables-mod-ipopt, iptables-mod-nfqueue, iptables-mod-conntrack-extra, kmod-nf-conntrack-netlink
44
Source: /feed/openwrt
55
SourceName: UA3F

src/internal/config/config.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Config struct {
5050
Desync DesyncConfig `yaml:"desync"`
5151

5252
Rules []Rule `yaml:"rules" validate:"dive"`
53-
RulesJson string
53+
RulesJson string `yaml:"rules_json,omitempty"`
5454
}
5555

5656
type DesyncConfig struct {
@@ -62,7 +62,7 @@ type DesyncConfig struct {
6262
}
6363

6464
type Rule struct {
65-
Enabled bool `json:"enabled" yaml:"enabled"`
65+
Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
6666

6767
Type string `json:"type" yaml:"type" validate:"required,oneof=HEADER-KEYWORD HEADER-REGEX DEST-PORT IP-CIDR SRC-IP DOMAIN-SUFFIX DOMAIN-KEYWORD DOMAIN FINAL"`
6868

@@ -90,6 +90,7 @@ func Parse() (*Config, bool, error) {
9090
rewriteMode string
9191
rulesJson string
9292
showVer bool
93+
genConfig bool
9394
ttl bool
9495
ipid bool
9596
tcpTimestamp bool
@@ -112,6 +113,7 @@ func Parse() (*Config, bool, error) {
112113
flag.StringVar(&rewriteMode, "x", "", "Rewrite mode: GLOBAL, DIRECT, RULE")
113114
flag.StringVar(&rulesJson, "z", "", "Rules JSON string")
114115
flag.BoolVar(&showVer, "v", false, "Show version")
116+
flag.BoolVar(&genConfig, "g", false, "Generate template config file")
115117
flag.BoolVar(&ttl, "ttl", false, "Set TTL")
116118
flag.BoolVar(&ipid, "ipid", false, "Set IP ID")
117119
flag.BoolVar(&tcpTimestamp, "tcpts", false, "Delete TCP Timestamp")
@@ -123,6 +125,19 @@ func Parse() (*Config, bool, error) {
123125
flag.UintVar(&injectTTL, "desync-inject-ttl", 0, "Desync inject TTL")
124126
flag.Parse()
125127

128+
if genConfig {
129+
_, err := GenerateTemplateConfig(true)
130+
if err != nil {
131+
return nil, false, fmt.Errorf("failed to generate template config: %w", err)
132+
}
133+
fmt.Println("Template config file 'config.yaml' generated successfully.")
134+
return nil, false, nil
135+
}
136+
137+
if showVer {
138+
return nil, true, nil
139+
}
140+
126141
// Track which CLI flags were explicitly set
127142
cliSet := make(map[string]bool)
128143
flag.Visit(func(f *flag.Flag) {

src/internal/config/template.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"go.yaml.in/yaml/v3"
8+
)
9+
10+
func GenerateTemplateConfig(writeToFile bool) (Config, error) {
11+
cfg := Config{
12+
ServerMode: "SOCKS5",
13+
BindAddress: "127.0.0.1",
14+
Port: 1080,
15+
16+
LogLevel: "info",
17+
18+
RewriteMode: "GLOBAL",
19+
20+
UserAgent: "FFF",
21+
UserAgentRegex: "",
22+
UserAgentPartialReplace: false,
23+
24+
TTL: false,
25+
IPID: false,
26+
TCPTimeStamp: false,
27+
TCPInitialWindow: false,
28+
29+
Desync: DesyncConfig{
30+
Reorder: false,
31+
ReorderBytes: 8,
32+
ReorderPackets: 1500,
33+
Inject: false,
34+
InjectTTL: 3,
35+
},
36+
37+
Rules: []Rule{
38+
{
39+
Type: "FINAL",
40+
Action: "REPLACE",
41+
RewriteHeader: "User-Agent",
42+
RewriteValue: "FFF",
43+
},
44+
},
45+
}
46+
47+
if writeToFile {
48+
data, err := yaml.Marshal(&cfg)
49+
if err != nil {
50+
return Config{}, fmt.Errorf("failed to marshal template config to YAML: %w", err)
51+
}
52+
if err := os.WriteFile("config.yaml", data, 0644); err != nil {
53+
return Config{}, fmt.Errorf("failed to write template config to file: %w", err)
54+
}
55+
}
56+
return cfg, nil
57+
}

src/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ func main() {
2727
return
2828
}
2929

30-
log.SetLogConf(cfg.LogLevel)
31-
3230
if showVer {
3331
fmt.Printf("UA3F version %s\n", appVersion)
3432
return
3533
}
3634

35+
if cfg == nil {
36+
return
37+
}
38+
39+
log.SetLogConf(cfg.LogLevel)
40+
3741
log.LogHeader(appVersion, cfg)
3842

3943
if err := daemon.DaemonSetup(cfg); err != nil {

0 commit comments

Comments
 (0)