更新 main.go
This commit is contained in:
64
main.go
64
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
@@ -22,7 +23,7 @@ const (
|
|||||||
downloadDir = "./chrome_versions"
|
downloadDir = "./chrome_versions"
|
||||||
checkInterval = 24 * time.Hour
|
checkInterval = 24 * time.Hour
|
||||||
maxRetries = 3
|
maxRetries = 3
|
||||||
updateXMLURL = "https://tools.google.com/service/update2"
|
updateURL = "https://tools.google.com/service/update2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -38,23 +39,11 @@ type Version struct {
|
|||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCheck struct {
|
|
||||||
XMLName xml.Name `xml:"request"`
|
|
||||||
OS struct {
|
|
||||||
Platform string `xml:"platform,attr"`
|
|
||||||
Arch string `xml:"arch,attr"`
|
|
||||||
} `xml:"os"`
|
|
||||||
App struct {
|
|
||||||
AppID string `xml:"appid,attr"`
|
|
||||||
Version string `xml:"version,attr"`
|
|
||||||
Lang string `xml:"lang,attr"`
|
|
||||||
UpdateCheck struct{} `xml:"updatecheck"`
|
|
||||||
} `xml:"app"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateResponse struct {
|
type UpdateResponse struct {
|
||||||
XMLName xml.Name `xml:"response"`
|
XMLName xml.Name `xml:"response"`
|
||||||
|
Protocol string `xml:"protocol,attr"`
|
||||||
App struct {
|
App struct {
|
||||||
|
Status string `xml:"status,attr"`
|
||||||
UpdateCheck struct {
|
UpdateCheck struct {
|
||||||
Status string `xml:"status,attr"`
|
Status string `xml:"status,attr"`
|
||||||
URLs struct {
|
URLs struct {
|
||||||
@@ -69,7 +58,8 @@ type UpdateResponse struct {
|
|||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Required bool `xml:"required,attr"`
|
Required bool `xml:"required,attr"`
|
||||||
Size int64 `xml:"size,attr"`
|
Size int64 `xml:"size,attr"`
|
||||||
Hash string `xml:"hash_sha256,attr"`
|
Hash string `xml:"hash,attr"`
|
||||||
|
HashSHA256 string `xml:"hash_sha256,attr"`
|
||||||
} `xml:"package"`
|
} `xml:"package"`
|
||||||
} `xml:"packages"`
|
} `xml:"packages"`
|
||||||
} `xml:"manifest"`
|
} `xml:"manifest"`
|
||||||
@@ -117,42 +107,51 @@ func monitor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLatestVersionInfo() (version, downloadURL string, err error) {
|
func getLatestVersionInfo() (version, downloadURL, sha256 string, err error) {
|
||||||
reqBody := `<?xml version="1.0" encoding="UTF-8"?>
|
reqBody := `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<request protocol="3.0" version="1.3.23.9" shell_version="1.3.21.103" ismachine="0" sessionid="{3597644B-2952-4F92-AE55-D315F45F80A5}" installsource="ondemandcheckforupdate" requestid="{CD7523AD-A40D-49F4-AEEF-8C114B804658}" dedup="cr" domainjoined="0">
|
<request protocol="3.0" updater="Omaha" updaterversion="1.3.36.372" shell_version="1.3.36.352" ismachine="0" sessionid="{11111111-1111-1111-1111-111111111111}" installsource="taggedmi" requestid="{11111111-1111-1111-1111-111111111111}" dedup="cr" domainjoined="0">
|
||||||
<hw sse="1" sse2="1" sse3="1" ssse3="1" sse41="1" sse42="1" avx="1" physmemory="16" />
|
<hw physmemory="16" sse="1" sse2="1" sse3="1" ssse3="1" sse41="1" sse42="1" avx="1"/>
|
||||||
<os platform="win" version="10.0.19045.0" sp="" arch="x64"/>
|
<os platform="win" version="10.0.26100.1742" arch="x64"/>
|
||||||
<app appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" version="" nextversion="" lang="zh-CN" brand="GCEU" client="" installage="1">
|
<app version="" appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="x64-stable">
|
||||||
<updatecheck/>
|
<updatecheck/>
|
||||||
</app>
|
<data name="install" index="empty"/>
|
||||||
|
</app>
|
||||||
</request>`
|
</request>`
|
||||||
|
|
||||||
resp, err := http.Post(updateXMLURL, "application/xml", strings.NewReader(reqBody))
|
resp, err := http.Post(updateURL, "application/xml", strings.NewReader(reqBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
log.Printf("Update response: %s", string(body))
|
|
||||||
|
|
||||||
var updateResp UpdateResponse
|
var updateResp UpdateResponse
|
||||||
if err := xml.Unmarshal(body, &updateResp); err != nil {
|
if err := xml.Unmarshal(body, &updateResp); err != nil {
|
||||||
return "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
version = updateResp.App.UpdateCheck.Manifest.Version
|
version = updateResp.App.UpdateCheck.Manifest.Version
|
||||||
if len(updateResp.App.UpdateCheck.URLs.URL) > 0 {
|
sha256 = updateResp.App.UpdateCheck.Manifest.Packages.Package.HashSHA256
|
||||||
codebase := updateResp.App.UpdateCheck.URLs.URL[0].Codebase
|
|
||||||
packageName := updateResp.App.UpdateCheck.Manifest.Packages.Package.Name
|
packageName := updateResp.App.UpdateCheck.Manifest.Packages.Package.Name
|
||||||
downloadURL = codebase + packageName
|
|
||||||
|
if len(updateResp.App.UpdateCheck.URLs.URL) > 0 {
|
||||||
|
for _, url := range updateResp.App.UpdateCheck.URLs.URL {
|
||||||
|
if strings.HasPrefix(url.Codebase, "https://dl.google.com") {
|
||||||
|
downloadURL = url.Codebase + packageName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if downloadURL == "" {
|
||||||
|
downloadURL = updateResp.App.UpdateCheck.URLs.URL[0].Codebase + packageName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return version, downloadURL, nil
|
return version, downloadURL, sha256, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkAndDownload() {
|
func checkAndDownload() {
|
||||||
version, downloadURL, err := getLatestVersionInfo()
|
version, downloadURL, sha256, err := getLatestVersionInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get version info: %v", err)
|
log.Printf("Failed to get version info: %v", err)
|
||||||
return
|
return
|
||||||
@@ -160,6 +159,7 @@ func checkAndDownload() {
|
|||||||
|
|
||||||
log.Printf("Latest Chrome version: %s", version)
|
log.Printf("Latest Chrome version: %s", version)
|
||||||
log.Printf("Download URL: %s", downloadURL)
|
log.Printf("Download URL: %s", downloadURL)
|
||||||
|
log.Printf("SHA256: %s", sha256)
|
||||||
|
|
||||||
if downloadURL == "" {
|
if downloadURL == "" {
|
||||||
log.Println("No download URL found")
|
log.Println("No download URL found")
|
||||||
|
|||||||
Reference in New Issue
Block a user