cleanup echo

able to list clients via dns lease file

del bridge-nf-call-iptables
This commit is contained in:
garywill 2018-08-31 18:41:06 +08:00 committed by garywill
parent 7f03b321f0
commit 9cc0f40aa4
1 changed files with 29 additions and 17 deletions

View File

@ -958,6 +958,7 @@ _cleanup() {
# if we are the last lnxrouter instance then set back the common values # if we are the last lnxrouter instance then set back the common values
if ! has_running_instance; then if ! has_running_instance; then
echo "Exiting: This is the only running instance"
# kill common processes # kill common processes
for x in $COMMON_CONFDIR/*.pid; do for x in $COMMON_CONFDIR/*.pid; do
[[ -f $x ]] && kill -9 $(cat $x) [[ -f $x ]] && kill -9 $(cat $x)
@ -965,19 +966,15 @@ _cleanup() {
# set old ip_forward # set old ip_forward
if [[ -f $COMMON_CONFDIR/ip_forward ]]; then if [[ -f $COMMON_CONFDIR/ip_forward ]]; then
echo Set to old value: /proc/sys/net/ipv4/ip_forward=$(cat $COMMON_CONFDIR/ip_forward)
cp -f $COMMON_CONFDIR/ip_forward /proc/sys/net/ipv4 cp -f $COMMON_CONFDIR/ip_forward /proc/sys/net/ipv4
rm -f $COMMON_CONFDIR/ip_forward rm -f $COMMON_CONFDIR/ip_forward
fi fi
# set old bridge-nf-call-iptables
if [[ -f $COMMON_CONFDIR/bridge-nf-call-iptables ]]; then
if [[ -e /proc/sys/net/bridge/bridge-nf-call-iptables ]]; then
cp -f $COMMON_CONFDIR/bridge-nf-call-iptables /proc/sys/net/bridge
fi
rm -f $COMMON_CONFDIR/bridge-nf-call-iptables
fi
rm -rf $COMMON_CONFDIR rm -rf $COMMON_CONFDIR
else
echo "Exiting: This is NOT the only running instance"
fi fi
ip link set down dev ${AP_IFACE} ip link set down dev ${AP_IFACE}
@ -1024,7 +1021,7 @@ cleanup() {
echo echo
echo -n "Doing cleanup.. " echo -n "Doing cleanup.. "
clean_iptables clean_iptables
_cleanup > /dev/null 2>&1 _cleanup 2> /dev/null
echo "done" echo "done"
} }
@ -1091,7 +1088,7 @@ get_confdir_from_pid() {
mutex_unlock mutex_unlock
} }
print_client() { print_client_by_mac() {
local line ipaddr hostname local line ipaddr hostname
local mac="$1" local mac="$1"
@ -1107,6 +1104,23 @@ print_client() {
printf "%-20s %-18s %s\n" "$mac" "$ipaddr" "$hostname" printf "%-20s %-18s %s\n" "$mac" "$ipaddr" "$hostname"
} }
print_clients_in_leases() {
local line ipaddr hostname
local mac
if [[ -f $CONFDIR/dnsmasq.leases ]]; then
while read line
do
mac=$(echo $line | cut -d' ' -f2)
ipaddr=$(echo $line | cut -d' ' -f3)
hostname=$(echo $line | cut -d' ' -f4)
printf "%-20s %-18s %s\n" "MAC" "IP" "Hostname"
printf "%-20s %-18s %s\n" "$mac" "$ipaddr" "$hostname"
done < $CONFDIR/dnsmasq.leases
fi
}
list_clients() { list_clients() {
local subn_iface pid local subn_iface pid
@ -1118,7 +1132,6 @@ list_clients() {
fi fi
[[ -z "$subn_iface" ]] && subn_iface="$1" [[ -z "$subn_iface" ]] && subn_iface="$1"
is_wifi_interface "$subn_iface" || die "'$subn_iface' is not a WiFi interface."
[[ -z "$pid" ]] && pid=$(get_pid_from_subn_iface "$subn_iface") [[ -z "$pid" ]] && pid=$(get_pid_from_subn_iface "$subn_iface")
[[ -z "$pid" ]] && die "'$subn_iface' is not used from $PROGNAME instance.\n\ [[ -z "$pid" ]] && die "'$subn_iface' is not used from $PROGNAME instance.\n\
@ -1126,7 +1139,7 @@ list_clients() {
Use --list-running to find it out." Use --list-running to find it out."
[[ -z "$CONFDIR" ]] && CONFDIR=$(get_confdir_from_pid "$pid") [[ -z "$CONFDIR" ]] && CONFDIR=$(get_confdir_from_pid "$pid")
if [[ $USE_IWCONFIG -eq 0 ]]; then if [[ -f $CONFDIR/hostapd.conf && $USE_IWCONFIG -eq 0 ]]; then
local awk_cmd='($1 ~ /Station$/) {print $2}' local awk_cmd='($1 ~ /Station$/) {print $2}'
local client_list=$(iw dev "$subn_iface" station dump | awk "$awk_cmd") local client_list=$(iw dev "$subn_iface" station dump | awk "$awk_cmd")
@ -1139,11 +1152,12 @@ list_clients() {
local mac local mac
for mac in $client_list; do for mac in $client_list; do
print_client $mac print_client_by_mac $mac
done done
else else
die "This option is not supported for the current driver." echo "Listing clients via DNS lease file. non-DHCPed clients won't be showed"
fi print_clients_in_leases
fi
} }
has_running_instance() { has_running_instance() {
@ -1364,9 +1378,7 @@ COMMON_CONFDIR=/tmp/lnxrouter.common.conf
mkdir -p $COMMON_CONFDIR mkdir -p $COMMON_CONFDIR
cp -n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR cp -n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR
if [[ -e /proc/sys/net/bridge/bridge-nf-call-iptables ]]; then
cp -n /proc/sys/net/bridge/bridge-nf-call-iptables $COMMON_CONFDIR
fi
mutex_unlock mutex_unlock