741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
29 |
// |
741 |
10 Oct 06 |
olle |
// This program is free software; you can redistribute it and/or |
741 |
10 Oct 06 |
olle |
// modify it under the terms of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// as published by the Free Software Foundation; either version 2 |
741 |
10 Oct 06 |
olle |
// of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
34 |
// |
741 |
10 Oct 06 |
olle |
// This program is distributed in the hope that it will be useful, |
741 |
10 Oct 06 |
olle |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 |
10 Oct 06 |
olle |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
741 |
10 Oct 06 |
olle |
// GNU General Public License for more details. |
741 |
10 Oct 06 |
olle |
39 |
// |
741 |
10 Oct 06 |
olle |
// You should have received a copy of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// along with this program; if not, write to the Free Software |
741 |
10 Oct 06 |
olle |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
741 |
10 Oct 06 |
olle |
43 |
// |
741 |
10 Oct 06 |
olle |
44 |
// |
741 |
10 Oct 06 |
olle |
45 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
// ## YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT: ## |
741 |
10 Oct 06 |
olle |
// ## HTTP://WWW.JAVASCRIPT.NU/XERVER/ ## |
741 |
10 Oct 06 |
olle |
48 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## IF YOUR SOFTWARE IS NOT RELEASED UNDER THE ## |
741 |
10 Oct 06 |
olle |
// ## GNU GENERAL PUBLIC LICENSE (GPL), ## |
741 |
10 Oct 06 |
olle |
// ## PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!! ## |
741 |
10 Oct 06 |
olle |
52 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## FOR FULL LICENSE, PLEASE READ "XERVER LICENSE". ## |
741 |
10 Oct 06 |
olle |
54 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
55 |
|
1652 |
22 May 07 |
gregory |
56 |
package se.lu.thep.coreftpd.webserver; |
741 |
10 Oct 06 |
olle |
57 |
|
791 |
23 Oct 06 |
olle |
58 |
import se.lu.thep.coreftpd.common.MyString; |
741 |
10 Oct 06 |
olle |
59 |
import java.util.Date; |
741 |
10 Oct 06 |
olle |
60 |
|
741 |
10 Oct 06 |
olle |
61 |
/** |
1652 |
22 May 07 |
gregory |
62 |
* |
1652 |
22 May 07 |
gregory |
* <B>How to use:</B> <BR> |
1652 |
22 May 07 |
gregory |
* <CODE>new HitStatistic(String argIP, String argStatusCode, String |
1652 |
22 May 07 |
gregory |
* argFileLocation, String arghitDate, String argFileExtension, String |
1652 |
22 May 07 |
gregory |
* argLoginRealm, String argLoginUserName[, char argSpaceCharacter=' ']);</CODE> |
741 |
10 Oct 06 |
olle |
* <BR> |
1652 |
22 May 07 |
gregory |
* <CODE>new HitStatistic();</CODE> <BR> |
741 |
10 Oct 06 |
olle |
* <BR> |
1652 |
22 May 07 |
gregory |
70 |
* |
1652 |
22 May 07 |
gregory |
* <B>More info:</B> <BR> |
1652 |
22 May 07 |
gregory |
* For each request sent to the server (and logging is enabled = the swing |
1652 |
22 May 07 |
gregory |
* interface is used), a <CODE>HitStatistic</CODE> will be created, containing |
1652 |
22 May 07 |
gregory |
* information about the request. <BR> |
741 |
10 Oct 06 |
olle |
* This is in other words a log-entry. |
1652 |
22 May 07 |
gregory |
76 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @version 1.0 |
741 |
10 Oct 06 |
olle |
79 |
*/ |
741 |
10 Oct 06 |
olle |
80 |
|
1652 |
22 May 07 |
gregory |
81 |
final public class HitStatistic { |
1652 |
22 May 07 |
gregory |
82 |
private String IP; |
741 |
10 Oct 06 |
olle |
83 |
|
1652 |
22 May 07 |
gregory |
84 |
private String statusCode; |
741 |
10 Oct 06 |
olle |
85 |
|
741 |
10 Oct 06 |
olle |
86 |
private String fileLocation; |
1652 |
22 May 07 |
gregory |
87 |
|
741 |
10 Oct 06 |
olle |
88 |
private String hitDate; |
1652 |
22 May 07 |
gregory |
89 |
|
741 |
10 Oct 06 |
olle |
90 |
private String fileExtension; |
1652 |
22 May 07 |
gregory |
91 |
|
741 |
10 Oct 06 |
olle |
92 |
private String loginRealm; |
1652 |
22 May 07 |
gregory |
93 |
|
741 |
10 Oct 06 |
olle |
94 |
private String loginUserName; |
1652 |
22 May 07 |
gregory |
95 |
|
1652 |
22 May 07 |
gregory |
96 |
public static boolean showIP = true; |
1652 |
22 May 07 |
gregory |
97 |
|
1652 |
22 May 07 |
gregory |
98 |
public static boolean showStatusCode = true; |
1652 |
22 May 07 |
gregory |
99 |
|
1652 |
22 May 07 |
gregory |
100 |
public static boolean showFileLocation = true; |
1652 |
22 May 07 |
gregory |
101 |
|
1652 |
22 May 07 |
gregory |
102 |
public static boolean showHitDate = true; |
1652 |
22 May 07 |
gregory |
103 |
|
1652 |
22 May 07 |
gregory |
104 |
public static boolean showFileExtension = true; |
1652 |
22 May 07 |
gregory |
105 |
|
1652 |
22 May 07 |
gregory |
106 |
public static boolean showLoginRealm = true; |
1652 |
22 May 07 |
gregory |
107 |
|
1652 |
22 May 07 |
gregory |
108 |
public static boolean showLoginUserName = true; |
1652 |
22 May 07 |
gregory |
109 |
|
1652 |
22 May 07 |
gregory |
110 |
public static int showLengthIP = 30; |
1652 |
22 May 07 |
gregory |
111 |
|
1652 |
22 May 07 |
gregory |
112 |
public static int showLengthStatusCode = 14; |
1652 |
22 May 07 |
gregory |
113 |
|
1652 |
22 May 07 |
gregory |
114 |
public static int showLengthHitDate = 15; |
1652 |
22 May 07 |
gregory |
115 |
|
1652 |
22 May 07 |
gregory |
116 |
public static int showLengthFileExtension = 6; |
1652 |
22 May 07 |
gregory |
117 |
|
1652 |
22 May 07 |
gregory |
118 |
public static int showLengthLoginRealm = 10; |
1652 |
22 May 07 |
gregory |
119 |
|
1652 |
22 May 07 |
gregory |
120 |
public static int showLengthLoginUserName = 10; |
1652 |
22 May 07 |
gregory |
121 |
|
741 |
10 Oct 06 |
olle |
122 |
private char spaceCharacter; |
741 |
10 Oct 06 |
olle |
123 |
|
1652 |
22 May 07 |
gregory |
124 |
HitStatistic() { |
1652 |
22 May 07 |
gregory |
125 |
this("IP/Host", "Status Code", "File", "Date", "Extension", "Zone", |
1652 |
22 May 07 |
gregory |
126 |
"UserName", '.'); |
741 |
10 Oct 06 |
olle |
127 |
} |
741 |
10 Oct 06 |
olle |
128 |
|
1652 |
22 May 07 |
gregory |
129 |
HitStatistic(String argIP, String argStatusCode, String argFileLocation, |
1652 |
22 May 07 |
gregory |
130 |
Date arghitDate, String argFileExtension, String argLoginRealm, |
1652 |
22 May 07 |
gregory |
131 |
String argLoginUserName) { |
1652 |
22 May 07 |
gregory |
132 |
this(argIP, argStatusCode, argFileLocation, arghitDate.toString() |
1652 |
22 May 07 |
gregory |
133 |
.substring(4, 19), argFileExtension, argLoginRealm, |
1652 |
22 May 07 |
gregory |
134 |
argLoginUserName, ' '); |
741 |
10 Oct 06 |
olle |
135 |
} |
741 |
10 Oct 06 |
olle |
136 |
|
1652 |
22 May 07 |
gregory |
137 |
HitStatistic(String argIP, String argStatusCode, String argFileLocation, |
1652 |
22 May 07 |
gregory |
138 |
String arghitDate, String argFileExtension, String argLoginRealm, |
1652 |
22 May 07 |
gregory |
139 |
String argLoginUserName, char argSpaceCharacter) { |
1652 |
22 May 07 |
gregory |
140 |
IP = argIP.intern(); |
1652 |
22 May 07 |
gregory |
141 |
statusCode = argStatusCode.intern(); |
1652 |
22 May 07 |
gregory |
142 |
fileLocation = argFileLocation; |
1652 |
22 May 07 |
gregory |
143 |
hitDate = arghitDate; |
1652 |
22 May 07 |
gregory |
144 |
fileExtension = argFileExtension.intern(); |
1652 |
22 May 07 |
gregory |
145 |
loginRealm = argLoginRealm.intern(); |
1652 |
22 May 07 |
gregory |
146 |
loginUserName = argLoginUserName.intern(); |
1652 |
22 May 07 |
gregory |
147 |
spaceCharacter = argSpaceCharacter; |
741 |
10 Oct 06 |
olle |
148 |
} |
741 |
10 Oct 06 |
olle |
149 |
|
2386 |
14 Nov 07 |
gregory |
150 |
@Override |
1652 |
22 May 07 |
gregory |
151 |
public String toString() { |
1652 |
22 May 07 |
gregory |
// hitDate.toString() ==> "Sat Aug 12 02:30:00 PDT 1995" |
1652 |
22 May 07 |
gregory |
153 |
StringBuffer strBuf = new StringBuffer(); |
741 |
10 Oct 06 |
olle |
154 |
|
741 |
10 Oct 06 |
olle |
155 |
if (showIP) |
1652 |
22 May 07 |
gregory |
156 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
157 |
MyString.giveStringWithFixLength(IP, showLengthIP, |
1652 |
22 May 07 |
gregory |
158 |
spaceCharacter)).append(spaceCharacter).append( |
1652 |
22 May 07 |
gregory |
159 |
spaceCharacter); |
741 |
10 Oct 06 |
olle |
160 |
if (showStatusCode) |
1652 |
22 May 07 |
gregory |
161 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
162 |
MyString.giveStringWithFixLength(statusCode, |
1652 |
22 May 07 |
gregory |
163 |
showLengthStatusCode, spaceCharacter)).append( |
1652 |
22 May 07 |
gregory |
164 |
spaceCharacter).append(spaceCharacter); |
741 |
10 Oct 06 |
olle |
165 |
if (showFileExtension) |
1652 |
22 May 07 |
gregory |
166 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
167 |
MyString.giveStringWithFixLength(fileExtension, |
1652 |
22 May 07 |
gregory |
168 |
showLengthFileExtension, spaceCharacter)).append( |
1652 |
22 May 07 |
gregory |
169 |
spaceCharacter).append(spaceCharacter); |
741 |
10 Oct 06 |
olle |
170 |
if (showLoginRealm) |
1652 |
22 May 07 |
gregory |
171 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
172 |
MyString.giveStringWithFixLength(loginRealm, |
1652 |
22 May 07 |
gregory |
173 |
showLengthLoginRealm, spaceCharacter)).append( |
1652 |
22 May 07 |
gregory |
174 |
spaceCharacter).append(spaceCharacter); |
741 |
10 Oct 06 |
olle |
175 |
if (showLoginUserName) |
1652 |
22 May 07 |
gregory |
176 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
177 |
MyString.giveStringWithFixLength(loginUserName, |
1652 |
22 May 07 |
gregory |
178 |
showLengthLoginUserName, spaceCharacter)).append( |
1652 |
22 May 07 |
gregory |
179 |
spaceCharacter).append(spaceCharacter); |
741 |
10 Oct 06 |
olle |
180 |
if (showHitDate) |
1652 |
22 May 07 |
gregory |
181 |
strBuf.append( |
1652 |
22 May 07 |
gregory |
182 |
MyString.giveStringWithFixLength(hitDate, |
1652 |
22 May 07 |
gregory |
183 |
showLengthHitDate, spaceCharacter)).append( |
1652 |
22 May 07 |
gregory |
184 |
spaceCharacter).append(spaceCharacter); |
741 |
10 Oct 06 |
olle |
185 |
if (showFileLocation) |
741 |
10 Oct 06 |
olle |
186 |
strBuf.append(fileLocation); |
741 |
10 Oct 06 |
olle |
187 |
|
741 |
10 Oct 06 |
olle |
188 |
return strBuf.toString(); |
741 |
10 Oct 06 |
olle |
189 |
} |
741 |
10 Oct 06 |
olle |
190 |
} |
741 |
10 Oct 06 |
olle |
191 |
|
1652 |
22 May 07 |
gregory |
// (1+hitDate.getHours())+":"+(1+hitDate.getMinutes())+":"+(1+hitDate.getSeconds())+" |
1652 |
22 May 07 |
gregory |
// "+hitDate.getDate()+"/"+hitDate.getMonth()+" |