1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.waarp.gateway.ftp.control;
18
19 import org.waarp.common.command.ReplyCode;
20 import org.waarp.common.command.exception.CommandAbstractException;
21 import org.waarp.common.database.DbSession;
22 import org.waarp.common.database.data.AbstractDbData.UpdatedInfo;
23 import org.waarp.common.database.exception.WaarpDatabaseException;
24 import org.waarp.common.logging.WaarpLogger;
25 import org.waarp.common.logging.WaarpLoggerFactory;
26 import org.waarp.ftp.core.command.FtpCommandCode;
27 import org.waarp.ftp.core.control.BusinessHandler;
28 import org.waarp.ftp.core.data.FtpTransfer;
29 import org.waarp.ftp.core.exception.FtpNoFileException;
30 import org.waarp.ftp.core.session.FtpSession;
31 import org.waarp.gateway.ftp.config.FileBasedConfiguration;
32 import org.waarp.gateway.ftp.database.DbConstant;
33 import org.waarp.gateway.ftp.database.data.DbTransferLog;
34
35
36
37
38
39
40
41 public class WaarpActionLogger {
42
43
44
45 private static final WaarpLogger logger = WaarpLoggerFactory
46 .getLogger(WaarpActionLogger.class);
47
48
49
50
51
52
53
54
55
56 public static long logCreate(DbSession ftpSession,
57 String message, String file, BusinessHandler handler) {
58 FtpSession session = handler.getFtpSession();
59 String sessionContexte = session.toString();
60 logger.info(message + " " + sessionContexte);
61 if (ftpSession != null) {
62 FtpCommandCode code = session.getCurrentCommand().getCode();
63 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
64 boolean isSender =
65 FtpCommandCode.isRetrLikeCommand(code);
66 try {
67
68 DbTransferLog log =
69 new DbTransferLog(ftpSession,
70 session.getAuth().getUser(),
71 session.getAuth().getAccount(),
72 DbConstant.ILLEGALVALUE,
73 isSender, file,
74 code.name(),
75 ReplyCode.REPLY_000_SPECIAL_NOSTATUS, message,
76 UpdatedInfo.TOSUBMIT);
77 logger.debug("Create FS: " + log.toString());
78 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
79 if (isSender) {
80 FileBasedConfiguration.fileBasedConfiguration.monitoring
81 .updateLastOutBand();
82 } else {
83 FileBasedConfiguration.fileBasedConfiguration.monitoring
84 .updateLastInBound();
85 }
86 }
87 return log.getSpecialId();
88 } catch (WaarpDatabaseException e1) {
89
90 }
91 }
92 }
93 return DbConstant.ILLEGALVALUE;
94 }
95
96
97
98
99
100
101
102
103
104
105
106 public static long logAction(DbSession ftpSession, long specialId,
107 String message, BusinessHandler handler, ReplyCode rcode,
108 UpdatedInfo info) {
109 FtpSession session = handler.getFtpSession();
110 String sessionContexte = session.toString();
111 logger.info(message + " " + sessionContexte);
112 if (ftpSession != null && specialId != DbConstant.ILLEGALVALUE) {
113 FtpCommandCode code = session.getCurrentCommand().getCode();
114 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
115 try {
116
117 DbTransferLog log =
118 new DbTransferLog(ftpSession,
119 session.getAuth().getUser(),
120 session.getAuth().getAccount(), specialId);
121 log.changeUpdatedInfo(info);
122 log.setInfotransf(message);
123 log.setReplyCodeExecutionStatus(rcode);
124 log.update();
125 logger.debug("Update FS: " + log.toString());
126 return log.getSpecialId();
127 } catch (WaarpDatabaseException e) {
128
129 }
130 } else {
131 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
132 FileBasedConfiguration.fileBasedConfiguration.monitoring.
133 updateCodeNoTransfer(rcode);
134 }
135 }
136 } else {
137 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
138 FileBasedConfiguration.fileBasedConfiguration.monitoring.
139 updateCodeNoTransfer(rcode);
140 }
141 }
142 return specialId;
143 }
144
145
146
147
148
149
150
151
152
153
154
155 public static void logErrorAction(DbSession ftpSession, long specialId,
156 FtpTransfer transfer,
157 String message, ReplyCode rcode, BusinessHandler handler) {
158 FtpSession session = handler.getFtpSession();
159 String sessionContexte = session.toString();
160 logger.error(rcode.getCode() + ":" + message + " " + sessionContexte);
161 logger.debug("Log",
162 new Exception("Log"));
163 if (ftpSession != null && specialId != DbConstant.ILLEGALVALUE) {
164 FtpCommandCode code = session.getCurrentCommand().getCode();
165 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
166 String file = null;
167 if (transfer != null) {
168 try {
169 file = transfer.getFtpFile().getFile();
170 } catch (CommandAbstractException e1) {
171 } catch (FtpNoFileException e1) {
172 }
173 } else {
174 file = null;
175 }
176 UpdatedInfo info = UpdatedInfo.INERROR;
177 try {
178
179 DbTransferLog log =
180 new DbTransferLog(ftpSession,
181 session.getAuth().getUser(),
182 session.getAuth().getAccount(), specialId);
183 log.changeUpdatedInfo(info);
184 log.setInfotransf(message);
185 if (rcode.getCode() < 400) {
186 log.setReplyCodeExecutionStatus(ReplyCode.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED);
187 } else {
188 log.setReplyCodeExecutionStatus(rcode);
189 }
190 if (file != null) {
191 log.setFilename(file);
192 }
193 log.update();
194 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
195 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
196 notifyInfoTask(message, log);
197 }
198 logger.debug("Update FS: " + log.toString());
199 } catch (WaarpDatabaseException e) {
200
201 }
202 } else {
203 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
204 FileBasedConfiguration.fileBasedConfiguration.monitoring.
205 updateCodeNoTransfer(rcode);
206 }
207 if (rcode != ReplyCode.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN &&
208 rcode != ReplyCode.REPLY_550_REQUESTED_ACTION_NOT_TAKEN) {
209 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
210 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
211 notifyWarning(rcode.getMesg(), message);
212 }
213 }
214 }
215 } else {
216 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
217 FileBasedConfiguration.fileBasedConfiguration.monitoring.
218 updateCodeNoTransfer(rcode);
219 }
220 if (rcode != ReplyCode.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN &&
221 rcode != ReplyCode.REPLY_550_REQUESTED_ACTION_NOT_TAKEN) {
222 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
223 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
224 notifyWarning(rcode.getMesg(), message);
225 }
226 }
227 }
228 }
229 }