#!/bin/sh

op=$1

case "$op" in
"init")
    #init auth_fail_count from uci
    echo "init auth_fail_count from uci" > /dev/console
    local count="$(uci get dropbear.msg.FailedAttempts)"
    local minute="$(uci get dropbear.msg.LockedTimestamp)"
    if [ -z "$count" ];then
        count=0
    fi
    if [ -z "$minute" ];then
        minute=0
    fi
    echo "$count $minute" > /etc/dropbear/auth_fail_count
    ;;

"save")
    #save auth_fail_count to uci
    echo "save auth_fail_count to uci" > /dev/console
    local count="$(cat /etc/dropbear/auth_fail_count | awk '{print $1}')"
    local minute="$(cat /etc/dropbear/auth_fail_count | awk '{print $2}')"
    if [ -z "$count" ];then
        count=0
    fi
    if [ -z "$minute" ];then
        minute=0
    fi
    uci set dropbear.msg.FailedAttempts="$count"
    uci set dropbear.msg.LockedTimestamp="$minute"
    uci commit dropbear
    saveconfig
    ;;

*)
    echo "auth covert error option" > /dev/console
    ;;
esac