netmaker/netclient/wireguard/windows.go

53 lines
1.5 KiB
Go
Raw Normal View History

2021-09-20 02:03:47 +08:00
package wireguard
2021-11-18 10:57:27 +08:00
import (
"fmt"
"github.com/gravitl/netmaker/logger"
2021-11-18 10:57:27 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
)
2021-09-20 02:03:47 +08:00
2021-12-12 23:16:53 +08:00
// ApplyWindowsConf - applies the WireGuard configuration file on Windows
2021-09-20 02:03:47 +08:00
func ApplyWindowsConf(confPath string) error {
2022-02-16 09:51:00 +08:00
/*
pathStrings := strings.Split(confPath, ncutils.GetWGPathSpecific())
if len(pathStrings) == 2 {
copyConfPath := fmt.Sprintf("%s\\%s", ncutils.WINDOWS_WG_DPAPI_PATH, pathStrings[1])
err := ncutils.Copy(confPath, copyConfPath)
if err != nil {
logger.Log(err.Error(), 1)
2022-02-16 09:51:00 +08:00
}
2021-12-12 23:16:53 +08:00
}
2022-02-16 09:51:00 +08:00
*/
2021-11-18 10:57:27 +08:00
var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
2021-09-20 02:03:47 +08:00
return err
}
return nil
}
2021-12-12 23:16:53 +08:00
// RemoveWindowsConf - removes the WireGuard configuration file on Windows and dpapi file
2021-09-20 02:03:47 +08:00
func RemoveWindowsConf(ifacename string, printlog bool) error {
if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
logger.Log(1, err.Error())
2021-12-12 23:16:53 +08:00
}
2022-02-16 09:51:00 +08:00
/*
dpapipath := fmt.Sprintf("%s\\%s.conf.dpapi", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
confpath := fmt.Sprintf("%s\\%s.conf", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
if ncutils.FileExists(confpath) {
err := os.Remove(confpath)
if err != nil {
logger.Log(err.Error(), 1)
2022-02-16 09:51:00 +08:00
}
2021-12-12 23:16:53 +08:00
}
2022-02-16 09:51:00 +08:00
time.Sleep(time.Second >> 2)
if ncutils.FileExists(dpapipath) {
err := os.Remove(dpapipath)
if err != nil {
logger.Log(err.Error(), 1)
2022-02-16 09:51:00 +08:00
}
2021-12-12 23:16:53 +08:00
}
2022-02-16 09:51:00 +08:00
*/
2021-09-20 02:03:47 +08:00
return nil
}