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.

106 lines
2.2 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2017 OpenWrt.org
  3. START=99
  4. USE_PROCD=1
  5. CONFIGNAME="bandwidthd"
  6. CONFIGFILE="/tmp/etc/bandwidthd.conf"
  7. config_cb() {
  8. local cfg_type="$1"
  9. local cfg_name="$2"
  10. case "$cfg_type" in
  11. bandwidthd)
  12. append cfgs "$cfg_name"
  13. ;;
  14. esac
  15. }
  16. export_bool() {
  17. local option="$1"
  18. local section="$2"
  19. local _loctmp
  20. config_get_bool _loctmp "$section" "$option"
  21. if [ -n "$_loctmp" ]; then
  22. conffile="${conffile}$option "
  23. if [ 1 -eq "$_loctmp" ]; then
  24. conffile="${conffile}true"
  25. else
  26. conffile="${conffile}false"
  27. fi
  28. conffile="${conffile}\n"
  29. fi
  30. }
  31. export_number() {
  32. local option="$1"
  33. local section="$2"
  34. local _loctmp
  35. config_get _loctmp "$section" "$option"
  36. if [ -n "$_loctmp" ]; then
  37. conffile="${conffile}$option ${_loctmp}\n"
  38. fi
  39. }
  40. export_string() {
  41. local option="$1"
  42. local section="$2"
  43. local _loctmp
  44. config_get _loctmp "$section" "$option"
  45. if [ -n "$_loctmp" ]; then
  46. conffile="${conffile}$option \"${_loctmp}\"\n"
  47. fi
  48. }
  49. set_conf_file() {
  50. local subnet conffile
  51. [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /www/logo.gif /tmp/bandwidthd/
  52. [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs
  53. [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd
  54. rm -f $CONFIGFILE
  55. touch $CONFIGFILE
  56. [ -e /etc/bandwidthd.conf ] || ln -s $CONFIGFILE /etc/bandwidthd.conf
  57. config_load $CONFIGNAME
  58. for cfg in $cfgs; do
  59. config_get subnets $cfg subnets
  60. for subnet in $subnets; do
  61. conffile="${conffile}subnet ${subnet}\n"
  62. done
  63. export_string dev $cfg
  64. export_number skip_intervals $cfg
  65. export_number graph_cutoff $cfg
  66. export_bool promiscuous $cfg
  67. export_bool output_cdf $cfg
  68. export_bool recover_cdf $cfg
  69. export_string filter $cfg
  70. export_bool graph $cfg
  71. export_number meta_refresh $cfg
  72. export_string pgsql_connect_string $cfg
  73. export_string sqlite_filename $cfg
  74. export_string sensor_id $cfg
  75. [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGFILE
  76. unset conffile
  77. done
  78. cd /
  79. }
  80. service_triggers()
  81. {
  82. procd_add_reload_trigger $CONFIGNAME
  83. }
  84. start_service() {
  85. set_conf_file
  86. procd_open_instance
  87. procd_set_param command /usr/sbin/bandwidthd
  88. procd_close_instance
  89. }
  90. stop_service() {
  91. service_stop /usr/sbin/bandwidthd
  92. }