VLAN for qt/x11
This commit is contained in:
parent
ded9da8455
commit
05dc221336
@ -847,6 +847,9 @@ list_host_vlans() {
|
||||
|
||||
host="$in_name"
|
||||
|
||||
# signle line, like true enum
|
||||
local single="$1"
|
||||
|
||||
if [ -z "$host" ]; then
|
||||
return
|
||||
fi
|
||||
@ -864,8 +867,13 @@ list_host_vlans() {
|
||||
continue
|
||||
fi
|
||||
|
||||
# Ajax has alterator-listbox multi-select, qt/x11 doesn't
|
||||
if [ "$iface_host" = "$host" ]; then
|
||||
if [ -z "$single" ]; then
|
||||
write_table_item "name" "$i" "list_vlan_name" "$i" "list_vlan_id" "$vid"
|
||||
else
|
||||
write_enum_item "$i" "$i -- $vid"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -978,6 +986,11 @@ vlan_edit() {
|
||||
return
|
||||
fi
|
||||
|
||||
if ! ( [ -n "${vid##0*}" -a -n "${vid##*[!0-9]*}" ] && [ "$vid" -gt 0 ] 2>/dev/null ); then
|
||||
write_error "`_ "Bad VLAN ID: $vid"`"
|
||||
return
|
||||
fi
|
||||
|
||||
local ifacedir=
|
||||
|
||||
# If doesn't exist return /etc/net
|
||||
@ -986,6 +999,7 @@ vlan_edit() {
|
||||
if ! [ "$old" = "$new" ] && [ -d "$ifacedir" ] && ! [ -e "$ifacedir/REMOVED" ]; then
|
||||
# already exists
|
||||
# can't rename to already existed interface
|
||||
write_error "`_ "Already existed: $new"`"
|
||||
return
|
||||
fi
|
||||
|
||||
@ -1034,6 +1048,11 @@ vlan_add_new() {
|
||||
return
|
||||
fi
|
||||
|
||||
if ! ( [ -n "${vid##0*}" -a -n "${vid##*[!0-9]*}" ] && [ "$vid" -gt 0 ] 2>/dev/null ); then
|
||||
write_error "`_ "Bad VLAN ID: $vid"`"
|
||||
return
|
||||
fi
|
||||
|
||||
local ifacedir=
|
||||
|
||||
# If doesn't exist return /etc/net
|
||||
@ -1041,6 +1060,7 @@ vlan_add_new() {
|
||||
|
||||
if [ -d "$ifacedir" ] && ! [ -e "$ifacedir/REMOVED" ]; then
|
||||
# Can't add already exists
|
||||
write_error "`_ "Already existed: $name"`"
|
||||
return
|
||||
fi
|
||||
|
||||
@ -1134,6 +1154,7 @@ on_message()
|
||||
avail_controlled) list_controlled "$in_bridge";;
|
||||
avail_iface_address) list_iface_addresses "$(name_with_bridge "$in_name")" "$in_ipv";;
|
||||
list_host_vlans) list_host_vlans;;
|
||||
list_host_vlans_single) list_host_vlans "single_line_on" ;;
|
||||
list_host_vlans2) list_host_vlans2;;
|
||||
list_vlans) list_vlans_cached|write_enum;;
|
||||
# avail_ifaces
|
||||
|
@ -21,15 +21,20 @@
|
||||
(lambda()
|
||||
(let* ((cmd (woo-read-first "/net-eth" 'name name))
|
||||
(has_infant_vlans (woo-get-option cmd 'has_infant_vlans #f))
|
||||
(is_bridge (woo-get-option cmd 'bridge)))
|
||||
(is_bridge (woo-get-option cmd 'bridge))
|
||||
(is_etcnet (if (string-ci=? (woo-get-option cmd 'controlled) "etcnet") #t #f))
|
||||
(is_wireless (woo-get-option cmd 'wireless #f)))
|
||||
(form-update-enum "controlled" (woo-list "/net-eth/avail_controlled" 'bridge is_bridge))
|
||||
(form-update-value "iface" name)
|
||||
(form-update-visibility "area-vlan-list" has_infant_vlans)
|
||||
(form-update-visibility "area-vlan-edit" has_infant_vlans)
|
||||
(form-update-visibility "area-vlan" (and is_etcnet (not is_wireless)))
|
||||
(form-update-visibility "area-vlan-list" (and is_etcnet has_infant_vlans))
|
||||
(form-update-visibility "area-vlan-edit" (and is_etcnet has_infant_vlans))
|
||||
(form-update-activity "bridge" (not has_infant_vlans))
|
||||
(form-update-activity "controlled" (not has_infant_vlans))
|
||||
(form-update-visibility "label_bridge" has_infant_vlans)
|
||||
(form-update-value-list '("name" "controlled" "bridge") cmd)
|
||||
|
||||
|
||||
; VLAN
|
||||
(and
|
||||
has_infant_vlans
|
||||
@ -37,19 +42,22 @@
|
||||
; FILL LISTS
|
||||
(for-each
|
||||
(lambda(lst)
|
||||
(let ((data (woo-list (string-append "/net-eth/" lst)
|
||||
'name name
|
||||
(let* ((name (car lst))
|
||||
(select_first (car (cdr lst)))
|
||||
(data (woo-list (string-append "/net-eth/" name)
|
||||
'name *name*
|
||||
'language (form-value "language"))))
|
||||
(form-update-enum lst data)
|
||||
(form-update-enum name data)
|
||||
; take first, make it active
|
||||
(and
|
||||
select_first
|
||||
(pair? data)
|
||||
; select first item only for general enums, not multi-select lists
|
||||
(= (length (car data)) 5)
|
||||
(let ((xxx (woo-get-option (car data) 'name)))
|
||||
(form-update-value lst (if (string? xxx) xxx ""))))
|
||||
))
|
||||
'("list_host_vlans" "list_host_vlans2"))
|
||||
'(("list_host_vlans" #f) ("list_host_vlans2" #t)))
|
||||
|
||||
; REBIND ACTIONS ON LISTS
|
||||
;(form-bind "list_host_vlans2" "change" vlan_selected)
|
||||
|
@ -36,7 +36,7 @@
|
||||
<hr style="min-width:550px; width:1%"/>
|
||||
<!-- VLAN: ADD NEW -->
|
||||
<div align="center" name="area-vlan-add" style="width:100%;">
|
||||
<h2><span translate="_">Add new child VLAN interface</span></h2>
|
||||
<b><span translate="_">Add new child VLAN interface</span></b><br/>
|
||||
<span style="white-space: nowrap;">
|
||||
<span translate="_">Name for new interface:</span>
|
||||
<input type="text" class="text" name="vlan_new_name"/>
|
||||
@ -48,7 +48,7 @@
|
||||
</div>
|
||||
<!-- VLAN: LIST -->
|
||||
<div align="center" name="area-vlan-list" style="width:100%;">
|
||||
<h2><span translate="_">List of infant VLAN interfaces</span></h2>
|
||||
<b><span translate="_">List of infant VLAN interfaces</span></b><br/>
|
||||
<table name="list_host_vlans" class="alterator-listbox multi-select" style="min-width:550px; width:1%">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -68,7 +68,7 @@
|
||||
</div>
|
||||
<!-- VLAN: EDIT -->
|
||||
<div align="center" name="area-vlan-edit" style="width:100%;">
|
||||
<h2><span translate="_">Edit current VLAN interface</span></h2>
|
||||
<b><span translate="_">Edit current VLAN interface</span></b><br/>
|
||||
<span style="white-space: nowrap;">
|
||||
<select name="list_host_vlans2" style="min-width:100px;"></select>
|
||||
<span translate="_">Rename to:</span>
|
||||
|
@ -2,15 +2,133 @@
|
||||
|
||||
(define *name* (global 'name))
|
||||
|
||||
|
||||
; DEBUG STRING (PASTE IN FOR YOUR NEEDS).
|
||||
; (format #t "XXX: ~S\n" rdp_profile_name)
|
||||
; (format #t "[ajax, module] action info\n")
|
||||
|
||||
; TO DEBUG DO:
|
||||
; 1) define *debug* to #t
|
||||
; 2) start ahttpd -l -d
|
||||
(define *debug* #f)
|
||||
(define (dmsg msg . args)
|
||||
(if *debug*
|
||||
(format #t "[ajax, net-eth-advanced]: ~S ~S\n" msg args)))
|
||||
|
||||
;;; Functions
|
||||
(define (ui-read)
|
||||
(catch/message
|
||||
(lambda()
|
||||
(let* ((cmd (woo-read-first "/net-eth" 'name *name*))
|
||||
(is_bridge (woo-get-option cmd 'bridge)))
|
||||
(has_infant_vlans (woo-get-option cmd 'has_infant_vlans #f))
|
||||
(is_bridge (woo-get-option cmd 'bridge))
|
||||
(is_etcnet (if (string-ci=? (woo-get-option cmd 'controlled) "etcnet") #t #f))
|
||||
(is_wireless (woo-get-option cmd 'wireless #f)))
|
||||
(form-update-enum "controlled" (woo-list "/net-eth/avail_controlled" 'bridge is_bridge))
|
||||
(form-update-visibility "area-vlan" (and is_etcnet (not is_wireless)))
|
||||
(form-update-visibility "area-vlan-list" (and is_etcnet has_infant_vlans))
|
||||
(form-update-visibility "area-vlan-edit" (and is_etcnet has_infant_vlans))
|
||||
(form-update-visibility "label_bridge" has_infant_vlans)
|
||||
(form-update-activity "bridge" (not has_infant_vlans))
|
||||
(form-update-activity "controlled" (not has_infant_vlans))
|
||||
(form-update-value-list '("name" "controlled" "bridge") cmd)
|
||||
|
||||
; VLAN
|
||||
(and
|
||||
has_infant_vlans
|
||||
|
||||
; FILL LISTS
|
||||
(for-each
|
||||
(lambda(lst)
|
||||
(let* ((name (car lst))
|
||||
(select_first (car (cdr lst)))
|
||||
(data (woo-list (string-append "/net-eth/" name)
|
||||
'name *name*
|
||||
'language (form-value "language"))))
|
||||
(form-update-enum name data)
|
||||
; take first, make it active
|
||||
(and
|
||||
select_first
|
||||
(pair? data)
|
||||
; select first item only for general enums, not multi-select lists
|
||||
(= (length (car data)) 5)
|
||||
(let ((xxx (woo-get-option (car data) 'name)))
|
||||
(form-update-value lst (if (string? xxx) xxx ""))))
|
||||
))
|
||||
'(("list_host_vlans_single" #f) ("list_host_vlans2" #t)))
|
||||
|
||||
; REBIND ACTIONS ON LISTS
|
||||
(form-bind "list_host_vlans2" "change" vlan_selected)
|
||||
|
||||
; RESET INTERFACE
|
||||
(for-each (lambda(p) (form-update-value p ""))
|
||||
'("vlan_new_name"
|
||||
"vlan_new_vid"))
|
||||
|
||||
(vlan_selected))))))
|
||||
|
||||
; REMOVE SELECTED VLAN INTERFACES
|
||||
(define (vlan-remove-selected)
|
||||
|
||||
(dmsg "vlan-remove-selected() -- enter")
|
||||
|
||||
(catch/message
|
||||
(lambda()
|
||||
(woo "vlan_remove_infants" "/net-eth"
|
||||
'name (form-value "name")
|
||||
'infants (form-value "list_host_vlans_single"))))
|
||||
|
||||
(ui-read))
|
||||
|
||||
|
||||
; ADD NEW VLAN INTERFACE FOR SELECTED HOST
|
||||
(define (vlan-add-new)
|
||||
|
||||
(dmsg "vlan-add-new() -- enter")
|
||||
|
||||
(catch/message
|
||||
(lambda()
|
||||
(woo "vlan_add_new" "/net-eth"
|
||||
'name (form-value "name")
|
||||
'vlan_new_name (form-value "vlan_new_name")
|
||||
'vlan_new_vid (form-value "vlan_new_vid"))))
|
||||
|
||||
(ui-read))
|
||||
|
||||
|
||||
; VLAN EDIT
|
||||
(define (vlan-edit)
|
||||
|
||||
(dmsg "vlan-edit() -- enter")
|
||||
|
||||
(catch/message
|
||||
(lambda()
|
||||
(woo "vlan_edit" "/net-eth"
|
||||
'name (form-value "name")
|
||||
'vlan_old_name (form-value "list_host_vlans2")
|
||||
'vlan_new_name (form-value "vlan_new_name_edit")
|
||||
'vlan_new_vid (form-value "vlan_new_vid_edit"))))
|
||||
|
||||
(ui-read))
|
||||
|
||||
|
||||
; REACT TO SELECTED VLAN
|
||||
(define (vlan_selected)
|
||||
|
||||
(dmsg "vlan_selected() -- enter")
|
||||
|
||||
(let ((vlan (form-value "list_host_vlans2")))
|
||||
(if (not (string-null? vlan))
|
||||
(catch/message
|
||||
(lambda()
|
||||
(let* ((cmd (woo "vlan_info" "/net-eth" 'name vlan))
|
||||
(vid (woo-get-option (car cmd) 'vid))
|
||||
(host (woo-get-option (car cmd) 'host))
|
||||
(name (woo-get-option (car cmd) 'name)))
|
||||
(form-update-value "vlan_new_name_edit" name)
|
||||
(form-update-value "vlan_new_vid_edit" vid)))))))
|
||||
|
||||
|
||||
(form-update-value-list '("name" "controlled" "bridge") cmd)))))
|
||||
|
||||
(define (ui-exit)
|
||||
(document:end))
|
||||
@ -38,7 +156,7 @@
|
||||
;;; UI
|
||||
|
||||
width 600
|
||||
height 300
|
||||
height 500
|
||||
|
||||
(gridbox
|
||||
columns "0;100"
|
||||
@ -53,7 +171,8 @@ height 300
|
||||
(combobox name "controlled")
|
||||
;;
|
||||
(label text (_ "Use interface as bridge") align "right" name "bridge")
|
||||
(checkbox name "bridge")
|
||||
(hbox align "left" (checkbox name "bridge")
|
||||
(label text (_ "- remove infants to change") name "label_bridge"))
|
||||
;;
|
||||
(label colspan 2)
|
||||
|
||||
@ -63,10 +182,53 @@ height 300
|
||||
(button (_ "OK") name "ok")
|
||||
(button (_ "Cancel") name "cancel")))
|
||||
|
||||
;;
|
||||
(vbox colspan 2 align "center" name "area-vlan"
|
||||
(separator)
|
||||
(label align "center" text (bold (_ "Add new child VLAN interface")))
|
||||
(hbox
|
||||
(label text (_ "Name for new interface:"))
|
||||
(edit name "vlan_new_name")
|
||||
(label text (_ "VID (1-4095):"))
|
||||
(edit name "vlan_new_vid")
|
||||
(button (_ "Add") name "btn_vlan_add_new")
|
||||
))
|
||||
|
||||
(separator)
|
||||
|
||||
;;
|
||||
(vbox colspan 2 align "center" name "area-vlan-list"
|
||||
(label align "center" text (bold (_ "List of infant VLAN interfaces")))
|
||||
|
||||
(document:id vlans (checklistbox name "list_host_vlans_single"))
|
||||
(vlans columns 1)
|
||||
(vlans header (vector (_ "Infant interface name -- VLAN ID")))
|
||||
|
||||
; form-update-enum
|
||||
|
||||
(button (_ "Remove selected vlans") align "center" name "btn_remove_selected_vlans"))
|
||||
|
||||
;;
|
||||
(separator)
|
||||
|
||||
;;
|
||||
(hbox colspan 2 align "center" name "area-vlan-edit"
|
||||
(combobox name "list_host_vlans2")
|
||||
(label text (_ "Rename to:"))
|
||||
(edit name "vlan_new_name_edit")
|
||||
(label text (_ "VID (1-4095):"))
|
||||
(edit name "vlan_new_vid_edit")
|
||||
(button (_ "Save") align "center" name "btn_vlan_edit"))
|
||||
|
||||
|
||||
;;
|
||||
(document:root
|
||||
(when loaded
|
||||
(ui-read)
|
||||
(form-bind "bridge" "change" bridge-changed)
|
||||
(form-bind "list_host_vlans2" "change" vlan_selected)
|
||||
(form-bind "btn_remove_selected_vlans" "click" vlan-remove-selected)
|
||||
(form-bind "btn_vlan_add_new" "click" vlan-add-new)
|
||||
(form-bind "btn_vlan_edit" "click" vlan-edit)
|
||||
(form-bind "ok" "click" ui-write)
|
||||
(form-bind "cancel" "click" ui-exit)))
|
||||
|
@ -36,11 +36,28 @@
|
||||
(woo-list "/net-eth/avail_iface_address" 'name name 'ipv (form-value "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"))
|
||||
(is-vlan (if (string-ci=? iface-type "etcnet") #t #f)))
|
||||
(form-update-visibility
|
||||
"wireless"
|
||||
(and (woo-get-option cmd 'wireless)
|
||||
(string=? (woo-get-option cmd 'controlled) "etcnet")))
|
||||
|
||||
(for-each
|
||||
(lambda(lst)
|
||||
(form-update-visibility lst is-vlan))
|
||||
'("box_vlan_caption" "box_vlan_info"))
|
||||
|
||||
(for-each
|
||||
(lambda(lst)
|
||||
(form-update-visibility lst (not is-vlan)))
|
||||
'("adaptor" "advanced" "wireless"))
|
||||
|
||||
(form-update-value-list
|
||||
'("label_vlan_host" "label_vlan_vid")
|
||||
cmd)
|
||||
|
||||
(form-update-value-list
|
||||
'("name" "real_name" "ipv_enabled")
|
||||
cmd)
|
||||
@ -76,7 +93,9 @@
|
||||
(form-update-enum "add-mask" (woo-list "/net-eth/avail_masks" 'ipv ipv))
|
||||
(form-update-value "add-mask" (if (string=? ipv "4") "24" "64"))
|
||||
(form-update-enum "configuration" (woo-list "/net-eth/avail_configurations" 'ipv ipv))
|
||||
(form-update-enum "name" (woo-list "/net-eth/avail_ifaces")))
|
||||
(form-update-enum "name" (append
|
||||
(woo-list "/net-eth/avail_ifaces")
|
||||
(woo-list "/net-eth/list_vlans"))))
|
||||
|
||||
(define (reset-interface)
|
||||
(catch/message
|
||||
@ -110,7 +129,9 @@
|
||||
(write-interface name ipv)))
|
||||
(begin
|
||||
(form-popup "/net-eth/advanced" 'name name)
|
||||
(form-update-enum "name" (woo-list "/net-eth/avail_ifaces"))
|
||||
(form-update-enum "name" (append
|
||||
(woo-list "/net-eth/avail_ifaces")
|
||||
(woo-list "/net-eth/list_vlans")))
|
||||
(read-interface name ipv)
|
||||
(form-update-value "prev_name" (or (form-value "name") ""))))))
|
||||
|
||||
@ -161,6 +182,16 @@
|
||||
;;
|
||||
(textbox colspan 2 name "adaptor" max-height 70 alterability #f)
|
||||
|
||||
;;
|
||||
(label colspan 2 text (bold (_ "VLAN")) align "center" nameref "box_vlan_caption")
|
||||
|
||||
;;
|
||||
(hbox colspan 2 align "center" nameref "box_vlan_info"
|
||||
(label text (_ "Host:"))
|
||||
(label name "label_vlan_host")
|
||||
(label text (_ "VID:"))
|
||||
(label name "label_vlan_vid"))
|
||||
|
||||
;;
|
||||
(hbox align "left" colspan 2
|
||||
(label text (_ "Select IP version:"))
|
||||
@ -239,3 +270,5 @@
|
||||
|
||||
(frame:on-back (lambda() (or (commit-interface) 'cancel)))
|
||||
(frame:on-next (lambda() (or (commit-interface) 'cancel)))
|
||||
|
||||
; vim: ft=lisp expandtab
|
||||
|
Loading…
x
Reference in New Issue
Block a user