diff --git a/README.md b/README.md index 1587cb1..d87ee76 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ - +   #  **ONLINE TOOLS ([codetabs.com](https://codetabs.com))** -**version 0.8.2** +**version 0.8.3** 1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online) 2. [CORS proxy](#cors-proxy) diff --git a/_utils/stats.go b/_utils/stats.go index cc59432..6c08264 100644 --- a/_utils/stats.go +++ b/_utils/stats.go @@ -3,6 +3,7 @@ package _utils import ( + "fmt" "log" "net/http" "os" @@ -11,21 +12,29 @@ import ( ) // AddHit ... -func AddHit(w http.ResponseWriter, r *http.Request, - service, mode string, hLog *log.Logger) { +func AddHit(w http.ResponseWriter, r *http.Request, service, mode string, + hLog *log.Logger) { ip := GetIP(r) sv := strings.ToUpper(service) - host := r.Header.Get("Origin") + host := r.Header.Get("Host") if host == "" { - host = " ? " + host = r.Header.Get("Origin") + if host == "" { + host = r.Header.Get("Referer") + if host == "" { + host = "???" + } + } } - quest := r.Form.Get("quest") + + askingFor := strings.Trim(fmt.Sprint(r.URL), string(r.URL.Path)) + if mode == "production" { - hLog.Println(ip, sv, host, quest) + hLog.Println(ip, sv, host, askingFor) hitUrl := "http://localhost:3970/addHit/" + service saveHit(w, hitUrl) } else { - log.Println(ip, sv, host, quest) + log.Println(ip, sv, host, askingFor) } } diff --git a/main.go b/main.go index f64578f..54ff58f 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( "github.com/jolav/codetabs/weather" ) -var version = "0.8.2" +var version = "0.8.3" var when = "undefined" type Conf struct { diff --git a/stars/stars.go b/stars/stars.go index 4ae0869..d86e248 100644 --- a/stars/stars.go +++ b/stars/stars.go @@ -62,6 +62,10 @@ func Router(w http.ResponseWriter, r *http.Request) { s.cleanStarsStruct() r.ParseForm() data := r.Form.Get("repo") + if data == "" { + u.BadRequest(w, r) + return + } s.source = data[0:2] s.repo = data[2:len(data)] aux := strings.Split(s.repo, "/") diff --git a/www/_public/templates/version.html b/www/_public/templates/version.html index a746918..a37255e 100644 --- a/www/_public/templates/version.html +++ b/www/_public/templates/version.html @@ -2,7 +2,7 @@