Legend:
- Unmodified
- Added
- Removed
-
trunk/README.md
r139 r140 27 27 28 28 ``` 29 $ go get github.com/asciimoo/morty29 $ go install github.com/asciimoo/morty@latest 30 30 $ "$GOPATH/bin/morty" --help 31 31 ``` … … 38 38 -followredirect 39 39 Follow HTTP GET redirect 40 -hashparam string 41 User-defined requesting string HASH parameter name (ie: '/?hash=...' or '/?h=...') (default "mortyhash") 40 42 -ipv6 41 43 Allow IPv6 HTTP requests (default true) … … 52 54 -timeout uint 53 55 Request timeout (default 5) 56 -urlparam string 57 User-defined requesting string URL parameter name (ie: '/?url=...' or '/?u=...') (default "mortyurl") 54 58 -version 55 59 Show version … … 61 65 - `MORTY_ADDRESS`: Listen address (default to `127.0.0.1:3000`) 62 66 - `MORTY_KEY`: HMAC url validation key (base64 encoded) to prevent direct URL opening. Leave blank to disable validation. Use `openssl rand -base64 33` to generate. 67 - `MORTY_URL_PARAM`: User-defined requesting string URL parameter name (ie: `/?url=...` or `/?u=...`) (default `mortyurl`) 68 - `MORTY_HASH_PARAM`: User-defined requesting string HASH parameter name (ie: `/?hash=...` or `/?h=...`) (default `mortyhash`) 63 69 - `DEBUG`: Enable/disable proxy and redirection logs (default to `true`). Set to `false` to disable. 64 70 -
trunk/config/config.go
r132 r140 12 12 RequestTimeout uint 13 13 FollowRedirect bool 14 MaxConnsPerHost uint 15 UrlParameter string 16 HashParameter string 14 17 } 15 18 … … 21 24 default_listen_addr = "127.0.0.1:3000" 22 25 } 26 default_url_parameter := os.Getenv("MORTY_URL_PARAM") 27 if default_url_parameter == "" { 28 default_url_parameter = "mortyurl" 29 } 30 default_hash_parameter := os.Getenv("MORTY_HASH_PARAM") 31 if default_hash_parameter == "" { 32 default_hash_parameter = "mortyhash" 33 } 23 34 default_key := os.Getenv("MORTY_KEY") 24 35 DefaultConfig = &Config{ … … 29 40 RequestTimeout: 5, 30 41 FollowRedirect: false, 42 MaxConnsPerHost: 4, 43 UrlParameter: default_url_parameter, 44 HashParameter: default_hash_parameter, 31 45 } 32 46 } -
trunk/go.mod
r136 r140 4 4 5 5 require ( 6 github.com/valyala/fasthttp v1. 21.07 golang.org/x/net v0. 0.0-20201016165138-7b1cca2348c08 golang.org/x/text v0. 3.36 github.com/valyala/fasthttp v1.34.0 7 golang.org/x/net v0.7.0 8 golang.org/x/text v0.7.0 9 9 ) -
trunk/go.sum
r136 r140 1 github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= 2 github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= 3 github.com/klauspost/compress v1.10.4 h1:jFzIFaf586tquEB5EhzQG0HwGNSlgAJpG53G6Ss11wc= 4 github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 5 github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= 6 github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 1 github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= 2 github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 3 github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= 4 github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= 7 5 github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 8 6 github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 9 github.com/valyala/fasthttp v1.14.0 h1:67bfuW9azCMwW/Jlq/C+VeihNpAuJMWkYPBig1gdi3A= 10 github.com/valyala/fasthttp v1.14.0/go.mod h1:ol1PCaL0dX20wC0htZ7sYCsvCYmrouYra0zHzaclZhE= 11 github.com/valyala/fasthttp v1.21.0 h1:fJjaQ7cXdaSF9vDBujlHLDGj7AgoMTMIXvICeePzYbU= 12 github.com/valyala/fasthttp v1.21.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= 13 github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= 7 github.com/valyala/fasthttp v1.34.0 h1:d3AAQJ2DRcxJYHm7OXNXtXt2as1vMDfxeIcFvhmGGm4= 8 github.com/valyala/fasthttp v1.34.0/go.mod h1:epZA5N+7pY6ZaEKRmstzOuYJx9HI8DI1oaCGZpdH4h0= 9 github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= 10 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 14 11 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 15 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 16 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 17 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= 18 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 19 golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= 20 golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 21 golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg= 22 golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 12 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 13 golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 14 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 15 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 16 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 17 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 18 golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 19 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 20 golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= 21 golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 22 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 23 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 23 24 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 24 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 25 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 26 golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 25 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 26 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 27 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 28 golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 29 golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 30 golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 31 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 32 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 33 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 34 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 35 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 27 36 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 28 golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=29 37 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 38 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 39 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 40 golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= 41 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 30 42 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 43 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 44 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 45 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -
trunk/morty.go
r137 r140 66 66 contenttype.NewFilterEquals("image", "x-ms-bmp", ""), 67 67 contenttype.NewFilterEquals("image", "x-icon", ""), 68 contenttype.NewFilterEquals("image", "svg", "xml"), 68 69 // fonts 69 70 contenttype.NewFilterEquals("application", "font-otf", ""), … … 196 197 BaseURL string 197 198 HasMortyKey bool 199 URLParamName string 198 200 } 199 201 … … 201 203 BaseURL string 202 204 MortyHash string 205 URLParamName string 206 HashParamName string 207 } 208 type HTMLMainPageFormParam struct { 209 URLParamName string 203 210 } 204 211 205 212 var HTML_FORM_EXTENSION *template.Template 206 213 var HTML_BODY_EXTENSION *template.Template 214 var HTML_MAIN_PAGE_FORM *template.Template 207 215 var HTML_HEAD_CONTENT_TYPE string = `<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 208 216 <meta http-equiv="X-UA-Compatible" content="IE=edge"> … … 261 269 <label for="mortytoggle">hide</label> 262 270 <span><a href="/">Morty Proxy</a></span> 263 <input type="url" value="{{.BaseURL}}" name=" mortyurl" {{if .HasMortyKey }}readonly="true"{{end}} />271 <input type="url" value="{{.BaseURL}}" name="{{.URLParamName}}" {{if .HasMortyKey }}readonly="true"{{end}} /> 264 272 This is a <a href="https://github.com/asciimoo/morty">proxified and sanitized</a> view of the page, visit <a href="{{.BaseURL}}" rel="noreferrer">original site</a>. 265 273 </form> … … 281 289 panic(err) 282 290 } 291 HTML_MAIN_PAGE_FORM, err = template.New("html_main_page_form").Parse(` 292 <form action="post"> 293 Visit url: <input placeholder="https://url.." name="{{.URLParamName}}" autofocus /> 294 <input type="submit" value="go" /> 295 </form>`) 296 if err != nil { 297 panic(err) 298 } 283 299 } 284 300 … … 289 305 } 290 306 291 requestHash := popRequestParam(ctx, []byte( "mortyhash"))292 293 requestURI := popRequestParam(ctx, []byte( "mortyurl"))307 requestHash := popRequestParam(ctx, []byte(cfg.HashParameter)) 308 309 requestURI := popRequestParam(ctx, []byte(cfg.UrlParameter)) 294 310 295 311 if requestURI == nil { … … 301 317 if !verifyRequestURI(requestURI, requestHash, p.Key) { 302 318 // HTTP status code 403 : Forbidden 303 p.serveMainPage(ctx, 403, errors.New(`invalid "mortyhash" parameter`)) 319 error_message := fmt.Sprintf(`invalid "%s" parameter. hint: Hash URL Parameter`, cfg.HashParameter) 320 p.serveMainPage(ctx, 403, errors.New(error_message)) 304 321 return 305 322 } … … 352 369 353 370 req.SetRequestURI(requestURIStr) 354 req.Header.SetUserAgentBytes([]byte("Mozilla/5.0 (Windows NT 1 0.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"))371 req.Header.SetUserAgentBytes([]byte("Mozilla/5.0 (Windows NT 1.0; Win64; x64; rv:112.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36")) 355 372 356 373 resp := fasthttp.AcquireResponse() … … 488 505 sanitizeHTML(rc, ctx, responseBody) 489 506 if !rc.BodyInjected { 490 p := HTMLBodyExtParam{rc.BaseURL.String(), false }507 p := HTMLBodyExtParam{rc.BaseURL.String(), false, cfg.UrlParameter} 491 508 if len(rc.Key) > 0 { 492 509 p.HasMortyKey = true … … 699 716 key = hash(urlStr, rc.Key) 700 717 } 701 err := HTML_FORM_EXTENSION.Execute(out, HTMLFormExtParam{urlStr, key })718 err := HTML_FORM_EXTENSION.Execute(out, HTMLFormExtParam{urlStr, key, cfg.UrlParameter, cfg.HashParameter}) 702 719 if err != nil { 703 720 if cfg.Debug { … … 712 729 switch string(tag) { 713 730 case "body": 714 p := HTMLBodyExtParam{rc.BaseURL.String(), false }731 p := HTMLBodyExtParam{rc.BaseURL.String(), false, cfg.UrlParameter} 715 732 if len(rc.Key) > 0 { 716 733 p.HasMortyKey = true … … 983 1000 984 1001 if rc.Key == nil { 985 return fmt.Sprintf("./? mortyurl=%s%s", url.QueryEscape(morty_uri), fragment), nil986 } 987 return fmt.Sprintf("./? mortyhash=%s&mortyurl=%s%s", hash(morty_uri, rc.Key), url.QueryEscape(morty_uri), fragment), nil1002 return fmt.Sprintf("./?%s=%s%s", cfg.UrlParameter, url.QueryEscape(morty_uri), fragment), nil 1003 } 1004 return fmt.Sprintf("./?%s=%s&%s=%s%s", cfg.HashParameter, hash(morty_uri, rc.Key), cfg.UrlParameter, url.QueryEscape(morty_uri), fragment), nil 988 1005 } 989 1006 … … 1043 1060 } 1044 1061 if p.Key == nil { 1045 ctx.Write([]byte(` 1046 <form action="post"> 1047 Visit url: <input placeholder="https://url.." name="mortyurl" autofocus /> 1048 <input type="submit" value="go" /> 1049 </form>`)) 1062 p := HTMLMainPageFormParam{cfg.UrlParameter} 1063 err := HTML_MAIN_PAGE_FORM.Execute(ctx, p) 1064 if err != nil { 1065 if cfg.Debug { 1066 fmt.Println("failed to inject main page form", err) 1067 } 1068 } 1050 1069 } else { 1051 1070 ctx.Write([]byte(`<h3>Warning! This instance does not support direct URL opening.</h3>`)) … … 1064 1083 proxy := flag.String("proxy", "", "Use the specified HTTP proxy (ie: '[user:pass@]hostname:port'). Overrides -socks5, -ipv6.") 1065 1084 socks5 := flag.String("socks5", "", "Use a SOCKS5 proxy (ie: 'hostname:port'). Overrides -ipv6.") 1085 urlParameter := flag.String("urlparam", cfg.UrlParameter, "user-defined requesting string URL parameter name (ie: '/?url=...' or '/?u=...')") 1086 hashParameter := flag.String("hashparam", cfg.HashParameter, "user-defined requesting string HASH parameter name (ie: '/?hash=...' or '/?h=...')") 1066 1087 version := flag.Bool("version", false, "Show version") 1067 1088 flag.Parse() … … 1073 1094 cfg.RequestTimeout = *requestTimeout 1074 1095 cfg.FollowRedirect = *followRedirect 1096 cfg.UrlParameter = *urlParameter 1097 cfg.HashParameter = *hashParameter 1075 1098 1076 1099 if *version {
Note:
See TracChangeset
for help on using the changeset viewer.