mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 10:02:09 +08:00
增加审计日志、图表数据自动清理功能
This commit is contained in:
@@ -49,3 +49,8 @@ func GetAuditSession(search string) *xorm.Session {
|
||||
}
|
||||
return session
|
||||
}
|
||||
|
||||
func ClearAccessAudit(ts string) (int64, error) {
|
||||
affected, err := xdb.Where("created_at < '" + ts + "'").Delete(&AccessAudit{})
|
||||
return affected, err
|
||||
}
|
||||
|
@@ -87,6 +87,13 @@ func addInitData() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SettingAuditLog
|
||||
auditLog := SettingGetAuditLogDefault()
|
||||
err = SettingSessAdd(sess, auditLog)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// SettingOther
|
||||
other := &SettingOther{
|
||||
LinkAddr: "vpn.xx.com",
|
||||
|
@@ -3,6 +3,7 @@ package dbdata
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,11 @@ type SettingSmtp struct {
|
||||
Encryption string `json:"encryption"`
|
||||
}
|
||||
|
||||
type SettingAuditLog struct {
|
||||
LifeDay int `json:"life_day"`
|
||||
ClearTime string `json:"clear_time"`
|
||||
}
|
||||
|
||||
type SettingOther struct {
|
||||
LinkAddr string `json:"link_addr"`
|
||||
Banner string `json:"banner"`
|
||||
@@ -64,3 +70,30 @@ func SettingGet(data interface{}) error {
|
||||
err = json.Unmarshal(s.Data, data)
|
||||
return err
|
||||
}
|
||||
|
||||
func SettingGetAuditLog() (SettingAuditLog, error) {
|
||||
data := SettingAuditLog{}
|
||||
err := SettingGet(&data)
|
||||
if err == nil {
|
||||
return data, err
|
||||
}
|
||||
if !CheckErrNotFound(err) {
|
||||
return data, err
|
||||
}
|
||||
sess := xdb.NewSession()
|
||||
defer sess.Close()
|
||||
auditLog := SettingGetAuditLogDefault()
|
||||
err = SettingSessAdd(sess, auditLog)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
return auditLog, nil
|
||||
}
|
||||
|
||||
func SettingGetAuditLogDefault() SettingAuditLog {
|
||||
auditLog := SettingAuditLog{
|
||||
LifeDay: 0,
|
||||
ClearTime: "05:00",
|
||||
}
|
||||
return auditLog
|
||||
}
|
||||
|
@@ -203,7 +203,6 @@ func (s *StatsInfo) getScopeDetail(scope string) (sd *ScopeDetail) {
|
||||
switch base.Cfg.DbType {
|
||||
case "sqlite3", "postgres":
|
||||
sd.fsTime = sd.sTime.UTC().Format(LayoutTimeFormat)
|
||||
sd.feTime = sd.eTime.UTC().Format(LayoutTimeFormat)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -237,3 +236,17 @@ func (s *StatsInfo) getStatsWhere(sd *ScopeDetail) (where string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *StatsInfo) ClearStatsInfo(action string, ts string) (affected int64, err error) {
|
||||
switch action {
|
||||
case "online":
|
||||
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsOnline{})
|
||||
case "network":
|
||||
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsNetwork{})
|
||||
case "cpu":
|
||||
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsCpu{})
|
||||
case "mem":
|
||||
affected, err = xdb.Where("created_at < '" + ts + "'").Delete(&StatsMem{})
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user