]> git.entuzijast.net Git - imunes.git/commitdiff
Added support for more (more than one) custom configurations for each node.
authorana <ana>
Wed, 17 Jan 2007 20:28:32 +0000 (20:28 +0000)
committerana <ana>
Wed, 17 Jan 2007 20:28:32 +0000 (20:28 +0000)
Configuration reading is backwards compatible with old configurations (.imn).

Bug found by:
Submitted by:
Requested by:
Reviewed by:
Approved by:
Obtained from:

cfgparse.tcl
editor.tcl
exec.tcl
initgui.tcl
ipsec.tcl
nodecfg.tcl

index 4165db4c6d0eb4b004d4e81a20c4fe3e26e2450a..3e8cef63a5b98ee2d744772b167011438cb8a49b 100755 (executable)
@@ -106,10 +106,21 @@ proc dumpCfg {method dest} {
                    }
                    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 \{"
@@ -274,31 +285,25 @@ proc loadCfg { cfg } {
                        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] == "     " } {
index 10a795742939b38f8dae42470bf6ab2def57ee43..b235c06016d7be1d20f51f87dfb89beb498e682f 100755 (executable)
@@ -1889,9 +1889,9 @@ proc popupConfigDialog { c } {
         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
 
@@ -2057,8 +2057,10 @@ proc popupConfigDialog { c } {
 #   * 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
 }
 
 
@@ -2071,25 +2073,89 @@ proc cfgGenerate { node } {
 #   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"
 
@@ -2097,17 +2163,25 @@ proc editStartupCfg { node } {
     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
 }
 
@@ -2128,17 +2202,19 @@ proc customConfigApply { w node } {
     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
 }
 
@@ -2166,7 +2242,8 @@ proc popupConfigApply { wi object_type target phase } {
     global changed oper_mode router_model badentry
     global customEnabled ipsecEnabled
     global eid
-
+       global showIPsecConfig
+       
     $wi config -cursor watch
     update
     if { $phase == 0 } {
@@ -2316,6 +2393,9 @@ proc popupConfigApply { wi object_type target phase } {
             set changed 1
         }
 
+               if { $showIPsecConfig == 0 } {
+                       set ipsecEnabled 0
+               }
         set oldipsecenabled [getIpsecEnabled $target]
         if {$oldipsecenabled != $ipsecEnabled} {
             setIpsecEnabled $target $ipsecEnabled
index 27449aac5d6d445f9efcbdb0b6c2cd2bcf3d8098..64ed1b84d3134179f0a133f882949b02618825c0 100755 (executable)
--- a/exec.tcl
+++ b/exec.tcl
@@ -402,9 +402,23 @@ proc l3node.start { eid node } {
        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 ""
index c02cb62ba632f8b292c3176b30866bad95299cbf..69c71cceba536654b91ef4516ac9faaf6f0b913e 100755 (executable)
@@ -134,6 +134,7 @@ set showIfIPaddrs 1
 set showIfIPv6addrs 1
 set showNodeLabels 1
 set showLinkLabels 1
+global showIPsecConfig
 set showIPsecConfig 1
 
 set supp_router_models "xorp quagga static"
@@ -347,7 +348,6 @@ menu .menubar.view -tearoff 0
        }
     }
 }
-.menubar.view add separator
 .menubar.view add command -label "Show All" \
     -underline 5 \
     -command {
index 15472fd115616a0f01374d7f2490ea469bdea438..4336cec222e8d72d07180e64de7625a27a6a4a03 100755 (executable)
--- a/ipsec.tcl
+++ b/ipsec.tcl
@@ -56,7 +56,6 @@ proc editIpsecCfg { w node deleteid edit phase } {
 
        global viewid badentry
 
-#### TODO: ########################
        $w config -cursor watch; update
        if { $phase == 0 } {
                set badentry 0
@@ -67,7 +66,6 @@ proc editIpsecCfg { w node deleteid edit phase } {
                $w config -cursor left_ptr
                return
        }
-#################################
        set ipsecCfgList [getIpsecConfig $node]
        set i 0
        foreach element $ipsecCfgList {
index eb31b1094237bcfb162f14e33730f53446e50ccd..bb0894fd3b3bf973fd0f9d60f9c2fc63d7bb1023 100755 (executable)
@@ -328,12 +328,6 @@ proc getCustomCmd { node } {
     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 
@@ -353,22 +347,11 @@ proc setCustomCmd { node cmd } {
     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 
@@ -384,14 +367,28 @@ proc setAddCustomCmd { node cmd } {
 
 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
@@ -403,34 +400,68 @@ proc getAddCustomConfig { node } {
 #   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