summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2012-12-21 18:58:19 +0000
committerdteske <dteske@FreeBSD.org>2012-12-21 18:58:19 +0000
commit5e7ea05b1afc71ededb3af74c2ab29cec62cc286 (patch)
treeb36ed1ce72c48c84674686128b0f6e806b3330e4
parent804c67a4867afb8b7ef41a3ade748cab870b788c (diff)
downloadFreeBSD-src-5e7ea05b1afc71ededb3af74c2ab29cec62cc286.zip
FreeBSD-src-5e7ea05b1afc71ededb3af74c2ab29cec62cc286.tar.gz
Add much-needed dialog(1) --inputbox function for simplifying the process of
requesting input from the user.
-rwxr-xr-xusr.sbin/bsdconfig/console/saver29
-rwxr-xr-xusr.sbin/bsdconfig/mouse/flags28
-rw-r--r--usr.sbin/bsdconfig/networking/share/hostname.subr32
-rw-r--r--usr.sbin/bsdconfig/networking/share/ipaddr.subr30
-rw-r--r--usr.sbin/bsdconfig/networking/share/netmask.subr32
-rw-r--r--usr.sbin/bsdconfig/networking/share/resolv.subr30
-rw-r--r--usr.sbin/bsdconfig/networking/share/routing.subr29
-rw-r--r--usr.sbin/bsdconfig/share/dialog.subr50
-rwxr-xr-xusr.sbin/bsdconfig/startup/misc29
-rw-r--r--usr.sbin/bsdconfig/startup/share/rcconf.subr31
-rw-r--r--usr.sbin/bsdconfig/startup/share/rcedit.subr33
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/group_input.subr93
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/user_input.subr290
13 files changed, 134 insertions, 602 deletions
diff --git a/usr.sbin/bsdconfig/console/saver b/usr.sbin/bsdconfig/console/saver
index 5313265..00938d4 100755
--- a/usr.sbin/bsdconfig/console/saver
+++ b/usr.sbin/bsdconfig/console/saver
@@ -167,33 +167,10 @@ while :; do
break ;;
"$msg_timeout") # Set the screen saver timeout interval
f_dialog_title "$msg_value_required"
- title="$DIALOG_TITLE"
- btitle="$DIALOG_BACKTITLE"
+ blanktime=$( f_dialog_input "$msg_enter_timeout_period" \
+ "$( f_sysrc_get blanktime )"
+ ) && f_sysrc_set blanktime "$blanktime"
f_dialog_title_restore
- prompt="$msg_enter_timeout_period"
- blanktime=$( f_sysrc_get blanktime )
- hline=""
- size=$( f_dialog_inputbox_size \
- "$title" \
- "$btitle" \
- "$prompt" \
- "$blanktime" \
- "$hline" )
- dialog_inputbox=$( $DIALOG \
- --title "$title" \
- --backtitle "$btitle" \
- --hline "$hline" \
- --ok-label "$msg_ok" \
- --cancel-label "$msg_cancel" \
- --inputbox "$prompt" $size \
- "$blanktime" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- blanktime=$( f_dialog_inputstr )
- [ $retval -eq $SUCCESS ] &&
- f_sysrc_set blanktime "$blanktime"
;;
esac
done
diff --git a/usr.sbin/bsdconfig/mouse/flags b/usr.sbin/bsdconfig/mouse/flags
index 21478de..62f9c84 100755
--- a/usr.sbin/bsdconfig/mouse/flags
+++ b/usr.sbin/bsdconfig/mouse/flags
@@ -79,32 +79,10 @@ flags=$( f_sysrc_get moused_flags )
# Prompt the user with the current value
#
f_dialog_title "$msg_value_required"
-title="$DIALOG_TITLE"
-btitle="$DIALOG_BACKTITLE"
+flags=$( f_dialog_input "$msg_please_specify_the_mouse_daemon_flags" \
+ "$flags"
+ ) || f_die
f_dialog_title_restore
-hline=
-prompt="$msg_please_specify_the_mouse_daemon_flags"
-size=$( f_dialog_inputbox_size \
- "$title" \
- "$btitle" \
- "$prompt" \
- "$flags" \
- "$hline" )
-dialog_inputbox=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$prompt\" $size \
- \"\$flags\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
-)
-retval=$?
-setvar MENU_INPUTBOX_$$ "$dialog_inputbox"
-flags=$( f_dialog_inputstr )
-
-[ $retval -eq $SUCCESS ] || f_die
#
# Save the new value
diff --git a/usr.sbin/bsdconfig/networking/share/hostname.subr b/usr.sbin/bsdconfig/networking/share/hostname.subr
index fed8679..e34e80c 100644
--- a/usr.sbin/bsdconfig/networking/share/hostname.subr
+++ b/usr.sbin/bsdconfig/networking/share/hostname.subr
@@ -132,41 +132,15 @@ f_dialog_input_hostname()
msg="$msg_please_enter_fqhn"
fi
- local hline="$hline_alnum_punc_tab_enter"
-
#
# Loop until the user provides taint-free input.
#
- local size height width
while :; do
-
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hostname" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$hostname\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- hostname=$( f_dialog_inputstr )
-
- [ $retval -eq $SUCCESS ] || return $retval
-
+ hostname=$( f_dialog_input "$msg" "$hostname" \
+ "$hline_alnum_punc_tab_enter"
+ ) || return
# Taint-check the user's input
f_dialog_validate_hostname "$hostname" && break
-
done
#
diff --git a/usr.sbin/bsdconfig/networking/share/ipaddr.subr b/usr.sbin/bsdconfig/networking/share/ipaddr.subr
index 65c2b98..b345d1c 100644
--- a/usr.sbin/bsdconfig/networking/share/ipaddr.subr
+++ b/usr.sbin/bsdconfig/networking/share/ipaddr.subr
@@ -360,41 +360,21 @@ f_dialog_input_ipaddr()
fi
local msg="$( printf "$msg_please_enter_new_ip_addr" "$interface" )"
- local hline="$hline_num_punc_tab_enter"
- local size="$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_ipaddr" \
- "$hline" )"
#
# Loop until the user provides taint-free input.
#
+ local retval
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_ipaddr\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
-
#
# Return error status if:
- # - User has not made any changes to the given value
# - User has either pressed ESC or chosen Cancel/No
+ # - User has not made any changes to the given value
#
+ _input=$( f_dialog_input "$msg" "$_ipaddr" \
+ "$hline_num_punc_tab_enter"
+ ) || return
[ "$_ipaddr" = "$_input" ] && return $FAILURE
- [ $retval -eq $SUCCESS ] || return $retval
# Return success if NULL value was entered
[ "$_input" ] || return $SUCCESS
diff --git a/usr.sbin/bsdconfig/networking/share/netmask.subr b/usr.sbin/bsdconfig/networking/share/netmask.subr
index 2f2b378..12e6be9 100644
--- a/usr.sbin/bsdconfig/networking/share/netmask.subr
+++ b/usr.sbin/bsdconfig/networking/share/netmask.subr
@@ -164,42 +164,20 @@ f_dialog_input_netmask()
return $FAILURE
fi
- local msg="$( printf "$msg_please_enter_subnet_mask" "$interface" )"
- local hline="$hline_num_punc_tab_enter"
- local size="$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_netmask" \
- "$hline" )"
-
#
# Loop until the user provides taint-free input.
#
+ local msg="$( printf "$msg_please_enter_subnet_mask" "$interface" )"
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_netmask\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
-
#
# Return error status if:
- # - User has not made any changes to the given value
# - User has either pressed ESC or chosen Cancel/No
+ # - User has not made any changes to the given value
#
+ _input=$( f_dialog_input "$msg" "$_netmask" \
+ "$hline_num_punc_tab_enter"
+ ) || return
[ "$_netmask" = "$_input" ] && return $FAILURE
- [ $retval -eq $SUCCESS ] || return $retval
# Return success if NULL value was entered
[ "$_input" ] || return $SUCCESS
diff --git a/usr.sbin/bsdconfig/networking/share/resolv.subr b/usr.sbin/bsdconfig/networking/share/resolv.subr
index 154748b..fc328c5 100644
--- a/usr.sbin/bsdconfig/networking/share/resolv.subr
+++ b/usr.sbin/bsdconfig/networking/share/resolv.subr
@@ -329,36 +329,13 @@ f_dialog_input_nameserver()
msg="$msg_please_enter_nameserver"
fi
- local hline="$hline_num_punc_tab_enter"
- local size="$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$ns" \
- "$hline" )"
-
#
# Loop until the user provides taint-free input.
#
while :; do
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$ns\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- new_ns=$( f_dialog_inputstr )
-
- [ $retval -eq $SUCCESS ] || return $retval
+ new_ns=$( f_dialog_input "$msg" "$ns" \
+ "$hline_num_punc_tab_enter"
+ ) || return
# Take only the first "word" of the user's input
new_ns="${new_ns%%[$IFS]*}"
@@ -369,7 +346,6 @@ f_dialog_input_nameserver()
# Update prompt to allow user to re-edit previous entry
ns="$new_ns"
-
done
#
diff --git a/usr.sbin/bsdconfig/networking/share/routing.subr b/usr.sbin/bsdconfig/networking/share/routing.subr
index b8ccdcd..2b346d4 100644
--- a/usr.sbin/bsdconfig/networking/share/routing.subr
+++ b/usr.sbin/bsdconfig/networking/share/routing.subr
@@ -97,35 +97,16 @@ f_dialog_input_defaultrouter()
return $FAILURE
fi
- local msg="$msg_please_enter_default_router"
- local hline="$hline_num_punc_tab_enter"
- local size="$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$defaultrouter" \
- "$hline" )"
-
#
# Loop until the user provides taint-free input.
#
+ local retval
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$defaultrouter\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ defaultrouter=$( f_dialog_input \
+ "$msg_please_enter_default_router" \
+ "$defaultrouter" "$hline_num_punc_tab_enter"
)
-
- local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- defaultrouter=$( f_dialog_inputstr )
-
+ retval=$?
[ "$defaultrouter" ] || return $SUCCESS
[ $retval -eq $SUCCESS ] || return $retval
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr
index bf10388..4f45817 100644
--- a/usr.sbin/bsdconfig/share/dialog.subr
+++ b/usr.sbin/bsdconfig/share/dialog.subr
@@ -1115,7 +1115,7 @@ f_dialog_noyes()
# f_dialog_inputstr
#
# Obtain the inputstr entered by the user from the most recently displayed
-# dialog(1) inputbox and clean up any temporary files.
+# dialog(1) inputbox and clean up any temporary files/variables.
#
f_dialog_inputstr()
{
@@ -1138,12 +1138,58 @@ f_dialog_inputstr()
return $SUCCESS
}
+# f_dialog_input $prompt [$init [$hline]]
+#
+# Prompt the user with a dialog(1) inputbox to enter some value. The inputbox
+# remains until the the user presses ENTER or ESC, or otherwise ends the
+# editing session, by selecting `Cancel' for example.
+#
+# If the user presses ENTER, the exit status is zero (success), otherwise if
+# the user presses ESC the exit status is 255, or if the user chose Cancel, the
+# exit status is instead 1.
+#
+# NOTE: The hline should correspond to the type of data you want from the user.
+# NOTE: Should not be used to edit multiline values.
+#
+f_dialog_input()
+{
+ local prompt="$1" init="$2" hline="$3"
+ local size="$( f_dialog_inputbox_size \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$init" \
+ "$hline" )"
+
+ local opterm="--"
+ [ "$USE_XDIALOG" ] && opterm=
+
+ local dialog_input
+ dialog_input=$(
+ eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --inputbox \"\$prompt\" $size \
+ $opterm \"\$init\" \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+
+ setvar DIALOG_INPUTBOX_$$ "$dialog_input"
+ f_dialog_inputstr
+
+ return $retval
+}
+
############################################################ MENU FUNCTIONS
# f_dialog_menutag
#
# Obtain the menutag chosen by the user from the most recently displayed
-# dialog(1) menu and clean up any temporary files.
+# dialog(1) menu and clean up any temporary files/variables.
#
f_dialog_menutag()
{
diff --git a/usr.sbin/bsdconfig/startup/misc b/usr.sbin/bsdconfig/startup/misc
index 6407d08..4dfdaff 100755
--- a/usr.sbin/bsdconfig/startup/misc
+++ b/usr.sbin/bsdconfig/startup/misc
@@ -253,34 +253,11 @@ dialog_menu_main()
#
dialog_input_value()
{
- local hline="$hline_alnum_tab_enter"
- local size prompt="$1" _input="$2"
+ local prompt="$1" _input="$2"
f_dialog_title "$msg_value_required"
-
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$prompt" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$prompt\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
-
+ _input=$( f_dialog_input "$prompt" "$_input" "$hline_alnum_tab_enter" )
+ local retval=$?
f_dialog_title_restore
# Return if user has either pressed ESC or chosen Cancel/No
diff --git a/usr.sbin/bsdconfig/startup/share/rcconf.subr b/usr.sbin/bsdconfig/startup/share/rcconf.subr
index 16cb290..efab30a 100644
--- a/usr.sbin/bsdconfig/startup/share/rcconf.subr
+++ b/usr.sbin/bsdconfig/startup/share/rcconf.subr
@@ -418,39 +418,16 @@ f_dialog_input_rclist()
#
f_dialog_input_rcvar()
{
- local msg="$msg_please_enter_rcvar_name"
- local hline="$hline_alnum_tab_enter"
-
#
# Loop until the user provides taint-free/valid input
#
- local size _input="$1"
+ local _input="$1"
while :; do
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
# Return if user either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_please_enter_rcvar_name" \
+ "$_input" "$hline_alnum_tab_enter"
+ ) || return
# Check for invalid entry (1of2)
if ! echo "$_input" | grep -q "^[[:alpha:]_]"; then
diff --git a/usr.sbin/bsdconfig/startup/share/rcedit.subr b/usr.sbin/bsdconfig/startup/share/rcedit.subr
index 4905a18..1f38a5c 100644
--- a/usr.sbin/bsdconfig/startup/share/rcedit.subr
+++ b/usr.sbin/bsdconfig/startup/share/rcedit.subr
@@ -53,8 +53,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
#
f_dialog_rcedit()
{
- local msg size retval var="$1" _input
- local hline="$hline_alnum_punc_tab_enter"
+ local msg var="$1" _input
msg=$( printf "$msg_please_enter_a_new_value" \
"$var" "$( f_sysrc_get_default "$var" )" )
@@ -67,34 +66,10 @@ f_dialog_rcedit()
_input=$( f_sysrc_get "$var" )
fi
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local opterm="--"
- [ "$USE_XDIALOG" ] && opterm=
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- $opterm \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
-
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg" "$_input" \
+ "$hline_alnum_punc_tab_enter"
+ ) || return
# Return if the value has not changed from current
local cur_val="$( f_sysrc_get "$var" )"
diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
index e3d59d0..b722ce2 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
@@ -111,39 +111,16 @@ f_dialog_menu_group_list()
#
f_dialog_input_group_name()
{
- local msg="$( printf "$msg_group" )"
- local hline="$hline_alnum_tab_enter"
-
#
# Loop until the user provides taint-free/valid input
#
- local size retval _name="$1" _input="$1"
+ local _name="$1" _input="$1"
while :; do
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_group" "$_input" \
+ "$hline_alnum_tab_enter"
+ ) || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -283,35 +260,12 @@ f_dialog_input_group_password()
#
f_dialog_input_group_gid()
{
- local msg size retval _input="$1"
- local hline="$hline_num_tab_enter"
-
- msg=$( printf "$msg_group_id_leave_empty_for_default" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter"
+ ) || return
group_gid="$_input"
save_flag=1
@@ -416,36 +370,13 @@ f_dialog_input_group_members()
_input="$_group_members"
;;
2) # Enter Group Members manually
- hline="$hline_num_tab_enter"
- msg=$(
- printf "$msg_group_members ($msg_separated_by_commas)"
- )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _group_members=$( f_dialog_inputstr )
+ msg="$msg_group_members ($msg_separated_by_commas)"
# Return to previous menu if user has either
# pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || continue
+ _group_members=$( f_dialog_input "$msg" "$_input" \
+ "$hline_num_tab_enter"
+ ) || continue
_input="$_group_members"
;;
diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
index 8b356b6..ba665c1 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
@@ -216,39 +216,16 @@ f_dialog_input_member_groups()
#
f_dialog_input_name()
{
- local msg="$( printf "$msg_login" )"
- local hline="$hline_alnum_tab_enter"
-
#
# Loop until the user provides taint-free/valid input
#
- local size retval _name="$1" _input="$1"
+ local _name="$1" _input="$1"
while :; do
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_login" "$_input" \
+ "$hline_alnum_tab_enter"
+ ) || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -389,35 +366,12 @@ f_dialog_input_password()
#
f_dialog_input_gecos()
{
- local msg size retval _input="$1"
- local hline="$hline_alnum_punc_tab_enter"
-
- msg=$( printf "$msg_full_name" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_full_name" "$_input" \
+ "$hline_alnum_punc_tab_enter"
+ ) || return
pw_gecos="$_input"
save_flag=1
@@ -435,35 +389,12 @@ f_dialog_input_gecos()
#
f_dialog_input_uid()
{
- local msg size retval _input="$1"
- local hline="$hline_num_tab_enter"
-
- msg=$( printf "$msg_user_id_leave_empty_for_default" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_user_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter"
+ ) || return
pw_uid="$_input"
save_flag=1
@@ -481,35 +412,12 @@ f_dialog_input_uid()
#
f_dialog_input_gid()
{
- local msg size retval _input="$1"
- local hline="$hline_num_tab_enter"
-
- msg=$( printf "$msg_group_id_leave_empty_for_default" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter"
+ ) || return
pw_gid="$_input"
save_flag=1
@@ -527,35 +435,12 @@ f_dialog_input_gid()
#
f_dialog_input_class()
{
- local msg size retval _input="$1"
- local hline="$hline_alnum_tab_enter"
-
- msg=$( printf "$msg_login_class" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_login_class" "$_input" \
+ "$hline_alnum_tab_enter"
+ ) || return
pw_class="$_input"
save_flag=1
@@ -695,31 +580,11 @@ f_dialog_input_change()
f_isinteger "$ret_days" &&
ret_days=$(( $ret_days + 1 ))
- msg="$msg_password_expires_in_how_many_days"
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$ret_days" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$ret_days\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_days=$( f_dialog_inputstr )
-
# Return to menu if either ESC or Cancel/No
- [ $retval -eq $SUCCESS ] || continue
+ ret_days=$( f_dialog_input \
+ "$msg_password_expires_in_how_many_days" \
+ "$ret_days" "$hline"
+ ) || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
@@ -741,30 +606,10 @@ f_dialog_input_change()
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_secs=$( f_dialog_inputstr )
# Return to menu if either ESC or Cancel/No
- [ $retval -eq $SUCCESS ] || continue
+ ret_secs=$( f_dialog_input \
+ "$msg" "$_input" "$hline" ) || continue
_input="$ret_secs"
@@ -919,31 +764,11 @@ f_dialog_input_expire()
f_isinteger "$ret_days" &&
ret_days=$(( $ret_days + 1 ))
- msg="$msg_account_expires_in_how_many_days"
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$ret_days" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$ret_days\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_days=$( f_dialog_inputstr )
-
# Return to menu if either ESC or Cancel/No
- [ $retval -eq $SUCCESS ] || continue
+ ret_days=$( f_dialog_input \
+ "$msg_account_expires_in_how_many_days" \
+ "$ret_days" "$hline"
+ ) || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
@@ -965,30 +790,10 @@ f_dialog_input_expire()
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_secs=$( f_dialog_inputstr )
# Return to menu if either ESC or Cancel/No
- [ $retval -eq $SUCCESS ] || continue
+ ret_secs=$( f_dialog_input \
+ "$msg" "$_input" "$hline" ) || continue
_input="$ret_secs"
@@ -1022,35 +827,12 @@ f_dialog_input_expire()
#
f_dialog_input_home_dir()
{
- local msg size retval _input="$1"
- local hline="$hline_alnum_punc_tab_enter"
-
- msg=$( printf "$msg_home_directory" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$_input" \
- "$hline" )
-
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$msg\" $size \
- \"\$_input\" \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
+ local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ _input=$( f_dialog_input "$msg_home_directory" "$_input" \
+ "$hline_alnum_punc_tab_enter"
+ ) || return
pw_home_dir="$_input"
save_flag=1
OpenPOWER on IntegriCloud