# COPYRIGHT POLICY
# ----------------
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to Free Software Foundation, Inc.
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Copyright (C) 1998 Luc Deschenaux <lcd@gkb.com>
#
# DISCLAIMER
# ----------
# Use it at your own risk. You're sole responsible for anything that could
# happend before, while, after or without using this program.

# the next line restarts using wish \
exec wish "$0" "$@"
# interface generated by SpecTcl version 1.1 from /root/vftpd/EdUser.ui
#   root     is the parent window for this user interface

proc EdUser_ui {root args} {

	# this treats "." as a special case

	if {$root == "."} {
	    set base ""
	} else {
	    set base $root
	}
    
	label $base.label#1 \
		-text User:

	entry $base.entry#1 \
		-textvariable login \
		-width 10
	catch {
		$base.entry#1 configure \
			-font -*-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*
	}

	label $base.label#6 \
		-text Login:

	entry $base.entry#6 \
		-textvariable server_login \
		-width 10
	catch {
		$base.entry#6 configure \
			-font -*-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*
	}

	label $base.label#2 \
		-text Password:

	entry $base.entry#2 \
		-textvariable pass \
		-width 10

	label $base.label#7 \
		-text Pass:

	entry $base.entry#7 \
		-textvariable server_pass \
		-width 10

	label $base.label#3 \
		-text Port:

	entry $base.entry#3 \
		-textvariable port \
		-width 5

	label $base.label#8 \
		-text Port:

	entry $base.entry#8 \
		-textvariable server_port \
		-width 5

	label $base.label#4 \
		-text {Max connections:}

	entry $base.entry#4 \
		-textvariable maxCon \
		-width 5

	label $base.label#9 \
		-text Server:

	entry $base.entry#9 \
		-textvariable address \
		-width 40

	label $base.label#5 \
		-text {Max idle time:}

	entry $base.entry#5 \
		-textvariable maxIdle \
		-width 5

	label $base.label#10 \
		-text Path:

	entry $base.entry#10 \
		-textvariable path \
		-width 40

	checkbutton $base.checkbutton#1 \
		-text chroot \
		-variable chroot

	label $base.label#11 \
		-text Permissions:

	checkbutton $base.checkbutton#2 \
		-text Download \
		-variable down_perm

	entry $base.entry#11 \
		-cursor {} \
		-textvariable ratio \
		-width 5

	checkbutton $base.checkbutton#5 \
		-justify left \
		-text Ratio \
		-variable ratio_enable

	checkbutton $base.checkbutton#3 \
		-text Upload \
		-variable up_perm

	entry $base.entry#12 \
		-justify right \
		-textvariable ratio_ul

	label $base.label#12 \
		-text {bytes uploaded.}

	checkbutton $base.checkbutton#4 \
		-text Change \
		-variable chg_perm

	entry $base.entry#13 \
		-justify right \
		-textvariable ratio_dl

	label $base.label#13 \
		-text {bytes downloaded.}

	checkbutton $base.checkbutton#6 \
		-text {Disk cache:} \
		-variable cache_enable

	entry $base.entry#14 \
		-textvariable cache_dir \
		-width 40

	button $base.button#2 \
		-text Cancel \
		-width 8
	catch {
		$base.button#2 configure \
			-font -*-Helvetica-Bold-R-Normal-*-*-120-*-*-*-*-*-*
	}

	button $base.button#1 \
		-text OK \
		-width 8


	# Geometry management

	grid $base.label#1 -in $root	-row 2 -column 2  \
		-sticky e
	grid $base.entry#1 -in $root	-row 2 -column 3  \
		-sticky w
	grid $base.label#6 -in $root	-row 2 -column 4  \
		-sticky e
	grid $base.entry#6 -in $root	-row 2 -column 5  \
		-sticky w
	grid $base.label#2 -in $root	-row 3 -column 2  \
		-sticky e
	grid $base.entry#2 -in $root	-row 3 -column 3  \
		-sticky w
	grid $base.label#7 -in $root	-row 3 -column 4  \
		-sticky e
	grid $base.entry#7 -in $root	-row 3 -column 5  \
		-sticky w
	grid $base.label#3 -in $root	-row 4 -column 2  \
		-sticky e
	grid $base.entry#3 -in $root	-row 4 -column 3  \
		-sticky w
	grid $base.label#8 -in $root	-row 4 -column 4  \
		-sticky e
	grid $base.entry#8 -in $root	-row 4 -column 5  \
		-sticky w
	grid $base.label#4 -in $root	-row 5 -column 2  \
		-sticky e
	grid $base.entry#4 -in $root	-row 5 -column 3  \
		-sticky w
	grid $base.label#9 -in $root	-row 5 -column 4  \
		-sticky e
	grid $base.entry#9 -in $root	-row 5 -column 5  \
		-columnspan 2 \
		-sticky w
	grid $base.label#5 -in $root	-row 6 -column 2  \
		-sticky e
	grid $base.entry#5 -in $root	-row 6 -column 3  \
		-sticky w
	grid $base.label#10 -in $root	-row 6 -column 4  \
		-sticky e
	grid $base.entry#10 -in $root	-row 6 -column 5  \
		-columnspan 2 \
		-sticky w
	grid $base.checkbutton#1 -in $root	-row 6 -column 7  \
		-sticky w
	grid $base.label#11 -in $root	-row 8 -column 2  \
		-sticky e
	grid $base.checkbutton#2 -in $root	-row 8 -column 3  \
		-sticky w
	grid $base.entry#11 -in $root	-row 8 -column 5  \
		-sticky e
	grid $base.checkbutton#5 -in $root	-row 8 -column 6  \
		-sticky w
	grid $base.checkbutton#3 -in $root	-row 9 -column 3  \
		-sticky w
	grid $base.entry#12 -in $root	-row 9 -column 5  \
		-sticky e
	grid $base.label#12 -in $root	-row 9 -column 6  \
		-sticky w
	grid $base.checkbutton#4 -in $root	-row 10 -column 3  \
		-sticky w
	grid $base.entry#13 -in $root	-row 10 -column 5  \
		-sticky e
	grid $base.label#13 -in $root	-row 10 -column 6  \
		-sticky w
	grid $base.checkbutton#6 -in $root	-row 12 -column 2  \
		-sticky e
	grid $base.entry#14 -in $root	-row 12 -column 3  \
		-columnspan 3 \
		-sticky w
	grid $base.button#2 -in $root	-row 12 -column 7 
	grid $base.button#1 -in $root	-row 13 -column 7 

	# Resize behavior management

	grid rowconfigure $root 1 -weight 0 -minsize 10
	grid rowconfigure $root 2 -weight 0 -minsize 30
	grid rowconfigure $root 3 -weight 0 -minsize 30
	grid rowconfigure $root 4 -weight 0 -minsize 30
	grid rowconfigure $root 5 -weight 0 -minsize 30
	grid rowconfigure $root 6 -weight 0 -minsize 30
	grid rowconfigure $root 7 -weight 0 -minsize 30
	grid rowconfigure $root 8 -weight 0 -minsize 30
	grid rowconfigure $root 9 -weight 0 -minsize 30
	grid rowconfigure $root 10 -weight 0 -minsize 30
	grid rowconfigure $root 11 -weight 0 -minsize 30
	grid rowconfigure $root 12 -weight 0 -minsize 30
	grid rowconfigure $root 13 -weight 0 -minsize 30
	grid rowconfigure $root 14 -weight 0 -minsize 10
	grid columnconfigure $root 1 -weight 0 -minsize 30
	grid columnconfigure $root 2 -weight 0 -minsize 30
	grid columnconfigure $root 3 -weight 0 -minsize 30
	grid columnconfigure $root 4 -weight 0 -minsize 30
	grid columnconfigure $root 5 -weight 0 -minsize 30
	grid columnconfigure $root 6 -weight 0 -minsize 30
	grid columnconfigure $root 7 -weight 0 -minsize 30
	grid columnconfigure $root 8 -weight 0 -minsize 30
# additional interface code
source vftpd_users
global login pass port maxCon maxIdle address server_port \
server_login server_pass path chroot down_perm up_perm \
chg_perm  ratio_enable ratio ratio_ul ratio_dl cache_enable\
cache_dir

global username

if {$args==""} then {

set username ""
set login ""
set pass ""
set port ""
set maxCon ""
set maxIdle ""
set address ""
set server_port ""
set server_login ""
set server_pass ""
set path ""
set chroot 0
set down_perm 0
set up_perm 0
set chg_perm 0
set ratio_enable 0
set ratio ""
set ratio_ul ""
set ratio_dl ""
set cache_enable 0
set cache_dir ""

} else {

  set username $args
  set config [open vftpd.users r]
  set login ""
  while {[eof $config]==0} {
 	eval [gets $config]
	if {$login==$username} then {
		while {[eof $config]==0} {
			eval [gets $config]
			if {$login!=$username} then {
				set login $username
				break
			}
		}
		break
	}
  }

  close $config

  if {$login!=$username} then {
	tk_dialog "$base.error" Error "Can't find '$username'." "" 0 OK
	return TCL_OK
  }

}

global proot
set proot $base
$root.button#1 configure -command {vftpd_AddUser_OK $proot $username $login $pass $port $maxCon $maxIdle $address $server_port $server_login $server_pass $path $chroot $down_perm $up_perm $chg_perm  $ratio_enable $ratio $ratio_ul $ratio_dl $cache_enable $cache_dir}
$root.button#2 configure -command {vftpd_AddUser_Cancel $proot $username}
# end additional interface code

}

