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.

80 lines
1.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2014 OpenWrt.org
  3. START=60
  4. USE_PROCD=1
  5. PROG=/usr/sbin/mactelnetd
  6. USERS=/var/etc/mactelnetd.users
  7. SSHMODE=0
  8. add_account() {
  9. local cfg="$1"
  10. local user pass
  11. [ $SSHMODE -eq 0 ] || {
  12. [ -n "$already_warned" ] || {
  13. echo "mactelnet.$cfg: login sections ignored in SSH mode" >&1
  14. already_warned=1
  15. }
  16. return
  17. }
  18. config_get username "$cfg" username
  19. config_get password "$cfg" password
  20. [ -n "$username" ] || {
  21. echo "mactelnet.$cfg: username missing" >&2
  22. return
  23. }
  24. [ -n "$password" ] || {
  25. echo "mactelnet.$cfg: password missing" >&2
  26. return
  27. }
  28. echo "$username:$password" >> $USERS
  29. }
  30. add_interface() {
  31. local iface="$1"
  32. local device
  33. [ -n "$iface" ] || return
  34. if network_get_physdev device "$iface"; then
  35. procd_append_param command -i "$device"
  36. fi
  37. procd_add_reload_interface_trigger "$iface"
  38. }
  39. add_globals() {
  40. local cfg="$1"
  41. config_get_bool SSHMODE "$cfg" sshmode 0
  42. [ $SSHMODE -eq 0 ] || procd_append_param command -S
  43. config_list_foreach "$cfg" interface add_interface
  44. }
  45. start_service() {
  46. . /lib/functions/network.sh
  47. procd_open_instance
  48. procd_add_reload_trigger mactelnet
  49. procd_set_param command "$PROG" -f
  50. config_load mactelnet
  51. config_foreach add_globals mactelnetd
  52. [ $SSHMODE -eq 1 ] || {
  53. rm -f $USERS
  54. config_foreach add_account login
  55. }
  56. procd_close_instance
  57. }