Bug fix & Improve

This commit is contained in:
SimpleTracker 2024-04-30 10:25:50 +08:00 committed by Simple-Tracker
parent b1533482b4
commit 3203ed44b1
7 changed files with 28 additions and 21 deletions

View File

@ -34,5 +34,6 @@ jobs:
platforms: 'linux/386,linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le'
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args:
build-args: |
"GITHUB_REF=${{ github.ref }}"
"PROGRAM_NIGHTLY=${{ github.event_name != 'release' && 'true' || 'false' }}"

View File

@ -1,7 +1,7 @@
FROM --platform=${BUILDPLATFORM} golang:1.20.13-alpine AS go
WORKDIR /app
ARG BUILDOS BUILDARCH TARGETOS TARGETARCH PROGRAM_NIGHTLY
ARG BUILDOS BUILDARCH TARGETOS TARGETARCH GITHUB_REF PROGRAM_NIGHTLY
ENV GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=7
RUN PROGRAM_VERSION="$(basename ${GITHUB_REF})"; \
@ -13,14 +13,14 @@ RUN PROGRAM_VERSION="$(basename ${GITHUB_REF})"; \
if [ "${PROGRAM_NIGHTLY}" == 'true' ]; then \
PROGRAM_VERSION="${PROGRAM_VERSION} (Nightly)"; \
fi; \
export PROGRAM_VERSION
echo "export PROGRAM_VERSION='${PROGRAM_VERSION}'" > /envfile
RUN echo "Running on ${BUILDOS}/${BUILDARCH}, Building for ${TARGETOS}/${TARGETARCH}, Version: ${PROGRAM_VERSION}"
RUN . /envfile; echo "Running on ${BUILDOS}/${BUILDARCH}, Building for ${TARGETOS}/${TARGETARCH}, Version: ${PROGRAM_VERSION}"
ADD lang/ *LICENSE* *.md *.go *.sh go.mod go.sum config.json ./
RUN go mod download
RUN go build -ldflags "-w -X \"main.programVersion=${PROGRAM_VERSION}\"" -o qBittorrent-ClientBlocker
RUN . /envfile; go build -ldflags "-w -X \"main.programVersion=${PROGRAM_VERSION}\"" -o qBittorrent-ClientBlocker
RUN rm -f *.go go.mod go.sum
FROM alpine

View File

