#!/usr/bin/wish -f

################################################################################
#          IBM Logo
################################################################################

################################################################################
#         Windows Manager Commands
################################################################################

wm title . "IBM NetworkStation Setup Utility"
wm iconname . "IBM NS Setup"
wm resizable . 0 0

set c [canvas .c -width 545 -height 195 -relief sunken -bd 2]

#set image [image create photo -file IBMIMAGE.GIF]
set image [image create photo -file /IBM/IBMIMAGE.GIF]

$c create image 275 100 -image $image -tags item

pack .c

################################################################################
#      System Restore defaults
################################################################################
proc CheckForFiles {} {

if {[file exists /root/IBM/NetworkAddresses] == 0} {
  tk_messageBox -title Error -message "An error occured reading your IBM NetworkAddresses file.  Loading defaults."
  set filename "/root/IBM/NetworkAddresses"
  set fd [open $filename w]
  fconfigure $fd
  puts $fd [format "%s=" "bootprotocol" ]
  foreach i {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
     puts $fd [format "%s=%s" $i "0.0.0.0"]
  }
  foreach i {hostname domainname} {
     puts $fd [format "%s=" $i ]
  }
  close $fd
  exec "/bin/sync"
}
if {[file exists /root/IBM/IBMSetupInformationBlock] == 0} {
  global soundMaster
  global displayResolution
  global displayColor
  global clientServerConfigure
  global clientServerIP
  global clientROMFlash
  global clientCompactFlash

  tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file.  Loading defaults."
  set soundMaster 50
  set clientServerConfigure 0
  set clientServerIP "0.0.0.0"
  set clientROMFlash 1
  set clientCompactFlash 1
  set displayResolution 640
  set displayColor 8
  SaveInfoBlock
}

}

proc CheckForWizard {} {
 global wizardboot
 global bootprotocol
 global ip
 global gateway
 global subnetmask
 global nameserver1
 global nameserver2
 global nameserver3
 global hostname
 global domainname
 global displayResolution
 global displayColor
 global clientServerIP
 global clientServerConfigure
 global soundMaster
 global clientROMFlash
 global clientCompactFlash

 if {[file exists /tmp/RunWizard] == 1} {
   readip
   ReadInfoBlock
   if {[string compare $bootprotocol "ip"] == 0} {
    set wizardboot 2
   }
   if {[string compare $bootprotocol "dhcp"] == 0} {
    set wizardboot 1
   }
   if {[string compare $bootprotocol "bootp"] == 0} {
    set wizardboot 1
   }
   if {[string length $bootprotocol ] == 0} {
    set wizardboot 1
   }
   after 100 {
     WizardPage1
   }
   wm iconify .
 }
}

proc WizardPage5 {} {

   global wizardboot

   if {[winfo exists .c.m]} {
        wm deiconify .c.m
	return
   }
   set m [toplevel .c.m -width 500 -height 500]

   wm title .c.m "IBM NetworkStation Configuration Complete"
   wm resizable .c.m 0 0
   wm transient .c.m .

   set image1 [image create photo -file /IBM/IBMWIZARD.GIF ]
   set image2 [image create photo -file /IBM/SYSTEM.GIF ]

   frame .c.m.total
   frame .c.m.total.data
   frame .c.m.total.manage
   frame .c.m.total.manage.ip

   canvas .c.m.total.dummyv1 -width 465 -height 300
   canvas .c.m.total.dummyv2 -width 465 -height 10
   label .c.m.image1 -image $image1
   label .c.m.total.data.image2 -image $image2
   label .c.m.total.data.label1 -justify left -wraplength 370 -text "Congratulations!  You have completed the configuration of your IBM NetworkStation." 
   button .c.m.total.next -text " Done " -command CheckWizardNextPage 
   button .c.m.total.back -text " < Back "  -command CheckWizardBackPage
   .c.m.total.dummyv1 create text 180 90 -text "Press Done to reboot your IBM NetworkStation."

   grid .c.m.total.data.image2 -row 1 -column 1 -padx 10
   grid .c.m.total.data.label1 -row 1 -column 2 -padx 10

   grid .c.m.total.data -row 1 -column 1 
   grid .c.m.total.dummyv1 -row 2 -column 1
   grid .c.m.total.manage -row 3 -column 1
   grid .c.m.total.dummyv2 -row 4 -column 1
   grid .c.m.total.next -row 5 -column 1 -sticky E  -padx 10 -pady 5
   grid .c.m.total.back -row 5 -column 1 -sticky W  -padx 10 -pady 5

   pack .c.m.total -side right
   pack .c.m.image1 -side left -pady  10

   proc CheckWizardNextPage {} {
     global bootprotocol
     global ip
     global gateway
     global subnetmask
     global nameserver1
     global nameserver2
     global nameserver3
     global hostname
     global domainname
     global displayResolution
     global displayColor
     global clientServerIP
     global clientServerConfigure
     global soundMaster
     global clientROMFlash
     global clientCompactFlash

     saveip
     SaveInfoBlock
     destroy .c.m
     exit
   }

   proc CheckWizardBackPage {} {
   
     destroy .c.m
     WizardPage4
   }
}

proc WizardPage4 {} {

   global wizardboot
   global clientServerIP
   global clientServerConfigure

   if {[winfo exists .c.l]} {
        wm deiconify .c.l
	return
   }
   set l [toplevel .c.l -width 500 -height 500]

   wm title .c.l "IBM Mananagment Server"
   wm resizable .c.l 0 0
   wm transient .c.l .

   set image1 [image create photo -file /IBM/IBMWIZARD.GIF ]
   set image2 [image create photo -file /IBM/SYSTEM.GIF ]

   frame .c.l.total
   frame .c.l.total.data
   frame .c.l.total.manage
   frame .c.l.total.manage.ip

   canvas .c.l.total.dummyv1 -width 465 -height 80
   canvas .c.l.total.dummyv2 -width 465 -height 160
   label .c.l.image1 -image $image1
   label .c.l.total.data.image2 -image $image2
   label .c.l.total.data.label1 -justify left -wraplength 370 -text "Selecting the IBM Managment server allows your IBM NetworkStation to be managed from a central location." 
   button .c.l.total.next -text " Next > " -command CheckWizardNextPage 
   button .c.l.total.back -text " < Back "  -command CheckWizardBackPage

   checkbutton .c.l.total.manage.configure -text "Enable Managment" -variable clientServerConfigure -relief flat
   label .c.l.total.manage.ip.label -text "IBM NetworkStation Managment Server: "
   label .c.l.total.manage.ip.label1 -text "."
   label .c.l.total.manage.ip.label2 -text "."
   label .c.l.total.manage.ip.label3 -text "."

   entry .c.l.total.manage.ip.entry1 -relief sunken -width 3 
   entry .c.l.total.manage.ip.entry2 -relief sunken -width 3
   entry .c.l.total.manage.ip.entry3 -relief sunken -width 3
   entry .c.l.total.manage.ip.entry4 -relief sunken -width 3

   pack .c.l.total.manage.ip.label -side left
   pack .c.l.total.manage.ip.entry4 -side right 
   pack .c.l.total.manage.ip.label1 -side right
   pack .c.l.total.manage.ip.entry3 -side right 
   pack .c.l.total.manage.ip.label2 -side right
   pack .c.l.total.manage.ip.entry2 -side right 
   pack .c.l.total.manage.ip.label3 -side right
   pack .c.l.total.manage.ip.entry1 -side right 
  
   pack .c.l.total.manage.configure -pady 10
   pack .c.l.total.manage.ip -pady 5 -padx 15


   grid .c.l.total.data.image2 -row 1 -column 1 -padx 10
   grid .c.l.total.data.label1 -row 1 -column 2 -padx 10

   grid .c.l.total.data -row 1 -column 1 
   grid .c.l.total.dummyv1 -row 2 -column 1
   grid .c.l.total.manage -row 3 -column 1
   grid .c.l.total.dummyv2 -row 4 -column 1
   grid .c.l.total.next -row 5 -column 1 -sticky E  -padx 10 -pady 5
   grid .c.l.total.back -row 5 -column 1 -sticky W  -padx 10 -pady 5

   pack .c.l.total -side right
   pack .c.l.image1 -side left -pady  10

   scan $clientServerIP "%d.%d.%d.%d" number1 number2 number3 number4
   .c.l.total.manage.ip.entry1 insert 0 $number1
   .c.l.total.manage.ip.entry2 insert 0 $number2
   .c.l.total.manage.ip.entry3 insert 0 $number3
   .c.l.total.manage.ip.entry4 insert 0 $number4

   proc CheckWizardNextPage {} {
    
     StoreIP
     destroy .c.l
     WizardPage5

   }
   proc CheckWizardBackPage {} {
     StoreIP 
     destroy .c.l
     WizardPage3
   }

   proc StoreIP {} {
     global clientServerIP  
  
     set string1 [.c.l.total.manage.ip.entry1 get]
     set string2 [.c.l.total.manage.ip.entry2 get]
     set string3 [.c.l.total.manage.ip.entry3 get]
     set string4 [.c.l.total.manage.ip.entry4 get]
     if {[string length $string1] == 0} then {
        set string1 "0"
     }
     if {[string length $string2] == 0} then {
        set string2 "0"
     }
     if {[string length $string3] == 0} then {
        set string3 "0"
     }
     if {[string length $string4] == 0} then {
        set string4 "0"
     }
     set clientServerIP [format "%d.%d.%d.%d" $string1 $string2 $string3 $string4]
  }
}

