home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 December / PCWorld_2000-12_cd.bin / Komunikace / Comanche / plugins / samba / samba.tcl < prev   
Text File  |  2000-11-02  |  10KB  |  401 lines

  1.  
  2.  
  3. class sambaPlugIn {
  4.     inherit basePlugIn
  5.  
  6.     public variable dumper
  7.  
  8.     public variable ppManager
  9.     public variable ppDef
  10.  
  11.     public variable configurationFilesManager
  12.  
  13.  
  14.     public variable namespace
  15.  
  16.  
  17.     public variable nodeManagement
  18.  
  19.  
  20.     public variable confDoc
  21.  
  22.     public variable rootNode
  23.     variable shares
  24.     variable printers
  25.     variable status
  26.     variable homes
  27.  
  28.     method _registerWithNamespace {}
  29.     method _inquiryForPropertyPages  { node }
  30.     method _inquiryForMenu { node }
  31.     method _inquiryForWizard { type node }   
  32.     method _inquiryForRightPaneContent { node }
  33.     method _receivedWizard { node xuiPropertyPages }       
  34.     method _receivedPropertyPages { node xuiPropertyPages }
  35.     method _receivedCommand { node command }
  36.     
  37.     method init 
  38.     method _createAllNodes { } 
  39.     method _createShare {container}
  40.     method _createShares {}
  41.     method _createHomes { container }
  42.     method _createStatus {}
  43.     method _createPrinters {}
  44.     method _createAllPrinters { container }
  45.     method _createPrinter {container}
  46.  
  47.     method _saveConfig 
  48.  
  49. }
  50.  
  51. body sambaPlugIn::_saveConfig {} {
  52. #       set f [open $::comanche::globals(smb.conf) w]
  53. #        puts $f [$dumper dump $confDoc]
  54. #        close $f   
  55.     $dumper dump $confDoc $::comanche::globals(smb.conf) 
  56. }
  57.  
  58. body  sambaPlugIn::_receivedPropertyPages { node xuiPropertyPages } {
  59.  
  60.  
  61.  
  62.     set container [ $nodeManagement getContainer $node ]
  63.  
  64.     if [string length $container] {
  65.  
  66.     foreach pp [$xuiPropertyPages getComponents] {
  67.  
  68.         $ppManager savePropertyPage $pp $confDoc $container      
  69.     }
  70.     }
  71.     _saveConfig
  72. }
  73.  
  74.  
  75.  
  76. body  sambaPlugIn::_receivedWizard { node xuiPropertyPages } {
  77.  
  78.     
  79.     set container [ $nodeManagement getContainer $node ]
  80.     set name [ $nodeManagement getNodeName $node ]
  81.     switch $name {
  82.     shares {
  83.         set name [[[$xuiPropertyPages getComponents] \
  84.             getComponentByName share_name] getValue]
  85.         set cont [$confDoc addContainer \
  86.             [$confDoc getRootContainer] $name share]
  87.         $confDoc addDirective  [[[$xuiPropertyPages getComponents] \
  88.             getComponentByName comment] clone] $cont
  89.         $confDoc addDirective [[[$xuiPropertyPages getComponents] \
  90.             getComponentByName path] clone] $cont
  91.         _createShare $cont 
  92.     }  printers {
  93.         set name [[[$xuiPropertyPages getComponents] \
  94.             getComponentByName section_name] getValue]
  95.         set cont [$confDoc addContainer \
  96.             [$confDoc getRootContainer] $name share]
  97.         $confDoc addDirective  [[[$xuiPropertyPages getComponents] \
  98.             getComponentByName comment] clone] $cont
  99.         $confDoc addDirective [[[$xuiPropertyPages getComponents] \
  100.             getComponentByName path] clone] $cont
  101.         _createPrinter $cont
  102.  
  103.     } default {
  104.         error "Container: $name "
  105.     }
  106.     }
  107.     _saveConfig
  108. }
  109.            
  110.                                       
  111.  
  112.     
  113. body sambaPlugIn::init {} {
  114.     _createAllNodes 
  115. }
  116.  
  117.  
  118.  
  119. body sambaPlugIn::_inquiryForPropertyPages { node } {
  120.     
  121.     
  122.     set result {}
  123.     set name [$nodeManagement getNodeName $node]
  124.     set container [$nodeManagement getContainer $node]
  125.     switch $name {
  126.     shares {
  127.         foreach pp { newbieBaseOptions  newbieLog \
  128.             newbieBrowse newbieSecurity } {
  129.         set mypp [$ppDef getPPByName $pp]
  130.         lappend result $mypp
  131.         $ppManager loadPropertyPage $mypp $confDoc $container
  132.         }
  133.     } share - homes {
  134.         foreach pp { newbieShareBase 
  135.         newbieShareBrowse newbieShareSecurity } {
  136.         set mypp [$ppDef getPPByName $pp]
  137.         lappend result $mypp
  138.         $ppManager loadPropertyPage $mypp $confDoc $container
  139.         }
  140.     } printer - printers {
  141.         foreach pp { newbieShareBase 
  142.         newbieShareBrowse newbieShareSecurity newbiePrintingOptions} {
  143.         set mypp [$ppDef getPPByName $pp]
  144.         lappend result $mypp
  145.         $ppManager loadPropertyPage $mypp $confDoc $container        
  146.         }
  147.     }
  148.     }
  149.     return $result
  150. }
  151.  
  152. body sambaPlugIn::_inquiryForWizard { type node } {
  153.     
  154.     
  155.     
  156.     set result {}
  157.     set name [$nodeManagement getNodeName $node]
  158.     set container [$nodeManagement getContainer $node]
  159.     switch $name {
  160.     shares {
  161.         set mypp [$ppDef getPPByName shareAddWizard]
  162.         return $mypp
  163.     } rootNode - status  {
  164.         return {}
  165.     } printers {
  166.         set mypp [$ppDef getPPByName printerAddWizard]
  167.         return $mypp
  168.     }
  169.     }
  170.     return $result
  171. }                           
  172.     
  173.  
  174. body sambaPlugIn::_inquiryForRightPaneContent { node } {
  175.     
  176.     set container [$nodeManagement getContainer $node]
  177.     set name [$nodeManagement getNodeName $node]
  178.     switch $name {
  179.     rootNode {
  180.         set result {
  181.         <img src="samba_logo">
  182.         <h1>Samba</h1>
  183.         <br>
  184.         This plugin configures the <b>Samba file and printing services</b>.
  185.         <br>You can configure existing printers and shares:<br><br>}
  186.     append result { <img src="sharesBig" ><a href="command selectNode -namespaceNode }
  187.         append result $shares
  188.     append result  { " >Shares</a> <br><br>}
  189.     append result { <img src="printerBig"> <a href="command selectNode -namespaceNode }
  190.         append result $printers
  191.     append result  { " >Printers</a> <br><br>}    
  192.  
  193.     } shares {
  194.         set result {
  195.         <img src="samba_logo"><br>
  196.         <h1>Shares</h1>
  197.         <br>
  198.         <img src="sharesBig">
  199.         Here you can configure the 
  200.     <a href="command propertyPages">global properties</a> that apply to all shares and <a href="command addNewNode">create</a> new ones
  201.     <br>}
  202.     } printers {
  203.         set result {
  204.         <img src="samba_logo"><br>
  205.         <h1>Printers</h1>
  206.         <br>
  207.         <img src="printerBig">
  208.         Here you can configure the 
  209.     <a href="command propertyPages">global properties</a> that apply to all printers and <a href="command addNewNode">create</a> new ones.
  210.     <br>}
  211.  
  212.     } share {
  213.         append result {
  214.         <img src="samba_logo"><br>
  215.         <h1>Share } 
  216.         append result  [ $container getName ]
  217.         append result {</h1><br>}
  218.         catch [list append result "Path: [[$confDoc getDirectiveByName $container path] getValue]<br>"]
  219.         catch [list append result "Comment: [[$confDoc getDirectiveByName $container comment] getValue]<br>"]
  220.         append result {
  221.         <br><br>
  222.         <img src="folderBig">
  223.                  You can configure the properties of this share <a href="command
  224. propertyPages" >here</a>}
  225.     } homes {
  226.         append result {
  227.         <img src="samba_logo"><br>
  228.         <h1>Homes</h1> <br>
  229.             <img src="kfmHomeBig> 
  230. If a section called 'homes' is created, services connecting clients to their home directories can be created on the fly by the server. 
  231.                  You can configure the properties of this share <a href="command
  232. propertyPages" >here</a>}
  233.  
  234.     } printer {
  235.         append result {
  236.         <img src="samba_logo"><br>
  237.         <h1>Share } 
  238.         append result  [ $container getName ]
  239.         append result {</h1><br>}
  240.         catch [list append result "Path: [[$confDoc getDirectiveByName $container path] getValue]<br>"]
  241.         catch [list append result "Comment: [[$confDoc getDirectiveByName $container comment] getValue]<br>"]
  242.         append result {
  243.         <br><br>
  244.         <img src="printerBig">
  245.                  You can configure the properties of this printer <a href="command
  246. propertyPages" >here</a>}
  247.  
  248.     } status {
  249.         append result {
  250.         <img src="samba_logo"><br>
  251.         <h1>Info</h1>
  252.         <img src="informationBig"> Here you will be able to find information about active connections and shares and open folders.
  253.     } 
  254.  
  255.         } default {
  256.         set result kkk
  257.  
  258.     }
  259.     }
  260.     return $result
  261. }
  262.  
  263.  
  264. body sambaPlugIn::_createAllNodes {  } {
  265.  
  266.     _createStatus
  267.     _createShares   
  268.     _createPrinters   
  269.     foreach container [$confDoc getContainers [$confDoc getRootContainer]] {
  270.     switch [$container getName] {
  271.         global {
  272.         $nodeManagement setContainer $shares $container
  273.         } printers {
  274.         $nodeManagement setContainer $printers $container
  275.         } homes {
  276.         _createHomes $container
  277.  
  278.         } default {
  279.         if [string length \
  280.             [$confDoc getDirectiveByName $container printer]] {
  281.             _createPrinter $container
  282.         } else {
  283.             _createShare $container
  284.         }
  285.         }
  286.     }
  287.     }
  288. }
  289.  
  290.  
  291. body sambaPlugIn::_createShares { } {
  292.     set shares [ $nodeManagement addNode $rootNode\
  293.         -label "Shares" \
  294.         -openIcon shares\
  295.         -classes {container samba} \
  296.         -closedIcon shares\
  297.         -container {} \
  298.         -nodeName shares ]
  299. }
  300.  
  301. body sambaPlugIn::_createShare { container } {
  302.     set label [$container getName] 
  303.     if [string length \
  304.         [set cdir [$confDoc getDirectiveByName $container comment]]] {
  305.     append label " - [$cdir getValue]"
  306.     }
  307.    $nodeManagement addNode $shares\
  308.         -label $label \
  309.         -openIcon openFolder\
  310.         -classes {leaf samba} \
  311.         -closedIcon closedFolder\
  312.         -container $container \
  313.         -nodeName share 
  314. }
  315.  
  316. body sambaPlugIn::_createPrinter { container } {
  317.     set label [$container getName] 
  318.     if [string length \
  319.         [set cdir [$confDoc getDirectiveByName $container comment]]] {
  320.     append label " - [$cdir getValue]"
  321.     }
  322.    $nodeManagement addNode $printers\
  323.         -label $label \
  324.         -openIcon openFolder\
  325.         -classes {leaf samba} \
  326.         -closedIcon printer\
  327.         -container $container \
  328.         -nodeName printer 
  329. }
  330.  
  331.  
  332. body sambaPlugIn::_createHomes { container } {
  333.  
  334.  
  335.     set homes [ $nodeManagement addNode $shares\
  336.         -label "Homes" \
  337.         -openIcon kfmHome\
  338.         -classes {leaf samba} \
  339.         -closedIcon kfmHome\
  340.         -container $container \
  341.         -nodeName homes ]
  342. }
  343.  
  344.  
  345.  
  346. body sambaPlugIn::_createAllPrinters { container } {
  347. }
  348.  
  349. body sambaPlugIn::_createPrinters { } {
  350.     set printers [ $nodeManagement addNode  $rootNode\
  351.         -label "Printers" \
  352.         -openIcon printer\
  353.         -classes {container samba} \
  354.         -closedIcon printer\
  355.         -container {}\
  356.         -nodeName printers ]
  357. }
  358.  
  359. body sambaPlugIn::_createStatus {} {
  360.     set status [ $nodeManagement addNode  $rootNode\
  361.         -label "Status" \
  362.         -openIcon information\
  363.         -classes {leaf samba} \
  364.         -closedIcon information \
  365.         -container {}\
  366.         -nodeName status ]
  367. }
  368.  
  369.  
  370.  
  371. body sambaPlugIn::_registerWithNamespace {} {
  372.     
  373.     set node $rootNode
  374.     set rootNode [$nodeManagement addNode $node\
  375.         -label "Samba 2.0.0" \
  376.         -openIcon samba\
  377.         -closedIcon samba\
  378.         -container {}\
  379.         -nodeName rootNode]
  380. }
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.