@@ -14,16 +14,37 @@ var (
1414 Type string
1515 path string
1616 help bool
17- defConfig string = "/usr/local/etc/mbtc.conf "
17+ defFolder string = "maltego-btc "
1818)
1919
2020func main () {
21- // parse flags and config
21+ // makes config folder
22+ appconfig , _ := os .UserConfigDir ()
23+ _ = os .MkdirAll (appconfig +
24+ string (os .PathSeparator )+
25+ defFolder , 0755 )
26+ // if path is defined use it, otherwise fall back to default
27+ LogFile := config .LogFile
28+ if LogFile == "" {
29+ LogFile = appconfig +
30+ string (os .PathSeparator ) +
31+ defFolder +
32+ string (os .PathSeparator ) +
33+ "maltego-btc.log"
34+ }
35+ CacheFile := config .CacheFile
36+ if CacheFile == "" {
37+ LogFile = appconfig +
38+ string (os .PathSeparator ) +
39+ defFolder +
40+ string (os .PathSeparator ) +
41+ "maltego-btc.cache"
42+ }
2243 argc := parseArgs ()
2344 config = ParseConfig (path )
2445
2546 // enable logging
26- f , err := os .OpenFile (config . LogFile , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0644 )
47+ f , err := os .OpenFile (LogFile , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0644 )
2748 if err != nil {
2849 fmt .Println ("Error: %v" , err )
2950 os .Exit (1 )
@@ -32,20 +53,46 @@ func main() {
3253 log .SetOutput (f )
3354
3455 if argc >= 3 {
35- LoadCache (config . CacheFile )
56+ LoadCache (CacheFile )
3657 list := GetTransform (query , Type )
3758
3859 FilterTransform (query , Type , & list )
3960 PrintTransform (& list )
4061 CacheGC ()
41- SaveCache (config . CacheFile )
62+ SaveCache (CacheFile )
4263 } else {
4364 flag .PrintDefaults ()
4465 os .Exit (1 )
4566 }
4667}
4768
4869func parseArgs () (argc int ) {
70+ appconfig , _ := os .UserConfigDir ()
71+ defConfig := appconfig +
72+ string (os .PathSeparator ) +
73+ defFolder +
74+ string (os .PathSeparator ) +
75+ "maltego-btc.conf"
76+
77+ configTemplate := `
78+ {
79+ "logfile": "",
80+ "cachefile": "",
81+ "link_address_color": "#B0BEC5",
82+ "link_wallet_color": "#107896",
83+ "wallet_max_size": 5000,
84+ "cache_addresses": 1000,
85+ "cache_wallets": 5000,
86+ "icon_address": "https://raw.githubusercontent.com/Megarushing/maltego-btc/master/assets/bitcoin.png",
87+ "icon_wallet": "https://raw.githubusercontent.com/Megarushing/maltego-btc/master/assets/wallet.png",
88+ "icon_service": "https://raw.githubusercontent.com/Megarushing/maltego-btc/master/assets/service.png"
89+ }
90+ `
91+ if _ , err := os .Stat (defConfig ); err != nil {
92+ f , _ := os .Create (defConfig )
93+ f .WriteString (configTemplate )
94+ f .Close ()
95+ }
4996 // parse flags
5097 flag .StringVar (& path , "c" , defConfig , "Path to config file" )
5198 flag .BoolVar (& help , "h" , false , "Print Help" )
0 commit comments