#!/usr/bin/wish
# read the config file
load ./tclLdap.so
proc bindtodb {} {
LdapBind $host $binddn $bindpw
exit
}
set configfile "~/.ldaprc"
set base "random"
set port "389"
global host
global base
global binddn
global bindpw
global port
set conf [ open $configfile r]
while { [ eof $conf ] == 0 } {
gets $conf confline
regexp {^BASE +(.*)} $confline x base
regexp {^HOST +(.*)} $confline x host
regexp {^PORT +(.*)} $confline x port
}
close $conf
set binddn "uid=$env(USER),$base"

# create the login widget
frame .login
label .login.binddn_txt \
  -text "Bind DN"
entry .login.binddn \
  -width 30 \
  -textvariable binddn

label .login.bindpw_txt \
  -text "Bind Pw"
entry .login.bindpw \
  -width 30 \
  -show * \
  -textvariable bindpw

label .login.base_txt \
  -text "Base"
entry .login.base \
  -width 30 \
  -textvariable base

label .login.host_txt \
 -text "Server"
entry .login.host \
  -width 30 \
  -textvariable host

label .login.port_txt \
 -text "Port"
entry .login.port \
  -width 30 \
  -textvariable port
frame .go
button .go.bindtoldap \
  -text "Bind to Database" \
  -command { LdapBind $host $port $binddn $bindpw }

grid config .login.binddn_txt -column 0 -row 0 -sticky e
grid config .login.binddn -column 1 -row 0 -sticky e
grid config .login.bindpw_txt -column 0 -row 1 -sticky e
grid config .login.bindpw -column 1 -row 1 -sticky e
grid config .login.base_txt -column 0 -row 2 -sticky e
grid config .login.base -column 1 -row 2 -sticky e
grid config .login.host_txt -column 0 -row 3 -sticky e
grid config .login.host -column 1 -row 3 -sticky e
grid config .login.port_txt -column 0 -row 4 -sticky e
grid config .login.port -column 1 -row 4 -sticky e
pack .go.bindtoldap
pack .login .go
