netclientutils_linux.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package ncutils
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "strings"
  6. )
  7. // RunCmd - runs a local command
  8. func RunCmd(command string, printerr bool) (string, error) {
  9. args := strings.Fields(command)
  10. cmd := exec.Command(args[0], args[1:]...)
  11. cmd.Wait()
  12. out, err := cmd.CombinedOutput()
  13. if err != nil && printerr {
  14. Log(fmt.Sprintf("error running command: %s", command))
  15. Log(strings.TrimSuffix(string(out), "\n"))
  16. }
  17. return string(out), err
  18. }
  19. // RunCmdFormatted - does nothing for linux
  20. func RunCmdFormatted(command string, printerr bool) (string, error) {
  21. return "", nil
  22. }
  23. // GetEmbedded - if files required for linux, put here
  24. func GetEmbedded() error {
  25. return nil
  26. }
  27. // CreateWireGuardConf - creates a user space WireGuard conf
  28. //func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) {
  29. // peersString, err := parsePeers(node.PersistentKeepalive, peers)
  30. // var listenPortString, postDownString, postUpString string
  31. // if node.MTU <= 0 {
  32. // node.MTU = 1280
  33. // }
  34. // if node.PostDown != "" {
  35. // postDownString = fmt.Sprintf("PostDown = %s", node.PostDown)
  36. // }
  37. // if node.PostUp != "" {
  38. // postUpString = fmt.Sprintf("PostUp = %s", node.PostUp)
  39. // }
  40. //
  41. // if listenPort != "" {
  42. // listenPortString = fmt.Sprintf("ListenPort = %s", listenPort)
  43. // }
  44. //
  45. // if err != nil {
  46. // return "", err
  47. // }
  48. // config := fmt.Sprintf(`[Interface]
  49. //Address = %s
  50. //PrivateKey = %s
  51. //MTU = %s
  52. //%s
  53. //%s
  54. //%s
  55. //
  56. //%s
  57. //
  58. //`,
  59. // node.Address+"/32",
  60. // privatekey,
  61. // strconv.Itoa(int(node.MTU)),
  62. // postDownString,
  63. // postUpString,
  64. // listenPortString,
  65. // peersString)
  66. // return config, nil
  67. //}