forked from projectdiscovery/simplehttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
70 lines (61 loc) · 1.61 KB
/
runner.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
package runner
import (
"github.com/projectdiscovery/simplehttpserver/pkg/httpserver"
"github.com/projectdiscovery/simplehttpserver/pkg/tcpserver"
)
// Runner is a client for running the enumeration process.
type Runner struct {
options *Options
serverTCP *tcpserver.TCPServer
httpServer *httpserver.HTTPServer
}
func New(options *Options) (*Runner, error) {
r := Runner{options: options}
if r.options.EnableTCP {
serverTCP, err := tcpserver.New(tcpserver.Options{
Listen: r.options.ListenAddress,
TLS: r.options.TCPWithTLS,
Domain: "local.host",
Verbose: r.options.Verbose,
})
if err != nil {
return nil, err
}
err = serverTCP.LoadTemplate(r.options.RulesFile)
if err != nil {
return nil, err
}
r.serverTCP = serverTCP
return &r, nil
}
httpServer, err := httpserver.New(&httpserver.Options{
Folder: r.options.Folder,
EnableUpload: r.options.EnableUpload,
ListenAddress: r.options.ListenAddress,
TLS: r.options.HTTPS,
Certificate: r.options.TLSCertificate,
CertificateKey: r.options.TLSKey,
CertificateDomain: r.options.TLSDomain,
BasicAuthUsername: r.options.username,
BasicAuthPassword: r.options.password,
BasicAuthReal: r.options.Realm,
Verbose: r.options.Verbose,
})
if err != nil {
return nil, err
}
r.httpServer = httpServer
return &r, nil
}
func (r *Runner) Run() error {
if r.options.EnableTCP {
return r.serverTCP.ListenAndServe()
}
if r.options.HTTPS {
return r.httpServer.ListenAndServeTLS()
}
return r.httpServer.ListenAndServe()
}
func (r *Runner) Close() error {
return nil
}