@ -4,7 +4,7 @@ var currentClientType = ""
// 重复判断 nil 是因为输出的类型转换 (qB_MainDataStruct -> interface{}) 会导致 nil 比较失效.
func IsBanPort() bool {
if qB_useNewBanPeersMethod {
if currentClientType == "qBittorrent" && qB_useNewBanPeersMethod {
return true
}
@ -14,8 +14,6 @@ func IsSupportClient() bool {
switch currentClientType {
case "qBittorrent", "Transmission", "BitComet":
return true
default:
return false
}
return false

View File

@ -26,7 +26,8 @@ type ReleaseStruct struct {
}
func ProcessVersion(version string) (int, int, int, int, string) {
versionSplit := strings.SplitN(strings.SplitN(version, " ", 2)[0], ".", 2)
realVersion := strings.SplitN(version, " ", 2)[0]
versionSplit := strings.SplitN(realVersion, ".", 2)
if versionSplit[0] == "Unknown" {
return -1, 0, 0, 0, ""
@ -69,7 +70,7 @@ func ProcessVersion(version string) (int, int, int, int, string) {
return -3, 0, 0, 0, ""
}
return versionType, mainVersion, subVersion, sub2Version, version
return versionType, mainVersion, subVersion, sub2Version, realVersion
}
func CheckUpdate() {
if !config.CheckUpdate || (lastCheckUpdateTimestamp + 86400) > currentTimestamp {
@ -241,7 +242,7 @@ func Task() {
}
}
currentIPBlockCount := CheckAllIP(ipMap, lastIPMap)
ipBlockCount += CheckAllIP(ipMap, lastIPMap)
torrentBlockCount, torrentIPBlockCount := CheckAllTorrent(torrentMap, lastTorrentMap)
blockCount += torrentBlockCount
ipBlockCount += torrentIPBlockCount
@ -253,12 +254,12 @@ func Task() {
Log("Debug-Task_IgnoreBadPeersCount", "%d", false, badPeersCount)
Log("Debug-Task_IgnoreEmptyPeersCount", "%d", false, emptyPeersCount)
if cleanCount != 0 || blockCount != 0 {
if cleanCount != 0 || blockCount != 0 || ipBlockCount != 0 {
SubmitBlockPeer(blockPeerMap)
if !config.IPUploadedCheck && len(ipBlockListCompiled) <= 0 && len(ipBlockListFromURLCompiled) <= 0 {
Log("Task", GetLangText("Task_BanInfo"), true, blockCount, len(blockPeerMap))
} else {
Log("Task", GetLangText("Task_BanInfoWithIP"), true, blockCount, len(blockPeerMap), currentIPBlockCount, ipBlockCount)
Log("Task", GetLangText("Task_BanInfoWithIP"), true, blockCount, ipBlockCount, len(blockPeerMap))
}
}
@ -299,8 +300,15 @@ func WaitStop() {
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
<-signalChan
Log("WaitStop", GetLangText("WaitStop_Stoping"), true)
isRunning = false
ReqStop()
}
func ReqStop() {
if !isRunning {
return
}
Log("ReqStop", GetLangText("ReqStop_Stoping"), true)
isRunning = false
}
func RunConsole() {
if startDelay > 0 {

View File

@ -20,7 +20,7 @@ if [ -n "$useENV" ]; then
# Convert "true" to true, "false" to false, digital string to number
configKVPair=$(echo $envKVPair | jq --argjson tmpBlockList "$tmpBlockList" --argjson tmpIPBlockList "$tmpIPBlockList" '{
(.key): (
if (.key|ascii_downcase) == "qbusername" or (.key|ascii_downcase) == "qbpassword" then .value
if (.key|ascii_downcase) == "clientusername" or (.key|ascii_downcase) == "clientpassword" then .value
elif (.key|ascii_downcase) == "blocklist" then $tmpBlockList
elif (.key|ascii_downcase) == "ipblocklist" then $tmpIPBlockList
else .value|(
@ -32,7 +32,7 @@ if [ -n "$useENV" ]; then
)
}')
(echo $configKVPair | jq -s add) > config.json
(echo $configKVPair | jq -s add) > config_additional.json
fi
commandArgStr=''

View File

@ -17,9 +17,9 @@ var defaultLangContent = map[string]string {
"RunConsole_StartDelay": "启动延迟: %d 秒",
"RunConsole_AuthFailed": "认证失败",
"RunConsole_ProgramHasStarted": "程序已启动",
"WaitStop_Stoping": "程序正在停止..",
"ReqStop_Stoping": "程序正在停止..",
"Task_BanInfo": "此次封禁客户端: %d 个, 当前封禁客户端: %d 个",
"Task_BanInfoWithIP": "此次封禁客户端: %d 个, 当前封禁客户端: %d 个, 此次封禁 IP 地址: %d 个, 当前封禁 IP 地址: %d 个",
"Task_BanInfoWithIP": "此次封禁客户端: %d 个, 此次封禁 IP: %d 个, 当前封禁 IP 及客户端: %d 个",
"GC_IPMap": "触发垃圾回收 (ipMap): %d",
"GC_TorrentMap": "触发垃圾回收 (torrentMap): %s/%d",
"GetConfig_UseConfig": "使用客户端配置文件: %s",

View File

@ -7,9 +7,9 @@
"RunConsole_StartDelay": "Start delay: %d Sec",
"RunConsole_AuthFailed": "Authentication failed",
"RunConsole_ProgramHasStarted": "Program has started",
"WaitStop_Stoping": "Program is stopping..",
"ReqStop_Stoping": "Program is stopping..",
"Task_BanInfo": "Ban Client (This time): %d, Ban Client (Current): %d",
"Task_BanInfoWithIP": "Ban Client (This time): %d, Ban Client (Current): %d, Ban IP (This time): %d, Ban IP (Current): %d",
"Task_BanInfoWithIP": "Ban Client (This time): %d, Ban IP (This time): %d, Ban IP/Client (Current): %d",
"GC_IPMap": "Trigger GC (ipMap): %d",
"GC_TorrentMap": "Trigger GC (torrentMap): %s/%d",
"GetConfig_UseConfig": "Use client config: %s",