summaryrefslogtreecommitdiff
path: root/pkg/helper/windows.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-04-22 23:52:04 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-04-30 22:10:27 +0200
commite05f5aa352f6ba55562a0afade0fa9046aeaf0d1 (patch)
treee225f9c4cb33cd5d0b0fb2b1c9b4a07c47d836a4 /pkg/helper/windows.go
parente3baef0e9e36e1b0f3e899ef8e83520004b50a29 (diff)
[pkg] initialize service early for windows
Diffstat (limited to 'pkg/helper/windows.go')
-rw-r--r--pkg/helper/windows.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/pkg/helper/windows.go b/pkg/helper/windows.go
index 376b376..70c6d6a 100644
--- a/pkg/helper/windows.go
+++ b/pkg/helper/windows.go
@@ -37,15 +37,20 @@ const (
chocoOpenvpnPath = `C:\Program Files\OpenVPN\bin\openvpn.exe`
)
+type httpConf struct {
+ BindAddr string
+}
+
var (
platformOpenvpnFlags = []string{
"--script-security", "1",
"--block-outside-dns",
}
- httpBindAddr string
+ httpServerConf = &httpConf{}
)
func parseCliArgs() {
+ log.Println("Parsing CLI args...")
isIntSess, err := svc.IsAnInteractiveSession()
if err != nil {
log.Fatalf("Failed to determine if we are running in an interactive session: %v", err)
@@ -54,15 +59,18 @@ func parseCliArgs() {
runService(svcName, false)
return
}
+ log.Println("Checking for admin")
admin := isAdmin()
fmt.Printf("Running as admin: %v\n", admin)
if !admin {
- log.Fatal("Needs to be run as administrator")
+ fmt.Println("Needs to be run as administrator")
+ os.Exit(2)
}
if len(os.Args) < 2 {
usage("ERROR: no command specified")
}
cmd := strings.ToLower(os.Args[1])
+ log.Println("cmd:", cmd)
switch cmd {
case "debug":
runService(svcName, true)
@@ -95,16 +103,19 @@ func usage(errmsg string) {
os.Exit(2)
}
-func daemonize() {}
-
-// http server is called from within Execute in windows
-func doHandleCommands(preferredPort int) {
+// initializeService only initializes the server.
+// we expect serveHTTP to be called from within Execute in windows
+func initializeService(preferredPort int) {
port := getFirstAvailablePortFrom(preferredPort)
writePortToFile(port)
- bindAddr := "localhost:" + strconv.Itoa(port)
- httpBindAddr = bindAddr
+ httpServerConf.BindAddr = "localhost:" + strconv.Itoa(port)
+ log.Println("Command server initialized to listen on", httpServerConf.BindAddr)
}
+func daemonize() {}
+
+func runServer(port int) {}
+
func getOpenvpnPath() string {
if _, err := os.Stat(openvpnPath); !os.IsNotExist(err) {
return openvpnPath