diff options
-rwxr-xr-x | computer-time-limit | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/computer-time-limit b/computer-time-limit index 7732728..84e2eb9 100755 --- a/computer-time-limit +++ b/computer-time-limit @@ -28,19 +28,19 @@ sende_msg() { --data "msg=${data}" \ --data "sig=$( echo "${data}" \ - | signify -S -s "$2" -m /dev/stdin -x /dev/stdout \ + | signify -S -s "${key}" -m /dev/stdin -x /dev/stdout \ | base64 -w0 )" \ 'https://eckner.net/computer-time-limit.php' } wie_lange_noch() { - if [ ! -f "$1" ]; then + if [ ! -f "${key}" ]; then noch=0 ab=$(date +%s) return fi - home=$(getent passwd "$1" | cut -d: -f6) + home=$(getent passwd "${user}" | cut -d: -f6) if [ -d "${home}" ]; then cd "${home}" if [ -f '.shared_secret' ] \ @@ -54,7 +54,7 @@ wie_lange_noch() { cd - fi erg=$( - sende_msg start "$2" + sende_msg start ) if [ -n "${erg}" ] && ! echo "${erg}" | grep -qvx '[0-9]\+'; then noch="${erg}" @@ -67,8 +67,8 @@ wie_lange_noch() { check_time() { if [ "${noch}" -le 0 ]; then - sende_msg stop "$2" >/dev/null - loginctl terminate-user "$1" + sende_msg stop >/dev/null + loginctl terminate-user "${user}" ( sleep 1m if is_logged_in "${user}"; then @@ -109,18 +109,19 @@ check_time() { } is_logged_in() { - if users | grep -qwF "$1"; then + if users | grep -qwF "${user}"; then return 0 fi - if loginctl list-users -l | sed -n '2,/^$/p' | awk '{print $2}' | grep -qxF "$1"; then + if loginctl list-users -l | sed -n '2,/^$/p' | awk '{print $2}' | grep -qxF "${user}"; then return 0 fi return 1 } stop_all() { - for key_file in "${keys[@]}"; do - sende_msg stop "${key_file}" >/dev/null + for user in "${!keys[@]}"; do + key="${keys["${user}"]}" + sende_msg stop >/dev/null done } @@ -131,11 +132,11 @@ ab=$(date +%s) while true; do for user in "${!keys[@]}"; do key="${keys["${user}"]}" - if is_logged_in "${user}"; then - wie_lange_noch "${user}" "${key}" - check_time "${user}" "${key}" + if is_logged_in; then + wie_lange_noch + check_time else - sende_msg stop "${key}" >/dev/null + sende_msg stop >/dev/null fi done [ ${noch} -lt 0 ] && noch=0 |