#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] || {
  /etc/init.d/netflow stop 2>/dev/null
  /etc/init.d/netflow disable 2>/dev/null

  iptables -t nat -D PREROUTING -j NETFLOW 2>/dev/null
  iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 7874 2>/dev/null
  iptables -t nat -D PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 7874 2>/dev/null
  iptables -t nat -F NETFLOW 2>/dev/null
  iptables -t nat -X NETFLOW 2>/dev/null
  iptables -t nat -D OUTPUT -p tcp -j NETFLOW_OUT 2>/dev/null
  iptables -t nat -F NETFLOW_OUT 2>/dev/null
  iptables -t nat -X NETFLOW_OUT 2>/dev/null

  iptables -t nat -F netflow_v2board 2>/dev/null
  iptables -t nat -D PREROUTING -j netflow_v2board 2>/dev/null
  iptables -t nat -X netflow_v2board 2>/dev/null
  iptables -t nat -F NETFLOW_DNS 2>/dev/null
  iptables -t nat -D PREROUTING -j NETFLOW_DNS 2>/dev/null
  iptables -t nat -X NETFLOW_DNS 2>/dev/null

  nft delete table ip netflow 2>/dev/null

  killall mihomo 2>/dev/null

  rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
  rm -rf /tmp/netflow_*
  rm -f /etc/netflow/mihomo/config.yaml
  rm -f /etc/netflow/mihomo/cache.db
  rm -rf /etc/netflow/mihomo/cache
}
exit 0
