Unlocking Locked Users Due to Excessive BK Password Retries

  • Scope: BK users who have entered their login password too many times and have been locked out, need to be unlocked.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash

set -e

MYSQL_COMMAND=${MYSQL_COMMAND:-/usr/bin/mysql --login-path=mysql-default}

usage_and_exit () {
cat <<EOF
用法:
$PROGRAM [--find-user|--unlock-id]
EOF
exit 1
}

find_user_id () {
local user_name=$1
$MYSQL_COMMAND \
-NBe "select id from bk_user.profiles_profile where username = "\'"${user_name}"\'";"
}

find_audit_log_id () {
local user_id=$1
$MYSQL_COMMAND \
-NBe "select id from bk_user.audit_login where profile_id=$user_id order by id desc limit 1;"
}

unlock_user () {
local user_id=$1
local audit_log_id=$2
$MYSQL_COMMAND \
-NBe "update bk_user.audit_login set is_success = 1 where profile_id=$user_id and id=$audit_log_id;"
}

# 解析命令行参数,长短混合模式
(( $# == 0 )) && usage_and_exit 1
while (( $# > 0 )); do
case "$1" in
--find-user )
shift
USER_NAME=$1
;;
--unlock-id )
shift
USER_ID=$1
;;
-*)
error "不可识别的参数: $1"
;;
*)
break
;;
esac
shift
done

if [ "$USER_NAME" != '' ]; then
USER_ID=$(find_user_id "$USER_NAME")
fi

if [ "USER_ID" == '' ]; then
usage_and_exit
fi

unlock_user "${USER_ID}" "$(find_audit_log_id $USER_ID)"

Unlocking Locked Users Due to Excessive BK Password Retries

https://1.not.icu/Unlocking-Locked-Users-Due-to-Excessive-BK-Password-Retries/

作者

Sony Dog

发布于

2023-12-26

更新于

2023-12-26

许可协议

CC BY-NC-SA 4.0