diff --git a/commands/prepare.go b/commands/prepare.go index d3daf9bb55..ff664e430c 100644 --- a/commands/prepare.go +++ b/commands/prepare.go @@ -20,6 +20,7 @@ package commands import ( "flag" "os" + "path/filepath" "github.com/Sirupsen/logrus" c "github.com/future-architect/vuls/config" @@ -72,7 +73,9 @@ func (p *PrepareCmd) SetFlags(f *flag.FlagSet) { f.BoolVar(&p.debug, "debug", false, "debug mode") - defaultConfPath := os.Getenv("PWD") + "/config.toml" + wd, _ := os.Getwd() + + defaultConfPath := filepath.Join(wd, "config.toml") f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") f.BoolVar( diff --git a/commands/scan.go b/commands/scan.go index 272a29f52d..c586f72296 100644 --- a/commands/scan.go +++ b/commands/scan.go @@ -20,6 +20,7 @@ package commands import ( "flag" "os" + "path/filepath" "github.com/Sirupsen/logrus" c "github.com/future-architect/vuls/config" @@ -87,10 +88,12 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) { f.BoolVar(&p.debug, "debug", false, "debug mode") f.BoolVar(&p.debugSQL, "debug-sql", false, "SQL debug mode") - defaultConfPath := os.Getenv("PWD") + "/config.toml" + wd, _ := os.Getwd() + + defaultConfPath := filepath.Join(wd, "config.toml") f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") - defaultDBPath := os.Getenv("PWD") + "/vuls.sqlite3" + defaultDBPath := filepath.Join(wd, "vuls.sqlite3") f.StringVar(&p.dbpath, "dbpath", defaultDBPath, "/path/to/sqlite3") defaultURL := "http://127.0.0.1:1323" diff --git a/commands/tui.go b/commands/tui.go index 927c29f629..610e57fd4a 100644 --- a/commands/tui.go +++ b/commands/tui.go @@ -21,6 +21,7 @@ import ( "flag" "fmt" "os" + "path/filepath" c "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/report" @@ -54,7 +55,9 @@ func (p *TuiCmd) SetFlags(f *flag.FlagSet) { // f.StringVar(&p.lang, "lang", "en", "[en|ja]") f.BoolVar(&p.debugSQL, "debug-sql", false, "debug SQL") - defaultDBPath := os.Getenv("PWD") + "/vuls.sqlite3" + wd, _ := os.Getwd() + + defaultDBPath := filepath.Join(wd, "vuls.sqlite3") f.StringVar(&p.dbpath, "dbpath", defaultDBPath, fmt.Sprintf("/path/to/sqlite3 (default: %s)", defaultDBPath)) } diff --git a/report/logrus.go b/report/logrus.go index 4a663e985b..cba0ed781a 100644 --- a/report/logrus.go +++ b/report/logrus.go @@ -19,6 +19,8 @@ package report import ( "os" + "path/filepath" + "runtime" "github.com/Sirupsen/logrus" "github.com/future-architect/vuls/models" @@ -31,6 +33,9 @@ type LogrusWriter struct { func (w LogrusWriter) Write(scanResults []models.ScanResult) error { path := "/var/log/vuls/report.log" + if runtime.GOOS == "windows" { + path = filepath.Join(os.Getenv("APPDATA"), "vuls", "report.log") + } f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return err diff --git a/scan/sshutil.go b/scan/sshutil.go index df39c49aae..d9ea4fbc03 100644 --- a/scan/sshutil.go +++ b/scan/sshutil.go @@ -122,7 +122,7 @@ func sshExec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (re } else { logger = log[0] } - + c.SudoOpt.ExecBySudo = true var err error if sudo && c.User != "root" { switch { diff --git a/util/logutil.go b/util/logutil.go index 008e65f725..25cbc58d23 100644 --- a/util/logutil.go +++ b/util/logutil.go @@ -20,6 +20,8 @@ package util import ( "fmt" "os" + "path/filepath" + "runtime" "github.com/Sirupsen/logrus" "github.com/rifflock/lfshook" @@ -40,6 +42,9 @@ func NewCustomLogger(c config.ServerInfo) *logrus.Entry { // File output logDir := "/var/log/vuls" + if runtime.GOOS == "windows" { + logDir = filepath.Join(os.Getenv("APPDATA"), "vuls") + } if _, err := os.Stat(logDir); os.IsNotExist(err) { if err := os.Mkdir(logDir, 0666); err != nil { logrus.Errorf("Failed to create log directory: %s", err)