#!/usr/bin/sh
# $Log: indium.in,v $
# Revision 2.116  2016-06-09 13:05:42+05:30  Cprogrammer
# added full list of man pages
#
# Revision 2.115  2016-06-08 19:29:10+05:30  Cprogrammer
# fixed version information display
#
# Revision 2.114  2016-06-08 10:42:27+05:30  Cprogrammer
# fixed paths for missing images
#
# Revision 2.113  2016-06-07 23:41:34+05:30  Cprogrammer
# fixed mysql_user, mysql_pass variables as global variables
#
# Revision 2.112  2016-06-07 22:32:32+05:30  Cprogrammer
# renamed madHelp to IndiMailHelp
#
# Revision 2.111  2016-06-07 18:38:54+05:30  Cprogrammer
# FHS compliance
#
# Revision 2.110  2010-06-25 17:44:13+05:30  Cprogrammer
# changes for field name changes in vdominfo
#
# Revision 2.109  2010-04-14 10:43:28+05:30  Cprogrammer
# renamed vmoddomlimits to vlimit
#
# Revision 2.108  2010-02-20 11:16:54+05:30  Cprogrammer
# added -n option to adminclient
#
# Revision 2.107  2010-02-19 23:07:48+05:30  Cprogrammer
# use clientcert.pem for encrypted adminclient session
#
# Revision 2.106  2009-10-03 23:54:50+05:30  Cprogrammer
# changed etcdir to scriptdir
#
# Revision 2.105  2008-05-21 15:51:07+05:30  Cprogrammer
# added domainbindings functionality to qmail-remote
#
# Revision 2.104  2007-12-22 00:21:52+05:30  Cprogrammer
# combined SPAMFILTER & SPAMFILTERARGS as SPAMFILTER
#
# Revision 2.103  2005-04-05 22:51:01+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.102  2005-03-30 23:57:42+05:30  Cprogrammer
# added options for setting qhpsi, viruscheck and AUTHSELF (persistent db connection)
#
# Revision 2.101  2005-03-03 14:35:25+05:30  Cprogrammer
# added todointerval control file
#
# Revision 2.100  2005-02-15 19:11:23+05:30  Cprogrammer
# added qscanq, qscanq-stdin
#
# Revision 2.99  2005-02-09 16:48:16+05:30  Cprogrammer
# added qregex control file
#
# Revision 2.98  2004-10-27 14:48:32+05:30  Cprogrammer
# added rfc-3798
#
# Revision 2.97  2004-10-02 19:32:33+05:30  Cprogrammer
# added badext, badextpatterns
#
# Revision 2.96  2004-09-20 19:54:01+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.95  2004-09-09 23:56:14+05:30  Cprogrammer
# added rfc 3834
#
# Revision 2.94  2004-08-25 22:52:38+05:30  Cprogrammer
# added spf control files
# added rfc 2476
# added maxcmdlen control file
#
# Revision 2.93  2004-07-12 22:56:02+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.92  2004-07-02 18:09:08+05:30  Cprogrammer
# Changed IndiGroup to MailGroup
# corrected filenames for prefilt, postfilt
#
# Revision 2.91  2004-07-01 22:23:21+05:30  Cprogrammer
# problem with editcontrol corrected
#
# Revision 2.90  2004-06-22 22:26:08+05:30  Cprogrammer
# added mailcount and mailsize limits
#
# Revision 2.89  2004-06-19 00:21:42+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.88  2004-05-29 22:57:37+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.87  2004-05-29 21:42:23+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.86  2004-05-25 09:59:33+05:30  Cprogrammer
# added option to set domain masquerading
#
# Revision 2.85  2004-05-23 22:19:17+05:30  Cprogrammer
# added paranoid option for hostaccess
#
# Revision 2.84  2004-05-22 23:48:27+05:30  Cprogrammer
# added hostcntrl, ipchange
#
# Revision 2.83  2004-05-19 20:00:46+05:30  Cprogrammer
# escape bounce variable before passing to adminclient
#
# Revision 2.82  2004-05-12 08:58:39+05:30  Cprogrammer
# option to disable/enable global filters
#
# Revision 2.81  2004-05-05 22:54:19+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.80  2004-05-05 11:52:58+05:30  Cprogrammer
# update screen before authentication
#
# Revision 2.79  2004-04-08 13:04:02+05:30  Cprogrammer
# added postfilt id
#
# Revision 2.78  2004-02-18 14:24:11+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.77  2004-01-15 23:21:47+05:30  Cprogrammer
# added authsmtp, authall, helocheck badhelo options to supervise config
#
# Revision 2.76  2004-01-10 09:46:47+05:30  Cprogrammer
# code to add LOGFILTER
#
# Revision 2.75  2004-01-06 17:17:05+05:30  Cprogrammer
# added maildirkw
#
# Revision 2.74  2004-01-05 14:10:34+05:30  Cprogrammer
# added qregex option
# changed bogofilter switches for bogofilter-0.16.0
#
# Revision 2.73  2004-01-02 19:12:41+05:30  Cprogrammer
# added password-cache option
#
# Revision 2.72  2003-12-31 23:52:45+05:30  Cprogrammer
# added syncdir option
# added balloonHelp for checkbuttons
#
# Revision 2.71  2003-12-31 01:20:05+05:30  Cprogrammer
# added usefsync
#
# Revision 2.70  2003-12-30 00:29:01+05:30  Cprogrammer
# envdir modifications and other improvements
#
# Revision 2.69  2003-12-28 09:10:38+05:30  Cprogrammer
# changes for svctool - envdir
#
# Revision 2.68  2003-12-26 14:49:44+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.67  2003-12-26 00:35:06+05:30  Cprogrammer
# added rfc-2505, rf-2635 (Spam related)
#
# Revision 2.66  2003-12-21 21:15:13+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.65  2003-12-17 23:32:12+05:30  Cprogrammer
# added check to prevent deletion of system mail ids
#
# Revision 2.64  2003-12-16 00:34:18+05:30  Cprogrammer
# changes for spam functionality
#
# Revision 2.63  2003-12-10 01:39:49+05:30  Cprogrammer
# added option to build tcprules
#
# Revision 2.62  2003-12-08 20:23:18+05:30  Cprogrammer
# added control file rejectspam
#
# Revision 2.61  2003-12-07 23:10:18+05:30  Cprogrammer
# added reject spam checkbutton
# changed path of /var/log/qmail to /var/log/indimail
#
# Revision 2.60  2003-12-07 00:20:05+05:30  Cprogrammer
# added spam control files
#
# Revision 2.59  2003-11-07 17:13:45+05:30  Cprogrammer
# sql disconnect was called wrongly
# display quota in maildirformat in listbox
#
# Revision 2.58  2003-11-05 14:27:26+05:30  Cprogrammer
# fixed multiple domain entries appearing in domain combobox for distributed
# domains
#
# Revision 2.57  2003-11-03 00:50:07+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.56  2003-10-29 13:20:06+05:30  Cprogrammer
# added qvirtual configuration
# added DOMAIN_LIMIT configuration
#
# Revision 2.55  2003-10-28 19:43:36+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.54  2003-10-27 22:38:12+05:30  Cprogrammer
# added domain limits
#
# Revision 2.53  2003-10-26 00:10:57+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.52  2003-10-24 22:41:56+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.51  2003-10-24 00:44:05+05:30  Cprogrammer
# added NO_SMTP, V_OVERRIDE
#
# Revision 2.50  2003-10-23 13:20:16+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.49  2003-10-18 00:16:48+05:30  Cprogrammer
# extensive functionality added to svctool
#
# Revision 2.48  2003-10-16 00:04:35+05:30  Cprogrammer
# added mclistbox to show service entries in svctool
#
# Revision 2.47  2003-10-14 01:41:57+05:30  Cprogrammer
# added public folders in editcontrol
#
# Revision 2.46  2003-10-06 00:01:27+05:30  Cprogrammer
# added atrn options
#
# Revision 2.45  2003-10-03 01:22:13+05:30  Cprogrammer
# option to enable/disable all filters
# option to edit .qmail-default
#
# Revision 2.44  2003-10-01 02:12:45+05:30  Cprogrammer
# valias correction
# updated control file list
#
# Revision 2.43  2003-09-16 12:29:48+05:30  Cprogrammer
# use sqlserver to connect to mysql
# added Privilege editor
#
# Revision 2.42  2003-09-13 10:26:43+05:30  Cprogrammer
# added logging
#
# Revision 2.41  2003-09-08 17:25:22+05:30  Cprogrammer
# common.tcl move
#
# Revision 2.40  2003-09-04 19:47:27+05:30  Cprogrammer
# moved common functions to common.tcl
# added functionality for indi lite
#
# Revision 2.39  2003-08-24 22:01:17+05:30  Cprogrammer
# added gq to fastbutton
#
# Revision 2.38  2003-08-24 16:20:41+05:30  Cprogrammer
# added Ldap Client
# do not display Options in menu if executables are missing
#
# Revision 2.37  2003-08-22 12:22:12+05:30  Cprogrammer
# added xcron
#
# Revision 2.36  2003-08-21 09:27:26+05:30  Cprogrammer
# editcontrol modification
#
# Revision 2.35  2003-08-11 00:46:19+05:30  Cprogrammer
# added tree code for editing control files
#
# Revision 2.34  2003-08-07 22:41:20+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.33  2003-08-06 22:25:56+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.32  2003-07-30 19:05:48+05:30  Cprogrammer
# changed default user to indimail
#
# Revision 2.31  2003-07-29 22:23:16+05:30  Cprogrammer
# added option to select specific license file
#
# Revision 2.30  2003-07-29 14:12:17+05:30  Cprogrammer
# added vatrn
#
# Revision 2.29  2003-07-25 09:23:43+05:30  Cprogrammer
# added license display
#
# Revision 2.28  2003-07-21 14:13:55+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.27  2003-07-18 19:18:58+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.26  2003-07-06 14:16:01+05:30  Cprogrammer
# *** empty log message ***
#
# Revision 2.25  2003-06-23 22:52:50+05:30  Cprogrammer
# added preference to disable splash
#
# Revision 2.24  2003-06-23 01:32:39+05:30  Cprogrammer
# added relay modification functionality
#
# Revision 2.23  2003-06-22 10:52:49+05:30  Cprogrammer
# *** empty log message ***
#
# Borrowed Code in madsrc
# LogBrowser Code borrowed from TkView version 1.1.5
# Copyright 1999,2000 by Sami Tikka, <sti@iki.fi>
# see http://www.iki.fi/sti/tkview.html for details
#
# Following widgets from Bryan Oakley oakley@channelpoint.com
# mclistbox.tcl
# combobox.tcl
#
# balloon.tcl - procedures used by balloon help
# Copyright (C) 1996-1997 Stewart Allen
#
# help.tcl
#  Developed by  :  Andrei A. Gratchev      <grand@midc.miem.edu.ru>
#                :                          <angra@intrinsix.com>
#
# notebook.tcl
# Copyright (C) 1996,1997,1998 D. Richard Hipp
#
# @(#)progressbar.tcl v1.3 00/04/28 (c) 2000 Alexander Schoepe
#
# SecPanel - Graphical user interface for managing SSH- and
# SCP-connections
# Author: Steffen Leich <secpanel@pingx.net>
# http://www.pingx.net/secpanel
#
# fileman.tcl and FMbrowse
# http://www.cmbi.kun.nl/~schaft/FileMan/fileman.html
#
# WISH Supernotepad 0.8.0
# by David McClamrock <mcclamrock@locl.net>
# based on Tk NotePad 0.5.0 by Joseph Acosta
# and "textedit.tcl" by Eric Foster-Johnson
#
#
# the next line restarts using wish \
exec wish "$0" "$@"

proc main {} {
	global argc argv BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	global bgColor menubarcolor text
	global authenticated inactiveFlag refreshUser logfile

	# build widget .mbar1
	frame .mbar1 -relief flat -bd 2
	pack .mbar1 -side top -fill x
	.mbar1 configure -background black
	#.mbar1 configure -background $menubarcolor
	if {[file exist /usr/share/indimail/indium/images/mbar1.gif]} {
		label .mbar1.logo
		.mbar1.logo config -image [image create photo -file /usr/share/indimail/indium/images/mbar1.gif] -bg black
		pack .mbar1.logo -side right -anchor e
	}
	balloonHelp .mbar1.logo "Indium - The Elements of Mail Administration"
	frame .mbar2  -relief groove -bd 2
	pack .mbar2 -side top -fill x -anchor w
	.mbar2 configure -background black
	#
	# Administration Menu
	#
	menubutton .mbar1.admin -text "Administration"  -menu .mbar1.admin.menu -highlightthickness 2 -highlightbackground black -bd 4 -background orange -underline 0
	menu .mbar1.admin.menu -tearoff 0
	.mbar1.admin.menu add cascade -label "Domain Admin" -menu .mbar1.admin.domain   -underline 0
		menu .mbar1.admin.domain -tearoff 0
		.mbar1.admin.domain add command -label "Add    Domain"        -command {vadddomain}      -underline 0
		.mbar1.admin.domain add command -label "Modify Domain"        -command {vmodDomain}      -underline 0
		.mbar1.admin.domain add command -label "Domain Limits"        -command {vlimit}   -underline 7
		.mbar1.admin.domain add separator
		.mbar1.admin.domain add command -label "Database Controls"    -command {dbcontrol}       -underline 0
		.mbar1.admin.domain add separator
		.mbar1.admin.domain add command -label "Bulletin"             -command {vbulletin}       -underline 0
		.mbar1.admin.domain add command -label "Delete Old Users"     -command {vdeloldusers}    -underline 7
		.mbar1.admin.domain add command -label "Edit Privileges"      -command {vpriv}           -underline 5
	.mbar1.admin.menu add cascade -label "User Admin" -menu .mbar1.admin.uadmin -underline 0
		menu .mbar1.admin.uadmin -tearoff 0
		.mbar1.admin.uadmin add command -label "Add    User"          -command {vadduser} -underline 0
		.mbar1.admin.uadmin add command -label "Modify User"          -command {vmoduser} -underline 0
		.mbar1.admin.uadmin add command -label "Delete User"          -command {vdeluser} -underline 0
		.mbar1.admin.uadmin add command -label "Group Address"        -command {addgroup} -underline 0
	.mbar1.admin.menu add separator
	.mbar1.admin.menu add command -label "Change User"                -command {Login 1} -underline 0
	.mbar1.admin.menu add command -label "Remote Admin"               -command secpanel  -underline 0
	.mbar1.admin.menu add command -label {Exit}                       -command {exit}    -underline 0

	#
	# Qmail Menu
	#
	menubutton .mbar1.qmail -text "Qmail" -menu .mbar1.qmail.menu -highlightthickness 2 -highlightbackground black -bd 4 -background orange -underline 0
	menu .mbar1.qmail.menu -tearoff 0
		.mbar1.qmail.menu add command -label "Show Control Info"  -command {showCtl 1}     -underline 5
		.mbar1.qmail.menu add command -label "Edit Control Files" -command {editcontrol} -underline 0
		.mbar1.qmail.menu add command -label "Supervise Control"  -command {svctool 1}     -underline 0
		.mbar1.qmail.menu add command -label "Advanced"           -command {qmailAdv 1}    -underline 0

	#
	# Misc Menu
	#
	menubutton .mbar1.misc -text "Misc" -menu .mbar1.misc.menu -highlightthickness 2 -highlightbackground black -bd 4 \
		-background orange -underline 0
	menu .mbar1.misc.menu -tearoff 0
		.mbar1.misc.menu add command -label "File Manager"         -command "madFilemgr" -underline 0
		if {[file exists /usr/bin/top]} {
		.mbar1.misc.menu add command -label "Top System Processes" -command "catch {exec $configs(xterm) -e /usr/bin/top &} result" -underline 0
		}
		if {[file exists /usr/bin/mytop]} {
		.mbar1.misc.menu add command -label "Top MySQL  Processes" -command "catch {exec $configs(xterm) -e /usr/bin/mytop &} result" -underline 4
		}
		.mbar1.misc.menu add command -label "Flash Interface"       -command "catch {exec $configs(xterm) -e /usr/bin/flash &} result" -underline 5
		.mbar1.misc.menu add command -label "MySQL Client"         -command "mysql" -underline 6
		.mbar1.misc.menu add command -label "Command Line"         -command "commandLine" -underline 1
		.mbar1.misc.menu add command -label "Scheduler"            -command "xcron 1" -underline 0
		if {[file exists /usr/bin/fetchmailconf]} {
		.mbar1.misc.menu add command -label "Fetchmail Config"     -command "fetch_config" -underline 2
		}
		.mbar1.misc.menu add separator
		.mbar1.misc.menu add command -label "Preferences"          -command "preferences 1" -underline 0
	#
	# Help Menu
	#
	menubutton .mbar1.help -text "Help" -menu .mbar1.help.menu -highlightthickness 2 -highlightbackground black -bd 4 \
		-background brown1 -underline 0
	menu .mbar1.help.menu -tearoff 0
	.mbar1.help.menu add command -label "IndiMail"       -command "exec evince /usr/share/indimail/doc/indimail.pdf &" -underline 0
	.mbar1.help.menu add command -label "About"          -command "doHelp About" -underline 0
	.mbar1.help.menu add separator
	.mbar1.help.menu add cascade -label "qmail commands(1)"  -menu .mbar1.help.menu.qmail1 -underline 15
		menu .mbar1.help.menu.qmail1 -tearoff 0
		foreach line { 822addr 822body 822bodyfilter 822date 822field 822fields 822header 822headerfilter \
			822headerok 822print 822received addcr altermime autoresponder bf_compact bf_copy bf_tar bogofilter \
			bogolexer bogotune bogoupgrade bogoutil bouncesaying cdbdump cdbget cdbgetm cdbmake cdbstats cdbtest \
			checkaddr checkdomain condredirect condtomaildir datemail delcr dot-forward \
			drate except fastforward filterto fixcrio flash fortune forward iecho ifaddr iftocc iftoccfrom incrmesg \
			initsvc ismaildup logclient maildir2mbox maildiracl maildircmd maildirdeliver maildirkw maildirmake \
			maildirqmtp maildirserial maildirsmtp maildirwatch mailsubj mpack multipipe multitail munpack new-inject \
			newaliases newinclude plugtest predate preline printdir printforward printmaillist qaes qarf qbase64 \
			qfilelog qlogselect qmail-cat qmail-qfilter qmail-rm qmaildirmake qnotify qreceipt randstr rblsmtpd \
			recordio relaytest replier-config replier ripmime rrforward rrt serialcmd serialcmd serialqmtp serialsmtp \
			setforward setmaillist spipe srs sslerator strfile swaks teepipe uacl udpclient unstr vaddaliasdomain vadddomain \
			vadduser valias vatrn vbulletin vcfilter vdeldomain vdeluser vdominfo vgroup vipmap vlimit vmoddomain vmoduser \
			vmoveuser vpasswd vrenamedomain vrenameuser vserverinfo vsetuserquota vtable vuserinfo xqp } {
			.mbar1.help.menu.qmail1 add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "qmail formats(5)"   -menu .mbar1.help.menu.qmail5 -underline 14
		menu .mbar1.help.menu.qmail5 -tearoff 0
		foreach line {addresses envelopes maildir mbox dot-qmail qmail-control qmail-header qmail-log \
			qmail-users qmtp nssd.conf rewriting} {
			.mbar1.help.menu.qmail5 add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "qmail internals(7)" -menu .mbar1.help.menu.qmail7 -underline 16
		menu .mbar1.help.menu.qmail7 -tearoff 0
		foreach line {forgeries qmail qmail-limits indimail} {
			.mbar1.help.menu.qmail7 add command -label $line -command "Browse command \"man -s7 $line | ul -t unknown\""
		}
		.mbar1.help.menu add cascade -label "qmail system(8)"   -menu .mbar1.help.menu.qmail8 -underline 14
		menu .mbar1.help.menu.qmail8 -tearoff 0
		foreach line {adminclient chowkidar cleanq clearopensmtp dbinfo dk-filter dkim dknewkey \
			dktest greydaemon hostcntrl hostsync indisrvr inlookup \
			inquerytest install_tables ipchange ldap-checkpwd logalert logmonitor logselect logsrv makeimapaccess \
			mgmtpass mkdhparams nssd ofmipd ofmipname osh pam-checkpwd \
			pam-multi postdel proxyimap proxypop3 qmail-cdb qmail-clean qmail-command qmail-daemon qmail-dk \
			qmail-dkim qmail-getpw qmail-greyd qmail-inject qmail-internals qmail-local qmail-lspawn qmail-multi \
			qmail-newmrh qmail-newu qmail-nullqueue qmail-pop3d qmail-poppass qmail-popup qmail-pw2u qmail-qmqpc \
			qmail-qmqpd qmail-qmtpd qmail-qread qmail-queue qmail-remote qmail-rspawn qmail-send qmail-showctl \
			qmail-smtpd qmail-sql qmail-start qmail-tcpok qmail-tcpto qmail-todo qmailctl qscanq-stdin qscanq \
			queue-fix recipient-cdb resetquota rmail rpclog run-cleanq sendmail \
			spawn-filter splogger surblfilter sys-checkpwd systpass udplogger updaterules vacation vcalias vcaliasrev \
			vchkpass vdelivermail vdeloldusers vfilter vfstab vhostid vpriv vproxy vreorg vsmtp } {
			.mbar1.help.menu.qmail8 add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "ucspi-tcp"      -menu .mbar1.help.menu.ucspi -underline 0
		menu .mbar1.help.menu.ucspi -tearoff 0
		foreach line {argv0 date@ finger@ http@ who@ mconnect tcp-env tcp-environ tcpcat tcpclient tcprules \
			tcprulescheck tcpserver} {
			.mbar1.help.menu.ucspi add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "daemontools"    -menu .mbar1.help.menu.daemon -underline 0
		menu .mbar1.help.menu.daemon -tearoff 0
		foreach line {svctool svscan svscanboot readproctitle supervise svc svok svstat multilog softlimit envdir \
			envuidgid fghack pgrphack setlock setuidgid tai64n tai64nlocal tai64nunix tai2tai64n tai64n2tai } {
			.mbar1.help.menu.daemon add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "Qmailanalog"    -menu .mbar1.help.menu.analog -underline 0
		menu .mbar1.help.menu.analog -tearoff 0
		foreach line {matchup mlmatchup xsender xrecipient columnt} {
			.mbar1.help.menu.analog add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "RFC"            -menu .mbar1.help.menu.rfc -underline 0
		menu .mbar1.help.menu.rfc -tearoff 0
		foreach line {rfc-822 rfc-2821 rfc-1893 rfc-1894 rfc-1985 rfc-2645 rfc-2554 rfc-1321 rfc-2104 \
		rfc-2505 rfc-2635 rfc-2476 rfc-3834 rfc-3798} {
			.mbar1.help.menu.rfc add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "IMAP/POP3"      -menu .mbar1.help.menu.imap -underline 0
		menu .mbar1.help.menu.imap -tearoff 0
		foreach line {authlib authcustom authpam authpwd authshadow courier-unicode maildirmake deliverquota \
			imapd mkimapdcert mkpop3dcert couriertls couriertcpd } {
			.mbar1.help.menu.imap add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	.mbar1.help.menu add cascade -label "Fetchmail"     -menu .mbar1.help.menu.slite -underline 0
		menu .mbar1.help.menu.slite -tearoff 0
		foreach line {fetchmail fetchmailconf} {
			.mbar1.help.menu.slite add command -label $line -command "Browse command \"man $line | ul -t unknown\""
		}
	#.mbar1.help.menu add command -label "IndiMail"       -command "showManEntry" -underline 0

	pack .mbar1.admin .mbar1.qmail .mbar1.misc .mbar1.help -side left -fill y
	bind . <F1> {doHelp About}
	if {[winfo exists .intro]} {
		bind . <F2> {wm deiconify .intro}
	}
	button .mbar2.b1 -text "Add    Domain" -command "vadddomain"   -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/adddomain.gif]} {
		.mbar2.b1 config -image [image create photo -file /usr/share/indimail/indium/images/adddomain.gif]
	}
	button .mbar2.b2 -text "Modify Domain" -command "vmodDomain"   -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/deldomain.gif]} {
		.mbar2.b2 config -image [image create photo -file /usr/share/indimail/indium/images/deldomain.gif]
	}
	button .mbar2.b3 -text "Add      User" -command "vadduser"     -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/adduser.gif]} {
		.mbar2.b3 config -image [image create photo -file /usr/share/indimail/indium/images/adduser.gif]
	}
	button .mbar2.b4 -text "Modify   User" -command "vmoduser"     -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/moduser.gif]} {
		.mbar2.b4 config -image [image create photo -file /usr/share/indimail/indium/images/moduser.gif]
	}
	button .mbar2.b5 -text "Delete   User" -command "vdeluser"     -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/deluser.gif]} {
		.mbar2.b5 config -image [image create photo -file /usr/share/indimail/indium/images/deluser.gif]
	}

	button .mbar2.b6 -text "Add     Group" -command "addgroup"     -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/addgroup.gif]} {
		.mbar2.b6 config -image [image create photo -file /usr/share/indimail/indium/images/addgroup.gif]
	}

	button .mbar2.b7 -text "Database Controls" -command "dbcontrol" -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/dbcontrol.gif]} {
		.mbar2.b7 config -image [image create photo -file /usr/share/indimail/indium/images/dbcontrol.gif]
	}
	button .mbar2.b8 -text "Supervise Control" -command "svctool 1"      -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/serviceTool.gif]} {
		.mbar2.b8 config -image [image create photo -file /usr/share/indimail/indium/images/serviceTool.gif]
	}
	button .mbar2.b9 -text "Bulletin"      -command "vbulletin"    -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/bulletin.gif]} {
		.mbar2.b9 config -image [image create photo -file /usr/share/indimail/indium/images/bulletin.gif]
	}
	button .mbar2.b10 -text "Remote Admin"   -command "secpanel"   -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/secpanel.gif]} {
		.mbar2.b10 config -image [image create photo -file /usr/share/indimail/indium/images/secpanel.gif]
	}
	button .mbar2.b11 -text "File  Manager" -command "madFilemgr"  -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/filemanager.gif]} {
		.mbar2.b11 config -image [image create photo -file /usr/share/indimail/indium/images/filemanager.gif]
	}
	button .mbar2.b12 -text "Edit Control" -command "editcontrol"  -relief groove -bd 2 \
		-highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/textedit.gif]} {
		.mbar2.b12 config -image [image create photo -file /usr/share/indimail/indium/images/textedit.gif]
	}
	button .mbar2.bh -text "Help"          -command "exec evince /usr/share/indimail/doc/indimail.pdf &" \
		-relief groove -bd 2 -highlightthickness 1 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/help.gif]} {
		.mbar2.bh config -image [image create photo -file /usr/share/indimail/indium/images/help.gif]
	} else {
		.mbar2.bh config -image [image create photo -data "R0lGODlhFgAWAIYAAAQCBAQ2NPwCBHSurIS2tBx2dBweHPz+/Ozm1GxiTGyqpPz6/Pz69GSqpOzaxPzy5HxuVLSmlOTazPz27PT29NzClPTexHxuXLSmjAxqbFSinPTy9KyehNy+lPTy5Pz29HxyXNzWxKSahOzexPzy7IR2ZOTWtESenPTy7KSWfIyCbKyijAQGBDyalPTu3KSSdDSOjJyOdCSGhPzu3OzizJSGdPTq1PTq3JySdMy6lAyKhOzWtOzi1OTOrJyKbMS2nJySfMS+rAwCBNzOrNTCpNzKpJSGZKyafLSifLyylIx+ZHx6ZDSChAQuLAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAIALAAAAAAWABYAAAf/gAABAoSFhoeHAAMAiI2IAAQFjI6EAAaJkQeTjwAICYkKBQcLm5WdBwyfhgChB66bp64HCQC1lQ2irqQCAA4PowsLEBESE4wAuLIHFAAVFr+uDBcYxRm1GrmuGxwdFh4Mrh8gGCET1gDYyhsiFSMkDAsMDCUYJhvnJ9kHKCnODwwfPlBQsULCPRYAWogK9sHFiwoOPEyQh0JFPXO1YBSYwBEFghjdHkwQOYGgwQwIZRR44GHGDBogabhAsYEEihrUMAIoUMCEDRs3HODIYQHFA6MPcJA7KICFjgw7eIzo4cOfiwc/gKwIUm2SkKdDdlDt4AABDaU/iIRwwbTSUyJFOow4S3Hkx9oNDDZgXPU0h1wcSIgEGUw4ibVET5WoWMKksePHpdxmyKADAEIWly9HJtQkQJMmlAgZCAQAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	}

	if {$BWidget_present == 1} {
		set text .v.t
		set font -*-Terminal-Medium-R-Normal--*-120-*-*-*-*-*-*
		SelectFont .mbar2.font -type toolbar -font $font -bg $menubarcolor -command setFont
		balloonHelp .mbar2.font "Change Font size for text windows"
	}
	checkbutton .mbar2.inac -selectcolor red -indicatoron false -bg orange \
		-variable inactiveFlag -relief raised -command {
			set refreshUser 1
		}
	button .mbar2.userlist -command userlist
	.mbar2.userlist configure -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBMTCxISChAT+BMRaBPyqXARCBPz+/FxaXAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARLEIRJa5Ui673nsGAgeKE1Bl9AUEXbiqTlFlZaGUZoszm4BzhDAVf5BYbAXI+TAR6CS2ZGSZSEiIIqYIsSIEaJ7GRrlY7J1lKA7I8AACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	if {$BWidget_present} {
		SpinBox .mbar2.lim -relief sunken -textvariable userLimit -bd 2 -width 5 \
			-range {0 5000 100} \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry .mbar2.lim   -relief sunken -textvariable userLimit -bd 2 -width 5 \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	balloonHelp .mbar2.inac     "Check for Inactive Users"
	balloonHelp .mbar2.userlist "Get a Quick list of users"
	balloonHelp .mbar2.lim      "Row Count limit on User Queries"

	button .mbar2.be -text "Exit"          -command "exit"         -relief groove -bd 2 \
		-highlightthickness 2 -highlightbackground black
	if {[file exist /usr/share/indimail/indium/images/quit.gif]} {
		.mbar2.be config -image [image create photo -file /usr/share/indimail/indium/images/quit.gif]
	}
	pack  .mbar2.b1 .mbar2.b2 .mbar2.b3 .mbar2.b4 .mbar2.b5 .mbar2.b6 .mbar2.b7 .mbar2.b8 .mbar2.b9 \
		.mbar2.b10 .mbar2.b11 .mbar2.b12 .mbar2.bh -side left
	if {$BWidget_present == 1} {
		pack .mbar2.font -side left -padx 2 -pady 2 -anchor nw
	}
	pack .mbar2.inac .mbar2.userlist .mbar2.lim -side left -anchor nw
	pack .mbar2.be -side right

	balloonHelp .mbar2.b1   "Add Domain"
	balloonHelp .mbar2.b2   "Modify Domain"
	balloonHelp .mbar2.b3   "Add User"
	balloonHelp .mbar2.b4   "Modify User"
	balloonHelp .mbar2.b5   "Delete/Rename User"
	balloonHelp .mbar2.b6   "Add   Group"
	balloonHelp .mbar2.b7   "Database Management"
	balloonHelp .mbar2.b8   "Services Management"
	balloonHelp .mbar2.b9   "Bulletin"
	balloonHelp .mbar2.b10  "Remote Administration"
	balloonHelp .mbar2.b11  "File Manager"
	balloonHelp .mbar2.b12  "Edit Control Files"
	balloonHelp .mbar2.bh   "Help"
	balloonHelp .mbar2.be   "Bye Bye"

	frame .statusBar
	label .statusBar.lab -text "Indi Mail Administration and Troubleshooting Enabler" -relief sunken -bd 1 \
		-font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* -anchor w
	label .statusBar.labh -text "Press F1 for HELP" -relief sunken -bd 1 \
		-font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* -width 20
	label .statusBar.foo -width 28 -relief sunken -bd 1 \
		-font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-* -anchor w
	pack .statusBar.lab  -side left -padx 2 -expand yes -fill both
	pack .statusBar.labh -side left -padx 2 -expand no
	pack .statusBar.foo -side left -padx 2
	pack .statusBar -side bottom -fill x -pady 2 -anchor s
	menuStatus disabled
	update
	logBrowser 1
	if {[file exist /var/log/svc/deliver.25/current]} {
		set logfile "/var/log/svc/deliver.25/current"
	} elseif {[file exist /var/log/indimail/deliver.25/current]} {
		set logfile "/var/log/indimail/deliver.25/current"
	} elseif {[file exist /var/log/qmail/deliver.25/current]} {
		set logfile "/var/log/qmail/deliver.25/current"
	} elseif {[file exist /var/log/messages]} {
		set logfile "/var/log/messages"
	} elseif {[file exist /var/adm/messages]} {
		set logfile "/var/adm/messages"
	}
}

#
# Arguments:
#
proc ClientStart {} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global argv default_domain
	set appname mad

	for {set i 0} {$i < [llength $argv]} {incr i} {
		set in [expr {$i+1}]
		switch -regexp -- [lindex $argv $i] {
	   		-domain {
	    		if {$in == [llength $argv]} {
					ClientUsage
	   			}
	    		set default_domain [lindex $argv $in]
	    		incr i
			}
	    	-appname {
		    	if {$in == [llength $argv]} {
					ClientUsage
		    	}
		    	set appname [lindex $argv $in]
		    	incr i
			}
	    	-(ssh|rsh) {
				catch {exec /usr/bin/secpanel} result
				exit 0
			}
	    	default {
				ClientUsage
	    	}
		}
	}
}

# Shows the usage message
#
# Arguments:

proc ClientUsage {} {
	global argv0

	puts "Usage: $argv0 \[-domain default_domain\] \[-appname name\] \[-ssh ?name?\]"
	exit 0
}

#
# Sets using dbinfo -s and vdominfo
# 1 domain_list
# 2 local_domain_list
# 3 alias_domain_list
# 
proc initdomain {} {
	global local_domain_list
	source /usr/share/indimail/indium/scripts/global.tcl
	set result ""

	set domain_list {}
	set cmd "| /usr/bin/dbinfo -s"
	if {[catch {open $cmd r} f] } {
		msg_dialog .d {initdomain} "$f" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set dombuf [read $f]
	if {[catch {close $f} result]} {
		msg_dialog .d {initdomain} "$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set datalist [split $dombuf "\n"]
	set line_count [llength $datalist]
	for {set i 0} {$i < $line_count} {incr i} {
		set line [lindex [lindex $datalist $i] 0]
		if {[string index $line 0] == "-"} {
			continue
		}
		switch $line {
			"domain" {
				set line [lindex [lindex $datalist $i] 1]
				if {[llength $domain_list] == 0 || [lsearch -exact $domain_list $line] == -1} {
					lappend domain_list $line
				}
				if {[lindex [lindex $datalist $i] 3] == "Non"} {
					set is_distributed($line) 0
				} else {
					set is_distributed($line) 1
				}
			}
		}
	}

	if {[llength $domain_list] == 0} {
		msg_dialog .d {initdomain} {No Domains found} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		set authenticated 2
		return 1
	}
	set local_domain_list {}
	array set alias_domain_list ""
	foreach line $domain_list {
		catch {unset dummy}
		catch {unset server_list($line)}
		catch {unset sqlserver_list($line)}
		catch {unset aliasdomain_list($line)}
		foreach server [exec /usr/bin/dbinfo -s -d $line | grep ^mda | awk {{print $3}} 2>/dev/null] {
			set server_list($line) [lappend dummy $server]
		}
		foreach server [exec /usr/bin/dbinfo -s -d $line | grep ^sqlserver | awk {{print $2}} 2>/dev/null] {
			set sqlserver_list($line) [lappend dummy $server]
		}
		set cmd "| /usr/bin/vdominfo -l $line"
		if {[catch {open $cmd r} f] } {
			msg_dialog .d {initdomain} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set aliasdomain_list($line) ""
		while {[gets $f aliasdomain] >= 0} {
			if {[string index $aliasdomain 0] == "-"} {
				continue
			}
			if {[string compare $aliasdomain "AliasDomains:"] == 0} {
				continue
			}
			lappend aliasdomain_list($line) $aliasdomain
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			puts stderr "initdomain: $line: $result"
		}
	}
	catch {exec /usr/bin/vdominfo | grep "domain:" | grep -v "aliased to" | awk {{print $2}} 2>/dev/null} tmp_list
	if {[llength $tmp_list]} {
		foreach line $tmp_list {
			if {[lsearch -exact $domain_list $line] != -1} {
				set server_list($line) "127.0.0.1"
				set aliasdomain_list($line) ""
				set sqlserver_list($line) ""
				lappend local_domain_list $line
			}
		}
	}
}

# Draws arrow in small increment
proc setScaleWidth1 {w width} {
	source /usr/share/indimail/indium/scripts/global.tcl
	set var_quota $width

	set width1 [expr $width * 10]
	incr width1 21
	set x2 [expr $width1 - 30]
	if {$x2 < 21} {
		set x2 21
	}
	$w coords poly 20 15 20 35 $x2 35 $x2 45 $width1 25 $x2 5 $x2 15 20 15
	$w coords line 20 15 20 35 $x2 35 $x2 45 $width1 25 $x2 5 $x2 15 20 15
}

# Draws arrow in large increment
proc setScaleWidth2 {w width} {
	source /usr/share/indimail/indium/scripts/global.tcl
	set var_quota $width

	if {$var_quota > 24} {
		set var_quota1 25
	} else {
		set var_quota1 $var_quota
	}
	set width1 [expr $width / 2]
	incr width1 21
	set x2 [expr $width1 - 30]
	if {$x2 < 21} {
		set x2 21
	}
	$w coords poly 20 15 20 35 $x2 35 $x2 45 $width1 25 $x2 5 $x2 15 20 15
	$w coords line 20 15 20 35 $x2 35 $x2 45 $width1 25 $x2 5 $x2 15 20 15
}

# Prepares list from server_list(domain)
proc setServerVal {parent curwin domain} {
	source /usr/share/indimail/indium/scripts/global.tcl

	set exists [winfo exists $parent]
	if {$exists  == 0} {
		return 0
	}
	if {[string length $domain] > 0} {
		$parent list delete 0 end
		foreach server $server_list($domain) {
			$parent list insert end $server
		}
		$parent select 0
	}
}

# Prepares list from sqlserver_list(domain)
proc setSqlServerVal {t_domain curwin t_server args} {
	source /usr/share/indimail/indium/scripts/global.tcl

	set exists [winfo exists $curwin]
	if {$exists  == 0} {
		return 0
	}
	set sqlserver ""
	if {[string length $t_domain] > 0} {
		set count [llength $server_list($t_domain)]
		for {set i 0} {$i < $count} {incr i} {
			if {[string compare $t_server [lindex $server_list($t_domain) $i]] == 0} {
				set sqlserver [lindex $sqlserver_list($t_domain) $i]
				break
			}
		}
	}
}

# Prepares list from aliasdomain_list(domain)
proc setServerAliasVal {parent aliaslabel aliaswin flag curwin domain} {
	global aliasdomain Domain
	global real_domain
	source /usr/share/indimail/indium/scripts/global.tcl

	set exists [winfo exists $parent]
	if {$exists  == 0} {
		return 0
	}
	if {[string length $domain] > 0} {
		set Domain $domain
		set real_domain 1
		$parent list delete 0 end
		foreach server $server_list($domain) {
			$parent list insert end $server
		}
		$parent select 0
		$aliaswin list delete 0 end
		set aliasdomain ""
		set count 0
		foreach line $aliasdomain_list($domain) {
			if {$count == 0} {
				set aliasdomain $line
			}
			set count 1
			$aliaswin list insert end $line
		}
		if {$count == 0} {
			$aliaslabel configure -text ""
			pack forget $aliaswin
			$aliaswin configure -state disabled
		} else {
			$aliaslabel configure -text "AliasDomains"
			if {$flag != 3} {
				$aliaswin configure -state normal
			}
			pack $aliaswin
		}
	}
}

proc aliasSet {curwin domain} {
	global aliasdomain Domain
	global real_domain
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[string length $domain] > 0} {
		set Domain $domain
		set real_domain 0
	}
}

proc setUidGidValue {parent curwin username} {
	source /usr/share/indimail/indium/scripts/global.tcl

	set exists [winfo exists $parent.username.u]
	if {$exists  == 0} {
		return 0
	}
	set exists [winfo exists $parent.username.g]
	if {$exists  == 0} {
		return 0
	}
	set uindex [$curwin list index active]
	if {[string compare $username "indimail"] == 0} {
		if {$uindex > 0} {
			$parent.username.u select $uindex
			$parent.username.g select $uindex
		}
	} else {
		if {$uindex > -1} {
			$parent.username.u select $uindex
			$parent.username.g select $uindex
		}
	}
}

proc mysqlSelect {} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	set lwin .mysql.left
	set rwin .mysql.right

	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {host required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	catch {destroy .mysql}
	toplevel .mysql -relief flat -borderwidth 2
	wm title .mysql "MySQL Selection"

	frame $lwin -relief flat -borderwidth 2
	frame $rwin -relief flat -borderwidth 2
	pack $lwin -side left -anchor nw
	pack $rwin -side left -anchor nw -ipady 22 -ipadx 45

	label $lwin.database -relief ridge -text "MySQL Database" -bd 2
	label $lwin.user     -relief ridge -text "MySQL User"     -bd 2
	label $lwin.password -relief ridge -text "MySQL Pass"     -bd 2
	label $lwin.host     -relief ridge -text "MySQL Host"     -bd 2
	label $lwin.port     -relief ridge -text "MySQL Port"     -bd 2

	entry $rwin.database -relief sunken -textvariable mysql_database -bd 4 \
		-vcmd {expr {[string length %P]<=16}} -validate key  -invcmd bell
	entry $rwin.user     -relief sunken -textvariable mysql_user     -bd 4 \
		-vcmd {expr {[string length %P]<=16}} -validate key  -invcmd bell
	entry $rwin.password -relief sunken -textvariable mysql_pass     -bd 4 -show * \
		-vcmd {expr {[string length %P]<=8}} -validate key  -invcmd bell
	entry $rwin.host     -relief sunken -textvariable mysql_host     -bd 4 \
		-vcmd {expr {[string length %P]<=32}} -validate key  -invcmd bell
	if {$BWidget_present == 1} {
	SpinBox $rwin.port   -relief sunken -textvariable mysql_port     -bd 4 -width 5 \
		-range {3306 65534 1} \
		-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
	entry $rwin.port     -relief sunken -textvariable mysql_port     -bd 4 \
		-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}

	pack $lwin.database $lwin.user $lwin.password $lwin.host $lwin.port -side top -fill x -ipady 3
	pack $rwin.database $rwin.user $rwin.password $rwin.host $rwin.port -side top -anchor nw

	button $lwin.quit -text Dismiss -bg IndianRed \
		-command {destroy .mysql;return 0} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $lwin.quit  -side left
}

proc vadddomain {} {
	global BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	global Domain lwin rwin
	variable lw
	set bounce 1
	set etrn 0
	set cluster 0
	set vfilter 1
	set bounceaddr ""
	set etrnaddr ""
	set lboxstate "normal"
	set uindex -1
	set Domain ""
	set password ""

	set returnstatus [catch {set vpopvar [eval {exec grep ^indimail /etc/passwd | awk -F: {{print $1 " " $3 " " $4 " " $6}}}]} result]
	if {$returnstatus != 0} {
		msg_dialog .d {Add Domain} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set username [lindex $vpopvar 0]
	set uid [lindex $vpopvar 1]
	set gid [lindex $vpopvar 2]
	set indimaildir_tmp [lindex $vpopvar 3]
	set domaindir $indimaildir_tmp

	createWindow
	focus $w
	if {$authenticated == 0} {
		Login 1
	}
	wm title . "Domain Addition"
	set Description "Domain Addition"
	catch {.statusBar.lab configure -text $Description}
	bind . <F1> {doHelp adddomain}

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr1 -text $Description -side center -relief ridge -bd 2
		TitleFrame $w.fr2 -text "Relay Hosts" -side center -relief ridge -bd 2
		pack $w.fr1 -side left -anchor nw -fill both
		pack $w.fr2 -side left -anchor nw -fill y -expand 1
		set fr [$w.fr1 getframe]
		set lw [$w.fr2 getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set dwin $fr.debug
	}

	label $lwin.domain     -relief ridge -text Domain -bd 2
	label $lwin.password   -relief ridge -text Password -bd 2
	label $lwin.username   -relief ridge -text "Userid For Domain" -bd 2
	label $lwin.domaindir  -relief ridge -text "Domain Directory"  -bd 2
	label $lwin.bounceaddr -relief ridge -text "Email for Bounce"  -bd 2
	label $lwin.etrnaddr   -relief ridge -text "ETRN IP Address"   -bd 2
	label $lwin.quota      -relief ridge -text "Postmaster Quota"  -bd 2

	frame $rwin.server    -relief ridge -bd 2
	entry $rwin.server.e  -relief sunken -textvariable Domain -bd 2 -width 15 \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	label $rwin.server.l  -relief ridge  -text Server         -bd 2
	combobox $rwin.server.s \
	-textvariable adminhost \
	-editable false \
	-highlightthickness 1 \
	-width 13 \
	-borderwidth 2

	catch {$rwin.server.s list insert 0 $adminhost}
	button $rwin.server.b  -relief raised -text "MySQL Parameters" \
		-command {mysqlSelect}
	$rwin.server.b configure -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBKSipMTCxARCRFxaXASChDQyNATCxISChAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARYEMgZqqXU6gCuDIJQDQTBBQX3hUFpmN2hFaxhIPCJDrRo46dPglf7BTvDXsB2OwaSCd8tZ0kWgZ3Uk+hDvHRV5bfyybACPNmkY2EVZKpM5UBPre8fD94fAQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
	balloonHelp $rwin.server.b "MySQL Parameters"
	pack $rwin.server.e $rwin.server.l $rwin.server.s $rwin.server.b -side left

	entry $rwin.password   -relief sunken -textvariable password -bd 2 -width 10 -show * \
		-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell
	frame $rwin.username   -relief ridge -bd 2
	combobox $rwin.username.t \
		-textvariable username \
		-editable false \
		-highlightthickness 1 \
		-value $username \
		-width 14 \
		-maxheight 5 \
		-state normal \
		-borderwidth 2 \
		-command "setUidGidValue $rwin"

	if {[catch {open {| cut -d: -f1 /etc/passwd} r} f] } {
		msg_dialog .d {Add Domain} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	} else {
		while {[gets $f line] >= 0} {
			$rwin.username.t list insert end $line
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			msg_dialog .d {Add Domain} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	label $rwin.username.l1  -relief ridge -text Uid -bd 2
	combobox $rwin.username.u \
		-textvariable uid \
		-editable false \
		-highlightthickness 1 \
		-state $lboxstate \
		-value $uid \
		-width 5 \
		-maxheight 5 \
		-borderwidth 2 

	if {[catch {open {| cut -d: -f3 /etc/passwd} r} f] } {
		msg_dialog .d {Add Domain} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	} else {
		while {[gets $f line] >= 0} {
			$rwin.username.u list insert end $line
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			msg_dialog .d {Add Domain} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	label $rwin.username.l2  -relief ridge -text Gid -bd 2
	combobox $rwin.username.g \
	-textvariable gid \
	-editable false \
	-highlightthickness 1 \
	-state $lboxstate \
	-value $gid \
	-width 5 \
	-maxheight 5 \
	-borderwidth 2

	if {[catch {open {| cut -d: -f4 /etc/passwd} r} f] } {
		msg_dialog .d {Add Domain} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	} else {
		while {[gets $f line] >= 0} {
			$rwin.username.g list insert end $line
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			msg_dialog .d {Add Domain} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	pack $rwin.username.t $rwin.username.l1 $rwin.username.u $rwin.username.l2 $rwin.username.g -side left
	entry   $rwin.domaindir  -relief sunken -textvariable domaindir  -bd 3 -width 40
	entry   $rwin.bounceaddr -relief flat   -textvariable bounceaddr -bd 3 -state disabled
	entry   $rwin.etrnaddr   -relief flat   -textvariable etrnaddr   -bd 3 -state disabled \
		-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell
	if {$BWidget_present == 1} {
		SpinBox $rwin.quota  -relief sunken -textvariable var_quota  -bd 3 -width 5 \
			-range {0 500 1} \
			-modifycmd {set var_quota1 $var_quota} -vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $rwin.quota    -relief sunken -textvariable var_quota  -bd 3 -width 5 \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	bind $rwin.quota <FocusIn> {
		if {$var_quota > 25} {
			set var_quota1 0
		} else {
			set var_quota1 $var_quota
		}
	}
	pack $lwin.domain     -side top -fill x -ipady 2
	pack $lwin.password   -side top -fill x -ipady 2
	pack $lwin.username   -side top -fill x -ipady 4
	pack $lwin.domaindir  -side top -fill x -ipady 2
	pack $lwin.bounceaddr -side top -fill x -ipady 2
	pack $lwin.etrnaddr   -side top -fill x -ipady 2
	pack $lwin.quota      -side top -fill x -ipady 2

	pack $rwin.server     -side top -anchor w
	pack $rwin.password   -side top -anchor w
	pack $rwin.username   -side top -anchor w
	pack $rwin.domaindir  -side top -anchor w
	pack $rwin.bounceaddr -side top -anchor w
	pack $rwin.etrnaddr   -side top -anchor w
	pack $rwin.quota      -side top -anchor w

	frame $lwin.cluster -bd 2 -relief ridge
	pack $lwin.cluster  -side top -anchor nw -expand 0 -fill x
	label $lwin.cluster.label -text "Domain Type" -width 20
	pack $lwin.cluster.label
	radiobutton $lwin.cluster.rdb1 -text "NonCluster" -variable cluster -relief flat -value 0 -width 8 -indicatoron 0
	radiobutton $lwin.cluster.rdb2 -text "Cluster"    -variable cluster -relief flat -value 1 -width 8 -indicatoron 0
	$lwin.cluster.rdb1 select
	pack $lwin.cluster.rdb1 $lwin.cluster.rdb2 -side left -expand 1 -fill x

	frame $lwin.bounce -bd 2 -relief ridge
	pack $lwin.bounce  -side top -anchor nw -expand 0 -fill x
	label $lwin.bounce.label -text "Bounce Handling"
	pack $lwin.bounce.label
	radiobutton $lwin.bounce.rdb1 -text "Automatic" -variable bounce -relief flat -value 1 -width 8 -indicatoron 0
	radiobutton $lwin.bounce.rdb2 -text "Email ID"  -variable bounce -relief flat -value 0 -width 8 -indicatoron 0
	$lwin.bounce.rdb1 select
	pack $lwin.bounce.rdb1 $lwin.bounce.rdb2 -side left -expand 1 -fill x
	bind $lwin.bounce.rdb1 <Button-1> {
		set bounceaddr ""
		$rwin.bounceaddr configure -state disabled -relief flat
	}
	bind $lwin.bounce.rdb2 <Button-1> {
		$rwin.bounceaddr configure -state normal -relief sunken
	}

	frame $lwin.etrn -bd 2 -relief ridge
	pack $lwin.etrn  -side top -anchor nw -expand 0 -fill x
	label $lwin.etrn.label -text "Enable ETRN/ATRN"
	pack $lwin.etrn.label
	radiobutton $lwin.etrn.rdb1 -text "NO"  -variable etrn -relief flat -value 0 -width 8 -indicatoron 0
	radiobutton $lwin.etrn.rdb2 -text "YES" -variable etrn -relief flat -value 1 -width 8 -indicatoron 0
	$lwin.etrn.rdb1 select
	pack $lwin.etrn.rdb1 $lwin.etrn.rdb2 -side left -expand 1 -fill x
	bind $lwin.etrn.rdb1 <Button-1> {
		set etrnaddr ""
		$rwin.etrnaddr configure -state disabled -relief flat
	}
	bind $lwin.etrn.rdb2 <Button-1> {
		$rwin.etrnaddr configure -state normal -relief sunken
	}

	frame $lwin.vfilter -bd 2 -relief ridge
	pack $lwin.vfilter -side top -anchor nw -expand 0 -fill x
	label $lwin.vfilter.label -text "Enable VFILTER"
	pack $lwin.vfilter.label -side top -fill x
	radiobutton $lwin.vfilter.rdb1 -text "YES" -variable vfilter -relief flat -value 1 -width 8 -indicatoron 0
	radiobutton $lwin.vfilter.rdb2 -text "NO"  -variable vfilter -relief flat -value 0 -width 8 -indicatoron 0
	$lwin.vfilter.rdb1 select
	pack $lwin.vfilter.rdb1 $lwin.vfilter.rdb2 -side left -expand 1 -fill x

	set var_quota1 5
	set var_quota 5
	scale $rwin.scale1 -orient horizontal -length 284 -from 0 -to 25 \
		-variable var_quota1 -command "setScaleWidth1 $rwin.canvas" -tickinterval 5
	scale $rwin.scale2 -orient horizontal -length 284 -from 0 -to 500 \
		-variable var_quota  -command "setScaleWidth2 $rwin.canvas" -tickinterval 100
	$rwin.scale1 set 5
	$rwin.scale2 set 5
	canvas $rwin.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
	$rwin.canvas create polygon 0 0 1 1 2 2     -fill tomato -tags poly
	$rwin.canvas create line    0 0 1 1 2 2 0 0 -fill black -tags line
	pack $rwin.canvas -side top -expand no -anchor nw -fill x  -padx 1
	pack $rwin.scale1 -side top -expand no -anchor nw
	pack $rwin.scale2 -side top -expand no -anchor nw

	button $rwin.run  -text Add  -bg orange \
		-command {run_adddomain $lw.1.domain} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $rwin.quit -text Cancel -bg IndianRed   \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $rwin.run $rwin.quit -side left -expand 0 -fill none -anchor nw
	####### Relay Frame Definitions ###########################################
	variable relayhost
	variable listb
	variable opframe
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
	global relayhosts localips
	variable flag
	variable relayhost
	variable filename
	variable localip
	variable oldline
	variable newline
	variable all_relays
	set relayhosts {}
	set localips {}
	set localip ""
	set filename ""
	set flag 0
	ipmeprint 0
	####### Frame 1 ###########################################################
	frame $lw.1
	pack $lw.1 -side top -anchor nw
	label $lw.1.label -text "Domain" -width 10
	if {$BWidget_present == 1} {
		ComboBox $lw.1.domain \
			-textvariable Domain \
			-editable false \
			-bd 2 \
			-modifycmd {setRelayhost $Domain $lw.2.e} \
			-vcmd {regexp {^[A-Za-z0-9]*$} %P} -validate key -invcmd bell \
			-values $domain_list
	} else {
		combobox $lw.1.domain \
			-textvariable domain \
			-editable false \
			-highlightthickness 1 \
			-command {setRelayhost $Domain}
			-bd 2
		foreach line $domain_list {
			$lw.1.domain list insert end $line
		}
	}
	pack $lw.1.label $lw.1.domain -side left -anchor nw
	####### Frame 2 ###########################################################
	frame $lw.2
	pack $lw.2 -side top -anchor nw
	label $lw.2.l -text "Relay Host" -width 10
	if {$BWidget_present == 1} {
		ComboBox $lw.2.e \
			-textvariable relayhost \
			-editable true \
			-bd 2 \
			-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell \
			-values $relayhosts
	} else {
		combobox $lw.2.e \
			-textvariable relayhost \
			-editable true \
			-highlightthickness 1 \
			-bd 2
		foreach line $relayhosts {
			$lw.2.e list insert end $line
		}
	}
	pack $lw.2.l $lw.2.e -side left -anchor nw
	setRelayhost $Domain $lw.2.e
	####### Frame 3 ###########################################################
	frame $lw.3
	pack $lw.3 -side top -anchor nw
	set filenames {rcpthosts smtproutes}
	label  $lw.3.l -relief flat -text "Filename" -bd 2 -width 10
	if {$BWidget_present == 1} {
		ComboBox $lw.3.f \
			-textvariable filename \
			-editable false \
			-modifycmd {displayFile $filename $relayhost $listb.list} \
			-bd 2 \
			-values $filenames
	} else {
		combobox $lw.3.f \
			-textvariable filename \
			-editable false \
			-command {displayFile $filename $relayhost $listb.list} \
			-highlightthickness 1 \
			-bd 2
		foreach line $filenames {
			$Lwin.2.f list insert end $line
		}
	}
	pack $lw.3.l $lw.3.f -side left -anchor nw
	####### Frame 4 ###########################################################
	frame $lw.4
	pack $lw.4 -side top -anchor nw
	label $lw.4.l -text "Local IP" -width 10
	if {[llength $localips] > 0} {
		set localip [lindex $localips 0]
	}
	if {$BWidget_present == 1} {
		ComboBox $lw.4.e \
			-textvariable localip \
			-editable false \
			-bd 2 \
			-values $localips
	} else {
		combobox $lw.4.e \
			-textvariable localip \
			-editable false \
			-highlightthickness 1 \
			-bd 2
		foreach line $localips {
			$Lwin.4.e list insert end $line
		}
	}
	pack $lw.4.l $lw.4.e -side left -anchor nw
	####### Frame 7 ###########################################################
	frame $lw.7
	pack $lw.7 -side top -anchor nw
	label  $lw.7.l -relief flat -text "Selection" -bd 2 -width 10
	entry $lw.7.e -textvariable oldline -bd 2 -state disabled
	pack $lw.7.l $lw.7.e -side left -anchor nw
	####### Frame 8 ###########################################################
	frame $lw.8
	pack $lw.8 -side top -anchor nw
	label  $lw.8.l -relief flat -text "New Line" -bd 2 -width 10
	entry $lw.8.e -textvariable newline -bd 2 
	pack $lw.8.l $lw.8.e -side left -anchor nw
	####### Frame 6 ###########################################################
	frame $lw.6
	pack $lw.6 -pady 10 -side top -anchor nw -expand 1 -fill both
	if {$BWidget_present == 1} {
		TitleFrame $lw.6.radio -text "Options"     -side center -relief sunken -bd 2
		TitleFrame $lw.6.listb -text "FileContent" -side center -relief sunken -bd 2
		pack $lw.6.radio $lw.6.listb -side left -anchor nw -expand 1 -fill both
		set opframe [$lw.6.radio getframe]
		set listb   [$lw.6.listb getframe]
	} else {
		frame $lw.6.radio -relief ridge -bd 2
		pack $lw.6.radio -side top -anchor w
		set opframe $lw.6.radio
	}
	radiobutton $opframe.1 -value 1 -variable flag -text "Add Relay" \
		-command {
		$opframe.9.run configure -state normal
		$opframe.9.run configure -text "Add Relay"
		$opframe.9.run configure -cursor {}
		$lw.7.e configure        -cursor {}
		$lw.8.e configure        -cursor {}
		$lw.8.e configure -state disabled
		$opframe.9.c configure -state disabled
		set all_relays 0
		if {[string compare [focus -displayof .dname] "$lw.2.e.e"]} {
			focus $lw.2.e
		}
	}
	radiobutton $opframe.2 -value 2 -variable flag -text "Delete Relay" \
		-command {
		$opframe.9.run configure -state normal
		$opframe.9.run configure -text "Delete Relay"
		$opframe.9.run configure -cursor pirate
		$lw.7.e        configure -cursor {}
		$lw.8.e        configure -cursor {}
		$lw.8.e configure -state disabled
		$opframe.9.c configure -state disabled
		set all_relays 0
		if {[string compare [focus -displayof .dname] "$lw.2.e.e"]} {
			focus $lw.2.e
		}
	}
	radiobutton $opframe.3 -value 3 -variable flag -text "Add    Line" \
		-command {
		$opframe.9.run configure -state normal
		$opframe.9.run configure -text "Add Line"
		$opframe.9.run configure -cursor {}
		$lw.7.e configure        -cursor {}
		$lw.8.e configure        -cursor {}
		$lw.8.e configure -state normal
		$opframe.9.c configure -state normal
		focus $lw.8.e
	}
	radiobutton $opframe.4 -value 4 -variable flag -text "Update Line" \
		-command {
		$opframe.9.run configure -state normal
		$opframe.9.run configure -text "Update Line"
		$opframe.9.run configure -cursor pirate
		$lw.7.e configure        -cursor pirate
		$lw.8.e configure        -cursor pirate
		$lw.8.e configure -state normal
		$opframe.9.c configure -state normal
		focus $lw.8.e
	}
	radiobutton $opframe.5 -value 5 -variable flag -text "Delete Line" \
		-command {
		$opframe.9.run configure -state normal
		$opframe.9.run configure -text "Delete Line"
		$opframe.9.run configure -cursor pirate
		$lw.7.e configure        -cursor pirate
		$lw.8.e configure        -cursor {}
		$lw.8.e configure -state disabled
		$opframe.9.c configure -state normal
		focus $listb.list
	}
	pack $opframe.1 $opframe.2 $opframe.3 $opframe.4 $opframe.5 -side top -anchor w
	scrollbar $listb.scrolly -trough black -command "$listb.list yview"
	scrollbar $listb.scrollx -trough black -command "$listb.list xview" \
		-orient horizontal
	listbox $listb.list \
	-xscroll "$listb.scrollx set" \
	-yscroll "$listb.scrolly set" \
	-selectmode single \
	-setgrid 1 \
	-font $font \
	-width 20 \
	-height 10
	bind $listb.list <<ListboxSelect>> {
		set li [$listb.list curselection]
		if {$li != ""} {
			set oldline [$listb.list get $li]
		}
		focus $listb.list
	}
	pack $listb.scrollx -side bottom -fill x
	pack $listb.scrolly -side right  -fill y
	pack $listb.list -side left -expand 1 -fill both
	####### Frame 9 ###########################################################
	frame $opframe.9
	pack $opframe.9 -side bottom -anchor nw
	checkbutton $opframe.9.c -text "All Relays" -variable all_relays \
		-relief flat -state disabled
	balloonHelp $opframe.9.c "Add domain on all relays to rcpthosts"
	button $opframe.9.run  -text ""  -bg orange \
		-bd 5 -width 12 -highlightthickness 5 -highlightbackground black \
		-state disabled \
		-command {run_relay $flag $all_relays $relayhost $Domain $filename $oldline $newline $lw $listb.list}
	pack $opframe.9.c $opframe.9.run -side top -expand 0 -fill none -anchor nw
}

proc run_relay {operation all host dom filename oldline newline lw listwin} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global relayhosts

	if {$all == 0} {
		if {[string length $host] <= 0} {
			msg_dialog .d {Invalid Host} {RelayHost value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		if {[string compare $host "127.0.0.1"] == 0 || [string compare $host "0.0.0.0"] == 0} {
			msg_dialog .d {Invalid Host $host} {value $host is an invalid IP Address} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	} else {
		if {[llength $relayhosts] < 1]} {
			msg_dialog .d {Invalid RelayHosts} {No RelayHosts defined} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		foreach line $relayhosts {
			if {[string compare $line "127.0.0.1"] == 0 || [string compare $line "0.0.0.0"] == 0} {
				msg_dialog .d {Invalid Host $line} {value $line is an invalid IP Address} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
	}
	if {[string length $dom] <= 0} {
		msg_dialog .d {Invalid Domain} {Domain value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$operation == 3 || $operation == 4} {
		if {[string length $newline] <= 0} {
			msg_dialog .d {Invalid Entry} {New Line not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	if {$operation == 4 || $operation == 5} {
		if {[string length $oldline] <= 0} {
			msg_dialog .d {Invalid Entry} {Old Line not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	switch $operation {
		1 {
			set cmd "| /usr/libexec/indimail/controlsync -h $host -v -f $controldir/me -u $adminuser -P $adminpass -p $adminport"
			if {[catch {open $cmd r} f] } {
				msg_dialog .d {controlsync} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set found 0
			while {[gets $f line] >= 0} {
				set found 1
				break
			}
			set returnstatus [catch {close $f} result]
			if {$returnstatus != 0 || $found == 0} {
				msg_dialog .d $result "$host is not a valid indimail setup" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set cmd "exec /usr/libexec/indimail/controlsync -a -h $host -D $dom"
		}
		2 {
			set msg "You are About to Delete Relay $host for Domain $dom.\nAre you sure you want to delete?\nClick OK to continue"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return
			}
			set cmd "exec /usr/libexec/indimail/controlsync -d -h $host -D $dom"
		}
		3 {
			if {$all == 0} {
				set cmd "exec /usr/libexec/indimail/controlsync -h $host -A $newline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
			} else {
				foreach line $relayhosts {
					set cmd "exec /usr/libexec/indimail/controlsync -h $line -A $newline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
					runCommand $cmd
					if {$returnstatus != 0} {
						msg_dialog .d $line $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
					} else {
						.statusBar.lab configure -text "Updated file $controldir/$filename on $line"
					}
				}
			}
		}
		4 {
			set msg "You are About to Modify Line $oldline to $newline.\nAre you sure you want to change?\nClick OK to continue"
			set action [msg_dialog .d {Confirm Modification} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return
			}
			if {$all == 0} {
				set cmd "exec /usr/libexec/indimail/controlsync -h $host -A $newline -R $oldline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
			} else {
				foreach line $relayhosts {
					set cmd "exec /usr/libexec/indimail/controlsync -h $line -A $newline -R $oldline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
					runCommand $cmd
					if {$returnstatus != 0} {
						msg_dialog .d $line $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
					} else {
						.statusBar.lab configure -text "Updated file $controldir/$filename on $line"
					}
				}
			}
		}
		5 {
			set msg "You are About to Delete Line $oldline.\nAre you sure you want to delete?\nClick OK to continue"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return
			}
			if {$all == 0} {
				set cmd "exec /usr/libexec/indimail/controlsync -h $host -R $oldline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
			} else {
				foreach line $relayhosts {
					set cmd "exec /usr/libexec/indimail/controlsync -h $line -R $oldline -u $adminuser -P $adminpass -p $adminport -f $controldir/$filename"
					runCommand $cmd
					if {$returnstatus != 0} {
						msg_dialog .d $line $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
					} else {
						.statusBar.lab configure -text "Updated file $controldir/$filename on $line"
					}
				}
			}
		}
	   	default {
			msg_dialog .d {Invalid Operation} {Operation not correct} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	if {$all == 0 || $operation < 3} {
		runCommand $cmd
		if {$returnstatus != 0} {
			msg_dialog .d $host $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
		if {$operation == 1 || $operation == 2} {
			if {$operation == 1} {
				.statusBar.lab configure -text "Added Relay $host for domain $dom"
			} else {
				.statusBar.lab configure -text "Deleted Relay $host for domain $dom"
			}
			setRelayhost $dom $lw.2.e
		} else {
			.statusBar.lab configure -text "Updated file $controldir/$filename"
			displayFile $filename $host $listwin
		}
	}
}

proc displayFile {filename host listwin args} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {$host == ""} {
		msg_dialog .d {displayFile} "RelayHost not selected" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set cmd "| /usr/libexec/indimail/controlsync -h $host -v -f $controldir/$filename -u $adminuser -P $adminpass -p $adminport"
	if {[catch {open $cmd r} f] } {
		msg_dialog .d {controlsync} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$listwin delete 0 end
	while {[gets $f line] >= 0} {
		$listwin insert end $line
	}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		msg_dialog .d "$filename@$host" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc setRelayhost {domain args} {
	global BWidget_present errorCode
	source /usr/share/indimail/indium/scripts/global.tcl
	global relayhost relayhosts

	set relayhost ""
	set relayhosts {}
	set len [string len $domain]
	set len [expr $len + 1]
	if {[catch {open $controldir/relayhosts r} f] == 0} {
		while {[gets $f line] >= 0} {
			if {[string compare -length $len "$domain:" $line] == 0} {
				set tmp [string trim [string range $line [expr [string first ":" $line] + 1] end]]
				lappend relayhosts $tmp
				if {$BWidget_present == 0 && [info exists args] && [llength $args]} {
					[lindex $args 0] list insert end $tmp
				}
			}
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			msg_dialog .d "$controldir/relayhosts" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		if {$BWidget_present == 1} {
			if {[info exists args] && [llength $args]} {
				[lindex $args 0] configure -values $relayhosts
			}
			set relayhost [lindex $relayhosts 0]
		}
	} else {
		if {[string compare [lindex $errorCode 1] "ENOENT"] != 0} {
			msg_dialog .d "$controldir/relayhosts" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "WARNING: $f"
		}
		return 1
	}
}

proc ipmeprint {local} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global localips

	if {$local == 1} {
		set cmd "| /usr/libexec/indimail/dnsfq $hostname"
		if {[catch {open $cmd r} f] } {
			msg_dialog .d {dnsfq} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set localips {}
		while {[gets $f line] >= 0} {
			lappend localips $line
		}
		set returnstatus [catch {close $f} result]
		if {$returnstatus != 0} {
			if {[string compare $result "soft error"] != 0} {
				.statusBar.lab configure -text "dnsfq: $hostname: $result"
			}
		}
	} else {
		set localips {}
	}
	set cmd "| /usr/libexec/indimail/ipmeprint"
	if {[catch {open $cmd r} f] } {
		msg_dialog .d {ipmeprint} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	while {[gets $f tline] >= 0} {
		set line [lindex $tline 2]
		if {$local == 0} {
			if {[string compare $line "0.0.0.0"] == 0 || [string compare $line "127.0.0.1"] == 0 || [string compare $line "0000:0000:0000:0000:0000:0000:0000:0000" ] == 0} {
				continue
			}
		}
		lappend localips $line
	}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		msg_dialog .d "ipmeprint" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
}

proc run_adddomain {args} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global Domain lwin rwin

	if {[string length $Domain] == 0} {
		msg_dialog .d {Add Domain} {Domain Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mysql_host] == 0} {
		msg_dialog .d {Add Domain} {MySQL Host not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mysql_port] == 0} {
		msg_dialog .d {Add Domain} {MySQL Port not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mysql_database] == 0} {
		msg_dialog .d {Add Domain} {MySQL Database not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mysql_user] == 0} {
		msg_dialog .d {Add Domain} {MySQL User not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mysql_pass] == 0} {
		msg_dialog .d {Add Domain} {MySQL Password not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domaindir] == 0} {
		msg_dialog .d {Add Domain} {Domain Directory not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $password] == 0} {
		msg_dialog .d {Add Domain} {Password Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$var_quota <= 0} {
		msg_dialog .d {Add Domain} {Quota should be a Positive Number} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$etrn == 1 && [string length $etrnaddr] == 0} {
		msg_dialog .d {Add Domain} {ETRN Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$bounce == 0 && [string length $bounceaddr] == 0} {
		msg_dialog .d {Add Domain} {Bounce EmailID Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set opt ""
	if {[string length $bounceaddr] == 0} {
		append opt "-b "
	} else {
		append opt "-e $bounceaddr "
	}
	if {[string length $etrnaddr] > 0} {
		append opt "-t $etrnaddr "
	}
	if {$vfilter == 1} {
		append opt "-f "
	}
	if {$cluster == 1} {
		append opt "-c "
	}
	set quota [expr $var_quota * 1048576]
	set vaddcmd "\"vadddomain -D $mysql_database -S $mysql_host -p $mysql_port -U $mysql_user -P $mysql_pass -q $quota -d $domaindir -i $uid -g $gid $opt $Domain $password\""
	set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vaddcmd"
	runCommand $cmd
	if {$returnstatus == 0} {
		.statusBar.lab configure -text "Added domain $Domain"
		msg_dialog .d $Domain "Added domain $Domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		initdomain
		set bounce 1
		set cluster 0
		set etrn 0
		set vfilter 1
		set bounceaddr ""
		set etrnaddr ""
		set Domain ""
		set password ""
		focus $rwin.server.e
		if {$BWidget_present == 1} {
			[lindex $args 0] configure -values $domain_list
		} else {
			foreach line $domain_list {
				[lindex $args 0] list insert end $line
			}
		}
		if {$authenticated == 2} {
			set default_domain $Domain
			menuStatus normal
			set authenticated 0
		}
	} else {
		msg_dialog .d $Domain $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc vadduser {} {
	global BWidget_present prgtext w lwin rwin
	source /usr/share/indimail/indium/scripts/global.tcl
	set username ""
	set domain ""
	set password ""
	set gecos ""
	set firstname ""
	set lastname ""
	set phone1 ""
	set phone2 ""
	set dept ""

	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set Description "User Addition"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp adduser}

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr -text $Description -side center -relief ridge -bd 2
		pack $w.fr -side top -anchor w -fill both
		set fr [$w.fr getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set dwin $fr.debug
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin $rwin -pady 40
	}

	label $lwin.username  -relief ridge -text "Username*" -bd 2
	label $lwin.password  -relief ridge -text "Password*" -bd 2
	label $lwin.domain    -relief ridge -text "Domain*" -bd 2
	label $lwin.server    -relief ridge -text "Server*" -bd 2
	label $lwin.gecos     -relief ridge -text "Comment" -bd 2
	label $lwin.first     -relief ridge -text "First Name*" -bd 2
	label $lwin.last      -relief ridge -text "Last Name*" -bd 2
	label $lwin.ph1       -relief ridge -text "Contact Number-Residence" -bd 2
	label $lwin.ph2       -relief ridge -text "Contact Number-Office" -bd 2
	label $lwin.dept      -relief ridge -text "Department" -bd 2
	label $lwin.quota     -relief ridge -text "Mail Quota" -bd 2

	entry $rwin.username   -relief sunken -textvariable username -bd 3 -width 40 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	entry $rwin.password   -relief sunken -textvariable password -bd 3 -width 10 -show * \
		-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell

	combobox $rwin.domain \
		-textvariable domain \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 3 \
		-value $domain \
		-command "setServerVal $rwin.server"
	combobox $rwin.server \
		-textvariable adminhost \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 3
	foreach line $domain_list {
		$rwin.domain list insert end $line
	}
	set domain $default_domain
	setServerVal $rwin.server $w $domain

	entry $rwin.gecos -relief sunken -textvariable gecos     -bd 3 -width 40 \
		-vcmd {expr {[string length %P]<=48}} -validate key -invcmd bell
	entry $rwin.first -relief sunken -textvariable firstname -bd 3 -width 30 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	entry $rwin.last  -relief sunken -textvariable lastname  -bd 3 -width 30 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	entry $rwin.ph1   -relief sunken -textvariable phone1    -bd 3 -width 20 \
			-vcmd {regexp {^[+]?[0-9,-]*$} %P} -validate key -invcmd bell
	entry $rwin.ph2   -relief sunken -textvariable phone2    -bd 3 -width 20 \
			-vcmd {regexp {^[+]?[0-9,-]*$} %P} -validate key -invcmd bell
	entry $rwin.dept  -relief sunken -textvariable dept      -bd 3 -width 30 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	if {$BWidget_present} {
		SpinBox $rwin.quota  -relief sunken -textvariable var_quota -bd 3 -width 4 \
			-range {0 500 1} \
			-modifycmd {set var_quota1 $var_quota} -vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $rwin.quota    -relief sunken -textvariable var_quota -bd 3 -width 4 \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	bind $rwin.quota <FocusIn> {
		if {$var_quota > 25} {
			set var_quota1 0
		} else {
			set var_quota1 $var_quota
		}
	}
	pack $lwin.username -side top -fill x -ipady 2
	pack $lwin.password -side top -fill x -ipady 2
	pack $lwin.domain   -side top -fill x -ipady 2
	pack $lwin.server   -side top -fill x -ipady 2
	pack $lwin.gecos    -side top -fill x -ipady 2
	pack $lwin.first    -side top -fill x -ipady 2
	pack $lwin.last     -side top -fill x -ipady 2
	pack $lwin.ph1      -side top -fill x -ipady 2
	pack $lwin.ph2      -side top -fill x -ipady 2
	pack $lwin.dept     -side top -fill x -ipady 2
	pack $lwin.quota    -side top -fill x -ipady 2

	pack $rwin.username -side top -anchor w
	pack $rwin.password -side top -anchor w
	pack $rwin.domain   -side top -anchor w
	pack $rwin.server   -side top -anchor w
	pack $rwin.gecos    -side top -anchor w
	pack $rwin.first    -side top -anchor w 
	pack $rwin.last     -side top -anchor w
	pack $rwin.ph1      -side top -anchor w
	pack $rwin.ph2      -side top -anchor w
	pack $rwin.dept     -side top -anchor w
	pack $rwin.quota    -side top -anchor w

	frame $lwin.pwgen -bd 2 -relief ridge
	pack $lwin.pwgen -anchor nw -expand 0 -fill x
	label $lwin.pwgen.label -text "Generate Password"
	pack $lwin.pwgen.label -side top -fill x
	radiobutton $lwin.pwgen.rdb1 -text "No"  -variable pwgen -relief flat -value 0 -width 8 -indicatoron 0
	radiobutton $lwin.pwgen.rdb2 -text "Yes" -variable pwgen -relief flat -value 1 -width 8 -indicatoron 0
	$lwin.pwgen.rdb1 select
	pack $lwin.pwgen.rdb1 $lwin.pwgen.rdb2 -side left -expand 1 -fill x
	bind $lwin.pwgen.rdb1 <Button-1> {
		$rwin.password configure -state normal -relief sunken
	}
	bind $lwin.pwgen.rdb2 <Button-1> {
		set password ""
		$rwin.password configure -state disabled -relief flat
	}

	frame $lwin.passwdtyp -bd 2 -relief ridge
	pack $lwin.passwdtyp -anchor nw -expand 0 -fill x
	label $lwin.passwdtyp.label -text "Password Type"
	pack $lwin.passwdtyp.label -side top -fill x
	radiobutton $lwin.passwdtyp.rdb1 -text "PlainText" -variable passwdtyp -relief flat -value 0 -width 8 -indicatoron 0
	radiobutton $lwin.passwdtyp.rdb2 -text "Encrypted" -variable passwdtyp -relief flat -value 1 -width 8 -indicatoron 0
	$lwin.passwdtyp.rdb1 select
	pack $lwin.passwdtyp.rdb1 $lwin.passwdtyp.rdb2 -side left -expand 1 -fill x

	frame $lwin.fsbalance -bd 2 -relief ridge
	pack $lwin.fsbalance -anchor nw -expand 0 -fill x
	label $lwin.fsbalance.label -text "Filesystem Balance"
	pack $lwin.fsbalance.label -side top -fill x
	radiobutton $lwin.fsbalance.rdb1 -text "No"  -variable fsbalance -relief flat -value 0 -width 8 -indicatoron 0
	radiobutton $lwin.fsbalance.rdb2 -text "Yes" -variable fsbalance -relief flat -value 1 -width 8 -indicatoron 0
	$lwin.fsbalance.rdb1 select
	pack $lwin.fsbalance.rdb1 $lwin.fsbalance.rdb2 -side left -expand 1 -fill x

	set var_quota1 5
	set var_quota 5
	scale $rwin.scale1 -orient horizontal -length 284 -from 0 -to 25 \
		-variable var_quota1 -command "setScaleWidth1 $rwin.canvas" -tickinterval 5
	scale $rwin.scale2 -orient horizontal -length 284 -from 0 -to 500 \
		-variable var_quota -command "setScaleWidth2 $rwin.canvas" -tickinterval 100
	$rwin.scale1 set 5
	$rwin.scale2 set 5
	canvas $rwin.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
	$rwin.canvas create polygon 0 0 1 1 2 2     -fill tomato -tags poly
	$rwin.canvas create line    0 0 1 1 2 2 0 0 -fill black  -tags line
	pack $rwin.canvas -side top -expand no -anchor nw -fill x -padx 1
	pack $rwin.scale1 -side top -expand no -anchor nw
	pack $rwin.scale2 -side top -expand no -anchor nw

	frame $lwin.buttons
	pack $lwin.buttons -side top -anchor nw
	button $lwin.buttons.run  -text Add  -bg orange -command "run_adduser" -bd 5 \
		-highlightthickness 5 -highlightbackground black -takefocus 1
	button $lwin.buttons.quit -text Cancel -bg IndianRed   -command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black -takefocus 1
	pack $lwin.buttons.run $lwin.buttons.quit -side left -expand 0 -fill none -anchor nw
	label $lwin.l -text "* marked fields are mandatory"
	pack $lwin.l -side left -anchor nw
}

proc run_adduser {} {
	source /usr/share/indimail/indium/scripts/global.tcl
	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set plen [string length $username]
	if {$plen == 0 || $plen > 32} {
		msg_dialog .d {Invalid Username} {Username should not be null or greater than 32 chars} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$pwgen != 1} {
		set plen [string length $password]
		if {$plen == 0 || $plen > 8} {
			msg_dialog .d {Password} {Password should not be null or greater than 8 chars} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	if {$var_quota <= 0} {
		msg_dialog .d {Invalid Quota} {Quota should be a Positive Number} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $firstname] <= 0} {
		msg_dialog .d {Insufficient Details} {FirstName required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $lastname] <= 0} {
		msg_dialog .d {Insufficient Details} {LastName required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $phone1] <= 0} {
		set phone1 null
	}
	if {[string length $phone2] <= 0} {
		set phone2 null
	}
	if {[string length $dept] <= 0} {
		set dept null
	}
	set opt ""
	if {$pwgen == 1} {
		append opt "-r "
	}
	if {$passwdtyp == 1} {
		append opt "-e "
	}
	if {$fsbalance == 1} {
		append opt "-b "
	}
	set quota [expr $var_quota * 1048576]
	set vaddcmd "\"vadduser -q $quota -c \\\"$gecos\\\" $opt $username@$domain $password\""
	set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vaddcmd"
	runCommand $cmd
	if {$returnstatus == 0} {
		.statusBar.lab configure -text "Added user $username@$domain"
		msg_dialog .d "$username@$domain" "Added $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		set username ""
		set password ""
		set gecos ""
		set firstname ""
		set lastname ""
		set phone1 ""
		set phone2 ""
		set dept ""
		focus $rwin.username 
	 } else {
		msg_dialog .d "$username@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	 }
}

proc vmoduser {} {
	global lwin rwin awin dwin list awinfr inactiveFlag vdelLine delInsList
	source /usr/share/indimail/indium/scripts/global.tcl
	global epassword BWidget_present prgtext t_username oldmaildir userList2 vacationflag
	global User filename

	set username ""
	set domain ""
	set server ""
	set password ""
	set epassword ""
	set result ""
	set uid 1
	set gid 0
	set gecos ""
	set maildir ""
	set oldmaildir ""
	set usage ""
	set inactive_flag 0
	set no_dialup 0
	set no_pass 0
	set no_pop3 0
	set no_smtp 0
	set no_limits 0
	set no_imap 0
	set no_web 0
	set no_mail 0
	set no_relay 0
	set admin_priv 0
	set allpriv 0
	set var_quota1 5
	set var_quota 5
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*

	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set Description "User Modification"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp moduser}

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr -text $Description -side left -relief ridge -bd 2
		pack $w.fr -side top -anchor w -padx 10 -pady 10 -fill both
		set fr [$w.fr getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set awinfr $fr.alias
		set list $fr.list
		set dwin $fr.debug
	} else {
		set awinfr $w.alias
		set list $w.list
		set dwin $w.debug
		set fr $w
	}
	if {[info exists t_username]} {
		set username $t_username
	}

	text_create "Userinfo" 1 45 10
	frame $list -relief ridge -bd 2
	pack $list -side top -padx 15 -expand 0 -fill x -anchor nw
	scrollbar $list.vsb -orient vertical   -trough black \
		-command [list $list.listbox yview]
	scrollbar $list.hsb -orient horizontal -trough black \
		-command [list $list.listbox xview]
	mclistbox $list.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 3 \
	    -width 50 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -xscrollcommand [list $list.hsb set] \
	    -yscrollcommand [list $list.vsb set]
	bind $list.listbox <<ListboxSelect>> {
		focus $list.listbox
	}
	bind $list.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	$list.listbox column add a1  -label "Name"         -width 15
	$list.listbox column add a2  -label "Password"     -width 32
	$list.listbox column add a3  -label "uid"          -width 5
	$list.listbox column add a4  -label "gid"          -width 5
	$list.listbox column add a5  -label "gecos"        -width 15
	$list.listbox column add a6  -label "Quota"        -width 10
	$list.listbox column add a7  -label "Usage"        -width 15
	$list.listbox column add a8  -label "MailStore IP" -width 15
	$list.listbox column add a9  -label "MailStore ID" -width 15
	$list.listbox column add a10 -label "Sql Server"   -width 15
	$list.listbox column add a11 -label "Table"        -width 10
	$list.listbox column add a12 -label "Relay"        -width 6
	$list.listbox column add a13 -label "Days Inact"   -width 32
	$list.listbox column add a14 -label "Added On"     -width 43
	$list.listbox column add a15 -label "last auth"    -width 43
	$list.listbox column add a16 -label "last IMAP"    -width 43
	$list.listbox column add a17 -label "last POP3"    -width 43
	$list.listbox column add a18 -label "last PASS"    -width 43
	$list.listbox column add a19 -label "Inact Date"   -width 43
	$list.listbox column add a20 -label "Activ Date"   -width 43
	$list.listbox column add a21 -label "Deliv Time"   -width 43
	pack $list.hsb     -side bottom -fill x
	pack $list.vsb     -side right  -fill y
	pack $list.listbox -side left -expand 1 -fill both
	frame $awinfr -relief flat
	pack $awinfr -side top -padx 15 -expand 0 -fill none -anchor nw
	frame $awinfr.1 -relief flat
	frame $awinfr.2 -relief flat
	pack $awinfr.1 $awinfr.2 -side left -fill y
	set awin $awinfr.1

	label $awin.label -relief raised -text "Alias/Forwarding"  -bd 2 -width 16 -justify left
	scrollbar $awin.scrolly -trough black -command "$awin.list yview"
	scrollbar $awin.scrollx -trough black -command "$awin.list xview" \
		-orient horizontal
	listbox $awin.list \
	-xscroll "$awin.scrollx set" \
	-yscroll "$awin.scrolly set" \
	-width 40 \
	-selectmode single \
	-setgrid 1 \
	-font $font \
	-height 4
	bind $awin.list <<ListboxSelect>> {
		focus $awin.list
	}
	bind $awin.list <Button-3> {
		$awin.list selection clear 0 end
		set li [$awin.list nearest %y]
		$awin.list activate $li
		$awin.list selection set $li
		showmenuAlias [$awin.list get $li] "$server"
	}
	pack $awin.label -fill x
	pack $awin.scrollx -side bottom -fill x
	pack $awin.scrolly -side right  -fill y
	pack $awin.list -side left -expand 1 -fill both
	button $awinfr.2.b1 -text Filter   -bg LightGrey \
		-command {dbcontrol 6 $username $domain} -bd 5 \
		-highlightthickness 5 -highlightbackground black -state disabled -width 10
	balloonHelp $awinfr.2.b1 "VFilter Control"
	pack $awinfr.2.b1 -side top -anchor nw

	frame $lwin.username
	label $lwin.username.label   -relief ridge  -text "Username" -bd 2 -width 10 -justify left
	button $lwin.username.button -relief raised -text "Go"       -bd 2 \
		-command {
			set password ""
			set epassword ""
			set maildir ""
			set oldmaildir ""
			set result ""
			set uid 1
			set gid 0
			set gecos ""
			set usage ""
			set inactive_flag 0
			set no_dialup 0
			set allpriv 0
			set t_username $username
			vuserinfo $server
		}
	balloonHelp $lwin.username.button  "Get User Info"
	if {[file exist /usr/share/indimail/indium/images/go.gif]} {
		$lwin.username.button configure -image [image create photo -file /usr/share/indimail/indium/images/go.gif]
	}
	label $lwin.domain           -relief ridge  -text "Domain"      -bd 2 -width 10 -justify left
	label $lwin.server           -relief ridge  -text "Server"      -bd 2 -width 10 -justify left
	label $lwin.password         -relief ridge  -text "Password"    -bd 2 -width 10 -justify left
	label $lwin.uid              -relief ridge  -text "User  ID"    -bd 2 -width 10 -justify left
	label $lwin.gecos            -relief ridge  -text "Comments"    -bd 2 -width 10 -justify left
	label $lwin.dir              -relief ridge  -text "Directory"   -bd 2 -width 10 -justify left
	label $lwin.quota            -relief ridge  -text "Mail Quota"  -bd 2 -width 10 -justify left

	frame  $rwin.username
	hugecombo  $rwin.username.e -relief sunken -textvariable username -bd 2 -width 25 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell -listvariable ::userList2
	button $rwin.username.b1 \
		-command {
			list_user2 $domain $server $inactiveFlag
			$rwin.username.e list open
		}
	balloonHelp $rwin.username.b1  "List Users on System"
	$rwin.username.b1 config -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBPz+/MTCxISChMT+/ATCxASChFxaXAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARaEMg5gw00yyDGIAR1YUDggeFWFIZhnSBZrsZxdIOFEGTA2oeBAHeyuGwvzxBlYdUOLROMFzDQntJPrNoqAKUBaqnV+k57ZORruykHDj2LqIzUVKp1u0iuB/gjACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	button $rwin.username.b2 -relief raised -bd 2 -state disabled \
		-command {
		run_deluser $server
		set username ""
		set password ""
		set epassword ""
		set maildir ""
		set oldmaildir ""
		set result ""
		set uid 1
		set gid 0
		set gecos ""
		set usage ""
		set inactive_flag 0
		set no_dialup 0
		set allpriv 0
		$rwin.run    configure -state disabled
		$awinfr.2.b1 configure -state disabled
		$rwin.dir.b  configure -state disabled
		$rwin.username.b2 configure -state disabled
	}
	balloonHelp $rwin.username.b2  "*** Delete User ***"
	$rwin.username.b2 configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBAQCBKSipFxaXPz+/MTCxISChDQyNCH5BAEAAAAALAAAAAAQABAAAANQCKrRsZA5EYZ7K5BdugkdlQVCsRHdoGLMRwqw8UWvIKvGwTICQdmGgY7W+92GEJKPdNwBlMYgMlNkSp3QgOxKXAKFWE0UHHlObI3yyFH2JwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	$rwin.username.b2 configure -cursor pirate
	set tw [$rwin.username.e component entry]
	bind $tw <Return> {
		set password ""
		set epassword ""
		set maildir ""
		set oldmaildir ""
		set result ""
		set uid 1
		set gid 0
		set gecos ""
		set usage ""
		set inactive_flag 0
		set no_dialup 0
		set allpriv 0
		set t_username $username
		vuserinfo "$server"
	}

	set domain $default_domain
	combobox $rwin.domain \
		-textvariable domain \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 3 \
		-value $domain \
		-command "setServerVal $rwin.server"
	foreach line $domain_list {
		$rwin.domain list insert end $line
	}

	combobox $rwin.server \
		-textvariable server \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 3 \
		-command {setSqlServerVal $domain}

	setServerVal $rwin.server $w $domain

	frame $rwin.password -relief ridge -bd 3
	entry $rwin.password.p -relief sunken -textvariable password  -bd 2 -width 15 -show * \
		-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell
	balloonHelp $rwin.password.p  "Plain Text Password"
	bind $rwin.password.p <Return> {
		if {[string length $password] > 0} {
			run_passwd "$server"
			set password ""
			set epassword ""
			set maildir ""
			set oldmaildir ""
			set result ""
			set uid 1
			set gid 0
			set gecos ""
			set usage ""
			set inactive_flag 0
			set no_dialup 0
			set allpriv 0
			vuserinfo "$server"
		}
	}
	entry $rwin.password.e -relief ridge  -textvariable epassword -bd 2 -width 32 \
		-vcmd {expr {[string length %P]<=13}} -validate key -invcmd bell
	balloonHelp $rwin.password.e  "Encrypted Password"
	bind $rwin.password.e <Return> {
		if {[string length $epassword] > 0} {
			run_passwd "$server"
			set password ""
			set epassword ""
			set maildir ""
			set oldmaildir ""
			set result ""
			set uid 1
			set gid 0
			set gecos ""
			set usage ""
			set inactive_flag 0
			set no_dialup 0
			set allpriv 0
			vuserinfo "$server"
			set password ""
		}
	}
	if {$BWidget_present} {
		SpinBox $rwin.uid      -relief sunken -textvariable uid       -bd 2 \
			-width 5 -range {0 65534 1} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry   $rwin.uid      -relief sunken -textvariable uid       -bd 2 \
			-width 5 -vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	entry   $rwin.gecos    -relief sunken -textvariable gecos     -bd 3 -width 20 \
		-vcmd {expr {[string length %P]<=48}} -validate key -invcmd bell
	frame $rwin.dir -relief flat
	entry  $rwin.dir.e -relief sunken -textvariable maildir -bd 2 -width 40
	button $rwin.dir.b -relief raised -bd 2 -padx 9 -pady 3 -state disabled \
		-command {
			if {$oldmaildir == ""} {
				set oldmaildir $maildir
			}
			set initialdir [file dirname $maildir]
			fileDialog $w $rwin.dir.e dir 0
		}
	balloonHelp $rwin.dir.b  "Click to Change Maildir"
	$rwin.dir.b configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBPz+hPz+BOSmZPzSnPzChFxaXMTCBPyuZPz+xPzGhEwyHExOTPz+/MSGTFROTPT29OTm5KyurDQyNNza3Ozq5Nze3LR+RLy+vJyenMzKzNTS1Ly6vJSWlFRSTMzOzMTGxLS2tKSmpGxubBQSFAwKDKSinJyanIyOjCQiJERCRERGRBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaNQIBwSCwaj8ikcokMCIqBaEDoBAQG1meAUDAQpIcBQoy1dg2JdBqhECgQ1IWB0WgcBIOBwIHXBwwPEBEREhIBbG4IExR/DBUVFhIXV2NjDVYYDY8SFU4ZVxpVAQwbGxynGxkdTh6XVh8gGSGzGSITIxokJUImGSMTwLcnKCkprgAqDSt1zCssKxQtQ35BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	frame   $rwin.quota    -relief ridge -bd 2
	if {$BWidget_present} {
		SpinBox $rwin.quota.e1 -relief sunken -textvariable var_quota -bd 2 \
			-width 5 -range {0 500 1} \
			-modifycmd {set var_quota1 $var_quota} -vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $rwin.quota.e1 -relief sunken -textvariable var_quota -bd 2 \
			-width 5 -vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	bind $rwin.quota.e1 <FocusIn> {
		if {$var_quota > 25} {
			set var_quota1 0
		} else {
			set var_quota1 $var_quota
		}
	}
	entry $rwin.quota.e2   -relief ridge  -textvariable usage     -bd 2 -width 20 -state disabled \
			-vcmd {regexp {^[0-9,]*$} %P} -validate key -invcmd bell
	frame $rwin.delins -relief flat -bd 2
	set filename ""
	set vdelLine ""
	set delInsList {}
	label $rwin.delins.l -relief flat -text "Delivery Instruction" -bd 0
	ComboBox $rwin.delins.e \
		-textvariable vdelLine \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 2 \
		-values $delInsList
	balloonHelp $rwin.delins.e  "Delivery Instruction List"
	button $rwin.delins.b1 -relief raised -text "Edit" -bd 2 \
		-command {editfile 2}
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$rwin.delins.b1 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	balloonHelp $rwin.delins.b1  "Click to Edit Delivery Instructions"
	pack $rwin.delins.l -side left -expand 0 -anchor nw
	pack $rwin.delins.e -side left -expand 1 -fill x -anchor nw
	pack $rwin.delins.b1 -side left -expand 0 -anchor nw

	pack $lwin.username        -side top -anchor w -expand 0 -fill x
	pack $lwin.username.label  -side left -expand 1 -fill x -ipady 2
	pack $lwin.username.button -side left
	pack $lwin.domain          -side top -anchor w -expand 0 -fill x -ipady 2
	pack $lwin.server          -side top -anchor w -expand 0 -fill x -ipady 3
	pack $lwin.password        -side top -anchor w -expand 0 -fill x -ipady 3
	pack $lwin.uid             -side top -anchor w -expand 0 -fill x -ipady 2
	pack $lwin.gecos           -side top -anchor w -expand 0 -fill x -ipady 2
	pack $lwin.dir             -side top -anchor w -expand 0 -fill x -ipady 1
	pack $lwin.quota           -side top -anchor w -expand 0 -fill x -ipady 2

	pack $rwin.username       -side top -anchor w -expand 0 -fill none
	pack $rwin.username.e     -side left -expand 1 -fill x -ipady 2
	pack $rwin.username.b1    -side left
	pack $rwin.username.b2    -side left
	pack $rwin.domain         -side top -anchor w -expand 0 -fill none
	pack $rwin.server         -side top -anchor w -expand 0 -fill none
	pack $rwin.password       -side top -anchor w -expand 0 -fill none
	pack $rwin.password.p     -side left
	pack $rwin.password.e     -side left
	pack $rwin.uid            -side top -anchor w -expand 0 -fill none
	pack $rwin.gecos          -side top -anchor w -expand 0 -fill none
	pack $rwin.dir            -side top -anchor w -expand 0 -fill none
	pack $rwin.dir.e          -side left
	pack $rwin.dir.b          -side left
	pack $rwin.quota          -side top -anchor w -expand 0 -fill none
	pack $rwin.quota.e1       -side left -anchor w
	pack $rwin.quota.e2       -side left -anchor e
	pack $rwin.delins         -side top -anchor w -expand 1 -pady 2 -fill x

	set allpriv 0
	checkbutton $lwin.b1    -text "Inactivate        " -variable inactive_flag -relief flat
	checkbutton $lwin.b2    -text "No Dialup         " -variable no_dialup     -relief flat -command {set gid [expr $gid | 0x40]}
	checkbutton $lwin.b3    -text "No Password Change" -variable no_pass       -relief flat -command {set gid [expr $gid | 0x01]}
	checkbutton $lwin.b4    -text "No POP3 Access    " -variable no_pop3       -relief flat -command {set gid [expr $gid | 0x02]}
	checkbutton $lwin.b6    -text "No WEB  Access    " -variable no_web        -relief flat -command {set gid [expr $gid | 0x04]}
	checkbutton $lwin.b5    -text "No IMAP Access    " -variable no_imap       -relief flat -command {set gid [expr $gid | 0x08]}
	checkbutton $lwin.b7    -text "Bounce Flag       " -variable no_mail       -relief flat -command {set gid [expr $gid | 0x10]}
	checkbutton $lwin.b8    -text "No Relay          " -variable no_relay      -relief flat -command {set gid [expr $gid | 0x20]}
	checkbutton $lwin.b12   -text "No SMTP Access    " -variable no_smtp       -relief flat -command {set gid [expr $gid | 0x200]}
	checkbutton $lwin.b13   -text "No Domain Limits  " -variable no_limits     -relief flat -command {set gid [expr $gid | 0x100]}
	checkbutton $lwin.b9    -text "Admin Privilege   " -variable admin_priv    -relief flat -command {set gid [expr $gid | 0x80]}
	checkbutton $lwin.b10   -text "Reset Privilege   " -variable allpriv       -relief flat -command {set gid 0;resetpriv $w $allpriv}
	frame $lwin.b11
	if {[string compare $User "postmaster"] != 0} {
		$lwin.b9  configure -state disabled
		$lwin.b10 configure -state disabled
		$lwin.b13 configure -state disabled
	}
	checkbutton $lwin.b11.c -text "Vacation" \
		-variable vacationflag  -relief flat -state disabled \
		-command {setvacation}
	button $lwin.b11.b -relief raised -text "Edit" \
		-bd 2 -state disabled \
		-command {exec /usr/bin/supernotepad -r $maildir/.vacation.msg &}
	balloonHelp $lwin.b11.b "Edit Auto Response Text"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$lwin.b11.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	pack $lwin.b11.c $lwin.b11.b -side left -anchor nw
	pack $lwin.b1  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b2  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b3  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b4  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b5  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b6  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b7  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b8  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b12 -expand 0 -side top -fill none -anchor nw
	pack $lwin.b13 -expand 0 -side top -fill none -anchor nw
	pack $lwin.b9  -expand 0 -side top -fill none -anchor nw
	pack $lwin.b10 -expand 0 -side top -fill none -anchor nw
	pack $lwin.b11 -expand 0 -side top -fill none -anchor nw

	scale $rwin.scale1 -orient horizontal -length 284 -from 0 -to 25 \
		-variable var_quota1 -command "setScaleWidth1 $rwin.canvas" \
		-tickinterval 5
	scale $rwin.scale2 -orient horizontal -length 284 -from 0 -to 500 \
		-variable var_quota -command "setScaleWidth2 $rwin.canvas" \
		-tickinterval 100
	$rwin.scale1 set 5
	$rwin.scale2 set 5
	canvas $rwin.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
	$rwin.canvas create polygon 0 0 1 1 2 2     -fill tomato -tags poly
	$rwin.canvas create line    0 0 1 1 2 2 0 0 -fill black -tags line
	pack $rwin.canvas -side top -expand no -anchor nw -fill x -padx 1
	pack $rwin.scale1 -side top -expand no -anchor nw
	pack $rwin.scale2 -side top -expand no -anchor nw

	button $rwin.run  -text Modify -bg LightGrey \
		-command "run_moduser $server" -bd 5 \
		-highlightthickness 5 -highlightbackground black -state disabled
	button $rwin.quit -text Cancel   -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black -state normal
	pack $rwin.run  -side left -expand 0 -fill x
	pack $rwin.quit -side left -expand 0 -fill x
	if {[info exists t_username] && $t_username != ""} {
		set password ""
		set epassword ""
		set maildir ""
		set oldmaildir ""
		set result ""
		set uid 1
		set gid 0
		set gecos ""
		set usage ""
		set inactive_flag 0
		set no_dialup 0
		set allpriv 0
		set username $t_username
		vuserinfo $server
	}
}

proc setvacation {} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global vacationflag islocal

	if {$islocal == 0} {
		set vacationflag 0
		$lwin.b11.c deselect
		$lwin.b11.c configure -state disabled
		return
	}

	if {$vacationflag == 1} { 
		set returnstatus [catch {file copy $maildir/.vacation.msg $maildir/vacation.msg} result]
		exec /usr/bin/supernotepad -r $maildir/vacation.msg
		if {[file exists $maildir/vacation.msg] == 0} { 
			set vacationflag 0
			$lwin.b11.c deselect
		} else {
			set cmd "exec /usr/bin/vacation $username@$domain $maildir/vacation.msg"
			runCommand $cmd
			if {$returnstatus == 0} {
				.statusBar.lab configure -text "Set vacation for $username@$domain"
				msg_dialog .d "Vacation" "Set vacation for $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				set vacationflag 1
				file delete $maildir/vacation.msg
				$lwin.b11.c select
			} else {
				set vacationflag 0
				$lwin.b11.c deselect
				.statusBar.lab configure -text "Failed to set vacation for $username@$domain:$result"
				msg_dialog .d "Vacation" "Failed to set vacation for $username@$domain: $result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return
			}
		}
	} else {
		set cmd "exec /usr/bin/vacation $username@$domain -"
		runCommand $cmd
		if {$returnstatus == 0} {
			.statusBar.lab configure -text "Removed vacation for $username@$domain"
			msg_dialog .d "Vacation" "Removed vacation for $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			set vacationflag 0
			$lwin.b11.c deselect
		} else {
			.statusBar.lab configure -text "Failed to remove vacation for $username@$domain"
			msg_dialog .d "Vacation" "Failed to remove vacation for $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			set vacationflag 1
			$lwin.b11.c select
		}
	}
}

proc vuserinfo {server} {
	global BWidget_present lwin rwin awin list awinfr vdelLine delInsList
	source /usr/share/indimail/indium/scripts/global.tcl
	global epassword prgtext vacationflag islocal filename
	variable tmp_vac

	if {[string length $username] <= 0} {
		$rwin.run    configure -state disabled -background LightGrey
		$awinfr.2.b1 configure -state disabled -background LightGrey
		$rwin.dir.b  configure -state disabled -background LightGrey
		$lwin.b11.c  configure -state disabled
		$lwin.b11.b  configure -state disabled
		$rwin.username.b2 configure -state disabled -background LightGrey
		msg_dialog .d {Invalid User} {username required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain] <= 0} {
		$rwin.run    configure -state disabled -background LightGrey
		$awinfr.2.b1 configure -state disabled -background LightGrey
		$rwin.dir.b  configure -state disabled -background LightGrey
		$lwin.b11.c  configure -state disabled
		$lwin.b11.b  configure -state disabled
		$rwin.username.b2 configure -state disabled -background LightGrey
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		$rwin.run    configure -state disabled -background LightGrey
		$awinfr.2.b1 configure -state disabled -background LightGrey
		$rwin.dir.b  configure -state disabled -background LightGrey
		$lwin.b11.c  configure -state disabled
		$lwin.b11.b  configure -state disabled
		$rwin.username.b2 configure -state disabled -background LightGrey
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	catch {unset varuser}
	catch {unset status}
	if {[string length $server] > 0} {
		set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vuserinfo $username@$domain\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vuserinfo $username@$domain\""
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {vuserinfo} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line\n"}
		if {[string index $line 0] == "-"} {
			lappend status $line
			continue
		}
		if {[string match -nocase "*no such user" $line] == 1} {
			$rwin.run    configure -state disabled -background LightGrey
			$awinfr.2.b1 configure -state disabled -background LightGrey
			$rwin.dir.b  configure -state disabled -background LightGrey
			$lwin.b11.c  configure -state disabled
			$lwin.b11.b  configure -state disabled
			$rwin.username.b2 configure -state disabled -background LightGrey
			catch {destroy .progress}
			msg_dialog .d {userinfo} "$username@$domain: No such user" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			catch {close $f}
			return 1
		}
		if {[string compare -length 25 $line "gecos         : MailGroup"] == 0} {
			catch {destroy .progress}
			$rwin.run    configure -state disabled -background LightGrey
			$awinfr.2.b1 configure -state disabled -background LightGrey
			$rwin.dir.b  configure -state disabled -background LightGrey
			$lwin.b11.c  configure -state disabled
			$lwin.b11.b  configure -state disabled
			$rwin.username.b2 configure -state disabled -background LightGrey
			msg_dialog .d {userinfo} "$username@$domain: Is a Group" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			catch {close $f}
			return 1
		}
		lappend varuser $line
	}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		append varuser $result
		$dwin.log insert end "$result\n"
		$dwin.log insert end "-------------------------------------------------------\n"
		$dwin.log yview moveto 1
		catch {destroy .progress}
		msg_dialog .d {vuserinfo Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$dwin.log insert end "-------------------------------------------------------\n"
	catch {$dwin.log yview moveto 1}
	# making a combobox normal has the side effect of making the window jump
	# $rwin.server configure -state normal 
	$rwin.run         configure -state normal -background orange
	$awinfr.2.b1      configure -state normal -background orange
	$rwin.username.b2 configure -state normal -background LightGrey
	$lwin.b11.c       configure -state normal
	$lwin.b11.b       configure -state normal
	$rwin.dir.b       configure -state normal -background LightGrey

    #
    # This idea of using lsearch came from radha. It has revolutionized
    # the way fields can be extracted from output of command line programs
    #
	foreach {infotag vartag} {epassword passwd uid uid gid gid gecos gecos maildir dir \
		tmpquota quota usage curr mailstoreip Ip mailstoreid Id sqlserver Sql tablename \
		Table relayon Relay daysinact "Days inact" addedon Added lastauth auth lastpop3 \
		POP3 lastimap IMAP lastpass PassChange inactdate "Inact Date" actdate "Activ Date" \
		deldate "Delivery Time" tmp_vac "Forwarding"} {
		set lineNo [lsearch -regexp $varuser $vartag]
		set str [lindex $varuser $lineNo]
		set $infotag [string trim [string range $str [expr [string first ":" $str] + 1] end]]
	}
	if {[string compare [lindex $mailstoreip 3] "local)"] == 0} {
		set islocal 1
		$rwin.dir.e configure -state normal
		$rwin.dir.b configure -state normal
		pack $lwin.b11
		if {[string compare -length [expr [string length /usr/bin] + 11] $tmp_vac "| /usr/bin/vacation"] == 0 || [string compare -length [expr [string length /usr] + 24] $tmp_vac "| /usr/bin/qmail-autoresponder"] == 0} {
			$lwin.b11.c select
		} else {
			$lwin.b11.c deselect
		}
	} else {
		pack forget $lwin.b11
		$rwin.dir.e configure -state disabled
		$rwin.dir.b configure -state disabled
		set islocal 0
	}
	set tvar_quota  [lindex [split [lindex $tmpquota 0] ,] 0]
	if {[string compare $tvar_quota "NOQUOTA"]} {
		set var_quota   [expr [lindex [split [lindex $tmpquota 0] ,] 0]/1048576]
	}
	set epassword [lindex $epassword 0]
	$list.listbox delete 0 end
	$list.listbox insert end [list $username $epassword $uid $gid $gecos [lindex $tmpquota 0] $usage $mailstoreip $mailstoreid \
		$sqlserver $tablename $relayon $daysinact $addedon $lastauth $lastimap $lastpop3 $lastpass $inactdate $actdate \
		$deldate]
	setScaleWidth2 $rwin.canvas $var_quota
	$list.listbox yview scroll 1 units

	if {[string compare $tablename "indibak"] == 0} {
		set isinactive 1
		$lwin.b1 select
	} else {
		set isinactive 0
		$lwin.b1 deselect
	}
	if {$gid & 0x40} {
		$lwin.b2 select
	} else {
		$lwin.b2 deselect
	}
	if {$gid & 0x01} {
		$lwin.b3 select
	} else {
		$lwin.b3 deselect
	}
	if {$gid & 0x02} {
		$lwin.b4 select
	} else {
		$lwin.b4 deselect
	}
	if {$gid & 0x08} {
		$lwin.b5 select
	} else {
		$lwin.b5 deselect
	}
	if {$gid & 0x04} {
		$lwin.b6 select
	} else {
		$lwin.b6 deselect
	}
	if {$gid & 0x10} {
		$lwin.b7 select
	} else {
		$lwin.b7 deselect
	}
	if {$gid & 0x20} {
		$lwin.b8 select
	} else {
		$lwin.b8 deselect
	}
	if {$gid & 0x200} {
		$lwin.b12 select
	} else {
		$lwin.b12 deselect
	}
	if {$gid & 0x100} {
		$lwin.b13 select
	} else {
		$lwin.b13 deselect
	}
	if {$gid & 0x80} {
		$lwin.b9 select
	} else {
		$lwin.b9 deselect
	}
	if {[string length $server] > 0} {
		set cmd "| /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -s $username@$domain\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -s $username@$domain\""
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {valias} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$awin.list delete 0 end
	while {[gets $f line] >= 0} {
		set index [string last "->" $line]
		if {$index == -1} {
			continue
		} else {
			$awin.list insert end [string range $line [expr $index + 3] end]
		}
	}
	catch {close $f} result
	if {[string length $result] != 0} {
		catch {destroy .progress}
		msg_dialog .d {valias Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	catch {destroy .progress}
	set vdelLine ""
	set delInsList {}
	if {$islocal == 0} {
		$rwin.delins.e configure -values $delInsList
		return
	}
	set filename $maildir/.qmail
	if {[file exists $filename]} {
		if {[catch {open $filename r} f]} {
			catch {destroy .progress}
			msg_dialog .d "$filename" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		while {[gets $f line] >= 0} {
			lappend delInsList $line
		}
		close $f
		$rwin.delins.e configure -values $delInsList
		$rwin.delins.e setvalue first
	} else {
		$rwin.delins.e configure -values $delInsList
	}
}

proc calcGid {w} {
	global gid lwin

	if {$gid & 0x40} {
		$lwin.b2 select
	} else {
		$lwin.b2 deselect
	}
	if {$gid & 0x01} {
		$lwin.b3 select
	} else {
		$lwin.b3 deselect
	}
	if {$gid & 0x02} {
		$lwin.b4 select
	} else {
		$lwin.b4 deselect
	}
	if {$gid & 0x08} {
		$lwin.b5 select
	} else {
		$lwin.b5 deselect
	}
	if {$gid & 0x04} {
		$lwin.b6 select
	} else {
		$lwin.b6 deselect
	}
	if {$gid & 0x10} {
		$lwin.b7 select
	} else {
		$lwin.b7 deselect
	}
	if {$gid & 0x20} {
		$lwin.b8 select
	} else {
		$lwin.b8 deselect
	}
	if {$gid & 0x200} {
		$lwin.b12 select
	} else {
		$lwin.b12 deselect
	}
	if {$gid & 0x100} {
		$lwin.b13 select
	} else {
		$lwin.b13 deselect
	}
	if {$gid & 0x80} {
		$lwin.b9 select
	} else {
		$lwin.b9 deselect
	}
}

proc run_moduser {server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global epassword
	global oldmaildir

	if {$oldmaildir != "" && [string compare $oldmaildir $maildir] != 0} {
		set msg "You are About to change Maildir $oldmaildir to $maildir.\nAre you sure you want to change?\nClick OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			set maildir $oldmaildir
			set oldmaildir ""
			return
		}
		set vmodcmd "\"vmoveuser  $username@$domain $maildir\""
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vmodcmd"
		runCommand $cmd
		if {$returnstatus == 0} {
			.statusBar.lab configure -text "$username@$domain Maildir modified to $maildir"
			msg_dialog .d "Maildir Modification" "Modified maildir for $username@$domain to $maildir" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "$username@$domain Maildir modification failed:$result"
			msg_dialog .d "Maildir Modification" "$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return
		}
	}
	set opt ""
	if {$allpriv == 1} {
		append opt "-x "
	} else {
		if {$inactive_flag == 1} {
			if {$isinactive == 0} {
				append opt "-n "
			}
		} else {
			if {$isinactive == 1} {
				append opt "-n "
			}
		}
		if {$no_dialup == 1} {
			append opt "-u "
		}
		if {$no_pass == 1} {
			append opt "-d "
		}
		if {$no_pop3 == 1} {
			append opt "-p "
		}
		if {$no_smtp == 1} {
			append opt "-s "
		}
		if {$no_web == 1} {
			append opt "-w "
		}
		if {$no_imap == 1} {
			append opt "-i "
		}
		if {$no_mail == 1} {
			append opt "-b "
		}
		if {$no_relay == 1} {
			append opt "-r "
		}
		if {$admin_priv == 1} {
			append opt "-a "
		}
		if {[string length $opt] == 0} {
			set opt "-x"
		}
	}
	if {[string length $opt] > 0 && [string compare $opt "-x"] != 0} {
		set vmodcmd "\"vmoduser -x $username@$domain\""
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vmodcmd"
		runCommand $cmd
	}
	set quota [expr $var_quota * 1048576]
	if {[string length $password] > 8} {
		msg_dialog .d {Password} {Password should not be greater than 8 chars} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$var_quota <= 0} {
		msg_dialog .d {Invalid Quota} {Quota should be a Positive Number} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $password] > 0} {
		set vmodcmd "\"vmoduser -q $quota -c \\\"$gecos\\\" -P $password $opt $username@$domain\""
	} elseif {[string length $epassword] > 0} {
		set epass [string map {$ \\$} $epassword]
		set vmodcmd "\"vmoduser -q $quota -c \\\"$gecos\\\" -e '$epass' $opt $username@$domain\""
	} else {
		set vmodcmd "\"vmoduser -q $quota -c \\\"$gecos\\\" $opt $username@$domain\""
	}
	set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vmodcmd"
	runCommand $cmd
	if {$returnstatus == 0} {
		vuserinfo $server
		.statusBar.lab configure -text "$username@$domain modified"
		msg_dialog .d "$username@$domain" "Modified Attributes for $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		focus $rwin.username.e
	} else {
		.statusBar.lab configure -text "$result"
		msg_dialog .d "$username@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc run_passwd {server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global epassword

	if {[string length $password] > 0} {
		set vmodcmd "\"vpasswd $username@$domain $password\""
	} elseif {[string length $epassword] > 0} {
		set epass [string map {$ \\$} $epassword]
		set vmodcmd "\"vpasswd $username@$domain '$epass' -e\""
	} else {
		return 0
	}
	set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vmodcmd"
	runCommand $cmd
	if {$returnstatus == 0} {
		vuserinfo $server
		msg_dialog .d "$username@$domain" "Modified Password for $username@$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		.statusBar.lab configure -text "$username@$domain password changed"
	} else {
		.statusBar.lab configure -text "$result"
		msg_dialog .d "$username@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc resetpriv {w priv_val} {
	global lwin
	source /usr/share/indimail/indium/scripts/global.tcl

	if {$priv_val != 0} {
		$lwin.b2 configure -state disabled
		$lwin.b3 configure -state disabled
		$lwin.b4 configure -state disabled
		$lwin.b5 configure -state disabled
		$lwin.b6 configure -state disabled
		$lwin.b7 configure -state disabled
		$lwin.b8 configure -state disabled
		$lwin.b12 configure -state disabled
		$lwin.b13 configure -state disabled
		$lwin.b9 configure -state disabled
	} else {
		$lwin.b2 configure -state normal
		$lwin.b3 configure -state normal
		$lwin.b4 configure -state normal
		$lwin.b5 configure -state normal
		$lwin.b6 configure -state normal
		$lwin.b7 configure -state normal
		$lwin.b8 configure -state normal
		$lwin.b12 configure -state normal
		$lwin.b13 configure -state normal
		$lwin.b9 configure -state normal
	}
}

proc showmenuAlias {alias server} {
	global mode w
	if [winfo exists .pm1] {
		destroy .pm1
	}
	menu .pm1 -title "Alias/Forwarding" -type normal -tearoff 0 -borderwidth 2
	set x [winfo pointerx $w]
	set y [winfo pointery $w]
	.pm1 add command -label "Add    Alias" \
		-command "set mode add;getAliasInput $server $server $x $y"
	if {[string length $alias] > 0} {
		.pm1 add command -label "Modify Alias" \
			-command "set mode mod;getAliasInput \"$alias\" $server $x $y"
		.pm1 add command -label "Delete Alias" \
			-command "set mode del;run_alias \"$alias\" $server"
	}
	.pm1 add command -label "Cancel      " -command "return 0"
	.pm1 post $x $y
}

proc getAliasInput {alias server x y} {
	global w
	source /usr/share/indimail/indium/scripts/global.tcl
	global new_alias mode

	catch {destroy .f1}
	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		set new_alias ""
		set base .f1
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief raised
		wm geometry $base +${x}+${y}
		wm focusmodel $base passive
		wm geometry $base 400x80
		wm maxsize $base 1009 738
		wm minsize $base 1 1
		wm overrideredirect $base 1
		wm resizable $base 0 0
		wm title $base "Indium - New Alias Entry"
		grab .f1
		frame .f1.1
		frame .f1.2
		pack .f1.1 .f1.2 -side top
		if {$mode == "mod"} {
		label .f1.1.l -text "Modified Alias" -relief ridge -bd 2 -width 15
		} else {
		label .f1.1.l -text "New Alias" -relief ridge -bd 2 -width 10
		}
		entry .f1.1.e -relief sunken -textvariable new_alias -bd 2 -width 40 \
			-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
		focus .f1.1.e
		pack .f1.1.l .f1.1.e -side left
		button .f1.2.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 \
			-highlightbackground black -command "run_alias \"$alias\" $server"
		button .f1.2.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 \
			-highlightbackground black -command {releaseGrab .f1;wm withdraw .f1;return 0}
		pack .f1.2.b1 .f1.2.b2 -side left
	}
}

proc run_alias {alias server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global new_alias mode

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string compare $mode "add"] == 0} {
		set valiascmd "\"valias -i \\\"$new_alias\\\" $username@$domain\""
	} elseif {[string compare $mode "mod"] == 0} {
		set valiascmd "\"valias -u \\\"$alias\\\" -i \\\"$new_alias\\\" $username@$domain\""
	} else {
		set msg "You are About to Delete Alias $alias. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return
		}
		set valiascmd "\"valias -d \\\"$alias\\\" $username@$domain\""
	}
	set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $valiascmd"
	runCommand $cmd
	if {$returnstatus == 0} {
		vuserinfo $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "alias $new_alias added"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "alias $alias modified to $new_alias"
		} else {
			.statusBar.lab configure -text "alias $alias deleted"
		}
	} else {
		msg_dialog .d "$username@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc vmodDomain {} {
	global w BWidget_present prgtext real_domain
	global local_domain_list
	source /usr/share/indimail/indium/scripts/global.tcl
	variable twin1
	variable twin2
	variable twin3
	variable twin4
	variable bwin
	variable new_domain
	variable flag
	global aliasdomain Domain vdelLine delInsList
	set domain ""
	set Domain ""
	set result ""
	set aliasdomain ""
	set vdelLine ""
	set w .dname
	set flag 1

	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Domain Modification"
	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw  -expand 1 -fill both
		set pane1  [$pw add -weight 60 -minsize 40]
		set pane2  [$pw add -weight 40 -minsize 40]
		set lf [TitleFrame $pane1.f1 -text $Description -side center -relief ridge -bd 2]
		pack $lf -padx 20 -pady 20 -side top -anchor nw -fill x
		set fr [$lf getframe]
		set twin1 [frame $fr.1]
		set twin2 [frame $fr.2]
		set twin3 [frame $fr.3]
		set twin4 [frame $fr.4]
		set bwin  [frame $fr.b]
		pack $twin1 $twin2 $twin3 $twin4 $bwin -side top -expand 1 -fill x -anchor nw
		set dwin $pane2.debug
	} else {
		frame $w -relief ridge -bd 2
		pack $w -side left -expand 1 -fill both -anchor nw
		frame $w.left -relief ridge -bd 2
		frame $w.right
		pack $w.left  -side left -anchor nw -expand 1 -fill x
		pack $w.right -side left -anchor nw -expand 1 -fill both
		set twin1 [frame $w.left.1 -relief flat]
		set twin2 [frame $w.left.2 -relief flat]
		set twin3 [frame $w.left.3 -relief flat]
		set twin4 [frame $w.left.4 -relief flat]
		set bwin  [frame $w.left.b -relief flat]
		pack $twin1 $twin2 $twin3 $twin4 $bwin -side top -anchor nw
		set dwin $w.right.debug
	}
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp moddomain}
	text_create "vmodDomain" 1 40 25

	label $twin1.label -text "Domain" -relief flat -bd 0 -width 15
	combobox $twin1.domain \
		-textvariable domain \
		-editable false \
		-highlightthickness 1 \
		-command {
			set vdelLine ""
			$twin4.b1 configure -state disabled
			$twin4.b3 configure -state disabled
			setServerAliasVal $twin2.server $twin1.alias $twin1.aliasdomain $flag
		}
	balloonHelp $twin1.domain  "Virtual & ETRN/ATRN/Autoturn Domains List"
	foreach line $domain_list {
		$twin1.domain list insert end $line
	}
	foreach line $local_domain_list {
		foreach jline $domain_list {
			if {[lsearch -exact $jline $line] == -1} {
				$twin1.domain list insert end $line
			}
		}
	}
	label $twin1.alias -text "" -relief flat -bd 0 -width 15
	combobox $twin1.aliasdomain \
		-textvariable aliasdomain \
		-editable false \
		-state normal \
		-highlightthickness 1 \
		-state disabled \
		-command {
			set vdelLine ""
			$twin4.b1 configure -state disabled
			$twin4.b3 configure -state disabled
			aliasSet
		}
	balloonHelp $twin1.aliasdomain  "Alias Domains List"
	pack $twin1.label       -side left -expand 0 -anchor nw
	pack $twin1.domain      -side left -expand 0 -anchor nw -fill x
	pack $twin1.alias       -side left -expand 0 -anchor nw -padx 2
	pack $twin1.aliasdomain -side left -expand 0 -anchor nw -fill x
	pack forget $twin1.aliasdomain

	label $twin2.label -text "Server" -relief flat -bd 0 -width 15
	combobox $twin2.server \
		-textvariable adminhost \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 2 
	balloonHelp $twin2.server  "Server List"
	pack $twin2.label  -side left -expand 0 -anchor nw
	pack $twin2.server -side left -expand 0 -fill x -anchor nw

	label $twin3.label -relief flat -bd 0 -width 15
	entry $twin3.entry -relief flat -textvariable new_domain -bd 2 -state disabled -width 15 \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	pack $twin3.label -side left -expand 0 -anchor nw
	pack $twin3.entry -side left -expand 0 -fill x -anchor nw

	label $twin4.label -relief flat -text "Delivery Instruction" -bd 0
	set delInsList {}
	ComboBox $twin4.entry \
		-textvariable vdelLine \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 2 \
		-values $delInsList
	balloonHelp $twin4.entry  "Delivery Instruction List"
	button $twin4.b1 -relief raised -text "Edit" -bd 2 -state disabled
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$twin4.b1 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	balloonHelp $twin4.b1  "Click to Edit Delivery Instructions"
	button $twin4.b2 -relief raised -text "ATRN Map" -bd 2 \
		-state normal -command {dbcontrol 7 "" $domain}
	if {[file exist /usr/share/indimail/indium/images/atrn.gif]} {
		$twin4.b2 configure -image [image create photo -file /usr/share/indimail/indium/images/atrn.gif]
	}
	balloonHelp $twin4.b2  "Click to Edit ATRN Maps"
	button $twin4.b3 -relief raised -text "Edit" -bd 2 -state disabled
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$twin4.b3 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	balloonHelp $twin4.b3  "Click to Edit Qvirtual"
	pack $twin4.label -side left -expand 0 -anchor nw
	pack $twin4.entry -side left -expand 1 -fill x -anchor nw
	pack $twin4.b1 $twin4.b3 $twin4.b2 -side left -expand 0 -anchor nw

	if {$BWidget_present == 1} {
		TitleFrame $bwin.button -text "Options" -side center -relief sunken -bd 2
		pack $bwin.button -side top -anchor w
		set opframe [$bwin.button getframe]
	} else {
		frame $bwin.button -relief ridge -bd 2
		pack $bwin.button -side top -anchor w
		set opframe $bwin.button
	}

	button $bwin.info -text Info   -bg orange \
		-bd 4 -highlightthickness 5 -highlightbackground black -width 15 \
		-command {modify_domain $flag $twin1.domain $Domain $new_domain $twin4}
	button $bwin.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 4 \
		-highlightthickness 5 -highlightbackground black -state normal
	frame $opframe.e -relief flat
	label $opframe.e.l -relief flat -text "Domain" -bd 2 -width 7
	entry $opframe.e.e -relief sunken -textvariable Domain -state disabled \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	pack $opframe.e.l $opframe.e.e -side left
	radiobutton $opframe.1 -value 1 -variable flag -text "Domain Info" -underline 7 \
		-command {
			$bwin.info configure -text "Info"
			$bwin.info configure -cursor {}
			$twin3.label configure -text ""
			$twin1.aliasdomain configure -state normal
			set new_domain ""
			$twin3.entry configure -state disabled -relief flat
		}
	radiobutton $opframe.2 -value 2 -variable flag -text "Rename Domain" -underline 0 \
		-state disabled \
		-command {
			$bwin.info configure -text "Rename Domain"
			$bwin.info configure -cursor {}
			$twin3.label configure -text "New Domain"
			$twin1.aliasdomain configure -state normal
			set new_domain ""
			$twin3.entry configure -state normal -relief sunken
		}
	radiobutton $opframe.3 -value 3 -variable flag -text "Add Alias Domain" -underline 0 \
		-command {
			$bwin.info configure -text "Add Alias Domain"
			$bwin.info configure -cursor {}
			$twin3.label configure -text "New AliasDomain"
			$twin1.aliasdomain configure -state disabled
			if {[info exists real_domain]} {
				if {$real_domain == 0} {
					set Domain ""
				}
			}
			set new_domain ""
			$twin3.entry configure -state normal -relief sunken
		}
	radiobutton $opframe.4 -value 4 -variable flag -text "Delete Domain" -underline 0 \
		-command {
			$bwin.info configure -text "Delete Domain"
			$bwin.info configure -cursor pirate
			$twin3.label configure -text ""
			$twin1.aliasdomain configure -state normal
			set new_domain ""
			set new_domain " "
			$twin3.entry configure -state disabled -relief flat
		}
	pack $opframe.e $opframe.1 $opframe.2 $opframe.3 $opframe.4 -side top -anchor w
	pack $bwin.info $bwin.quit  -side left -pady 5 -expand 0 -anchor nw -fill x
}

proc modify_domain {operation w1 old_domain new_domain w4} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global olddomain
	global newdomain

	set olddomain $old_domain
	set newdomain $new_domain
	if {$operation == 1} {
		run_dominfo $olddomain $w4
	} elseif {$operation == 2} {
		run_renamedomain $olddomain $newdomain
	} elseif {$operation == 3} {
		run_addaliasdomain $olddomain $newdomain
	} elseif {$operation == 4} {
		run_deldomain $w1 $olddomain
	}
}

proc run_dominfo {domval w4} {
	global filename vdelLine delInsList
	source /usr/share/indimail/indium/scripts/global.tcl
	variable dir

	if {$domval == ""} {
		set cmd "| /usr/bin/vdominfo"
	} else {
		set cmd "| /usr/bin/vdominfo $domval"
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d "vdominfo" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	catch {unset domline}
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line\n"}
		catch {$dwin.log yview scroll 1 units}
		lappend domline $line
	}
	catch {$dwin.log insert end "-------------------------------------------------------\n"}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		msg_dialog .d "vdominfo" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	foreach {infotag vartag} {domain domain uid uid gid gid hostid "host ID" ip "IP Addr" ports Ports dir "Domain Dir"} {
		set lineNo [lsearch -regexp $domline $vartag]
		set str [lindex $domline $lineNo]
		set $infotag [string trim [string range $str [expr [string first ":" $str] + 1] end]]
	}
	if {$dir == ""} {
		$w4.b1 configure -state disabled
		$w4.b3 configure -state disabled
		$w4.entry  configure -state disabled
		set filename ""
		set vdelLine ""
		set delInsList {}
		$w4.entry configure -values $delInsList
	} else {
		set len [string length "/var/indimail/autoturn"]
		if {[string compare -length $len $dir "/var/indimail/autoturn"] == 0} {
			$w4.b3 configure -state normal -command {
				set filename "$dir/.qvirtual"
				editfile 2
			}
		} else {
			$w4.b3 configure -state disabled
		}
		$w4.b1 configure -state normal -command {
			set filename "$dir/.qmail-default"
			editfile 2
		}
		$w4.entry  configure -state normal
		if {[catch {open "$dir/.qmail-default" r} f]} {
			catch {destroy .progress}
			msg_dialog .d "vdominfo $dir/.qmail-default" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set delInsList {}
		while {[gets $f line] >= 0} {
			lappend delInsList $line
		}
		$w4.entry configure -values $delInsList
		$w4.entry setvalue first
		close $f
	}
}

proc run_deldomain {w1 w2} {
	global dwin
	global real_domain Domain aliasdomain
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[string length $w2] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $w2 $default_domain] == 0} {
		if {$real_domain == 1} {
			set msg "You are About to Delete Real Domain $w2.\nAre you sure you want to DELETE $w2?\nIf you delete this default domain your\nentire Mail system might become unusable.\nClick OK to continue"
		} else {
			set msg "You are About to Delete Alias Domain $w2.\nAre you sure you want to DELETE $w2?\nIf you delete this default domain your\nentire Mail system might become unusable.\nClick OK to continue"
		}
	} else {
		if {$real_domain == 1} {
			set msg "You are About to Delete Real Domain $w2. Click OK to continue"
		} else {
			set msg "You are About to Delete Alias Domain $w2. Click OK to continue"
		}
	}
	set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action == 1} {
		set msg "Please confirm again. You are About to Delete $w2.
Are you sure you want to DELETE $w2?  Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	}
	if {$action == 1} {
		if {$real_domain == 1} {
			set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vdeldomain -c $w2\""
		} else {
			set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vdeldomain $w2\""
		}
		runCommand $cmd
		if {[string length $result]} {
			$dwin.log insert end "$result\n"
			$dwin.log insert end "-------------------------------------------------------\n"
			$dwin.log yview moveto 1
		}
		if {$returnstatus == 0} {
			set domain ""
			set aliasdomain ""
			set Domain ""
			initdomain
			$w1 list delete 0 end
			foreach line $domain_list {
				$w1 list insert end $line
			}
			.statusBar.lab configure -text "Deleted domain $w2"
			if {$real_domain == 1} {
				msg_dialog .d $w2 "Deleted Real domain $w2" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				msg_dialog .d $w2 "Deleted Alias domain $w2" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			}
		} else {
			msg_dialog .d "$w2" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc run_renamedomain {old_domain new_domain} {
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[string length $old_domain] <= 0} {
		msg_dialog .d {Invalid Old Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $new_domain] <= 0} {
		msg_dialog .d {Invalid New Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set msg "You are About to Rename $old_domain to $new_domain. Click OK to continue"
	set action [msg_dialog .d {Confirm Rename} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action == 1} {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vrenamedomain $old_domain $new_domain\""
		runCommand $cmd
		if {$returnstatus == 0} {
			.statusBar.lab configure -text "Renamed domain $old_domain to $new_domain"
			msg_dialog .d "$old_domain" "Renamed domain $old_domain to $new_domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			msg_dialog .d "rename $old_domain to $newdomain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	set domain ""
	set new_domain ""
}

proc run_addaliasdomain {olddomain aliasdomain} {
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[string length $olddomain] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $aliasdomain] <= 0} {
		msg_dialog .d {Invalid Domain} {Aliasdomain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vaddaliasdomain $aliasdomain $olddomain\""
	runCommand $cmd
	if {$returnstatus == 0} {
		initdomain
		.statusBar.lab configure -text "Added aliasdomain $aliasdomain"
		msg_dialog .d "$aliasdomain" "Added aliasdomain $aliasdomain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
	} else {
		msg_dialog .d "$aliasdomain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
	set domain ""
	set new_domain ""
}


proc vdeluser {} {
	global BWidget_present prgtext inactiveFlag userList2
	source /usr/share/indimail/indium/scripts/global.tcl
	variable newuser
	variable flag1
	set flag1 1
	set newuser  ""
	set domain ""
	set result 0

	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set Description " Delete/Rename User"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp deluser}

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr1 -text $Description  -side center -relief ridge -bd 2
		pack $w.fr1 -padx 10 -side top -anchor w -fill both
		set fr1 [$w.fr1 getframe]
		set lwin [frame $fr1.left  -relief flat -bd 2]
		set rwin [frame $fr1.right -relief flat -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr1
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr1 -after $lwin
		set dwin $fr1.debug
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin $rwin -padx 10 -pady 20
	}
##################### Delete User #############################################
	label $lwin.username -text "Username" -relief ridge -bd 2 -width 9
	label $lwin.newuser  -text ""         -relief flat  -bd 2 -width 9
	label $lwin.domain   -text "Domain"   -relief ridge -bd 2 -width 9
	label $lwin.server   -text "Server"   -relief ridge -bd 2 -width 9

	frame $rwin.username -relief flat
	hugecombo $rwin.username.e1  -relief sunken -textvariable username -bd 3 -width 40 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell -listvariable ::userList2
	button $rwin.username.b1 \
		-command {list_user2 $domain $sqlserver $inactiveFlag;$rwin.username.e1 list open}
	balloonHelp $rwin.username.b1 "List Users on System"
	$rwin.username.b1 config -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBPz+/MTCxISChMT+/ATCxASChFxaXAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARaEMg5gw00yyDGIAR1YUDggeFWFIZhnSBZrsZxdIOFEGTA2oeBAHeyuGwvzxBlYdUOLROMFzDQntJPrNoqAKUBaqnV+k57ZORruykHDj2LqIzUVKp1u0iuB/gjACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	entry $rwin.newuser   -relief flat   -textvariable newuser  -bd 3 -width 40 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell -state disabled
	set domain $default_domain
	combobox $rwin.domain \
		-textvariable domain \
		-editable false \
		-highlightthickness 1 \
		-borderwidth 3 \
		-width 15 \
		-value $domain \
		-command "setServerVal $rwin.server"
	foreach line $domain_list {
		$rwin.domain list insert end $line
	}
	combobox $rwin.server \
		-textvariable server \
		-editable false \
		-highlightthickness 1 \
		-width 15 \
		-command {setSqlServerVal $domain} \
		-borderwidth 3 
	setServerVal $rwin.server $w $domain
	$rwin.username configure -cursor pirate
	$rwin.newuser  configure -cursor pirate

	button $rwin.run  -text Delete  -bg orange \
		-command "run_deluser $server" -bd 5 \
		-highlightthickness 5 -highlightbackground black -width 15
	button $rwin.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	$rwin.run   configure -cursor pirate

	pack $lwin.username -side top    -expand 0 -anchor nw -fill x -ipady 2
	pack $lwin.newuser  -side top    -expand 0 -anchor nw -fill x -ipady 2
	pack $lwin.domain   -side top    -expand 0 -anchor nw -fill x -ipady 2
	pack $lwin.server   -side top    -expand 0 -anchor nw -fill x -ipady 2
	pack $rwin.username -side top    -expand 0 -anchor nw -fill none
	pack $rwin.username.e1 $rwin.username.b1 -side left
	pack $rwin.newuser  -side top    -expand 0 -anchor nw -fill none
	pack $rwin.domain   -side top    -expand 0 -anchor nw -fill none
	pack $rwin.server   -side top    -expand 0 -anchor nw -fill none
	pack $rwin.run      -side left   -expand 0 -anchor nw -fill none
	pack $rwin.quit     -side left   -expand 0 -anchor nw -fill none

	if {$BWidget_present == 1} {
		TitleFrame $lwin.options -text "Options" -side center -relief sunken -bd 2
		pack $lwin.options -side top -anchor nw -fill y -expand 1
		set opframe [$lwin.options getframe]
	} else {
		frame $lwin.options -relief ridge -bd 2
		pack $lwin.options -side top -anchor nw -fill y -expand 1
		set opframe $lwin.options
	}
	radiobutton $opframe.1 -value 1 -variable flag1 -text "Delete User" -underline 0 \
		-command {
			$lwin.newuser configure -relief flat
			$lwin.newuser configure -text ""
			$rwin.newuser configure -relief flat
			$rwin.newuser configure -state disabled
			$rwin.run configure -text "Delete"
			$rwin.run configure -command {run_deluser $server}
		}
	radiobutton $opframe.2 -value 2 -variable flag1 -text "Rename User" -underline 0 \
		-command {
			$lwin.newuser configure -relief ridge
			$lwin.newuser configure -text "New User"
			$rwin.newuser configure -relief sunken
			$rwin.newuser configure -state normal
			$rwin.run configure -text "Rename"
			$rwin.run configure \
				-command {run_renameuser $username $newuser $domain $server}
		}
	pack $opframe.1 $opframe.2 -side top -anchor w
}

proc run_deluser {server} {
	source /usr/share/indimail/indium/scripts/global.tcl

	foreach line {postmaster abuse editor prefilt postfilt register-spam register-nonspam spam nonspam} {
		if {[string compare -nocase $username $line] == 0} {
			msg_dialog .d {Invalid Username} "$username is not allowed to be deleted as this user is mandatory" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	if {[string length $username] <= 0} {
		msg_dialog .d {Invalid Username} {username required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set msg "You are About to Delete $username@$domain. Click OK to continue\n"
	set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action == 1} {
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vdeluser $username@$domain\""
		runCommand $cmd
		if {$returnstatus == 0} {
			set username ""
			.statusBar.lab configure -text "Deleted user $username$domain"
			msg_dialog .d "$username@$domain" "Deleted user $username$domain" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			msg_dialog .d "$username@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc run_renameuser {olduser newuser domain_name server} {
	source /usr/share/indimail/indium/scripts/global.tcl

	foreach line {postmaster abuse editor prefilt postfilt register-spam register-nonspam spam nonspam} {
		if {[string compare -nocase $olduser $line] == 0} {
			msg_dialog .d {Invalid Username} "$olduser is not allowed to be renamed as this user is mandatory" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
	}
	if {[string length $olduser] <= 0 || [string length $newuser] <= 0} {
		msg_dialog .d {Invalid Username} {username required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain_name] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set msg "You are About to rename $olduser@$domain_name to  $newuser@$domain_name. Click OK to continue\n"
	set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action == 1} {
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vrenameuser $olduser@$domain_name $newuser@$domain_name\""
		runCommand $cmd
		if {$returnstatus == 0} {
			set username ""
			.statusBar.lab configure -text "Renamed user $olduser$domain_name to $newuser@$domain_name"
			msg_dialog .d "$olduser@$domain" "Renamed user $olduser$domain_name to $newuser@$domain_name" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			msg_dialog .d "$olduser@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc userlist {} {
	global BWidget_present prgtext userCount userLimit refreshUser
	source /usr/share/indimail/indium/scripts/global.tcl
	variable Lwin
	variable inactiveFlag
	variable search
	variable base
	set search ""
	set result "" 
	set w .dname
	set alphabets  {
		"a"\
		"b"\
		"c"\
		"d"\
		"e"\
		"f"\
		"g"\
		"h"\
		"i"\
		"j"\
		"k"\
		"l"\
		"m"\
		"n"\
		"o"\
		"p"\
		"q"\
		"r"\
		"s"\
		"t"\
		"u"\
		"v"\
		"w"\
		"x"\
		"y"\
		"z"\
		"0"\
		"1"\
		"2"\
		"3"\
		"4"\
		"5"\
		"6"\
		"7"\
		"8"\
		"9"
	}
	set base .list
	if {[winfo exists $base]} {
		wm deiconify $base
		focus $base
		return 0
	}
	if {$authenticated != 1} {
		Login 1
	}
	set refreshUser 1
	set description "User List"
	set target .
	set x [expr [winfo rootx $target] + ([winfo width  $target]/2)]
	set y [expr [winfo rooty $target] + ([winfo height $target]/2)]
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 \
		-highlightbackground black -takefocus 1 -relief raised
	wm geometry $base +${x}+${y}
	wm focusmodel $base passive
	wm geometry $base 820x480
	wm maxsize $base 1009 738
	wm minsize $base 1 1
	wm overrideredirect $base 0
	wm resizable $base 0 0
	wm protocol $base WM_DELETE_WINDOW {wm withdraw $base}
	wm title $base $description
	bind $base <F1> {doHelp userlist}
	if {$BWidget_present == 1} {
		set lf [TitleFrame .list.w -text $description -side center -relief ridge -bd 2]
		pack $lf -side top -anchor nw -fill both
		set tf [$lf getframe]
		set Lwin $tf
	} else {
		frame .list.w -relief flat  -bd 2
		pack .list.w -side left -anchor nw -expand 1 -fill x
		set Lwin [frame .list.w.left  -relief flat  -bd 2]
		pack $Lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $w
	}
	## Frame 1 #######################################################################
	frame $Lwin.1
	frame $Lwin.2
	frame $Lwin.3
	frame $Lwin.4
	pack $Lwin.1 $Lwin.2 $Lwin.3 $Lwin.4 -side top -anchor nw
	label  $Lwin.1.l1 -relief flat -text "Domain" -bd 2 -width 10
	set domain $default_domain
	combobox $Lwin.1.e1 \
		-textvariable domain \
		-editable false \
		-borderwidth 2 \
		-value $domain \
		-command {setServerVal $Lwin.1.e2}
	foreach line $domain_list {
		$Lwin.1.e1 list insert end $line
	}
	label  $Lwin.1.l2 -relief flat -text "Server"    -bd 2
	combobox $Lwin.1.e2 \
		-textvariable server \
		-editable false \
		-highlightthickness 1 \
		-command {setSqlServerVal $domain} \
		-borderwidth 2
	setServerVal $Lwin.1.e2 $w $domain

	button $Lwin.1.showall -relief raised -bd 4 -bg IndianRed
	$Lwin.1.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	balloonHelp $Lwin.1.showall  "Show/Hide Columns"
	$Lwin.1.showall configure -command {showContextMenu $Lwin.3.listbox}
	pack $Lwin.1.l1 $Lwin.1.e1 $Lwin.1.l2 $Lwin.1.e2 $Lwin.1.showall -side left

	label  $Lwin.2.l1 -relief flat -text "NamePrefix" -bd 2 -width 10
	if {$BWidget_present == 1} {
		ComboBox $Lwin.2.search \
			-textvariable search \
			-editable true \
			-bd 2 \
			-vcmd {regexp {^[A-Za-z0-9][A-Za-z0-9!#$&'*+-./=?^ `{|}~]*$} %P} -validate key -invcmd bell \
			-width 5 \
			-values $alphabets
	} else {
		combobox $Lwin.2.search \
			-textvariable search \
			-editable false \
			-highlightthickness 1 \
			-bd 2 \
			-width 5
		foreach line $alphabets {
			$Lwin.2.search list insert end $line
		}
	}
	checkbutton $Lwin.2.c1  -padx 2 -text "Inactive Users" \
		-variable inactiveFlag -relief flat -command {
		$Lwin.4.run configure -text "List"
		$Lwin.4.run configure -state normal
		set refreshUser 1
	}
	checkbutton $Lwin.2.c2  -padx 2 -text "Refresh" -variable refreshUser \
		-relief raised -bd 2 -command {
		$Lwin.4.run configure -text "List"
		$Lwin.4.run configure -state normal
	}
	balloonHelp $Lwin.2.c1  "Get only Inactive user list"
	balloonHelp $Lwin.2.c2  "Reload User List on next query"
	if {[file exist /usr/share/indimail/indium/images/reload.gif]} {
		$Lwin.2.c2 config -image [image create photo -file /usr/share/indimail/indium/images/reload.gif]
	}
	pack $Lwin.2.l1 $Lwin.2.search $Lwin.2.c1 $Lwin.2.c2 -side left -anchor nw

	frame $Lwin.2.f -relief ridge -bd 2
	label $Lwin.2.f.l1 -relief flat -text "User Limit" -bd 2
	if {$BWidget_present} {
		SpinBox $Lwin.2.f.e -relief sunken -textvariable userLimit -bd 2 -width 5 \
			-range {0 5000 100} \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $Lwin.2.f.e   -relief sunken -textvariable userLimit -bd 2 -width 5 \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	label $Lwin.2.f.l2 -relief flat -text "Total" -bd 2
	label $Lwin.2.f.l3 -relief flat -justify left -textvariable userCount -width 10 -bd 2
	pack $Lwin.2.f -side left -padx 20 -anchor nw
	pack $Lwin.2.f.l1 $Lwin.2.f.e $Lwin.2.f.l2 $Lwin.2.f.l3 -side left -anchor nw

	scrollbar $Lwin.3.vsb -orient vertical   -trough black \
		-command [list $Lwin.3.listbox yview]
	scrollbar $Lwin.3.hsb -orient horizontal -trough black \
		-command [list $Lwin.3.listbox xview]
	mclistbox $Lwin.3.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 15 \
	    -width 135 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand "selectUser $Lwin.3.listbox" \
	    -xscrollcommand [list $Lwin.3.hsb set] \
	    -yscrollcommand [list $Lwin.3.vsb set]
	bind $Lwin.3.listbox <<ListboxSelect>> {
		focus $Lwin.3.listbox
	}
	bind $Lwin.3.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	$Lwin.3.listbox column add a1    -label "Name"      -width 25
	$Lwin.3.listbox column add a2    -label "Domain"    -width 25
	$Lwin.3.listbox column add a3    -label "Password"  -width 14
	$Lwin.3.listbox column add a4    -label "uid"       -width 5
	$Lwin.3.listbox column add a5    -label "gid"       -width 5
	$Lwin.3.listbox column add a6    -label "Gecos"     -width 25
	$Lwin.3.listbox column add a7    -label "Directory" -width 45
	$Lwin.3.listbox column add a8    -label "Quota"     -width 15

	$Lwin.3.listbox label bind a1 <ButtonPress-1> "listboxsort %W a1"
	$Lwin.3.listbox label bind a2 <ButtonPress-1> "listboxsort %W a2"
	$Lwin.3.listbox label bind a3 <ButtonPress-1> "listboxsort %W a3"
	$Lwin.3.listbox label bind a4 <ButtonPress-1> "listboxsort %W a4"
	$Lwin.3.listbox label bind a5 <ButtonPress-1> "listboxsort %W a5"
	$Lwin.3.listbox label bind a6 <ButtonPress-1> "listboxsort %W a6"
	$Lwin.3.listbox label bind a7 <ButtonPress-1> "listboxsort %W a7"
	$Lwin.3.listbox label bind a8 <ButtonPress-1> "listboxsort %W a8"

	pack $Lwin.3.hsb     -side bottom -fill x
	pack $Lwin.3.vsb     -side right  -fill y
	pack $Lwin.3.listbox -side left -expand 1 -fill both

	button $Lwin.4.run  -text "List"   -bg orange \
		-bd 5 -highlightthickness 5 -highlightbackground black \
		-command {
			list_user1 $Lwin $domain $sqlserver $search $inactiveFlag
		}
	button $Lwin.4.exit -text "Close" -bg IndianRed \
		-bd 5 -highlightthickness 5 -highlightbackground black \
		-command {wm withdraw $base;return}

	pack $Lwin.4.run  -side left -expand 0 -anchor nw -fill none
	pack $Lwin.4.exit -side left -expand 0 -anchor nw -fill none
}

proc list_user1 {dbwin domain server search flag} {
	global BWidget_present prgtext userList1 userCount refreshUser userLimit userList2
	source /usr/share/indimail/indium/scripts/global.tcl
	variable t_server
	variable currOffset

	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {Domain value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {$server == ""} {
		set t_server $mysql_host
	} else {
		set t_server $server
	}
	if {$flag == 1} {
		set table "indibak"
	} else {
		set table "indimail"
	}
	if {$refreshUser == 1 || $userLimit <= 0} {
		set ::userList1 {}
		set ::userList2 {}
		set userCount 0
		set currOffset 0
		$dbwin.3.listbox delete 0 end
		set refreshUser 0
	}
	if {$userLimit > 0} {
		set limit " LIMIT $currOffset,$userLimit"
	} else {
		set limit ""
	}
	if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
		catch {destroy .progress}
		msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[catch {sql selectdb indimail} result]} {
		catch {destroy .progress}
		msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		sql disconnect
		return 1
	}
	if {[string length $search] <= 0} {
		set sql_statement "SELECT pw_name, pw_domain, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell FROM $table where pw_domain=\"$domain\" $limit"
	} else {
		set sql_statement "SELECT pw_name, pw_domain, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell FROM $table where pw_name like \"$search%\" and pw_domain=\"$domain\" $limit"
	}
	set currOffset [expr $currOffset + $userLimit]
	if {[catch {sql $sql_statement} result]} {
		catch {destroy .progress}
		msg_dialog .d "MySQL Select" "$sql_statement\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		sql disconnect
		return 1
	}
	sql disconnect
	foreach row $result {
		set a1 [lindex $row 0]
		set a2 [lindex $row 1]
		set a3 [lindex $row 2]
		set a4 [lindex $row 3]
		set a5 [lindex $row 4]
		set a6 [lindex $row 5]
		if {[string compare -length 9 $a6 "MailGroup"] == 0} {
			continue
		}
		lappend ::userList1 $a1@$domain
		lappend ::userList2 $a1
		set userCount [expr $userCount + 1]
		set a7 [lindex $row 6]
		set a8 [lindex $row 7]
		$dbwin.3.listbox insert end [list $a1 $a2 $a3 $a4 $a5 $a6 $a7 $a8]
		catch {$dwin.log insert end "$row\n"}
	}
	if {[llength $result] < $userLimit} {
		$dbwin.4.run configure -text "No Rows"
		$dbwin.4.run configure -state disabled
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	catch {$dwin.log yview moveto 1}
}

proc list_user2 {domain server flag} {
	global userList1 userList2 userCount refreshUser userLimit
	source /usr/share/indimail/indium/scripts/global.tcl
	global saveDomain
	variable t_server
	variable currOffset

	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {Domain value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$server == ""} {
		set t_server $adminhost
	} else {
		set t_server $server
	}
	if {$flag == 1} {
		set table "indibak"
	} else {
		set table "indimail"
	}
	if {$saveDomain != $domain} {
		set refreshUser 1
	}
	if {$refreshUser == 1 || $userLimit <= 0} {
		set ::userList1 {}
		set ::userList2 {}
		set userCount 0
		set currOffset 0
		set refreshUser 0
	}
	if {$userLimit > 0} {
		set limit " LIMIT $currOffset,$userLimit"
	} else {
		set limit ""
	}
	if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
		msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[catch {sql selectdb indimail} result]} {
		msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		sql disconnect
		return 1
	}
	set sql_statement "SELECT pw_name, pw_gecos FROM $table where pw_domain=\"$domain\" $limit"
	set currOffset [expr $currOffset + $userLimit]
	if {[catch {sql $sql_statement} result]} {
		msg_dialog .d "MySQL Select" "$sql_statement\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		sql disconnect
		return 1
	}
	sql disconnect
	. configure -cursor watch
	update idletasks
	foreach row $result {
		set a1 [lindex $row 0]
		set a2 [lindex $row 1]
		if {[string compare -length 9 $a2 "MailGroup"] != 0} {
			lappend ::userList1 $a1@$domain
			lappend ::userList2 $a1
			set userCount [expr $userCount + 1]
		}
	}
	. configure -cursor {}
}

proc selectUser {w1 args} {
	global t_username username
	variable cur_sel

	if {[info exists args] && [string length $args] > 0} {
		set t_username [lindex [$w1 get $args] 0]
		set domain     [lindex [$w1 get $args] 1]
		set username $t_username
		set Domain $domain
	}
}

proc mysql {} {
	global BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	set domain ""
	set result 0

	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set Description "MySQL"
	wm title . $Description
	bind . <F1> {doHelp mysqlclient}
	.statusBar.lab configure -text $Description

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr -text $Description -side center -relief ridge -bd 2
		pack $w.fr -side top -anchor w -fill both
		set fr [$w.fr getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set dwin $fr.debug
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin $rwin -pady 40
	}

	label $lwin.domain   -text "Domain"   -relief ridge -bd 2 -width 9
	label $lwin.server   -text "Server"   -relief ridge -bd 2 -width 9

	set domain $default_domain
	combobox $rwin.domain \
		-textvariable domain \
		-editable false \
		-borderwidth 3 \
		-width 15 \
		-value $domain \
		-command {setServerVal $rwin.server}
	foreach line $domain_list {
		$rwin.domain list insert end $line
	}
	combobox $rwin.server \
		-textvariable server \
		-editable false \
		-width 15 \
		-command {setSqlServerVal $domain} \
		-borderwidth 3 
	setServerVal $rwin.server $w $domain

	button $rwin.run  -text Run  -bg orange -command "run_mysql" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $rwin.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black

	pack $lwin.domain -side top  -expand 0 -anchor nw -fill x -ipady 2
	pack $lwin.server -side top  -expand 0 -anchor nw -fill x -ipady 2
	pack $rwin.domain -side top  -expand 0 -anchor nw -fill none
	pack $rwin.server -side top  -expand 0 -anchor nw -fill none
	pack $rwin.run    -side left -expand 0 -anchor nw -fill none
	pack $rwin.quit   -side left -expand 0 -anchor nw -fill none
}

proc run_mysql {} {
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {domain required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $adminhost] <= 0} {
		msg_dialog .d {Invalid Host} {hostname required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	puts stdout "exec $configs(xterm) -e /usr/libexec/indimail/execmysql -d $domain $adminhost"
	catch "exec $configs(xterm) -e \"/usr/libexec/indimail/execmysql -d $domain $adminhost\" &" result
}

proc dbcontrol {args} {
	global BWidget_present prgtext
	global Domain mcdfile Checkbutton mdahost
	global t_adminuser t_adminpass admin_list
	global local_domain_list win
	source /usr/share/indimail/indium/scripts/global.tcl
	variable smtpframe
	variable hostidframe
	variable dbinfoframe
	variable fstabframe
	variable ipmapframe
	variable tmpwin
	variable li
	variable twin1
	variable twin2
	variable pane2
	variable bwin
	variable lwin8
	variable flag1
	variable flag2
	set flag1 1
	set flag2 1

	set w .dname
	set win $w
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*

	set li 0
	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Database Controls"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp DBmgmt}
	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw -expand 1 -fill both
		set pane1  [$pw add -weight 60 -minsize 10]
		set pane2  [$pw add -weight 40 -minsize 10]
		set lf [TitleFrame $pane1.fr -text $Description -side center -relief ridge -bd 2]
		pack $lf -side top -anchor nw -fill both
		set tf [$lf getframe]
		set lwin $tf.notebook
		set dwin $pane2.debug
		set prgtext "Hmm... I am very Busy"
		progressDialog
	} else {
		frame $w -relief ridge -bd 2
		pack $w -expand 1 -fill both
		set lwin $w.left
		set dwin $w.debug
	}
	if {[info exists args] && $args != ""} {
		set Domain [lindex $args 2]
		set domain $Domain
	} else {
		set domain $default_domain
	}
	if {$BWidget_present == 1} {
		set notebook [NoteBook $lwin]
		$notebook compute_size
		pack $notebook -side left -fill y -expand 0 -padx 4 -pady 4
		set lwin1 [$lwin insert end smtp   -text "SMTP" \
			-raisecmd {pack forget $dwin;smtproutes 1 $pane2} \
			-leavecmd {destroy $pane2.fr;pack $dwin -expand 1 -fill both} \
		]
		set lwin2 [$lwin insert end hostid -text "Hostid"]
		set lwin3 [$lwin insert end dbinfo -text "Dbinfo"]
		set lwin4 [$lwin insert end fstab  -text "FSTAB"]
		set lwin5 [$lwin insert end ipmap  -text "IPMAP"]
		set lwin6 [$lwin insert end ports  -text "Ports" \
			-raisecmd {pack forget $dwin;vpriv $pane2} \
			-leavecmd {destroy $pane2.t;pack $dwin -expand 1 -fill both} \
			]
		set lwin7 [$lwin insert end filter -text "Filter"]
		set lwin8 [$lwin insert end atrnmap -text "ATRN Maps" \
			-raisecmd {catch {$lwin8.domain.e select 0}} \
			-leavecmd {set Domain $default_domain;set server [lindex $server_list($Domain) 0]} \
			]
		if {[info exists args] && $args != ""} {
			$notebook raise [$notebook page [lindex $args 0]]
		} else {
			$notebook raise [$notebook page 0]
		}
	} else {
		set NotebookPages {SMTP Hostid Dbinfo FSTAB IPMAP Ports Filter}
		Notebook:create $lwin -pad 2 -pages $NotebookPages
		set lwin1 [Notebook:frame $lwin SMTP]
		set lwin2 [Notebook:frame $lwin Hostid]
		set lwin3 [Notebook:frame $lwin Dbinfo]
		set lwin4 [Notebook:frame $lwin FSTAB]
		set lwin5 [Notebook:frame $lwin IPMAP]
		set lwin6 [Notebook:frame $lwin Ports]
		set lwin7 [Notebook:frame $lwin Filter]
		set lwin8 [Notebook:frame $lwin ATRNMAP]
		pack $lwin -side left -fill y -expand 0 -anchor nw -padx 4 -pady 4
	}
	## Frame 1 #######################################################################
	foreach tmpwin "$lwin1 $lwin2 $lwin3 $lwin4 $lwin5 $lwin8" {
		frame $tmpwin.domain -relief flat   -bd 2
		pack $tmpwin.domain  -side top -anchor w
		label $tmpwin.domain.l1 -relief flat   -text Domain -bd 2 -width 10
		combobox $tmpwin.domain.e \
			-textvariable Domain \
			-editable false \
			-borderwidth 2 \
			-value $domain \
			-command "setServerVal $tmpwin.domain.s"
		if {$tmpwin == $lwin8} {
			foreach line $local_domain_list {
				$tmpwin.domain.e list insert end $line
			}
		} else {
			foreach line $domain_list {
				$tmpwin.domain.e list insert end $line
			}
		}
		label $tmpwin.domain.l2 -relief flat   -text Server -bd 2
		combobox $tmpwin.domain.s \
			-textvariable server \
			-editable false \
			-width 13 \
			-borderwidth 2 \
			-command "setmdahost"
		setServerVal $tmpwin.domain.s $tmpwin.domain.e $Domain
		pack $tmpwin.domain.l1  -side left -fill x -ipady 2
		pack $tmpwin.domain.e $tmpwin.domain.l2 $tmpwin.domain.s -side left
		button $tmpwin.domain.showall -relief raised -bd 4 -bg IndianRed
		$tmpwin.domain.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
		pack $tmpwin.domain.showall -side left
		balloonHelp $tmpwin.domain.showall  "Show/Hide Columns"
	}
	foreach tmpwin "$lwin6 $lwin7" {
		frame $tmpwin.domain -relief flat   -bd 2
		pack $tmpwin.domain  -side top -anchor w
		label $tmpwin.domain.l1 -relief flat   -text Domain -bd 2 -width 10
		combobox $tmpwin.domain.e \
			-textvariable Domain \
			-editable false \
			-borderwidth 2 \
			-value $domain \
			-command "setServerVal $tmpwin.domain.s"
		foreach line $domain_list {
			$tmpwin.domain.e list insert end $line
		}
		combobox $tmpwin.domain.s \
			-textvariable server \
			-editable false \
			-width 13 \
			-command {setSqlServerVal $Domain} \
			-borderwidth 2
		catch {setServerVal $tmpwin.domain.s $tmpwin.domain.e $Domain}
		catch {setSqlServerVal $Domain $tmpwin.domain.s $server}
		label $tmpwin.domain.l2 -relief flat   -text Server -bd 2
		pack $tmpwin.domain.l1  -side left -fill x -ipady 2
		pack $tmpwin.domain.e $tmpwin.domain.l2 $tmpwin.domain.s -side left
		button $tmpwin.domain.showall -relief raised -bd 4 -bg IndianRed
		$tmpwin.domain.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
		pack $tmpwin.domain.showall -side left
		balloonHelp $tmpwin.domain.showall  "Show/Hide Columns"
	}
	$lwin3.domain.e configure -editable true
	set result ""
	text_create "Database Controls" 1 40 25
	pack forget $dwin
	## SMTP PORT ------------------------------------------------------------------------------------------------
	## Frame 1 #######################################################################

	set smtpframe $lwin1.port
	set f1        $lwin1.buttons
	frame $smtpframe -relief flat -bd 0
	frame $f1        -relief flat -bd 2
	pack $smtpframe $f1 -side top -fill none -anchor nw

	scrollbar $smtpframe.vsb -orient vertical   -trough black \
		-command [list $smtpframe.listbox yview]
	scrollbar $smtpframe.hsb -orient horizontal -trough black \
		-command [list $smtpframe.listbox xview]
	mclistbox $smtpframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 40 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand {listboxSelection} \
	    -xscrollcommand [list $smtpframe.hsb set] \
	    -yscrollcommand [list $smtpframe.vsb set]
	bind $smtpframe.listbox <<ListboxSelect>> {
		focus $smtpframe.listbox
	}
	bind $smtpframe.listbox <ButtonPress-3> {
		set count [llength [$smtpframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$smtpframe.listbox selection clear 0 end
			$smtpframe.listbox selection set $li
			$smtpframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuSmtp $smtpframe.listbox [$smtpframe.listbox get $li] $server \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$smtpframe.listbox column add port  -label "Port"      -width 8
	$smtpframe.listbox column add srcip -label "Source IP" -width 16
	$smtpframe.listbox column add dstip -label "Dest   IP" -width 16

	# set up bindings to sort the columns.
	$smtpframe.listbox label bind port  <ButtonPress-1> "listboxsort %W port"
	$smtpframe.listbox label bind srcip <ButtonPress-1> "listboxsort %W srcip"
	$smtpframe.listbox label bind dstip <ButtonPress-1> "listboxsort %W dstip"

	pack $smtpframe.hsb     -side bottom -fill x
	pack $smtpframe.vsb     -side right  -fill y
	label $smtpframe.l
	$smtpframe.l configure -image [image create photo -file /usr/share/indimail/indium/images/postel.gif]
	pack $smtpframe.l -side right -anchor ne
	pack $smtpframe.listbox -side left -expand 1 -fill both
	$lwin1.domain.showall configure \
		-command {showContextMenu $smtpframe.listbox}

	button $f1.run  -text Submit -bg Orange \
		-command {get_smtp $smtpframe.listbox $server} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $f1.quit -text Cancel -bg IndianRed   \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $f1.run $f1.quit      -side left -expand 0 -anchor nw -fill none

	## HOSTID    ------------------------------------------------------------------------------------------------
	## Frame 2 #######################################################################

	set hostidframe $lwin2.hostid
	set f2          $lwin2.buttons
	frame $hostidframe -relief flat  -bd 0
	frame $f2          -relief flat  -bd 2
	pack $hostidframe $f2 -side top -fill none -anchor nw

	scrollbar $hostidframe.vsb -orient vertical   -trough black \
		-command [list $hostidframe.listbox yview]
	scrollbar $hostidframe.hsb -orient horizontal -trough black \
		-command [list $hostidframe.listbox xview]
	mclistbox $hostidframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 32 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand "listboxSelection" \
	    -xscrollcommand [list $hostidframe.hsb set] \
	    -yscrollcommand [list $hostidframe.vsb set]
	bind $hostidframe.listbox <<ListboxSelect>> {
		focus $hostidframe.listbox
	}
	bind $hostidframe.listbox <ButtonPress-3> {
		set count [llength [$hostidframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$hostidframe.listbox selection clear 0 end
			$hostidframe.listbox selection set $li
			$hostidframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuHostid $hostidframe.listbox [$hostidframe.listbox get $li] $server \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$hostidframe.listbox column add hostid -label "Host ID"    -width 16
	$hostidframe.listbox column add ipaddr -label "IP Address" -width 16

	$hostidframe.listbox label bind hostid <ButtonPress-1> "listboxsort %W hostid"
	$hostidframe.listbox label bind ipaddr <ButtonPress-1> "listboxsort %W ipaddr"

	pack $hostidframe.hsb     -side bottom -fill x
	pack $hostidframe.vsb     -side right  -fill y
	pack $hostidframe.listbox -side left -expand 1 -fill both
	$lwin2.domain.showall configure \
		-command {showContextMenu $hostidframe.listbox}

	button $f2.run  -text Submit -bg Orange \
		-command {get_hostid $hostidframe.listbox $server} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $f2.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $f2.run $f2.quit      -side left -expand 0 -anchor nw -fill none

	## DBINFO    ------------------------------------------------------------------------------------------------
	## Frame 3 #######################################################################
	variable entryframe1
	set entryframe1  $lwin3.entry
	set dbinfoframe $lwin3.dbinfo
	set f3          $lwin3.buttons
	frame $entryframe1 -relief flat  -bd 2
	frame $dbinfoframe -relief flat  -bd 0
	frame $f3          -relief flat  -bd 2
	pack $entryframe1 $dbinfoframe $f3 -side top -fill none -anchor nw
	label $entryframe1.l -relief flat   -text "MCD File" -bd 2 -width 10
	set mcdfile /etc/indimail
	append mcdfile "/control/sql"
	entry  $entryframe1.e -relief sunken -textvariable mcdfile -bd 2 -width 40
	button $entryframe1.b \
		-command {set initialdir /etc/indimail/control;fileDialog $w $entryframe1.e open 0} -padx "9" -pady "3" -relief ridge 
	balloonHelp $entryframe1.b "Click to browse for MCD File"
	$entryframe1.b configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
	set Checkbutton [checkbutton $entryframe1.c -text "Clustered" -variable clustered]
	balloonHelp $entryframe1.c "Enable clustering of domain"
	pack $entryframe1.l $entryframe1.e $entryframe1.b $entryframe1.c -side left

	scrollbar $dbinfoframe.vsb -orient vertical   -trough black \
		-command [list $dbinfoframe.listbox yview]
	scrollbar $dbinfoframe.hsb -orient horizontal -trough black \
		-command [list $dbinfoframe.listbox xview]
	mclistbox $dbinfoframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 80 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand "listboxSelection" \
	    -xscrollcommand [list $dbinfoframe.hsb set] \
	    -yscrollcommand [list $dbinfoframe.vsb set]
	bind $dbinfoframe.listbox <<ListboxSelect>> {
		focus $dbinfoframe.listbox
	}
	bind $dbinfoframe.listbox <ButtonPress-3> {
		set count [llength [$dbinfoframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$dbinfoframe.listbox selection clear 0 end
			$dbinfoframe.listbox selection set $li
			$dbinfoframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuDbinfo $dbinfoframe.listbox $mcdfile [$dbinfoframe.listbox get $li] \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$dbinfoframe.listbox column add domain    -label "Domain"    -width 15
	$dbinfoframe.listbox column add mdahost   -label "MdaHost"   -width 15
	$dbinfoframe.listbox column add mserver   -label "Server"    -width 15
	$dbinfoframe.listbox column add port      -label "Port"      -width 5
	$dbinfoframe.listbox column add dbname    -label "Database"  -width 10
	$dbinfoframe.listbox column add user      -label "User"      -width 10
	$dbinfoframe.listbox column add passwd    -label "Password"  -width 10

	$dbinfoframe.listbox label bind mdahost <ButtonPress-1> "listboxsort %W mdahost"
	$dbinfoframe.listbox label bind mserver <ButtonPress-1> "listboxsort %W mserver"
	$dbinfoframe.listbox label bind port    <ButtonPress-1> "listboxsort %W port"
	$dbinfoframe.listbox label bind dbname  <ButtonPress-1> "listboxsort %W dbname"
	$dbinfoframe.listbox label bind user    <ButtonPress-1> "listboxsort %W user"
	$dbinfoframe.listbox label bind passwd  <ButtonPress-1> "listboxsort %W passwd"

	pack $dbinfoframe.hsb     -side bottom -fill x
	pack $dbinfoframe.vsb     -side right  -fill y
	pack $dbinfoframe.listbox -side left -expand 1 -fill both
	$lwin3.domain.showall configure \
		-command {showContextMenu $dbinfoframe.listbox}

	button $f3.run  -text Submit -bg Orange \
		-command {get_dbinfo $dbinfoframe.listbox} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $f3.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $f3.run $f3.quit      -side left -expand 0 -anchor nw -fill none
	## FSTAB ----------------------------------------------------------------------------------------------------
	## Frame 4 #######################################################################

	variable entryframe2
	set entryframe2  $lwin4.entry
	set fstabframe   $lwin4.fstab
	set f4           $lwin4.buttons
	set mdahost ""
	frame $entryframe2 -relief flat  -bd 2
	frame $fstabframe  -relief flat  -bd 0
	frame $f4          -relief flat  -bd 2
	pack $entryframe2 $fstabframe $f4 -side top -fill none -anchor nw
	label $entryframe2.l -relief flat   -text "MDA Host"      -bd 2 -width 10
	entry $entryframe2.e -relief sunken -textvariable mdahost -bd 2 \
		-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell
	pack $entryframe2.l $entryframe2.e -side left

	scrollbar $fstabframe.vsb -orient vertical   -trough black \
		-command [list $fstabframe.listbox yview]
	scrollbar $fstabframe.hsb -orient horizontal -trough black \
		-command [list $fstabframe.listbox xview]
	mclistbox $fstabframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 86 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -fillcolumn filesystem \
	    -selectcommand "listboxSelection" \
	    -xscrollcommand [list $fstabframe.hsb set] \
	    -yscrollcommand [list $fstabframe.vsb set]
	bind $fstabframe.listbox <<ListboxSelect>> {
		focus $fstabframe.listbox
	}
	bind $fstabframe.listbox <ButtonPress-3> {
		set count [llength [$fstabframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$fstabframe.listbox selection clear 0 end
			$fstabframe.listbox selection set $li
			$fstabframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuFstab $fstabframe.listbox [$fstabframe.listbox get $li] $server \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$fstabframe.listbox column add filesystem -label "Filesystem"  -width 10
	$fstabframe.listbox column add host       -label "Host"        -width 15
	$fstabframe.listbox column add status     -label "Status"      -width 10
	$fstabframe.listbox column add maxusers   -label "Max Users"   -width 10
	$fstabframe.listbox column add curusers   -label "Cur Users"   -width 10
	$fstabframe.listbox column add maxsize    -label "Max Size KB" -width 12
	$fstabframe.listbox column add cursize    -label "Cur Size KB" -width 12
	$fstabframe.listbox column add load       -label "Load"        -width 7

	$fstabframe.listbox label bind filesystem <ButtonPress-1> "listboxsort %W filesystem"
	$fstabframe.listbox label bind host       <ButtonPress-1> "listboxsort %W host"
	$fstabframe.listbox label bind status     <ButtonPress-1> "listboxsort %W status"
	$fstabframe.listbox label bind maxusers   <ButtonPress-1> "listboxsort %W maxusers"
	$fstabframe.listbox label bind curusers   <ButtonPress-1> "listboxsort %W curusers"
	$fstabframe.listbox label bind maxsize    <ButtonPress-1> "listboxsort %W maxsize"
	$fstabframe.listbox label bind cursize    <ButtonPress-1> "listboxsort %W cursize"
	$fstabframe.listbox label bind load       <ButtonPress-1> "listboxsort %W load"

	pack $fstabframe.hsb     -side bottom -fill x
	pack $fstabframe.vsb     -side right  -fill y
	pack $fstabframe.listbox -side left -expand 1 -fill both
	$lwin4.domain.showall configure \
		-command {showContextMenu $fstabframe.listbox}

	button $f4.run  -text Submit -bg Orange \
		-command {get_fstab $fstabframe.listbox $server} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $f4.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $f4.run $f4.quit      -side left -expand 0 -anchor nw -fill none

	## IPMAP     ------------------------------------------------------------------------------------------------
	## Frame 5 #######################################################################

	set ipmapframe  $lwin5.hostid
	set f5          $lwin5.buttons
	frame $ipmapframe -relief flat  -bd 0
	frame $f5         -relief flat  -bd 2
	pack $ipmapframe $f5 -side top -fill none -anchor nw

	scrollbar $ipmapframe.vsb -orient vertical   -trough black \
		-command [list $ipmapframe.listbox yview]
	scrollbar $ipmapframe.hsb -orient horizontal -trough black \
		-command [list $ipmapframe.listbox xview]
	mclistbox $ipmapframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 40 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand "listboxSelection" \
	    -xscrollcommand [list $ipmapframe.hsb set] \
	    -yscrollcommand [list $ipmapframe.vsb set]
	bind $ipmapframe.listbox <<ListboxSelect>> {
		focus $ipmapframe.listbox
	}
	bind $ipmapframe.listbox <ButtonPress-3> {
		set count [llength [$ipmapframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$ipmapframe.listbox selection clear 0 end
			$ipmapframe.listbox selection set $li
			$ipmapframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuIpmap $ipmapframe.listbox [$ipmapframe.listbox get $li] $server \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$ipmapframe.listbox column add ipaddr -label "IP Address" -width 15
	$ipmapframe.listbox column add domain -label "Domain"     -width 25

	$ipmapframe.listbox label bind ipaddr <ButtonPress-1> "listboxsort %W ipaddr"
	$ipmapframe.listbox label bind domain <ButtonPress-1> "listboxsort %W domain"

	pack $ipmapframe.hsb     -side bottom -fill x
	pack $ipmapframe.vsb     -side right  -fill y
	pack $ipmapframe.listbox -side left -expand 1 -fill both
	$lwin5.domain.showall configure \
		-command {showContextMenu $ipmapframe.listbox}

	button $f5.run  -text Submit -bg Orange \
		-command {get_ipmap $ipmapframe.listbox $server} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $f5.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $f5.run $f5.quit      -side left -expand 0 -anchor nw -fill none

	## Ports     ------------------------------------------------------------------------------------------------
	## Frame 6 #######################################################################

	set admin_list {}
	set twin1 [frame $lwin6.1]
	set fr    [frame $lwin6.2]
	pack $twin1 $fr -side top -anchor nw
	set bwin  [frame $fr.1]
	set twin2 [frame $fr.2]
	pack $bwin $twin2 -side left -anchor w

	scrollbar $twin1.vsb -orient vertical   -trough black \
		-command [list $twin1.listbox yview]
	scrollbar $twin1.hsb -orient horizontal -trough black \
		-command [list $twin1.listbox xview]
	mclistbox $twin1.listbox \
		-bd 0 \
		-font "Terminal" \
		-height 10 \
		-width 95 \
		-labelanchor w \
		-columnrelief flat \
		-columnborderwidth 2 \
		-labelborderwidth 2 \
		-resizablecolumn 1 \
		-selectmode single \
		-selectcommand "selectadminUser $twin1.listbox" \
		-xscrollcommand [list $twin1.hsb set] \
		-yscrollcommand [list $twin1.vsb set]
	bind $twin1.listbox <<ListboxSelect>> {
		focus $twin1.listbox
	}
	$twin1.listbox column add user       -label "User"        -width 15
	$twin1.listbox column add encrypted  -label "Encrypted"   -width 14
	$twin1.listbox column add uid        -label "Uid"         -width 4
	$twin1.listbox column add gid        -label "Gid"         -width 4
	$twin1.listbox column add lastaccess -label "Last Access" -width 20
	$twin1.listbox column add lastupdate -label "Last Update" -width 20
	$twin1.listbox column add attempts   -label "Attempts"    -width 9
	$twin1.listbox column add status     -label "Status"      -width 8

	$twin1.listbox label bind user       <ButtonPress-1> "listboxsort %W user"
	$twin1.listbox label bind encrypted  <ButtonPress-1> "listboxsort %W encrypted"
	$twin1.listbox label bind uid        <ButtonPress-1> "listboxsort %W uid"
	$twin1.listbox label bind gid        <ButtonPress-1> "listboxsort %W gid"
	$twin1.listbox label bind lastaccess <ButtonPress-1> "listboxsort %W lastaccess"
	$twin1.listbox label bind lastupdate <ButtonPress-1> "listboxsort %W lastupdate"
	$twin1.listbox label bind attempts   <ButtonPress-1> "listboxsort %W attempts"
	$twin1.listbox label bind status     <ButtonPress-1> "listboxsort %W status"

	pack $twin1.hsb     -side bottom -fill x
	pack $twin1.vsb     -side right  -fill y
	pack $twin1.listbox -side left -expand 1 -fill both
	$lwin6.domain.showall configure -command {showContextMenu $twin1.listbox}

	bind $twin1.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}

	frame $twin2.1
	frame $twin2.2
	pack $twin2.1 $twin2.2 -side top -anchor nw
	label $twin2.1.l -relief flat -bd 0 -width 15
	label $twin2.2.l -relief flat -bd 0 -width 15
	entry $twin2.1.e -relief flat -bd 2 -textvariable t_adminuser -state disabled \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	entry $twin2.2.e -relief flat -bd 2 -textvariable t_adminpass -state disabled -show * \
		-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell
	pack $twin2.1.l -side left -expand 0 -anchor nw
	pack $twin2.1.e -side left -expand 0 -anchor nw -fill x
	pack $twin2.2.l -side left -expand 0 -anchor nw
	pack $twin2.2.e -side left -expand 0 -anchor nw -fill x

	if {$BWidget_present == 1} {
		TitleFrame $bwin.button -text "Options" -side center -relief sunken -bd 2
		pack $bwin.button -side top -pady 5 -anchor nw
		set opframe [$bwin.button getframe]
	} else {
		frame $bwin.button -relief ridge -bd 2
		pack $bwin.button -side top -pady 5 -anchor nw
		set opframe $bwin.button
	}
	radiobutton $opframe.1 -value 1 -variable flag1 -text "User Info"       -underline 0 \
		-command {
			$twin2.1.e configure -relief flat -state disabled
			$twin2.2.e configure -relief flat -state disabled
			$twin2.1.l configure -text ""
			$twin2.2.l configure -text ""
			$bwin.info configure -text "Info"
			$bwin.info configure -cursor {}
		}

	radiobutton $opframe.2 -value 2 -variable flag1 -text "Change Password" -underline 0 \
		-command {
			set t_adminpass ""
			$twin2.1.e configure -relief flat -state disabled
			$twin2.2.e configure -relief sunken -state normal
			$twin2.1.l configure -text ""
			$twin2.2.l configure -text "New Password"
			$bwin.info configure -text "Change Password"
			$bwin.info configure -cursor {}
		}

	radiobutton $opframe.3 -value 3 -variable flag1 -text "Add User"        -underline 0 \
		-command {
			set t_adminuser ""
			$twin2.1.e configure -relief sunken -state normal
			$twin2.2.e configure -relief sunken -state normal
			$twin2.1.l configure -text "New User"
			$twin2.2.l configure -text "New Password"
			$bwin.info configure -text "Add User"
			$bwin.info configure -cursor {}
		}

	radiobutton $opframe.4 -value 4 -variable flag1 -text "Delete User"     -underline 0 \
		-command {
			$twin2.1.e configure -relief flat -state disabled
			$twin2.2.e configure -relief flat -state disabled
			$twin2.1.l configure -text ""
			$twin2.2.l configure -text ""
			$bwin.info configure -text "Delete User"
			$bwin.info configure -cursor pirate
		}
	pack $opframe.1 $opframe.2 $opframe.3 $opframe.4 -side top -anchor w
	button $bwin.info -text Info -bg orange \
		-bd 5 -highlightthickness 2 -highlightbackground black -width 20 \
		-command {run_mgmt $flag1 $twin1.listbox $t_adminuser $t_adminpass}
	button $bwin.quit -text Quit -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 2 -highlightbackground black -state normal
	pack $bwin.info $bwin.quit  -side left -expand 0 -anchor nw -fill x

	## Filters  ------------------------------------------------------------------------------------------------
	## Frame 7 #######################################################################
	global header_list filter_comparision_list t_filterno t_username
	global t_filtername t_header_no t_comparision_no t_keyword t_destination t_forward
	global t_header t_comparision
	set t_filtername ""
	set t_header_no ""
	set t_comparision_no ""
	set t_keyword ""
	set t_destination ""
	set t_forward ""
	set t_header ""
	set t_comparision ""
	set t_filterno ""
	set t_header ""
	set t_comparision ""
	variable filterframe1
	variable filterframe2
	variable filterframe2
	variable filterframe3
	variable filterframe4
	variable optwin
	global   opframe2 inactiveFlag vfilter_disabled vfilterFile \
		postFlag preFlag global_disabled post_disabled
	if {[catch {open /etc/indimail/headerlist r} f]} {
		set header_list {
			"Return-Path" \
			"From" \
			"Subject" \
			"To" \
			"Cc" \
			"Bcc" \
			"Reply-To" \
			"Date" \
			"Sender" \
			"User-Agent" \
			"Message-Id" \
			"MIME-Version" \
			"Content-Type" \
			"Content-Transfer-Encoding" \
			"Precedence" \
			"Organization" \
			"Errors-To" \
			"List-Id" \
			"Mailing-List" \
			"X-Sender" \
			"X-Mailing-List" \
			"X-ML-Name" \
			"X-List" \
			"X-Loop" \
			"X-BeenThere" \
			"X-Sequence" \
			"X-Mailer" \
			"Importance" \
			"X-Priority" \
			"X-Mailer" \
			"X-Spam-Status" \
			"X-Spam-Rating" \
			"Received" \
		}
	} else {
		set header_list [read $f]
		close $f
	}
	set filter_comparision_list {
		"Equals" \
		"Contains" \
		"Does not contain" \
		"Starts with" \
		"Ends with" \
		"Sender Not in Address Book" \
		"My id not in To, CC, Bcc" \
		"Numerical Logical Exp" \
		"RegExp"
	}
	set filterframe1  [frame $lwin7.1]
	set filterframe2  [frame $lwin7.2]
	set fr            [frame $lwin7.3]
	set optwin        [frame $fr.1]
	set tmpfr         [frame $fr.2]
	pack $optwin    -side left -anchor nw
	pack $tmpfr     -side left -anchor nw
	set filterframe3  [frame $tmpfr.1]
	set filterframe4  [frame $tmpfr.2]
	pack $filterframe3 -side top -anchor nw -expand 1 -fill x
	pack $filterframe4 -side top -anchor nw
	pack $filterframe1 $filterframe2 $fr -side top -anchor nw

	label $filterframe1.l1 -relief flat   -text "Username" -bd 2 -width 10
	hugecombo $filterframe1.e1 -relief sunken -textvariable t_username -bd 2 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell \
		-listvariable ::userList2
	button $filterframe1.b1 \
		-command {list_user2 $Domain $server $inactiveFlag;$filterframe1.e1 list open}
	balloonHelp $filterframe1.b1 "List Users on System"
	$filterframe1.b1 config -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBPz+/MTCxISChMT+/ATCxASChFxaXAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARaEMg5gw00yyDGIAR1YUDggeFWFIZhnSBZrsZxdIOFEGTA2oeBAHeyuGwvzxBlYdUOLROMFzDQntJPrNoqAKUBaqnV+k57ZORruykHDj2LqIzUVKp1u0iuB/gjACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	set vfilter_disabled 2
	set global_disabled 2
	set post_disabled 2
	frame $filterframe1.b2
	checkbutton $filterframe1.b2.1 -text "Disable All User Filters" \
		-variable vfilter_disabled -state disabled -command {
			if {[info exists vfilter_disabled] && [info exists vfilterFile]} {
				if {$vfilter_disabled == 1} {
					file delete -force $vfilterFile
				} elseif {$vfilter_disabled == 0} {
					close [open $vfilterFile w]
					file attributes $vfilterFile -owner indimail -group vchkpw
				}
			}
		}
	balloonHelp $filterframe1.b2.1 "Disable User defined Filters.\nGlobal Filters and Post Filters will however work"
	checkbutton $filterframe1.b2.2 -text "Disable Global Pre Filters" \
		-variable global_disabled -state disabled -command {
			if {[info exists global_disabled] && [info exists preFlag]} {
				if {$global_disabled == 1} {
					close [open $preFlag w]
					file attributes $preFlag -owner indimail -group vchkpw
				} elseif {$global_disabled == 0} {
					file delete -force $preFlag
				}
			}
		}
	balloonHelp $filterframe1.b2.2 "Disable Global Pre Filters."
	checkbutton $filterframe1.b2.3 -text "Disable Global Post Filters" \
		-variable post_disabled -state disabled -command {
			if {[info exists post_disabled] && [info exists postFlag]} {
				if {$post_disabled == 1} {
					close [open $postFlag w]
					file attributes $postFlag -owner indimail -group vchkpw
				} elseif {$post_disabled == 0} {
					file delete -force $postFlag
				}
			}
		}
	balloonHelp $filterframe1.b2.3 "Disable Global Post Filters."
	pack $filterframe1.b2.1 $filterframe1.b2.2 $filterframe1.b2.3 -side top -anchor nw
	bind $filterframe1.e1 <Return> {
		if {[string length $t_username]} {
			set username $t_username
			$opframe2.1 select
			$filterframe4.info configure -text "Info"
			run_filter 1 $filterframe2.listbox $t_username $Domain
			$filterframe2.listbox selection set 0
		}
	}
	pack $filterframe1.l1 -side left
	pack $filterframe1.e1 $filterframe1.b1 $filterframe1.b2 -padx 2 -side left

	scrollbar $filterframe2.vsb -orient vertical   -trough black \
		-command [list $filterframe2.listbox yview]
	scrollbar $filterframe2.hsb -orient horizontal -trough black \
		-command [list $filterframe2.listbox xview]
	mclistbox $filterframe2.listbox \
		-bd 0 \
		-font "Terminal" \
		-height 5 \
		-width 175 \
		-labelanchor w \
		-columnrelief flat \
		-columnborderwidth 2 \
		-labelborderwidth 2 \
		-resizablecolumn 1 \
		-selectmode single \
		-selectcommand {selectFilter $filterframe2.listbox} \
		-xscrollcommand [list $filterframe2.hsb set] \
		-yscrollcommand [list $filterframe2.vsb set]
	bind $filterframe2.listbox <<ListboxSelect>> {
		focus $filterframe2.listbox
	}
	$filterframe2.listbox column add filter_no   -label "No"            -width 5
	$filterframe2.listbox column add user        -label "User"          -width 30
	$filterframe2.listbox column add filter_name -label "Filter Name"   -width 20
	$filterframe2.listbox column add header      -label "Header"        -width 20
	$filterframe2.listbox column add comparision -label "Comparision"   -width 15
	$filterframe2.listbox column add keyword     -label "Keyword"       -width 30
	$filterframe2.listbox column add destination -label "Destination"   -width 20
	$filterframe2.listbox column add baction     -label "Action"        -width 10
	$filterframe2.listbox column add forward     -label "Forward"       -width 25

	$filterframe2.listbox label bind filter_no   <ButtonPress-1> "listboxsort %W filter_no"
	$filterframe2.listbox label bind user        <ButtonPress-1> "listboxsort %W user"
	$filterframe2.listbox label bind filter_name <ButtonPress-1> "listboxsort %W filter_name"
	$filterframe2.listbox label bind header      <ButtonPress-1> "listboxsort %W header"
	$filterframe2.listbox label bind comparision <ButtonPress-1> "listboxsort %W comparision"
	$filterframe2.listbox label bind keyword     <ButtonPress-1> "listboxsort %W keyword"
	$filterframe2.listbox label bind destination <ButtonPress-1> "listboxsort %W destination"
	$filterframe2.listbox label bind baction     <ButtonPress-1> "listboxsort %W baction"
	$filterframe2.listbox label bind forward     <ButtonPress-1> "listboxsort %W forward"

	pack $filterframe2.hsb     -side bottom -fill x
	pack $filterframe2.vsb     -side right  -fill y
	pack $filterframe2.listbox -side left -expand 1 -fill both -anchor nw
	$lwin7.domain.showall configure \
		-command {showContextMenu $filterframe2.listbox}

	bind $filterframe2.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
		[::mclistbox::convert %W -W] \
		[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	## - Options ----------------------------------------------------------------------------
	if {$BWidget_present == 1} {
		TitleFrame $filterframe3.button -text "Options" -side left -relief sunken
		pack $filterframe3.button -side top -anchor ne -padx 10 -expand 1 -fill x
		set opframe2 [$filterframe3.button getframe]
	} else {
		frame $filterframe3.button -relief ridge -bd 2
		pack $filterframe3.button -side top -padx 10 -pady 5 -anchor ne
		set opframe2 $filterframe3.button
	}
	filter_add $optwin $filterframe2.listbox 1
	radiobutton $opframe2.1 -value 1 -variable flag2 -text "Info"   -underline 0 \
		-command {$filterframe4.info configure -text "Info";filter_add $optwin $filterframe2.listbox $flag2}
	radiobutton $opframe2.2 -value 2 -variable flag2 -text "Add"    -underline 0 \
		-command {$filterframe4.info configure -text "Add Filter";filter_add $optwin $filterframe2.listbox $flag2}
	radiobutton $opframe2.3 -value 3 -variable flag2 -text "Modify" -underline 0 \
		-command {$filterframe4.info configure -text "Modify Filter";filter_add $optwin $filterframe2.listbox $flag2}
	radiobutton $opframe2.4 -value 4 -variable flag2 -text "Delete" -underline 0 \
		-command {$filterframe4.info configure -text "Delete Filter";filter_add $optwin $filterframe2.listbox $flag2}
	pack $opframe2.1 $opframe2.2 $opframe2.3 $opframe2.4 -side top -anchor w
	## - Options ----------------------------------------------------------------------------

	button $filterframe4.info -text Info -bg orange \
		-bd 5 -highlightthickness 2 -highlightbackground black -width 20 \
		-command {
			run_filter $flag2 $filterframe2.listbox $t_username $Domain
			$filterframe1.b2.1 configure -state normal
			$filterframe1.b2.2 configure -state normal
		} 
	button $filterframe4.quit -text Quit -bg IndianRed \
		-bd 5 -highlightthickness 2 -highlightbackground black -state normal \
		-command "destroyWindows;return" 
	pack $filterframe4.info $filterframe4.quit  -side top -expand 0 -pady 5 -anchor nw -fill x
	catch {destroy .progress}
	if {[info exists args] && $args != "" && [lindex $args 0] == 6} {
		$opframe2.1 select
		$filterframe4.info configure -text "Info"
		set t_username [lindex $args 1]
		set username $t_username
		run_filter 1 $filterframe2.listbox $t_username $Domain
		$filterframe2.listbox selection set 0
	}

	## ATRNMAP   ------------------------------------------------------------------------------------------------
	## Frame 8 #######################################################################

	variable atmapframe
	set atmapframe  $lwin8.atrnmap
	set but         $lwin8.buttons
	frame $atmapframe -relief flat  -bd 0
	frame $but         -relief flat  -bd 2
	pack $atmapframe $but -side top -fill none -anchor nw

	scrollbar $atmapframe.vsb -orient vertical   -trough black \
		-command [list $atmapframe.listbox yview]
	scrollbar $atmapframe.hsb -orient horizontal -trough black \
		-command [list $atmapframe.listbox xview]
	mclistbox $atmapframe.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 65 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
	    -selectcommand "listboxSelection" \
	    -xscrollcommand [list $atmapframe.hsb set] \
	    -yscrollcommand [list $atmapframe.vsb set]
	bind $atmapframe.listbox <<ListboxSelect>> {
		focus $atmapframe.listbox
	}
	bind $atmapframe.listbox <ButtonPress-3> {
		set count [llength [$atmapframe.listbox get 0 end]]
		if {$count > 0} {
			set li [expr %y / 16]
			if {$li >= $count} {
				set li [expr $count - 1]
			}
			$atmapframe.listbox selection clear 0 end
			$atmapframe.listbox selection set $li
			$atmapframe.listbox activate $li
		} else {
			set li -1
		}
		showmenuAtrnMap $atmapframe.listbox [$atmapframe.listbox get $li] $server \
	   		[::mclistbox::convert %W -x %x] [::mclistbox::convert %W -y %y]  %X %Y 
	}
	$atmapframe.listbox column add username   -label "Username"    -width 15
	$atmapframe.listbox column add domain     -label "Domain"      -width 25
	$atmapframe.listbox column add atrndomain -label "ATRN Domain" -width 25

	$atmapframe.listbox label bind username   <ButtonPress-1> "listboxsort %W username"
	$atmapframe.listbox label bind domain     <ButtonPress-1> "listboxsort %W domain"
	$atmapframe.listbox label bind atrndomain <ButtonPress-1> "listboxsort %W atrndomain"

	pack $atmapframe.hsb     -side bottom -fill x
	pack $atmapframe.vsb     -side right  -fill y
	pack $atmapframe.listbox -side left -expand 1 -fill both
	$lwin8.domain.showall configure \
		-command {showContextMenu $atmapframe.listbox}

	button $but.run  -text Submit -bg Orange \
		-command {get_atrnmap $atmapframe.listbox $server} -bd 5 \
		-highlightthickness 5 -highlightbackground black
	button $but.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $but.run $but.quit      -side left -expand 0 -anchor nw -fill none
	if {[info exists args] && $args != "" && [lindex $args 0] == 7} {
		get_atrnmap $atmapframe.listbox $server
	}
}

proc filter_add {optwin w1 operation} {
	global vframe
	global header_list filter_comparision_list
	global BWidget_present prgtext
	global t_filterno t_filtername t_header_no t_comparision_no t_keyword t_destination t_forward t_bounce
	global t_header t_comparision

	if {$operation == 2} {
		set t_filtername ""
		set t_header_no ""
		set t_comparision_no ""
		set t_keyword ""
		set t_destination ""
		set t_forward ""
		set t_ftype 0
		set t_bounce 0
		if {[info exists vframe] && [winfo exists $vframe]} {
			if {$BWidget_present == 1} {
				set t_header ""
				set t_comparision ""
				set t_filterno ""
			} else {
				$vframe.2.e selection clear
				$vframe.3.e selection clear
			}
			set t_header ""
			set t_comparision ""
		}
	} else {
		set cur_sel [$w1 curselection]
		if {[info exists cur_sel] && $cur_sel >= 0} {
			$w1 selection clear 0 end
			$w1 selection set $cur_sel
			$w1 activate $cur_sel
		}
	}
	if {$operation == 1 || $operation == 4} {
		catch {
			$vframe.1.e1     configure -state disabled
			$vframe.2.e      configure -state disabled
			$vframe.3.e      configure -state disabled
			$vframe.4.e      configure -state disabled
			$vframe.5.e      configure -state disabled
			$vframe.6.1.rdb1 configure -state disabled
			$vframe.6.1.rdb2 configure -state disabled
			$vframe.6.2.e    configure -state disabled
			$vframe.6.2.c    configure -state disabled
		}
	} else {
		catch {
			$vframe.1.e1     configure -state normal
			$vframe.2.e      configure -state normal
			$vframe.3.e      configure -state normal
			$vframe.4.e      configure -state normal
			$vframe.5.e      configure -state normal
			$vframe.6.1.rdb1 configure -state normal
			$vframe.6.1.rdb2 configure -state normal
			$vframe.6.2.e    configure -state normal
			$vframe.6.2.c    configure -state normal
		}
	}
	if {$operation == 4} {
		catch {$vframe.1.e2 configure -state normal}
	} else {
		catch {$vframe.1.e2 configure -state disabled}
	}
	if {[winfo exists $optwin.add]} {
		if {$operation == 1} {
			$optwin.add configure -text "Filter Information"
		} elseif {$operation == 2} {
			$optwin.add configure -text "Filter Addition"
		} elseif {$operation == 3} {
			$optwin.add configure -text "Filter Modification"
		} elseif {$operation == 4} {
			$optwin.add configure -text "Filter Deletion"
		}
		return 0
	}
	if {$BWidget_present == 1} {
		if {$operation == 1} {
			TitleFrame $optwin.add -text "Filter Information"  -side center -relief sunken -bd 2
		} elseif {$operation == 2} {
			TitleFrame $optwin.add -text "Filter Addition"     -side center -relief sunken -bd 2
		} elseif {$operation == 3} {
			TitleFrame $optwin.add -text "Filter Modification" -side center -relief sunken -bd 2
		} elseif {$operation == 4} {
			TitleFrame $optwin.add -text "Filter Deletion"     -side center -relief sunken -bd 2
		}
		pack $optwin.add -side top -anchor nw
		set vframe [$optwin.add getframe]
	} else {
		set vframe [frame $optwin.add]
		pack $optwin.add
	}
	frame $vframe.1
	frame $vframe.2
	frame $vframe.3
	frame $vframe.4
	frame $vframe.5
	frame $vframe.6 -relief ridge -bd 2
	pack $vframe.1 $vframe.2 $vframe.3 $vframe.4 $vframe.5 -side top -anchor nw
	pack $vframe.6 -side top -anchor nw -expand 1 -fill x

	label $vframe.1.l1 -text "FilterName" -width 10
	entry $vframe.1.e1 -textvariable t_filtername -relief sunken -bd 2 -width 20 -state disabled \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	pack $vframe.1.l1 $vframe.1.e1 -side left
	label $vframe.1.l2 -text "FilterNo" -width 10
	if {$BWidget_present == 1} {
		SpinBox $vframe.1.e2 -relief sunken -textvariable t_filterno -width 5 -range {0 10000 1} -state disabled \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $vframe.1.e2 -textvariable t_filterno -relief sunken -bd 2 -width 5 -state disabled \
			-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $vframe.1.l2 $vframe.1.e2 -side left
	set t_filterno ""

	label $vframe.2.l -text "Header" -width 10
	if {$BWidget_present == 1} {
		ComboBox $vframe.2.e \
			-textvariable t_header \
			-editable false \
			-modifycmd {selectHeader $vframe.2.e} \
			-width 20 \
			-state disabled \
			-borderwidth 2 \
			-values $header_list
	} else {
		combobox $vframe.2.e \
			-textvariable t_header \
			-editable false \
			-command {selectHeader $vframe.2.e} \
			-width 25 \
			-state disabled \
			-borderwidth 2
		foreach line $header_list {
			$vframe.2.e list insert end $line
		}
	}
	pack $vframe.2.l $vframe.2.e -side left

	label $vframe.3.l -text "Comparision" -width 10
	if {$BWidget_present == 1} {
		ComboBox $vframe.3.e \
			-textvariable t_comparision \
			-editable false \
			-modifycmd {selectComparision $vframe.3.e} \
			-width 20 \
			-state disabled \
			-borderwidth 2 \
			-values $filter_comparision_list
	} else {
		combobox $vframe.3.e \
			-textvariable t_comparision \
			-editable false \
			-command {selectComparision $vframe.3.e} \
			-width 25 \
			-state disabled \
			-borderwidth 2
		foreach line $filter_comparision_list {
			$vframe.3.e list insert end $line
		}
	}
	pack $vframe.3.l $vframe.3.e -side left

	label $vframe.4.l -text "Keyword" -width 10
	entry $vframe.4.e -textvariable t_keyword -relief sunken -bd 2 -width 20 -state disabled
	pack $vframe.4.l $vframe.4.e -side left

	label $vframe.5.l -text "Destination" -width 10
	entry $vframe.5.e -textvariable t_destination -relief sunken -bd 2 -width 20 -state disabled
	pack $vframe.5.l $vframe.5.e -side left

	label $vframe.6.label -text "Forwarding" -width 20
	pack $vframe.6.label -anchor nw
	frame $vframe.6.1
	frame $vframe.6.2
	pack $vframe.6.1 -side top -anchor nw
	pack $vframe.6.2 -side top -anchor nw -expand 1 -fill x
	radiobutton $vframe.6.1.rdb1 -text "Email"   -variable t_ftype -relief flat -value 0 -width 8 -indicatoron 1 -state disabled
	radiobutton $vframe.6.1.rdb2 -text "Program" -variable t_ftype -relief flat -value 1 -width 8 -indicatoron 1 -state disabled
	$vframe.6.1.rdb1 select
	pack $vframe.6.1.rdb1 $vframe.6.1.rdb2 -side left -expand 1 -fill x

	entry $vframe.6.2.e -textvariable t_forward -relief sunken -bd 2 -width 20 -state disabled
	checkbutton $vframe.6.2.c -text "Bounce" -variable t_bounce -state disabled
	balloonHelp $vframe.6.2.c "Bounce emails back to sender"
	pack $vframe.6.2.e -side left -expand 1 -fill x
	pack $vframe.6.2.c -side left
}

proc setmdahost {win server} {
	global mdahost
	
	set mdahost $server
}

proc get_smtp {dbwin server} {
	global Domain prgtext
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	if {[string length $Domain] == 0} {
		msg_dialog .d {SMTP} "Domain should be specified for SMTP Routes" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 0
	}
	.statusBar.lab configure -text "SMTP"
	if {$server != ""} {
		set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vsmtp -s $Domain\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vsmtp -s $Domain\""
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {vsmtp Command Failed} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$dbwin delete 0 end
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string index $line 0] == "S"} {
			continue
		}
		set port [lindex $line 3]
		set srcip [lindex $line 0]
		set dstip [lindex $line 1]
		$dbwin insert end [list $port $srcip $dstip]
	}
	catch {$dwin.log yview moveto 1}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		catch {$dwin.log insert end "$result  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string compare $result "child process exited abnormally"] != 0} {
			msg_dialog .d {vsmtp Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc showmenuSmtp {dbwin line server x y rootx rooty} {
	global mode w
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set port    -1
	set srchost "0.0.0.0"
	set dsthost "0.0.0.0"
	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    Port" \
		-command "set mode add;getSmtpInput $dbwin $port $srchost $dsthost $server $x $y"
	set count [llength $line]
	if {$count > 0} {
		set port     [lindex $line 0]
		set srchost  [lindex $line 1]
		set dsthost  [lindex $line 2]
		.pm1 add command -label "Modify Port" \
			-command "set mode mod;getSmtpInput $dbwin $port $srchost $dsthost $server $x $y"
		.pm1 add command -label "Delete Port" \
			-command "set mode del;run_smtp     $dbwin $port $srchost $dsthost $server"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getSmtpInput {dbwin port srchost dsthost server x y} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global new_port mode src_host dst_host w1

	catch {destroy .f1}
	set w1 $dbwin
	set new_port ""
	set src_host ""
	set dst_host ""
	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		if {[string compare $mode "mod"] == 0} {
			set new_port $port
		}
		set base .f1
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
		wm focusmodel $base passive
		wm geometry $base +${x}+${y}
		wm geometry $base 250x120
		wm maxsize $base 300 150
		wm minsize $base 1 1
		wm overrideredirect $base 1
		wm resizable $base 1 1
		wm title $base "Indium - New Port Entry"
		grab .f1
		frame .f1.1
		frame .f1.2
		frame .f1.3
		frame .f1.4
		pack .f1.1 .f1.2 .f1.3 .f1.4 -side top

		label .f1.1.l -text "SMTP Port" -relief ridge -bd 2 -width 10
		if {$BWidget_present == 1} {
			SpinBox .f1.1.e -relief sunken -textvariable new_port \
				-width 5 -range {25 65534 1} \
				-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
		} else {
			entry .f1.1.e -relief sunken -textvariable new_port -bd 2 \
				-width 20 -vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
		}
		focus .f1.1.e
		pack .f1.1.l .f1.1.e -side left

		if {[string compare $mode "add"] == 0} {
			label .f1.2.l -text "Src Host" -relief ridge -bd 2 -width 10
			entry .f1.2.e -relief sunken -textvariable src_host -bd 2 -width 20 \
				-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell
			pack .f1.2.l .f1.2.e -side left

			label .f1.3.l -text "Dst Host" -relief ridge -bd 2 -width 10
			entry .f1.3.e -relief sunken -textvariable dst_host -bd 2 -width 20 \
				-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell
			pack .f1.3.l .f1.3.e -side left
		} 
		button .f1.4.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "run_smtp $w1 $port $srchost $dsthost $server"
		button .f1.4.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack .f1.4.b1 .f1.4.b2 -side left
	}
}

proc run_smtp {dbwin port srchost dsthost server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global new_port mode src_host dst_host

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string length $port] == 0} {
		msg_dialog .d {SMTP} {SMTP Port Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $srchost] == 0} {
		msg_dialog .d {SMTP} {Source IP Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $dsthost] == 0} {
		msg_dialog .d {SMTP} {Destination IP Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $server] == 0} {
		msg_dialog .d {SMTP} {Server IP Address Not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		set smtpcmd "/usr/bin/vsmtp -i $new_port -m $src_host $dst_host@$domain"
	} elseif {[string compare $mode "mod"] == 0} {
		set smtpcmd "/usr/bin/vsmtp -u $new_port -m $srchost $dsthost@$domain"
	} else {
		set msg "You are About to Delete SMTP Route for Domain $domain from $srchost to $dsthost. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set smtpcmd "/usr/bin/vsmtp -d -m $srchost $dsthost@$domain"
	}
	if {$server != ""} {
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$smtpcmd\""
	} else {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$smtpcmd\""
	}
	runCommand $cmd
	if {$returnstatus == 0} {
		get_smtp $dbwin $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "port $new_port added"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "port $port modified to $new_port"
		} else {
			.statusBar.lab configure -text "port $port deleted"
		}
	} else {
		msg_dialog .d "$dsthost@$domain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc get_hostid {dbwin server} {
	global prgtext Domain
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	.statusBar.lab configure -text "HOSTID"
	if {[string length $server] > 0} {
		set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vhostid -s\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vhostid -s\""
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {Hostid} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	$dbwin delete 0 end
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line  \n"}
		if {[string index $line 0] == "H"} {
			continue
		}
		set hostid [lindex $line 0]
		set ipaddr [lindex $line 1]
		$dbwin insert end [list $hostid $ipaddr]
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		catch {$dwin.log insert end "$result  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string compare $result "child process exited abnormally"] != 0} {
			msg_dialog .d {vhostid Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc showmenuHostid {dbwin line server x y rootx rooty} {
	global mode w
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set hostid "0x0"
	set ipaddr "0.0.0.0"
	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    Host" \
		-command "set mode add;getHostidInput $dbwin $hostid $ipaddr $server $x $y"
	set count [llength $line]
	if {$count > 0} {
		set hostid  [lindex $line 0]
		set ipaddr  [lindex $line 1]
		.pm1 add command -label "Modify Host" \
			-command "set mode mod;getHostidInput $dbwin $hostid $ipaddr $server $x $y"
		.pm1 add command -label "Delete Host" \
			-command "set mode del;run_hostid     $dbwin $hostid $ipaddr $server"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getHostidInput {dbwin hostid ipaddr server x y} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global new_hostid new_ipaddr mode w1

	catch {destroy .f1}
	set w1 $dbwin
	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		set base .f1
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
		wm focusmodel $base passive
		wm geometry $base +${x}+${y}
		wm geometry $base 250x100
		wm maxsize $base 300 150
		wm minsize $base 1 1
		wm overrideredirect $base 1
		wm resizable $base 1 1
		wm title $base "Indium - New Hostid Entry"
		grab .f1
		frame .f1.1
		frame .f1.2
		frame .f1.3
		pack .f1.1 .f1.2 .f1.3 -side top
		if {[string compare $mode "add"] == 0} {
			set new_hostid ""
			set new_ipaddr ""
			label .f1.1.l -text "New Hostid" -relief ridge -bd 2 -width 10
			entry .f1.1.e -relief sunken -textvariable new_hostid -bd 2 -width 20 \
				-vcmd {regexp {^[A-Za-z0-9]*$} %P} -validate key -invcmd bell
			focus .f1.1.e
			pack .f1.1.l .f1.1.e -side left
		} else {
			set new_hostid $hostid
			set new_ipaddr $ipaddr
		}
		label .f1.2.l -text "IP Address" -relief ridge -bd 2 -width 10
		entry .f1.2.e -relief sunken -textvariable new_ipaddr -bd 2 -width 20 \
			-vcmd {regexp {^[0-9.]*$} %P} -validate key -invcmd bell
		pack .f1.2.l .f1.2.e -side left
		button .f1.3.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command {run_hostid $w1 $new_hostid $new_ipaddr $server}
		button .f1.3.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack .f1.3.b1 .f1.3.b2 -side left
	}
}

proc run_hostid {dbwin hostid ipaddr server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string length $hostid] == 0} {
		msg_dialog .d {HOSTID} {Host ID Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $ipaddr] == 0} {
		msg_dialog .d {HOSTID} {IP Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $server] == 0} {
		msg_dialog .d {SMTP} {Server IP Address Not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		set hostidcmd "vhostid -i $ipaddr $hostid"
	} elseif {[string compare $mode "mod"] == 0} {
		set hostidcmd "vhostid -u $ipaddr $hostid"
	} else {
		set msg "You are About to Delete hostid $hostid for IP $ipaddr. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set hostidcmd "vhostid -d $hostid"
	}
	if {$server != ""} {
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$hostidcmd\""
	} else {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$hostidcmd\""
	}
	runCommand $cmd
	if {$returnstatus == 0} {
		get_hostid $dbwin $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "Host ID $hostid added"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "Host ID $hostid IP modified to $ipaddr"
		} else {
			.statusBar.lab configure -text "Host ID $hostid deleted"
		}
	} else {
		msg_dialog .d "$hostid@$ipaddr" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc get_dbinfo {dbwin} {
	global Domain prgtext mcdfile Checkbutton
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	.statusBar.lab configure -text "DBINFO"
	if {[string length $Domain]} {
		set cmd "| /usr/bin/dbinfo -s -l -d $Domain $mcdfile 2>/dev/null"
	} else {
		set cmd "| /usr/bin/dbinfo -s -l $mcdfile 2>/dev/null"
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {dbinfo} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$dbwin delete 0 end
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line  \n"}
		set filename  [lindex $line 0]
		set tmpDomain [lindex $line 1]
		set clustered [lindex $line 2]
		set mserver   [lindex $line 3]
		set mdahost   [lindex $line 4]
		set port      [lindex $line 5]
		set dbname    [lindex $line 6]
		set user      [lindex $line 7]
		set passwd    [lindex $line 8]
		if {$clustered == 1} {
			catch {$Checkbutton select}
		} else {
			catch {$Checkbutton deselect}
		}
		$dbwin insert end [list $tmpDomain $mdahost $mserver $port $dbname $user $passwd]
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		catch {$dwin.log insert end "$result  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string compare $result "child process exited abnormally"] != 0} {
			msg_dialog .d {dbinfo Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc showmenuDbinfo {dbwin mcdfile line x y rootx rooty} {
	global mode Domain clustered w
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set tmpDomain "----"
	set mserver "0.0.0.0"
	set mdahost "0.0.0.0"
	set port    -1
	set dbname "----"
	set user   "----"
	set passwd "----"

	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    Server" \
		-command "set mode add;getDbinfoInput $dbwin $tmpDomain $mcdfile $mserver $mdahost $port $dbname $user $passwd -1 $x $y"
	set count [llength $line]
	if {$count > 0} {
		set tmpDomain [lindex $line 0]
		set mdahost   [lindex $line 1]
		set mserver   [lindex $line 2]
		set port      [lindex $line 3]
		set dbname    [lindex $line 4]
		set user      [lindex $line 5]
		set passwd    [lindex $line 6]
		.pm1 add command -label "Modify Server" \
			-command "set mode mod;getDbinfoInput $dbwin $tmpDomain $mcdfile $mserver $mdahost $port $dbname $user $passwd $clustered $x $y"
		.pm1 add command -label "Delete Server" \
			-command "set mode del;run_dbinfo $dbwin $tmpDomain $mcdfile $mserver $mdahost $port $dbname $user $passwd $clustered"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getDbinfoInput {dbwin Domain mcdfile mserver mdahost port dbname user passwd clustered x y} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode
	global mserver_tmp
	global mdahost_tmp
	global mport
	global dbname_tmp
	global muser
	global mpasswd
	global mclustered w1

	catch {destroy .f1}
	set base .f1
	set w1 $dbwin
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
	wm focusmodel $base passive
	wm geometry $base +${x}+${y}
	wm geometry $base 293x210
	wm maxsize $base 300 250
	wm minsize $base 1 1
	wm overrideredirect $base 0
	wm resizable $base 1 1
	wm title $base "Indium - New MCD Entry"
	grab .f1

	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		frame .f1.1
		frame .f1.2
		frame .f1.3
		frame .f1.4
		frame .f1.5
		frame .f1.6
		frame .f1.7
		frame .f1.8
		if {[string compare $mode "add"] == 0} {
			set mserver_tmp ""
			set mda_host ""
			set mport 3306
			set dbname_tmp "indimail"
			set muser "indimail"
			set mpasswd ""
		} else {
			set mserver_tmp $mserver
			set mdahost_tmp $mdahost
			set mport $port
			set dbname_tmp $dbname
			set muser $user
			set mpasswd $passwd
			set mclustered $clustered
		}
		pack .f1.1 .f1.2 .f1.3 .f1.4 .f1.5 .f1.6 .f1.7 .f1.8 -side top -anchor nw
		label .f1.1.l -text "MySQL Server"  -relief ridge  -bd 2 -width 15
		entry .f1.1.e -textvariable mserver_tmp -relief sunken -bd 2 -width 20 \
			-vcmd {regexp {^[A-Za-z0-9.]*$} %P} -validate key -invcmd bell
		focus .f1.1.e
		pack .f1.1.l .f1.1.e -side left
		if {[string compare $mode "add"] == 0} {

			label .f1.2.l -text "MDA Host"      -relief ridge  -bd 2 -width 15
			entry .f1.2.e -textvariable mdahost_tmp -relief sunken -bd 2 -width 20
			pack .f1.2.l .f1.2.e -side left
		}

		label .f1.3.l -text "MySQL Port" -relief ridge  -bd 2 -width 15
		if {$BWidget_present == 1} {
			SpinBox .f1.3.e -relief sunken -textvariable mport \
				-width 5 -range {3306 65534 1} \
				-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
		} else {
			entry .f1.3.e -textvariable mport -relief sunken -bd 2 -width 20 \
				-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
		}
		pack .f1.3.l .f1.3.e -side left

		label .f1.4.l -text "MySQL DBname" -relief ridge  -bd 2 -width 15
		entry .f1.4.e -textvariable dbname_tmp -relief sunken -bd 2 -width 20 \
			-vcmd {expr {[string length %P]<=16}} -validate key -invcmd bell
		pack .f1.4.l .f1.4.e -side left

		label .f1.5.l -text "MySQL User" -relief ridge  -bd 2 -width 15
		entry .f1.5.e -textvariable muser -relief sunken -bd 2 -width 20 \
			-vcmd {expr {[string length %P]<=16}} -validate key -invcmd bell
		pack .f1.5.l .f1.5.e -side left

		label .f1.6.l -text "MySQL Passwd" -relief ridge  -bd 2 -width 15
		entry .f1.6.e -textvariable mpasswd -relief sunken -bd 2 -width 20 -show * \
			-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell
		pack .f1.6.l .f1.6.e -side left

		checkbutton .f1.7.c -text "Clustered" -variable mclustered
		balloonHelp .f1.7.c "Enable clustering of domain"
		pack .f1.7.c -side left

		button .f1.8.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command {run_dbinfo  $w1 $Domain $mcdfile $mserver_tmp $mdahost_tmp $mport $dbname_tmp $muser $mpasswd $mclustered}
		button .f1.8.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack .f1.8.b1 .f1.8.b2 -side left
	}
}

proc run_dbinfo {dbwin Domain mcdfile mserver mdahost port dbname user passwd clustered} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string length $Domain] == 0} {
		msg_dialog .d {DBINFO} {Domain Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mcdfile] == 0} {
		msg_dialog .d {DBINFO} {MCD Filename Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mserver] == 0} {
		msg_dialog .d {DBINFO} {MySQL Server IP Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mdahost] == 0} {
		msg_dialog .d {DBINFO} {MDA Host Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $port] == 0} {
		msg_dialog .d {DBINFO} {MySQL Port Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $dbname] == 0} {
		msg_dialog .d {DBINFO} {MySQL Database Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $user] == 0} {
		msg_dialog .d {DBINFO} {MySQL User Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $passwd] == 0} {
		msg_dialog .d {DBINFO} {MySQL Password Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		if {$clustered == 1} {
			set opt "-c"
		} else {
			set opt ""
		}
		set dbinfocmd "/usr/bin/dbinfo -i -S $mserver -p $port -D $dbname -U $user -P $passwd $opt -d $Domain -m $mdahost $mcdfile"
	} elseif {[string compare $mode "mod"] == 0} {
		if {$clustered == 1} {
			set opt "-c"
		} else {
			set opt ""
		}
		set dbinfocmd "/usr/bin/dbinfo -u -S $mserver -p $port -D $dbname -U $user -P $passwd $opt -d $Domain -m $mdahost $mcdfile"
	} else {
		set msg "You are About to Delete Database info $mcdfile for $mdahost Domain $Domain. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set dbinfocmd "/usr/bin/dbinfo -r -d $Domain -m $mdahost $mcdfile"
	}
	set cmd "exec $dbinfocmd"
	set returnstatus [catch {eval $cmd} result]
	if {$returnstatus == 0} {
		initdomain
		get_dbinfo $dbwin
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "MySQL Server $mserver added"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "MySQL Server $mserver"
		} else {
			.statusBar.lab configure -text "MySQL Server $mserver deleted"
		}
	} else {
		msg_dialog .d "$mserver" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc showmenuFstab {dbwin line server x y rootx rooty} {
	global mode mdahost w
	variable filesystem
	variable host
	variable status
	variable curusers
	variable maxusers
	variable cursize
	variable maxsize
	variable load

	if [winfo exists .pm1] {
		destroy .pm1
	}
	set filesystem "/"
	set host "0.0.0.0"
	set status "ONLINE"
	set maxusers -1
	set maxsize -1
	set load -1
	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    Filesystem" \
		-command "set mode add;getFstabInput $dbwin $filesystem $host $status $maxusers $maxsize $server $x $y"
	set count [llength $line]
	if {$count > 0} {
		set filesystem [lindex $line 0]
		set host       [lindex $line 1]
		set status     [lindex $line 2]
		set maxusers   [lindex $line 3]
		set curusers   [lindex $line 4]
		set maxsize    [expr [lindex $line 5] * 1024]
		set cursize    [expr [lindex $line 6] * 1024]
		set load       [lindex $line 7]
		.pm1 add command -label "Modify Filesystem" \
			-command "set mode mod;getFstabInput $dbwin $filesystem $host $status $maxusers $maxsize $server $x $y"
		.pm1 add command -label "Delete Filesystem" \
			-command "set mode del;run_fstab     $dbwin $filesystem $host $status $maxusers $maxsize $server"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getFstabInput {dbwin filesystem host status maxusers maxsize server x y} {
	global mdahost
	source /usr/share/indimail/indium/scripts/global.tcl
	variable filesystem_tmp
	variable mdahost_tmp
	variable maxusers_tmp
	variable maxsize_tmp
	variable status_tmp
	global mode w1

	catch {destroy .f1}
	set base .f1
	set w1 $dbwin
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
	wm focusmodel $base passive
	wm geometry $base +${x}+${y}
	wm geometry $base 293x160
	wm maxsize $base 300 250
	wm minsize $base 1 1
	wm overrideredirect $base 1
	wm resizable $base 1 1
	wm title $base "Indium - New FSTAB Entry"
	grab .f1

	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		frame .f1.1
		frame .f1.2
		frame .f1.3
		frame .f1.4
		frame .f1.5
		frame .f1.6
		if {[string compare $mode "add"] == 0} {
			set filesystem_tmp ""
			set mdahost_tmp $mdahost
			set maxusers_tmp ""
			set maxsize_tmp ""
			set status_tmp 1
		} else {
			set filesystem_tmp $filesystem
			set mdahost_tmp $host
			set maxusers_tmp $maxusers
			set maxsize_tmp $maxsize
			if {[string compare $status "ONLINE"] == 0} {
				set status_tmp 1
			} else {
				set status_tmp 0
			}
		}
		pack .f1.1 .f1.2 .f1.3 .f1.4 .f1.5 .f1.6 -side top -anchor nw
		if {[string compare $mode "add"] == 0} {
			label .f1.1.l -text "Filesystem"  -relief ridge  -bd 2 -width 15
			entry .f1.1.e -textvariable filesystem_tmp -relief sunken -bd 2 -width 20
			focus .f1.1.e
			pack .f1.1.l .f1.1.e -side left
			label .f1.2.l -text "MDA Host"    -relief ridge  -bd 2 -width 15
			entry .f1.2.e -textvariable mdahost_tmp -relief sunken -bd 2 -width 20
			pack .f1.2.l .f1.2.e -side left
		}

		label .f1.3.l -text "Max Users" -relief ridge  -bd 2 -width 15
		entry .f1.3.e -textvariable maxusers_tmp -relief sunken -bd 2 -width 20 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
		pack .f1.3.l .f1.3.e -side left

		label .f1.4.l -text "Max Quota" -relief ridge  -bd 2 -width 15
		entry .f1.4.e -textvariable maxsize_tmp -relief sunken -bd 2 -width 20 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
		pack .f1.4.l .f1.4.e -side left

		checkbutton .f1.5.c -text "Online" -variable status_tmp
		balloonHelp .f1.5.c "Enable filesystem for creation of User's Maildir"
		pack .f1.5.c -side left
		if {[string compare $mode "add"] == 0} {
			.f1.5.c select
		}

		button .f1.6.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command {run_fstab  $w1 $filesystem_tmp $mdahost_tmp $maxusers_tmp $maxsize_tmp $status_tmp $server}
		button .f1.6.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack .f1.6.b1 .f1.6.b2 -side left
	}
}

proc run_fstab {dbwin filesystem mdahost maxusers maxsize status server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string length $filesystem] == 0} {
		msg_dialog .d {FSTAB} {Filesystem Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $mdahost] == 0} {
		msg_dialog .d {FSTAB} {MDA Host Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $maxusers] == 0} {
		msg_dialog .d {FSTAB} {Maximum No of Users supported on this filesystem not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $maxsize] == 0} {
		msg_dialog .d {FSTAB} {Maximum Size to be allocated for mail not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $server] == 0} {
		msg_dialog .d {FSTAB} {Server IP Address Not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		if {$status == 1} {
			set opt "-o 1"
		} else {
			set opt "-o 0"
		}
		set fstabcmd "/usr/sbin/vfstab -i $opt -n $maxusers -q $maxsize -m $mdahost $filesystem"
	} elseif {[string compare $mode "mod"] == 0} {
		if {$status == 1} {
			set opt "-o 1"
		} else {
			set opt "-o 0"
		}
		set fstabcmd "/usr/sbin/vfstab -u $opt -n $maxusers -q $maxsize -m $mdahost $filesystem"
	} else {
		set msg "You are About to Delete filesystem $filesystem for $mdahost. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set fstabcmd "/usr/sbin/vfstab -d -m $mdahost $filesystem"
	}
	if {$server != ""} {
		set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$fstabcmd\""
	} else {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$fstabcmd\""
	}
	runCommand $cmd
	if {$returnstatus == 0} {
		get_fstab $dbwin $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "Filesystem $filesystem for $mdahost added"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "Filesystem $filesystem for $mdahost modified"
		} else {
			.statusBar.lab configure -text "Filesystem $filesystem for $mdahost deleted"
		}
	} else {
		msg_dialog .d "$filesystem" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc get_fstab {dbwin server} {
	global Domain prgtext mdahost
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	
	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	.statusBar.lab configure -text "FSTAB"
	if {[string length $server] > 0} {
		if {[string length $mdahost] > 0} {
			set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vfstab -s -m $mdahost\""
		} else {
			set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vfstab -s\""
		}
	} else {
		if {[string length $mdahost] > 0} {
			set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vfstab -s -m $mdahost\""
		} else {
			set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vfstab -s\""
		}
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {fstab} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$dbwin delete 0 end
	set row_count 0
	while {[gets $f line] >= 0} {
		if {[string index $line 0] == "F"} {
			continue
		}
		incr row_count
		catch {$dwin.log insert end "$line  \n"}
		set filesystem [lindex $line 0]
		set host       [lindex $line 1]
		set status     [lindex $line 2]
		set maxusers   [lindex $line 3]
		set curusers   [lindex $line 4]
		set maxsize    [lindex $line 5]
		set cursize    [lindex $line 7]
		set load       [lindex $line 9]
		$dbwin insert end [list $filesystem $host $status $maxusers $curusers $maxsize $cursize $load]
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		if {[string compare $result "child process exited abnormally"] != 0} {
			catch {$dwin.log insert end "$result  \n"}
			catch {$dwin.log yview moveto 1}
			msg_dialog .d {vfstab Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc get_ipmap {dbwin server} {
	global prgtext Domain
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	.statusBar.lab configure -text "IPMAP"
	if {[string length $server] > 0} {
		set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vipmap -s $Domain\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vipmap -s $Domain\""
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {ipmap} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	$dbwin delete 0 end
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line  \n"}
		if {[string index $line 0] == "H"} {
			continue
		}
		set ipaddr  [lindex $line 0]
		set idomain [lindex $line 1]
		$dbwin insert end [list $ipaddr $idomain]
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		catch {$dwin.log insert end "$result  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string compare $result "child process exited abnormally"] != 0} {
			msg_dialog .d {vipmap Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc showmenuIpmap {dbwin line server x y rootx rooty} {
	global mode w
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set ipaddr "0.0.0.0"
	set idomain "0.0.0.0"
	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    MAP" \
		-command "set mode add;getIpmapInput $dbwin $ipaddr $idomain $server $x $y"
	set count [llength $line]
	if {$count > 0} {
		set ipaddr   [lindex $line 0]
		set idomain  [lindex $line 1]
		.pm1 add command -label "Modify MAP" \
			-command "set mode mod;getIpmapInput $dbwin $ipaddr $idomain $server $x $y"
		.pm1 add command -label "Delete MAP" \
			-command "set mode del;run_ipmap $dbwin $ipaddr $idomain $server"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getIpmapInput {dbwin ipaddr idomain server x y} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode w1
	variable new_ipaddr
	variable new_domain

	catch {destroy .f1}
	set w1 $dbwin
	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		set base .f1
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
		wm focusmodel $base passive
		wm geometry $base +${x}+${y}
		wm geometry $base 250x100
		wm maxsize $base 300 150
		wm minsize $base 1 1
		wm overrideredirect $base 1
		wm resizable $base 1 1
		wm title $base "Indium - New IPMAP Entry"
		grab .f1
		frame .f1.1
		frame .f1.2
		frame .f1.3
		pack .f1.1 .f1.2 .f1.3 -side top
		if {[string compare $mode "add"] == 0} {
			set new_ipaddr ""
			set new_domain ""
			label .f1.1.l -text "IP Address" -relief ridge -bd 2 -width 10
			entry .f1.1.e -relief sunken -textvariable new_ipaddr -bd 2 -width 20 \
				-vcmd {regexp {^[0-9.]*$} %P} -validate key -invcmd bell
			focus .f1.1.e
			pack .f1.1.l .f1.1.e -side left
		} else {
			set new_ipaddr $ipaddr
			set new_domain $idomain
		}
		label .f1.2.l -text "Domain"     -relief ridge -bd 2 -width 10
		entry .f1.2.e -relief sunken -textvariable new_domain -bd 2 -width 20 \
			-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
		pack .f1.2.l .f1.2.e -side left
		button .f1.3.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command {run_ipmap $w1 $new_ipaddr $new_domain $server}
		button .f1.3.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack .f1.3.b1 .f1.3.b2 -side left
	}
}

proc run_ipmap {dbwin ipaddr idomain server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {[string length $ipaddr] == 0} {
		msg_dialog .d {IPMAP} {IP Address Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain] == 0} {
		msg_dialog .d {IPMAP} {Domain Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $server] == 0} {
		msg_dialog .d {IPMAP} {Server IP Address Not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		set vipmapcmd "/usr/bin/vipmap -i $ipaddr $idomain"
	} elseif {[string compare $mode "mod"] == 0} {
		set vipmapcmd "/usr/bin/vipmap -u $ipaddr $idomain"
	} else {
		set msg "You are About to Delete IPMAP for $ipaddr. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set vipmapcmd "/usr/bin/vipmap -d $ipaddr $idomain"
	}
	if {$server != ""} {
		set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$vipmapcmd\""
	} else {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$vipmapcmd\""
	}
	runCommand $cmd
	if {$returnstatus == 0} {
		get_ipmap $dbwin $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "IP MAP for $ipaddr added ($idomain)"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "IP MAP for $ipaddr modified to $idomain"
		} else {
			.statusBar.lab configure -text "IP MAP for $ipaddr deleted"
		}
	} else {
		msg_dialog .d "$ipaddr@$idomain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc get_atrnmap {dbwin server} {
	global prgtext Domain
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	.statusBar.lab configure -text "ATRNMAP"
	if {[string length $server] > 0} {
		set cmd "| /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vatrn -s $Domain\""
	} else {
		set cmd "| /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vatrn -s $Domain\""
	}
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f]} {
		catch {destroy .progress}
		msg_dialog .d {ipmap} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$BWidget_present == 1} {
		catch {destroy .progress}
	}
	$dbwin delete 0 end
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line  \n"}
		if {[string index $line 0] == "H"} {
			continue
		}
		set username   [lindex $line 0]
		set domain     [lindex $line 1]
		set atrndomain [lindex $line 2]
		$dbwin insert end [list $username $domain $atrndomain]
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		$dbwin delete 0 end
		catch {$dwin.log insert end "$result  \n"}
		catch {$dwin.log yview moveto 1}
		if {[string compare $result "child process exited abnormally"] != 0} {
			msg_dialog .d {vatrn Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			.statusBar.lab configure -text "No rows selected"
		}
		return 1
	}
}

proc showmenuAtrnMap {dbwin1 line server x1 y1 rootx1 rooty1} {
	global mode w
	variable x
	variable y
	variable rootx
	variable rooty
	variable dbwin
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set x $x1
	set y $y1
	set rootx $rootx1
	set rooty $rooty1
	set dbwin $dbwin1
	set username ""
	set domain ""
	set atrndomain ""
	menu .pm1 -tearoff 0 -borderwidth 1
	.pm1 add command -label "Add    ATRN Map" -command {set mode add;getAtrnInput $dbwin "" "" "" $server $x $y}
	set count [llength $line]
	if {$count > 0} {
		set username   [lindex $line 0]
		set domain     [lindex $line 1]
		set atrndomain [lindex $line 2]
		.pm1 add command -label "Modify MAP" \
			-command "set mode mod;getAtrnInput $dbwin $username $domain $atrndomain $server $x $y"
		.pm1 add command -label "Delete MAP" \
			-command "set mode del;run_atrn  $dbwin $username $domain $atrndomain $server"
	}
	.pm1 add command -label "Cancel     " -command "return 0"
	showContextMenu1 \
		$dbwin \
		$x $y $rootx $rooty \
		.pm1
	.pm1 post [winfo pointerx $w] [winfo pointery $w]
}

proc getAtrnInput {dbwin username domain atrndomain server x y} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode local_domain_list newatrndomain
	variable t_username
	variable vframe

	catch {destroy .f1}
	if {[string compare $mode "add"] == 0 || [string compare $mode "mod"] == 0} {
		set base .f1
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief flat
		wm focusmodel $base passive
		wm geometry $base +${x}+${y}
		wm geometry $base 450x250
		wm maxsize $base 450 200
		wm minsize $base 1 1
		wm overrideredirect $base 1
		wm resizable $base 1 1
		wm title $base "Indium - ATRN Map"
		grab .f1
		TitleFrame .f1.f -text "ATRN Maps"     -side center -relief sunken -bd 2
		pack .f1.f -side top -anchor nw -expand 1 -fill both
		set vframe [.f1.f getframe]

		frame $vframe.1
		frame $vframe.2
		frame $vframe.3
		if {$mode == "mod"} {
			frame $vframe.4
		}
		frame $vframe.5
		if {$mode == "mod"} {
			pack $vframe.1 $vframe.2 $vframe.3 $vframe.4 $vframe.5 -side top -anchor nw
		} else {
			pack $vframe.1 $vframe.2 $vframe.3 $vframe.5 -side top -anchor nw
		}

		if {$mode == "mod"} {
			set t_username $username
		}
		label $vframe.1.l -text "Domain" -bd 2 -width 14
		combobox $vframe.1.e \
			-width 25 \
			-textvariable domain \
			-editable false \
			-borderwidth 2 \
			-value $domain \
			-command "setServerVal $vframe.3.s"
		foreach line $domain_list {
			$vframe.1.e list insert end $line
		}
		pack $vframe.1.l $vframe.1.e -side left -anchor nw

		label $vframe.2.l -text "Username" -bd 2 -width 14
		hugecombo  $vframe.2.e -relief sunken -textvariable t_username -bd 2 -width 25 \
			-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell -listvariable ::userList2
		button $vframe.2.b1 \
			-command {list_user2 $domain $server $inactiveFlag;$vframe.2.e list open}
		balloonHelp $vframe.2.b1 "List Users on System"
		$vframe.2.b1 config -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBPz+/MTCxISChMT+/ATCxASChFxaXAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARaEMg5gw00yyDGIAR1YUDggeFWFIZhnSBZrsZxdIOFEGTA2oeBAHeyuGwvzxBlYdUOLROMFzDQntJPrNoqAKUBaqnV+k57ZORruykHDj2LqIzUVKp1u0iuB/gjACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
		focus $vframe.2.e
		pack $vframe.2.l $vframe.2.e $vframe.2.b1 -side left -anchor nw

		label $vframe.3.l -text "ATRN Domain" -bd 2 -width 14
		combobox $vframe.3.e \
			-textvariable atrndomain \
			-editable true \
			-borderwidth 2 \
			-command "setServerVal $vframe.3.s"
		foreach line $local_domain_list {
			$vframe.3.e list insert end $line
		}
		$vframe.3.e select 0
		combobox $vframe.3.s \
			-textvariable server \
			-editable false \
			-width 13 \
			-borderwidth 2 \
			-command "setmdahost"
		pack $vframe.3.l $vframe.3.e $vframe.3.s -side left -anchor nw

		if {$mode == "mod"} {
			label $vframe.4.l -text "New ATRN Domain" -bd 2 -width 14
			ComboBox $vframe.4.e \
				-textvariable newatrndomain \
				-editable true \
				-bd 2 \
				-vcmd {string compare -nocase %P $atrndomain} \
				-validate all -invcmd bell \
				-values $local_domain_list
			pack $vframe.4.l $vframe.4.e -side left -anchor nw
		}

		button $vframe.5.b1 -text Submit -bg orange    -bd 4 -highlightthickness 5 -highlightbackground black \
			-command {run_atrn $dbwin $t_username $domain $atrndomain $server}
		button $vframe.5.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 -highlightbackground black \
			-command "wm withdraw .f1;grab release .f1;return 0"
		pack $vframe.5.b1 $vframe.5.b2 -side left
	}
}

proc run_atrn {dbwin username domain atrndomain server} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global mode newatrndomain

	if {[winfo exists .f1]} {
		grab release .f1
		wm withdraw .f1
	}
	if {$mode == "mod" && $newatrndomain == $atrndomain} {
		msg_dialog .d {ATRN Map} {Old  and New Domains cannot be same} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $username] == 0} {
		msg_dialog .d {ATRN Map} {Username Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain] == 0} {
		msg_dialog .d {ATRN Map} {Domain Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $atrndomain] == 0} {
		msg_dialog .d {ATRN Map} {ATRN Domain Name Required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $server] == 0} {
		msg_dialog .d {ATRN Map} {Server IP Address Not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string compare $mode "add"] == 0} {
		set atrnmapcmd "/usr/bin/vatrn -i $atrndomain $username@$domain"
	} elseif {[string compare $mode "mod"] == 0} {
		set atrnmapcmd "/usr/bin/vatrn -u $atrndomain -i $newatrndomain $username@$domain"
	} else {
		set msg "You are About to Delete ATRN Map for $atrndomain. Click OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return 1
		}
		set atrnmapcmd "/usr/bin/vatrn -d $atrndomain $username@$domain"
	}
	if {$server != ""} {
		set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$atrnmapcmd\""
	} else {
		set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"$atrnmapcmd\""
	}
	runCommand $cmd
	if {$returnstatus == 0} {
		get_atrnmap $dbwin $server
		if {[string compare $mode "add"] == 0} {
			.statusBar.lab configure -text "ATRN MAP for $atrndomain added ($username@$domain)"
		} elseif {[string compare $mode "mod"] == 0} {
			.statusBar.lab configure -text "ATRN MAP for $atrndomain modified to $newatrndomain"
		} else {
			.statusBar.lab configure -text "ATRN MAP for $atrndomain deleted"
		}
	} else {
		msg_dialog .d "$atrndomain" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc selectFilter {w1 args} {
	global header_list filter_comparision_list BWidget_present prgtext
	global vframe
	global t_filterno t_username t_filtername t_keyword t_destination t_forward t_bounce t_ftype
	global t_header t_comparision t_header_no t_comparision_no
	variable cur_sel

	catch {$w1 curselection} cur_sel
	if {[llength $cur_sel] > 1} {
		return
	}
	if {[info exists args] && [string length $args] > 0} {
		set t_filterno    [lindex [$w1 get $args] 0]
		set t_username    [lindex [split [lindex [$w1 get $args] 1] @] 0]
		set t_filtername  [lindex [$w1 get $args] 2]
		set t_header      [lindex [$w1 get $args] 3]
		set t_comparision [lindex [$w1 get $args] 4]
		set t_keyword     [lindex [$w1 get $args] 5]
		set t_destination [lindex [$w1 get $args] 6]
		set bounce_t      [lindex [$w1 get $args] 7]
		if {[string compare $bounce_t "Bounce"] == 0} {
			set t_bounce 1
		} else {
			set t_bounce 0
		}
		set  email_type [string index [lindex [$w1 get $args] 8] 0]
		if {$email_type == "&"} {
			set t_ftype 0
		} elseif {$email_type == "|"} {
			set t_ftype 1
		} else {
			set t_ftype -1
		}
		set t_forward [string range [lindex [$w1 get $args] 8] 1 end]
		set i 0
		foreach line $header_list {
			if {[string compare $line $t_header] == 0} {
				if {$BWidget_present == 1} {
					$vframe.2.e setvalue @$i
				} else {
					$vframe.2.e select $i
				}
				set t_header_no $i
				break
			}
			incr i
		}
		set i 0
		foreach line $filter_comparision_list {
			if {[string compare $line $t_comparision] == 0} {
				if {$BWidget_present == 1} {
					$vframe.3.e setvalue @$i
				} else {
					$vframe.3.e select $i
				}
				set t_comparision_no $i
				break
			}
			incr i
		}
		$w1 selection set $cur_sel
	}
}

proc selectadminUser {w1 args} {
	global t_adminuser
	set mgmt_list ""
	if {[info exists args] && [string length $args] > 0} {
		set mgmt_list [$w1 get $args]
		if {[llength $mgmt_list] > 8} {
			return
		}
		set t_adminuser [lindex $mgmt_list 0]
	}
}

proc selectHeader {w1 args} {
	global t_header_no BWidget_present
	if {$BWidget_present == 1} {
		set t_header_no [$w1 getvalue]
	} else {
		set t_header_no [$w1 curselection]
	}
}

proc selectComparision {w1 args} {
	global t_comparision_no BWidget_present
	if {$BWidget_present == 1} {
		set t_comparision_no [$w1 getvalue]
	} else {
		set t_comparision_no [$w1 curselection]
	}
}

proc run_mgmt {operation dbwin user pass} {
	global BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	global admin_list User Domain
	variable t_server
	
	if {$sqlserver != ""} {
		set t_server $sqlserver
	} else {
		set t_server $mysql_host
	}
	if {$is_distributed($Domain)} {
		if {[file exists $controldir/host.cntrl]} {
			if {[catch {open $controldir/host.cntrl r} f] } {
				msg_dialog .d "$controldir/host.cntrl" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set t_server [read -nonewline $f]
			close $f
		} elseif {[file exists $controldir/host.master]} {
			if {[catch {open $controldir/host.master r} f] } {
				msg_dialog .d "$controldir/host.cntrl" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set t_server [read -nonewline $f]
			close $f
		}
	}
	switch $operation {
		1 {
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[catch {sql selectdb indimail} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			$dbwin delete 0 end
			if {[catch {sql "SELECT user, pass, pw_uid, pw_gid, lastaccess, lastupdate, attempts, status FROM mgmtaccess"} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			sql disconnect
			set admin_list {}
			foreach row $result {
				set user       [lindex $row 0]
				lappend admin_list $user
				set pass       [lindex $row 1]
				set pw_uid     [lindex $row 2]
				set pw_gid     [lindex $row 3]
				set lastaccess [lindex $row 4]
				set lastupdate [lindex $row 5]
				set attempts   [lindex $row 6]
				set status     [lindex $row 7]
				set atime [clock format $lastaccess -format "%d:%m:%Y %H:%M:%S"]
				set mtime [clock format $lastaccess -format "%d:%m:%Y %H:%M:%S"]
				if {$status == 0} {
					$dbwin insert end [list $user $pass $pw_uid $pw_gid $atime $mtime $attempts "Enabled"]
				} else {
					$dbwin insert end [list $user $pass $pw_uid $pw_gid $atime $mtime $attempts "Disabled"]
				}
				catch {$dwin.log insert end "$row\n"}
			}
			if {$BWidget_present == 1} {
				destroy .progress
			}
			catch {$dwin.log yview moveto 1}
		}
		2 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $user] == 0} {
				msg_dialog .d "Ports" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $pass] == 0} {
				msg_dialog .d "Ports" "Password Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			set result ""
			set cmd "exec /usr/sbin/mgmtpass -u $user -p $pass"
			set returnstatus [catch {eval $cmd} result]
			if {$returnstatus != 0} {
				catch {destroy .progress}
				msg_dialog .d "Password Change" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$BWidget_present == 1} {
				destroy .progress
			}
			run_mgmt 1 $dbwin $user $pass
			msg_dialog .d "Ports" "Password Changed for $user" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
		3 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $user] == 0} {
				msg_dialog .d "Ports" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $pass] == 0} {
				msg_dialog .d "Ports" "Password Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			set result ""
			set cmd "exec /usr/sbin/mgmtpass -u $user -a $pass"
			set returnstatus [catch {eval $cmd} result]
			if {$returnstatus != 0} {
				catch {destroy .progress}
				msg_dialog .d "Add $user" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$BWidget_present == 1} {
				destroy .progress
			}
			run_mgmt 1 $dbwin $user $pass
			msg_dialog .d "Ports" "Added user $user" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
		4 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $user] == 0} {
				msg_dialog .d "Ports" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set msg "You are About to Delete Port User $user. Click OK to continue\n"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return 1
			}
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[catch {sql selectdb indimail} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL SelectDb" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			set returnstatus [catch {sql "delete FROM mgmtaccess where user='$user'"} result]
			sql disconnect
			catch {destroy .progress}
			if {$returnstatus != 0} {
				msg_dialog .d "MySQL Query" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			run_mgmt 1 $dbwin $user $pass
			set user ""
			set pass ""
			msg_dialog .d "Ports" "Deleted User $user" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc run_filter {operation dbwin user domain} {
	global BWidget_present prgtext vfilter_disabled global_disabled post_disabled
	source /usr/share/indimail/indium/scripts/global.tcl
	global mdahost
	global header filter_comparision header_list filter_comparision_list
	global t_filterno t_filtername t_header_no t_comparision_no t_keyword t_destination t_forward t_bounce t_ftype
	global vframe t_header t_comparision vfilterFile preFlag postFlag
	variable bvar
	variable t_server

	if {$sqlserver != ""} {
		set t_server $sqlserver
	} else {
		set t_server $mysql_host
	}
	set vfilterFile ""
	set preFlag ""
	set postFlag ""
	if {[string length $user] <= 0} {
		msg_dialog .d {Invalid User} {Username value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[string length $domain] <= 0} {
		msg_dialog .d {Invalid Domain} {Domain value not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[array exists header] == 0} {
		set i 0
		foreach j $header_list {
			set header($i) $j
			incr i
		}
	}
	if {[array exists filter_comparision] == 0} {
		set i 0
		foreach j $filter_comparision_list {
			set filter_comparision($i) $j
			incr i
		}
	}
	switch $operation {
		1 {
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
				destroy .progress
				msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[catch {sql selectdb indimail} result]} {
				destroy .progress
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			$dbwin delete 0 end
			if {[catch {sql "SELECT emailid, filter_no, filter_name, header_name, comparision, keyword, destination, bounce_action FROM vfilter where emailid=\"$user@$domain\""} result]} {
				destroy .progress
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			foreach row $result {
				set tuser       [lindex $row 0]
				set filter_no   [lindex $row 1]
				set filter_name [lindex $row 2]
				set header_no   [lindex $row 3]
				set comparision [lindex $row 4]
				set keyword     [lindex $row 5]
				if {[string index [lindex $row 6] 0] == "."} {
					set destination [string range [lindex $row 6] 1 end]
				} else {
					set destination [string range [lindex $row 6] 0 end]
				}
				set baction     [string index [lindex $row 7] 0]
				if {$baction > 1} {
					set forward [string range [lindex $row 7] 1 end]
				} else {
					set forward ""
				}
				if {$baction == 0 || $baction == 2} {
					$dbwin insert end [list $filter_no $tuser $filter_name $header($header_no) $filter_comparision($comparision) $keyword $destination "Deliver" $forward]
				} else {
					$dbwin insert end [list $filter_no $tuser $filter_name $header($header_no) $filter_comparision($comparision) $keyword $destination "Bounce"  $forward]
				}
				catch {$dwin.log insert end "$row\n"}
			}
			if {[catch {sql "SELECT pw_dir FROM indimail where pw_name=\"$user\" and pw_domain=\"$domain\""} result]} {
				destroy .progress
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			sql disconnect
			if {$result != ""} {
				set vfilterFile "$result/Maildir/vfilter"
				set preFlag "$result/Maildir/noprefilt"
				set postFlag "$result/Maildir/nopostfilt"
				if {[file exists $vfilterFile]} {
					set vfilter_disabled 0
				} else {
					set vfilter_disabled 1
				}
				if {[file exists $preFlag]} {
					set global_disabled 1
				} else {
					set global_disabled 0
				}
				if {[file exists $postFlag]} {
					set post_disabled 1
				} else {
					set post_disabled 0
				}
			} else {
				unset vfilterFile
			}
			if {$BWidget_present == 1} {
				destroy .progress
			}
			catch {$dwin.log yview moveto 1}
		}
		2 {
			if {[string length $t_filtername] <= 0} {
				msg_dialog .d {Add Filter} {Filter Name not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_header_no] <= 0} {
				msg_dialog .d {Add Filter} {Header Name not Selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_comparision_no] <= 0} {
				msg_dialog .d {Add Filter} {Comparision not Selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_keyword] <= 0} {
				msg_dialog .d {Add Filter} {keyword for comparision not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_destination] <= 0} {
				msg_dialog .d {Add Filter} {Destination Folder not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_bounce] <= 0} {
				msg_dialog .d {Add Filter} {Bounce Action not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set result ""
			if {[info exists t_forward] && [string length $t_forward]} {
				if {$t_bounce == 0} {
					set bvar 2
				} else {
					set bvar 3
				}
				if {$t_ftype == 0} {
					append bvar "&"
				} else {
					append bvar "|"
				}
				append bvar $t_forward
			} else {
				set bvar $t_bounce
			}
			set filtcmd "\"/usr/bin/vcfilter -i -t \\\"$t_filtername\\\" -h $t_header_no -c $t_comparision_no -k $t_keyword -f $t_destination -b \\\"$bvar\\\" $user@$domain\""
			if {[string length $server] > 0} {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			} else {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			}
			runCommand $cmd
			if {$returnstatus != 0} {
				msg_dialog .d "Filter Addition" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			run_filter 1 $dbwin $user $domain
			set t_filterno ""
			set t_filtername ""
			set t_header_no ""
			set t_comparision_no ""
			set t_keyword ""
			set t_destination ""
			set t_forward ""
			set t_bounce 0
			if {[info exists vframe] && [winfo exists $vframe]} {
				set t_header ""
				set t_comparision ""
				if {$BWidget_present == 0} {
					$vframe.2.e selection clear
					$vframe.3.e selection clear
				}
			}
		}
		3 {
			if {[string length $t_filtername] <= 0} {
				msg_dialog .d {Add Filter} {Filter Name not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_header_no] <= 0} {
				msg_dialog .d {Add Filter} {Header Name not Selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_comparision_no] <= 0} {
				msg_dialog .d {Add Filter} {Comparision not Selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_keyword] <= 0} {
				msg_dialog .d {Add Filter} {keyword for comparision not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_destination] <= 0} {
				msg_dialog .d {Add Filter} {Destination Folder not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_bounce] <= 0} {
				msg_dialog .d {Add Filter} {Bounce Action not given} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[info exists t_forward] && [string length $t_forward]} {
				if {$t_bounce == 0} {
					set bvar 2
				} else {
					set bvar 3
				}
				if {$t_ftype == 0} {
					append bvar "&"
				} else {
					append bvar "|"
				}
				append bvar $t_forward
			} else {
				set bvar $t_bounce
			}
			set filtcmd "\"/usr/bin/vcfilter -u $t_filterno -h $t_header_no -c $t_comparision_no -k $t_keyword -f $t_destination -b $bvar $user@$domain\""
			set result ""
			if {[string length $server] > 0} {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			} else {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			}
			runCommand $cmd
			if {$returnstatus != 0} {
				msg_dialog .d "Filter Update" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			run_filter 1 $dbwin $user $domain
		}
		4 {
			set msg "You are About to Delete Filter no $t_filterno for $user@$domain. Click OK to continue\n"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return 1
			}
			set result ""
			set filtcmd "\"/usr/bin/vcfilter -d $t_filterno $user@$domain\""
			if {[string length $server] > 0} {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $server    -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			} else {
				if {[string length $mdahost] > 0} {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				} else {
					set cmd "exec /usr/sbin/adminclient -h $adminhost -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $filtcmd"
				}
			}
			runCommand $cmd
			if {$returnstatus != 0} {
				msg_dialog .d "Filter Delete" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			} else {
				set t_filterno ""
				set t_filtername ""
				set t_header_no ""
				set t_comparision_no ""
				set t_keyword ""
				set t_destination ""
				set t_forward ""
				set t_bounce 0
				set t_header ""
				set t_comparision ""
				if {$BWidget_present == 0} {
					$vframe.2.e selection clear
					$vframe.3.e selection clear
				}
				run_filter 1 $dbwin $user $domain
			}
		}
	}
}

proc vbulletin {} {
	global lwin rwin BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	global Domain
	global email
	global emailfile
	global exfile
	global subscribefile
	global filename
	global spost bulletin_type copy_type dry_run
	set emailfile ""
	set exfile ""
	set subscribefile ""
	set filename ""
	set result ""
	set uindex -1
	set spost 0
	set bulletin_type 0
	set initialdir "/"

	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Bulletin"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp bulletin}

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr -text $Description -side left -relief ridge -bd 2
		pack $w.fr -padx 10 -side top -anchor w -fill both
		set fr [$w.fr getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set dwin $fr.debug
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin $rwin -padx 10 -pady 20 -fill none
	}
	text_create "vbulletin" 0 40 20
	label $lwin.emailfile   -relief ridge  -text "Bulletin   File..." -bd 2 -pady 2
	label $lwin.exfile      -relief ridge  -text "Exclude    List..." -bd 2 -pady 2
	label $lwin.subscribe   -relief ridge  -text "Subscriber List..." -bd 2 -pady 2
	label $lwin.domain      -relief ridge  -text "Domain"             -bd 2
	label $lwin.server      -relief ridge  -text "Server"             -bd 2
	frame $lwin.files
	label  $lwin.files.label  -relief ridge  -text "EditFile" -bd 2
	button $lwin.files.button -relief raised -text "Edit"     -bd 2 \
		-command "editfile 2"
	balloonHelp $lwin.files.button "Click to edit file in entry box"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$lwin.files.button configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	label $lwin.email       -relief ridge  -text "Email"              -bd 2

	checkbutton $lwin.spost -text "BulkMail" -variable spost -offvalue 0 \
		-onvalue 1 -bd 2 -relief flat -indicatoron 1 -command {
		if {$spost == 0} {
			$rwin.email            configure -state normal -relief sunken
			$rwin.exfile.entry     configure -state disabled -relief flat
			$rwin.exfile.button    configure -state disabled
			$rwin.subscribe.entry  configure -state disabled -relief flat 
			$rwin.subscribe.button configure -state disabled
			$lwin.options.rdb3     configure -state disabled
		} else {
			$rwin.email            configure -state disabled -relief flat
			$rwin.exfile.entry     configure -state normal -relief sunken
			$rwin.exfile.button    configure -state normal
			$rwin.subscribe.entry  configure -state normal -relief sunken
			$rwin.subscribe.button configure -state normal
			if {$bulletin_type == 0} {
				$lwin.options.rdb3     configure -state normal
			}
		} 
	}
	$lwin.spost select
	checkbutton $lwin.mysql -text "Instant Bulletin" -variable bulletin_type \
		-offvalue 0 -onvalue 1 -bd 2 -relief flat -indicatoron 1 \
		-command {
		if {$bulletin_type == 0} {
			$lwin.spost            configure -state normal
			$rwin.exfile.entry     configure -state normal -relief sunken
			$rwin.exfile.button    configure -state normal -relief ridge
			$lwin.options.rdb1     configure -state normal
			$lwin.options.rdb2     configure -state normal
			$lwin.filesys          configure -state disabled
			set domain_bulletin 0
			if {$spost == 1} {
				$lwin.options.rdb3 configure -state normal
				$rwin.subscribe.entry  configure -state normal -relief sunken
				$rwin.subscribe.button configure -state normal
				$rwin.email            configure -state disabled -relief flat
			} else {
				$rwin.subscribe.entry  configure -state disabled -relief flat
				$rwin.subscribe.button configure -state disabled
				$rwin.exfile.entry     configure -state disabled -relief flat
				$rwin.exfile.button    configure -state disabled
				$rwin.email            configure -state normal -relief sunken
			}
			if {$copy_type != 1} {
				$lwin.options.rdb2 select
			}
		} else {
			$rwin.email            configure -state disabled -relief flat
			set subscribefile ""
			set spost 0
			$lwin.spost            configure -state disabled
			$rwin.subscribe.entry  configure -state normal -relief sunken
			$rwin.subscribe.button configure -state normal -relief ridge
			$rwin.exfile.entry     configure -state disabled -relief flat
			$rwin.exfile.button    configure -state disabled
			$lwin.options.rdb1     configure -state disabled
			$lwin.options.rdb2     configure -state disabled
			$lwin.options.rdb3     configure -state disabled
			$lwin.filesys          configure -state normal
		}
	}
	checkbutton $lwin.filesys -text "Domain Bulletin" -variable domain_bulletin \
		-offvalue 0 -onvalue 1 -bd 2 -relief flat -indicatoron 1 -state disabled \
		-command {
			if {$domain_bulletin == 1} {
				$rwin.subscribe.entry  configure -state disabled -relief flat
				$rwin.subscribe.button configure -state disabled
			} else {
				$rwin.subscribe.entry  configure -state normal -relief sunken
				$rwin.subscribe.button configure -state normal
			}
		}
	frame  $rwin.emailfile
	entry  $rwin.emailfile.entry -relief sunken -textvariable emailfile -bd 2 -width 50
	button $rwin.emailfile.button \
		-padx "9" -pady "3" -relief ridge \
		-command "fileDialog $w $rwin.emailfile.entry open 1"
	balloonHelp $rwin.emailfile.button "Click to browse for Email File"
	$rwin.emailfile.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]

	frame $rwin.exfile
	entry $rwin.exfile.entry    -relief sunken -textvariable exfile -bd 2 -width 50
	button $rwin.exfile.button \
		-padx "9" -pady "3" -relief ridge \
		-command "fileDialog $w $rwin.exfile.entry open 1"
	balloonHelp $rwin.emailfile.button "Click to browse for Exclude File"
	$rwin.exfile.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]

	frame $rwin.subscribe
	entry $rwin.subscribe.entry -relief sunken -textvariable subscribefile -bd 2 -width 50
	button $rwin.subscribe.button \
		-padx "9" -pady "3" -relief ridge \
		-command "fileDialog $w $rwin.subscribe.entry open 1"
	balloonHelp $rwin.emailfile.button "Click to browse for Subscribe File"
	$rwin.subscribe.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]

	set Domain $default_domain
	combobox $rwin.domain \
	-textvariable Domain \
	-editable false \
	-highlightthickness 1 \
	-borderwidth 3 \
	-value $domain \
	-command "setServerVal $rwin.server"
	foreach line $domain_list {
		$rwin.domain list insert end $line
	}
	combobox $rwin.server \
	-textvariable adminhost \
	-editable false \
	-highlightthickness 1 \
	-borderwidth 3
	catch {$rwin.server list insert 0 $adminhost}

	combobox $rwin.files \
	-textvariable filename \
	-editable true \
	-highlightthickness 1 \
	-borderwidth 3
	entry $rwin.email     -relief flat  -textvariable email -bd 2 -width 40 -state disabled \
		-vcmd {expr {[string length %P]<=96}} -validate key -invcmd bell

	pack $lwin.emailfile      -side top  -fill x    -ipady 1
	pack $lwin.subscribe      -side top  -fill x    -ipady 1
	pack $lwin.exfile         -side top  -fill x    -ipady 1
	pack $lwin.domain         -side top  -fill x    -ipady 2
	pack $lwin.server         -side top  -fill x    -ipady 2
	pack $lwin.files          -side top  -fill x    -ipady 3
	pack $lwin.email          -side top  -fill x    -expand 0
	pack $lwin.files.label    -side left -fill x    -expand 1
	pack $lwin.files.button   -side left -fill none -expand 0
	pack $lwin.spost          -side top  -fill none -expand 0 -ipady 2 -anchor nw
	pack $lwin.mysql          -side top  -fill none -expand 0 -ipady 2 -anchor nw
	pack $lwin.filesys        -side top  -fill none -expand 0 -ipady 2 -anchor nw

	pack $rwin.emailfile -side top -anchor w -fill none -expand 0
	pack $rwin.emailfile.entry $rwin.emailfile.button -side left
	pack $rwin.subscribe -side top -anchor w -fill none -expand 0
	pack $rwin.subscribe.entry $rwin.subscribe.button -side left
	pack $rwin.exfile    -side top -anchor w -fill none -expand 0
	pack $rwin.exfile.entry $rwin.exfile.button -side left
	pack $rwin.domain    -side top -anchor w
	pack $rwin.server    -side top -anchor w
	pack $rwin.files     -side top -anchor w
	pack $rwin.email     -side top -anchor w
	pack $rwin -expand 0

	checkbutton $lwin.test -text "Dry Run" -variable dry_run -offvalue 0 -onvalue 1 -bd 2 -relief flat -indicatoron 1
	pack $lwin.test  -side top -fill none -expand 0 -anchor nw -ipady 2

	frame $lwin.options -bd 2 -relief sunken
	pack $lwin.options -anchor nw -expand 0 -fill x

	label $lwin.options.label -text "Copy Type" -relief ridge
	pack $lwin.options.label -expand 0 -fill x
	radiobutton $lwin.options.rdb1 -text "Copy File" -variable copy_type -relief flat -value 0 -indicatoron 1
	radiobutton $lwin.options.rdb2 -text "Symb Link" -variable copy_type -relief flat -value 1 -indicatoron 1
	radiobutton $lwin.options.rdb3 -text "Hard Link" -variable copy_type -relief flat -value 2 -indicatoron 1
	$lwin.options.rdb2 select
	pack $lwin.options.rdb1 $lwin.options.rdb2 $lwin.options.rdb3 -side top -expand 0 -fill none -anchor nw

	button $rwin.run  -text Submit  -bg orange -bd 5 \
		-command "run_bulletin" \
		-highlightthickness 5 -highlightbackground black
	button $rwin.quit -text Cancel -bg IndianRed -bd 5 \
		-command "destroyWindows;return" \
		-highlightthickness 5 -highlightbackground black
	pack $rwin.run       -side left -expand 0 -anchor nw -fill none
	pack $rwin.quit      -side left -expand 0 -anchor nw -fill none
}

proc run_bulletin {} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global Domain
	global email
	global emailfile
	global exfile
	global subscribefile
	global spost bulletin_type copy_type dry_run
	if {[info exists emailfile] == 0 || [string length $emailfile] <= 0} {
		msg_dialog .d {vbulletin} {Email File not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	append cmd "exec /usr/bin/vbulletin -f $emailfile "
	if {$bulletin_type == 1} {
		if {$domain_bulletin == 1} {
			append cmd "-a "
		} else {
			if {[info exists subscribefile] == 0 || [string length $subscribefile] <= 0} {
				msg_dialog .d {vbulletin} {Subscribler List File not selected} /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			append cmd "-S $subscribefile "
		}
	} else {
		if {$spost == 1} {
			if {[info exists exfile] && [string length $exfile] > 0} {
				append cmd "-e $exfile "
			}
		}
		if {$copy_type == 0} {
			append cmd "-c "
		} elseif {$copy_type == 1} {
			append cmd "-s "
		}
		if {$spost == 1 && $copy_type == 2} {
			append cmd "-h "
		}
	}
	if {$dry_run == 1} {
		append cmd "-n "
	}
	if {$spost == 1 || $bulletin_type == 1} {
		append cmd "$Domain"
	} else {
		append cmd "$email@$Domain"
	}
	set returnstatus [catch {eval $cmd} result]
	if {$returnstatus == 0} {
		$dwin.log insert end "$cmd: Sucessfull run\n"
		set email ""
	} else {
		$dwin.log insert end "$result\n"
	}
	$dwin.log yview moveto 1
}

proc editcontrol {} {
	global BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	global filename novice_mode
	global userList
	variable tcpfile
	set tcpfile ""
	set filename ""
	set result ""
	set w .dname

	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Control Files"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp editcontrol}
	if {$BWidget_present == 1} {
		TitleFrame $w -text $Description -side left -relief flat -bd 2
		pack $w -side top -anchor w -padx 5 -pady 5 -fill both
		set fr [$w getframe]
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin -expand 1 -fill both
	}
	set userList {}
	if {[catch {open {| cut -d: -f1 /etc/passwd} r} f] } {
		msg_dialog .d {editcontrol} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	} else {
		while {[gets $f line] >= 0} {
			lappend userList $line
		}
	}
	close $f
	frame $fr.1
	frame $fr.2
	frame $fr.3
	frame $fr.4
	pack $fr.1 -expand 1 -fill x    -side top
	pack $fr.3 -expand 0 -fill none -side top -anchor nw
	pack $fr.2 -expand 1 -fill both -side top
	pack $fr.4 -expand 0 -fill none -side top -anchor nw
	Entry $fr.1.e -editable false -relief sunken  -textvariable filename -bd 2
	pack $fr.1.e -side left -expand 1 -fill x -anchor nw
	create_tree $fr.2
	set controldirs [glob -nocomplain /etc/indimail/control*]
	frame $fr.3.controldir
	frame $fr.3.1
	frame $fr.3.2
	frame $fr.3.3
	pack $fr.3.controldir -side top -anchor nw
	pack $fr.3.1          -side top -anchor nw
	pack $fr.3.2          -side top -anchor nw
	pack $fr.3.3          -side top -anchor nw

	label $fr.3.controldir.l -text "Control Directory"
	ComboBox $fr.3.controldir.e \
		-textvariable controldir \
		-editable true \
		-width 30 \
		-modifycmd {setControldir $controldir} \
		-height 10 \
		-bd 2 \
		-vcmd {regexp {^[A-Za-z0-9]*$} %P} -validate key -invcmd bell \
		-values $controldirs

	pack $fr.3.controldir.l $fr.3.controldir.e -side left -anchor nw
	if {[file exists /usr/bin/easyedit]} {
		checkbutton $fr.3.controldir.c -text "Novice Mode" -variable novice_mode -offvalue 0 \
			-onvalue 1 -bd 2 -relief flat -indicatoron 1
		pack $fr.3.controldir.c -side left -expand 0  -anchor nw
	} else {
		set novice_mode 0
	}
	button $fr.3.1.b1 -text "Rebuild Assign" -command {exec /usr/sbin/qmail-newu}
	balloonHelp $fr.3.1.b1 "Rebuild /etc/indimail/users/cdb"
	$fr.3.1.b1 configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBCRaJBxWJBxOHBRGBCxeLLTatCSKFCymJBQ6BAwmBNzu3AQCBAQOBCRSJKzWrGy+ZDy+NBxSHFSmTBxWHLTWtCyaHCSSFCx6PETKNBQ+FBwaHCRKJMTixLy6vExOTKyqrFxaXDQyNDw+PBQSFHx6fCwuLJyenDQ2NISChLSytJSSlFxeXAwODCQmJBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaBQIBQGBAMBALCcCksGA4IQkJBUDIDC6gVwGhshY5HlMn9DiCRL1MyYE8iiapaSKlALBdMRiPckDkdeXt9HgxkGhWDXB4fH4ZMGnxcICEiI45kQiQkDCUmJZskmUIiJyiPQgyoQwwpH35LqqgMKiEjq5obqh8rLCMtowAkLqovuH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	label $fr.3.1.l -text "Rebuild Assign CDB File" -anchor nw -justify left
	button $fr.3.1.b2 -relief raised -text "Edit" -bd 2 -command "set filename /etc/indimail/users/assign;editfile 2"
	balloonHelp $fr.3.1.b2 "Edit /etc/indimail/users/assign"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$fr.3.1.b2 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	pack $fr.3.1.b1 $fr.3.1.b2 $fr.3.1.l -side left -anchor nw

	button $fr.3.2.b1 -text "Rebuild Morercpthosts" -command {exec /usr/sbin/qmail-newmrh}
	balloonHelp $fr.3.2.b1 "Rebuild /etc/indimail/control/morercpthosts.cdb"
	$fr.3.2.b1 configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBCRaJBxWJBxOHBRGBCxeLLTatCSKFCymJBQ6BAwmBNzu3AQCBAQOBCRSJKzWrGy+ZDy+NBxSHFSmTBxWHLTWtCyaHCSSFCx6PETKNBQ+FBwaHCRKJMTixLy6vExOTKyqrFxaXDQyNDw+PBQSFHx6fCwuLJyenDQ2NISChLSytJSSlFxeXAwODCQmJBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaBQIBQGBAMBALCcCksGA4IQkJBUDIDC6gVwGhshY5HlMn9DiCRL1MyYE8iiapaSKlALBdMRiPckDkdeXt9HgxkGhWDXB4fH4ZMGnxcICEiI45kQiQkDCUmJZskmUIiJyiPQgyoQwwpH35LqqgMKiEjq5obqh8rLCMtowAkLqovuH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	label $fr.3.2.l -text "Rebuild morercpthosts CDB File" -anchor nw -justify left
	button $fr.3.2.b2 -relief raised -text "Edit" -bd 2 \
		-command "set filename $controldir/morercpthosts;editfile 2"
	balloonHelp $fr.3.2.b2 "Rebuild /etc/indimail/control/morercpthosts.cdb"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$fr.3.2.b2 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	pack $fr.3.2.b1 $fr.3.2.b2 $fr.3.2.l -side left -anchor nw

	button $fr.3.3.b1 -text "Rebuild tcprules" \
		-command {
			exec /usr/bin/tcprules /etc/indimail/$tcpfile.cdb
			/etc/indimail/$tcpfile.tmp < /etc/indimail/$tcpfile
		}
	$fr.3.3.b1 configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBCRaJBxWJBxOHBRGBCxeLLTatCSKFCymJBQ6BAwmBNzu3AQCBAQOBCRSJKzWrGy+ZDy+NBxSHFSmTBxWHLTWtCyaHCSSFCx6PETKNBQ+FBwaHCRKJMTixLy6vExOTKyqrFxaXDQyNDw+PBQSFHx6fCwuLJyenDQ2NISChLSytJSSlFxeXAwODCQmJBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaBQIBQGBAMBALCcCksGA4IQkJBUDIDC6gVwGhshY5HlMn9DiCRL1MyYE8iiapaSKlALBdMRiPckDkdeXt9HgxkGhWDXB4fH4ZMGnxcICEiI45kQiQkDCUmJZskmUIiJyiPQgyoQwwpH35LqqgMKiEjq5obqh8rLCMtowAkLqovuH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	balloonHelp $fr.3.3.b1 "Rebuild tcprules in CDB Format"
	label $fr.3.3.l -text "Rebuild tcprules" -anchor nw -justify left
	ComboBox $fr.3.3.c \
		-textvariable tcpfile \
		-editable false \
		-width 8 \
		-height 3 \
		-bd 2 \
		-values {tcp.smtp tcp.imap tcp.pop3}
	button $fr.3.3.b2 -relief raised -text "Edit" -bd 2 \
		-command {
				if {$tcpfile != ""} {
					set filename /etc/indimail/$tcpfile
					editfile 2
				} else {
					msg_dialog .d {tcprules} "rules file not selected" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
			}
	balloonHelp $fr.3.3.b2 "Edit Rules File"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$fr.3.3.b2 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	pack $fr.3.3.b1 $fr.3.3.b2 $fr.3.3.l $fr.3.3.c -side left -anchor nw

	button $fr.4.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black
	pack $fr.4.quit -side left -anchor nw
}

proc setControldir {cntrldir} {
	global env
	set env(CONTROLDIR) $cntrldir
}

proc create_tree {twin} {
	variable tree
	variable list
	global env

    set pw    [PanedWindow $twin.pw -side top]
    set pane  [$pw add -weight 1]
    set title [TitleFrame $pane.lf -text "Directory Tree" -ipad 10]
    set sw    [ScrolledWindow [$title getframe].sw -relief sunken -borderwidth 2]
    set tree  [Tree $sw.tree -relief flat -borderwidth 2 -width 25 \
		-highlightthickness 0 -redraw 1 \
		-opencmd   "moddir 1 $sw.tree" \
		-closecmd  "moddir 0 $sw.tree"]
	$sw setwidget $tree
	pack $sw    -expand 1 -fill both -side top
	pack $title -expand 1 -fill both 
	set pane [$pw add -weight 2]
	set lf   [TitleFrame $pane.lf -text "Content"]
	set sw   [ScrolledWindow [$lf getframe].sw \
		-scrollbar horizontal -auto none -relief sunken -borderwidth 2]
	set list [ListBox::create $sw.lb \
		-relief flat -borderwidth 0 \
		-width 40 -height 15 \
		-highlightthickness 0 -multicolumn true \
		-redraw 0]
	$sw setwidget $list
	pack $sw $lf -fill both -expand yes
	pack $pw -fill both -expand yes
	$tree bindText  <ButtonPress-1>        "select tree 1 $tree $list"
	$tree bindText  <Double-ButtonPress-1> "select tree 2 $tree $list"
	$list bindText  <ButtonPress-1>        "select list 1 $tree $list"
	$list bindText  <Double-ButtonPress-1> "select list 2 $tree $list"
	$list bindImage <Double-ButtonPress-1> "select list 2 $tree $list"

	$tree bindText  <ButtonPress-3>        "select tree 3 $tree $list"
	$tree bindImage <ButtonPress-3>        "select tree 3 $tree $list"
	foreach rootdir [glob -nocomplain /etc/indimail/control*] {
		$tree insert end root $rootdir -text $rootdir -data $rootdir -open 0 \
			-image [Bitmap::get folder]
		getdir $tree $rootdir $rootdir
	}
	foreach rootdir "/etc/indimail $env(HOME)" {
		$tree insert end root $rootdir -text $rootdir -data $rootdir -open 0 \
			-image [Bitmap::get folder]
		getdir $tree $rootdir $rootdir
	}
	if {[file exists /etc/indimail/maildirshared]} {
		$tree insert end root "PublicFolders" -text "PublicFolders" -open 1 \
			-image [Bitmap::get folder]
		getshareddir $tree "PublicFolders"
	}
	$tree configure -redraw 1
	$list configure -redraw 1
}

proc getshareddir {tree node} {
	variable count

	if {[catch {open /etc/indimail/maildirshared r} f] } {
		msg_dialog .d {Public Folders} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set count 0
	while {[gets $f line] >= 0} {
		set name          [lindex $line 0]
		set sharedmaildir [lindex $line 1]
		$tree insert end $node $sharedmaildir \
			-text      $name \
			-image     [Bitmap::get folder] \
			-drawcross allways \
			-data      $sharedmaildir
		incr count
	}
	close $f
	$tree itemconfigure $node -drawcross auto
}

proc getdir {tree node path} {
	variable count
	global lfiles
	if {[catch {open /etc/indimail/controlfiles r} f]} {
		set control_files {
			"badheaders" \
			"badheaderthresh" \
			"badmailfrom" \
			"badmailpatterns" \
			"badrcptpatterns" \
			"badrcptto" \
			"bindroutes" \
			"domainbindings" \
			"blackholedpatterns" \
			"blackholedsender" \
			"bouncefrom" \
			"bouncehost" \
			"bouncemaxbytes" \
			"bouncemessage" \
			"bouncesubject" \
			"chkrcptdomains" \
			"authdomains" \
			"concurrencyincoming" \
			"concurrencylocal" \
			"concurrencyremote" \
			"databytes" \
			"defaultdelivery" \
			"defaultdomain" \
			"defaulthost" \
			"doublebouncehost" \
			"doublebouncemessage" \
			"doublebouncesubject" \
			"doublebounceto" \
			"envnoathost" \
			"etrnhosts" \
			"extraqueue" \
			"helohost" \
			"holdlocal" \
			"holdremote" \
			"qregex" \
			"host.cntrl" \
			"hostid" \
			"hostip" \
			"host.master" \
			"host.mysql" \
			"idhost" \
			"localiphost" \
			"locals" \
			"maxhops" \
			"maxrecipients" \
			"me" \
			"morercpthosts" \
			"morercpthosts.cdb" \
			"nodnscheck" \
			"badhelo" \
			"outgoingip" \
			"percenthack" \
			"plusdomain" \
			"qmqpservers" \
			"queueforward" \
			"queuelifetime" \
			"rcpthosts" \
			"relayclients" \
			"relaydomains" \
			"relayhosts" \
			"relaymailfrom" \
			"smtpgreeting" \
			"smtproutes" \
			"spamignore" \
			"spamignorepatterns" \
			"spamignoreheaders" \
			"globalspamredirect" \
			"spamredirect" \
			"spamfilterargs" \
			"spamignoreheaders" \
			"rejectspam" \
			"filterargs" \
			"tarpitcount" \
			"tarpitdelay" \
			"timeoutconnect" \
			"timeoutread" \
			"timeoutremote" \
			"timeoutsmtpd" \
			"timeoutwrite" \
			"tlsclientciphers" \
			"tlsserverciphers" \
			"virtualdomains" \
			"from.envrules" \
			"rcpt.envrules" \
			"bodycheck" \
			"signatures" \
			"hostaccess" \
			"maxcmdlen" \
			"spfbehavior" \
			"spfexp" \
			"spfguess" \
			"spfrules" \
			"badext" \
			"badextpatterns" \
			"todointerval" \
			"quarantine" \
			"removeheaders" \
		}
	} else {
		set control_files [read $f]
		close $f
	}
	set count 0
	set lentries [glob -nocomplain [file join $path "*"] [file join $path ".*"]]
	set lfiles   {}
	foreach f $lentries {
		set tail [file tail $f]
		if {$tail == "inquery" || $tail == "ratelimit" || $tail == "defaultqueue" || $tail == "domainkeys"} {
			continue
		}
		if {$tail  == "." || $tail == ".."} {
			continue
		}
		if {[file isdirectory $f] == 1} {
			catch {$tree insert end $node $f \
				-text      $tail \
				-image     [Bitmap::get folder] \
				-drawcross allways \
				-data      $f} result
			if {$result != ""} {
				continue
			}
			incr count
		} else {
			lappend lfiles $tail
		}
	}
	set tail [file tail $path]
	set len [string length /etc/indimail]
	if {[string compare -length $len $path /etc/indimail] == 0 && [string compare -length 7 $tail "control"] == 0} {
		foreach line $control_files {
			if {[file exists [file join $path $line]] == 0} {
				lappend lfiles $line
			}
		}
	}
	set lfiles [lsort -dictionary $lfiles]
	$tree itemconfigure $node -drawcross auto -data $lfiles
}

proc moddir {idx tree node} {
	set mode [$tree itemcget $node -drawcross]
	if {$idx && $mode == "allways"} {
		getdir $tree $node [$tree itemcget $node -data]
		if { [llength [$tree nodes $node]] } {
			$tree itemconfigure $node -image [Bitmap::get openfold]
		} else {
			$tree itemconfigure $node -image [Bitmap::get folder]
		}
	} else {
		$tree itemconfigure $node -image [Bitmap::get [lindex {folder openfold} $idx]]
	}
}

proc showMenuMaildir {node name} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global w
	variable x
	variable y
	variable nodeTmp
	variable nameTmp

	if {[catch {open /etc/indimail/maildirshared r} f] } {
		msg_dialog .d {Public Folders} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set nodeTmp $node
	set nameTmp $name
	set is_publicfolder 0
	while {[gets $f line] >= 0} {
		set sharedmaildir [lindex $line 1]
		set len [string length $sharedmaildir]
		if {[string compare -length $len $sharedmaildir $node] == 0} {
			set is_publicfolder 1
			break;
		}
	}
	close $f
	if {$is_publicfolder == 0 && $node != "PublicFolders"} {
		return;
	}
	if [winfo exists .pm1] {
		destroy .pm1
	}
	set x [winfo pointerx $w]
	set y [winfo pointery $w]
	menu .pm1 -title "Public Folders" -type normal -tearoff 0 -borderwidth 2
	set x [winfo pointerx $w]
	set y [winfo pointery $w]
	.pm1 add command -label "Create Public Maildir" \
		-command {createMaildir $x $y}
	if {$node != "PublicFolders"} {
	.pm1 add command -label "Create Shared Folder in $name ($node)" \
		-command {createSharedFolder $nodeTmp $x $y}
	.pm1 add command -label "Delete $name ($node)" -command {
			set msg "You are About to delete Maildir $nodeTmp.\nAre you sure?\nClick OK to continue"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action == 1} {
				catch {file delete -force $nodeTmp} result
				if {$result != ""} {
					msg_dialog .d {deleteMaildir} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
					return
				}
				set maildir_line "$nameTmp	$nodeTmp"
				set cmd "exec /usr/libexec/indimail/updatefile -d \"$maildir_line\" /etc/indimail/maildirshared"
				runCommand $cmd
				if {$returnstatus != 0} {
					msg_dialog .d {updatefile} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				} else {
					editcontrol
				}
			}
		}
	}
	.pm1 add command -label "Cancel      " -command "return 0"
	.pm1 post $x $y
}

proc createMaildir {x y} {
	global w
	global userList
	source /usr/share/indimail/indium/scripts/global.tcl

	catch {destroy .f1}
	set base .f1
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief raised
	wm geometry $base +${x}+${y}
	wm focusmodel $base passive
	wm geometry $base 400x120
	wm maxsize $base 1009 738
	wm minsize $base 1 1
	wm overrideredirect $base 0
	wm resizable $base 0 0
	wm title $base "Indium - New Public Maildir"
	grab .f1
	frame .f1.1
	frame .f1.2
	frame .f1.3
	frame .f1.4
	pack .f1.1 .f1.2 .f1.3 -side top -anchor nw
	pack .f1.4 -side top -anchor sw

	label .f1.1.l -text "Public Maildir Name" -width 18
	entry .f1.1.e -relief sunken -textvariable maildirname -bd 2 \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	focus .f1.1.e
	pack .f1.1.l .f1.1.e -side left -anchor nw

	label .f1.2.l -text "Maildir Path" -width 18
	entry .f1.2.e -relief sunken -textvariable maildirpath -bd 2 -width 40 \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	pack .f1.2.l .f1.2.e -side left -anchor nw

	label .f1.3.l -text Username -width 18
	set username "indimail"
	ComboBox .f1.3.u \
		-textvariable username \
		-editable false \
		-width 30 \
		-height 10 \
		-bd 2 \
		-values $userList
	pack .f1.3.l .f1.3.u -side left -anchor nw

	button .f1.4.b1 -text Submit -bg orange -bd 4 -highlightthickness 5 \
		-highlightbackground black\
		-command {
			set maildir_line "$maildirname	$maildirpath"
			set cmd "exec /usr/bin/maildirmake -S $maildirpath"
			runCommand $cmd
			if {$returnstatus != 0} {
				msg_dialog .d {maildirmake} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				set cmd "exec /usr/libexec/indimail/updatefile -u \"$maildir_line\" /etc/indimail/maildirshared"
				runCommand $cmd
				if {$returnstatus != 0} {
					msg_dialog .d {updatefile} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
				catch {exec chown -R $username:vchkpw $maildirpath} result
				if {$result != ""} {
					msg_dialog .d {chown} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
				editcontrol
			}
		}
	button .f1.4.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 \
		-highlightbackground black \
		-command "releaseGrab .f1;wm withdraw .f1;return 0"
	pack .f1.4.b1 .f1.4.b2 -side left -anchor nw
}

proc createSharedFolder {maildir x y} {
	global w
	source /usr/share/indimail/indium/scripts/global.tcl
	variable maildirname
	variable Rdonly
	variable Write
	variable Group
	variable var_quota
	global folderOptions userList
	variable maildirTmp

	catch {destroy .f1}
	set base .f1
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief raised
	wm geometry $base +${x}+${y}
	wm focusmodel $base passive
	wm geometry $base 350x180
	wm maxsize $base 1009 738
	wm minsize $base 1 1
	wm overrideredirect $base 0
	wm resizable $base 0 0
	wm title $base "Indium - New Shared Folder"
	grab .f1
	frame .f1.1
	frame .f1.2
	frame .f1.3
	frame .f1.4

	pack .f1.1 .f1.3 .f1.2 -side top -anchor nw
	pack .f1.4 -side top -anchor sw

	if {[catch {open $maildir/maildirsize r} f] } {
		set var_quota -1
	} else {
		if {[gets $f tmp] >= 0} {
			set var_quota [string range $tmp 0 [expr [string length $tmp] - 2]]
		}
		close $f
	}
	set maildirTmp $maildir
	label .f1.1.l -text "Public Folder Name" -width 16
	entry .f1.1.e -relief sunken -textvariable maildirname -bd 2 -width 20 \
		-vcmd {regexp {^[A-Za-z][A-Za-z0-9*+-_.=?^ ~]*$} %P} \
		-validate key -invcmd bell
	focus .f1.1.e
	pack .f1.1.l .f1.1.e -side left -anchor nw
	checkbutton .f1.2.c1 -text "Read Only" -variable Rdonly
	checkbutton .f1.2.c2 -text "Write"     -variable Write
	checkbutton .f1.2.c3 -text "Group"     -variable Group
	frame .f1.2.c4
	label .f1.2.c4.l -text "Quota"
	SpinBox .f1.2.c4.s -relief sunken -textvariable var_quota -bd 2 \
		-width 5 -range {0 500 1} \
		-vcmd {regexp {^[+]?[0-9]*$} %P} -validate key -invcmd bell
	pack .f1.2.c4.l .f1.2.c4.s -side left -anchor nw
	pack .f1.2.c1 .f1.2.c2 .f1.2.c3 .f1.2.c4 -side top -anchor nw

	label .f1.3.l -text Username -width 16
	set username "indimail"
	ComboBox .f1.3.u \
		-textvariable username \
		-editable false \
		-height 10 \
		-bd 2 \
		-values $userList
	pack .f1.3.l .f1.3.u -side left -anchor nw

	button .f1.4.b1 -text Submit -bg orange -bd 4 -highlightthickness 5 \
		-highlightbackground black -command {
		setFolderOptions $Rdonly $Write $Group
		if {$var_quota == -1} {
		set cmd "exec /usr/bin/maildirmake -s $folderOptions -f $maildirname $maildirTmp"
		} else {
		set cmd "exec /usr/bin/maildirmake -s $folderOptions -q $var_quota -f $maildirname $maildirTmp"
		}
		runCommand $cmd
		if {$returnstatus != 0} {
			msg_dialog .d {maildirmake} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			editcontrol
		}
	}
	button .f1.4.b2 -text Cancel -bg IndianRed -bd 4 -highlightthickness 5 \
		-highlightbackground black \
		-command "releaseGrab .f1;wm withdraw .f1;return 0"
	pack .f1.4.b1 .f1.4.b2 -side left -anchor nw
}

proc setFolderOptions {Rdonly Write Group} {
	global folderOptions

	set folderOptions ""
	if {$Rdonly} {
		if {$folderOptions == ""} {
			append folderOptions "read"
		} else {
			append folderOptions ",read"
		}
	}
	if {$Write} {
		if {$folderOptions == ""} {
			append folderOptions "write"
		} else {
			append folderOptions ",write"
		}
	}
	if {$Group} {
		if {$folderOptions == ""} {
			append folderOptions "group"
		} else {
			append folderOptions ",group"
		}
	}
}

proc select {where num tree list node} {
	variable dblclick
	global lfiles filename my_dir novice_mode

	if {$num == 2 && $where == "list"} {
		set first_char [string index $node 0]
		if {$first_char == "f"} {
			set index [string last ":" $node]
			incr index
			set ind [string range $node $index end]
			set filename [file join $my_dir [lindex $lfiles $ind]]
			if {$num == 2} {
				if {$novice_mode == 1} {
				exec easyedit $filename &
				} else {
				exec supernotepad -r $filename &
				}
			}
		}
	}
	if {$where == "tree"} {
		moddir 1 $tree $node
		select_node $tree $list $node
	}
	if {$num == 3} {
		showMenuMaildir $node [$tree itemcget $node -text]
		return
	}
	set dblclick 1
	if {$num == 1} {
		if { $where == "tree" && [lsearch [$tree selection get] $node] != -1 } {
			unset dblclick
			#after 1500 "edit_item tree $tree $list $node"
			return
		}
		if {$where == "list" && [lsearch [$list selection get] $node] != -1} {
			unset dblclick
			after 1500 "edit_item list $tree $list $node"
			return
		}
		if {$where == "tree"} {
			select_node $tree $list $node
		} else {
			$list selection set $node
		}
	} elseif {$where == "list" && [$tree exists $node]} {
		set parent [$tree parent $node]
		while {$parent != "root"} {
			$tree itemconfigure $parent -open 1
			set parent [$tree parent $parent]
		}
		select_node $tree $list $node
	}
}

proc select_node {tree list node} {
	global lfiles my_dir

	set my_dir $node
	set lfiles   {}
	$tree selection set $node
	eval $list delete [$list item 0 end]
	set dir [lsort -dictionary [$tree itemcget $node -data]]
	foreach subnode [$tree nodes $node] {
		$list insert end $subnode \
			-data  [$tree itemcget $subnode -data] \
			-text  [$tree itemcget $subnode -text] \
			-image [Bitmap::get folder]
	}
	set mode [$tree itemcget $node -drawcross]
	if {$mode == "allways"} {
		getdir $tree $node $dir
		set dir [lsort -dictionary [$tree itemcget $node -data]]
	}
	if {$dir == ""} {
		return
	}
	set num 0
	foreach f $dir {
		lappend lfiles $f
		if {[file tail $node] == "control"} {
			if {[file exists $node/$f]} {
				$list insert end f:$num -text $f -image [image create photo -file /usr/share/indimail/indium/images/file.gif]
			} else {
				$list insert end f:$num -text $f -image [image create photo -file /usr/share/indimail/indium/images/filemiss.gif]
			}
		} else {
			$list insert end f:$num -text $f -image [image create photo -file /usr/share/indimail/indium/images/file.gif]
		}
		incr num
	}
}

proc edit_item {where tree list node} {
	variable dblclick
	variable olddata
	variable res

	if {[info exists dblclick]} {
		return
	}
	if {$where == "tree" && [lsearch [$tree selection get] $node] != -1} {
		set res [$tree edit $node [$tree itemcget $node -text]]
		if {$res != ""} {
			$tree itemconfigure $node -text $res
			if {[$list exists $node]} {
				$list itemconfigure $node -text $res
			}
			$tree selection set $node
		}
		return
	}
	if {$where == "list"} {
		set olddata [$list itemcget $node -text]
		set res [$list edit $node [$list itemcget $node -text]]
		if { $res != "" } {
			$list itemconfigure $node -text $res
			if {[$tree exists $node]} {
				$tree itemconfigure $node -text $res
				nodeRename $node $olddata $res
			} else {
				set cursel [$tree selection get]
				set index  [expr {[$list index $node]-[llength [$tree nodes $cursel]]}]
				set data   [$tree itemcget $cursel -data]
				set data   [lreplace $data $index $index $res]
				$tree itemconfigure $cursel -data $data
				nodeRename $node $olddata $res
			}
			$list selection set $node
		}
	}
}

proc nodeRename {node olddata newdata} {
	global lfiles
	global my_dir
	variable oldfile
	variable newfile

	set first_char [string index $node 0]
	if {$first_char == "f"} {
		set index [string last ":" $node]
		if {$index == -1} {
			return
		}
		incr index
		set ind [string range $node $index end]
		set filename [file join $my_dir [lindex $lfiles $ind]]
	} else {
		set filename $node
	}
	if {$first_char == "f"} {
		set lfiles [lreplace $lfiles $ind $ind $newdata]
	}
	set index [string last $olddata $filename]
	if {$index == -1 || $index == 0} {
		return
	}
	incr index -1
	set oldfile [string range $filename 0 $index]
	set newfile $oldfile
	append oldfile $olddata
	append newfile $newdata
	if {[file exists $oldfile]} {
		catch {file rename -force $oldfile $newfile} result
		if {$result != ""} {
			msg_dialog .d {Rename $oldfile to $newfile} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc expand { tree but } {
	if { [set cur [$tree selection get]] != "" } {
		if { $but == 0 } {
			$tree opentree $cur
		} else {
			$tree closetree $cur
		}
	}
}

proc editfile {action} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global filename fil

	if {$filename == ""} {
		msg_dialog .d {Invalid Filename} {filename required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {$action == 0} {
		set cmd "exec sh -c \"echo File $controldir/$filename;cat $controldir/$filename;echo ------------------------------------------------------------------\""
		catch $cmd result
		catch {$dwin.log insert end "$result\n"}
		catch {$dwin.log yview moveto 1}
	} elseif {$action == 1} {
		set cmd "exec /usr/bin/supernotepad -r $controldir/$filename &"
		set returnstatus [catch {eval $cmd} result]
	} elseif {$action == 2} {
		set cmd "exec /usr/bin/supernotepad -r $filename &"
		catch $cmd result
		catch {$dwin.log insert end "$result\n"}
		catch {$dwin.log yview moveto 1}
	}
}
# TODO
# shutdown command (edit run and shutdown file)
# down file
# removal of service
proc svctool {mode} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global service_name service_name1 service_name2 service_name3 flag BWidget_present
	global lwin lwin1 lwin2 service_name4 notebook
	global service_path default_up User service_tag
	variable svc_tag
	variable service_list
	variable listwin
	variable pane2
	variable tf
	variable envFile
	variable varlist
	variable size
	variable textval
	set w .dname

	set Description "Supervise Control"
	set size 0
	set varlist {}
	if {$mode == 1} {
		destroyFirstPage
		if {$authenticated != 1} {
			Login 1
		}
		wm title . $Description
	} else {
		set base .f2
		catch {destroy $base}
		toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief raised
		set x [winfo pointerx .]
		set y [winfo pointery .]
		wm geometry $base +${x}+${y}
		wm focusmodel $base passive
		wm geometry $base 650x450
		wm maxsize $base 1009 738
		wm minsize $base 1 1
		wm overrideredirect $base 0
		wm resizable $base 1 1
		wm title $base "Indium - Supervise Tool"
		set w $base.fr
	}

	bind . <F1> {doHelp svcmgmt}

	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw -expand 1 -fill both
		set pane1  [$pw add -weight 45 -minsize 40]
		set pane2  [$pw add -weight 55 -minsize 10]
		set lf [TitleFrame $pane1.fr -text $Description -side center -relief ridge -bd 2]
		pack $lf -side top -anchor nw -expand 1 -fill both
		set tf [$lf getframe]
		ScrollableFrame $tf.sf -yscrollcommand "$tf.sf.vscroll set" \
			-constrainedwidth true -areawidth 0
		scrollbar $tf.sf.vscroll -command "$tf.sf yview" -trough black -orient vert
		pack $tf.sf -side left -anchor nw -expand 1 -fill both
		pack $tf.sf.vscroll -anchor ne -expand 1 -fill y
		set lwin [$tf.sf getframe].notebook
		set listwin $pane2.lw
		frame $listwin
		pack $listwin -side top -anchor nw
		set dwin $pane2.debug
	} else {
		frame $w -relief ridge -bd 2
		pack $w -side left -ipadx 20 -ipady  20 -expand 1 -fill both -anchor nw
		set lwin $w.left
		set listwin $w.lw
		frame $listwin
		pack $listwin -side top -anchor nw
		set dwin $w.debug
	}

	if {$BWidget_present == 1} {
		set notebook [NoteBook $lwin]
		$notebook compute_size
		pack $notebook -side left -expand 1 -fill x -padx 4 -pady 4 -anchor nw
		set lwin1 [$lwin insert end pref -text "Monitor"]
		set lwin2 [$lwin insert end adv  -text "Config"]
		$notebook raise [$notebook page 0]
	} else {
		set NotebookPages {Monitor Config}
		Notebook:create $lwin -pad 2 -pages $NotebookPages
		set lwin1 [Notebook:frame $lwin Monitor]
		set lwin2 [Notebook:frame $lwin Config]
		pack $lwin -side left -expand 0 -fill both -padx 4 -pady 4 -anchor nw
	}
	.statusBar.lab configure -text $Description

	## Frame 1 #######################################################################
	frame  $lwin1.servicedir
	frame  $lwin1.inittab
	frame  $lwin1.refresh1
	frame  $lwin1.refresh2
	pack   $lwin1.servicedir $lwin1.inittab $lwin1.refresh1 $lwin1.refresh2 -side top -anchor nw
	label  $lwin1.servicedir.label1 -relief flat -text "Service Directory" -bd 2
	catch {exec ls $servicedir} service_list
	combobox $lwin1.servicedir.entry1 \
		-textvariable servicedir \
		-editable true \
		-highlightthickness 1 \
		-borderwidth 2 \
		-command {
			catch {exec ls $servicedir} service_list
			refreshService $lwin1 $listwin $service_list
			dummyProc
		}
	foreach line [glob -nocomplain /service*] {
		$lwin1.servicedir.entry1 list insert end $line
	}
	button $lwin1.servicedir.button \
		-command "set initialdir /;fileDialog $w $lwin1.servicedir.entry1 dir 0" -padx "9" -pady "3" -relief ridge
	balloonHelp $lwin1.servicedir.button "Click to browse for service directory"
	$lwin1.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
	pack $lwin1.servicedir.label1 $lwin1.servicedir.entry1 -side left -fill x -expand 0
	pack $lwin1.servicedir.button -side left
	button $lwin1.servicedir.showall -relief raised -bd 4 -bg IndianRed
	$lwin1.servicedir.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	pack $lwin1.servicedir.showall -side left
	balloonHelp $lwin1.servicedir.showall  "Show/Hide Columns"
	$lwin1.servicedir.showall configure \
		-command {showContextMenu $listwin.list}
	variable initEnable
	if {[catch {exec /usr/sbin/initsvc -status} result] == 0} {
		set initEnable 1
	} else {
		set initEnable 0
	}
	checkbutton $lwin1.inittab.c -text "Enable Inittab/Upstart" -variable initEnable \
		-command {
			if {$initEnable} {
				if {[catch {exec /usr/sbin/initsvc -on} result]} {
					msg_dialog .d {service tool} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
			} else {
				if {[catch {exec /usr/sbin/initsvc -off} result]} {
					msg_dialog .d {service tool} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
			}
			if {[catch {exec /usr/sbin/initsvc -status} result] == 0} {
				set initEnable 1
			} else {
				set initEnable 0
			}
			if {[catch {exec /usr/sbin/initsvc -print} result] == 0} {
				balloonHelp $lwin1.inittab.c $result
			}
			msg_dialog .d {service tool} "Current /etc/inittab entry\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	if {[catch {exec /usr/sbin/initsvc -print} result] == 0} {
		balloonHelp $lwin1.inittab.c $result
	} else {
		balloonHelp $lwin1.inittab.c "Enable svscan in System Startup (inittab or upstart)"
	}
	pack $lwin1.inittab.c -side left -anchor nw
	label $lwin1.refresh1.l  -text "Reread inittab/Upstart"
	button $lwin1.refresh1.b -text "Reread inittab/Upstart" -command {
		if {[file exist /etc/event.t/svscan]} {
			if {[catch {exec /sbin/initctl emit qmailstart} result]} {
				msg_dialog .d {service tool} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				msg_dialog .d {service tool} "initctl emit qmailstart" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				refreshService $lwin1 $listwin $service_list
			}
		} else {
			if {[catch {exec init q} result]} {
				msg_dialog .d {service tool} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				msg_dialog .d {service tool} "Reread inittab" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				refreshService $lwin1 $listwin $service_list
			}
		}
	}
	balloonHelp $lwin1.refresh1.b "Signal init/initctl to restart job"
	if {$User != "postmaster"} {
		$lwin1.inittab.c configure -state disabled
		$lwin1.refresh1.l configure -state disabled
		$lwin1.refresh1.b configure -state disabled
	}
	$lwin1.refresh1.b configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBCRaJBxWJBxOHBRGBCxeLLTatCSKFCymJBQ6BAwmBNzu3AQCBAQOBCRSJKzWrGy+ZDy+NBxSHFSmTBxWHLTWtCyaHCSSFCx6PETKNBQ+FBwaHCRKJMTixLy6vExOTKyqrFxaXDQyNDw+PBQSFHx6fCwuLJyenDQ2NISChLSytJSSlFxeXAwODCQmJBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaBQIBQGBAMBALCcCksGA4IQkJBUDIDC6gVwGhshY5HlMn9DiCRL1MyYE8iiapaSKlALBdMRiPckDkdeXt9HgxkGhWDXB4fH4ZMGnxcICEiI45kQiQkDCUmJZskmUIiJyiPQgyoQwwpH35LqqgMKiEjq5obqh8rLCMtowAkLqovuH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	pack $lwin1.refresh1.b $lwin1.refresh1.l -side left -anchor nw

	label $lwin1.refresh2.l  -text "Refresh Status"
	button $lwin1.refresh2.b -text "Refresh Status" -command {
		set varlist {}
		refreshService $lwin1 $listwin $service_list
		$tf.3.1.entry configure -values $varlist
		set envFile ""
		set textval ""
	}
	balloonHelp $lwin1.refresh2.b "Refresh Service List"
	$lwin1.refresh2.b configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBCRaJBxWJBxOHBRGBCxeLLTatCSKFCymJBQ6BAwmBNzu3AQCBAQOBCRSJKzWrGy+ZDy+NBxSHFSmTBxWHLTWtCyaHCSSFCx6PETKNBQ+FBwaHCRKJMTixLy6vExOTKyqrFxaXDQyNDw+PBQSFHx6fCwuLJyenDQ2NISChLSytJSSlFxeXAwODCQmJBweHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaBQIBQGBAMBALCcCksGA4IQkJBUDIDC6gVwGhshY5HlMn9DiCRL1MyYE8iiapaSKlALBdMRiPckDkdeXt9HgxkGhWDXB4fH4ZMGnxcICEiI45kQiQkDCUmJZskmUIiJyiPQgyoQwwpH35LqqgMKiEjq5obqh8rLCMtowAkLqovuH5BACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	pack $lwin1.refresh2.b $lwin1.refresh2.l -side left -anchor nw
	## Frame 2 #######################################################################
	frame  $lwin1.start -bd 2 -relief ridge
	pack   $lwin1.start -side top -anchor nw -pady 4
	button $lwin1.start.button -text "Start All" \
		-command "svc $lwin1 $listwin upall" -padx "9" -pady "3" -relief ridge
	balloonHelp $lwin1.start.button "Start All Services"
	label  $lwin1.start.label -relief flat -text "Start Services" -bd 2
	pack $lwin1.start.button -side left
	pack $lwin1.start.label -side top -anchor w
	frame $lwin1.start.right
	pack $lwin1.start.right -side left
	combobox $lwin1.start.right.entry \
	-textvariable service_name1 \
	-width 40 \
	-editable false \
	-highlightthickness 1 \
	-borderwidth 2 \
	-command {
		if {$service_name2 != "" && $servicedir != ""} {
			set service_path $servicedir/$service_name2
			set varlist {}
			set envFile ""
			$tf.3.1.entry configure -values $varlist
			set envFile ""
			set textval ""
		}
		dummyProc
	}
	button $lwin1.start.right.button -text "Start" \
		-command "svc $lwin1 $listwin up" -padx "0" -pady "0" -relief flat
	balloonHelp $lwin1.start.right.button "Start the selected Services"
	$lwin1.start.right.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBBRObAwSHBRSdISevBRWfAweLNzu/BSOrAQWLPz6/FzC3DzW5BxObHTS5ByyzAyixEze7BSStBRWdAyWvByixAQSHCQ2TAQCBBRGZJze7CS61BSavAxefMzq9ETW3CSWtAwmPPz+/CzG1ITC3FyuxBSCnAQeLAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAZfQIBwSCwaj8hhQJAkDggFQxMQIBwQhUSyqlgwsFpjg6BwPCARySSstC4eFAqEURlYhoMLBpPRUDYcHXt7RgUeFB8gIU0BIoiKjAcUIwiLSQUkJRsmGIwJJwmEU6OkfkEAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	pack $lwin1.start.right.entry $lwin1.start.right.button -side left
	## Frame 3 #######################################################################
	frame  $lwin1.stop -bd 2 -relief ridge
	pack   $lwin1.stop -side top -anchor nw -pady 4
	label  $lwin1.stop.label -relief flat -text "Stop Services" -bd 2
	pack $lwin1.stop.label   -side top -anchor w
	frame $lwin1.stop.right
	pack $lwin1.stop.right -side left
	combobox $lwin1.stop.right.entry \
	-textvariable service_name2 \
	-editable false \
	-width 40 \
	-highlightthickness 1 \
	-borderwidth 2 \
	-command {
		if {$service_name2 != "" && $servicedir != ""} {
			set service_path $servicedir/$service_name2
			set varlist {}
			set envFile ""
			$tf.3.1.entry configure -values $varlist
			set envFile ""
			set textval ""
		}
		dummyProc
	}
	button $lwin1.stop.right.button -text "Stop" \
		-command "svc $lwin1 $listwin down" -padx "0" -pady "0" -relief flat
	balloonHelp $lwin1.stop.right.button "Stop the selected Services"
	$lwin1.stop.right.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBBRObCRKZBxCXAwyTKTK3Ozy/NTm9GSivAQWHNzu/FzC3IzO5CySrAQOHAyuzETS3CSWtAyOtETa5Aw2VLze7ByWtBy61BSavAxWdBRCXAwqPAQCBDR+nKTe7FS+1Eze7ByixBRmjPz+/AyexAyixAQKFBRqjAQGDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAZeQIBwSCwaj0hAYCkYEJLKguGASEADigWj4bgaHpBINykwSCYRa5HCFFQsF0xGo9lwhpSOwfORYC4gISJ3RAQdIyQYJSAlImNrh4uNJkl5CoKUUBQnjlB4KJ6hokN+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
	pack $lwin1.stop.right.entry $lwin1.stop.right.button -side left
	## Frame 4 #######################################################################
	frame  $lwin1.svc -bd 2 -relief ridge
	pack   $lwin1.svc -side top -anchor nw -pady 4
	frame $lwin1.svc.bottom
	pack $lwin1.svc.bottom -side bottom -anchor nw
	menubutton $lwin1.svc.button -indicatoron "1" -menu "$lwin1.svc.button.m" -padx "2" -pady "4" -relief ridge \
		-text "Signal" -bg orange -bd 2 -width 15
	menu $lwin1.svc.button.m -borderwidth "1" -cursor "" -tearoff "0" 
	pack $lwin1.svc.button -fill x -side top -anchor w
	set flag "-u"
	$lwin1.svc.button.m add radiobutton -value "-u" -variable flag -label "Up Service"
	$lwin1.svc.button.m add radiobutton -value "-d" -variable flag -label "Down Service"
	$lwin1.svc.button.m add radiobutton -value "-o" -variable flag -label "Start Once"
	$lwin1.svc.button.m add radiobutton -value "-p" -variable flag -label "STOP Signal"
	$lwin1.svc.button.m add radiobutton -value "-c" -variable flag -label "CONT Signal"
	$lwin1.svc.button.m add radiobutton -value "-h" -variable flag -label "HUP  Signal"
	$lwin1.svc.button.m add radiobutton -value "-a" -variable flag -label "ALRM Signal"
	$lwin1.svc.button.m add radiobutton -value "-i" -variable flag -label "INT  Signal"
	$lwin1.svc.button.m add radiobutton -value "-t" -variable flag -label "TERM Signal"
	$lwin1.svc.button.m add radiobutton -value "-1" -variable flag -label "USR1 Signal"
	$lwin1.svc.button.m add radiobutton -value "-2" -variable flag -label "USR2 Signal"
	$lwin1.svc.button.m add radiobutton -value "-k" -variable flag -label "KILL Signal"
	$lwin1.svc.button.m add radiobutton -value "-x" -variable flag -label "KILL Supervise"
	button $lwin1.svc.startall  -text StartAll -bg orange \
		-command "svc $lwin1 $listwin upall"   -bd 4 \
		-highlightthickness 2 -highlightbackground black
	balloonHelp $lwin1.svc.startall "Start all Services"
	button $lwin1.svc.stopall   -text StopAll  -bg IndianRed \
		-command "svc $lwin1 $listwin downall" -bd 4 \
		-highlightthickness 2 -highlightbackground black
	balloonHelp $lwin1.svc.stopall "Stop all Services"
	pack $lwin1.svc.startall -side left -anchor nw
	pack $lwin1.svc.stopall  -side left -anchor nw

	combobox $lwin1.svc.bottom.entry \
	-textvariable service_name3 \
	-editable false \
	-width 40 \
	-highlightthickness 1 \
	-bd 2
	set found 0
	foreach line $service_list {
		$lwin1.svc.bottom.entry list insert end $line
	}
	button $lwin1.svc.bottom.button -text "Go" \
		-command "svc $lwin1 $listwin signal" \
		-padx "9" -pady "3" -relief raised
	balloonHelp $lwin1.svc.bottom.button "Issue signal to selected service"
	if {[file exist /usr/share/indimail/indium/images/go.gif]} {
		$lwin1.svc.bottom.button configure -image [image create photo -file /usr/share/indimail/indium/images/go.gif]
	}
	pack $lwin1.svc.bottom.entry $lwin1.svc.bottom.button -side left -anchor nw
	## Frame 1 #######################################################################
	frame  $lwin2.service
	pack   $lwin2.service -side top -anchor nw -fill x
	set service_name4 ""
	label  $lwin2.service.label -relief flat -text "Service Name" -bd 2
	combobox $lwin2.service.entry \
	-width 14 \
	-textvariable service_name4 \
	-editable false \
	-highlightthickness 1 \
	-command "stupidHack $listwin {$service_list}" \
	-bd 2
	foreach line {smtp imap pop3 dbserver indisrvr fetchmail} {
		$lwin2.service.entry list insert end $line
	}
	checkbutton $lwin2.service.c -text "Service Tag" -variable svc_tag \
		-command {
			if {$svc_tag == 0} {
				set service_tag ""
			} else {
				if {$service_tag != ""} {
					getsvcvalue $service_name4 $lwin2 $service_tag
				}
			}
		}
	balloonHelp $lwin2.service.c "Check to Lock Service Tag"
	SpinBox $lwin2.service.te -relief sunken -textvariable service_tag \
		-width 4 -range {0 65534 1} \
		-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell \
		-modifycmd {
			getsvcvalue $service_name4 $lwin2 $service_tag
		}
	pack $lwin2.service.label $lwin2.service.entry -side left -anchor nw
	pack $lwin2.service.c $lwin2.service.te -side left -anchor nw
	set service_tag ""

	## Frame n #######################################################################
	foreach tmpwin "$lwin1 $lwin2" {
		if {$mode == 1} {
			button $tmpwin.quit -text Quit -bg IndianRed \
			-command "destroyWindows;return" -bd 5 \
				-highlightthickness 5 -highlightbackground black
		} else {
			button $tmpwin.quit -text Quit -bg IndianRed \
				-command "destroy .f2;return" -bd 5 \
				-highlightthickness 5 -highlightbackground black
		}
		pack $tmpwin.quit -side top -anchor sw
	}
	scrollbar $listwin.vsb -orient vertical   -trough black \
		-command [list $listwin.list yview]
	scrollbar $listwin.hsb -orient horizontal -trough black \
		-command [list $listwin.list xview]
	mclistbox $listwin.list \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 90 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
		-selectcommand {selectService $tf $listwin.list}\
	    -selectmode single \
	    -xscrollcommand [list $listwin.hsb set] \
	    -yscrollcommand [list $listwin.vsb set]
	bind $listwin.list <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	$listwin.list column add service    -label "Service" -width 25
	$listwin.list column add status     -label "Status"  -width 8
	$listwin.list column add uptimes    -label "Uptime Sec" -width 10
	$listwin.list column add started    -label "Started" -width 21
	$listwin.list column add uptimeh    -label "Uptime Hr"  -width 18
	$listwin.list column add pid        -label "Pid"     -width 8

	$listwin.list label bind service    <ButtonPress-1> "listboxsort %W service"
	$listwin.list label bind status     <ButtonPress-1> "listboxsort %W status"
	$listwin.list label bind uptimes    <ButtonPress-1> "listboxsort %W uptimes"
	$listwin.list label bind started    <ButtonPress-1> "listboxsort %W started"
	$listwin.list label bind uptimeh    <ButtonPress-1> "listboxsort %W uptimeh"
	$listwin.list label bind pid        <ButtonPress-1> "listboxsort %W pid"
	pack $listwin.hsb  -side bottom -fill x
	pack $listwin.vsb  -side right  -fill y
	pack $listwin.list -side left -expand 1 -fill both
	set result ""
	refreshService $lwin1 $listwin $service_list
####################################################################
	TitleFrame $pane2.fr -text "Advanced Configuration" -side center -relief ridge -bd 2
	pack $pane2.fr -side top -pady 5 -anchor nw -expand 1 -fill x
	set tf [$pane2.fr getframe]
	frame $tf.0
	frame $tf.1
	frame $tf.2
	frame $tf.3
	frame $tf.4
	frame $tf.5
	pack $tf.0 $tf.1 $tf.2 $tf.3 $tf.4 $tf.5 -side top -anchor nw

	label $tf.0.l1 -text "Service Path"
	Entry $tf.0.l2 -editable false -textvariable service_path -width 40 -relief sunken -bd 2
	pack $tf.0.l1 $tf.0.l2 -side left -anchor nw
	radiobutton $tf.1.rdb1 -text "Default Up"   -variable default_up -relief flat -value 1 -indicatoron 1
	radiobutton $tf.1.rdb2 -text "Default Down" -variable default_up -relief flat -value 2 -indicatoron 1
	pack $tf.1.rdb1 $tf.1.rdb2 -side top -anchor nw

	button $tf.2.b1 -relief ridge -bd 2 -text "Remove Service" \
		-command {removeService $service_path}
	balloonHelp $tf.2.b1 "Click to remove the selected service"
	$tf.2.b1 configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBAQCBKSipFxaXPz+/MTCxISChDQyNCH5BAEAAAAALAAAAAAQABAAAANQCKrRsZA5EYZ7K5BdugkdlQVCsRHdoGLMRwqw8UWvIKvGwTICQdmGgY7W+92GEJKPdNwBlMYgMlNkSp3QgOxKXAKFWE0UHHlObI3yyFH2JwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	$tf.2.b1 configure -cursor pirate
	label  $tf.2.l  -text "Remove Service"
	pack $tf.2.b1 $tf.2.l -side left -anchor nw

	frame $tf.3.1
	frame $tf.3.2
	pack $tf.3.1 -side top -anchor nw
	pack $tf.3.2 -side top -anchor nw -fill x -expand 1
	label $tf.3.1.l1 -text "Control Variables" -width 15 -justify left -anchor nw
	ComboBox $tf.3.1.entry \
		-textvariable envFile \
		-editable false \
		-height 10 \
		-bd 2 \
		-values $varlist \
		-modifycmd {
			if {$envFile != "" && [info exists service_path] && $service_path != ""} {
				if {[file exists $service_path/variables/$envFile]} {
					set size [file size $service_path/variables/$envFile]
					set f [open $service_path/variables/$envFile r]
					set textval [read -nonewline $f]
					close $f
				}
			}
		}
	button $tf.3.1.b1 -relief raised -text "Edit" -bd 2 \
		-command {
			if {$envFile != ""} {
				if {[file exists $service_path/variables/$envFile]} {
					set filename $service_path/variables/$envFile
					editfile 2
				}
			}
		}
	balloonHelp $tf.3.1.b1 "Edit the selected variable using text editor"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$tf.3.1.b1 configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	button $tf.3.1.b2 -relief ridge -text "Remove" -bd 2 \
		-command {
			if {$envFile != ""} {
				set msg "You are About to delete variable $envFile.\nAre you sure?\nClick OK to continue"
				set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
				if {$action == 1} {
					if {[file exists $service_path/variables/$envFile]} {
						if {[file size $service_path/variables/$envFile]} {
							catch {close [open $service_path/variables/$envFile w+]}
							msg_dialog .d {svctool} "unset variable $envFile" /usr/share/indimail/indium/images/warning.gif 0 "OK"
						} else {
							catch {file delete -force $service_path/variables/$envFile}
							msg_dialog .d {svctool} "deleted variable $envFile" /usr/share/indimail/indium/images/warning.gif 0 "OK"
							set envFile ""
						}
						if {[file exists $service_path/variables/$envFile]} {
							set size [file size $service_path/variables/$envFile]
						}
					}
					set varlist {}
					foreach i [glob -nocomplain $service_path/variables/*] {
						lappend varlist [file tail $i]
					}
					$tf.3.1.entry configure -values $varlist
				}
			}
		}
	balloonHelp $tf.3.1.b2 "Remove the selected variable\nClick once to unset\nClick twice to delete"
	$tf.3.1.b2 configure -cursor pirate -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBAQCBKSipFxaXPz+/MTCxISChDQyNCH5BAEAAAAALAAAAAAQABAAAANQCKrRsZA5EYZ7K5BdugkdlQVCsRHdoGLMRwqw8UWvIKvGwTICQdmGgY7W+92GEJKPdNwBlMYgMlNkSp3QgOxKXAKFWE0UHHlObI3yyFH2JwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	label $tf.3.1.l2 -textvariable size -width 6 -justify left -anchor nw
	label $tf.3.1.l3 -text "Bytes" -justify left -anchor nw
	pack $tf.3.1.l1 $tf.3.1.entry $tf.3.1.b1 $tf.3.1.b2 $tf.3.1.l2 $tf.3.1.l3 -side left -anchor nw
	entry $tf.3.2.e -textvariable textval
	button $tf.3.2.b1 -text save -bd 2 -relief ridge -command {
			if {$envFile != ""} {
				if {$textval != ""} {
					if {[catch {open $service_path/variables/$envFile w} f] } {
						msg_dialog .d {svstat} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
					} else {
						puts $f $textval
						close $f
						msg_dialog .d {svctool} "saved variable $envFile" /usr/share/indimail/indium/images/warning.gif 0 "OK"
					}
				} else {
					catch {close [open $service_path/variables/$envFile w+]}
				}
				set size [file size $service_path/variables/$envFile]
			}
		}
	balloonHelp $tf.3.2.b1 "Save value in the entry box to the variable"
	$tf.3.2.b1 configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBFRSVMTCxKyurPz+/JSWlFRWVJyenKSipJSSlOzu7ISChISGhIyOjHR2dJyanIyKjHx6fMzOzGRiZAQGBFxeXGRmZHRydGxqbAwODOTm5ExOTERGRExKTHx+fGxubNza3Dw+PDQ2NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaAQIAQECgOj0jBgFAoBpBHpaFAbRqRh0F1a30ClAhuNZHwZhViqgFhJizSjIZXQCAoHOKHYw5xRBiAElQTFAoVQgINFBYXGBkZFxYHGRqIDBQbmRwdHgKeH2YgHpmkIR0HAhFeTqSZIhwCFIdIrBsjAgcPXlBERZ4Gu7xCRZVDfkEAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	button $tf.3.2.b2 -text Newva -bd 2 -relief ridge -command {
			if {$service_path != ""} {
				newVariable $lwin2 $tf $service_path
			}
		}
	balloonHelp $tf.3.2.b2 "Create a new variable"
	$tf.3.2.b2 configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBFxaXNze3Ly2rJyanPz+/Ozq7GxqbPz6/GxubNTKxDQyNIyKhHRydERCROTi3PT29Pz29Pzy7PTq3My2pPzu5PTi1NS+rPTq5PTezMyynPTm1Pz69OzWvMyqjPTu5PTm3OzOtOzGrMSehNTCtNS+tAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAZ/QAAgQCwWhUhhQMBkDgKEQFIpKFgLhgMiOl1eC4iEYrtIer+MxsFRRgYe3wLkMWC0qXE5/T6sfiMSExR8Z1YRFRMWF4RwYIcYFhkahH6AGBuRk2YCCBwSFZgdHR6UgB8gkR0hpJsSGCAZoiEiI4QKtyQlFBQeHrVmC8HCw21+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
	pack $tf.3.2.b1  -side left -anchor nw
	pack $tf.3.2.b2  -side left -anchor nw
	pack $tf.3.2.e -side left -anchor nw -fill x -expand 1

	label $tf.4.l -text "Startup Script" -width 15 -justify left -anchor nw
	button $tf.4.b -relief raised -text "Edit" -bd 2 \
		-command {
			set filename $service_path/run;editfile 2
		}
	balloonHelp $tf.4.b "Edit supervise run script"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$tf.4.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	pack $tf.4.l $tf.4.b -side left -anchor nw

	label $tf.5.l -text "Shutdown Script" -width 15 -justify left -anchor nw
	button $tf.5.b -relief raised -text "Edit" -bd 2 \
		-command {set filename $service_path/shutdown;editfile 2}
	balloonHelp $tf.5.b "Edit supervise shutdown script"
	if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
		$tf.5.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
	}
	global shutdown_present
	checkbutton $tf.5.c -variable shutdown_present -state disabled \
		-selectcolor green
	$tf.5.c configure -disabledforeground green
	pack $tf.5.l $tf.5.b $tf.5.c -side left -anchor nw
	if {$User != "postmaster"} {
		$tf.2.b1   configure -state disabled
		$tf.3.1.b1 configure -state disabled
		$tf.3.1.b2 configure -state disabled
		$tf.3.2.b1  configure -state disabled
		$tf.3.2.b2  configure -state disabled
		$tf.3.2.e  configure -state disabled
		$tf.4.b    configure -state disabled
		$tf.5.b    configure -state disabled
	}
}

# REVIEWED
proc dummyProc {args} {
	return
}

proc removeService {path} {
	global servicedir logfd
	variable action
	variable newPath

	if {$path == ""} {
		msg_dialog .d {removeService} "No Service Selected" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return
	}
	set len [string length $servicedir]
	if {[string compare -length $len $path $servicedir]} {
		msg_dialog .d {removeService} "Service should be in $servicedir" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return
	}
	set msg "You are About to Service in $path.\nAre you sure?\nClick OK to continue"
	set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action == 1} {
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Removing Service $path"
		set len [string length $servicedir]
		incr len
		set newPath "$servicedir/.[string range $path $len end]"
		set prgtext "Renaming $path to $newPath"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Renaming $path to $newPath"
		progressDialog
		if {[catch {file rename -force $path $newPath} result]} {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$atime: $result"
			catch {destroy .progress}
			msg_dialog .d {Rename $oldfile to $newfile} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return
		}
		set prgtext "Stopping service $newPath"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Stopping service $newPath"
		if {[catch {exec /usr/bin/svc -d $newPath} result]} {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$atime: $result"
			catch {destroy .progress}
			msg_dialog .d {removeService} "$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return
		}
		set prgtext "Stopping service $newPath/log"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Stopping service $newPath/log"
		if {[catch {exec /usr/bin/svc -d $newPath/log} result]} {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$atime: $result"
			catch {destroy .progress}
			msg_dialog .d {removeService} "$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return
		}
		set prgtext "Deleting $newPath"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Deleting $newPath"
		if {[catch {file delete -force $newPath} result]} {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$atime: $result"
			catch {destroy .progress}
			msg_dialog .d {removeService} "$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return
		}
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Removed $newPath"
		catch {destroy .progress}
		msg_dialog .d {removeService} "Removed Service $path" /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc selectService {w1 w2 args} {
	global service_path servicedir default_up service_name1 service_name2
	global shutdown_present service_name3 envFile varlist
	variable textval
	variable size

	set textval ""
	set size 0
	catch {$w2 curselection} cur_sel
	if {[llength $cur_sel] > 1} {
		return
	}
	if {[info exists args] && [string length $args] > 0} {
		set name   [lindex [$w2 get $args] 0]
		set status [lindex [$w2 get $args] 1]
		set service_name3 $name
		if {$status == "down"} {
			set service_name1 $name
		} else {
			set service_name2 $name
		}
		if {$name != ""} {
			set service_path "$servicedir/$name"
			if {[file exists $service_path/down]} {
				set default_up 2
			} else {
				set default_up 1
			}
			if {[file exists $service_path/shutdown]} {
				set shutdown_present 1
			} else {
				set shutdown_present 0
			}
			set envFile ""
			set varlist {}
			foreach i [glob -nocomplain $service_path/variables/*] {
				lappend varlist [file tail $i]
			}
			$w1.3.1.entry configure -values $varlist
		}
	}
}

proc refreshService {lwin1 listwin service_list} {
	source /usr/share/indimail/indium/scripts/global.tcl
	global service_name1 service_name2 service_name3 BWidget_present service_name1 service_path

	set service_name1 ""
	set service_name2 ""
	set service_name3 ""
	set service_path ""
	$listwin.list delete 0 end
	$lwin1.start.right.entry list delete 0 end
	$lwin1.stop.right.entry  list delete 0 end
	$lwin1.svc.bottom.entry  list delete 0 end
	set dfound 0
	set ufound 0
	$listwin.list delete 0 end
	set svText ""
	foreach line $service_list {
		set cmd "| /usr/bin/svstat $servicedir/$line"
		if {[catch {open $cmd r} f] } {
			msg_dialog .d {svstat} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
			break
		}
		set result [read $f]
		append svText "$result"
		svcListFunc $result $line $listwin
		set returnstatus [catch {close $f} result]
		$lwin1.svc.bottom.entry list insert end $line
		if {$returnstatus == 1} {
			set dfound 1
			$lwin1.start.right.entry list insert end $line
		} else {
			set ufound 1
			$lwin1.stop.right.entry list insert end $line
		}

		if {[file isdirectory $servicedir/$line/log]} {
			set cmd "| /usr/bin/svstat $servicedir/$line/log"
			if {[catch {open $cmd r} f] } {
				msg_dialog .d {svstat} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				break
			}
			set result [read $f]
			append svText "$result"
			svcListFunc $result $line/log $listwin
			set returnstatus [catch {close $f} result]
			if {$returnstatus == 1} {
				set dfound 1
				$lwin1.start.right.entry list insert end $line/log
			} else {
				set ufound 1
				$lwin1.stop.right.entry list insert end $line/log
			}
		}
	}
	balloonHelp .l1.b.scale.e.svc $svText
	if {$dfound} {
		listboxsort $listwin.list status
		$lwin1.start.right.entry select 0
		$lwin1.start.button configure -image [image create photo -file /usr/share/indimail/indium/images/red.gif]
		$lwin1.start.right.entry configure -commandstate normal
	} else {
		listboxsort $listwin.list uptimes
		$lwin1.start.button configure -image [image create photo -file /usr/share/indimail/indium/images/green.gif]
		$lwin1.start.right.entry configure -commandstate disabled
	}
	if {$ufound} {
		$lwin1.stop.right.entry configure -commandstate normal
	} else {
		$lwin1.stop.right.entry configure -commandstate disabled
	}
	.statusBar.lab configure -text "Refreshed Service List"
}

proc svcListFunc {svresult name listwin} {
	set tmval [clock seconds]
	set sv_status [lindex $svresult 1]
	set tmp       [lindex $svresult 3]
	set len [string length $tmp]
	incr len -2
	if {$sv_status == "up"} {
		set sv_pid [string range $tmp 0 $len]
		set sv_uptimes [lindex $svresult 4]
	} else {
		set sv_pid "down"
		set sv_uptimes [lindex $svresult 2]
	}
	set Expr {^[0-9 ]*$}
	if {[regexp $Expr $sv_uptimes] == 0} {
		set sv_uptimes ""
		set sv_uptimeh ""
		set started "supervise not running"
		set sv_status "down"
		set sv_pid "down"
		$listwin.list insert end [list $name $sv_status $sv_uptimes $started $sv_uptimeh $sv_pid]
		return
	}
	set start_time [expr $tmval - $sv_uptimes]
	set started [clock format $start_time -format "%d-%b-%Y %H:%M:%S"]
	set hour [expr $sv_uptimes / 3600]
	set min  [expr [expr $sv_uptimes % 3600] / 60]
	set secs [expr $sv_uptimes % 60]
	set sv_uptimeh [format "%02d Hr %02d M %02d S" $hour $min $secs]
	$listwin.list insert end [list $name $sv_status $sv_uptimes $started $sv_uptimeh $sv_pid]
}

proc stupidHack {listwin service_list win mode} {
	global lwin2
	svcConfig $listwin $service_list $lwin2
}

proc svcConfig {listwin $service_list win} {
	global w BWidget_present svc_controldir service_name4 notebook
	global smtpport qbase qcount qstart servicedir minfree domlimit chkusr antispoofing
	global cugmail chkrelay dynroute rblcheck skipsend authall authself authsmtp authself
	global spamvar masquerade spamfilterargs memory filterlogstatus 
	global filterlog odmr bodycheck bodycheckfile qhpsi qhpsival viruscheck viruscheckval paranoid dmasquerade
	global rejectspam rejectspamv spamexit spamexitcode
	global localfilter remotefilter controldir
	global proxy imapport pop3port destport maxdaemons maxperip nolastauth mailcount_limit \
	       mailsize_limit overquota_mailsize
	global dbfifo_name dbthreads
	global basepath adminport mysqlhost mysqluser mysqlpass avguserquota hardquota
	global folderport filename localips default_domain_val
	global svc_tag service_tag usefsync usesyncdir pwcache qregex dnscheck
	global helocheck helofqdn
	global lwin1

	source /usr/share/indimail/indium/scripts/global.tcl
	set localips {}
	set mysqluser $mysql_user
	set mysqlpass $mysql_pass
	set default_domain_val ""
	set overquota_mailsize -1
	variable mode
	variable tmpwin
	variable dlimit
	set w .dname
	set tmpwin $win

	catch {destroy $win.frame}
	catch {destroy $win.buttons}
	set mode $service_name4
	catch {pack forget $win.quit}
	frame $win.frame -relief groove -bd 2
	pack $win.frame -side top -anchor nw -pady 5 -expand 0
	ipmeprint 1
	if {[llength $localips] > 0} {
		set ipaddress [lindex $localips 0]
	} else {
		set ipaddress ""
	}
	frame $win.buttons
	button $win.buttons.run  -text "Create" -bg orange \
		-bd 4 -highlightthickness 2 -highlightbackground black \
		-command {
			if {[$tmpwin.buttons.run cget -text] == "Modify"} {
				set msg "You are About to Modify Configuration for $mode.\nAre you sure you want to do this?\nClick OK to continue"
				set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
				if {$action == 1} {
					createSvc $mode
					refreshService $lwin1 $listwin $service_list
				}
			} else {
				createSvc $mode
				refreshService $lwin1 $listwin $service_list
			}
		}
	button $win.buttons.quit -text "Cancel" -bg IndianRed \
		-command "set service_name4 \"\";destroy $win.frame;destroy $win.buttons;return" -bd 4 \
		-highlightthickness 2 -highlightbackground black
	switch -regexp $mode {
		smtp {
			$win.service.c  configure -state normal
			$win.service.te configure -state normal
			set smtpport 25
			set service_tag 25
			set maxdaemons 40
			set dnscheck 1
			set helocheck 0
			set helofqdn 0
			set authall 0
			set authself 0
			set authsmtp 0
			frame $win.frame.servicedir
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 15
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0" -padx "9" \
				-pady "3" -relief ridge
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			set svc_controldir $controldir
			frame $win.frame.controldir
			label $win.frame.controldir.label -relief flat -text "Control Dir" -bd 0 -width 15
			entry $win.frame.controldir.entry -relief sunken \
				-textvariable svc_controldir
			button $win.frame.controldir.button \
				-command "set initialdir /etc/indimail;fileDialog $w $win.frame.controldir.entry dir 0" -padx "9" \
				-pady "3" -relief ridge
			balloonHelp $win.frame.controldir.button "Click to browse for qmail's control directory"
			$win.frame.controldir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.controldir.label $win.frame.controldir.entry $win.frame.controldir.button -side left -anchor nw

			frame $win.frame.localip
			label $win.frame.localip.label -relief flat -text "Local IP" -bd 0 -width 15
			ComboBox $win.frame.localip.entry \
				-textvariable ipaddress \
				-editable true \
				-bd 2 \
				-values $localips
			pack $win.frame.localip.label $win.frame.localip.entry -side left -anchor nw

			frame $win.frame.port
			label $win.frame.port.label -relief flat -text "SMTP Port" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.port.entry -relief sunken -textvariable smtpport \
					-width 5 -range {25 65534 1} \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-modifycmd {
						if {$svc_tag == 0} {
							set service_tag $smtpport
							getsvcvalue "smtp" $tmpwin $service_tag
						}
					}
			} else {
				entry $win.frame.port.entry   -relief sunken -textvariable smtpport -width 5 \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-command {
						if {$svc_tag == 0} {
							set service_tag $smtpport
							getsvcvalue "smtp" $tmpwin $service_tag
						}
					}
			}
			set odmr 0
			checkbutton $win.frame.port.c -text "Enable ODMR" -variable odmr \
				-command {
					if {$odmr} {
						$tmpwin.frame.helocheck configure -state disabled
						$tmpwin.frame.helofqdn  configure -state disabled
						$tmpwin.frame.dnscheck configure -state disabled
						$tmpwin.frame.hostaccess.h configure -state disabled
						$tmpwin.frame.hostaccess.d configure -state disabled
						$tmpwin.frame.viruscheck.c configure -state disabled
						$tmpwin.frame.viruscheck.e configure -state disabled
						$tmpwin.frame.qhpsi.c      configure -state disabled
						$tmpwin.frame.qhpsi.e      configure -state disabled
						$tmpwin.frame.bodycheck.c  configure -state disabled
						$tmpwin.frame.bodycheck.e  configure -state disabled
						$tmpwin.frame.qregex   configure -state disabled
						$tmpwin.frame.fsync    configure -state disabled
						$tmpwin.frame.syncdir  configure -state disabled
						$tmpwin.frame.skipsend configure -state disabled
						$tmpwin.frame.dynroute configure -state disabled
						$tmpwin.frame.deliverylimit.c configure -state disabled
						$tmpwin.frame.deliverylimit.entry1 configure -state disabled
						$tmpwin.frame.deliverylimit.entry2 configure -state disabled
						$tmpwin.frame.deliverylimit.l1 configure -state disabled
						$tmpwin.frame.deliverylimit.l2 configure -state disabled
						$tmpwin.frame.chkusr.l configure -state disabled
						$tmpwin.frame.chkusr.c configure -state disabled
						$tmpwin.frame.chkusr.b configure -state disabled
						$tmpwin.frame.domlimit configure -state disabled
						$tmpwin.frame.cugmail configure -state disabled
						$tmpwin.frame.antispoof configure -state disabled
						$tmpwin.frame.authsmtp configure -state disabled
						$tmpwin.frame.authall  configure -state disabled
						$tmpwin.frame.authself  configure -state disabled
						$tmpwin.frame.chkrelay configure -state disabled
						$tmpwin.frame.rblcheck configure -state disabled
						$tmpwin.frame.masquera configure -state disabled
						$tmpwin.frame.spamfilt configure -state disabled
						$tmpwin.frame.qbase.label configure -state disabled
						$tmpwin.frame.qbase.entry configure -state disabled
						$tmpwin.frame.qbase.button configure -state disabled
						$tmpwin.frame.qcount.label configure -state disabled
						$tmpwin.frame.qcount.entry configure -state disabled
						$tmpwin.frame.qstart.label configure -state disabled
						$tmpwin.frame.qstart.entry configure -state disabled
						$tmpwin.frame.minfree.label configure -state disabled
						$tmpwin.frame.minfree.entry configure -state disabled
						$tmpwin.frame.overquota.l configure -state disabled
						$tmpwin.frame.overquota.e configure -state disabled
						$tmpwin.frame.loclfilt configure -state disabled
						$tmpwin.frame.remtfilt configure -state disabled
						$tmpwin.frame.filtstat.c configure -state disabled
						$tmpwin.frame.filtstat.e configure -state disabled
						$tmpwin.frame.args.l   configure -state disabled
						$tmpwin.frame.args.e   configure -state disabled
						$tmpwin.frame.exitco.c configure -state disabled
						$tmpwin.frame.exitco.e configure -state disabled
						$tmpwin.frame.reject.c configure -state disabled
						$tmpwin.frame.reject.s configure -state disabled
						$tmpwin.frame.control.s configure -state disabled
						$tmpwin.frame.control.b configure -state disabled
						set smtpport 366
					} else {
						$tmpwin.frame.helocheck configure -state normal
						$tmpwin.frame.helofqdn  configure -state normal
						$tmpwin.frame.dnscheck configure -state normal
						if {[file exists $svc_controldir/hostaccess]} {
						$tmpwin.frame.hostaccess.h configure -state normal
						$tmpwin.frame.hostaccess.d configure -state normal
						}
						$tmpwin.frame.viruscheck.c configure -state normal
						if {$viruscheck = 1} {
							$tmpwin.frame.viruscheck.e configure -state normal
						}
						$tmpwin.frame.qhpsi.c      configure -state normal
						if {$qhpsi = 1} {
						$tmpwin.frame.qhpsi.e      configure -state normal
						}
						$tmpwin.frame.bodycheck.c configure -state normal
						if {$bodycheck = 1} {
						$tmpwin.frame.bodycheck.e configure -state normal
						}
						$tmpwin.frame.qregex    configure -state normal
						$tmpwin.frame.fsync    configure -state normal
						$tmpwin.frame.syncdir  configure -state normal
						$tmpwin.frame.skipsend configure -state normal
						$tmpwin.frame.dynroute configure -state normal
						$tmpwin.frame.deliverylimit.c configure -state normal
						$tmpwin.frame.deliverylimit.entry1 configure -state normal
						$tmpwin.frame.deliverylimit.entry2 configure -state normal
						$tmpwin.frame.deliverylimit.l1 configure -state normal
						$tmpwin.frame.deliverylimit.l2 configure -state normal
						$tmpwin.frame.chkusr.l configure -state normal
						$tmpwin.frame.chkusr.c configure -state normal
						$tmpwin.frame.chkusr.b configure -state normal
						$tmpwin.frame.domlimit configure -state normal
						$tmpwin.frame.cugmail configure -state normal
						$tmpwin.frame.antispoof configure -state normal
						$tmpwin.frame.authsmtp configure -state normal
						$tmpwin.frame.authall  configure -state normal
						$tmpwin.frame.authself  configure -state normal
						$tmpwin.frame.chkrelay configure -state normal
						$tmpwin.frame.rblcheck configure -state normal
						$tmpwin.frame.masquera configure -state normal
						$tmpwin.frame.spamfilt configure -state normal
						if {$spamvar != 0} {
							$tmpwin.frame.loclfilt  configure -state normal
							$tmpwin.frame.remtfilt configure -state normal
							$tmpwin.frame.filtstat.c configure -state normal
							$tmpwin.frame.filtstat.e configure -state normal
							$tmpwin.frame.args.l   configure -state normal
							$tmpwin.frame.args.e   configure -state normal
							$tmpwin.frame.exitco.c configure -state normal
							$tmpwin.frame.control.s configure -state normal
							$tmpwin.frame.control.b configure -state normal
							if {$spamexit} {
								$tmpwin.frame.exitco.e configure -state normal
								$tmpwin.frame.reject.c configure -state normal
								if {$rejectspam == 1} {
								$tmpwin.frame.reject.s configure -state normal
								} else {
								$tmpwin.frame.reject.s configure -state disabled
								}
							} else {
								$tmpwin.frame.exitco.e configure -state disabled
								$tmpwin.frame.reject.c configure -state disabled
								$tmpwin.frame.reject.s configure -state disabled
							}
						}
						$tmpwin.frame.qbase.label configure -state normal
						$tmpwin.frame.qbase.entry configure -state normal
						$tmpwin.frame.qbase.button configure -state normal
						$tmpwin.frame.qcount.label configure -state normal
						$tmpwin.frame.qcount.entry configure -state normal
						$tmpwin.frame.qstart.label configure -state normal
						$tmpwin.frame.qstart.entry configure -state normal
						$tmpwin.frame.minfree.label configure -state normal
						$tmpwin.frame.minfree.entry configure -state normal
						$tmpwin.frame.overquota.l configure -state normal
						$tmpwin.frame.overquota.e configure -state normal
						set smtpport 25
					}
				}
			balloonHelp $win.frame.port.c "Enable On Demand Mail Relay Protocol"
			pack $win.frame.port.label $win.frame.port.entry $win.frame.port.c \
				-side left -anchor nw

			frame $win.frame.maxdaemons
			label $win.frame.maxdaemons.label -relief flat -text "Max Concurrency" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxdaemons.entry -relief sunken -textvariable maxdaemons \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxdaemons.entry   -relief sunken -textvariable maxdaemons -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxdaemons.label $win.frame.maxdaemons.entry -side left -anchor nw

			frame $win.frame.maxperip
			label $win.frame.maxperip.label -relief flat -text "Max Per IP" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxperip.entry -relief sunken -textvariable maxperip \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxperip.entry   -relief sunken -textvariable maxperip -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxperip.label $win.frame.maxperip.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			frame $win.frame.qbase
			label $win.frame.qbase.label -relief flat -text "Queue Base" -bd 0 -width 15
			entry $win.frame.qbase.entry -relief sunken -textvariable qbase
			button $win.frame.qbase.button \
				-padx "9" -pady "3" -relief ridge \
				-command "set initialdir /queue;fileDialog $w $win.frame.qbase.entry dir 0"
			balloonHelp $win.frame.qbase.button "Click to browse for base directory for queue"
			$win.frame.qbase.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.qbase.label $win.frame.qbase.entry $win.frame.qbase.button -side left -anchor nw

			frame $win.frame.qcount
			label $win.frame.qcount.label -relief flat -text "Queue Count" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.qcount.entry -relief sunken -textvariable qcount \
					-width 5 -range {1 40 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.qcount.entry   -relief sunken -textvariable qcount -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.qcount.label $win.frame.qcount.entry -side left -anchor nw

			frame $win.frame.qstart
			label $win.frame.qstart.label -relief flat -text "First Queue No" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.qstart.entry -relief sunken -textvariable qstart \
					-width 5 -range {1 40 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.qstart.entry   -relief sunken -textvariable qstart -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.qstart.label $win.frame.qstart.entry -side left -anchor nw

			frame $win.frame.minfree
			label $win.frame.minfree.label -relief flat -text "Min Free (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.minfree.entry -relief sunken -textvariable minfree \
					-width 5 -range {50 1024 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.minfree.entry   -relief sunken -textvariable minfree -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.minfree.label $win.frame.minfree.entry -side left -anchor nw

			checkbutton $win.frame.qregex -text "Use QREGEX" -variable qregex
			balloonHelp $win.frame.qregex  "Turn on regular expressions on\n\
				badmailfrom\n\
				badrcptto\n\
				blackholesenders\n\
				spamignore\n\
				relaymailfrom\n\
				authdomains\n\
				badhelo\n\
				chkuserdomains"
			checkbutton $win.frame.fsync  -text "Use FSYNC" -variable usefsync
			balloonHelp $win.frame.fsync "Turn on fsync when writing files"
			checkbutton $win.frame.syncdir    -text "Use SYNCDIR" -variable usesyncdir
			balloonHelp $win.frame.syncdir "Turn on directory syncing"

			frame $win.frame.hostaccess
			checkbutton $win.frame.hostaccess.h -text "Paranoid Host Access" \
				-variable paranoid
			checkbutton $win.frame.hostaccess.d -text "Allow Domain Masquerade" \
				-variable dmasquerade
			pack $win.frame.hostaccess.h $win.frame.hostaccess.d -side top -anchor nw
			balloonHelp $win.frame.hostaccess.h \
				"Allow SMTP Access only from domain/IP Address pair \
				\rListed in control file hostaccess. Default is to allow\
				\rif domain is not listed in the control file hostaccess"
			balloonHelp $win.frame.hostaccess.d \
				"Allow domains to be masqueraded from known \
				\rIP addresses"

			if {[file exists $svc_controldir/hostaccess]} {
				$win.frame.hostaccess.h configure -state normal
				$win.frame.hostaccess.d configure -state normal
			} else {
				$win.frame.hostaccess.h configure -state disabled
				$win.frame.hostaccess.d configure -state disabled
			}

			checkbutton $win.frame.dnscheck  -text "Enable Sender Domain DNS MX check" \
				-variable dnscheck
			balloonHelp $win.frame.dnscheck \
				"Check existense of MX for sender domains\n\
				MAIL FROM is rejected if sender domain\n\
				does not have a MX record"

			checkbutton $win.frame.helofqdn  -text "Force HELO/EHLO FQDN" \
				-variable helofqdn
			balloonHelp $win.frame.helofqdn "Enforce HELO/EHLO to have . in the name"
			checkbutton $win.frame.helocheck -text "Bad HELO/EHLO check" \
				-variable helocheck
			balloonHelp $win.frame.helocheck \
				"Force HELO/EHLO argument to be a valid domain\n\
				Useful SPAM control but breaks RFC 2821"
			checkbutton $win.frame.skipsend   -text "Skip Send" -variable skipsend \
				-command {
					if {$skipsend} {
						set dlimit 0
						set dynroute 0
						set mailcount_limit -1
						set mailsize_limit -1
						$tmpwin.frame.dynroute configure -state disabled
						$tmpwin.frame.deliverylimit.c configure -state disabled
						$tmpwin.frame.deliverylimit.entry1 configure -state disabled
						$tmpwin.frame.deliverylimit.entry2 configure -state disabled
					} else {
						$tmpwin.frame.dynroute configure -state normal
						$tmpwin.frame.deliverylimit.c configure -state normal
						$tmpwin.frame.deliverylimit.entry1 configure -state normal
						$tmpwin.frame.deliverylimit.entry2 configure -state normal
					}
				}
			balloonHelp $win.frame.skipsend "Turn off delivery (Enable SMTP only)"
			checkbutton $win.frame.dynroute   -text "Dynamic Routing" \
				-variable dynroute
			balloonHelp $win.frame.dynroute "Enable Dynamic Routing for Clustered Domains"

			frame $win.frame.overquota
			label $win.frame.overquota.l -text "Overquota Size"
			if {$BWidget_present} {
				SpinBox $win.frame.overquota.e -relief sunken -textvariable overquota_mailsize \
					-width 5 -range {1000 4096 100} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.overquota.e -relief sunken -textvariable overquota_mailsize \
					-width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			balloonHelp $win.frame.overquota.e "Max size of mails (Bytes) to allow after user is overquota"
			pack $win.frame.overquota.l $win.frame.overquota.e -side left -anchor nw

			frame $win.frame.deliverylimit
			checkbutton $win.frame.deliverylimit.c -text "DeliveryLimits" -width 12 \
				-justify left -anchor nw -variable dlimit -command {
				if {$dlimit} {
					set mailcount_limit 150
					set mailsize_limit 10
					$tmpwin.frame.deliverylimit.entry1 configure -state normal
					$tmpwin.frame.deliverylimit.entry2 configure -state normal
				} else {
					$tmpwin.frame.deliverylimit.entry1 configure -state disabled
					$tmpwin.frame.deliverylimit.entry2 configure -state disabled
					set mailcount_limit -1
					set mailsize_limit -1
				}
			}
			balloonHelp $win.frame.deliverylimit.c "Impose a limit on count/size of Mails delivered in a day"
			$win.frame.deliverylimit.c deselect
			if {$BWidget_present} {
				label $win.frame.deliverylimit.l1 -text "Count" -bd 2 -padx 2
				SpinBox $win.frame.deliverylimit.entry1 -relief sunken -textvariable mailcount_limit \
					-width 5 -range {150 1024 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
				label $win.frame.deliverylimit.l2 -text "Total Size" -bd 2 -padx 2
				SpinBox $win.frame.deliverylimit.entry2 -relief sunken -textvariable mailsize_limit \
					-width 5 -range {10 10000 10} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				label $win.frame.deliverylimit.l1 -text "Count" -bd 2
				entry $win.frame.deliverylimit.entry1   -relief sunken -textvariable mailcount_limit -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
				label $win.frame.deliverylimit.l2 -text "Total Size" -bd 2
				entry $win.frame.deliverylimit.entry2   -relief sunken -textvariable mailsize_limit -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			balloonHelp $win.frame.deliverylimit.entry1 "Impose a limit on count of Mails delivered in a day"
			balloonHelp $win.frame.deliverylimit.entry2 "Impose a limit on size (MB) of Mails delivered in a day"
			if {$skipsend} {
				set dlimit 0
				set mailcount_limit -1
				set mailsize_limit -1
				set dynroute 0
				$tmpwin.frame.dynroute configure -state disabled
				$tmpwin.frame.deliverylimit.c configure -state disabled
			} else {
				$tmpwin.frame.dynroute configure -state normal
				$tmpwin.frame.deliverylimit.c configure -state normal
			}
			if {$dlimit} {
				$tmpwin.frame.deliverylimit.entry1 configure -state normal
				$tmpwin.frame.deliverylimit.entry2 configure -state normal
			} else {
				$tmpwin.frame.deliverylimit.entry1 configure -state disabled
				$tmpwin.frame.deliverylimit.entry2 configure -state disabled
				set mailcount_limit -1
				set mailsize_limit -1
			}
			pack $win.frame.deliverylimit.c      -side left -anchor nw
			pack $win.frame.deliverylimit.l1     -side left -anchor nw
			pack $win.frame.deliverylimit.entry1 -side left -anchor nw
			pack $win.frame.deliverylimit.l2     -side left -anchor nw
			pack $win.frame.deliverylimit.entry2 -side left -anchor nw

			checkbutton $win.frame.domlimit   -text "Domain Limit" \
				-variable domlimit
			balloonHelp $win.frame.domlimit "Impose Domain limits on SMTP service"

			frame $win.frame.chkusr
			checkbutton $win.frame.chkusr.c   -text "Check Recipients"      -variable chkusr
			balloonHelp $win.frame.chkusr.c "Accept mails for valid recipients only"
			label $win.frame.chkusr.l -text "Check Recipient Domains"
			button $win.frame.chkusr.b -relief raised -text "Edit" -bd 2 \
				-state normal \
				-command "set filename $svc_controldir/chkrcptdomains; editfile 2"
			balloonHelp $win.frame.chkusr.b "Edit chkrcptdomains control file"
			if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
				$win.frame.chkusr.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
			}
			pack $win.frame.chkusr.c $win.frame.chkusr.b $win.frame.chkusr.l -side left -anchor nw

			checkbutton $win.frame.cugmail  -text "Enforce CUG Mail" \
				-variable cugmail
			balloonHelp $win.frame.cugmail \
				"Allow SMTP only from local users and\n\
				validate user before accepting mails"

			checkbutton $win.frame.antispoof  -text "Anti Spoofing" \
				-variable antispoofing
			balloonHelp $win.frame.antispoof "Enable Anti Spoofing Code"

			checkbutton $win.frame.authsmtp   -text "Enforce Auth SMTP" \
				-variable authsmtp -command {
					if {$authsmtp} {
						$tmpwin.frame.authall  configure -state disabled
						$tmpwin.frame.chkrelay configure -state disabled
					} else {
						$tmpwin.frame.authall configure -state normal
						if {$authall} {
							$tmpwin.frame.chkrelay configure -state disabled
						} else {
							$tmpwin.frame.chkrelay configure -state normal
						}
					}
				}
			balloonHelp $win.frame.authsmtp \
				"Enforce Authenticated SMTP before \
				\raccepting MAIL FROM command"

			checkbutton $win.frame.authall   -text "Auth All" \
				-variable authall -command {
					if {$authall} {
						$tmpwin.frame.chkrelay configure -state disabled
					} else {
						$tmpwin.frame.chkrelay configure -state normal
					}
				}
			balloonHelp $win.frame.authall \
				"Accept mails (local and remote) only from authenticated users. \
				\rAuthentication may be via AUTH SMTP or \
				\rPOP/IMAP before SMTP"

			checkbutton $win.frame.authself   -text "Persistent Connections" \
				-variable authself
			balloonHelp $win.frame.authself \
				"Force local deliveries to maintain persistent database connections \
				\rCausing significant efficiencies in getting results from the database"

			checkbutton $win.frame.chkrelay   -text "Check Relay" \
				-variable chkrelay
			balloonHelp $win.frame.chkrelay \
				"Relay mails to remote domains only from \
				\rauthenticated users. \
				\rAuthentication may be via AUTH SMTP or \
				\rPOP/IMAP before SMTP"

			frame $win.frame.viruscheck
			checkbutton $win.frame.viruscheck.c  -text "Virus Filter" \
				-variable viruscheck -command {
				if {$viruscheck} {
					set viruscheckval 1
					$tmpwin.frame.viruscheck.e configure -state normal
				} else {
					$tmpwin.frame.viruscheck.e configure -state disabled
				}
			}
			balloonHelp $win.frame.viruscheck.c "Enable Virus Scanner\n1 - Internal Scanner\n2 - Internal+External Scanner\n3 - Internal+Attachment Scanner\n4 - Internal+External+Attachment Scanner\n5 - External+Attachment Scanner\n6 - External Scanner\n7 - Attachment Scanner"
			SpinBox $win.frame.viruscheck.e -relief sunken -textvariable viruscheckval \
				-width 3 -range {0 7 1} -vcmd {regexp {^[0-9]*$} %P} \
				-validate key -invcmd bell
			if {$viruscheck} {
				$tmpwin.frame.viruscheck.e configure -state normal
			} else {
				$tmpwin.frame.viruscheck.e configure -state disabled
			}
			pack $win.frame.viruscheck.c $win.frame.viruscheck.e -side left -anchor nw

			frame $win.frame.qhpsi
			checkbutton $win.frame.qhpsi.c  -text "QHPSI" \
				-variable qhpsi -command {
				if {$qhpsi} {
					$tmpwin.frame.qhpsi.e configure -state normal
				} else {
					$tmpwin.frame.qhpsi.e configure -state disabled
				}
			}
			balloonHelp $win.frame.qhpsi.c "Enable Qmail High Performance Virus Scanner"
			entry $win.frame.qhpsi.e -textvariable qhpsival -bd 2 -width 40
			if {$qhpsi} {
				$tmpwin.frame.qhpsi.e configure -state normal
			} else {
				$tmpwin.frame.qhpsi.e configure -state disabled
			}
			pack $win.frame.qhpsi.c $win.frame.qhpsi.e -side left -anchor nw

			frame $win.frame.bodycheck
			checkbutton $win.frame.bodycheck.c  -text "Content Filter" \
				-variable bodycheck -command {
				if {$bodycheck} {
					$tmpwin.frame.bodycheck.e configure -state normal
				} else {
					$tmpwin.frame.bodycheck.e configure -state disabled
				}
			}
			entry $win.frame.bodycheck.e -textvariable bodycheckfile -bd 2 -width 30
			if {$bodycheck} {
				$tmpwin.frame.bodycheck.e configure -state normal
			} else {
				$tmpwin.frame.bodycheck.e configure -state disabled
			}
			pack $win.frame.bodycheck.c $win.frame.bodycheck.e -side left -anchor nw
			balloonHelp $win.frame.bodycheck.c "Enable content Filtering in SMTP"
			balloonHelp $win.frame.bodycheck.e "Enter a filename (if different from the control file 'bodycheck'"
			checkbutton $win.frame.rblcheck   -text "RBL Check" \
				-variable rblcheck
			balloonHelp $win.frame.rblcheck "Check agains RBL before accepting mails"
			checkbutton $win.frame.masquera   -text "Enable Masquerade" \
				-variable masquerade
			balloonHelp $win.frame.masquera "Enable envelope sender to be changed"
			checkbutton $win.frame.spamfilt   -text "Spam Filter" \
				-variable spamvar -command {
				if {$spamvar} {
					$tmpwin.frame.loclfilt  configure -state normal
					$tmpwin.frame.remtfilt configure -state normal
					$tmpwin.frame.filtstat.c configure -state normal
					$tmpwin.frame.filtstat.e configure -state normal
					$tmpwin.frame.args.l   configure -state normal
					$tmpwin.frame.args.e   configure -state normal
					$tmpwin.frame.exitco.c configure -state normal
					$tmpwin.frame.control.s configure -state normal
					$tmpwin.frame.control.b configure -state normal
					if {$spamexit} {
						$tmpwin.frame.exitco.e configure -state normal
						$tmpwin.frame.reject.c configure -state normal
						if {$rejectspam == 1} {
						$tmpwin.frame.reject.s configure -state normal
						} else {
						$tmpwin.frame.reject.s configure -state disabled
						}
					} else {
						$tmpwin.frame.exitco.e configure -state disabled
						$tmpwin.frame.reject.c configure -state disabled
						$tmpwin.frame.reject.s configure -state disabled
					}
				} else {
					$tmpwin.frame.loclfilt  configure -state disabled
					$tmpwin.frame.remtfilt configure -state disabled
					$tmpwin.frame.filtstat.c configure -state disabled
					$tmpwin.frame.filtstat.e configure -state disabled
					$tmpwin.frame.args.l   configure -state disabled
					$tmpwin.frame.args.e   configure -state disabled
					$tmpwin.frame.exitco.c configure -state disabled
					$tmpwin.frame.exitco.e configure -state disabled
					$tmpwin.frame.reject.c configure -state disabled
					$tmpwin.frame.reject.s configure -state disabled
					$tmpwin.frame.control.s configure -state disabled
					$tmpwin.frame.control.b configure -state disabled
				}
			}
			balloonHelp $win.frame.spamfilt "Turn on SPAM filter"
			checkbutton $win.frame.loclfilt -text "Local  Filter" -variable localfilter
			balloonHelp $win.frame.loclfilt "Turn on SPAM filtering of local mails"
			checkbutton $win.frame.remtfilt -text "Remote Filter" -variable remotefilter
			balloonHelp $win.frame.remtfilt "Turn on SPAM filtering of remote mails"
			frame $win.frame.filtstat
			checkbutton $win.frame.filtstat.c -text "SPAM Status Logging" \
				-variable filterlogstatus -command {
					if {$filterlogstatus} {
						$tmpwin.frame.filtstat.e configure -state normal
					} else {
						set filterlog ""
						$tmpwin.frame.filtstat.e configure -state disabled
					}
				}
			entry $win.frame.filtstat.e -textvariable filterlog -bd 2 -width 20
			pack $win.frame.filtstat.c $win.frame.filtstat.e -side left -anchor nw
			balloonHelp $win.frame.filtstat.c "Enable logging of SPAM rating"

			frame $win.frame.args
			label $win.frame.args.l -text "Filter Arguments" -width 16 -justify left -anchor nw
			set spamfilterargs "/usr/bin/bogofilter -p -d /etc/indimail"
			entry $win.frame.args.e -textvariable spamfilterargs -bd 2 \
				-width 30 -state disabled
			pack $win.frame.args.l $win.frame.args.e -side left -anchor nw

			frame $win.frame.exitco
			set spamexitcode ""
			set rejectspamv ""
			checkbutton $win.frame.exitco.c -width 15 -text "Spamexit Code" \
				-anchor nw \
				-variable spamexit -command {
					if {$spamexit} {
						$tmpwin.frame.exitco.e configure -state normal
						$tmpwin.frame.reject.c configure -state normal
						if {$rejectspam == 1} {
						$tmpwin.frame.reject.s configure -state normal
						} else {
						$tmpwin.frame.reject.s configure -state disabled
						}
					} else {
						$tmpwin.frame.exitco.e configure -state disabled
						$tmpwin.frame.reject.c configure -state disabled
						set rejectspam 0
						set rejectspamv ""
						set spamexitcode ""
						$tmpwin.frame.reject.s configure -state disabled
					}
				}
			balloonHelp $win.frame.exitco.c "Enable checking of exit code\nfrom spam filter program"
			SpinBox $win.frame.exitco.e -relief sunken -textvariable spamexitcode \
				-width 5 -range {0 255 1} -vcmd {regexp {^[0-9]*$} %P} \
				-validate key -invcmd bell
			if {$spamexit} {
				$tmpwin.frame.exitco.e configure -state normal
			} else {
				$tmpwin.frame.exitco.e configure -state disabled
			}
			pack $win.frame.exitco.c $win.frame.exitco.e -side left -anchor nw

			frame $win.frame.reject
			checkbutton $win.frame.reject.c -width 15 -text "Reject Spam" \
				-anchor nw \
				-variable rejectspam -command {
					if {$rejectspam == 0} {
						set rejectspamv ""
						$tmpwin.frame.reject.s configure -state disabled
					} else {
						set rejectspamv 1
						$tmpwin.frame.reject.s configure -state normal
					}
				}
			balloonHelp $win.frame.reject.c "How to handle SPAM\n0 - Accept SPAM\n1 - Reject SPAM\n2 - Blackhole SPAM"
			SpinBox $win.frame.reject.s -relief sunken -textvariable rejectspamv \
				-width 5 -range {0 255 1} -vcmd {regexp {^[0-9]*$} %P} \
				-validate key -invcmd bell
			pack $win.frame.reject.c $win.frame.reject.s -side left -anchor nw

			frame $win.frame.control
			button $win.frame.control.b -relief raised -text "Edit" -bd 2 \
				-command {
						if {$spamfile != ""} {
							if {[string index $svc_controldir 0] == "/"} {
								set filename $svc_controldir/$spamfile
							} else {
								set filename /etc/indimail/$svc_controldir/$spamfile
							}
							editfile 2
						} else {
							msg_dialog .d {svctool} "spam control file not selected" /usr/share/indimail/indium/images/warning.gif 0 "OK"
						}
					}
			balloonHelp $win.frame.control.b "Click to edit the selected spam control file"
			if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
				$win.frame.control.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
			}
			ComboBox $win.frame.control.s \
				-textvariable spamfile \
				-editable false \
				-bd 2 \
				-values {spamignore spamignorepatterns spamignoreheaders \
					rejectspam globalspamredirect spamredirect spamfilterargs \
					filterargs badhelo badmailfrom badrcptto spamdb bodycheck \
					signatures hostaccess badext badextpatterns}
			pack $win.frame.control.b $win.frame.control.s -side left -anchor nw

			if {$authsmtp} {
				$tmpwin.frame.authall  configure -state disabled
				$tmpwin.frame.chkrelay configure -state disabled
			} else {
				$tmpwin.frame.authall configure -state normal
				if {$authall} {
					$tmpwin.frame.chkrelay configure -state disabled
				} else {
					$tmpwin.frame.chkrelay configure -state normal
				}
			}
			if {$spamvar} {
				$tmpwin.frame.loclfilt  configure -state normal
				$tmpwin.frame.remtfilt configure -state normal
				$tmpwin.frame.filtstat.c configure -state normal
				$tmpwin.frame.filtstat.e configure -state normal
				$tmpwin.frame.args.l   configure -state normal
				$tmpwin.frame.args.e   configure -state normal
				$tmpwin.frame.control.s configure -state normal
				$tmpwin.frame.control.b configure -state normal
				$tmpwin.frame.exitco.c configure -state normal
				if {$spamexit} {
					$tmpwin.frame.exitco.e configure -state normal
					$tmpwin.frame.reject.c configure -state normal
					if {$rejectspam == 1} {
					$tmpwin.frame.reject.s configure -state normal
					} else {
					$tmpwin.frame.reject.s configure -state disabled
					}
				} else {
					$tmpwin.frame.reject.c configure -state disabled
					$tmpwin.frame.exitco.e configure -state disabled
					$tmpwin.frame.reject.s configure -state disabled
				}
			} else {
				$tmpwin.frame.loclfilt  configure -state disabled
				$tmpwin.frame.remtfilt configure -state disabled
				$tmpwin.frame.filtstat.c configure -state disabled
				$tmpwin.frame.filtstat.e configure -state disabled
				$tmpwin.frame.args.l   configure -state disabled
				$tmpwin.frame.args.e   configure -state disabled
				$tmpwin.frame.reject.c configure -state disabled
				$tmpwin.frame.reject.s configure -state disabled
				$tmpwin.frame.control.s configure -state disabled
				$tmpwin.frame.control.b configure -state disabled
				$tmpwin.frame.exitco.c configure -state disabled
				$tmpwin.frame.exitco.e configure -state disabled
			}
			pack $win.frame.servicedir -side top -anchor nw
			pack $win.frame.controldir -side top -anchor nw
			pack $win.frame.localip    -side top -anchor nw
			pack $win.frame.port       -side top -anchor nw
			pack $win.frame.maxdaemons -side top -anchor nw
			pack $win.frame.maxperip   -side top -anchor nw
			pack $win.frame.memory     -side top -anchor nw
			pack $win.frame.qbase      -side top -anchor nw
			pack $win.frame.qcount     -side top -anchor nw
			pack $win.frame.qstart     -side top -anchor nw
			pack $win.frame.minfree    -side top -anchor nw
			pack $win.frame.skipsend   -side top -anchor nw
			pack $win.frame.dynroute   -side top -anchor nw
			pack $win.frame.overquota  -side top -anchor nw
			pack $win.frame.deliverylimit -side top -anchor nw
			pack $win.frame.domlimit   -side top -anchor nw
			pack $win.frame.qregex     -side top -anchor nw
			pack $win.frame.fsync      -side top -anchor nw
			pack $win.frame.syncdir    -side top -anchor nw
			pack $win.frame.hostaccess -side top -anchor nw
			pack $win.frame.dnscheck   -side top -anchor nw
			pack $win.frame.helofqdn   -side top -anchor nw
			pack $win.frame.helocheck  -side top -anchor nw
			pack $win.frame.chkusr     -side top -anchor nw
			pack $win.frame.cugmail    -side top -anchor nw
			pack $win.frame.antispoof  -side top -anchor nw
			pack $win.frame.authsmtp   -side top -anchor nw
			pack $win.frame.authall    -side top -anchor nw
			pack $win.frame.authself   -side top -anchor nw
			pack $win.frame.masquera   -side top -anchor nw
			pack $win.frame.chkrelay   -side top -anchor nw
			pack $win.frame.rblcheck   -side top -anchor nw
			pack $win.frame.viruscheck -side top -anchor nw
			pack $win.frame.qhpsi      -side top -anchor nw
			pack $win.frame.bodycheck  -side top -anchor nw
			pack $win.frame.spamfilt   -side top -anchor nw
			pack $win.frame.loclfilt   -side top -anchor nw
			pack $win.frame.remtfilt   -side top -anchor nw
			pack $win.frame.filtstat   -side top -anchor nw
			pack $win.frame.args       -side top -anchor nw
			pack $win.frame.exitco     -side top -anchor nw
			pack $win.frame.reject     -side top -anchor nw
			pack $win.frame.control    -side top -anchor nw
			$win.frame.chkusr.c select
			$win.frame.chkrelay select
			getsvcvalue "smtp" $tmpwin $smtpport
		}
		imap {
			$win.service.c  configure -state normal
			$win.service.te configure -state normal
			set imapport 143
			set destport 143
			set service_tag 143
			set maxdaemons 40
			frame $win.frame.servicedir
			pack $win.frame.servicedir -side top -anchor nw -fill x
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 15
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-padx "9" -pady "3" -relief ridge \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0"
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			frame $win.frame.domain
			pack $win.frame.domain -side top -anchor nw -fill x
			label $win.frame.domain.label -relief flat -text "Default Domain" -bd 0 -width 15
			ComboBox $win.frame.domain.entry \
				-textvariable default_domain_val \
				-editable false \
				-bd 2 \
				-values $domain_list
			pack $win.frame.domain.label $win.frame.domain.entry -side left -anchor nw

			frame $win.frame.localip
			pack $win.frame.localip -side top -anchor nw -fill x
			label $win.frame.localip.label -relief flat -text "Local IP" -bd 0 -width 15
			ComboBox $win.frame.localip.entry \
				-textvariable ipaddress \
				-editable true \
				-bd 2 \
				-values $localips
			pack $win.frame.localip.label $win.frame.localip.entry -side left -anchor nw

			frame $win.frame.port
			pack $win.frame.port -side top -anchor nw -fill x
			label $win.frame.port.label -relief flat -text "IMAP Port" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.port.entry -relief sunken -textvariable imapport \
					-width 5 -range {143 65534 1} \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-modifycmd {
						if {$svc_tag == 0} {
							set service_tag $imapport
							getsvcvalue "imap" $tmpwin $service_tag
						}
					}
			} else {
				entry $win.frame.port.entry   -relief sunken -textvariable imapport -width 5 \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-command {
						if {$svc_tag == 0} {
							set service_tag $imapport
							getsvcvalue "imap" $tmpwin $service_tag
						}
					}
			}
			pack $win.frame.port.label $win.frame.port.entry -side left -anchor nw

			frame $win.frame.maxdaemons
			pack $win.frame.maxdaemons -side top -anchor nw -fill x
			label $win.frame.maxdaemons.label -relief flat -text "Max Concurrency" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxdaemons.entry -relief sunken -textvariable maxdaemons \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxdaemons.entry   -relief sunken -textvariable maxdaemons -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxdaemons.label $win.frame.maxdaemons.entry -side left -anchor nw

			frame $win.frame.maxperip
			pack $win.frame.maxperip -side top -anchor nw -fill x
			label $win.frame.maxperip.label -relief flat -text "Max Per IP" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxperip.entry -relief sunken -textvariable maxperip \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxperip.entry   -relief sunken -textvariable maxperip -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxperip.label $win.frame.maxperip.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			pack $win.frame.memory -side top -anchor nw -fill x
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			checkbutton $win.frame.domlimit   -text "Domain Limit" \
				-variable domlimit
			balloonHelp $win.frame.domlimit "Impose Domain limits on IMAP service"
			checkbutton $win.frame.lastauth   -text "Skip Lastlog" \
				-variable nolastauth
			balloonHelp $win.frame.lastauth "Disable logging of Last Authencition"
			set proxy 0
			checkbutton $win.frame.proxy      -text "Proxy Mode"  \
				-variable proxy -command {
					if {$proxy} {
						$tmpwin.frame.destport.label configure -state normal
						$tmpwin.frame.destport.entry configure -state normal
					} else {
						$tmpwin.frame.destport.label configure -state disabled
						$tmpwin.frame.destport.entry configure -state disabled
					}
				}
			balloonHelp $win.frame.proxy "Setup the service as an IMAP proxy"
			pack $win.frame.domlimit   -side top -anchor nw
			pack $win.frame.lastauth   -side top -anchor nw
			pack $win.frame.proxy      -side top -anchor nw

			frame $win.frame.destport
			pack $win.frame.destport -side top -anchor nw -fill x
			label $win.frame.destport.label -relief flat -text "Dest IMAP Port" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.destport.entry -relief sunken -textvariable destport \
					-width 5 -range {25 65534 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.destport.entry   -relief sunken -textvariable destport -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.destport.label $win.frame.destport.entry -side left -anchor nw
			if {$proxy} {
				$win.frame.destport.label configure -state normal
				$win.frame.destport.entry configure -state normal
			} else {
				$win.frame.destport.label configure -state disabled
				$win.frame.destport.entry configure -state disabled
			}
			getsvcvalue "imap" $tmpwin $imapport
		}
		pop3 {
			$win.service.c  configure -state normal
			$win.service.te configure -state normal
			set pop3port 110
			set destport 110
			set service_tag 110
			set maxdaemons 40
			frame $win.frame.servicedir
			pack $win.frame.servicedir -side top -anchor nw -fill x
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 15
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0"
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			frame $win.frame.domain
			pack $win.frame.domain -side top -anchor nw -fill x
			label $win.frame.domain.label -relief flat -text "Default Domain" -bd 0 -width 15
			ComboBox $win.frame.domain.entry \
				-textvariable default_domain_val \
				-editable false \
				-bd 2 \
				-values $domain_list
			pack $win.frame.domain.label $win.frame.domain.entry -side left -anchor nw

			frame $win.frame.localip
			pack $win.frame.localip -side top -anchor nw -fill x
			label $win.frame.localip.label -relief flat -text "Local IP" -bd 0 -width 15
			ComboBox $win.frame.localip.entry \
				-textvariable ipaddress \
				-editable true \
				-bd 2 \
				-values $localips
			pack $win.frame.localip.label $win.frame.localip.entry -side left -anchor nw

			frame $win.frame.port
			pack $win.frame.port -side top -anchor nw -fill x
			label $win.frame.port.label -relief flat -text "POP3 Port" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.port.entry -relief sunken -textvariable pop3port \
					-width 5 -range {110 65534 1} \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-modifycmd {
						if {$svc_tag == 0} {
							set service_tag $pop3port
							getsvcvalue "pop3" $tmpwin $service_tag
						}
					}
			} else {
				entry $win.frame.port.entry   -relief sunken -textvariable pop3port -width 5 \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-command {
						if {$svc_tag == 0} {
							set service_tag $pop3port
							getsvcvalue "pop3" $tmpwin $service_tag
						}
					}
			}
			pack $win.frame.port.label $win.frame.port.entry -side left -anchor nw

			frame $win.frame.maxdaemons
			pack $win.frame.maxdaemons -side top -anchor nw -fill x
			label $win.frame.maxdaemons.label -relief flat -text "Max Concurrency" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxdaemons.entry -relief sunken -textvariable maxdaemons \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxdaemons.entry   -relief sunken -textvariable maxdaemons -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxdaemons.label $win.frame.maxdaemons.entry -side left -anchor nw

			frame $win.frame.maxperip
			pack $win.frame.maxperip -side top -anchor nw -fill x
			label $win.frame.maxperip.label -relief flat -text "Max Per IP" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.maxperip.entry -relief sunken -textvariable maxperip \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxperip.entry   -relief sunken -textvariable maxperip -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxperip.label $win.frame.maxperip.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			pack $win.frame.memory -side top -anchor nw -fill x
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			checkbutton $win.frame.domlimit   -text "Domain Limit" \
				-variable domlimit
			balloonHelp $win.frame.domlimit "Impose Domain limits on POP3 service"
			checkbutton $win.frame.lastauth   -text "Skip Lastlog" \
				-variable nolastauth
			balloonHelp $win.frame.lastauth "Disable logging of Last Authencition"
			set proxy 0
			checkbutton $win.frame.proxy      -text "Proxy Mode" \
				-variable proxy -command {
					if {$proxy} {
						$tmpwin.frame.destport.label configure -state normal
						$tmpwin.frame.destport.entry configure -state normal
					} else {
						$tmpwin.frame.destport.label configure -state disabled
						$tmpwin.frame.destport.entry configure -state disabled
					}
				}
			balloonHelp $win.frame.proxy "Setup the service as an POP3 proxy"
			pack $win.frame.domlimit   -side top -anchor nw
			pack $win.frame.lastauth   -side top -anchor nw
			pack $win.frame.proxy      -side top -anchor nw

			frame $win.frame.destport
			pack $win.frame.destport -side top -anchor nw -fill x
			label $win.frame.destport.label -relief flat -text "Dest POP3 Port" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.destport.entry -relief sunken -textvariable destport -width 5 \
					-range {25 65534 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.destport.entry   -relief sunken -textvariable destport -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.destport.label $win.frame.destport.entry -side left -anchor nw
			if {$proxy} {
				$win.frame.destport.label configure -state normal
				$win.frame.destport.entry configure -state normal
			} else {
				$win.frame.destport.label configure -state disabled
				$win.frame.destport.entry configure -state disabled
			}
			getsvcvalue "pop3" $tmpwin $pop3port
		}
		dbserver {
			$win.service.c  configure -state disabled
			$win.service.te configure -state disabled
			set service_tag ""
			set dbfifo_name "dbfifo"
			frame $win.frame.servicedir
			pack $win.frame.servicedir -side top -anchor nw -fill x
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 17
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0"
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			frame $win.frame.controldir
			pack $win.frame.controldir -side top -anchor nw -fill x
			label $win.frame.controldir.label -relief flat -text "Control Dir" -bd 0 -width 17
			entry $win.frame.controldir.entry -relief sunken -textvariable svc_controldir
			button $win.frame.controldir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /etc/indimail;fileDialog $w $win.frame.controldir.entry dir 0"
			balloonHelp $win.frame.controldir.button "Click to browse for qmail's control directory"
			$win.frame.controldir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.controldir.label $win.frame.controldir.entry $win.frame.controldir.button -side left -anchor nw

			frame $win.frame.dbfifo
			pack $win.frame.dbfifo -side top -anchor nw -fill x
			label $win.frame.dbfifo.label -relief flat -text "DbFifo Name" -bd 0 -width 17
			entry $win.frame.dbfifo.entry -relief sunken -textvariable dbfifo_name
			pack $win.frame.dbfifo.label $win.frame.dbfifo.entry -side left -anchor nw

			frame $win.frame.threads
			pack $win.frame.threads -side top -anchor nw -fill x
			label $win.frame.threads.label -relief flat -text "DBServer Threads" -bd 0 -width 17
			if {$BWidget_present} {
				SpinBox $win.frame.threads.entry -relief sunken -textvariable dbthreads -width 5 \
					-range {1 256 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.threads.entry   -relief sunken -textvariable dbthreads -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.threads.label $win.frame.threads.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			pack $win.frame.memory -side top -anchor nw -fill x
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 17
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			checkbutton $win.frame.pwcache   -text "Password Cache" \
				-variable pwcache
			balloonHelp $win.frame.pwcache "Turn on Password Caching"
			pack $win.frame.pwcache -side top -anchor nw

			checkbutton $win.frame.domlimit   -text "Domain Limit"   -variable domlimit
			balloonHelp $win.frame.domlimit "Impose Domain limit"
			pack $win.frame.domlimit -side top -anchor nw
			getsvcvalue "dbserver" $tmpwin $dbfifo_name
		}
		indisrvr {
			$win.service.c  configure -state normal
			$win.service.te configure -state normal
			set adminport 4000
			set service_tag 4000
			set basepath "/mail"
			set avguserquota 2
			set hardquota 50
			set maxdaemons 40
			frame $win.frame.servicedir
			pack $win.frame.servicedir -side top -anchor nw -fill x
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 20
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0"
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			frame $win.frame.basepath
			pack $win.frame.basepath -side top -anchor nw -fill x
			label $win.frame.basepath.label -relief flat -text "Mail Basepath" -bd 0 -width 20
			entry $win.frame.basepath.entry -relief sunken -textvariable basepath
			button $win.frame.basepath.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /;fileDialog $w $win.frame.basepath.entry dir 0"
			balloonHelp $win.frame.basepath.button "Click to browse for base path for user's home directory"
			$win.frame.basepath.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.basepath.label $win.frame.basepath.entry $win.frame.basepath.button -side left -anchor nw

			frame $win.frame.port
			pack $win.frame.port -side top -anchor nw -fill x
			label $win.frame.port.label -relief flat -text "Admin Port" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.port.entry -relief sunken -textvariable adminport \
					-width 5 -range {4000 65534 1} \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-modifycmd {
						if {$svc_tag == 0} {
							set service_tag $adminport
							getsvcvalue "indisrvr" $tmpwin $service_tag
						}
					}
			} else {
				entry $win.frame.port.entry   -relief sunken -textvariable adminport -width 5 \
					-validate key -invcmd bell -vcmd {regexp {^[0-9]*$} %P} \
					-command {
						if {$svc_tag == 0} {
							set service_tag $adminport
							getsvcvalue "indisrvr" $tmpwin $service_tag
						}
					}
			}
			pack $win.frame.port.label $win.frame.port.entry -side left -anchor nw

			frame $win.frame.maxdaemons
			pack $win.frame.maxdaemons -side top -anchor nw -fill x
			label $win.frame.maxdaemons.label -relief flat -text "Max Concurrency" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.maxdaemons.entry -relief sunken -textvariable maxdaemons \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxdaemons.entry   -relief sunken -textvariable maxdaemons -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxdaemons.label $win.frame.maxdaemons.entry -side left -anchor nw

			frame $win.frame.maxperip
			pack $win.frame.maxperip -side top -anchor nw -fill x
			label $win.frame.maxperip.label -relief flat -text "Max Per IP" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.maxperip.entry -relief sunken -textvariable maxperip \
					-width 5 -range {25 4096 25} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.maxperip.entry   -relief sunken -textvariable maxperip -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.maxperip.label $win.frame.maxperip.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			pack $win.frame.memory -side top -anchor nw -fill x
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			frame $win.frame.mysqlhost
			pack $win.frame.mysqlhost -side top -anchor nw -fill x
			label $win.frame.mysqlhost.label -relief flat -text "MySQL Host" -bd 0 -width 20
			combobox $win.frame.mysqlhost.entry \
			-textvariable mysqlhost \
			-editable true \
			-highlightthickness 1 \
			-bd 2
			set found 0
			$win.frame.mysqlhost.entry list delete 0 end
			foreach i $domain_list {
				foreach j $sqlserver_list($i) {
					$win.frame.mysqlhost.entry list insert end $j
				}
				set found 1
			}
			if {$found == 1} {
				$win.frame.mysqlhost.entry select 0
			}
			pack $win.frame.mysqlhost.label $win.frame.mysqlhost.entry -side left -anchor nw

			frame $win.frame.mysqluser
			pack $win.frame.mysqluser -side top -anchor nw -fill x
			label $win.frame.mysqluser.label -relief flat -text "MySQL User" -bd 0 -width 20
			entry $win.frame.mysqluser.entry -relief sunken -textvariable mysqluser -width 10
			pack $win.frame.mysqluser.label $win.frame.mysqluser.entry -side left -anchor nw

			frame $win.frame.mysqlpass
			pack $win.frame.mysqlpass -side top -anchor nw -fill x
			label $win.frame.mysqlpass.label -relief flat -text "MySQL Passwd" -bd 0 -width 20
			entry $win.frame.mysqlpass.entry -relief sunken -textvariable mysqlpass -width 10 -show * \
				-vcmd {expr {[string length %P]<=8}} -validate key -invcmd bell
			pack $win.frame.mysqlpass.label $win.frame.mysqlpass.entry -side left -anchor nw

			frame $win.frame.avguserquota
			pack $win.frame.avguserquota -side top -anchor nw -fill x
			label $win.frame.avguserquota.label -relief flat -text "Avg User Quota(MB)" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.avguserquota.entry -relief sunken -textvariable avguserquota \
					-width 5 -range {1 50 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.avguserquota.entry   -relief sunken -textvariable avguserquota -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.avguserquota.label $win.frame.avguserquota.entry -side left -anchor nw

			frame $win.frame.hardquota
			pack $win.frame.hardquota -side top -anchor nw -fill x
			label $win.frame.hardquota.label -relief flat -text "Hard Quota(MB)" -bd 0 -width 20
			if {$BWidget_present} {
				SpinBox $win.frame.hardquota.entry -relief sunken -textvariable hardquota \
					-width 5 -range {1 500 10} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.hardquota.entry   -relief sunken -textvariable hardquota -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.hardquota.label $win.frame.hardquota.entry -side left -anchor nw
			getsvcvalue "indisrvr" $tmpwin $adminport
		}
		fetchmail {
			$win.service.c  configure -state disabled
			$win.service.te configure -state disabled
			set service_tag ""
			frame $win.frame.servicedir
			pack $win.frame.servicedir -side top -anchor nw -fill x
			label $win.frame.servicedir.label -relief flat -text "Service Dir" -bd 0 -width 15
			entry $win.frame.servicedir.entry -relief sunken -textvariable servicedir
			button $win.frame.servicedir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /service;fileDialog $w $win.frame.servicedir.entry dir 0"
			balloonHelp $win.frame.servicedir.button "Click to browse for service directory"
			$win.frame.servicedir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.servicedir.label $win.frame.servicedir.entry $win.frame.servicedir.button -side left -anchor nw

			frame $win.frame.controldir
			pack $win.frame.controldir -side top -anchor nw -fill x
			label $win.frame.controldir.label -relief flat -text "Control Dir" -bd 0 -width 15
			entry $win.frame.controldir.entry -relief sunken -textvariable svc_controldir
			button $win.frame.controldir.button \
				-pady "3" -relief ridge -padx "9" \
				-command "set initialdir /etc/indimail;fileDialog $w $win.frame.controldir.entry dir 0"
			balloonHelp $win.frame.controldir.button "Click to browse for qmail's control directory"
			$win.frame.controldir.button configure -image [image create photo -data "R0lGODlhEAAQAIUAAPwCBAQCBOSmZPzSnPzChPzGhPyuZEwyHExOTFROTFxaVFRSTMSGTPT29Ozu7Nze3NTS1MzKzMTGxLy6vLS2tLSytDQyNOTm5OTi5Ly+vKyqrKSmpIyOjLR+RNTW1MzOzJyenGxqZBweHKSinJSWlExKTMTCxKyurGxubBQSFAwKDJyanERCRERGRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaRQIBwGCgGhkhkEWA8HpNPojFJFU6ryitTiw0IBgRBkxsYFAiGtDodDZwPCERCEV8sEk0CI9FoOB4BEBESExQVFgEEBw8PFxcYEBIZGhscCEwdCxAPGA8eHxkUGyAhIkwHEREQqxEZExUjJCVWCBAZJhEmGRUnoygpQioZGxsnxsQrHByzQiJxz3EsLSwWpkJ+QQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7"]
			pack $win.frame.controldir.label $win.frame.controldir.entry $win.frame.controldir.button -side left -anchor nw

			frame $win.frame.domain
			pack $win.frame.domain -side top -anchor nw -fill x
			label $win.frame.domain.label -relief flat -text "Default Domain" -bd 0 -width 15
			ComboBox $win.frame.domain.entry \
				-textvariable default_domain_val \
				-editable false \
				-bd 2 \
				-values $domain_list
			pack $win.frame.domain.label $win.frame.domain.entry -side left -anchor nw

			set memory 5
			frame $win.frame.memory
			pack $win.frame.memory -side top -anchor nw -fill x
			label $win.frame.memory.label -relief flat -text "Softlimit (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.memory.entry -relief sunken -textvariable memory \
					-width 5 -range {5 500 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.memory.entry   -relief sunken -textvariable memory -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.memory.label $win.frame.memory.entry -side left -anchor nw

			frame $win.frame.qcount
			pack $win.frame.qcount -side top -anchor nw -fill x
			label $win.frame.qcount.label -relief flat -text "Queue Count" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.qcount.entry -relief sunken -textvariable qcount \
					-width 5 -range {1 40 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.qcount.entry   -relief sunken -textvariable qcount -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.qcount.label $win.frame.qcount.entry -side left -anchor nw

			frame $win.frame.qstart
			pack $win.frame.qstart -side top -anchor nw -fill x
			label $win.frame.qstart.label -relief flat -text "First Queue No" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.qstart.entry -relief sunken -textvariable qstart \
					-width 5 -range {1 40 1} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.qstart.entry   -relief sunken -textvariable qstart -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.qstart.label $win.frame.qstart.entry -side left -anchor nw

			frame $win.frame.minfree
			pack $win.frame.minfree -side top -anchor nw -fill x
			label $win.frame.minfree.label -relief flat -text "Min Free (Mb)" -bd 0 -width 15
			if {$BWidget_present} {
				SpinBox $win.frame.minfree.entry -relief sunken -textvariable minfree \
					-width 5 -range {50 1024 5} \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			} else {
				entry $win.frame.minfree.entry   -relief sunken -textvariable minfree -width 5 \
					-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			}
			pack $win.frame.minfree.label $win.frame.minfree.entry -side left -anchor nw

			checkbutton $win.frame.fsync      -text "Use FSYNC"    -variable usefsync
			balloonHelp $win.frame.fsync "Turn on fsync when writing files"
			checkbutton $win.frame.syncdir    -text "Use SYNCDIR"    -variable usesyncdir
			balloonHelp $win.frame.syncdir "Turn on directory syncing"
			checkbutton $win.frame.spamfilt   -text "Spam Filter"  -variable spamvar \
				-command {
				if {$spamvar} {
					$tmpwin.frame.args.l   configure -state normal
					$tmpwin.frame.args.e   configure -state normal
					$tmpwin.frame.exitco.c configure -state normal
					$tmpwin.frame.control.s configure -state normal
					$tmpwin.frame.control.b configure -state normal
					if {$spamexit} {
						$tmpwin.frame.exitco.e configure -state normal
						$tmpwin.frame.reject.c configure -state normal
						if {$rejectspam == 1} {
						$tmpwin.frame.reject.s configure -state normal
						} else {
						$tmpwin.frame.reject.s configure -state disabled
						}
					} else {
						$tmpwin.frame.exitco.e configure -state disabled
						$tmpwin.frame.reject.c configure -state disabled
						$tmpwin.frame.reject.s configure -state disabled
					}
				} else {
					$tmpwin.frame.args.l   configure -state disabled
					$tmpwin.frame.args.e   configure -state disabled
					$tmpwin.frame.exitco.c configure -state disabled
					$tmpwin.frame.exitco.e configure -state disabled
					$tmpwin.frame.reject.c configure -state disabled
					$tmpwin.frame.reject.s configure -state disabled
					$tmpwin.frame.control.s configure -state disabled
					$tmpwin.frame.control.b configure -state disabled
				}
			}
			balloonHelp $win.frame.spamfilt "Turn on SPAM filter"

			frame $win.frame.args
			label $win.frame.args.l -text "Filter Arguments" -width 16 -justify left -anchor nw
			set spamfilterargs "/usr/bin/bogofilter -p -d /etc/indimail"
			entry $win.frame.args.e -textvariable spamfilterargs -bd 2 \
				-width 30

			frame $win.frame.exitco
			set spamexitcode ""
			checkbutton $win.frame.exitco.c -text "Spamexit Code" \
				-variable spamexit -command {
					if {$spamexit} {
						$tmpwin.frame.exitco.e configure -state normal
						$tmpwin.frame.reject.c configure -state normal
					} else {
						$tmpwin.frame.exitco.e configure -state disabled
						$tmpwin.frame.reject.c configure -state disabled
						set rejectspam 0
						set rejectspamv ""
						set spamexitcode ""
						$tmpwin.frame.reject.s configure -state disabled
					}
				}
			balloonHelp $win.frame.exitco.c "Enable checking of exit code\nfrom spam filter program"
			SpinBox $win.frame.exitco.e -relief sunken -textvariable spamexitcode \
				-width 5 -range {0 255 1} -vcmd {regexp {^[0-9]*$} %P} \
				-validate key -invcmd bell
			if {$spamexit} {
				$tmpwin.frame.exitco.e configure -state normal
			} else {
				$tmpwin.frame.exitco.e configure -state disabled
			}
			pack $win.frame.exitco.c $win.frame.exitco.e -side left -anchor nw

			frame $win.frame.reject
			checkbutton $win.frame.reject.c -text "Reject Spam" \
				-variable rejectspam -command {
					if {$rejectspam == 0} {
						set rejectspamv ""
						$tmpwin.frame.reject.s configure -state disabled
					} else {
						set rejectspamv 1
						$tmpwin.frame.reject.s configure -state normal
					}
				}
			balloonHelp $win.frame.reject.c "How to handle SPAM\n0 - Accept SPAM\n1 - Reject SPAM\n2 - Blackhole SPAM"
			SpinBox $win.frame.reject.s -relief sunken -textvariable rejectspamv \
				-width 5 -range {0 255 1} -vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
			pack $win.frame.reject.c $win.frame.reject.s -side left -anchor nw

			frame $win.frame.control
			button $win.frame.control.b -relief raised -text "Edit" -bd 2 \
				-command {
						if {$spamfile != ""} {
							set filename $svc_controldir/$spamfile
							editfile 2
						} else {
							msg_dialog .d {svctool} "spam control file not selected" /usr/share/indimail/indium/images/warning.gif 0 "OK"
						}
					}
			balloonHelp $win.frame.control.b "Click to edit selected spam control file"
			if {[file exist /usr/share/indimail/indium/images/edit.gif]} {
				$win.frame.control.b configure -image [image create photo -file /usr/share/indimail/indium/images/edit.gif]
			}
			ComboBox $win.frame.control.s \
				-textvariable spamfile \
				-editable false \
				-bd 2 \
				-values {spamignore spamignorepatterns spamignoreheaders \
					rejectspam globalspamredirect spamredirect spamfilterargs \
					filterargs badhelo badmailfrom badrcptto spamdb bodycheck \
					signatures hostaccess badext badextpatterns}
			pack $win.frame.control.b $win.frame.control.s -side left -anchor nw

			if {$spamvar} {
				$tmpwin.frame.args.l   configure -state normal
				$tmpwin.frame.args.e   configure -state normal
				$tmpwin.frame.exitco.c configure -state normal
				$tmpwin.frame.control.s configure -state normal
				$tmpwin.frame.control.b configure -state normal
				if {$spamexit} {
					$tmpwin.frame.exitco.e configure -state normal
					$tmpwin.frame.reject.c   configure -state normal
					if {$rejectspam == 1} {
					$tmpwin.frame.reject.s   configure -state normal
					} else {
					$tmpwin.frame.reject.s   configure -state disabled
					}
				} else {
					$tmpwin.frame.exitco.e configure -state disabled
					$tmpwin.frame.reject.c   configure -state disabled
					$tmpwin.frame.reject.s   configure -state disabled
				}
			} else {
				$tmpwin.frame.args.l   configure -state disabled
				$tmpwin.frame.args.e   configure -state disabled
				$tmpwin.frame.reject.c configure -state disabled
				$tmpwin.frame.reject.s configure -state disabled
				$tmpwin.frame.exitco.c configure -state disabled
				$tmpwin.frame.exitco.e configure -state disabled
				$tmpwin.frame.control.s configure -state disabled
				$tmpwin.frame.control.b configure -state disabled
			}
			pack $win.frame.args.l $win.frame.args.e -side left -anchor nw
			pack $win.frame.fsync     -side top -anchor nw
			pack $win.frame.syncdir  -side top -anchor nw
			pack $win.frame.spamfilt -side top -anchor nw
			pack $win.frame.args     -side top -anchor nw
			pack $win.frame.exitco   -side top -anchor nw
			pack $win.frame.reject   -side top -anchor nw
			pack $win.frame.control  -side top -anchor nw
			getsvcvalue "fetchmail" $tmpwin ""
		}
	}
	pack $win.buttons -side top -anchor nw -fill x
	pack $win.buttons.run  -side left -anchor nw
	pack $win.buttons.quit -side left -anchor nw
	pack $win.quit -side top -anchor sw
	if {$BWidget_present == 1} {
		$notebook compute_size
	}
}

proc newVariable {win w1 path} {
	variable base
	variable tmpPath
	variable tmpwin
	variable varval
	variable varname
	variable tw
	global envFile

	set tw $w1
	set tmpPath $path
	set tmpwin $win
	set base .f2
	catch {destroy $base}
	toplevel $base -class Toplevel -bd 2 -highlightthickness 2 -highlightbackground black -takefocus 1 -relief raised
	set x [winfo pointerx .]
	set y [winfo pointery .]
	wm geometry $base +${x}+${y}
	wm focusmodel $base passive
	wm geometry $base 250x90
	wm maxsize $base 1009 738
	wm minsize $base 1 1
	wm overrideredirect $base 1
	wm resizable $base 1 1
	wm title $base "Indium - Supervise Tool"
	frame $base.fr1
	frame $base.fr2
	frame $base.fr3
	pack $base.fr1 -side top -anchor nw
	pack $base.fr2 -side top -anchor nw
	pack $base.fr3 -side top -anchor nw

	label $base.fr1.l -text "Variable Name"
	entry $base.fr1.e -textvariable varname
	pack $base.fr1.l $base.fr1.e -side left -anchor nw

	SpinBox $base.fr2.e1 -relief sunken -textvariable varval \
		-width 5 -range {0 65535 1} -vcmd {regexp {^[0-9]*$} %P} \
		-validate key -invcmd bell
	entry $base.fr2.e2 -relief sunken -textvariable varval
	pack $base.fr2.e1 $base.fr2.e2 -side left -anchor nw
	set varname ""
	set varval ""

	button $base.fr3.run -text Save -bg Orange \
		-highlightthickness 5 -highlightbackground black \
		-command {
			validateVar $tmpPath $tw $varname $varval
			set envFile $varname
			destroy $base
			return
		}
	button $base.fr3.quit -text Quit -bg IndianRed \
		-highlightthickness 5 -highlightbackground black \
		-command "destroy $base;return" -bd 5
	pack $base.fr3.run $base.fr3.quit -side left -anchor nw
}

proc validateVar {path w1 varname varval} {
	global varlist
	if {[file exists $path/variables/$varname]} {
		msg_dialog .d {svctool} "variable $varname exists" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return
	}
	if {[catch {open $path/variables/$varname w} f] } {
		msg_dialog .d {svstat} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return
	} else {
		puts $f $varval
		close $f
		set varlist {}
		foreach i [glob -nocomplain $path/variables/*] {
			lappend varlist [file tail $i]
		}
		$w1.3.1.entry configure -values $varlist
		msg_dialog .d {svctool} "saved variable $varname" /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc getsvcvalue {mode win tag} {
	global w BWidget_present
	global smtpport maxdaemons maxperip qcount qstart qbase chkrelay chkusr \
	cugmail ipaddress odmr memory minfree skipsend dynroute mailcount_limit mailsize_limit \
	dlimit domlimit masquerade rblcheck bodycheck bodycheckfile viruscheck viruscheckval \
	paranoid dmasquerade qhpsi qhpsival \
	spamvar spamfilterargs overquota_mailsize \
	spamexit spamexitcode rejectspam rejectspamv filterlogstatus filterlog \
	localfilter remotefilter authall authself authsmtp antispoofing
	global imapport pop3port destport nolastauth proxy default_domain_val
	global basepath avguserquota hardquota mysqlhost mysqluser mysqlpass
	global folderport dbfifo_name dbthreads User svc_controldir usefsync usesyncdir
	global svc_tag pwcache qregex dnscheck helocheck helofqdn
	variable tmpwin
	set tmpwin $win
	source /usr/share/indimail/indium/scripts/global.tcl

	if {$User != "postmaster"} {
		$tmpwin.buttons.run configure -state disabled
	} else {
		$tmpwin.buttons.run configure -state normal
	}
	switch -regexp $mode {
		smtp {
			set qregex 0
			set dnscheck 1
			set helocheck 0
			set helofqdn 0
			set maxdaemons 40
			set maxperip 25
			set cugmail 0
			set antispoofing 0
			set chkusr 0
			set antispoofing 0
			set chkrelay 0
			set autsmtp 0
			set authall 0
			set authself 0
			set qcount 1
			set qstart 1
			set qbase ""
			set ipaddress ""
			set odmr 0
			set memory 5
			set minfree 50
			set skipsend 0
			set dynroute 0
			set dlimit 0
			set domlimit 0
			set mailcount_limit -1
			set mailsize_limit -1
			set overquota_mailsize -1
			set masquerade 0
			set rbl 0
			set bodycheck 0
			set bodycheckfile ""
			set viruscheck 0
			set viruscheckval 0
			set qhpsi 0
			set qhpsival ""
			set paranoid 0
			set dmasquerade 0
			set spamvar 0
			set spamfilterargs "/usr/bin/bogofilter -p -d /etc/indimail"
			set spamexit 0
			set spamexitcode ""
			set rejectspam 0
			set rejectspamv ""
			set filterlogstatus 0
			set filterlog ""
			set localfilter 0
			set remotefilter 0
			set usefsync 0
			set usesyncdir 0
			if {[file exists $servicedir/qmail-smtpd.$tag/variables]} {
				$tmpwin.buttons.run configure -text "Modify"
			} else {
				$tmpwin.buttons.run configure -text "Create"
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/MAXDAEMONS r} f] == 0} {
				set maxdaemons [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/CONTROLDIR r} f] == 0} {
				set tmp [read -nonewline $f]
				close $f
				if {$tmp != ""} {
					if {[string index $tmp 0] == "/"} {
						set svc_controldir $tmp
					} else {
						set svc_controldir "/etc/indimail/$tmp"
					}
				}
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/MAXPERIP r} f] == 0} {
				set maxperip [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/QUEUE_COUNT r} f] == 0} {
				set qcount [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/QUEUE_START r} f] == 0} {
				set qstart [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/QUEUE_BASE r} f] == 0} {
				set qbase [read -nonewline $f]
				close $f
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/QREGEX] && [file size $servicedir/qmail-smtpd.$tag/variables/QREGEX]} {
				set qregex 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/BODYCHECK] && [file size $servicedir/qmail-smtpd.$tag/variables/BODYCHECK]} {
				set bodycheck 1
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/BODYCHECK r} f] == 0} {
					set bodycheckfile [read -nonewline $f]
					close $f
				}
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/QHPSI] && [file size $servicedir/qmail-smtpd.$tag/variables/QHPSI]} {
				set qhpsi 1
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/QHPSI r} f] == 0} {
					set qhpsival [read -nonewline $f]
					close $f
				}
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/VIRUSCHECK] && [file size $servicedir/qmail-smtpd.$tag/variables/VIRUSCHECK]} {
				set viruscheck 1
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/VIRUSCHECK r} f] == 0} {
					set viruscheckval [read -nonewline $f]
					close $f
				}
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/NODNSCHECK] && [file size $servicedir/qmail-smtpd.$tag/variables/NODNSCHECK]} {
				set dnscheck 0
			} else {
				set dnscheck 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/PARANOID] && [file size $servicedir/qmail-smtpd.$tag/variables/PARANOID]} {
				set paranoid 1
			} else {
				set paranoid 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/DOMAIN_MASQUERADE] && [file size $servicedir/qmail-smtpd.$tag/variables/DOMAIN_MASQUERADE]} {
				set dmasquerade 1
			} else {
				set dmasquerade 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/ENFORCE_FQDN_HELO] && [file size $servicedir/qmail-smtpd.$tag/variables/ENFORCE_FQDN_HELO]} {
				set helofqdn 1
			} else {
				set helofqdn 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/BADHELOCHECK] && [file size $servicedir/qmail-smtpd.$tag/variables/BADHELOCHECK]} {
				set helocheck 1
			} else {
				set helocheck 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/CHECKRELAY] && [file size $servicedir/qmail-smtpd.$tag/variables/CHECKRELAY]} {
				set chkrelay 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/AUTH_ALL] && [file size $servicedir/qmail-smtpd.$tag/variables/AUTH_ALL]} {
				set authall 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/AUTHSELF] && [file size $servicedir/qmail-smtpd.$tag/variables/AUTHSELF]} {
				set authself 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/REQUIREAUTH] && [file size $servicedir/qmail-smtpd.$tag/variables/REQUIREAUTH]} {
				set authsmtp 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/CHECKRECIPIENT] && [file size $servicedir/qmail-smtpd.$tag/variables/CHECKRECIPIENT]} {
				set chkusr 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/ANTISPOOFING] && [file size $servicedir/qmail-smtpd.$tag/variables/ANTISPOOFING]} {
				set antispoofing 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/CUGMAIL] && [file size $servicedir/qmail-smtpd.$tag/variables/CUGMAIL]} {
				set cugmail 1
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/LOCALIP r} f] == 0} {
				set ipaddress [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/PORT r} f] == 0} {
				set smtpport [read -nonewline $f]
				close $f
			}
			if {$smtpport == 366} {
				set odmr 1
			}
			if {$smtpport != $tag} {
				set svc_tag 1
			}
			if {$odmr} {
				$tmpwin.frame.helofqdn     configure -state disabled
				$tmpwin.frame.helocheck    configure -state disabled
				$tmpwin.frame.dnscheck     configure -state disabled
				$tmpwin.frame.hostaccess.h configure -state disabled
				$tmpwin.frame.hostaccess.d configure -state disabled
				$tmpwin.frame.qregex       configure -state disabled
				$tmpwin.frame.fsync        configure -state disabled
				$tmpwin.frame.syncdir      configure -state disabled
				$tmpwin.frame.skipsend     configure -state disabled
				$tmpwin.frame.dynroute     configure -state disabled
				$tmpwin.frame.deliverylimit.c configure -state disabled
				$tmpwin.frame.deliverylimit.l1 configure -state disabled
				$tmpwin.frame.deliverylimit.l2 configure -state disabled
				$tmpwin.frame.deliverylimit.entry1 configure -state disabled
				$tmpwin.frame.deliverylimit.entry2 configure -state disabled
				$tmpwin.frame.chkusr.l     configure -state disabled
				$tmpwin.frame.chkusr.c     configure -state disabled
				$tmpwin.frame.chkusr.b     configure -state disabled
				$tmpwin.frame.domlimit     configure -state disabled
				$tmpwin.frame.cugmail      configure -state disabled
				$tmpwin.frame.antispoof    configure -state disabled
				$tmpwin.frame.authsmtp     configure -state disabled
				$tmpwin.frame.authall      configure -state disabled
				$tmpwin.frame.authself      configure -state disabled
				$tmpwin.frame.chkrelay     configure -state disabled
				$tmpwin.frame.viruscheck.c configure -state disabled
				$tmpwin.frame.viruscheck.e configure -state disabled
				$tmpwin.frame.qhpsi.c      configure -state disabled
				$tmpwin.frame.qhpsi.e      configure -state disabled
				$tmpwin.frame.bodycheck.c  configure -state disabled
				$tmpwin.frame.bodycheck.e  configure -state disabled
				$tmpwin.frame.rblcheck     configure -state disabled
				$tmpwin.frame.masquera     configure -state disabled
				$tmpwin.frame.spamfilt     configure -state disabled
				$tmpwin.frame.qbase.label  configure -state disabled
				$tmpwin.frame.qbase.entry  configure -state disabled
				$tmpwin.frame.qbase.button configure -state disabled
				$tmpwin.frame.qcount.label configure -state disabled
				$tmpwin.frame.qcount.entry configure -state disabled
				$tmpwin.frame.qstart.label configure -state disabled
				$tmpwin.frame.qstart.entry configure -state disabled
				$tmpwin.frame.minfree.label configure -state disabled
				$tmpwin.frame.minfree.entry configure -state disabled
				$tmpwin.frame.overquota.l  configure -state disabled
				$tmpwin.frame.overquota.e  configure -state disabled
				$tmpwin.frame.loclfilt     configure -state disabled
				$tmpwin.frame.remtfilt     configure -state disabled
				$tmpwin.frame.filtstat.c   configure -state disabled
				$tmpwin.frame.filtstat.e   configure -state disabled
				$tmpwin.frame.args.l       configure -state disabled
				$tmpwin.frame.args.e       configure -state disabled
				$tmpwin.frame.exitco.c     configure -state disabled
				$tmpwin.frame.exitco.e     configure -state disabled
				$tmpwin.frame.reject.c     configure -state disabled
				$tmpwin.frame.reject.s     configure -state disabled
				$tmpwin.frame.control.s    configure -state disabled
				$tmpwin.frame.control.b    configure -state disabled
			} else {
				$tmpwin.frame.helofqdn     configure -state normal
				$tmpwin.frame.helocheck    configure -state normal
				$tmpwin.frame.dnscheck     configure -state normal
				if {[file exists $svc_controldir/hostaccess]} {
					$tmpwin.frame.hostaccess.h configure -state normal
					$tmpwin.frame.hostaccess.d configure -state normal
				}
				$tmpwin.frame.qregex        configure -state normal
				$tmpwin.frame.fsync         configure -state normal
				$tmpwin.frame.syncdir       configure -state normal
				$tmpwin.frame.skipsend      configure -state normal
				$tmpwin.frame.dynroute      configure -state normal
				$tmpwin.frame.deliverylimit.c configure -state normal
				$tmpwin.frame.deliverylimit.l1 configure -state normal
				$tmpwin.frame.deliverylimit.l2 configure -state normal
				$tmpwin.frame.deliverylimit.entry1 configure -state normal
				$tmpwin.frame.deliverylimit.entry2 configure -state normal
				$tmpwin.frame.chkusr.l      configure -state normal
				$tmpwin.frame.chkusr.c      configure -state normal
				$tmpwin.frame.chkusr.b      configure -state normal
				$tmpwin.frame.domlimit      configure -state normal
				$tmpwin.frame.cugmail       configure -state normal
				$tmpwin.frame.antispoof     configure -state normal
				$tmpwin.frame.authsmtp      configure -state normal
				$tmpwin.frame.authall       configure -state normal
				$tmpwin.frame.authself       configure -state normal
				$tmpwin.frame.chkrelay      configure -state normal
				$tmpwin.frame.viruscheck.c  configure -state normal
				if {$viruscheck == 1} {
					$tmpwin.frame.viruscheck.e  configure -state normal
				else
					$tmpwin.frame.viruscheck.e  configure -state disabled
				}
				$tmpwin.frame.qhpsi.c       configure -state normal
				if {$qhpsi == 1} {
					$tmpwin.frame.qhpsi.e       configure -state normal
				} else {
					$tmpwin.frame.qhpsi.e       configure -state disabled
				}
				$tmpwin.frame.bodycheck.c   configure -state normal
				if {$bodycheck == 1} {
					$tmpwin.frame.bodycheck.e   configure -state normal
				} else {
					$tmpwin.frame.bodycheck.e   configure -state disabled
				}
				$tmpwin.frame.rblcheck      configure -state normal
				$tmpwin.frame.masquera      configure -state normal
				$tmpwin.frame.spamfilt      configure -state normal
				$tmpwin.frame.qbase.label   configure -state normal
				$tmpwin.frame.qbase.entry   configure -state normal
				$tmpwin.frame.qbase.button  configure -state normal
				$tmpwin.frame.qcount.label  configure -state normal
				$tmpwin.frame.qcount.entry  configure -state normal
				$tmpwin.frame.qstart.label  configure -state normal
				$tmpwin.frame.qstart.entry  configure -state normal
				$tmpwin.frame.minfree.label configure -state normal
				$tmpwin.frame.minfree.entry configure -state normal
				$tmpwin.frame.overquota.l   configure -state normal
				$tmpwin.frame.overquota.e   configure -state normal
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/SOFT_MEM r} f] == 0} {
				set memory [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[catch {open $servicedir/qmail-smtpd.$tag/variables/MIN_FREE r} f] == 0} {
				set minfree [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/DOMAIN_LIMITS] && [file size $servicedir/qmail-smtpd.$tag/variables/DOMAIN_LIMITS]} {
				set domlimit 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/USE_FSYNC] && [file size $servicedir/qmail-smtpd.$tag/variables/USE_FSYNC]} {
				set usefsync 1
			} else {
				set usefsync 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/USE_SYNCDIR] && [file size $servicedir/qmail-smtpd.$tag/variables/USE_SYNCDIR]} {
				set usesyncdir 1
			} else {
				set usesyncdir 0
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/MASQUERADE] && [file size $servicedir/qmail-smtpd.$tag/variables/MASQUERADE]} {
				set masquerade 1
			}
			if {[file exists $servicedir/qmail-smtpd.$tag/variables/SPAMFILTER] && [file size $servicedir/qmail-smtpd.$tag/variables/SPAMFILTER]} {
				set spamvar 1
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/LOGFILTER r} f] == 0} {
					set filterlog [read -nonewline $f]
					if {$filterlog != ""} {
						set filterlogstatus 1
					}
				}
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/SPAMFILTERARGS r} f] == 0} {
					set spamfilterargs [read -nonewline $f]
					close $f
				}
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/SPAMEXITCODE r} f] == 0} {
					set spamexitcode [read -nonewline $f]
					close $f
					if {$spamexitcode != ""} {
						set spamexit 1
					}
				}
				if {[catch {open $servicedir/qmail-smtpd.$tag/variables/REJECTSPAM r} f] == 0} {
					set rejectspamv [read -nonewline $f]
					close $f
					if {$rejectspamv != ""} {
						set rejectspam 1
						$tmpwin.frame.reject.s configure -state normal
					} else {
						$tmpwin.frame.reject.s configure -state disabled
					}
				}
			}
			if {$spamvar} {
				$tmpwin.frame.loclfilt  configure -state normal
				$tmpwin.frame.remtfilt configure -state normal
				$tmpwin.frame.filtstat.c configure -state normal
				$tmpwin.frame.filtstat.e configure -state normal
				$tmpwin.frame.args.l   configure -state normal
				$tmpwin.frame.args.e   configure -state normal
				$tmpwin.frame.exitco.c configure -state normal
				$tmpwin.frame.control.s configure -state normal
				$tmpwin.frame.control.b configure -state normal
				if {$spamexit} {
					$tmpwin.frame.reject.c configure -state normal
					$tmpwin.frame.exitco.e configure -state normal
					if {$rejectspam == 1} {
					$tmpwin.frame.reject.s configure -state normal
					} else {
					$tmpwin.frame.reject.s configure -state disabled
					}
				} else {
					$tmpwin.frame.reject.c configure -state disabled
					$tmpwin.frame.reject.s configure -state disabled
					$tmpwin.frame.exitco.e configure -state disabled
				}
			} else {
				$tmpwin.frame.loclfilt  configure -state disabled
				$tmpwin.frame.remtfilt configure -state disabled
				$tmpwin.frame.filtstat.c configure -state disabled
				$tmpwin.frame.filtstat.e configure -state disabled
				$tmpwin.frame.args.l   configure -state disabled
				$tmpwin.frame.args.e   configure -state disabled
				$tmpwin.frame.exitco.c configure -state disabled
				$tmpwin.frame.exitco.e configure -state disabled
				$tmpwin.frame.reject.c configure -state disabled
				$tmpwin.frame.reject.s configure -state disabled
				$tmpwin.frame.control.s configure -state disabled
				$tmpwin.frame.control.b configure -state disabled
			}
			if {$authsmtp} {
				$tmpwin.frame.authall  configure -state disabled
				$tmpwin.frame.chkrelay configure -state disabled
			} else {
				$tmpwin.frame.authall configure -state normal
				if {$authall} {
					$tmpwin.frame.chkrelay configure -state disabled
				} else {
					$tmpwin.frame.chkrelay configure -state normal
				}
			}
			if {[file exists $servicedir/qmail-send.$tag] == 0} {
				set skipsend 1
			} else {
				if {[catch {open $servicedir/qmail-send.$tag/variables/MAILCOUNT_LIMIT r} f] == 0} {
					set mailcount_limit [read -nonewline $f]
					close $f
					if {$mailcount_limit > 0} {
						set dlimit 1
					}
				}
				if {[catch {open $servicedir/qmail-send.$tag/variables/MAILSIZE_LIMIT r} f] == 0} {
					set mailsize_limit [expr [read -nonewline $f] / (1024 * 1024)]
					close $f
					if {$mailsize_limit > 0} {
						set dlimit 1
					}
				}
				if {[catch {open $servicedir/qmail-send.$tag/variables/OVERQUOTA_MAILSIZE r} f] == 0} {
					set overquota_mailsize [read -nonewline $f]
					close $f
				}
				if {[catch {open $servicedir/qmail-send.$tag/variables/ROUTES r} f] == 0} {
					set routes [read -nonewline $f]
					close $f
					if {$routes != "" && $routes != "static"} {
						set dynroute 1
					}
				}
				if {[file exists $servicedir/qmail-send.$tag/variables/SPAMFILTER] && [file size $servicedir/qmail-send.$tag/variables/SPAMFILTER]} {
					if {[file exists $servicedir/qmail-send.$tag/variables/QMAILLOCAL] && [file size $servicedir/qmail-send.$tag/variables/QMAILLOCAL]} {
						set localfilter 1
					}
					if {[file exists $servicedir/qmail-send.$tag/variables/QMAILREMOTE] && [file size $servicedir/qmail-send.$tag/variables/QMAILREMOTE]} {
						set remotefilter 1
					}
				}
			}
			if {$skipsend} {
				set dlimit 0
				set mailcount_limit -1
				set mailsize_limit -1
				set dynroute 0
				$tmpwin.frame.dynroute configure -state disabled
				$tmpwin.frame.deliverylimit.c configure -state disabled
			} else {
				$tmpwin.frame.dynroute configure -state normal
				$tmpwin.frame.deliverylimit.c configure -state normal
			}
			if {$dlimit} {
				$tmpwin.frame.deliverylimit.entry1 configure -state normal
				$tmpwin.frame.deliverylimit.entry2 configure -state normal
			} else {
				$tmpwin.frame.deliverylimit.entry1 configure -state disabled
				$tmpwin.frame.deliverylimit.entry2 configure -state disabled
				set mailcount_limit -1
				set mailsize_limit -1
			}
		}
		pop3 -
		imap {
			variable tmp
			set maxdaemons 40
			set maxperip 25
			set domlimit 0
			set nolastauth 0
			set proxy 0
			set ipaddress ""
			set memory 5
			set default_domain_val ""
			if {$mode == "imap"} {
				set tmp "imapd"
				set destport 143
			} else {
				set tmp "pop3d"
				set destport 110
			}
			if {[file exists $servicedir/qmail-$tmp.$tag/variables]} {
				$tmpwin.buttons.run configure -text "Modify"
			} else {
				$tmpwin.buttons.run configure -text "Create"
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/MAXDAEMONS r} f] == 0} {
				set maxdaemons [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/MAXPERIP r} f] == 0} {
				set maxperip [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/DEFAULT_DOMAIN r} f] == 0} {
				set default_domain_val [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/LOCALIP r} f] == 0} {
				set ipaddress [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/PORT r} f] == 0} {
				if {$mode == "imap"} {
					set imapport [read -nonewline $f]
					if {$imapport != $tag} {
						set svc_tag 1
					}
				} else {
					set pop3port [read -nonewline $f]
					if {$pop3port != $tag} {
						set svc_tag 1
					}
				}
				close $f
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/SOFT_MEM r} f] == 0} {
				set memory [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[file exists $servicedir/qmail-$tmp.$tag/variables/DOMAIN_LIMITS] && [file size $servicedir/qmail-$tmp.$tag/variables/DOMAIN_LIMITS]} {
				set domlimit 1
			}
			if {[file exists $servicedir/qmail-$tmp.$tag/variables/NOLASTAUTHLOGGING] && [file size $servicedir/qmail-$tmp.$tag/variables/NOLASTAUTHLOGGING]} {
				set nolastauth 1
			}
			if {[catch {open $servicedir/qmail-$tmp.$tag/variables/DESTPORT r} f] == 0} {
				set tmp [string range [read -nonewline $f] 5 end]
				if {$tmp != ""} {
					set destport $tmp
					set proxy 1
				}
			}
			if {$proxy == 1} {
				$tmpwin.frame.destport.label configure -state normal
				$tmpwin.frame.destport.entry configure -state normal
			} else {
				$tmpwin.frame.destport.label configure -state disabled
				$tmpwin.frame.destport.entry configure -state disabled
			}
		}
		fetchmail {
			set minfree 50
			set memory 5
			set spamvar 0
			set spamfilterargs "/usr/bin/bogofilger -p -d /etc/indimail"
			set spamexit 0
			set spamexitcode ""
			set rejectspam 0
			set rejectspamv ""
			set usefsync 0
			set usesyncdir 0
			if {[file exists $servicedir/fetchmail/variables]} {
				$tmpwin.buttons.run configure -text "Modify"
			} else {
				$tmpwin.buttons.run configure -text "Create"
			}
			if {[catch {open $servicedir/fetchmail/variables/CONTROLDIR r} f] == 0} {
				set tmp [read -nonewline $f]
				close $f
				if {$tmp != ""} {
					set svc_controldir $tmp
				}
			}
			if {[catch {open $servicedir/fetchmail/variables/QMAILDEFAULTHOST r} f] == 0} {
				set default_domain_val [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/fetchmail/variables/SOFT_MEM r} f] == 0} {
				set memory [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[catch {open $servicedir/fetchmail/variables/QUEUE_COUNT r} f] == 0} {
				set qcount [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/fetchmail/variables/QUEUE_START r} f] == 0} {
				set qstart [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/fetchmail/variables/MIN_FREE r} f] == 0} {
				set minfree [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[file exists $servicedir/fetchmail/variables/USE_FSYNC] && [file size $servicedir/fetchmail/variables/USE_FSYNC]} {
				set usefsync 1
			} else {
				set usefsync 0
			}
			if {[file exists $servicedir/fetchmail/variables/USE_SYNCDIR] && [file size $servicedir/fetchmail/variables/USE_SYNCDIR]} {
				set usesyncdir 1
			} else {
				set usesyncdir 0
			}
			if {[file exists $servicedir/fetchmail/variables/SPAMFILTER] && [file size $servicedir/fetchmail/variables/SPAMFILTER]} {
				set spamvar 1
				if {[catch {open $servicedir/fetchmail/variables/SPAMFILTERARGS r} f] == 0} {
					set spamfilterargs [read -nonewline $f]
					close $f
				}
				if {[catch {open $servicedir/fetchmail/variables/SPAMEXITCODE r} f] == 0} {
					set spamexitcode [read -nonewline $f]
					close $f
					if {$spamexitcode != ""} {
						set spamexit 1
					}
				}
				if {[catch {open $servicedir/fetchmail/variables/REJECTSPAM r} f] == 0} {
					set rejectspamv [read -nonewline $f]
					close $f
					if {$rejectspamv != ""} {
						set rejectspam 1
						$tmpwin.frame.reject.s configure -state normal
					} else {
						$tmpwin.frame.reject.s configure -state disabled
					}
				}
			}
			if {$spamvar} {
				$tmpwin.frame.args.l   configure -state normal
				$tmpwin.frame.args.e   configure -state normal
				$tmpwin.frame.exitco.c configure -state normal
				$tmpwin.frame.control.s configure -state normal
				$tmpwin.frame.control.b configure -state normal
				if {$spamexit} {
					$tmpwin.frame.reject.c configure -state normal
					$tmpwin.frame.exitco.e configure -state normal
					if {$rejectspam == 1} {
					$tmpwin.frame.reject.s configure -state normal
					} else {
					$tmpwin.frame.reject.s configure -state disabled
					}
				} else {
					$tmpwin.frame.reject.c configure -state disabled
					$tmpwin.frame.reject.s configure -state disabled
					$tmpwin.frame.exitco.e configure -state disabled
				}
			} else {
				$tmpwin.frame.args.l   configure -state disabled
				$tmpwin.frame.args.e   configure -state disabled
				$tmpwin.frame.exitco.c configure -state disabled
				$tmpwin.frame.exitco.e configure -state disabled
				$tmpwin.frame.reject.c configure -state disabled
				$tmpwin.frame.reject.s configure -state disabled
				$tmpwin.frame.control.s configure -state disabled
				$tmpwin.frame.control.b configure -state disabled
			}
		}
		dbserver {
			set dbfifo_name "dbfifo"
			set dbthreads 1
			set memory 5
			set domlimit 0
			set pwcache 1
			if {[file exists $servicedir/dbserver.$tag/variables]} {
				$tmpwin.buttons.run configure -text "Modify"
			} else {
				$tmpwin.buttons.run configure -text "Create"
			}
			if {[catch {open $servicedir/dbserver.$tag/variables/CONTROLDIR r} f] == 0} {
				set tmp [read -nonewline $f]
				close $f
				if {$tmp != ""} {
					set svc_controldir $tmp
				}
			}
			if {[file exists $servicedir/dbserver.$tag/variables/DOMAIN_LIMITS] && [file size $servicedir/dbserver.$tag/variables/DOMAIN_LIMITS]} {
				set domlimit 1
			}
			if {[file exists $servicedir/dbserver.$tag/variables/PASSWD_CACHE] && [file size $servicedir/dbserver.$tag/variables/PASSWD_CACHE]} {
				set pwcache 1
			} else {
				set pwcache 0
			}
			if {[catch {open $servicedir/dbserver.$tag/variables/THREAD_COUNT r} f] == 0} {
				set dbthreads [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/dbserver.$tag/variables/DBFIFO r} f] == 0} {
				set dbfifo_name [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/dbserver.$tag/variables/SOFT_MEM r} f] == 0} {
				set memory [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
		}
		indisrvr {
			set basepath "/mail"
			set avguserquota 2
			set hardquota 50
			set maxdaemons 40
			set maxperip 25
			set memory 5
			if {[file exists $servicedir/indisrvr.$tag/variables]} {
				$tmpwin.buttons.run configure -text "Modify"
			} else {
				$tmpwin.buttons.run configure -text "Create"
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/BASE_PATH r} f] == 0} {
				set basepath [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/MAXDAEMONS r} f] == 0} {
				set maxdaemons [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/MAXPERIP r} f] == 0} {
				set maxperip [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/DEFAULT_DOMAIN r} f] == 0} {
				set default_domain_val [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/LOCALIP r} f] == 0} {
				set ipaddress [read -nonewline $f]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/PORT r} f] == 0} {
				set adminport [read -nonewline $f]
				close $f
			}
			if {$adminport != $tag} {
				set svc_tag 1
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/SOFT_MEM r} f] == 0} {
				set memory [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/MYSQL_HOST r} f] == 0} {
				set mysqlhost [read -nonewline $f]
				close $f
				if {[catch {open $servicedir/indisrvr.$tag/variables/MYSQL_USER r} f] == 0} {
					set mysqluser [read -nonewline $f]
					close $f
				}
				if {[catch {open $servicedir/indisrvr.$tag/variables/MYSQL_PASS r} f] == 0} {
					set mysqlpass [read -nonewline $f]
					close $f
				}
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/AVG_USER_QUOTA r} f] == 0} {
				set avguserquota [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
			if {[catch {open $servicedir/indisrvr.$tag/variables/HARD_QUOTA r} f] == 0} {
				set hardquota [expr [read -nonewline $f] / (1024 * 1024)]
				close $f
			}
		}
	}
}

proc createSvc {mode} {
	global w BWidget_present prgtext
	global smtpport qbase qcount qstart servicedir service_list svc_controldir minfree \
	chkusr domlimit cugmail chkrelay dynroute rblcheck bodycheck paranoid \
	dmasquerade skipsend memory spamvar bodycheckfile qhpsi qhpsival viruscheck viruscheckval \
	spamfilterargs filterlogstatus filterlog masquerade mailcount_limit mailsize_limit \
	odmr authall authself authsmtp antispoofing overquota_mailsize
	global rejectspam rejectspamv spamexit spamexitcode
	global proxy imapport pop3port destport maxdaemons maxperip nolastauth
	global dbfifo_name dbthreads localfilter remotefilter
	global basepath adminport mysqlhost mysqluser mysqlpass avguserquota hardquota
	global folderport default_domain_val usefsync usesyncdir pwcache qregex
	global dnscheck helocheck helofqdn
	variable cntrldir
	source /usr/share/indimail/indium/scripts/global.tcl
	
	if {$BWidget_present == 1} {
		set prgtext "Creating $mode service configuraton"
		progressDialog
	}
	switch -regexp $mode {
		smtp {
			set index [string last "/" $svc_controldir]
			if {$index == -1} {
				set cntrldir $svc_controldir
			} else {
				incr index
				set cntrldir [string range $svc_controldir $index end]
			}
			if {$odmr} {
				set cmd "exec /usr/sbin/svctool --smtp=$smtpport --servicedir=$servicedir \
					--cntrldir=$cntrldir --odmr --maxdaemons=$maxdaemons --maxperip=$maxperip"
			} else {
				set t_min_free [expr $minfree * 1024 * 1024]
				set cmd "exec /usr/sbin/svctool --smtp=$smtpport --qbase=$qbase --qcount=$qcount --qstart=$qstart --servicedir=$servicedir \
					--cntrldir=$cntrldir --min-free=$t_min_free --maxdaemons=$maxdaemons --maxperip=$maxperip"
				if {$usefsync == 1} {
					append cmd " --fsync "
				}
				if {$qregex == 1} {
					append cmd " --qregex "
				}
				if {$dnscheck == 1} {
					append cmd " --dnscheck "
				}
				if {$helofqdn == 1} {
					append cmd " --helofqdn "
				}
				if {$helocheck == 1} {
					append cmd " --helocheck "
				}
				if {$usesyncdir == 1} {
					append cmd " --syncdir "
				}
				if {$chkusr == 1} {
					append cmd " --chkrecipient "
				}
				if {$domlimit == 1} {
					append cmd " --domlimit "
				}
				if {$cugmail == 1} {
					append cmd " --cugmail "
				}
				if {$antispoofing == 1} {
					append cmd " --antispoof "
				}
				if {$authsmtp == 1} {
					append cmd " --authsmtp "
				} else {
					if {$authall == 1} {
						append cmd " --authall "
					} else {
						if {$chkrelay == 1} {
							append cmd " --chkrelay "
						}
					}
				}
				if {$authself == 1} {
					append cmd " --authself "
				}
				if {$dynroute == 1} {
					append cmd " --routes "
				}
				if {$rblcheck == 1} {
					append cmd " --rbl "
				}
				if {$viruscheck == 1} {
					if {$viruscheckval > 0} {
						append cmd " --virus-filter=$viruscheckval "
					}
				}
				if {$qhpsi == 1} {
					if {$qhpsival != ""} {
						append cmd " --qhpsi=$qhpsival "
					}
				}
				if {$bodycheck == 1} {
					if {$bodycheckfile != ""} {
						append cmd " --content-filter=$bodycheckfile "
					} else {
						append cmd " --content-filter "
					}
				}
				if {$paranoid == 1} {
					append cmd " --paranoid "
				}
				if {$dmasquerade == 1} {
					append cmd " --dmasquerade "
				}
				if {$skipsend == 1} {
					append cmd " --skipsend "
				}
				if {$masquerade == 1} {
					append cmd " --masquerade "
				}
				if {$mailcount_limit != -1} {
					append cmd " --deliverylimit-count=$mailcount_limit "
				}
				if {$mailsize_limit != -1} {
					set t_mailsize [expr $mailsize_limit * 1024 * 1024]
					append cmd " --deliverylimit-size=$t_mailsize "
				}
				if {$overquota_mailsize != -1} {
					append cmd " --overquota_mailsize=$overquota_mailsize "
				}
				if {$spamvar && $spamfilterargs != ""} {
					append cmd " --spamfilterargs=$spamfilterargs"
					if {$filterlogstatus == 1} {
						append cmd " --filterlog=$filterlog"
					}
					if {$spamexit == 1} {
						append cmd " --spamexitcode=$spamexitcode"
						if {$rejectspam == 1} {
							append cmd " --rejectspam=$rejectspamv"
						}
					}
					if {$localfilter == 1} {
						append cmd " --localfilter"
					}
					if {$remotefilter == 1} {
						append cmd " --remotefilter"
					}
				}
			}
			if {$memory != -1} {
				set t_memory   [expr $memory * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
		}
		imap {
			set cmd "exec /usr/sbin/svctool --imap=$imapport \
				--servicedir=$servicedir --maxdaemons=$maxdaemons \
				--maxperip=$maxperip"
			if {$default_domain_val == ""} {
				append cmd " --default-domain=$default_domain "
			} else {
				append cmd " --default-domain=$default_domain "
			}
			if {$proxy == 1} {
				append cmd " --proxy=$destport "
			}
			if {$nolastauth == 1} {
				append cmd " --nolastauth "
			}
			if {$domlimit == 1} {
				append cmd " --domlimit "
			}
			if {$memory != -1} {
				set t_memory   [expr $memory * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
		}
		pop3 {
			set cmd "exec /usr/sbin/svctool --pop3=$pop3port \
				--servicedir=$servicedir --maxdaemons=$maxdaemons \
				--maxperip=$maxperip"
			if {$default_domain_val == ""} {
				append cmd " --default-domain=$default_domain "
			} else {
				append cmd " --default-domain=$default_domain "
			}
			if {$proxy == 1} {
				append cmd " --proxy=$destport "
			}
			if {$nolastauth == 1} {
				append cmd " --nolastauth "
			}
			if {$domlimit == 1} {
				append cmd " --domlimit "
			}
			if {$memory != -1} {
				set t_memory   [expr $memory * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
		}
		dbserver {
			set index [string last "/" $svc_controldir]
			if {$index == -1} {
				set cntrldir $svc_controldir
			} else {
				incr index
				set cntrldir [string range $svc_controldir $index end]
			}
			set cmd "exec /usr/sbin/svctool \
				--dbserver=$dbfifo_name \
				--cntrldir=$cntrldir --servicedir=$servicedir --threads=$dbthreads"
			if {$pwcache == 1} {
				append cmd " --password-cache "
			}
			if {$memory != -1} {
				set t_memory   [expr $memory * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
		}
		indisrvr {
			set t_avg_userquota [expr $avguserquota * 1024 * 1024]
			set t_hard_quota [expr $hardquota * 1024 * 1024]
			set cmd "exec /usr/sbin/svctool --indisrvr=$adminport \
				--servicedir=$servicedir --mysqlhost=$mysqlhost \
				--mysqluser=$mysqluser --mysqlpass=$mysqlpass --avguserquota=$t_avg_userquota \
				--hardquota=$t_hard_quota --basepath=$basepath \
				--maxdaemons=$maxdaemons --maxperip=$maxperip"
			if {$memory != -1} {
				set t_memory   [expr $memory * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
		}
		fetchmail {
			set index [string last "/" $svc_controldir]
			if {$index == -1} {
				set cntrldir $svc_controldir
			} else {
				incr index
				set cntrldir [string range $svc_controldir $index end]
			}
			set t_min_free [expr $minfree * 1024 * 1024]
			set cmd "exec /usr/sbin/svctool --fetchmail --qcount=$qcount --qstart=$qstart --servicedir=$servicedir \
				--cntrldir=$cntrldir --min-free=$t_min_free"
			if {$default_domain_val == ""} {
				append cmd " --default-domain=$default_domain "
			} else {
				append cmd " --default-domain=$default_domain "
			}
			if {$usefsync == 1} {
				append cmd " --fsync "
			}
			if {$usesyncdir == 1} {
				append cmd " --syncdir "
			}
			if {$memory != -1} {
				set t_memory   [expr $minfree * 1024 * 1024]
				append cmd " --memory=$t_memory "
			}
			if {$spamvar && $spamfilterargs != ""} {
				append cmd " --spamfilterargs=$spamfilterargs"
				if {$spamexit == 1} {
					append cmd " --spamexitcode=$spamexitcode"
					if {$rejectspam == 1} {
						append cmd " --rejectspam=$rejectspamv"
					}
				}
			}
		}
	}
	set returnstatus [catch {eval $cmd} result]
	catch {destroy .progress}
	if {$returnstatus != 0} {
		msg_dialog .d {svctool} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
	} else {
		catch {exec ls $servicedir} service_list
		if {$mode == "smtp" && $odmr != 0} {
			msg_dialog .d {svctool} "Created configuration for On Demand Mail Relay" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		} else {
			msg_dialog .d {svctool} "Created configuration for $mode" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
}

proc svc {win listwin type} {
	global service_name service_name1 service_name2 service_name3 flag logfd
	source /usr/share/indimail/indium/scripts/global.tcl
	set result ""

	update idletasks
	if {[string compare $type "signal"] == 0} {
		if {[string length $service_name3] == 0} {
			msg_dialog .d {Invalid Service} {Service name required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set result ""
		append result "svc $flag $servicedir/$service_name3\n"
		catch {$dwin.log insert end "$result"}
		catch {exec /usr/bin/svc $flag $servicedir/$service_name3} result
		if {[string length $result] == 0} {
			.statusBar.lab configure -text "svc $flag $servicedir/$service_name3 success"
		} else {
			catch {$dwin.log insert end "$result\n"}
			msg_dialog .d "svc $flag $service_name3" {Command Failed} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	if {[string compare $type "up"] == 0} {
		if {[string length $service_name1] == 0} {
			catch {$dwin.log yview moveto 1}
			msg_dialog .d {Invalid Service} {Service name required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set result ""
		append result "Starting service $servicedir/$service_name1\n"
		catch {$dwin.log insert end "$result"}
		catch {exec /usr/bin/svc -u $servicedir/$service_name1} result
		if {[string length $result] == 0} {
			. configure -cursor watch
			update idletasks
			after 1000
			. configure -cursor {}
			.statusBar.lab configure -text "Started $service_name1"
		} else {
			catch {$dwin.log insert end "$result\n"}
			msg_dialog .d {Startup Failed} "$service_name1:$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	if {[string compare $type "down"] == 0} {
		if {[string length $service_name2] == 0} {
			catch {$dwin.log yview moveto 1}
			msg_dialog .d {Invalid Service} {Service name required} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set result ""
		append result "Shutting service $servicedir/$service_name2\n"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Shutting service $servicedir/$service_name2"
		catch {$dwin.log insert end "$result"}
		catch {exec /usr/bin/svc -d $servicedir/$service_name2} result
		if {[string length $result] == 0} {
			. configure -cursor watch
			update idletasks
			after 1000
			. configure -cursor {}
			.statusBar.lab configure -text "Stopped $service_name2"
		} else {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$atime: $result"
			catch {$dwin.log insert end "$result\n"}
			msg_dialog .d $service_name2 {Stop Failed} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	if {[string compare $type "downall"] == 0} {
		set result ""
		append result "Stopping all services in $servicedir\n"
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$atime: Stopping all services in $servicedir"
		catch {$dwin.log insert end "$result"}
		set service_name [glob -nocomplain $servicedir/*]
		if {[llength $service_name] == 0} {
			$dwin.log yview moveto 1
			msg_dialog .d $servicedir {No Services Found} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set returnstatus 0
		foreach line $service_name {
			catch {exec /usr/bin/svc -d $line} tmp_result
			if {[string length $tmp_result] != 0} {
				set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
				puts $logfd "$atime: $tmp_result"
				set returnstatus 1
				catch {$dwin.log insert end "$tmp_result\n"}
			}
		}
		if {$returnstatus == 0} {
			.statusBar.lab configure -text "Stopped All Services"
		} else {
			msg_dialog .d $servicedir {Some service could not be stopped} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	if {[string compare $type "upall"] == 0} {
		set service_name [glob -nocomplain $servicedir/*]
		if {[llength $service_name] == 0} {
			catch {$dwin.log yview moveto 1}
			msg_dialog .d $servicedir {No Services Found} /usr/share/indimail/indium/images/warning.gif 0 "OK"
			return 1
		}
		set result ""
		append result "Starting all services in $servicedir\n"
		set returnstatus 0
		foreach line $service_name {
			catch {exec /usr/bin/svc -u $line} tmp_result
			if {[string length $tmp_result] != 0} {
				set returnstatus 1
				catch {$dwin.log insert end "$tmp_result\n"}
			}
		}
		if {$returnstatus == 0} {
			.statusBar.lab configure -text "Started all Services"
		} else {
			msg_dialog .d $servicedir {$result} /usr/share/indimail/indium/images/warning.gif 0 "OK"
		}
	}
	catch {$dwin.log yview moveto 1}
	if {[string compare $type "up"] == 0 || [string compare $type "down"] == 0 \
		|| [string compare $type "signal"] == 0 || [string compare $type "upall"] == 0 \
		|| [string compare $type "downall"] == 0} {
		catch {exec ls $servicedir} service_list
		$win.start.right.entry list delete 0 end
		$win.stop.right.entry  list delete 0 end
		set ufound 0
		set dfound 0
		set service_name1 ""
		set service_name2 ""
		set service_name3 ""
		$listwin.list delete 0 end
		foreach line $service_list {
			set cmd "| /usr/bin/svstat $servicedir/$line"
			if {[catch {open $cmd r} f] } {
				catch {$dwin.log insert end "$f\n"}
				msg_dialog .d "svstat" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				break
			}
			set result [read $f]
			svcListFunc $result $line $listwin
			catch {$dwin.log insert end "$result"}
			set returnstatus [catch {close $f} result]
			if {$returnstatus == 1} {
				set dfound 1
				$win.start.right.entry list insert end $line
			} else {
				set ufound 1
				$win.stop.right.entry list insert end $line
			}
			if {[file isdirectory $servicedir/$line/log]} {
				set cmd "| /usr/bin/svstat $servicedir/$line/log"
				if {[catch {open $cmd r} f] } {
					catch {$dwin.log insert end "$f\n"}
					msg_dialog .d "svstat" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
					break
				}
				set result [read $f]
				svcListFunc $result $line/log $listwin
				catch {$dwin.log insert end "$result"}
				set returnstatus [catch {close $f} result]
				if {$returnstatus == 1} {
					set dfound 1
					$win.start.right.entry list insert end $line/log
				} else {
					set ufound 1
					$win.stop.right.entry list insert end $line/log
				}
			}
		}
		if {$dfound} {
			listboxsort $listwin.list status
		} else {
			listboxsort $listwin.list uptimes
		}
		if {$ufound == 0} {
			$win.stop.right.entry configure -commandstate disabled
			if {[file exist /usr/share/indimail/indium/images/red.gif]} {
				$win.start.button configure -image [image create photo -file /usr/share/indimail/indium/images/red.gif]
			}
		} else {
			$win.stop.right.entry configure -commandstate normal
		}
		if {$dfound == 0} {
			$win.start.right.entry configure -commandstate disabled
			if {[file exist /usr/share/indimail/indium/images/green.gif]} {
				$win.start.button configure -image [image create photo -file /usr/share/indimail/indium/images/green.gif]
			}
		} else {
			$win.start.right.entry select 0
			$win.start.right.entry configure -commandstate normal
			if {[file exist /usr/share/indimail/indium/images/red.gif]} {
				$win.start.button configure -image [image create photo -file /usr/share/indimail/indium/images/red.gif]
			}
		}
	}
	catch {$dwin.log yview moveto 1}
}

proc commandLine {} {
	global BWidget_present
	source /usr/share/indimail/indium/scripts/global.tcl
	global program cmdline
	set program ""
	set cmdline ""
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*

	set program_list  {
		"adminclient" \
		"chowkidar" \
		"clearopensmtp" \
		"crc" \
		"crcdiff" \
		"crypt" \
		"dbinfo" \
		"dbquerytest" \
		"hostsync" \
		"logcount" \
		"logmonitor" \
		"logtop" \
		"maildirmake" \
		"mgmtpass" \
		"printdir" \
		"indisrvr" \
		"spost" \
		"updaterules" \
		"vacation" \
		"vaddaliasdomain" \
		"vmoddomain" \
		"vadddomain" \
		"vadduser" \
		"valias" \
		"vbulletin" \
		"vcalias" \
		"vcaliasrev.sh" \
		"vcdir" \
		"vcfilter" \
		"vconvert" \
		"vdeldomain" \
		"vdeloldusers" \
		"vdeluser" \
		"vdominfo" \
		"versioninfo" \
		"vfstab" \
		"vhostid" \
		"vipmap" \
		"vmkpasswd" \
		"vmoduser" \
		"vmoveuser" \
		"vpasswd" \
		"vpopbull" \
		"vrenamedomain" \
		"vrenameuser" \
		"vreorg" \
		"vsetuserquota" \
		"vsmtp" \
		"vuserinfo" \
		"vatrn" \
		"vpriv" \
		"vlimit" \
		"hostcntrl" \
		"ipchange" \
	}
	createWindow
	focus $w
	if {$authenticated != 1} {
		Login 1
	}
	set debug_flag 1
	set Description "Command Line"
	wm title . $Description
	bind . <F1> {doHelp cmdline}
	.statusBar.lab configure -text $Description

	if {$BWidget_present == 1} {
		destroy $lwin
		destroy $rwin
		TitleFrame $w.fr -text $Description -side center -relief ridge -bd 2
		pack $w.fr -side top -anchor w -fill both
		set fr [$w.fr getframe]
		set lwin [frame $fr.left  -relief flat  -bd 2]
		set rwin [frame $fr.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $fr -after $lwin
		set dwin $fr.debug
	} else {
		$w configure -relief ridge -bd 2
		pack $lwin $rwin -pady 40
	}
	text_create $Description 1 40 20
	## Frame 1 #######################################################################
	frame $lwin.cmd
	pack $lwin.cmd -side top -anchor nw

	label $lwin.cmd.label1  -relief raised -text "Program Name" -bd 2 -width 20
	scrollbar $lwin.cmd.scrolly -trough black -command "$lwin.cmd.list yview"
	scrollbar $lwin.cmd.scrollx -trough black -command "$lwin.cmd.list xview" \
		-orient horizontal
	listbox $lwin.cmd.list \
	-xscroll "$lwin.cmd.scrollx set" \
	-yscroll "$lwin.cmd.scrolly set" \
	-selectmode browse \
	-width 20 \
	-setgrid 1 \
	-font $font \
	-height 20
	bind $lwin.cmd.list <<ListboxSelect>> {
		focus $lwin.cmd.list
	}
	set program [lindex $program_list 0]
	bind $lwin.cmd.list <Button-1> {
		set li [$lwin.cmd.list nearest %y]
		$lwin.cmd.list activate $li
		set program [$lwin.cmd.list get $li]
	}
	pack $lwin.cmd.label1 -fill x
	pack $lwin.cmd.scrollx -side bottom -fill x
	pack $lwin.cmd.scrolly -side right  -fill y
	pack $lwin.cmd.list    -side left -expand 1 -fill both

	foreach line $program_list {
		$lwin.cmd.list insert end $line
	}
	$lwin.cmd.list selection clear 0 end
	$lwin.cmd.list selection set 0
	## Frame 2 #######################################################################
	frame $lwin.program
	pack $lwin.program -pady 10 -side top -anchor nw
	label $lwin.program.label -relief raised -text "Command Line"  -bd 2 -width 20
	entry $lwin.program.entry -relief sunken -textvariable cmdline -bd 2 -width 50
	pack $lwin.program.label -side left
	pack $lwin.program.entry -side left -padx 10
	bind $lwin.program.entry <Return> {
		runcmd
	}
	## Frame n #######################################################################
	frame $lwin.but
	pack $lwin.but -side top -anchor nw
	button $lwin.but.run  -text Run    -bg orange    -command "runcmd" \
		-bd 5 -highlightthickness 5 -highlightbackground black
	button $lwin.but.quit -text Cancel -bg IndianRed \
		-bd 5 -highlightthickness 5 -highlightbackground black \
		-command {
			catch {wm withdraw .debug}
			destroyWindows
			set debug_flag 0
			return
		}
	pack $lwin.but.run  -side left -expand 0 -anchor nw -fill x
	pack $lwin.but.quit -side left -expand 1 -anchor nw -fill x
}

proc runcmd {} {
	global program cmdline dwin configs
	set cmd "exec sh -c \"/usr/bin/$program $cmdline\""
	set returnstatus [catch {eval $cmd} result]
	$dwin.log insert end "$result\n"
	$dwin.log yview moveto 1
}

proc secpanel {} {
	global argc argv
	source /usr/share/indimail/indium/scripts/global.tcl
	wm withdraw .
	catch {exec /usr/bin/secpanel "indimail"} result
	wm deiconify .
}

proc addgroup {} {
	global BWidget_present prgtext
	global t_email t_groupname t_oldgroupname t_member Domain t_oldemail userList1 inactiveFlag
	global memberList
	source /usr/share/indimail/indium/scripts/global.tcl
	set w .dname
	variable addgroupfr
	variable optwin
	variable entwin
	variable flag1
	variable buttfr
	variable toolwin
	set flag1 1
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
	set t_email ""
	set t_oldemail ""
	set t_groupname ""
	set t_oldgroupname ""
	set t_member ""
	set memberList {}

	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Group Addresses"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp addgroup}

	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw -expand 1 -fill both
		set pane1  [$pw add -weight 70 -minsize 40]
		set pane2  [$pw add -weight 30 -minsize 10]
		set lf [TitleFrame $pane1.fr -text $Description -side center -relief flat -bd 0]
		pack $lf -side top -anchor nw -fill x
		set rf [TitleFrame $pane2.fr -text "Multi Address Selection" -side center -relief flat -bd 0]
		pack $rf -side top -anchor nw -fill none
		set lwin [$lf getframe]
		set toolwin [$rf getframe]
	} else {
		catch {destroy $lwin}
		catch {destroy $rwin}
		frame $w -relief flat  -bd 2
		pack $w -side left -anchor nw -expand 1 -fill x
		set lwin [frame $w.left  -relief flat  -bd 2]
		set rwin [frame $w.right -relief flat  -bd 2]
		set toolwin $rwin
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $w
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $w -after $lwin
	}
	## Frame 1 #######################################################################
	set twin1 [frame $lwin.1 -relief sunken -bd 2]
	set fr    [frame $lwin.2]
	pack $twin1 $fr -side top -anchor nw -fill x
	set addgroupfr $twin1
	set optwin [frame $fr.1]
	set dummfr [frame $fr.2]
	pack $optwin $dummfr -side left -anchor nw
	if {$BWidget_present == 1} {
		TitleFrame $dummfr.1 -text "Group Address Entry" -side center -relief sunken -bd 2
		set entwin [$dummfr.1 getframe]
	} else {
		set entwin [frame $dummfr.1]
	}
	pack $entwin -side left -anchor nw
	set buttfr [frame $dummfr.2]
	pack $dummfr.1 -side top -padx 5 -anchor nw
	pack $dummfr.2 -side top -padx 5 -pady 5 -anchor sw

	frame $addgroupfr.ent -relief flat -bd 0
	pack $addgroupfr.ent -side top -anchor w

	label  $addgroupfr.ent.l1 -relief flat -text "Domain"     -bd 2 -width 12
	set domain $default_domain
	combobox $addgroupfr.ent.e1 \
		-textvariable Domain \
		-editable false \
		-borderwidth 2 \
		-value $domain \
		-command "setServerVal $addgroupfr.ent.e2"
	foreach line $domain_list {
		$addgroupfr.ent.e1 list insert end $line
	}
	label  $addgroupfr.ent.l2 -relief flat -text "Server"    -bd 2
	set server $adminhost
	combobox $addgroupfr.ent.e2 \
	-textvariable server \
	-editable false \
	-highlightthickness 1 \
	-borderwidth 2
	catch {$addgropfr.ent.e2 list insert 0 $adminhost}

	button $addgroupfr.ent.showall -relief raised -bd 4 -bg IndianRed
	$addgroupfr.ent.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	balloonHelp $addgroupfr.ent.showall  "Show/Hide Columns"
	$addgroupfr.ent.showall configure \
		-command {showContextMenu $addgroupfr.1.listbox}

	pack $addgroupfr.ent.l1 $addgroupfr.ent.e1 $addgroupfr.ent.l2 $addgroupfr.ent.e2 $addgroupfr.ent.showall -side left
	frame $addgroupfr.1
	frame $addgroupfr.2
	pack $addgroupfr.1 $addgroupfr.2 -padx 5 -side left
	scrollbar $addgroupfr.1.vsb -orient vertical   -trough black \
		-command [list $addgroupfr.1.listbox yview]
	scrollbar $addgroupfr.1.hsb -orient horizontal -trough black \
		-command [list $addgroupfr.1.listbox xview]
	mclistbox $addgroupfr.1.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 40 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
		-selectcommand {selectGroup $addgroupfr.1.listbox $addgroupfr.2.listbox $addgroupfr.2.label} \
	    -xscrollcommand [list $addgroupfr.1.hsb set] \
	    -yscrollcommand [list $addgroupfr.1.vsb set]
	bind $addgroupfr.1.listbox <<ListboxSelect>> {
		focus $addgroupfr.1.listbox
	}
	bind $addgroupfr.1.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	$addgroupfr.1.listbox column add email     -label "Email"      -width 25
	$addgroupfr.1.listbox column add groupname -label "GroupName"  -width 15

	$addgroupfr.1.listbox label bind email     <ButtonPress-1> "listboxsort %W email"
	$addgroupfr.1.listbox label bind groupname <ButtonPress-1> "listboxsort %W groupname"

	pack $addgroupfr.1.hsb     -side bottom -fill x
	pack $addgroupfr.1.vsb     -side right  -fill y
	pack $addgroupfr.1.listbox -side left -expand 1 -fill both

	label $addgroupfr.2.label  -relief raised -text "Member Emailid" -bd 2 -width 20
	scrollbar $addgroupfr.2.scrolly -trough black \
		-command "$addgroupfr.2.listbox yview"
	scrollbar $addgroupfr.2.scrollx -trough black \
		-command "$addgroupfr.2.listbox xview" -orient horizontal
	listbox $addgroupfr.2.listbox \
		-xscroll "$addgroupfr.2.scrollx set" \
		-yscroll "$addgroupfr.2.scrolly set" \
		-selectmode browse \
		-height 10 \
		-width 30 \
		-setgrid 1 \
		-listvar memberList \
		-font $font
	bind $addgroupfr.2.listbox <<ListboxSelect>> {
		set li [$addgroupfr.2.listbox curselection]
		if {$li != ""} {
			$addgroupfr.2.listbox activate $li
			set t_member [$addgroupfr.2.listbox get $li]
			set t_oldmember $t_member
		}
		focus $addgroupfr.2.listbox
	}
	pack $addgroupfr.2.label   -fill x
	pack $addgroupfr.2.scrollx -side bottom -fill x
	pack $addgroupfr.2.scrolly -side right  -fill y
	pack $addgroupfr.2.listbox -side left

	scrollbar $toolwin.scrolly -trough black \
		-command "$toolwin.listbox yview"
	scrollbar $toolwin.scrollx -trough black \
		-command "$toolwin.listbox xview" -orient horizontal
	listbox $toolwin.listbox \
		-selectmode extended \
		-xscroll "$toolwin.scrollx set" \
		-yscroll "$toolwin.scrolly set" \
		-height 20 \
		-width 30 \
		-setgrid 1 \
		-listvar ::userList1 \
		-font $font \
		-state disabled
	pack $toolwin.scrollx -side bottom -fill x
	pack $toolwin.scrolly -side right  -fill y
	pack $toolwin.listbox -side left

	if {$BWidget_present == 1} {
		TitleFrame $optwin.options -text "Options" -side center -relief sunken -bd 2
		pack $optwin.options -side top -anchor nw -fill y -expand 1
		set opframe [$optwin.options getframe]
	} else {
		frame $optwin.options -relief ridge -bd 2
		pack $optwin.options -side top -anchor nw -fill y -expand 1
		set opframe $optwin.options
	}
	radiobutton $opframe.1 -value 1 -variable flag1 -text "Group List" -underline 0 \
		-command {
			set t_email ""
			set t_oldemail ""
			set t_groupname ""
			set t_oldgroupname ""
			set t_member ""
			$entwin.1.entry configure -state disabled
			$entwin.2.entry configure -state disabled
			$entwin.3.entry configure -state disabled
			$entwin.3.b     configure -state disabled
			$entwin.1.entry configure -relief flat
			$entwin.2.entry configure -relief flat
			$entwin.3.entry configure -relief flat
			$addgroupfr.2.label configure -text "Member Emailid"
			$toolwin.listbox configure -state disabled
			bind $toolwin.listbox <<ListboxSelect>> ""
			$buttfr.info configure -text "List"
			$buttfr.info configure -cursor {}
		}
	radiobutton $opframe.2 -value 2 -variable flag1 -text "Add Group"  -underline 0 \
		-command {
			set t_email ""
			set t_oldemail ""
			set t_groupname ""
			set t_oldgroupname ""
			set t_member ""
			$entwin.1.entry configure -state normal
			$entwin.2.entry configure -state normal
			$entwin.3.entry configure -state disabled
			$entwin.3.b     configure -state disabled
			$entwin.1.entry configure -relief sunken
			$entwin.2.entry configure -relief sunken
			$entwin.3.entry configure -relief flat
			$addgroupfr.2.label configure -text "Member Emailid"
			$toolwin.listbox configure -state disabled
			bind $toolwin.listbox <<ListboxSelect>> "" 
			$buttfr.info configure -text "Add"
			$buttfr.info configure -cursor {}
			$addgroupfr.1.listbox selection clear 0 end
		}
	radiobutton $opframe.3 -value 3 -variable flag1 -text "Modify Group"  -underline 0 \
		-command {
			if {$t_email == ""} {
				$buttfr.info configure -text "List"
				set flag1 1
			} else {
				set t_oldemail $t_email
				set t_oldgroupname $t_groupname
				$entwin.1.entry configure -state normal
				$entwin.2.entry configure -state normal
				$entwin.3.entry configure -state disabled
				$entwin.3.b     configure -state disabled
				$entwin.1.entry configure -relief sunken
				$entwin.2.entry configure -relief sunken
				$entwin.3.entry configure -relief flat
				$addgroupfr.2.label configure -text "Member Emailid"
				$toolwin.listbox configure -state disabled
				bind $toolwin.listbox <<ListboxSelect>> "" 
				$buttfr.info configure -text "Modify"
				$buttfr.info configure -cursor {}
			}
		}
	radiobutton $opframe.4 -value 4 -variable flag1 -text "Delete Group"  -underline 0 \
		-command {
			if {$t_email == ""} {
				$buttfr.info configure -text "List"
				set flag1 1
			} else {
				$entwin.1.entry configure -state disabled
				$entwin.2.entry configure -state disabled
				$entwin.3.entry configure -state disabled
				$entwin.3.b     configure -state disabled
				$entwin.1.entry configure -relief flat
				$entwin.2.entry configure -relief flat
				$entwin.3.entry configure -relief flat
				$addgroupfr.2.label configure -text "Member Emailid"
				$toolwin.listbox configure -state disabled
				bind $toolwin.listbox <<ListboxSelect>> "" 
				$buttfr.info configure -text "Delete"
				$buttfr.info configure -cursor pirate
			}
		}
	radiobutton $opframe.5 -value 5 -variable flag1 -text "Add Member"    -underline 0 \
		-command {
			if {$t_email == ""} {
				$buttfr.info configure -text "List"
				set flag1 1
			} else {
				set t_member ""
				$entwin.1.entry configure -state disabled
				$entwin.2.entry configure -state disabled
				$entwin.3.entry configure -state normal
				$entwin.3.b     configure -state normal
				$entwin.1.entry configure -relief flat
				$entwin.2.entry configure -relief flat
				$entwin.3.entry configure -relief sunken
				$toolwin.listbox configure -state normal
				bind $toolwin.listbox <<ListboxSelect>> {
					$addgroupfr.2.label configure -text "Member CurSelection"
					set memberList {}
					focus $toolwin.listbox
					set t_member ""
					set t_oldmember ""
					foreach index [$toolwin.listbox curselection] {
						lappend memberList [$toolwin.listbox get $index]
					}
				}
				$buttfr.info configure -text "Add"
				$buttfr.info configure -cursor {}
			}
		}
	radiobutton $opframe.6 -value 6 -variable flag1 -text "Modify Member" -underline 0 \
		-command {
			if {$t_email == ""} {
				$buttfr.info configure -text "List"
				set flag1 1
			} else {
				set t_oldmember $t_member
				$entwin.1.entry configure -state disabled
				$entwin.2.entry configure -state disabled
				$entwin.3.entry configure -state normal
				$entwin.3.b     configure -state disabled
				$entwin.1.entry configure -relief flat
				$entwin.2.entry configure -relief flat
				$entwin.3.entry configure -relief sunken
				$addgroupfr.2.label configure -text "Member Emailid"
				$toolwin.listbox configure -state disabled
				bind $toolwin.listbox <<ListboxSelect>> "" 
				$buttfr.info configure -text "Modify"
				$buttfr.info configure -cursor {}
			}
		}
	radiobutton $opframe.7 -value 7 -variable flag1 -text "Delete Member" -underline 0 \
		-command {
			if {$t_email == ""} {
				$buttfr.info configure -text "List"
				set flag1 1
			} else {
				$entwin.1.entry configure -state disabled
				$entwin.2.entry configure -state disabled
				$entwin.3.entry configure -state disabled
				$entwin.3.b     configure -state disabled
				$entwin.1.entry configure -relief flat
				$entwin.2.entry configure -relief flat
				$entwin.3.entry configure -relief flat
				$addgroupfr.2.label configure -text "Member Emailid"
				$toolwin.listbox configure -state disabled
				bind $toolwin.listbox <<ListboxSelect>> "" 
				$buttfr.info configure -text "Delete"
				$buttfr.info configure -cursor pirate
			}
		}

	frame $entwin.1
	frame $entwin.2
	frame $entwin.3
	pack $entwin.1 $entwin.2 $entwin.3 -side top

	label  $entwin.1.label -relief flat -text "Email" -bd 2        -width 15
	entry  $entwin.1.entry -relief flat -textvariable t_email -width 35 -state disabled
	pack $entwin.1.label $entwin.1.entry -side left
	bind $entwin.1.entry <FocusOut> {
		set index [string last "@" $t_email]
		if {$index == -1} {
			set t_groupname $t_email
			append t_email "@$Domain"
		} else {
			set name   [string range $t_email 0 [expr $index - 1]]
			set t_dom  [string range $t_email [expr $index + 1] end]
			if {[string compare $t_dom $domain] != 0} {
				set action [msg_dialog .d {Add Group} "Domain should be $Domain\nModify Domain to $Domain ?" /usr/share/indimail/indium/images/warning.gif 0 "OK"]
				if {$action == 1} {
					set t_email $name@$Domain
					set t_groupname $name
				} else {
					set t_email ""
					set t_groupname ""
				}
			} else {
				set t_email $name@$Domain
				set t_groupname $name
			}
		}
	}

	label  $entwin.2.label -relief flat -text "GroupName" -bd 2    -width 15
	entry  $entwin.2.entry -relief flat -textvariable t_groupname -width 35 -state disabled \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	pack $entwin.2.label $entwin.2.entry -side left -anchor nw

	label $entwin.3.label -relief flat -text "Member Email" -bd 2 -width 15
	hugecombo $entwin.3.entry -relief flat -textvariable t_member -width 29 -state disabled \
		-vcmd {expr {[string length %P]<=96}} -validate key -invcmd bell -listvariable ::userList1
	button $entwin.3.b \
		-command {list_user2 $Domain $server $inactiveFlag; $entwin.3.entry list open} -state disabled
	balloonHelp $entwin.3.b "List Users on System"
	$entwin.3.b config -image [image create photo -data "R0lGODlhEAAQAIMAAPwCBAQCBPz+/MTCxISChMT+/ATCxASChFxaXAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARaEMg5gw00yyDGIAR1YUDggeFWFIZhnSBZrsZxdIOFEGTA2oeBAHeyuGwvzxBlYdUOLROMFzDQntJPrNoqAKUBaqnV+k57ZORruykHDj2LqIzUVKp1u0iuB/gjACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs="]
	pack $entwin.3.label $entwin.3.entry $entwin.3.b -side left -anchor nw

	pack $opframe.1 $opframe.2 $opframe.3 $opframe.4 $opframe.5 $opframe.6 $opframe.7 -side top -anchor w
	button $buttfr.info  -text List -bg Orange \
		-command {run_group $flag1 $addgroupfr.1.listbox $addgroupfr.2.listbox} -bd 5 \
		-highlightthickness 5 -highlightbackground black -width 10
	button $buttfr.quit -text Quit -bg IndianRed \
		-command "destroyWindows;return" -bd 5 \
		-highlightthickness 5 -highlightbackground black -width 10
	pack $buttfr.info $buttfr.quit -side left -expand 0 -anchor sw -fill none
}

proc selectGroup {w1 w2 w3 args} {
	global t_email t_firstname t_groupname t_oldemail t_oldgroupname t_member
	source /usr/share/indimail/indium/scripts/global.tcl

	$w3 configure -text "Member Emailid"
	if {[info exists args] && [string length $args] > 0} {
		set t_email     [lindex [$w1 get $args] 0]
		set t_groupname [lindex [$w1 get $args] 1]
		set t_oldemail $t_email
		set t_oldgroupname $t_groupname
		set t_member ""
		groupMember $w2
	}
}

proc groupMember {w1} {
	global t_email
	source /usr/share/indimail/indium/scripts/global.tcl

	set cmd "| /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -s $t_email\""
	if {[catch {open $cmd r} f] } {
		msg_dialog .d {Add Group} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	$w1 delete 0 end
	while {[gets $f line] >= 0} {
		if {[string match -nocase "*no such user" $line] == 1} {
			msg_dialog .d {userinfo} "$t_email: No such Group" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			catch {close $f}
			return 1
		}
		set alias [string trim [string range $line [expr [string first "->" $line] + 2] end]]
		$w1 insert end $alias
	}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		msg_dialog .d {valias Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
}

proc run_group {operation dbwin mwin} {
	global Domain prgtext
	global BWidget_present
	global t_email t_groupname t_member t_oldmember t_oldemail t_oldgroupname memberList
	source /usr/share/indimail/indium/scripts/global.tcl

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	switch $operation {
		1 {
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			if {[string length $Domain] == 0} {
				set cmd "| @ldapbindir@/ldapsearch -x -b \"o=indimail\"  \"givenName=MailGroup\" | /usr/bin/ldapaddr"
			} else {
				set cmd "| @ldapbindir@/ldapsearch -x -b \"ou=$Domain,o=indimail\" \"givenName=MailGroup\" | /usr/bin/ldapaddr"
			}
			if {[catch {open $cmd r} f] } {
				catch {destroy .progress}
				msg_dialog .d {ldapsearch Command Failed} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			$dbwin delete 0 end
			$mwin  delete 0 end
			while {[gets $f line] >= 0} {
				set email     [lindex $line 0]
				set firstname [lindex $line 1]
				set lastname  [lindex $line 2]
				$dbwin insert end [list $email $lastname]
			}
			if {$BWidget_present == 1} {
				catch {destroy .progress}
			}
			set returnstatus [catch {close $f} result]
			if {$returnstatus != 0} {
				$dbwin delete 0 end
				if {[string compare $result "child process exited abnormally"] != 0} {
					msg_dialog .d {ldapsearch Command Failed} $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				} else {
					.statusBar.lab configure -text "No rows selected"
				}
				return 1
			}
		}
		2 {
			if {[string length $t_email] == 0} {
				msg_dialog .d "Add Group" "Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_groupname] == 0} {
				msg_dialog .d "Add Group" "GroupName Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vgroup -a $t_email -c $t_groupname postmaster\""
			runCommand $cmd
			if {$returnstatus == 0} {
				run_group 1 $dbwin $mwin
				.statusBar.lab configure -text "Added Group $t_email"
				msg_dialog .d "Add Group" "Added Group $t_email" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				set tmp_result $result
				.statusBar.lab configure -text "Address addition failed for $t_email"
				msg_dialog .d "Add Group" "Group addition $t_email\n$tmp_result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
		3 {
			if {[string length $t_email] == 0} {
				msg_dialog .d "Modify Group" "Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_groupname] == 0} {
				msg_dialog .d "Modify Group" "Groupname Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string compare $t_oldgroupname $t_groupname] == 0 && [string compare $t_oldemail $t_email] == 0} {
				return 0
			}
			if {[string compare $t_oldemail $t_email] != 0} {
				set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vrenameuser $t_oldemail $t_email\""
				runCommand $cmd
				if {$returnstatus != 0} {
					.statusBar.lab configure -text "Group rename $t_oldemail to $t_email failed"
					msg_dialog .d "Rename Group" "Group rename $t_oldemail to $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
					return 1
				} else {
					run_group 1 $dbwin $mwin
					set t_oldemail $t_email
				}
			}
			if {[string compare $t_oldgroupname $t_groupname] != 0} {
				set gecos "MailGroup $t_groupname"
				set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vmoduser -c \\\"$gecos\\\" $t_email\""
				runCommand $cmd
				if {$returnstatus == 0} {
					run_group 1 $dbwin $mwin
					.statusBar.lab configure -text "Modified Group $t_email"
					msg_dialog .d "Modify Group" "Modified Group $t_email" /usr/share/indimail/indium/images/warning.gif 0 "OK"
					set t_oldgroupname $t_groupname
				} else {
					.statusBar.lab configure -text "Group Modification failed for $t_email"
					msg_dialog .d "Modify Group" "Group Modification failed for $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
					return 1
				}
			}
		}
		4 {
			set msg "You are About to Delete Group $t_email. Click OK to continue\n"
			set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
			if {$action != 1} {
				return 1
			}
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"vdeluser $t_email\""
			runCommand $cmd
			if {$returnstatus == 0} {
				run_group 1 $dbwin $mwin
				set t_email ""
				set t_oldemail ""
				set t_groupname ""
				set t_oldgroupname ""
				set t_member ""
				set t_oldmember ""
				.statusBar.lab configure -text "Deleted Group $t_email"
				msg_dialog .d "Delete Group" "Deleted Group $t_email" /usr/share/indimail/indium/images/warning.gif 0 "OK"
			} else {
				.statusBar.lab configure -text "Group Deletion failed for $t_email"
				msg_dialog .d "Delete Group" "Group Deletion failed for $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
		5 {
			if {[string length $t_email] == 0} {
				msg_dialog .d "Add Member" "Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_member] == 0 && [llength $memberList] == 0} {
				msg_dialog .d "Add Member" "Member Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$t_member != ""} {
				lappend memberList $t_member
			}
			foreach alias $memberList {
				set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -i \\\"$alias\\\" $t_email\""
				runCommand $cmd
				if {$returnstatus == 0} {
					groupMember $mwin
					.statusBar.lab configure -text "Added Member $t_member to Group $t_email"
				} else {
					.statusBar.lab configure -text "Failed to add member $t_email for Group $t_email"
					msg_dialog .d "Delete Group" "Failed to add member $t_email for Group $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				}
			}
		}
		6 {
			if {[string length $t_email] == 0} {
				msg_dialog .d "Add Member" "Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_member] == 0} {
				msg_dialog .d "Add Member" "Member Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_oldmember] == 0} {
				msg_dialog .d "Add Member" "Old Member Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -u \\\"$t_oldmember\\\" -i \\\"$t_member\\\" $t_email\""
			runCommand $cmd
			if {$returnstatus == 0} {
				groupMember $mwin
				.statusBar.lab configure -text "Modified Member $t_oldmember to $t_member for Group $t_email"
				msg_dialog .d "Add Member" "Modified Member $t_oldmember to $t_member for $t_email" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				set t_oldmember $t_member
			} else {
				.statusBar.lab configure -text "Failed to modify member $t_email for Group $t_email"
				msg_dialog .d "Delete Group" "Failed to modify member $t_email for Group $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
		7 {
			if {[string length $t_email] == 0} {
				msg_dialog .d "Delete Member" "Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[string length $t_member] == 0} {
				msg_dialog .d "Delete Member" "Member Email Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c \"valias -d \\\"$t_member\\\" $t_email\""
			runCommand $cmd
			if {$returnstatus == 0} {
				groupMember $mwin
				set t_member ""
				.statusBar.lab configure -text "Deleted Member $t_member for Group $t_email"
			} else {
				.statusBar.lab configure -text "Failed to delete member $t_email from Group $t_email"
				msg_dialog .d "Delete Group" "Failed to delete member $t_email from Group $t_email\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
	}
	return 0
}

proc vdeloldusers {} {
	global BWidget_present prgtext
	source /usr/share/indimail/indium/scripts/global.tcl
	variable iage
	variable mage
	variable tage
	variable flag1
	variable flag2
	variable flag3
	variable runfast
	variable verbose
	set result ""
	set font -*-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*
	set w .dname

	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Delete Old Users"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp vdeloldusers}
	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw -expand 1 -fill both
		set pane1  [$pw add -weight 35 -minsize 200]
		set pane2  [$pw add -weight 65 -minsize 200]
		set lf [TitleFrame $pane1.fr -text $Description -side center -relief ridge -bd 2]
		pack $lf -side top -anchor nw -fill both
		set tf [$lf getframe]
		set lwin $tf
		set dwin $pane2.debug
	} else {
		catch {destroy $lwin}
		catch {destroy $rwin}
		frame $w -relief flat  -bd 2
		pack $w -side left -anchor nw -expand 1 -fill x
		set lwin [frame $w.left  -relief flat  -bd 2]
		set rwin [frame $w.right -relief flat  -bd 2]
		pack $lwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $w
		pack $rwin -side left -anchor nw -expand 0 -fill x -anchor nw -in $w -after $lwin
		set dwin $w.debug
	}
	text_create $Description 1 45 10
	## Frame 1 #######################################################################
	frame $lwin.domain -relief groove -bd 2
	pack $lwin.domain -side top -anchor nw -padx 5 -pady 2
	label $lwin.domain.l -text "Domain" -relief flat -bd 2
	set domain $default_domain
	combobox $lwin.domain.e \
	-textvariable domain \
	-editable false \
	-command "setServerVal $lwin.server.e" \
	-highlightthickness 1
	foreach line $domain_list {
		$lwin.domain.e list insert end $line
	}
	pack $lwin.domain.l $lwin.domain.e -side left -anchor nw
	## Frame 2 #######################################################################
	frame $lwin.server -relief groove -bd 2
	pack $lwin.server -side top -anchor nw -padx 5 -pady 2
	label  $lwin.server.l -text "Server" -relief flat -bd 2
	set server $adminhost
	combobox $lwin.server.e \
	-textvariable server \
	-editable false \
	-highlightthickness 1 \
	-borderwidth 2
	catch {$lwin.server.e list insert 0 $adminhost}
	pack $lwin.server.l $lwin.server.e -side left -anchor nw
	## Frame 3 #######################################################################
	frame $lwin.iage -relief groove -bd 2
	pack $lwin.iage -side top -anchor nw -padx 5 -pady 2
	label  $lwin.iage.l -text "Inactivity Age" -relief flat -bd 2
	set iage 60
	if {$BWidget_present} {
		SpinBox $lwin.iage.e -relief sunken -textvariable iage \
			-width 5 -range {0 3650 30} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.iage.e   -relief sunken -textvariable iage -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.iage.l $lwin.iage.e -side left -anchor nw
	## Frame 4 #######################################################################
	frame $lwin.mage -relief groove -bd 2
	pack $lwin.mage -side top -anchor nw -padx 5 -pady 2
	set mage -1
	checkbutton $lwin.mage.c -text "Max MailAge" -relief flat -variable flag1 \
		-command {
		if {$flag1 == 1} {
			set mage 30
		} else {
			set mage -1
		}
	}
	if {$BWidget_present} {
		SpinBox $lwin.mage.e -relief sunken -textvariable mage \
			-width 5 -range {0 3650 30} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.mage.e   -relief sunken -textvariable mage -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.mage.c $lwin.mage.e -side left -anchor nw
	## Frame 5 #######################################################################
	frame $lwin.tage -relief groove -bd 2
	pack $lwin.tage -side top -anchor nw -padx 5 -pady 2
	set tage -1
	checkbutton $lwin.tage.c -text "Clean Trash" -relief flat -variable flag2 \
		-command {
		if {$flag2 == 1} {
			set tage 1
		} else {
			set tage -1
		}
	}
	if {$BWidget_present} {
		SpinBox $lwin.tage.e -relief sunken -textvariable tage \
			-width 5 -range {0 60 1} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.tage.e   -relief sunken -textvariable tage -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	label $lwin.tage.l -text " days active users" -state active -bg $bgColor
	pack $lwin.tage.c $lwin.tage.e $lwin.tage.l -side left -anchor w
	## Frame 6 #######################################################################
	frame $lwin.fast -bd 2
	pack $lwin.fast -side top -anchor nw -padx 5 -pady 2
	set runfast 0
	checkbutton $lwin.fast.c -text "Run Fast" -relief flat -variable runfast
	pack $lwin.fast.c -side left -anchor nw
	## Frame 7 #######################################################################
	frame $lwin.verbose -bd 2
	pack $lwin.verbose -side top -anchor nw -padx 5 -pady 2
	set verbose 1
	checkbutton $lwin.verbose.c -text "Verbose" -relief flat -variable verbose
	pack $lwin.verbose.c -side left -anchor nw
	## Frame 7 #######################################################################
	if {$BWidget_present == 1} {
		TitleFrame $lwin.options -text "Options" -side center -relief ridge -bd 2
		pack $lwin.options -side top -anchor nw -fill y -expand 1
		set opframe [$lwin.options getframe]
	} else {
		frame $lwin.options -relief ridge -bd 2
		pack $lwin.options -side top -anchor nw -fill y -expand 1
		set opframe $lwin.options
	}
	set flag3 1
	radiobutton $opframe.1 -value 1 -variable flag3 -text "Report Mode" -underline 0
	radiobutton $opframe.2 -value 2 -variable flag3 -text "Clear Mails" -underline 0
	radiobutton $opframe.3 -value 3 -variable flag3 -text "Inactivate User" -underline 0
	radiobutton $opframe.4 -value 4 -variable flag3 -text "Delete User" -underline 0
	pack $opframe.1 $opframe.2 $opframe.3 $opframe.4 -side top -anchor w

	## Frame n #######################################################################
	frame $lwin.but
	pack $lwin.but -side top -anchor nw
	button $lwin.but.edit -text Delete -bg orange \
		-bd 5 -highlightthickness 5 -highlightbackground black \
		-command {run_delolduser $domain $server $flag3 $iage $mage $tage $runfast $verbose}
	button $lwin.but.quit -text Quit   -bg IndianRed  \
		-command "destroyWindows;return" \
		-bd 5 -highlightthickness 5 -highlightbackground black
	pack $lwin.but.edit -side left -expand 0 -pady 5 -anchor nw -fill none
	pack $lwin.but.quit -side left -expand 1 -pady 5 -anchor nw -fill x
}

proc run_delolduser {domain server option iage mage tage runfast verbose} {
	global BWidget_present prgtext logfd logevent errorCode
	source /usr/share/indimail/indium/scripts/global.tcl

	if {$option != 1} {
		set msg "You are About to Delete Users/Mails.\nAre you sure you want to do this?\nClick OK to continue"
		set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
		if {$action != 1} {
			return
		}
	}
	set vdelopt ""
	switch $option {
		1 {
			append vdelopt " -r "
		}
		2 {
			append vdelopt " -c "
		}
		3 {
			append vdelopt " -i "
		}
		4 {
			append vdelopt " -p "
		}
	}
	if {$runfast == 1} {
		append vdelopt " -f "
	}
	if {$verbose == 1} {
		append vdelopt " -v "
	}
	catch {$dwin.log insert end "vdeloldusers -d $domain $vdelopt -a $iage -u $mage -t $tage\n"}
	set vdelcmd "\"vdeloldusers -d $domain $vdelopt -a $iage -u $mage -t $tage\""
	set cmd "| /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vdelcmd"
	set returnstatus [catch {open $cmd r} f]
	if {[info exists logfd] && [info exists logevent]} {
		incr logevent
	} else {
		set logevent 1
	}
	if {$returnstatus} {
		if {[info exists logfd]} {
			set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
			puts $logfd "$logevent: $atime: Cmd \[$cmd\], Status $returnstatus, Code $errorCode"
			if {$result != ""} {
				puts $logfd "Command Output -----------------"
				puts $logfd "$f"
				puts $logfd "----------------------------------------------------"
			}
			flush $logfd
		}
		msg_dialog .d {Delete Old Users} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	if {[info exists logfd]} {
		set atime [clock format [clock seconds] -format "%d:%m:%y %H:%M:%S"]
		puts $logfd "$logevent: $atime: Cmd \[$cmd\], Status 0"
		flush $logfd
	}
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line \n"}
		catch {$dwin.log yview moveto 1}
	}
	catch {$dwin.log yview moveto 1}
	set returnstatus [catch {close $f} result]
	if {$returnstatus == 0} {
		.statusBar.lab configure -text "Deleted Old Users"
	} else {
		.statusBar.lab configure -text "vdeloldusers failed"
		msg_dialog .d "Delete Old Users" "vdeloldusers failed\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
	}
}

proc vpriv {privwin} {
	global BWidget_present prgtext
	global t_adminuser t_olduser program cmdargs Domain admin_list
	source /usr/share/indimail/indium/scripts/global.tcl
	variable privfr
	variable optwin
	variable entwin
	variable flag4
	variable buttfr
	set flag4 1
	set program ""
	set cmdargs ""

	## Frame 1 #######################################################################
	catch {destroy $privwin.t}
	set tf [TitleFrame $privwin.t -text "Program Privileges Editor" -side center -relief sunken -bd 2]
	pack $tf -side top -expand 1 -fill x -anchor nw
	set privfr [frame [$tf getframe].1]
	set fr     [frame [$tf getframe].2]
	pack $privfr $fr -side top -anchor nw
	set optwin [frame $fr.1]
	pack $optwin -side left -anchor nw
	if {$BWidget_present == 1} {
		TitleFrame $fr.2 -text "Program Privileges" -side center -relief sunken -bd 2
		pack $fr.2 -side left -expand 1 -fill x -anchor nw
		set entwin [$fr.2 getframe]
	} else {
		set entwin [frame $fr.2]
		pack $entwin -side left -expand 1 -fill x -anchor nw
	}
	frame $privfr.f -bd 0
	pack $privfr.f -side top -anchor nw
	label $privfr.f.l -text "Admin Username"
	hugecombo  $privfr.f.e -relief sunken -textvariable t_adminuser -bd 2 -width 25 \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell -listvariable ::admin_list
	pack $privfr.f.l $privfr.f.e -side left -anchor nw

	scrollbar $privfr.vsb -orient vertical   -trough black \
		-command [list $privfr.listbox yview]
	scrollbar $privfr.hsb -orient horizontal -trough black \
		-command [list $privfr.listbox xview]
	mclistbox $privfr.listbox \
	    -bd 0 \
		-font "Terminal" \
	    -height 10 \
	    -width 50 \
	    -labelanchor w \
	    -columnrelief flat \
	    -columnborderwidth 2 \
	    -labelborderwidth 2 \
		-resizablecolumn 1 \
	    -selectmode single \
		-selectcommand {selectPriv $privfr.listbox} \
	    -xscrollcommand [list $privfr.hsb set] \
	    -yscrollcommand [list $privfr.vsb set]
	bind $privfr.listbox <<ListboxSelect>> {
		focus $privfr.listbox
	}
	bind $privfr.listbox <ButtonPress-3> \
	{ \
		showContextMenu1 \
	   	[::mclistbox::convert %W -W] \
	   	[::mclistbox::convert %W -x %x] \
	   	[::mclistbox::convert %W -y %y] \
		%X %Y \
	}
	$privfr.listbox column add program -label "Program"            -width 35
	$privfr.listbox column add cmdargs -label "Program Switches"   -width 15

	$privfr.listbox label bind program <ButtonPress-1> "listboxsort %W program"
	$privfr.listbox label bind cmdargs <ButtonPress-1> "listboxsort %W cmdargs"

	pack $privfr.hsb     -side bottom -fill x
	pack $privfr.vsb     -side right  -fill y
	pack $privfr.listbox -side left -expand 1 -fill both

	if {$BWidget_present == 1} {
		TitleFrame $optwin.options -text "Options" -side center -relief sunken -bd 2
		pack $optwin.options -side top -padx 10 -anchor nw -fill y -expand 1
		set opframe [$optwin.options getframe]
	} else {
		frame $optwin.options -relief ridge -bd 2
		pack $optwin.options -side top -anchor nw -fill y -expand 1
		set opframe $optwin.options
	}
	radiobutton $opframe.1 -value 1 -variable flag4 -text "Privilege List" -underline 0 \
		-command {
			$entwin.1.entry configure -relief flat -state disabled
			$entwin.2.entry configure -relief flat -state disabled
			$buttfr.info configure -text "List"
			$buttfr.info configure -cursor {}
		}
	radiobutton $opframe.2 -value 2 -variable flag4 -text "Add Privilege"  -underline 0 \
		-command {
			set program ""
			set cmdargs ""
			$entwin.1.entry configure -relief sunken -state normal
			$entwin.2.entry configure -relief sunken -state normal
			$buttfr.info configure -text "Add"
			$privfr.listbox selection clear 0 end
			$buttfr.info configure -cursor {}
		}
	radiobutton $opframe.3 -value 3 -variable flag4 -text "Modify Privilege"  -underline 0 \
		-command {
			$entwin.1.entry configure -relief sunken -state normal
			$entwin.2.entry configure -relief sunken -state normal
			if {$t_adminuser == ""} {
				$buttfr.info configure -text "List"
				set flag4 1
			} else {
				$buttfr.info configure -text "Modify"
				$buttfr.info configure -cursor {}
			}
		}
	radiobutton $opframe.4 -value 4 -variable flag4 -text "Delete Privilege"  -underline 0 \
		-command {
			$entwin.1.entry configure -relief flat -state disabled
			$entwin.2.entry configure -relief flat -state disabled
			if {$t_adminuser == ""} {
				$buttfr.info configure -text "List"
				set flag4 1
			} else {
				$buttfr.info configure -text "Delete"
				$buttfr.info configure -cursor pirate
			}
		}

	frame $entwin.1
	frame $entwin.2
	pack $entwin.1 $entwin.2 -side top
	set buttfr [frame $entwin.3]
	pack $buttfr -side top -padx 5 -anchor nw

	label  $entwin.1.label -relief flat -text "Program" -bd 2 -width 13
	entry  $entwin.1.entry -relief flat -textvariable program -width 35 -state disabled \
		-vcmd {expr {[string length %P]<=64}} -validate key -invcmd bell
	pack $entwin.1.label $entwin.1.entry -side left

	label  $entwin.2.label -relief flat -text "Command Args" -bd 2 -width 13
	entry  $entwin.2.entry -relief flat -textvariable cmdargs -width 35 -state disabled \
		-vcmd {expr {[string length %P]<=32}} -validate key -invcmd bell
	pack $entwin.2.label $entwin.2.entry -side left

	pack $opframe.1 $opframe.2 $opframe.3 $opframe.4 -side top -anchor w
	button $buttfr.info  -text List -bg Orange -bd 5 \
		-highlightthickness 5 -highlightbackground black -width 10 \
		-command {
			run_priv $flag4 $privfr.listbox
			if {$flag4 == 4} {
				$buttfr.info configure -text "List"
				$buttfr.info configure -cursor {}
				set flag4 1
				set program ""
			}
		}
	button $buttfr.showall -relief raised -bd 4 -bg IndianRed
	$buttfr.showall configure -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBDQyNAQCBPz+/PzerAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAMmCLrc/i1IAVkYg1Z1iRYUKCqitp1oikqBWV3ZOnhkWNagqu+qnwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	balloonHelp $buttfr.showall  "Show/Hide Columns"
	$buttfr.showall configure -command {showContextMenu $privfr.listbox}
	pack $buttfr.info $buttfr.showall -side left -expand 0 -anchor nw -fill none
}

proc selectPriv {w1 args} {
	global program cmdargs

	if {[info exists args] && [string length $args] > 0} {
		set program [lindex [$w1 get $args] 0]
		set cmdargs [lindex [$w1 get $args] 1]
	}
}

proc run_priv {operation dbwin} {
	global prgtext
	global BWidget_present
	global t_adminuser t_olduser program cmdargs User
	global Domain
	source /usr/share/indimail/indium/scripts/global.tcl
	variable t_server
	
	if {$sqlserver != ""} {
		set t_server $sqlserver
	} else {
		set t_server $mysql_host
	}
	if {$is_distributed($Domain)} {
		if {[file exists $controldir/host.cntrl]} {
			if {[catch {open $controldir/host.cntrl r} f] } {
				msg_dialog .d "$controldir/host.cntrl" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set t_server [read -nonewline $f]
			close $f
		} elseif {[file exists $controldir/host.master]} {
			if {[catch {open $controldir/host.master r} f] } {
				msg_dialog .d "$controldir/host.cntrl" $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set t_server [read -nonewline $f]
			close $f
		}
	}

	if {[winfo exists $dbwin] == 0} {
		return 0
	}
	switch $operation {
		1 {
			if {$t_adminuser == ""} {
				msg_dialog .d "Privilege Editor" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$BWidget_present == 1} {
				set prgtext "Hmm... I am Busy"
				progressDialog
			}
			if {[catch {sql connect $t_server $mysql_user $mysql_pass} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL Connect" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {[catch {sql selectdb indimail} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			$dbwin delete 0 end
			if {[catch {sql "SELECT user, program, cmdswitches FROM vpriv"} result]} {
				catch {destroy .progress}
				msg_dialog .d "MySQL SelectDB" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
				sql disconnect
				return 1
			}
			sql disconnect
			foreach row $result {
				set user        [lindex $row 0]
				set program     [lindex $row 1]
				set cmdswitches [lindex $row 2]
				$dbwin insert end [list $program $cmdswitches]
			}
			catch {$dwin.log insert end "$row\n"}
			if {$BWidget_present == 1} {
				catch {destroy .progress}
			}
		}
		2 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$t_adminuser == ""} {
				msg_dialog .d "Privilege Editor" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$program == ""} {
				msg_dialog .d "Privilege Editor" "Program Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$cmdargs == ""} {
				msg_dialog .d "Privilege Editor" "Command Args Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set vprivcmd "\"vpriv -i $program $t_adminuser $cmdargs\""
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vprivcmd"
			runCommand $cmd
			if {$returnstatus == 0} {
				run_priv 1 $dbwin
				.statusBar.lab configure -text "Added Privileges to $t_adminuser for Program $program $cmdargs"
			} else {
				.statusBar.lab configure -text "Failed to add Privilege to $t_adminuser for Program $program"
				msg_dialog .d "Add Privilege" "Failed to add Privilege to $t_adminuser for Program $program\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
		3 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$t_adminuser == ""} {
				msg_dialog .d "Privilege Editor" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$program == ""} {
				msg_dialog .d "Privilege Editor" "Program Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$cmdargs == ""} {
				msg_dialog .d "Privilege Editor" "Command Args Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set vprivcmd "\"vpriv -m $program $t_adminuser $cmdargs\""
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vprivcmd"
			runCommand $cmd
			if {$returnstatus == 0} {
				run_priv 1 $dbwin
				.statusBar.lab configure -text "Modified Privileges to $t_adminuser for Program $program $cmdargs"
			} else {
				.statusBar.lab configure -text "Failed to modify Privilege to $t_adminuser for Program $program"
				msg_dialog .d "Add Privilege" "Failed to modify Privilege to $t_adminuser for Program $program\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
		4 {
			if {[string compare $User "postmaster"] != 0} {
				msg_dialog .d "Privilege Editor" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$t_adminuser == ""} {
				msg_dialog .d "Privilege Editor" "Username Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			if {$program == ""} {
				msg_dialog .d "Privilege Editor" "Program Required" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
			set vprivcmd "\"vpriv -d $program $t_adminuser\""
			set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $vprivcmd"
			runCommand $cmd
			if {$returnstatus == 0} {
				run_priv 1 $dbwin
				.statusBar.lab configure -text "Modified Privileges to $t_adminuser for Program $program $cmdargs"
			} else {
				.statusBar.lab configure -text "Failed to modify Privilege to $t_adminuser for Program $program"
				msg_dialog .d "Add Privilege" "Failed to modify Privilege to $t_adminuser for Program $program\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
				return 1
			}
		}
	}
	return 0
}

proc vlimit {} {
	global BWidget_present prgtext User
	source /usr/share/indimail/indium/scripts/global.tcl
	set result ""
	set w .dname

	destroyFirstPage
	if {$authenticated != 1} {
		Login 1
	}
	set Description "Set Domain Limits"
	wm title . $Description
	.statusBar.lab configure -text $Description
	bind . <F1> {doHelp vlimit}
	if {$BWidget_present == 1} {
		set   pw  [PanedWindow $w -weights available -side top]
		pack $pw -expand 1 -fill both
		set pane1  [$pw add -weight 45 -minsize 40]
		set pane2  [$pw add -weight 55 -minsize 10]
		set lf [TitleFrame $pane1.fr -text $Description -side center -relief ridge -bd 2]
		pack $lf -side top -anchor nw -expand 1 -fill both
		set tf [$lf getframe]
		ScrollableFrame $tf.sf -yscrollcommand "$tf.sf.vscroll set" \
			-constrainedwidth true -areawidth 0
		scrollbar $tf.sf.vscroll -command "$tf.sf yview" -trough black \
			-orient vert
		pack $tf.sf -side left -anchor nw -expand 1 -fill both
		pack $tf.sf.vscroll -anchor ne -expand 1 -fill y
		set lwin [$tf.sf getframe]
		set dwin $pane2.debug
	} else {
		frame $w -relief ridge -bd 2
		pack $w -side left -ipadx 20 -ipady  20 -expand 1 -fill both -anchor nw
		set lwin $w.left
		set dwin $w.debug
	}
	text_create $Description 1 45 10
	namespace eval domlimits {
		variable hardquota 0
		variable msgcount 0
		variable userhardquota 0
		variable usermsgcount 0
		variable maxaccounts -1
		variable maxaliases -1
		variable nodialup 0
		variable nopass 0
		variable nopop3 0
		variable noimap 0
		variable nowebmail 0
		variable nosmtp 0
		variable norelay 0
		variable reset 0
	}

	frame $lwin.domain
	pack $lwin.domain -side top -anchor nw -padx 5 -pady 2
	label $lwin.domain.l1 -text "Domain" -relief flat -bd 2 -width 7
	set domain $default_domain
	combobox $lwin.domain.e1 \
		-textvariable domain \
		-editable false \
		-bd 2 \
		-command "get_domlimits;setServerVal $lwin.server.e1" \
		-highlightthickness 1
	foreach line $domain_list {
		$lwin.domain.e1 list insert end $line
	}
	button $lwin.domain.b1 -text "Delete Limits" -command del_domlimits
	balloonHelp $lwin.domain.b1 "Delete Domain Limits"
	$lwin.domain.b1 configure -cursor pirate -image [image create photo -data "R0lGODlhEAAQAIIAAPwCBAQCBKSipFxaXPz+/MTCxISChDQyNCH5BAEAAAAALAAAAAAQABAAAANQCKrRsZA5EYZ7K5BdugkdlQVCsRHdoGLMRwqw8UWvIKvGwTICQdmGgY7W+92GEJKPdNwBlMYgMlNkSp3QgOxKXAKFWE0UHHlObI3yyFH2JwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw=="]
	balloonHelp $lwin.domain.b1 "Delete Domain limits"
	pack $lwin.domain.l1 $lwin.domain.e1 $lwin.domain.b1 -side left -anchor nw

	frame $lwin.server
	pack $lwin.server -side top -anchor nw -padx 5 -pady 2
	label $lwin.server.l1 -relief flat -text Server -bd 2 -width 7
	combobox $lwin.server.e1 \
		-textvariable server \
		-editable false \
		-bd 2 \
		-command "setmdahost"
	pack $lwin.server.l1 $lwin.server.e1 -side left -anchor nw
	setServerVal $lwin.server.e1 $lwin.domain.e1 $domain
	get_domlimits

	frame $lwin.1
	pack $lwin.1 -side top -anchor nw
	label $lwin.1.l -text "Domain Quota" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.1.e -relief sunken -textvariable domlimits::hardquota \
			-width 5 -range {0 500 10} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.1.e   -relief sunken -textvariable domlimits::hardquota -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.1.l $lwin.1.e -side left -anchor nw

	frame $lwin.2
	pack $lwin.2 -side top -anchor nw
	label $lwin.2.l -text "Domain Msg Count" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.2.e -relief sunken -textvariable domlimits::msgcount \
			-width 5 -range {0 10000 1000} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.2.e   -relief sunken -textvariable domlimits::msgcount -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.2.l $lwin.2.e -side left -anchor nw

	frame $lwin.3
	pack $lwin.3 -side top -anchor nw
	label $lwin.3.l -text "User Quota" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.3.e -relief sunken -textvariable domlimits::userhardquota \
			-width 5 -range {0 500 10} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.3.e   -relief sunken -textvariable domlimits::userhardquota -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.3.l $lwin.3.e -side left -anchor nw

	frame $lwin.4
	pack $lwin.4 -side top -anchor nw
	label $lwin.4.l -text "User Msg Count" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.4.e -relief sunken -textvariable domlimits::usermsgcount \
			-width 5 -range {0 10000 1000} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.4.e   -relief sunken -textvariable domlimits::usermsgcount -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.4.l $lwin.4.e -side left -anchor nw

	frame $lwin.5
	pack $lwin.5 -side top -anchor nw
	label $lwin.5.l -text "Max Accounts" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.5.e -relief sunken -textvariable domlimits::maxaccounts \
			-width 5 -range {-1 500000 500} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.5.e   -relief sunken -textvariable domlimits::maxaccounts -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.5.l $lwin.5.e -side left -anchor nw

	frame $lwin.6
	pack $lwin.6 -side top -anchor nw
	label $lwin.6.l -text "Max Aliases" -width 17
	if {$BWidget_present} {
		SpinBox $lwin.6.e -relief sunken -textvariable domlimits::maxaliases \
			-width 5 -range {-1 50 1} \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	} else {
		entry $lwin.6.e   -relief sunken -textvariable domlimits::maxaliases -width 5 \
			-vcmd {regexp {^[0-9]*$} %P} -validate key -invcmd bell
	}
	pack $lwin.6.l $lwin.6.e -side left -anchor nw
	TitleFrame $lwin.7 -text "Access Flags" -side center -relief ridge -bd 2
	pack $lwin.7 -side top -anchor nw
	set fr [$lwin.7 getframe]
	checkbutton $fr.dialup  -text "No Dialup"          -variable domlimits::nodialup
	checkbutton $fr.nopass  -text "No Password Change" -variable domlimits::nopass
	checkbutton $fr.nopop3  -text "No POP3"            -variable domlimits::nopop3
	checkbutton $fr.noimap  -text "No IMAP"            -variable domlimits::noimap
	checkbutton $fr.webmail -text "No WEBMAIL"         -variable domlimits::nowebmail
	checkbutton $fr.nosmtp  -text "No SMTP"            -variable domlimits::nosmtp
	checkbutton $fr.norelay -text "No RELAY"           -variable domlimits::norelay
	checkbutton $fr.reset   -text "Reset All"          -variable domlimits::reset \
		-command {
			set domlimits::nodialup 0
			set domlimits::nopass 0
			set domlimits::nopop3 0
			set domlimits::noimap 0
			set domlimits::nowebmail 0
			set domlimits::nosmtp 0
			set domlimits::norelay 0
		}
	pack $fr.dialup $fr.nopass $fr.nopop3 $fr.noimap $fr.webmail $fr.nosmtp \
		$fr.norelay $fr.reset -side top -anchor nw

	frame $lwin.but
	pack $lwin.but -side top -anchor nw
	button $lwin.but.run  -text Modify -bg orange    -command "run_domlimits" \
		-bd 5 -highlightthickness 5 -highlightbackground black
	button $lwin.but.quit -text Cancel -bg IndianRed \
		-command "destroyWindows;return" \
		-bd 5 -highlightthickness 5 -highlightbackground black
	if {$User != "postmaster"} {
		$lwin.but.run configure -state disabled
	}
	pack $lwin.but.run  -side left -expand 0 -anchor nw -fill x
	pack $lwin.but.quit -side left -expand 1 -anchor nw -fill x

	set result ""
}

proc run_domlimits {} {
	global BWidget_present prgtext
	global dwin domain server adminport adminuser adminpass
	global returnstatus User
	variable options

	if {$User != "postmaster"} {
		msg_dialog .d "Modify Domain Limits" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set options ""
	if {$domlimits::hardquota != 0} {
		append options "-Q $domlimits::hardquota "
	}
	if {$domlimits::msgcount != 0} {
		append options "-M $domlimits::msgcount "
	}
	if {$domlimits::userhardquota != 0} {
		append options "-q $domlimits::userhardquota "
	}
	if {$domlimits::usermsgcount != 0} {
		append options "-m $domlimits::msgcount "
	}
	if {$domlimits::maxaccounts != -1} {
		append options "-P $domlimits::maxaccounts "
	}
	if {$domlimits::maxaliases != -1} {
		append options "-P $domlimits::maxaliases "
	}
	set gidflags ""
	if {$domlimits::nodialup != 0} {
		append gidflags "u"
	}
	if {$domlimits::nopass != 0} {
		append gidflags "d"
	}
	if {$domlimits::nopop3 != 0} {
		append gidflags "p"
	}
	if {$domlimits::nosmtp != 0} {
		append gidflags "s"
	}
	if {$domlimits::nowebmail != 0} {
		append gidflags "w"
	}
	if {$domlimits::noimap != 0} {
		append gidflags "i"
	}
	if {$domlimits::norelay != 0} {
		append gidflags "r"
	}
	if {$domlimits::reset != 0} {
		set gidflags "x"
	}
	if {$gidflags != ""} {
		set domlimitcmd "\"vlimit $domain -g $gidflags\""
	} else {
		set domlimitcmd "\"vlimit $domain\""
	}
	set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $domlimitcmd"
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	runCommand $cmd
	catch {destroy .progress}
	if {$returnstatus == 0} {
		get_domlimits
		.statusBar.lab configure -text "Modified Domain limits for $domain"
	} else {
		.statusBar.lab configure -text "Failed to modify Domain limits for $domain"
		msg_dialog .d "Modify Domain Limits" "Failed to modify Domain limits for $domain\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
}

proc del_domlimits {} {
	global BWidget_present prgtext
	global dwin domain server adminport adminuser adminpass
	global returnstatus User
	variable action

	if {$User != "postmaster"} {
		msg_dialog .d "Modify Domain Limits" "You don't have privilege" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	set msg "You are About to Delete Domain limits for Domain $domain.\nAre you sure you want to delete?\nClick OK to continue"
	set action [msg_dialog .d {Confirm Deletion} $msg /usr/share/indimail/indium/images/warning.gif 0 "OK"]
	if {$action != 1} {
		return
	}
	set domlimitcmd "\"vlimit -D $domain\""
	set cmd "exec /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $domlimitcmd"
	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	runCommand $cmd
	catch {destroy .progress}
	if {$returnstatus == 0} {
		get_domlimits
		.statusBar.lab configure -text "Deleted Domain limits for $domain"
	} else {
		.statusBar.lab configure -text "Failed to Delete Domain limits for $domain"
		msg_dialog .d "Delete Domain Limits" "Failed to Delete Domain limits for $domain\n$result" /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
}

proc get_domlimits {} {
	global BWidget_present prgtext
	global dwin domain server adminport adminuser adminpass

	set domlimits::hardquota 0
	set domlimits::msgcount 0
	set domlimits::userhardquota 0
	set domlimits::usermsgcount 0
	set domlimits::maxaccounts -1
	set domlimits::maxaliases -1
	set domlimits::nodialup 0
	set domlimits::nopass 0
	set domlimits::nopop3 0
	set domlimits::noimap 0
	set domlimits::nowebmail 0
	set domlimits::nosmtp 0
	set domlimits::norelay 0
	set domlimits::reset 0
	set domlimitcmd "\"vlimit -s $domain\""
	set cmd "| /usr/sbin/adminclient -h $server -p $adminport -u $adminuser -P $adminpass -n /etc/indimail/control/clientcert.pem -c $domlimitcmd"

	if {$BWidget_present == 1} {
		set prgtext "Hmm... I am Busy"
		progressDialog
	}
	if {[catch {open $cmd r} f] } {
		catch {destroy .progress}
		msg_dialog .d {vlimit} $f /usr/share/indimail/indium/images/warning.gif 0 "OK"
		return 1
	}
	catch {unset limitline}
	while {[gets $f line] >= 0} {
		catch {$dwin.log insert end "$line\n"}
		catch {$dwin.log yview scroll 1 units}
		if {[string first "NO_IMAP" $line] != -1} {
			set domlimits::noimap 1
		}
		if {[string first "NO_SMTP" $line] != -1} {
			set domlimits::nosmtp 1
		}
		if {[string first "NO_POP" $line] != -1} {
			set domlimits::nopop3 1
		}
		if {[string first "NO_WEBMAIL" $line] != -1} {
			set domlimits::nowebmail 1
		}
		if {[string first "NO_PASSWD_CHNG" $line] != -1} {
			set domlimits::nopass 1
		}
		if {[string first "NO_RELAY" $line] != -1} {
			set domlimits::norelay 1
		}
		if {[string first "NO_DIALUP" $line] != -1} {
			set domlimits::nodialup 1
		}
		lappend limitline $line
	}
	catch {destroy .progress}
	set returnstatus [catch {close $f} result]
	if {$returnstatus != 0} {
		msg_dialog .d "vlimit" $result /usr/share/indimail/indium/images/warning.gif 0 "OK"
		continue
	}
	foreach {infotag vartag} { \
			domlimits::hardquota      "Max Domain Quota" \
			domlimits::msgcount       "Max Domain Messages" \
			domlimits::userhardquota  "Default User Quota" \
			domlimits::usermsgcount   "Default User Messages" \ 
			domlimits::maxpopaccounts "Max Pop Accounts" \ 
			domlimits::maxaliases     "Max Aliases" \ 
		} {
		set lineNo [lsearch -regexp $limitline $vartag]
		set str [lindex $limitline $lineNo]
		set $infotag [string trim [string range $str [expr [string first ":" $str] + 1] end]]
	}
}

##############################################################################
global indiumversion
global BWidget_present
global prgindic prgtext
global default_domain configs
global configs option

set tmval [clock click -milliseconds]
set indiumversion 1.0
set hostname [info hostname]
puts stdout "$tcl_platform(os) $hostname $tcl_platform(osVersion) $tcl_platform(machine)"
if {$::tcl_platform(platform) != "unix"} {
	puts stderr "You are not running on a reliable OS"
	puts stderr "You may want to upgrade to Linux"
	puts stderr "Have a good day"
	exit 1
}
package require BWidget
catch {package require BWidget} result
if {[string compare [lindex $result 0] "can't"] == 0} {
	set BWidget_present 0
} else {
	set BWidget_present 1
}
cd /
ClientStart
set prgindic 0
set prgtext "Loading Module..common.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/common.tcl

set prgtext "Loading $env(HOME)/.indimail/.indiumrc [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
if {[file exists $env(HOME)/.indimail/.indiumrc]} {
	source $env(HOME)/.indimail/.indiumrc
} else {
	default_config
}
if {$BWidget_present == 1} {
	if {[info exists configs(splash)] == 0} {
		splash 25
	} elseif {[info exists configs(splash)] == 1 && $configs(splash) == 1} {
		splash 25
	}
}
set prgtext "$tcl_platform(os) $hostname $tcl_platform(osVersion) $tcl_platform(machine) [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
### Get Environment Variables
catch {set adminuser $env(ADMIN_USER)}
set exists [info exists adminuser]
if {$exists == 0} {
	set adminuser "admin"
} 
catch {set adminpass $env(ADMIN_PASS)}
set exists [info exists adminpass]
if {$exists == 0} {
	set adminpass "benhur20"
} 
catch {set adminport $env(ADMIN_PORT)}
set exists [info exists adminport]
if {$exists == 0} {
	set adminport 4000
} 
set prgtext "Setting Environment Variables [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
### Set Environment Variables
set env(ADMIN_USER) $adminuser
set env(ADMIN_PASS) $adminpass
set env(ADMIN_PORT) $adminport
#
# Preference for setting default_domain
# 1. ClientStart takes precedence
# 2. Settings in $HOME/.indiumrc
# 3. Environment Variable DEFAULT_DOMAIN
#
if {[info exists default_domain] == 0} {
	if {[llength [array get configs default_domain]] != 0 } {
		set default_domain $configs(default_domain)
	}
	if {[info exists default_domain] == 0} {
		catch {set default_domain $env(DEFAULT_DOMAIN)}
	}
}

set inactiveFlag   0
set refreshUser    1
set saveDomain ""
set mysql_port     $configs(mysql_port)
set mysql_host     $configs(mysql_host)
set mysql_database $configs(mysql_database)
set mysql_user     $configs(mysql_user)
set mysql_pass     $configs(mysql_pass)
set adminhost      $configs(adminhost)
set adminport      $configs(adminport)
set adminuser      $configs(adminuser)
set adminpass      $configs(adminpass)
set controldir     $configs(controldir)
set servicedir     $configs(servicedir)
set bgColor        $configs(bgColor)
set textcolor      $configs(textcolor)
set menubarcolor   $configs(menubarcolor)
set clockmode      $configs(clockmode)
if {[info exists configs(taiconvert)]} {
	set taiconvert     $configs(taiconvert)
} else {
	set taiconvert 0
	set configs(taiconvert) 0
}
set want_progressdialog $configs(progressdialog)
set userLimit      $configs(userLimit)

set prgtext "Loading Modules.. [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}

set prgtext "Loading Module..global.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/global.tcl

set prgtext "Loading Module..combobox.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/combobox.tcl
set prgtext "Loading Module..progressbar.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/progressbar.tcl
set prgtext "Loading Module..fileman.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/fileman.tcl
set prgtext "Loading Module..help.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/help.tcl
set prgtext "Loading Module..balloon.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/balloon.tcl
set prgtext "Loading Module..notebook.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/notebook.tcl

set prgtext "Loading Module..hugecombo.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/hugecombo.tcl

set prgtext "Loading Module..mclistbox.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/mclistbox.tcl

set prgtext "Loading Module..base64.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/base64.tcl

set prgtext "Loading Module..IndiMailHelp.tcl [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
source /usr/share/indimail/indium/scripts/IndiMailHelp.tcl

package require combobox 2.2
package require mclistbox 1.02
package require Hugecombo 1.1
set prgtext "Loading Module..libfbsql.so [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
catch {package require Fbsql 1.0} result
if {[string compare [lindex $result 0] "can't"] == 0} {
	load /usr/lib64/libfbsql.so
}
package require Fbsql 1.0

set prgtext "Loading Module..libtai64.so [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
catch {package require tai64 1.0} result
if {[string compare [lindex $result 0] "can't"] == 0} {
	load /usr/lib64/libtai64.so
}
package require tai64 1.0

set prgtext "Finished Loading Modules [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}

catch {namespace import combobox::*}
catch {namespace import progressbar::*}
catch {namespace import mclistbox::*}
catch {namespace import base64::*}
catch {namespace import ::hugecombo::hugecombo}
catch {namespace import ::hugelist::hugelist}
hugecombo option set -height 24 -bg beige -alternate gray95 -relief groove -state normal
hugecombo parms set b:relief groove

if {[info exists bgColor]} {
	tk_setPalette $bgColor
}
set authenticated 0
set debug_flag 0
wm title . "Indium $indiumversion $hostname"
wm positionfrom . user
wm sizefrom . program
wm grid . 80 30 6 12
#
# Initialize domain_list and server_list through dbinfo
#
set prgtext "Initializing Domain List [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
initdomain
set prgtext "Initialized Domains .... [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
if {[llength $domain_list] > 0 && [info exists default_domain] == 0} {
	set default_domain [lindex $domain_list 0]
	if {[info exists default_domain] == 0} {
		puts stderr "Could not set default_domain"
		exit 1
	}
}
set prgtext "Setting Default Domain to $default_domain [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}

set option(icon_name) "Indium $indiumversion"
set option(icon) small
wm iconname . $option(icon_name)
SetIcon . $option(icon)
#
# Attempt Authentication on postmaster for default_domain
#
if {[llength [array get server_list $default_domain]] == 0} {
	puts stderr "No servers found for domain $default_domain"
	set authenticated 2
} else {
	set prgtext "Setting up authentication [expr [clock click -milliseconds] - $tmval] ms"
	incr prgindic
	Login 1
	catch {destroy .progress}
}
setWidthHeight . 85 30
set prgtext "Initializing Log Browser [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
initBrowser
set prgtext "Loading Main [expr [clock click -milliseconds] - $tmval] ms"
incr prgindic
catch {.intro.x.f.fr.log insert end "$prgtext\n"}
if {[winfo exists .intro]} {
	after 5000 {wm withdraw .intro}
}
main
