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