You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2001/12/14 02:22:05 UTC
cvs commit: jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/util BaseProperties.java
hammant 01/12/13 17:22:04
Modified: apps/ftpserver build.xml
apps/ftpserver/src/conf ftp-assembly.xml ftp-config.xml
apps/ftpserver/src/java/org/apache/avalon/ftpserver
FtpConnection.java FtpDataConnection.java
FtpUser.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server
DefaultFtpServer.java DefaultFtpServer.xinfo
RemoteAdminAdaptor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui
CommonHandler.java ConfigTableModel.java
FtpAdminDialog.java FtpAdminFrame.java
FtpAdminPanel.java FtpConnectionPanel.java
FtpConnectionTableModel.java FtpIpPanel.java
FtpRootPanel.java FtpSpyDialog.java
FtpStatisticsPanel.java FtpTreeModel.java
FtpUserPanel.java GuiUtils.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces
FtpAdmin.java FtpConnectionObserver.java
FtpStatisticsListener.java SpyUserInterface.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/services
FtpServer.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/util
BaseProperties.java
Added: apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/config
DefaultConfig.java DefaultConfig.xinfo
RemoteFtpConfigAdaptor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/iprestrictor
DefaultIpRestrictor.java DefaultIpRestrictor.xinfo
RemoteIpRestrictorAdaptor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/stats
DefaultFtpStatistics.java
DefaultFtpStatistics.xinfo
RemoteFtpStatisticsAdaptor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager
AbstractUserManager.java DefaultUserHandler.java
DefaultUserHandler.xinfo
RemoteUserHandlerAdaptor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/db
DbUserManager.java DbUserManager.xinfo
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/ldap
LdapUserManager.java LdapUserManager.xinfo
apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/props
PropertiesUserManager.java
PropertiesUserManager.xinfo
apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces
FtpConfig.java FtpStatistics.java IpRestrictor.java
RemoteFtpAdmin.java RemoteFtpConfig.java
RemoteFtpStatistics.java RemoteIpRestrictor.java
RemoteUserHandler.java UserHandler.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/services
FtpConfigService.java UserManager.java
Removed: apps/ftpserver/src/java/org/apache/avalon/ftpserver
FtpConfig.java FtpStatistics.java
FtpUserHandler.java IpRestrictor.java
apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces
FtpConfigInterface.java FtpRemoteAdmin.java
FtpStatisticsInterface.java
IpRestrictorInterface.java
UserHandlerInterface.java
Log:
Second stage of refactoring of FtpServer
Revision Changes Path
1.22 +5 -3 jakarta-avalon-cornerstone/apps/ftpserver/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/build.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- build.xml 2001/12/13 13:26:04 1.21
+++ build.xml 2001/12/14 01:22:02 1.22
@@ -168,9 +168,11 @@
<rmic base="${build.classes}"
includes="org/apache/avalon/ftpserver/FtpStatistics.class, \
org/apache/avalon/ftpserver/FtpConfig.class, \
+ org/apache/avalon/ftpserver/blocks/config/RemoteFtpConfig.class, \
+ org/apache/avalon/ftpserver/blocks/iprestrictor/RemoteIpRestrictorAdaptor.class, \
org/apache/avalon/ftpserver/blocks/server/RemoteAdminAdaptor.class, \
- org/apache/avalon/ftpserver/FtpUserHandler.class, \
- org/apache/avalon/ftpserver/IpRestrictor.class, \
+ org/apache/avalon/ftpserver/blocks/stats/RemoteFtpStatisticsAdaptor.class, \
+ org/apache/avalon/ftpserver/blocks/usermanager/RemoteUserHandlerAdaptor.class, \
org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.class, \
org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.class, \
org/apache/avalon/ftpserver/gui/FtpSpyDialog.class">
@@ -425,7 +427,7 @@
<delete file="${jar.name}.sar" dir="${phoenix.apps}"/>
</target>
- <target name="admintest" depends="main">
+ <target name="admintest" depends="main" description="Launches the Swing Admin test client">
<java classname="org.apache.avalon.ftpserver.gui.FtpAdminFrame" fork="true">
<classpath refid="test.path"/>
</java>
1.5 +35 -4 jakarta-avalon-cornerstone/apps/ftpserver/src/conf/ftp-assembly.xml
Index: ftp-assembly.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/conf/ftp-assembly.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ftp-assembly.xml 2001/12/13 13:26:04 1.4
+++ ftp-assembly.xml 2001/12/14 01:22:02 1.5
@@ -7,6 +7,9 @@
-->
<assembly>
+ <!-- The Storage block -->
+ <block class="org.apache.avalon.cornerstone.blocks.masterstore.RepositoryManager"
+ name="objectstorage" />
<!-- The ThreadManager block -->
<block class="org.apache.avalon.cornerstone.blocks.threads.DefaultThreadManager"
@@ -28,12 +31,40 @@
<provide name="thread-manager"
role="org.apache.avalon.cornerstone.services.threads.ThreadManager" />
</block>
+
+
+ <!-- FTP SERVER BLOCKS -->
<block class="org.apache.avalon.ftpserver.blocks.server.DefaultFtpServer" name="ftp-server" >
- <provide name="sockets" role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
- <provide name="connections"
- role="org.apache.avalon.cornerstone.services.connection.ConnectionManager" />
- <provide name="scheduler" role="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"/>
+ <provide name="sockets" role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
+ <provide name="connections" role="org.apache.avalon.cornerstone.services.connection.ConnectionManager" />
+ <provide name="ftp-cfg" role="org.apache.avalon.ftpserver.services.FtpConfigService"/>
+ <provide name="ftp-uhandler" role="org.apache.avalon.ftpserver.interfaces.UserHandler"/>
+ <provide name="ftp-ip-rstr" role="org.apache.avalon.ftpserver.interfaces.IpRestrictor"/>
</block>
+
+ <block class="org.apache.avalon.ftpserver.blocks.config.DefaultConfig" name="ftp-cfg" >
+ <provide name="ftp-uhandler" role="org.apache.avalon.ftpserver.interfaces.UserHandler"/>
+ <provide name="ftp-ip-rstr" role="org.apache.avalon.ftpserver.interfaces.IpRestrictor"/>
+ <provide name="ftp-stats" role="org.apache.avalon.ftpserver.interfaces.FtpStatistics"/>
+ </block>
+
+ <block class="org.apache.avalon.ftpserver.blocks.usermanager.props.PropertiesUserManager" name="ftp-umanager">
+ <provide name="ftp-cfg" role="org.apache.avalon.ftpserver.services.FtpConfigService"/>
+ <provide name="objectstorage" role="org.apache.avalon.cornerstone.services.store.Store"/>
+ </block>
+
+ <block class="org.apache.avalon.ftpserver.blocks.usermanager.DefaultUserHandler" name="ftp-uhandler">
+ <provide name="scheduler" role="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"/>
+ <provide name="ftp-umanager" role="org.apache.avalon.ftpserver.services.UserManager"/>
+ </block>
+
+ <block class="org.apache.avalon.ftpserver.blocks.stats.DefaultFtpStatistics" name="ftp-stats">
+ <provide name="ftp-cfg" role="org.apache.avalon.ftpserver.services.FtpConfigService"/>
+ </block>
+
+ <block class="org.apache.avalon.ftpserver.blocks.iprestrictor.DefaultIpRestrictor" name="ftp-ip-rstr">
+ <provide name="objectstorage" role="org.apache.avalon.cornerstone.services.store.Store"/>
+ </block>
</assembly>
1.9 +46 -4 jakarta-avalon-cornerstone/apps/ftpserver/src/conf/ftp-config.xml
Index: ftp-config.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/conf/ftp-config.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ftp-config.xml 2001/11/11 09:08:05 1.8
+++ ftp-config.xml 2001/12/14 01:22:02 1.9
@@ -7,6 +7,38 @@
-->
<config>
+ <!-- The Storage block .... needed by various -->
+ <objectstorage>
+ <repositories>
+ <repository class="org.apache.avalon.cornerstone.blocks.masterstore.File_Persistent_Object_Repository">
+ <protocols>
+ <protocol>file</protocol>
+ </protocols>
+ <types>
+ <type>OBJECT</type>
+ </types>
+ <models>
+ <model>SYNCHRONOUS</model>
+ <model>ASYNCHRONOUS</model>
+ <model>CACHE</model>
+ </models>
+ </repository>
+ <repository class="org.apache.avalon.cornerstone.blocks.masterstore.File_Persistent_Stream_Repository">
+ <protocols>
+ <protocol>file</protocol>
+ </protocols>
+ <types>
+ <type>STREAM</type>
+ </types>
+ <models>
+ <model>SYNCHRONOUS</model>
+ <model>ASYNCHRONOUS</model>
+ <model>CACHE</model>
+ </models>
+ </repository>
+ </repositories>
+ </objectstorage>
+
<thread-manager>
<thread-group>
<name>default</name>
@@ -56,15 +88,20 @@
<idle-max>300</idle-max>
<poll-period>120</poll-period>
</connection>
+
+
+ </ftp-server>
-
<!-- property based user manager -->
+ <ftp-umanager>
<user-manager>
<class>org.apache.avalon.ftpserver.usermanager.PropertiesUserManager</class>
</user-manager>
+ </ftp-umanager>
<!-- database based user manager
+ <ftp-umanager>
<user-manager>
<class>org.apache.avalon.ftpserver.usermanager.DbUserManager</class>
<driver>org.gjt.mm.mysql.Driver</driver>
@@ -72,9 +109,11 @@
<user>root</user>
<password>admin</password>
</user-manager>
+ </ftp-umanager>
-->
<!-- ldap based user manager
+ <ftp-umanager>
<user-manager>
<class>org.apache.avalon.ftpserver.usermanager.LdapUserManager</class>
<url>ldap://localhost:389</url>
@@ -83,9 +122,12 @@
<password>password</password>
<authentication>simple</authentication>
</user-manager>
- -->
-
- </ftp-server>
+ </ftp-umanager>
+ -->
+ <ftp-cfg></ftp-cfg>
+ <ftp-uhandler></ftp-uhandler>
+ <ftp-stats></ftp-stats>
+ <ftp-ip-rstr></ftp-ip-rstr>
</config>
1.6 +15 -7 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java
Index: FtpConnection.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpConnection.java 2001/11/10 21:34:04 1.5
+++ FtpConnection.java 2001/12/14 01:22:02 1.6
@@ -34,6 +34,10 @@
import org.apache.avalon.ftpserver.util.IoUtils;
import org.apache.avalon.ftpserver.util.StreamConnector;
import org.apache.avalon.ftpserver.util.Message;
+import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
+import org.apache.avalon.ftpserver.services.FtpConfigService;
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
+import org.apache.avalon.ftpserver.interfaces.IpRestrictor;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.component.*;
@@ -63,7 +67,9 @@
private final static Class[] METHOD_INPUT_SIG = new Class[] {FtpRequest.class, Writer.class};
- private FtpConfig mCfg = null;
+ private FtpConfigService mCfg = null;
+ private UserHandler mUserHandler;
+ private IpRestrictor mIpRestrictor;
private FtpStatus mFtpStatus = null;
private FtpDataConnection mDataCon = null;
private Socket mControlSoc = null;
@@ -84,8 +90,10 @@
/**
* Set configuration file and the control socket.
*/
- public FtpConnection(FtpConfig ftpConfig) {
+ public FtpConnection(FtpConfigService ftpConfig, UserHandler userHandler, IpRestrictor ipRestrictor) {
mCfg = ftpConfig;
+ mUserHandler = userHandler;
+ mIpRestrictor = ipRestrictor;
mFtpStatus = mCfg.getStatus();
}
@@ -98,7 +106,7 @@
mControlSoc = socket;
mDataCon = new FtpDataConnection(mCfg);
mUser = new FtpUser(mCfg, mControlSoc, mDataCon);
- mCfg.getUserHandler().newConnection(mUser);
+ mUserHandler.newConnection(mUser);
serveRequest();
}
@@ -115,7 +123,7 @@
out = new OutputStreamWriter(mControlSoc.getOutputStream());
// permission check
- if( !mCfg.getIpRestrictor().hasPermission(mControlSoc.getInetAddress()) ) {
+ if( !mIpRestrictor.hasPermission(mControlSoc.getInetAddress()) ) {
write(out, mFtpStatus.getResponse(530, null, null));
return;
}
@@ -216,7 +224,7 @@
public void stop() {
if (!mbStopRequest) {
mbStopRequest = true;
- mCfg.getUserHandler().closeConnection(mUser.getSessionId());
+ mUserHandler.closeConnection(mUser.getSessionId());
}
}
@@ -860,7 +868,7 @@
args.add(mUser.getName());
String pass = request.hasArgument() ? request.getArgument() : "";
mUser.setPassword(pass);
- mCfg.getUserHandler().login(mUser.getSessionId());
+ mUserHandler.login(mUser.getSessionId());
write(out, mFtpStatus.getResponse(230, request, args));
}
@@ -1481,7 +1489,7 @@
return;
}
else {
- mCfg.getUserHandler().closeConnection(mUser.getSessionId());
+ mUserHandler.closeConnection(mUser.getSessionId());
}
}
1.3 +4 -2 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java
Index: FtpDataConnection.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpDataConnection.java 2001/11/28 09:02:12 1.2
+++ FtpDataConnection.java 2001/12/14 01:22:02 1.3
@@ -8,6 +8,8 @@
package org.apache.avalon.ftpserver;
+import org.apache.avalon.ftpserver.services.FtpConfigService;
+
import java.io.IOException;
import java.net.Socket;
import java.net.ServerSocket;
@@ -21,7 +23,7 @@
*/
class FtpDataConnection {
- private FtpConfig mConfig = null;
+ private FtpConfigService mConfig = null;
private Socket mDataSoc = null;
private ServerSocket mServSoc = null;
private InetAddress mAddress = null;
@@ -35,7 +37,7 @@
* Constructor.
* @param cfg ftp config object.
*/
- public FtpDataConnection(FtpConfig cfg) {
+ public FtpDataConnection(FtpConfigService cfg) {
mConfig = cfg;
}
1.7 +7 -5 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpUser.java
Index: FtpUser.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpUser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FtpUser.java 2001/11/21 07:58:38 1.6
+++ FtpUser.java 2001/12/14 01:22:02 1.7
@@ -22,6 +22,8 @@
import org.apache.avalon.ftpserver.util.VirtualDirectory;
import org.apache.avalon.ftpserver.interfaces.SpyUserInterface;
import org.apache.avalon.ftpserver.interfaces.FtpConnectionObserver;
+import org.apache.avalon.ftpserver.interfaces.FtpConfig;
+import org.apache.avalon.ftpserver.services.FtpConfigService;
/**
@@ -38,7 +40,7 @@
private transient Socket mSocket = null;
private transient FtpDataConnection mDataCon = null;
- private transient FtpConfig mConfig = null;
+ private transient FtpConfigService mConfig = null;
private transient SpyUserInterface mSpy = null;
private transient FtpConnectionObserver mObserver = null;
@@ -67,7 +69,7 @@
/**
* Constructor - does nothing.
*/
- public FtpUser(FtpConfig cfg, Socket soc, FtpDataConnection dataCon) {
+ public FtpUser(FtpConfigService cfg, Socket soc, FtpDataConnection dataCon) {
mConfig = cfg;
mSocket = soc;
mDataCon = dataCon;
@@ -351,7 +353,7 @@
/**
* User login.
*/
- void login() {
+ public void login() {
mlLoginTime = System.currentTimeMillis();
mlLastAccessTime = mlLoginTime;
}
@@ -359,7 +361,7 @@
/**
* User logout.
*/
- void logout() {
+ public void logout() {
// close control socket
if(mSocket!=null) {
@@ -380,7 +382,7 @@
/**
* Hit user. Update last access time.
*/
- void hitUser() {
+ public void hitUser() {
mlLastAccessTime = System.currentTimeMillis();
if(mObserver != null) {
mConfig.getMessageQueue().add(new Message() {
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/config/DefaultConfig.java
Index: DefaultConfig.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.config;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.List;
import java.util.ArrayList;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import org.apache.avalon.ftpserver.util.AsyncMessageQueue;
import org.apache.avalon.ftpserver.blocks.iprestrictor.DefaultIpRestrictor;
import org.apache.avalon.ftpserver.interfaces.IpRestrictor;
import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.interfaces.FtpStatistics;
import org.apache.avalon.ftpserver.FtpStatus;
import org.apache.avalon.ftpserver.blocks.usermanager.DefaultUserHandler;
import org.apache.avalon.ftpserver.blocks.stats.DefaultFtpStatistics;
import org.apache.avalon.ftpserver.services.FtpConfigService;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.phoenix.BlockContext;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
import org.apache.avalon.cornerstone.services.store.Store;
/**
* Ftp configuration class. It has all ftp server configuration
* parameters. This is not hot-editable. parameters will be loaded
* once during server startup. We can add our own config parameters.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DefaultConfig extends AbstractLogEnabled
implements Block, FtpConfigService, Contextualizable, Composable, Configurable,
Initializable {
private int miMaxConnection;
private int miMaxAnonConnection;
private int miServerPort;
private int miRmiPort;
private int miMaxIdleTime;
private int miSchedulerInterval;
private boolean mbAnonAllowed;
private boolean mbRemoteAdminAllowed;
private Registry mRegistry = null;
private String mstBaseDir = null;
private File mDataDir = null;
private File mDefaultRoot = null;
private FtpStatus mStatus = null;
private UserHandler mUserHandler;
private IpRestrictor mIpRestrictor = null;
private InetAddress mAddr = null;
private String mAddrStr;
private TimeScheduler msScheduler = null;
private AsyncMessageQueue mMsgQ = null;
private BlockContext mBlockContext = null;
private RemoteFtpConfigAdaptor mRemoteFtpConfigAdaptor;
private FtpStatistics mFtpStatistics;
/**
* Set application context
*/
public void contextualize(Context context) {
mBlockContext = (BlockContext) context;
// get file propertis
mstBaseDir = mBlockContext.getBaseDirectory().getAbsolutePath();
mDataDir = new File(mBlockContext.getBaseDirectory(), "data");
mDataDir.mkdirs();
mDefaultRoot = new File(mBlockContext.getBaseDirectory(), "root");
mDefaultRoot.mkdirs();
}
/**
* Configure the block.
*
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {
mAddrStr = conf.getChild("ftp-host").getValue("localhost");
miServerPort = conf.getChild("ftp-port").getValueAsInteger(21);
miMaxConnection = conf.getChild("connection").getChild("max").getValueAsInteger(20);
miMaxAnonConnection =
conf.getChild("connection").getChild("anonymous-max").getValueAsInteger(10);
miMaxIdleTime = conf.getChild("connection").getChild("idle-max").getValueAsInteger(300);
miSchedulerInterval =
conf.getChild("connection").getChild("poll-period").getValueAsInteger(120);
mbAnonAllowed =
conf.getChild("connection").getChild("anonymous-allowed").getValueAsBoolean(true);
mbRemoteAdminAllowed =
conf.getChild("connection").getChild("remote-admin-allowed").getValueAsBoolean(true);
miRmiPort = conf.getChild("connection").getChild("rmi-port").getValueAsInteger(1099);
;
}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
mIpRestrictor = (IpRestrictor) compManager.lookup(IpRestrictor.class.getName());
mUserHandler = (UserHandler) compManager.lookup(UserHandler.class.getName());
mFtpStatistics = (FtpStatistics) compManager.lookup(FtpStatistics.class.getName());
}
/**
* Initialize server socket.
*/
public void initialize() throws Exception {
mAddr = InetAddress.getByName(mAddrStr);
// open FTP status
mStatus = new FtpStatus();
// RMI registry
try {
mRegistry = LocateRegistry.getRegistry(miRmiPort);
mRegistry.list();
} catch (RemoteException ex) {
mRegistry = null;
}
if (mRegistry == null) {
mRegistry = LocateRegistry.createRegistry(miRmiPort);
}
mRemoteFtpConfigAdaptor = new RemoteFtpConfigAdaptor(this);
UnicastRemoteObject.exportObject(mRemoteFtpConfigAdaptor);
mMsgQ = new AsyncMessageQueue();
}
/**
* Close this config and all the related resources. Ftp server
* <code>FtpServer.stop()</code> method will call this method.
*/
public void close() {
// close user handler
if (mUserHandler != null) {
mUserHandler.close();
mUserHandler = null;
}
// close message queue
if (mMsgQ != null) {
mMsgQ.stop();
mMsgQ = null;
}
}
/**
* Get message queue.
*/
public AsyncMessageQueue getMessageQueue() {
return mMsgQ;
}
/**
* Get server port.
*/
public int getServerPort() {
return miServerPort;
}
/**
* Get server bind address.
*/
public InetAddress getServerAddress() {
return mAddr;
}
/**
* Check annonymous login support.
*/
public boolean isAnonymousLoginSupported() {
return mbAnonAllowed;
}
/**
* Is remote admin supported
*/
public boolean isRemoteAdminSupported() {
return mbRemoteAdminAllowed;
}
/**
* Get remote admin port
*/
public int getRemoteAdminPort() {
return miRmiPort;
}
/**
* Get RMI registry.
*/
public Registry getRegistry() {
return mRegistry;
}
/**
* Get maximum idle time
*/
public int getMaxIdleTime() {
return miMaxIdleTime;
}
/**
* Get scheduler interval in second
*/
public int getSchedulerInterval() {
return miSchedulerInterval;
}
/**
* Get resource directory.
*/
public File getDataDir() {
return mDataDir;
}
/**
* Get base directory
*/
public String getBaseDirectory() {
return mstBaseDir;
}
/**
* Get default ftp root
*/
public File getDefaultRoot() {
return mDefaultRoot;
}
/**
* Get ftp status resource.
*/
public FtpStatus getStatus() {
return mStatus;
}
/**
* Get user manager object.
*/
public UserHandler getUserHandler() {
return mUserHandler;
}
/**
* Get maximum number of connections.
*/
public int getMaxConnections() {
return miMaxConnection;
}
/**
* Get maximum number of anonymous connections.
*/
public int getMaxAnonymousConnections() {
if (!mbAnonAllowed) {
return 0;
}
return miMaxAnonConnection;
}
/**
* Get the system name.
*/
public String getSystemName() {
String systemName = System.getProperty("os.name");
if (systemName == null) {
systemName = "UNKNOWN";
} else {
systemName = systemName.toUpperCase();
systemName = systemName.replace(' ', '-');
}
return systemName;
}
/**
* Get global statistics object.
*/
public FtpStatistics getStatistics() {
return mFtpStatistics;
}
/**
* Method getIpRestrictor
*
*
* @return
*
*/
public IpRestrictor getIpRestrictor() {
return mIpRestrictor;
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/config/DefaultConfig.xinfo
Index: DefaultConfig.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.ftpserver.interfaces.UserHandler" version="1.0"/>
</dependency>
<dependency>
<service name="org.apache.avalon.ftpserver.interfaces.IpRestrictor" version="1.0"/>
</dependency>
<dependency>
<service name="org.apache.avalon.ftpserver.interfaces.FtpStatistics" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/config/RemoteFtpConfigAdaptor.java
Index: RemoteFtpConfigAdaptor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.config;
import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
import org.apache.avalon.ftpserver.interfaces.FtpConfig;
import org.apache.avalon.ftpserver.interfaces.RemoteIpRestrictor;
import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.interfaces.FtpStatistics;
import org.apache.avalon.ftpserver.interfaces.RemoteFtpStatistics;
import org.apache.avalon.ftpserver.blocks.iprestrictor.RemoteIpRestrictorAdaptor;
import org.apache.avalon.ftpserver.blocks.stats.RemoteFtpStatisticsAdaptor;
import java.net.InetAddress;
/**
* Class RemoteFtpConfigAdaptor
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class RemoteFtpConfigAdaptor implements RemoteFtpConfig {
FtpConfig mFtpConfig;
private RemoteIpRestrictor mRemoteIpRestrictor;
/**
* Constructor RemoteFtpConfigAdaptor
*
*
* @param ftpConfig
*
*/
public RemoteFtpConfigAdaptor(FtpConfig ftpConfig) {
mFtpConfig = ftpConfig;
}
/**
* Get server port.
*/
public int getServerPort() {
return mFtpConfig.getServerPort();
}
/**
* Check annonymous login support.
*/
public boolean isAnonymousLoginSupported() {
return mFtpConfig.isAnonymousLoginSupported();
}
/**
* Get maximum number of connections.
*/
public int getMaxConnections() {
return mFtpConfig.getMaxConnections();
}
/**
* Get maximum number of anonymous connections.
*/
public int getMaxAnonymousConnections() {
return mFtpConfig.getMaxAnonymousConnections();
}
/**
* Get default maximum idle time
*/
public int getMaxIdleTime() {
return mFtpConfig.getMaxIdleTime();
}
/**
* Get scheduler interval
*/
public int getSchedulerInterval() {
return mFtpConfig.getSchedulerInterval();
}
/**
* Check remote admin support
*/
public boolean isRemoteAdminSupported() {
return mFtpConfig.isRemoteAdminSupported();
}
/**
* Get remote admin port
*/
public int getRemoteAdminPort() {
return mFtpConfig.getRemoteAdminPort();
}
/**
* Get ftp base directory
*/
public String getBaseDirectory() {
return mFtpConfig.getBaseDirectory();
}
/**
* Get the server address.
*/
public InetAddress getServerAddress() {
return mFtpConfig.getServerAddress();
}
/**
* Get the IP restrictor object.
*/
public RemoteIpRestrictor getRemoteIpRestrictor() {
if (mRemoteIpRestrictor == null) {
mRemoteIpRestrictor = new RemoteIpRestrictorAdaptor(mFtpConfig.getIpRestrictor());
}
return mRemoteIpRestrictor;
}
/**
* Get user manager object.
*/
public UserHandler getUserHandler() {
return mFtpConfig.getUserHandler();
}
/**
* Get global statistics object.
*/
public RemoteFtpStatistics getStatistics() {
return new RemoteFtpStatisticsAdaptor(mFtpConfig.getStatistics());
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/iprestrictor/DefaultIpRestrictor.java
Index: DefaultIpRestrictor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.iprestrictor;
import java.rmi.server.UnicastRemoteObject;
import java.net.InetAddress;
import java.util.Vector;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Collections;
import java.util.Iterator;
import org.apache.avalon.ftpserver.interfaces.IpRestrictor;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
import org.apache.avalon.cornerstone.services.store.ObjectRepository;
import org.apache.avalon.cornerstone.services.store.Store;
/**
* This class provides IP restriction functionality.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DefaultIpRestrictor extends AbstractLogEnabled
implements Block, IpRestrictor, Contextualizable, Composable, Configurable,
Initializable {
private Vector mIPs = new Vector();
private RemoteIpRestrictorAdaptor mRemoteIpRestrictorAdaptor;
private BlockContext mBlockContext;
protected Store mStore;
protected Configuration mStoreConfig;
protected ObjectRepository mObjectRepository;
/**
* Read the IP restriction config file.
*
*/
public DefaultIpRestrictor() {
reload();
mRemoteIpRestrictorAdaptor = new RemoteIpRestrictorAdaptor(this);
}
/**
* Method getRemote
*
*
* @return
*
*/
public RemoteIpRestrictorAdaptor getRemote() {
return mRemoteIpRestrictorAdaptor;
}
/**
* Set application context
*/
public void contextualize(Context context) {
mBlockContext = (BlockContext) context;
}
/**
* Configure the block.
*
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {
mStoreConfig = conf.getChild("repository");
}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
mStore = (Store) compManager.lookup(Store.class.getName());
}
/**
* Initialize server socket.
*/
public void initialize() throws Exception {
mObjectRepository = (ObjectRepository) mStore.select(mStoreConfig);
UnicastRemoteObject.exportObject(mRemoteIpRestrictorAdaptor);
}
/**
* Method clear
*
*
*/
public void clear() {
mIPs.clear();
}
/**
* Read the list from the file.
*/
public synchronized void reload() {
mIPs = (Vector) mObjectRepository.get("ip-restrictions");
}
/**
* Save this IP restriction list.
*/
public synchronized void save() {
mObjectRepository.put("ip-restrictions", mIPs);
}
/**
* Add a new entry.
*/
public void addEntry(String str) {
str = str.trim();
if ((!str.equals("")) && (!mIPs.contains(str))) {
mIPs.add(str);
}
}
/**
* Remove entry.
*/
public void removeEntry(String str) {
mIPs.remove(str.trim());
}
/**
* Get all entries.
*/
public List getAllEntries() {
return Collections.unmodifiableList(mIPs);
}
/**
* Check IP permission. Compare it with all the entries in the list.
*/
public synchronized boolean hasPermission(InetAddress addr) {
boolean bMatch = false;
for (Iterator ipIt = mIPs.iterator(); ipIt.hasNext(); ) {
bMatch = isMatched(ipIt.next().toString(), addr);
if (bMatch) {
break;
}
}
return !bMatch;
}
/**
* Match the internet address with the entry.
*/
private boolean isMatched(String listEntry, InetAddress addr) {
StringTokenizer st1 = new StringTokenizer(listEntry, ".");
if (st1.countTokens() != 4) {
return false;
}
StringTokenizer st2 = new StringTokenizer(addr.getHostAddress(), ".");
boolean bMatch = true;
for (int i = 0; i < 4; i++) {
String tok1 = st1.nextToken();
String tok2 = st2.nextToken();
if (tok1.equals("*")) {
continue;
}
try {
int n1 = Integer.parseInt(tok1);
int n2 = Integer.parseInt(tok2);
bMatch = (n1 == n2);
} catch (NumberFormatException ex) {
bMatch = false;
}
if (!bMatch) {
break;
}
}
return bMatch;
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/iprestrictor/DefaultIpRestrictor.xinfo
Index: DefaultIpRestrictor.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.interfaces.IpRestrictor" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/iprestrictor/RemoteIpRestrictorAdaptor.java
Index: RemoteIpRestrictorAdaptor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.iprestrictor;
import org.apache.avalon.ftpserver.interfaces.RemoteIpRestrictor;
import org.apache.avalon.ftpserver.interfaces.IpRestrictor;
import java.rmi.RemoteException;
import java.net.InetAddress;
import java.util.List;
/**
* Class RemoteIpRestrictorAdaptor
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class RemoteIpRestrictorAdaptor implements RemoteIpRestrictor {
private IpRestrictor mIpRestrictor;
/**
* Constructor RemoteIpRestrictorAdaptor
*
*
* @param ipRestrictor
*
*/
public RemoteIpRestrictorAdaptor(IpRestrictor ipRestrictor) {
mIpRestrictor = ipRestrictor;
}
/**
* Reload data from store.
*/
public void reload() {
mIpRestrictor.reload();
}
/**
* Save data into store.
*/
public void save() {
mIpRestrictor.save();
}
/**
* Check IP permission.
*/
public boolean hasPermission(InetAddress addr) {
return mIpRestrictor.hasPermission(addr);
}
/**
* Clear all entries.
*/
public void clear() {
mIpRestrictor.clear();
}
/**
* Add new entry
*/
public void addEntry(String str) {
mIpRestrictor.addEntry(str);
}
/**
* Remove entry
*/
public void removeEntry(String str) {
mIpRestrictor.removeEntry(str);
}
/**
* Get all entries
*/
public List getAllEntries() {
return mIpRestrictor.getAllEntries();
}
}
1.2 +80 -61 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/DefaultFtpServer.java
Index: DefaultFtpServer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/DefaultFtpServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultFtpServer.java 2001/12/13 13:26:04 1.1
+++ DefaultFtpServer.java 2001/12/14 01:22:02 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -7,17 +8,24 @@
*/
package org.apache.avalon.ftpserver.blocks.server;
+
+
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
+
import java.rmi.server.UnicastRemoteObject;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
+
+import org.apache.avalon.ftpserver.interfaces.FtpConfig;
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
-import org.apache.avalon.ftpserver.FtpConfig;
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
+import org.apache.avalon.ftpserver.interfaces.IpRestrictor;
+import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
import org.apache.avalon.ftpserver.FtpConnection;
import org.apache.avalon.ftpserver.FtpException;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.services.FtpServer;
+import org.apache.avalon.ftpserver.services.FtpConfigService;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.*;
@@ -31,7 +39,6 @@
import org.apache.avalon.cornerstone.services.connection.ConnectionManager;
import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
import org.apache.avalon.cornerstone.services.sockets.SocketManager;
-import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
@@ -46,23 +53,23 @@
* @version 1.0
*/
public class DefaultFtpServer extends AbstractLogEnabled
- implements Block, FtpServer, Contextualizable,
- Composable, Configurable, Initializable, ConnectionHandlerFactory {
+ implements Block, FtpServer, Contextualizable, Composable, Configurable, Initializable,
+ ConnectionHandlerFactory {
- private ServerSocket mServerSocket = null;
- private FtpConfig mConfig = null;
- private SocketManager mSocManager = null;
+ private ServerSocket mServerSocket = null;
+ private FtpConfigService mFtpConfigService = null;
+ private SocketManager mSocManager = null;
private ConnectionManager mConManager = null;
- private TimeScheduler mTimeScheduler = null;
- private BlockContext mContext = null;
+ private BlockContext mContext = null;
private RemoteAdminAdaptor mRemoteAdminAdaptor;
-
+ private UserHandler mUserHandler;
+ private IpRestrictor mIpRestrictor;
/**
* Set application context
*/
public void contextualize(Context context) {
- mContext = (BlockContext)context;
+ mContext = (BlockContext) context;
}
/**
@@ -71,48 +78,53 @@
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {
- try {
- mConfig = new FtpConfig(conf, mContext, getLogger(), mTimeScheduler);
- mRemoteAdminAdaptor = new RemoteAdminAdaptor(this);
- UnicastRemoteObject.exportObject(mRemoteAdminAdaptor);
-
- if(mConfig.isRemoteAdminSupported()) {
- mConfig.getRegistry().rebind(FtpAdmin.class.getName(), mRemoteAdminAdaptor);
- }
- System.out.println("FTP server ready!");
- }
- catch(Exception ex) {
- ex.printStackTrace();
- throw new ConfigurationException(ex.getMessage(), ex);
- }
+
+ try {
+ mRemoteAdminAdaptor = new RemoteAdminAdaptor(this);
+
+ UnicastRemoteObject.exportObject(mRemoteAdminAdaptor);
+
+ if (mFtpConfigService.isRemoteAdminSupported()) {
+ mFtpConfigService.getRegistry().rebind(FtpAdmin.class.getName(),
+ mRemoteAdminAdaptor);
+ }
+
+ System.out.println("FTP server ready!");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+
+ throw new ConfigurationException(ex.getMessage(), ex);
+ }
}
/**
* Get all managers.
*/
- public void compose(ComponentManager compManager) {
+ public void compose(ComponentManager compManager) throws ComponentException {
+
getLogger().info("FtpServer compose");
- try{
- mSocManager = (SocketManager)compManager.lookup(SocketManager.ROLE);
- mConManager = (ConnectionManager)compManager.lookup(ConnectionManager.ROLE);
- mTimeScheduler = (TimeScheduler)compManager.lookup(TimeScheduler.ROLE);
- //TODO (PH) should fall through or be rethrown ?
- } catch (ComponentException ce) {
- getLogger().error("compose(): ComponentException",ce);
- }
+
+ mSocManager = (SocketManager) compManager.lookup(SocketManager.ROLE);
+ mConManager = (ConnectionManager) compManager.lookup(ConnectionManager.ROLE);
+ mFtpConfigService = (FtpConfigService) compManager.lookup(FtpConfigService.class.getName());
+ mUserHandler = (UserHandler) compManager.lookup(UserHandler.class.getName());
+ mIpRestrictor = (IpRestrictor) compManager.lookup(IpRestrictor.class.getName());
}
/**
* Initialize server socket.
*/
public void initialize() throws Exception {
+
ServerSocketFactory factory = mSocManager.getServerSocketFactory("plain");
- mServerSocket = factory.createServerSocket(mConfig.getServerPort(), 5, mConfig.getServerAddress());
- mConManager.connect(DISPLAY_NAME, mServerSocket, this );
+
+ mServerSocket = factory.createServerSocket(mFtpConfigService.getServerPort(), 5,
+ mFtpConfigService.getServerAddress());
+
+ mConManager.connect(DISPLAY_NAME, mServerSocket, this);
getLogger().info("FTP Server started!");
}
-
/**
* Construct an appropriate <code>ConnectionHandler</code>
* to handle a new connection.
@@ -121,73 +133,80 @@
* @exception Exception if an error occurs
*/
public ConnectionHandler createConnectionHandler() throws Exception {
- FtpConnection conHandle = new FtpConnection(mConfig);
+
+ FtpConnection conHandle = new FtpConnection(mFtpConfigService, mUserHandler,
+ mIpRestrictor);
+
setupLogger(conHandle, getLogger());
+
return conHandle;
}
-
/**
* Get the server object.
*/
- public FtpConfigInterface getConfigInterface(String sessId) throws FtpException {
+ public FtpConfig getConfig(String sessId) throws FtpException {
+
isAdminLogin(sessId);
- return mConfig;
- }
+ return mFtpConfigService;
+ }
/**
* Remote login
*/
public String adminLogin(String id, String psd) throws FtpException {
- if(id == null || psd == null) {
+
+ if ((id == null) || (psd == null)) {
throw new FtpException(530);
}
+
if (!id.equals(FtpUser.ADMIN)) {
- throw new FtpException(530);
+ throw new FtpException(530);
}
-
- FtpUser adminUser = new FtpUser(mConfig, null, null);
+
+ FtpUser adminUser = new FtpUser(mFtpConfigService, null, null);
+
adminUser.setName(id);
adminUser.setPassword(psd);
-
- mConfig.getUserHandler().newConnection(adminUser);
- mConfig.getUserHandler().login(adminUser.getSessionId());
-
+ mUserHandler.newConnection(adminUser);
+ mUserHandler.login(adminUser.getSessionId());
getLogger().info("Remote admin login");
+
return adminUser.getSessionId();
}
-
/**
* Remote admin logout.
*/
public void adminLogout(String sessId) throws FtpException {
+
isAdminLogin(sessId);
- mConfig.getUserHandler().closeConnection(sessId);
+ mUserHandler.closeConnection(sessId);
getLogger().info("Remote admin logout");
}
-
/**
* Check admin login status.
*/
private void isAdminLogin(String sessId) throws FtpException {
- if(sessId == null) {
+
+ if (sessId == null) {
throw new FtpException(530);
}
-
- FtpUser adminUser = mConfig.getUserHandler().getConnectedUser(sessId);
- if(adminUser == null) {
+
+ FtpUser adminUser = mUserHandler.getConnectedUser(sessId);
+
+ if (adminUser == null) {
throw new FtpException(530);
}
- if(!adminUser.getIsAdmin()) {
+
+ if (!adminUser.getIsAdmin()) {
throw new FtpException(530);
}
+
if (!adminUser.hasLoggedIn()) {
throw new FtpException(530);
}
}
-
}
-
1.2 +10 -6 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/DefaultFtpServer.xinfo
Index: DefaultFtpServer.xinfo
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/DefaultFtpServer.xinfo,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultFtpServer.xinfo 2001/12/13 13:26:04 1.1
+++ DefaultFtpServer.xinfo 2001/12/14 01:22:02 1.2
@@ -18,14 +18,18 @@
<service name="org.apache.avalon.cornerstone.services.sockets.SocketManager" version="1.0"/>
</dependency>
<dependency>
- <service name="org.apache.avalon.cornerstone.services.connection.ConnectionManager"
+ <service name="org.apache.avalon.cornerstone.services.connection.ConnectionManager"
version="1.0"/>
</dependency>
<dependency>
- <service name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"
- version="1.0"/>
- </dependency>
-
- </dependencies>
+ <service name="org.apache.avalon.ftpserver.interfaces.IpRestrictor" version="1.0"/>
+ </dependency>
+ <dependency>
+ <service name="org.apache.avalon.ftpserver.interfaces.UserHandler" version="1.0"/>
+ </dependency>
+ <dependency>
+ <service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0"/>
+ </dependency>
+ </dependencies>
</blockinfo>
1.2 +27 -8 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/RemoteAdminAdaptor.java
Index: RemoteAdminAdaptor.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/server/RemoteAdminAdaptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteAdminAdaptor.java 2001/12/13 13:26:04 1.1
+++ RemoteAdminAdaptor.java 2001/12/14 01:22:02 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -6,28 +7,47 @@
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.server;
+
+
-import org.apache.avalon.ftpserver.interfaces.FtpRemoteAdmin;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpAdmin;
+import org.apache.avalon.ftpserver.interfaces.FtpConfig;
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
import org.apache.avalon.ftpserver.FtpException;
+import org.apache.avalon.ftpserver.blocks.config.RemoteFtpConfigAdaptor;
import java.rmi.RemoteException;
-public class RemoteAdminAdaptor implements FtpRemoteAdmin {
+/**
+ * Class RemoteAdminAdaptor
+ *
+ *
+ * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
+ * @version $Revision: 1.2 $
+ */
+public class RemoteAdminAdaptor implements RemoteFtpAdmin {
+
FtpAdmin mFtpAdmin;
+ RemoteFtpConfig mRemoteFtpConfig;
+ /**
+ * Constructor RemoteAdminAdaptor
+ *
+ *
+ * @param ftpAdmin
+ *
+ */
public RemoteAdminAdaptor(FtpAdmin ftpAdmin) {
mFtpAdmin = ftpAdmin;
}
-
/**
* Remote admin login
*/
public String adminLogin(String id, String password) throws RemoteException, FtpException {
- return mFtpAdmin.adminLogin(id,password);
+ return mFtpAdmin.adminLogin(id, password);
}
/**
@@ -40,8 +60,7 @@
/**
* Get configuration interface
*/
- public FtpConfigInterface getConfigInterface(String sessId) throws RemoteException, FtpException {
- return mFtpAdmin.getConfigInterface(sessId);
+ public RemoteFtpConfig getConfig(String sessId) throws RemoteException, FtpException {
+ return new RemoteFtpConfigAdaptor(mFtpAdmin.getConfig(sessId));
}
-
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/stats/DefaultFtpStatistics.java
Index: DefaultFtpStatistics.java
===================================================================
package org.apache.avalon.ftpserver.blocks.stats;
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Date;
import org.apache.avalon.ftpserver.interfaces.FtpStatisticsListener;
import org.apache.avalon.ftpserver.interfaces.FtpStatistics;
import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
import org.apache.avalon.ftpserver.blocks.server.RemoteAdminAdaptor;
import org.apache.avalon.ftpserver.util.Message;
import org.apache.avalon.ftpserver.services.FtpConfigService;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
/**
* This class encapsulates all the global statistics.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DefaultFtpStatistics extends AbstractLogEnabled
implements Block, FtpStatistics, Contextualizable, Composable, Configurable,
Initializable {
private FtpStatisticsListener mListener = null;
private DefaultConfig mConfig = null;
private FtpConfigService mFtpConfigService;
private DefaultFtpStatistics mSelf = null;
private Date mStartTime = new Date();
private int miNbrUpload = 0;
private int miNbrDownload = 0;
private int miNbrDelete = 0;
private int miLogins = 0;
private int miTotalLogins = 0;
private int miAnonLogins = 0;
private int miTotalAnonLogins = 0;
private int miConnections = 0;
private int miTotalConnections = 0;
private long mlBytesUpload = 0L;
private long mlBytesDownload = 0L;
private RemoteFtpStatisticsAdaptor mRemoteFtpStatisticsAdaptor;
private BlockContext mBlockContext;
/**
* Set application context
*/
public void contextualize(Context context) {
mBlockContext = (BlockContext) context;
}
/**
* Configure the server.
*
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
mFtpConfigService =
(FtpConfigService) compManager.lookup(FtpConfigService.class.getName());
}
/**
* Initialize server socket.
*/
public void initialize() throws Exception {
mRemoteFtpStatisticsAdaptor = new RemoteFtpStatisticsAdaptor(this);
UnicastRemoteObject.exportObject(mRemoteFtpStatisticsAdaptor);
}
///////////////// All get methods /////////////////
/**
* Get server start time.
*/
public Date getStartTime() {
return mStartTime;
}
/**
* Get number of files uploaded.
*/
public int getFileUploadNbr() {
return miNbrUpload;
}
/**
* Get number of files downloaded.
*/
public int getFileDownloadNbr() {
return miNbrDownload;
}
/**
* Get number of files deleted.
*/
public int getFileDeleteNbr() {
return miNbrDelete;
}
/**
* Get total number of bytes uploaded.
*/
public long getFileUploadSize() {
return mlBytesUpload;
}
/**
* Get total number of bytes downloaded.
*/
public long getFileDownloadSize() {
return mlBytesDownload;
}
/**
* Get current number of connections.
*/
public int getConnectionNbr() {
return miConnections;
}
/**
* Get total connection number
*/
public int getTotalConnectionNbr() {
return miTotalConnections;
}
/**
* Get current number of logins
*/
public int getLoginNbr() {
return miLogins;
}
/**
* Get total number of logins
*/
public int getTotalLoginNbr() {
return miTotalLogins;
}
/**
* Get current anonymous logins.
*/
public int getAnonLoginNbr() {
return miAnonLogins;
}
/**
* Get total anonymous logins
*/
public int getTotalAnonLoginNbr() {
return miTotalAnonLogins;
}
///////////////// All set methods ///////////////////
/**
* Increment upload count.
*/
public void setUpload(long sz) {
++miNbrUpload;
mlBytesUpload += sz;
notifyUpload();
}
/**
* Increment download count.
*/
public void setDownload(long sz) {
++miNbrDownload;
mlBytesDownload += sz;
notifyDownload();
}
/**
* Increment delete count.
*/
public void setDelete() {
++miNbrDelete;
notifyDelete();
}
/**
* New login.
*/
public void setLogin(boolean anonymous) {
++miLogins;
++miTotalLogins;
if (anonymous) {
++miAnonLogins;
++miTotalAnonLogins;
}
notifyLogin();
}
/**
* User logout
*/
public void setLogout(boolean anonymous) {
--miLogins;
if (anonymous) {
--miAnonLogins;
}
notifyLogout();
}
/**
* New connection
*/
public void setOpenConnection() {
++miConnections;
++miTotalConnections;
notifyConnection();
}
/**
* Close connection
*/
public void setCloseConnection() {
--miConnections;
notifyConnection();
}
////////////////////////////////////////////////////////////
// Event listener methods
// As the listener may be a remote object, we are using
// asynchronous message queue for notifications.
///////////////////////////////////////////////////////////
/**
* Add a listener object.
*/
public void setListener(FtpStatisticsListener listener) {
mListener = listener;
}
/**
* Get listener object.
*/
public FtpStatisticsListener getListener() {
return mListener;
}
/**
* Listener upload notification.
*/
private void notifyUpload() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyUpload();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
/**
* Listener download notification.
*/
private void notifyDownload() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyDownload();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
/**
* Listener delete notification.
*/
private void notifyDelete() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyDelete();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
/**
* Listener user login notification.
*/
private void notifyLogin() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyLogin();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
/**
* Listener user logout notification.
*/
private void notifyLogout() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyLogout();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
/**
* Listener user connection open/close notification.
*/
private void notifyConnection() {
if (mListener != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mListener.notifyConnection();
} catch (Exception ex) {
mSelf.setListener(null);
}
}
});
}
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/stats/DefaultFtpStatistics.xinfo
Index: DefaultFtpStatistics.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.interfaces.FtpStatistics" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/stats/RemoteFtpStatisticsAdaptor.java
Index: RemoteFtpStatisticsAdaptor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.stats;
import org.apache.avalon.ftpserver.interfaces.RemoteFtpStatistics;
import org.apache.avalon.ftpserver.interfaces.FtpStatistics;
import org.apache.avalon.ftpserver.interfaces.RemoteIpRestrictor;
import org.apache.avalon.ftpserver.interfaces.FtpStatisticsListener;
import java.net.InetAddress;
import java.util.Date;
import java.rmi.RemoteException;
/**
* Class RemoteFtpStatisticsAdaptor
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class RemoteFtpStatisticsAdaptor implements RemoteFtpStatistics {
private FtpStatistics mFtpStatistics;
/**
* Constructor RemoteFtpStatisticsAdaptor
*
*
* @param ftpStatistics
*
*/
public RemoteFtpStatisticsAdaptor(FtpStatistics ftpStatistics) {
mFtpStatistics = ftpStatistics;
}
/**
* Get server start time.
*/
public Date getStartTime() throws RemoteException {
return mFtpStatistics.getStartTime();
}
/**
* Get number of files uploaded.
*/
public int getFileUploadNbr() throws RemoteException {
return mFtpStatistics.getFileUploadNbr();
}
/**
* Get number of files downloaded.
*/
public int getFileDownloadNbr() throws RemoteException {
return mFtpStatistics.getFileDownloadNbr();
}
/**
* Get number of files deleted.
*/
public int getFileDeleteNbr() throws RemoteException {
return mFtpStatistics.getFileDeleteNbr();
}
/**
* Get total number of bytes uploaded.
*/
public long getFileUploadSize() throws RemoteException {
return mFtpStatistics.getFileUploadSize();
}
/**
* Get total number of bytes downloaded.
*/
public long getFileDownloadSize() throws RemoteException {
return mFtpStatistics.getFileDownloadSize();
}
/**
* Get current number of connections.
*/
public int getConnectionNbr() throws RemoteException {
return mFtpStatistics.getConnectionNbr();
}
/**
* Get total number of connections
*/
public int getTotalConnectionNbr() throws RemoteException {
return mFtpStatistics.getTotalConnectionNbr();
}
/**
* Get current number of anonymous logins.
*/
public int getAnonLoginNbr() throws RemoteException {
return mFtpStatistics.getAnonLoginNbr();
}
/**
* Get total number of anonymous logins
*/
public int getTotalAnonLoginNbr() throws RemoteException {
return mFtpStatistics.getTotalAnonLoginNbr();
}
/**
* Get current number of logins
*/
public int getLoginNbr() throws RemoteException {
return mFtpStatistics.getLoginNbr();
}
/**
* Get total number of logins
*/
public int getTotalLoginNbr() throws RemoteException {
return mFtpStatistics.getTotalLoginNbr();
}
/**
* Set a listener object.
*/
public void setListener(FtpStatisticsListener listener) throws RemoteException {
mFtpStatistics.setListener(listener);
}
/**
* Get listener object.
*/
public FtpStatisticsListener getListener() throws RemoteException {
return mFtpStatistics.getListener();
}
/**
* Method setOpenConnection
*
*
* @throws RemoteException
*
*/
public void setOpenConnection() throws RemoteException {
mFtpStatistics.setOpenConnection();
}
/**
* Method setCloseConnection
*
*
* @throws RemoteException
*
*/
public void setCloseConnection() throws RemoteException {
mFtpStatistics.setCloseConnection();
}
/**
* Method setLogin
*
*
* @param anonymous
*
* @throws RemoteException
*
*/
public void setLogin(boolean anonymous) throws RemoteException {
mFtpStatistics.setLogin(anonymous);
}
/**
* Method setLogout
*
*
* @param anonymous
*
* @throws RemoteException
*
*/
public void setLogout(boolean anonymous) throws RemoteException {
mFtpStatistics.setLogout(anonymous);
}
/**
* Method setDownload
*
*
* @param sz
*
* @throws RemoteException
*
*/
public void setDownload(long sz) throws RemoteException {
mFtpStatistics.setDownload(sz);
}
/**
* Method setUpload
*
*
* @param sz
*
* @throws RemoteException
*
*/
public void setUpload(long sz) throws RemoteException {
mFtpStatistics.setUpload(sz);
}
/**
* Method setDelete
*
*
* @throws RemoteException
*
*/
public void setDelete() throws RemoteException {
mFtpStatistics.setDelete();
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/AbstractUserManager.java
Index: AbstractUserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager;
import org.apache.avalon.ftpserver.services.UserManager;
import org.apache.avalon.ftpserver.services.FtpConfigService;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.activity.Initializable;
/**
* Class AbstractUserManager
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public abstract class AbstractUserManager extends AbstractLogEnabled
implements Block, UserManager, Contextualizable, Composable, Configurable, Initializable {
protected BlockContext mBlockContext;
protected FtpConfigService mConfig;
/**
* Set application context
*/
public void contextualize(Context context) {
mBlockContext = (BlockContext) context;
}
/**
* Configure the block.
*
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
mConfig = (FtpConfigService) compManager.lookup(FtpConfigService.class.getName());
}
/**
* Initialize
*/
public void initialize() throws Exception {}
protected RuntimeException processException(Exception e) {
return new RuntimeException("Some low-level problem during operation", e);
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/DefaultUserHandler.java
Index: DefaultUserHandler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Enumeration;
import java.lang.reflect.Constructor;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import org.apache.avalon.ftpserver.util.Message;
import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.interfaces.FtpConnectionObserver;
import org.apache.avalon.ftpserver.interfaces.SpyUserInterface;
import org.apache.avalon.ftpserver.interfaces.FtpConfig;
import org.apache.avalon.ftpserver.services.UserManager;
import org.apache.avalon.ftpserver.services.FtpConfigService;
import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.FtpException;
import org.apache.avalon.cornerstone.services.scheduler.Target;
import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
import org.apache.avalon.cornerstone.services.scheduler.PeriodicTimeTrigger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.phoenix.Block;
/**
* User connection handler class. This class will instantiate the appropriate
* user manager using reflection API. We can use different user
* manager implementation classes.
* This class is responsible for all ftp user management, connection
* handling. We can add, update, delete, find users.
* We can also monitor, close connectins using this class.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DefaultUserHandler extends AbstractLogEnabled
implements Block, UserHandler, Contextualizable, Composable, Configurable, Initializable,
Target {
/**
* Observer to monitor ftp connections.
*/
private FtpConnectionObserver mObserver = null;
/**
* Self reference
*/
private DefaultUserHandler mSelf = null;
/**
* User manager
*/
private UserManager mUserManager = null;
/**
* Ftp server configuration object.
*/
private FtpConfigService mConfig = null;
private TimeScheduler mScheduler;
/**
* Active user hashtable. Key is the session ID
* and the value is the connected user object.
*/
private Hashtable mUserHash = new Hashtable();
private RemoteUserHandlerAdaptor mUserHandlerAdaptor;
/**
* Default constructor. Starts the user cleaner thread.
*/
public DefaultUserHandler(DefaultConfig cfg) throws Exception {
mSelf = this;
mConfig = cfg;
mUserHandlerAdaptor = new RemoteUserHandlerAdaptor(this);
createDefaultUsers();
UnicastRemoteObject.exportObject(mUserHandlerAdaptor);
mScheduler.addTrigger(getClass().getName(),
new PeriodicTimeTrigger(0, mConfig.getSchedulerInterval() * 1000),
this);
}
/**
* Set application context
*/
public void contextualize(Context context) {}
/**
* Configure the block.
*
* @param conf the XML configuration block
*/
public void configure(Configuration conf) throws ConfigurationException {}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
mUserManager = (UserManager) compManager.lookup(UserManager.class.getName());
mScheduler = (TimeScheduler) compManager.lookup(TimeScheduler.class.getName());
}
/**
* Initialize
*/
public void initialize() throws Exception {}
/**
* It returns a list of all the currently connected user objects.
*/
public List getAllConnectedUsers() {
ArrayList userList = new ArrayList();
for (Enumeration userEn = mUserHash.keys(); userEn.hasMoreElements(); ) {
FtpUser thisUser = (FtpUser) mUserHash.get(userEn.nextElement());
if (thisUser != null) {
userList.add(thisUser);
}
}
return userList;
}
/**
* Set user manager observer.
*/
public void setObserver(FtpConnectionObserver obsr) {
mObserver = obsr;
for (Enumeration userEn = mUserHash.keys(); userEn.hasMoreElements(); ) {
FtpUser thisUser = (FtpUser) mUserHash.get(userEn.nextElement());
if (thisUser != null) {
thisUser.setObserver(mObserver);
}
}
}
/**
* Get the observer.
*/
public FtpConnectionObserver getObserver() {
return mObserver;
}
/**
* User login method. If successfull, populates the user object.
*/
public void login(final String sessId) throws FtpException {
// null value check
if (sessId == null) {
throw new FtpException(530);
}
// get the user object
FtpUser thisUser = (FtpUser) mUserHash.get(sessId);
if (thisUser == null) {
throw new FtpException(530);
}
// already logged in
if (thisUser.hasLoggedIn()) {
return;
}
// get name and password
String user = thisUser.getName();
String password = thisUser.getPassword();
if ((user == null) || (password == null)) {
throw new FtpException(530);
}
// authenticate user
if (!authenticate(user, password)) {
throw new FtpException(530);
}
// populate user properties
populateProperties(thisUser, user);
// user enable check
if (!thisUser.getEnabled()) {
throw new FtpException(530);
}
// connection limit check
checkConnection(thisUser);
thisUser.setPassword(null);
thisUser.login();
if (thisUser.getSocket() != null) {
getLogger().info(thisUser.getSocket().getInetAddress().getHostAddress() + " - "
+ thisUser.getName());
}
// notify observer
if (mObserver != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mObserver.updateConnection(sessId);
} catch (Exception ex) {
mSelf.setObserver(null);
}
}
});
}
// update global statistics
mConfig.getStatistics().setLogin(thisUser.getIsAnonymous());
}
/**
* Populate user properties
*/
private void populateProperties(final FtpUser thisUser, String user) throws FtpException {
// get the existing user
FtpUser existUser = getUserByName(user);
if (existUser == null) {
throw new FtpException(530);
}
// map properties
thisUser.getVirtualDirectory()
.setRootDirectory(new File(existUser.getVirtualDirectory().getRootDirectory()));
thisUser.setEnabled(existUser.getEnabled());
thisUser.getVirtualDirectory()
.setWritePermission(existUser.getVirtualDirectory().getWritePermission());
thisUser.setMaxIdleTime(existUser.getMaxIdleTime());
thisUser.setMaxUploadRate(existUser.getMaxUploadRate());
thisUser.setMaxDownloadRate(existUser.getMaxDownloadRate());
}
/**
* Connection limit check.
*/
private void checkConnection(FtpUser thisUser) throws FtpException {
int maxConnection = mConfig.getMaxConnections();
int maxAnonConnection = mConfig.getMaxAnonymousConnections();
int anonNbr = mConfig.getStatistics().getAnonLoginNbr();
int totalNbr = mConfig.getStatistics().getLoginNbr();
// final check
if (thisUser.getIsAnonymous()) {
if (!mConfig.isAnonymousLoginSupported()) {
throw new FtpException(530);
}
if ((anonNbr >= maxAnonConnection) || (totalNbr >= maxConnection)) {
throw new FtpException(530);
}
if (thisUser.getSocket() != null) {
getLogger().info(thisUser.getSocket().getInetAddress().getHostAddress() + " - "
+ thisUser.getPassword());
}
} else {
if (totalNbr >= maxConnection) {
throw new FtpException(530);
}
}
}
/**
* New connection has been established - not yet loggedin.
*/
public void newConnection(final FtpUser newUser) {
if (newUser == null) {
return;
}
mUserHash.put(newUser.getSessionId(), newUser);
newUser.setObserver(mObserver);
// notify observer about a new connection
if (mObserver != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mObserver.newConnection(newUser.getSessionId());
} catch (Exception ex) {
mSelf.setObserver(null);
}
}
});
}
// update global statistics
mConfig.getStatistics().setOpenConnection();
}
/**
* Close ftp connection for this session id.
*/
public void closeConnection(final String sessId) {
if (sessId == null) {
return;
}
FtpUser thisUser = (FtpUser) mUserHash.get(sessId);
mUserHash.remove(sessId);
if (thisUser == null) {
return;
}
// logout notification
if (thisUser.hasLoggedIn()) {
mConfig.getStatistics().setLogout(thisUser.getIsAnonymous());
}
thisUser.logout();
if (mObserver != null) {
mConfig.getMessageQueue().add(new Message() {
public void execute() {
try {
mObserver.closeConnection(sessId);
} catch (Exception ex) {
mSelf.setObserver(null);
}
}
});
}
mConfig.getStatistics().setCloseConnection();
}
/**
* Close all - close all the connections.
*/
public void closeAllConnections() {
Iterator connectedUsers = getAllConnectedUsers().iterator();
while (connectedUsers.hasNext()) {
FtpUser thisUser = (FtpUser) connectedUsers.next();
if (thisUser != null) {
closeConnection(thisUser.getSessionId());
}
}
}
/**
* Create default users (admin/anonymous) if necessary
*/
private void createDefaultUsers() {
// create admin user
if (!doesExist(FtpUser.ADMIN)) {
getLogger().info("Creating user " + FtpUser.ADMIN);
FtpUser adminUser = new FtpUser(mConfig, null, null);
adminUser.setName(FtpUser.ADMIN);
adminUser.setPassword(FtpUser.ADMIN);
adminUser.setEnabled(true);
adminUser.getVirtualDirectory().setWritePermission(true);
adminUser.setMaxUploadRate(0);
adminUser.setMaxDownloadRate(0);
adminUser.getVirtualDirectory().setRootDirectory(mConfig.getDefaultRoot());
adminUser.setMaxIdleTime(mConfig.getMaxIdleTime());
save(adminUser);
}
// create anonymous user
if (!doesExist(FtpUser.ANONYMOUS)) {
getLogger().info("Creating user " + FtpUser.ANONYMOUS);
FtpUser anonUser = new FtpUser(mConfig, null, null);
anonUser.setName(FtpUser.ANONYMOUS);
anonUser.setPassword("");
anonUser.setEnabled(true);
anonUser.getVirtualDirectory().setWritePermission(false);
anonUser.setMaxUploadRate(4800);
anonUser.setMaxDownloadRate(4800);
anonUser.getVirtualDirectory().setRootDirectory(mConfig.getDefaultRoot());
anonUser.setMaxIdleTime(mConfig.getMaxIdleTime());
save(anonUser);
}
}
/**
* Monitor a logged-in user.
*/
public void setSpyObject(String sessId, SpyUserInterface spy) {
if (sessId == null) {
return;
}
FtpUser user = (FtpUser) mUserHash.get(sessId);
if (user != null) {
user.setSpyObject(spy);
}
}
/**
* Get connected user by session id.
*/
public FtpUser getConnectedUser(String sessionId) {
if (sessionId == null) {
return null;
}
return (FtpUser) mUserHash.get(sessionId);
}
/**
* User existance check - default implementation.
* @param name user name
*/
public boolean doesExist(String name) {
return mUserManager.doesExist(name);
}
/**
* Save user object
*/
public void save(FtpUser user) {
mUserManager.save(user);
}
/**
* Delete user
*/
public void delete(String name) {
mUserManager.delete(name);
}
/**
* Get user by name
*/
public FtpUser getUserByName(String name) {
return mUserManager.getUserByName(name);
}
/**
* Get all user names
*/
public List getAllUserNames() {
return mUserManager.getAllUserNames();
}
/**
* User authenticate
*/
public boolean authenticate(String login, String password) {
return mUserManager.authenticate(login, password);
}
/**
* Close this user manager. If closes all the connected
* users and stops the cleaner thread.
*/
public void close() {
getLogger().info("Closing user manager : " + getClass().getName());
closeAllConnections();
mScheduler.removeTrigger(getClass().getName());
mUserManager.close();
}
/////////////////////////////////////////////////////
///////// Cleaner Thread Starting Point /////////
/////////////////////////////////////////////////////
/**
* This schedule driven period checks all the connected users and
* removes the idle users.
*/
public void targetTriggered(String triggerName) {
if (!getClass().getName().equals(triggerName)) {
return;
}
long currTime = System.currentTimeMillis();
// get inactive user list
ArrayList inactiveUserList = new ArrayList();
for (Enumeration userEn = mUserHash.keys(); userEn.hasMoreElements(); ) {
FtpUser thisUser = (FtpUser) mUserHash.get(userEn.nextElement());
if ((thisUser != null) && (!thisUser.isActive(currTime))) {
inactiveUserList.add(thisUser);
}
}
// now remove all the idle users
Iterator usrIt = inactiveUserList.iterator();
while (usrIt.hasNext()) {
FtpUser thisUser = (FtpUser) usrIt.next();
if (thisUser.getName() != null) {
getLogger().info("Removing idle user " + thisUser);
} else {
getLogger().info("Removing idle user");
}
closeConnection(thisUser.getSessionId());
}
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/DefaultUserHandler.xinfo
Index: DefaultUserHandler.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.interfaces.UserHandler" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler" version="1.0"/>
</dependency>
<dependency>
<service name="org.apache.avalon.ftpserver.services.UserManager" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/RemoteUserHandlerAdaptor.java
Index: RemoteUserHandlerAdaptor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager;
import org.apache.avalon.ftpserver.interfaces.RemoteUserHandler;
import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.interfaces.FtpConnectionObserver;
import org.apache.avalon.ftpserver.interfaces.SpyUserInterface;
import org.apache.avalon.ftpserver.FtpUser;
import java.util.List;
/**
* Class RemoteUserHandlerAdaptor
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class RemoteUserHandlerAdaptor implements RemoteUserHandler {
UserHandler mUserHandler;
/**
* Constructor RemoteUserHandlerAdaptor
*
*
* @param userHandler
*
*/
public RemoteUserHandlerAdaptor(UserHandler userHandler) {
mUserHandler = userHandler;
}
/**
* Save the user. If a new user, create it else update the
* existing user.
*/
public void save(FtpUser user) {
mUserHandler.save(user);
}
/**
* Delete the user from the system.
*
*
* @param userName
*/
public void delete(String userName) {
mUserHandler.delete(userName);
}
/**
* Get user by name.
*/
public FtpUser getUserByName(String name) {
return mUserHandler.getUserByName(name);
}
/**
* Fid user by session id
*/
public FtpUser getConnectedUser(String sessionId) {
return mUserHandler.getConnectedUser(sessionId);
}
/**
* Get all user names in the system.
*/
public List getAllUserNames() {
return mUserHandler.getAllUserNames();
}
/**
* User existance check.
*
* @param name user name
*/
public boolean doesExist(String name) {
return mUserHandler.doesExist(name);
}
/**
* Get all logged in user list. It returns a list of all the
* currently connected user objects.
*/
public List getAllConnectedUsers() {
return mUserHandler.getAllConnectedUsers();
}
/**
* Logout all ftp connections.
*/
public void closeAllConnections() {
mUserHandler.closeAllConnections();
}
/**
* Close connection
*/
public void closeConnection(String sessionId) {
mUserHandler.closeConnection(sessionId);
}
/**
* Set user manager observer.
*/
public void setObserver(FtpConnectionObserver obsr) {
mUserHandler.setObserver(obsr);
}
/**
* Get user manager observer.
*/
public FtpConnectionObserver getObserver() {
return mUserHandler.getObserver();
}
/**
* Set spy object.
*/
public void setSpyObject(String sessId, SpyUserInterface spy) {
mUserHandler.setSpyObject(sessId, spy);
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/db/DbUserManager.java
Index: DbUserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager.db;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
import org.apache.avalon.ftpserver.blocks.usermanager.AbstractUserManager;
import org.apache.avalon.ftpserver.services.UserManager;
/**
* This is another database based user manager class. I have
* tested it using MySQL database. The table structure is:
*
* <pre>
* CREATE TABLE USER (
* NAME CHAR(32) NOT NULL PRIMARY KEY,
* PASSWORD CHAR(32) NOT NULL,
* HOME CHAR(128) NOT NULL,
* ENABLED CHAR(8) NOT NULL,
* WRITE_PERM CHAR(8) NOT NULL,
* IDLE_TIME INT NOT NULL,
* UPLOAD_RATE INT NOT NULL,
* DOWNLOAD_RATE INT NOT NULL
* )
* </pre>
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DbUserManager extends AbstractUserManager {
private Connection mDbConnection = null;
private PreparedStatement mNewUserStmt = null;
private PreparedStatement mDelUserStmt = null;
private PreparedStatement mGetUserStmt = null;
private PreparedStatement mGetAllStmt = null;
private PreparedStatement mUpdUserStmt = null;
/**
* Method configure
*
*
* @param conf
*
* @throws ConfigurationException
*
*/
public void configure(Configuration conf) throws ConfigurationException {
super.configure(conf);
try {
Class.forName(conf.getChild("user-manager").getChild("driver").getValue());
String url = conf.getChild("user-manager").getChild("url").getValue();
String user = conf.getChild("user-manager").getChild("user").getValue(null);
String password = conf.getChild("user-manager").getChild("password").getValue(null);
mDbConnection = DriverManager.getConnection(url, user, password);
mDbConnection.setAutoCommit(true);
} catch (SQLException sqle) {
throw processSQLException(sqle);
} catch (ClassNotFoundException cnfe) {
throw processException(cnfe);
}
}
/**
* Method initialize
*
*
* @throws Exception
*
*/
public void initialize() throws Exception {
// prepare statements
try {
mDelUserStmt = mDbConnection.prepareStatement("DELETE FROM USER WHERE NAME = ?");
mGetAllStmt = mDbConnection.prepareStatement("SELECT NAME FROM USER");
mNewUserStmt =
mDbConnection
.prepareStatement("INSERT INTO USER VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
mUpdUserStmt = mDbConnection.prepareStatement(
"UPDATE USER SET PASSWORD = ?, HOME = ?, ENABLED = ?, WRITE_PERM = ?, IDLE_TIME = ?, UPLOAD_RATE = ?, DOWNLOAD_RATE = ? WHERE NAME = ?");
mGetUserStmt = mDbConnection.prepareStatement("SELECT * FROM USER WHERE NAME = ?");
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
}
/**
* Delete user. Delete the row from the table.
*/
public synchronized void delete(String name) {
try {
mDelUserStmt.setString(1, name);
mDelUserStmt.executeUpdate();
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
}
/**
* Save user. If new insert a new row, else update the existing row.
*/
public synchronized void save(FtpUser user) {
try {
// null value check
if (user.getName() == null) {
throw new NullPointerException("User name is null.");
}
if (!doesExist(user.getName())) {
mNewUserStmt.setString(1, user.getName());
mNewUserStmt.setString(2, getPassword(user));
mNewUserStmt.setString(3, user.getVirtualDirectory().getRootDirectory());
mNewUserStmt.setString(4, String.valueOf(user.getEnabled()));
mNewUserStmt
.setString(5, String
.valueOf(user.getVirtualDirectory().getWritePermission()));
mNewUserStmt.setInt(6, user.getMaxIdleTime());
mNewUserStmt.setInt(7, user.getMaxUploadRate());
mNewUserStmt.setInt(8, user.getMaxDownloadRate());
mNewUserStmt.executeUpdate();
} else {
mUpdUserStmt.setString(1, getPassword(user));
mUpdUserStmt.setString(2, user.getVirtualDirectory().getRootDirectory());
mUpdUserStmt.setString(3, String.valueOf(user.getEnabled()));
mUpdUserStmt
.setString(4, String
.valueOf(user.getVirtualDirectory().getWritePermission()));
mUpdUserStmt.setInt(5, user.getMaxIdleTime());
mUpdUserStmt.setInt(6, user.getMaxUploadRate());
mUpdUserStmt.setInt(7, user.getMaxDownloadRate());
mUpdUserStmt.setString(8, user.getName());
mUpdUserStmt.executeUpdate();
}
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
}
/**
* Get the user object. Fetch the row from the table.
*/
public synchronized FtpUser getUserByName(String name) {
try {
FtpUser thisUser = null;
mGetUserStmt.setString(1, name);
ResultSet rs = mGetUserStmt.executeQuery();
if (rs.next()) {
thisUser = new FtpUser(mConfig, null, null);
thisUser.setName(rs.getString("NAME"));
thisUser.getVirtualDirectory().setRootDirectory(new File(rs.getString("HOME")));
thisUser.setEnabled(rs.getString("ENABLED").equals(Boolean.TRUE.toString()));
thisUser.getVirtualDirectory()
.setWritePermission(rs.getString("WRITE_PERM")
.equals(Boolean.TRUE.toString()));
thisUser.setMaxIdleTime(rs.getInt("IDLE_TIME"));
thisUser.setMaxUploadRate(rs.getInt("UPLOAD_RATE"));
thisUser.setMaxDownloadRate(rs.getInt("DOWNLOAD_RATE"));
}
rs.close();
return thisUser;
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
}
/**
* User existance check
*/
public boolean doesExist(String name) {
boolean bValid = false;
try {
mGetUserStmt.setString(1, name);
ResultSet rs = mGetUserStmt.executeQuery();
bValid = rs.next();
rs.close();
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
return bValid;
}
/**
* Get all user names from the database.
*/
public synchronized List getAllUserNames() {
ArrayList names = new ArrayList();
try {
ResultSet rs = mGetAllStmt.executeQuery();
while (rs.next()) {
names.add(rs.getString("NAME"));
}
rs.close();
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
return names;
}
/**
* Get user password.
*/
private synchronized String getPassword(FtpUser user) {
try {
if (user.getPassword() != null) {
return user.getPassword();
}
String password = "";
mGetUserStmt.setString(1, user.getName());
ResultSet rs = mGetUserStmt.executeQuery();
if (rs.next()) {
password = rs.getString("PASSWORD");
}
rs.close();
return password;
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
}
/**
* User authentication
*/
public synchronized boolean authenticate(String user, String password) {
if (FtpUser.ANONYMOUS.equals(user)) {
return true;
}
String existPassword = null;
try {
mGetUserStmt.setString(1, user);
ResultSet rs = mGetUserStmt.executeQuery();
if (rs.next()) {
existPassword = rs.getString("PASSWORD");
}
rs.close();
} catch (SQLException sqle) {
throw processSQLException(sqle);
}
if (existPassword == null) {
return false;
}
return existPassword.equals(password);
}
/**
* Close this user manager. Close the database statements and connection.
*/
public synchronized void close() {
try {
mNewUserStmt.close();
} catch (SQLException ex) {}
try {
mDelUserStmt.close();
} catch (SQLException ex) {}
try {
mGetUserStmt.close();
} catch (SQLException ex) {}
try {
mGetAllStmt.close();
} catch (SQLException ex) {}
try {
mUpdUserStmt.close();
} catch (SQLException ex) {}
try {
mDbConnection.close();
} catch (SQLException ex) {}
}
private RuntimeException processSQLException(SQLException sqle) {
return new RuntimeException("Some low-level problem during SQL operation", sqle);
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/db/DbUserManager.xinfo
Index: DbUserManager.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.services.UserManager" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/ldap/LdapUserManager.java
Index: LdapUserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager.ldap;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.util.Properties;
import javax.naming.*;
import javax.naming.directory.*;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.blocks.config.DefaultConfig;
import org.apache.avalon.ftpserver.blocks.usermanager.AbstractUserManager;
import org.apache.avalon.ftpserver.services.UserManager;
import org.apache.avalon.framework.configuration.Configuration;
/**
* Ldap based user manager class. Tested using Netscape Directory Server 4.1.
* The LDAP requires the password to be nonempty for simple authentication. So
* instead of using empty string password (""), we will be using single space (" ").
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class LdapUserManager extends AbstractUserManager {
// LDAP attributes
private final static String LOGIN = "memberuid";
private final static String UID = "uid";
private final static String CN = "cn";
private final static String SN = "sn";
private final static String PASSWORD = "userpassword";
private final static String OBJ_CLASS = "objectclass";
private final static String ENABLE = "enableflag";
private final static String ROOT_DIR = "homedirectory";
private final static String WRITE_PERM = "writepermission";
private final static String IDLE_TIME = "idletime";
private final static String UP_RATE = "uploadrate";
private final static String DOWN_RATE = "downloadrate";
private final static String[] ALL_ATTRS = {
CN, LOGIN, ENABLE, ROOT_DIR, WRITE_PERM, IDLE_TIME, UP_RATE, DOWN_RATE
};
private final static Attribute OBJCLASS_ATTR = new BasicAttribute(OBJ_CLASS, true);
// Currently we are using only one connection.
// This will be replaced by LDAP connection pool.
private DirContext mAdminContext;
private Properties mAdminEnv;
private String mstLdapRoot;
/**
* Instantiate <code>UserManager</code> implementation.
* Open LDAP connection pool.
*/
public void configure(Configuration conf)
throws org.apache.avalon.framework.configuration.ConfigurationException {
super.configure(conf);
// get ldap parameters
String url = conf.getChild("user-manager").getChild("url").getValue();
String ldapRoot = conf.getChild("user-manager").getChild("root").getValue();
String admin = conf.getChild("user-manager").getChild("admin").getValue();
String password = conf.getChild("user-manager").getChild("password").getValue();
String auth = conf.getChild("user-manager").getChild("authentication").getValue();
mAdminEnv = new Properties();
mAdminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
mAdminEnv.setProperty(Context.PROVIDER_URL, url);
mAdminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth);
mAdminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin);
mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);
try {
mAdminContext = new InitialDirContext(mAdminEnv);
mstLdapRoot = ldapRoot;
} catch (NamingException ne) {
throw processNamingException(ne);
}
}
/**
* Get common name
*/
private synchronized String getCommonName(String login) throws NamingException {
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute(LOGIN, login));
matchAttrs.put(OBJCLASS_ATTR);
NamingEnumeration answers = mAdminContext.search("ou=people," + mstLdapRoot, matchAttrs,
ALL_ATTRS);
String cn = null;
if (answers.hasMore()) {
SearchResult sr = (SearchResult) answers.next();
cn = sr.getAttributes().get(CN).get().toString();
}
answers.close();
return cn;
}
/**
* Get all user names
*/
public List getAllUserNames() {
List allUsers = new ArrayList();
try {
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(OBJCLASS_ATTR);
NamingEnumeration answers = mAdminContext.search("ou=people," + mstLdapRoot,
matchAttrs, ALL_ATTRS);
while (answers.hasMore()) {
SearchResult sr = (SearchResult) answers.next();
String login = sr.getAttributes().get(LOGIN).get().toString();
allUsers.add(login);
}
} catch (NamingException ex) {
getLogger().error(ex.getMessage());
}
return allUsers;
}
/**
* Get user object.
*/
public FtpUser getUserByName(String name) {
FtpUser user = null;
try {
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute(LOGIN, name));
matchAttrs.put(OBJCLASS_ATTR);
NamingEnumeration answers = mAdminContext.search("ou=people," + mstLdapRoot,
matchAttrs, ALL_ATTRS);
if (answers.hasMore()) {
SearchResult sr = (SearchResult) answers.next();
Attributes attrs = sr.getAttributes();
user = new FtpUser(mConfig, null, null);
user.setName(attrs.get(LOGIN).get().toString());
user.getVirtualDirectory()
.setRootDirectory(new File(attrs.get(ROOT_DIR).get().toString()));
user.setEnabled(Boolean.TRUE.toString()
.equals(attrs.get(ENABLE).get().toString()));
user.getVirtualDirectory()
.setWritePermission(Boolean.TRUE.toString()
.equals(attrs.get(WRITE_PERM).get().toString()));
user.setMaxIdleTime(Integer.parseInt(attrs.get(IDLE_TIME).get().toString()));
user.setMaxUploadRate(Integer.parseInt(attrs.get(UP_RATE).get().toString()));
user.setMaxDownloadRate(Integer.parseInt(attrs.get(DOWN_RATE).get().toString()));
}
answers.close();
} catch (NamingException ex) {
getLogger().error(ex.getMessage());
user = null;
}
return user;
}
/**
* User authentication.
*/
public boolean authenticate(String name, String password) {
// anonymous user - authentication is not required
if (FtpUser.ANONYMOUS.equals(name)) {
return true;
}
// empty password string is not allowed
if (password == null) {
password = " ";
}
if (password.equals("")) {
password = " ";
}
try {
String cn = getCommonName(name);
if (cn != null) {
Properties userProp = (Properties) mAdminEnv.clone();
String dn = CN + '=' + cn + ",ou=people," + mstLdapRoot;
userProp.setProperty(Context.SECURITY_PRINCIPAL, dn);
userProp.setProperty(Context.SECURITY_CREDENTIALS, password);
DirContext userContext = new InitialDirContext(userProp);
userContext.close();
return true;
}
} catch (NamingException ex) {}
return false;
}
/**
* Save user
*/
public synchronized void save(FtpUser user) {
if (doesExist(user.getName())) {
update(user);
} else {
add(user);
}
}
/**
* Add a new user
*/
private synchronized void add(FtpUser user) {
// empty password is not allowed
if (user.getPassword() == null) {
user.setPassword(" ");
}
if (user.getPassword().equals("")) {
user.setPassword(" ");
}
// ensure atlease one milliseceond time difference
try {
Thread.sleep(1);
} catch (InterruptedException ex) {}
String cn = user.getName() + "-" + System.currentTimeMillis();
String path = CN + '=' + cn + ",ou=people," + mstLdapRoot;
Attributes attrs = new BasicAttributes(true);
attrs.put(new BasicAttribute(LOGIN, user.getName()));
attrs.put(new BasicAttribute(UID, user.getName()));
attrs.put(new BasicAttribute(CN, cn));
attrs.put(new BasicAttribute(SN, user.getName()));
attrs.put(new BasicAttribute(PASSWORD, user.getPassword()));
attrs.put(OBJCLASS_ATTR);
attrs.put(new BasicAttribute(ENABLE, String.valueOf(user.getEnabled())));
attrs.put(new BasicAttribute(ROOT_DIR, user.getVirtualDirectory().getRootDirectory()));
attrs.put(new BasicAttribute(WRITE_PERM,
String.valueOf(user.getVirtualDirectory()
.getWritePermission())));
attrs.put(new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime())));
attrs.put(new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate())));
attrs.put(new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate())));
try {
mAdminContext.bind(path, null, attrs);
} catch (NamingException ne) {
throw processNamingException(ne);
}
}
/**
* Update an existing user
*/
private synchronized void update(FtpUser user) {
try {
String cn = getCommonName(user.getName());
String dn = CN + '=' + cn + ",ou=people," + mstLdapRoot;
ArrayList mods = new ArrayList();
if (user.getPassword() != null) {
if (user.getPassword().equals("")) {
user.setPassword(" ");
}
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(PASSWORD, user.getPassword())));
}
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(ENABLE,
String.valueOf(user.getEnabled()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(ROOT_DIR,
user.getVirtualDirectory()
.getRootDirectory())));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(WRITE_PERM,
String.valueOf(user
.getVirtualDirectory()
.getWritePermission()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(IDLE_TIME,
String.valueOf(user
.getMaxIdleTime()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(UP_RATE,
String.valueOf(user
.getMaxUploadRate()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(DOWN_RATE,
String.valueOf(user
.getMaxDownloadRate()))));
ModificationItem modArr[] = new ModificationItem[mods.size()];
for (int i = 0; i < modArr.length; i++) {
modArr[i] = (ModificationItem) mods.get(i);
}
mAdminContext.modifyAttributes(dn, modArr);
} catch (NamingException ne) {
throw processNamingException(ne);
}
}
/**
* User existance check
*/
public synchronized boolean doesExist(String name) {
String cn = null;
try {
cn = getCommonName(name);
} catch (NamingException ex) {
getLogger().error(ex.getMessage());
}
return cn != null;
}
/**
* Delete user
*/
public synchronized void delete(String userName) {
try {
String cn = getCommonName(userName);
if (cn != null) {
String dn = CN + '=' + cn + ",ou=people," + mstLdapRoot;
mAdminContext.unbind(dn);
}
} catch (NamingException ne) {
throw processNamingException(ne);
}
}
/**
* Close user manager
*/
public synchronized void close() {
try {
if (mAdminContext != null) {
mAdminContext.close();
}
} catch (NamingException ex) {
getLogger().error(ex.getMessage());
}
mAdminContext = null;
}
private RuntimeException processNamingException(NamingException ne) {
return new RuntimeException("Some low-level problem during naming operation", ne);
}
// static block
static {
OBJCLASS_ATTR.add("top");
OBJCLASS_ATTR.add("person");
OBJCLASS_ATTR.add("organizationalPerson");
OBJCLASS_ATTR.add("inetOrgPerson");
OBJCLASS_ATTR.add("ftpUsers");
}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/ldap/LdapUserManager.xinfo
Index: LdapUserManager.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.services.UserManager" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/props/PropertiesUserManager.java
Index: PropertiesUserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.blocks.usermanager.props;
import java.io.File;
import java.util.List;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Collections;
import java.util.ArrayList;
import org.apache.avalon.ftpserver.util.BaseProperties;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.blocks.usermanager.AbstractUserManager;
import org.apache.avalon.cornerstone.services.store.ObjectRepository;
import org.apache.avalon.cornerstone.services.store.Store;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
/**
* Default properties file based <code>UserManager</code>
* implementation. We use <code>user.properties</code> file
* to store user data.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class PropertiesUserManager extends AbstractUserManager {
private final static String PREFIX = "FtpServer.user.";
private final static String USER_PROP = "user.properties";
private BaseProperties mUserData;
protected Store mStore;
protected Configuration mStoreConfig;
protected ObjectRepository mObjectRepository;
/**
* Method configure
*
*
* @param conf
*
* @throws ConfigurationException
*
*/
public void configure(Configuration conf) throws ConfigurationException {
super.configure(conf);
mStoreConfig = conf.getChild("repository");
}
/**
* Get all managers.
*/
public void compose(ComponentManager compManager) throws ComponentException {
super.compose(compManager);
mStore = (Store) compManager.lookup(Store.class.getName());
}
/**
* Initialize server socket.
*/
public void initialize() throws Exception {
super.initialize();
mObjectRepository = (ObjectRepository) mStore.select(mStoreConfig);
loadData();
}
/**
* Save user data. Store the properties.
*/
public synchronized void save(FtpUser usr) {
// null value check
if (usr.getName() == null) {
throw new NullPointerException("User name is null.");
}
String thisPrefix = PREFIX + usr.getName() + '.';
// set password
if (doesExist(usr.getName())) {
if (usr.getPassword() != null) {
mUserData.setProperty(thisPrefix + "password", usr.getPassword());
}
} else {
String password = usr.getPassword();
if (password == null) {
password = "";
}
mUserData.setProperty(thisPrefix + "password", password);
}
// set other properties
mUserData.setProperty(thisPrefix + "home", usr.getVirtualDirectory().getRootDirectory());
mUserData.setProperty(thisPrefix + "enabled", usr.getEnabled());
mUserData.setProperty(thisPrefix + "write",
usr.getVirtualDirectory().getWritePermission());
mUserData.setProperty(thisPrefix + "idle", usr.getMaxIdleTime());
mUserData.setProperty(thisPrefix + "upload", usr.getMaxUploadRate());
mUserData.setProperty(thisPrefix + "download", usr.getMaxDownloadRate());
mObjectRepository.put("user-data", mUserData);
}
/**
* Delete an user. Removes all this user entries from the properties.
* After removing the corresponding from the properties, save the data.
*/
public synchronized void delete(String usrName) {
String thisPrefix = PREFIX + usrName + '.';
Enumeration propNames = mUserData.propertyNames();
while (propNames.hasMoreElements()) {
String thisKey = propNames.nextElement().toString();
if (thisKey.startsWith(thisPrefix)) {
mUserData.remove(thisKey);
}
}
mObjectRepository.remove("user-data");
}
/**
* Read the properties file again.
*/
private synchronized void loadData() {
if (mObjectRepository.containsKey("user-data")) {
mUserData = (BaseProperties) mObjectRepository.get("user-data");
} else {
mUserData = new BaseProperties();
}
getLogger().info("Loaded user data file ");
}
/**
* Get all user names.
*/
public List getAllUserNames() {
// get all unique user names
HashSet hlst = new HashSet();
Enumeration allKeys = mUserData.propertyNames();
while (allKeys.hasMoreElements()) {
String key = (String) allKeys.nextElement();
if (key.endsWith(".home")) {
String name = key.substring(PREFIX.length());
int endIndex = name.length() - ".home".length();
name = name.substring(0, endIndex);
hlst.add(name);
}
}
// get all user objects
ArrayList retLst = new ArrayList();
for (Iterator ait = hlst.iterator(); ait.hasNext(); ) {
retLst.add(ait.next().toString());
}
return retLst;
}
/**
* Load user data.
*/
public FtpUser getUserByName(String userName) {
if (!doesExist(userName)) {
return null;
}
String baseKey = PREFIX + userName + '.';
FtpUser user = new FtpUser(mConfig, null, null);
user.setName(userName);
user.setEnabled(mUserData.getBoolean(baseKey + "enabled", true));
user.getVirtualDirectory().setRootDirectory(mUserData.getFile(baseKey + "home",
new File("/")));
user.getVirtualDirectory().setWritePermission(mUserData.getBoolean(baseKey + "write",
false));
user.setMaxIdleTime(mUserData.getInteger(baseKey + "idle", 0));
user.setMaxUploadRate(mUserData.getInteger(baseKey + "upload", 0));
user.setMaxDownloadRate(mUserData.getInteger(baseKey + "download", 0));
return user;
}
/**
* User existance check
*/
public boolean doesExist(String name) {
String key = PREFIX + name + ".home";
return mUserData.containsKey(key);
}
/**
* User authenticate method
*/
public boolean authenticate(String user, String password) {
// anonymous user
if (FtpUser.ANONYMOUS.equals(user)) {
return true;
}
String passVal = mUserData.getProperty(PREFIX + user + ".password");
return password.equals(passVal);
}
/**
* Close the user manager - does nothing.
*/
public void close() {}
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/blocks/usermanager/props/PropertiesUserManager.xinfo
Index: PropertiesUserManager.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.services.UserManager" version="1.0" />
</services>
<dependencies>
<dependency>
<service name="org.apache.avalon.ftpserver.services.FtpConfigService" version="1.0"/>
</dependency>
<dependency>
<service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
1.4 +20 -19 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/CommonHandler.java
Index: CommonHandler.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/CommonHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CommonHandler.java 2001/12/13 13:26:04 1.3
+++ CommonHandler.java 2001/12/14 01:22:03 1.4
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,14 +6,17 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
-import java.awt.Component;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
-import org.apache.avalon.ftpserver.interfaces.FtpRemoteAdmin;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpAdmin;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
-/**
+import java.awt.*;
+
+
+/**
* GUI common handler methods.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
@@ -24,36 +28,33 @@
*/
void handleException(Exception ex);
-
/**
* Terminate application
*/
- void terminate();
-
-
+ void terminate();
+
/**
* Get admin session
*/
String getSessionId();
-
+
/**
* Get ftp server interface
*/
- FtpRemoteAdmin getServer();
-
-
+ RemoteFtpAdmin getServer();
+
/**
* Get config interface
*/
- FtpConfigInterface getConfig();
-
+ RemoteFtpConfig getConfig();
+
/**
* Logout admin
- */
+ */
void logout();
-
+
/**
* Get top component
- */
- Component getTopComponent();
+ */
+ Component getTopComponent();
}
1.5 +58 -64 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/ConfigTableModel.java
Index: ConfigTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/ConfigTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigTableModel.java 2001/11/10 21:34:04 1.4
+++ ConfigTableModel.java 2001/12/14 01:22:03 1.5
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,152 +6,145 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.util.Vector;
+
import javax.swing.table.AbstractTableModel;
+
import java.rmi.RemoteException;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
+
+
/**
* This table model is used to display <code>Properties</code>.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class ConfigTableModel extends AbstractTableModel {
-
- private final static String[] COL_NAMES = {"Name", "Value"};
-
+public class ConfigTableModel extends AbstractTableModel {
+
+ private final static String[] COL_NAMES = { "Name", "Value" };
+
/**
* Ftp config remote object.
- */
- private FtpConfigInterface mConfig;
-
+ */
+ private RemoteFtpConfig mConfig;
private CommonHandler mCommonHandler;
-
+
/**
* All properties key.
*/
- private Vector mTableKeys = new Vector();
+ private Vector mTableKeys = new Vector();
private Vector mTableVals = new Vector();
-
-
+
/**
* Create this <code>TableModel</code>.
*/
public ConfigTableModel(CommonHandler commonHandler) throws RemoteException {
+
mConfig = commonHandler.getConfig();
mCommonHandler = commonHandler;
+
initializeTable();
}
-
+
/**
* Initialize table - populate vector.
*/
private void initializeTable() throws RemoteException {
+
mTableKeys.clear();
mTableVals.clear();
-
- if(mConfig != null) {
+
+ if (mConfig != null) {
mTableKeys.add("Server Address");
mTableVals.add(String.valueOf(mConfig.getServerAddress().getHostAddress()));
-
mTableKeys.add("Server Port");
mTableVals.add(String.valueOf(mConfig.getServerPort()));
-
mTableKeys.add("Maximum Connections");
mTableVals.add(String.valueOf(mConfig.getMaxConnections()));
-
mTableKeys.add("Anonymous Login Supported");
mTableVals.add(String.valueOf(mConfig.isAnonymousLoginSupported()));
-
mTableKeys.add("Maximum Anonymous Connections");
mTableVals.add(String.valueOf(mConfig.getMaxAnonymousConnections()));
-
mTableKeys.add("Scheduler Interval (sec)");
mTableVals.add(String.valueOf(mConfig.getSchedulerInterval()));
-
mTableKeys.add("Default Idle Time (sec)");
mTableVals.add(String.valueOf(mConfig.getMaxIdleTime()));
-
mTableKeys.add("Remote Admin Supported");
mTableVals.add(String.valueOf(mConfig.isRemoteAdminSupported()));
-
mTableKeys.add("Remote Admin Port");
mTableVals.add(String.valueOf(mConfig.getRemoteAdminPort()));
-
- mTableKeys.add("User Manager Class");
- mTableVals.add(String.valueOf(mConfig.getUserManagerClassName()));
-
mTableKeys.add("Base Directory");
mTableVals.add(String.valueOf(mConfig.getBaseDirectory()));
}
-
- }
-
-
+ }
+
/**
* Get column class - always string.
*/
public Class getColumnClass(int index) {
return String.class;
}
-
+
/**
* Get column count.
*/
public int getColumnCount() {
return COL_NAMES.length;
- }
-
+ }
+
/**
* Get column name.
*/
public String getColumnName(int index) {
return COL_NAMES[index];
- }
-
+ }
+
/**
* Get row count.
*/
public int getRowCount() {
return mTableKeys.size();
- }
-
+ }
+
/**
* Get value at.
*/
public Object getValueAt(int row, int col) {
- if(col == 0) {
+
+ if (col == 0) {
return mTableKeys.get(row);
+ } else {
+ return mTableVals.get(row);
}
- else {
- return mTableVals.get(row);
- }
- }
-
+ }
+
/**
* Is cell editable - currently true.
*/
public boolean isCellEditable(int row, int col) {
return true;
- }
-
- /**
- * Set value at - does not set value - dummy metod.
- */
- public void setValueAt(Object val, int row, int col) {
- }
-
- /**
- * Clear table model.
- */
- public void clear() {
- mTableKeys.clear();
- mTableVals.clear();
- mConfig = null;
- fireTableDataChanged();
- }
-}
+ }
+
+ /**
+ * Set value at - does not set value - dummy metod.
+ */
+ public void setValueAt(Object val, int row, int col) {}
+
+ /**
+ * Clear table model.
+ */
+ public void clear() {
+
+ mTableKeys.clear();
+ mTableVals.clear();
+
+ mConfig = null;
+
+ fireTableDataChanged();
+ }
+}
1.2 +86 -52 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminDialog.java
Index: FtpAdminDialog.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminDialog.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpAdminDialog.java 2001/12/13 13:26:04 1.1
+++ FtpAdminDialog.java 2001/12/14 01:22:03 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,19 +6,24 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
+
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
+
import org.apache.avalon.ftpserver.FtpException;
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
-import org.apache.avalon.ftpserver.interfaces.FtpRemoteAdmin;
+import org.apache.avalon.ftpserver.interfaces.FtpConfig;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpAdmin;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
/**
@@ -26,26 +32,25 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpAdminDialog extends JDialog implements CommonHandler {
+public class FtpAdminDialog extends JDialog implements CommonHandler {
- private String mstSessionId = null;
- private JTextField mjHostTxt = null;
- private JTextField mjPortTxt = null;
- private JTextField mjAdminTxt = null;
+ private String mstSessionId = null;
+ private JTextField mjHostTxt = null;
+ private JTextField mjPortTxt = null;
+ private JTextField mjAdminTxt = null;
private JPasswordField mjPasswordTxt = null;
-
- private FtpRemoteAdmin mServer = null;
- private FtpConfigInterface mConfig = null;
+ private RemoteFtpAdmin mServer = null;
+ private RemoteFtpConfig mConfig = null;
private FtpAdminFrame mFtpAdminFrame;
-
/**
* Consructor - initialize components and display
* the login dialog box.
*/
public FtpAdminDialog(FtpAdminFrame faf) {
+
mFtpAdminFrame = faf;
+
initComponents();
pack();
setResizable(false);
@@ -58,123 +63,153 @@
* Iniialize all the swing components.
*/
public void initComponents() {
+
GridBagConstraints gc;
+
getContentPane().setLayout(new GridBagLayout());
// Host name
JLabel jHostLab = new JLabel("Host");
+
jHostLab.setHorizontalAlignment(JLabel.RIGHT);
jHostLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
+
getContentPane().add(jHostLab, gc);
mjHostTxt = new JTextField("localhost");
+
mjHostTxt.setColumns(15);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 0;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
+
getContentPane().add(mjHostTxt, gc);
// Port number
JLabel jPortLab = new JLabel("Port");
+
jPortLab.setHorizontalAlignment(JLabel.RIGHT);
jPortLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 1;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
+
getContentPane().add(jPortLab, gc);
mjPortTxt = new JTextField(String.valueOf(Registry.REGISTRY_PORT));
+
mjPortTxt.setColumns(5);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 1;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
+
getContentPane().add(mjPortTxt, gc);
// Admin login id
JLabel jAdminLab = new JLabel("Admin Id");
+
jAdminLab.setHorizontalAlignment(JLabel.RIGHT);
jAdminLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 2;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
+
getContentPane().add(jAdminLab, gc);
mjAdminTxt = new JTextField();
+
mjAdminTxt.setColumns(15);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 2;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
+
getContentPane().add(mjAdminTxt, gc);
// Admin password
JLabel jPasswordLab = new JLabel("Admin Password");
+
jPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jPasswordLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 3;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
+
getContentPane().add(jPasswordLab, gc);
mjPasswordTxt = new JPasswordField();
+
mjPasswordTxt.setColumns(15);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 3;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
+
getContentPane().add(mjPasswordTxt, gc);
// button panel
JPanel btnPane = new JPanel();
+
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton jLoginBtn = new JButton("Login");
+
jLoginBtn.setSelected(true);
jLoginBtn.setDefaultCapable(true);
btnPane.add(jLoginBtn);
JButton jCancelBtn = new JButton("Cancel");
+
btnPane.add(jCancelBtn);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 4;
gc.gridwidth = 3;
- getContentPane().add(btnPane, gc);
+ getContentPane().add(btnPane, gc);
// event listeners
jLoginBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
login();
- }
+ }
});
-
jCancelBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
terminate();
- }
+ }
});
}
@@ -182,23 +217,25 @@
* Handle window closing event.
*/
protected void processWindowEvent(WindowEvent e) {
+
int id = e.getID();
+
if (id == WindowEvent.WINDOW_CLOSING) {
super.processWindowEvent(e);
terminate();
}
}
-
/**
* Login and get remote object
*/
private void login() {
+
try {
String host = mjHostTxt.getText();
String port = mjPortTxt.getText();
String login = mjAdminTxt.getText();
- String password = new String(mjPasswordTxt.getPassword());
+ String password = new String(mjPasswordTxt.getPassword());
mjHostTxt.setText("localhost");
mjPortTxt.setText(String.valueOf(Registry.REGISTRY_PORT));
@@ -206,20 +243,17 @@
mjPasswordTxt.setText("");
String url = "rmi://" + host + ":" + port + "/" + FtpAdmin.class.getName();
- mServer = (FtpRemoteAdmin)Naming.lookup(url);
- mstSessionId = mServer.adminLogin(login, password);
- mConfig = mServer.getConfigInterface(mstSessionId);
+ mServer = (RemoteFtpAdmin) Naming.lookup(url);
+ mstSessionId = mServer.adminLogin(login, password);
+ mConfig = mServer.getConfig(mstSessionId);
mFtpAdminFrame.setCommonHandler(this);
-
setVisible(false);
- }
- catch(FtpException ex) {
+ } catch (FtpException ex) {
GuiUtils.showErrorMessage(getTopComponent(), "Login failuer - try again.");
- }
- catch(Exception ex) {
- handleException(ex);
+ } catch (Exception ex) {
+ handleException(ex);
}
}
@@ -227,10 +261,12 @@
* Handle exception
*/
public void handleException(Exception ex) {
+
//ex.printStackTrace();
GuiUtils.showErrorMessage(getTopComponent(), ex.getMessage());
- if (ex instanceof java.rmi.RemoteException) {
- logout();
+
+ if (ex instanceof java.rmi.RemoteException) {
+ logout();
}
}
@@ -238,65 +274,63 @@
* Terminate application
*/
public void terminate() {
+
logout();
dispose();
+
//System.exit(0);
}
-
/**
* Get admin session id
*/
public String getSessionId() {
- return mstSessionId;
+ return mstSessionId;
}
-
/**
* Get server interface
*/
- public FtpRemoteAdmin getServer() {
- return mServer;
+ public RemoteFtpAdmin getServer() {
+ return mServer;
}
-
/**
* Get ftp server configuration
*/
- public FtpConfigInterface getConfig() {
- return mConfig;
+ public RemoteFtpConfig getConfig() {
+ return mConfig;
}
-
/**
* Logout admin user
*/
public void logout() {
- if (mFtpAdminFrame != null) {
+
+ if (mFtpAdminFrame != null) {
mFtpAdminFrame.close();
+
mFtpAdminFrame = null;
}
+
setVisible(true);
+
if (mServer != null) {
- try {
+ try {
mServer.adminLogout(mstSessionId);
- }
- catch(Exception ex) {
- }
+ } catch (Exception ex) {}
+
mServer = null;
- }
+ }
+
mstSessionId = null;
mConfig = null;
}
-
/**
* Get top component of this application
*/
public Component getTopComponent() {
- return this;
+ return this;
}
-
-
-
}
1.9 +73 -47 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java
Index: FtpAdminFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FtpAdminFrame.java 2001/12/13 13:26:04 1.8
+++ FtpAdminFrame.java 2001/12/14 01:22:03 1.9
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,116 +6,137 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.RemoteException;
+
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
-import org.apache.avalon.ftpserver.interfaces.FtpConfigInterface;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpConfig;
import org.apache.avalon.ftpserver.FtpException;
+
import org.jesktop.frimble.JFrimble;
import org.jesktop.frimble.FrimbleEvent;
import org.jesktop.frimble.FrimbleAdapter;
/**
- * Ftp server admin user interface.
+ * Ftp server admin user interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpAdminFrame extends JFrimble
- implements TreeSelectionListener {
-
- private JTabbedPane mjTabPane;
-
- private JTree mjFtpTree = null;
- private JPanel mjFtpPane = null;
-
- private FtpRootPanel mRootPane = null;
- private FtpConfigInterface mConfig = null;
- private CommonHandler mCommonHandler = null;
- private FtpAdminPanel mFtpAdminPanel;
+public class FtpAdminFrame extends JFrimble implements TreeSelectionListener {
+ private JTabbedPane mjTabPane;
+ private JTree mjFtpTree = null;
+ private JPanel mjFtpPane = null;
+ private FtpRootPanel mRootPane = null;
+ private RemoteFtpConfig mConfig = null;
+ private CommonHandler mCommonHandler = null;
+ private FtpAdminPanel mFtpAdminPanel;
/**
- * Creates new form MyServerFrame
+ * Creates new form MyServerFrame
*/
public FtpAdminFrame() {
+
JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu("File");
JMenuItem jmi = new JMenuItem("Connect..");
+
jmb.add(jm);
jm.add(jmi);
jmi.addActionListener(new ActionListener() {
+
public void actionPerformed(ActionEvent ae) {
new FtpAdminDialog(FtpAdminFrame.this);
}
});
super.setJMenuBar(jmb);
+
mFtpAdminPanel = new FtpAdminPanel();
+
this.getContentPane().add(mFtpAdminPanel, BorderLayout.CENTER);
pack();
setTitle("Ftp Server");
GuiUtils.setLocation(this.getFrimbleContained());
}
+ /**
+ * Method setCommonHandler
+ *
+ *
+ * @param commonHandler
+ *
+ * @throws FtpException
+ * @throws RemoteException
+ *
+ */
void setCommonHandler(CommonHandler commonHandler) throws RemoteException, FtpException {
+
mCommonHandler = commonHandler;
mConfig = mCommonHandler.getConfig();
- initComponents();
+ initComponents();
}
/**
* This method is called from within the constructor to
* initialize the form.
*/
- private void initComponents() throws RemoteException {
+ private void initComponents() throws RemoteException {
+
mjTabPane = new JTabbedPane();
-
+
// top level
JSplitPane jSplitPane = new JSplitPane();
+
jSplitPane.setDividerSize(2);
-
+
// left pane
mjFtpTree = new JTree(new FtpTreeModel());
- JScrollPane custPane = new JScrollPane(mjFtpTree,
+
+ JScrollPane custPane = new JScrollPane(mjFtpTree,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
jSplitPane.setLeftComponent(custPane);
-
+
// right pane
mjFtpPane = new JPanel();
+
jSplitPane.setRightComponent(mjFtpPane);
-
+
mRootPane = new FtpRootPanel(mCommonHandler);
mjFtpPane.add(mRootPane);
-
mjFtpTree.addTreeSelectionListener(this);
mjFtpTree.setSelectionPath(new TreePath(FtpAdmin.DISPLAY_NAME));
-
- jSplitPane.setDividerLocation(120);
+ jSplitPane.setDividerLocation(120);
mjTabPane.addTab(FtpAdmin.DISPLAY_NAME, jSplitPane);
mFtpAdminPanel.add(mjTabPane, BorderLayout.CENTER);
-
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
// handle closing of window.
this.addFrimbleListener(new FrimbleAdapter() {
- public void frimbleClosing(FrimbleEvent e) {
- if ( !GuiUtils.getConfirmation(FtpAdminFrame.this.getFrimbleContained(), "Do you really want to exit?") ) {
- return;
- }
- mCommonHandler.terminate();
- }
+
+ public void frimbleClosing(FrimbleEvent e) {
+
+ if (!GuiUtils.getConfirmation(FtpAdminFrame.this.getFrimbleContained(),
+ "Do you really want to exit?")) {
+ return;
+ }
+
+ mCommonHandler.terminate();
+ }
});
}
@@ -122,49 +144,53 @@
* Handle tree selection
*/
public void valueChanged(TreeSelectionEvent e) {
+
Object node = e.getPath().getLastPathComponent();
TreeModel model = mjFtpTree.getModel();
JPanel dispPane = null;
- if(model.getRoot().equals(node)) {
+
+ if (model.getRoot().equals(node)) {
dispPane = mRootPane;
- }
- else if(node.equals(FtpTreeModel.CHILDREN[0])) {
+ } else if (node.equals(FtpTreeModel.CHILDREN[0])) {
dispPane = mRootPane.getUserPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[1])) {
+ } else if (node.equals(FtpTreeModel.CHILDREN[1])) {
dispPane = mRootPane.getConnectionPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[2])) {
+ } else if (node.equals(FtpTreeModel.CHILDREN[2])) {
dispPane = mRootPane.getIpPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[3])) {
+ } else if (node.equals(FtpTreeModel.CHILDREN[3])) {
dispPane = mRootPane.getStatisticsPanel();
}
-
- if(dispPane != null) {
+
+ if (dispPane != null) {
GuiUtils.showNewPanel(mjFtpPane, dispPane);
}
}
-
+
/**
* Release resources
*/
public void close() {
- setVisible(false);
+
+ setVisible(false);
+
if (mRootPane != null) {
mRootPane.close();
}
+
dispose();
}
////////////////////////////////////////////////////////////////////////
/////////////////////// Program Starting Point ///////////////////////
////////////////////////////////////////////////////////////////////////
+
/**
* Remote admin starting point.
*/
public static void main(String args[]) {
+
JFrimble f = new FtpAdminFrame();
+
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(new Dimension(600, 450));
1.2 +26 -1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminPanel.java
Index: FtpAdminPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpAdminPanel.java 2001/10/27 13:15:56 1.1
+++ FtpAdminPanel.java 2001/12/14 01:22:03 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,16 +6,40 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import javax.swing.*;
+
import java.awt.*;
+
+/**
+ * Class FtpAdminPanel
+ *
+ *
+ * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
+ * @version $Revision: 1.2 $
+ */
public class FtpAdminPanel extends JPanel {
+
+ /**
+ * Constructor FtpAdminPanel
+ *
+ *
+ */
public FtpAdminPanel() {
this.setLayout(new BorderLayout());
}
+
+ /**
+ * Method getPreferredSize
+ *
+ *
+ * @return
+ *
+ */
public Dimension getPreferredSize() {
return new Dimension(600, 450);
}
1.3 +96 -68 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionPanel.java
Index: FtpConnectionPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionPanel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpConnectionPanel.java 2001/11/10 21:34:04 1.2
+++ FtpConnectionPanel.java 2001/12/14 01:22:03 1.3
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,15 +6,19 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.RemoteException;
+
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
+
import org.apache.avalon.ftpserver.FtpUser;
-import org.apache.avalon.ftpserver.interfaces.UserHandlerInterface;
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
/**
@@ -21,140 +26,163 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpConnectionPanel extends JPanel {
-
- private JTable mjConnectionTable;
- private FtpSpyDialog mSpyDlg;
- private UserHandlerInterface mUserHandler;
+public class FtpConnectionPanel extends JPanel {
+
+ private JTable mjConnectionTable;
+ private FtpSpyDialog mSpyDlg;
+ private UserHandler mUserHandler;
private CommonHandler mCommonHandler;
-
+
/**
* Instantiate login panel.
*/
public FtpConnectionPanel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- mUserHandler = commonHandler.getConfig().getUserHandlerInterface();
+ mUserHandler = commonHandler.getConfig().getUserHandler();
mSpyDlg = new FtpSpyDialog(mCommonHandler);
+
initComponents();
}
-
+
/**
* Initialize UI components
*/
private void initComponents() throws RemoteException {
-
+
setLayout(new BorderLayout());
-
+
mjConnectionTable = new JTable(new FtpConnectionTableModel(mCommonHandler));
+
mjConnectionTable.setPreferredScrollableViewportSize(new Dimension(420, 320));
mjConnectionTable.setColumnSelectionAllowed(false);
- JScrollPane bottomPane = new JScrollPane(mjConnectionTable,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ JScrollPane bottomPane = new JScrollPane(mjConnectionTable,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
add(bottomPane, BorderLayout.CENTER);
-
-
+
// buttons
JPanel btnPane = new JPanel();
+
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
JButton jCloseBtn = new JButton("Close");
+
btnPane.add(jCloseBtn);
-
+
JButton jSpyBtn = new JButton("Spy User");
+
btnPane.add(jSpyBtn);
-
+
JButton jReloadBtn = new JButton("Reload");
+
btnPane.add(jReloadBtn);
-
add(btnPane, BorderLayout.SOUTH);
-
+
// event handlers
jCloseBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
closeConnection();
- }
+ }
});
-
jSpyBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
spyUser();
- }
+ }
});
-
jReloadBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
reload();
- }
+ }
});
}
-
-
+
/**
* Close this connection.
*/
public void closeConnection() {
- try {
- FtpConnectionTableModel tableModel = (FtpConnectionTableModel)mjConnectionTable.getModel();
- int indices[] = mjConnectionTable.getSelectedRows();
- if(indices.length == 0) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "Please select user(s).");
- return;
- }
-
- boolean response = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(), "Do you really want to close the selected connection(s)?");
- if(!response) {
- return;
- }
-
- for(int i=0; i<indices.length; i++) {
- FtpUser user = tableModel.getUser(indices[i]);
- if(user != null) {
- mUserHandler.closeConnection(user.getSessionId());
- }
- }
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
+
+ try {
+ FtpConnectionTableModel tableModel =
+ (FtpConnectionTableModel) mjConnectionTable.getModel();
+ int indices[] = mjConnectionTable.getSelectedRows();
+
+ if (indices.length == 0) {
+ GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(),
+ "Please select user(s).");
+
+ return;
+ }
+
+ boolean response = GuiUtils.getConfirmation(
+ mCommonHandler.getTopComponent(),
+ "Do you really want to close the selected connection(s)?");
+
+ if (!response) {
+ return;
+ }
+
+ for (int i = 0; i < indices.length; i++) {
+ FtpUser user = tableModel.getUser(indices[i]);
+
+ if (user != null) {
+ mUserHandler.closeConnection(user.getSessionId());
+ }
+ }
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
}
}
-
+
/**
* Monitor the selected user.
*/
public void spyUser() {
- FtpConnectionTableModel tableModel = (FtpConnectionTableModel)mjConnectionTable.getModel();
+ FtpConnectionTableModel tableModel =
+ (FtpConnectionTableModel) mjConnectionTable.getModel();
int indices[] = mjConnectionTable.getSelectedRows();
- if(indices.length == 0) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "Please select a connection.");
+
+ if (indices.length == 0) {
+ GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(),
+ "Please select a connection.");
+
return;
}
-
+
FtpUser thisUser = tableModel.getUser(indices[0]);
+
mSpyDlg.init(thisUser);
}
-
+
/**
- * Reload logn table
+ * Reload logn table
*/
public void reload() {
+
try {
- FtpConnectionTableModel model = (FtpConnectionTableModel)mjConnectionTable.getModel();
+ FtpConnectionTableModel model =
+ (FtpConnectionTableModel) mjConnectionTable.getModel();
+
model.reload();
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
-
+
/**
* Release resources
*/
public void close() {
- FtpConnectionTableModel model = (FtpConnectionTableModel)mjConnectionTable.getModel();
+
+ FtpConnectionTableModel model = (FtpConnectionTableModel) mjConnectionTable.getModel();
+
model.close();
mSpyDlg.close();
- }
+ }
}
1.3 +116 -97 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java
Index: FtpConnectionTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpConnectionTableModel.java 2001/11/10 21:34:04 1.2
+++ FtpConnectionTableModel.java 2001/12/14 01:22:03 1.3
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,18 +6,24 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
+
import java.net.InetAddress;
+
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
+
import java.text.SimpleDateFormat;
+
import javax.swing.table.AbstractTableModel;
-import org.apache.avalon.ftpserver.interfaces.UserHandlerInterface;
+
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.interfaces.FtpConnectionObserver;
import org.apache.avalon.ftpserver.FtpUser;
@@ -26,217 +33,229 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpConnectionTableModel extends AbstractTableModel
- implements FtpConnectionObserver {
-
+public class FtpConnectionTableModel extends AbstractTableModel implements FtpConnectionObserver {
+
private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
-
- private final static String[] COL_NAMES = {"Name",
- "Login Time",
- "Last Access Time",
- "Client"};
-
+ private final static String[] COL_NAMES = { "Name", "Login Time", "Last Access Time",
+ "Client" };
private List mConnectedUserList = new ArrayList();
- private UserHandlerInterface mUserHandler;
+ private UserHandler mUserHandler;
private CommonHandler mCommonHandler;
-
-
+
/**
* Constructor - initialize user list
*/
public FtpConnectionTableModel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- mUserHandler = mCommonHandler.getConfig().getUserHandlerInterface();
+ mUserHandler = mCommonHandler.getConfig().getUserHandler();
mConnectedUserList = mUserHandler.getAllConnectedUsers();
+
UnicastRemoteObject.exportObject(this);
mUserHandler.setObserver(this);
}
-
+
/**
* Get column class - always string
*/
public Class getColumnClass(int index) {
return String.class;
}
-
+
/**
* Get column count.
*/
public int getColumnCount() {
return COL_NAMES.length;
}
-
+
/**
* Get column name.
*/
public String getColumnName(int index) {
return COL_NAMES[index];
- }
-
+ }
+
/**
* Get row count.
*/
public synchronized int getRowCount() {
return mConnectedUserList.size();
}
-
+
/**
* Is cell editable - currently false.
*/
public boolean isCellEditable(int row, int col) {
return true;
}
-
- /**
- * Set value at - dummy method
- */
- public void setValueAt(Object val, int row, int col) {
- }
-
- /**
- * Get value at.
- */
+
+ /**
+ * Set value at - dummy method
+ */
+ public void setValueAt(Object val, int row, int col) {}
+
+ /**
+ * Get value at.
+ */
public synchronized Object getValueAt(int row, int col) {
-
+
// error check
String retVal = "";
- if(row >= mConnectedUserList.size()) {
+
+ if (row >= mConnectedUserList.size()) {
return retVal;
}
-
- FtpUser thisUser = (FtpUser)mConnectedUserList.get(row);
- switch(col) {
- case 0:
- if (thisUser.getName() != null) {
- retVal = thisUser.getName();
- }
- break;
-
- case 1:
- if (thisUser.getLoginTime() != 0) {
- retVal = DATE_FMT.format(new Date(thisUser.getLoginTime()));
- }
- break;
-
- case 2:
- if (thisUser.getLastAccessTime() != 0) {
- retVal = DATE_FMT.format(new Date(thisUser.getLastAccessTime()));
- }
- break;
-
- case 3:
- InetAddress remoteHost = thisUser.getRemoteHost();
- if(remoteHost != null) {
- retVal = remoteHost.getHostAddress();
- }
- break;
+
+ FtpUser thisUser = (FtpUser) mConnectedUserList.get(row);
+
+ switch (col) {
+
+ case 0 :
+ if (thisUser.getName() != null) {
+ retVal = thisUser.getName();
+ }
+ break;
+
+ case 1 :
+ if (thisUser.getLoginTime() != 0) {
+ retVal = DATE_FMT.format(new Date(thisUser.getLoginTime()));
+ }
+ break;
+
+ case 2 :
+ if (thisUser.getLastAccessTime() != 0) {
+ retVal = DATE_FMT.format(new Date(thisUser.getLastAccessTime()));
+ }
+ break;
+
+ case 3 :
+ InetAddress remoteHost = thisUser.getRemoteHost();
+
+ if (remoteHost != null) {
+ retVal = remoteHost.getHostAddress();
+ }
+ break;
}
+
return retVal;
}
-
+
/**
* Get user at an index.
*/
public synchronized FtpUser getUser(int index) {
- if( (index < 0) || (index >=mConnectedUserList.size()) ) {
+
+ if ((index < 0) || (index >= mConnectedUserList.size())) {
return null;
}
- return (FtpUser)mConnectedUserList.get(index);
+
+ return (FtpUser) mConnectedUserList.get(index);
}
-
-
+
/////////////////////////// Observer Methods ///////////////////////////
+
/**
* Add a new user
*/
public synchronized void newConnection(String sessId) throws RemoteException {
-
+
if (sessId == null) {
return;
}
+
FtpUser thisUser = mUserHandler.getConnectedUser(sessId);
+
if (thisUser == null) {
return;
}
-
+
mConnectedUserList.add(thisUser);
+
int sz = mConnectedUserList.size();
+
fireTableRowsInserted(sz, sz);
- }
-
-
+ }
+
/**
* Close .
*/
public synchronized void closeConnection(String sessionId) {
- if(sessionId == null) {
+
+ if (sessionId == null) {
return;
}
-
+
int index = -1;
- for(int i=0; i<mConnectedUserList.size(); i++) {
- FtpUser currUser = (FtpUser)mConnectedUserList.get(i);
+
+ for (int i = 0; i < mConnectedUserList.size(); i++) {
+ FtpUser currUser = (FtpUser) mConnectedUserList.get(i);
String currSessId = currUser.getSessionId();
- if(currSessId.equals(sessionId)) {
+
+ if (currSessId.equals(sessionId)) {
index = i;
+
break;
}
}
-
- if(index != -1) {
+
+ if (index != -1) {
mConnectedUserList.remove(index);
fireTableRowsDeleted(index, index);
}
-
}
-
+
/**
* Existing connected user update notification.
*/
public synchronized void updateConnection(String sessId) throws RemoteException {
+
if (sessId == null) {
return;
}
+
FtpUser thisUser = mUserHandler.getConnectedUser(sessId);
+
if (thisUser == null) {
return;
}
-
+
int index = -1;
- for(int i=0; i<mConnectedUserList.size(); i++) {
- FtpUser currUser = (FtpUser)mConnectedUserList.get(i);
- if(currUser.getSessionId().equals(sessId)) {
+
+ for (int i = 0; i < mConnectedUserList.size(); i++) {
+ FtpUser currUser = (FtpUser) mConnectedUserList.get(i);
+
+ if (currUser.getSessionId().equals(sessId)) {
index = i;
+
break;
}
}
- if(index != -1) {
- mConnectedUserList.set(index, thisUser);
+ if (index != -1) {
+ mConnectedUserList.set(index, thisUser);
fireTableRowsUpdated(index, index);
}
- }
-
-
+ }
+
/**
* Reload table model
*/
public synchronized void reload() throws RemoteException {
+
mConnectedUserList = mUserHandler.getAllConnectedUsers();
+
fireTableDataChanged();
- }
-
-
+ }
+
/**
* Close the resource
*/
public void close() {
+
try {
mUserHandler.setObserver(null);
mConnectedUserList.clear();
- }
- catch(Exception ex) {
- }
- }
-}
+ } catch (Exception ex) {}
+ }
+}
1.6 +63 -45 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpIpPanel.java
Index: FtpIpPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpIpPanel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpIpPanel.java 2001/11/10 21:34:04 1.5
+++ FtpIpPanel.java 2001/12/14 01:22:03 1.6
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,122 +6,139 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.util.Iterator;
import java.util.StringTokenizer;
+
import java.rmi.RemoteException;
+
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
import javax.swing.border.*;
-import org.apache.avalon.ftpserver.interfaces.IpRestrictorInterface;
+
+import org.apache.avalon.ftpserver.interfaces.RemoteIpRestrictor;
+
/**
* Ip restrictor panel.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpIpPanel extends JPanel {
-
+public class FtpIpPanel extends JPanel {
+
private JTextArea mjIpTxt;
- private IpRestrictorInterface mRestrictor; private CommonHandler mCommonHandler;
-
-
+ private RemoteIpRestrictor mRestrictor;
+ private CommonHandler mCommonHandler;
+
/**
* Instantiate IP restrictor panel
*/
public FtpIpPanel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- mRestrictor = mCommonHandler.getConfig().getIpRestrictorInterface();
+ mRestrictor = mCommonHandler.getConfig().getRemoteIpRestrictor();
+
initComponents();
refresh();
}
-
+
/**
* Initialize UI components
*/
private void initComponents() {
+
setLayout(new BorderLayout());
-
+
JLabel headerLab = new JLabel("IP Restriction");
+
headerLab.setHorizontalAlignment(JLabel.CENTER);
headerLab.setForeground(Color.black);
add(headerLab, BorderLayout.NORTH);
-
+
mjIpTxt = new JTextArea(18, 15);
- JScrollPane txtPane = new JScrollPane(mjIpTxt,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
+ JScrollPane txtPane = new JScrollPane(mjIpTxt, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
add(txtPane, BorderLayout.CENTER);
-
+
// buttons
JPanel btnPane = new JPanel();
+
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
JButton jSaveBtn = new JButton("Save");
+
btnPane.add(jSaveBtn);
-
+
JButton jRefreshBtn = new JButton("Refresh");
+
btnPane.add(jRefreshBtn);
-
add(btnPane, BorderLayout.SOUTH);
-
+
// event handlers
jSaveBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
save();
- }
+ }
});
-
jRefreshBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
refresh();
- }
+ }
});
}
-
+
/**
* Save IP data
*/
public void save() {
- if(mRestrictor != null) {
+
+ if (mRestrictor != null) {
try {
mRestrictor.clear();
+
StringTokenizer st = new StringTokenizer(mjIpTxt.getText(), "\r\n");
- while(st.hasMoreTokens()) {
+
+ while (st.hasMoreTokens()) {
mRestrictor.addEntry(st.nextToken());
}
+
mRestrictor.save();
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
}
-
+
/**
* Refresh table data
*/
private void refresh() {
- try {
- mjIpTxt.setText("");
- Iterator ipRestrictorIt = mRestrictor.getAllEntries().iterator();
- while(ipRestrictorIt.hasNext()) {
- mjIpTxt.append(ipRestrictorIt.next().toString());
- mjIpTxt.append("\n");
- }
- }
- catch(RemoteException ex) {
- mCommonHandler.handleException(ex);
+
+ try {
+ mjIpTxt.setText("");
+
+ Iterator ipRestrictorIt = mRestrictor.getAllEntries().iterator();
+
+ while (ipRestrictorIt.hasNext()) {
+ mjIpTxt.append(ipRestrictorIt.next().toString());
+ mjIpTxt.append("\n");
+ }
+ } catch (RemoteException ex) {
+ mCommonHandler.handleException(ex);
}
}
-
+
/**
* Close resource
*/
- public void close() {
- }
-}
+ public void close() {}
+}
1.6 +61 -43 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpRootPanel.java
Index: FtpRootPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpRootPanel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpRootPanel.java 2001/11/10 21:34:04 1.5
+++ FtpRootPanel.java 2001/12/14 01:22:03 1.6
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,15 +6,21 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.*;
+
import java.util.*;
+
import java.io.*;
+
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
+
import org.apache.avalon.ftpserver.interfaces.*;
@@ -23,126 +30,137 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpRootPanel extends JPanel {
+public class FtpRootPanel extends JPanel {
+
private JTextField mjHostTxt = null;
- private JTable mjCfgTbl = null;
-
- private FtpUserPanel mUserPane = null;
+ private JTable mjCfgTbl = null;
+ private FtpUserPanel mUserPane = null;
private FtpConnectionPanel mConnectionPane = null;
- private FtpIpPanel mIpPane = null;
- private FtpStatisticsPanel mStatPane = null;
- private FtpRootPanel mSelf = null;
- private CommonHandler mCommonHandler = null;
-
-
-
- /**
- * Creates new panel for root.
+ private FtpIpPanel mIpPane = null;
+ private FtpStatisticsPanel mStatPane = null;
+ private FtpRootPanel mSelf = null;
+ private CommonHandler mCommonHandler = null;
+
+ /**
+ * Creates new panel for root.
*/
public FtpRootPanel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- initComponents ();
+
+ initComponents();
}
-
- /**
+
+ /**
* This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() throws RemoteException {
-
+
setLayout(new BorderLayout());
-
+
// top panel
JPanel topPane = new JPanel();
+
topPane.setLayout(new GridBagLayout());
+
GridBagConstraints gc;
-
JLabel hostLab = new JLabel("Remote Host");
+
hostLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.insets = new Insets(0, 0, 0, 10);
+
topPane.add(hostLab, gc);
-
+
mjHostTxt = new JTextField();
+
mjHostTxt.setColumns(15);
mjHostTxt.setEditable(false);
mjHostTxt.setText(mCommonHandler.getConfig().getServerAddress().getHostAddress());
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 0;
gc.gridwidth = 1;
gc.insets = new Insets(0, 0, 0, 10);
+
topPane.add(mjHostTxt, gc);
-
+
JLabel headerLab = new JLabel("Configuration Parameters");
+
headerLab.setHorizontalAlignment(JLabel.CENTER);
headerLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 1;
gc.gridwidth = 2;
gc.insets = new Insets(30, 0, 0, 0);
+
topPane.add(headerLab, gc);
add(topPane, BorderLayout.NORTH);
-
-
+
// bottom panel - display config parameters
ConfigTableModel cfgModel = new ConfigTableModel(mCommonHandler);
+
mjCfgTbl = new JTable(cfgModel);
+
mjCfgTbl.setPreferredScrollableViewportSize(new Dimension(420, 200));
mjCfgTbl.setColumnSelectionAllowed(false);
- JScrollPane bottomPane = new JScrollPane(mjCfgTbl,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ JScrollPane bottomPane = new JScrollPane(mjCfgTbl,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
add(bottomPane, BorderLayout.CENTER);
-
-
+
// create other panels
mUserPane = new FtpUserPanel(mCommonHandler);
mConnectionPane = new FtpConnectionPanel(mCommonHandler);
- mIpPane = new FtpIpPanel(mCommonHandler);
- mStatPane = new FtpStatisticsPanel(mCommonHandler);
+ mIpPane = new FtpIpPanel(mCommonHandler);
+ mStatPane = new FtpStatisticsPanel(mCommonHandler);
}
-
+
/**
* Get user panel.
*/
public JPanel getUserPanel() {
- return mUserPane;
- }
-
+ return mUserPane;
+ }
+
/**
* Get login panel.
*/
public JPanel getConnectionPanel() {
return mConnectionPane;
}
-
+
/**
* Get IP panel.
*/
public JPanel getIpPanel() {
return mIpPane;
}
-
+
/**
* Get statistics panel
*/
public JPanel getStatisticsPanel() {
- return mStatPane;
- }
-
+ return mStatPane;
+ }
+
/**
* Close the resources.
*/
public void close() {
+
mStatPane.close();
mConnectionPane.close();
mUserPane.close();
mIpPane.close();
- }
-
+ }
}
1.7 +76 -60 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpSpyDialog.java
Index: FtpSpyDialog.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpSpyDialog.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FtpSpyDialog.java 2001/11/10 21:34:04 1.6
+++ FtpSpyDialog.java 2001/12/14 01:22:03 1.7
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,17 +6,22 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.awt.*;
+
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
+
import java.awt.event.*;
+
import javax.swing.*;
+
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.interfaces.SpyUserInterface;
-import org.apache.avalon.ftpserver.interfaces.UserHandlerInterface;
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.gui.GuiUtils;
@@ -24,154 +30,164 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpSpyDialog extends JDialog implements SpyUserInterface {
-
+public class FtpSpyDialog extends JDialog implements SpyUserInterface {
+
private static String EMPTY = " ";
-
- private FtpUser mUser = null;
- private JTextArea mLogTxt = null;
- private JLabel mUsrLab = null;
- private JButton mCloseBtn = null;
-
- private UserHandlerInterface mHandler = null;
- private CommonHandler mCommonHandler = null;
-
-
+ private FtpUser mUser = null;
+ private JTextArea mLogTxt = null;
+ private JLabel mUsrLab = null;
+ private JButton mCloseBtn = null;
+ private UserHandler mHandler = null;
+ private CommonHandler mCommonHandler = null;
+
/**
* Instantiate this dialog box
*/
public FtpSpyDialog(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- mHandler = mCommonHandler.getConfig().getUserHandlerInterface();
+ mHandler = mCommonHandler.getConfig().getUserHandler();
+
initComponents();
UnicastRemoteObject.exportObject(this);
}
-
+
/**
* Initialize the UI components
*/
private void initComponents() {
-
+
getContentPane().setLayout(new BorderLayout());
-
+
mUsrLab = new JLabel(EMPTY);
+
mUsrLab.setHorizontalAlignment(JLabel.CENTER);
mUsrLab.setForeground(Color.black);
getContentPane().add(mUsrLab, BorderLayout.NORTH);
-
+
mLogTxt = new JTextArea(15, 30);
+
mLogTxt.setEditable(false);
- JScrollPane txtPane = new JScrollPane(mLogTxt,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ JScrollPane txtPane = new JScrollPane(mLogTxt, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
getContentPane().add(txtPane, BorderLayout.CENTER);
-
+
JPanel btnPane = new JPanel();
+
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
mCloseBtn = new JButton("Close Connection");
+
btnPane.add(mCloseBtn);
-
getContentPane().add(btnPane, BorderLayout.SOUTH);
pack();
GuiUtils.setLocation(this);
setVisible(false);
-
+
// add event handler
mCloseBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
closeConnection();
- }
+ }
});
}
-
+
/**
* Spy the ftp connection.
* @param user the connected user to be monitored.
*/
public void init(FtpUser user) {
-
- try {
+
+ try {
mLogTxt.setText("");
mUsrLab.setText("");
mUsrLab.setText(EMPTY);
-
+
mUser = user;
- if(mUser != null) {
+
+ if (mUser != null) {
mHandler.setSpyObject(mUser.getSessionId(), this);
- if(mUser.getName() != null) {
+
+ if (mUser.getName() != null) {
mUsrLab.setText(mUser.getName());
}
}
+
mCloseBtn.setEnabled(true);
setVisible(true);
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
- }
-
+ }
+
/**
* Write message
*/
public void write(String msg) {
- if(mUser != null) {
+
+ if (mUser != null) {
mLogTxt.append(msg);
}
}
-
+
/*
* Handle window closing event.
- */
+ */
protected void processWindowEvent(WindowEvent e) {
+
int id = e.getID();
+
if (id == WindowEvent.WINDOW_CLOSING) {
close();
} else {
super.processWindowEvent(e);
- }
+ }
}
-
/**
* Close this connection.
*/
private void closeConnection() {
-
+
// null value check
- if(mUser == null) {
+ if (mUser == null) {
return;
}
-
- boolean bConf = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(), "Do you want to close the connection?");
- if(bConf) {
+
+ boolean bConf = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(),
+ "Do you want to close the connection?");
+
+ if (bConf) {
try {
mHandler.closeConnection(mUser.getSessionId());
+
mUser = null;
+
mCloseBtn.setEnabled(false);
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
- }
-
+ }
+
/**
* hide this dialog
*/
- public void close() {
- if(mUser != null) {
+ public void close() {
+
+ if (mUser != null) {
try {
mHandler.setSpyObject(mUser.getSessionId(), null);
+
mUser = null;
- }
- catch(Exception ex) {
- }
+ } catch (Exception ex) {}
}
+
mLogTxt.setText("");
mUsrLab.setText(EMPTY);
setVisible(false);
}
-
-}
+}
1.7 +202 -123 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java
Index: FtpStatisticsPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FtpStatisticsPanel.java 2001/11/21 07:58:38 1.6
+++ FtpStatisticsPanel.java 2001/12/14 01:22:03 1.7
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,472 +6,550 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
+
import java.text.SimpleDateFormat;
+
import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
import org.apache.avalon.ftpserver.interfaces.FtpStatisticsListener;
-import org.apache.avalon.ftpserver.interfaces.FtpStatisticsInterface;
+import org.apache.avalon.ftpserver.interfaces.FtpStatistics;
+import org.apache.avalon.ftpserver.interfaces.RemoteFtpStatistics;
+
+import javax.swing.*;
+
/**
* Ftp server global statistics panel. It listenes to the global
* statistics changes.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpStatisticsPanel extends JPanel
- implements FtpStatisticsListener {
+public class FtpStatisticsPanel extends JPanel implements FtpStatisticsListener {
private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("dd,MMM,yyyy HH:mm");
-
private JTextField mjStartTimeTxt;
-
private JTextField mjUploadNbrTxt;
private JTextField mjDownloadNbrTxt;
private JTextField mjDeleteNbrTxt;
-
private JTextField mjUploadBytesTxt;
private JTextField mjDownloadBytesTxt;
-
private JTextField mjLoginNbrTxt;
private JTextField mjAnonLoginNbrTxt;
private JTextField mjConNbrTxt;
-
private JTextField mjTotalLoginNbrTxt;
private JTextField mjTotalAnonLoginNbrTxt;
private JTextField mjTotalConNbrTxt;
-
private CommonHandler mCommonHandler;
- private FtpStatisticsInterface mStat;
-
-
- /**
- * Creates new panel to display ftp global statistics.
+ private RemoteFtpStatistics mStat;
+
+ /**
+ * Creates new panel to display ftp global statistics.
*/
public FtpStatisticsPanel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
+
UnicastRemoteObject.exportObject(this);
- mStat = mCommonHandler.getConfig().getStatisticsInterface();
+
+ mStat = mCommonHandler.getConfig().getStatistics();
+
mStat.setListener(this);
initComponents();
- try { mjStartTimeTxt.setText(DATE_FMT.format(mStat.getStartTime())); } catch(Exception ex) {}
+
+ try {
+ mjStartTimeTxt.setText(DATE_FMT.format(mStat.getStartTime()));
+ } catch (Exception ex) {}
+
reload();
}
- /**
+ /**
* This method is called from within the constructor to
* initialize the panel.
*/
private void initComponents() {
-
+
GridBagConstraints gc;
+
setLayout(new GridBagLayout());
-
+
// start time
JLabel jStartTimeLab = new JLabel("Start Time");
+
jStartTimeLab.setHorizontalAlignment(JLabel.RIGHT);
jStartTimeLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jStartTimeLab, gc);
-
+
mjStartTimeTxt = new JTextField();
+
mjStartTimeTxt.setColumns(15);
mjStartTimeTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 0;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjStartTimeTxt, gc);
-
+
// number of uploads
JLabel jUploadNbrLab = new JLabel("Number of uploads");
+
jUploadNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jUploadNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 1;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
- add(jUploadNbrLab, gc);
-
+
+ add(jUploadNbrLab, gc);
+
mjUploadNbrTxt = new JTextField();
+
mjUploadNbrTxt.setColumns(6);
mjUploadNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 1;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjUploadNbrTxt, gc);
-
+
// number of downloads
JLabel jDownloadNbrLab = new JLabel("Number of downloads");
+
jDownloadNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jDownloadNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 2;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jDownloadNbrLab, gc);
-
+
mjDownloadNbrTxt = new JTextField();
+
mjDownloadNbrTxt.setColumns(6);
mjDownloadNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 2;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjDownloadNbrTxt, gc);
-
+
// number of downloads
JLabel jDeleteNbrLab = new JLabel("Number of deletes");
+
jDeleteNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jDeleteNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 3;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jDeleteNbrLab, gc);
-
+
mjDeleteNbrTxt = new JTextField();
+
mjDeleteNbrTxt.setColumns(6);
mjDeleteNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 3;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- add(mjDeleteNbrTxt, gc);
-
+
+ add(mjDeleteNbrTxt, gc);
+
// number of uploaded bytes
JLabel jUploadBytesLab = new JLabel("Uploaded bytes");
+
jUploadBytesLab.setHorizontalAlignment(JLabel.RIGHT);
jUploadBytesLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 4;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jUploadBytesLab, gc);
-
+
mjUploadBytesTxt = new JTextField();
+
mjUploadBytesTxt.setColumns(15);
mjUploadBytesTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 4;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjUploadBytesTxt, gc);
-
+
// number of uploaded bytes
JLabel jDownloadBytesLab = new JLabel("Downloaded bytes");
+
jDownloadBytesLab.setHorizontalAlignment(JLabel.RIGHT);
jDownloadBytesLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 5;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jDownloadBytesLab, gc);
-
+
mjDownloadBytesTxt = new JTextField();
+
mjDownloadBytesTxt.setColumns(15);
- mjDownloadBytesTxt.setEditable(false);
+ mjDownloadBytesTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 5;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjDownloadBytesTxt, gc);
-
+
// number of current logins
JLabel jLoginNbrLab = new JLabel("Current logins");
+
jLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jLoginNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 6;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jLoginNbrLab, gc);
-
+
mjLoginNbrTxt = new JTextField();
+
mjLoginNbrTxt.setColumns(6);
mjLoginNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 6;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjLoginNbrTxt, gc);
-
+
// number of total logins
JLabel jTotalLoginNbrLab = new JLabel("Total logins");
+
jTotalLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jTotalLoginNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 7;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jTotalLoginNbrLab, gc);
-
+
mjTotalLoginNbrTxt = new JTextField();
+
mjTotalLoginNbrTxt.setColumns(6);
mjTotalLoginNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 7;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjTotalLoginNbrTxt, gc);
-
+
// number of current anonymous logins
JLabel jAnonLoginNbrLab = new JLabel("Current anonymous logins");
+
jAnonLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jAnonLoginNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 8;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jAnonLoginNbrLab, gc);
-
+
mjAnonLoginNbrTxt = new JTextField();
+
mjAnonLoginNbrTxt.setColumns(6);
mjAnonLoginNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 8;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- add(mjAnonLoginNbrTxt, gc);
-
+
+ add(mjAnonLoginNbrTxt, gc);
+
// number of total anonymous logins
JLabel jTotalAnonLoginNbrLab = new JLabel("Total anonymous logins");
+
jTotalAnonLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jTotalAnonLoginNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 9;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jTotalAnonLoginNbrLab, gc);
-
+
mjTotalAnonLoginNbrTxt = new JTextField();
+
mjTotalAnonLoginNbrTxt.setColumns(6);
mjTotalAnonLoginNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 9;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjTotalAnonLoginNbrTxt, gc);
-
+
// number of current connections
JLabel jConNbrLab = new JLabel("Current connections");
+
jConNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jConNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 10;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jConNbrLab, gc);
-
+
mjConNbrTxt = new JTextField();
+
mjConNbrTxt.setColumns(6);
mjConNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 10;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- add(mjConNbrTxt, gc);
-
+
+ add(mjConNbrTxt, gc);
+
// number of current connections
JLabel jTotalConNbrLab = new JLabel("Total connections");
+
jTotalConNbrLab.setHorizontalAlignment(JLabel.RIGHT);
jTotalConNbrLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 11;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(jTotalConNbrLab, gc);
-
+
mjTotalConNbrTxt = new JTextField();
+
mjTotalConNbrTxt.setColumns(6);
mjTotalConNbrTxt.setEditable(false);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 11;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
+
add(mjTotalConNbrTxt, gc);
-
+
// reload button
JButton reloadBtn = new JButton("Reload");
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 12;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(15, 0, 0, 5);
+
add(reloadBtn, gc);
-
reloadBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
reload();
- }
+ }
});
}
-
-
+
/**
* Upload notification.
*/
public void notifyUpload() {
- if(mStat != null) {
- try {
- mjUploadNbrTxt.setText(String.valueOf(mStat.getFileUploadNbr()));
- mjUploadBytesTxt.setText(String.valueOf(mStat.getFileUploadSize()));
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
- }
- }
+
+ if (mStat != null) {
+ try {
+ mjUploadNbrTxt.setText(String.valueOf(mStat.getFileUploadNbr()));
+ mjUploadBytesTxt.setText(String.valueOf(mStat.getFileUploadSize()));
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
+ }
+ }
}
-
+
/**
* Download notification.
*/
public void notifyDownload() {
- if(mStat != null) {
- try {
- mjDownloadNbrTxt.setText(String.valueOf(mStat.getFileDownloadNbr()));
- mjDownloadBytesTxt.setText(String.valueOf(mStat.getFileDownloadSize()));
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
- }
- }
+
+ if (mStat != null) {
+ try {
+ mjDownloadNbrTxt.setText(String.valueOf(mStat.getFileDownloadNbr()));
+ mjDownloadBytesTxt.setText(String.valueOf(mStat.getFileDownloadSize()));
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
+ }
+ }
}
-
-
+
/**
* Delete notification.
*/
public void notifyDelete() {
- if(mStat != null) {
- try {
- mjDeleteNbrTxt.setText(String.valueOf(mStat.getFileDeleteNbr()));
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
- }
- }
+
+ if (mStat != null) {
+ try {
+ mjDeleteNbrTxt.setText(String.valueOf(mStat.getFileDeleteNbr()));
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
+ }
+ }
}
-
+
/**
* User login notification.
*/
public void notifyLogin() {
- if(mStat != null) {
- try {
- mjLoginNbrTxt.setText(String.valueOf(mStat.getLoginNbr()));
- mjAnonLoginNbrTxt.setText(String.valueOf(mStat.getAnonLoginNbr()));
- mjTotalLoginNbrTxt.setText(String.valueOf(mStat.getTotalLoginNbr()));
- mjTotalAnonLoginNbrTxt.setText(String.valueOf(mStat.getTotalAnonLoginNbr()));
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
- }
- }
+
+ if (mStat != null) {
+ try {
+ mjLoginNbrTxt.setText(String.valueOf(mStat.getLoginNbr()));
+ mjAnonLoginNbrTxt.setText(String.valueOf(mStat.getAnonLoginNbr()));
+ mjTotalLoginNbrTxt.setText(String.valueOf(mStat.getTotalLoginNbr()));
+ mjTotalAnonLoginNbrTxt.setText(String.valueOf(mStat.getTotalAnonLoginNbr()));
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
+ }
+ }
}
-
+
/**
* User logout notification.
*/
public void notifyLogout() {
notifyLogin();
- }
-
+ }
+
/**
* Notify open/close connection
- */
+ */
public void notifyConnection() {
- if(mStat != null) {
- try {
- mjConNbrTxt.setText(String.valueOf(mStat.getConnectionNbr()));
- mjTotalConNbrTxt.setText(String.valueOf(mStat.getTotalConnectionNbr()));
- }
- catch(Exception ex) {
- mCommonHandler.handleException(ex);
- }
- }
- }
-
+
+ if (mStat != null) {
+ try {
+ mjConNbrTxt.setText(String.valueOf(mStat.getConnectionNbr()));
+ mjTotalConNbrTxt.setText(String.valueOf(mStat.getTotalConnectionNbr()));
+ } catch (Exception ex) {
+ mCommonHandler.handleException(ex);
+ }
+ }
+ }
+
/**
* Load all the global statistics parameters
*/
public void reload() {
+
notifyUpload();
notifyDownload();
notifyDelete();
notifyLogin();
notifyConnection();
}
-
-
+
/**
* Close it.
*/
public void close() {
- try {
- mStat.setListener(null);
- }
- catch(RemoteException ex) {
- }
- }
-
+
+ try {
+ mStat.setListener(null);
+ } catch (RemoteException ex) {}
+ }
}
1.6 +28 -28 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpTreeModel.java
Index: FtpTreeModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpTreeModel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpTreeModel.java 2001/12/13 13:26:04 1.5
+++ FtpTreeModel.java 2001/12/14 01:22:03 1.6
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,17 +6,20 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
import java.util.Vector;
+
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeModel;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
+
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
+
/**
* This is FTP user interface tree structure. Currently it is very simple.
* It looks like:
@@ -33,19 +37,11 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpTreeModel implements TreeModel {
-
+public class FtpTreeModel implements TreeModel {
+
private Vector mListenrList;
-
- public final static String[] CHILDREN = {
- "Users",
- "Connection",
- "IP",
- "Statistics"
- };
-
-
+ public final static String[] CHILDREN = { "Users", "Connection", "IP", "Statistics" };
+
/**
* create this tree model
*/
@@ -53,7 +49,6 @@
mListenrList = new Vector();
}
-
/**
* get root object
*/
@@ -61,20 +56,22 @@
return FtpAdmin.DISPLAY_NAME;
}
- /**
+ /**
* get child object
*/
public Object getChild(Object parent, int index) {
return CHILDREN[index];
- }
+ }
/**
* get child count
*/
public int getChildCount(Object parent) {
- if(parent.equals(FtpAdmin.DISPLAY_NAME)) {
+
+ if (parent.equals(FtpAdmin.DISPLAY_NAME)) {
return CHILDREN.length;
}
+
return 0;
}
@@ -82,28 +79,31 @@
* is a leaf or node
*/
public boolean isLeaf(Object node) {
- return !node.equals(FtpAdmin.DISPLAY_NAME);
+ return !node.equals(FtpAdmin.DISPLAY_NAME);
}
/**
* get child index
*/
public int getIndexOfChild(Object parent, Object child) {
- int childIdx = -1;
- for(int i=0; i<CHILDREN.length; i++) {
- if(CHILDREN[i].equals(child)) {
- childIdx = i;
- break;
- }
- }
- return childIdx;
+
+ int childIdx = -1;
+
+ for (int i = 0; i < CHILDREN.length; i++) {
+ if (CHILDREN[i].equals(child)) {
+ childIdx = i;
+
+ break;
+ }
+ }
+
+ return childIdx;
}
/**
* Object changed. In our case it is not possible - so ignore it.
*/
- public void valueForPathChanged(TreePath path, Object newValue) {
- }
+ public void valueForPathChanged(TreePath path, Object newValue) {}
/**
* Add a listener
1.9 +228 -146 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java
Index: FtpUserPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FtpUserPanel.java 2001/11/21 07:58:38 1.8
+++ FtpUserPanel.java 2001/12/14 01:22:03 1.9
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,60 +6,49 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.util.*;
+
import java.io.*;
+
import java.awt.*;
import java.awt.event.*;
+
import java.rmi.*;
import java.rmi.registry.*;
+
import javax.swing.*;
import javax.swing.event.*;
-import org.apache.avalon.ftpserver.interfaces.UserHandlerInterface;
+
+import org.apache.avalon.ftpserver.interfaces.UserHandler;
import org.apache.avalon.ftpserver.FtpUser;
+
/**
* Ftp server user admin panel. You can create, update,
* delete user using this panel.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpUserPanel extends JPanel
- implements ActionListener {
-
+public class FtpUserPanel extends JPanel implements ActionListener {
+
private final static Object[] BYTE_RATES = {
- "No limit",
- new Integer(1200),
- new Integer(2400),
- new Integer(4800),
- new Integer(9600),
- new Integer(14400),
- new Integer(28800),
- new Integer(57600),
- new Integer(115200)
- };
-
+ "No limit", new Integer(1200), new Integer(2400), new Integer(4800), new Integer(9600),
+ new Integer(14400), new Integer(28800), new Integer(57600), new Integer(115200)
+ };
private final static Object[] IDLE_MINUTES = {
- "No limit",
- new Integer(1),
- new Integer(5),
- new Integer(15),
- new Integer(30),
- new Integer(60)
+ "No limit", new Integer(1), new Integer(5), new Integer(15), new Integer(30),
+ new Integer(60)
};
-
- private UserHandlerInterface mUserHandler;
-
+ private UserHandler mUserHandler;
private JComboBox mjUserLst;
private JTextField mjNameTxt;
-
private JPasswordField mjPasswordTxt;
private JPasswordField mjRetypePasswordTxt;
private JCheckBox mjPasswordChkBox;
-
private JTextField mjDirectoryTxt;
private JCheckBox mjEnabledChkBox;
private JCheckBox mjWriteChkBox;
@@ -67,158 +57,196 @@
private JComboBox mjDownloadLst;
private JButton mjDeleteBtn;
private JButton mjSaveBtn;
-
private CommonHandler mCommonHandler;
-
- /**
- * Creates new panel.
+
+ /**
+ * Creates new panel.
*/
public FtpUserPanel(CommonHandler commonHandler) throws RemoteException {
+
mCommonHandler = commonHandler;
- mUserHandler = mCommonHandler.getConfig().getUserHandlerInterface();
- initComponents ();
- refresh();
+ mUserHandler = mCommonHandler.getConfig().getUserHandler();
+
+ initComponents();
+ refresh();
}
- /**
+ /**
* This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() {
-
+
GridBagConstraints gc;
+
setLayout(new GridBagLayout());
-
+
// user list
mjUserLst = new JComboBox();
+
mjUserLst.addActionListener(this);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.gridwidth = 3;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjUserLst, gc);
-
+
// user name
JLabel jNameLab = new JLabel("Name");
+
jNameLab.setHorizontalAlignment(JLabel.RIGHT);
jNameLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 1;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jNameLab, gc);
-
+
mjNameTxt = new JTextField();
+
mjNameTxt.setColumns(12);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 1;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjNameTxt, gc);
-
+
// password
JLabel jPasswordLab = new JLabel("Password");
+
jPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jPasswordLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 2;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
- add(jPasswordLab, gc);
-
+
+ add(jPasswordLab, gc);
+
mjPasswordTxt = new JPasswordField();
+
mjPasswordTxt.setColumns(12);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 2;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjPasswordTxt, gc);
-
+
// retype password
JLabel jRetypePasswordLab = new JLabel("Retype Password");
+
jRetypePasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jRetypePasswordLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 3;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jRetypePasswordLab, gc);
-
+
mjRetypePasswordTxt = new JPasswordField();
+
mjRetypePasswordTxt.setColumns(12);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 3;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjRetypePasswordTxt, gc);
-
+
// set password
JLabel jSetPasswordLab = new JLabel("Set Password");
+
jSetPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jSetPasswordLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 4;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jSetPasswordLab, gc);
-
+
mjPasswordChkBox = new JCheckBox();
+
mjPasswordChkBox.setHorizontalTextPosition(SwingConstants.LEFT);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 4;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjPasswordChkBox, gc);
// root directory
JLabel jDirectoryLab = new JLabel("Root Directory");
+
jDirectoryLab.setHorizontalAlignment(JLabel.RIGHT);
jDirectoryLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 5;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jDirectoryLab, gc);
-
+
mjDirectoryTxt = new JTextField();
- mjDirectoryTxt.setColumns(18);
+
+ mjDirectoryTxt.setColumns(18);
+
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 5;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
- add(mjDirectoryTxt, gc);
-
+
+ add(mjDirectoryTxt, gc);
+
// enable/disable
JLabel jEnabledLab = new JLabel("Enabled");
+
jEnabledLab.setHorizontalAlignment(JLabel.RIGHT);
jEnabledLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 6;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jEnabledLab, gc);
mjEnabledChkBox = new JCheckBox();
@@ -228,20 +256,24 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjEnabledChkBox, gc);
-
+
// write permission
JLabel jWritePermLab = new JLabel("Write Permission");
+
jWritePermLab.setHorizontalAlignment(JLabel.RIGHT);
jWritePermLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 7;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jWritePermLab, gc);
-
+
mjWriteChkBox = new JCheckBox();
gc = new GridBagConstraints();
gc.gridx = 1;
@@ -249,20 +281,24 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjWriteChkBox, gc);
-
+
// idle time
JLabel jIdleLab = new JLabel("Max. Idle Time (minutes)");
+
jIdleLab.setHorizontalAlignment(JLabel.RIGHT);
jIdleLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 8;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jIdleLab, gc);
-
+
mjIdleLst = new JComboBox(IDLE_MINUTES);
gc = new GridBagConstraints();
gc.gridx = 1;
@@ -270,23 +306,28 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjIdleLst, gc);
-
+
JPanel btnPane = new JPanel();
+
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
// user upload limit
JLabel jUploadLab = new JLabel("Max. Upload (bytes/sec)");
+
jUploadLab.setHorizontalAlignment(JLabel.RIGHT);
jUploadLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 9;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jUploadLab, gc);
-
+
mjUploadLst = new JComboBox(BYTE_RATES);
gc = new GridBagConstraints();
gc.gridx = 1;
@@ -294,20 +335,24 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjUploadLst, gc);
-
+
// user download limit
JLabel jDownloadLab = new JLabel("Max. Download (bytes/sec)");
+
jDownloadLab.setHorizontalAlignment(JLabel.RIGHT);
jDownloadLab.setForeground(Color.black);
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 10;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(jDownloadLab, gc);
-
+
mjDownloadLst = new JComboBox(BYTE_RATES);
gc = new GridBagConstraints();
gc.gridx = 1;
@@ -315,130 +360,148 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
+
add(mjDownloadLst, gc);
-
+
// save user
mjSaveBtn = new JButton("Save");
+
mjSaveBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
save(evt);
- }
+ }
});
btnPane.add(mjSaveBtn);
-
+
// delete user
mjDeleteBtn = new JButton("Delete");
+
mjDeleteBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
+
+ public void actionPerformed(ActionEvent evt) {
delete(evt);
- }
+ }
});
btnPane.add(mjDeleteBtn);
-
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 11;
gc.gridwidth = 3;
gc.insets = new Insets(5, 0, 0, 10);
+
add(btnPane, gc);
}
-
-
+
/**
* Save the user object
*/
private void save(ActionEvent evt) {
-
+
// check user name field
String userName = mjNameTxt.getText().trim();
- if(userName.equals("")) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "Please enter an user name");
+
+ if (userName.equals("")) {
+ GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(),
+ "Please enter an user name");
+
return;
}
-
+
try {
FtpUser user = new FtpUser(null, null, null);
+
user.setName(userName);
- if(setPassword(user)) {
- user.getVirtualDirectory().setRootDirectory(new File(mjDirectoryTxt.getText()).getCanonicalFile());
- user.setEnabled(mjEnabledChkBox.isSelected());
- user.getVirtualDirectory().setWritePermission(mjWriteChkBox.isSelected());
- user.setMaxIdleTime(getMaxIdleTime());
- user.setMaxUploadRate(getBytesTransferRate(mjUploadLst));
- user.setMaxDownloadRate(getBytesTransferRate(mjDownloadLst));
- mUserHandler.save(user);
- refresh();
+
+ if (setPassword(user)) {
+ user.getVirtualDirectory()
+ .setRootDirectory(new File(mjDirectoryTxt.getText()).getCanonicalFile());
+ user.setEnabled(mjEnabledChkBox.isSelected());
+ user.getVirtualDirectory().setWritePermission(mjWriteChkBox.isSelected());
+ user.setMaxIdleTime(getMaxIdleTime());
+ user.setMaxUploadRate(getBytesTransferRate(mjUploadLst));
+ user.setMaxDownloadRate(getBytesTransferRate(mjDownloadLst));
+ mUserHandler.save(user);
+ refresh();
}
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
-
-
+
/**
* Save the user object
*/
private void delete(ActionEvent evt) {
+
Object selVal = mjUserLst.getSelectedItem();
- if(selVal == null) {
+
+ if (selVal == null) {
return;
}
-
+
String userName = selVal.toString();
- boolean bConf = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(), "Do you really want to delete user " + userName + "?");
- if(!bConf) {
+ boolean bConf = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(),
+ "Do you really want to delete user " + userName
+ + "?");
+
+ if (!bConf) {
return;
}
+
try {
mUserHandler.delete(userName);
refresh();
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
-
+
/**
* Initialize user list.
*/
private void refresh() {
+
try {
mjUserLst.removeAllItems();
+
java.util.List allUsers = mUserHandler.getAllUserNames();
+
Collections.sort(allUsers);
- for(Iterator userIt = allUsers.iterator(); userIt.hasNext(); ) {
+
+ for (Iterator userIt = allUsers.iterator(); userIt.hasNext(); ) {
mjUserLst.addItem(userIt.next());
}
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
}
-
-
/**
- * List selection changed.
+ * List selection changed.
*/
public void actionPerformed(ActionEvent e) {
+
Object selVal = mjUserLst.getSelectedItem();
+
try {
- if(selVal != null) {
+ if (selVal != null) {
String userName = selVal.toString();
FtpUser thisUser = mUserHandler.getUserByName(userName);
+
populateFields(thisUser);
}
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
- }
-
+ }
+
/**
* Populate user data fields.
*/
public void populateFields(FtpUser user) {
+
mjNameTxt.setText(user.getName());
mjPasswordTxt.setText("");
mjRetypePasswordTxt.setText("");
@@ -449,120 +512,139 @@
setIdleTimeCombo(user.getMaxIdleTime());
setByteRateCombo(mjUploadLst, user.getMaxUploadRate());
setByteRateCombo(mjDownloadLst, user.getMaxDownloadRate());
-
+
// admin and anonymous users cannot be deleted
- if(user.getIsAnonymous() || user.getIsAdmin()) {
+ if (user.getIsAnonymous() || user.getIsAdmin()) {
mjDeleteBtn.setEnabled(false);
+ } else {
+ mjDeleteBtn.setEnabled(true);
}
- else {
- mjDeleteBtn.setEnabled(true);
- }
}
-
+
/**
* Set password if necessary.
*/
private boolean setPassword(FtpUser usr) {
-
+
try {
String userName = usr.getName();
boolean bNewUser = !mUserHandler.doesExist(userName);
boolean bPassSet = mjPasswordChkBox.isSelected();
String password = new String(mjPasswordTxt.getPassword());
- String repassword = new String(mjRetypePasswordTxt.getPassword());
+ String repassword = new String(mjRetypePasswordTxt.getPassword());
+
usr.setPassword(null);
-
+
// anonymous user - password not required
if (usr.getIsAnonymous()) {
- return true;
+ return true;
}
-
+
// new user - no password - error
- if (bNewUser && (!bPassSet) ) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "New user - password required");
+ if (bNewUser && (!bPassSet)) {
+ GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(),
+ "New user - password required");
+
return false;
}
-
+
// password set - two passwords are not same - error
- if(bPassSet && (!password.equals(repassword))) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "Password entries are not equal");
+ if (bPassSet && (!password.equals(repassword))) {
+ GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(),
+ "Password entries are not equal");
+
return false;
}
-
+
// password set
if (bPassSet) {
- usr.setPassword(password);
+ usr.setPassword(password);
}
-
+
return true;
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
mCommonHandler.handleException(ex);
}
+
return false;
- }
-
+ }
+
/**
* Get max bytes/sec.
*/
private int getBytesTransferRate(JComboBox byteLst) {
+
int rate = 0;
int byteInd = byteLst.getSelectedIndex();
- if(byteInd != 0) {
- rate = ((Integer)BYTE_RATES[byteInd]).intValue();
+
+ if (byteInd != 0) {
+ rate = ((Integer) BYTE_RATES[byteInd]).intValue();
}
+
return rate;
}
-
+
/**
* Get max idle time in sec.
*/
private int getMaxIdleTime() {
+
int sec = 0;
int idleInd = mjIdleLst.getSelectedIndex();
- if(idleInd != 0) {
- sec = ((Integer)IDLE_MINUTES[idleInd]).intValue() * 60;
+
+ if (idleInd != 0) {
+ sec = ((Integer) IDLE_MINUTES[idleInd]).intValue() * 60;
}
+
return sec;
}
-
+
/**
* Set byte transfer rate combo.
*/
private void setByteRateCombo(JComboBox combo, int rate) {
+
int index = 0;
- if(rate != 0) {
+
+ if (rate != 0) {
Integer currRate = new Integer(rate);
- for(int i=1; i<BYTE_RATES.length; i++) {
- if(BYTE_RATES[i].equals(currRate)) {
+
+ for (int i = 1; i < BYTE_RATES.length; i++) {
+ if (BYTE_RATES[i].equals(currRate)) {
index = i;
+
break;
}
}
}
+
combo.setSelectedIndex(index);
}
-
+
/**
* Set idle time combo.
*/
private void setIdleTimeCombo(int idle) {
+
int index = 0;
- if(idle != 0) {
- Integer currIdle = new Integer(idle/60);
- for(int i=0; i<IDLE_MINUTES.length; i++) {
- if(IDLE_MINUTES[i].equals(currIdle)) {
+
+ if (idle != 0) {
+ Integer currIdle = new Integer(idle / 60);
+
+ for (int i = 0; i < IDLE_MINUTES.length; i++) {
+ if (IDLE_MINUTES[i].equals(currIdle)) {
index = i;
+
break;
}
}
}
+
mjIdleLst.setSelectedIndex(index);
- }
-
+ }
+
/**
* Close all resources.
*/
- public void close() {
- }
+ public void close() {}
}
1.5 +51 -44 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/GuiUtils.java
Index: GuiUtils.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/GuiUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GuiUtils.java 2001/11/21 07:58:38 1.4
+++ GuiUtils.java 2001/12/14 01:22:03 1.5
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,79 +6,83 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.gui;
+
+
import java.util.*;
+
import java.io.*;
+
import java.net.*;
+
import java.awt.*;
+
import javax.swing.*;
+
/**
* This is the GUI utility class.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class GuiUtils {
+public class GuiUtils {
- private static JFileChooser mDirChoose = null;
- private static JFileChooser mFileChoose = null;
-
- private static final GuiUtils SELF_REF = new GuiUtils();
+ private static JFileChooser mDirChoose = null;
+ private static JFileChooser mFileChoose = null;
+ private static final GuiUtils SELF_REF = new GuiUtils();
/**
* Create image icon.
*/
public static ImageIcon createImageIcon(String imgFile) {
+
URL imgUrl = SELF_REF.getClass().getClassLoader().getResource(imgFile);
+
if (imgUrl == null) {
return null;
}
+
return new ImageIcon(imgUrl);
}
-
/**
* Create splash window. Returns null if image not found.
*/
public static JWindow createSplashWindow(String imgFile) {
ImageIcon icon = createImageIcon(imgFile);
+
if (icon == null) {
return null;
}
JLabel lab = new JLabel();
+
lab.setIcon(icon);
Dimension iDim = new Dimension(icon.getIconWidth(), icon.getIconHeight());
-
JWindow splashWin = new JWindow();
+
splashWin.getContentPane().add(lab);
splashWin.setSize(iDim);
setLocation(splashWin);
+
return splashWin;
}
-
-
/**
* Display error message.
*/
public static void showErrorMessage(Component parent, String str) {
- JOptionPane.showMessageDialog(parent, str, "Error!",
- JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(parent, str, "Error!", JOptionPane.ERROR_MESSAGE);
}
-
/**
* Display warning message.
*/
public static void showWarningMessage(Component parent, String str) {
- JOptionPane.showMessageDialog(parent, str, "Warning!",
- JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(parent, str, "Warning!", JOptionPane.WARNING_MESSAGE);
}
/**
@@ -85,25 +90,20 @@
*/
public static void showInformationMessage(Component parent, String str) {
JOptionPane.showMessageDialog(parent, str, "Information!",
- JOptionPane.INFORMATION_MESSAGE );
+ JOptionPane.INFORMATION_MESSAGE);
}
-
-
/**
* Get confirmation.
*/
public static boolean getConfirmation(Component parent, String str) {
- int res = JOptionPane.showConfirmDialog(parent,
- str,
- "Confirmation",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE
- );
- return(res == JOptionPane.YES_OPTION);
- }
+ int res = JOptionPane.showConfirmDialog(parent, str, "Confirmation",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE);
+ return (res == JOptionPane.YES_OPTION);
+ }
/**
* Get file name.
@@ -112,6 +112,7 @@
if (mFileChoose == null) {
mFileChoose = new JFileChooser();
+
mFileChoose.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
@@ -126,11 +127,12 @@
/**
* Get directory name.
- */
+ */
public static String getDirName(Component parent) {
if (mDirChoose == null) {
mDirChoose = new JFileChooser();
+
mDirChoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
@@ -151,6 +153,7 @@
if (mDirChoose != null) {
SwingUtilities.updateComponentTreeUI(mDirChoose);
}
+
if (mFileChoose != null) {
SwingUtilities.updateComponentTreeUI(mFileChoose);
}
@@ -160,30 +163,34 @@
* Position properly - center.
*/
public static void setLocation(Component comp) {
+
Dimension cDim = comp.getSize();
Dimension wDim = Toolkit.getDefaultToolkit().getScreenSize();
- comp.setLocation((wDim.width - cDim.width)/2, (wDim.height - cDim.height)/2);
+
+ comp.setLocation((wDim.width - cDim.width) / 2, (wDim.height - cDim.height) / 2);
+ }
+
+ /**
+ * Position with respect to the parent component.
+ */
+ public static void setLocation(Component comp, Component parent) {
+
+ Dimension cDim = comp.getSize();
+ Rectangle pRect = parent.getBounds();
+ int x = pRect.x + (pRect.width - cDim.width) / 2;
+ int y = pRect.y + (pRect.height - cDim.height) / 2;
+
+ comp.setLocation(x, y);
}
-
- /**
- * Position with respect to the parent component.
- */
- public static void setLocation(Component comp, Component parent) {
- Dimension cDim = comp.getSize();
- Rectangle pRect = parent.getBounds();
- int x = pRect.x + (pRect.width - cDim.width)/2;
- int y = pRect.y + (pRect.height - cDim.height)/2;
- comp.setLocation(x, y);
- }
-
+
/**
* Display a new panel. First removes all children, then add.
*/
- public static void showNewPanel(JPanel parent, JPanel child) {
+ public static void showNewPanel(JPanel parent, JPanel child) {
+
parent.removeAll();
parent.add(child);
parent.validate();
parent.repaint();
}
-
}
1.2 +9 -8 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpAdmin.java
Index: FtpAdmin.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpAdmin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpAdmin.java 2001/12/13 13:26:05 1.1
+++ FtpAdmin.java 2001/12/14 01:22:04 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,39 +6,39 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.interfaces;
+
+
import org.apache.avalon.ftpserver.FtpException;
/**
* Ftp server interface. Only the implementation of this
* interface will be bound. After binding we have to call
- * <code>adminLogin(user, password)</code>.
+ * <code>adminLogin(user, password)</code>.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-interface FtpAdmin {
+public interface FtpAdmin {
/**
* Ftp server name
*/
String DISPLAY_NAME = "Ftp";
-
+
/**
* Remote admin login
*/
String adminLogin(String id, String password) throws FtpException;
-
+
/**
* Remote admin logout
*/
void adminLogout(String sessId) throws FtpException;
-
+
/**
* Get configuration interface
*/
- FtpConfigInterface getConfigInterface(String sessId) throws FtpException;
+ FtpConfig getConfig(String sessId) throws FtpException;
}
1.4 +8 -7 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpConnectionObserver.java
Index: FtpConnectionObserver.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpConnectionObserver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FtpConnectionObserver.java 2001/11/21 07:58:38 1.3
+++ FtpConnectionObserver.java 2001/12/14 01:22:04 1.4
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,9 +6,10 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.interfaces;
+
+
import java.rmi.Remote;
import java.rmi.RemoteException;
@@ -17,24 +19,23 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-interface FtpConnectionObserver extends Remote {
-
+public interface FtpConnectionObserver extends Remote {
+
/**
* New connection notification.
* @param sessId new connection session id.
*/
void newConnection(String sessId) throws RemoteException;
-
+
/**
* Close connection notification
* @param sessId closed connection session id.
*/
void closeConnection(String sessId) throws RemoteException;
-
+
/**
* Update connection notification
* @param sessId updated connection session id.
*/
void updateConnection(String sessId) throws RemoteException;
-}
+}
1.5 +12 -12 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpStatisticsListener.java
Index: FtpStatisticsListener.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpStatisticsListener.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FtpStatisticsListener.java 2001/10/11 06:18:09 1.4
+++ FtpStatisticsListener.java 2001/12/14 01:22:04 1.5
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,9 +6,10 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.interfaces;
+
+
import java.rmi.Remote;
import java.rmi.RemoteException;
@@ -17,37 +19,35 @@
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-interface FtpStatisticsListener extends Remote {
-
+public interface FtpStatisticsListener extends Remote {
+
/**
* User file upload notification.
*/
void notifyUpload() throws RemoteException;
-
+
/**
* User file download notification.
*/
void notifyDownload() throws RemoteException;
-
+
/**
* User file delete notification.
*/
void notifyDelete() throws RemoteException;
-
+
/**
* New user login notification.
*/
void notifyLogin() throws RemoteException;
-
+
/**
* User logout notification.
*/
void notifyLogout() throws RemoteException;
-
+
/**
* Connection open/close notification
*/
- void notifyConnection() throws RemoteException;
-
-}
+ void notifyConnection() throws RemoteException;
+}
1.4 +7 -5 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/SpyUserInterface.java
Index: SpyUserInterface.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/SpyUserInterface.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SpyUserInterface.java 2001/09/12 14:42:13 1.3
+++ SpyUserInterface.java 2001/12/14 01:22:04 1.4
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,21 +6,22 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.interfaces;
+
+
import java.io.IOException;
+
import java.rmi.Remote;
/**
* This interface is used to monitor user activities;
*/
-public
-interface SpyUserInterface extends Remote {
-
+public interface SpyUserInterface extends Remote {
+
/**
* Write user spy message.
*/
void write(String msg) throws IOException;
-}
+}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpConfig.java
Index: FtpConfig.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.net.InetAddress;
/**
* Remote ftp configuration interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface FtpConfig {
/**
* Get server port.
*/
int getServerPort();
/**
* Check annonymous login support.
*/
boolean isAnonymousLoginSupported();
/**
* Get maximum number of connections.
*/
int getMaxConnections();
/**
* Get maximum number of anonymous connections.
*/
int getMaxAnonymousConnections();
/**
* Get default maximum idle time
*/
int getMaxIdleTime();
/**
* Get scheduler interval
*/
int getSchedulerInterval();
/**
* Check remote admin support
*/
boolean isRemoteAdminSupported();
/**
* Get remote admin port
*/
int getRemoteAdminPort();
/**
* Get ftp base directory
*/
String getBaseDirectory();
/**
* Get the server address.
*/
InetAddress getServerAddress();
/**
* Get the IP restrictor object.
*/
IpRestrictor getIpRestrictor();
/**
* Get user manager object.
*/
UserHandler getUserHandler();
/**
* Get global statistics object.
*/
FtpStatistics getStatistics();
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/FtpStatistics.java
Index: FtpStatistics.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Date;
/**
* Ftp statistis remote interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface FtpStatistics {
/**
* Get server start time.
*/
Date getStartTime();
/**
* Get number of files uploaded.
*/
int getFileUploadNbr();
/**
* Get number of files downloaded.
*/
int getFileDownloadNbr();
/**
* Get number of files deleted.
*/
int getFileDeleteNbr();
/**
* Get total number of bytes uploaded.
*/
long getFileUploadSize();
/**
* Get total number of bytes downloaded.
*/
long getFileDownloadSize();
/**
* Get current number of connections.
*/
int getConnectionNbr();
/**
* Get total number of connections
*/
int getTotalConnectionNbr();
/**
* Get current number of anonymous logins.
*/
int getAnonLoginNbr();
/**
* Get total number of anonymous logins
*/
int getTotalAnonLoginNbr();
/**
* Get current number of logins
*/
int getLoginNbr();
/**
* Get total number of logins
*/
int getTotalLoginNbr();
/**
* Set a listener object.
*/
void setListener(FtpStatisticsListener listener);
/**
* Get listener object.
*/
FtpStatisticsListener getListener();
/**
* Method setOpenConnection
*
*
*/
void setOpenConnection();
/**
* Method setCloseConnection
*
*
*/
void setCloseConnection();
/**
* Method setLogin
*
*
* @param anonymous
*
*/
void setLogin(boolean anonymous);
/**
* Method setLogout
*
*
* @param anonymous
*
*/
void setLogout(boolean anonymous);
/**
* Method setDownload
*
*
* @param sz
*
*/
void setDownload(long sz);
/**
* Method setUpload
*
*
* @param sz
*
*/
void setUpload(long sz);
/**
* Method setDelete
*
*
*/
void setDelete();
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/IpRestrictor.java
Index: IpRestrictor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.net.InetAddress;
import java.util.List;
/**
* IP Restrictor interface
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface IpRestrictor {
/**
* Reload data from store.
*/
void reload();
/**
* Save data into store.
*/
void save();
/**
* Check IP permission.
*/
boolean hasPermission(InetAddress addr);
/**
* Clear all entries.
*/
void clear();
/**
* Add new entry
*/
void addEntry(String str);
/**
* Remove entry
*/
void removeEntry(String str);
/**
* Get all entries
*/
List getAllEntries();
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/RemoteFtpAdmin.java
Index: RemoteFtpAdmin.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import org.apache.avalon.ftpserver.FtpException;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* Ftp server interface. Only the implementation of this
* interface will be bound. After binding we have to call
* <code>adminLogin(user, password)</code>.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface RemoteFtpAdmin extends Remote {
/**
* Ftp server name
*/
String DISPLAY_NAME = "Ftp";
/**
* Remote admin login
*/
String adminLogin(String id, String password) throws RemoteException, FtpException;
/**
* Remote admin logout
*/
void adminLogout(String sessId) throws RemoteException, FtpException;
/**
* Get configuration interface
*/
RemoteFtpConfig getConfig(String sessId) throws RemoteException, FtpException;
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/RemoteFtpConfig.java
Index: RemoteFtpConfig.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.net.InetAddress;
/**
* Remote ftp configuration interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface RemoteFtpConfig extends Remote {
/**
* Get server port.
*/
int getServerPort() throws RemoteException;
/**
* Check annonymous login support.
*/
boolean isAnonymousLoginSupported() throws RemoteException;
/**
* Get maximum number of connections.
*/
int getMaxConnections() throws RemoteException;
/**
* Get maximum number of anonymous connections.
*/
int getMaxAnonymousConnections() throws RemoteException;
/**
* Get default maximum idle time
*/
int getMaxIdleTime() throws RemoteException;
/**
* Get scheduler interval
*/
int getSchedulerInterval() throws RemoteException;
/**
* Check remote admin support
*/
boolean isRemoteAdminSupported() throws RemoteException;
/**
* Get remote admin port
*/
int getRemoteAdminPort() throws RemoteException;
/**
* Get ftp base directory
*/
String getBaseDirectory() throws RemoteException;
/**
* Get the server address.
*/
InetAddress getServerAddress() throws RemoteException;
/**
* Get the IP restrictor object.
*/
RemoteIpRestrictor getRemoteIpRestrictor() throws RemoteException;
/**
* Get user manager object.
*/
UserHandler getUserHandler() throws RemoteException;
/**
* Get global statistics object.
*/
RemoteFtpStatistics getStatistics() throws RemoteException;
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/RemoteFtpStatistics.java
Index: RemoteFtpStatistics.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Date;
/**
* Ftp statistis remote interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface RemoteFtpStatistics extends Remote {
/**
* Get server start time.
*/
Date getStartTime() throws RemoteException;
/**
* Get number of files uploaded.
*/
int getFileUploadNbr() throws RemoteException;
/**
* Get number of files downloaded.
*/
int getFileDownloadNbr() throws RemoteException;
/**
* Get number of files deleted.
*/
int getFileDeleteNbr() throws RemoteException;
/**
* Get total number of bytes uploaded.
*/
long getFileUploadSize() throws RemoteException;
/**
* Get total number of bytes downloaded.
*/
long getFileDownloadSize() throws RemoteException;
/**
* Get current number of connections.
*/
int getConnectionNbr() throws RemoteException;
/**
* Get total number of connections
*/
int getTotalConnectionNbr() throws RemoteException;
/**
* Get current number of anonymous logins.
*/
int getAnonLoginNbr() throws RemoteException;
/**
* Get total number of anonymous logins
*/
int getTotalAnonLoginNbr() throws RemoteException;
/**
* Get current number of logins
*/
int getLoginNbr() throws RemoteException;
/**
* Get total number of logins
*/
int getTotalLoginNbr() throws RemoteException;
/**
* Set a listener object.
*/
void setListener(FtpStatisticsListener listener) throws RemoteException;
/**
* Get listener object.
*/
FtpStatisticsListener getListener() throws RemoteException;
/**
* Method setOpenConnection
*
*
* @throws RemoteException
*
*/
void setOpenConnection() throws RemoteException;
/**
* Method setCloseConnection
*
*
* @throws RemoteException
*
*/
void setCloseConnection() throws RemoteException;
/**
* Method setLogin
*
*
* @param anonymous
*
* @throws RemoteException
*
*/
void setLogin(boolean anonymous) throws RemoteException;
/**
* Method setLogout
*
*
* @param anonymous
*
* @throws RemoteException
*
*/
void setLogout(boolean anonymous) throws RemoteException;
/**
* Method setDownload
*
*
* @param sz
*
* @throws RemoteException
*
*/
void setDownload(long sz) throws RemoteException;
/**
* Method setUpload
*
*
* @param sz
*
* @throws RemoteException
*
*/
void setUpload(long sz) throws RemoteException;
/**
* Method setDelete
*
*
* @throws RemoteException
*
*/
void setDelete() throws RemoteException;
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/RemoteIpRestrictor.java
Index: RemoteIpRestrictor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.net.InetAddress;
import java.util.List;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* IP Restrictor interface
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface RemoteIpRestrictor extends Remote {
/**
* Reload data from store.
*/
void reload() throws RemoteException;
/**
* Save data into store.
*/
void save() throws RemoteException;
/**
* Check IP permission.
*/
boolean hasPermission(InetAddress addr) throws RemoteException;
/**
* Clear all entries.
*/
void clear() throws RemoteException;
/**
* Add new entry
*/
void addEntry(String str) throws RemoteException;
/**
* Remove entry
*/
void removeEntry(String str) throws RemoteException;
/**
* Get all entries
*/
List getAllEntries() throws RemoteException;
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/RemoteUserHandler.java
Index: RemoteUserHandler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
import org.apache.avalon.ftpserver.FtpUser;
/**
* The remote user manager interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface RemoteUserHandler extends Remote {
/**
* Save the user. If a new user, create it else update the
* existing user.
*/
void save(FtpUser user) throws RemoteException;
/**
* Delete the user from the system.
*
*
* @param userName
*
* @throws RemoteException
*/
void delete(String userName) throws RemoteException;
/**
* Get user by name.
*/
FtpUser getUserByName(String name) throws RemoteException;
/**
* Fid user by session id
*/
FtpUser getConnectedUser(String sessionId) throws RemoteException;
/**
* Get all user names in the system.
*/
List getAllUserNames() throws RemoteException;
/**
* User existance check.
*
* @param name user name
*/
boolean doesExist(String name) throws RemoteException;
/**
* Get all logged in user list. It returns a list of all the
* currently connected user objects.
*/
List getAllConnectedUsers() throws RemoteException;
/**
* Logout all ftp connections.
*/
void closeAllConnections() throws RemoteException;
/**
* Close connection
*/
void closeConnection(String sessionId) throws RemoteException;
/**
* Set user manager observer.
*/
void setObserver(FtpConnectionObserver obsr) throws RemoteException;
/**
* Get user manager observer.
*/
FtpConnectionObserver getObserver() throws RemoteException;
/**
* Set spy object.
*/
void setSpyObject(String sessId, SpyUserInterface spy) throws RemoteException;
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/interfaces/UserHandler.java
Index: UserHandler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.interfaces;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.FtpException;
import java.util.List;
/**
* The remote user manager interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface UserHandler {
/**
* Save the user. If a new user, create it else update the
* existing user.
*/
void save(FtpUser user);
/**
* Delete the user from the system.
*
*
* @param userName
*/
void delete(String userName);
/**
* Get user by name.
*/
FtpUser getUserByName(String name);
/**
* Method login
*
*
* @param sessId
*
* @throws FtpException
*
*/
void login(final String sessId) throws FtpException;
/**
* Fid user by session id
*/
FtpUser getConnectedUser(String sessionId);
/**
* Get all user names in the system.
*/
List getAllUserNames();
/**
* User existance check.
*
* @param name user name
*/
boolean doesExist(String name);
/**
* Get all logged in user list. It returns a list of all the
* currently connected user objects.
*/
List getAllConnectedUsers();
/**
* Logout all ftp connections.
*/
void closeAllConnections();
/**
* Close connection
*/
void closeConnection(String sessionId);
/**
* Set user manager observer.
*/
void setObserver(FtpConnectionObserver obsr);
/**
* Get user manager observer.
*/
FtpConnectionObserver getObserver();
/**
* Set spy object.
*/
void setSpyObject(String sessId, SpyUserInterface spy);
/**
* Method newConnection
*
*
* @param newUser
*
*/
void newConnection(final FtpUser newUser);
/**
* Method close
*
*
*/
void close();
}
1.2 +5 -6 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/services/FtpServer.java
Index: FtpServer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/services/FtpServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpServer.java 2001/12/13 13:26:05 1.1
+++ FtpServer.java 2001/12/14 01:22:04 1.2
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -5,20 +6,18 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
package org.apache.avalon.ftpserver.services;
+
+
import org.apache.avalon.ftpserver.interfaces.FtpAdmin;
/**
* Ftp server interface. Only the implementation of this
* interface will be bound. After binding we have to call
- * <code>adminLogin(user, password)</code>.
+ * <code>adminLogin(user, password)</code>.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-interface FtpServer extends FtpAdmin {
-
-}
+public interface FtpServer extends FtpAdmin {}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/services/FtpConfigService.java
Index: FtpConfigService.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.services;
import org.apache.avalon.ftpserver.interfaces.FtpConfig;
import org.apache.avalon.ftpserver.util.AsyncMessageQueue;
import org.apache.avalon.ftpserver.blocks.stats.DefaultFtpStatistics;
import org.apache.avalon.ftpserver.FtpStatus;
import java.rmi.registry.Registry;
import java.io.File;
/**
* This is the base class of all the user manager classes.
* If we want to add a new user manager, we have to override
* this class.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface FtpConfigService extends FtpConfig {
/**
* Method getMessageQueue
*
*
* @return
*
*/
AsyncMessageQueue getMessageQueue();
/**
* Method getRegistry
*
*
* @return
*
*/
Registry getRegistry();
/**
* Method getSystemName
*
*
* @return
*
*/
String getSystemName();
/**
* Method getStatus
*
*
* @return
*
*/
FtpStatus getStatus();
/**
* Method getDefaultRoot
*
*
* @return
*
*/
File getDefaultRoot();
}
1.1 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/services/UserManager.java
Index: UserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.services;
import org.apache.avalon.ftpserver.FtpUser;
import java.util.List;
/**
* This is the base class of all the user manager classes.
* If we want to add a new user manager, we have to override
* this class.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public interface UserManager {
/**
* Save the user. If a new user, create it else update the
* existing user.
*/
public void save(FtpUser user);
/**
* Delete the user from the system.
*
*
* @param userName
*/
public void delete(String userName);
/**
* Get user by name.
*/
public FtpUser getUserByName(String name);
/**
* Get all user names in the system.
*/
public List getAllUserNames();
/**
* User existance check.
*
* @param name user name
*/
public boolean doesExist(String name);
/**
* Close the user manager.
*/
public void close();
/**
* Authenticate user
*/
public boolean authenticate(String login, String password);
}
1.3 +2 -11 jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/BaseProperties.java
Index: BaseProperties.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/BaseProperties.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseProperties.java 2001/11/10 21:34:04 1.2
+++ BaseProperties.java 2001/12/14 01:22:04 1.3
@@ -20,7 +20,7 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class BaseProperties extends Properties {
+class BaseProperties extends Properties implements Serializable{
/**
@@ -35,16 +35,7 @@
public BaseProperties(Properties prop) {
super(prop);
}
-
- /**
- * Load properties from file
- */
- public BaseProperties(File fl) throws IOException {
- FileInputStream fis = new FileInputStream(fl);
- load(fis);
- fis.close();
- }
-
+
/**
* Load properties from <code>InputStream</code>
*/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>