Skip to content

Commit 339828f

Browse files
committed
feat(console): change console password
1 parent 46e0dba commit 339828f

2 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎system/cuos/dialog-maintenance.sh‎

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ session_timeout() {
4141
}
4242

4343
maintenance_menu() {
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"
44+
maintenance_menu_check_login || return 1
5045

5146
while true; do
5247
local ipaddress
@@ -117,18 +112,28 @@ install_menu() {
117112
maintenance_menu_check_login() {
118113
local console_password
119114
console_password="$(jq_config '.console_password // ""')"
120-
if [ -z "${console_password}" ]; then return 0; fi
115+
if [ -z "${console_password}" ]; then
116+
report_notice "cuos:console:login" "Login to console interface"
117+
return 0
118+
fi
121119

122120
local confirm
123121
confirm=$(pwbox "The maintenance menu is protected by a password:" "Maintenance Menu") || return 1
124122
if ! check_password "${console_password}" "${confirm}"; then
123+
report_err "cuos:console:login_failed" "Login to console interface failed"
125124
DIALOGRC="${SCRIPT_DIR}/dialog-red.rc" msg "Password does not match. Aborting." "Maintenance Menu"
126125
return 1
127126
fi
128127

128+
report_notice "cuos:console:login" "Login to console interface"
129129
return 0
130130
}
131131

132+
hash_password() {
133+
local password="$1"
134+
echo "${password}" | openssl passwd -6 -stdin
135+
}
136+
132137
hash_admin_password() {
133138
local password="$1"
134139
local saltlen=8
@@ -164,11 +169,38 @@ change_admin_password() {
164169
'.system_admin_password = $password' \
165170
"${CONFIG_PATH}"
166171
)
172+
report_notice "cuos:system:admin_password" "Administrator password changed"
167173
msg "Administrator password set." "Password"
168174
return 0
169175
done
170176
}
171177

178+
change_console_password() {
179+
local p1 p2
180+
while true; do
181+
p1="$(pwbox "Enter a new password (Beware the keyboard layout):" "Console Password" 10 70)" || return 1
182+
p2="$(pwbox "Confirm password:" "Console Password" 10 70)" || return 1
183+
if [[ "$p1" != "$p2" ]]; then
184+
msg "Passwords do not match. Please try again." "Password"
185+
continue
186+
fi
187+
if [[ ${#p1} -lt 8 ]]; then
188+
msg "Password too short. Minimum 8 characters." "Password"
189+
continue
190+
fi
191+
(
192+
set +x
193+
jq_replace \
194+
--arg password "$(hash_password "$p1")" \
195+
'.console_password = $password' \
196+
"${CONFIG_PATH}"
197+
)
198+
msg "Console password changed." "Password"
199+
report_notice "cuos:console:password" "Console password changed"
200+
return 0
201+
done
202+
}
203+
172204
system_actions_menu() {
173205
while true; do
174206
local choice
@@ -178,6 +210,7 @@ system_actions_menu() {
178210
- " " \
179211
"update" "Trigger System Update" \
180212
"rollback" "Rollback Last Update (OS only)" \
213+
"password" "Change Console Password (this menu)" \
181214
"expand" "Expand Filesystem" \
182215
"factory" "Factory Reset" \
183216
- " " \
@@ -187,6 +220,7 @@ system_actions_menu() {
187220
shutdown) system_shutdown ;;
188221
update) system_update ;;
189222
rollback) system_rollback ;;
223+
password) change_console_password ;;
190224
expand) system_expand_fs ;;
191225
factory) system_factory_reset ;;
192226
back|"") return 0 ;;
@@ -200,12 +234,14 @@ system_actions_menu_installation() {
200234
choice="$(fmenu "System Actions" "Select an action:" 17 72 10 \
201235
"shutdown" "Shutdown System" \
202236
"update" "Trigger System Update" \
237+
"password" "Set Console Password (this menu)" \
203238
"expand" "Expand Filesystem" \
204239
- " " \
205240
"back" "\Z5Back\Z0")" || return 1
206241
case "$choice" in
207242
shutdown) system_shutdown ;;
208243
update) system_update ;;
244+
password) change_console_password ;;
209245
expand) system_expand_fs ;;
210246
back|"") return 0 ;;
211247
esac

‎system/cuos/utils.sh‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ jq_config() {
7777
jq_replace() {
7878
# Usage: jq_replace jq_expression file
7979
# like jq, but with inplace edit function
80-
local args=("$@")
80+
local args=("${@:1:$#-1}")
8181
local file="${!#}"
82-
unset 'args[-1]'
8382

8483
(
8584
#lock the execution

0 commit comments

Comments
 (0)