com.Prominic.jFTPd
Class FTPHandler

java.lang.Object
  extended by java.util.Observable
      extended by com.Prominic.jFTPd.FTPHandler
All Implemented Interfaces:
ConnectionHandler

public class FTPHandler
extends java.util.Observable
implements ConnectionHandler

This is the main part of the server. It parses the command line, reads the configuration file, starts up the server on the specified port and fires FTPConnection's for each connection to the FTP port. Also, it initialises JSSL for secure connections to the FTP server.

Author:
VIulian

Field Summary
(package private)  AdminConnection adminConnection
           
(package private)  java.lang.String adminPassword
           
(package private)  boolean anonDelete
           
(package private)  java.lang.String anonDirectory
           
(package private)  boolean anonDownload
           
(package private)  boolean anonOnly
           
(package private)  boolean anonUpload
           
(package private)  java.lang.String basePath
           
(package private)  java.util.Vector connections
           
(package private)  int connTimeout
           
private  java.lang.String currentUsersDatDefaultGroup
           
private  java.lang.String currentUsersDatDefaultMask
           
private  java.lang.String currentUsersDatDefaultOwner
           
private  java.lang.String currentUsersDatDefaultReadAccess
           
(package private)  int currentUsersDatFormat
           
(package private)  boolean debug
           
(package private)  boolean DEBUG
           
(package private)  java.lang.String debugFilename
           
(package private)  boolean echoError
           
(package private)  boolean echoLog
           
(package private)  java.lang.String errorFilename
           
private static javax.net.ssl.SSLSocketFactory factory
           
(package private)  IdleKiller idleKiller
           
(package private)  int kDefaultPort
           
private static javax.net.ssl.KeyManagerFactory kmf
           
private static java.security.KeyStore ks
           
(package private)  boolean logActions
           
(package private)  boolean logError
           
(package private)  java.io.RandomAccessFile logFile
           
(package private)  java.lang.String logFilename
           
(package private)  FTPLogger logger
           
(package private)  int maxConnections
           
(package private)  int passConnTimeout
           
(package private)  int passiveHighPort
           
(package private)  int passiveLowPort
           
(package private)  char pathSeparator
           
(package private)  boolean permDelete
           
(package private)  boolean permDownload
           
(package private)  boolean permUpload
           
(package private)  int port
           
(package private)  boolean rmiStarted
           
(package private)  FTPUserListSecuritySource securitySource
           
(package private)  GenericServer server
           
(package private)  boolean serverOn
           
private static javax.net.ssl.SSLContext sslcontext
           
private  long totalBytesDownloaded
           
private  long totalBytesUploaded
           
private  int totalFilesDownloaded
           
private  int totalFilesUploaded
           
(package private)  boolean useGUI
           
(package private)  java.lang.String userFilename
           
(package private)  java.util.Properties userParamHash
           
(package private)  int usersUpdateInterval
           
 
Constructor Summary
FTPHandler(AdminConnection _adminConnection)
          Default constructor - it initialises the defaults.
 
Method Summary
protected  void addConnection(Connection c)
          Adds a connection to the internal list of collections.
 void doConnection(java.net.Socket s)
          Fired when a connection is made to the FTP port.
 java.util.Hashtable getAllParameters()
          Returns all configuration parameters.
 java.lang.String getBasePath()
          Returns the base path.
 Connection[] getConnections()
          Returns an array of currently openened connections.
 int getMaxConnections()
          Maximum number of connections accepted by FTP server.
 java.lang.String getParameter(java.lang.String key)
          Gets the key's value (where key represents a configuration parameter).
 java.lang.String getParameter(java.lang.String key, java.lang.String def)
          Gets the key's value (where key represents a configuration parameter).
 int getPort()
          Returns the jFTPd port number.
 java.lang.String getServerUptime()
          Returns the server uptime in humanly readable form.
static javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
          Returns the SSLSocket Factory.
 long getTotalBytesDownloaded()
          Gets the total bytes that were downloaded since jFTPd started.
 long getTotalBytesUploaded()
          Gets the total bytes that were uploaded since jFTPd started.
 int getTotalFilesDownloaded()
          Gets the total number of files that were downloaded since jFTPd started.
 int getTotalFilesUploaded()
          Gets the total number of files that were uploaded since jFTPd started.
 java.util.Hashtable getUserParams()
          Returns all configuration parameters.
 void initKeystore()
          Initialises the keystore.
