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.

88 lines
1.9 KiB

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