(ctx *gin.Context, req dto.SearchSSHLog)
| 659 | } |
| 660 | |
| 661 | func (u *SSHService) LoadLog(ctx *gin.Context, req dto.SearchSSHLog) (int64, []dto.SSHHistory, error) { |
| 662 | var fileList []sshFileItem |
| 663 | var data []dto.SSHHistory |
| 664 | baseDir := "/var/log" |
| 665 | fileItems, err := os.ReadDir(baseDir) |
| 666 | if err != nil { |
| 667 | return 0, data, err |
| 668 | } |
| 669 | for _, item := range fileItems { |
| 670 | if item.IsDir() || (!strings.HasPrefix(item.Name(), "secure") && !strings.HasPrefix(item.Name(), "auth.log")) { |
| 671 | continue |
| 672 | } |
| 673 | info, _ := item.Info() |
| 674 | itemPath := path.Join(baseDir, info.Name()) |
| 675 | if strings.HasSuffix(itemPath, ".gz") { |
| 676 | if _, err := os.Stat(strings.TrimSuffix(itemPath, ".gz")); err == nil { |
| 677 | continue |
| 678 | } |
| 679 | } |
| 680 | fileList = append(fileList, sshFileItem{Name: itemPath, Year: info.ModTime().Year()}) |
| 681 | } |
| 682 | fileList = sortFileList(fileList) |
| 683 | |
| 684 | filter := "" |
| 685 | if len(req.Info) != 0 { |
| 686 | if cmd.CheckIllegal(req.Info) { |
| 687 | return 0, data, buserr.New("ErrCmdIllegal") |
| 688 | } |
| 689 | filter = req.Info |
| 690 | } |
| 691 | |
| 692 | showCountFrom := (req.Page - 1) * req.PageSize |
| 693 | showCountTo := req.Page * req.PageSize |
| 694 | nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) |
| 695 | itemFailed, itemTotal := 0, 0 |
| 696 | for _, file := range fileList { |
| 697 | dataItem, successCount, failedCount := loadSSHData( |
| 698 | ctx, |
| 699 | file.Name, |
| 700 | req.Status, |
| 701 | filter, |
| 702 | req.StartTime, |
| 703 | req.EndTime, |
| 704 | showCountFrom, |
| 705 | showCountTo, |
| 706 | file.Year, |
| 707 | nyc, |
| 708 | ) |
| 709 | itemFailed += failedCount |
| 710 | itemTotal += successCount + failedCount |
| 711 | showCountFrom = showCountFrom - (successCount + failedCount) |
| 712 | if showCountTo != -1 { |
| 713 | showCountTo = showCountTo - (successCount + failedCount) |
| 714 | } |
| 715 | data = append(data, dataItem...) |
| 716 | } |
| 717 | |
| 718 | total := itemTotal |
no test coverage detected