Skip to content
Snippets Groups Projects
Commit b22edc65 authored by jkito's avatar jkito :skull:
Browse files

Revert "Remove unused code"

This reverts commit 883d208f.
parent 6490c6e4
No related branches found
No related tags found
1 merge request!193Revert "Remove unused code"
Pipeline #225723 passed
......@@ -23,3 +23,7 @@ func stopVPN() {
Msg("Could not stop VPN")
}
}
func getGateway() string {
return ctx.bm.GetCurrentGateway()
}
......@@ -29,6 +29,10 @@ import (
pmautostart "github.com/ProtonMail/go-autostart"
)
const (
errorMsg = `An error has ocurred initializing the VPN: %v`
)
// Autostart holds the functions to enable and disable the application autostart
type Autostart interface {
Disable() error
......
package helper
import (
"io/ioutil"
"net"
"os"
"path"
"strconv"
)
func getFirstAvailablePortFrom(port int) int {
for {
if isPortAvailable(port) {
return port
}
if port > 65535 {
return 0
}
port += 1
}
}
func isPortAvailable(port int) bool {
conn, err := net.Dial("tcp", "127.0.0.1:"+strconv.Itoa(port))
if err != nil {
return true
} else {
defer conn.Close()
return false
}
}
func writePortToFile(port int) error {
exeDir, err := getExecutableDir()
if err != nil {
return err
}
portFile := path.Join(exeDir, "port")
return ioutil.WriteFile(portFile, []byte(strconv.Itoa(port)+"\n"), 0644)
}
func getExecutableDir() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", err
}
return path.Dir(ex), nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment