mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 08:44:29 +00:00
Compare commits
3 Commits
97263044f0
...
f4379c77ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4379c77ba | ||
|
|
87c290b60c | ||
|
|
47bb5874f2 |
@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=UA3F
|
||||
PKG_VERSION:=2.2.2
|
||||
PKG_VERSION:=2.2.3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
# PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<span style="display: inline-flex;">
|
||||
<a href="https://github.com/SunBK201/UA3F" target="_blank">
|
||||
Version: <span id="ua3f-current-version">2.2.2</span>
|
||||
Version: <span id="ua3f-current-version">2.2.3</span>
|
||||
</a>
|
||||
<span id="ua3f-update-status" style="margin-left: 10px;"></span>
|
||||
</span>
|
||||
|
||||
@ -10,8 +10,6 @@ PROG="/usr/bin/$NAME"
|
||||
start_service() {
|
||||
config_load "$NAME"
|
||||
|
||||
mkdir -p /var/log/ua3f && chmod o+w /var/log/ua3f
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "enabled" "enabled" "0"
|
||||
[ "$enabled" -eq "1" ] || return 0
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
set -e
|
||||
|
||||
project_name="ua3f"
|
||||
release_version="2.2.2"
|
||||
release_version="2.2.3"
|
||||
target=main.go
|
||||
|
||||
LINUX_ARCHS="amd64 arm arm64 mipsle mips64 riscv64 386 mipsle-softfloat mipsle-hardfloat armv7 armv8"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
Package: ua3f
|
||||
Version: 2.2.2-1
|
||||
Version: 2.2.3-1
|
||||
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
|
||||
Source: /feed/openwrt
|
||||
SourceName: UA3F
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
Package: ua3f
|
||||
Version: 2.2.2-1
|
||||
Version: 2.2.3-1
|
||||
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
|
||||
Source: /feed/openwrt
|
||||
SourceName: UA3F
|
||||
|
||||
@ -11,12 +11,10 @@ import (
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
const log_file = "/var/log/ua3f/ua3f.log"
|
||||
|
||||
func SetLogConf(level string) {
|
||||
writer2 := os.Stdout
|
||||
writer3 := &lumberjack.Logger{
|
||||
Filename: log_file,
|
||||
Filename: GetLogFilePath(),
|
||||
MaxSize: 5, // megabytes
|
||||
MaxBackups: 5,
|
||||
MaxAge: 7, // days
|
||||
@ -58,6 +56,7 @@ func SetLogConf(level string) {
|
||||
func LogHeader(version string, cfg *config.Config) {
|
||||
slog.Info("UA3F started", "version", version, "", cfg)
|
||||
slog.Info("OS Info", GetOSInfo()...)
|
||||
slog.Info("Log file", "path", GetLogFilePath())
|
||||
}
|
||||
|
||||
func LogDebugWithAddr(src string, dest string, msg string) {
|
||||
|
||||
81
src/internal/log/path.go
Normal file
81
src/internal/log/path.go
Normal file
@ -0,0 +1,81 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
logDir string
|
||||
logDirOnce bool
|
||||
)
|
||||
|
||||
// GetLogDir returns the platform-specific log directory for UA3F.
|
||||
// - Linux: /var/log/ua3f/
|
||||
// - Windows: ~/.ua3f/
|
||||
// - Other (fallback): temp directory
|
||||
// The directory is created automatically with proper permissions if it doesn't exist.
|
||||
func GetLogDir() string {
|
||||
if logDirOnce {
|
||||
return logDir
|
||||
}
|
||||
|
||||
logDir = determineLogDir()
|
||||
logDirOnce = true
|
||||
|
||||
// Ensure the directory exists
|
||||
if err := os.MkdirAll(logDir, 0755); err != nil {
|
||||
// If creation fails, fall back to temp directory
|
||||
logDir = filepath.Join(os.TempDir(), "ua3f")
|
||||
_ = os.MkdirAll(logDir, 0755)
|
||||
}
|
||||
|
||||
return logDir
|
||||
}
|
||||
|
||||
func determineLogDir() string {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
// Try /var/log/ua3f/ first for Linux
|
||||
varLogDir := "/var/log/ua3f"
|
||||
if err := os.MkdirAll(varLogDir, 0755); err == nil {
|
||||
// Test write permission
|
||||
testFile := filepath.Join(varLogDir, ".write_test")
|
||||
if f, err := os.Create(testFile); err == nil {
|
||||
_ = f.Close()
|
||||
_ = os.Remove(testFile)
|
||||
return varLogDir
|
||||
}
|
||||
}
|
||||
// Fall through to user home directory
|
||||
return getUserLogDir()
|
||||
default:
|
||||
// macOS, Windows, FreeBSD, etc. - try user home first
|
||||
return getUserLogDir()
|
||||
}
|
||||
}
|
||||
|
||||
func getUserLogDir() string {
|
||||
// Try user home directory
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
userLogDir := filepath.Join(homeDir, ".ua3f")
|
||||
if err := os.MkdirAll(userLogDir, 0755); err == nil {
|
||||
return userLogDir
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to temp directory
|
||||
return filepath.Join(os.TempDir(), "ua3f")
|
||||
}
|
||||
|
||||
// GetLogFilePath returns the full path to the main log file.
|
||||
func GetLogFilePath() string {
|
||||
return filepath.Join(GetLogDir(), "ua3f.log")
|
||||
}
|
||||
|
||||
// GetStatsFilePath returns the full path to a stats file.
|
||||
func GetStatsFilePath(name string) string {
|
||||
return filepath.Join(GetLogDir(), name)
|
||||
}
|
||||
@ -57,31 +57,16 @@ func (s *Server) NftSetDesync(tx *knftables.Transaction, table *knftables.Table)
|
||||
Rule: netfilter.NftRuleIgnorePorts,
|
||||
})
|
||||
|
||||
if netfilter.NftIHAvailable() {
|
||||
tx.Add(&knftables.Rule{
|
||||
Chain: chain.Name,
|
||||
Rule: knftables.Concat(
|
||||
"meta l4proto tcp",
|
||||
"ct state established",
|
||||
"ct direction original",
|
||||
"@ih,0,8 & 0 == 0",
|
||||
fmt.Sprintf("ct bytes < %d", s.CtByte),
|
||||
fmt.Sprintf("ct packets < %d", s.CtPackets),
|
||||
fmt.Sprintf("counter queue num %d bypass", s.nfqServer.QueueNum),
|
||||
),
|
||||
})
|
||||
} else {
|
||||
tx.Add(&knftables.Rule{
|
||||
Chain: chain.Name,
|
||||
Rule: knftables.Concat(
|
||||
"meta l4proto tcp",
|
||||
"ct state established",
|
||||
"ct direction original",
|
||||
"ip length > 41",
|
||||
fmt.Sprintf("ct bytes < %d", s.CtByte),
|
||||
fmt.Sprintf("ct packets < %d", s.CtPackets),
|
||||
fmt.Sprintf("counter queue num %d bypass", s.nfqServer.QueueNum),
|
||||
),
|
||||
})
|
||||
}
|
||||
tx.Add(&knftables.Rule{
|
||||
Chain: chain.Name,
|
||||
Rule: knftables.Concat(
|
||||
"meta l4proto tcp",
|
||||
"ct state established",
|
||||
"ct direction original",
|
||||
"ip length > 41",
|
||||
fmt.Sprintf("ct bytes < %d", s.CtByte),
|
||||
fmt.Sprintf("ct packets < %d", s.CtPackets),
|
||||
fmt.Sprintf("counter queue num %d bypass", s.nfqServer.QueueNum),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package statistics
|
||||
|
||||
import "github.com/sunbk201/ua3f/internal/log"
|
||||
|
||||
type Recorder struct {
|
||||
RewriteRecordList *RewriteRecordList
|
||||
PassThroughRecordList *PassThroughRecordList
|
||||
@ -8,9 +10,9 @@ type Recorder struct {
|
||||
|
||||
func New() *Recorder {
|
||||
return &Recorder{
|
||||
RewriteRecordList: NewRewriteRecordList("/var/log/ua3f/rewrite_stats"),
|
||||
PassThroughRecordList: NewPassThroughRecordList("/var/log/ua3f/pass_stats"),
|
||||
ConnectionRecordList: NewConnectionRecordList("/var/log/ua3f/conn_stats"),
|
||||
RewriteRecordList: NewRewriteRecordList(log.GetStatsFilePath("rewrite_stats")),
|
||||
PassThroughRecordList: NewPassThroughRecordList(log.GetStatsFilePath("pass_stats")),
|
||||
ConnectionRecordList: NewConnectionRecordList(log.GetStatsFilePath("conn_stats")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user