-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-tui.subr
2448 lines (2004 loc) · 57.3 KB
/
settings-tui.subr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if [ ! "$_CBSD_SETTINGS_TUI_SUBR" ]; then
_CBSD_SETTINGS_TUI_SUBR=1
###
#required for . ${dialog}
TMPFILE="${ftmpdir}/inputbox.$$"
jname_msg="Jail name. Name must begin with a letter / a-z / and not have any special symbols: -,.=%"
host_hostname_msg="Jail Fully Qualified Domain Name"
ip4_addr_msg="Jail IP address from CBSD pool: ${nodeippool}. Use IP/PREFIX form. Comma-separated for aliases. 0 for disable IP creating by CBSD: useful for vnet Jails. Or DHCP for determine free IP automatically"
interface_msg="Auto create and auto remove IP on selected NICs. 0 for disable, auto - for auto detect"
ver_msg="Jail base source version"
basename_msg="Alternative jailbase name"
zfs_snapsrc_msg="Use this ZFS snapshot as source for jail data, e.g zmirror/jails/jail1@init"
path_msg="Mount point for Jail"
data_msg="Data directory for Jail"
devfs_ruleset_msg="DEVFS ruleset number for Jail devfs"
arch_msg="Target architecture, i386/amd64 or qemu-users arch"
baserw_msg="1,yes - Jail have personal copy of base system with write access, no NULLFS mount. 0,no - read-only and NULLFS"
mount_src_msg="1,yes - Jail have shared /usr/src tree in read-only"
kernelmount_msg="1,yes - Jail have mounted /boot/kernel tree in read-only. Usefull for DTRACE stuff in Jail"
mount_obj_msg="1,yes - Jail have mounted /usr/obj tree in read-only"
mount_ports_msg="1,yes - Jail have /usr/ports /usr/ports tree in read-only"
applytpl_msg="1,yes - Apply CBSD templates for Jail environment"
floatresolv_msg="1,yes - Floating /etc/resolv.conf content"
astart_msg="1,yes - Automatically start Jail when system boot"
vnet_msg="1.yes - Enable VIMAGE/VNet feature"
exec_timeout_msg="The maximum amount of time to wait for a command to complete"
exec_fib_msg="The FIB routing table to set when running commands inside the prison"
exec_consolelog_msg="Jail consolelog file for stdout/stderr output. Possible values: path_to_file, 0 - for disable log to file, 1 - for automatic $logdir/jname.log"
stop_timeout_msg="The maximum amount of time to wait for a jailed processes to exit after sending them a SIGTERM signal"
allow_dying_msg="Allow making changes to a dying Jail"
depend_msg="Specify a Jail or jails that this jail depends on"
allow_zfs_msg="Privileged users inside the jail will be able to mount and unmount the ZFS file system"
protected_msg="Prevent modification or deletion of a environment. 1 - protect/lock"
hidden_msg="Invisible environment flag. 1 - hide environment for frontend"
allow_kmem_msg="Allow kmem and /dev/io devices for jail. Warning: this is insecure options. Use it only for private purposes/X-jails"
allow_mount_msg="Allow privileged users inside the jail mount and unmount file system"
allow_devfs_msg="Allow privileged users inside the jail mount and unmount DEVFS file system"
mount_devfs_msg="Mount DEVFS filesystem in the jail"
mkhostsfile_msg="Automatically set IP/NAME in /etc/hosts when jail started"
allow_nullfs_msg="Allow privileged users inside the jail mount and unmount NULLFS file system"
allow_tmpfs_msg="Allow privileged users inside the jail mount and unmount TMPFS file system"
allow_procfs_msg="Allow privileged users inside the jail mount and unmount PROCFS file system"
allow_reserved_ports_msg="Allow the jail root may bind to ports lower than 1024. For FreeBSD 11.1+"
childrenmax_msg="Enable hierarchical jails and set limit max children"
persist_msg="Allows a jail to exist without any processes."
enforce_statfs_msg="This determines what information processes in a jail are able to get about mount points"
allow_fdescfs_msg="Jail may mount the fdescfs file system"
allow_sysvipc_msg="Jail may use SYSV IPC (separated for FreeBSD 11.0+)"
mount_fdescfs_msg="Mount a FDESCFS filesystem on the chrooted /dev/fd directory"
cpuset_msg="Associate group of CPUs to jail. 0 - for all cores, See man 1 cpuset for valid value"
mdsize_msg="Enter size for the images"
jdomain_msg="Specify CBSD node group name for jail"
GET_NODENAME_MSG="Change nodename. Warning: this operation will recreate the ssh keys in $workdir/.ssh dir"
GET_IMGSIZE_MSG="Allocate X size of image free space: 100m, 1g"
GET_SWAPSIZE_MSG="Configure swap partitional in X size (usual RAMx2), 0 - for disable, e.g: 4g"
GET_CPUS_MSG="Number of CPUs: 1, max: 16"
GET_VM_VNC_PORT_MSG="VNC port. 0 - for auto, 1 - disable"
GET_RAM_MSG="RAM in MB, eg: 512, 1024M, 2g"
GET_VMPROFILE_MSG="Select profile for VMs"
GET_JAILPROFILE_MSG="Profile for jcreate"
GET_HOSTBRIDGE_MSG="Hostbridge for VMs, eg: hostbridge or amd_hostbridge"
GET_ALLOW_SYSVIPC_MSG="Select SYSVIPC behaviour"
GET_GUESTFS_MSG="Choose FS for boot image"
GET_EFI_MSG="Choose UEFI firmware"
GET_VM_PACKAGE_MSG="Choose package name"
GET_CONSOLE_MSG="Choose default console"
GET_IMGTYPE_MSG="Choose image type"
GET_ISOPATH_MSG="Path to ISO image in srcdir/iso, eg: release.iso. 0 - for default img_iso"
GET_VM_ISOPATH_MSG="Select available/registered ISO"
GET_VM_CPU_TOPOLOGY_MSG="Select CPU topology profile name"
GET_GW4_MSG="Enter default gateway inside VMs or jail"
# show [] * for empty $1 values
# for Option list from -tui
curval()
{
local T
[ -z "${1}" ] && return 0
eval T="\$$1"
if [ -n "${T}" ]; then
printf "${T}"
else
printf " "
fi
return 0
}
# Increment index for menu counter
# required cbsd as shell for is_number
inc_menu_index()
{
local T
[ -z "${1}" ] && return 0
eval T="\$$1"
if ! is_number ${T}; then
T=$(( T + 1 ))
else
T=$( echo ${T} | /usr/bin/tr '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]' '[BCDEFGHIJKLMNOPQRSTUVWXYZA]' )
fi
eval "${1}=${T}"
return 0
}
# form for $pkglist
get_construct_pkglist()
{
local _i
[ -z "${pkglist}" -o "${pkglist}" = "NO" ] && pkglist="${ftmpdir}/tui.$$"
# load pkg list from profile
if [ -n "${tpl_pkglist}" ]; then
if [ -r "${tpl_pkglist}" ]; then
/bin/cat ${tpl_pkglist} >> ${pkglist}
else
for _i in ${tpl_pkglist}; do
echo ${_i} >> ${pkglist}
done
fi
fi
pkgbrowser controlmaster="${pkglist}"
[ ! -s "${pkglist}" ] && pkglist="NO"
}
# form for $srvlist
get_construct_services()
{
srvlist="${ftmpdir}/srv.$$"
srvbrowser controlmaster="${srvlist}" baseonly=1
[ ! -s "${srvlist}" ] && srvlist="NO"
}
# form for $srvlist
get_construct_add_user()
{
adduser="${ftmpdir}/adduser.$$"
adduser-tui controlmaster="${adduser}"
[ ! -s "${adduser}" ] && adduser=
}
# form for $jname
# if $1 = "nosearch" than skip for searching/testing of available jname
get_construct_jname()
{
local _ok _message _input _retval _oldjname
_oldjname="${jname}"
f_dialog_title " jname "
if [ "$1" = "nosearch" ]; then
freejname=${jname}
else
if [ -n "${jname}" ]; then
freejname="${jname}"
else
freejname=$( freejname default_jailname=${default_jailname} )
fi
fi
_ok=0
while [ ${_ok} -ne 1 ]; do
f_dialog_input _input "${jname_msg}" "${freejname}" \
"${_message}" || return $?
validate_jname ${_input}
case $? in
1)
jstatus jname="${_input}" >/dev/null 2>&1
if [ $? -ne 0 ]; then
_message="ERROR: Jail ${_input} already exist"
else
_ok=1
fi
;;
*)
_message="ERROR: Bad name. Choose other one"
;;
esac
done
[ -n "${_input}" ] && jname="${_input}"
# reload some dynamic variables depended from jname
[ -z "${jname}" ] && return 0
if [ "${_oldjname}" != "${jname}" ]; then
#merge_apply_profiles ${etcdir}/defaults/${zero_profile} ${global_profile_file}
host_hostname="${jname}.${default_domain}"
path="${jaildir}/${jname}"
data="${jaildatadir}/${jname}-${jaildatapref}"
mount_fstab="${jailfstabdir}/${jailfstabpref}${jname}"
rcconf="${jailrcconfdir}/rc.conf_${jname}"
fi
}
# form for $host_hostname
get_construct_host_hostname()
{
local _input _defdomain
f_dialog_title " host_hostname "
if [ -n "${host_hostname}" ]; then
_defdomain="${host_hostname}"
else
if [ -n "${default_domain}" ]; then
if [ -z "${jname}" ]; then
_defdomain="${jname}.${default_domain}"
else
_defdomain="jail1.${default_domain}"
fi
else
_defdomain="my.domain"
fi
fi
f_dialog_input _input "${host_hostname_msg}" "${_defdomain}" \
"${_message}" || return $?
[ -n "${_input}" ] && host_hostname="${_input}"
}
get_construct_ip4_addr()
{
local _ok=0 _input _retval _i _j _existing_ipjail _existing_ip _myip
local msg_yes msg_no IFS _jname _ips
f_dialog_title " ip4_addr "
while [ ${_ok} -ne 1 ]; do
if [ -z "${ip4_addr}" ]; then
ip4_addr=$( dhcpd 2>/dev/null )
if [ $? -eq 2 ]; then
ip4_addr="DHCP"
local msg_ok="It's a pity"
f_dialog_msgbox "No free IP address for DHCP in nodeippool"
return 0
fi
fi
f_dialog_input _input "${ip4_addr_msg}" "${ip4_addr}" "IP4 or IP6 Address"
_retval=$?
[ ${_retval} -ne 0 ] && return 0
#check ip in two phases:
# 1) via sqlite database for other's jails ips
# 2) for ip in LAN
if [ -z "${_input}" -a "${_input}" = "0" -a "{_input}" = "DHCP" ]; then
ip4_addr="${_input}"
return 0
fi
msg_yes="Ok"
msg_no="Not Ok"
_existing_ipjail=""
_existing_ip=""
_myip=""
IFS=","
for _i in ${_input}; do
ipwmask ${_i}
[ -z "${IWM}" -o "${_i}" = "0" ] && continue
iptype ${IWM}
[ $? -ne 0 ] && _myip="${_myip} ${IWM}"
done
# check for other jail
IFS="|"
_i=0
eval $( cbsdsql local SELECT jname,ip4_addr FROM jails WHERE ip4_addr!="0" 2>/dev/null |while read _jname _ips; do
echo jname${_i}=\"$_jname\"
echo ips${_i}=\"${_ips}\"
_i=$(( _i + 1 ))
done )
unset IFS
_ok=1
for _i in $( /usr/bin/seq 0 255 ); do
eval _jname="\$jname$_i"
[ -z "${_jname}" ] && break
# skip for myself
[ "${_jname}" = "${jname}" ] && continue
eval _existing_ipjail="\$ips$_i"
[ -z "${_existing_ipjail}" ] && break
_existing_ipjail=$( echo ${_existing_ipjail}|/usr/bin/tr "," " " )
for _i in ${_existing_ipjail}; do
ipwmask ${_i}
[ -z "${IWM}" ] && continue
iptype ${IWM}
[ $? -eq 1 ] && _existing_ip="${_existing_ip} ${IWM}"
done
for _i in ${_existing_ip}; do
for _j in ${_myip}; do
[ "${_i}" = "${_j}" ] && _ok=0 && break
done
[ ${_ok} -eq 0 ] && break
done
if [ ${_ok} -eq 0 ]; then
f_dialog_noyes "${_i} already assigned to jail: ${_jname}.\nIf you believe that it's ok, choose 'ok' to continue or 'not ok' for another IP address" "WARNING"
if [ $? -eq 1 ]; then
_ok=0
break
fi
_ok=2
break
fi
done # check for local jail end
[ ${_ok} -eq 0 ] && continue # if not ok from previous stage - repeat
[ ${_ok} -eq 2 ] && _ok=1 && continue
_ok=1
local _ipexist=
# check for ip existance in LAN
for _i in ${_myip}; do
IFS=" "
f_dialog_info "Probing for ${_i} availability. Please wait..."
unset IFS
checkip ip=${_i} check=1 2>/dev/null
if [ $? -eq 2 ]; then
_ok=0
_ipexist="${_ipexist} ${_i}"
fi
done
if [ ${_ok} -eq 0 ]; then
f_dialog_noyes "Seems like ${_ipexist} address already used on several devices on the LAN\nYou can found MAC address by \"arp -an\" command.\n If you believe that it's ok, choose 'ok' to continue or 'not ok' for another IP address" "WARNING"
[ $? -eq 0 ] && _ok=1
fi
done
ip4_addr="${_input}"
return 0
}
# form for $interface
# -b 1 - add "bridge" device
# -c choose_default item - defaultitem set to this value
# -s "skip this network list"
# -d 1 - add "disable" choice
# -m 1 - add "manual" choice
# -v 1 - add "vale" device
get_construct_interface()
{
local _input _def_iface _mynic _mydesc _mystatus
local defaultitem _skipnics="" _disable=0 _choose
local _manual=0 _vale=0 _bridge=0
local title=" interface "
local prompt="${interface_msg}"
hline=
local menu_list="
'EXIT' 'EXIT' 'Exit'
" # END-QUOTE
while getopts "b:c:s:d:m:v:" opt; do
case "$opt" in
b) _bridge="${OPTARG}" ;;
c) _choose="${OPTARG}" ;;
s) _skipnics="${OPTARG}" ;;
d) _disable="${OPTARG}" ;;
m) _manual="${OPTARG}" ;;
o) _optional="${OPTARG}" ;;
v) _vale="${OPTARG}" ;;
esac
shift $(($OPTIND - 1))
done
menu_list="${menu_list} 'auto' 'auto' 'Recommended: determine nic for jail IP via route table.'"
if [ "${_manual}" = "1" ]; then
menu_list="${menu_list} 'manual' 'manual' 'Enter interface by hand.'"
fi
if [ ${_disable} -eq 1 ]; then
menu_list="${menu_list} 'disable' 'disable' 'Do not create/remove IP automatically: IP of jail must be already initialized or for vnet mode'"
fi
menu_list="${menu_list} '-' '-' ''"
local OLDIFS="${IFS}"
local IFS=":"
local _num=1
eval $( ${miscdir}/nics-list -da -s "${_skipnics}" |while read _nicname _nicdesc _nicstatus; do
echo "nic${_num}_name=\"${_nicname}\""
echo "nic${_num}_desc=\"${_nicdesc}\""
echo "nic${_num}_status=\"${_nicstatus}\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
if [ "${_vale}" = "1" ]; then
eval $( cbsdsql local SELECT name FROM vale | while read name; do
echo "nic${_num}_name=\"vale_${name}\""
echo "nic${_num}_desc=\"VALE SWITCH: ${name}\""
echo "nic${_num}_status=\"UP\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
# eval "nic${_num}_name='vale'"
# eval "nic${_num}_desc='very fast Virtual Local Ethernet using the netmap API'"
# eval "nic${_num}_status='UP'"
fi
if [ "${_bridge}" = "1" ]; then
#menu_list="${menu_list} '-' 'Existing bridges' 'Use existing bridges'"
eval $( ${miscdir}/nics-list -o "bridge" | while read _nicname; do
echo "nic${_num}_name=\"${_nicname}\""
echo "nic${_num}_status=\"initialized\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
fi
IFS="${OLDIFS}"
if [ -n "${interface}" ]; then
case "${interface}" in
"0")
defaultitem="disable"
;;
*)
defaultitem="${interface}"
;;
esac
else
if [ -n "${_choose}" ]; then
defaultitem="${_choose}"
elif [ -n "${interface}" ]; then
defaultitem="${interface}"
else
interface="auto"
defaultitem="auto"
fi
fi
[ -n "${_choose}" ] && defaultitem="${_choose}"
for _num in $( /usr/bin/seq 1 9999 ); do
unset _mynic _mydesc _mystatus
eval _mynic="\$nic${_num}_name"
[ -z "${_mynic}" ] && break
eval _mydesc="\$nic${_num}_desc"
eval _mystatus="\$nic${_num}_status"
case "${_mynic%%[0-9]*}" in
tun|bridge|epair|tap|vlan)
_mydesc="Pseudo interface"
;;
lo)
_mydesc="Loopback interface"
;;
esac
[ -z "${_mydesc}" ] && _mydesc="Not available"
menu_list="${menu_list} '${_mynic}' '${_mynic} (${_mystatus} )' 'Description: ${_mydesc}'"
done
cbsd_menubox
retval=$?
case ${retval} in
${DIALOG_OK})
case "${mtag}" in
"-")
continue
;;
EXIT)
return 1
;;
disable)
interface="0"
;;
manual)
defaultitem="auto"
title=" interface "
prompt="Enter interface"
cbsd_inputbox_simple && interface="${mtag}"
;;
*)
[ -n "${mtag}" ] && interface="${mtag}"
;;
esac
;;
*)
;;
esac
return ${retval}
}
# form for $ver
get_construct_ver()
{
title=" ver "
prompt="${ver_msg}"
defaultitem="${ver}"
cbsd_inputbox_simple && ver="${mtag}"
}
# form for $basename
get_construct_basename()
{
title=" basename "
prompt="${basename_msg}"
defaultitem="${basename}"
cbsd_inputbox_simple && basename="${mtag}"
}
# form for $exec_stop
get_construct_exec_stop()
{
title=" exec_stop "
prompt=" Redefine for exec_stop "
defaultitem="${exec_stop}"
cbsd_inputbox_simple && exec_stop="${mtag}"
}
# form for $exec_start
get_construct_exec_start()
{
title=" exec_start "
prompt=" Redefine for exec_start "
defaultitem="${exec_start}"
cbsd_inputbox_simple && exec_start="${mtag}"
}
# form for $childrenmax
get_construct_childrenmax()
{
title=" childrenmax "
prompt="${childrenmax_msg}"
defaultitem="${childrenmax}"
cbsd_inputbox_simple && childrenmax="${mtag}"
}
# form for $enforce_statfs
get_construct_enforce_statfs()
{
title=" enforce_statfs "
prompt="${enforce_statfs_msg}"
defaultitem="${enforce_statfs}"
cbsd_inputbox_simple && enforce_statfs="${mtag}"
}
# form for $zfs_snapsrc
get_construct_zfs_snapsrc()
{
title=" zfs_snapsrc "
prompt="${zfs_snapsrc_msg}"
defaultitem="${zfs_snapsrc}"
if cbsd_inputbox_simple; then
if [ -n "${mtag}" ]; then
zfs_snapsrc="${mtag}"
else
unset zfs_snapsrc
fi
fi
}
# form for select password
# if $1 - can_empty than allow empty passowrd
get_password()
{
local prompt1="Enter New Password"
local prompt2="Re-enter Password"
local hline="Use alpha-numeric, punctuation, TAB or ENTER"
if [ "${1}" = "can_empty" ]; then
local can_empty=1
else
local can_empty=0
fi
f_dialog_title " Select Password "
local height1 width1
f_dialog_inputbox_size height1 width1 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
"$prompt1" \
"" \
"$hline"
local height2 width2
f_dialog_inputbox_size height2 width2 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
"$prompt2" \
"" \
"$hline"
#
# Loop until the user provides taint-free/valid input
#
local _password1 _password2
while :; do
_password1=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "$msg_ok" \
--cancel-label "$msg_cancel" \
--insecure \
--passwordbox "$prompt1" \
$height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
) || return $?
# Return if user either pressed ESC or chose Cancel/No
debug= f_dialog_line_sanitize _password1
_password2=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "$msg_ok" \
--cancel-label "$msg_cancel" \
--insecure \
--passwordbox "$prompt2" \
$height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
) || return $?
# Return if user either pressed ESC or chose Cancel/No
debug= f_dialog_line_sanitize _password2
if [ ${can_empty} -eq 0 ]; then
# Check for NULL entry
if ! [ "$_password1" -o "$_password2" ]; then
f_show_msg "Password is empty"
continue
fi
mtag=''
fi
# Check for password mismatch
if [ "$_password1" != "$_password2" ]; then
f_show_msg "Password do not match"
continue
fi
mtag="$_password1"
break
done
return $DIALOG_OK
}
# form for $user_pw_root
get_construct_user_pw_root()
{
if get_password; then
user_pw_root_crypt=$( ${miscdir}/pwcrypt ${mtag} )
if [ $? -eq 0 ]; then
unset user_pw_root
else
user_pw_root="${mtag}"
unset user_pw_root_crypt
fi
fi
}
# form for $vnc_password
get_construct_vnc_password()
{
if get_password can_empty; then
vnc_password="${mtag}"
else
unset vnc_password
fi
[ -z "${vnc_password}" ] && vnc_password="0"
}
# form for $vnc_password
get_construct_bhyve_vnc_vgaconf_menu()
{
local _input _res
# for default values
readconf vnc.conf
local title="VGACONF setting"
local defaultitem="${bhyve_vnc_vgaconf}"
local menu_list="
'io' 'io' 'I/O port queries'
'on' 'on' 'for legacy VGA I/O and memory regions'
'off' 'off' 'VGA adapter is present if they detect the I/O ports'
" # END-QUOTE
cbsd_menubox
retval=$?
case $retval in
${DIALOG_OK})
[ -n "${mtag}" ] && bhyve_vnc_vgaconf="${mtag}"
;;
*)
;;
esac
return ${retval}
}
# form for $path
get_construct_path()
{
title=" path "
prompt="${path_msg}"
defaultitem="${path}"
cbsd_inputbox_simple && path="${mtag}"
}
# form for $data
get_construct_data()
{
title=" data "
prompt="${data_msg}"
defaultitem="${data}"
cbsd_inputbox_simple && data="${mtag}"
}
# form for $devfs_ruleset
get_construct_devfs_ruleset()
{
title=" devfs_ruleset "
prompt="${devfs_ruleset_msg}"
defaultitem="${devfs_ruleset}"
cbsd_inputbox_simple && devfs_ruleset="${mtag}"
}
# $1 - 1,0 - default values
get_construct_yesno()
{
local _default=1
msg_yes="no"
msg_no="yes"
[ -n "${1}" ] && _default="${1}"
if [ ${_default} -eq 0 ]; then
f_dialog_yesno "${msg}" "${hline}"
else
f_dialog_noyes "${msg}" "${hline}"
fi
return $?
}
get_construct_mdsize()
{
title=" mdsize "
prompt="${mdsize_msg}"
defaultitem="${mdsize}"
cbsd_inputbox_simple && mdsize="${mtag}"
}
get_construct_imgsize()
{
local _input
f_dialog_title " imgsize "
f_dialog_input _input "${GET_IMGSIZE_MSG}:" "${imgsize}" \
"${_message}" || return $?
imgsize="${_input}"
}
get_construct_swapsize()
{
local _input
f_dialog_title " swapsize "
f_dialog_input _input "${GET_SWAPSIZE_MSG}:" "${swapsize}" \
"${_message}" || return $?
swapsize="${_input}"
}
# form for $exec_timeout
get_construct_exec_timeout()
{
local _input
f_dialog_title " exec_timeout "
f_dialog_input _input "${exec_timeout_msg}" "${exec_timeout}" \
"${_message}" || return $?
exec_timeout="${_input}"
}
# form for $exec_fib
get_construct_exec_fib()
{
local _input
f_dialog_title " exec_fib "
f_dialog_input _input "${exec_fib_msg}" "${exec_fib}" \
"${_message}" || return $?
exec_fib="${_input}"
}
# form for $exec_consolelog
get_construct_exec_consolelog()
{
local _input
f_dialog_title " exec_consolelog "
f_dialog_input _input "${exec_consolelog_msg}" "${exec_consolelog}" \
"${_message}" || return $?
exec_consolelog="${_input}"
}
# form for $stop_timeout
get_construct_stop_timeout()
{
local _input
f_dialog_title " stop_timeout "
f_dialog_input _input "${stop_timeout_msg}" "${stop_timeout}" \
"${_message}" || return $?
stop_timeout="${_input}"
}
# form for $depend
get_jail_depend()
{
local _input
f_dialog_title " depend "
f_dialog_input _input "${depend_msg}" \
"${_message}" || return $?
depend="${_input}"
}
# form for $cpuset
get_construct_cpuset()
{
local _input
f_dialog_title " cpuset "
f_dialog_input _input "${cpuset_msg}" "${cpuset}" \
"${_message}" || return $?
cpuset="${_input}"
}
# form for $cpus
get_construct_vm_cpus()
{
local _input _message=" current hoster logical CPUs: ${ncpu} "
local _ret=1
f_dialog_title " vCpus "
while [ ${_ret} -ne 0 ]; do
f_dialog_input _input "${GET_CPUS_MSG}" "${vm_cpus}" \
"${_message}" || return $?
if is_number ${_input}; then
f_show_msg "Only number is valid input for cpu"
continue
fi
if [ ${_input} -gt ${ncpu} -a ${_input} -lt 16 ]; then
if ! getyesno "Warning! Current node cpu: ${ncpu}. Overcommitting vCPUs can hurt perfomance.\nContinue anyway?"; then
continue
fi
elif [ ${_input} -lt 1 -o ${_input} -gt 16 ]; then
f_show_msg "Valid number of guest CPUs within 1 - 16 range"
continue
fi
_ret=0
done
vm_cpus="${_input}"
}
# form for $vm_vnc_port
get_construct_vm_vnc_port()
{
local _input
f_dialog_title " vnc port "
f_dialog_input _input "${GET_VM_VNC_PORT_MSG}" "${vm_vnc_port}" \
"${_message}" || return $?
vm_vnc_port="${_input}"
}
# form for $ram
get_construct_vm_ram()
{
local _input _tmp
f_dialog_title " ram "
f_dialog_input _input "${GET_RAM_MSG}" "${vm_ram}" \
"${_message}" || return $?
# test for human
if ! is_number "${_input}"; then
# is number. assume user's input value in MB, so convert to bytes
_input=$(( _input * 1024 * 1024 ))
if conv2human "${_input}"; then
_tmp="${convval}"
else
_tmp=$(( _input * 1024 * 1024 ))
if conv2human "${VAL}"; then
_tmp="${convval}"
fi
fi
else
_tmp="${_input}"
fi
vm_ram="${_tmp}"
}
# form for $vm_iso_path
get_construct_isopath()
{
local _input
f_dialog_title " isopath "
f_dialog_input _input "${GET_ISOPATH_MSG}" "${vm_iso_path}" \
"${_message}" || return $?
vm_iso_path="${_input}"
}
# form for $arch
get_construct_arch()
{
local _input _res
local qemu_mips64=$( /usr/bin/which qemu-mips64-static 2>/dev/null )
local qemu_arm=$( /usr/bin/which qemu-arm-static 2>/dev/null )
local qemu_aarch64=$( /usr/bin/which qemu-aarch64-static 2>/dev/null )
local amd64_menu=
local i386_menu=
local amd64_desc=
local i386_desc=
local arm_menu=
local mips_menu=
local arm_desc=
local mips_desc=
local qemu_mips64_desc=
local qemu_arm_desc=
local qemu_aarch64_desc=