windows.go 886 B

123456789101112131415161718192021222324252627282930
  1. package wireguard
  2. import (
  3. "fmt"
  4. "github.com/gravitl/netmaker/logger"
  5. "github.com/gravitl/netmaker/netclient/ncutils"
  6. )
  7. // ApplyWindowsConf - applies the WireGuard configuration file on Windows
  8. func ApplyWindowsConf(confPath, iface string, isConnected bool) error {
  9. RemoveConfGraceful(iface) // have to remove gracefully before applying windows conf
  10. if !isConnected {
  11. return nil
  12. }
  13. var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
  14. if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
  15. return err
  16. }
  17. return nil
  18. }
  19. // RemoveWindowsConf - removes the WireGuard configuration file on Windows and dpapi file
  20. func RemoveWindowsConf(ifacename string, printlog bool) error {
  21. if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
  22. logger.Log(1, err.Error())
  23. }
  24. return nil
  25. }