mirror of
https://github.com/schollz/hostyoself.git
synced 2026-01-23 02:15:14 +00:00
check domain before using referrer
This commit is contained in:
parent
a11230bf29
commit
c4dfc70944
1 changed files with 16 additions and 5 deletions
|
|
@ -127,13 +127,17 @@ Disallow: /`))
|
|||
// determine file path and the domain
|
||||
pathToFile := r.URL.Path[1:]
|
||||
domain := strings.Split(r.URL.Path[1:], "/")[0]
|
||||
// if there is a referer, try to obtain the domain from referer
|
||||
piecesOfReferer := strings.Split(r.Referer(), "/")
|
||||
if len(piecesOfReferer) > 4 && strings.HasPrefix(r.Referer(), s.publicURL) {
|
||||
domain = piecesOfReferer[3]
|
||||
}
|
||||
// clean domain
|
||||
domain = strings.Replace(strings.ToLower(strings.TrimSpace(domain)), " ", "-", -1)
|
||||
if !s.isdomain(domain) {
|
||||
log.Debugf("getting referer")
|
||||
// if there is a referer, try to obtain the domain from referer
|
||||
piecesOfReferer := strings.Split(r.Referer(), "/")
|
||||
if len(piecesOfReferer) > 4 && strings.HasPrefix(r.Referer(), s.publicURL) {
|
||||
domain = piecesOfReferer[3]
|
||||
domain = strings.Replace(strings.ToLower(strings.TrimSpace(domain)), " ", "-", -1)
|
||||
}
|
||||
}
|
||||
|
||||
// prefix the domain if it doesn't exist
|
||||
if !strings.HasPrefix(pathToFile, domain) {
|
||||
|
|
@ -275,6 +279,13 @@ func (s *server) handleWebsocket(w http.ResponseWriter, r *http.Request) (err er
|
|||
return
|
||||
}
|
||||
|
||||
func (s *server) isdomain(domain string) bool {
|
||||
s.Lock()
|
||||
_, ok := s.conn[domain]
|
||||
s.Unlock()
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s *server) get(domain, filePath, ipAddress string) (payload string, err error) {
|
||||
var connections []*connection
|
||||
s.Lock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue