Configuration reading is backwards compatible with old configurations (.imn).
Bug found by:
Submitted by:
Requested by:
Reviewed by:
Approved by:
Obtained from:
}
dumpputs $method $dest " \}"
} elseif { "[lindex $element 0]" == "custom-config" } {
- dumpputs $method $dest " custom-config \{"
- foreach line [lindex $element 1] {
- dumpputs $method $dest " $line"
- }
+ dumpputs $method $dest " custom-config \{"
+ foreach line [lindex $element 1] {
+ if { $line != {} } {
+ set str [lindex $line 0]
+ if { $str == "custom-config" } {
+ dumpputs $method $dest " config \{"
+ foreach element [lindex $line 1] {
+ dumpputs $method $dest " $element"
+ }
+ dumpputs $method $dest " \}"
+ } else {
+ dumpputs $method $dest " $line"
+ }
+ }
+ }
dumpputs $method $dest " \}"
} elseif { "[lindex $element 0]" == "ipsec-config" } {
dumpputs $method $dest " ipsec-config \{"
custom-command {
lappend $object "custom-command {$value}"
}
- add-custom-command {
- lappend $object "add-custom-command {$value}"
- }
custom-config {
set cfg ""
+
foreach zline [split $value {
}] {
if { [string index "$zline" 0] == " " } {
set zline [string replace "$zline" 0 0]
}
lappend cfg $zline
- }
+ }
set cfg [lrange $cfg 1 [expr [llength $cfg] - 2]]
lappend $object "custom-config {$cfg}"
}
- add-custom-config {
- lappend $object "add-custom-config {$value}"
- }
ipsec-enabled {
lappend $object "ipsec-enabled $value"
}
ipsec-config {
set cfg ""
- lappend cfg "name $value"
foreach zline [split $value {
}] {
if { [string index "$zline" 0] == " " } {
button $wi.custom.cfg.generate -text "Generate" \
-command "cfgGenerate $target"
button $wi.custom.cfg.edit -text "Edit" \
- -command "editStartupCfg $target"
+ -command "editStartupCfg $target 0"
button $wi.custom.cfg.clear -text "Clear" \
- -command "setCustomConfig $target {}"
+ -command "setCustomConfig $target {} {} {} 0"
pack $wi.custom.cfg.generate $wi.custom.cfg.edit \
$wi.custom.cfg.clear -side left
# * node_id -- node id
#****
proc cfgGenerate { node } {
- setCustomConfig $node [[typemodel $node].cfggen $node]
- setCustomCmd $node [[typemodel $node].bootcmd $node]
+ set id "generic"
+ set cmd [[typemodel $node].bootcmd $node]
+ set cfg [[typemodel $node].cfggen $node]
+ setCustomConfig $node $id $cmd $cfg 0
}
# Creates an edit startup configuration dialog box.
# INPUTS
# * node_id -- node id
+# * deleted -- if deleted is set to 1, editStartupCfg
+# has been invoked after deleting custom-config
+# with specified custom-config-id.
#****
-proc editStartupCfg { node } {
+proc editStartupCfg { node deleted } {
+
+ set customCfgList ""
+ set customCfgList [getCustomConfig $node]
+ set customidlist {}
+ foreach customCfg $customCfgList {
+ set customid [lindex [lsearch -inline $customCfg \
+ "custom-config-id *"] 1]
+ lappend customidlist $customid
+ }
+
+ global viewcustomid
+ set edit 1
+ if { $deleted == "1" } {
+ set viewcustomid [lindex $customidlist 0]
+ }
+
+ if { $customidlist == "" } {
+ set warning "Custom config list is empty."
+ tk_messageBox -message $warning -type ok -icon warning \
+ -title "Custom configuration warning"
+ } else {
+
set w .cfgeditor
catch {destroy $w}
toplevel $w -takefocus 1
- wm transient $w .
+ #wm transient $w .
grab $w
wm title $w "Custom config $node"
wm iconname $w "$node"
-
+
+ labelframe $w.custom -padx 4 -pady 4
+ if { $edit == "1" } {
+ frame $w.custom.viewid -borderwidth 4
+ label $w.custom.viewid.label -text "View custom-config:"
+ pack $w.custom.viewid.label -side left -anchor w
+ eval {tk_optionMenu $w.custom.viewid.optmenu viewcustomid} $customidlist
+ pack $w.custom.viewid.label $w.custom.viewid.optmenu \
+ -side left -anchor w
+ pack $w.custom.viewid -side top -anchor w
+ button $w.custom.viewid.button -text View \
+ -command "editStartupCfg $node 0"
+ pack $w.custom.viewid.button -side right
+
+ foreach element $customCfgList {
+ set cid [lindex [lsearch -inline $element "custom-config-id *"] 1]
+ if { $viewcustomid == $cid } {
+ set customCfg $element
+ }
+ }
+ }
+
+ frame $w.custom.id -borderwidth 4
+ label $w.custom.id.label -text "Custom config id:"
+ entry $w.custom.id.text -bg white -width 30
+ if { $customCfg != {} } {
+ set ccfg [getConfig $customCfg "custom-config-id"]
+ } else {
+ set ccfg ""
+ }
+ $w.custom.id.text insert 0 $ccfg
+ pack $w.custom.id.text $w.custom.id.label -side right -padx 4 -pady 4
+ pack $w.custom.id -side top -anchor w
+ pack $w.custom -side top -anchor w -fill both
+
frame $w.ftop -borderwidth 4
label $w.ftop.label -text "Startup command:"
entry $w.ftop.cmd -bg white -width 64
- $w.ftop.cmd insert 0 [getCustomCmd $node]
- pack $w.ftop.cmd $w.ftop.label -side right -padx 4 -pady 4
+ if { $customCfg != {} } {
+ set ccmd [getConfig $customCfg "custom-command"]
+ } else {
+ set ccmd ""
+ }
+ $w.ftop.cmd insert 0 $ccmd
+ pack $w.ftop.cmd $w.ftop.label -side right -padx 4 -pady 4
pack $w.ftop -side top -anchor w
text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" \
- -setgrid 1 -height 40 -undo 1 -autosep 1 -background white
+ -setgrid 1 -height 20 -undo 1 -autosep 1 -background white
focus $w.text
scrollbar $w.scroll -command "$w.text yview"
pack $w.buttons -side bottom
button $w.buttons.apply -text "Apply" \
-command "customConfigApply $w $node"
- button $w.buttons.cancel -text Cancel -command "destroy $w"
- pack $w.buttons.apply $w.buttons.cancel -side left
+ button $w.buttons.close -text Close -command "destroy $w"
+ button $w.buttons.delete -text Delete -command \
+ "deleteCustomConfig $w $node $viewcustomid {} {} 1"
+ pack $w.buttons.apply $w.buttons.close $w.buttons.delete -side left
pack $w.scroll -side right -fill y
pack $w.text -expand yes -fill both
- foreach line [getCustomConfig $node] {
- $w.text insert end "$line^M"
- }
+ if { $customCfg != {} } {
+ set ccfg [getConfig $customCfg "config"]
+ } else {
+ set ccfg ""
+ }
+ foreach line $ccfg {
+ $w.text insert end "$line\n"
+ }
$w.text mark set insert 0.0
+ }
return
}
global changed
set newcmd [$w.ftop.cmd get]
- set newconf [split [$w.text get 0.0 end] {^M}]
- while { [lindex $newconf end] == {} && $newconf != {} } {
+ set newid [$w.custom.id.text get]
+ set newconf [split [$w.text get 0.0 end] "\n"]
+ while { [lindex $newconf end] == {} && $newconf != {} } {
set newconf [lreplace $newconf end end]
}
+ # TODO:
if { [getCustomCmd $node] != $newcmd || \
[getCustomConfig $node] != $newconf } {
set changed 1
}
- setCustomCmd $node $newcmd
- setCustomConfig $node $newconf
+ setCustomConfig $node $newid $newcmd $newconf 0
destroy $w
+ editStartupCfg $node 0
return
}
global changed oper_mode router_model badentry
global customEnabled ipsecEnabled
global eid
-
+ global showIPsecConfig
+
$wi config -cursor watch
update
if { $phase == 0 } {
set changed 1
}
+ if { $showIPsecConfig == 0 } {
+ set ipsecEnabled 0
+ }
set oldipsecenabled [getIpsecEnabled $target]
if {$oldipsecenabled != $ipsecEnabled} {
setIpsecEnabled $target $ipsecEnabled
nexec vimage $node_id ifconfig $ifc mtu $mtu
}
+ global viewcustomid
if { [getCustomEnabled $node] == true } {
- set bootcmd [getCustomCmd $node]
- set bootcfg [getCustomConfig $node]
+ set customCfg ""
+ set customCfgList ""
+ set customCfgList [getCustomConfig $node]
+ foreach element $customCfgList {
+ set cid [lindex [lsearch -inline $element "custom-config-id *"] 1]
+ if { $cid == $viewcustomid } {
+ set customCfg $element
+ }
+ }
+ if { $customCfg == "" } {
+ set customCfg [lindex $customCfgList 0]
+ }
+
+ set bootcmd [getConfig $customCfg "custom-command"]
+ set bootcfg [getConfig $customCfg "config"]
} else {
set bootcmd ""
set bootcfg ""
set showIfIPv6addrs 1
set showNodeLabels 1
set showLinkLabels 1
+global showIPsecConfig
set showIPsecConfig 1
set supp_router_models "xorp quagga static"
}
}
}
-.menubar.view add separator
.menubar.view add command -label "Show All" \
-underline 5 \
-command {
global viewid badentry
-#### TODO: ########################
$w config -cursor watch; update
if { $phase == 0 } {
set badentry 0
$w config -cursor left_ptr
return
}
-#################################
set ipsecCfgList [getIpsecConfig $node]
set i 0
foreach element $ipsecCfgList {
return [lindex [lsearch -inline [set $node] "custom-command *"] 1]
}
-proc getAddCustomCmd { node } {
- global $node
-
- return [lindex [lsearch -inline [set $node] "add-custom-command *"] 1]
-}
-
#****f* nodecfg.tcl/setCustomCmd
# NAME
# setCustomEnabled -- set custom configuration command
if { $i >= 0 } {
set $node [lreplace [set $node] $i $i]
}
+
lappend $node [list custom-command $cmd]
return
}
-# TODO:
-proc setAddCustomCmd { node cmd } {
- global $node
-
- set i [lsearch [set $node] "add-custom-command *"]
- if { $i >= 0 } {
- set $node [lreplace [set $node] $i $i]
- }
- lappend $node [list add-custom-command $cmd]
- return
-}
-
#****f* nodecfg.tcl/getCustomConfig
# NAME
# getCustomConfig -- get custom configuration section
proc getCustomConfig { node } {
global $node
+ set customCfgList {}
+
+ set customcmd ""
+ set customcfg ""
+ set customcmd [lsearch -inline [set $node] "custom-command *"]
+ set customcmdval [lindex $customcmd 1]
+ set customcfg [lsearch -inline [set $node] "custom-config *"]
+ set customcfgval [lindex $customcfg 1]
+ if { $customcmd != "" } {
+ set customid [list custom-config-id generic]
+ set customcmd [list custom-command $customcmdval]
+ set customcfg [list config $customcfgval]
+ set customCfgList [list [list $customid $customcmd $customcfg]]
+
+ } else {
+ set values [lsearch -all -inline [set $node] "custom-config *"]
+ foreach val $values {
+ lappend customCfgList [lindex $val 1]
+ }
+ }
- return [lindex [lsearch -inline [set $node] "custom-config *"] 1]
-}
-
-proc getAddCustomConfig { node } {
- global $node
-
- return [lindex [lsearch -inline [set $node] "add-custom-config *"] 1]
+ return $customCfgList
}
#****f* nodecfg.tcl/setCustomConfig
# For input node this procedure sets custom configuration section.
# INPUTS
# * node_id -- node id
+# * id -- custom-config id
+# * cmd -- custom command
# * cfg -- custom configuration section
+# * delete -- if delete is set to 1, setCustomConfig is invoked
+# to delete custom-config with custom-config-id $id
+# *
#****
-proc setCustomConfig { node cfg } {
+proc setCustomConfig { node id cmd cfg delete } {
+ global viewcustomid
global $node
- set i [lsearch [set $node] "custom-config *"]
- if { $i >= 0 } {
- set $node [lreplace [set $node] $i $i]
- }
- if { $cfg != {} } {
- lappend $node [list custom-config $cfg]
+ set i [lsearch [set $node] "custom-command *"]
+ if { $i != "-1" } {
+ set $node [lreplace [set $node] $i $i]
+ set j [lsearch [set $node] "custom-config *"]
+ set $node [lreplace [set $node] $j $j]
+ }
+
+ set indices [lsearch -all [set $node] "custom-config *"]
+ foreach i $indices {
+ set tmp [lindex [set $node] $i]
+ set customCfg [lindex $tmp 1]
+ set cid [lindex [lsearch -inline $customCfg \
+ "custom-config-id *"] 1]
+ if { $cid == $id } {
+ set $node [lreplace [set $node] $i $i]
+ }
+ }
+
+ if { $delete == 0 } {
+ if { $cfg != {} && $cmd != {} && $id != {} } {
+ set newid [list custom-config-id $id]
+ set viewcustomid [lindex $newid 1]
+ set newcmd [list custom-command $cmd]
+ set newcfg [list config $cfg]
+ lappend $node [ list custom-config \
+ [list $newid $newcmd $newcfg] ]
}
+ }
return
}
-# TODO
-proc setAddCustomConfig { node cfg } {
- global $node
+#****f* nodecfg.tcl/deleteCustomConfig
+# NAME
+# deleteCustomConfig -- delete custom configuration
+# SYNOPSIS
+# deleteCustomConfig $w $node $id $cmd $cfg $delete
+# FUNCTION
+# Delete specified custom-config element and invokes
+# editStartupCfg function.
+# INPUTS
+# * all the inputs are equivalent to the inputs in the
+# * setCustomConfig function
+#****
- set i [lsearch [set $node] "add-custom-config *"]
- if { $i >= 0 } {
- set $node [lreplace [set $node] $i $i]
- }
- if { $cfg != {} } {
- lappend $node [list add-custom-config $cfg]
- }
- return
+proc deleteCustomConfig { w node id cmd cfg delete } {
+ global viewcustomid
+
+ setCustomConfig $node $viewcustomid {} {} 1
+ destroy $w
+ editStartupCfg $node 1
}
#****f* nodecfg.tcl/netconfFetchSection