-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (55 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"flag"
"log"
"path/filepath"
"github.com/kemokemo/wisloc/config"
"github.com/kemokemo/wisloc/util"
)
func main() {
infoPath := flag.String("i", "info.xml", "file path of the information xml to collect logs")
outPath := flag.String("o", `.\`, "root path to save logs.")
flag.Parse()
rootpath := filepath.Clean(*outPath)
// make directory to save files
destPath, err := util.CreateUniqueDir(rootpath)
if err != nil {
log.Fatal("Failed to create the destination directory.", err)
}
// read xml file
conf, err := config.LoadConfig(*infoPath)
// save windows event logs
if conf.IsNeedWindowsEventLogs {
dst := filepath.Join(destPath, `eventlogs`)
err = util.CheckAndMakeDir(dst)
if err != nil {
log.Fatal("Failed to create a directory.", err)
}
err = util.SaveEventLog(dst)
if err != nil {
log.Fatal("Failed to save the windows event logs.", err)
}
}
// save application logs
for _, item := range conf.LogPathInfoList {
dst := filepath.Join(destPath, filepath.Base(item.Path))
err = util.Copy(item.Path, dst)
if err != nil {
log.Fatal("Failed to copy.", err)
}
}
// save application registry entries
for _, reg := range conf.RegistryInfoList {
err = util.RegExport(reg.Key, destPath)
if err != nil {
log.Fatal("Failed to export registry.", err)
}
}
// archive the directory
archiver := util.ZIP
filename := archiver.DestFmt()(filepath.Base(destPath))
err = archiver.Archive(destPath, filepath.Join(rootpath, filename))
if err != nil {
log.Println("Failed to archive.", err)
}
}