You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
591B

  1. package main
  2. import (
  3. "io"
  4. "os/exec"
  5. "strings"
  6. )
  7. func cmd(args ...string) string {
  8. if len(args) < 2 {
  9. return "Invalid # of args"
  10. }
  11. cmd := exec.Command(args[0], args[1])
  12. if len(args) == 3 {
  13. // wg pubkey
  14. stdin, _ := cmd.StdinPipe()
  15. go func() {
  16. defer stdin.Close()
  17. io.WriteString(stdin, args[2])
  18. }()
  19. }
  20. out, _ := cmd.Output()
  21. return strings.TrimSuffix(string(out), "\n")
  22. }
  23. func wg_genkey() string {
  24. return cmd("wg", "genkey")
  25. }
  26. func wg_genpsk() string {
  27. return cmd("wg", "genpsk")
  28. }
  29. func wg_pubkey(private string) string {
  30. return cmd("wg", "pubkey", private)
  31. }