Changeset 36 in code for trunk/morty.go


Ignore:
Timestamp:
Nov 24, 2016, 9:30:15 PM (9 years ago)
Author:
asciimoo
Message:

Merge pull request #28 from dalf/http_status_code

[mod] returns different HTTP status codes according to the errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r35 r36  
    110110<div id="mortyheader">
    111111  <input type="checkbox" id="mortytoggle" autocomplete="off" />
    112   <div><p>This is a proxified and sanitized view of the page,<br />visit <a href="%s">original site</a>.</p><div><p><label for="mortytoggle">hide</label></p></div></div>
     112  <div><p>This is a proxified and sanitized view of the page,<br />visit <a href="%s" rel="noreferrer">original site</a>.</p><p><label for="mortytoggle">hide</label></p></div>
    113113</div>
    114114<style>
    115 #mortyheader { position: fixed; top: 15%%; left: 0; max-width: 10em; color: #444; overflow: hidden; z-index: 110000; font-size: 0.9em; padding: 1em 1em 1em 0; margin: 0; }
    116 #mortyheader a { color: #3498db; }
    117 #mortyheader p { padding: 0; margin: 0; }
    118 #mortyheader > div { padding: 8px; font-size: 0.9em; border-width: 4px 4px 4px 0; border-style: solid; border-color: #1abc9c; background: #FFF; line-height: 1em; }
     115#mortyheader { position: fixed; padding: 12px 12px 12px 0; margin: 0; box-sizing: content-box; top: 15%%; left: 0; max-width: 140px; color: #444; overflow: hidden; z-index: 110000; font-size: 12px; line-height: normal; }
     116#mortyheader a { color: #3498db; font-weight: bold; }
     117#mortyheader p { padding: 0 0 0.7em 0; margin: 0; }
     118#mortyheader > div { padding: 8px; font-size: 12px !important; font-family: sans !important; border-width: 4px 4px 4px 0; border-style: solid; border-color: #1abc9c; background: #FFF; line-height: 1em; }
    119119#mortyheader label { text-align: right; cursor: pointer; display: block; color: #444; padding: 0; margin: 0; }
    120120input[type=checkbox]#mortytoggle { display: none; }
     
    307307                        startIndex = urlEnd
    308308                } else {
    309                         log.Println("cannot proxify css uri:", css[urlStart:urlEnd])
     309                        log.Println("cannot proxify css uri:", string(css[urlStart:urlEnd]))
    310310                }
    311311        }
     
    504504        if bytes.Equal(http_equiv, []byte("refresh")) && urlIndex != -1 {
    505505                contentUrl := content[urlIndex+4:]
     506                // special case of <meta http-equiv="refresh" content="0; url='example.com/url.with.quote.outside'">
     507                if len(contentUrl)>=2 && (contentUrl[0] == byte('\'') || contentUrl[0] == byte('"')) {
     508                        if contentUrl[0] == contentUrl[len(contentUrl)-1] {
     509                                contentUrl=contentUrl[1:len(contentUrl)-1]
     510                        }
     511                }
     512                // output proxify result
    506513                if uri, err := rc.ProxifyURI(string(contentUrl)); err == nil {
    507514                        fmt.Fprintf(out, ` http-equiv="refresh" content="%surl=%s"`, content[:urlIndex], uri)
     
    529536                        fmt.Fprintf(out, " %s=\"%s\"", attrName, uri)
    530537                } else {
    531                         log.Println("cannot proxify uri:", attrValue)
     538                        log.Println("cannot proxify uri:", string(attrValue))
    532539                }
    533540        case "style":
     
    538545}
    539546
    540 func mergeURIs(u1, u2 *url.URL) (*url.URL) {
     547func mergeURIs(u1, u2 *url.URL) *url.URL {
    541548        return u1.ResolveReference(u2)
    542549}
     
    603610<head>
    604611<title>MortyProxy</title>
     612<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=1.0, user-scalable=1" />
    605613<style>
    606 body { font-family: 'Garamond', 'Georgia', serif; text-align: center; color: #444; background: #FAFAFA; margin: 0; padding: 0; font-size: 1.1em; }
     614html { height: 100%; }
     615body { min-height : 100%; display: flex; flex-direction:column; font-family: 'Garamond', 'Georgia', serif; text-align: center; color: #444; background: #FAFAFA; margin: 0; padding: 0; font-size: 1.1em; }
    607616input { border: 1px solid #888; padding: 0.3em; color: #444; background: #FFF; font-size: 1.1em; }
     617input[placeholder] { width:80%; }
    608618a { text-decoration: none; #2980b9; }
    609619h1, h2 { font-weight: 200; margin-bottom: 2rem; }
    610620h1 { font-size: 3em; }
    611 .footer { position: absolute; bottom: 2em; width: 100%; }
     621.container { flex:1; min-height: 100%; margin-bottom: 1em; }
     622.footer { margin: 1em; }
    612623.footer p { font-size: 0.8em; }
    613 
    614624</style>
    615625</head>
    616626<body>
    617         <h1>MortyProxy</h1>`))
     627        <div class="container">
     628                <h1>MortyProxy</h1>
     629`))
    618630        if err != nil {
    619631                log.Println("error:", err)
     
    624636        if p.Key == nil {
    625637                ctx.Write([]byte(`
    626 <form action="post">
    627         Visit url: <input placeholder="https://url.." name="mortyurl" />
    628         <input type="submit" value="go" />
    629 </form>`))
     638                <form action="post">
     639                Visit url: <input placeholder="https://url.." name="mortyurl" autofocus />
     640                <input type="submit" value="go" />
     641                </form>`))
    630642        } else {
    631643                ctx.Write([]byte(`<h3>Warning! This instance does not support direct URL opening.</h3>`))
    632644        }
    633645        ctx.Write([]byte(`
    634 <div class="footer">
    635         <p>Morty rewrites web pages to exclude malicious HTML tags and CSS/HTML attributes. It also replaces external resource references to prevent third-party information leaks.<br />
    636         <a href="https://github.com/asciimoo/morty">view on github</a>
    637         </p>
    638 </div>
     646        </div>
     647        <div class="footer">
     648                <p>Morty rewrites web pages to exclude malicious HTML tags and CSS/HTML attributes. It also replaces external resource references to prevent third-party information leaks.<br />
     649                <a href="https://github.com/asciimoo/morty">view on github</a>
     650                </p>
     651        </div>
    639652</body>
    640653</html>`))
Note: See TracChangeset for help on using the changeset viewer.