proc WizardPage3 {} {

   global wizardboot
   global displayColor
   global displayResolution

   if {[winfo exists .c.k]} {
        wm deiconify .c.k
	return
   }
   set j [toplevel .c.k -width 500 -height 500]

   wm title .c.k "Display Preferences"
   wm resizable .c.k 0 0
   wm transient .c.k .

   set image1 [image create photo -file /IBM/IBMWIZARD.GIF ]
   set image2 [image create photo -file /IBM/SYSTEM.GIF ]

   frame .c.k.total
   frame .c.k.total.data
   frame .c.k.total.resolution

   canvas .c.k.total.dummyv1 -width 465 -height 80
   canvas .c.k.total.dummyv2 -width 465 -height 150
   label .c.k.image1 -image $image1
   label .c.k.total.data.image2 -image $image2
   label .c.k.total.data.label1 -justify left -wraplength 370 -text "Please select your display resolution preferences.  Color depth is the number of colors that can be displayed on the screen at once." 
   button .c.k.total.next -text " Next > " -command CheckWizardNextPage 
   button .c.k.total.back -text " < Back "  -command CheckWizardBackPage

   label .c.k.total.resolution.label1 -text "Display Resolution:"
   label .c.k.total.resolution.label2 -text "Color Depth:"
   label .c.k.total.resolution.label3 -text ""

   radiobutton .c.k.total.resolution.8bit -text "8 bit" -variable displayColor -value 8 -justify left
   radiobutton .c.k.total.resolution.16bit -text "16 bit" -variable displayColor -value 16 -justify left
   radiobutton .c.k.total.resolution.640480 -text "640x480" -variable displayResolution -value 640 -justify left
   radiobutton .c.k.total.resolution.800600 -text "800x600" -variable displayResolution -value 800 -justify left
   radiobutton .c.k.total.resolution.1024768 -text "1024x768" -variable displayResolution -value 1024 -justify left
   radiobutton .c.k.total.resolution.12801024 -text "1280x1024" -variable displayResolution -value 1280 -justify left

   grid .c.k.total.resolution.label1 -row 1 -column 1 -sticky "w"
   grid .c.k.total.resolution.640480 -row 1 -column 2 -sticky "w"
   grid .c.k.total.resolution.800600 -row 2 -column 2 -sticky "w"
   grid .c.k.total.resolution.1024768 -row 1 -column 3 -sticky "w"
   grid .c.k.total.resolution.12801024 -row 2 -column 3 -sticky "w"
   grid .c.k.total.resolution.label3 -row 3 -column 1 -sticky "w"
   grid .c.k.total.resolution.label2 -row 4 -column 1 -sticky "w"
   grid .c.k.total.resolution.8bit -row 4 -column 2 -sticky "w"
   grid .c.k.total.resolution.16bit -row 4 -column 3 -sticky "w"


   grid .c.k.total.data.image2 -row 1 -column 1 -padx 10
   grid .c.k.total.data.label1 -row 1 -column 2 -padx 10

   grid .c.k.total.data -row 1 -column 1 
   grid .c.k.total.dummyv1 -row 2 -column 1
   grid .c.k.total.resolution -row 3 -column 1
   grid .c.k.total.dummyv2 -row 4 -column 1
   grid .c.k.total.next -row 5 -column 1 -sticky E  -padx 10 -pady 5
   grid .c.k.total.back -row 5 -column 1 -sticky W  -padx 10 -pady 5

   pack .c.k.total -side right
   pack .c.k.image1 -side left -pady  10

   proc CheckWizardNextPage {} {
    
     destroy .c.k
     WizardPage4

   }
   proc CheckWizardBackPage {} {
   
     global wizardboot

     destroy .c.k
     if {$wizardboot == 1} {
      WizardPage1
     }
     if {$wizardboot == 2} {
      WizardPage2
     }
   }
}


