home *** CD-ROM | disk | FTP | other *** search
-
- # Example plugin
- #
- # Original idea and code by Stew Benedict
-
- class nameserversPlugIn {
- inherit basePlugIn
-
- # This variable contains property page
-
- variable nameserversXuiPP
- variable nameserversNodeId
-
- constructor {} {
-
- # Create property page
-
- set nameserversXuiPP [::libgui::createXuiFromFile $::resolv::pp]
- }
- method init { args }
- method fillPropertyPages {}
- method saveNameServerSettings { xuiPropertyPage}
- method _inquiryForRightPaneContent { node }
- method _inquiryForPropertyPages { node }
- method _receivedPropertyPages { node xuiPropertyPages}
- }
-
-
-
- # args contains the options that are passed to the plugIn at initialization
- # time.
- #
- # -namespace contains the name of the name space server
-
-
- body nameserversPlugIn::init {args} {
-
- # We are hooking to the root node
- # The ::plugInUtils::addNode syntaxis is the following
- # ::plugInUtils::addNode caller namespace parentNode
- # where
- # caller: Name of the object that is adding the node (the plugIn object)
- # namespace: Namespace where we are adding the node
- # parentNode: Parent node
- #
- # The list of available icons is in view/images.tcl
-
- array set options $args
- set namespace $options(-namespace)
- set parentNode [[ $namespace getRootNode] getId]
- set nameserversNode [::plugInUtils::addNode $this $namespace $parentNode \
- -classes {nameservers leaf} \
- -openIcon network \
- -closedIcon network \
- -label [mesg::get resolv_nameservers_settings]]
- set nameserversNodeId [$nameserversNode getId]
- }
-
- body nameserversPlugIn::_inquiryForRightPaneContent { node } {
- global tcl_platform
- set result [mesg::get resolv_nameservers_right_pane]
- if [catch { set inhdl [open /etc/resolv.conf r] } kk] {
- return "<br>Not possible to read /etc/resolv.conf. \
- Error follows:<br><pre> $kk </pre>"
- }
- while { [gets $inhdl buff] >= 0 } {
- append result " <BR><b>$buff</b>"
- }
- close $inhdl
- return $result
- }
-
-
- body nameserversPlugIn::_inquiryForPropertyPages { node } {
- global tcl_platform
- fillPropertyPages
- return $nameserversXuiPP
- }
-
-
- body nameserversPlugIn::_receivedPropertyPages { node xuiPropertyPages } {
- set pp [$xuiPropertyPages getComponentByName nameserversPP]
- saveNameServerSettings $pp
- }
-
- body nameserversPlugIn::saveNameServerSettings { xuiPropertyPage } {
- set domainList [$xuiPropertyPage.domainList getChildren]
- set result {}
- if [llength $domainList] {
- append result "search"
- foreach domain $domainList {
- append result " [$domain getValue]"
- }
- append result \n
- }
- foreach nameserver [$xuiPropertyPage.dnsList getChildren] {
- append result "nameserver [$nameserver getValue]\n"
- }
- set f [open /etc/resolv.conf w]
- puts $f $result
- close $f
- }
-
- body nameserversPlugIn::fillPropertyPages {} {
-
- # Clear the property pages
-
- $nameserversXuiPP.domainList clear
- $nameserversXuiPP.dnsList clear
-
- # Read the data
-
- set f [open /etc/resolv.conf r]
- set lines [split [read $f] \n]
- foreach line $lines {
-
- # - For each line, test if comment, nameserver or search
- # Fill the data
-
- set text [string trim $line]
- switch -glob $text {
- #* {
- } search* {
- foreach domain [lrange $text 1 end] {
- set newDomain [$nameserversXuiPP.domainList newChild]
- $newDomain setValue $domain
- $nameserversXuiPP.domainList insertChild $newDomain
- }
- } nameserver* {
- foreach dns [lrange $text 1 end] {
- set newDns [$nameserversXuiPP.dnsList newChild]
- $newDns setValue $dns
- $nameserversXuiPP.dnsList insertChild $newDns
- }
- }
- }
- }
- }
-