Skip to content

Commit 46e0dba

Browse files
committed
feat(console): Added session timeout and reports for login and logout
1 parent 0d08215 commit 46e0dba

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,43 @@ source "${SCRIPT_DIR}/lib-dialog.sh"
1010
source "${SCRIPT_DIR}/dialog-keyboard.sh"
1111

1212

13+
session_timeout() {
14+
local timeout_seconds="$(jq_config '.console_session_timeout // ""')"
15+
timeout_seconds="${timeout_seconds:-"1800"}"
16+
export TIMEOUT_PID=""
17+
18+
# Run the command in background so trap can be checked
19+
"$@" &
20+
export CMD_PID=$!
21+
22+
# Start the timeout process
23+
(trap exit TERM; sleep "$timeout_seconds" & wait; echo "Timeout reached"; pkill -P "${CMD_PID}"; kill "${CMD_PID}") &
24+
TIMEOUT_PID=$!
25+
26+
cleanup() {
27+
if [[ -n "${TIMEOUT_PID}" ]]; then
28+
kill "${TIMEOUT_PID}" 2>/dev/null
29+
if ! wait "${TIMEOUT_PID}"; then
30+
report_notice "cuos:console:logout" "Logout from console interface"
31+
else
32+
report_notice "cuos:console:logout_timeout" "Logout from console interface after timeout"
33+
fi
34+
TIMEOUT_PID=""
35+
fi
36+
exit 0
37+
}
38+
trap cleanup SIGINT SIGTERM EXIT
39+
40+
wait $CMD_PID
41+
}
42+
1343
maintenance_menu() {
14-
maintenance_menu_check_login || return 1
44+
maintenance_menu_check_login || {
45+
report_err "cuos:console:login_failed" "Login to console interface failed"
46+
return 1
47+
}
48+
49+
report_notice "cuos:console:login" "Login to console interface"
1550

1651
while true; do
1752
local ipaddress
@@ -28,7 +63,7 @@ maintenance_menu() {
2863
"act" "System Actions" \
2964
"diag" "Diagnostics" \
3065
- " " \
31-
"exit" "\Z5Exit Menu\Z0")" || return 1
66+
"exit" "\Z5Exit Menu\Z0")" || break
3267
#"pass" "Change Admin Password"
3368
case "$choice" in
3469
host)
@@ -358,6 +393,6 @@ elif [[ -n "${1:-}" && "$(type -t "${1}")" == "function" ]]; then
358393
exit "$?"
359394
else
360395
change_vt
361-
maintenance_menu "$@"
396+
session_timeout maintenance_menu "$@"
362397
fi
363398

‎system/cuos/utils.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ set -uo pipefail
44

55
CONFIG_PATH="${CONFIG_PATH:-"/system.json"}"
66

7+
if [[ -n "${TEST:-}" ]]; then
8+
logger() {
9+
echo logger "$@"
10+
}
11+
fi
12+
713
report_emerg() {
814
local msg_id="$1"
915
shift

0 commit comments

Comments
 (0)