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.

102 lines
2.0 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. STOP=50
  4. USE_PROCD=1
  5. NAME=ttyd
  6. PROG=/usr/bin/$NAME
  7. validate_section_ttyd()
  8. {
  9. uci_load_validate ttyd ttyd "$1" "$2" \
  10. 'enable:bool:1' \
  11. 'port:port' \
  12. 'interface:string' \
  13. 'credential:string' \
  14. 'uid:uinteger' \
  15. 'gid:uinteger' \
  16. 'signal:uinteger' \
  17. 'url_arg:bool' \
  18. 'readonly:bool' \
  19. 'client_option:list(string)' \
  20. 'terminal_type:string' \
  21. 'check_origin:bool' \
  22. 'max_clients:uinteger' \
  23. 'once:bool' \
  24. 'index:string' \
  25. 'ipv6:bool' \
  26. 'ssl:bool' \
  27. 'ssl_cert:file' \
  28. 'ssl_key:file' \
  29. 'ssl_ca:file' \
  30. 'debug:uinteger' \
  31. 'command:string'
  32. }
  33. ttyd_instance()
  34. {
  35. [ "$2" = 0 ] || {
  36. echo "validation failed"
  37. return 1
  38. }
  39. [ "$enable" = 0 ] && return 1
  40. [ -z "$command" ] && return 1
  41. [ "${interface::1}" = @ ] && {
  42. interface=$(
  43. . /lib/functions/network.sh
  44. network_get_device device "${interface:1}"
  45. echo -n "$device"
  46. )
  47. }
  48. [ "$url_arg" = 0 ] && url_arg=""
  49. [ "$readonly" = 0 ] && readonly=""
  50. [ "$check_origin" = 0 ] && check_origin=""
  51. [ "$once" = 0 ] && once=""
  52. [ "$ipv6" = 0 ] && ipv6=""
  53. [ "$ssl" = 0 ] && ssl=""
  54. procd_open_instance
  55. procd_set_param command "$PROG" \
  56. ${port:+-p $port} \
  57. ${interface:+-i $interface} \
  58. ${credential:+-c $credential} \
  59. ${uid:+-u $uid} \
  60. ${gid:+-g $gid} \
  61. ${signal:+-s $signal} \
  62. ${url_arg:+-a} \
  63. ${readonly:+-R} \
  64. ${terminal_type:+-T $terminal_type} \
  65. ${check_origin:+-O} \
  66. ${max_clients:+-m $max_clients} \
  67. ${once:+-o} \
  68. ${index:+-I $index} \
  69. ${ipv6:+-6} \
  70. ${ssl:+-S} \
  71. ${ssl_cert:+-C $ssl_cert} \
  72. ${ssl_key:+-K $ssl_key} \
  73. ${ssl_ca:+-A $ssl_ca} \
  74. ${debug:+-d $debug}
  75. config_list_foreach "$1" client_option "procd_append_param command -t"
  76. procd_append_param command $command
  77. procd_set_param stdout 1
  78. procd_set_param stderr 1
  79. procd_close_instance
  80. }
  81. start_service() {
  82. config_load "$NAME"
  83. config_foreach validate_section_ttyd ttyd ttyd_instance
  84. }
  85. shutdown() {
  86. # close all open connections
  87. killall "$NAME"
  88. }
  89. service_triggers() {
  90. procd_add_reload_trigger "$NAME"
  91. }