Merge pull request #28 from dalf/http_status_code
[mod] returns different HTTP status codes according to the errors git-svn-id: file:///srv/svn/repo/yukari/trunk@36 f3bd38d9-da89-464d-a02a-eb04e43141b5
This commit is contained in:
parent
00bd224041
commit
348a8346f4
55
morty.go
55
morty.go
@ -109,13 +109,13 @@ var HTML_FORM_EXTENSION string = `<input type="hidden" name="mortyurl" value="%s
|
||||
var HTML_BODY_EXTENSION string = `
|
||||
<div id="mortyheader">
|
||||
<input type="checkbox" id="mortytoggle" autocomplete="off" />
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
<style>
|
||||
#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; }
|
||||
#mortyheader a { color: #3498db; }
|
||||
#mortyheader p { padding: 0; margin: 0; }
|
||||
#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; }
|
||||
#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; }
|
||||
#mortyheader a { color: #3498db; font-weight: bold; }
|
||||
#mortyheader p { padding: 0 0 0.7em 0; margin: 0; }
|
||||
#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; }
|
||||
#mortyheader label { text-align: right; cursor: pointer; display: block; color: #444; padding: 0; margin: 0; }
|
||||
input[type=checkbox]#mortytoggle { display: none; }
|
||||
input[type=checkbox]#mortytoggle:checked ~ div { display: none; }
|
||||
@ -306,7 +306,7 @@ func sanitizeCSS(rc *RequestConfig, out io.Writer, css []byte) {
|
||||
out.Write([]byte(uri))
|
||||
startIndex = urlEnd
|
||||
} else {
|
||||
log.Println("cannot proxify css uri:", css[urlStart:urlEnd])
|
||||
log.Println("cannot proxify css uri:", string(css[urlStart:urlEnd]))
|
||||
}
|
||||
}
|
||||
if startIndex < len(css) {
|
||||
@ -503,6 +503,13 @@ func sanitizeMetaAttrs(rc *RequestConfig, out io.Writer, attrs [][][]byte) {
|
||||
urlIndex := bytes.Index(bytes.ToLower(content), []byte("url="))
|
||||
if bytes.Equal(http_equiv, []byte("refresh")) && urlIndex != -1 {
|
||||
contentUrl := content[urlIndex+4:]
|
||||
// special case of <meta http-equiv="refresh" content="0; url='example.com/url.with.quote.outside'">
|
||||
if len(contentUrl)>=2 && (contentUrl[0] == byte('\'') || contentUrl[0] == byte('"')) {
|
||||
if contentUrl[0] == contentUrl[len(contentUrl)-1] {
|
||||
contentUrl=contentUrl[1:len(contentUrl)-1]
|
||||
}
|
||||
}
|
||||
// output proxify result
|
||||
if uri, err := rc.ProxifyURI(string(contentUrl)); err == nil {
|
||||
fmt.Fprintf(out, ` http-equiv="refresh" content="%surl=%s"`, content[:urlIndex], uri)
|
||||
}
|
||||
@ -528,7 +535,7 @@ func sanitizeAttr(rc *RequestConfig, out io.Writer, attrName, attrValue, escaped
|
||||
if uri, err := rc.ProxifyURI(string(attrValue)); err == nil {
|
||||
fmt.Fprintf(out, " %s=\"%s\"", attrName, uri)
|
||||
} else {
|
||||
log.Println("cannot proxify uri:", attrValue)
|
||||
log.Println("cannot proxify uri:", string(attrValue))
|
||||
}
|
||||
case "style":
|
||||
cssAttr := bytes.NewBuffer(nil)
|
||||
@ -537,7 +544,7 @@ func sanitizeAttr(rc *RequestConfig, out io.Writer, attrName, attrValue, escaped
|
||||
}
|
||||
}
|
||||
|
||||
func mergeURIs(u1, u2 *url.URL) (*url.URL) {
|
||||
func mergeURIs(u1, u2 *url.URL) *url.URL {
|
||||
return u1.ResolveReference(u2)
|
||||
}
|
||||
|
||||
@ -602,19 +609,24 @@ func (p *Proxy) serveMainPage(ctx *fasthttp.RequestCtx, statusCode int, err erro
|
||||
ctx.Write([]byte(`<!doctype html>
|
||||
<head>
|
||||
<title>MortyProxy</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=1.0, user-scalable=1" />
|
||||
<style>
|
||||
body { font-family: 'Garamond', 'Georgia', serif; text-align: center; color: #444; background: #FAFAFA; margin: 0; padding: 0; font-size: 1.1em; }
|
||||
html { height: 100%; }
|
||||
body { 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; }
|
||||
input { border: 1px solid #888; padding: 0.3em; color: #444; background: #FFF; font-size: 1.1em; }
|
||||
input[placeholder] { width:80%; }
|
||||
a { text-decoration: none; #2980b9; }
|
||||
h1, h2 { font-weight: 200; margin-bottom: 2rem; }
|
||||
h1 { font-size: 3em; }
|
||||
.footer { position: absolute; bottom: 2em; width: 100%; }
|
||||
.container { flex:1; min-height: 100%; margin-bottom: 1em; }
|
||||
.footer { margin: 1em; }
|
||||
.footer p { font-size: 0.8em; }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>MortyProxy</h1>`))
|
||||
<div class="container">
|
||||
<h1>MortyProxy</h1>
|
||||
`))
|
||||
if err != nil {
|
||||
log.Println("error:", err)
|
||||
ctx.Write([]byte("<h2>Error: "))
|
||||
@ -623,19 +635,20 @@ h1 { font-size: 3em; }
|
||||
}
|
||||
if p.Key == nil {
|
||||
ctx.Write([]byte(`
|
||||
<form action="post">
|
||||
Visit url: <input placeholder="https://url.." name="mortyurl" />
|
||||
<input type="submit" value="go" />
|
||||
</form>`))
|
||||
<form action="post">
|
||||
Visit url: <input placeholder="https://url.." name="mortyurl" autofocus />
|
||||
<input type="submit" value="go" />
|
||||
</form>`))
|
||||
} else {
|
||||
ctx.Write([]byte(`<h3>Warning! This instance does not support direct URL opening.</h3>`))
|
||||
}
|
||||
ctx.Write([]byte(`
|
||||
<div class="footer">
|
||||
<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 />
|
||||
<a href="https://github.com/asciimoo/morty">view on github</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<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 />
|
||||
<a href="https://github.com/asciimoo/morty">view on github</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>`))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user