diff --git a/README.md b/README.md index 7bfebcf..ccdd660 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,12 @@ UA3F 已支持 LuCI Web 页面,可以打开 Services -> UA3F 进行相关配 > [!NOTE] > 设置说明: > -> - Port 为 UA3F 监听端口,默认 `1080`。 -> - Bind Address 为 UA3F 监听地址,默认 `127.0.0.1`。 -> - User-Agent 为自定义 User-Agent,默认 `FFF`。 -> - User-Agent Regex Pattern 为 User-Agent 正则表达式规则。如果流量中的 User-Agent 匹配该正则表达式,则会被修改为 User-Agent 字段的内容,否则不会被修改;如果该字段为空,则所有流量 User-Agent 都会被修改。默认 `(iPhone|iPad|Android|Macintosh|Windows|Linux)`,即只修改携带设备与系统信息的 User-Agent。 -> - Log Level 为日志等级,默认 `info`, 如果需要调试排查错误可以设置为 `debug`。 +> - Port: UA3F 监听端口,默认 `1080`。 +> - Bind Address: UA3F 监听地址,默认 `127.0.0.1`。 +> - Log Level: 日志等级,默认 `info`, 如果需要调试排查错误可以设置为 `debug`。 +> - User-Agent: 自定义 User-Agent,默认 `FFF`。 +> - User-Agent Regex Pattern: User-Agent 正则表达式规则。如果流量中的 User-Agent 匹配该正则表达式,则会被修改为 User-Agent 字段的内容,否则不会被修改;如果该字段为空,则所有流量 User-Agent 都会被修改。默认 `(iPhone|iPad|Android|Macintosh|Windows|Linux)`,即只修改携带设备与系统信息的 User-Agent。 +> - Partial Replace: 部分替换,如果开启,则只替换 User-Agent Regex Pattern 中匹配到的部分。该选项仅在 User-Agent Regex Pattern 不为空时生效。 ### 作为后台服务运行 @@ -111,11 +112,12 @@ sudo -u shellcrash /usr/bin/ua3f 相关启动参数: +- `-b `: 自定义绑定监听地址,默认 127.0.0.1 - `-p `: 端口号,默认 1080 +- `-l `: 日志等级,默认 info,可选:debug,默认日志位置:`/var/log/ua3f.log` - `-f `: 自定义 UA,默认 FFF - `-r `: 自定义正则匹配 User-Agent, 默认 `(iPhone|iPad|Android|Macintosh|Windows|Linux)` -- `-b `: 自定义绑定监听地址,默认 127.0.0.1 -- `-l `: 日志等级,默认 info,可选:debug,默认日志位置:`/var/log/ua3f.log` +- `-s`: 部分替换,仅替换正则匹配到的部分 ### Clash 配置建议 diff --git a/build.sh b/build.sh index 05d248f..a7e79fa 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/sh project_name="ua3f" -release_version="0.5.1" +release_version="0.6.0" target=main.go dist=./dist release_dir=./bin diff --git a/install.sh b/install.sh index 281eb44..0fcf870 100755 --- a/install.sh +++ b/install.sh @@ -98,7 +98,7 @@ install_ua3f() { cd /root getcpucore -version=0.5.1 +version=0.6.0 ua3f_tar=ua3f-$version-$cpucore.tar.gz chmod_clash diff --git a/openwrt/Makefile b/openwrt/Makefile index 5ee5280..7679fda 100644 --- a/openwrt/Makefile +++ b/openwrt/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=UA3F -PKG_VERSION:=0.5.1 +PKG_VERSION:=0.6.0 PKG_RELEASE:=1 # PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz diff --git a/openwrt/files/luci/cbi.lua b/openwrt/files/luci/cbi.lua index dac14d3..591f39d 100644 --- a/openwrt/files/luci/cbi.lua +++ b/openwrt/files/luci/cbi.lua @@ -3,7 +3,7 @@ local uci = require("luci.model.uci").cursor() ua3f = Map("ua3f", "UA3F", [[ - Version: 0.5.1 + Version: 0.6.0
Across the Campus we can reach every corner in the world. ]] @@ -56,12 +56,15 @@ uaRegexPattern.placeholder = "(iPhone|iPad|Android|Macintosh|Windows|Linux|Apple uaRegexPattern.description = "Regular expression pattern for matching User-Agent" partialRepalce = main:taboption("general", Flag, "partial_replace", "Partial Replace") -partialRepalce.description = "Replace only the matched part of the User-Agent, only works when User-Agent Regex Pattern is not empty" +partialRepalce.description = +"Replace only the matched part of the User-Agent, only works when User-Agent Regex Pattern is not empty" partialRepalce.default = "0" +--[[ local apply = luci.http.formvalue("cbi.apply") --- if apply then --- io.popen("/etc/init.d/ua3f restart") --- end +if apply then + io.popen("/etc/init.d/ua3f restart") +end +--]] return ua3f diff --git a/opkg/CONTROL/control b/opkg/CONTROL/control index 01a6bdc..dc3322f 100644 --- a/opkg/CONTROL/control +++ b/opkg/CONTROL/control @@ -1,5 +1,5 @@ Package: ua3f -Version: 0.5.1-1 +Version: 0.6.0-1 Depends: libc, luci-compat Source: /feed/openwrt SourceName: UA3F diff --git a/opkg/CONTROL/control-e b/opkg/CONTROL/control-e index 4a9a8f0..dc3322f 100644 --- a/opkg/CONTROL/control-e +++ b/opkg/CONTROL/control-e @@ -1,11 +1,11 @@ Package: ua3f -Version: 0.5.1-1 -Depends: luci-compat +Version: 0.6.0-1 +Depends: libc, luci-compat Source: /feed/openwrt SourceName: UA3F License: GPL-3.0-only Section: net SourceDateEpoch: 1711267200 Architecture: all -Installed-Size: 2703360 +Installed-Size: 2775040 Description: Implementation of the next generation of HTTP User-Agent modification methodology. diff --git a/opkg/etc/config/ua3f b/opkg/etc/config/ua3f index e305d8c..93b4153 100644 --- a/opkg/etc/config/ua3f +++ b/opkg/etc/config/ua3f @@ -5,5 +5,6 @@ config 'ua3f' 'main' option port '1080' option bind '127.0.0.1' option ua 'FFF' - option ua_regex '(iPhone|iPad|Android|Macintosh|Windows|Linux)' - option log_level 'info' + option ua_regex '(iPhone|iPad|Android|Macintosh|Windows|Linux|Apple|Mac OS X)' + option partial_replace false + option log_level 'info' \ No newline at end of file diff --git a/opkg/etc/init.d/ua3f b/opkg/etc/init.d/ua3f index 04ff66f..c961050 100755 --- a/opkg/etc/init.d/ua3f +++ b/opkg/etc/init.d/ua3f @@ -20,10 +20,13 @@ start_service() { local bind local ua local log_level + local ua_regex + local partial_replace config_get port "main" "port" "1080" config_get bind "main" "bind" "127.0.0.1" config_get ua "main" "ua" "FFF" config_get ua_regex "main" "ua_regex" "(iPhone|iPad|Android|Macintosh|Windows|Linux)" + config_get_bool partial_replace "main" "partial_replace" 0 config_get log_level "main" "log_level" "info" chmod o+w /var/log @@ -35,6 +38,7 @@ start_service() { procd_append_param command -f "$ua" procd_append_param command -r "$ua_regex" procd_append_param command -l $log_level + [ "$partial_replace" = "1" ] && procd_append_param command -s procd_set_param respawn procd_set_param stdout 1 diff --git a/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua b/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua index 75242fe..009840a 100755 --- a/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua +++ b/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua @@ -3,7 +3,7 @@ local uci = require("luci.model.uci").cursor() ua3f = Map("ua3f", "UA3F", [[ - Version: 0.5.1 + Version: 0.6.0
Across the Campus we can reach every corner in the world. ]] @@ -29,13 +29,11 @@ main:tab("log", "Log") port = main:taboption("general", Value, "port", "Port") port.placeholder = "1080" + bind = main:taboption("general", Value, "bind", "Bind Address") bind:value("127.0.0.1") bind:value("0.0.0.0") -ua = main:taboption("general", Value, "ua", "User-Agent") -ua.placeholder = "FFF" -uaRegexPattern = main:taboption("general", Value, "ua_regex", "User-Agent Regex Pattern") -uaRegexPattern.placeholder = "(iPhone|iPad|Android|Macintosh|Windows|Linux)" + log_level = main:taboption("general", ListValue, "log_level", "Log Level") log_level:value("debug") log_level:value("info") @@ -43,7 +41,6 @@ log_level:value("warn") log_level:value("error") log_level:value("fatal") log_level:value("panic") - log = main:taboption("log", TextValue, "") log.readonly = true log.cfgvalue = function(self, section) @@ -51,9 +48,23 @@ log.cfgvalue = function(self, section) end log.rows = 30 +ua = main:taboption("general", Value, "ua", "User-Agent") +ua.placeholder = "FFF" + +uaRegexPattern = main:taboption("general", Value, "ua_regex", "User-Agent Regex Pattern") +uaRegexPattern.placeholder = "(iPhone|iPad|Android|Macintosh|Windows|Linux|Apple|Mac OS X)" +uaRegexPattern.description = "Regular expression pattern for matching User-Agent" + +partialRepalce = main:taboption("general", Flag, "partial_replace", "Partial Replace") +partialRepalce.description = +"Replace only the matched part of the User-Agent, only works when User-Agent Regex Pattern is not empty" +partialRepalce.default = "0" + +--[[ local apply = luci.http.formvalue("cbi.apply") if apply then io.popen("/etc/init.d/ua3f restart") end +--]] return ua3f diff --git a/src/main.go b/src/main.go index b802050..6105b09 100644 --- a/src/main.go +++ b/src/main.go @@ -17,7 +17,7 @@ import ( "github.com/sunbk201/ua3f/log" ) -var version = "0.5.1" +var version = "0.6.0" var payloadByte []byte var payload string var uaPattern string