Skip to content

Commit

Permalink
re-factor anti tls / h2 anti-fingerprinting. update to chrome v120
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Dec 18, 2023
1 parent a2c05e6 commit 0998041
Show file tree
Hide file tree
Showing 22 changed files with 402 additions and 516 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ptool

自用的 PT (private tracker) 网站辅助工具。提供全自动刷流(brush)、自动辅种(使用 iyuu 接口)、BT客户端控制等功能。
自用的 PT (private tracker) 网站辅助工具([Github](https://github.com/sagan/ptool))。提供全自动刷流(brush)、自动辅种(使用 iyuu 接口)、BT客户端控制等功能。

主要特性:

Expand Down
4 changes: 2 additions & 2 deletions client/qbittorrent/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func (qbclient *Client) GetTorrentContents(infoHash string) ([]client.TorrentCon
}
apiUrl := qbclient.ClientConfig.Url + "api/v2/torrents/files?hash=" + infoHash
qbTorrentContents := []apiTorrentContent{}
err = util.FetchJson(apiUrl, &qbTorrentContents, qbclient.HttpClient, "", "", nil)
err = util.FetchJson(apiUrl, &qbTorrentContents, qbclient.HttpClient)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -877,7 +877,7 @@ func (qbclient *Client) GetTorrentTrackers(infoHash string) (client.TorrentTrack
}
apiUrl := qbclient.ClientConfig.Url + "api/v2/torrents/trackers?hash=" + infoHash
qbTorrentTrackers := []apiTorrentTracker{}
err = util.FetchJson(apiUrl, &qbTorrentTrackers, qbclient.HttpClient, "", "", nil)
err = util.FetchJson(apiUrl, &qbTorrentTrackers, qbclient.HttpClient)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cookiecloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GetCookiecloudData(server string, uuid string, password string, proxy strin
}
}
var data *CookieCloudBody
err := util.FetchJson(server+"get/"+uuid, &data, httpClient, "", "", nil)
err := util.FetchJson(server+"get/"+uuid, &data, httpClient)
if err != nil || data == nil {
return nil, fmt.Errorf("failed to get cookiecloud data: err=%v, null data=%t", err, data == nil)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/cookiecloud/cookiecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
)

var Command = &cobra.Command{
Use: "cookiecloud",
Short: "Use cookiecloud to sync site cookies or import sites.",
Use: "cookiecloud",
Aliases: []string{"cc"},
Short: "Use cookiecloud to sync site cookies or import sites.",
Long: `Use cookiecloud to sync site cookies or import sites.
To use this feature, add the cookiecloud servers to config file, e.g. :
Expand Down
10 changes: 4 additions & 6 deletions cmd/iyuu/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ func IyuuApiHash(token string, infoHashes []string) (map[string][]IyuuTorrentInf
}

func IyuuApiGetUser(token string) (data map[string]any, err error) {
err = util.FetchJson("https://api.iyuu.cn/index.php?s=App.Api.GetUser&sign="+token,
&data, nil, "", "", nil)
err = util.FetchJson("https://api.iyuu.cn/index.php?s=App.Api.GetUser&sign="+token, &data, nil)
return
}

func IyuuApiSites(token string) ([]IyuuApiSite, error) {
resData := &IyuuApiSitesResponse{}
err := util.FetchJson("https://api.iyuu.cn/index.php?s=App.Api.Sites&version="+
IYUU_VERSION+"&sign="+token,
resData, nil, "", "", nil)
IYUU_VERSION+"&sign="+token, resData, nil)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +136,7 @@ func IyuuApiBind(token string, site string, uid int64, passkey string) (map[stri
"&site=" + site + "&id=" + fmt.Sprint(uid) + "&passkey=" + util.Sha1String(passkey)

resData := &IyuuApiResponse{}
err := util.FetchJson(apiUrl, &resData, nil, "", "", nil)
err := util.FetchJson(apiUrl, &resData, nil)
if err != nil {
return nil, err
}
Expand All @@ -152,7 +150,7 @@ func IyuuApiGetRecommendSites() ([]IyuuApiRecommendSite, error) {
apiUrl := "https://api.iyuu.cn/index.php?s=App.Api.GetRecommendSites"

var resData *IyuuGetRecommendSitesResponse
err := util.FetchJson(apiUrl, &resData, nil, "", "", nil)
err := util.FetchJson(apiUrl, &resData, nil)
if err != nil {
return nil, err
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/versioncmd/versioncmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ func versioncmd(cmd *cobra.Command, args []string) error {
fmt.Printf("- os/type: %s\n", runtime.GOOS)
fmt.Printf("- os/arch: %s\n", runtime.GOARCH)
fmt.Printf("- go/version: %s\n", runtime.Version())
fmt.Printf("- config/default_ua: %s\n", util.CHROME_HTTP_REQUEST_HEADERS["User-Agent"])
fmt.Printf("- config/default_http_request_headers:\n")
defaultHttpHeaders := util.MapKeys(util.CHROME_HTTP_REQUEST_HEADERS)
for _, key := range defaultHttpHeaders {
fmt.Printf(" %s: %s\n", key, util.CHROME_HTTP_REQUEST_HEADERS[key])
for _, header := range util.CHROME_HTTP_REQUEST_HEADERS {
value := header[1]
if value == util.HTTP_HEADER_PLACEHOLDER {
value = ""
}
fmt.Printf(" %s: %s\n", header[0], value)
}
return nil
}
128 changes: 67 additions & 61 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
DEFAULT_CLIENT_BRUSH_MAX_TORRENTS = int64(9999)
DEFAULT_CLIENT_BRUSH_MIN_RATION = float64(0.2)
DEFAULT_CLIENT_BRUSH_DEFAULT_UPLOAD_SPEED_LIMIT = int64(10 * 1024 * 1024)
DEFAULT_SITE_TIMEOUT = int64(5)
DEFAULT_SITE_BRUSH_TORRENT_MIN_SIZE_LIMIT = int64(0)
DEFAULT_SITE_BRUSH_TORRENT_MAX_SIZE_LIMIT = int64(1024 * 1024 * 1024 * 1024 * 1024) // 1PB, that's say, unlimited
DEFAULT_SITE_TORRENT_UPLOAD_SPEED_LIMIT = int64(10 * 1024 * 1024)
Expand Down Expand Up @@ -79,65 +80,67 @@ type ClientConfigStruct struct {
}

type SiteConfigStruct struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Aliases []string // for internal use only
Comment string `yaml:"comment"`
Disabled bool `yaml:"disabled"`
Hidden bool `yaml:"hidden"` // exclude from default groups (like "_all")
Url string `yaml:"url"`
Domains []string `yaml:"domains"` // other site domains (do not include subdomain part)
TorrentsUrl string `yaml:"torrentsUrl"`
SearchUrl string `yaml:"searchUrl"`
TorrentsExtraUrls []string `yaml:"torrentsExtraUrls"`
Cookie string `yaml:"cookie"`
UserAgent string `yaml:"userAgent"`
HttpHeaders *map[string]string `yaml:"httpHeaders"`
NoDefaultHttpHeaders bool `yaml:"noDefaultHttpHeaders"`
Ja3 string `yaml:"ja3"`
Ja3ForceAttemptHTTP2 bool `yaml:"ja3ForceAttemptHTTP2"`
Proxy string `yaml:"proxy"`
Insecure bool `yaml:"insecure"` // 访问站点时跳过TLS证书安全校验
TorrentUploadSpeedLimit string `yaml:"torrentUploadSpeedLimit"`
GlobalHnR bool `yaml:"globalHnR"`
Timezone string `yaml:"timezone"`
BrushTorrentMinSizeLimit string `yaml:"brushTorrentMinSizeLimit"`
BrushTorrentMaxSizeLimit string `yaml:"brushTorrentMaxSizeLimit"`
BrushAllowNoneFree bool `yaml:"brushAllowNoneFree"`
BrushAllowPaid bool `yaml:"brushAllowPaid"`
BrushAllowHr bool `yaml:"brushAllowHr"`
BrushAllowZeroSeeders bool `yaml:"brushAllowZeroSeeders"`
BrushExcludes []string `yaml:"brushExcludes"`
SelectorTorrentsListHeader string `yaml:"selectorTorrentsListHeader"`
SelectorTorrentsList string `yaml:"selectorTorrentsList"`
SelectorTorrentBlock string `yaml:"selectorTorrentBlock"` // dom block of a torrent in list
SelectorTorrent string `yaml:"selectorTorrent"`
SelectorTorrentDownloadLink string `yaml:"selectorTorrentDownloadLink"`
SelectorTorrentDetailsLink string `yaml:"selectorTorrentDetailsLink"`
SelectorTorrentTime string `yaml:"selectorTorrentTime"`
SelectorTorrentSeeders string `yaml:"selectorTorrentSeeders"`
SelectorTorrentLeechers string `yaml:"selectorTorrentLeechers"`
SelectorTorrentSnatched string `yaml:"selectorTorrentSnatched"`
SelectorTorrentSize string `yaml:"selectorTorrentSize"`
SelectorTorrentProcessBar string `yaml:"selectorTorrentProcessBar"`
SelectorTorrentFree string `yaml:"SelectorTorrentFree"`
SelectorTorrentNoTraffic string `yaml:"selectorTorrentNoTraffic"`
SelectorTorrentNeutral string `yaml:"selectorTorrentNeutral"`
SelectorTorrentHnR string `yaml:"selectorTorrentHnR"`
SelectorTorrentPaid string `yaml:"selectorTorrentPaid"`
SelectorTorrentDiscountEndTime string `yaml:"selectorTorrentDiscountEndTime"`
SelectorUserInfo string `yaml:"selectorUserInfo"`
SelectorUserInfoUserName string `yaml:"selectorUserInfoUserName"`
SelectorUserInfoUploaded string `yaml:"selectorUserInfoUploaded"`
SelectorUserInfoDownloaded string `yaml:"selectorUserInfoDownloaded"`
TorrentDownloadUrl string `yaml:"torrentDownloadUrl"` // use {id} placeholders in url
TorrentDownloadUrlPrefix string `yaml:"torrentDownloadUrlPrefix"`
Passkey string `yaml:"passkey"`
UseCuhash bool `yaml:"useCuhash"` // hdcity 使用机制。种子下载地址里必须有cuhash参数
UseDigitHash bool `yaml:"useDigitHash"` // ttg 使用机制。种子下载地址末段必须有4位数字校验码或Passkey参数(即使有 Cookie)
TorrentUrlIdRegexp string `yaml:"torrentUrlIdRegexp"`
FlowControlInterval int64 `yaml:"flowControlInterval"` // 暂定名。两次请求种子列表页间隔时间(秒)
NexusphpNoLetDown bool `yaml:"nexusphpNoLetDown"`
Type string `yaml:"type"`
Name string `yaml:"name"`
Aliases []string // for internal use only
Comment string `yaml:"comment"`
Disabled bool `yaml:"disabled"`
Hidden bool `yaml:"hidden"` // exclude from default groups (like "_all")
Url string `yaml:"url"`
Domains []string `yaml:"domains"` // other site domains (do not include subdomain part)
TorrentsUrl string `yaml:"torrentsUrl"`
SearchUrl string `yaml:"searchUrl"`
TorrentsExtraUrls []string `yaml:"torrentsExtraUrls"`
Cookie string `yaml:"cookie"`
UserAgent string `yaml:"userAgent"`
HttpHeaders [][]string `yaml:"httpHeaders"`
NoDefaultHttpHeaders bool `yaml:"noDefaultHttpHeaders"`
Ja3 string `yaml:"ja3"`
Timeoout int64 `yaml:"timeout"`
H2Fingerprint string `yaml:"h2Fingerprint"`
Proxy string `yaml:"proxy"`
Insecure bool `yaml:"insecure"` // 访问站点时强制跳过TLS证书安全校验
Secure bool `yaml:"secure"` // 访问站点时强制TLS证书安全校验
TorrentUploadSpeedLimit string `yaml:"torrentUploadSpeedLimit"`
GlobalHnR bool `yaml:"globalHnR"`
Timezone string `yaml:"timezone"`
BrushTorrentMinSizeLimit string `yaml:"brushTorrentMinSizeLimit"`
BrushTorrentMaxSizeLimit string `yaml:"brushTorrentMaxSizeLimit"`
BrushAllowNoneFree bool `yaml:"brushAllowNoneFree"`
BrushAllowPaid bool `yaml:"brushAllowPaid"`
BrushAllowHr bool `yaml:"brushAllowHr"`
BrushAllowZeroSeeders bool `yaml:"brushAllowZeroSeeders"`
BrushExcludes []string `yaml:"brushExcludes"`
SelectorTorrentsListHeader string `yaml:"selectorTorrentsListHeader"`
SelectorTorrentsList string `yaml:"selectorTorrentsList"`
SelectorTorrentBlock string `yaml:"selectorTorrentBlock"` // dom block of a torrent in list
SelectorTorrent string `yaml:"selectorTorrent"`
SelectorTorrentDownloadLink string `yaml:"selectorTorrentDownloadLink"`
SelectorTorrentDetailsLink string `yaml:"selectorTorrentDetailsLink"`
SelectorTorrentTime string `yaml:"selectorTorrentTime"`
SelectorTorrentSeeders string `yaml:"selectorTorrentSeeders"`
SelectorTorrentLeechers string `yaml:"selectorTorrentLeechers"`
SelectorTorrentSnatched string `yaml:"selectorTorrentSnatched"`
SelectorTorrentSize string `yaml:"selectorTorrentSize"`
SelectorTorrentProcessBar string `yaml:"selectorTorrentProcessBar"`
SelectorTorrentFree string `yaml:"SelectorTorrentFree"`
SelectorTorrentNoTraffic string `yaml:"selectorTorrentNoTraffic"`
SelectorTorrentNeutral string `yaml:"selectorTorrentNeutral"`
SelectorTorrentHnR string `yaml:"selectorTorrentHnR"`
SelectorTorrentPaid string `yaml:"selectorTorrentPaid"`
SelectorTorrentDiscountEndTime string `yaml:"selectorTorrentDiscountEndTime"`
SelectorUserInfo string `yaml:"selectorUserInfo"`
SelectorUserInfoUserName string `yaml:"selectorUserInfoUserName"`
SelectorUserInfoUploaded string `yaml:"selectorUserInfoUploaded"`
SelectorUserInfoDownloaded string `yaml:"selectorUserInfoDownloaded"`
TorrentDownloadUrl string `yaml:"torrentDownloadUrl"` // use {id} placeholders in url
TorrentDownloadUrlPrefix string `yaml:"torrentDownloadUrlPrefix"`
Passkey string `yaml:"passkey"`
UseCuhash bool `yaml:"useCuhash"` // hdcity 使用机制。种子下载地址里必须有cuhash参数
UseDigitHash bool `yaml:"useDigitHash"` // ttg 使用机制。种子下载地址末段必须有4位数字校验码或Passkey参数(即使有 Cookie)
TorrentUrlIdRegexp string `yaml:"torrentUrlIdRegexp"`
FlowControlInterval int64 `yaml:"flowControlInterval"` // 暂定名。两次请求种子列表页间隔时间(秒)
NexusphpNoLetDown bool `yaml:"nexusphpNoLetDown"`
TorrentUploadSpeedLimitValue int64
BrushTorrentMinSizeLimitValue int64
BrushTorrentMaxSizeLimitValue int64
Expand All @@ -152,8 +155,11 @@ type ConfigStruct struct {
SiteProxy string `yaml:"siteProxy"`
SiteUserAgent string `yaml:"siteUserAgent"`
SiteNoDefaultHttpHeaders bool `yaml:"siteNoDefaultHttpHeaders"`
SiteHttpHeaders *map[string]string `yaml:"siteHttpHeaders"`
SiteHttpHeaders [][]string `yaml:"siteHttpHeaders"`
SiteJa3 string `yaml:"siteJa3"`
SiteTimeout int64 `yaml:"siteTimeout"` // 访问网站超时时间(秒)
SiteSecure bool `yaml:"siteSecure"` // 强制开启所有站点 TLS 证书校验。
SiteH2Fingerprint string `yaml:"siteH2Fingerprint"`
BrushEnableStats bool `yaml:"brushEnableStats"`
Clients []*ClientConfigStruct `yaml:"clients"`
Sites []*SiteConfigStruct `yaml:"sites"`
Expand Down Expand Up @@ -447,7 +453,7 @@ func (siteConfig *SiteConfigStruct) ParseSiteUrl(siteUrl string, appendQueryStri
pageUrl = siteUrl
} else {
siteUrl = strings.TrimPrefix(siteUrl, "/")
pageUrl = siteConfig.Url + siteUrl
pageUrl = strings.TrimSuffix(siteConfig.Url, "/") + "/" + siteUrl
}
}

Expand Down
25 changes: 15 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ replace github.com/stromland/cobra-prompt => ./cobra-prompt

require (
github.com/Emyrk/torrent v0.0.0-20170330203609-3216b1ef9450
github.com/Noooste/azuretls-client v1.2.4
github.com/PuerkitoBio/goquery v1.8.1
github.com/anacrolix/torrent v1.52.3
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8
Expand All @@ -26,19 +27,18 @@ require (
github.com/jpillora/go-tld v1.2.1
github.com/mattn/go-runewidth v0.0.14
github.com/pelletier/go-toml/v2 v2.0.8
github.com/refraction-networking/utls v1.3.2
github.com/sirupsen/logrus v1.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stromland/cobra-prompt v0.5.0
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
golang.org/x/net v0.10.0
golang.org/x/net v0.19.0
gorm.io/gorm v1.25.1
)

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
modernc.org/libc v1.22.6 // indirect
Expand All @@ -48,12 +48,16 @@ require (
)

require (
github.com/Noooste/fhttp v1.0.6 // indirect
github.com/Noooste/go-utils v1.0.5 // indirect
github.com/Noooste/utls v1.2.4 // indirect
github.com/Noooste/websocket v1.0.1 // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/v2 v2.7.2-0.20230527121029-a582b4f397b9 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/cloudflare/circl v1.3.6 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gaukas/godicttls v0.0.3 // indirect
github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -62,21 +66,22 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/quic-go/quic-go v0.40.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

0 comments on commit 0998041

Please sign in to comment.