-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
109 lines (92 loc) · 2.98 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"flag"
"fmt"
"os"
"org.samba/isetta/adapter/dnsconfig"
"org.samba/isetta/adapter/envvars"
"org.samba/isetta/adapter/httpchecker"
"org.samba/isetta/adapter/linux"
"org.samba/isetta/adapter/windows"
"org.samba/isetta/config"
"org.samba/isetta/core"
"org.samba/isetta/gsudo"
"org.samba/isetta/helper"
log "org.samba/isetta/simplelogger"
)
const version = "0.5.1"
func main() {
envSettings := flag.Bool("env-settings", false, "Prints environment config. Handy if called via 'source'")
printVersion := flag.Bool("version", false, "Print isetta version")
flag.Parse()
if *printVersion {
fmt.Printf("Isetta version %v\n", version)
os.Exit(0)
}
conf := config.FromConfigFile("$HOME", log.GetValidLogLevels())
log.Logger.CurrentLogLevel = log.Levels[conf.General.LogLevel]
handler := setupDependencies(conf)
if *envSettings {
handler.PrintEnvVars()
} else {
err := handler.ConfigureNetwork()
helper.AssertNoError2(err)
}
}
func setupDependencies(conf config.Config) core.Handler {
envVarprinter := envvars.ConsoleEnvVarPrinter{
WindowsIp: conf.Network.P2p.WindowsIp,
PxProxyPort: conf.Network.PxProxyPort,
NoProxy: conf.Network.NoProxy,
}
windowsChecker := windows.WindowsCheckerImpl{PxProxyPort: conf.Network.PxProxyPort}
windowsConfigurer := windows.WindowsConfigurerImpl{
WindowsIp: conf.Network.P2p.WindowsIp,
SubnetMask: conf.Network.P2p.SubnetMask,
PxProxyPort: conf.Network.PxProxyPort,
Gsudo: &gsudo.Gsudo{},
}
linuxPinger := linux.LinuxPingerImpl{}
linuxConfigurer := linux.LinuxConfigurerImpl{
WindowsIp: conf.Network.P2p.WindowsIp,
LinuxIp: conf.Network.P2p.LinuxIp,
SubnetMask: conf.Network.P2p.SubnetMask,
}
dnsConfigurer := dnsconfig.DnsConfigurerImpl{}
httpchecker, err := httpchecker.New(conf.General.InternetAccessTestUrl, config.GetProxyUrl(conf))
helper.AssertNoError2(err)
directAccess := core.DirectAccess{
PublicDnsServer: conf.Dns.PublicServer,
DnsConfigurer: dnsConfigurer,
LinuxPinger: &linuxPinger,
LinuxConfigurer: &linuxConfigurer,
HttpChecker: &httpchecker,
EnvVarPrinter: &envVarprinter,
}
viaproxy := core.ViaProxy{
// static
LinuxP2pIp: conf.Network.P2p.LinuxIp,
WindowsP2pIp: conf.Network.P2p.WindowsIp,
PxProxyPort: conf.Network.PxProxyPort,
InternalDnsServer: conf.Dns.InternalServer,
// objects
WindowsChecker: &windowsChecker,
WindowsConfigurer: &windowsConfigurer,
DnsConfigurer: &dnsConfigurer,
LinuxPinger: &linuxPinger,
LinuxConfigurer: &linuxConfigurer,
HttpChecker: &httpchecker,
}
handler := core.Handler{
RunningAsRoot: os.Geteuid() == 0,
InternalDnsServer: conf.Dns.InternalServer,
PublicDnsServer: conf.Dns.PublicServer,
WindowsChecker: &windowsChecker,
DnsConfigurer: &dnsConfigurer,
EnvVarPrinter: &envVarprinter,
DirectAccess: &directAccess,
ViaProxy: &viaproxy,
InternetChecker: core.NewInternetChecker(&httpchecker),
}
return handler
}