'SCRIPT:  	SiteCommands.vbs
'AUTHOR:  	Gene6
'DATE:    	2004/10/25
'DESC:    	Implementation of some SITE commands
'		SITE commands implemented are : 
'
'		SITE BAN <IP>: ban an IP for 2 days
'		SITE KICK <ClientID>: kick a client by his ID
'		SITE KICKBAN <ClientID>: kick and ban a client by his ID for 2 days
'		SITE TIME: display server date/time
'		SITE WHO: display clients connected : Id IP Username Directory LastCommand

'-----------------------------------------------------------------------
' SITE TIME
' no parameters
sub OnSitetime(params)
	Client.Send 220, FormatDateTime(Now)
end sub

'-----------------------------------------------------------------------
' SITE BAN <IP>
' 1 parameter : IP to ban
sub OnSiteban(params)
	Dim Manager
	Set Manager = CreateObject("G6FTPServer.Manager")

	IP = params

	Manager.Domains.Item(Domain.Name).BanList.ban IP, "banned for 2 days", 2*24*60*60

	Client.Send 220, "IP " & IP & " banned for 2 days"
end sub

'-----------------------------------------------------------------------
' SITE KICK <ClientID>
' 1 parameter : Client ID you get with SITE WHO
sub OnSitekick(params)
	if params <> "" then
		Dim Manager
		Set Manager = CreateObject("G6FTPServer.Manager")

		Dim Lclient
		Set Lclient = Manager.Domains.Item(Domain.Name).ClientList.ItemByID(Params)

		if Lclient is Nothing then
			Client.Send 500, "Unknown client ID"
		else
			LClient.Kick
			Client.Send 220, "Client kicked"
		end if
	else
		Client.Send 500, "Bad parameters"
	end if
end sub

'-----------------------------------------------------------------------
' SITE KICKBAN <clientID>
' 1 parameter : Client ID you get with SITE WHO
sub OnSitekickban(params)
	if params <> "" then
		Dim Manager
		Set Manager = CreateObject("G6FTPServer.Manager")

		Dim Lclient
		Set Lclient = Manager.Domains.Item(Domain.Name).ClientList.ItemByID(Params)

		if Lclient is Nothing then
			Client.Send 500, "Unknown client ID"
		else
			IP = Lclient.IP

			Manager.Domains.Item(Domain.Name).BanList.ban IP, "banned for 2 days", 2*24*60*60

			LClient.Kick
			Client.Send 220, "Client kicked and IP " & IP & " banned for 2 days"
		end if
	else
		Client.Send 500, "Bad parameters"
	end if
end sub

'-----------------------------------------------------------------------
' SITE WHO
' no parameters
sub OnSitewho(params)
	Dim Manager
	Set Manager = CreateObject("G6FTPServer.Manager")

	Dim clients
	Set clients = Manager.Domains.Item(Domain.Name).ClientList

	answer = ""

	Dim LClient

	For Index = 0 To clients.Count-1
		Set LClient = clients.Item(Index)
		answer = answer & LClient.ID & " " & LClient.IP & " " & LClient.Username & " " & LClient.Directory & " " & LClient.LastCommand & chr(10)
	Next

	client.Send 220, "begin" & chr(10) & answer & "end"
end sub