proc WizardPage2 {} {

   global bootprotocol
   global ip
   global gateway
   global subnetmask
   global nameserver1
   global nameserver2
   global nameserver3
   global hostname
   global domainname

   if {[winfo exists .c.j]} {
        wm deiconify .c.j
	return
   }
   set j [toplevel .c.j -width 500 -height 500]

   wm title .c.j "Specify Static IP Data"
   wm resizable .c.j 0 0
   wm transient .c.j .

   set image1 [image create photo -file /IBM/IBMWIZARD.GIF ]
   set image2 [image create photo -file /IBM/SYSTEM.GIF ]

   frame .c.j.total
   frame .c.j.total.data

   canvas .c.j.total.dummyv -width 465 -height 1
   label .c.j.image1 -image $image1
   label .c.j.total.data.image2 -image $image2
   label .c.j.total.data.label1 -justify left -wraplength 370 -text "The client's IP address is used by your IBM NetworkStation to connect to servers on the network. Please enter the client's static IP data." 
   button .c.j.total.next -text " Next > " -command CheckWizardNextPage 
   button .c.j.total.back -text " < Back "  -command CheckWizardBackPage

###############################################################################

  frame .c.j.total.sip
  frame .c.j.total.sip.ip -bd 8 
  label .c.j.total.sip.ip.label
  foreach i {1 2 3} {
    label .c.j.total.sip.ip.label$i
  }
  entry .c.j.total.sip.ip.entry1 -relief sunken -width 3 
  entry .c.j.total.sip.ip.entry2 -relief sunken -width 3
  entry .c.j.total.sip.ip.entry3 -relief sunken -width 3
  entry .c.j.total.sip.ip.entry4 -relief sunken -width 3
  pack .c.j.total.sip.ip.label -side left
  pack .c.j.total.sip.ip.entry4 -side right 
  pack .c.j.total.sip.ip.label1 -side right
  pack .c.j.total.sip.ip.entry3 -side right 
  pack .c.j.total.sip.ip.label2 -side right
  pack .c.j.total.sip.ip.entry2 -side right 
  pack .c.j.total.sip.ip.label3 -side right
  pack .c.j.total.sip.ip.entry1 -side right 

 foreach i {hostname domainname} {
  frame .c.j.total.sip.$i -bd 2
  entry .c.j.total.sip.$i.entry -relief sunken -width 20
  label .c.j.total.sip.$i.label
  pack .c.j.total.sip.$i.entry -side right -padx 5 
  pack .c.j.total.sip.$i.label -side left -padx 5
 }

 foreach i {gateway subnetmask nameserver1 nameserver2 nameserver3} {
  frame .c.j.total.sip.$i -bd 5
  label .c.j.total.sip.$i.label
  foreach j {1 2 3} {
    label .c.j.total.sip.$i.label$j
  }
  entry .c.j.total.sip.$i.entry1 -relief sunken -width 3
  entry .c.j.total.sip.$i.entry2 -relief sunken -width 3
  entry .c.j.total.sip.$i.entry3 -relief sunken -width 3
  entry .c.j.total.sip.$i.entry4 -relief sunken -width 3
  pack .c.j.total.sip.$i.label -side left
  pack .c.j.total.sip.$i.entry4 -side right -padx 1
  pack .c.j.total.sip.$i.label1 -side right
  pack .c.j.total.sip.$i.entry3 -side right -padx 1
  pack .c.j.total.sip.$i.label2 -side right
  pack .c.j.total.sip.$i.entry2 -side right -padx 1
  pack .c.j.total.sip.$i.label3 -side right
  pack .c.j.total.sip.$i.entry1 -side right -padx 1
 }

 .c.j.total.sip.ip.label config -text "IP Address:"
 .c.j.total.sip.hostname.label config -text "Host Name:"
 .c.j.total.sip.domainname.label config -text "Domain Name:"
 .c.j.total.sip.gateway.label config -text "Gateway:"
 .c.j.total.sip.subnetmask.label config -text "Subnet Mask:"
 .c.j.total.sip.nameserver1.label config -text "First Nameserver:"
 .c.j.total.sip.nameserver2.label config -text "Second Nameserver:"
 .c.j.total.sip.nameserver3.label config -text "Third Nameserver:"
 foreach j {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
    foreach i {1 2 3} {
      .c.j.total.sip.$j.label$i config -text "."
    }
 }
 pack .c.j.total.sip.ip -pady 5  -fill x
 pack .c.j.total.sip.hostname -pady 5   -fill x
 pack .c.j.total.sip.domainname -pady 10  -fill x
 pack .c.j.total.sip.gateway -pady 5 -fill x  
 pack .c.j.total.sip.subnetmask -pady 5 -fill x
 pack .c.j.total.sip.nameserver1 .c.j.total.sip.nameserver2 .c.j.total.sip.nameserver3 -fill x

 #this is where the defaults are loaded ??
 scan $ip "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.ip.entry1 insert 0 $number1
 .c.j.total.sip.ip.entry2 insert 0 $number2
 .c.j.total.sip.ip.entry3 insert 0 $number3
 .c.j.total.sip.ip.entry4 insert 0 $number4
 scan $gateway "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.gateway.entry1 insert 0 $number1
 .c.j.total.sip.gateway.entry2 insert 0 $number2
 .c.j.total.sip.gateway.entry3 insert 0 $number3
 .c.j.total.sip.gateway.entry4 insert 0  $number4
 scan $subnetmask "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.subnetmask.entry1 insert 0 $number1
 .c.j.total.sip.subnetmask.entry2 insert 0 $number2
 .c.j.total.sip.subnetmask.entry3 insert 0 $number3
 .c.j.total.sip.subnetmask.entry4 insert 0 $number4
 scan $nameserver1 "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.nameserver1.entry1 insert 0 $number1
 .c.j.total.sip.nameserver1.entry2 insert 0 $number2
 .c.j.total.sip.nameserver1.entry3 insert 0 $number3
 .c.j.total.sip.nameserver1.entry4 insert 0 $number4
 scan $nameserver2 "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.nameserver2.entry1 insert 0 $number1
 .c.j.total.sip.nameserver2.entry2 insert 0 $number2
 .c.j.total.sip.nameserver2.entry3 insert 0 $number3
 .c.j.total.sip.nameserver2.entry4 insert 0 $number4
 scan $nameserver3 "%d.%d.%d.%d" number1 number2 number3 number4
 .c.j.total.sip.nameserver3.entry1 insert 0 $number1
 .c.j.total.sip.nameserver3.entry2 insert 0 $number2
 .c.j.total.sip.nameserver3.entry3 insert 0 $number3
 .c.j.total.sip.nameserver3.entry4 insert 0 $number4
 .c.j.total.sip.hostname.entry insert 0 $hostname 
 .c.j.total.sip.domainname.entry insert 0 $domainname 
###############################################################################

   grid .c.j.total.data.image2 -row 1 -column 1 -padx 10
   grid .c.j.total.data.label1 -row 1 -column 2 -padx 10

   grid .c.j.total.data -row 1 -column 1 
   grid .c.j.total.dummyv -row 2 -column 1
   grid .c.j.total.sip -row 3 -column 1 -padx 20
   grid .c.j.total.next -row 4 -column 1 -sticky E  -padx 10 -pady 5
   grid .c.j.total.back -row 4 -column 1 -sticky W  -padx 10 -pady 5

   pack .c.j.total -side right
   pack .c.j.image1 -side left -pady  10

   focus .c.j.total.sip.ip.entry1 

   proc CheckWizardNextPage {} {
   
     StoreIP 
     destroy .c.j
     WizardPage3

   }
   proc CheckWizardBackPage {} {
   
     StoreIP
     destroy .c.j
     WizardPage1

   }

   proc StoreIP {} {
     global bootprotocol
     global ip
     global gateway
     global subnetmask
     global nameserver1
     global nameserver2
     global nameserver3
     global hostname
     global domainname
  
     foreach i {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
       set string1 [.c.j.total.sip.$i.entry1 get]
       set string2 [.c.j.total.sip.$i.entry2 get]
       set string3 [.c.j.total.sip.$i.entry3 get]
       set string4 [.c.j.total.sip.$i.entry4 get]
       if {[string length $string1] == 0} then {
          set string1 "0"
       }
       if {[string length $string2] == 0} then {
          set string2 "0"
       }
       if {[string length $string3] == 0} then {
          set string3 "0"
       }
       if {[string length $string4] == 0} then {
          set string4 "0"
       }
       set $i [format "%s.%s.%s.%s" $string1 $string2 $string3 $string4]
     }
     set hostname [.c.j.total.sip.hostname.entry get]
     set domainname [.c.j.total.sip.domainname.entry get]
   }
}

proc WizardPage1 {} {

   global wizardboot

   if {[winfo exists .c.i]} {
        wm deiconify .c.i
	return
   }
   set i [toplevel .c.i -width 500 -height 500]

   wm title .c.i "Welcome"
   wm resizable .c.i 0 0
   wm transient .c.i .

   set image1 [image create photo -file /IBM/IBMWIZARD.GIF ]
   set image2 [image create photo -file /IBM/SYSTEM.GIF ]

   frame .c.i.total
   frame .c.i.total.data
   frame .c.i.total.network 

   canvas .c.i.total.text -width 425 -height 100
   canvas .c.i.total.dummyv -width 425 -height 150
   label .c.i.image1 -image $image1
   label .c.i.total.data.image2 -image $image2
   label .c.i.total.data.label1 -text "Welcome to the IBM NetworkStation Setup program. This\nprogram will help you configure your IBM NetworkStation." 
   button .c.i.total.next -text " Next > "  -command CheckWizardNextPage

   radiobutton .c.i.total.network.dhcp -text "DHCP" -variable wizardboot -value 1 -justify left 
   radiobutton .c.i.total.network.ip -text "Static IP" -variable wizardboot -value 2 -justify left
   
   .c.i.total.text create text 215 90 -text "Please select the method to obtain the system IP address:"

   grid .c.i.total.network.dhcp -row 1 -column 1 -sticky W -pady 5 -padx 5
   grid .c.i.total.network.ip -row 2 -column 1  -sticky W -pady 5 -padx 5

   grid .c.i.total.data.image2 -row 1 -column 1 -padx 10
   grid .c.i.total.data.label1 -row 1 -column 2 -padx 10

   grid .c.i.total.data -row 1 -column 1 
   grid .c.i.total.text -row 2 -column 1 -padx 20
   grid .c.i.total.network -row 3 -column 1
   grid .c.i.total.dummyv -row 4 -column 1
   grid .c.i.total.next -row 5 -column 1 -sticky E -padx 10 -pady 5 

   pack .c.i.total -side right
   pack .c.i.image1 -side left -pady  10

   proc CheckWizardNextPage {} {
    
     global wizardboot
     global bootprotocol

     destroy .c.i 

     if {$wizardboot == 2} {
       set bootprotocol ip
       WizardPage2
     }
     if {$wizardboot == 1} {
       set bootprotocol dhcp
       WizardPage3
     }

   }

}

