12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package main
- import (
- "encoding/json"
- "net/http"
- "imuslab.com/zoraxy/mod/dynamicproxy"
- "imuslab.com/zoraxy/mod/uptime"
- "imuslab.com/zoraxy/mod/utils"
- )
- func HandleCountryDistrSummary(w http.ResponseWriter, r *http.Request) {
- requestClientCountry := map[string]int{}
- statisticCollector.DailySummary.RequestClientIp.Range(func(key, value interface{}) bool {
-
- clientIp := key.(string)
-
- ci, err := geodbStore.ResolveCountryCodeFromIP(clientIp)
- if err != nil {
- return true
- }
- isoCode := ci.CountryIsoCode
- if isoCode == "" {
-
- isoCode = "local"
- }
- uc, ok := requestClientCountry[isoCode]
- if !ok {
-
- requestClientCountry[isoCode] = 1
- } else {
- requestClientCountry[isoCode] = uc + 1
- }
- return true
- })
- js, _ := json.Marshal(requestClientCountry)
- utils.SendJSONResponse(w, string(js))
- }
- func GetUptimeTargetsFromReverseProxyRules(dp *dynamicproxy.Router) []*uptime.Target {
- subds := dp.GetSDProxyEndpointsAsMap()
- vdirs := dp.GetVDProxyEndpointsAsMap()
- UptimeTargets := []*uptime.Target{}
- for subd, target := range subds {
- url := "http://" + target.Domain
- protocol := "http"
- if target.RequireTLS {
- url = "https://" + target.Domain
- protocol = "https"
- }
- UptimeTargets = append(UptimeTargets, &uptime.Target{
- ID: subd,
- Name: subd,
- URL: url,
- Protocol: protocol,
- })
- }
- for vdir, target := range vdirs {
- url := "http://" + target.Domain
- protocol := "http"
- if target.RequireTLS {
- url = "https://" + target.Domain
- protocol = "https"
- }
- UptimeTargets = append(UptimeTargets, &uptime.Target{
- ID: vdir,
- Name: "*" + vdir,
- URL: url,
- Protocol: protocol,
- })
- }
- return UptimeTargets
- }
- func HandleUptimeMonitorListing(w http.ResponseWriter, r *http.Request) {
- if uptimeMonitor != nil {
- uptimeMonitor.HandleUptimeLogRead(w, r)
- } else {
- http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
- return
- }
- }
|