ui: Cleanup IP configuration in 'static' mode

In case of other then 'static' we are show current configuration
(IP addresses, default gateway, DNS). When confuguration is changed
to static we should clean this data, otherwise it is confused users.
See ALT bug #48920.
This commit is contained in:
Mikhail Efremov 2024-01-12 20:33:03 +03:00
parent e8999d3f66
commit 283726c03e
2 changed files with 74 additions and 25 deletions

View File

@ -3,6 +3,7 @@
:use-module (alterator ajax) :use-module (alterator ajax)
:use-module (alterator algo) :use-module (alterator algo)
:use-module (alterator woo) :use-module (alterator woo)
:use-module (alterator str)
:export (init)) :export (init))
;;; low level ;;; low level
@ -46,6 +47,16 @@
(form-update-enum "addresses" (form-update-enum "addresses"
(woo-list "/net-eth/list_current_iface_address" 'name name 'ipv (form-value "ipv")))))) (woo-list "/net-eth/list_current_iface_address" 'name name 'ipv (form-value "ipv"))))))
(define (update-interface-ipconfig name cmd)
(form-update-value-list
'("dns" "search" "addresses" "add-mask" "default") cmd)
(if (string=? (woo-get-option cmd 'configuration) "static")
(read-interface-address name)
(read-interface-current-address name))
)
(define (read-interface name ipv) (define (read-interface name ipv)
(let* ((cmd (woo-read-first "/net-eth" 'name name 'ipv ipv 'language (form-value "language"))) (let* ((cmd (woo-read-first "/net-eth" 'name name 'ipv ipv 'language (form-value "language")))
(iface-type (woo-get-option cmd 'iface_type "eth")) (iface-type (woo-get-option cmd 'iface_type "eth"))
@ -91,22 +102,39 @@
has-wifi-module has-wifi-module
(woo-get-option cmd 'wireless) (woo-get-option cmd 'wireless)
(string=? (woo-get-option cmd 'controlled) "etcnet"))) (string=? (woo-get-option cmd 'controlled) "etcnet")))
(form-update-value-list
'("name" "ipv_enabled") (form-update-value-list
cmd) '("name" "ipv_enabled" "computer_name")
(form-update-value-list
'("computer_name" "dns" "search")
cmd) cmd)
(form-update-activity "computer_name" (not (woo-get-option cmd 'altdomain))) (form-update-activity "computer_name" (not (woo-get-option cmd 'altdomain)))
(if (string=? (woo-get-option cmd 'configuration) "static")
(read-interface-address name)
(read-interface-current-address name))
(form-update-value-list (form-update-value-list
'("iface_info" "add-mask" "default" "configuration" "controlled") '("configuration" "controlled")
cmd) cmd)
(update-ipv-activity))) (update-interface-ipconfig name cmd)
(update-ipv-activity)
)
)
(define (configuration_changed)
(let ((name (form-value "name"))
(ipv (form-value "ipv"))
(configuration (form-value "configuration")))
(if (string=? configuration "static")
(begin
(form-update-enum "addresses" '())
(form-update-value "add-mask" (if (string=? ipv "4") "24" "64"))
(form-update-value "default" "")
(form-update-value "dns" "")
(form-update-value "search" ""))
(begin
(catch/message
(lambda() (update-interface-ipconfig name (woo-read-first "/net-eth" 'name name 'ipv ipv)))))
)
(update-configuration-activity configuration (form-value "controlled"))
)
)
(define (write-interface name ipv) (define (write-interface name ipv)
(apply woo-write (apply woo-write
@ -233,7 +261,7 @@
(form-bind "name" "change" update-interface) (form-bind "name" "change" update-interface)
(form-bind "ipv" "change" ipv_changed) (form-bind "ipv" "change" ipv_changed)
(form-bind "ipv_enabled" "change" update-ipv-activity) (form-bind "ipv_enabled" "change" update-ipv-activity)
(form-bind "configuration" "change" (lambda() (update-configuration-activity (form-value "configuration") (form-value "controlled")))) (form-bind "configuration" "change" configuration_changed)
(form-bind "wireless" "click" wireless-interface) (form-bind "wireless" "click" wireless-interface)
(form-bind "advanced" "click" advanced-interface) (form-bind "advanced" "click" advanced-interface)
(form-bind "vlan" "click" vlan-interface) (form-bind "vlan" "click" vlan-interface)

View File

@ -40,6 +40,16 @@
(form-update-enum "addresses" (form-update-enum "addresses"
(woo-list "/net-eth/list_current_iface_address" 'name name 'ipv (form-value "ipv")))))) (woo-list "/net-eth/list_current_iface_address" 'name name 'ipv (form-value "ipv"))))))
(define (update-interface-ipconfig name cmd)
(form-update-value-list
'("dns" "search" "addresses" "add-mask" "default") cmd)
(if (string=? (woo-get-option cmd 'configuration) "static")
(read-interface-address name)
(read-interface-current-address name))
)
(define (read-interface name ipv) (define (read-interface name ipv)
(let* ((cmd (woo-read-first "/net-eth" 'name name 'ipv ipv)) (let* ((cmd (woo-read-first "/net-eth" 'name name 'ipv ipv))
(iface-type (woo-get-option cmd 'iface_type "eth")) (iface-type (woo-get-option cmd 'iface_type "eth"))
@ -87,27 +97,38 @@
'("iface_info" "advanced")) '("iface_info" "advanced"))
(form-update-value-list (form-update-value-list
'("name" "ipv_enabled") '("name" "ipv_enabled" "computer_name" "iface_info")
cmd)
(form-update-value-list
'("computer_name" "dns" "search")
cmd) cmd)
(form-update-activity "computer_name" (not (woo-get-option cmd 'altdomain))) (form-update-activity "computer_name" (not (woo-get-option cmd 'altdomain)))
(form-update-value-list
'("add-mask" "iface_info" "default" "configuration")
cmd)
(if (string=? (woo-get-option cmd 'configuration) "static")
(read-interface-address name)
(read-interface-current-address name))
(form-update-value-list (form-update-value-list
'("configuration" "controlled") '("configuration" "controlled")
cmd) cmd)
(update-ipv-activity) (update-interface-ipconfig name cmd)
(update-ipv-activity)
) )
) )
(define (configuration_changed)
(let ((name (form-value "name"))
(ipv (form-value "ipv"))
(configuration (form-value "configuration")))
(if (string=? configuration "static")
(begin
(form-update-enum "addresses" '())
(form-update-value "add-mask" (if (string=? ipv "4") "24" "64"))
(form-update-value "default" "")
(form-update-value "dns" "")
(form-update-value "search" ""))
(begin
(catch/message
(lambda() (update-interface-ipconfig name (woo-read-first "/net-eth" 'name name 'ipv ipv)))))
)
(update-configuration-activity configuration (form-value "controlled"))
)
)
(define (write-interface name ipv) (define (write-interface name ipv)
(apply woo-write (apply woo-write
"/net-eth" "/net-eth"
@ -346,7 +367,7 @@
(form-bind "name" "change" update-interface) (form-bind "name" "change" update-interface)
(form-bind "ipv" "change" ipv_changed) (form-bind "ipv" "change" ipv_changed)
(form-bind "ipv_enabled" "change" update-ipv-activity) (form-bind "ipv_enabled" "change" update-ipv-activity)
(form-bind "configuration" "change" (lambda() (update-configuration-activity (form-value "configuration") (form-value "controlled")))) (form-bind "configuration" "change" configuration_changed)
(form-bind "wireless" "click" wireless-interface) (form-bind "wireless" "click" wireless-interface)
(form-bind "advanced" "click" advanced-interface) (form-bind "advanced" "click" advanced-interface)
(form-bind "vlan" "click" vlan-interface) (form-bind "vlan" "click" vlan-interface)