darkstat.init (2229B)
1 #!/bin/sh /etc/rc.common 2 # Copyright (C) 2007-2016 OpenWrt.org 3 4 START=60 5 APP=darkstat 6 RUN_D=/var/empty 7 PID_F=$RUN_D/darkstat.pid 8 9 SYSLOG="" 10 VERBOSE="" 11 NODAEMON="" 12 NOPROMISC="" 13 NODNS="" 14 NOMACS="" 15 NOLASTSEEN="" 16 LOCAL="" 17 paramstr="" 18 19 export_bool () { 20 local option="$1" 21 local section="$2" 22 local _keystr="$3" 23 local _loctmp 24 paramstr="" 25 config_get_bool _loctmp "$section" "$option" 26 if [ -n "$_loctmp" ]; then 27 if [ 1 -eq "$_loctmp" ]; then 28 paramstr="${_keystr} " 29 fi 30 fi 31 } 32 33 start() { 34 mkdir -p $RUN_D 35 . /lib/functions/network.sh 36 config_load darkstat 37 config_foreach start_darkstat darkstat 38 } 39 40 start_darkstat() { 41 local cfg="$1" 42 config_get interface $cfg interface 43 export_bool syslog $cfg "--syslog" 44 SYSLOG=$paramstr 45 export_bool verbose $cfg "--verbose" 46 VERBOSE=$paramstr 47 export_bool no_daemon $cfg "--no-daemon" 48 NODAEMON=$paramstr 49 export_bool no_promisc $cfg "--no-promisc" 50 NOPROMISC=$paramstr 51 export_bool no_dns $cfg "--no-dns" 52 NODNS=$paramstr 53 export_bool no_macs $cfg "--no-macs" 54 NOMACS=$paramstr 55 export_bool no_lastseen $cfg "--no-lastseen" 56 NOLASTSEEN=$paramstr 57 config_get httpaddr $cfg httpaddr 58 config_get httpport $cfg httpport 59 config_get network_filter $cfg network_filter 60 config_get network_netmask $cfg network_netmask 61 export_bool local_only $cfg "--local-only" 62 LOCAL=$paramstr 63 config_get hosts_max $cfg hosts_max 64 config_get hosts_keep $cfg hosts_keep 65 config_get ports_max $cfg ports_max 66 config_get ports_keep $cfg ports_keep 67 config_get highest_port $cfg highest_port 68 69 70 network_get_device ifname "$interface" && { 71 /usr/sbin/$APP -i "$ifname" \ 72 ${SYSLOG} \ 73 ${VERBOSE} \ 74 ${NODAEMON} \ 75 ${NOPROMISC} \ 76 ${NODNS} \ 77 ${NOMACS} \ 78 ${NOLASTSEEN} \ 79 ${httpaddr:+-b "$httpaddr"} \ 80 ${httpport:+-p "$httpport"} \ 81 ${network_filter:+-f "$network_filter"} \ 82 ${network_netmask:+-l "$network_netmask"} \ 83 ${LOCAL} \ 84 ${hosts_max:+--hosts-max "$hosts_max"} \ 85 ${hosts_keep:+--hosts-keep "$hosts_keep"} \ 86 ${ports_max:+--ports-max "$ports_max"} \ 87 ${ports_keep:+--ports-keep "$ports_keep"} \ 88 ${highest_port:+--highest-port "$highest_port"} \ 89 --chroot $RUN_D \ 90 --pidfile $PID_F 91 } 92 } 93 94 stop() { 95 start-stop-daemon -K -n $APP -p $PID_F -s TERM 96 rm -f $PID_F 97 }