|
@ -1,97 +1,100 @@ |
|
|
#!/bin/sh /etc/rc.common |
|
|
|
|
|
# Copyright (C) 2007-2016 OpenWrt.org |
|
|
|
|
|
|
|
|
#!/bin/sh /etc/rc.common |
|
|
|
|
|
# Copyright (C) 2018 Jean-Michel Lacroix |
|
|
|
|
|
|
|
|
|
|
|
USE_PROCD=1 |
|
|
|
|
|
|
|
|
START=60 |
|
|
START=60 |
|
|
|
|
|
|
|
|
APP=darkstat |
|
|
APP=darkstat |
|
|
RUN_D=/var/empty |
|
|
RUN_D=/var/empty |
|
|
PID_F=$RUN_D/darkstat.pid |
|
|
|
|
|
|
|
|
PID_F=$RUN_D/$APP.pid |
|
|
|
|
|
CONFIGNAME=darkstat |
|
|
|
|
|
USER=nobody |
|
|
|
|
|
GROUP=nogroup |
|
|
|
|
|
|
|
|
SYSLOG="" |
|
|
|
|
|
VERBOSE="" |
|
|
|
|
|
NODAEMON="" |
|
|
|
|
|
NOPROMISC="" |
|
|
|
|
|
NODNS="" |
|
|
|
|
|
NOMACS="" |
|
|
|
|
|
NOLASTSEEN="" |
|
|
|
|
|
LOCAL="" |
|
|
|
|
|
paramstr="" |
|
|
|
|
|
|
|
|
CONFIGSTR="" |
|
|
|
|
|
FILTERSTR="" |
|
|
|
|
|
|
|
|
export_bool () { |
|
|
export_bool () { |
|
|
local option="$1" |
|
|
local option="$1" |
|
|
local section="$2" |
|
|
local section="$2" |
|
|
local _keystr="$3" |
|
|
local _keystr="$3" |
|
|
local _loctmp |
|
|
local _loctmp |
|
|
paramstr="" |
|
|
|
|
|
config_get_bool _loctmp "$section" "$option" |
|
|
config_get_bool _loctmp "$section" "$option" |
|
|
if [ -n "$_loctmp" ]; then |
|
|
if [ -n "$_loctmp" ]; then |
|
|
if [ 1 -eq "$_loctmp" ]; then |
|
|
if [ 1 -eq "$_loctmp" ]; then |
|
|
paramstr="${_keystr} " |
|
|
|
|
|
|
|
|
CONFIGSTRING="$CONFIGSTRING${_keystr} " |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start() { |
|
|
|
|
|
|
|
|
set_config_string(){ |
|
|
mkdir -p $RUN_D |
|
|
mkdir -p $RUN_D |
|
|
|
|
|
chown $USER:$GROUP $RUN_D |
|
|
. /lib/functions/network.sh |
|
|
. /lib/functions/network.sh |
|
|
config_load darkstat |
|
|
|
|
|
config_foreach start_darkstat darkstat |
|
|
|
|
|
|
|
|
config_load $CONFIGNAME |
|
|
|
|
|
config_foreach build_config_string darkstat |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start_darkstat() { |
|
|
|
|
|
local cfg="$1" |
|
|
|
|
|
|
|
|
build_config_string() { |
|
|
|
|
|
local cfg="$1" |
|
|
config_get interface $cfg interface |
|
|
config_get interface $cfg interface |
|
|
|
|
|
network_get_device ifname "$interface" |
|
|
|
|
|
CONFIGSTR=" -i $ifname " |
|
|
export_bool syslog $cfg "--syslog" |
|
|
export_bool syslog $cfg "--syslog" |
|
|
SYSLOG=$paramstr |
|
|
|
|
|
export_bool verbose $cfg "--verbose" |
|
|
export_bool verbose $cfg "--verbose" |
|
|
VERBOSE=$paramstr |
|
|
|
|
|
export_bool no_daemon $cfg "--no-daemon" |
|
|
|
|
|
NODAEMON=$paramstr |
|
|
|
|
|
|
|
|
# We need the --no-daemon parameter as with PROCD the process has to run in the background |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR--no-daemon " |
|
|
export_bool no_promisc $cfg "--no-promisc" |
|
|
export_bool no_promisc $cfg "--no-promisc" |
|
|
NOPROMISC=$paramstr |
|
|
|
|
|
export_bool no_dns $cfg "--no-dns" |
|
|
export_bool no_dns $cfg "--no-dns" |
|
|
NODNS=$paramstr |
|
|
|
|
|
export_bool no_macs $cfg "--no-macs" |
|
|
export_bool no_macs $cfg "--no-macs" |
|
|
NOMACS=$paramstr |
|
|
|
|
|
export_bool no_lastseen $cfg "--no-lastseen" |
|
|
export_bool no_lastseen $cfg "--no-lastseen" |
|
|
NOLASTSEEN=$paramstr |
|
|
|
|
|
config_get httpaddr $cfg httpaddr |
|
|
config_get httpaddr $cfg httpaddr |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${httpaddr:+-b "$httpaddr"} " |
|
|
config_get httpport $cfg httpport |
|
|
config_get httpport $cfg httpport |
|
|
config_get network_filter $cfg network_filter |
|
|
|
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${httpport:+-p "$httpport"} " |
|
|
config_get network_netmask $cfg network_netmask |
|
|
config_get network_netmask $cfg network_netmask |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${network_netmask:+-l "$network_netmask"} " |
|
|
export_bool local_only $cfg "--local-only" |
|
|
export_bool local_only $cfg "--local-only" |
|
|
LOCAL=$paramstr |
|
|
|
|
|
config_get hosts_max $cfg hosts_max |
|
|
config_get hosts_max $cfg hosts_max |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${hosts_max:+--hosts-max "$hosts_max"} " |
|
|
config_get hosts_keep $cfg hosts_keep |
|
|
config_get hosts_keep $cfg hosts_keep |
|
|
config_get ports_max $cfg ports_max |
|
|
|
|
|
config_get ports_keep $cfg ports_keep |
|
|
|
|
|
config_get highest_port $cfg highest_port |
|
|
|
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${ports_keep:+--ports-keep "$ports_keep"} " |
|
|
|
|
|
config_get highest_port $cfg highest_port |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${highest_port:+--highest-port "$highest_port"} " |
|
|
|
|
|
config_get export_file $cfg export_file |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${export_file:+--export "$export_file"} " |
|
|
|
|
|
config_get import_file $cfg import_file |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${import_file:+--import "$import_file"} " |
|
|
|
|
|
config_get daylog_file $cfg daylog_file |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR${daylog_file:+--daylog "$daylog_file"} " |
|
|
|
|
|
CONFIGSTR="$CONFIGSTR--chroot $RUN_D --pidfile $PID_F" |
|
|
|
|
|
# Now that we have the configuration string (CONFIGSTR), let us get the filter (FILTERSTR) |
|
|
|
|
|
config_get network_filter $cfg network_filter |
|
|
|
|
|
FILTERSTR="${network_filter:+$network_filter}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
service_triggers() { |
|
|
|
|
|
procd_add_reload_trigger $CONFIGNAME |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
network_get_device ifname "$interface" && { |
|
|
|
|
|
/usr/sbin/$APP -i "$ifname" \ |
|
|
|
|
|
${SYSLOG} \ |
|
|
|
|
|
${VERBOSE} \ |
|
|
|
|
|
${NODAEMON} \ |
|
|
|
|
|
${NOPROMISC} \ |
|
|
|
|
|
${NODNS} \ |
|
|
|
|
|
${NOMACS} \ |
|
|
|
|
|
${NOLASTSEEN} \ |
|
|
|
|
|
${httpaddr:+-b "$httpaddr"} \ |
|
|
|
|
|
${httpport:+-p "$httpport"} \ |
|
|
|
|
|
${network_filter:+-f "$network_filter"} \ |
|
|
|
|
|
${network_netmask:+-l "$network_netmask"} \ |
|
|
|
|
|
${LOCAL} \ |
|
|
|
|
|
${hosts_max:+--hosts-max "$hosts_max"} \ |
|
|
|
|
|
${hosts_keep:+--hosts-keep "$hosts_keep"} \ |
|
|
|
|
|
${ports_max:+--ports-max "$ports_max"} \ |
|
|
|
|
|
${ports_keep:+--ports-keep "$ports_keep"} \ |
|
|
|
|
|
${highest_port:+--highest-port "$highest_port"} \ |
|
|
|
|
|
--chroot $RUN_D \ |
|
|
|
|
|
--pidfile $PID_F |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
start_service() { |
|
|
|
|
|
set_config_string |
|
|
|
|
|
procd_open_instance |
|
|
|
|
|
procd_set_param command /usr/sbin/$APP |
|
|
|
|
|
procd_append_param command $CONFIGSTR |
|
|
|
|
|
# Let us check if we have a filter string and apply it if we do |
|
|
|
|
|
if [ "$FILTERSTR" != "" ]; then |
|
|
|
|
|
procd_append_param command "-f" "$FILTERSTR" |
|
|
|
|
|
fi |
|
|
|
|
|
procd_close_instance |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stop() { |
|
|
|
|
|
start-stop-daemon -K -n $APP -p $PID_F -s TERM |
|
|
|
|
|
|
|
|
stop_service() { |
|
|
rm -f $PID_F |
|
|
rm -f $PID_F |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reload_service() { |
|
|
|
|
|
stop |
|
|
|
|
|
start |
|
|
|
|
|
} |