Changeset 149 in code
- Timestamp:
- Mar 21, 2024, 10:39:20 PM (15 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.md
r142 r149 1 # v0.2.3 - 2024.03.21 2 * Document the configuration file format, which is INI-style (which is compatible to the old format in the codebase, though it's now called as `config.Config.<key>`) 3 * Manual page has been rewritten (using `mdoc(7)`) 4 * 'YukariSukima' is an incorrect transliteration, use 'Yukari no Sukima' to indicate possession/ownership 5 * Remove the 'proxified and sanitized view' text as it should already be obvious 6 * The font family used earlier is horrible, changed it to `sans-serif` 7 * Bump required Go toolchain version to 1.16 in order to use `//go:embed` 8 * Rename some all-uppercase constants/variables to camelCase (I think?), also rename CLIENT to Gap (lol) 9 1 10 # v0.2.1 - 2023.08.26 2 Applied some suggestions from the issue tracker, and 3 rebrand this fork. 11 Applied some suggestions from the [issue tracker](https://github.com/asciimoo/morty/issues), and rebrand this fork. 4 12 5 13 # v0.2.0 - 2018.05.28 -
trunk/Makefile
r147 r149 23 23 clean: 24 24 $(RM) -f yukari 25 install: 25 install: all 26 26 $(MKDIR) -p $(DESTDIR)$(PREFIX)/$(BINDIR) 27 27 $(MKDIR) -p $(DESTDIR)$(PREFIX)/$(MANDIR)/man1 -
trunk/README.md
r147 r149 20 20 21 21 ## Installation and setup 22 Requirement: Go version 1.16 or higher .22 Requirement: Go version 1.16 or higher (thus making it incompatible with MortyProxy's own requirement, but also to use `go embed`) 23 23 24 24 ``` 25 $ go install marisa.chaotic.ninja/yukari @latest25 $ go install marisa.chaotic.ninja/yukari/cmd/yukari@latest 26 26 $ "$GOPATH/bin/yukari" --help 27 27 ``` 28 28 29 29 ### Usage 30 31 ``` 32 -debug 33 Debug mode (default true) 34 -followredirect 35 Follow HTTP GET redirect 36 -hashparam string 37 User-defined requesting string HASH parameter name (ie: '/?hash=...' or '/?h=...') (default "yukarihash") 38 -ipv6 39 Allow IPv6 HTTP requests (default true) 40 -key string 41 HMAC url validation key (base64 encoded) - leave blank to disable validation 42 -listen string 43 Listen address (default "127.0.0.1:3000") 44 -proxy string 45 Use the specified HTTP proxy (ie: '[user:pass@]hostname:port'). Overrides -socks5, -ipv6. 46 -proxyenv 47 Use a HTTP proxy as set in the environment (HTTP_PROXY, HTTPS_PROXY and NO_PROXY). Overrides -proxy, -socks5, -ipv6. 48 -socks5 string 49 Use a SOCKS5 proxy (ie: 'hostname:port'). Overrides -ipv6. 50 -timeout uint 51 Request timeout (default 5) 52 -urlparam string 53 User-defined requesting string URL parameter name (ie: '/?url=...' or '/?u=...') (default "yukariurl") 54 -version 55 Show version 56 ``` 30 See `yukari(1)` 57 31 58 32 ### Environment variables … … 82 56 83 57 ## Bugs 84 Bugs or suggestions? Visit the [issue tracker](https://git.chaotic.ninja/yakumo.izuru/yukari/issues).58 Bugs or suggestions? Mail [yukari-dev@chaotic.ninja](mailto:yukari-dev@chaotic.ninja) -
trunk/cmd/yukari/main.go
r148 r149 40 40 ) 41 41 42 const M AX_REDIRECT_COUNT= 543 44 var CLIENT*fasthttp.Client = &fasthttp.Client{42 const MaxRedirectCount = 5 43 44 var Gap *fasthttp.Client = &fasthttp.Client{ 45 45 MaxResponseBodySize: 10 * 1024 * 1024, // 10M 46 46 ReadBufferSize: 16 * 1024, // 16K 47 47 } 48 48 49 var CSS_URL_REGEXP*regexp.Regexp = regexp.MustCompile("url\\((['\"]?)[ \\t\\f]*([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?")49 var cssURLRegex *regexp.Regexp = regexp.MustCompile("url\\((['\"]?)[ \\t\\f]*([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?") 50 50 51 51 type Proxy struct { … … 77 77 } 78 78 79 var FAVICON_BYTES[]byte80 var HTML_FORM_EXTENSION*template.Template81 var HTML_BODY_EXTENSION*template.Template82 var HTML_MAIN_PAGE_FORM*template.Template79 var faviconBytes []byte 80 var htmlFormExtension *template.Template 81 var htmlBodyExtension *template.Template 82 var htmlMainPageForm *template.Template 83 83 84 84 //go:embed templates/yukari_content_type.html 85 var HTML_HEAD_CONTENT_TYPEstring85 var htmlHeadContentType string 86 86 //go:embed templates/yukari_start.html 87 var YUKARI_HTML_PAGE_STARTstring87 var htmlPageStart string 88 88 //go:embed templates/yukari_stop.html 89 var YUKARI_HTML_PAGE_ENDstring89 var htmlPageStop string 90 90 91 91 func init() { 92 92 FaviconBase64 := "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII" 93 93 94 FAVICON_BYTES, _ = base64.StdEncoding.DecodeString(FaviconBase64)94 faviconBytes, _ = base64.StdEncoding.DecodeString(FaviconBase64) 95 95 var err error 96 HTML_FORM_EXTENSION, err = template.New("html_form_extension").Parse(96 htmlFormExtension, err = template.New("html_form_extension").Parse( 97 97 `<input type="hidden" name="yukariurl" value="{{.BaseURL}}" />{{if .YukariHash}}<input type="hidden" name="yukarihash" value="{{.YukariHash}}" />{{end}}`) 98 98 if err != nil { 99 99 panic(err) 100 100 } 101 HTML_BODY_EXTENSION, err = template.New("html_body_extension").Parse(` 102 <input type="checkbox" id="yukaritoggle" autocomplete="off" /> 101 htmlBodyExtension, err = template.New("html_body_extension").Parse(` 103 102 <div id="yukariheader"> 104 103 <form method="get"> 105 <label for="yukaritoggle">hide</label>106 104 <span><a href="/">Yukari's Gap</a></span> 107 105 <input type="url" value="{{.BaseURL}}" name="{{.URLParamName}}" {{if .HasYukariKey }}readonly="true"{{end}} /> 108 This is a proxified and sanitized view of the page, visit <a href="{{.BaseURL}}" rel="noreferrer">original site.109 106 </form> 110 107 </div> … … 117 114 #yukariheader label { text-align: right; cursor: pointer; position: fixed; right: 4px; top: 4px; display: block; color: #444; } 118 115 #yukariheader > form > span { font-size: 24px; font-weight: bold; margin-right: 20px; margin-left: 20px; } 119 input[type=checkbox]#yukaritoggle { display: none; }120 input[type=checkbox]#yukaritoggle:checked ~ div { display: none; visibility: hidden; }121 116 #yukariheader input[type=url] { width: 50%; padding: 4px; font-size: 16px; } 122 117 </style> … … 125 120 panic(err) 126 121 } 127 HTML_MAIN_PAGE_FORM, err = template.New("html_main_page_form").Parse(`122 htmlMainPageForm, err = template.New("html_main_page_form").Parse(` 128 123 <form action="post"> 129 124 Visit url: <input placeholder="https://url.." name="{{.URLParamName}}" autofocus /> … … 215 210 } 216 211 217 err = CLIENT.DoTimeout(req, resp, p.RequestTimeout)212 err = Gap.DoTimeout(req, resp, p.RequestTimeout) 218 213 219 214 if err != nil { … … 235 230 if p.FollowRedirect && ctx.IsGet() { 236 231 // GET method: Yukari follows the redirect 237 if redirectCount < M AX_REDIRECT_COUNT{232 if redirectCount < MaxRedirectCount { 238 233 if config.Config.Debug { 239 234 log.Println("follow redirect to", string(loc)) … … 345 340 p.HasYukariKey = true 346 341 } 347 err := HTML_BODY_EXTENSION.Execute(ctx, p)342 err := htmlBodyExtension.Execute(ctx, p) 348 343 if err != nil { 349 344 if config.Config.Debug { … … 394 389 if bytes.Equal(ctx.Path(), []byte("/favicon.ico")) { 395 390 ctx.SetContentType("image/png") 396 ctx.Write( FAVICON_BYTES)391 ctx.Write(faviconBytes) 397 392 return true 398 393 } … … 416 411 // TODO 417 412 418 urlSlices := CSS_URL_REGEXP.FindAllSubmatchIndex(css, -1)413 urlSlices := cssURLRegex.FindAllSubmatchIndex(css, -1) 419 414 420 415 if urlSlices == nil { … … 532 527 533 528 if bytes.Equal(tag, []byte("head")) { 534 fmt.Fprintf(out, HTML_HEAD_CONTENT_TYPE)529 fmt.Fprintf(out, htmlHeadContentType) 535 530 } 536 531 … … 552 547 key = hash(urlStr, rc.Key) 553 548 } 554 err := HTML_FORM_EXTENSION.Execute(out, HTMLFormExtParam{urlStr, key, config.Config.UrlParameter, config.Config.HashParameter})549 err := htmlFormExtension.Execute(out, HTMLFormExtParam{urlStr, key, config.Config.UrlParameter, config.Config.HashParameter}) 555 550 if err != nil { 556 551 if config.Config.Debug { … … 569 564 p.HasYukariKey = true 570 565 } 571 err := HTML_BODY_EXTENSION.Execute(out, p)566 err := htmlBodyExtension.Execute(out, p) 572 567 if err != nil { 573 568 if config.Config.Debug { … … 873 868 ctx.SetContentType("text/html") 874 869 ctx.SetStatusCode(403) 875 ctx.Write([]byte( YUKARI_HTML_PAGE_START))870 ctx.Write([]byte(htmlPageStart)) 876 871 ctx.Write([]byte("<h2>You are about to exit Yukari no Sukima</h2>")) 877 872 ctx.Write([]byte("<p>Following</p><p><a href=\"")) … … 880 875 ctx.Write([]byte(html.EscapeString(uri.String()))) 881 876 ctx.Write([]byte("</a></p><p>the content of this URL will be <b>NOT</b> sanitized.</p>")) 882 ctx.Write([]byte( YUKARI_HTML_PAGE_END))877 ctx.Write([]byte(htmlPageStop)) 883 878 } 884 879 … … 886 881 ctx.SetContentType("text/html; charset=UTF-8") 887 882 ctx.SetStatusCode(statusCode) 888 ctx.Write([]byte( YUKARI_HTML_PAGE_START))883 ctx.Write([]byte(htmlPageStart)) 889 884 if err != nil { 890 885 if config.Config.Debug { … … 897 892 if p.Key == nil { 898 893 p := HTMLMainPageFormParam{config.Config.UrlParameter} 899 err := HTML_MAIN_PAGE_FORM.Execute(ctx, p)894 err := htmlMainPageForm.Execute(ctx, p) 900 895 if err != nil { 901 896 if config.Config.Debug { … … 906 901 ctx.Write([]byte(`<h3>Warning! This instance does not support direct URL opening.</h3>`)) 907 902 } 908 ctx.Write([]byte( YUKARI_HTML_PAGE_END))903 ctx.Write([]byte(htmlPageStop)) 909 904 } 910 905 … … 912 907 var configFile string 913 908 var proxy string 914 var proxyEnv bool915 909 var socks5 string 916 910 var version bool 917 911 918 912 flag.StringVar(&configFile, "f", "", "Configuration file") 919 flag.BoolVar(&proxyEnv, "proxyenv", false, "Use a HTTP proxy as set in the environment (HTTP_PROXY, HTTPS_PROXY and NO_PROXY). Overrides: -proxy, -socks5, IPv6")920 913 flag.StringVar(&proxy, "proxy", "", "Use the specified HTTP proxy (ie: '[user:pass@]hostname:port'). Overrides: -socks5, IPv6") 921 914 flag.StringVar(&socks5, "socks5", "", "Use a SOCKS5 proxy (ie: 'hostname:port'). Overrides: IPv6.") … … 931 924 config.Config.UrlParameter = "yukariurl" 932 925 config.Config.HashParameter = "yukarihash" 933 config.Config.MaxConnsPerHost = 4 926 config.Config.MaxConnsPerHost = 5 927 config.Config.ProxyEnv = false 934 928 935 929 if version { … … 938 932 } 939 933 940 if proxyEnv && os.Getenv("HTTP_PROXY") == "" && os.Getenv("HTTPS_PROXY") == "" {934 if config.Config.ProxyEnv && os.Getenv("HTTP_PROXY") == "" && os.Getenv("HTTPS_PROXY") == "" { 941 935 log.Fatal("Error -proxyenv is used but no environment variables named 'HTTP_PROXY' and/or 'HTTPS_PROXY' could be found.") 942 936 os.Exit(1) 943 937 } 944 938 945 if proxyEnv { 946 CLIENT.Dial = fasthttpproxy.FasthttpProxyHTTPDialer() 939 if config.Config.ProxyEnv { 940 config.Config.IPV6 = false 941 Gap.Dial = fasthttpproxy.FasthttpProxyHTTPDialer() 947 942 log.Println("Using environment defined proxy(ies).") 948 943 } else if proxy != "" { 949 CLIENT.Dial = fasthttpproxy.FasthttpHTTPDialer(proxy) 944 config.Config.IPV6 = false 945 Gap.Dial = fasthttpproxy.FasthttpHTTPDialer(proxy) 950 946 log.Println("Using custom HTTP proxy.") 951 947 } else if socks5 != "" { 952 CLIENT.Dial = fasthttpproxy.FasthttpSocksDialer(socks5) 948 config.Config.IPV6 = false 949 Gap.Dial = fasthttpproxy.FasthttpSocksDialer(socks5) 953 950 log.Println("Using Socks5 proxy.") 954 951 } else if config.Config.IPV6 { 955 CLIENT.Dial = fasthttp.DialDualStack952 Gap.Dial = fasthttp.DialDualStack 956 953 log.Println("Using dual stack (IPv4/IPv6) direct connections.") 957 954 } else { 958 CLIENT.Dial = fasthttp.Dial955 Gap.Dial = fasthttp.Dial 959 956 log.Println("Using IPv4 only direct connections.") 960 957 } -
trunk/config/config.go
r147 r149 15 15 UrlParameter string 16 16 HashParameter string 17 ProxyEnv bool 17 18 } 18 19 … … 31 32 Config.UrlParameter = cfg.Section("yukari").Key("urlparam").String() 32 33 Config.HashParameter = cfg.Section("yukari").Key("hashparam").String() 33 34 Config.ProxyEnv, _ = cfg.Section("yukari").Key("proxyenv").Bool() 34 35 return nil 35 36 }
Note:
See TracChangeset
for help on using the changeset viewer.