windows.go 1.5 KB

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