##################################################################################
# Restore defaults
##################################################################################

proc RestoreDefaults {} {

 if {[winfo exists .c.h]} {
        wm deiconify .c.h
	return
 }

 set h [toplevel .c.h -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.h "Restore Defaults"
 wm resizable .c.h 0 0
 wm transient .c.h .

 global RestoreIP
 global RestoreA
 global RestoreD
 global RestoreMAN

 set RestoreIP 0
 set RestoreD 0
 set RestoreA 0
 set RestoreMAN 0

 frame .c.h.buttons
 frame .c.h.restore
 button .c.h.buttons.close -text "Restore" -command closeRestoreDefaults
 button .c.h.buttons.cancel -text "Cancel" -command cancelRestoreDefaults
 label .c.h.label1 -text "Please make your selection:"
 checkbutton .c.h.restore.restoreip -text "Restore Default Network Settings" -variable RestoreIP -relief flat
 checkbutton .c.h.restore.restoreD -text "Restore Default Display Settings" -variable RestoreD -relief flat
 checkbutton .c.h.restore.restoreA -text "Restore Default Audio Settings" -variable RestoreA -relief flat
 checkbutton .c.h.restore.restoreMAN -text "Restore Default Managment Settings" -variable RestoreMAN -relief flat

 grid .c.h.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.h.buttons.close -row 1 -column 1 -padx 10
 grid .c.h.restore.restoreip -row 1 -column 1 -padx 20 -sticky W
 grid .c.h.restore.restoreD -row 2 -column 1 -padx 20 -sticky W
 grid .c.h.restore.restoreA -row 3 -column 1 -padx 20 -sticky W
 grid .c.h.restore.restoreMAN -row 4 -column 1 -padx 20 -sticky W


 pack .c.h.label1 -fill x -pady 5 -padx 15
 pack .c.h.restore -pady 10
 pack .c.h.buttons -pady 5

 proc closeRestoreDefaults {} {
   global RestoreIP
   global RestoreA
   global RestoreD
   global RestoreMAN

   if {$RestoreMAN|$RestoreIP|$RestoreA|$RestoreD == 1} {
   set button [tk_messageBox -icon question -type okcancel -title "Question" -message "Do you wish to continue?"]
   if {[string compare $button "ok"] == 0} {
      if {$RestoreIP == 1} {
         set filename "/root/IBM/NetworkAddresses"
#         set filename "NetworkAddresses"
         set fd [open $filename w]
         fconfigure $fd
         puts $fd [format "%s=" "bootprotocol" ]
         foreach i {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
            puts $fd [format "%s=%s" $i "0.0.0.0"]
         }
         foreach i {hostname domainname} {
            puts $fd [format "%s=" $i ]
         }
         close $fd
         exec "/bin/sync"
      }
      if {$RestoreA == 1} {
        global soundMaster

        ReadInfoBlock
        set soundMaster 50
        SaveInfoBlock
      }
      if {$RestoreD == 1} {
        global displayResolution
        global displayColor

        ReadInfoBlock
        set displayResolution 640
        set displayColor 8
        SaveInfoBlock
      }
      if {$RestoreMAN == 1} {
        global clientServerConfigure
        global clientServerIP
        global clientROMFlash
        global clientCompactFlash

        ReadInfoBlock
        set clientServerConfigure 1
        set clientServerIP "0.0.0.0"
        set clientROMFlash 1
        set clientCompactFlash 1
        SaveInfoBlock
      }
   }
   destroy .c.h

   }
 }

 proc cancelRestoreDefaults {} {
   destroy .c.h
 }

}



################################################################################
#      Managment Server
################################################################################

proc manServer {} {

 if {[winfo exists .c.g]} {
        wm deiconify .c.g
	return
 }

 set g [toplevel .c.g -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.g "Server Managment"
 wm resizable .c.g 0 0
 wm transient .c.g .

 global clientServerConfigure
 global clientServerIP
 global serverconfigure
 global ison
 global error
 global serverdir
 set serverdir "/tftboot/IBMNetworkStation"
 set error " " 

 frame .c.g.buttons
 frame .c.g.ip
 frame .c.g.mount
#eric
 button .c.g.buttons.mount -text "Mount" -command mountServer 
 button .c.g.buttons.close -text "Save" -command closeManServer
 button .c.g.buttons.cancel -text "Cancel" -command cancelManServer
 checkbutton .c.g.configure -text "Enable Managment" -variable serverconfigure -relief flat -command printMessage 
	
 label .c.g.label -text "Please make your selection:"
 label .c.g.mount.label -text "Server Mount Directory: "
 label .c.g.ip.label -text "IBM Network Station Managment Server: "
 label .c.g.ip.label1 -text "."
 label .c.g.ip.label2 -text "."
 label .c.g.ip.label3 -text "."
 grid .c.g.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.g.buttons.close -row 1 -column 1 -padx 10
 grid .c.g.buttons.mount -row 1 -column 0 -padx 10 

 entry .c.g.mount.entry -relief sunken -width 35 
 entry .c.g.ip.entry1 -relief sunken -width 3 
 entry .c.g.ip.entry2 -relief sunken -width 3
 entry .c.g.ip.entry3 -relief sunken -width 3
 entry .c.g.ip.entry4 -relief sunken -width 3

 #bind the period to focus on the next widget entry
 bind all <period> {
       set string1 [%W get]
       %W delete [string last "%A" $string1]
       if {"%W" != ".c.g.ip.entry4"} {
         focus [tk_focusNext %W]
	 [tk_focusNext %W] select range 0 3 
       }
 }

 #test each key to make sure that it is a numeric (alpha's get a bell)
 bind all <KeyPress> {
  if {"%W" != ".c.g.mount.entry"} {
    set string1 [%W get]
    if {"%A" != "{}"} {
      if {![regexp "\[0-9\x1b\b\t\x7f\n\r\]" %A]} {
        bell
        %W delete [string last "%A" $string1]
        #set error_msg 2
        #set the_focus %W
        #changeState
        focus %W
      } elseif {[string length $string1] > 3} {
          if {![regexp "\[\x1b\x7f\n\r\b\t\]" %A]} {
            if {"%A" != "{}"} {
              bell
              %W delete [string last "%A" $string1]
              #set the_focus %W
              #set error_msg 2
              #changeState
              focus %W
            }
          }
        }
      if {$string1 > 255} {
        bell
        #set error_msg 1
        #changeState
        #set the_focus %W
        %W delete [string last "%A" $string1]
        focus %W
      }
    }
  }
 }


 ReadInfoBlock
#eric
 set serverconfigure $clientServerConfigure
 set serverip $clientServerIP

  if {$serverconfigure == 0} {
       .c.g.buttons.mount configure -state disabled
 } else {
       .c.g.buttons.mount configure -state normal
 }
 

 scan $clientServerIP "%d.%d.%d.%d" number1 number2 number3 number4
 .c.g.ip.entry1 insert 0 $number1
 .c.g.ip.entry2 insert 0 $number2
 .c.g.ip.entry3 insert 0 $number3
 .c.g.ip.entry4 insert 0 $number4

 .c.g.mount.entry insert 0 $serverdir 
 pack .c.g.mount.label -side left
 pack .c.g.mount.entry -side right
 pack .c.g.ip.label -side left
 pack .c.g.ip.entry4 -side right 
 pack .c.g.ip.label1 -side right
 pack .c.g.ip.entry3 -side right 
 pack .c.g.ip.label2 -side right
 pack .c.g.ip.entry2 -side right 
 pack .c.g.ip.label3 -side right
 pack .c.g.ip.entry1 -side right 

 pack .c.g.label -pady 5 -padx 15
 pack .c.g.configure
 pack .c.g.ip -pady 5 -padx 15
 pack .c.g.mount -pady 5 -padx 15
 pack .c.g.buttons -pady 5
 
 proc mountServer {} {
   global clientServerIP
   global serverdir
   exec mount -n -t $clientServerIP:$serverdir/Application /Application
   exec mount -n -t $clientServerIP:$serverdir/Manage /Management
 } 

 proc printMessage {} {
   global serverconfigure
   if {$serverconfigure == 0} {
    	.c.g.buttons.mount configure -state disabled
   } else {
        .c.g.buttons.mount configure -state normal
   }
 }

 proc closeManServer {} {
   global clientServerConfigure
   global clientServerIP
   global serverconfigure

   set string1 [.c.g.ip.entry1 get]
   set string2 [.c.g.ip.entry2 get]
   set string3 [.c.g.ip.entry3 get]
   set string4 [.c.g.ip.entry4 get]
   if {[string length $string1] == 0} then {
      set string1 "0"
   }
   if {[string length $string2] == 0} then {
      set string2 "0"
   }
   if {[string length $string3] == 0} then {
      set string3 "0"
   }
   if {[string length $string4] == 0} then {
      set string4 "0"
   }
   set clientServerIP [format "%d.%d.%d.%d" $string1 $string2 $string3 $string4]
   set clientServerConfigure $serverconfigure
   SaveInfoBlock
   destroy .c.g
 }

 proc cancelManServer {} {
   destroy .c.g
 }

}

################################################################################
#      Managment ROM
################################################################################

proc manROM {} {

 if {[winfo exists .c.f]} {
        wm deiconify .c.f
	return
 }

 set f [toplevel .c.f -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.f "System ROM Managment"
 wm resizable .c.f 0 0
 wm transient .c.f .

 global clientROMFlash
 global allowrom

 ReadInfoBlock

 set allowrom $clientROMFlash

 frame .c.f.buttons
 button .c.f.buttons.close -text "Save" -command closeManROM
 button .c.f.buttons.cancel -text "Cancel" -command cancelManROM
 label .c.f.label1 -text "Please make your selection:"
 checkbutton .c.f.configure -text "Enable System ROM Managment: " -variable allowrom -relief flat

 grid .c.f.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.f.buttons.close -row 1 -column 1 -padx 10

 pack .c.f.label1 -fill x -pady 5 -padx 15
 pack .c.f.configure
 pack .c.f.buttons -pady 5

 proc closeManROM {} {
   global clientROMFlash
   global allowrom

   set clientROMFlash $allowrom
   SaveInfoBlock
   destroy .c.f
 }

 proc cancelManROM {} {
   destroy .c.f
 }

}



################################################################################
#      Managment Compact Flash
################################################################################

proc manCompactFlash {} {

 if {[winfo exists .c.e]} {
        wm deiconify .c.e
	return
 }

 set e [toplevel .c.e -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.e "Compact Flash Managment"
 wm resizable .c.e 0 0
 wm transient .c.e .

 global clientCompactFlash
 global allowcf

 ReadInfoBlock

 set allowcf $clientCompactFlash


 frame .c.e.buttons
 button .c.e.buttons.close -text "Save" -command closeManCompactFlash
 button .c.e.buttons.cancel -text "Cancel" -command cancelCompactFlash
 label .c.e.label1 -text "Please make your selection:"
 checkbutton .c.e.configure -text "Enable System Compact Flash Managment: " -variable allowcf -relief flat


 grid .c.e.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.e.buttons.close -row 1 -column 1 -padx 10

 pack .c.e.label1 -fill x -pady 5 -padx 15
 pack .c.e.configure
 pack .c.e.buttons -pady 5

 proc closeManCompactFlash {} {
   global clientCompactFlash
   global allowcf

   set clientCompactFlash $allowcf
   SaveInfoBlock
   destroy .c.e
 }

 proc cancelCompactFlash {} {
   destroy .c.e
 }

}



################################################################################
#         display menu
################################################################################

proc displaySettings {} {

 if {[winfo exists .c.d]} {
        wm deiconify .c.d
	return
 }

 set d [toplevel .c.d -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.d "Display Settings"
 wm resizable .c.d 0 0
 wm transient .c.d .

 global displayResolution
 global displayColor
 global depth
 global resolution

 ReadInfoBlock

 set depth $displayColor
 set resolution $displayResolution

 frame .c.d.buttons
 frame .c.d.resolution
 button .c.d.buttons.close -text "Save" -command closeDisplay
 button .c.d.buttons.cancel -text "Cancel" -command cancelDisplay
 label .c.d.label1 -text "Please make your selection:"
 label .c.d.resolution.label1 -text "Display Resolution:"
 label .c.d.resolution.label2 -text "Color Depth:"
 label .c.d.resolution.label3 -text ""

 radiobutton .c.d.resolution.8bit -text "8 bit" -variable depth -value 8 -justify left
 radiobutton .c.d.resolution.16bit -text "16 bit" -variable depth -value 16 -justify left
 radiobutton .c.d.resolution.640480 -text "640x480" -variable resolution -value 640 -justify left
 radiobutton .c.d.resolution.800600 -text "800x600" -variable resolution -value 800 -justify left
 radiobutton .c.d.resolution.1024768 -text "1024x768" -variable resolution -value 1024 -justify left
 radiobutton .c.d.resolution.12801024 -text "1280x1024" -variable resolution -value 1280 -justify left
 grid .c.d.resolution.label1 -row 1 -column 1 -sticky "w"
 grid .c.d.resolution.640480 -row 1 -column 2 -sticky "w"
 grid .c.d.resolution.800600 -row 2 -column 2 -sticky "w"
 grid .c.d.resolution.1024768 -row 1 -column 3 -sticky "w"
 grid .c.d.resolution.12801024 -row 2 -column 3 -sticky "w"
 grid .c.d.resolution.label3 -row 3 -column 1 -sticky "w"
 grid .c.d.resolution.label2 -row 4 -column 1 -sticky "w"
 grid .c.d.resolution.8bit -row 4 -column 2 -sticky "w"
 grid .c.d.resolution.16bit -row 4 -column 3 -sticky "w"

 grid .c.d.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.d.buttons.close -row 1 -column 1 -padx 10

 pack .c.d.label1 -fill x -pady 5 -padx 10
 pack .c.d.resolution -pady 5 -padx 10
 pack .c.d.buttons -pady 5

 proc closeDisplay {} {
   global displayResolution
   global displayColor
   global depth
   global resolution

   set displayColor $depth
   set displayResolution $resolution 
   SaveInfoBlock
   destroy .c.d
 }

 proc cancelDisplay {} {
   destroy .c.d
 }

}

################################################################################
#         audio menu
################################################################################

proc audioSettings {} {

 if {[winfo exists .c.c]} {
        wm deiconify .c.c
	return
 }

 set c [toplevel .c.c -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.c "Audio Settings"
 wm resizable .c.c 0 0
 wm transient .c.c .

 global mastervolume
 global soundMaster

 ReadInfoBlock

 set mastervolume $soundMaster

######################### Must make an exec later
# set mastervolume 5     
  scan [split [exec "/IBM/volume"] "=," ] "%s %s %s %s %d" string1 string2 string3 string4 number1
  set mastervolume $number1
#########################

 frame .c.c.buttons
 button .c.c.buttons.close -text "Save" -command closeBox
 button .c.c.buttons.cancel -text "Cancel" -command cancelAudio
 label .c.c.label1 -text "Please make your selection:"
 scale .c.c.scale -orient vertical -length 150 -from 100 -to 0 -tickinterval 50 -variable mastervolume -command AdjustVolume
 label .c.c.label2 -text "Master Volume"

 grid .c.c.buttons.cancel -row 1 -column 2 -padx 10
 grid .c.c.buttons.close -row 1 -column 1 -padx 10

 pack .c.c.label1 -fill x -pady 5 -padx 10
 pack .c.c.scale -padx 5
 pack .c.c.label2
 pack .c.c.buttons -pady 5 

 proc closeBox {} {
   global soundMaster
   global mastervolume

   set soundMaster $mastervolume
   SaveInfoBlock
   destroy .c.c
 }

 proc cancelAudio {} {
   global soundMaster
   exec "/IBM/volume" $soundMaster
   destroy .c.c
 }

 proc AdjustVolume args {
   global mastervolume
   exec "/IBM/volume" $mastervolume
 }

}

################################################################################
#         Help Menu
################################################################################

proc AboutIBM {} {

 if {[winfo exists .c.b]} {
        wm deiconify .c.b
	return
 }

 set b [toplevel .c.b -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.b "About IBM Network Station Setup"
 wm resizable .c.b 0 0
 wm transient .c.b .

 button .c.b.close -text "Close" -command closeAboutBox
 label .c.b.label1
 label .c.b.label2
 label .c.b.label3
 label .c.b.label4

 .c.b.label1 config -text "IBM Network Station Setup Utility"
 .c.b.label2 config -text "Version 3.1 - December 2, 1999"
 .c.b.label3 config -text ""
 .c.b.label4 config -text "http://www.pc.ibm.com/us/networkstation"

 pack .c.b.label1 -fill x -pady 5 
 pack .c.b.label2 -fill x 
 pack .c.b.label3 -fill x
 pack .c.b.label4 -fill x -padx 20
 pack .c.b.close -pady 5

 proc closeAboutBox {} {
   destroy .c.b
 }

}



################################################################################
#         Network IP configure
################################################################################

proc NetworkIP {} {

 if {[winfo exists .c.a]} {
	wm deiconify .c.a
	return
 }
  
  global bootprotocol
  global ip
  global gateway
  global subnetmask
  global nameserver1
  global nameserver2
  global nameserver3
  global hostname
  global domainname
  global error_msg
  global the_focus
 
 set error_msg 0
 set a [toplevel .c.a -width 545 -height 195 -relief sunken -bd 4]

 wm title .c.a "Network Setup"
 wm resizable .c.a 0 0
 wm transient .c.a .

 label .c.a.label 
 frame .c.a.sel 
 frame .c.a.sip

 radiobutton .c.a.sel.dhcp -text "DHCP" -variable bootprotocol -value dhcp -justify left -command changeState
 radiobutton .c.a.sel.bootp -text "BOOTP" -variable bootprotocol -value bootp -justify left -command changeState
 radiobutton .c.a.sel.ip -text "Specify IP" -variable bootprotocol -value ip -justify left -command changeState
 button .c.a.sel.save -text "Save" -command SaveIPClose
 button .c.a.sel.cancel -text "Cancel" -command restoreip

 grid .c.a.sel.dhcp -row 1 -column 1 -sticky "w"
 grid .c.a.sel.bootp -row 2 -column 1 -sticky "w"
 grid .c.a.sel.ip -row 3 -column 1 -sticky "w"
 grid .c.a.sel.save -row 4 -column 1 -pady 5
 grid .c.a.sel.cancel -row 4 -column 2 
 
################################################################################
#   NVRAM Boot
################################################################################
# if {[winfo exists .c.d]} {
#	wm deiconify .c.d
#	return
# }
# set d [toplevel .c.d -width 545 -height 195 -relief sunken -bd 2]
# wm title .c.d "Set Individual IP Address"

  #eric
  frame .c.a.ser -bd 8
  label .c.a.ser.label
  
  .c.a.ser.label config -text "" 
  pack .c.a.ser.label -side left -fill x -pady 10
 
  #grid .c.a.ser -row 4 -column 2 -sticky "s" 

  frame .c.a.serr -bd 8
  #button .c.a.serr.close -text "OK" -command {grid remove .c.a.serr}
  label .c.a.serr.label
  label .c.a.serr.icon -bitmap error 

  .c.a.serr.label config -text "Must be a number between 0 and 255"
  pack .c.a.serr.icon -side left -pady 10 
  pack .c.a.serr.label -side left -fill x -pady 10 
  #pack .c.a.serr.close -side right -padx 10 -pady 5

  frame .c.a.serr2 -bd 8
  #button .c.a.serr2.close -text "OK" -command {grid remove .c.a.serr2}
  label .c.a.serr2.label
  label .c.a.serr2.icon -bitmap error

  .c.a.serr2.label config -text "Please Enter Numbers Only"
  pack .c.a.serr2.icon -side left -pady 10
  pack .c.a.serr2.label -side left -fill x -pady 10
  #pack .c.a.serr2.close -side right -padx 10 -pady 5

  frame .c.a.sip.ip -bd 8 
  label .c.a.sip.ip.label
   
  foreach i {1 2 3} {
    label .c.a.sip.ip.label$i
  }
  #These set the blanks for the IP address
  entry .c.a.sip.ip.entry1 -relief sunken -width 3 
  entry .c.a.sip.ip.entry2 -relief sunken -width 3
  entry .c.a.sip.ip.entry3 -relief sunken -width 3
  entry .c.a.sip.ip.entry4 -relief sunken -width 3
  pack .c.a.sip.ip.label -side left
  pack .c.a.sip.ip.entry4 -side right 
  pack .c.a.sip.ip.label1 -side right
  pack .c.a.sip.ip.entry3 -side right 
  pack .c.a.sip.ip.label2 -side right
  pack .c.a.sip.ip.entry2 -side right 
  pack .c.a.sip.ip.label3 -side right
  pack .c.a.sip.ip.entry1 -side right 

 #these set the blanks for the hostname and domainname
 foreach i {hostname domainname} {
  frame .c.a.sip.$i -bd 2
  entry .c.a.sip.$i.entry -relief sunken -width 20
  label .c.a.sip.$i.label
  pack .c.a.sip.$i.entry -side right -padx 5 
  pack .c.a.sip.$i.label -side left -padx 5
 }

 #These set the sunken blanks for gateway subnetmask nameserver1 etc
 foreach i {gateway subnetmask nameserver1 nameserver2 nameserver3} {
  frame .c.a.sip.$i -bd 5
  label .c.a.sip.$i.label
  foreach j {1 2 3} {
    label .c.a.sip.$i.label$j
  }
  
  entry .c.a.sip.$i.entry1 -relief sunken -width 3
  entry .c.a.sip.$i.entry2 -relief sunken -width 3
  entry .c.a.sip.$i.entry3 -relief sunken -width 3
  entry .c.a.sip.$i.entry4 -relief sunken -width 3
  pack .c.a.sip.$i.label -side left
  pack .c.a.sip.$i.entry4 -side right -padx 1
  pack .c.a.sip.$i.label1 -side right
  pack .c.a.sip.$i.entry3 -side right -padx 1
  pack .c.a.sip.$i.label2 -side right
  pack .c.a.sip.$i.entry2 -side right -padx 1
  pack .c.a.sip.$i.label3 -side right
  pack .c.a.sip.$i.entry1 -side right -padx 1
 }

 .c.a.sip.ip.label config -text "IP Address:"
 .c.a.sip.hostname.label config -text "Host Name:"
 .c.a.sip.domainname.label config -text "Domain Name:"
 .c.a.sip.gateway.label config -text "Gateway:"
 .c.a.sip.subnetmask.label config -text "Subnet Mask:"
 .c.a.sip.nameserver1.label config -text "First Nameserver:"
 .c.a.sip.nameserver2.label config -text "Second Nameserver:"
 .c.a.sip.nameserver3.label config -text "Third Nameserver:"
 foreach j {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
    foreach i {1 2 3} {
      .c.a.sip.$j.label$i config -text "."
    }
 }
 pack .c.a.sip.ip -pady 5 -fill x 
 pack .c.a.sip.hostname -pady 5   -fill x
 pack .c.a.sip.domainname -pady 10  -fill x
 pack .c.a.sip.gateway -pady 5 -fill x  
 pack .c.a.sip.subnetmask -pady 5 -fill x
 pack .c.a.sip.nameserver1 .c.a.sip.nameserver2 .c.a.sip.nameserver3 -fill x

 .c.a.label config -text "Please make your selection:"

 grid .c.a.label -row 1 -column 1 -sticky "w" -padx 5
 grid .c.a.sel -row 2 -column 1 -sticky "n" 

# bind .c.a.sip.ip.entry1 <KeyPress> {tk_messageBox -message "%%K=%K\n%%A=%A\n123"}
 
 #bind the period to focus on the next widget entry
 bind all <period> {
    if {"%W" != ".c.a.sip.hostname.entry"} {
      if {"%W" != ".c.a.sip.domainname.entry"} {
       set string1 [%W get]
       %W delete [string last "%A" $string1]
       if {"%W" != ".c.a.sip.nameserver3.entry4"} {
         focus [tk_focusNext %W]
         if {[tk_focusNext %W] != ".c.a.sip.hostname.entry"} {
	   [tk_focusNext %W] select range 0 3
         }
       }
      }
    } 
 }

 #test each key to make sure that it is a numeric (alpha's get a bell) 
 bind all <KeyPress> {
       set string1 [%W get]
 if {"%W" != ".c.a.sip.hostname.entry"} {
  if {"%W" != ".c.a.sip.domainname.entry"} { 
    if {"%A" != "{}"} {
      if {![regexp "\[0-9\x1b\b\t\x7f\n\r\]" %A]} {
        bell
        %W delete [string last "%A" $string1]
        set error_msg 2
        set the_focus %W
        changeState
        focus %W
      } elseif {[string length $string1] > 3} {
          if {![regexp "\[\x1b\x7f\n\r\b\t\]" %A]} {
            if {"%A" != "{}"} {
              bell
              %W delete [string last "%A" $string1]
              set the_focus %W
              set error_msg 2
              changeState
              focus %W
            }
          }
      } else {
	  grid remove .c.a.serr2
  	  grid .c.a.ser -row 4 -column 2 -sticky "s"
	} 
      if {$string1 > 255} {
        bell
        set error_msg 1
        changeState
        set the_focus %W
        %W delete [string last "%A" $string1]
        focus %W
      } else { 
          grid remove .c.a.serr
	  grid .c.a.ser -row 4 -column 2 -sticky "s"
	}
    }
   }
  }
 }
 
 proc changeState args {
   global bootprotocol
   global error_msg
   global the_focus 
   if {$bootprotocol == "ip"} {
	catch {
         grid .c.a.sip -row 2  -column 2 -sticky "w"
 	 grid .c.a.ser -row 4 -column 2 -sticky "s"
	 focus .c.a.sip.ip.entry1
        }
   } else {
         set error_msg 0
         grid remove .c.a.sip
 	 grid remove .c.a.serr
	 grid remove .c.a.ser
	 grid remove .c.a.serr2 
         focus .c.a.label
   }
   if {$error_msg == 1} {
     catch {
      grid remove .c.a.ser
      grid remove .c.a.serr2
      grid .c.a.serr -row 4 -column 2 -sticky "s"
      focus $the_focus
     }
   }  elseif {$error_msg == 2} {
	 catch {
           grid remove .c.a.ser
           grid remove .c.a.serr
	   grid .c.a.serr2 -row 4 -column 2 -sticky "s"
           focus $the_focus
         }
      } 
 }

 proc SaveIPClose {} {
  global bootprotocol
  global ip
  global gateway
  global subnetmask
  global nameserver1
  global nameserver2
  global nameserver3
  global hostname
  global domainname
  set error_msg 1
  #Before saving test to see if number is negative or > 255
  foreach i {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
    set string1 [.c.a.sip.$i.entry1 get]
    set string2 [.c.a.sip.$i.entry2 get]
    set string3 [.c.a.sip.$i.entry3 get]
    set string4 [.c.a.sip.$i.entry4 get]
   if {[string length $string1] == 0} then {
       set string1 "0"
       set error_msg 1
    }
   #If there's nothing in the field, enter a 0 as the value
    if {[string length $string2] == 0} then {
       set string2 "0"
       set error_msg 1
    }
    if {[string length $string3] == 0} then {
       set string3 "0"
       set error_msg 1
    }
    if {[string length $string4] == 0} then {
       set string4 "0"
       set error_msg 1
    }
    set $i [format "%s.%s.%s.%s" $string1 $string2 $string3 $string4]
  }
  set hostname [.c.a.sip.hostname.entry get]
  set domainname [.c.a.sip.domainname.entry get]

  if {$error_msg == 1} then {
     saveip
     destroy .c.a
  }
  if {$error_msg == 0} then {
     tk_messageBox -title Error -message "Must be a number between 0 and 255"
  }
 }

 proc ReadIPOpen {} {
  
  global bootprotocol
  global ip
  global gateway
  global subnetmask
  global nameserver1
  global nameserver2
  global nameserver3
  global hostname
  global domainname

  readip

  scan $ip "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.ip.entry1 insert 0 $number1
  .c.a.sip.ip.entry2 insert 0 $number2
  .c.a.sip.ip.entry3 insert 0 $number3
  .c.a.sip.ip.entry4 insert 0 $number4
  scan $gateway "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.gateway.entry1 insert 0 $number1
  .c.a.sip.gateway.entry2 insert 0 $number2
  .c.a.sip.gateway.entry3 insert 0 $number3
  .c.a.sip.gateway.entry4 insert 0 $number4
  scan $subnetmask "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.subnetmask.entry1 insert 0 $number1
  .c.a.sip.subnetmask.entry2 insert 0 $number2
  .c.a.sip.subnetmask.entry3 insert 0 $number3
  .c.a.sip.subnetmask.entry4 insert 0 $number4
  scan $nameserver1 "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.nameserver1.entry1 insert 0 $number1
  .c.a.sip.nameserver1.entry2 insert 0 $number2
  .c.a.sip.nameserver1.entry3 insert 0 $number3
  .c.a.sip.nameserver1.entry4 insert 0 $number4
  scan $nameserver2 "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.nameserver2.entry1 insert 0 $number1
  .c.a.sip.nameserver2.entry2 insert 0 $number2
  .c.a.sip.nameserver2.entry3 insert 0 $number3
  .c.a.sip.nameserver2.entry4 insert 0 $number4
  scan $nameserver3 "%d.%d.%d.%d" number1 number2 number3 number4
  .c.a.sip.nameserver3.entry1 insert 0 $number1
  .c.a.sip.nameserver3.entry2 insert 0 $number2
  .c.a.sip.nameserver3.entry3 insert 0 $number3
  .c.a.sip.nameserver3.entry4 insert 0 $number4
  .c.a.sip.hostname.entry insert 0 $hostname 
  .c.a.sip.domainname.entry insert 0 $domainname 

 }

 proc restoreip args {
   destroy .c.a
 }

 ReadIPOpen
 changeState
}	

##############################################################################
# Save NetworkAddresses file
##############################################################################

proc saveip args {
  global bootprotocol
  global ip
  global gateway
  global subnetmask
  global nameserver1
  global nameserver2
  global nameserver3
  global hostname
  global domainname
#dabba
  #tk_messageBox -message "$bootprotocol\n$ip\n$gateway\n$subnetmask\n$nameserver1\n$nameserver2\n$nameserver3\n$hostname\n$domainname"

  set filename "/root/IBM/NetworkAddresses"
#  set filename "NetworkAddresses"
  set fd [open $filename w]
  fconfigure $fd
  puts $fd [format "%s=%s" "bootprotocol" $bootprotocol]
  puts $fd [format "%s=%s" "ip" $ip] 
  puts $fd [format "%s=%s" "gateway" $gateway] 
  puts $fd [format "%s=%s" "subnetmask" $subnetmask] 
  puts $fd [format "%s=%s" "nameserver1" $nameserver1] 
  puts $fd [format "%s=%s" "nameserver2" $nameserver2] 
  puts $fd [format "%s=%s" "nameserver3" $nameserver3] 
  puts $fd [format "%s=%s" "hostname" $hostname ]
  puts $fd [format "%s=%s" "domainname" $domainname ]

  close $fd
  exec "/bin/sync"
}

##############################################################################
# Read NetworkAddresses file
##############################################################################

proc readip args {
  global bootprotocol
  global ip
  global gateway
  global subnetmask
  global nameserver1
  global nameserver2
  global nameserver3
  global hostname
  global domainname

  set filename "/root/IBM/NetworkAddresses"
#  set filename "NetworkAddresses"
  set fd [open $filename r]
  fconfigure $fd
###############
# Boot protocol
###############
  gets $fd entry1
  set result [scan [split $entry1 "="] "%s %s" identifer string1]
  if { [string match $string1 "{}" ] == 1} then {
       set string1 ""
  }
  if { $result == 1} then {
       set string1 ""
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: value - bootprotocol"
  }
  if {[string match $identifer "bootprotocol"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: identifer - bootprotocol"
  }
  set bootprotocol $string1
#############
# Numbers
#############
  foreach i {ip gateway subnetmask nameserver1 nameserver2 nameserver3} {
    gets $fd entry1
    if {[scan [split $entry1 "="] "%s %s" identifer string1] != 2} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: value - $i"
    }
    if {[string match $identifer $i] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: identifer - $i"
    }
#    .c.a.sip.$i.entry1 insert 0 $number1
#    .c.a.sip.$i.entry2 insert 0 $number2
#    .c.a.sip.$i.entry3 insert 0 $number3
#    .c.a.sip.$i.entry4 insert 0 $number4
    set $i $string1
  }
  gets $fd entry1
##################
# hostname
##################
  set result [scan [split $entry1 "=" ] "%s %s" identifer string1]
  if { [string match $string1 "{}" ] == 1} then {
       set string1 ""
  }
  if {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: value - hostname"
  }
  if {[string match $identifer "hostname"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: identifer - hostname"
  }
  set hostname $string1
##################
# domainname
##################
  gets $fd entry1
  set result [scan [split $entry1 "=" ] "%s %s" identifer string1]
  if { [string match $string1 "{}" ] == 1} then {
       set string1 ""
  }
  if {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: value - domainname"
  }
  if {[string match $identifer "domainname"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your NetworkAddresses file: identifer - domainname"
  }
  set domainname $string1
  close $fd
  exec "/bin/sync"
}

##############################################################################
# Save Info Block
##############################################################################

proc SaveInfoBlock args {
  global soundMaster
  global displayResolution
  global displayColor
  global clientServerConfigure
  global clientServerIP
  global clientROMFlash
  global clientCompactFlash

#  set filename "IBMSetupInformationBlock"
  set filename "/root/IBM/IBMSetupInformationBlock"
  set fd [open $filename w]
  fconfigure $fd
  puts $fd [format "%s=%s" "soundmaster" $soundMaster]
  puts $fd [format "%s=%s" "displayresolution" $displayResolution]
  puts $fd [format "%s=%s" "displaycolor" $displayColor]
  puts $fd [format "%s=%s" "clientserverconfigure" $clientServerConfigure]
  puts $fd [format "%s=%s" "clientserverip" $clientServerIP]
  puts $fd [format "%s=%s" "clientromflash" $clientROMFlash]
  puts $fd [format "%s=%s" "clientcompactflash" $clientCompactFlash]
  close $fd
  exec "/bin/sync"
}
##############################################################################
# Read Info Block
##############################################################################

proc ReadInfoBlock args {
  global soundMaster
  global displayResolution
  global displayColor
  global clientServerConfigure
  global clientServerIP
  global clientROMFlash
  global clientCompactFlash

#  set filename "IBMSetupInformationBlock"
  set filename "/root/IBM/IBMSetupInformationBlock"
  set fd [open $filename r]
  fconfigure $fd

######### Master Volume

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 10
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - soundMaster"
  }
  if {[string match $identifer "soundmaster"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - soundMaster"
  }
  set soundMaster $number

######### Display Resolution

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 640
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - displayResolution"
  }
  if {[string match $identifer "displayresolution"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - displayResolution"
  }
  set displayResolution $number

######### Display Color Depth

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 8
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - displayColor"
  }
  if {[string match $identifer "displaycolor"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - displayResolution"
  }
  set displayColor $number

######### Client Server Configure

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 1
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - clientServerConfigure"
  }
  if {[string match $identifer "clientserverconfigure"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - clientServerConfigure"
  }
  set clientServerConfigure $number

######### Client Server IP

  gets $fd entry
  set result [scan [split $entry "="] "%s %s" identifer string]
  if { $result == 1} then {
       set string ""
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - clientServerIP"
  }
  if {[string match $identifer "clientserverip"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - clientServerIP"
  }
  set clientServerIP $string

######### Client ROM Flash

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 1
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - clientROMFlash"
  }
  if {[string match $identifer "clientromflash"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - clientROMFlash"
  }
  set clientROMFlash $number

######### Client Compact Flash

  gets $fd entry
  set result [scan [split $entry "="] "%s %d" identifer number]
  if { $result == 1} then {
       set number 1
  } elseif {$result != 2} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: value - clientCompactFlash"
  }
  if {[string match $identifer "clientcompactflash"] == 0} then {
       tk_messageBox -title Error -message "An error occured reading your IBMSetupInformationBlock file: identifer - clientCompactFlash"
  }
  set clientCompactFlash $number
  close $fd
  exec "/bin/sync"
}

proc Pleaseexit {} {
 tk_messageBox -title "Information" -message "You must reboot for changes to take effect."
 exit
}


proc ForceWizard {} {
 global wizardboot
 global bootprotocol
 global ip
 global gateway
 global subnetmask
 global nameserver1
 global nameserver2
 global nameserver3
 global hostname
 global domainname
 global displayResolution
 global displayColor
 global clientServerIP
 global clientServerConfigure

 readip
 ReadInfoBlock
 if {[string compare $bootprotocol "ip"] == 0} {
  set wizardboot 2
 }
 if {[string compare $bootprotocol "dhcp"] == 0} {
  set wizardboot 1
 }
 if {[string compare $bootprotocol "bootp"] == 0} {
  set wizardboot 1
 }
 if {[string length $bootprotocol ] == 0} {
  set wizardboot 1
 }

 WizardPage1
}

################################################################################
#        Menu Bar
################################################################################

menu .menu -tearoff 1 -type menubar

set m .menu.file
menu $m -tearoff 0
.menu add cascade -label "File" -menu $m -underline 0
$m add command -label "Exit..." -command "Pleaseexit" -underline 0
bind . "Pleaseexit"

set m .menu.network
menu $m -tearoff 0
.menu add cascade -label "Network" -menu $m -underline 0
$m add command -label "TCP/IP Address" -command "NetworkIP" -underline 0 -command NetworkIP
bind . "NetworkIP"

set m .menu.configure
menu $m -tearoff 0
.menu add cascade -label "Settings" -menu $m -underline 0
$m add command -label "Display Settings" -underline 0 -command displaySettings
$m add command -label "Audio Settings" -underline 0 -command audioSettings
bind . "Settings"

set m .menu.managment
menu $m -tearoff 0
.menu add cascade -label "Managment" -menu $m -underline 0
$m add command -label "Managment Server" -underline 0 -command manServer
$m add command -label "Compact Flash Managment" -underline 0 -command manCompactFlash
$m add command -label "System ROM Managment" -underline 0 -command manROM
bind . "Managment"

set m .menu.restore
menu $m -tearoff 0
.menu add cascade -label "System" -menu $m -underline 0
$m add command -label "Restore Defaults" -underline 0 -command RestoreDefaults
$m add command -label "Setup Wizard" -underline 0 -command ForceWizard
bind . "System"

set m .menu.help
menu $m -tearoff 0
.menu add cascade -label "Help" -menu $m -underline 0
$m add command -label "About" -underline 0 -command AboutIBM
bind . "AboutIBM"

. configure -menu .menu

CheckForFiles
CheckForWizard
