It was 29/11/2006 19:53, when Niklas Gustavsson wrote:
I think ServerFtpStatistics is a better fit as FtpStatistics is read
only and could therefore be exposed to those we don't want changing stuff.
Agreed, and done. Patch attached.
I have also added a "failed login" counter, which is incremented
when the login attempt is not successful. This in turn will call a
notifyLoginFail() method on the StatisticsObserver.
I've passed in the RemoteAddress, to enable implementations to log
or otherwise make use of the address that the failed login came in
on. Perhaps this is enough to address FTPSERVER-52?
I haven't passed the username info into this method, because often
times, users can end up putting their password in as part of the
username. Therefore logging this information would be bad for
security. It could be added though with a disclaimer about it's use.
------------------------------------------------------------------------
Index: src/java/org/apache/ftpserver/FtpStatisticsImpl.java
===================================================================
--- src/java/org/apache/ftpserver/FtpStatisticsImpl.java (revision
472118)
+++ src/java/org/apache/ftpserver/FtpStatisticsImpl.java (working copy)
@@ -54,6 +54,7 @@
private int currLogins = 0;
private int totalLogins = 0;
+ private int totalFailedLogins = 0;
private int currAnonLogins = 0;
private int totalAnonLogins = 0;
@@ -186,6 +187,13 @@
}
/**
+ * Get total failed login number.
+ */
+ public int getTotalFailedLoginNumber() {
+ return totalFailedLogins;
+ }
+
+ /**
* Get current number of logins.
*/
public int getCurrentLoginNumber() {
@@ -340,7 +348,15 @@
notifyLogin(connection);
}
-
+
+ /**
+ * Increment failed login count.
+ */
+ public void setLoginFail(Connection connection) {
+ ++totalFailedLogins;
+ notifyLoginFail(connection);
+ }
+
/**
* User logout
*/
@@ -485,6 +501,16 @@
}
/**
+ * Observer failed login notification.
+ */
+ private void notifyLoginFail(Connection connection) {
+ StatisticsObserver observer = this.observer;
+ if (observer != null) {
+
observer.notifyLoginFail(connection.getRequest().getRemoteAddress());
+ }
+ }
+
+ /**
* Observer logout notification.
*/
private void notifyLogout(Connection connection) {
@@ -501,5 +527,25 @@
}
}
-
+ /**
+ * Reset the cumulative counters.
+ */
+ public void resetStasticCounters() {
+ startTime = new Date();
+
+ uploadCount = 0;
+ downloadCount = 0;
+ deleteCount = 0;
+
+ mkdirCount = 0;
+ rmdirCount = 0;
+
+ totalLogins = 0;
+ totalFailedLogins = 0;
+ totalAnonLogins = 0;
+ totalConnections = 0;
+
+ bytesUpload = 0;
+ bytesDownload = 0;
+ }
}
Index: src/java/org/apache/ftpserver/command/PASS.java
===================================================================
--- src/java/org/apache/ftpserver/command/PASS.java (revision 472118)
+++ src/java/org/apache/ftpserver/command/PASS.java (working copy)
@@ -146,6 +146,7 @@
} else {
log.warn("Login failure - " + userName);
out.send(530, "PASS", userName);
+ stat.setLoginFail(handler);
return;
}
Index: src/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java
===================================================================
--- src/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java
(revision 472118)
+++ src/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java
(working copy)
@@ -83,7 +83,18 @@
void setLogin(Connection connection);
/**
+ * Increment failed login count.
+ */
+ void setLoginFail(Connection connection);
+
+ /**
* Decrement current login count.
*/
void setLogout(Connection connection);
+
+ /**
+ * Reset all cumulative total counters. Do not reset current counters, like
+ * current logins, otherwise these will become negative when someone disconnects.
+ */
+ void resetStasticCounters();
}
Index: src/java/org/apache/ftpserver/interfaces/StatisticsObserver.java
===================================================================
--- src/java/org/apache/ftpserver/interfaces/StatisticsObserver.java
(revision 472118)
+++ src/java/org/apache/ftpserver/interfaces/StatisticsObserver.java
(working copy)
@@ -19,6 +19,8 @@
package org.apache.ftpserver.interfaces;
+import java.net.InetAddress;
+
/**
* Ftp statistics observer interface.
*
@@ -58,6 +60,12 @@
void notifyLogin(boolean anonymous);
/**
+ * Failed user login notification.
+ * @param address Remote address that the failure came from
+ */
+ void notifyLoginFail(InetAddress address);
+
+ /**
* User logout notification.
*/
void notifyLogout(boolean anonymous);
@@ -71,4 +79,5 @@
* Connection close notification
*/
void notifyCloseConnection();
+
}