123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package main
- import (
- "encoding/json"
- "net/http"
- "imuslab.com/zoraxy/mod/dynamicproxy"
- "imuslab.com/zoraxy/mod/mdns"
- "imuslab.com/zoraxy/mod/uptime"
- "imuslab.com/zoraxy/mod/utils"
- )
- /*
- Statistic Summary
- */
- //Handle conversion of statistic daily summary to country summary
- func HandleCountryDistrSummary(w http.ResponseWriter, r *http.Request) {
- requestClientCountry := map[string]int{}
- statisticCollector.DailySummary.RequestClientIp.Range(func(key, value interface{}) bool {
- //Get this client country of original
- clientIp := key.(string)
- //requestCount := value.(int)
- ci, err := geodbStore.ResolveCountryCodeFromIP(clientIp)
- if err != nil {
- return true
- }
- isoCode := ci.CountryIsoCode
- if isoCode == "" {
- //local or reserved addr
- isoCode = "local"
- }
- uc, ok := requestClientCountry[isoCode]
- if !ok {
- //Create the counter
- requestClientCountry[isoCode] = 1
- } else {
- requestClientCountry[isoCode] = uc + 1
- }
- return true
- })
- js, _ := json.Marshal(requestClientCountry)
- utils.SendJSONResponse(w, string(js))
- }
- /*
- Up Time Monitor
- */
- //Generate uptime monitor targets from reverse proxy rules
- 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
- }
- //Handle rendering up time monitor data
- 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
- }
- }
- //Handle listing current registered mdns nodes
- func HandleMdnsListing(w http.ResponseWriter, r *http.Request) {
- js, _ := json.Marshal(previousmdnsScanResults)
- utils.SendJSONResponse(w, string(js))
- }
- func HandleMdnsScanning(w http.ResponseWriter, r *http.Request) {
- domain, err := utils.PostPara(r, "domain")
- var hosts []*mdns.NetworkHost
- if err != nil {
- //Search for arozos node
- hosts = mdnsScanner.Scan(30, "")
- previousmdnsScanResults = hosts
- } else {
- //Search for other nodes
- hosts = mdnsScanner.Scan(30, domain)
- }
- js, _ := json.Marshal(hosts)
- utils.SendJSONResponse(w, string(js))
- }
|