#!/bin/sh

. /lib/functions.sh

chilli_fix_users() {
        local section="$1"
        config_get password "$section" password

        hashed_check=$(echo "$password" | grep -E '\$1\$.{8}\$')
        [ -n $hashed_check ] && return

        hashed_check=$(echo "$password" | grep -E '\$6\$.{16}\$')
        [ -n $hashed_check ] && return

        password=$(mkpasswd -m md5 "$password")
        uci_set chilli "$section" password "$password"
}

config_load chilli
config_foreach chilli_fix_users user

uci_commit chilli
