mirror of
https://github.com/luscis/openlan.git
synced 2025-09-27 04:46:02 +08:00
fix: display expire time.
This commit is contained in:
@@ -15,8 +15,9 @@ func (v Version) Url(prefix, name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v Version) Tmpl() string {
|
func (v Version) Tmpl() string {
|
||||||
return `Version : {{ .Version }}
|
return `Version : {{ .Version }}
|
||||||
Build at: {{ .Date}}
|
Build at : {{ .Date}}
|
||||||
|
Expire at: {{ .Expire }}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/luscis/openlan/pkg/schema"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/luscis/openlan/pkg/cache"
|
||||||
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Version struct {
|
type Version struct {
|
||||||
@@ -15,5 +17,6 @@ func (l Version) Router(router *mux.Router) {
|
|||||||
|
|
||||||
func (l Version) List(w http.ResponseWriter, r *http.Request) {
|
func (l Version) List(w http.ResponseWriter, r *http.Request) {
|
||||||
ver := schema.NewVersionSchema()
|
ver := schema.NewVersionSchema()
|
||||||
|
ver.Expire = cache.User.ExpireTime()
|
||||||
ResponseJson(w, ver)
|
ResponseJson(w, ver)
|
||||||
}
|
}
|
||||||
|
23
pkg/cache/user.go
vendored
23
pkg/cache/user.go
vendored
@@ -246,6 +246,29 @@ func (w *user) SetCert(cfg *libol.CertConfig) {
|
|||||||
w.Cert = cfg.Crt
|
w.Cert = cfg.Crt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *user) ExpireTime() string {
|
||||||
|
if w.Cert == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
pemData, err := os.ReadFile(w.Cert)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
block, rest := pem.Decode(pemData)
|
||||||
|
if block == nil || len(rest) > 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, err := x509.ParseCertificate(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return cert.NotAfter.Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
var User = user{
|
var User = user{
|
||||||
Users: libol.NewSafeStrMap(1024),
|
Users: libol.NewSafeStrMap(1024),
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import "github.com/luscis/openlan/pkg/libol"
|
|||||||
type Version struct {
|
type Version struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
|
Expire string `json:"expire"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVersionSchema() Version {
|
func NewVersionSchema() Version {
|
||||||
|
Reference in New Issue
Block a user