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.

96 lines
2.1 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=50
  3. BIN=tcpproxy
  4. DAEMON=/usr/bin/$BIN
  5. DAEMON_ARGS=""
  6. DESC=$BIN
  7. RUN_D=/var/run
  8. CONFIG_DIR=/var/etc
  9. CONFIG_FILE=$CONFIG_DIR/$BIN.conf
  10. tcpproxy_write_config() {
  11. local cfg="$1"
  12. config_get_bool value "$cfg" disabled 0
  13. [ "$value" -ne 0 ] && return
  14. local local_addr=""
  15. local resolv=""
  16. local local_port=""
  17. local remote_addr=""
  18. local remote_resolv=""
  19. local remote_port=""
  20. local source_addr=""
  21. config_get local_addr "$cfg" local_addr
  22. config_get local_port "$cfg" local_port
  23. config_get resolv "$cfg" resolv
  24. config_get remote_addr "$cfg" remote_addr
  25. config_get remote_port "$cfg" remote_port
  26. config_get remote_resolv "$cfg" remote_resolv
  27. config_get source_addr "$cfg" source_addr
  28. if [ -z "$local_addr" ]; then
  29. local_addr="*"
  30. fi
  31. echo "listen $local_addr $local_port" >> $CONFIG_FILE
  32. echo "{" >> $CONFIG_FILE
  33. if [ -n "$resolv" ]; then
  34. echo " resolv: $resolv;" >> $CONFIG_FILE
  35. fi
  36. echo " remote: $remote_addr $remote_port;" >> $CONFIG_FILE
  37. if [ -n "$remote_resolv" ]; then
  38. echo " remote-resolv: $remote_resolv;" >> $CONFIG_FILE
  39. fi
  40. if [ -n "$source_addr" ]; then
  41. echo " source: $source_addr;" >> $CONFIG_FILE
  42. fi
  43. echo "};" >> $CONFIG_FILE
  44. echo "" >> $CONFIG_FILE
  45. }
  46. tcpproxy_generate_args() {
  47. local cfg="$1"
  48. local option
  49. local value
  50. for option in username groupname chroot log
  51. do
  52. config_get value "$cfg" "$option"
  53. option=`echo $option | tr '_' '-'`
  54. if [ -n "$value" ]; then
  55. DAEMON_ARGS="$DAEMON_ARGS --$option $value"
  56. fi
  57. done
  58. }
  59. tcpproxy_rebuild_config() {
  60. mkdir -p $CONFIG_DIR
  61. rm -f $CONFIG_FILE
  62. touch $CONFIG_FILE
  63. config_load $BIN
  64. config_foreach tcpproxy_write_config listen
  65. }
  66. start() {
  67. echo -n "Starting $DESC "
  68. tcpproxy_rebuild_config
  69. config_foreach tcpproxy_generate_args $BIN
  70. $DAEMON $DAEMON_ARGS --config $CONFIG_FILE --write-pid "$RUN_D/$BIN.pid"
  71. echo "."
  72. }
  73. reload() {
  74. echo -n "Reloading $DESC "
  75. tcpproxy_rebuild_config
  76. kill -SIGHUP `cat "$RUN_D/$BIN.pid"`
  77. echo "."
  78. }
  79. stop() {
  80. echo -n "Stopping $DESC "
  81. kill `cat $RUN_D/$BIN.pid` > /dev/null 2>&1
  82. echo "."
  83. }