001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.plugins;
019:
020: import java.io.File;
021: import java.io.FileOutputStream;
022: import java.io.IOException;
023: import java.io.PrintStream;
024: import java.text.SimpleDateFormat;
025: import java.util.Date;
026: import java.util.Locale;
027:
028: import net.sf.drftpd.FatalException;
029: import net.sf.drftpd.event.Event;
030: import net.sf.drftpd.event.FtpListener;
031: import net.sf.drftpd.event.TransferEvent;
032:
033: /**
034: * @see http://www.wu-ftpd.org/man/xferlog.html
035: * @author mog
036: * @version $Id: XferLog.java 1238 2005-09-02 11:54:26Z zubov $
037: */
038: public class XferLog extends FtpListener {
039: /**
040: * xferlog.log - Contains all the upload/download information for all files
041: transferred (if logging of that is enabled). The format is the
042: following: current time, transfer time, user's hostname, number
043: of bytes sent, filename, 'a' if transfer was in ASCII mode or
044: 'b' if BINARY, _ (meaningless), 'i' if incoming (user uploading)
045: or 'o' if outgoing (user downloading), 'r' (no meaning), user's
046: name, user's group, 1 if user had ident or 0 if not, user's ident
047:
048: current-time transfer-time remote-host file-
049: size filename transfer-type special-action-
050: flag direction access-mode username ser?
051: vice-name authentication-method authenticated-
052: user-id completion-status
053:
054: example lines:
055: Mon Aug 11 14:03:30 2003 20 hostname 15000000 /path/to/file b _ i r user group 0 *
056: Mon Aug 11 14:03:31 2003 33 hostname 15000000 /path/to/file b _ i r user group 1 user
057: Mon Aug 11 14:03:44 2003 13 hostname 15000000 /path/to/file b _ i r user group 0 *
058: */
059: public static SimpleDateFormat DATE_FMT = new SimpleDateFormat(
060: "EEE MMM d HH:mm:ss yyyy", Locale.ENGLISH);
061: private PrintStream _out;
062:
063: public XferLog() {
064: super ();
065: new File("logs").mkdirs();
066:
067: try {
068: //APPEND
069: _out = new PrintStream(new FileOutputStream("logs/xferlog",
070: true));
071: } catch (IOException e) {
072: throw new FatalException(e);
073: }
074: }
075:
076: public void actionPerformed(Event event) {
077: if (event instanceof TransferEvent) {
078: actionPerformed((TransferEvent) event);
079: }
080: }
081:
082: public void actionPerformed(TransferEvent event) {
083: char direction;
084:
085: if (event.getCommand().equals("STOR")) {
086: direction = 'i';
087: } else if (event.getCommand().equals("RETR")) {
088: direction = 'o';
089: } else {
090: return;
091: }
092:
093: char transferType;
094:
095: if (event.getType() == 'I') { // IMAGE
096: transferType = 'b';
097: } else if (event.getType() == 'A') { // ASCII
098: transferType = 'a';
099: } else {
100: throw new FatalException("Invalid transfer type");
101: }
102:
103: //char completed = event.isComplete() ? 'c' : 'i';
104: // all transfers are noted as complete
105: char completed = 'c';
106: _out.println(DATE_FMT.format(new Date(event.getTime())) + " "
107: + (event.getDirectory().getXfertime() / 1000) + " "
108: + event.getPeer().getHostName() + " "
109: + event.getDirectory().length() + " "
110: + event.getDirectory().getPath() + " " + transferType
111: + " _ " + direction + " r " + event.getUser().getName()
112: + " " + event.getUser().getGroup() + " 0 * " // authentication-method authenticated-user-id
113: + completed);
114: }
115: }
|