package main import ( "encoding/hex" "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" "strconv" "strings" "time" ) func loggingRequest(tag string, r *http.Request) { fmt.Printf("%s --- %s\n", time.Now(), tag) } // 前面有代理,获取不到正确的域名的情况 func createIndexHandler(reverseHost string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { loggingRequest("indexHandler", r) var host string if len(reverseHost) > 0 { host = reverseHost } else { host = "http://" + r.Host + r.RequestURI } host = strings.TrimSuffix(host, "/") w.Header().Set("content-type", "text/html; charset=utf-8") w.WriteHeader(200) html := `
License Server started at %s
JRebel 7.1 and earlier version Activation address was: %s/{tokenname}, with any email."
JRebel 2018.1 and later version Activation address was: %s/{guid}(eg: %s/%s ), with any email.`
_, _ = fmt.Fprintf(w, html, host, host, host, host, newUUIDV4String())
}
}
func jrebelLeasesHandler(w http.ResponseWriter, r *http.Request) {
loggingRequest("jrebelLeasesHandler", r)
w.Header().Set("content-type", "application/json; charset=utf-8")
parameter, err := getHttpBodyParameter(r)
if err != nil {
w.WriteHeader(403)
_, _ = fmt.Fprintf(w, "%s\n", err)
return
}
clientRandomness := parameter.Get("randomness")
username := parameter.Get("username")
guid := parameter.Get("guid")
if clientRandomness == "" || username == "" || guid == "" {
w.WriteHeader(403)
_, _ = fmt.Fprint(w)
return
}
offline, err := strconv.ParseBool(parameter.Get("offline"))
if err != nil {
offline = false
}
validFrom := "null"
validUntil := "null"
if offline {
clientTime := parameter.Get("clientTime")
_ = parameter.Get("offlineDays")
startTimeInt, err := strconv.ParseInt(clientTime, 10, 64)
if err != nil {
startTimeInt = int64(time.Now().Second()) * 1000
}
// 过期时间
expTime := int64(180 * 24 * 60 * 60 * 100)
validFrom = clientTime
validUntil = strconv.FormatInt(startTimeInt+expTime, 10)
}
serverRandomness := newServerRandomness()
signature := toLeaseCreateJson(clientRandomness, serverRandomness, guid, offline, validFrom, validUntil)
var responseBody = jRebelLeases
responseBody.ServerRandomness = serverRandomness
responseBody.Signature = signature
responseBody.Company = username
response(w, &responseBody)
}
func jrebelLeases1Handler(w http.ResponseWriter, r *http.Request) {
loggingRequest("jrebelLeases1Handler", r)
w.Header().Set("content-type", "application/json; charset=utf-8")
parameter, err := getHttpBodyParameter(r)
if err != nil {
w.WriteHeader(403)
_, _ = fmt.Fprintf(w, "%s\n", err)
return
}
username := parameter.Get("username")
var responseBody = jrebelLeases1
if username != "" {
responseBody.Company = username
}
response(w, &responseBody)
}
func jrebelValidateHandler(w http.ResponseWriter, r *http.Request) {
loggingRequest("jrebelValidateHandler", r)
w.Header().Add("content-type", "application/json; charset=utf-8")
w.WriteHeader(200)
_, _ = fmt.Fprintf(w, "%s\n", jrebelValidateJson)
}
func pingHandler(w http.ResponseWriter, r *http.Request) {
loggingRequest("pingHandler", r)
w.Header().Add("content-type", "text/html; charset=utf-8")
parameter, err := getHttpBodyParameter(r)
if err != nil {
w.WriteHeader(403)
_, _ = fmt.Fprintf(w, "%s\n", err)
return
}
salt := parameter.Get("salt")
if salt == "" {
w.WriteHeader(403)
_, _ = fmt.Fprint(w)
} else {
xmlContent := "