Fix: change in username property, auto-gen a persistent device fingerprint

This commit is contained in:
TheAxeDude 2023-09-04 19:07:09 +02:00
parent b5be608b39
commit 968d07064e
10 changed files with 50 additions and 17 deletions

View File

@ -10,12 +10,14 @@ import (
"github.com/pdfcpu/pdfcpu/pkg/api" "github.com/pdfcpu/pdfcpu/pkg/api"
"github.com/playwright-community/playwright-go" "github.com/playwright-community/playwright-go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -40,6 +42,7 @@ func main() {
zinioHostPtr := flag.String("e", "api-sec.ziniopro.com", "Zinio Host (Excluding port and URI Scheme). Known: `api-sec`, `api-sec-2`") zinioHostPtr := flag.String("e", "api-sec.ziniopro.com", "Zinio Host (Excluding port and URI Scheme). Known: `api-sec`, `api-sec-2`")
exportUsingWKHTML := flag.String("wkhtml", "false", "Use WKHTML instead of Chrome to generate PDF (false by default)") exportUsingWKHTML := flag.String("wkhtml", "false", "Use WKHTML instead of Chrome to generate PDF (false by default)")
exportUsingPlaywright := flag.String("playwright", "false", "Use Playwright Chromium instead of local Chrome to generate PDF (false by default)") exportUsingPlaywright := flag.String("playwright", "false", "Use Playwright Chromium instead of local Chrome to generate PDF (false by default)")
deviceFingerprintPtr := flag.String("fingerprint", "abcd123", "This devices fingerprint - presented to Zinio API")
flag.Parse() flag.Parse()
@ -69,6 +72,20 @@ func main() {
fmt.Println("chromepath taken from config file") fmt.Println("chromepath taken from config file")
} }
fingerprint := gjson.GetBytes(byteValue, "fingerprint")
if fingerprint.Exists() {
*deviceFingerprintPtr = fingerprint.String()
fmt.Println("Fingerprint taken from config file")
} else {
fmt.Println("No fingerprint found in text file, generating and writing")
newJson, _ := sjson.Set(string(byteValue), "fingerprint", randSeq(15))
err := ioutil.WriteFile("config.json", []byte(newJson), 0644)
if err != nil {
log.Fatalf("unable to write file: %v", err)
}
}
} }
//fmt.Println("Starting the application...") //fmt.Println("Starting the application...")
@ -76,7 +93,7 @@ func main() {
//if err != nil { //if err != nil {
// os.Exit(1) // os.Exit(1)
//} //}
loginToken := GetLoginToken(*usernamePtr, *passwordPtr) loginToken := GetLoginToken(*usernamePtr, *passwordPtr, *deviceFingerprintPtr)
issues := GetLibrary(loginToken, *zinioHostPtr) issues := GetLibrary(loginToken, *zinioHostPtr)
for i := range issues { for i := range issues {
issueList := issues[i] issueList := issues[i]
@ -93,17 +110,19 @@ func main() {
fmt.Println("Resolved working directory to: " + mydir) fmt.Println("Resolved working directory to: " + mydir)
//fmt.Println("Grabbing list of pages...") //fmt.Println("Grabbing list of pages...")
if _, err := os.Stat(mydir + "/issue/"); os.IsNotExist(err) { issueDirectory := filepath.Join(mydir, "issue")
os.Mkdir(mydir+"/issue/", 0600) if _, err := os.Stat(issueDirectory); os.IsNotExist(err) {
os.Mkdir(issueDirectory, 0600)
} }
for _, issue := range issueList.Data { for _, issue := range issueList.Data {
issuePath := mydir + "/issue/" + strconv.Itoa(issue.Id) fmt.Println(issue)
issuePath := filepath.Join(issueDirectory, strconv.Itoa(issue.Id))
publicationName := RemoveBadCharacters(issue.Publication.Name) publicationName := RemoveBadCharacters(issue.Publication.Name)
issueName := RemoveBadCharacters(issue.Name) issueName := RemoveBadCharacters(issue.Name)
completeName := mydir + "/issue/" + publicationName + " - " + issueName + ".pdf" completeName := filepath.Join(issueDirectory, publicationName+" - "+issueName+".pdf")
fmt.Println("Checking if issue exists: " + completeName) fmt.Println("Checking if issue exists: " + completeName)
if fileExists(completeName) { if fileExists(completeName) {
fmt.Println("Issue already found: " + completeName) fmt.Println("Issue already found: " + completeName)
@ -273,13 +292,13 @@ func GetInitialToken() (token string, err error) {
return string(found[2]), nil return string(found[2]), nil
} }
func GetLoginToken(username string, password string) LoginResponse { func GetLoginToken(username string, password string, fingerprint string) LoginResponse {
fmt.Println("GettingLogin") fmt.Println("GettingLogin")
client := &http.Client{} client := &http.Client{}
var jsonStr = []byte(`{"username":"` + username + `","password":"` + password + `","device":{"name":"Windows Chrome","fingerprint":"` + randSeq(32) + `","device_type":"Desktop","client_type":"Web"},"newsstand":{"currency":"ZAR","id":134,"country":"ZA","name":"South Africa","cc":"za","localeCode":"en_ZA","userLang":"en_ZA","userCountry":"ZA","userCurrency":"ZAR","requiresCookies":true,"requiresExplicitConsent":true,"requiresAdultConfirmation":true,"adWords":{"id":1,"label":""},"isDefaultNewsstand":false}}`) var jsonStr = []byte(`{"email":"` + username + `","password":"` + password + `","device":{"name":"Windows Chrome","fingerprint":"` + fingerprint + `","device_type":"Desktop","client_type":"Web"},"newsstand":{"currency":"ZAR","id":134,"country":"ZA","name":"South Africa","cc":"za","localeCode":"en_ZA","userLang":"en_ZA","userCountry":"ZA","userCurrency":"ZAR","requiresCookies":true,"requiresExplicitConsent":true,"requiresAdultConfirmation":true,"adWords":{"id":1,"label":""},"isDefaultNewsstand":false}}`)
//fmt.Println(string(jsonStr)) fmt.Println(string(jsonStr))
req, _ := http.NewRequest("POST", "https://www.zinio.com/api/login?project=99&logger=null", bytes.NewBuffer(jsonStr)) req, _ := http.NewRequest("POST", "https://www.zinio.com/api/login?project=99&logger=null", bytes.NewBuffer(jsonStr))

View File

@ -3,18 +3,27 @@ set GOARCH=amd64
cd .. cd ..
go build -v -o built/Zinigo_Windows_x64.exe Zinigo/main.go go build -v -o built/Zinigo_Windows_x64.exe Zinigo/main.go
cd buildscripts cd buildscripts
set GOOS=windows
set GOARCH=386
cd ..
go build -o built/Zinigo_Windows_x86.exe Zinigo/main.go
cd buildscripts
set GOOS=linux set GOOS=linux
set GOARCH=amd64 set GOARCH=amd64
cd .. cd ..
go build -o built/Zinigo_Linux_AMD64 Zinigo/main.go go build -o built/Zinigo_Linux_AMD64 Zinigo/main.go
cd buildscripts cd buildscripts
set GOOS=darwin set GOOS=darwin
set GOARCH=amd64 set GOARCH=amd64
cd .. cd ..
go build -o built/Zinigo_Macos_AMD64 Zinigo/main.go go build -o built/Zinigo_Macos_Intel Zinigo/main.go
cd buildscripts cd buildscripts
set GOOS=windows
set GOARCH=386 set GOOS=darwin
set GOARCH=arm64
cd .. cd ..
go build -o built/Zinigo_Windows.exe Zinigo/main.go go build -o built/Zinigo_Macos_AppleSilicon Zinigo/main.go
cd buildscripts cd buildscripts

Binary file not shown.

Binary file not shown.

BIN
built/Zinigo_Macos_AppleSilicon Normal file → Executable file

Binary file not shown.

BIN
built/Zinigo_Macos_Intel Normal file → Executable file

Binary file not shown.

Binary file not shown.

BIN
built/Zinigo_Windows_x86.exe Normal file → Executable file

Binary file not shown.

5
go.mod
View File

@ -7,7 +7,8 @@ require (
github.com/icza/gox v0.0.0-20220921190100-610a6663952b github.com/icza/gox v0.0.0-20220921190100-610a6663952b
github.com/pdfcpu/pdfcpu v0.3.13 github.com/pdfcpu/pdfcpu v0.3.13
github.com/playwright-community/playwright-go v0.2000.1 github.com/playwright-community/playwright-go v0.2000.1
github.com/tidwall/gjson v1.14.3 github.com/tidwall/gjson v1.16.0
github.com/tidwall/sjson v1.2.5
) )
require ( require (
@ -18,7 +19,7 @@ require (
github.com/kr/text v0.2.0 // indirect github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/pretty v1.2.1 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/text v0.3.6 // indirect golang.org/x/text v0.3.6 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect

10
go.sum
View File

@ -32,12 +32,16 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg=
github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk= golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=