mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Resolve hostname for chromium RDP requests (#2174)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -87,7 +88,7 @@ func loadURL(ctx context.Context, loadURL string, client *http.Client, scraperCo
|
|||||||
// func urlFromCDP uses chrome cdp and DOM to load and process the url
|
// func urlFromCDP uses chrome cdp and DOM to load and process the url
|
||||||
// if remote is set as true in the scraperConfig it will try to use localhost:9222
|
// if remote is set as true in the scraperConfig it will try to use localhost:9222
|
||||||
// else it will look for google-chrome in path
|
// else it will look for google-chrome in path
|
||||||
func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) {
|
func urlFromCDP(ctx context.Context, urlCDP string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) {
|
||||||
|
|
||||||
if !driverOptions.UseCDP {
|
if !driverOptions.UseCDP {
|
||||||
return nil, fmt.Errorf("url shouldn't be fetched through CDP")
|
return nil, fmt.Errorf("url shouldn't be fetched through CDP")
|
||||||
@@ -107,6 +108,33 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti
|
|||||||
if isCDPPathHTTP(globalConfig) || isCDPPathWS(globalConfig) {
|
if isCDPPathHTTP(globalConfig) || isCDPPathWS(globalConfig) {
|
||||||
remote := cdpPath
|
remote := cdpPath
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
// #1023
|
||||||
|
// when chromium is listening over RDP it only accepts requests
|
||||||
|
// with host headers that are either IPs or `localhost`
|
||||||
|
cdpURL, err := url.Parse(remote)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse CDP Path: %v", err)
|
||||||
|
}
|
||||||
|
hostname := cdpURL.Hostname()
|
||||||
|
if hostname != "localhost" {
|
||||||
|
if net.ParseIP(hostname) == nil { // not an IP
|
||||||
|
addr, err := net.LookupIP(hostname)
|
||||||
|
if err != nil || len(addr) == 0 { // can not resolve to IP
|
||||||
|
return nil, fmt.Errorf("CDP: hostname <%s> can not be resolved", hostname)
|
||||||
|
}
|
||||||
|
if len(addr[0]) == 0 { // nil IP
|
||||||
|
return nil, fmt.Errorf("CDP: hostname <%s> resolved to nil", hostname)
|
||||||
|
}
|
||||||
|
// addr is a valid IP
|
||||||
|
// replace the host part of the cdpURL with the IP
|
||||||
|
cdpURL.Host = strings.Replace(cdpURL.Host, hostname, addr[0].String(), 1)
|
||||||
|
// use that for remote
|
||||||
|
remote = cdpURL.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
// if CDPPath is http(s) then we need to get the websocket URL
|
// if CDPPath is http(s) then we need to get the websocket URL
|
||||||
if isCDPPathHTTP(globalConfig) {
|
if isCDPPathHTTP(globalConfig) {
|
||||||
var err error
|
var err error
|
||||||
@@ -150,7 +178,7 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti
|
|||||||
setCDPCookies(driverOptions),
|
setCDPCookies(driverOptions),
|
||||||
printCDPCookies(driverOptions, "Cookies found"),
|
printCDPCookies(driverOptions, "Cookies found"),
|
||||||
network.SetExtraHTTPHeaders(network.Headers(headers)),
|
network.SetExtraHTTPHeaders(network.Headers(headers)),
|
||||||
chromedp.Navigate(url),
|
chromedp.Navigate(urlCDP),
|
||||||
chromedp.Sleep(sleepDuration),
|
chromedp.Sleep(sleepDuration),
|
||||||
setCDPClicks(driverOptions),
|
setCDPClicks(driverOptions),
|
||||||
chromedp.OuterHTML("html", &res, chromedp.ByQuery),
|
chromedp.OuterHTML("html", &res, chromedp.ByQuery),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
* Show counts on list tabs in Performer, Studio and Tag pages. ([#2169](https://github.com/stashapp/stash/pull/2169))
|
* Show counts on list tabs in Performer, Studio and Tag pages. ([#2169](https://github.com/stashapp/stash/pull/2169))
|
||||||
|
|
||||||
### 🐛 Bug fixes
|
### 🐛 Bug fixes
|
||||||
|
* Resolve CDP hostname if necessary. ([#2174](https://github.com/stashapp/stash/pull/2174))
|
||||||
* Generate sprites for short video files. ([#2167](https://github.com/stashapp/stash/pull/2167))
|
* Generate sprites for short video files. ([#2167](https://github.com/stashapp/stash/pull/2167))
|
||||||
* Fix stash-box scraping including underscores in ethnicity. ([#2191](https://github.com/stashapp/stash/pull/2191))
|
* Fix stash-box scraping including underscores in ethnicity. ([#2191](https://github.com/stashapp/stash/pull/2191))
|
||||||
* Fix stash-box batch performer task not setting birthdate. ([#2189](https://github.com/stashapp/stash/pull/2189))
|
* Fix stash-box batch performer task not setting birthdate. ([#2189](https://github.com/stashapp/stash/pull/2189))
|
||||||
|
|||||||
Reference in New Issue
Block a user