From 83db0f096f18dc6a081c86c67370761b0ae8149e Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Thu, 4 Jul 2024 12:10:12 +0800 Subject: [PATCH] fix: display stats by html. --- pkg/proxy/http.go | 92 ++++++++++++++++++++++++++------------------- pkg/switch/ipsec.go | 9 ++--- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/pkg/proxy/http.go b/pkg/proxy/http.go index 33ce9f2..d4d1aba 100755 --- a/pkg/proxy/http.go +++ b/pkg/proxy/http.go @@ -23,12 +23,12 @@ import ( type HttpRecord struct { Count int - LastAt time.Time + LastAt string } func (r *HttpRecord) Update() { r.Count += 1 - r.LastAt = time.Now() + r.LastAt = time.Now().Local().String() } type HttpProxy struct { @@ -389,57 +389,71 @@ func (t *HttpProxy) Start() { var httpTmpl = map[string]string{ "stats": ` - - - - - - - - - - - - - -
Configuration:json
StartAt:{{ .StartAt }}
Total:{{ .Total }}
- - - - - - - - {{- range $k, $v := .Requests }} - - - - - - {{- end }} -
DomainCountLastAt
{{ $k }}{{ $v.Count }}{{ $v.LastAt }}
`, - + + + + + OpenLAN Proxy + + + + + + + + + + + + + +
Configuration:display
StartAt:{{ .StartAt }}
Total:{{ .Total }}
+ + + + + {{- range $k, $v := .Requests }} + + + + {{- end }} +
DomainCountLastAt
{{ $k }}{{ $v.Count }}{{ $v.LastAt }}
+ +`, "pac": ` function FindProxyForURL(url, host) { - if (isPlainHostName(host)) - return "DIRECT"; + if (isPlainHostName(host)) + return "DIRECT"; {{- range .Rules }} - if (shExpMatch(host, "(^|*\.){{ . }}")) - return "PROXY {{ $.Local }}"; + if (shExpMatch(host, "(^|*\.){{ . }}")) + return "PROXY {{ $.Local }}"; {{- end }} - return "DIRECT"; + return "DIRECT"; }`, } func (t *HttpProxy) GetStats(w http.ResponseWriter, r *http.Request) { data := &struct { - StartAt time.Time + StartAt string Total int Requests map[string]*HttpRecord }{ Total: len(t.requests), Requests: t.requests, - StartAt: t.startat, + StartAt: t.startat.Local().String(), } if tmpl, err := template.New("main").Parse(httpTmpl["stats"]); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/pkg/switch/ipsec.go b/pkg/switch/ipsec.go index a2f4ffa..19d0d3f 100644 --- a/pkg/switch/ipsec.go +++ b/pkg/switch/ipsec.go @@ -69,8 +69,7 @@ conn {{ .Name }}-c2 rightid=@c1.{{ .RightId }}.{{ .Transport }} {{- end }} leftprotoport=udp - rightprotoport=udp/8472 -`, + rightprotoport=udp/8472`, "gre": ` conn {{ .Name }}-c1 auto=add @@ -92,11 +91,9 @@ conn {{ .Name }}-c1 {{- end }} authby=secret leftprotoport=gre - rightprotoport=gre -`, + rightprotoport=gre`, "secret": ` -%any @{{ .RightId }}.{{ .Transport }} : PSK "{{ .Secret }}" -`, +%any @{{ .RightId }}.{{ .Transport }} : PSK "{{ .Secret }}"`, } func (w *IPSecWorker) Initialize() {