protected  boolean isTrue(java.lang.String s)
          Checks if the configuration parameter 's' has value true (not equal to O, false or no.
 void notifyDone(Connection conn)
          Called when a connection ended.
 java.lang.String password()
          Returns the admin password.
protected  void removeConnection(Connection c)
          Removes a connection from the internal list of connections, as well as updating the total server counters (files dl/up, bytes dl/up) with the values from the connection.
 boolean serverRunning()
          Checks the server status.
 void setParameter(java.lang.String key, java.lang.String value)
          Sets a configuration parameter's value.
private  void setTotalBytesDownloaded(long newTotalBytesDownloaded)
          Updates the counter for total bytes downloaded.
private  void setTotalBytesUploaded(long newTotalBytesUploaded)
          Updates the counter for total bytes uploaded.
private  void setTotalFilesDownloaded(int newTotalFilesDownloaded)
          Updates the counter for total files downloaded.
private  void setTotalFilesUploaded(int newTotalFilesUploaded)
          Updates the counter for total files uploaded.
 void setupDone()
          Called when setting up the the server configuration is done (it will start up the server using startService unless the requirement is to start up in GUI mode).
 void startRMI()
          Starts up the RMI listener on port given by rmiport in the configuration file (or 1101 if no value is found for it).
 void startService()
          Starts the server itself.
 void stopService()
          Stops the server, shuts down the idle killer thread and also interrupts the AdminConnection.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

final boolean DEBUG
See Also:
Constant Field Values

basePath

java.lang.String basePath

connections

java.util.Vector connections

pathSeparator

char pathSeparator

server

GenericServer server

permDownload

boolean permDownload

permUpload

boolean permUpload

permDelete

boolean permDelete

idleKiller

IdleKiller idleKiller

logFile

java.io.RandomAccessFile logFile

logActions

boolean logActions

logFilename

java.lang.String logFilename

errorFilename

java.lang.String errorFilename

debugFilename

java.lang.String debugFilename

debug

boolean debug

logError

boolean logError

port

int port

serverOn

boolean serverOn

useGUI

boolean useGUI

maxConnections

int maxConnections

connTimeout

int connTimeout

userFilename

java.lang.String userFilename

userParamHash

java.util.Properties userParamHash

kDefaultPort

int kDefaultPort

securitySource

FTPUserListSecuritySource securitySource

logger

FTPLogger logger

usersUpdateInterval

int usersUpdateInterval

echoLog

boolean echoLog

echoError

boolean echoError

passiveLowPort

int passiveLowPort

passiveHighPort

int passiveHighPort

adminPassword

java.lang.String adminPassword

anonOnly

boolean anonOnly

anonUpload

boolean anonUpload

anonDownload

boolean anonDownload

anonDelete

boolean anonDelete

anonDirectory

java.lang.String anonDirectory

rmiStarted

boolean rmiStarted

passConnTimeout

int passConnTimeout

currentUsersDatFormat

int currentUsersDatFormat

adminConnection

AdminConnection adminConnection

currentUsersDatDefaultOwner

private java.lang.String currentUsersDatDefaultOwner

currentUsersDatDefaultGroup

private java.lang.String currentUsersDatDefaultGroup

currentUsersDatDefaultMask

private java.lang.String currentUsersDatDefaultMask

currentUsersDatDefaultReadAccess

private java.lang.String currentUsersDatDefaultReadAccess

totalFilesUploaded

private int totalFilesUploaded

totalFilesDownloaded

private int totalFilesDownloaded

totalBytesUploaded

private long totalBytesUploaded

totalBytesDownloaded

private long totalBytesDownloaded

ks

private static java.security.KeyStore ks

kmf

private static javax.net.ssl.KeyManagerFactory kmf

sslcontext

private static javax.net.ssl.SSLContext sslcontext

factory

private static javax.net.ssl.SSLSocketFactory factory
Constructor Detail

FTPHandler

public FTPHandler(AdminConnection _adminConnection)
Default constructor - it initialises the defaults. It needs an AdminConnection as a parameter [it listenes on the 5387 port and is able to stop the FTPHandler if needed]

Parameters:
_adminConnection - - admin connection.
Method Detail

addConnection

protected void addConnection(Connection c)
Adds a connection to the internal list of collections.

Parameters:
c - - the new connection.

doConnection

public void doConnection(java.net.Socket s)
Fired when a connection is made to the FTP port. Checks if that the number of maximum connections hasn't been reached (and if so will drop the connection with a meaningfull message for the user). If everything is ok, it will start up an FTPConnection given the client socket.

Specified by:
doConnection in interface ConnectionHandler
Parameters:
s - Socket - FTP client socket.

getAllParameters

public java.util.Hashtable getAllParameters()
Returns all configuration parameters.

Returns:
Hashtable - all configuration parameters.

getBasePath

public java.lang.String getBasePath()
Returns the base path.

Returns:
String - base path.

getConnections

public Connection[] getConnections()
Returns an array of currently openened connections.

Specified by:
getConnections in interface ConnectionHandler
Returns:
- array with the currently openend connections.

getMaxConnections

public int getMaxConnections()
Maximum number of connections accepted by FTP server.

Returns:
- maximum number of accepted connections.

getParameter

public java.lang.String getParameter(java.lang.String key)
Gets the key's value (where key represents a configuration parameter).

Parameters:
key - - configuration parameter
Returns:
String - value.

getParameter

public java.lang.String getParameter(java.lang.String key,
                                     java.lang.String def)
Gets the key's value (where key represents a configuration parameter).

Parameters:
key - - configuration parameter
def - - default value, in case the parameter was not defined.
Returns:
String - value.

getPort

public int getPort()
Returns the jFTPd port number.


getServerUptime

public java.lang.String getServerUptime()
Returns the server uptime in humanly readable form.

Returns:
- server uptime.

getTotalBytesDownloaded

public long getTotalBytesDownloaded()
Gets the total bytes that were downloaded since jFTPd started. Creation date: (2/26/2004 4:19:52 PM)

Returns:
long - total downloaded bytes.

getTotalBytesUploaded

public long getTotalBytesUploaded()
Gets the total bytes that were uploaded since jFTPd started. Creation date: (2/26/2004 4:19:16 PM)

Returns:
long - total uploaded bytes.

getTotalFilesDownloaded

public int getTotalFilesDownloaded()
Gets the total number of files that were downloaded since jFTPd started. Creation date: (2/26/2004 4:18:54 PM)

Returns:
int total downloaded files.

getTotalFilesUploaded

public int getTotalFilesUploaded()
Gets the total number of files that were uploaded since jFTPd started. Creation date: (2/26/2004 4:15:16 PM)

Returns:
int - total uploaded files

getUserParams

public java.util.Hashtable getUserParams()
Returns all configuration parameters.

Returns:
Hashtable - all configuration parameters.

isTrue

protected boolean isTrue(java.lang.String s)
Checks if the configuration parameter 's' has value true (not equal to O, false or no.

Parameters:
s - - parameter name
Returns:
- true if it is anything else beside 0, false or no.

notifyDone

public void notifyDone(Connection conn)
Called when a connection ended. It removes the connections from the internal list of connections thus making room for other connections (in case their number is limited by config).

Specified by:
notifyDone in interface ConnectionHandler
Parameters:
conn - = the connection which has ended.

password

public java.lang.String password()
Returns the admin password.

Returns:
- unecrypted admin password.

removeConnection

protected void removeConnection(Connection c)
Removes a connection from the internal list of connections, as well as updating the total server counters (files dl/up, bytes dl/up) with the values from the connection.

Parameters:
c - - the connection to be removed.

serverRunning

public boolean serverRunning()
Checks the server status.

Returns:
boolean true if server is running.

setParameter

public void setParameter(java.lang.String key,
                         java.lang.String value)
Sets a configuration parameter's value.

Specified by:
setParameter in interface ConnectionHandler
Parameters:
key - - parameter's name.
value - - parameter's value.

setTotalBytesDownloaded

private void setTotalBytesDownloaded(long newTotalBytesDownloaded)
Updates the counter for total bytes downloaded. Creation date: (2/26/2004 4:19:52 PM)

Parameters:
newTotalBytesDownloaded - long - new value for the counter

setTotalBytesUploaded

private void setTotalBytesUploaded(long newTotalBytesUploaded)
Updates the counter for total bytes uploaded. Creation date: (2/26/2004 4:19:16 PM)

Parameters:
newTotalBytesUploaded - long - new value for the counter

setTotalFilesDownloaded

private void setTotalFilesDownloaded(int newTotalFilesDownloaded)
Updates the counter for total files downloaded. Creation date: (2/26/2004 4:18:54 PM)

Parameters:
newTotalFilesDownloaded - int - new value for the counter

setTotalFilesUploaded

private void setTotalFilesUploaded(int newTotalFilesUploaded)
Updates the counter for total files uploaded. Creation date: (2/26/2004 4:15:16 PM)

Parameters:
newTotalFilesUploaded - int - new value for the counter

setupDone

public void setupDone()
Called when setting up the the server configuration is done (it will start up the server using startService unless the requirement is to start up in GUI mode).


startRMI

public void startRMI()
Starts up the RMI listener on port given by rmiport in the configuration file (or 1101 if no value is found for it). Service is bound using the value of rminame, or "FTPController" if value is not found.


startService

public void startService()
Starts the server itself. Reads the users.dat file, enables debugging and logging and starts the GenericServer thread.

Specified by:
startService in interface ConnectionHandler

initKeystore

public void initKeystore()
Initialises the keystore. For now the password is hardcoded, and is "aaaa11". Keystore is read from a file named jftpd_keystore found in the directory where jFTPd was started from.


getSSLSocketFactory

public static javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
Returns the SSLSocket Factory.

Returns:
- SSLSocket Factory

stopService

public void stopService()
Stops the server, shuts down the idle killer thread and also interrupts the AdminConnection.