- replace dhcp flag with configuration selector
This commit is contained in:
parent
f41fbed218
commit
03bbb0f4d6
@ -65,6 +65,13 @@ list_hw_binding()
|
||||
printf '("businfo" label "%s")' "`_ "by bus location"`"
|
||||
}
|
||||
|
||||
list_configuration()
|
||||
{
|
||||
printf '("off" label "%s")' "`_ "Turned off"`"
|
||||
printf '("dhcp" label "%s")' "`_ "DHCP"`"
|
||||
printf '("static" label "%s")' "`_ "Manual"`"
|
||||
}
|
||||
|
||||
read_hw_binding()
|
||||
{
|
||||
local config=
|
||||
@ -105,6 +112,27 @@ read_info()
|
||||
echo "$info"
|
||||
}
|
||||
|
||||
read_variable()
|
||||
{
|
||||
local var="$(shell_config_get "$1/options" "$3")"
|
||||
[ -n "$var" ] || var="$(ifvar "$2")"
|
||||
echo "$var"
|
||||
}
|
||||
|
||||
read_configuration()
|
||||
{
|
||||
local disabled="$(read_variable "$1" "$2" DISABLED)"
|
||||
local bootproto="$(read_variable "$1" "$2" BOOTPROTO)"
|
||||
|
||||
if [ "$(write_bool "$disabled")" = "#t" ];then
|
||||
echo 'off'
|
||||
elif [ "$bootproto" = "static" ];then
|
||||
echo 'static'
|
||||
else #dhcp by default
|
||||
echo 'dhcp'
|
||||
fi
|
||||
}
|
||||
|
||||
read_iface()
|
||||
{
|
||||
local name="$1"; shift
|
||||
@ -121,6 +149,7 @@ read_iface()
|
||||
printf 'info "%s" ' "$(read_info)"
|
||||
printf 'wireless %s ' "$(ifcheckwireless "$name" && echo "#t" || echo "#f")"
|
||||
printf 'hw_binding "%s" ' "$(read_hw_binding "$name")"
|
||||
printf 'configuration "%s"' "$(read_configuration "$ifacedir" "$name")"
|
||||
|
||||
local addr= ip= mask= bootproto=
|
||||
[ ! -s "/$ifacedir/ipv4address" ] ||
|
||||
@ -136,13 +165,6 @@ read_iface()
|
||||
[ ! -s "/$ifacedir/ipv4route" ] ||
|
||||
printf 'default "%s"\n' \
|
||||
$(grep '^default' "$ifacedir/ipv4route" | sed -r 's,default[[:space:]]+via[[:space:]],,' || echo "")
|
||||
|
||||
local bootproto="$(ifvar "$name" "BOOTPROTO")"
|
||||
case "$bootproto" in
|
||||
dhcp) echo "dhcp #t" ;;
|
||||
static) echo "dhcp #f" ;;
|
||||
*) echo 'dhcp #t' ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
@ -186,7 +208,6 @@ write_hw_binding()
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
write_iface()
|
||||
{
|
||||
local name="$1" && shift
|
||||
@ -202,11 +223,19 @@ write_iface()
|
||||
|
||||
shell_config_set "$ifacedir/options" TYPE eth
|
||||
|
||||
[ -n "$in_dhcp" ] &&
|
||||
shell_config_set \
|
||||
"$ifacedir/options" \
|
||||
BOOTPROTO \
|
||||
$(test_bool "$in_dhcp" && echo "dhcp" || echo "static")
|
||||
case "$in_configuration" in
|
||||
off)
|
||||
shell_config_set "$ifacedir/options" DISABLED yes
|
||||
;;
|
||||
static)
|
||||
shell_config_set "$ifacedir/options" DISABLED no
|
||||
shell_config_set "$ifacedir/options" BOOTPROTO static
|
||||
;;
|
||||
dhcp)
|
||||
shell_config_set "$ifacedir/options" DISABLED no
|
||||
shell_config_set "$ifacedir/options" BOOTPROTO dhcp
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -n "$in_hw_binding" ] &&
|
||||
write_hw_binding "$name" "$in_hw_binding"
|
||||
@ -255,21 +284,24 @@ on_message()
|
||||
case "${in__objects##*/}" in
|
||||
avail_masks) list_mask ;;
|
||||
avail_hw_bindings) list_hw_binding ;;
|
||||
avail_configurations) list_configuration ;;
|
||||
*) list_iface;;
|
||||
esac
|
||||
echo ')'
|
||||
;;
|
||||
read)
|
||||
echo "("
|
||||
local name="$in__objects"
|
||||
[ "$name" == "/" ] || read_iface "$name"
|
||||
local name="${in_ifname}"
|
||||
[ -n "$name" ] || name="$(iflist|cut -f1 -d' '|head -n1)"
|
||||
printf 'ifname "%s"' "$name"
|
||||
read_iface "$name"
|
||||
echo ")"
|
||||
;;
|
||||
write)
|
||||
local name="${in__objects}"
|
||||
[ "$name" == "/" ] || write_iface "$name"
|
||||
test_bool "$in_commit" && commit_iface
|
||||
test_bool "$in_reset" && reset_iface
|
||||
local name="${in_ifname}"
|
||||
write_iface "$name"
|
||||
[ -n "$in_commit" ] && commit_iface
|
||||
[ -n "$in_reset" ] && reset_iface
|
||||
write_nop
|
||||
;;
|
||||
*)
|
||||
|
@ -8,58 +8,55 @@
|
||||
(define *avail-ifaces* (make-cell '()))
|
||||
(define *avail-masks* (make-cell '()))
|
||||
(define *avail-hw-bindings* (make-cell '()))
|
||||
(define *avail-configurations* (make-cell '()))
|
||||
|
||||
(define *prev-current* (make-cell 0))
|
||||
|
||||
(define (prev-interface)
|
||||
(car (list-ref (cell-ref *avail-ifaces*) (cell-ref *prev-current*))))
|
||||
|
||||
(define (mask-index cmd)
|
||||
(or (string-list-index (woo-get-option cmd 'mask "24") (map car (cell-ref *avail-masks*)))
|
||||
0))
|
||||
|
||||
(define (hw-binding-index cmd)
|
||||
(format #t "cmd=~S,list=~S~%" (woo-get-option cmd 'hw_binding) (map car (cell-ref *avail-hw-bindings*)))
|
||||
(or (string-list-index (woo-get-option cmd 'hw_binding) (map car (cell-ref *avail-hw-bindings*)))
|
||||
0))
|
||||
|
||||
(define (current-interface)
|
||||
(let ((c (ifaces current)))
|
||||
(and (number? c)
|
||||
(>= c 0)
|
||||
(car (list-ref (cell-ref *avail-ifaces*) c)))))
|
||||
|
||||
(define (current-mask)
|
||||
(let ((c (iface-mask current)))
|
||||
(define (param-index cmd param list)
|
||||
(or (string-list-index (woo-get-option cmd param) (map car (cell-ref list)))
|
||||
0))
|
||||
|
||||
(define (param-value w list)
|
||||
(let ((c (w current)))
|
||||
(if (>= c 0)
|
||||
(car (list-ref (cell-ref *avail-masks*) c))
|
||||
(car (list-ref (cell-ref list) c))
|
||||
"")))
|
||||
|
||||
(define (current-hw-binding)
|
||||
(let ((c (iface-hw-binding current)))
|
||||
(if (>= c 0)
|
||||
(car (list-ref (cell-ref *avail-hw-bindings*) c))
|
||||
"")))
|
||||
(define (param-init path widget list)
|
||||
(let ((data (woo-list/name+label path)))
|
||||
(cell-set! list data)
|
||||
(widget rows (map cdr data))))
|
||||
|
||||
(define (read-interface name)
|
||||
(and (not-empty-string? name)
|
||||
(let ((cmd (woo-read-first (string-append "/net-eth" "/" name))))
|
||||
(let ((cmd (woo-read-first "/net-eth" 'ifname name)))
|
||||
(iface-info text (string-append "<small>(" (woo-get-option cmd 'info) ")</small>"))
|
||||
(iface-dhcp state (woo-get-option cmd 'dhcp #f) toggled)
|
||||
(iface-ip text (woo-get-option cmd 'ip))
|
||||
(iface-mask current (mask-index cmd))
|
||||
(iface-hw-binding current (hw-binding-index cmd))
|
||||
(iface-mask current (param-index cmd 'mask *avail-masks*))
|
||||
(iface-hw-binding current (param-index cmd 'hw_binding *avail-hw-bindings*))
|
||||
(iface-configuration current (param-index cmd 'configuration *avail-configurations*))
|
||||
(iface-configuration selected)
|
||||
(w-button activity (woo-get-option cmd 'wireless))
|
||||
(iface-gw text (woo-get-option cmd 'default)))))
|
||||
|
||||
(define (write-interface path name)
|
||||
(and (not-empty-string? name)
|
||||
(woo-write/constraints
|
||||
(string-append path "/" name)
|
||||
'dhcp (iface-dhcp state)
|
||||
(woo-write/constraints
|
||||
path
|
||||
'ifname name
|
||||
'ip (iface-ip text)
|
||||
'mask (current-mask)
|
||||
'hw_binding (current-hw-binding)
|
||||
'mask (param-value iface-mask *avail-masks*)
|
||||
'hw_binding (param-value iface-hw-binding *avail-hw-bindings*)
|
||||
'configuration (param-value iface-configuration *avail-configurations*)
|
||||
'default (iface-gw text))))
|
||||
|
||||
(define (commit-interface)
|
||||
@ -76,14 +73,12 @@
|
||||
(woo-catch/message
|
||||
(thunk
|
||||
(woo-write "/net-eth" 'reset #t)
|
||||
(and (global 'frame:next)
|
||||
(woo-write "/net-eth" 'reset #t))
|
||||
(let ((avail-masks (woo-list/name+label "/net-eth/eth0/avail_masks")))
|
||||
(cell-set! *avail-masks* avail-masks)
|
||||
(iface-mask rows (map cdr avail-masks)))
|
||||
(let ((avail-hw-bindings (woo-list/name+label "/net-eth/eth0/avail_hw_bindings")))
|
||||
(cell-set! *avail-hw-bindings* avail-hw-bindings)
|
||||
(iface-hw-binding rows (map cdr avail-hw-bindings)))
|
||||
(and (global 'frame:next) (woo-write "/net-eth" 'reset #t))
|
||||
|
||||
(param-init "/net-eth/avail_masks" iface-mask *avail-masks*)
|
||||
(param-init "/net-eth/avail_hw_bindings" iface-hw-binding *avail-hw-bindings*)
|
||||
(param-init "/net-eth/avail_configurations" iface-configuration *avail-configurations*)
|
||||
|
||||
(let ((avail-ifaces (woo-list/name+label "/net-eth")))
|
||||
(cell-set! *avail-ifaces* avail-ifaces)
|
||||
(ifaces rows (map cdr avail-ifaces))
|
||||
@ -118,15 +113,16 @@
|
||||
|
||||
;;
|
||||
(spacer)
|
||||
(label (_ "Configuration") align "right")
|
||||
(document:id iface-configuration (combobox
|
||||
(when selected
|
||||
((widgets iface-ip
|
||||
iface-mask
|
||||
iface-gw)
|
||||
activity (string=? (param-value iface-configuration *avail-configurations*)
|
||||
"static")))))
|
||||
(spacer)
|
||||
(document:id iface-dhcp (checkbox (_ "Use DHCP")
|
||||
(when toggled
|
||||
((widgets iface-ip
|
||||
iface-gw
|
||||
iface-mask)
|
||||
activity (not (iface-dhcp state))))))
|
||||
(spacer)
|
||||
|
||||
|
||||
;;
|
||||
(spacer)
|
||||
(label (_ "IP address") align "right")
|
||||
|
Loading…
x
Reference in New Issue
Block a user