forked from s-rah/onionscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onionscan_config.go
83 lines (72 loc) · 2.15 KB
/
onionscan_config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package config
import (
"bufio"
"fmt"
"github.com/jiderlesi/onionscan/crawldb"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"
)
// OnionScanConfig defines options to tweak the overall OnionScan system.
type OnionScanConfig struct {
TorProxyAddress string
Depth int
Fingerprint bool
Timeout time.Duration
Verbose bool
Database *crawldb.CrawlDB
RescanDuration time.Duration
Scans []string
CrawlConfigs map[string]CrawlConfig
Cookies []*http.Cookie
}
// Configure creates a new OnionScanConfig object with a set of options.
// FIXME: We can make this a decorate and make it much nicer.
func Configure(torProxyAddress string, directoryDepth int, fingerprint bool, timeout int, database string, scans []string, crawlconfigdir string, cookie string, verbose bool) *OnionScanConfig {
osc := new(OnionScanConfig)
osc.TorProxyAddress = torProxyAddress
osc.Depth = directoryDepth
osc.Fingerprint = fingerprint
osc.Timeout = time.Duration(time.Second * time.Duration(timeout))
osc.Verbose = verbose
osc.Database = new(crawldb.CrawlDB)
osc.Database.NewDB(database)
osc.RescanDuration = time.Hour * -100
osc.Scans = scans
osc.CrawlConfigs = make(map[string]CrawlConfig)
rawRequest := fmt.Sprintf("GET / HTTP/1.0\r\nCookie: %s\r\n\r\n", cookie)
req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(rawRequest)))
if err == nil {
osc.Cookies = req.Cookies()
}
visit := func(path string, f os.FileInfo, err error) error {
if !f.IsDir() {
cc, err := LoadCrawlConfig(path)
if err == nil {
osc.LogInfo(fmt.Sprintf("Loading Crawl Config for %s %v", cc.Onion, cc))
osc.CrawlConfigs[cc.Onion] = cc
} else {
osc.LogError(err)
}
}
return nil
}
if crawlconfigdir != "" {
filepath.Walk(crawlconfigdir, visit)
}
return osc
}
// LogInfo logs an informational message to the log, assuming that the log level
// is set low enough.
func (os *OnionScanConfig) LogInfo(message string) {
if os.Verbose {
log.Printf("INFO: %v", message)
}
}
// LogError logs an error message to the log, always.
func (os *OnionScanConfig) LogError(err error) {
log.Printf("ERROR: %v", err)
}