#!/bin/sh

[ -z "$ROOT" ] && ROOT=/www
CONFIG=$ROOT/config
SCRIPT=$ROOT/script

getHotspotInstanceList() {
  local list=""
  for instance in `seq 1 "$NO_SSID"` ; do
    eval local enabled="\$SSID${instance}_ENABLED"
    eval local hotspotEnabled="\$SSID${instance}_HOTSPOT"
    [ "$enabled" == 1 -a "$hotspotEnabled" == 1 ] && list="$list $instance";
  done

  echo $list
}

isHotspotEnabledOnSsid() {
  local instance="$1"

  eval local enabled="\$SSID${instance}_ENABLED"
  eval local hotspotEnabled="\$SSID${instance}_HOTSPOT"
  [ "$enabled" == 1 -a "$hotspotEnabled" == 1 ] && echo 1
}

isIpInIpSet() {
  ipset test -! authenticated$1 $2
}

addIpToIpset() {
  ipset add -! authenticated$1 $2 timeout 3600
  # ipset add -! keepcna $2
}

removeIpFromIpset() {
  ipset del -! authenticated$1 $2
}

clearIpset() {
  ipset flush -! authenticated$1
}

resetTimeoutOfIpInIpset() {
  ipset add -! authenticated$1 $2 timeout $3
}
