mirror of
https://github.com/tenox7/wrp.git
synced 2024-06-10 01:29:34 +00:00
made clicky work somehow
This commit is contained in:
parent
eb1476e579
commit
579d67f7fb
63
wrp.go
63
wrp.go
|
@ -36,20 +36,22 @@ var (
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
gifmap = make(map[string]bytes.Buffer)
|
gifmap = make(map[string]bytes.Buffer)
|
||||||
ismap = make(map[string]Params)
|
ismap = make(map[string]WrpReq)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Params - Page Configuration Parameters
|
// WrpReq - WRP Page Request
|
||||||
type Params struct {
|
type WrpReq struct {
|
||||||
U string // url
|
U string // url
|
||||||
P int64 // page
|
P int64 // page
|
||||||
W int64 // width
|
W int64 // width
|
||||||
H int64 // height
|
H int64 // height
|
||||||
S float64 // scale
|
S float64 // scale
|
||||||
C int64 // #colors
|
C int64 // #colors
|
||||||
|
X int64 // mouseX
|
||||||
|
Y int64 // mouseY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Params) parseForm(req *http.Request) {
|
func (p *WrpReq) parseForm(req *http.Request) {
|
||||||
req.ParseForm()
|
req.ParseForm()
|
||||||
p.U = req.FormValue("url")
|
p.U = req.FormValue("url")
|
||||||
if len(p.U) > 1 && !strings.HasPrefix(p.U, "http") {
|
if len(p.U) > 1 && !strings.HasPrefix(p.U, "http") {
|
||||||
|
@ -79,10 +81,10 @@ func (p *Params) parseForm(req *http.Request) {
|
||||||
if p.C < 2 || p.C > 256 {
|
if p.C < 2 || p.C > 256 {
|
||||||
p.C = 256
|
p.C = 256
|
||||||
}
|
}
|
||||||
log.Printf("Params from Form: %+v\n", p)
|
log.Printf("WrpReq from Form: %+v\n", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Params) printPage(out http.ResponseWriter) {
|
func (p WrpReq) printPage(out http.ResponseWriter) {
|
||||||
out.Header().Set("Content-Type", "text/html")
|
out.Header().Set("Content-Type", "text/html")
|
||||||
fmt.Fprintf(out, "<!-- Web Rendering Proxy Version %s -->\n", version)
|
fmt.Fprintf(out, "<!-- Web Rendering Proxy Version %s -->\n", version)
|
||||||
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#F0F0F0\">\n", p.U)
|
fmt.Fprintf(out, "<HTML>\n<HEAD><TITLE>WRP %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#F0F0F0\">\n", p.U)
|
||||||
|
@ -98,14 +100,14 @@ func (p Params) printPage(out http.ResponseWriter) {
|
||||||
fmt.Fprintf(out, "</FORM><BR>\n")
|
fmt.Fprintf(out, "</FORM><BR>\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Params) printFooter(out http.ResponseWriter) {
|
func (p WrpReq) printFooter(out http.ResponseWriter) {
|
||||||
fmt.Fprintf(out, "\n<P><A HREF=\"/?url=https://github.com/tenox7/wrp/&w=%d&h=%d&s=%1.2f&c=%d\">"+
|
fmt.Fprintf(out, "\n<P><A HREF=\"/?url=https://github.com/tenox7/wrp/&w=%d&h=%d&s=%1.2f&c=%d\">"+
|
||||||
"Web Rendering Proxy Version %s</A> | <A HREF=\"/shutdown/\">Shutdown WRP</A></BODY>\n</HTML>\n", p.W, p.H, p.S, p.C, version)
|
"Web Rendering Proxy Version %s</A> | <A HREF=\"/shutdown/\">Shutdown WRP</A></BODY>\n</HTML>\n", p.W, p.H, p.S, p.C, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pageServer(out http.ResponseWriter, req *http.Request) {
|
func pageServer(out http.ResponseWriter, req *http.Request) {
|
||||||
log.Printf("%s Page Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
log.Printf("%s Page Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
||||||
var p Params
|
var p WrpReq
|
||||||
p.parseForm(req)
|
p.parseForm(req)
|
||||||
p.printPage(out)
|
p.printPage(out)
|
||||||
if len(p.U) > 4 {
|
if len(p.U) > 4 {
|
||||||
|
@ -116,13 +118,6 @@ func pageServer(out http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
func mapServer(out http.ResponseWriter, req *http.Request) {
|
func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||||
log.Printf("%s ISMAP Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
log.Printf("%s ISMAP Request for %s [%+v]\n", req.RemoteAddr, req.URL.Path, req.URL.RawQuery)
|
||||||
var x, y int64
|
|
||||||
n, err := fmt.Sscanf(req.URL.RawQuery, "%d,%d", &x, &y)
|
|
||||||
if err != nil || n != 2 {
|
|
||||||
fmt.Fprintf(out, "n=%d, err=%s\n", n, err)
|
|
||||||
log.Printf("%s ISMAP n=%d, err=%s\n", req.RemoteAddr, n, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p, ok := ismap[req.URL.Path]
|
p, ok := ismap[req.URL.Path]
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintf(out, "Unable to find map %s\n", req.URL.Path)
|
fmt.Fprintf(out, "Unable to find map %s\n", req.URL.Path)
|
||||||
|
@ -130,7 +125,13 @@ func mapServer(out http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer delete(ismap, req.URL.Path)
|
defer delete(ismap, req.URL.Path)
|
||||||
log.Printf("%s Params from ISMAP: %+v\n", req.RemoteAddr, p)
|
n, err := fmt.Sscanf(req.URL.RawQuery, "%d,%d", &p.X, &p.Y)
|
||||||
|
if err != nil || n != 2 {
|
||||||
|
fmt.Fprintf(out, "n=%d, err=%s\n", n, err)
|
||||||
|
log.Printf("%s ISMAP n=%d, err=%s\n", req.RemoteAddr, n, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("%s WrpReq from ISMAP: %+v\n", req.RemoteAddr, p)
|
||||||
p.printPage(out)
|
p.printPage(out)
|
||||||
if len(p.U) > 4 {
|
if len(p.U) > 4 {
|
||||||
p.capture(req.RemoteAddr, out)
|
p.capture(req.RemoteAddr, out)
|
||||||
|
@ -153,21 +154,29 @@ func imgServer(out http.ResponseWriter, req *http.Request) {
|
||||||
out.(http.Flusher).Flush()
|
out.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Params) capture(c string, out http.ResponseWriter) {
|
func (p WrpReq) capture(c string, out http.ResponseWriter) {
|
||||||
var pngbuf []byte
|
var pngbuf []byte
|
||||||
var gifbuf bytes.Buffer
|
var gifbuf bytes.Buffer
|
||||||
var loc string
|
var loc string
|
||||||
var res *runtime.RemoteObject
|
var res *runtime.RemoteObject
|
||||||
|
var err error
|
||||||
|
|
||||||
log.Printf("%s Processing Capture Request for %s\n", c, p.U)
|
// Navigate to page
|
||||||
|
if p.X > 0 && p.Y > 0 {
|
||||||
// Run ChromeDP Magic
|
log.Printf("%s Mouse Click %d,%d\n", c, p.X, p.Y)
|
||||||
err := chromedp.Run(ctx,
|
chromedp.Run(ctx,
|
||||||
emulation.SetDeviceMetricsOverride(int64(float64(p.W)/p.S), int64(float64(p.H)/p.S), p.S, false),
|
chromedp.MouseClickXY(p.X, p.Y),
|
||||||
chromedp.Navigate(p.U),
|
chromedp.Sleep(time.Second*3),
|
||||||
chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", p.P*int64(float64(p.H)*float64(0.9))), &res),
|
chromedp.Location(&loc))
|
||||||
chromedp.Sleep(time.Second*1),
|
} else {
|
||||||
chromedp.Location(&loc))
|
log.Printf("%s Processing Capture Request for %s\n", c, p.U)
|
||||||
|
err = chromedp.Run(ctx,
|
||||||
|
emulation.SetDeviceMetricsOverride(int64(float64(p.W)/p.S), int64(float64(p.H)/p.S), p.S, false),
|
||||||
|
chromedp.Navigate(p.U),
|
||||||
|
chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", p.P*int64(float64(p.H)*float64(0.9))), &res),
|
||||||
|
chromedp.Sleep(time.Second*1),
|
||||||
|
chromedp.Location(&loc))
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "context canceled" {
|
if err.Error() == "context canceled" {
|
||||||
|
@ -180,6 +189,8 @@ func (p Params) capture(c string, out http.ResponseWriter) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mouse Click
|
||||||
log.Printf("%s Landed on: %s\n", c, loc)
|
log.Printf("%s Landed on: %s\n", c, loc)
|
||||||
p.U = loc
|
p.U = loc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user