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.

75 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2016 OpenWrt.org
  3. START=99
  4. USE_PROCD=1
  5. CONFIGNAME="bandwidthd-php"
  6. CONFIGFILE="/var/etc/bandwidthd-php.conf"
  7. config_cb() {
  8. local cfg_type="$1"
  9. local cfg_name="$2"
  10. case "$cfg_type" in
  11. $CONFIGNAME)
  12. append cfgs "$cfg_name"
  13. ;;
  14. esac
  15. }
  16. export_number() {
  17. local option="$1"
  18. local section="$2"
  19. local _loctmp
  20. paramstr=""
  21. config_get _loctmp "$section" "$option"
  22. if [ -n "$_loctmp" ]; then
  23. paramstr="${_loctmp}"
  24. fi
  25. }
  26. export_string() {
  27. local option="$1"
  28. local section="$2"
  29. local _loctmp
  30. paramstr=""
  31. config_get _loctmp "$section" "$option"
  32. if [ -n "$_loctmp" ]; then
  33. paramstr="${_loctmp}"
  34. fi
  35. }
  36. service_triggers()
  37. {
  38. procd_add_reload_trigger $CONFIGNAME
  39. }
  40. start_service() {
  41. local conffile="<?php\n// auto-generated config file from /etc/config/${CONFIGNAME}\n"
  42. rm -f $CONFIGFILE
  43. touch $CONFIGFILE
  44. config_load $CONFIGNAME
  45. for cfg in $cfgs; do
  46. export_number dflt_width $cfg
  47. conffile="${conffile}define(\"DFLT_WIDTH\", ${paramstr:-"900"});\n"
  48. export_number dflt_height $cfg
  49. conffile="${conffile}define(\"DFLT_HEIGHT\", ${paramstr:-"256"});\n"
  50. export_string dflt_interval $cfg
  51. conffile="${conffile}define(\"DFLT_INTERVAL\", ${paramstr:-"INT_DAILY"});\n\n"'$db_connect_string = "host='
  52. export_string host $cfg
  53. conffile="${conffile}${paramstr:-"127.0.0.1"} user="
  54. export_string user $cfg
  55. conffile="${conffile}${paramstr:-"postgres"} dbname="
  56. export_string dbname $cfg
  57. conffile="${conffile}${paramstr:-"bandwidthd"}"'"'"\n?>"
  58. [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGFILE
  59. done
  60. }