windows.go 793 B

12345678910111213141516171819202122232425262728
  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 string, isConnected bool) error {
  9. if !isConnected {
  10. return nil
  11. }
  12. var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
  13. if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
  14. return err
  15. }
  16. return nil
  17. }
  18. // RemoveWindowsConf - removes the WireGuard configuration file on Windows and dpapi file
  19. func RemoveWindowsConf(ifacename string, printlog bool) error {
  20. if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
  21. logger.Log(1, err.Error())
  22. }
  23. return nil
  24. }