@@ -4250,3 +4250,65 @@ func SyncRenewalCert() {
42504250 }
42514251
42524252}
4253+
4254+ func (s * Wafmastersite ) GetSiteLogsSize (request * http.Request ) core.Response {
4255+ // 备份网站日志
4256+ list , err := public .GetHistorySiteLogs ("/www/cloud_waf/vhost/history_backups/logs" )
4257+ if err != nil {
4258+ list = make (map [string ]int64 )
4259+ }
4260+ //当前的网站日志
4261+ list2 , err := public .GetHistorySiteLogs ("/www/cloud_waf/nginx/logs" )
4262+ if err != nil {
4263+ list2 = make (map [string ]int64 )
4264+ }
4265+ return core .Success (map [string ]interface {}{
4266+ "history" : list ,
4267+ "site" : list2 ,
4268+ })
4269+ }
4270+
4271+ // 清理日志
4272+ func (s * Wafmastersite ) ClearSiteLogs (request * http.Request ) core.Response {
4273+ //参数是一个list ["路径1", "路径2", ...]
4274+ params := struct {
4275+ Paths []string `json:"paths"`
4276+ }{}
4277+ if err := core .GetParamsFromRequestToStruct (request , & params ); err != nil {
4278+ return core .Fail (err )
4279+ }
4280+ if len (params .Paths ) == 0 {
4281+ return core .Fail ("参数错误,路径不能为空" )
4282+ }
4283+ for _ , path := range params .Paths {
4284+ if ! strings .HasSuffix (path , ".log" ) && ! strings .HasSuffix (path , ".zip" ) {
4285+ continue
4286+ }
4287+
4288+ abs , err := filepath .Abs (path )
4289+ if err != nil {
4290+ continue
4291+ }
4292+ if ! strings .HasPrefix (abs , "/www/cloud_waf/vhost/history_backups/logs/" ) && ! strings .HasPrefix (abs , "/www/cloud_waf/nginx/logs/" ) {
4293+ continue
4294+ }
4295+ //如果zip文件则直接删除
4296+ if strings .HasSuffix (path , ".zip" ) {
4297+ if public .FileExists (abs ) {
4298+ err = os .Remove (abs )
4299+ if err != nil {
4300+ return core .Fail ("删除文件失败:" + err .Error ())
4301+ }
4302+ }
4303+ continue
4304+ }
4305+ //如果是.log 的文件则内容直接清空
4306+ if public .FileExists (abs ) {
4307+ err = os .Truncate (abs , 0 )
4308+ if err != nil {
4309+ return core .Fail ("网站日志清空失败:" + err .Error ())
4310+ }
4311+ }
4312+ }
4313+ return core .Success ("网站日志清理成功" )
4314+ }
0 commit comments