#!/bin/sh /etc/rc.common

USE_PROCD=1
START=95

BIN=/usr/bin/wifidog-ng

parse_whitelist_mac() {
    local cfg="$1"
    local mac

    uci_validate_section wifidog-ng whitelist "${1}" \
        'mac:macaddr'

    [ $? -ne 0 ] && {
        echo "validation whitelist_mac failed" >&2
        exit 1
    }
}

parse_whitelist_domain() {
    local cfg="$1"
    local domain

    uci_validate_section wifidog-ng whitelist "${1}" \
        'domain:host'

    [ $? -ne 0 ] && {
        echo "validation whitelist_domain failed" >&2
        exit 1
    }
}

start_service() {
    modprobe wifidog-ng

    config_load wifidog-ng
    config_foreach parse_whitelist_mac whitelist_mac
    config_foreach parse_whitelist_domain whitelist_domain

    procd_open_instance
    procd_set_param command $BIN
    procd_set_param respawn
    procd_close_instance
}

stop_service() {
    rmmod wifidog-ng
}
