Skip to content

Commit

Permalink
Merge pull request #33 from mattn/windows
Browse files Browse the repository at this point in the history
Support Windows
  • Loading branch information
kotakanbe committed Apr 22, 2016
2 parents d7e1566 + da16f96 commit 9292448
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
5 changes: 4 additions & 1 deletion commands/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package commands
import (
"flag"
"os"
"path/filepath"

"github.com/Sirupsen/logrus"
c "github.com/future-architect/vuls/config"
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package commands
import (
"flag"
"os"
"path/filepath"

"github.com/Sirupsen/logrus"
c "github.com/future-architect/vuls/config"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion commands/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"

c "github.com/future-architect/vuls/config"
"github.com/future-architect/vuls/report"
Expand Down Expand Up @@ -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))
}
Expand Down
5 changes: 5 additions & 0 deletions report/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package report

import (
"os"
"path/filepath"
"runtime"

"github.com/Sirupsen/logrus"
"github.com/future-architect/vuls/models"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scan/sshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions util/logutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package util
import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/Sirupsen/logrus"
"github.com/rifflock/lfshook"
Expand All @@ -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)
Expand Down

0 comments on commit 9292448

Please sign in to comment.