Changeset 149 in code


Ignore:
Timestamp:
Mar 21, 2024, 10:39:20 PM (15 months ago)
Author:
Izuru Yakumo
Message:

Ready for v0.2.3

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

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
    110# v0.2.1 - 2023.08.26
    2 Applied some suggestions from the issue tracker, and
    3 rebrand this fork.
     11Applied some suggestions from the [issue tracker](https://github.com/asciimoo/morty/issues), and rebrand this fork.
    412
    513# v0.2.0 - 2018.05.28
  • trunk/Makefile

    r147 r149  
    2323clean:
    2424        $(RM) -f yukari
    25 install:
     25install: all
    2626        $(MKDIR) -p $(DESTDIR)$(PREFIX)/$(BINDIR)
    2727        $(MKDIR) -p $(DESTDIR)$(PREFIX)/$(MANDIR)/man1
  • trunk/README.md

    r147 r149  
    2020
    2121## Installation and setup
    22 Requirement: Go version 1.16 or higher.
     22Requirement: Go version 1.16 or higher (thus making it incompatible with MortyProxy's own requirement, but also to use `go embed`)
    2323
    2424```
    25 $ go install marisa.chaotic.ninja/yukari@latest
     25$ go install marisa.chaotic.ninja/yukari/cmd/yukari@latest
    2626$ "$GOPATH/bin/yukari" --help
    2727```
    2828
    2929### 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 ```
     30See `yukari(1)`
    5731
    5832### Environment variables
     
    8256
    8357## Bugs
    84 Bugs or suggestions? Visit the [issue tracker](https://git.chaotic.ninja/yakumo.izuru/yukari/issues).
     58Bugs or suggestions? Mail [yukari-dev@chaotic.ninja](mailto:yukari-dev@chaotic.ninja)
  • trunk/cmd/yukari/main.go

    r148 r149  
    4040)
    4141
    42 const MAX_REDIRECT_COUNT = 5
    43 
    44 var CLIENT *fasthttp.Client = &fasthttp.Client{
     42const MaxRedirectCount = 5
     43
     44var Gap *fasthttp.Client = &fasthttp.Client{
    4545        MaxResponseBodySize: 10 * 1024 * 1024, // 10M
    4646        ReadBufferSize:      16 * 1024,        // 16K
    4747}
    4848
    49 var CSS_URL_REGEXP *regexp.Regexp = regexp.MustCompile("url\\((['\"]?)[ \\t\\f]*([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?")
     49var cssURLRegex *regexp.Regexp = regexp.MustCompile("url\\((['\"]?)[ \\t\\f]*([\u0009\u0021\u0023-\u0026\u0028\u002a-\u007E]+)(['\"]?)\\)?")
    5050
    5151type Proxy struct {
     
    7777}
    7878
    79 var FAVICON_BYTES []byte
    80 var HTML_FORM_EXTENSION *template.Template
    81 var HTML_BODY_EXTENSION *template.Template
    82 var HTML_MAIN_PAGE_FORM *template.Template
     79var faviconBytes []byte
     80var htmlFormExtension *template.Template
     81var htmlBodyExtension *template.Template
     82var htmlMainPageForm *template.Template
    8383
    8484//go:embed templates/yukari_content_type.html
    85 var HTML_HEAD_CONTENT_TYPE string
     85var htmlHeadContentType string
    8686//go:embed templates/yukari_start.html
    87 var YUKARI_HTML_PAGE_START string
     87var htmlPageStart string
    8888//go:embed templates/yukari_stop.html
    89 var YUKARI_HTML_PAGE_END string
     89var htmlPageStop string
    9090
    9191func init() {
    9292        FaviconBase64 := "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII"
    9393
    94         FAVICON_BYTES, _ = base64.StdEncoding.DecodeString(FaviconBase64)
     94        faviconBytes, _ = base64.StdEncoding.DecodeString(FaviconBase64)
    9595        var err error
    96         HTML_FORM_EXTENSION, err = template.New("html_form_extension").Parse(
     96        htmlFormExtension, err = template.New("html_form_extension").Parse(
    9797                `<input type="hidden" name="yukariurl" value="{{.BaseURL}}" />{{if .YukariHash}}<input type="hidden" name="yukarihash" value="{{.YukariHash}}" />{{end}}`)
    9898        if err != nil {
    9999                panic(err)
    100100        }
    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(`
    103102<div id="yukariheader">
    104103  <form method="get">
    105     <label for="yukaritoggle">hide</label>
    106104    <span><a href="/">Yukari's Gap</a></span>
    107105    <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.
    109106  </form>
    110107</div>
     
    117114#yukariheader label { text-align: right; cursor: pointer; position: fixed; right: 4px; top: 4px; display: block; color: #444; }
    118115#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; }
    121116#yukariheader input[type=url] { width: 50%; padding: 4px; font-size: 16px; }
    122117</style>
     
    125120                panic(err)
    126121        }
    127         HTML_MAIN_PAGE_FORM, err = template.New("html_main_page_form").Parse(`
     122        htmlMainPageForm, err = template.New("html_main_page_form").Parse(`
    128123        <form action="post">
    129124        Visit url: <input placeholder="https://url.." name="{{.URLParamName}}" autofocus />
     
    215210        }
    216211
    217         err = CLIENT.DoTimeout(req, resp, p.RequestTimeout)
     212        err = Gap.DoTimeout(req, resp, p.RequestTimeout)
    218213
    219214        if err != nil {
     
    235230                                if p.FollowRedirect && ctx.IsGet() {
    236231                                        // GET method: Yukari follows the redirect
    237                                         if redirectCount < MAX_REDIRECT_COUNT {
     232                                        if redirectCount < MaxRedirectCount {
    238233                                                if config.Config.Debug {
    239234                                                        log.Println("follow redirect to", string(loc))
     
    345340                                p.HasYukariKey = true
    346341                        }
    347                         err := HTML_BODY_EXTENSION.Execute(ctx, p)
     342                        err := htmlBodyExtension.Execute(ctx, p)
    348343                        if err != nil {
    349344                                if config.Config.Debug {
     
    394389        if bytes.Equal(ctx.Path(), []byte("/favicon.ico")) {
    395390                ctx.SetContentType("image/png")
    396                 ctx.Write(FAVICON_BYTES)
     391                ctx.Write(faviconBytes)
    397392                return true
    398393        }
     
    416411        // TODO
    417412
    418         urlSlices := CSS_URL_REGEXP.FindAllSubmatchIndex(css, -1)
     413        urlSlices := cssURLRegex.FindAllSubmatchIndex(css, -1)
    419414
    420415        if urlSlices == nil {
     
    532527
    533528                                if bytes.Equal(tag, []byte("head")) {
    534                                         fmt.Fprintf(out, HTML_HEAD_CONTENT_TYPE)
     529                                        fmt.Fprintf(out, htmlHeadContentType)
    535530                                }
    536531
     
    552547                                                key = hash(urlStr, rc.Key)
    553548                                        }
    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})
    555550                                        if err != nil {
    556551                                                if config.Config.Debug {
     
    569564                                                p.HasYukariKey = true
    570565                                        }
    571                                         err := HTML_BODY_EXTENSION.Execute(out, p)
     566                                        err := htmlBodyExtension.Execute(out, p)
    572567                                        if err != nil {
    573568                                                if config.Config.Debug {
     
    873868        ctx.SetContentType("text/html")
    874869        ctx.SetStatusCode(403)
    875         ctx.Write([]byte(YUKARI_HTML_PAGE_START))
     870        ctx.Write([]byte(htmlPageStart))
    876871        ctx.Write([]byte("<h2>You are about to exit Yukari no Sukima</h2>"))
    877872        ctx.Write([]byte("<p>Following</p><p><a href=\""))
     
    880875        ctx.Write([]byte(html.EscapeString(uri.String())))
    881876        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))
    883878}
    884879
     
    886881        ctx.SetContentType("text/html; charset=UTF-8")
    887882        ctx.SetStatusCode(statusCode)
    888         ctx.Write([]byte(YUKARI_HTML_PAGE_START))
     883        ctx.Write([]byte(htmlPageStart))
    889884        if err != nil {
    890885                if config.Config.Debug {
     
    897892        if p.Key == nil {
    898893                p := HTMLMainPageFormParam{config.Config.UrlParameter}
    899                 err := HTML_MAIN_PAGE_FORM.Execute(ctx, p)
     894                err := htmlMainPageForm.Execute(ctx, p)
    900895                if err != nil {
    901896                        if config.Config.Debug {
     
    906901                ctx.Write([]byte(`<h3>Warning! This instance does not support direct URL opening.</h3>`))
    907902        }
    908         ctx.Write([]byte(YUKARI_HTML_PAGE_END))
     903        ctx.Write([]byte(htmlPageStop))
    909904}
    910905
     
    912907        var configFile string
    913908        var proxy string
    914         var proxyEnv bool
    915909        var socks5 string
    916910        var version bool
    917911
    918912        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")
    920913        flag.StringVar(&proxy, "proxy", "", "Use the specified HTTP proxy (ie: '[user:pass@]hostname:port'). Overrides: -socks5, IPv6")
    921914        flag.StringVar(&socks5, "socks5", "", "Use a SOCKS5 proxy (ie: 'hostname:port'). Overrides: IPv6.")
     
    931924        config.Config.UrlParameter = "yukariurl"
    932925        config.Config.HashParameter = "yukarihash"
    933         config.Config.MaxConnsPerHost = 4
     926        config.Config.MaxConnsPerHost = 5
     927        config.Config.ProxyEnv = false
    934928
    935929        if version {
     
    938932        }
    939933
    940         if proxyEnv && os.Getenv("HTTP_PROXY") == "" && os.Getenv("HTTPS_PROXY") == "" {
     934        if config.Config.ProxyEnv && os.Getenv("HTTP_PROXY") == "" && os.Getenv("HTTPS_PROXY") == "" {
    941935                log.Fatal("Error -proxyenv is used but no environment variables named 'HTTP_PROXY' and/or 'HTTPS_PROXY' could be found.")
    942936                os.Exit(1)
    943937        }
    944938
    945         if proxyEnv {
    946                 CLIENT.Dial = fasthttpproxy.FasthttpProxyHTTPDialer()
     939        if config.Config.ProxyEnv {
     940                config.Config.IPV6 = false
     941                Gap.Dial = fasthttpproxy.FasthttpProxyHTTPDialer()
    947942                log.Println("Using environment defined proxy(ies).")
    948943        } else if proxy != "" {
    949                 CLIENT.Dial = fasthttpproxy.FasthttpHTTPDialer(proxy)
     944                config.Config.IPV6 = false
     945                Gap.Dial = fasthttpproxy.FasthttpHTTPDialer(proxy)
    950946                log.Println("Using custom HTTP proxy.")
    951947        } else if socks5 != "" {
    952                 CLIENT.Dial = fasthttpproxy.FasthttpSocksDialer(socks5)
     948                config.Config.IPV6 = false
     949                Gap.Dial = fasthttpproxy.FasthttpSocksDialer(socks5)
    953950                log.Println("Using Socks5 proxy.")
    954951        } else if config.Config.IPV6 {
    955                 CLIENT.Dial = fasthttp.DialDualStack
     952                Gap.Dial = fasthttp.DialDualStack
    956953                log.Println("Using dual stack (IPv4/IPv6) direct connections.")
    957954        } else {
    958                 CLIENT.Dial = fasthttp.Dial
     955                Gap.Dial = fasthttp.Dial
    959956                log.Println("Using IPv4 only direct connections.")
    960957        }
  • trunk/config/config.go

    r147 r149  
    1515        UrlParameter string
    1616        HashParameter string
     17        ProxyEnv bool
    1718}
    1819
     
    3132        Config.UrlParameter = cfg.Section("yukari").Key("urlparam").String()
    3233        Config.HashParameter = cfg.Section("yukari").Key("hashparam").String()
    33 
     34        Config.ProxyEnv, _ = cfg.Section("yukari").Key("proxyenv").Bool()
    3435        return nil
    3536}
Note: See TracChangeset for help on using the changeset viewer.