netclientutils_freebsd.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package ncutils
  2. import (
  3. "context"
  4. "log"
  5. "os/exec"
  6. "strings"
  7. "syscall"
  8. "time"
  9. )
  10. // RunCmdFormatted - run a command formatted for freebsd
  11. func RunCmdFormatted(command string, printerr bool) (string, error) {
  12. return "", nil
  13. }
  14. // GetEmbedded - if files required for freebsd, put here
  15. func GetEmbedded() error {
  16. return nil
  17. }
  18. // Runs Commands for FreeBSD
  19. func RunCmd(command string, printerr bool) (string, error) {
  20. args := strings.Fields(command)
  21. ctx, cancel := context.WithTimeout(context.Background(), time.Second)
  22. defer cancel()
  23. cmd := exec.Command(args[0], args[1:]...)
  24. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  25. go func() {
  26. <-ctx.Done()
  27. _ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
  28. }()
  29. out, err := cmd.CombinedOutput()
  30. if err != nil && printerr {
  31. log.Println("error running command:", command)
  32. log.Println(strings.TrimSuffix(string(out), "\n"))
  33. }
  34. return string(out), err
  35. }
  36. // CreateWireGuardConf - creates a WireGuard conf string
  37. //func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) {
  38. // peersString, err := parsePeers(node.PersistentKeepalive, peers)
  39. // var listenPortString string
  40. // if node.MTU <= 0 {
  41. // node.MTU = 1280
  42. // }
  43. // if listenPort != "" {
  44. // listenPortString += "ListenPort = " + listenPort
  45. // }
  46. // if err != nil {
  47. // return "", err
  48. // }
  49. // config := fmt.Sprintf(`[Interface]
  50. //Address = %s
  51. //PrivateKey = %s
  52. //MTU = %s
  53. //%s
  54. //
  55. //%s
  56. //
  57. //`,
  58. // node.Address+"/32",
  59. // privatekey,
  60. // strconv.Itoa(int(node.MTU)),
  61. // listenPortString,
  62. // peersString)
  63. // return config, nil
  64. //}