Skip to content

Commit

Permalink
Merge pull request #169 from caffix/default-output-dir
Browse files Browse the repository at this point in the history
Changed the default output directory
  • Loading branch information
caffix committed May 18, 2019
2 parents 18550f9 + 7784326 commit 554bf60
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
7 changes: 4 additions & 3 deletions amass/handlers/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt" // Used by the cayley package
"github.com/cayleygraph/cayley/quad"
homedir "github.com/mitchellh/go-homedir"
)

const (
// DefaultGraphDBDirectory is the directory name used by default for the graph database.
DefaultGraphDBDirectory string = "amass_output"
DefaultGraphDBDirectory string = "amass"
)

// Graph is the object for managing a network infrastructure link graph.
Expand All @@ -39,9 +40,9 @@ type Graph struct {
func NewGraph(path string) *Graph {
var err error

// If a directory was not specified, $PWD/amass_output/ will be used
// If a directory was not specified, $HOME/amass/ will be used
if path == "" {
path, err = os.Getwd()
path, err = homedir.Dir()
if err != nil {
return nil
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/amass.tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/rand"
"os"
"path"
"path/filepath"
"sort"
"strings"
"time"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/OWASP/Amass/amass/handlers"
"github.com/OWASP/Amass/amass/utils"
"github.com/fatih/color"
homedir "github.com/mitchellh/go-homedir"
)

const (
Expand Down Expand Up @@ -102,13 +104,17 @@ func main() {
}

rand.Seed(time.Now().UTC().UnixNano())
// Check that the default graph database directory exists in the CWD

if *dir == "" {
if finfo, err := os.Stat(handlers.DefaultGraphDBDirectory); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
path, err := homedir.Dir()
if err != nil {
r.Fprintln(color.Error, "Failed to obtain the user home directory")
os.Exit(1)
}
} else if finfo, err := os.Stat(*dir); os.IsNotExist(err) || !finfo.IsDir() {
*dir = filepath.Join(path, handlers.DefaultGraphDBDirectory)
}
// Check that the default graph database directory exists
if finfo, err := os.Stat(*dir); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
os.Exit(1)
}
Expand Down
23 changes: 14 additions & 9 deletions cmd/amass.viz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"math/rand"
"os"
"path"
"path/filepath"
"time"

"github.com/OWASP/Amass/amass"
"github.com/OWASP/Amass/amass/handlers"
"github.com/OWASP/Amass/amass/utils/viz"
"github.com/fatih/color"
homedir "github.com/mitchellh/go-homedir"
)

var (
Expand Down Expand Up @@ -73,17 +75,20 @@ func main() {
os.Exit(1)
}
defer os.RemoveAll(*dir)
} else {
// Check that the default graph database directory exists in the CWD
if *dir == "" {
if finfo, err := os.Stat(handlers.DefaultGraphDBDirectory); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
os.Exit(1)
}
} else if finfo, err := os.Stat(*dir); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
}

if *dir == "" {
path, err := homedir.Dir()
if err != nil {
r.Fprintln(color.Error, "Failed to obtain the user home directory")
os.Exit(1)
}
*dir = filepath.Join(path, handlers.DefaultGraphDBDirectory)
}
// Check that the default graph database directory exists
if finfo, err := os.Stat(*dir); os.IsNotExist(err) || !finfo.IsDir() {
r.Fprintln(color.Error, "Failed to open the graph database")
os.Exit(1)
}

graph := handlers.NewGraph(*dir)
Expand Down
8 changes: 7 additions & 1 deletion cmd/amass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/OWASP/Amass/amass/handlers"
"github.com/OWASP/Amass/amass/utils"
"github.com/fatih/color"
homedir "github.com/mitchellh/go-homedir"
)

const (
Expand Down Expand Up @@ -266,7 +267,12 @@ func main() {
// Prepare output file paths
*dir = enum.Config.Dir
if *dir == "" {
*dir = handlers.DefaultGraphDBDirectory
path, err := homedir.Dir()
if err != nil {
r.Fprintln(color.Error, "Failed to obtain the user home directory")
os.Exit(1)
}
*dir = filepath.Join(path, handlers.DefaultGraphDBDirectory)
}
// If the directory does not yet exist, create it
if err = os.MkdirAll(*dir, 0755); err != nil {
Expand Down
File renamed without changes.

0 comments on commit 554bf60

Please sign in to comment.