home *** CD-ROM | disk | FTP | other *** search
-
- # Things we need.
- # - A list with all the synonyms.
- # - Location of the smb.conf file
- # - Special case mapping both smb.conf -> XML and the inverse (just like apache dumper)
- #
- # We allow for external files to be included and configured. We just do not allow %
- # escaped names
-
- class sambaPrettyDumper {
-
- inherit apachePrettyDumper
-
- method getSection
- method dumpRest
- method dumpContainer
- method dumpDirective
- method processSection
- method getLine
- method getTypeOfLine
- method processDirective
-
- }
-
- body sambaPrettyDumper::getSection {sectionInfo lineList} {
-
- set data [getLine lineList]
- set info [getTypeOfLine $data]
- set section {}
-
- # Only interested in endOfSection of same type, so we can anidate requests
-
- while {![expr [string match [lindex $info 0] beginSection]]} {
- lappend sectionLines $data
- set data [getLine lineList]
- set info [getTypeOfLine $data]
-
- # Reached end of file
-
- if ![llength $lineList] break
- }
- set lineList [concat $data $lineList]
- return [list $sectionLines $lineList]
- }
-
-
- body sambaPrettyDumper::dumpRest {} {
- set result \n
-
- # Now we have left the ones that were not found in the template
-
- foreach directive $currentXmlDirectives {
- set dirName [string tolower [$directive getName]]
-
- # # Skip disabled directives
- #
- # if ![$moduleManager isDirectiveEnabled $dirName] {
- # continue
- # }
- if [$directive doYouBelongTo unknownDirective] {
- debug "dumping unknown in dumpRest $directive - [$directive getValue]"
- append result [$directive getValue]\n
- } elseif [info exists specialCaseMapping($dirName)] {
- append result [dumpSpecialCase $dirName $directive]
- } else {
- append result [dumpDirective $directive]
- }
- }
-
-
-
- # Same goes with containers
-
- foreach one $containerList {
- append result [dumpContainer $one]
- set idx [lsearch -exact $containerList $one]
- set containerList [lreplace $containerList $idx $idx]
- }
- return $result
- }
-
- body sambaPrettyDumper::dumpContainer {container} {
- set result {}
- append result "\[[$container getName]\]\n"
- foreach directive [$xmlConfDoc getDirectives $container] {
- set dirName [string tolower [$directive getName]]
- if [info exists specialCaseMapping($dirName)] {
- append result [dumpSpecialCase $dirName $directive]
- } else {
- append result [dumpDirective $directive]
- }
- }
-
- # No anidated containers in Samba
-
- # foreach childContainer [$xmlConfDoc getContainers $container] {
- # append result [ dumpContainer $childContainer]
- # }
- return $result
- }
-
- # sectionInfo is a list containing {value class}
-
- body sambaPrettyDumper::processSection {sectionInfo data} {
- set result {}
- set value [lindex $sectionInfo 0]
-
- # Save previous state
-
- $xmlDirectivesStack push $currentXmlDirectives
- $currentContainerStack push $currentContainer
-
- # All classes should be the same (sambaContainer). So just look for a match in the name
-
- set matchingContainers {}
- foreach one $containerList {
- if [string match [$one getName] $value] {
- lappend matchingContainers $one
- }
- }
-
- switch [llength $matchingContainers] {
- 0 {
-
- # Do nothing
-
- } 1 {
-
- set matchingContainer $matchingContainers
-
- # Remove container from list
-
- set idx [lsearch -exact $containerList $matchingContainer]
- set containerList [lreplace $containerList $idx $idx]
- $containerListStack push $containerList
-
- set currentXmlDirectives [$xmlConfDoc getDirectives $matchingContainer]
- set currentContainer $matchingContainer
- set containerList [$xmlConfDoc getContainers $matchingContainer]
-
- append result "\[[$matchingContainer getName]\]\n"
-
- append result [parseText $data]
- append result [dumpRest]
-
- set containerList [$containerListStack pop]
- } default {
-
- # Should not more than one container in Samba
-
- # set commented {
- #
- # # By now, just ignore
- # # To-do finish this
- # # Address name based virtualhost
- #
- # if [string match $class virtualhost] {
- # # Check for servernames
- # }
- # }
- }
- }
-
- set currentXmlDirectives [$xmlDirectivesStack pop]
- set currentContainer [$currentContainerStack pop]
-
-
- return $result
- }
-
- body sambaPrettyDumper::getLine { lineList } {
- upvar $lineList list
- set result [lindex $list 0]
- set list [lrange $list 1 end]
- return $result
- }
-
- body sambaPrettyDumper::getTypeOfLine { line } {
-
- # In Samba, all sections have the same
-
- set data [string trim $line]
- if {[regexp "^#+" $data] || ![string length $data] || [regexp {^;} $data]} {
- return comment
- } elseif [regexp "^include (.*)" [string tolower $data] dummy fileName] {
-
- # By now, include directives are ignored until we handle them properly
- # (fix includeroot)
-
- return directive
-
- # Only include files that are not % substituted
- # If that is the case, just ignore it and leave it as-is (directive)
-
- if [string match *%* $fileName] {
- return directive
- }
- return [list include $fileName]
- } elseif [regexp {^\[(.*)\]} $data dummy name] {
- # If the regular expresion has [] on it, braces, not quotes
-
-
- # All containers in Samba have same class
-
- return [list beginSection [list $name sambaContainer]]
- } else {
- return directive
- }
-
- }
-
- body sambaPrettyDumper::processDirective {data} {
-
- set result {}
-
- # TODO: check if belongs to disabled module and return if so.
-
- set dirName [string tolower \
- [lindex [set elements \
- [ ::sambautils::getElements $data ]] 0]]
-
- # Check here synonyms
-
- if [ isSpecialCase $dirName ] {
-
- set xuiDirectiveName [string tolower $specialCaseDirectiveMapping($dirName)]
-
- # check if currentXMLDirectives contains xuiDirective associated
- # with this special case
-
- if [llength [set xuiDirective [ getXmlDirectivesWithThatName $xuiDirectiveName ]]] {
-
- # yes -> process it append to result
- # delete from currentXml
-
- set result [dumpSpecialCase $xuiDirectiveName $xuiDirective]
- set idx [lsearch -exact $currentXmlDirectives $xuiDirective]
- set currentXmlDirectives [lreplace $currentXmlDirectives $idx $idx]
- return $result
- } else {
-
- # no -> We already processed it return nothing
-
- return {}
- }
-
- }
-
- if [llength [set list [ getXmlDirectivesWithThatName $dirName ]]] {
-
- # yes --> process it append to result
- # delete from currentXmlDirectives
-
- # switch depending if unknown or not
-
- foreach one $list {
- if [$one doYouBelongTo unknownDirective] {
- append result [$one getValue]\n
- } else {
- append result [dumpDirective $one]
- }
- set idx [lsearch -exact $currentXmlDirectives $one]
- set currentXmlDirectives [lreplace $currentXmlDirectives $idx $idx]
- }
- return $result
- }
-
-
- # If we are here it was not found, so we ignore it
-
- return {}
-
- }
-
- body sambaPrettyDumper::dumpDirective {directive} {
- set result {}
- if [$directive doYouBelongTo unknownDirective] {
- set result "[$directive getValue]\n"
- return $result
- }
- set dirName [string tolower [$directive getName]]
- switch [$directive getXuiClass] {
- string - number {
- set value [$directive getValue]
- if [string compare $value [$directive getDefault]] {
- set value [$directive getValue]
- if {[$directive doYouBelongTo file] || \
- [$directive doYouBelongTo directory] } {
- if [regexp {\ } $value] {
- set value "\"$value\""
- }
- }
- append result "[split $dirName _] = $value\n"
- }
- } boolean {
- set value [$directive getValue]
- if [string compare $value [$directive getDefault]] {
- switch $value {
- 0 {
- append result "[split $dirName _] = no\n"
- } 1 {
- append result "[split $dirName _] = yes\n"
- }
- }
- }
- } choice {
-
- # TO-DO: Check if it is multiple choice
-
- if ![string match [$directive getName] [$directive getDefault]] {
- append result \
- "[split $dirName _] = [$directive getSelected]\n"
- }
- } default {
- error "No special case and not recognized in dumping\
- [$directive getXuiClass] [$directive getName]"
- }
- }
- if ![string length [string trim $result]] {
- return {}
- } else {
- return $result
- }
- }
-
-
-