group_input.subr (251242) | group_input.subr (251264) |
---|---|
1if [ ! "$_USERMGMT_GROUP_INPUT_SUBR" ]; then _USERMGMT_GROUP_INPUT_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 4# Copyright (c) 2012-2013 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# | 1if [ ! "$_USERMGMT_GROUP_INPUT_SUBR" ]; then _USERMGMT_GROUP_INPUT_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 4# Copyright (c) 2012-2013 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# |
28# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/share/group_input.subr 251242 2013-06-02 05:45:25Z dteske $ | 28# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/share/group_input.subr 251264 2013-06-02 20:02:50Z dteske $ |
29# 30############################################################ INCLUDES 31 32BSDCFG_SHARE="/usr/share/bsdconfig" 33. $BSDCFG_SHARE/common.subr || exit 1 34f_dprintf "%s: loading includes..." usermgmt/group_input.subr 35f_include $BSDCFG_SHARE/dialog.subr 36f_include $BSDCFG_SHARE/strings.subr --- 23 unchanged lines hidden (view full) --- 60 61# f_dialog_menu_group_list [$default] 62# 63# Allows the user to select a group from a list. Optionally, if present and 64# non-NULL, initially highlight $default group. 65# 66f_dialog_menu_group_list() 67{ | 29# 30############################################################ INCLUDES 31 32BSDCFG_SHARE="/usr/share/bsdconfig" 33. $BSDCFG_SHARE/common.subr || exit 1 34f_dprintf "%s: loading includes..." usermgmt/group_input.subr 35f_include $BSDCFG_SHARE/dialog.subr 36f_include $BSDCFG_SHARE/strings.subr --- 23 unchanged lines hidden (view full) --- 60 61# f_dialog_menu_group_list [$default] 62# 63# Allows the user to select a group from a list. Optionally, if present and 64# non-NULL, initially highlight $default group. 65# 66f_dialog_menu_group_list() 67{ |
68 local prompt= 69 local menu_list=" 70 'X $msg_exit' '' 71 " # END-QUOTE |
|
68 local defaultitem="$1" | 72 local defaultitem="$1" |
69 local menu_list | |
70 local hline="$hline_alnum_punc_tab_enter" 71 | 73 local hline="$hline_alnum_punc_tab_enter" 74 |
72 menu_list=" 73 'X $msg_exit' '' 74 " # END-QUOTE 75 | |
76 # Add groups from group(5) 77 menu_list="$menu_list $( pw groupshow -a | awk -F: ' 78 !/^[[:space:]]*(#|$)/ { 79 printf "'\'%s\'\ \'%s\''\n", $1, $1 80 }' 81 )" 82 83 local height width rows 84 eval f_dialog_menu_size height width rows \ 85 \"\$DIALOG_TITLE\" \ 86 \"\$DIALOG_BACKTITLE\" \ | 75 # Add groups from group(5) 76 menu_list="$menu_list $( pw groupshow -a | awk -F: ' 77 !/^[[:space:]]*(#|$)/ { 78 printf "'\'%s\'\ \'%s\''\n", $1, $1 79 }' 80 )" 81 82 local height width rows 83 eval f_dialog_menu_size height width rows \ 84 \"\$DIALOG_TITLE\" \ 85 \"\$DIALOG_BACKTITLE\" \ |
87 \"\" \ | 86 \"\$prompt\" \ |
88 \"\$hline\" \ 89 $menu_list 90 91 local menu_choice 92 menu_choice=$( eval $DIALOG \ 93 --title \"\$DIALOG_TITLE\" \ 94 --backtitle \"\$DIALOG_BACKTITLE\" \ 95 --hline \"\$hline\" \ 96 --ok-label \"\$msg_ok\" \ 97 --cancel-label \"\$msg_cancel\" \ 98 --default-item \"\$defaultitem\" \ | 87 \"\$hline\" \ 88 $menu_list 89 90 local menu_choice 91 menu_choice=$( eval $DIALOG \ 92 --title \"\$DIALOG_TITLE\" \ 93 --backtitle \"\$DIALOG_BACKTITLE\" \ 94 --hline \"\$hline\" \ 95 --ok-label \"\$msg_ok\" \ 96 --cancel-label \"\$msg_cancel\" \ 97 --default-item \"\$defaultitem\" \ |
99 --menu \"\" \ | 98 --menu \"\$prompt\" \ |
100 $height $width $rows \ 101 $menu_list \ 102 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 103 ) 104 local retval=$? 105 f_dialog_menutag_store -s "$menu_choice" 106 return $retval 107} --- 58 unchanged lines hidden (view full) --- 166} 167 168# f_dialog_input_group_password 169# 170# Prompt the user to enter a password (twice). 171# 172f_dialog_input_group_password() 173{ | 99 $height $width $rows \ 100 $menu_list \ 101 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 102 ) 103 local retval=$? 104 f_dialog_menutag_store -s "$menu_choice" 105 return $retval 106} --- 58 unchanged lines hidden (view full) --- 165} 166 167# f_dialog_input_group_password 168# 169# Prompt the user to enter a password (twice). 170# 171f_dialog_input_group_password() 172{ |
173 local prompt1="$msg_group_password" 174 local prompt2="$msg_reenter_group_password" |
|
174 local hline="$hline_alnum_punc_tab_enter" | 175 local hline="$hline_alnum_punc_tab_enter" |
175 local msg rmsg | |
176 | 176 |
177 msg=$( printf "$msg_group_password" ) | |
178 local height1 width1 179 f_dialog_inputbox_size height1 width1 \ 180 "$DIALOG_TITLE" \ 181 "$DIALOG_BACKTITLE" \ | 177 local height1 width1 178 f_dialog_inputbox_size height1 width1 \ 179 "$DIALOG_TITLE" \ 180 "$DIALOG_BACKTITLE" \ |
182 "$msg" \ | 181 "$prompt1" \ |
183 "" \ 184 "$hline" 185 | 182 "" \ 183 "$hline" 184 |
186 rmsg=$( printf "$msg_reenter_group_password" ) | |
187 local height2 width2 188 f_dialog_inputbox_size height2 width2 \ 189 "$DIALOG_TITLE" \ 190 "$DIALOG_BACKTITLE" \ | 185 local height2 width2 186 f_dialog_inputbox_size height2 width2 \ 187 "$DIALOG_TITLE" \ 188 "$DIALOG_BACKTITLE" \ |
191 "$rmsg" \ | 189 "$prompt2" \ |
192 "" \ 193 "$hline" 194 195 # 196 # Loop until the user provides taint-free/valid input 197 # 198 local retval _password1 _password2 199 while :; do 200 _password1=$( $DIALOG \ 201 --title "$DIALOG_TITLE" \ 202 --backtitle "$DIALOG_BACKTITLE" \ 203 --hline "$hline" \ 204 --ok-label "$msg_ok" \ 205 --cancel-label "$msg_cancel" \ 206 --insecure \ | 190 "" \ 191 "$hline" 192 193 # 194 # Loop until the user provides taint-free/valid input 195 # 196 local retval _password1 _password2 197 while :; do 198 _password1=$( $DIALOG \ 199 --title "$DIALOG_TITLE" \ 200 --backtitle "$DIALOG_BACKTITLE" \ 201 --hline "$hline" \ 202 --ok-label "$msg_ok" \ 203 --cancel-label "$msg_cancel" \ 204 --insecure \ |
207 --passwordbox "$msg" \ | 205 --passwordbox "$prompt1" \ |
208 $height1 $width1 \ 209 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 210 ) 211 retval=$? 212 debug= f_dialog_line_sanitize _password1 213 214 # Return if user has either pressed ESC or chosen Cancel/No 215 [ $retval -eq $SUCCESS ] || return $retval 216 217 _password2=$( $DIALOG \ 218 --title "$DIALOG_TITLE" \ 219 --backtitle "$DIALOG_BACKTITLE" \ 220 --hline "$hline" \ 221 --ok-label "$msg_ok" \ 222 --cancel-label "$msg_cancel" \ 223 --insecure \ | 206 $height1 $width1 \ 207 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 208 ) 209 retval=$? 210 debug= f_dialog_line_sanitize _password1 211 212 # Return if user has either pressed ESC or chosen Cancel/No 213 [ $retval -eq $SUCCESS ] || return $retval 214 215 _password2=$( $DIALOG \ 216 --title "$DIALOG_TITLE" \ 217 --backtitle "$DIALOG_BACKTITLE" \ 218 --hline "$hline" \ 219 --ok-label "$msg_ok" \ 220 --cancel-label "$msg_cancel" \ 221 --insecure \ |
224 --passwordbox "$rmsg" \ | 222 --passwordbox "$prompt2" \ |
225 $height2 $width2 \ 226 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 227 ) 228 retval=$? 229 debug= f_dialog_line_sanitize _password2 230 231 # Return if user has either pressed ESC or chosen Cancel/No 232 [ $retval -eq $SUCCESS ] || return $retval --- 50 unchanged lines hidden (view full) --- 283# f_dialog_input_group_members [$group_members] 284# 285# Allow the user to modify a list of members for a given group. If the user does 286# not cancel or press ESC, the $group_members variable will hold the newly- 287# configured value upon return. 288# 289f_dialog_input_group_members() 290{ | 223 $height2 $width2 \ 224 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 225 ) 226 retval=$? 227 debug= f_dialog_line_sanitize _password2 228 229 # Return if user has either pressed ESC or chosen Cancel/No 230 [ $retval -eq $SUCCESS ] || return $retval --- 50 unchanged lines hidden (view full) --- 281# f_dialog_input_group_members [$group_members] 282# 283# Allow the user to modify a list of members for a given group. If the user does 284# not cancel or press ESC, the $group_members variable will hold the newly- 285# configured value upon return. 286# 287f_dialog_input_group_members() 288{ |
291 local menu_choice retval _input="$1" 292 local msg="$msg_group_members:" 293 local hline="$hline_num_arrows_tab_enter" 294 local user 295 local menu_list 296 local all_users_valid 297 local _group_members 298 local checklist_users 299 300 menu_list=" | 289 local _input="$1" 290 local prompt="$msg_group_members:" 291 local menu_list=" |
301 'X' '$msg_continue' 302 '1' '$msg_select_group_members_from_list' 303 '2' '$msg_enter_group_members_manually' 304 " # END-QUOTE | 292 'X' '$msg_continue' 293 '1' '$msg_select_group_members_from_list' 294 '2' '$msg_enter_group_members_manually' 295 " # END-QUOTE |
296 local defaultitem= 297 local hline="$hline_num_arrows_tab_enter" |
|
305 | 298 |
306 local menu_choice defaultitem= | |
307 local mheight mwidth mrows 308 eval f_dialog_menu_size mheight mwidth mrows \ 309 \"\$DIALOG_TITLE\" \ 310 \"\$DIALOG_BACKTITLE\" \ | 299 local mheight mwidth mrows 300 eval f_dialog_menu_size mheight mwidth mrows \ 301 \"\$DIALOG_TITLE\" \ 302 \"\$DIALOG_BACKTITLE\" \ |
311 \"\$msg\" \ | 303 \"\$prompt\" \ |
312 \"\$hline\" \ 313 $menu_list 314 | 304 \"\$hline\" \ 305 $menu_list 306 |
307 local menu_choice retval |
|
315 while :; do 316 menu_choice=$( eval $DIALOG \ 317 --title \"\$DIALOG_TITLE\" \ 318 --backtitle \"\$DIALOG_BACKTITLE\" \ 319 --hline \"\$hline\" \ 320 --ok-label \"\$msg_ok\" \ 321 --cancel-label \"\$msg_cancel\" \ 322 --default-item \"\$defaultitem\" \ | 308 while :; do 309 menu_choice=$( eval $DIALOG \ 310 --title \"\$DIALOG_TITLE\" \ 311 --backtitle \"\$DIALOG_BACKTITLE\" \ 312 --hline \"\$hline\" \ 313 --ok-label \"\$msg_ok\" \ 314 --cancel-label \"\$msg_cancel\" \ 315 --default-item \"\$defaultitem\" \ |
323 --menu \"\$msg\" \ | 316 --menu \"\$prompt\" \ |
324 $mheight $mwidth $mrows \ 325 $menu_list \ 326 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 327 ) 328 retval=$? 329 f_dialog_data_sanitize menu_choice 330 defaultitem="$menu_choice" 331 f_dprintf "retval=%u menu_choice=[%s]" $retval "$menu_choice" 332 333 # Return if user has either pressed ESC or chosen Cancel/No 334 [ $retval -eq $SUCCESS ] || return $retval 335 | 317 $mheight $mwidth $mrows \ 318 $menu_list \ 319 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 320 ) 321 retval=$? 322 f_dialog_data_sanitize menu_choice 323 defaultitem="$menu_choice" 324 f_dprintf "retval=%u menu_choice=[%s]" $retval "$menu_choice" 325 326 # Return if user has either pressed ESC or chosen Cancel/No 327 [ $retval -eq $SUCCESS ] || return $retval 328 |
329 local _group_members |
|
336 case "$menu_choice" in 337 X) # Exit 338 break ;; 339 1) # Select Group Members from a list | 330 case "$menu_choice" in 331 X) # Exit 332 break ;; 333 1) # Select Group Members from a list |
340 user_list=$( pw usershow -a | awk -F: ' 341 !/^[[:space:]]*(#|$)/ { printf "%s\n", $1 }' ) 342 checklist_users= 343 for user in $user_list; do 344 checklist_users="$checklist_users $user \"\"" | 334 local user check_list= 335 for user in $( pw usershow -a | 336 awk -F: '!/^[[:space:]]*(#|$)/{print $1}' 337 ); do 338 # Format of a checklist entry: tag item status |
345 if echo "$_input" | grep -q "\<$user\>"; then | 339 if echo "$_input" | grep -q "\<$user\>"; then |
346 checklist_users="$checklist_users on" | 340 check_list="$check_list $user '' on" |
347 else | 341 else |
348 checklist_users="$checklist_users off" | 342 check_list="$check_list $user '' off" |
349 fi 350 done 351 352 local cheight cwidth crows 353 eval f_dialog_checklist_size cheight cwidth crows \ 354 \"\$DIALOG_TITLE\" \ 355 \"\$DIALOG_BACKTITLE\" \ | 343 fi 344 done 345 346 local cheight cwidth crows 347 eval f_dialog_checklist_size cheight cwidth crows \ 348 \"\$DIALOG_TITLE\" \ 349 \"\$DIALOG_BACKTITLE\" \ |
356 \"\" \ | 350 \"\$prompt\" \ |
357 \"\$hline\" \ | 351 \"\$hline\" \ |
358 $checklist_users | 352 $check_list |
359 _group_members=$( eval $DIALOG \ 360 --title \"\$DIALOG_TITLE\" \ 361 --backtitle \"\$DIALOG_BACKTITLE\" \ 362 --separate-output \ 363 --hline \"\$hline\" \ 364 --ok-label \"\$msg_ok\" \ 365 --cancel-label \"\$msg_cancel\" \ | 353 _group_members=$( eval $DIALOG \ 354 --title \"\$DIALOG_TITLE\" \ 355 --backtitle \"\$DIALOG_BACKTITLE\" \ 356 --separate-output \ 357 --hline \"\$hline\" \ 358 --ok-label \"\$msg_ok\" \ 359 --cancel-label \"\$msg_cancel\" \ |
366 --checklist \"\$msg\" \ | 360 --checklist \"\$prompt\" \ |
367 $cheight $cwidth $crows \ | 361 $cheight $cwidth $crows \ |
368 $checklist_users \ | 362 $check_list \ |
369 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 370 ) || continue 371 # Return to previous menu if user either 372 # pressed ESC or chose Cancel/No 373 f_dialog_data_sanitize _group_members 374 375 # Convert the newline separated list into a comma- 376 # separated one so that if the user switches over to 377 # manual editing, list reflects checklist selections 378 _group_members=$( echo "$_group_members" | 379 tr '\n' ' ' | 380 sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' 381 ) 382 383 _input="$_group_members" 384 ;; 385 2) # Enter Group Members manually | 363 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 364 ) || continue 365 # Return to previous menu if user either 366 # pressed ESC or chose Cancel/No 367 f_dialog_data_sanitize _group_members 368 369 # Convert the newline separated list into a comma- 370 # separated one so that if the user switches over to 371 # manual editing, list reflects checklist selections 372 _group_members=$( echo "$_group_members" | 373 tr '\n' ' ' | 374 sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' 375 ) 376 377 _input="$_group_members" 378 ;; 379 2) # Enter Group Members manually |
386 msg="$msg_group_members ($msg_separated_by_commas)" | 380 local p="$msg_group_members ($msg_separated_by_commas)" |
387 | 381 |
388 f_dialog_input _group_members "$msg" "$_input" \ | 382 f_dialog_input _group_members "$p" "$_input" \ |
389 "$hline_num_tab_enter" || continue 390 # Return to previous menu if user either 391 # pressed ESC or chose Cancel/No 392 393 _input="$_group_members" 394 ;; 395 esac 396 done --- 14 unchanged lines hidden --- | 383 "$hline_num_tab_enter" || continue 384 # Return to previous menu if user either 385 # pressed ESC or chose Cancel/No 386 387 _input="$_group_members" 388 ;; 389 esac 390 done --- 14 unchanged lines hidden --- |