windows.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package wireguard
  2. import (
  3. "fmt"
  4. "github.com/gravitl/netmaker/netclient/ncutils"
  5. )
  6. // ApplyWindowsConf - applies the WireGuard configuration file on Windows
  7. func ApplyWindowsConf(confPath string) error {
  8. /*
  9. pathStrings := strings.Split(confPath, ncutils.GetWGPathSpecific())
  10. if len(pathStrings) == 2 {
  11. copyConfPath := fmt.Sprintf("%s\\%s", ncutils.WINDOWS_WG_DPAPI_PATH, pathStrings[1])
  12. err := ncutils.Copy(confPath, copyConfPath)
  13. if err != nil {
  14. ncutils.PrintLog(err.Error(), 1)
  15. }
  16. }
  17. */
  18. var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
  19. if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
  20. return err
  21. }
  22. return nil
  23. }
  24. // RemoveWindowsConf - removes the WireGuard configuration file on Windows and dpapi file
  25. func RemoveWindowsConf(ifacename string, printlog bool) error {
  26. if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
  27. ncutils.PrintLog(err.Error(), 1)
  28. }
  29. /*
  30. dpapipath := fmt.Sprintf("%s\\%s.conf.dpapi", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
  31. confpath := fmt.Sprintf("%s\\%s.conf", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
  32. if ncutils.FileExists(confpath) {
  33. err := os.Remove(confpath)
  34. if err != nil {
  35. ncutils.PrintLog(err.Error(), 1)
  36. }
  37. }
  38. time.Sleep(time.Second >> 2)
  39. if ncutils.FileExists(dpapipath) {
  40. err := os.Remove(dpapipath)
  41. if err != nil {
  42. ncutils.PrintLog(err.Error(), 1)
  43. }
  44. }
  45. */
  46. return nil
  47. }