|
|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"html/template" |
|
|
|
"html/template" |
|
|
|
|
|
|
|
"math" |
|
|
|
"math/rand" |
|
|
|
"math/rand" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
@ -25,6 +26,7 @@ func init() { |
|
|
|
const ( |
|
|
|
const ( |
|
|
|
idLength = 5 |
|
|
|
idLength = 5 |
|
|
|
statsSavingInterval = 1 * time.Minute |
|
|
|
statsSavingInterval = 1 * time.Minute |
|
|
|
|
|
|
|
fraudThreshold = 7 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
@ -39,6 +41,7 @@ var ( |
|
|
|
rexpNewLine = regexp.MustCompile("[\n\r]") |
|
|
|
rexpNewLine = regexp.MustCompile("[\n\r]") |
|
|
|
rexpNonAlphaNum = regexp.MustCompile("[`~!@#$%^&*_|+=?;:'\",.<>{}\\/]") |
|
|
|
rexpNonAlphaNum = regexp.MustCompile("[`~!@#$%^&*_|+=?;:'\",.<>{}\\/]") |
|
|
|
rexpNoScriptIframe = regexp.MustCompile("<.*?(iframe|script).*?>") |
|
|
|
rexpNoScriptIframe = regexp.MustCompile("<.*?(iframe|script).*?>") |
|
|
|
|
|
|
|
rexpLink = regexp.MustCompile("(ht|f)tp://[^\\s]+") |
|
|
|
|
|
|
|
|
|
|
|
errorUnathorised = errors.New("id or password is wrong") |
|
|
|
errorUnathorised = errors.New("id or password is wrong") |
|
|
|
errorBadRequest = errors.New("password is empty") |
|
|
|
errorBadRequest = errors.New("password is empty") |
|
|
|
@ -48,7 +51,7 @@ type Note struct { |
|
|
|
ID, Title, Text, Password string |
|
|
|
ID, Title, Text, Password string |
|
|
|
Published, Edited time.Time |
|
|
|
Published, Edited time.Time |
|
|
|
Views int |
|
|
|
Views int |
|
|
|
Content template.HTML |
|
|
|
Content, Ads template.HTML |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func errPage(code int, details ...string) Note { |
|
|
|
func errPage(code int, details ...string) Note { |
|
|
|
@ -203,3 +206,10 @@ var mdRenderer = markdown.New(markdown.HTML(true)) |
|
|
|
func mdTmplHTML(content []byte) template.HTML { |
|
|
|
func mdTmplHTML(content []byte) template.HTML { |
|
|
|
return template.HTML(mdRenderer.RenderToString(content)) |
|
|
|
return template.HTML(mdRenderer.RenderToString(content)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (n *Note) Fraud() bool { |
|
|
|
|
|
|
|
stripped := rexpLink.ReplaceAllString(n.Text, "") |
|
|
|
|
|
|
|
l1 := len(n.Text) |
|
|
|
|
|
|
|
l2 := len(stripped) |
|
|
|
|
|
|
|
return int(math.Ceil(100*float64(l1-l2)/float64(l1))) > fraudThreshold |
|
|
|
|
|
|
|
} |
|
|
|
|