Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added download info to flare #1878

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ee/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func checkupsFor(k types.Knapsack, target targetBits) []checkupInt {
{&uninstallHistoryCheckup{k: k}, flareSupported},
{&desktopMenu{k: k}, flareSupported},
{&coredumpCheckup{}, doctorSupported | flareSupported},
{&downloadDirectory{}, flareSupported},
}

checkupsToRun := make([]checkupInt, 0)
Expand Down
120 changes: 120 additions & 0 deletions ee/debug/checkups/download_directory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package checkups

import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strings"
)

type downloadDirectory struct {
status Status
summary string
files []fileInfo
}

func (c *downloadDirectory) Name() string {
return "Kolide Downloads"
}

func (c *downloadDirectory) Run(_ context.Context, extraFH io.Writer) error {
downloadDirs := getDownloadDirs()
if len(downloadDirs) == 0 {
c.status = Erroring
c.summary = "No download directories found"
return nil
}

for _, downloadDir := range downloadDirs {
pattern := filepath.Join(downloadDir, "kolide-launcher*")
matches, err := filepath.Glob(pattern)

if err != nil {
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(extraFH, "Error listing files in directory (%s): %s\n", downloadDir, err)
continue
}

for _, match := range matches {
if info, err := os.Stat(match); err == nil {
c.files = append(c.files, fileInfo{
Name: match,
ModTime: info.ModTime(),
})
}
}
}

switch {
case len(c.files) == 0:
c.status = Informational
c.summary = "No Kolide installers found in any user's download directory"
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
default:
c.status = Informational
fileInfos := make([]string, len(c.files))
for i, file := range c.files {
fileName := filepath.Base(file.Name)
modTime := file.ModTime.Format("Mon, 02 Jan 2006 15:04:05 MST")
fileInfos[i] = fmt.Sprintf("%s (Modified: %s)", fileName, modTime)
}
installerList := strings.Join(fileInfos, ", ")
c.summary = fmt.Sprintf("Found Kolide installer(s) across user download directories: %s", installerList)
}

if len(c.files) > 0 {
fmt.Fprintln(extraFH, "Kolide installers found:")
for _, file := range c.files {
fmt.Fprintln(extraFH, file)
}
}

return nil
}

func (c *downloadDirectory) ExtraFileName() string {
return "kolide-installers-all-users.txt"
}

func (c *downloadDirectory) Status() Status {
return c.status
}

func (c *downloadDirectory) Summary() string {
return c.summary
}

func (c *downloadDirectory) Data() any {
return c.files
}

func getDownloadDirs() []string {
var userDirs []string
var baseDir string

if runtime.GOOS == "windows" {
baseDir = "C:\\Users"
} else if runtime.GOOS == "darwin" {
baseDir = "/Users"
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
} else {
baseDir = "/home"
}

entries, err := os.ReadDir(baseDir)
if err != nil {
return nil
}

for _, entry := range entries {
if !entry.IsDir() {
continue
}
userDir := filepath.Join(baseDir, entry.Name(), "Downloads")
if _, err := os.Stat(userDir); err == nil {
userDirs = append(userDirs, userDir)
}
}

return userDirs
}
Loading