1
0

bandwidthd-sqlite.init 3.2 KB

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