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 |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
27 |
// |
741 |
10 Oct 06 |
olle |
28 |
// |
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 |
33 |
// |
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 |
38 |
// |
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 |
42 |
// |
741 |
10 Oct 06 |
olle |
43 |
// |
741 |
10 Oct 06 |
olle |
44 |
// ############################################################# |
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 |
47 |
// ## ## |
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 |
51 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## FOR FULL LICENSE, PLEASE READ "XERVER LICENSE". ## |
741 |
10 Oct 06 |
olle |
53 |
// ############################################################# |
1652 |
22 May 07 |
gregory |
54 |
package se.lu.thep.coreftpd.webserver; |
741 |
10 Oct 06 |
olle |
55 |
|
791 |
23 Oct 06 |
olle |
56 |
import se.lu.thep.coreftpd.common.DataInputStreamWithReadLine; |
791 |
23 Oct 06 |
olle |
57 |
import se.lu.thep.coreftpd.common.HostInfo; |
791 |
23 Oct 06 |
olle |
58 |
import se.lu.thep.coreftpd.common.MyHashTable; |
791 |
23 Oct 06 |
olle |
59 |
import se.lu.thep.coreftpd.common.MyString; |
741 |
10 Oct 06 |
olle |
60 |
import java.io.BufferedInputStream; |
741 |
10 Oct 06 |
olle |
61 |
import java.io.BufferedOutputStream; |
741 |
10 Oct 06 |
olle |
62 |
import java.io.DataOutputStream; |
741 |
10 Oct 06 |
olle |
63 |
import java.io.File; |
741 |
10 Oct 06 |
olle |
64 |
import java.io.FileInputStream; |
741 |
10 Oct 06 |
olle |
65 |
import java.io.OutputStream; |
741 |
10 Oct 06 |
olle |
66 |
import java.net.Socket; |
741 |
10 Oct 06 |
olle |
67 |
import java.text.DateFormat; |
741 |
10 Oct 06 |
olle |
68 |
import java.util.Arrays; |
741 |
10 Oct 06 |
olle |
69 |
import java.util.Date; |
741 |
10 Oct 06 |
olle |
70 |
|
741 |
10 Oct 06 |
olle |
71 |
/** |
1652 |
22 May 07 |
gregory |
* <B>About this class:</B> <BR> |
2143 |
16 Oct 07 |
gregory |
* Every time a connection is established to Xerver, a |
2143 |
16 Oct 07 |
gregory |
* <CODE>NewConnection</CODE> is created. <BR> |
1652 |
22 May 07 |
gregory |
* <CODE>NewConnection</CODE> is a <CODE>Thread</CODE> and reads what the |
1652 |
22 May 07 |
gregory |
* user requested and gives the user an appropriate response to his/her request. |
741 |
10 Oct 06 |
olle |
* <BR> |
1652 |
22 May 07 |
gregory |
* This is the most "important class" in Xerver and is probably the class you |
1652 |
22 May 07 |
gregory |
* shall rewrite if you want to add more features to Xerver. <BR> |
1652 |
22 May 07 |
gregory |
80 |
* |
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 |
83 |
*/ |
2143 |
16 Oct 07 |
gregory |
84 |
final public class NewConnection |
2143 |
16 Oct 07 |
gregory |
85 |
extends Thread |
2143 |
16 Oct 07 |
gregory |
86 |
{ |
1652 |
22 May 07 |
gregory |
87 |
private static String hiddenFolder = "data" + File.separator; |
1652 |
22 May 07 |
gregory |
88 |
private static String errorFilesFolder = "errorHTML" + File.separator; |
1652 |
22 May 07 |
gregory |
89 |
private static String s_replyServerName = XerverKernel.getXerverName(); |
1652 |
22 May 07 |
gregory |
90 |
private final static boolean b_showErrors = false; // Set this to true if |
2143 |
16 Oct 07 |
gregory |
// and only if you are |
2143 |
16 Oct 07 |
gregory |
// debugging and want to |
2143 |
16 Oct 07 |
gregory |
// see what is happening |
2143 |
16 Oct 07 |
gregory |
// all the time |
1652 |
22 May 07 |
gregory |
95 |
private final static int i_soTimeoutAfterKeepAliveTransfer = 5000; |
1652 |
22 May 07 |
gregory |
96 |
private final static int i_maxsizeOfFileNameInDirListing = 35; |
1652 |
22 May 07 |
gregory |
97 |
private final static int i_maxFileSizeLength = 15; |
1652 |
22 May 07 |
gregory |
98 |
private final static String s_charsetToUse = "";// "; charset=ISO-8859-2"; |
1652 |
22 May 07 |
gregory |
99 |
public static long totalNumberOfHits = 0; |
2143 |
16 Oct 07 |
gregory |
100 |
public static long totalNumberOfBytesDownloaded = 0; |
2143 |
16 Oct 07 |
gregory |
101 |
/* |
2143 |
16 Oct 07 |
gregory |
* Number of bytes sent via headers/directory listings etc. are NOT |
2143 |
16 Oct 07 |
gregory |
* included. Only number of bytes from files are content. (HOWEVER: |
2143 |
16 Oct 07 |
gregory |
* directory listing does show icons, which are downloaded as regular files, |
2143 |
16 Oct 07 |
gregory |
* so a directory listing with an browser supporting images WILL result in |
2143 |
16 Oct 07 |
gregory |
* that "totalNumberOfBytesDownloaded" will increase in value) |
2143 |
16 Oct 07 |
gregory |
107 |
*/ |
741 |
10 Oct 06 |
olle |
108 |
public static MenuOptions myMenuOptions; |
741 |
10 Oct 06 |
olle |
109 |
public static int i_portNr; |
1652 |
22 May 07 |
gregory |
110 |
public static String[] as_indexNames; |
1652 |
22 May 07 |
gregory |
111 |
public static String[] as_sharedPaths; |
1652 |
22 May 07 |
gregory |
112 |
public static String[] as_fileExtensions; // Is always lower case... |
741 |
10 Oct 06 |
olle |
113 |
public static String s_rootPath; |
741 |
10 Oct 06 |
olle |
114 |
public static MyHashTable myHT_runnableExtensions; |
741 |
10 Oct 06 |
olle |
115 |
public static MyHashTable myHT_allAliases; |
1652 |
22 May 07 |
gregory |
116 |
public static String[] as_xerverPasswd; |
741 |
10 Oct 06 |
olle |
117 |
public static boolean b_allowFolderListing; |
741 |
10 Oct 06 |
olle |
118 |
public static boolean b_allowTheseFileExtensions; |
741 |
10 Oct 06 |
olle |
119 |
public static boolean b_shareHiddenFiles; |
1652 |
22 May 07 |
gregory |
120 |
public static boolean b_startupWindowMode; // If this is true, no window |
2143 |
16 Oct 07 |
gregory |
// will be opened. If this is |
2143 |
16 Oct 07 |
gregory |
// false, the awt-window will be |
2143 |
16 Oct 07 |
gregory |
// used. NOTE: When you start |
2143 |
16 Oct 07 |
gregory |
// this class from the Swing |
2143 |
16 Oct 07 |
gregory |
// interface, this will be set |
2143 |
16 Oct 07 |
gregory |
// to true so that the |
2143 |
16 Oct 07 |
gregory |
// AWT-window won't popup //When |
2143 |
16 Oct 07 |
gregory |
// you call the |
2143 |
16 Oct 07 |
gregory |
// XerverKernel()-constructor |
2143 |
16 Oct 07 |
gregory |
// this varaiable will be set to |
2143 |
16 Oct 07 |
gregory |
// true/false depending on what |
2143 |
16 Oct 07 |
gregory |
// you have choosed in the |
2143 |
16 Oct 07 |
gregory |
// setup-file: true=[0=you have |
2143 |
16 Oct 07 |
gregory |
// choosen to run with no |
2143 |
16 Oct 07 |
gregory |
// "window"]; false=[1 = you |
2143 |
16 Oct 07 |
gregory |
// have choosen to use a static |
2143 |
16 Oct 07 |
gregory |
// window (AWT); 2 = you have |
2143 |
16 Oct 07 |
gregory |
// choosen to use the most |
2143 |
16 Oct 07 |
gregory |
// advanced interface (with |
2143 |
16 Oct 07 |
gregory |
// logging) (Swing)] |
741 |
10 Oct 06 |
olle |
141 |
public static boolean b_allowExecuteScript; |
741 |
10 Oct 06 |
olle |
142 |
public static String s_defaultRootLocationWithoutSlashAtEnd; |
1652 |
22 May 07 |
gregory |
143 |
public static boolean b_acceptConnections = true; |
1652 |
22 May 07 |
gregory |
144 |
private RunScript rs_process = null; |
2143 |
16 Oct 07 |
gregory |
145 |
private boolean b_environmentHasBeenSetUp, b_isRunningScript; |
2143 |
16 Oct 07 |
gregory |
146 |
/* |
2143 |
16 Oct 07 |
gregory |
* b_isRunningScript is used so we know if a script is being run. If a |
2143 |
16 Oct 07 |
gregory |
* script is being run, NewConnection shall not close the OutputStream, but |
2143 |
16 Oct 07 |
gregory |
* ReadInputStreamSTDERR/STDOUT shall close the stream. //b_isRunningScript |
2143 |
16 Oct 07 |
gregory |
* is also used to that if an exception occur so that the NewConnection |
2143 |
16 Oct 07 |
gregory |
* thread will terminate then we shall kill the script-process so that we |
2143 |
16 Oct 07 |
gregory |
* don't end up with for example 20 perl.exe processes running |
2143 |
16 Oct 07 |
gregory |
153 |
*/ |
741 |
10 Oct 06 |
olle |
154 |
private Date d_dateToday; |
741 |
10 Oct 06 |
olle |
155 |
private DateFormat df_dateFormat; |
2143 |
16 Oct 07 |
gregory |
156 |
private final static int i_maxLineLengthReadFromHeader = 512; |
2143 |
16 Oct 07 |
gregory |
157 |
/* |
2143 |
16 Oct 07 |
gregory |
* This can be set to anything you believe is suitable. This is to make sure |
2143 |
16 Oct 07 |
gregory |
* we don't read and buffer very long header-lines sent by browser (in case |
2143 |
16 Oct 07 |
gregory |
* a hacker would try to do this) private static HashMap HM_allFileExt; |
2143 |
16 Oct 07 |
gregory |
161 |
*/ |
1652 |
22 May 07 |
gregory |
162 |
public String s_errorStatus; // By default: "200 OK" |
1652 |
22 May 07 |
gregory |
163 |
private String s_requestedDocumentWithoutUnescape, // s_requestedDocumentWithoutUnescape |
2143 |
16 Oct 07 |
gregory |
// is only used when |
2143 |
16 Oct 07 |
gregory |
// someone visits |
2143 |
16 Oct 07 |
gregory |
// "http://server.com/folder" |
2143 |
16 Oct 07 |
gregory |
// and shall be |
2143 |
16 Oct 07 |
gregory |
// redirected to |
2143 |
16 Oct 07 |
gregory |
// "http://server.com/folder/". |
2143 |
16 Oct 07 |
gregory |
// This is a MUST when |
2143 |
16 Oct 07 |
gregory |
// the folder contains |
2143 |
16 Oct 07 |
gregory |
// for example the |
2143 |
16 Oct 07 |
gregory |
// swedish letters ���. |
1652 |
22 May 07 |
gregory |
// if someone visits "http://server.com/folder/folder2/file.txt" the |
1652 |
22 May 07 |
gregory |
// variables below will get these values: |
1652 |
22 May 07 |
gregory |
176 |
s_requestDocument, // "/folder/folder2/file.txt" |
1652 |
22 May 07 |
gregory |
177 |
s_requestedFolderLocation, // "/folder/folder2/" |
1652 |
22 May 07 |
gregory |
178 |
s_requestedFileName, // "file.txt" |
1652 |
22 May 07 |
gregory |
179 |
s_requestedFileExtension, // "txt" |
1652 |
22 May 07 |
gregory |
180 |
s_requestedFileType, // "text/plain" |
1652 |
22 May 07 |
gregory |
181 |
s_requestMethod, // For example: "GET", "POST" or "HEAD" |
1652 |
22 May 07 |
gregory |
182 |
s_requestedHTTP, // For example: "HTTP/1.1", "HTTP/1.0" or |
2143 |
16 Oct 07 |
gregory |
// "HTTP/0.9" |
1652 |
22 May 07 |
gregory |
184 |
s_requestQueryString, // "file.htm?hello" ==> "hello", otherwise |
2143 |
16 Oct 07 |
gregory |
// an empty string (""). |
1652 |
22 May 07 |
gregory |
186 |
s_loginRealm, // When a user enters a password, he is entering for |
2143 |
16 Oct 07 |
gregory |
// a whole realm |
1652 |
22 May 07 |
gregory |
188 |
s_encryptedPasswordGiven, // Format: "encryptedPassword" |
2143 |
16 Oct 07 |
gregory |
// (actually, it is "user:pass" but |
2143 |
16 Oct 07 |
gregory |
// encrypted) |
1652 |
22 May 07 |
gregory |
191 |
s_visitorUsername, // Note: the username for this login: |
2143 |
16 Oct 07 |
gregory |
// [user:Donald; pass:Duck] can be |
2143 |
16 Oct 07 |
gregory |
// "anOtherUsername" (it can of course also be |
2143 |
16 Oct 07 |
gregory |
// "Donald") |
1652 |
22 May 07 |
gregory |
195 |
s_hostnameGivenByBrowser = null; // The string sent by browser in |
2143 |
16 Oct 07 |
gregory |
// "Host:" header. |
2143 |
16 Oct 07 |
gregory |
197 |
private String[] as_variablesGivenByBrowser, as_allEnvironmentVariables; |
2143 |
16 Oct 07 |
gregory |
198 |
/* |
2143 |
16 Oct 07 |
gregory |
* For each and every time you are going to use any of these, call |
2143 |
16 Oct 07 |
gregory |
* "createEnvironmentVariables()" (after you have called |
2143 |
16 Oct 07 |
gregory |
* "createEnvironmentVariables()" once, you can call |
2143 |
16 Oct 07 |
gregory |
* "createEnvironmentVariables()" several times without wasteing system |
2143 |
16 Oct 07 |
gregory |
* resources (the first call does however "use system resources")) |
2143 |
16 Oct 07 |
gregory |
204 |
*/ |
741 |
10 Oct 06 |
olle |
205 |
private Socket so_userConnection; |
1652 |
22 May 07 |
gregory |
206 |
private boolean b_logThisHit = false, b_useKeepAlive, b_hasBeenRedirected; // reserved |
2143 |
16 Oct 07 |
gregory |
// path |
2143 |
16 Oct 07 |
gregory |
208 |
// ==> |
2143 |
16 Oct 07 |
gregory |
// "/Image:xxxX" |
741 |
10 Oct 06 |
olle |
210 |
private int i_valueOfHttpContentLength; |
741 |
10 Oct 06 |
olle |
211 |
private int i_fileStatus; |
1652 |
22 May 07 |
gregory |
212 |
private final static int ISFILE = 1; |
1652 |
22 May 07 |
gregory |
213 |
private final static int ISFOLDER = 2; |
1652 |
22 May 07 |
gregory |
214 |
private final static int DOESNOTEXISTS = 3; |
2143 |
16 Oct 07 |
gregory |
215 |
private final static int maxNumbersOfENVAccepted = 200; |
2143 |
16 Oct 07 |
gregory |
216 |
/* |
2143 |
16 Oct 07 |
gregory |
* Maximum number of environment variables the browser can tell us* to |
2143 |
16 Oct 07 |
gregory |
* create. (Note: We might have more than 200 environment variables; because |
2143 |
16 Oct 07 |
gregory |
* we don't only create environment variables that the browser tell us to |
2143 |
16 Oct 07 |
gregory |
* create). If a browser gives more than 200 environment variables, we just |
2143 |
16 Oct 07 |
gregory |
* ignore the last variables. |
2143 |
16 Oct 07 |
gregory |
222 |
*/ |
741 |
10 Oct 06 |
olle |
223 |
private DataInputStreamWithReadLine DISWR_theInputWeGetFromBrowser; |
1652 |
22 May 07 |
gregory |
224 |
private String tmpStr; // NOTE: this should be used as a temporary variable |
2143 |
16 Oct 07 |
gregory |
// when needed (for optimization purpose)... |
1652 |
22 May 07 |
gregory |
226 |
private static String s_defaultLoginName = "[No Login]"; |
1652 |
22 May 07 |
gregory |
227 |
private static String s_defaultRealmName = "[No Login]"; |
1652 |
22 May 07 |
gregory |
228 |
private static final String CONSTANT_POST = "POST"; // Optimization... |
1652 |
22 May 07 |
gregory |
229 |
private static final String CONSTANT_HEAD = "HEAD"; // We don't need to |
2143 |
16 Oct 07 |
gregory |
// create these all the |
2143 |
16 Oct 07 |
gregory |
// time... |
1652 |
22 May 07 |
gregory |
232 |
private static final String CONSTANT_HTTP09 = "HTTP/0.9"; |
1652 |
22 May 07 |
gregory |
233 |
private static final String CONSTANT_HTTP10 = "HTTP/1.0"; |
1652 |
22 May 07 |
gregory |
234 |
private static final String CONSTANT_HTTP11 = "HTTP/1.1"; |
1652 |
22 May 07 |
gregory |
235 |
private static final int DATATYPE_HEADONLY = 0; |
1652 |
22 May 07 |
gregory |
236 |
private static final int DATATYPE_BODYONLY = 1; |
1652 |
22 May 07 |
gregory |
237 |
private static final int DATATYPE_BODYANDHEAD = 2; |
741 |
10 Oct 06 |
olle |
238 |
private int i_sendWhatData; |
741 |
10 Oct 06 |
olle |
239 |
|
2143 |
16 Oct 07 |
gregory |
240 |
|
1652 |
22 May 07 |
gregory |
241 |
public NewConnection(Socket agrUserConnection, ThreadGroup argThreadGroup)// throws |
2143 |
16 Oct 07 |
gregory |
// IOException |
741 |
10 Oct 06 |
olle |
243 |
{ |
1652 |
22 May 07 |
gregory |
244 |
super(argThreadGroup, "Connection"); |
1652 |
22 May 07 |
gregory |
// crateHashTableWithFileExtensions(); |
741 |
10 Oct 06 |
olle |
246 |
initEverything(agrUserConnection); |
741 |
10 Oct 06 |
olle |
247 |
} |
741 |
10 Oct 06 |
olle |
248 |
|
2143 |
16 Oct 07 |
gregory |
249 |
|
2143 |
16 Oct 07 |
gregory |
250 |
private void initEverything(Socket agrUserConnection) |
2143 |
16 Oct 07 |
gregory |
251 |
{ |
2143 |
16 Oct 07 |
gregory |
252 |
try |
2143 |
16 Oct 07 |
gregory |
253 |
{ |
1652 |
22 May 07 |
gregory |
254 |
so_userConnection = agrUserConnection; |
1652 |
22 May 07 |
gregory |
255 |
if (!b_acceptConnections) |
1652 |
22 May 07 |
gregory |
256 |
so_userConnection.close(); |
1652 |
22 May 07 |
gregory |
/* Init.. */ |
1652 |
22 May 07 |
gregory |
258 |
b_hasBeenRedirected = false; |
1652 |
22 May 07 |
gregory |
259 |
b_useKeepAlive = true; |
1652 |
22 May 07 |
gregory |
260 |
b_environmentHasBeenSetUp = false; |
1652 |
22 May 07 |
gregory |
261 |
b_isRunningScript = false; |
1652 |
22 May 07 |
gregory |
262 |
s_loginRealm = s_defaultRealmName; |
1652 |
22 May 07 |
gregory |
263 |
s_visitorUsername = s_defaultLoginName; |
1652 |
22 May 07 |
gregory |
264 |
if (myMenuOptions != null) |
1652 |
22 May 07 |
gregory |
265 |
b_logThisHit = true; // Only log hits when running in swing |
2143 |
16 Oct 07 |
gregory |
// mode... |
1652 |
22 May 07 |
gregory |
267 |
i_valueOfHttpContentLength = 0; |
1652 |
22 May 07 |
gregory |
268 |
i_fileStatus = -1; |
1652 |
22 May 07 |
gregory |
269 |
i_sendWhatData = DATATYPE_BODYANDHEAD; |
1652 |
22 May 07 |
gregory |
/* End Init... */ |
1652 |
22 May 07 |
gregory |
271 |
d_dateToday = new Date(); |
1652 |
22 May 07 |
gregory |
272 |
df_dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, |
2143 |
16 Oct 07 |
gregory |
273 |
DateFormat.LONG); |
1652 |
22 May 07 |
gregory |
274 |
s_errorStatus = "200 OK"; // By default the request is successful. |
2143 |
16 Oct 07 |
gregory |
275 |
} |
2143 |
16 Oct 07 |
gregory |
276 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
277 |
{ |
1652 |
22 May 07 |
gregory |
278 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
279 |
System.out.println("An error occured @ NewConnection:\n" + e |
2143 |
16 Oct 07 |
gregory |
280 |
.getMessage()); |
1652 |
22 May 07 |
gregory |
281 |
} |
741 |
10 Oct 06 |
olle |
282 |
} |
741 |
10 Oct 06 |
olle |
283 |
|
2143 |
16 Oct 07 |
gregory |
284 |
|
2386 |
14 Nov 07 |
gregory |
285 |
@Override |
2143 |
16 Oct 07 |
gregory |
286 |
public void run() |
2143 |
16 Oct 07 |
gregory |
287 |
{ |
2143 |
16 Oct 07 |
gregory |
288 |
try |
2143 |
16 Oct 07 |
gregory |
289 |
{ |
1652 |
22 May 07 |
gregory |
290 |
s_requestedHTTP = null; |
1652 |
22 May 07 |
gregory |
291 |
s_requestMethod = null; |
1652 |
22 May 07 |
gregory |
292 |
s_requestDocument = null; |
741 |
10 Oct 06 |
olle |
293 |
readHeaderSentByBrowser(); |
2143 |
16 Oct 07 |
gregory |
294 |
if (s_requestedHTTP == null || s_requestMethod == null || s_requestDocument == null) |
2143 |
16 Oct 07 |
gregory |
295 |
{ |
1652 |
22 May 07 |
gregory |
296 |
s_requestDocument = "/"; // Set this to something... don't |
2143 |
16 Oct 07 |
gregory |
// matters to what. This will be |
2143 |
16 Oct 07 |
gregory |
// sent together with the header for |
2143 |
16 Oct 07 |
gregory |
// the "400 Bad Request". |
1652 |
22 May 07 |
gregory |
300 |
b_logThisHit = false; |
1652 |
22 May 07 |
gregory |
301 |
s_errorStatus = "400 Bad Request"; |
1652 |
22 May 07 |
gregory |
302 |
showError("The client has sent an invalid request.", |
2143 |
16 Oct 07 |
gregory |
303 |
errorFilesFolder, "error400badrequest.html"); |
741 |
10 Oct 06 |
olle |
304 |
} |
1652 |
22 May 07 |
gregory |
305 |
setLocationParts(s_requestDocument, |
2143 |
16 Oct 07 |
gregory |
306 |
s_defaultRootLocationWithoutSlashAtEnd);// you MUST run |
2143 |
16 Oct 07 |
gregory |
// "readHeaderSentByBrowser();" |
2143 |
16 Oct 07 |
gregory |
// before you run |
2143 |
16 Oct 07 |
gregory |
// this line! |
741 |
10 Oct 06 |
olle |
310 |
initializeRequestedFileExtension(); |
1652 |
22 May 07 |
gregory |
311 |
if (b_hasBeenRedirected) // IMPORTANT: This is especially |
2143 |
16 Oct 07 |
gregory |
// important to make sure that a |
2143 |
16 Oct 07 |
gregory |
// password protected folder wont be |
2143 |
16 Oct 07 |
gregory |
// listed when entering "GET |
2143 |
16 Oct 07 |
gregory |
// /secretFolderWITHOUTslashAtEnd |
2143 |
16 Oct 07 |
gregory |
// HTTP/1.1"! Without this the server |
2143 |
16 Oct 07 |
gregory |
// first sends the 302 Redirected |
2143 |
16 Oct 07 |
gregory |
// header, and then the listing of the |
2143 |
16 Oct 07 |
gregory |
// folder (which won't be listed with a |
2143 |
16 Oct 07 |
gregory |
// normal browser, as the 302-header is |
2143 |
16 Oct 07 |
gregory |
// sent first, but still, the hidden |
2143 |
16 Oct 07 |
gregory |
// data is being showed! (with this we |
2143 |
16 Oct 07 |
gregory |
// have prevented this scenario)) |
741 |
10 Oct 06 |
olle |
324 |
{ |
1652 |
22 May 07 |
gregory |
// Do nothing... The user has already been redirected |
1652 |
22 May 07 |
gregory |
326 |
}// Some paths are "reserved", such as "/Image:showFolder"... |
2143 |
16 Oct 07 |
gregory |
// //s_requestDocument has to be set when you run |
2143 |
16 Oct 07 |
gregory |
// checkForReservedPaths |
2143 |
16 Oct 07 |
gregory |
329 |
else if (checkForReservedPaths()) |
2143 |
16 Oct 07 |
gregory |
330 |
{ |
1652 |
22 May 07 |
gregory |
// "checkForReservedPaths()" will show the image automatically |
2143 |
16 Oct 07 |
gregory |
332 |
} |
2143 |
16 Oct 07 |
gregory |
333 |
else if (!accessToFolderIsOK(s_requestedFolderLocation)) |
2143 |
16 Oct 07 |
gregory |
334 |
{ |
1652 |
22 May 07 |
gregory |
335 |
s_errorStatus = "401 Not Authorized"; |
741 |
10 Oct 06 |
olle |
336 |
showAccessDenied(s_loginRealm); |
2143 |
16 Oct 07 |
gregory |
337 |
} |
2143 |
16 Oct 07 |
gregory |
338 |
else if (!isFolderAllowed(s_requestedFolderLocation)) |
2143 |
16 Oct 07 |
gregory |
339 |
{ |
1652 |
22 May 07 |
gregory |
340 |
s_errorStatus = "403 Forbidden"; |
1652 |
22 May 07 |
gregory |
341 |
showError( |
2143 |
16 Oct 07 |
gregory |
342 |
"You have tried to reach a folder you do not have permission to access (" + s_requestedFolderLocation + ").", |
2143 |
16 Oct 07 |
gregory |
343 |
errorFilesFolder, "error403noaccessfolder.html"); |
2143 |
16 Oct 07 |
gregory |
344 |
} |
2143 |
16 Oct 07 |
gregory |
345 |
else if (i_fileStatus == DOESNOTEXISTS) |
2143 |
16 Oct 07 |
gregory |
346 |
{ |
1652 |
22 May 07 |
gregory |
347 |
s_errorStatus = "404 Not Found"; |
1652 |
22 May 07 |
gregory |
348 |
showError("The file you have tried to reach doesn't exist.", |
2143 |
16 Oct 07 |
gregory |
349 |
errorFilesFolder, "error404filedoesnotexist.html"); |
2143 |
16 Oct 07 |
gregory |
350 |
} |
2143 |
16 Oct 07 |
gregory |
351 |
else if (s_requestedFileName.equals(""))// If you are visiting a |
2143 |
16 Oct 07 |
gregory |
// folder and there is |
2143 |
16 Oct 07 |
gregory |
// no index-file to |
2143 |
16 Oct 07 |
gregory |
// show... |
741 |
10 Oct 06 |
olle |
355 |
{ |
1652 |
22 May 07 |
gregory |
356 |
if (b_allowFolderListing) // If you are allowed to list the |
2143 |
16 Oct 07 |
gregory |
// content of this directory... |
741 |
10 Oct 06 |
olle |
358 |
showDirectorylisting(); |
2143 |
16 Oct 07 |
gregory |
359 |
else |
2143 |
16 Oct 07 |
gregory |
360 |
{ |
1652 |
22 May 07 |
gregory |
361 |
s_errorStatus = "403 Forbidden"; |
1652 |
22 May 07 |
gregory |
362 |
showError("Directory listing is not allowed.", |
2143 |
16 Oct 07 |
gregory |
363 |
errorFilesFolder, "error403nodirectorylisting.html"); |
741 |
10 Oct 06 |
olle |
364 |
} |
2143 |
16 Oct 07 |
gregory |
365 |
} |
2143 |
16 Oct 07 |
gregory |
366 |
else if (!isFileExtensionAllowed(s_requestedFileExtension)) |
2143 |
16 Oct 07 |
gregory |
367 |
{ |
1652 |
22 May 07 |
gregory |
368 |
s_errorStatus = "403 Forbidden"; |
1652 |
22 May 07 |
gregory |
369 |
showError( |
2143 |
16 Oct 07 |
gregory |
370 |
"You have tried to download a file with an extension that you are not allowed to download.", |
2143 |
16 Oct 07 |
gregory |
371 |
errorFilesFolder, "error403noaccessextension.html"); |
2143 |
16 Oct 07 |
gregory |
372 |
} |
2143 |
16 Oct 07 |
gregory |
373 |
else if (!accessToFileIsOK(s_requestedFolderLocation + s_requestedFileName)) |
2143 |
16 Oct 07 |
gregory |
374 |
{ |
1652 |
22 May 07 |
gregory |
375 |
s_errorStatus = "403 Forbidden"; |
1652 |
22 May 07 |
gregory |
376 |
showError( |
2143 |
16 Oct 07 |
gregory |
377 |
"Unfortunately, the web server couldn't read the requested file. If you are server admin, make sure the web server has read permission for the file.", |
2143 |
16 Oct 07 |
gregory |
378 |
errorFilesFolder, "error403webservercantreadfile.html"); |
2143 |
16 Oct 07 |
gregory |
379 |
} |
2143 |
16 Oct 07 |
gregory |
380 |
else if (!isHTTPrecognized(s_requestedHTTP)) |
2143 |
16 Oct 07 |
gregory |
381 |
{ |
1652 |
22 May 07 |
gregory |
382 |
s_errorStatus = "505 HTTP Version Not Supported"; |
2143 |
16 Oct 07 |
gregory |
383 |
showError( |
2143 |
16 Oct 07 |
gregory |
384 |
"Unfortunately, the web server doesn't support " + s_requestedHTTP + ".", |
2143 |
16 Oct 07 |
gregory |
385 |
errorFilesFolder, "error505unknownhttp.html"); |
2143 |
16 Oct 07 |
gregory |
386 |
} |
2143 |
16 Oct 07 |
gregory |
387 |
else |
2143 |
16 Oct 07 |
gregory |
388 |
{ |
1652 |
22 May 07 |
gregory |
389 |
returnThisPage(s_requestedFolderLocation + s_requestedFileName);// returnThisPage(s_requestDocument); |
741 |
10 Oct 06 |
olle |
390 |
} |
1652 |
22 May 07 |
gregory |
391 |
if (b_logThisHit) // Don't count when moving from "/folder" ==> |
2143 |
16 Oct 07 |
gregory |
// "/folder/" and don't count the reserved paths |
2143 |
16 Oct 07 |
gregory |
// (when the user is downloading an image while |
2143 |
16 Oct 07 |
gregory |
// listing the content in a directory) |
741 |
10 Oct 06 |
olle |
395 |
addThisHitToLog(); |
2143 |
16 Oct 07 |
gregory |
396 |
} |
2143 |
16 Oct 07 |
gregory |
397 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
398 |
{ |
1652 |
22 May 07 |
gregory |
399 |
if (b_showErrors) // Probably beacuse an invalid Header has been |
2143 |
16 Oct 07 |
gregory |
// sent |
1652 |
22 May 07 |
gregory |
401 |
System.out |
2143 |
16 Oct 07 |
gregory |
402 |
.println("An error occured @ run:\n" + e.getMessage()); |
2143 |
16 Oct 07 |
gregory |
403 |
}; |
2143 |
16 Oct 07 |
gregory |
404 |
try |
2143 |
16 Oct 07 |
gregory |
405 |
{ |
741 |
10 Oct 06 |
olle |
406 |
so_userConnection.getOutputStream().flush(); |
1652 |
22 May 07 |
gregory |
407 |
if (!b_isRunningScript) // If, and only if, we are NOT running a |
2143 |
16 Oct 07 |
gregory |
// script we shall use Keep-Alive. Otherwise |
2143 |
16 Oct 07 |
gregory |
// ReadInputStreamSTDERR/STDOUT should close |
2143 |
16 Oct 07 |
gregory |
// the stream. |
741 |
10 Oct 06 |
olle |
411 |
{ |
1652 |
22 May 07 |
gregory |
// yield();//Do I want this line or not?? |
1652 |
22 May 07 |
gregory |
// sleep(150); //Wait before we close the OutputStream so that |
1652 |
22 May 07 |
gregory |
// all data actually get sent before we close the OutputStream |
1652 |
22 May 07 |
gregory |
// so_userConnection.getOutputStream().close(); |
1652 |
22 May 07 |
gregory |
// so_userConnection.close(); |
1652 |
22 May 07 |
gregory |
// This is faster than closing the connection (without |
1652 |
22 May 07 |
gregory |
// Keep-Alive) */ |
2143 |
16 Oct 07 |
gregory |
419 |
if (b_useKeepAlive) |
2143 |
16 Oct 07 |
gregory |
420 |
{ |
741 |
10 Oct 06 |
olle |
421 |
initEverything(so_userConnection); |
741 |
10 Oct 06 |
olle |
422 |
run(); |
2143 |
16 Oct 07 |
gregory |
423 |
} |
2143 |
16 Oct 07 |
gregory |
424 |
else if (!b_isRunningScript) // IF [it isn't a script that |
2143 |
16 Oct 07 |
gregory |
// has been running (but an old |
2143 |
16 Oct 07 |
gregory |
// browser without |
2143 |
16 Oct 07 |
gregory |
// Keep-Alive)]... |
741 |
10 Oct 06 |
olle |
428 |
{ |
741 |
10 Oct 06 |
olle |
429 |
so_userConnection.getOutputStream().flush(); |
1652 |
22 May 07 |
gregory |
430 |
sleep(20); // Needed?? |
741 |
10 Oct 06 |
olle |
431 |
so_userConnection.getOutputStream().close(); |
741 |
10 Oct 06 |
olle |
432 |
} |
741 |
10 Oct 06 |
olle |
433 |
} |
1652 |
22 May 07 |
gregory |
434 |
} |
2143 |
16 Oct 07 |
gregory |
435 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
436 |
{}; |
741 |
10 Oct 06 |
olle |
437 |
} |
741 |
10 Oct 06 |
olle |
438 |
|
2143 |
16 Oct 07 |
gregory |
439 |
|
2143 |
16 Oct 07 |
gregory |
440 |
protected void addThisHitToLog() |
2143 |
16 Oct 07 |
gregory |
441 |
{ |
1652 |
22 May 07 |
gregory |
442 |
if (myMenuOptions != null) // IMPORTANT to make sure that this isn't |
2143 |
16 Oct 07 |
gregory |
// null as ReadInputStreamxxx can call this |
2143 |
16 Oct 07 |
gregory |
// method directly |
741 |
10 Oct 06 |
olle |
445 |
{ |
1652 |
22 May 07 |
gregory |
446 |
if (s_errorStatus.equals("200 OK")) // If the visitor has downloaded |
2143 |
16 Oct 07 |
gregory |
// correctly (for example: not a |
2143 |
16 Oct 07 |
gregory |
// "404 error" or a "redirect" |
2143 |
16 Oct 07 |
gregory |
// site) |
1652 |
22 May 07 |
gregory |
450 |
tmpStr = s_requestedFolderLocation + s_requestedFileName;// s_defaultRootLocationWithoutSlashAtEnd+s_requestedFolderLocationWithoutRoot+s_requestedFileName; |
741 |
10 Oct 06 |
olle |
451 |
else |
1652 |
22 May 07 |
gregory |
452 |
tmpStr = s_requestDocument; |
741 |
10 Oct 06 |
olle |
453 |
totalNumberOfHits++; |
1652 |
22 May 07 |
gregory |
454 |
myMenuOptions.addIPToList(new HitStatistic(so_userConnection |
2143 |
16 Oct 07 |
gregory |
455 |
.getInetAddress().getHostAddress() + "/" + so_userConnection |
2143 |
16 Oct 07 |
gregory |
456 |
.getInetAddress().getHostName(), s_errorStatus, tmpStr, |
2143 |
16 Oct 07 |
gregory |
457 |
new Date(System.currentTimeMillis()), s_requestedFileExtension, |
2143 |
16 Oct 07 |
gregory |
458 |
s_loginRealm, s_visitorUsername)); |
2143 |
16 Oct 07 |
gregory |
459 |
/* |
2143 |
16 Oct 07 |
gregory |
* Use intern to use less memory (it does really use less memory? I |
2143 |
16 Oct 07 |
gregory |
* hope so...) |
2143 |
16 Oct 07 |
gregory |
462 |
*/ |
741 |
10 Oct 06 |
olle |
463 |
myMenuOptions.statsHasBeenUpdated(); |
741 |
10 Oct 06 |
olle |
464 |
} |
741 |
10 Oct 06 |
olle |
465 |
} |
741 |
10 Oct 06 |
olle |
466 |
|
2143 |
16 Oct 07 |
gregory |
467 |
|
1652 |
22 May 07 |
gregory |
// The following variables will be set here: |
1652 |
22 May 07 |
gregory |
// s_requestedHTTP |
1652 |
22 May 07 |
gregory |
// s_requestMethod |
1652 |
22 May 07 |
gregory |
// s_requestDocument |
2143 |
16 Oct 07 |
gregory |
472 |
private void readHeaderSentByBrowser() |
2143 |
16 Oct 07 |
gregory |
473 |
{ |
2143 |
16 Oct 07 |
gregory |
474 |
try |
2143 |
16 Oct 07 |
gregory |
475 |
{ |
741 |
10 Oct 06 |
olle |
476 |
String firstLineIndata; |
1652 |
22 May 07 |
gregory |
// ##########################READ INFORMATION GIVEN BY |
1652 |
22 May 07 |
gregory |
// BROWSER#################### |
1652 |
22 May 07 |
gregory |
// NOTE: |
1652 |
22 May 07 |
gregory |
// The first line in the Header-data that the browser sends is: |
1652 |
22 May 07 |
gregory |
// "GET /folder/file.txt HTTP/1.1" |
1652 |
22 May 07 |
gregory |
// However, if you run the command "lynx myserver.com", Lynx |
1652 |
22 May 07 |
gregory |
// establishes two connections. |
1652 |
22 May 07 |
gregory |
// The first one sends this first line header: |
1652 |
22 May 07 |
gregory |
// "GET /folder/ HTTP/1.0" |
1652 |
22 May 07 |
gregory |
// The second time it sends this line, which is a HTTP/0.9-syntax: |
1652 |
22 May 07 |
gregory |
// "GET /folder/" |
741 |
10 Oct 06 |
olle |
488 |
// |
1652 |
22 May 07 |
gregory |
// Also beware, a request for a folder such as "/dir with space/" is |
1652 |
22 May 07 |
gregory |
// sent as: |
1652 |
22 May 07 |
gregory |
// "GET /dir with space/ HTTP/1.0" |
1652 |
22 May 07 |
gregory |
// and then (which also is a HTTP/0.9-syntax): |
1652 |
22 May 07 |
gregory |
// "GET /dir with space/" |
741 |
10 Oct 06 |
olle |
494 |
// |
1652 |
22 May 07 |
gregory |
// Note, no headers shall be sent when a HTTP/0.9 request is |
1652 |
22 May 07 |
gregory |
// received, a valid request/response might be: |
1652 |
22 May 07 |
gregory |
// "GET /foo.txt" |
1652 |
22 May 07 |
gregory |
// "This is a one-line file." |
741 |
10 Oct 06 |
olle |
499 |
// |
1652 |
22 May 07 |
gregory |
// But Xerver don't care about this and sends an valid |
1652 |
22 May 07 |
gregory |
// HTTP/1.1-response to a HTTP/0.9-request. |
1652 |
22 May 07 |
gregory |
// The reason for this is that (for example) Lynx sends |
1652 |
22 May 07 |
gregory |
// HTTP/0.9-requests, despite it understands HTTP/1.1-responses. |
1652 |
22 May 07 |
gregory |
504 |
DISWR_theInputWeGetFromBrowser = new DataInputStreamWithReadLine( |
2143 |
16 Oct 07 |
gregory |
505 |
so_userConnection.getInputStream()); |
1652 |
22 May 07 |
gregory |
506 |
firstLineIndata = DISWR_theInputWeGetFromBrowser |
2143 |
16 Oct 07 |
gregory |
507 |
.myReadLine(i_maxLineLengthReadFromHeader * 10); |
2143 |
16 Oct 07 |
gregory |
508 |
/* |
2143 |
16 Oct 07 |
gregory |
* "GET /mapp/fil.txt HTTP/1.1" //i_maxLineLengthReadFromHeader*4 |
2143 |
16 Oct 07 |
gregory |
* can be anything that you believe is long enough to store an URL |
2143 |
16 Oct 07 |
gregory |
* and the GET-data which might come with it, but not so long that a |
2143 |
16 Oct 07 |
gregory |
* hacker would try to use all our memory by sending a very large |
2143 |
16 Oct 07 |
gregory |
* string System.out.println("READ: "+firstLineIndata); |
2143 |
16 Oct 07 |
gregory |
514 |
*/ |
1652 |
22 May 07 |
gregory |
515 |
int firstLineIndataIndexOfSpace = firstLineIndata.indexOf(" "); // Optimization... |
1652 |
22 May 07 |
gregory |
516 |
int firstLineIndataLastIndexOfSpace = firstLineIndata |
2143 |
16 Oct 07 |
gregory |
517 |
.lastIndexOf(" "); // Optimization... |
1652 |
22 May 07 |
gregory |
518 |
if (firstLineIndataIndexOfSpace != firstLineIndataLastIndexOfSpace) // There |
2143 |
16 Oct 07 |
gregory |
// are |
2143 |
16 Oct 07 |
gregory |
// two |
2143 |
16 Oct 07 |
gregory |
521 |
// " " |
2143 |
16 Oct 07 |
gregory |
// in |
2143 |
16 Oct 07 |
gregory |
// firstLineIndata |
741 |
10 Oct 06 |
olle |
524 |
{ |
1652 |
22 May 07 |
gregory |
525 |
if (isHTTPFormatRecognized(firstLineIndata |
2143 |
16 Oct 07 |
gregory |
526 |
.substring(firstLineIndataLastIndexOfSpace + 1))) // If |
2143 |
16 Oct 07 |
gregory |
// firstLineIndata |
2143 |
16 Oct 07 |
gregory |
// ends |
2143 |
16 Oct 07 |
gregory |
// with |
2143 |
16 Oct 07 |
gregory |
// "HTTP/0.9", |
2143 |
16 Oct 07 |
gregory |
// "HTTP/1.0" |
2143 |
16 Oct 07 |
gregory |
// or |
2143 |
16 Oct 07 |
gregory |
// "HTTP/1.1" |
2143 |
16 Oct 07 |
gregory |
// //(everything |
2143 |
16 Oct 07 |
gregory |
// is |
2143 |
16 Oct 07 |
gregory |
// correct) |
741 |
10 Oct 06 |
olle |
537 |
{ |
1652 |
22 May 07 |
gregory |
538 |
s_requestedDocumentWithoutUnescape = removeEncodedNullCharFromString(firstLineIndata |
2143 |
16 Oct 07 |
gregory |
539 |
.substring(firstLineIndataIndexOfSpace + 1, |
2143 |
16 Oct 07 |
gregory |
540 |
firstLineIndataLastIndexOfSpace)); |
1652 |
22 May 07 |
gregory |
541 |
s_requestMethod = firstLineIndata.substring(0, |
2143 |
16 Oct 07 |
gregory |
542 |
firstLineIndataIndexOfSpace); |
1652 |
22 May 07 |
gregory |
543 |
s_requestDocument = MyString |
2143 |
16 Oct 07 |
gregory |
544 |
.unescape(s_requestedDocumentWithoutUnescape); |
1652 |
22 May 07 |
gregory |
545 |
s_requestedHTTP = firstLineIndata.substring( |
2143 |
16 Oct 07 |
gregory |
546 |
firstLineIndataLastIndexOfSpace + 1).toUpperCase(); |
2143 |
16 Oct 07 |
gregory |
547 |
} |
2143 |
16 Oct 07 |
gregory |
548 |
else |
2143 |
16 Oct 07 |
gregory |
// A request such as "GET /dir with space/" has been |
2143 |
16 Oct 07 |
gregory |
// made (probably by lynx, but might also happen with |
2143 |
16 Oct 07 |
gregory |
// other browsers, don't know) |
741 |
10 Oct 06 |
olle |
552 |
{ |
1652 |
22 May 07 |
gregory |
553 |
s_requestedDocumentWithoutUnescape = removeEncodedNullCharFromString(firstLineIndata |
2143 |
16 Oct 07 |
gregory |
554 |
.substring(firstLineIndataIndexOfSpace + 1)); |
1652 |
22 May 07 |
gregory |
555 |
s_requestMethod = firstLineIndata.substring(0, |
2143 |
16 Oct 07 |
gregory |
556 |
firstLineIndataIndexOfSpace); |
1652 |
22 May 07 |
gregory |
557 |
s_requestDocument = MyString |
2143 |
16 Oct 07 |
gregory |
558 |
.unescape(s_requestedDocumentWithoutUnescape); |
1652 |
22 May 07 |
gregory |
559 |
s_requestedHTTP = CONSTANT_HTTP10; // Set this to anything |
2143 |
16 Oct 07 |
gregory |
// you want, it doesn't |
2143 |
16 Oct 07 |
gregory |
// matter... |
741 |
10 Oct 06 |
olle |
562 |
} |
2143 |
16 Oct 07 |
gregory |
563 |
} |
2143 |
16 Oct 07 |
gregory |
564 |
else |
2143 |
16 Oct 07 |
gregory |
// Lynx sometimes sends a stupid request like "GET /", which |
2143 |
16 Oct 07 |
gregory |
// will result in... (This is a valid HTTP/0.9-syntax, but I |
2143 |
16 Oct 07 |
gregory |
// have only seen Lynx be using it) |
741 |
10 Oct 06 |
olle |
568 |
{ |
1652 |
22 May 07 |
gregory |
569 |
s_requestedDocumentWithoutUnescape = removeEncodedNullCharFromString(firstLineIndata |
2143 |
16 Oct 07 |
gregory |
570 |
.substring(firstLineIndataIndexOfSpace + 1)); |
1652 |
22 May 07 |
gregory |
571 |
s_requestMethod = firstLineIndata.substring(0, |
2143 |
16 Oct 07 |
gregory |
572 |
firstLineIndataIndexOfSpace); |
1652 |
22 May 07 |
gregory |
573 |
s_requestDocument = MyString |
2143 |
16 Oct 07 |
gregory |
574 |
.unescape(s_requestedDocumentWithoutUnescape); |
1652 |
22 May 07 |
gregory |
575 |
s_requestedHTTP = CONSTANT_HTTP09; // Set this to anything you |
2143 |
16 Oct 07 |
gregory |
// want, it doesn't |
2143 |
16 Oct 07 |
gregory |
// matter... |
741 |
10 Oct 06 |
olle |
578 |
} |
2143 |
16 Oct 07 |
gregory |
579 |
if (!s_requestedHTTP.equals(CONSTANT_HTTP11)) |
2143 |
16 Oct 07 |
gregory |
580 |
{ |
1652 |
22 May 07 |
gregory |
581 |
b_useKeepAlive = false; |
2143 |
16 Oct 07 |
gregory |
582 |
if (s_requestedHTTP.equals(CONSTANT_HTTP09)) |
2143 |
16 Oct 07 |
gregory |
583 |
{ |
1652 |
22 May 07 |
gregory |
584 |
i_sendWhatData = DATATYPE_BODYONLY; |
741 |
10 Oct 06 |
olle |
585 |
} |
741 |
10 Oct 06 |
olle |
586 |
} |
2143 |
16 Oct 07 |
gregory |
587 |
s_requestDocument = s_requestDocument.trim(); |
2143 |
16 Oct 07 |
gregory |
588 |
/* |
2143 |
16 Oct 07 |
gregory |
* "/folder/ " ==> "/folder/" (This line is in case someone makes a |
2143 |
16 Oct 07 |
gregory |
* request such as "GET /folder/ HTTP/1.0", which would result in |
2143 |
16 Oct 07 |
gregory |
* that the s_requestMethod=="/folder/ ", which is incorrect) |
2143 |
16 Oct 07 |
gregory |
592 |
*/ |
1652 |
22 May 07 |
gregory |
593 |
if (s_requestMethod.toUpperCase().indexOf(CONSTANT_POST) != -1) |
1652 |
22 May 07 |
gregory |
594 |
s_requestMethod = CONSTANT_POST; |
2143 |
16 Oct 07 |
gregory |
595 |
else if (s_requestMethod.toUpperCase().indexOf(CONSTANT_HEAD) != -1) |
2143 |
16 Oct 07 |
gregory |
596 |
{ |
1652 |
22 May 07 |
gregory |
597 |
i_sendWhatData = DATATYPE_HEADONLY; |
1652 |
22 May 07 |
gregory |
598 |
s_requestMethod = CONSTANT_HEAD; |
2143 |
16 Oct 07 |
gregory |
599 |
} |
2143 |
16 Oct 07 |
gregory |
600 |
else |
1652 |
22 May 07 |
gregory |
601 |
s_requestMethod = "GET"; |
1652 |
22 May 07 |
gregory |
602 |
s_requestQueryString = ""; |
1652 |
22 May 07 |
gregory |
603 |
int requestDocumentIndexOfQuestion = s_requestDocument.indexOf("?"); |
1652 |
22 May 07 |
gregory |
604 |
if (requestDocumentIndexOfQuestion != -1) // "mapp1/mapp2/fil.htm?hejsan" |
2143 |
16 Oct 07 |
gregory |
605 |
// ==> |
2143 |
16 Oct 07 |
gregory |
// "mapp1/mapp2/fil.htm" |
741 |
10 Oct 06 |
olle |
607 |
{ |
1652 |
22 May 07 |
gregory |
608 |
s_requestQueryString = s_requestDocument |
2143 |
16 Oct 07 |
gregory |
609 |
.substring(requestDocumentIndexOfQuestion + 1); |
1652 |
22 May 07 |
gregory |
610 |
s_requestDocument = s_requestDocument.substring(0, |
2143 |
16 Oct 07 |
gregory |
611 |
requestDocumentIndexOfQuestion); |
741 |
10 Oct 06 |
olle |
612 |
} |
2143 |
16 Oct 07 |
gregory |
613 |
} |
2143 |
16 Oct 07 |
gregory |
614 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
615 |
{ |
1652 |
22 May 07 |
gregory |
// System.out.println("DIED!!!"); |
2143 |
16 Oct 07 |
gregory |
617 |
try |
2143 |
16 Oct 07 |
gregory |
618 |
{ |
741 |
10 Oct 06 |
olle |
619 |
so_userConnection.close(); |
741 |
10 Oct 06 |
olle |
620 |
/* |
1652 |
22 May 07 |
gregory |
* s_requestDocument="/"; //Set this to something... don't |
1652 |
22 May 07 |
gregory |
* matters to what. This will be sent together with the header |
1652 |
22 May 07 |
gregory |
* for the "400 Bad Request". b_logThisHit=false; |
1652 |
22 May 07 |
gregory |
* s_errorStatus="400 Bad Request"; showError("The client has |
1652 |
22 May 07 |
gregory |
* sent an invalid |
1652 |
22 May 07 |
gregory |
* request.",errorFilesFolder,"error400badrequest.html"); |
1652 |
22 May 07 |
gregory |
627 |
*/ |
1652 |
22 May 07 |
gregory |
628 |
} |
2143 |
16 Oct 07 |
gregory |
629 |
catch (Exception exc) |
2143 |
16 Oct 07 |
gregory |
630 |
{} |
1652 |
22 May 07 |
gregory |
631 |
if (b_showErrors) // Probably beacuse an invalid Header has been |
2143 |
16 Oct 07 |
gregory |
// sent |
1652 |
22 May 07 |
gregory |
633 |
System.out |
2143 |
16 Oct 07 |
gregory |
634 |
.println("An error occured @ readHeaderSentByBrowser:\n" + e |
2143 |
16 Oct 07 |
gregory |
635 |
.getMessage()); |
741 |
10 Oct 06 |
olle |
636 |
} |
741 |
10 Oct 06 |
olle |
637 |
} |
741 |
10 Oct 06 |
olle |
638 |
|
2143 |
16 Oct 07 |
gregory |
639 |
|
1652 |
22 May 07 |
gregory |
// From Opera: |
1652 |
22 May 07 |
gregory |
// GET /?y4errewfdpp HTTP/1.1 |
1652 |
22 May 07 |
gregory |
// User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0 [sv] |
1652 |
22 May 07 |
gregory |
// Host: localhost:12345 |
1652 |
22 May 07 |
gregory |
// Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */* |
1652 |
22 May 07 |
gregory |
// Accept-Language: sv |
1652 |
22 May 07 |
gregory |
// Accept-Charset: windows-1252;q=1.0, utf-8;q=1.0, utf-16;q=1.0, |
1652 |
22 May 07 |
gregory |
// iso-8859-1;q=0.6, *;q=0.1 |
1652 |
22 May 07 |
gregory |
// Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0 |
1652 |
22 May 07 |
gregory |
// Cache-Control: no-cache |
1652 |
22 May 07 |
gregory |
// Connection: Keep-Alive, TE |
1652 |
22 May 07 |
gregory |
// TE: deflate, gzip, chunked, identity, trailers |
1652 |
22 May 07 |
gregory |
private void setLocationParts(String relativePath, |
2143 |
16 Oct 07 |
gregory |
String rootLocationWithoutSlashAtEnd) |
2143 |
16 Oct 07 |
gregory |
654 |
{ |
741 |
10 Oct 06 |
olle |
String s_fileOrFolderThatIsReadOnHardDrive; |
1652 |
22 May 07 |
gregory |
String fileExtension = "", folderLocation = "", fileName = ""; |
741 |
10 Oct 06 |
olle |
File thisFolder; |
741 |
10 Oct 06 |
olle |
int sizeOfAliasName; |
1652 |
22 May 07 |
gregory |
int fileStatus = -1; |
1652 |
22 May 07 |
gregory |
sizeOfAliasName = myHT_allAliases.giveBiggestKeySize(relativePath); // gives |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// size |
2143 |
16 Oct 07 |
gregory |
// of |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// alias |
2143 |
16 Oct 07 |
gregory |
// name... |
2143 |
16 Oct 07 |
gregory |
// ("/alias/folder/file.txt" |
2143 |
16 Oct 07 |
gregory |
668 |
// ==> |
2143 |
16 Oct 07 |
gregory |
// "7") |
1652 |
22 May 07 |
gregory |
// ##############Start giving values to the variables############## |
1652 |
22 May 07 |
gregory |
if (sizeOfAliasName == -1) // You are not visiting an alias |
741 |
10 Oct 06 |
olle |
672 |
{ |
2143 |
16 Oct 07 |
gregory |
s_fileOrFolderThatIsReadOnHardDrive = rootLocationWithoutSlashAtEnd + relativePath |
2143 |
16 Oct 07 |
gregory |
.replace('/', File.separatorChar); |
2143 |
16 Oct 07 |
gregory |
675 |
} |
2143 |
16 Oct 07 |
gregory |
else |
2143 |
16 Oct 07 |
gregory |
// you are visiting an alias |
1652 |
22 May 07 |
gregory |
678 |
{ |
1652 |
22 May 07 |
gregory |
s_fileOrFolderThatIsReadOnHardDrive = getCorrectFolderFromAlias(relativePath |
2143 |
16 Oct 07 |
gregory |
.substring(0, sizeOfAliasName)) + relativePath.substring( |
2143 |
16 Oct 07 |
gregory |
sizeOfAliasName).replace('/', File.separatorChar); |
741 |
10 Oct 06 |
olle |
682 |
} |
1652 |
22 May 07 |
gregory |
thisFolder = new File(s_fileOrFolderThatIsReadOnHardDrive); |
2143 |
16 Oct 07 |
gregory |
if (thisFolder.exists()) |
2143 |
16 Oct 07 |
gregory |
685 |
{ |
2143 |
16 Oct 07 |
gregory |
if (thisFolder.isFile() && !relativePath.endsWith("/")) |
2143 |
16 Oct 07 |
gregory |
687 |
{ |
1652 |
22 May 07 |
gregory |
fileStatus = ISFILE; |
1652 |
22 May 07 |
gregory |
folderLocation = s_fileOrFolderThatIsReadOnHardDrive.substring( |
2143 |
16 Oct 07 |
gregory |
0, s_fileOrFolderThatIsReadOnHardDrive |
2143 |
16 Oct 07 |
gregory |
.lastIndexOf(File.separatorChar) + 1); |
1652 |
22 May 07 |
gregory |
fileName = s_fileOrFolderThatIsReadOnHardDrive |
2143 |
16 Oct 07 |
gregory |
.substring(s_fileOrFolderThatIsReadOnHardDrive |
2143 |
16 Oct 07 |
gregory |
.lastIndexOf(File.separatorChar) + 1); |
2143 |
16 Oct 07 |
gregory |
while (fileName.endsWith(".")) |
2143 |
16 Oct 07 |
gregory |
696 |
{ |
1652 |
22 May 07 |
gregory |
fileName = fileName.substring(0, fileName.length() - 1); |
1652 |
22 May 07 |
gregory |
} // "script.pl..." ==> "script.pl" (since Xerver consider |
2143 |
16 Oct 07 |
gregory |
// "script.pl..." to be the filename (and null is the file |
2143 |
16 Oct 07 |
gregory |
// extension), but the file system will show the content of |
2143 |
16 Oct 07 |
gregory |
// "script.pl" when xerver asks for the content of |
2143 |
16 Oct 07 |
gregory |
// "script.pl...", so you can see source code of arbitrary |
2143 |
16 Oct 07 |
gregory |
// script file) |
1652 |
22 May 07 |
gregory |
fileExtension = fileName |
2143 |
16 Oct 07 |
gregory |
.substring(fileName.lastIndexOf('.') + 1); |
2143 |
16 Oct 07 |
gregory |
706 |
} |
2143 |
16 Oct 07 |
gregory |
else if (thisFolder.isDirectory()) |
2143 |
16 Oct 07 |
gregory |
708 |
{ |
1652 |
22 May 07 |
gregory |
fileStatus = ISFOLDER; |
1652 |
22 May 07 |
gregory |
folderLocation = s_fileOrFolderThatIsReadOnHardDrive; |
1652 |
22 May 07 |
gregory |
fileName = giveNameOfIndexFile(folderLocation); // Returns the |
2143 |
16 Oct 07 |
gregory |
// name of the |
2143 |
16 Oct 07 |
gregory |
// correct |
2143 |
16 Oct 07 |
gregory |
// index-file, |
2143 |
16 Oct 07 |
gregory |
// if there is |
2143 |
16 Oct 07 |
gregory |
// any. |
2143 |
16 Oct 07 |
gregory |
// Otherwise |
2143 |
16 Oct 07 |
gregory |
// this returns |
2143 |
16 Oct 07 |
gregory |
719 |
// "" |
1652 |
22 May 07 |
gregory |
fileExtension = ""; |
2143 |
16 Oct 07 |
gregory |
721 |
} |
2143 |
16 Oct 07 |
gregory |
else |
2143 |
16 Oct 07 |
gregory |
// someone is visiting "/folder/fileExists.txt/". |
2143 |
16 Oct 07 |
gregory |
// thisFolder.exists() tells this is a file, but as the |
2143 |
16 Oct 07 |
gregory |
// visitor did request "/folder/fileExists.txt/" (and not |
2143 |
16 Oct 07 |
gregory |
// "/folder/fileExists.txt") we pretend the file doesn't |
2143 |
16 Oct 07 |
gregory |
// exists |
741 |
10 Oct 06 |
olle |
728 |
{ |
1652 |
22 May 07 |
gregory |
fileStatus = DOESNOTEXISTS; |
1652 |
22 May 07 |
gregory |
folderLocation = s_fileOrFolderThatIsReadOnHardDrive; |
1652 |
22 May 07 |
gregory |
fileName = ""; |
1652 |
22 May 07 |
gregory |
fileExtension = ""; |
741 |
10 Oct 06 |
olle |
733 |
} |
2143 |
16 Oct 07 |
gregory |
734 |
} |
2143 |
16 Oct 07 |
gregory |
else |
2143 |
16 Oct 07 |
gregory |
736 |
{ |
1652 |
22 May 07 |
gregory |
fileStatus = DOESNOTEXISTS; |
1652 |
22 May 07 |
gregory |
folderLocation = s_fileOrFolderThatIsReadOnHardDrive; |
1652 |
22 May 07 |
gregory |
fileName = ""; |
1652 |
22 May 07 |
gregory |
fileExtension = ""; |
741 |
10 Oct 06 |
olle |
741 |
} |
1652 |
22 May 07 |
gregory |
// ##############At this line, all variables shall have been |
1652 |
22 May 07 |
gregory |
// set############## |
1652 |
22 May 07 |
gregory |
// Finally, set the local variables to the global variables |
1652 |
22 May 07 |
gregory |
s_requestedFolderLocation = folderLocation; |
1652 |
22 May 07 |
gregory |
s_requestedFileName = fileName; |
1652 |
22 May 07 |
gregory |
s_requestedFileExtension = fileExtension; |
1652 |
22 May 07 |
gregory |
i_fileStatus = fileStatus; |
2143 |
16 Oct 07 |
gregory |
if (fileStatus == ISFOLDER && !s_requestDocument.endsWith("/")) |
2143 |
16 Oct 07 |
gregory |
750 |
/* |
2143 |
16 Oct 07 |
gregory |
* If [Visiting a folder] AND [the URL entered does NOT end with "/" ], |
2143 |
16 Oct 07 |
gregory |
* then... //NOTE: You CAN'T change "s_requestDocument" to |
2143 |
16 Oct 07 |
gregory |
* "relativePath". (reason: lets say you visit |
2143 |
16 Oct 07 |
gregory |
* "http://server.com/alias" (relativePath=="/alias"), and this |
2143 |
16 Oct 07 |
gregory |
* doesn't match any file/folder on the hard drive, then we check |
2143 |
16 Oct 07 |
gregory |
* with relativePath+"/" (relativePath=="/alias/")) |
2143 |
16 Oct 07 |
gregory |
757 |
*/ |
1652 |
22 May 07 |
gregory |
758 |
redirectToItselfWithSlash(); // If location is |
2143 |
16 Oct 07 |
gregory |
// "http://server.com/folder" ==> |
2143 |
16 Oct 07 |
gregory |
// "http://server.com/folder/" |
2143 |
16 Oct 07 |
gregory |
761 |
if (fileStatus == DOESNOTEXISTS && !relativePath.endsWith("/")) |
2143 |
16 Oct 07 |
gregory |
762 |
/* |
2143 |
16 Oct 07 |
gregory |
* If [the file/folder doesn't exists] AND [the URL entered does NOT |
2143 |
16 Oct 07 |
gregory |
* end with "/" ], then... //(reason for this check: lets say you |
2143 |
16 Oct 07 |
gregory |
* visit "http://server.com/alias" (relativePath=="/alias"), and |
2143 |
16 Oct 07 |
gregory |
* this doesn't match any file/folder on the hard drive, then we |
2143 |
16 Oct 07 |
gregory |
* check with relativePath+"/" (relativePath=="/alias/")) |
2143 |
16 Oct 07 |
gregory |
768 |
*/ |
1652 |
22 May 07 |
gregory |
769 |
setLocationParts(relativePath + "/", rootLocationWithoutSlashAtEnd); |
741 |
10 Oct 06 |
olle |
770 |
} |
741 |
10 Oct 06 |
olle |
771 |
|
2143 |
16 Oct 07 |
gregory |
772 |
|
1652 |
22 May 07 |
gregory |
773 |
private String getCorrectFolderFromAlias(String theAlias) // If no alias |
2143 |
16 Oct 07 |
gregory |
// is found |
2143 |
16 Oct 07 |
gregory |
// returns null, |
2143 |
16 Oct 07 |
gregory |
// otherwise the |
2143 |
16 Oct 07 |
gregory |
// path given by |
2143 |
16 Oct 07 |
gregory |
// the alias. |
741 |
10 Oct 06 |
olle |
779 |
{ |
1652 |
22 May 07 |
gregory |
780 |
tmpStr = myHT_allAliases.giveValueByIndex(theAlias); |
1652 |
22 May 07 |
gregory |
781 |
if (tmpStr == null) |
741 |
10 Oct 06 |
olle |
782 |
return null; |
2143 |
16 Oct 07 |
gregory |
783 |
else |
2143 |
16 Oct 07 |
gregory |
784 |
{ |
741 |
10 Oct 06 |
olle |
785 |
return tmpStr; |
741 |
10 Oct 06 |
olle |
786 |
} |
741 |
10 Oct 06 |
olle |
787 |
} |
741 |
10 Oct 06 |
olle |
788 |
|
2143 |
16 Oct 07 |
gregory |
789 |
|
2143 |
16 Oct 07 |
gregory |
790 |
private String removeEncodedNullCharFromString(String str) |
2143 |
16 Oct 07 |
gregory |
791 |
{ |
741 |
10 Oct 06 |
olle |
792 |
int i_indexOfNull = str.indexOf("%00"); |
1652 |
22 May 07 |
gregory |
793 |
if (i_indexOfNull != -1) // Someone has added "%00" to the URL: |
2143 |
16 Oct 07 |
gregory |
// "/folder/%00/" should be ==> "/folder/" |
741 |
10 Oct 06 |
olle |
795 |
{ |
1652 |
22 May 07 |
gregory |
796 |
return str.substring(0, i_indexOfNull); |
741 |
10 Oct 06 |
olle |
797 |
} |
741 |
10 Oct 06 |
olle |
798 |
return str; |
741 |
10 Oct 06 |
olle |
799 |
} |
741 |
10 Oct 06 |
olle |
800 |
|
2143 |
16 Oct 07 |
gregory |
801 |
|
1652 |
22 May 07 |
gregory |
802 |
private String[] getEnvironmentVariablesGivenByBrowser( |
2143 |
16 Oct 07 |
gregory |
803 |
DataInputStreamWithReadLine theInput) |
2143 |
16 Oct 07 |
gregory |
804 |
{ |
1652 |
22 May 07 |
gregory |
805 |
String[] allENVVariablesTMP = new String[maxNumbersOfENVAccepted], allENVVariables = new String[0]; |
2143 |
16 Oct 07 |
gregory |
806 |
try |
2143 |
16 Oct 07 |
gregory |
807 |
{ |
1652 |
22 May 07 |
gregory |
808 |
String tmp; |
1652 |
22 May 07 |
gregory |
809 |
int numberOfENVGivenByBrowser = 0; // This is the number of |
2143 |
16 Oct 07 |
gregory |
// ENV-variables we set after we |
2143 |
16 Oct 07 |
gregory |
// have read what the browser |
2143 |
16 Oct 07 |
gregory |
// has given us. For example |
2143 |
16 Oct 07 |
gregory |
// both CONTENT_TYPE and |
2143 |
16 Oct 07 |
gregory |
// HTTP_CONTENT_TYPE are set |
2143 |
16 Oct 07 |
gregory |
// when we have read |
2143 |
16 Oct 07 |
gregory |
// "CONTENT_TYPE". The number of |
2143 |
16 Oct 07 |
gregory |
// lines given to us from the |
2143 |
16 Oct 07 |
gregory |
// browser is not necessey (and |
2143 |
16 Oct 07 |
gregory |
// probably not) |
2143 |
16 Oct 07 |
gregory |
// ==numberOfENVGivenByBrowser |
1652 |
22 May 07 |
gregory |
821 |
String tmpStr = "_"; // Set this to any none-empty string (!="") |
2143 |
16 Oct 07 |
gregory |
// (don't set it to null) |
2143 |
16 Oct 07 |
gregory |
823 |
while (numberOfENVGivenByBrowser < maxNumbersOfENVAccepted - 1) |
2143 |
16 Oct 07 |
gregory |
824 |
/* |
2143 |
16 Oct 07 |
gregory |
* (assume: maxNumbersOfENVAccepted=200) less than 199 because it is |
2143 |
16 Oct 07 |
gregory |
* possible to run "numberOfENVGivenByBrowser++" twice in this loop. |
2143 |
16 Oct 07 |
gregory |
* (If we start the loop with 199 and run |
2143 |
16 Oct 07 |
gregory |
* "numberOfENVGivenByBrowser++" twice we will try to write to index |
2143 |
16 Oct 07 |
gregory |
* 200 (no, not 201; reason: we don't have |
2143 |
16 Oct 07 |
gregory |
* "++numberOfENVGivenByBrowser"), but the last index of the array |
2143 |
16 Oct 07 |
gregory |
* is 199 ==> exception is thrown!!!). |
2143 |
16 Oct 07 |
gregory |
832 |
*/ |
741 |
10 Oct 06 |
olle |
833 |
{ |
1652 |
22 May 07 |
gregory |
// First I only had the |
1652 |
22 May 07 |
gregory |
// "tmpStr=br_theInputWeGetFromBrowser.readLine();" line here, |
1652 |
22 May 07 |
gregory |
// and it worked OK. But after a while I saw I sometimes got |
1652 |
22 May 07 |
gregory |
// problems: "tmpStr=br_theInputWeGetFromBrowser.readLine();" |
1652 |
22 May 07 |
gregory |
// did never quit, the Thread had stopped here. I don't know for |
1652 |
22 May 07 |
gregory |
// sure, but the reason might be that the browser never sends a |
1652 |
22 May 07 |
gregory |
// "\n" or "\r" at the end of the line, so it never becomes a |
1652 |
22 May 07 |
gregory |
// "line". However, now we instead read |
1652 |
22 May 07 |
gregory |
// "i_valueOfHttpContentLength" from the stream after we have |
1652 |
22 May 07 |
gregory |
// read one empty line (==""). This seems to work without any |
1652 |
22 May 07 |
gregory |
// problems. //(BTW: the problem occured after I had implemented |
1652 |
22 May 07 |
gregory |
// the "401 Not Authorized"-support (so the browser sends a |
1652 |
22 May 07 |
gregory |
// "AUTHORIZATION=Basic enctyptedPass" line now). Is it possible |
1652 |
22 May 07 |
gregory |
// this has anything to do with that the browser doesn't send an |
1652 |
22 May 07 |
gregory |
// \n after the POST-data? (Did the browser send a \n after the |
1652 |
22 May 07 |
gregory |
// POST-data before this?) I don't know... :/ ) |
1652 |
22 May 07 |
gregory |
850 |
if (!tmpStr.equals("")) // If this is not the empty line before |
2143 |
16 Oct 07 |
gregory |
// the POST-line |
1652 |
22 May 07 |
gregory |
852 |
tmpStr = DISWR_theInputWeGetFromBrowser |
2143 |
16 Oct 07 |
gregory |
853 |
.myReadLine(i_maxLineLengthReadFromHeader); |
1652 |
22 May 07 |
gregory |
854 |
else if (i_valueOfHttpContentLength != 0) // This is the empty |
2143 |
16 Oct 07 |
gregory |
// line before the |
2143 |
16 Oct 07 |
gregory |
// POST-line |
1652 |
22 May 07 |
gregory |
857 |
{ |
1652 |
22 May 07 |
gregory |
// Next line is the POST-data |
1652 |
22 May 07 |
gregory |
// // Was used before: |
1652 |
22 May 07 |
gregory |
// // char[] cbuf=new char[i_valueOfHttpContentLength]; |
1652 |
22 May 07 |
gregory |
// // br_theInputWeGetFromBrowser.read( cbuf, 0, |
1652 |
22 May 07 |
gregory |
// i_valueOfHttpContentLength); |
1652 |
22 May 07 |
gregory |
// // b_STDINDataFromPOSTIsAvailable=true; |
1652 |
22 May 07 |
gregory |
864 |
break; // We have read everything we want to read |
2143 |
16 Oct 07 |
gregory |
865 |
} |
2143 |
16 Oct 07 |
gregory |
866 |
else |
1652 |
22 May 07 |
gregory |
// This happenes if there is no "CONTENT_LENGTH"-line in the |
1652 |
22 May 07 |
gregory |
// browser request. So this won't happen with a valid |
1652 |
22 May 07 |
gregory |
// browser... |
1652 |
22 May 07 |
gregory |
870 |
break; // We have read everything we want to read |
2143 |
16 Oct 07 |
gregory |
871 |
if (tmpStr != null) |
2143 |
16 Oct 07 |
gregory |
872 |
{ |
1652 |
22 May 07 |
gregory |
873 |
if (tmpStr.indexOf(":") != -1) // If the line read really |
2143 |
16 Oct 07 |
gregory |
// is a line such as |
2143 |
16 Oct 07 |
gregory |
// "HTTP_Connection: |
2143 |
16 Oct 07 |
gregory |
// Keep-Alive". Otherwise |
2143 |
16 Oct 07 |
gregory |
// this is the empty line |
2143 |
16 Oct 07 |
gregory |
// before the POST-line |
1652 |
22 May 07 |
gregory |
879 |
{ |
1652 |
22 May 07 |
gregory |
// "tmpStr" has this format: "CONTENT_LENGTH=65" (after |
1652 |
22 May 07 |
gregory |
// the line below has been run) |
1652 |
22 May 07 |
gregory |
882 |
String tmpEnvVarName = tmpStr.substring(0, |
2143 |
16 Oct 07 |
gregory |
883 |
tmpStr.indexOf(":")).toUpperCase() |
2143 |
16 Oct 07 |
gregory |
884 |
.replace('-', '_'); |
1652 |
22 May 07 |
gregory |
885 |
String tmpEnvVarValue = tmpStr.substring( |
2143 |
16 Oct 07 |
gregory |
886 |
tmpStr.indexOf(":") + 1).trim(); |
1652 |
22 May 07 |
gregory |
887 |
tmpStr = tmpEnvVarName + "=" + tmpEnvVarValue; |
2143 |
16 Oct 07 |
gregory |
888 |
allENVVariablesTMP[numberOfENVGivenByBrowser++] = "HTTP_" + tmpStr; |
1652 |
22 May 07 |
gregory |
// System.out.println("HEADER FROM BROWSER: "+tmpStr); |
2143 |
16 Oct 07 |
gregory |
890 |
if (tmpEnvVarName.equals("CONTENT_LENGTH")) |
2143 |
16 Oct 07 |
gregory |
891 |
{ |
1652 |
22 May 07 |
gregory |
892 |
allENVVariablesTMP[numberOfENVGivenByBrowser++] = tmpStr; |
1652 |
22 May 07 |
gregory |
893 |
i_valueOfHttpContentLength = Integer |
2143 |
16 Oct 07 |
gregory |
894 |
.parseInt(tmpEnvVarValue); // ...Save the |
2143 |
16 Oct 07 |
gregory |
// length of the |
2143 |
16 Oct 07 |
gregory |
// POST data |
2143 |
16 Oct 07 |
gregory |
897 |
} |
2143 |
16 Oct 07 |
gregory |
898 |
else if (tmpEnvVarName.equals("HOST")) |
2143 |
16 Oct 07 |
gregory |
899 |
{ |
1652 |
22 May 07 |
gregory |
900 |
s_hostnameGivenByBrowser = tmpEnvVarValue; |
2143 |
16 Oct 07 |
gregory |
901 |
} |
2143 |
16 Oct 07 |
gregory |
902 |
else if (tmpEnvVarName.equals("CONTENT_TYPE")) |
2143 |
16 Oct 07 |
gregory |
903 |
{ |
1652 |
22 May 07 |
gregory |
904 |
allENVVariablesTMP[numberOfENVGivenByBrowser++] = tmpStr; |
2143 |
16 Oct 07 |
gregory |
905 |
} |
2143 |
16 Oct 07 |
gregory |
906 |
else if (tmpEnvVarName.equals("AUTHORIZATION")) |
2143 |
16 Oct 07 |
gregory |
907 |
{ |
1652 |
22 May 07 |
gregory |
908 |
s_encryptedPasswordGiven = tmpStr.substring(tmpStr |
2143 |
16 Oct 07 |
gregory |
909 |
.indexOf("=Basic ") + ("=Basic ".length())); // Format: |
2143 |
16 Oct 07 |
gregory |
// "encryptedPassword" |
2143 |
16 Oct 07 |
gregory |
// (actually, it |
2143 |
16 Oct 07 |
gregory |
// is |
2143 |
16 Oct 07 |
gregory |
// "user:pass" |
2143 |
16 Oct 07 |
gregory |
// encrypted) |
1652 |
22 May 07 |
gregory |
915 |
} |
1652 |
22 May 07 |
gregory |
// else if (tmpStr.startsWith("COOKIE=")) |
1652 |
22 May 07 |
gregory |
// s_cookiesFromBrowser=tmpStr.substring("COOKIE=".length()); |
1652 |
22 May 07 |
gregory |
// //We don't need this |
741 |
10 Oct 06 |
olle |
919 |
} |
1652 |
22 May 07 |
gregory |
// Next 5 lines not in use anymore; was in use: |
1652 |
22 May 07 |
gregory |
// else if (s_requestMethod.equals(CONSTANT_POST) && |
1652 |
22 May 07 |
gregory |
// !tmpStr.equals("")) //If, and only if, a POST-request has |
1652 |
22 May 07 |
gregory |
// been made there is POST-data to read... (If tmpStr is |
1652 |
22 May 07 |
gregory |
// empty we are at the empty line before the POST-data |
1652 |
22 May 07 |
gregory |
925 |
// { |
1652 |
22 May 07 |
gregory |
// s_stdinDataForPOSTRequests=tmpStr.substring(0,i_valueOfHttpContentLength); |
1652 |
22 May 07 |
gregory |
// //Guaranty that "s_stdinDataForPOSTRequests" doesn't |
1652 |
22 May 07 |
gregory |
// contain more than "i_valueOfHttpContentLength" chars |
1652 |
22 May 07 |
gregory |
// break; //With a correct request, this is not necessey, as |
1652 |
22 May 07 |
gregory |
// the POST-lien data is the last one |
1652 |
22 May 07 |
gregory |
931 |
// } |
741 |
10 Oct 06 |
olle |
932 |
} |
741 |
10 Oct 06 |
olle |
933 |
} |
1652 |
22 May 07 |
gregory |
934 |
allENVVariables = new String[numberOfENVGivenByBrowser]; |
1652 |
22 May 07 |
gregory |
935 |
/* |
1652 |
22 May 07 |
gregory |
* for (int i=0; i<numberOfENVGivenByBrowser; i++) |
1652 |
22 May 07 |
gregory |
* allENVVariables[i]=allENVVariablesTMP[i]; |
1652 |
22 May 07 |
gregory |
938 |
*/ |
1652 |
22 May 07 |
gregory |
939 |
System.arraycopy(allENVVariablesTMP, 0, allENVVariables, 0, |
2143 |
16 Oct 07 |
gregory |
940 |
numberOfENVGivenByBrowser); |
1652 |
22 May 07 |
gregory |
// List all ENV from browser: |
1652 |
22 May 07 |
gregory |
// for (int i=0; i<numberOfENVGivenByBrowser; i++) |
1652 |
22 May 07 |
gregory |
// System.out.println("data "+allENVVariables[i]); |
1652 |
22 May 07 |
gregory |
// From Opera: |
1652 |
22 May 07 |
gregory |
// GET /?y4errewfdpp HTTP/1.1 |
1652 |
22 May 07 |
gregory |
// User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera |
1652 |
22 May 07 |
gregory |
// 6.0 [sv] |
1652 |
22 May 07 |
gregory |
// Host: localhost:12345 |
1652 |
22 May 07 |
gregory |
// Accept: text/html, image/png, image/jpeg, image/gif, |
1652 |
22 May 07 |
gregory |
// image/x-xbitmap, */* |
1652 |
22 May 07 |
gregory |
// Accept-Language: sv |
1652 |
22 May 07 |
gregory |
// Accept-Charset: windows-1252;q=1.0, utf-8;q=1.0, utf-16;q=1.0, |
1652 |
22 May 07 |
gregory |
// iso-8859-1;q=0.6, *;q=0.1 |
1652 |
22 May 07 |
gregory |
// Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0 |
1652 |
22 May 07 |
gregory |
// Cache-Control: no-cache |
1652 |
22 May 07 |
gregory |
// Connection: Keep-Alive, TE |
1652 |
22 May 07 |
gregory |
// TE: deflate, gzip, chunked, identity, trailers |
2143 |
16 Oct 07 |
gregory |
958 |
} |
2143 |
16 Oct 07 |
gregory |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
960 |
{ |
1652 |
22 May 07 |
gregory |
if (b_showErrors) |
1652 |
22 May 07 |
gregory |
System.out |
2143 |
16 Oct 07 |
gregory |
.println("An error occured @ getEnvironmentVariablesGivenByBrowser:\n" + e |
2143 |
16 Oct 07 |
gregory |
.getMessage()); |
1652 |
22 May 07 |
gregory |
965 |
} |
1652 |
22 May 07 |
gregory |
return allENVVariables; |
741 |
10 Oct 06 |
olle |
967 |
} |
741 |
10 Oct 06 |
olle |
968 |
|
2143 |
16 Oct 07 |
gregory |
969 |
|
1652 |
22 May 07 |
gregory |
// s_requestDocument has to be set when you run checkForReservedPaths |
1652 |
22 May 07 |
gregory |
// Returns true if there is a reserved path, otherwise false |
2143 |
16 Oct 07 |
gregory |
private boolean checkForReservedPaths() |
2143 |
16 Oct 07 |
gregory |
973 |
{ |
2143 |
16 Oct 07 |
gregory |
if (s_requestDocument.equals("/Image:showFolder")) |
2143 |
16 Oct 07 |
gregory |
975 |
{ |
1652 |
22 May 07 |
gregory |
b_logThisHit = false; |
1652 |
22 May 07 |
gregory |
s_requestedFolderLocation = (new File(hiddenFolder)) |
2143 |
16 Oct 07 |
gregory |
.getAbsolutePath() + File.separator; |
1652 |
22 May 07 |
gregory |
s_requestedFileName = "imagefolder.gif"; |
1652 |
22 May 07 |
gregory |
s_requestedFileExtension = "gif"; |
1652 |
22 May 07 |
gregory |
returnThisPage(s_requestedFolderLocation + s_requestedFileName); |
741 |
10 Oct 06 |
olle |
return true; |
741 |
10 Oct 06 |
olle |
983 |
} |
2143 |
16 Oct 07 |
gregory |
if (s_requestDocument.equals("/Image:showFileicon")) |
2143 |
16 Oct 07 |
gregory |
985 |
{ |
1652 |
22 May 07 |
gregory |
b_logThisHit = false; |
1652 |
22 May 07 |
gregory |
s_requestedFolderLocation = (new File(hiddenFolder)) |
2143 |
16 Oct 07 |
gregory |
.getAbsolutePath() + File.separator; |
1652 |
22 May 07 |
gregory |
s_requestedFileName = "imagefileicon.gif"; |
1652 |
22 May 07 |
gregory |
s_requestedFileExtension = "gif"; |
1652 |
22 May 07 |
gregory |
returnThisPage(s_requestedFolderLocation + s_requestedFileName); |
741 |
10 Oct 06 |
olle |
return true; |
741 |
10 Oct 06 |
olle |
993 |
} |
1652 |
22 May 07 |
gregory |
return false; |
741 |
10 Oct 06 |
olle |
995 |
} |
741 |
10 Oct 06 |
olle |
996 |
|
2143 |
16 Oct 07 |
gregory |
997 |
|
1652 |
22 May 07 |
gregory |
private String[] getAllEnvironmentVariables() // Se |
2143 |
16 Oct 07 |
gregory |
// http://hoohoo.ncsa.uiuc.edu/cgi/env.html |
741 |
10 Oct 06 |
olle |
1000 |
{ |
1652 |
22 May 07 |
gregory |
String[] envVariables, envVariablesTMP; |
1652 |
22 May 07 |
gregory |
int variablesGivenByBrowserLength = as_variablesGivenByBrowser.length; |
2143 |
16 Oct 07 |
gregory |
int maxNumberOfEnvironmentVariables = maxNumbersOfENVAccepted + variablesGivenByBrowserLength; |
741 |
10 Oct 06 |
olle |
String s_tmpStr; |
1652 |
22 May 07 |
gregory |
envVariablesTMP = new String[maxNumberOfEnvironmentVariables]; |
741 |
10 Oct 06 |
olle |
1006 |
/* |
1652 |
22 May 07 |
gregory |
* for (;i<variablesGivenByBrowserLength; i++) //Optimization... { |
1652 |
22 May 07 |
gregory |
* envVariablesTMP[i]=as_variablesGivenByBrowser[i]; } |
1652 |
22 May 07 |
gregory |
1009 |
*/ |
1652 |
22 May 07 |
gregory |
1010 |
System.arraycopy(as_variablesGivenByBrowser, 0, envVariablesTMP, 0, |
2143 |
16 Oct 07 |
gregory |
1011 |
variablesGivenByBrowserLength); |
1652 |
22 May 07 |
gregory |
1012 |
int i = variablesGivenByBrowserLength; |
1652 |
22 May 07 |
gregory |
1013 |
s_tmpStr = System.getProperty("java.library.path", "."); // We set |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// default |
2143 |
16 Oct 07 |
gregory |
// value to |
2143 |
16 Oct 07 |
gregory |
// ".", in |
2143 |
16 Oct 07 |
gregory |
// case we |
2143 |
16 Oct 07 |
gregory |
// don't get |
2143 |
16 Oct 07 |
gregory |
// anything |
2143 |
16 Oct 07 |
gregory |
// from |
2143 |
16 Oct 07 |
gregory |
// "java.library.path" |
1652 |
22 May 07 |
gregory |
1023 |
envVariablesTMP[i++] = "PATH=" + s_tmpStr; |
1652 |
22 May 07 |
gregory |
1024 |
s_tmpStr = System.getProperty("systemroot"); |
2143 |
16 Oct 07 |
gregory |
1025 |
if (s_tmpStr != null) |
2143 |
16 Oct 07 |
gregory |
1026 |
{ |
2143 |
16 Oct 07 |
gregory |
1027 |
envVariablesTMP[i++] = "systemroot=" + s_tmpStr; |
2143 |
16 Oct 07 |
gregory |
1028 |
/* |
2143 |
16 Oct 07 |
gregory |
* Without this line we will get an error while using MySQL (I have |
2143 |
16 Oct 07 |
gregory |
* tried PHPBB with MySQL, and it said: "Warning: mysql_connect(): |
2143 |
16 Oct 07 |
gregory |
* Can't create TCP/IP socket (10106) in <b>d:\folder\file.php</b> |
2143 |
16 Oct 07 |
gregory |
* on line xxx") (For example "C:\\WINNT" as value) |
2143 |
16 Oct 07 |
gregory |
1033 |
*/ |
741 |
10 Oct 06 |
olle |
1034 |
} |
1652 |
22 May 07 |
gregory |
1035 |
s_tmpStr = System.getProperty("windir"); |
2143 |
16 Oct 07 |
gregory |
1036 |
if (s_tmpStr != null) |
2143 |
16 Oct 07 |
gregory |
1037 |
{ |
1652 |
22 May 07 |
gregory |
1038 |
envVariablesTMP[i++] = "windir=" + s_tmpStr; |
741 |
10 Oct 06 |
olle |
1039 |
} |
1652 |
22 May 07 |
gregory |
1040 |
s_tmpStr = System.getProperty("pathext"); |
2143 |
16 Oct 07 |
gregory |
1041 |
if (s_tmpStr != null) |
2143 |
16 Oct 07 |
gregory |
1042 |
{ |
1652 |
22 May 07 |
gregory |
1043 |
envVariablesTMP[i++] = "pathext=" + s_tmpStr; |
741 |
10 Oct 06 |
olle |
1044 |
} |
1652 |
22 May 07 |
gregory |
1045 |
s_tmpStr = System.getProperty("comspec"); |
2143 |
16 Oct 07 |
gregory |
1046 |
if (s_tmpStr != null) |
2143 |
16 Oct 07 |
gregory |
1047 |
{ |
1652 |
22 May 07 |
gregory |
1048 |
envVariablesTMP[i++] = "comspec=" + s_tmpStr; |
741 |
10 Oct 06 |
olle |
1049 |
} |
2143 |
16 Oct 07 |
gregory |
1050 |
if (s_hostnameGivenByBrowser == null) |
2143 |
16 Oct 07 |
gregory |
1051 |
{ |
2143 |
16 Oct 07 |
gregory |
1052 |
envVariablesTMP[i++] = "SERVER_NAME=" + HostInfo |
2143 |
16 Oct 07 |
gregory |
1053 |
.getLocalHostNameOrLocalhost();// XerverKernel.s_egetIp; |
2143 |
16 Oct 07 |
gregory |
1054 |
} |
2143 |
16 Oct 07 |
gregory |
1055 |
else |
2143 |
16 Oct 07 |
gregory |
1056 |
{ |
1652 |
22 May 07 |
gregory |
1057 |
envVariablesTMP[i++] = "SERVER_NAME=" + s_hostnameGivenByBrowser; |
741 |
10 Oct 06 |
olle |
1058 |
} |
1652 |
22 May 07 |
gregory |
1059 |
envVariablesTMP[i++] = "SERVER_SOFTWARE=" + s_replyServerName; |
1652 |
22 May 07 |
gregory |
1060 |
envVariablesTMP[i++] = "GATEWAY_INTERFACE=CGI/1.1"; |
1652 |
22 May 07 |
gregory |
1061 |
envVariablesTMP[i++] = "SERVER_PROTOCOL=" + s_requestedHTTP; |
1652 |
22 May 07 |
gregory |
1062 |
envVariablesTMP[i++] = "SERVER_PORT=" + i_portNr; |
1652 |
22 May 07 |
gregory |
1063 |
envVariablesTMP[i++] = "REQUEST_METHOD=" + s_requestMethod; |
1652 |
22 May 07 |
gregory |
1064 |
envVariablesTMP[i++] = "DOCUMENT_NAME=" + s_requestedFileName; |
1652 |
22 May 07 |
gregory |
1065 |
envVariablesTMP[i++] = "DOCUMENT_URI=" + s_requestDocument; |
1652 |
22 May 07 |
gregory |
1066 |
// ####################################### |
1652 |
22 May 07 |
gregory |
// ## For PHP 5 for Windows: |
1652 |
22 May 07 |
gregory |
// ## This is enough to run PHP scripts: |
1652 |
22 May 07 |
gregory |
// ## C:\>set |
1652 |
22 May 07 |
gregory |
// ## PATH=c:/program files/php |
1652 |
22 May 07 |
gregory |
// ## SCRIPT_FILENAME=C:\files\test.php |
1652 |
22 May 07 |
gregory |
// ## C:\>php-cgi |
1652 |
22 May 07 |
gregory |
// ## Content-type: text/html |
1652 |
22 May 07 |
gregory |
// ## X-Powered-By: PHP/5.0.3 |
1652 |
22 May 07 |
gregory |
1075 |
// ## |
1652 |
22 May 07 |
gregory |
// ## Hello World |
1652 |
22 May 07 |
gregory |
1077 |
// ####################################### |
1652 |
22 May 07 |
gregory |
1078 |
// ####################################### |
1652 |
22 May 07 |
gregory |
// ## For PHP 5 for Windows: |
1652 |
22 May 07 |
gregory |
// ## However, when we have the SERVER_NAME |
1652 |
22 May 07 |
gregory |
// ## variable we also need set the |
1652 |
22 May 07 |
gregory |
// ## REDIRECT_STATUS variable, |
1652 |
22 May 07 |
gregory |
// ## otherwise we get error ("Security Alert!"). |
1652 |
22 May 07 |
gregory |
// ## C:\>set |
1652 |
22 May 07 |
gregory |
// ## PATH=c:/program files/php |
1652 |
22 May 07 |
gregory |
// ## SCRIPT_FILENAME=C:\files\test.php |
1652 |
22 May 07 |
gregory |
// ## SERVER_NAME=Xerver |
1652 |
22 May 07 |
gregory |
// ## REDIRECT_STATUS=200 |
1652 |
22 May 07 |
gregory |
// ## C:\>php-cgi |
1652 |
22 May 07 |
gregory |
// ## Content-type: text/html |
1652 |
22 May 07 |
gregory |
// ## X-Powered-By: PHP/5.0.3 |
1652 |
22 May 07 |
gregory |
1092 |
// ## |
1652 |
22 May 07 |
gregory |
// ## Hello World |
1652 |
22 May 07 |
gregory |
1094 |
// ####################################### |
1652 |
22 May 07 |
gregory |
// EXAMPLE PATH_INFO: |
1652 |
22 May 07 |
gregory |
// http://server/dir/file.pl ==> "/dir/file.pl" |
1652 |
22 May 07 |
gregory |
// http://site.com/script.pl/extra/folder/ ==> "/extra/folder/" |
1652 |
22 May 07 |
gregory |
1098 |
envVariablesTMP[i++] = "PATH_INFO=" + s_requestDocument; |
1652 |
22 May 07 |
gregory |
// EXAMPLE PATH_TRANSLATED |
1652 |
22 May 07 |
gregory |
// http://server/dir/file.pl ==> "d:\root\path\dir\file.pl" |
1652 |
22 May 07 |
gregory |
// http://site.com/script.pl/extra/folder/ ==> |
1652 |
22 May 07 |
gregory |
// "/path/to/root/extra/folder/" |
2143 |
16 Oct 07 |
gregory |
1103 |
envVariablesTMP[i++] = "PATH_TRANSLATED=" + s_requestedFolderLocation + s_requestedFileName; |
1652 |
22 May 07 |
gregory |
// EXAMPLE SCRIPT_NAME |
1652 |
22 May 07 |
gregory |
// http://server/dir/file.pl ==> "/dir/file.pl" |
1652 |
22 May 07 |
gregory |
// http://site.com/script.pl/extra/folder/ ==> "/extra/folder/" |
1652 |
22 May 07 |
gregory |
1107 |
envVariablesTMP[i++] = "SCRIPT_NAME=" + s_requestDocument; |
1652 |
22 May 07 |
gregory |
// SCRIPT_FILENAME is what PHP uses to execute scripts. |
1652 |
22 May 07 |
gregory |
// SCRIPT_FILENAME can be c:\scripts\php\test.php |
1652 |
22 May 07 |
gregory |
// Without this we get "No input file specified.": |
2143 |
16 Oct 07 |
gregory |
1111 |
envVariablesTMP[i++] = "SCRIPT_FILENAME=" + s_requestedFolderLocation + s_requestedFileName; // The |
2143 |
16 Oct 07 |
gregory |
// local |
2143 |
16 Oct 07 |
gregory |
// path |
2143 |
16 Oct 07 |
gregory |
// to |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// script |
1652 |
22 May 07 |
gregory |
1117 |
envVariablesTMP[i++] = "QUERY_STRING=" + s_requestQueryString; |
2143 |
16 Oct 07 |
gregory |
1118 |
try |
2143 |
16 Oct 07 |
gregory |
1119 |
{ |
1652 |
22 May 07 |
gregory |
1120 |
s_tmpStr = so_userConnection.getInetAddress().getHostName(); |
2143 |
16 Oct 07 |
gregory |
1121 |
envVariablesTMP[i++] = "REMOTE_HOST=" + so_userConnection |
2143 |
16 Oct 07 |
gregory |
1122 |
.getInetAddress().getHostName(); |
2143 |
16 Oct 07 |
gregory |
1123 |
/* |
2143 |
16 Oct 07 |
gregory |
* "This variable is not set if the server failed to look up the |
2143 |
16 Oct 07 |
gregory |
* host name or skipped the lookup in the interest of speed." |
2143 |
16 Oct 07 |
gregory |
1126 |
*/ |
2143 |
16 Oct 07 |
gregory |
1127 |
} |
2143 |
16 Oct 07 |
gregory |
1128 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
1129 |
{} // Do nothing if we fail look up |
2143 |
16 Oct 07 |
gregory |
1130 |
envVariablesTMP[i++] = "REMOTE_ADDR=" + so_userConnection |
2143 |
16 Oct 07 |
gregory |
1131 |
.getInetAddress().getHostAddress();// .toString().substring(so_userConnection.getInetAddress().toString().indexOf("/")+1); |
1652 |
22 May 07 |
gregory |
1132 |
if (!s_visitorUsername.equals(s_defaultLoginName)) // visitor has not |
2143 |
16 Oct 07 |
gregory |
// visited a |
2143 |
16 Oct 07 |
gregory |
// password |
2143 |
16 Oct 07 |
gregory |
// protected folder |
741 |
10 Oct 06 |
olle |
1136 |
{ |
1652 |
22 May 07 |
gregory |
1137 |
envVariablesTMP[i++] = "AUTH_TYPE=Basic"; // "Contains the type of |
2143 |
16 Oct 07 |
gregory |
// authentication being |
2143 |
16 Oct 07 |
gregory |
// used to limit access |
2143 |
16 Oct 07 |
gregory |
// to the current |
2143 |
16 Oct 07 |
gregory |
// document. E.g. |
2143 |
16 Oct 07 |
gregory |
// "Basic" or "Digest". |
2143 |
16 Oct 07 |
gregory |
1143 |
// " |
2143 |
16 Oct 07 |
gregory |
1144 |
envVariablesTMP[i++] = "REMOTE_USER=" + s_visitorUsername; |
2143 |
16 Oct 07 |
gregory |
1145 |
/* |
2143 |
16 Oct 07 |
gregory |
* "REMOTE_USER is only set for pages in a directory or subdirectory |
2143 |
16 Oct 07 |
gregory |
* that's password-protected via a .htaccess file." |
2143 |
16 Oct 07 |
gregory |
1148 |
*/ |
741 |
10 Oct 06 |
olle |
1149 |
} |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="REMOTE_IDENT=aaaaa"; //"If the HTTP server |
1652 |
22 May 07 |
gregory |
// supports RFC 931 identification, then this variable will be set to |
1652 |
22 May 07 |
gregory |
// the remote user name retrieved from the server. Usage of this |
1652 |
22 May 07 |
gregory |
// variable should be limited to logging only." |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="CONTENT_TYPE=aaaaa"; //This will be set |
1652 |
22 May 07 |
gregory |
// automatically when POST has been used |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="CONTENT_LENGTH=aaaaa"; //This will be set |
1652 |
22 May 07 |
gregory |
// automatically when POST has been used |
1652 |
22 May 07 |
gregory |
1158 |
envVariablesTMP[i++] = "REDIRECT_STATUS=" + s_errorStatus; |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="redirect_status_env=0";//PHP STUFF!!!!! |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="PHP_DOCUMENT_ROOT=e:\\";//PHP STUFF!!!!! |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="DOCUMENT_ROOT=e:\\";//PHP STUFF!!!!! |
1652 |
22 May 07 |
gregory |
// envVariablesTMP[i++]="DOC_ROOT=e:\\";//PHP STUFF!!!!! |
1652 |
22 May 07 |
gregory |
// i now contains the number of environmentvariables that shall be set |
1652 |
22 May 07 |
gregory |
1164 |
envVariables = new String[i]; |
741 |
10 Oct 06 |
olle |
1165 |
/* |
1652 |
22 May 07 |
gregory |
* for (int k=0; k<i; k++) { envVariables[k]=envVariablesTMP[k]; |
1652 |
22 May 07 |
gregory |
* System.out.println(envVariables[k]); } |
1652 |
22 May 07 |
gregory |
1168 |
*/ |
741 |
10 Oct 06 |
olle |
1169 |
System.arraycopy(envVariablesTMP, 0, envVariables, 0, i); |
1652 |
22 May 07 |
gregory |
1170 |
return envVariables; |
741 |
10 Oct 06 |
olle |
1171 |
} |
741 |
10 Oct 06 |
olle |
1172 |
|
2143 |
16 Oct 07 |
gregory |
1173 |
|
1652 |
22 May 07 |
gregory |
1174 |
private void initializeRequestedFileExtension()// This MUST be called once |
2143 |
16 Oct 07 |
gregory |
// before the page is |
2143 |
16 Oct 07 |
gregory |
// showed, or the page won't |
2143 |
16 Oct 07 |
gregory |
// work with for example |
2143 |
16 Oct 07 |
gregory |
// Netscape 1 //You can |
2143 |
16 Oct 07 |
gregory |
// safely run |
2143 |
16 Oct 07 |
gregory |
// initializeRequestedFileExtension |
2143 |
16 Oct 07 |
gregory |
// more than once if you |
2143 |
16 Oct 07 |
gregory |
// want |
741 |
10 Oct 06 |
olle |
1183 |
{ |
1652 |
22 May 07 |
gregory |
1184 |
s_requestedFileExtension = s_requestedFileName |
2143 |
16 Oct 07 |
gregory |
1185 |
.substring(s_requestedFileName.lastIndexOf(".") + 1); |
2143 |
16 Oct 07 |
gregory |
1186 |
/* |
2143 |
16 Oct 07 |
gregory |
* If there is no file extension s_requestedFileExtension is the same as |
2143 |
16 Oct 07 |
gregory |
* the file name |
2143 |
16 Oct 07 |
gregory |
1189 |
*/ |
1652 |
22 May 07 |
gregory |
1190 |
s_requestedFileType = getMimeTypeFromFileExt(s_requestedFileExtension); |
741 |
10 Oct 06 |
olle |
1191 |
/* |
1652 |
22 May 07 |
gregory |
* s_requestedFileType=(String)HM_allFileExt.get(s_requestedFileExtension); |
1652 |
22 May 07 |
gregory |
* if (s_requestedFileType==null) { s_requestedFileType="text/html"; |
1652 |
22 May 07 |
gregory |
* //Default } |
1652 |
22 May 07 |
gregory |
1195 |
*/ |
741 |
10 Oct 06 |
olle |
1196 |
/* |
1652 |
22 May 07 |
gregory |
* //The most common types are at top... if |
1652 |
22 May 07 |
gregory |
* (s_requestedFileName.equals("")) s_requestedFileType="text/html"; |
1652 |
22 May 07 |
gregory |
* else if ( s_requestedFileExtension.equalsIgnoreCase("htm") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("shtml") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("html") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("shtm") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("asp")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/html"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("txt") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("text") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ini") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("c") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("cc") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("c++") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("h") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pl") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("java") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("webl") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("inf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/plain"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("jpeg") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("jpg") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("jpe")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/jpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("gif")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/gif"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("png")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/png"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("uu") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("exe")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ps")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/postscript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("zip")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/zip"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-shar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-tar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("au") || |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("snd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/basic"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("wav")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-wav"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xml")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/xml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("hqx")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/mac-binhex40"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("cpt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/mac-compactpro"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ai")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/postscript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("aif")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-aiff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("aifc")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-aiff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("aiff")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-aiff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("au")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/basic"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("avi")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/x-msvideo"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("bcpio")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-bcpio"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("bin")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("bmp")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-xbitmap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("cdf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-netcdf"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("class")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("cpio")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-cpio"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("cpt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/mac-compactpro"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("csh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-csh"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("css")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/css"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dcr")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-director"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dir")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-director"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dll")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dms")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("doc")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/msword"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dtd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/xml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dvi")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-dvi"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dwg")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("dxr")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-director"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("eps")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/postscript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("etx")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/x-setext"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("evy")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-envoy"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("exe")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("fif")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/fractals"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("fli")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("gl")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("gtar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-gtar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("gz")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-gzip"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("hdf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-hdf"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("hpx")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/mac-binhex40"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("hqx")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/mac-binhex40"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ice")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="x-conference/x-cooltalk"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ief")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/ief"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("iges")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/iges"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("igs")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/iges"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("isv")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="bws-internal/intrasrv-urlencoded"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("jfm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="bws-internal/intrasrv-form"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("jrp")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="bws-internal/intrasrv-report"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("js")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-javascript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("kar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/midi"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("latex")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-latex"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("lha")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ls")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-javascript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("lzh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("man")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff-man"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("me")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff-me"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mesh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/mesh"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mid")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/midi"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("midi")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/midi"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mif")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-mif"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mocha")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-javascript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mov")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/quicktime"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("movie")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/x-sgi-movie"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mp2")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mp3")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mpe")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mpeg")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mpg")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("mpga")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/mpeg"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ms")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff-ms"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("msh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/mesh"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("nc")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-netcdf"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("oda")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/oda"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pac")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-ns-proxy-autoconfig"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pbm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-portable-bitmap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pdb")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="chemical/x-pdb"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pdf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/pdf"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pgm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-portable-graymap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("php3")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-httpd-php3"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("phtml-msql2")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-httpd-php-msql2"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("phtml")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-httpd-php"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("pnm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-portable-anymap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ppm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-portable-pixmap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ppt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/powerpoint"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ps")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/postscript"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("qt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="video/quicktime"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ra")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-realaudio"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ram")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-pn-realaudio"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ras")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-cmu-raster"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("rgb")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-rgb"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("roff")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("rpm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/x-pn-realaudio-plugin"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("rtf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/rtf"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("rtx")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/richtext"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("scm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/octet-stream"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sgm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/x-sgml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sgml")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/x-sgml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sh")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-sh"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("shar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-shar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("silo")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/mesh"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sit")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/stuffit"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sit")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-stuffit"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("skd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-koan"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("skm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-koan"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("skp")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-koan"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("skt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-koan"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("snd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/basic"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("src")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-wais-source"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sv4cpio")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-sv4cpio"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("sv4crc")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-sv4crc"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("swf")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-shockwave-flash"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("t")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-tar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tcl")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-tcl"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tex")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-tex"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("texi")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-texinfo"; // else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("texi")) // |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-textinfo"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("texinfo")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-textinfo"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tif")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/tiff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tiff")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/tiff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tr")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-troff"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tsp")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/dsptype"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("tsv")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/tab-separated-values"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("txt")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/plain"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("ustar")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-ustar"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("vcd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-cdlink"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("vox")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="audio/voxware"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("vrml")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/vrml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("wrl")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="model/vrml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xbm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-xbitmap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xml")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/xml"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xpm")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-xpixmap"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xwd")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="image/x-xwindowdump"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("xyz")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="chemical/x-pdb"; else if ( |
1652 |
22 May 07 |
gregory |
* s_requestedFileExtension.equalsIgnoreCase("z")) |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="application/x-compress"; else |
1652 |
22 May 07 |
gregory |
* s_requestedFileType="text/plain"; |
1652 |
22 May 07 |
gregory |
1508 |
*/ |
741 |
10 Oct 06 |
olle |
1509 |
} |
741 |
10 Oct 06 |
olle |
1510 |
|
2143 |
16 Oct 07 |
gregory |
1511 |
|
2143 |
16 Oct 07 |
gregory |
1512 |
private boolean accessToFolderIsOK(String folder) |
2143 |
16 Oct 07 |
gregory |
1513 |
{ |
1652 |
22 May 07 |
gregory |
1514 |
String s_allUsersAndPasswords = null; |
1652 |
22 May 07 |
gregory |
1515 |
int longestPath = -1; // If the visitor is visiting "/abc/def/ghi/" |
2143 |
16 Oct 07 |
gregory |
// and we have password protected both "/abc/" |
2143 |
16 Oct 07 |
gregory |
// and "/abc/def/" only the password for |
2143 |
16 Oct 07 |
gregory |
// "/abc/def/" shall be asked. |
1652 |
22 May 07 |
gregory |
1519 |
if (folder == null) |
741 |
10 Oct 06 |
olle |
1520 |
return false; |
1652 |
22 May 07 |
gregory |
// We have removed this so we shall not receive a "401 not authorized" |
1652 |
22 May 07 |
gregory |
// error when someone tries to download |
1652 |
22 May 07 |
gregory |
// "http://www.sida.com/folder/../../secretfile.txt" |
1652 |
22 May 07 |
gregory |
// if (folder.indexOf("..")!=-1) //You have tried to reach a folder with |
1652 |
22 May 07 |
gregory |
// "http://www.sida.com/folder/../../secretfile.txt" |
1652 |
22 May 07 |
gregory |
// return false; |
1652 |
22 May 07 |
gregory |
1527 |
int xerverPasswdLength = as_xerverPasswd.length; // Optimization... |
1652 |
22 May 07 |
gregory |
1528 |
if (xerverPasswdLength == 0) // If we have no password protected |
2143 |
16 Oct 07 |
gregory |
// folders |
741 |
10 Oct 06 |
olle |
1530 |
return true; |
1652 |
22 May 07 |
gregory |
1531 |
for (int i = 0; i < xerverPasswdLength; i++) // Optimization... |
741 |
10 Oct 06 |
olle |
1532 |
{ |
1652 |
22 May 07 |
gregory |
// Format of as_xerverPasswd[i]: |
1652 |
22 May 07 |
gregory |
// "/path/to/folder/*=realmName=user1:pass1;user2:pass2" |
1652 |
22 May 07 |
gregory |
String tmpDir = as_xerverPasswd[i]; |
1652 |
22 May 07 |
gregory |
tmpDir = tmpDir.substring(0, tmpDir.indexOf("<<@>>")); // Format: |
2143 |
16 Oct 07 |
gregory |
// "/path/to/folder/*" |
1652 |
22 May 07 |
gregory |
if (tmpDir.endsWith("*")) // If you are allowed to view the |
2143 |
16 Oct 07 |
gregory |
// content of subfolders as well... (if |
2143 |
16 Oct 07 |
gregory |
// the name ends with an * |
2143 |
16 Oct 07 |
gregory |
// ("/mapp1/mapp2/*")) |
741 |
10 Oct 06 |
olle |
1542 |
{ |
1652 |
22 May 07 |
gregory |
if (tmpDir.regionMatches(true, 0, folder, 0, |
2143 |
16 Oct 07 |
gregory |
tmpDir.length() - 1)) // If [the first |
2143 |
16 Oct 07 |
gregory |
// "tmpDir.length()-1" |
2143 |
16 Oct 07 |
gregory |
// characters of the two strings |
2143 |
16 Oct 07 |
gregory |
// are equal (case |
2143 |
16 Oct 07 |
gregory |
// insensitive)]... |
741 |
10 Oct 06 |
olle |
1549 |
{ |
2143 |
16 Oct 07 |
gregory |
if (tmpDir.length() > longestPath) |
2143 |
16 Oct 07 |
gregory |
1551 |
/* |
2143 |
16 Oct 07 |
gregory |
* If the visitor is visiting "/abc/def/ghi/" and we have |
2143 |
16 Oct 07 |
gregory |
* password protected both "/abc/" and "/abc/def/" only the |
2143 |
16 Oct 07 |
gregory |
* password for "/abc/def/" shall be asked. |
2143 |
16 Oct 07 |
gregory |
1555 |
*/ |
741 |
10 Oct 06 |
olle |
1556 |
{ |
1652 |
22 May 07 |
gregory |
1557 |
String[] tmpPartOfInfo = MyString.makeArrayOfString( |
2143 |
16 Oct 07 |
gregory |
1558 |
as_xerverPasswd[i], "<<@>>"); |
1652 |
22 May 07 |
gregory |
1559 |
s_loginRealm = tmpPartOfInfo[1]; |
1652 |
22 May 07 |
gregory |
1560 |
s_allUsersAndPasswords = tmpPartOfInfo[2]; |
1652 |
22 May 07 |
gregory |
1561 |
longestPath = tmpDir.length() - 1; // "-1" because the |
2143 |
16 Oct 07 |
gregory |
// "*" in the end |
741 |
10 Oct 06 |
olle |
1563 |
} |
741 |
10 Oct 06 |
olle |
1564 |
} |
2143 |
16 Oct 07 |
gregory |
1565 |
} |
2143 |
16 Oct 07 |
gregory |
1566 |
else if (tmpDir.equalsIgnoreCase(folder)) |
2143 |
16 Oct 07 |
gregory |
1567 |
{ |
1652 |
22 May 07 |
gregory |
1568 |
if (tmpDir.length() > longestPath) // If the visitor is |
2143 |
16 Oct 07 |
gregory |
// visiting "/abc/def/ghi/" |
2143 |
16 Oct 07 |
gregory |
// and we have password |
2143 |
16 Oct 07 |
gregory |
// protected both "/abc/" |
2143 |
16 Oct 07 |
gregory |
// and "/abc/def/" only the |
2143 |
16 Oct 07 |
gregory |
// password for "/abc/def/" |
2143 |
16 Oct 07 |
gregory |
// shall be asked. |
741 |
10 Oct 06 |
olle |
1575 |
{ |
1652 |
22 May 07 |
gregory |
1576 |
String[] tmpPartOfInfo = MyString.makeArrayOfString( |
2143 |
16 Oct 07 |
gregory |
1577 |
as_xerverPasswd[i], "<<@>>"); |
1652 |
22 May 07 |
gregory |
1578 |
s_loginRealm = tmpPartOfInfo[1]; |
1652 |
22 May 07 |
gregory |
1579 |
s_allUsersAndPasswords = tmpPartOfInfo[2]; |
1652 |
22 May 07 |
gregory |
1580 |
longestPath = tmpDir.length(); |
741 |
10 Oct 06 |
olle |
1581 |
} |
741 |
10 Oct 06 |
olle |
1582 |
} |
741 |
10 Oct 06 |
olle |
1583 |
} |
2143 |
16 Oct 07 |
gregory |
1584 |
if (longestPath != -1) |
2143 |
16 Oct 07 |
gregory |
1585 |
{ |
1652 |
22 May 07 |
gregory |
1586 |
createEnvironmentVariables(false); // This will set |
2143 |
16 Oct 07 |
gregory |
// "s_encryptedPasswordGiven" |
1652 |
22 May 07 |
gregory |
1588 |
return passwordMatch(s_encryptedPasswordGiven, MyString |
2143 |
16 Oct 07 |
gregory |
1589 |
.makeArrayOfString(s_allUsersAndPasswords, ";")); |
2143 |
16 Oct 07 |
gregory |
1590 |
/* |
2143 |
16 Oct 07 |
gregory |
* The folder we are visiting is password protected, demand a |
2143 |
16 Oct 07 |
gregory |
* correct password to show this site |
2143 |
16 Oct 07 |
gregory |
1593 |
*/ |
2143 |
16 Oct 07 |
gregory |
1594 |
} |
2143 |
16 Oct 07 |
gregory |
1595 |
else |
1652 |
22 May 07 |
gregory |
1596 |
return true; // The folder we are visiting is not password |
2143 |
16 Oct 07 |
gregory |
// protected, allow this folder to be viewed |
741 |
10 Oct 06 |
olle |
1598 |
} |
741 |
10 Oct 06 |
olle |
1599 |
|
2143 |
16 Oct 07 |
gregory |
1600 |
|
2143 |
16 Oct 07 |
gregory |
1601 |
private boolean passwordMatch(String passWord, String[] allUsersAndPasswords) |
2143 |
16 Oct 07 |
gregory |
1602 |
{ // Format |
2143 |
16 Oct 07 |
gregory |
// of |
2143 |
16 Oct 07 |
gregory |
// "allUsersAndPasswords[i]": |
2143 |
16 Oct 07 |
gregory |
// "user:pass" |
1652 |
22 May 07 |
gregory |
1606 |
for (int i = 0, allUsersAndPasswordsLength = allUsersAndPasswords.length; i < allUsersAndPasswordsLength; i++) // Optimization... |
741 |
10 Oct 06 |
olle |
1607 |
{ |
1652 |
22 May 07 |
gregory |
1608 |
String tmpallUsersAndPasswordsI = allUsersAndPasswords[i]; |
1652 |
22 May 07 |
gregory |
1609 |
if (tmpallUsersAndPasswordsI.substring( |
2143 |
16 Oct 07 |
gregory |
1610 |
tmpallUsersAndPasswordsI.indexOf(":") + 1).equals(passWord)) |
2143 |
16 Oct 07 |
gregory |
1611 |
{ |
1652 |
22 May 07 |
gregory |
1612 |
s_visitorUsername = tmpallUsersAndPasswordsI.substring(0, |
2143 |
16 Oct 07 |
gregory |
1613 |
tmpallUsersAndPasswordsI.indexOf(":")); // In case we |
2143 |
16 Oct 07 |
gregory |
// choose to log |
2143 |
16 Oct 07 |
gregory |
// his |
2143 |
16 Oct 07 |
gregory |
// activites, |
2143 |
16 Oct 07 |
gregory |
// the webserver |
2143 |
16 Oct 07 |
gregory |
// actually |
2143 |
16 Oct 07 |
gregory |
// doesn't need |
2143 |
16 Oct 07 |
gregory |
// to save this |
741 |
10 Oct 06 |
olle |
1621 |
return true; |
741 |
10 Oct 06 |
olle |
1622 |
} |
741 |
10 Oct 06 |
olle |
1623 |
} |
741 |
10 Oct 06 |
olle |
1624 |
return false; |
741 |
10 Oct 06 |
olle |
1625 |
} |
741 |
10 Oct 06 |
olle |
1626 |
|
2143 |
16 Oct 07 |
gregory |
1627 |
|
2143 |
16 Oct 07 |
gregory |
1628 |
private boolean isFolderAllowed(String folder) |
2143 |
16 Oct 07 |
gregory |
1629 |
{ |
1652 |
22 May 07 |
gregory |
1630 |
if (folder == null) |
741 |
10 Oct 06 |
olle |
1631 |
return false; |
1652 |
22 May 07 |
gregory |
1632 |
if (folder.indexOf("..") != -1) // You have tried to reach a folder with |
2143 |
16 Oct 07 |
gregory |
// "http://www.sida.com/folder/../../secretfile.txt" |
741 |
10 Oct 06 |
olle |
1634 |
return false; |
1652 |
22 May 07 |
gregory |
1635 |
for (int i = 0, sharedPathsLength = as_sharedPaths.length; i < sharedPathsLength; i++) // Optimization... |
741 |
10 Oct 06 |
olle |
1636 |
{ |
1652 |
22 May 07 |
gregory |
1637 |
String tmpDir = as_sharedPaths[i];// .replace('\\','/'); |
1652 |
22 May 07 |
gregory |
1638 |
if (tmpDir.endsWith("*")) // If you are allowed to view the |
2143 |
16 Oct 07 |
gregory |
// content of subfolders as well... (if |
2143 |
16 Oct 07 |
gregory |
// the name ends with an * |
2143 |
16 Oct 07 |
gregory |
// ("/mapp1/mapp2/*")) |
741 |
10 Oct 06 |
olle |
1642 |
{ |
1652 |
22 May 07 |
gregory |
if (tmpDir.regionMatches(true, 0, folder, 0, |
2143 |
16 Oct 07 |
gregory |
tmpDir.length() - 1)) // If [the first |
2143 |
16 Oct 07 |
gregory |
// "tmpDir.length()-1" |
2143 |
16 Oct 07 |
gregory |
// characters of the two strings |
2143 |
16 Oct 07 |
gregory |
// are equal (case |
2143 |
16 Oct 07 |
gregory |
// insensitive)]... |
741 |
10 Oct 06 |
olle |
return true; |
2143 |
16 Oct 07 |
gregory |
1650 |
} |
2143 |
16 Oct 07 |
gregory |
else if (tmpDir.equalsIgnoreCase(folder)) |
741 |
10 Oct 06 |
olle |
return true; |
741 |
10 Oct 06 |
olle |
1653 |
} |
741 |
10 Oct 06 |
olle |
return false; |
741 |
10 Oct 06 |
olle |
1655 |
} |
741 |
10 Oct 06 |
olle |
1656 |
|
2143 |
16 Oct 07 |
gregory |
1657 |
|
2143 |
16 Oct 07 |
gregory |
private boolean isFileExtensionAllowed(String fileExtension) |
2143 |
16 Oct 07 |
gregory |
1659 |
{ |
1652 |
22 May 07 |
gregory |
if (fileExtension == null) // be safe, make a check |
741 |
10 Oct 06 |
olle |
return false; |
1652 |
22 May 07 |
gregory |
// NOTE: If you receive an error saying "You have tried to download a |
1652 |
22 May 07 |
gregory |
// file with an extension that you are not allowed to download." when |
1652 |
22 May 07 |
gregory |
// you actually have requested a folder it's because an index file was |
1652 |
22 May 07 |
gregory |
// found in the folder, but the extension of this index file is not |
1652 |
22 May 07 |
gregory |
// allowed to be viewed. This is good, as you are not allowed to view |
1652 |
22 May 07 |
gregory |
// the content of a folder with an index file with an extension you are |
1652 |
22 May 07 |
gregory |
// not allowed to view. |
1652 |
22 May 07 |
gregory |
for (int i = 0, fileExtensionsLength = as_fileExtensions.length; i < fileExtensionsLength; i++) |
1652 |
22 May 07 |
gregory |
// Optimization... |
741 |
10 Oct 06 |
olle |
if (as_fileExtensions[i].equals(fileExtension)) |
1652 |
22 May 07 |
gregory |
return b_allowTheseFileExtensions; // If |
2143 |
16 Oct 07 |
gregory |
// b_allowTheseFileExtensions==true, |
2143 |
16 Oct 07 |
gregory |
// then you are only allowed |
2143 |
16 Oct 07 |
gregory |
// to download files with an |
2143 |
16 Oct 07 |
gregory |
// extension listed in |
2143 |
16 Oct 07 |
gregory |
// "as_fileExtensions". |
2143 |
16 Oct 07 |
gregory |
// Otherwise you are not |
2143 |
16 Oct 07 |
gregory |
// allowed to download these |
2143 |
16 Oct 07 |
gregory |
// file extensions. |
741 |
10 Oct 06 |
olle |
return !b_allowTheseFileExtensions; |
741 |
10 Oct 06 |
olle |
1682 |
} |
741 |
10 Oct 06 |
olle |
1683 |
|
2143 |
16 Oct 07 |
gregory |
1684 |
|
2143 |
16 Oct 07 |
gregory |
private boolean accessToFileIsOK(String fileName) |
2143 |
16 Oct 07 |
gregory |
1686 |
{ |
1652 |
22 May 07 |
gregory |
File theDocument = new File(fileName); |
741 |
10 Oct 06 |
olle |
if (theDocument.canRead()) |
741 |
10 Oct 06 |
olle |
return true; |
741 |
10 Oct 06 |
olle |
else |
741 |
10 Oct 06 |
olle |
return false; |
741 |
10 Oct 06 |
olle |
1692 |
} |
741 |
10 Oct 06 |
olle |
1693 |
|
2143 |
16 Oct 07 |
gregory |
1694 |
|
2143 |
16 Oct 07 |
gregory |
private boolean isHTTPFormatRecognized(String httpRequest) |
2143 |
16 Oct 07 |
gregory |
1696 |
{ |
1652 |
22 May 07 |
gregory |
if (httpRequest == null) // be safe, make a check |
741 |
10 Oct 06 |
olle |
return false; |
741 |
10 Oct 06 |
olle |
if (httpRequest.toUpperCase().startsWith("HTTP")) |
741 |
10 Oct 06 |
olle |
return true; |
741 |
10 Oct 06 |
olle |
else |
741 |
10 Oct 06 |
olle |
return false; |
741 |
10 Oct 06 |
olle |
1703 |
} |
741 |
10 Oct 06 |
olle |
1704 |
|
2143 |
16 Oct 07 |
gregory |
1705 |
|
2143 |
16 Oct 07 |
gregory |
private boolean isHTTPrecognized(String httpRequest) |
2143 |
16 Oct 07 |
gregory |
1707 |
{ |
1652 |
22 May 07 |
gregory |
if (httpRequest == null) // be safe, make a check |
741 |
10 Oct 06 |
olle |
return false; |
2143 |
16 Oct 07 |
gregory |
if (httpRequest.equalsIgnoreCase(CONSTANT_HTTP11) || httpRequest |
2143 |
16 Oct 07 |
gregory |
.equalsIgnoreCase(CONSTANT_HTTP10) || httpRequest |
2143 |
16 Oct 07 |
gregory |
.equalsIgnoreCase(CONSTANT_HTTP09)) |
2143 |
16 Oct 07 |
gregory |
1713 |
/* |
2143 |
16 Oct 07 |
gregory |
* For example Netscape 1(.22) uses HTTP/1.0 |
2143 |
16 Oct 07 |
gregory |
1715 |
*/ |
741 |
10 Oct 06 |
olle |
1716 |
return true; |
741 |
10 Oct 06 |
olle |
1717 |
else |
741 |
10 Oct 06 |
olle |
1718 |
return false; |
741 |
10 Oct 06 |
olle |
1719 |
} |
741 |
10 Oct 06 |
olle |
1720 |
|
2143 |
16 Oct 07 |
gregory |
1721 |
|
1652 |
22 May 07 |
gregory |
1722 |
private String giveNameOfIndexFile(String folder) // returns the name of |
2143 |
16 Oct 07 |
gregory |
// the index file, if |
2143 |
16 Oct 07 |
gregory |
// there is no index |
2143 |
16 Oct 07 |
gregory |
// file, returns "" |
741 |
10 Oct 06 |
olle |
1726 |
{ |
1652 |
22 May 07 |
gregory |
1727 |
if (File.separatorChar == '\\') // Windows user... don't make difference |
2143 |
16 Oct 07 |
gregory |
// on "index.html" and "INDEX.HTML" |
741 |
10 Oct 06 |
olle |
1729 |
{ |
2143 |
16 Oct 07 |
gregory |
1730 |
for (int i = 0, indexNamesLength = as_indexNames.length; i < indexNamesLength; i++) |
2143 |
16 Oct 07 |
gregory |
1731 |
{ |
1652 |
22 May 07 |
gregory |
1732 |
File thisFile = new File(folder + as_indexNames[i]); |
2143 |
16 Oct 07 |
gregory |
1733 |
if (thisFile.isFile()) |
2143 |
16 Oct 07 |
gregory |
1734 |
{ |
741 |
10 Oct 06 |
olle |
1735 |
return as_indexNames[i]; |
741 |
10 Oct 06 |
olle |
1736 |
} |
741 |
10 Oct 06 |
olle |
1737 |
} |
2143 |
16 Oct 07 |
gregory |
1738 |
} |
2143 |
16 Oct 07 |
gregory |
1739 |
else |
2143 |
16 Oct 07 |
gregory |
// If UNIX, Linux etc... |
741 |
10 Oct 06 |
olle |
1741 |
{ |
1652 |
22 May 07 |
gregory |
// First make the fast search for a file with correct CaSe |
1652 |
22 May 07 |
gregory |
// SeNsItIvItY |
2143 |
16 Oct 07 |
gregory |
1744 |
for (int i = 0, indexNamesLength = as_indexNames.length; i < indexNamesLength; i++) |
2143 |
16 Oct 07 |
gregory |
1745 |
{ |
1652 |
22 May 07 |
gregory |
1746 |
File thisFile = new File(folder + as_indexNames[i]); |
2143 |
16 Oct 07 |
gregory |
1747 |
if (thisFile.isFile()) |
2143 |
16 Oct 07 |
gregory |
1748 |
{ |
741 |
10 Oct 06 |
olle |
1749 |
return as_indexNames[i]; |
741 |
10 Oct 06 |
olle |
1750 |
} |
741 |
10 Oct 06 |
olle |
1751 |
} |
1652 |
22 May 07 |
gregory |
// Now make a slow search for a file with incorrect CaSe SeNsItIvItY |
1652 |
22 May 07 |
gregory |
// (so "index.html" also matches "INDEX.HTML") |
741 |
10 Oct 06 |
olle |
1754 |
String tmpIndexFile; |
1652 |
22 May 07 |
gregory |
1755 |
File thisFolder = new File(folder); |
1652 |
22 May 07 |
gregory |
1756 |
String[] allFilesInFolder = thisFolder.list(); |
2143 |
16 Oct 07 |
gregory |
1757 |
for (int i = 0, indexNamesLength = as_indexNames.length; i < indexNamesLength; i++) |
2143 |
16 Oct 07 |
gregory |
1758 |
{ |
2143 |
16 Oct 07 |
gregory |
1759 |
tmpIndexFile = as_indexNames[i].toLowerCase(); |
2143 |
16 Oct 07 |
gregory |
1760 |
/* |
2143 |
16 Oct 07 |
gregory |
* Optimization or not?? I don't know... The ".toLowerCase()" is |
2143 |
16 Oct 07 |
gregory |
* not needed as we make a ".equalsIgnoreCase()" comparison, but |
2143 |
16 Oct 07 |
gregory |
* as the ".equalsIgnoreCase()" is made very many times (it is |
2143 |
16 Oct 07 |
gregory |
* called as many times as there are files in the folder), and |
2143 |
16 Oct 07 |
gregory |
* the ".toLowerCase()" is only made once it might be worth to |
2143 |
16 Oct 07 |
gregory |
* make one ".toLowerCase()" to speed up the |
2143 |
16 Oct 07 |
gregory |
* ".equalsIgnoreCase()" method (or, does it really get faster?) |
2143 |
16 Oct 07 |
gregory |
1768 |
*/ |
2143 |
16 Oct 07 |
gregory |
1769 |
for (int j = 0, allFilesInFolderLength = allFilesInFolder.length; j < allFilesInFolderLength; j++) |
2143 |
16 Oct 07 |
gregory |
1770 |
{ |
2143 |
16 Oct 07 |
gregory |
1771 |
if (tmpIndexFile.equalsIgnoreCase(allFilesInFolder[j])) |
2143 |
16 Oct 07 |
gregory |
1772 |
{ |
741 |
10 Oct 06 |
olle |
1773 |
return allFilesInFolder[j]; |
741 |
10 Oct 06 |
olle |
1774 |
} |
741 |
10 Oct 06 |
olle |
1775 |
} |
741 |
10 Oct 06 |
olle |
1776 |
} |
741 |
10 Oct 06 |
olle |
1777 |
} |
1652 |
22 May 07 |
gregory |
1778 |
return ""; // Return "" if no index file matched... |
741 |
10 Oct 06 |
olle |
1779 |
} |
741 |
10 Oct 06 |
olle |
1780 |
|
2143 |
16 Oct 07 |
gregory |
1781 |
|
1652 |
22 May 07 |
gregory |
1782 |
private void showError(String errorMessage, String folder, |
1652 |
22 May 07 |
gregory |
1783 |
String showThisFile)// throws IOException |
741 |
10 Oct 06 |
olle |
1784 |
{ |
2143 |
16 Oct 07 |
gregory |
1785 |
try |
2143 |
16 Oct 07 |
gregory |
1786 |
{ |
1652 |
22 May 07 |
gregory |
1787 |
if (b_showErrors) |
1652 |
22 May 07 |
gregory |
1788 |
System.out.println(errorMessage); |
1652 |
22 May 07 |
gregory |
1789 |
s_requestedFileName = showThisFile; // This is needed in case an |
2143 |
16 Oct 07 |
gregory |
// invalid header is given, then |
2143 |
16 Oct 07 |
gregory |
// s_requestedFileName might not |
2143 |
16 Oct 07 |
gregory |
// have been set. |
1652 |
22 May 07 |
gregory |
1793 |
returnThisPage(folder + showThisFile); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before |
1652 |
22 May 07 |
gregory |
// all data has been sent |
1652 |
22 May 07 |
gregory |
// REMOVE ALL CLOSE: so_userConnection.close(); |
2143 |
16 Oct 07 |
gregory |
1798 |
} |
2143 |
16 Oct 07 |
gregory |
1799 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
1800 |
{ |
1652 |
22 May 07 |
gregory |
1801 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
1802 |
System.out.println("An error occured @ showError:\n" + e |
2143 |
16 Oct 07 |
gregory |
1803 |
.getMessage()); |
1652 |
22 May 07 |
gregory |
1804 |
} |
741 |
10 Oct 06 |
olle |
1805 |
} |
741 |
10 Oct 06 |
olle |
1806 |
|
2143 |
16 Oct 07 |
gregory |
1807 |
|
1652 |
22 May 07 |
gregory |
1808 |
private void createEnvironmentVariables( |
2143 |
16 Oct 07 |
gregory |
1809 |
boolean b_createConstantEnvironmentVariables) |
2143 |
16 Oct 07 |
gregory |
1810 |
/* |
2143 |
16 Oct 07 |
gregory |
* There is no reason to set b_createConstantEnvironmentVariables==true |
2143 |
16 Oct 07 |
gregory |
* unless you call "createEnvironmentVariables" just before you run a script |
2143 |
16 Oct 07 |
gregory |
* (before you call "RunScript"). "createEnvironmentVariables(true)" |
2143 |
16 Oct 07 |
gregory |
* ("b_createConstantEnvironmentVariables"==true) MUST be set to true and |
2143 |
16 Oct 07 |
gregory |
* called (at least) ONCE before you run a script, or the environment |
2143 |
16 Oct 07 |
gregory |
* variables WON'T BE SET!! (you can run this more than once, but it's |
2143 |
16 Oct 07 |
gregory |
* unnecessary) |
2143 |
16 Oct 07 |
gregory |
1818 |
*/ |
741 |
10 Oct 06 |
olle |
1819 |
{ |
2143 |
16 Oct 07 |
gregory |
1820 |
if (!b_environmentHasBeenSetUp) |
2143 |
16 Oct 07 |
gregory |
1821 |
{ |
1652 |
22 May 07 |
gregory |
1822 |
b_environmentHasBeenSetUp = true; |
1652 |
22 May 07 |
gregory |
1823 |
as_variablesGivenByBrowser = getEnvironmentVariablesGivenByBrowser(DISWR_theInputWeGetFromBrowser); |
741 |
10 Oct 06 |
olle |
1824 |
} |
741 |
10 Oct 06 |
olle |
1825 |
if (b_createConstantEnvironmentVariables) |
1652 |
22 May 07 |
gregory |
1826 |
as_allEnvironmentVariables = getAllEnvironmentVariables(); |
741 |
10 Oct 06 |
olle |
1827 |
} |
741 |
10 Oct 06 |
olle |
1828 |
|
2143 |
16 Oct 07 |
gregory |
1829 |
|
2143 |
16 Oct 07 |
gregory |
1830 |
private void readAllJunkHeaderData() |
2143 |
16 Oct 07 |
gregory |
1831 |
{ |
2143 |
16 Oct 07 |
gregory |
1832 |
try |
2143 |
16 Oct 07 |
gregory |
1833 |
{ |
1652 |
22 May 07 |
gregory |
// System.out.println("JUNKDATA"); |
1652 |
22 May 07 |
gregory |
1835 |
BufferedInputStream bis = new BufferedInputStream(so_userConnection |
2143 |
16 Oct 07 |
gregory |
1836 |
.getInputStream()); |
1652 |
22 May 07 |
gregory |
// System.out.println(bis.available()); |
1652 |
22 May 07 |
gregory |
1838 |
bis.skip(bis.available()); |
1652 |
22 May 07 |
gregory |
1839 |
/* |
1652 |
22 May 07 |
gregory |
* while (bis.available()>0) { System.out.print((char)bis.read()); } |
1652 |
22 May 07 |
gregory |
* System.out.println(""); |
1652 |
22 May 07 |
gregory |
1842 |
*/ |
2143 |
16 Oct 07 |
gregory |
1843 |
} |
2143 |
16 Oct 07 |
gregory |
1844 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
1845 |
{ |
1652 |
22 May 07 |
gregory |
1846 |
if (b_showErrors) |
1652 |
22 May 07 |
gregory |
1847 |
System.out |
2143 |
16 Oct 07 |
gregory |
1848 |
.println("An error occured @ readAllJunkHeaderData:\n" + e |
2143 |
16 Oct 07 |
gregory |
1849 |
.getMessage()); |
741 |
10 Oct 06 |
olle |
1850 |
} |
741 |
10 Oct 06 |
olle |
1851 |
} |
741 |
10 Oct 06 |
olle |
1852 |
|
2143 |
16 Oct 07 |
gregory |
1853 |
|
741 |
10 Oct 06 |
olle |
1854 |
private void returnThisPage(String documentToReturn)// throws IOException |
741 |
10 Oct 06 |
olle |
1855 |
{ |
741 |
10 Oct 06 |
olle |
1856 |
initializeRequestedFileExtension(); |
2143 |
16 Oct 07 |
gregory |
1857 |
try |
2143 |
16 Oct 07 |
gregory |
1858 |
{ |
2143 |
16 Oct 07 |
gregory |
1859 |
if (!b_allowExecuteScript || myHT_runnableExtensions |
2143 |
16 Oct 07 |
gregory |
1860 |
.giveValueByIndex(s_requestedFileExtension) == null) |
2143 |
16 Oct 07 |
gregory |
1861 |
/* |
2143 |
16 Oct 07 |
gregory |
* If [you are not allowed to run scripts] OR [The file is not |
2143 |
16 Oct 07 |
gregory |
* runnable], then show the content of this file... |
2143 |
16 Oct 07 |
gregory |
1864 |
*/ |
741 |
10 Oct 06 |
olle |
1865 |
{ |
1652 |
22 May 07 |
gregory |
1866 |
File theFile = new File(documentToReturn); |
1652 |
22 May 07 |
gregory |
1867 |
if (theFile.length() == 0) |
1652 |
22 May 07 |
gregory |
1868 |
s_errorStatus = "204 No Content"; |
2143 |
16 Oct 07 |
gregory |
1869 |
so_userConnection.setSoTimeout(0); |
2143 |
16 Oct 07 |
gregory |
1870 |
/* |
2143 |
16 Oct 07 |
gregory |
* This will make sure that the connection doesn't close |
2143 |
16 Oct 07 |
gregory |
* immediately after the file download. Why this?: Because if we |
2143 |
16 Oct 07 |
gregory |
* didn't have this, and lets say ".getSoTimeout()" is 5 sec, |
2143 |
16 Oct 07 |
gregory |
* then a file download on for example 6 seconds would result in |
2143 |
16 Oct 07 |
gregory |
* that the connection has been closed as soon as we had reached |
2143 |
16 Oct 07 |
gregory |
* a ".read(xxx)"-method. Now we set this to 0 (infinity) before |
2143 |
16 Oct 07 |
gregory |
* we send data and we set this back to for example 5 seconds |
2143 |
16 Oct 07 |
gregory |
* before we read data (call the ".read(xxx)"-method). |
2143 |
16 Oct 07 |
gregory |
1879 |
*/ |
1652 |
22 May 07 |
gregory |
1880 |
BufferedOutputStream theOutput = new BufferedOutputStream( |
2143 |
16 Oct 07 |
gregory |
1881 |
new DataOutputStream(new BufferedOutputStream( |
2143 |
16 Oct 07 |
gregory |
1882 |
so_userConnection.getOutputStream()))); // I |
2143 |
16 Oct 07 |
gregory |
// "java.io.*" |
741 |
10 Oct 06 |
olle |
1884 |
readAllJunkHeaderData(); |
2143 |
16 Oct 07 |
gregory |
1885 |
if (i_sendWhatData != DATATYPE_BODYONLY) |
2143 |
16 Oct 07 |
gregory |
1886 |
{ |
1652 |
22 May 07 |
gregory |
1887 |
theOutput |
2143 |
16 Oct 07 |
gregory |
1888 |
.write((s_requestedHTTP + " " + s_errorStatus + "\r\n" + "Date: " + df_dateFormat |
2143 |
16 Oct 07 |
gregory |
1889 |
.format(d_dateToday) + "\r\n" + "Server: " + s_replyServerName + "\r\n" + ((b_useKeepAlive) ? ("Connection: Keep-Alive\r\n") : ("Connection: Close\r\n")) + "Content-Length: " + theFile |
2143 |
16 Oct 07 |
gregory |
1890 |
.length() + "\r\n" + "Last-Modified: " + new Date( |
2143 |
16 Oct 07 |
gregory |
1891 |
theFile.lastModified()) + "\r\n" + "Location: " + s_requestDocument + "\r\n" + "Content-Type: " + s_requestedFileType + s_charsetToUse + "\r\n\r\n") |
2143 |
16 Oct 07 |
gregory |
1892 |
.getBytes()); |
741 |
10 Oct 06 |
olle |
1893 |
} |
741 |
10 Oct 06 |
olle |
1894 |
writeFileToStream(theFile, theOutput); |
1652 |
22 May 07 |
gregory |
// theOutput.write(("\r\n").getBytes()); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close |
1652 |
22 May 07 |
gregory |
// before all data has been sent |
741 |
10 Oct 06 |
olle |
1899 |
theOutput.flush(); |
1652 |
22 May 07 |
gregory |
// REMOVE ALL CLOSE: theOutput.close(); |
2143 |
16 Oct 07 |
gregory |
1901 |
} |
2143 |
16 Oct 07 |
gregory |
1902 |
else |
2143 |
16 Oct 07 |
gregory |
// The file is runnable and you have permission to run the |
2143 |
16 Oct 07 |
gregory |
// script |
741 |
10 Oct 06 |
olle |
1905 |
{ |
1652 |
22 May 07 |
gregory |
1906 |
b_useKeepAlive = false; |
1652 |
22 May 07 |
gregory |
1907 |
b_isRunningScript = true; |
1652 |
22 May 07 |
gregory |
1908 |
b_logThisHit = false; // The Threads created after the |
2143 |
16 Oct 07 |
gregory |
// RunScript is started will make sure |
2143 |
16 Oct 07 |
gregory |
// the user is "logged" |
1652 |
22 May 07 |
gregory |
1911 |
DataOutputStream theOutput = new DataOutputStream( |
2143 |
16 Oct 07 |
gregory |
1912 |
new BufferedOutputStream(so_userConnection |
2143 |
16 Oct 07 |
gregory |
1913 |
.getOutputStream())); // I "java.io.*" |
1652 |
22 May 07 |
gregory |
1914 |
createEnvironmentVariables(true); // This MUST be called. This |
2143 |
16 Oct 07 |
gregory |
// set |
2143 |
16 Oct 07 |
gregory |
// "as_allEnvironmentVariables". |
1652 |
22 May 07 |
gregory |
1917 |
if (documentToReturn.indexOf(" ") != -1) |
2143 |
16 Oct 07 |
gregory |
1918 |
(rs_process = new RunScript( |
2143 |
16 Oct 07 |
gregory |
1919 |
myHT_runnableExtensions |
2143 |
16 Oct 07 |
gregory |
1920 |
.giveValueByIndex(s_requestedFileExtension) + " \"" + documentToReturn + "\"\n", |
2143 |
16 Oct 07 |
gregory |
1921 |
theOutput, |
2143 |
16 Oct 07 |
gregory |
1922 |
as_allEnvironmentVariables, |
2143 |
16 Oct 07 |
gregory |
1923 |
(i_valueOfHttpContentLength == 0) ? null : DISWR_theInputWeGetFromBrowser, |
2143 |
16 Oct 07 |
gregory |
1924 |
s_requestDocument, documentToReturn, this)).start(); // Run: |
2143 |
16 Oct 07 |
gregory |
// 'perl |
2143 |
16 Oct 07 |
gregory |
// "c:/files/myFile.pl"' |
741 |
10 Oct 06 |
olle |
1927 |
else |
2143 |
16 Oct 07 |
gregory |
1928 |
(rs_process = new RunScript( |
2143 |
16 Oct 07 |
gregory |
1929 |
myHT_runnableExtensions |
2143 |
16 Oct 07 |
gregory |
1930 |
.giveValueByIndex(s_requestedFileExtension) + " " + documentToReturn + "\n", |
2143 |
16 Oct 07 |
gregory |
1931 |
theOutput, |
2143 |
16 Oct 07 |
gregory |
1932 |
as_allEnvironmentVariables, |
2143 |
16 Oct 07 |
gregory |
1933 |
(i_valueOfHttpContentLength == 0) ? null : DISWR_theInputWeGetFromBrowser, |
2143 |
16 Oct 07 |
gregory |
1934 |
s_requestDocument, documentToReturn, this)).start(); // Run: |
2143 |
16 Oct 07 |
gregory |
// 'perl |
2143 |
16 Oct 07 |
gregory |
// c:/files/myFile.pl' |
741 |
10 Oct 06 |
olle |
1937 |
} |
2143 |
16 Oct 07 |
gregory |
1938 |
so_userConnection.setSoTimeout(i_soTimeoutAfterKeepAliveTransfer); |
2143 |
16 Oct 07 |
gregory |
1939 |
/* |
2143 |
16 Oct 07 |
gregory |
* This make sure that the next time we read form the inputstream |
2143 |
16 Oct 07 |
gregory |
* (read what the browser has sent to us) we will only wait for 5 |
2143 |
16 Oct 07 |
gregory |
* seconds. |
2143 |
16 Oct 07 |
gregory |
1943 |
*/ |
2143 |
16 Oct 07 |
gregory |
1944 |
} |
2143 |
16 Oct 07 |
gregory |
1945 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
1946 |
{ |
741 |
10 Oct 06 |
olle |
1947 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
1948 |
System.out.println("An error occured @ returnThisPage:\n" + e |
2143 |
16 Oct 07 |
gregory |
1949 |
.getMessage()); |
741 |
10 Oct 06 |
olle |
1950 |
} |
741 |
10 Oct 06 |
olle |
1951 |
} |
741 |
10 Oct 06 |
olle |
1952 |
|
2143 |
16 Oct 07 |
gregory |
1953 |
|
2143 |
16 Oct 07 |
gregory |
1954 |
private void writeFileToStream(File theFile, OutputStream os) |
2143 |
16 Oct 07 |
gregory |
1955 |
{ |
1652 |
22 May 07 |
gregory |
1956 |
FileInputStream fileStreamed = null; |
2143 |
16 Oct 07 |
gregory |
1957 |
try |
2143 |
16 Oct 07 |
gregory |
1958 |
{ |
1652 |
22 May 07 |
gregory |
// setPriority(MIN_PRIORITY); |
1652 |
22 May 07 |
gregory |
1960 |
int numberOfBytesThatWillBeSent = 0; |
1652 |
22 May 07 |
gregory |
1961 |
fileStreamed = new FileInputStream(theFile); |
1652 |
22 May 07 |
gregory |
1962 |
byte[] myBuffer = new byte[8192];// 40960]; //2048*20 (i tested |
2143 |
16 Oct 07 |
gregory |
// and this value seems to give |
2143 |
16 Oct 07 |
gregory |
// a very high speed when you |
2143 |
16 Oct 07 |
gregory |
// download files) |
2143 |
16 Oct 07 |
gregory |
1966 |
if (i_sendWhatData != DATATYPE_HEADONLY) |
2143 |
16 Oct 07 |
gregory |
1967 |
{ |
1652 |
22 May 07 |
gregory |
1968 |
while ((numberOfBytesThatWillBeSent = fileStreamed |
2143 |
16 Oct 07 |
gregory |
1969 |
.read(myBuffer)) != -1) |
2143 |
16 Oct 07 |
gregory |
1970 |
{ |
1652 |
22 May 07 |
gregory |
// We add all "n" to a variable to know how many bytes have |
1652 |
22 May 07 |
gregory |
// been downloaded from Xerver |
1652 |
22 May 07 |
gregory |
1973 |
os.write(myBuffer, 0, numberOfBytesThatWillBeSent); |
1652 |
22 May 07 |
gregory |
1974 |
if (b_logThisHit) // Don't count the data sent when |
2143 |
16 Oct 07 |
gregory |
// downloading reserved paths ( ==> |
2143 |
16 Oct 07 |
gregory |
// "/Image:xxxX" ) |
741 |
10 Oct 06 |
olle |
1977 |
{ |
1652 |
22 May 07 |
gregory |
1978 |
totalNumberOfBytesDownloaded += numberOfBytesThatWillBeSent; |
741 |
10 Oct 06 |
olle |
1979 |
myMenuOptions.statsHasBeenUpdated(); |
741 |
10 Oct 06 |
olle |
1980 |
} |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// This is not necessery anymore. It works fine now: |
1652 |
22 May 07 |
gregory |
// sleep(25); //I noticed that without this for example some |
1652 |
22 May 07 |
gregory |
// large pictures (~200-300k) won't be shown. This might |
1652 |
22 May 07 |
gregory |
// (but I don't know for sure) be valid also for other large |
1652 |
22 May 07 |
gregory |
// files. |
741 |
10 Oct 06 |
olle |
1987 |
} |
741 |
10 Oct 06 |
olle |
1988 |
} |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(50); //Be safe, don't close before |
1652 |
22 May 07 |
gregory |
// all data has been sent |
1652 |
22 May 07 |
gregory |
// setPriority(NORM_PRIORITY); |
2143 |
16 Oct 07 |
gregory |
1993 |
} |
2143 |
16 Oct 07 |
gregory |
1994 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
1995 |
{ |
741 |
10 Oct 06 |
olle |
1996 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
1997 |
System.out |
2143 |
16 Oct 07 |
gregory |
1998 |
.println("An error occured @ writeFileToStream:\n" + e |
2143 |
16 Oct 07 |
gregory |
1999 |
.getMessage()); |
741 |
10 Oct 06 |
olle |
2000 |
} |
2143 |
16 Oct 07 |
gregory |
2001 |
try |
2143 |
16 Oct 07 |
gregory |
2002 |
{ |
1652 |
22 May 07 |
gregory |
2003 |
if (fileStreamed != null) // If fileStreamed "holds" a file |
741 |
10 Oct 06 |
olle |
2004 |
{ |
2143 |
16 Oct 07 |
gregory |
2005 |
fileStreamed.close(); |
2143 |
16 Oct 07 |
gregory |
2006 |
/* |
2143 |
16 Oct 07 |
gregory |
* Important: This must be reached no matter what! Even if an |
2143 |
16 Oct 07 |
gregory |
* exception occurs in the try block, whis must be reached. |
2143 |
16 Oct 07 |
gregory |
* Otherwise the file will be locked by Xerver (locked by |
2143 |
16 Oct 07 |
gregory |
* Java.exe) until the garbage collector is runned (and you |
2143 |
16 Oct 07 |
gregory |
* don't know when it will run) and detects that the file (the |
2143 |
16 Oct 07 |
gregory |
* object "fileStreamed") is no longer referenced from anywhere |
2143 |
16 Oct 07 |
gregory |
* else and it release the file by automatic. Until this |
2143 |
16 Oct 07 |
gregory |
* happenes, no other application can write to or rename this |
2143 |
16 Oct 07 |
gregory |
* file (however, this problem is solved with this line). |
2143 |
16 Oct 07 |
gregory |
2016 |
*/ |
741 |
10 Oct 06 |
olle |
2017 |
} |
2143 |
16 Oct 07 |
gregory |
2018 |
} |
2143 |
16 Oct 07 |
gregory |
2019 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
2020 |
{ |
741 |
10 Oct 06 |
olle |
2021 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
2022 |
System.out |
2143 |
16 Oct 07 |
gregory |
2023 |
.println("An error occured @ writeFileToStream:\n" + e |
2143 |
16 Oct 07 |
gregory |
2024 |
.getMessage()); |
741 |
10 Oct 06 |
olle |
2025 |
} |
741 |
10 Oct 06 |
olle |
2026 |
} |
741 |
10 Oct 06 |
olle |
2027 |
|
2143 |
16 Oct 07 |
gregory |
2028 |
|
2143 |
16 Oct 07 |
gregory |
2029 |
private boolean isThisFileExtensionAllowed(String fileName) |
2143 |
16 Oct 07 |
gregory |
2030 |
{ |
1652 |
22 May 07 |
gregory |
2031 |
fileName = fileName.toLowerCase(); |
1652 |
22 May 07 |
gregory |
// String filAndelse=fileName.substring(fileName.lastIndexOf(".")+1); |
1652 |
22 May 07 |
gregory |
// as_fileExtensions[i].equals(filAndelse) |
1652 |
22 May 07 |
gregory |
2034 |
for (int i = 0, fileExtensionsLength = as_fileExtensions.length; i < fileExtensionsLength; i++) |
741 |
10 Oct 06 |
olle |
2035 |
if (fileName.endsWith(as_fileExtensions[i])) |
2143 |
16 Oct 07 |
gregory |
2036 |
return b_allowTheseFileExtensions; |
2143 |
16 Oct 07 |
gregory |
2037 |
/* |
2143 |
16 Oct 07 |
gregory |
* If b_allowTheseFileExtensions==true, then you are only allowed to |
2143 |
16 Oct 07 |
gregory |
* download files with extensions that can be found in |
2143 |
16 Oct 07 |
gregory |
* "as_fileExtensions". Otwerwise these file extionsions shall not be |
2143 |
16 Oct 07 |
gregory |
* viewable! |
2143 |
16 Oct 07 |
gregory |
2042 |
*/ |
741 |
10 Oct 06 |
olle |
2043 |
return !b_allowTheseFileExtensions; |
741 |
10 Oct 06 |
olle |
2044 |
} |
741 |
10 Oct 06 |
olle |
2045 |
|
2143 |
16 Oct 07 |
gregory |
2046 |
|
1652 |
22 May 07 |
gregory |
// The visitor has to enter a password for each "realm". |
741 |
10 Oct 06 |
olle |
2048 |
private void showAccessDenied(String theRealm)// throws IOException |
741 |
10 Oct 06 |
olle |
2049 |
{ |
2143 |
16 Oct 07 |
gregory |
2050 |
try |
2143 |
16 Oct 07 |
gregory |
2051 |
{ |
741 |
10 Oct 06 |
olle |
2052 |
readAllJunkHeaderData(); |
2143 |
16 Oct 07 |
gregory |
2053 |
so_userConnection.setSoTimeout(0); |
2143 |
16 Oct 07 |
gregory |
2054 |
/* |
2143 |
16 Oct 07 |
gregory |
* This will make sure that the connection doesn't close immediately |
2143 |
16 Oct 07 |
gregory |
* after the file download. Why this?: Because if we didn't have |
2143 |
16 Oct 07 |
gregory |
* this, and lets say ".getSoTimeout()" is 5 sec, then a file |
2143 |
16 Oct 07 |
gregory |
* download on for example 6 seconds would result in that the |
2143 |
16 Oct 07 |
gregory |
* connection has been closed as soon as we had reached a |
2143 |
16 Oct 07 |
gregory |
* ".read(xxx)"-method. Now we set this to 0 (infinity) before we |
2143 |
16 Oct 07 |
gregory |
* send data and we set this back to for example 5 seconds before we |
2143 |
16 Oct 07 |
gregory |
* read data (call the ".read(xxx)"-method). |
2143 |
16 Oct 07 |
gregory |
2063 |
*/ |
2143 |
16 Oct 07 |
gregory |
2064 |
File theFile = new File( |
2143 |
16 Oct 07 |
gregory |
2065 |
errorFilesFolder + "error401notauthorized.html"); |
1652 |
22 May 07 |
gregory |
2066 |
DataOutputStream theOutput = new DataOutputStream( |
2143 |
16 Oct 07 |
gregory |
2067 |
new BufferedOutputStream(so_userConnection.getOutputStream())); // I |
2143 |
16 Oct 07 |
gregory |
// "java.io.*" |
2143 |
16 Oct 07 |
gregory |
2069 |
if (i_sendWhatData != DATATYPE_BODYONLY) |
2143 |
16 Oct 07 |
gregory |
2070 |
{ |
2143 |
16 Oct 07 |
gregory |
2071 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2072 |
.writeBytes(s_requestedHTTP + " 401 Not Authorized\r\n" + "Date: " + df_dateFormat |
2143 |
16 Oct 07 |
gregory |
2073 |
.format(d_dateToday) + "\r\n" + "WWW-Authenticate: Basic realm=\"" + theRealm + "\"\r\n" + "Server: " + s_replyServerName + "\r\n" + ((b_useKeepAlive) ? ("Connection: Keep-Alive\r\n") : ("Connection: Close\r\n")) + "Location: " + s_requestDocument + "\r\n" + "Content-Length: " + theFile |
2143 |
16 Oct 07 |
gregory |
2074 |
.length() + "\r\n" + |
2143 |
16 Oct 07 |
gregory |
// "Set-Cookie: hej=12345;\r\n"+ |
2143 |
16 Oct 07 |
gregory |
2076 |
"Content-Type: text/html\r\n\r\n"); |
741 |
10 Oct 06 |
olle |
2077 |
} |
1652 |
22 May 07 |
gregory |
2078 |
writeFileToStream(theFile, theOutput); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before |
1652 |
22 May 07 |
gregory |
// all data has been sent |
1652 |
22 May 07 |
gregory |
2082 |
theOutput.flush(); |
1652 |
22 May 07 |
gregory |
// REMOVE ALL CLOSE: theOutput.close(); |
2143 |
16 Oct 07 |
gregory |
2084 |
so_userConnection.setSoTimeout(i_soTimeoutAfterKeepAliveTransfer); |
2143 |
16 Oct 07 |
gregory |
2085 |
/* |
2143 |
16 Oct 07 |
gregory |
* This make sure that the next time we read form the inputstream |
2143 |
16 Oct 07 |
gregory |
* (read what the browser has sent to us) we will only wait for 5 |
2143 |
16 Oct 07 |
gregory |
* seconds. |
2143 |
16 Oct 07 |
gregory |
2089 |
*/ |
2143 |
16 Oct 07 |
gregory |
2090 |
} |
2143 |
16 Oct 07 |
gregory |
2091 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
2092 |
{ |
1652 |
22 May 07 |
gregory |
2093 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
2094 |
System.out.println("An error occured @ showAccessDenied:\n" + e |
2143 |
16 Oct 07 |
gregory |
2095 |
.getMessage()); |
1652 |
22 May 07 |
gregory |
2096 |
} |
741 |
10 Oct 06 |
olle |
2097 |
} |
741 |
10 Oct 06 |
olle |
2098 |
|
2143 |
16 Oct 07 |
gregory |
2099 |
|
741 |
10 Oct 06 |
olle |
2100 |
private void showDirectorylisting()// throws IOException |
741 |
10 Oct 06 |
olle |
2101 |
{ |
2143 |
16 Oct 07 |
gregory |
2102 |
try |
2143 |
16 Oct 07 |
gregory |
2103 |
{ |
1652 |
22 May 07 |
gregory |
2104 |
int countFolders = 0, countFiles = 0; |
1652 |
22 May 07 |
gregory |
2105 |
long totalFolderSize = 0; |
1652 |
22 May 07 |
gregory |
2106 |
File theFolder = new File(s_requestedFolderLocation); |
1652 |
22 May 07 |
gregory |
2107 |
String[] allFilesAndFolders = theFolder.list(); |
1652 |
22 May 07 |
gregory |
2108 |
Arrays.sort(allFilesAndFolders, new ComparatorIgnoreCase()); |
1652 |
22 May 07 |
gregory |
2109 |
int allFilesAndFoldersLength = allFilesAndFolders.length; |
1652 |
22 May 07 |
gregory |
2110 |
readAllJunkHeaderData(); |
1652 |
22 May 07 |
gregory |
2111 |
so_userConnection.setSoTimeout(0);// This will make sure that the |
2143 |
16 Oct 07 |
gregory |
// connection doesn't close |
2143 |
16 Oct 07 |
gregory |
// immediately after the file |
2143 |
16 Oct 07 |
gregory |
// download. Why this?: Because |
2143 |
16 Oct 07 |
gregory |
// if we didn't have this, and |
2143 |
16 Oct 07 |
gregory |
// lets say ".getSoTimeout()" is |
2143 |
16 Oct 07 |
gregory |
// 5 sec, then a file download |
2143 |
16 Oct 07 |
gregory |
// on for example 6 seconds |
2143 |
16 Oct 07 |
gregory |
// would result in that the |
2143 |
16 Oct 07 |
gregory |
// connection has been closed as |
2143 |
16 Oct 07 |
gregory |
// soon as we had reached a |
2143 |
16 Oct 07 |
gregory |
// ".read(xxx)"-method. Now we |
2143 |
16 Oct 07 |
gregory |
// set this to 0 (infinity) |
2143 |
16 Oct 07 |
gregory |
// before we send data and we |
2143 |
16 Oct 07 |
gregory |
// set this back to for example |
2143 |
16 Oct 07 |
gregory |
// 5 seconds before we read data |
2143 |
16 Oct 07 |
gregory |
// (call the |
2143 |
16 Oct 07 |
gregory |
// ".read(xxx)"-method). |
1652 |
22 May 07 |
gregory |
// DataOutputStream theOutput =new DataOutputStream(new |
1652 |
22 May 07 |
gregory |
// BufferedOutputStream(so_userConnection.getOutputStream())); //I |
1652 |
22 May 07 |
gregory |
// "java.io.*" |
1652 |
22 May 07 |
gregory |
2132 |
ChunkedDataOutputStream theOutput = new ChunkedDataOutputStream( |
2143 |
16 Oct 07 |
gregory |
2133 |
new BufferedOutputStream(so_userConnection.getOutputStream()), |
2143 |
16 Oct 07 |
gregory |
2134 |
s_requestedHTTP.equals(CONSTANT_HTTP11), b_logThisHit); // Chunked |
2143 |
16 Oct 07 |
gregory |
// data |
2143 |
16 Oct 07 |
gregory |
// transfer |
2143 |
16 Oct 07 |
gregory |
// is |
2143 |
16 Oct 07 |
gregory |
// supported |
2143 |
16 Oct 07 |
gregory |
// only |
2143 |
16 Oct 07 |
gregory |
// with |
2143 |
16 Oct 07 |
gregory |
// HTTP/1.1 |
2143 |
16 Oct 07 |
gregory |
2142 |
if (i_sendWhatData != DATATYPE_BODYONLY) |
2143 |
16 Oct 07 |
gregory |
2143 |
{ |
1652 |
22 May 07 |
gregory |
2144 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2145 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2146 |
s_requestedHTTP + " " + s_errorStatus + "\r\n" + "Date: " + df_dateFormat |
2143 |
16 Oct 07 |
gregory |
2147 |
.format(d_dateToday) + "\r\n" + "Server: " + s_replyServerName + "\r\n" + ((b_useKeepAlive) ? ("Connection: Keep-Alive\r\n") : ("Connection: Close\r\n")) + "Location: " + s_requestDocument + "\r\n" + |
2143 |
16 Oct 07 |
gregory |
// "Set-Cookie: hej=12345;\r\n"+ |
2143 |
16 Oct 07 |
gregory |
2149 |
((s_requestedHTTP.equals(CONSTANT_HTTP11)) ? ("Transfer-Encoding: chunked\r\n") : ("")) + // Only |
2143 |
16 Oct 07 |
gregory |
// HTTP/1.1-browser |
2143 |
16 Oct 07 |
gregory |
// will |
2143 |
16 Oct 07 |
gregory |
// understand this |
2143 |
16 Oct 07 |
gregory |
2153 |
"Content-Type: text/html" + s_charsetToUse + "\r\n\r\n", |
2143 |
16 Oct 07 |
gregory |
2154 |
false);// NOTE: |
2143 |
16 Oct 07 |
gregory |
// WE |
2143 |
16 Oct 07 |
gregory |
// MUST |
2143 |
16 Oct 07 |
gregory |
// HAVE |
2143 |
16 Oct 07 |
gregory |
// "false" |
2143 |
16 Oct 07 |
gregory |
// WHEN |
2143 |
16 Oct 07 |
gregory |
// SENDING |
2143 |
16 Oct 07 |
gregory |
// THE |
2143 |
16 Oct 07 |
gregory |
// HEADERS! |
2143 |
16 Oct 07 |
gregory |
// Otherwise |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// Hexadecimal |
2143 |
16 Oct 07 |
gregory |
// value |
2143 |
16 Oct 07 |
gregory |
// will |
2143 |
16 Oct 07 |
gregory |
// come |
2143 |
16 Oct 07 |
gregory |
// before |
2143 |
16 Oct 07 |
gregory |
// all |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// headers. |
2143 |
16 Oct 07 |
gregory |
// It |
2143 |
16 Oct 07 |
gregory |
// MUST |
2143 |
16 Oct 07 |
gregory |
// come |
2143 |
16 Oct 07 |
gregory |
// just |
2143 |
16 Oct 07 |
gregory |
// before |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// raw |
2143 |
16 Oct 07 |
gregory |
// data |
2143 |
16 Oct 07 |
gregory |
// instead. |
1652 |
22 May 07 |
gregory |
// "Content-Type: text/html; |
1652 |
22 May 07 |
gregory |
// charset=ISO-8859-1\r\n\r\n",false);//NOTE: WE MUST HAVE |
1652 |
22 May 07 |
gregory |
// "false" WHEN SENDING THE HEADERS! Otherwise the Hexadecimal |
1652 |
22 May 07 |
gregory |
// value will come before all the headers. It MUST come just |
1652 |
22 May 07 |
gregory |
// before the raw data instead. |
741 |
10 Oct 06 |
olle |
2187 |
} |
2143 |
16 Oct 07 |
gregory |
2188 |
if (i_sendWhatData != DATATYPE_HEADONLY) |
2143 |
16 Oct 07 |
gregory |
2189 |
{ |
1652 |
22 May 07 |
gregory |
2190 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2191 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2192 |
"<HTML><HEAD><TITLE>Directory Listing for " + s_requestDocument + "</TITLE>" + "<STYLE TYPE=\"text/css\"><!--\n" + "A {text-decoration: none;}" + "\n//--></STYLE>" + "</HEAD>" + "<BODY BGCOLOR=\"#FFFFFF\" COLOR=\"#000000\">" + "<FONT FACE=\"tahoma, arial, verdana\"><H2>Directory Listing for " + s_requestDocument + "</H2></FONT>" + "<PRE>", |
2143 |
16 Oct 07 |
gregory |
2193 |
true); |
1652 |
22 May 07 |
gregory |
2194 |
theOutput.writeBytes(makeFilenameToNiceOutputWithoutHTML( |
2143 |
16 Oct 07 |
gregory |
2195 |
"File name", "File size", "" + "Last modified", |
2143 |
16 Oct 07 |
gregory |
2196 |
i_maxsizeOfFileNameInDirListing), true); |
1652 |
22 May 07 |
gregory |
2197 |
if (!s_requestDocument.equals("/")) |
1652 |
22 May 07 |
gregory |
2198 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2199 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2200 |
"<A HREF=\"../\"><IMG SRC=\"/Image:showFolder\" BORDER=0 ALT=\"Dir\"> ../</A>\n", |
2143 |
16 Oct 07 |
gregory |
2201 |
true); |
1652 |
22 May 07 |
gregory |
2202 |
File theFile; |
1652 |
22 May 07 |
gregory |
2203 |
String tmpFileName; |
1652 |
22 May 07 |
gregory |
2204 |
for (int i = 0; i < allFilesAndFoldersLength; i++) // Optimization... |
741 |
10 Oct 06 |
olle |
2205 |
{ |
1652 |
22 May 07 |
gregory |
2206 |
tmpFileName = allFilesAndFolders[i]; |
1652 |
22 May 07 |
gregory |
2207 |
theFile = new File(s_requestedFolderLocation + tmpFileName); |
2143 |
16 Oct 07 |
gregory |
2208 |
if (theFile.isDirectory()) |
2143 |
16 Oct 07 |
gregory |
2209 |
{ |
1652 |
22 May 07 |
gregory |
2210 |
countFolders++; |
1652 |
22 May 07 |
gregory |
// NOTE: A link to a file called "abc%def.txt" won't |
1652 |
22 May 07 |
gregory |
// work! All "%" has to be replaced with "%25". However, |
1652 |
22 May 07 |
gregory |
// to check all filenames for a % during the listing |
1652 |
22 May 07 |
gregory |
// does take to much time, so we won't bother about |
1652 |
22 May 07 |
gregory |
// this. Note, this "problem" is a common problem (also |
1652 |
22 May 07 |
gregory |
// for many other servers). |
1652 |
22 May 07 |
gregory |
2217 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2218 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2219 |
"<A HREF=\"" + tmpFileName + "\"><IMG SRC=\"/Image:showFolder\" BORDER=0 ALT=\"Dir\"> " + tmpFileName + "</A>\n", |
2143 |
16 Oct 07 |
gregory |
2220 |
true); |
1652 |
22 May 07 |
gregory |
2221 |
allFilesAndFolders[i] = null; |
1652 |
22 May 07 |
gregory |
2222 |
} |
1652 |
22 May 07 |
gregory |
2223 |
} |
1652 |
22 May 07 |
gregory |
// IF [no file extensions added to the list] AND [we allow all |
1652 |
22 May 07 |
gregory |
// extensions], then we don't need to call |
1652 |
22 May 07 |
gregory |
// "isThisFileExtensionAllowed(...)". |
1652 |
22 May 07 |
gregory |
2227 |
boolean shallShowAllFile = (as_fileExtensions.length == 0 && !b_allowTheseFileExtensions); // Optimization... |
1652 |
22 May 07 |
gregory |
2228 |
long tmpFileSize; |
1652 |
22 May 07 |
gregory |
2229 |
for (int i = 0; i < allFilesAndFoldersLength; i++) // Optimization... |
1652 |
22 May 07 |
gregory |
2230 |
{ |
1652 |
22 May 07 |
gregory |
2231 |
tmpFileName = allFilesAndFolders[i]; |
1652 |
22 May 07 |
gregory |
2232 |
if (tmpFileName != null) // It's a file... |
741 |
10 Oct 06 |
olle |
2233 |
{ |
2143 |
16 Oct 07 |
gregory |
2234 |
theFile = new File( |
2143 |
16 Oct 07 |
gregory |
2235 |
s_requestedFolderLocation + tmpFileName); |
1652 |
22 May 07 |
gregory |
2236 |
if (b_shareHiddenFiles || !theFile.isHidden()) // If |
2143 |
16 Oct 07 |
gregory |
// [you |
2143 |
16 Oct 07 |
gregory |
// want |
2143 |
16 Oct 07 |
gregory |
// share |
2143 |
16 Oct 07 |
gregory |
// hidden |
2143 |
16 Oct 07 |
gregory |
// files] |
2143 |
16 Oct 07 |
gregory |
// OR |
2143 |
16 Oct 07 |
gregory |
// [this |
2143 |
16 Oct 07 |
gregory |
// is |
2143 |
16 Oct 07 |
gregory |
// not a |
2143 |
16 Oct 07 |
gregory |
// hidden |
2143 |
16 Oct 07 |
gregory |
// file], |
2143 |
16 Oct 07 |
gregory |
// then... |
1652 |
22 May 07 |
gregory |
2249 |
{ |
2143 |
16 Oct 07 |
gregory |
2250 |
if (shallShowAllFile || isThisFileExtensionAllowed(tmpFileName)) |
2143 |
16 Oct 07 |
gregory |
2251 |
{ |
1652 |
22 May 07 |
gregory |
2252 |
tmpFileSize = theFile.length(); |
1652 |
22 May 07 |
gregory |
2253 |
countFiles++; |
1652 |
22 May 07 |
gregory |
2254 |
totalFolderSize += tmpFileSize; |
1652 |
22 May 07 |
gregory |
2255 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2256 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2257 |
makeFilenameToNiceOutput( |
2143 |
16 Oct 07 |
gregory |
2258 |
tmpFileName, |
2143 |
16 Oct 07 |
gregory |
2259 |
MyString |
2143 |
16 Oct 07 |
gregory |
2260 |
.makeNumberToStringWithApostrophe("" + tmpFileSize), |
2143 |
16 Oct 07 |
gregory |
2261 |
"" + (new Date(theFile |
2143 |
16 Oct 07 |
gregory |
2262 |
.lastModified())), |
2143 |
16 Oct 07 |
gregory |
2263 |
i_maxsizeOfFileNameInDirListing), |
2143 |
16 Oct 07 |
gregory |
2264 |
true); |
1652 |
22 May 07 |
gregory |
2265 |
} |
1652 |
22 May 07 |
gregory |
2266 |
} |
741 |
10 Oct 06 |
olle |
2267 |
} |
741 |
10 Oct 06 |
olle |
2268 |
} |
1652 |
22 May 07 |
gregory |
2269 |
theOutput.writeBytes("\n", true); |
1652 |
22 May 07 |
gregory |
2270 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2271 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2272 |
makeFilenameToNiceOutputWithoutHTML( |
2143 |
16 Oct 07 |
gregory |
2273 |
"Folders: " + countFolders + " Files: " + countFiles, |
2143 |
16 Oct 07 |
gregory |
2274 |
MyString |
2143 |
16 Oct 07 |
gregory |
2275 |
.makeNumberToStringWithApostrophe("" + totalFolderSize), |
2143 |
16 Oct 07 |
gregory |
2276 |
"", i_maxsizeOfFileNameInDirListing), true); |
2143 |
16 Oct 07 |
gregory |
2277 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2278 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2279 |
"</PRE>" + "<HR>" + "<FONT SIZE=\"-1\" FACE=\"arial,verdana\">" + "<CENTER><A HREF=\"http://www.JavaScript.nu/xerver/\">Hosted by Xerver</A></CENTER>" + "</FONT>" + "</BODY></HTML>", |
2143 |
16 Oct 07 |
gregory |
2280 |
true); |
741 |
10 Oct 06 |
olle |
2281 |
theOutput.finalizeDataTransfer(); |
1652 |
22 May 07 |
gregory |
2282 |
} // if (i_sendWhatData!=DATATYPE_HEADONLY) |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before |
1652 |
22 May 07 |
gregory |
// all data has been sent |
741 |
10 Oct 06 |
olle |
2286 |
theOutput.flush(); |
1652 |
22 May 07 |
gregory |
2287 |
so_userConnection.setSoTimeout(i_soTimeoutAfterKeepAliveTransfer);// This |
2143 |
16 Oct 07 |
gregory |
// make |
2143 |
16 Oct 07 |
gregory |
// sure |
2143 |
16 Oct 07 |
gregory |
// that |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// next |
2143 |
16 Oct 07 |
gregory |
// time |
2143 |
16 Oct 07 |
gregory |
// we |
2143 |
16 Oct 07 |
gregory |
// read |
2143 |
16 Oct 07 |
gregory |
// form |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// inputstream |
2143 |
16 Oct 07 |
gregory |
// (read |
2143 |
16 Oct 07 |
gregory |
// what |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// browser |
2143 |
16 Oct 07 |
gregory |
// has |
2143 |
16 Oct 07 |
gregory |
// sent |
2143 |
16 Oct 07 |
gregory |
// to |
2143 |
16 Oct 07 |
gregory |
// us) |
2143 |
16 Oct 07 |
gregory |
// we |
2143 |
16 Oct 07 |
gregory |
// will |
2143 |
16 Oct 07 |
gregory |
// only |
2143 |
16 Oct 07 |
gregory |
// wait |
2143 |
16 Oct 07 |
gregory |
// for |
2143 |
16 Oct 07 |
gregory |
// 5 |
2143 |
16 Oct 07 |
gregory |
// seconds. |
1652 |
22 May 07 |
gregory |
// REMOVE ALL CLOSE: theOutput.close(); |
2143 |
16 Oct 07 |
gregory |
2315 |
} |
2143 |
16 Oct 07 |
gregory |
2316 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
2317 |
{ |
1652 |
22 May 07 |
gregory |
2318 |
if (b_showErrors) |
2143 |
16 Oct 07 |
gregory |
2319 |
System.out |
2143 |
16 Oct 07 |
gregory |
2320 |
.println("An error occured @ showDirectorylisting:\n" + e |
2143 |
16 Oct 07 |
gregory |
2321 |
.getMessage()); |
1652 |
22 May 07 |
gregory |
2322 |
} |
741 |
10 Oct 06 |
olle |
2323 |
} |
741 |
10 Oct 06 |
olle |
2324 |
|
2143 |
16 Oct 07 |
gregory |
2325 |
|
1652 |
22 May 07 |
gregory |
2326 |
private String makeFilenameToNiceOutputWithoutHTML(String fileName, |
2143 |
16 Oct 07 |
gregory |
2327 |
String fileSize, String lastModified, int argMaximumFileNameSize) |
2143 |
16 Oct 07 |
gregory |
2328 |
{ |
1652 |
22 May 07 |
gregory |
2329 |
StringBuffer strBuf = new StringBuffer(" <B>"); // |
2143 |
16 Oct 07 |
gregory |
// required, or |
2143 |
16 Oct 07 |
gregory |
// Opera 7 will |
2143 |
16 Oct 07 |
gregory |
// ignore the |
2143 |
16 Oct 07 |
gregory |
// first spaces |
2143 |
16 Oct 07 |
gregory |
// on each line, |
2143 |
16 Oct 07 |
gregory |
// so start with |
2143 |
16 Oct 07 |
gregory |
// |
2143 |
16 Oct 07 |
gregory |
// instead... |
1652 |
22 May 07 |
gregory |
2338 |
int fileNameLength = fileName.length(); |
2143 |
16 Oct 07 |
gregory |
2339 |
if (fileNameLength < argMaximumFileNameSize) |
2143 |
16 Oct 07 |
gregory |
2340 |
{ |
741 |
10 Oct 06 |
olle |
2341 |
strBuf.append(fileName); |
741 |
10 Oct 06 |
olle |
2342 |
strBuf.append(" "); |
2143 |
16 Oct 07 |
gregory |
2343 |
int forGoesTo = argMaximumFileNameSize + i_maxFileSizeLength - fileNameLength - fileSize |
2143 |
16 Oct 07 |
gregory |
2344 |
.length(); // Optimization... |
1652 |
22 May 07 |
gregory |
2345 |
for (int i = 0; i < forGoesTo; i++) |
1652 |
22 May 07 |
gregory |
// Optimization... |
741 |
10 Oct 06 |
olle |
2347 |
strBuf.append(" "); |
2143 |
16 Oct 07 |
gregory |
2348 |
} |
2143 |
16 Oct 07 |
gregory |
2349 |
else |
2143 |
16 Oct 07 |
gregory |
2350 |
{ |
1652 |
22 May 07 |
gregory |
2351 |
strBuf.append(fileName.substring(0, argMaximumFileNameSize)); |
741 |
10 Oct 06 |
olle |
2352 |
strBuf.append(" "); |
1652 |
22 May 07 |
gregory |
2353 |
int forGoesTo = fileNameLength - fileSize.length(); // Optimization... |
1652 |
22 May 07 |
gregory |
2354 |
for (int i = 0; i < forGoesTo; i++) |
1652 |
22 May 07 |
gregory |
// Optimization... |
741 |
10 Oct 06 |
olle |
2356 |
strBuf.append(" "); |
741 |
10 Oct 06 |
olle |
2357 |
} |
741 |
10 Oct 06 |
olle |
2358 |
strBuf.append(fileSize); |
741 |
10 Oct 06 |
olle |
2359 |
strBuf.append(" "); |
741 |
10 Oct 06 |
olle |
2360 |
strBuf.append(lastModified); |
741 |
10 Oct 06 |
olle |
2361 |
strBuf.append("</B><BR>"); |
741 |
10 Oct 06 |
olle |
2362 |
return strBuf.toString(); |
741 |
10 Oct 06 |
olle |
2363 |
} |
741 |
10 Oct 06 |
olle |
2364 |
|
2143 |
16 Oct 07 |
gregory |
2365 |
|
1652 |
22 May 07 |
gregory |
2366 |
private String makeFilenameToNiceOutput(String fileName, String fileSize, |
2143 |
16 Oct 07 |
gregory |
2367 |
String lastModified, int argMaximumFileNameSize) |
2143 |
16 Oct 07 |
gregory |
2368 |
{ |
1652 |
22 May 07 |
gregory |
2369 |
StringBuffer strBuf = new StringBuffer("<A HREF=\""); |
741 |
10 Oct 06 |
olle |
2370 |
strBuf.append(fileName); |
1652 |
22 May 07 |
gregory |
2371 |
strBuf |
2143 |
16 Oct 07 |
gregory |
2372 |
.append("\" STYLE=\"text-decoration: none;\"><IMG SRC=\"/Image:showFileicon\" BORDER=0 ALT=\"File\"> "); |
1652 |
22 May 07 |
gregory |
2373 |
int fileNameLength = fileName.length(); |
2143 |
16 Oct 07 |
gregory |
2374 |
if (fileNameLength < argMaximumFileNameSize) |
2143 |
16 Oct 07 |
gregory |
2375 |
{ |
741 |
10 Oct 06 |
olle |
2376 |
strBuf.append(fileName); |
741 |
10 Oct 06 |
olle |
2377 |
strBuf.append("</A>"); |
741 |
10 Oct 06 |
olle |
2378 |
strBuf.append(" "); |
2143 |
16 Oct 07 |
gregory |
2379 |
int forGoesTo = argMaximumFileNameSize - fileNameLength + i_maxFileSizeLength - fileSize |
2143 |
16 Oct 07 |
gregory |
2380 |
.length(); // -2, because |
2143 |
16 Oct 07 |
gregory |
// we have two " |
2143 |
16 Oct 07 |
gregory |
// " beside the |
2143 |
16 Oct 07 |
gregory |
// <IMG ...> and |
2143 |
16 Oct 07 |
gregory |
// </A> |
2143 |
16 Oct 07 |
gregory |
// //Optimization... |
1652 |
22 May 07 |
gregory |
2386 |
for (int i = 0; i < forGoesTo; i++) |
1652 |
22 May 07 |
gregory |
// Optimization... |
741 |
10 Oct 06 |
olle |
2388 |
strBuf.append(" "); |
2143 |
16 Oct 07 |
gregory |
2389 |
} |
2143 |
16 Oct 07 |
gregory |
2390 |
else |
2143 |
16 Oct 07 |
gregory |
2391 |
{ |
1652 |
22 May 07 |
gregory |
2392 |
strBuf.append(fileName.substring(0, argMaximumFileNameSize)); |
741 |
10 Oct 06 |
olle |
2393 |
strBuf.append("</A>"); |
741 |
10 Oct 06 |
olle |
2394 |
strBuf.append(" "); |
1652 |
22 May 07 |
gregory |
2395 |
int forGoesTo = i_maxFileSizeLength - fileSize.length(); // -2, |
2143 |
16 Oct 07 |
gregory |
// because |
2143 |
16 Oct 07 |
gregory |
// we |
2143 |
16 Oct 07 |
gregory |
// have |
2143 |
16 Oct 07 |
gregory |
// two " |
2143 |
16 Oct 07 |
gregory |
2400 |
// " |
2143 |
16 Oct 07 |
gregory |
// beside |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// <IMG |
2143 |
16 Oct 07 |
gregory |
2404 |
// ...> |
2143 |
16 Oct 07 |
gregory |
// and |
2143 |
16 Oct 07 |
gregory |
// </A> |
2143 |
16 Oct 07 |
gregory |
// //Optimization... |
1652 |
22 May 07 |
gregory |
2408 |
for (int i = 0; i < forGoesTo; i++) |
1652 |
22 May 07 |
gregory |
// Optimization... |
741 |
10 Oct 06 |
olle |
2410 |
strBuf.append(" "); |
741 |
10 Oct 06 |
olle |
2411 |
} |
1652 |
22 May 07 |
gregory |
// strBuf.append(fileName); |
1652 |
22 May 07 |
gregory |
// int |
1652 |
22 May 07 |
gregory |
// forGoesTo=argMaximumFileNameSize+16-fileName.length()-fileSize.length(); |
1652 |
22 May 07 |
gregory |
// //Optimization... |
1652 |
22 May 07 |
gregory |
// for (int i=0; i<forGoesTo; i++) //Optimization... |
1652 |
22 May 07 |
gregory |
// strBuf.append(" "); |
741 |
10 Oct 06 |
olle |
2418 |
strBuf.append(fileSize); |
741 |
10 Oct 06 |
olle |
2419 |
strBuf.append(" "); |
741 |
10 Oct 06 |
olle |
2420 |
strBuf.append(lastModified); |
741 |
10 Oct 06 |
olle |
2421 |
strBuf.append("<BR>"); |
741 |
10 Oct 06 |
olle |
2422 |
return strBuf.toString(); |
741 |
10 Oct 06 |
olle |
2423 |
} |
741 |
10 Oct 06 |
olle |
2424 |
|
2143 |
16 Oct 07 |
gregory |
2425 |
|
1652 |
22 May 07 |
gregory |
// only s_requestedDocumentWithoutUnescape needs to be set (not the other |
1652 |
22 May 07 |
gregory |
// location-variables) when this is called... |
741 |
10 Oct 06 |
olle |
2428 |
private void redirectToItselfWithSlash()// throws IOException |
741 |
10 Oct 06 |
olle |
2429 |
{ |
2143 |
16 Oct 07 |
gregory |
2430 |
try |
2143 |
16 Oct 07 |
gregory |
2431 |
{ |
1652 |
22 May 07 |
gregory |
2432 |
b_hasBeenRedirected = true; |
1652 |
22 May 07 |
gregory |
2433 |
b_logThisHit = false; |
1652 |
22 May 07 |
gregory |
2434 |
readAllJunkHeaderData(); |
1652 |
22 May 07 |
gregory |
// s_errorStatus="301 Moved Permanently"; |
1652 |
22 May 07 |
gregory |
2436 |
so_userConnection.setSoTimeout(0);// This will make sure that the |
2143 |
16 Oct 07 |
gregory |
// connection doesn't close |
2143 |
16 Oct 07 |
gregory |
// immediately after the file |
2143 |
16 Oct 07 |
gregory |
// download. Why this?: Because |
2143 |
16 Oct 07 |
gregory |
// if we didn't have this, and |
2143 |
16 Oct 07 |
gregory |
// lets say ".getSoTimeout()" is |
2143 |
16 Oct 07 |
gregory |
// 5 sec, then a file download |
2143 |
16 Oct 07 |
gregory |
// on for example 6 seconds |
2143 |
16 Oct 07 |
gregory |
// would result in that the |
2143 |
16 Oct 07 |
gregory |
// connection has been closed as |
2143 |
16 Oct 07 |
gregory |
// soon as we had reached a |
2143 |
16 Oct 07 |
gregory |
// ".read(xxx)"-method. Now we |
2143 |
16 Oct 07 |
gregory |
// set this to 0 (infinity) |
2143 |
16 Oct 07 |
gregory |
// before we send data and we |
2143 |
16 Oct 07 |
gregory |
// set this back to for example |
2143 |
16 Oct 07 |
gregory |
// 5 seconds before we read data |
2143 |
16 Oct 07 |
gregory |
// (call the |
2143 |
16 Oct 07 |
gregory |
// ".read(xxx)"-method). |
1652 |
22 May 07 |
gregory |
// Vid test av fel i Explorer d� man bes�ker "/katalogUtanSlash" och |
1652 |
22 May 07 |
gregory |
// man inte redirectas till "/katalogUtanSlash/". |
1652 |
22 May 07 |
gregory |
// s_requestedHTTP=CONSTANT_HTTP10; |
1652 |
22 May 07 |
gregory |
// b_useKeepAlive=false; |
1652 |
22 May 07 |
gregory |
// i_sendWhatData=DATATYPE_HEADONLY; |
1652 |
22 May 07 |
gregory |
// Note, a bug in Internet Explorer: |
1652 |
22 May 07 |
gregory |
// The behaviour of Internet Explorer is: |
1652 |
22 May 07 |
gregory |
// It sends a request for "/abc%20def" (this bug is only valid for |
1652 |
22 May 07 |
gregory |
// folders with spaces in the name |
1652 |
22 May 07 |
gregory |
// (maybe other special charaters as well)) and then Xerver responds |
1652 |
22 May 07 |
gregory |
// with |
1652 |
22 May 07 |
gregory |
// "HTTP/1.1 301 Moved Permanently" and with a new location which is |
1652 |
22 May 07 |
gregory |
// "/abc%20def/". |
1652 |
22 May 07 |
gregory |
// If the new request that Internet Explorer sends to "/abc%20def/" |
1652 |
22 May 07 |
gregory |
// gives a 403 error response |
1652 |
22 May 07 |
gregory |
// then Explorer will try again and again infinite times!!! |
1652 |
22 May 07 |
gregory |
2470 |
// |
1652 |
22 May 07 |
gregory |
// So once again, if (1) explorer asks for a folder with a space in |
1652 |
22 May 07 |
gregory |
// the name |
1652 |
22 May 07 |
gregory |
// and (2) it ask for the folder name without the last slash (so it |
1652 |
22 May 07 |
gregory |
// recieves a |
1652 |
22 May 07 |
gregory |
// 301 Moved Permanently message) and (3) the folder itself will |
1652 |
22 May 07 |
gregory |
// return an error message, |
1652 |
22 May 07 |
gregory |
// then explorer will go on forever and try to get the folder, |
1652 |
22 May 07 |
gregory |
// ignoring all the 403 messages it receives. |
1652 |
22 May 07 |
gregory |
2479 |
ChunkedDataOutputStream theOutput = new ChunkedDataOutputStream( |
2143 |
16 Oct 07 |
gregory |
2480 |
new BufferedOutputStream(so_userConnection.getOutputStream()), |
2143 |
16 Oct 07 |
gregory |
2481 |
s_requestedHTTP.equals(CONSTANT_HTTP11), b_logThisHit); // Chunked |
2143 |
16 Oct 07 |
gregory |
// data |
2143 |
16 Oct 07 |
gregory |
// transfer |
2143 |
16 Oct 07 |
gregory |
// is |
2143 |
16 Oct 07 |
gregory |
// supported |
2143 |
16 Oct 07 |
gregory |
// only |
2143 |
16 Oct 07 |
gregory |
// with |
2143 |
16 Oct 07 |
gregory |
// HTTP/1.1 |
1652 |
22 May 07 |
gregory |
// theOutput.writeBytes( "HTTP/1.0 303 See Other \r\n"+ |
1652 |
22 May 07 |
gregory |
// theOutput.writeBytes( s_requestedHTTP+" 302 Redirected\n"+ |
1652 |
22 May 07 |
gregory |
// //WARNING!!!! THIS MUST BE "\n", CAN NOT BE "\r\n" HERE, OR IT |
1652 |
22 May 07 |
gregory |
// WON'T WORK WITH ALL BROWSERS, FOR EXAMPLE NETSCAPE 1, EXPLORER 5 |
1652 |
22 May 07 |
gregory |
// M.FL. (seems to be a suspect problem :/ ) |
2143 |
16 Oct 07 |
gregory |
2494 |
if (i_sendWhatData != DATATYPE_BODYONLY) |
2143 |
16 Oct 07 |
gregory |
2495 |
{ |
1652 |
22 May 07 |
gregory |
2496 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2497 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2498 |
(s_requestedHTTP + " 301 Moved Permanently\r\n" + "Date: " + df_dateFormat |
2143 |
16 Oct 07 |
gregory |
2499 |
.format(d_dateToday) + "\r\n" + "Server: " + s_replyServerName + "\r\n" + ((s_requestedHTTP |
2143 |
16 Oct 07 |
gregory |
2500 |
.equals(CONSTANT_HTTP11)) ? ("Transfer-Encoding: chunked\r\n") : ("")) + // Only |
2143 |
16 Oct 07 |
gregory |
// HTTP/1.1-browser |
2143 |
16 Oct 07 |
gregory |
// will |
2143 |
16 Oct 07 |
gregory |
// understand this |
2143 |
16 Oct 07 |
gregory |
2504 |
((b_useKeepAlive) ? ("Connection: Keep-Alive\r\n") : ("Connection: Close\r\n")) + "Location: " + s_requestedDocumentWithoutUnescape + "/\r\n\r\n"), |
2143 |
16 Oct 07 |
gregory |
2505 |
false); |
1652 |
22 May 07 |
gregory |
2506 |
} |
2143 |
16 Oct 07 |
gregory |
2507 |
if (i_sendWhatData != DATATYPE_HEADONLY) |
2143 |
16 Oct 07 |
gregory |
2508 |
{ |
2143 |
16 Oct 07 |
gregory |
2509 |
theOutput |
2143 |
16 Oct 07 |
gregory |
2510 |
.writeBytes( |
2143 |
16 Oct 07 |
gregory |
2511 |
("<html><head>\r\n" + "<title>301 Moved Permanently</title>\r\n" + "</head><body>\r\n" + "<h1>Moved Permanently</h1>\r\n" + "<p>The document has moved <a href=\"" + s_requestedDocumentWithoutUnescape + "/" + "\">here</a>.</p>\r\n" + "</body></html>\r\n"), |
2143 |
16 Oct 07 |
gregory |
2512 |
true); |
1652 |
22 May 07 |
gregory |
2513 |
} |
1652 |
22 May 07 |
gregory |
2514 |
theOutput.finalizeDataTransfer(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: yield(); |
1652 |
22 May 07 |
gregory |
// NO MORE TIMEOUT STUFF: sleep(50); //Be safe, don't close before |
1652 |
22 May 07 |
gregory |
// all data has been sent |
1652 |
22 May 07 |
gregory |
// REMOVE ALL CLOSE: theOutput.close(); |
1652 |
22 May 07 |
gregory |
2519 |
so_userConnection.setSoTimeout(i_soTimeoutAfterKeepAliveTransfer);// This |
2143 |
16 Oct 07 |
gregory |
// make |
2143 |
16 Oct 07 |
gregory |
// sure |
2143 |
16 Oct 07 |
gregory |
// that |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// next |
2143 |
16 Oct 07 |
gregory |
// time |
2143 |
16 Oct 07 |
gregory |
// we |
2143 |
16 Oct 07 |
gregory |
// read |
2143 |
16 Oct 07 |
gregory |
// form |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// inputstream |
2143 |
16 Oct 07 |
gregory |
// (read |
2143 |
16 Oct 07 |
gregory |
// what |
2143 |
16 Oct 07 |
gregory |
// the |
2143 |
16 Oct 07 |
gregory |
// browser |
2143 |
16 Oct 07 |
gregory |
// has |
2143 |
16 Oct 07 |
gregory |
// sent |
2143 |
16 Oct 07 |
gregory |
// to |
2143 |
16 Oct 07 |
gregory |
// us) |
2143 |
16 Oct 07 |
gregory |
// we |
2143 |
16 Oct 07 |
gregory |
// will |
2143 |
16 Oct 07 |
gregory |
// only |
2143 |
16 Oct 07 |
gregory |
// wait |
2143 |
16 Oct 07 |
gregory |
// for |
2143 |
16 Oct 07 |
gregory |
// 5 |
2143 |
16 Oct 07 |
gregory |
// seconds. |
2143 |
16 Oct 07 |
gregory |
2546 |
} |
2143 |
16 Oct 07 |
gregory |
2547 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
2548 |
{ |
1652 |
22 May 07 |
gregory |
2549 |
if (b_showErrors) |
1652 |
22 May 07 |
gregory |
2550 |
System.out |
2143 |
16 Oct 07 |
gregory |
2551 |
.println("An error occured @ redirectToItselfWithSlash:\n" + e |
2143 |
16 Oct 07 |
gregory |
2552 |
.getMessage()); |
1652 |
22 May 07 |
gregory |
2553 |
} |
741 |
10 Oct 06 |
olle |
2554 |
} |
741 |
10 Oct 06 |
olle |
2555 |
|
2143 |
16 Oct 07 |
gregory |
2556 |
|
741 |
10 Oct 06 |
olle |
2557 |
/* |
1652 |
22 May 07 |
gregory |
* private void crateHashTableWithFileExtensions() { HM_allFileExt=new |
1652 |
22 May 07 |
gregory |
* HashMap(); String val; val="text/html"; HM_allFileExt.put("htm",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("shtml",val); HM_allFileExt.put("html",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("shtm",val); HM_allFileExt.put("asp",val); |
1652 |
22 May 07 |
gregory |
* val="text/html"; HM_allFileExt.put("txt",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("text",val); HM_allFileExt.put("c++",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("ini",val); HM_allFileExt.put("pl",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("java",val); HM_allFileExt.put("inf",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("cc",val); HM_allFileExt.put("c",val); |
1652 |
22 May 07 |
gregory |
* val="image/jpeg"; HM_allFileExt.put("jpg",val); |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("jpeg",val); HM_allFileExt.put("jpe",val); |
1652 |
22 May 07 |
gregory |
* val="image/gif"; HM_allFileExt.put("gif",val); val="image/png"; |
1652 |
22 May 07 |
gregory |
* HM_allFileExt.put("png",val); } |
1652 |
22 May 07 |
gregory |
2571 |
*/ |
2143 |
16 Oct 07 |
gregory |
2572 |
private String getMimeTypeFromFileExt(String s_fileExt) |
2143 |
16 Oct 07 |
gregory |
2573 |
{ |
1652 |
22 May 07 |
gregory |
2574 |
if (s_requestedFileName.equals("")) // Note: "s_requestedFileName", not |
2143 |
16 Oct 07 |
gregory |
// "s_fileExt" |
1652 |
22 May 07 |
gregory |
2576 |
return "text/html"; |
2143 |
16 Oct 07 |
gregory |
2577 |
if (s_fileExt.equalsIgnoreCase("htm") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2578 |
.equalsIgnoreCase("shtml") || s_fileExt.equalsIgnoreCase("html") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2579 |
.equalsIgnoreCase("shtm") || s_fileExt.equalsIgnoreCase("asp")) |
1652 |
22 May 07 |
gregory |
2580 |
return "text/html"; |
2143 |
16 Oct 07 |
gregory |
2581 |
if (s_fileExt.equalsIgnoreCase("txt") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2582 |
.equalsIgnoreCase("text") || s_fileExt.equalsIgnoreCase("ini") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2583 |
.equalsIgnoreCase("c") || s_fileExt.equalsIgnoreCase("cc") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2584 |
.equalsIgnoreCase("c++") || s_fileExt.equalsIgnoreCase("h") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2585 |
.equalsIgnoreCase("pl") || s_fileExt.equalsIgnoreCase("java") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2586 |
.equalsIgnoreCase("webl") || s_fileExt.equalsIgnoreCase("inf")) |
1652 |
22 May 07 |
gregory |
2587 |
return "text/plain"; |
2143 |
16 Oct 07 |
gregory |
2588 |
if (s_fileExt.equalsIgnoreCase("jpeg") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2589 |
.equalsIgnoreCase("jpg") || s_fileExt.equalsIgnoreCase("jpe")) |
1652 |
22 May 07 |
gregory |
2590 |
return "image/jpeg"; |
1652 |
22 May 07 |
gregory |
2591 |
if (s_fileExt.equalsIgnoreCase("gif")) |
1652 |
22 May 07 |
gregory |
2592 |
return "image/gif"; |
1652 |
22 May 07 |
gregory |
2593 |
if (s_fileExt.equalsIgnoreCase("png")) |
1652 |
22 May 07 |
gregory |
2594 |
return "image/png"; |
1652 |
22 May 07 |
gregory |
2595 |
if (s_fileExt.equalsIgnoreCase("mov")) |
1652 |
22 May 07 |
gregory |
2596 |
return "video/quicktime"; |
1652 |
22 May 07 |
gregory |
2597 |
if (s_fileExt.equalsIgnoreCase("js")) |
1652 |
22 May 07 |
gregory |
2598 |
return "application/x-javascript"; |
1652 |
22 May 07 |
gregory |
2599 |
if (s_fileExt.equalsIgnoreCase("midi")) |
1652 |
22 May 07 |
gregory |
2600 |
return "audio/midi"; |
1652 |
22 May 07 |
gregory |
2601 |
if (s_fileExt.equalsIgnoreCase("mp2")) |
1652 |
22 May 07 |
gregory |
2602 |
return "audio/mpeg"; |
1652 |
22 May 07 |
gregory |
2603 |
if (s_fileExt.equalsIgnoreCase("mp3")) |
1652 |
22 May 07 |
gregory |
2604 |
return "audio/mpeg"; |
1652 |
22 May 07 |
gregory |
2605 |
if (s_fileExt.equalsIgnoreCase("mpe")) |
1652 |
22 May 07 |
gregory |
2606 |
return "video/mpeg"; |
1652 |
22 May 07 |
gregory |
2607 |
if (s_fileExt.equalsIgnoreCase("mpeg")) |
1652 |
22 May 07 |
gregory |
2608 |
return "video/mpeg"; |
1652 |
22 May 07 |
gregory |
2609 |
if (s_fileExt.equalsIgnoreCase("mpg")) |
1652 |
22 May 07 |
gregory |
2610 |
return "video/mpeg"; |
1652 |
22 May 07 |
gregory |
2611 |
if (s_fileExt.equalsIgnoreCase("mpga")) |
1652 |
22 May 07 |
gregory |
2612 |
return "audio/mpeg"; |
1652 |
22 May 07 |
gregory |
2613 |
if (s_fileExt.equalsIgnoreCase("php3")) |
1652 |
22 May 07 |
gregory |
2614 |
return "application/x-httpd-php3"; |
1652 |
22 May 07 |
gregory |
2615 |
if (s_fileExt.equalsIgnoreCase("phtml-msql2")) |
1652 |
22 May 07 |
gregory |
2616 |
return "application/x-httpd-php-msql2"; |
1652 |
22 May 07 |
gregory |
2617 |
if (s_fileExt.equalsIgnoreCase("phtml")) |
1652 |
22 May 07 |
gregory |
2618 |
return "application/x-httpd-php"; |
1652 |
22 May 07 |
gregory |
2619 |
if (s_fileExt.equalsIgnoreCase("ps")) |
1652 |
22 May 07 |
gregory |
2620 |
return "application/postscript"; |
1652 |
22 May 07 |
gregory |
2621 |
if (s_fileExt.equalsIgnoreCase("wml")) |
1652 |
22 May 07 |
gregory |
2622 |
return "text/vnd.wap.wml"; |
1652 |
22 May 07 |
gregory |
2623 |
if (s_fileExt.equalsIgnoreCase("wbmp")) |
1652 |
22 May 07 |
gregory |
2624 |
return "image/vnd.wap.wbmp"; |
1652 |
22 May 07 |
gregory |
2625 |
if (s_fileExt.equalsIgnoreCase("wmls")) |
1652 |
22 May 07 |
gregory |
2626 |
return "text/vnd.wap.wmlscript"; |
1652 |
22 May 07 |
gregory |
2627 |
if (s_fileExt.equalsIgnoreCase("wmlc")) |
1652 |
22 May 07 |
gregory |
2628 |
return "application/vnd.wap.wmlc"; |
1652 |
22 May 07 |
gregory |
2629 |
if (s_fileExt.equalsIgnoreCase("wmlsc")) |
1652 |
22 May 07 |
gregory |
2630 |
return "application/vnd.wap.wmlscriptc"; |
1652 |
22 May 07 |
gregory |
2631 |
if (s_fileExt.equalsIgnoreCase("ra")) |
1652 |
22 May 07 |
gregory |
2632 |
return "audio/x-realaudio"; |
1652 |
22 May 07 |
gregory |
2633 |
if (s_fileExt.equalsIgnoreCase("ram")) |
1652 |
22 May 07 |
gregory |
2634 |
return "audio/x-pn-realaudio"; |
1652 |
22 May 07 |
gregory |
2635 |
if (s_fileExt.equalsIgnoreCase("pdf")) |
1652 |
22 May 07 |
gregory |
2636 |
return "application/pdf"; |
1652 |
22 May 07 |
gregory |
2637 |
if (s_fileExt.equalsIgnoreCase("swf")) |
1652 |
22 May 07 |
gregory |
2638 |
return "application/x-shockwave-flash"; |
2143 |
16 Oct 07 |
gregory |
2639 |
if (s_fileExt.equalsIgnoreCase("uu") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2640 |
.equalsIgnoreCase("exe")) |
1652 |
22 May 07 |
gregory |
2641 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2642 |
if (s_fileExt.equalsIgnoreCase("ps")) |
1652 |
22 May 07 |
gregory |
2643 |
return "application/postscript"; |
1652 |
22 May 07 |
gregory |
2644 |
if (s_fileExt.equalsIgnoreCase("zip")) |
1652 |
22 May 07 |
gregory |
2645 |
return "application/zip"; |
1652 |
22 May 07 |
gregory |
2646 |
if (s_fileExt.equalsIgnoreCase("sh")) |
1652 |
22 May 07 |
gregory |
2647 |
return "application/x-shar"; |
1652 |
22 May 07 |
gregory |
2648 |
if (s_fileExt.equalsIgnoreCase("tar")) |
1652 |
22 May 07 |
gregory |
2649 |
return "application/x-tar"; |
2143 |
16 Oct 07 |
gregory |
2650 |
if (s_fileExt.equalsIgnoreCase("au") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2651 |
.equalsIgnoreCase("snd")) |
1652 |
22 May 07 |
gregory |
2652 |
return "audio/basic"; |
1652 |
22 May 07 |
gregory |
2653 |
if (s_fileExt.equalsIgnoreCase("wav")) |
1652 |
22 May 07 |
gregory |
2654 |
return "audio/x-wav"; |
1652 |
22 May 07 |
gregory |
2655 |
if (s_fileExt.equalsIgnoreCase("xml")) |
1652 |
22 May 07 |
gregory |
2656 |
return "text/xml"; |
1652 |
22 May 07 |
gregory |
2657 |
if (s_fileExt.equalsIgnoreCase("hqx")) |
1652 |
22 May 07 |
gregory |
2658 |
return "application/mac-binhex40"; |
1652 |
22 May 07 |
gregory |
2659 |
if (s_fileExt.equalsIgnoreCase("cpt")) |
1652 |
22 May 07 |
gregory |
2660 |
return "application/mac-compactpro"; |
1652 |
22 May 07 |
gregory |
2661 |
if (s_fileExt.equalsIgnoreCase("ai")) |
1652 |
22 May 07 |
gregory |
2662 |
return "application/postscript"; |
1652 |
22 May 07 |
gregory |
2663 |
if (s_fileExt.equalsIgnoreCase("aif")) |
1652 |
22 May 07 |
gregory |
2664 |
return "audio/x-aiff"; |
1652 |
22 May 07 |
gregory |
2665 |
if (s_fileExt.equalsIgnoreCase("aifc")) |
1652 |
22 May 07 |
gregory |
2666 |
return "audio/x-aiff"; |
1652 |
22 May 07 |
gregory |
2667 |
if (s_fileExt.equalsIgnoreCase("aiff")) |
1652 |
22 May 07 |
gregory |
2668 |
return "audio/x-aiff"; |
1652 |
22 May 07 |
gregory |
2669 |
if (s_fileExt.equalsIgnoreCase("au")) |
1652 |
22 May 07 |
gregory |
2670 |
return "audio/basic"; |
1652 |
22 May 07 |
gregory |
2671 |
if (s_fileExt.equalsIgnoreCase("avi")) |
1652 |
22 May 07 |
gregory |
2672 |
return "video/x-msvideo"; |
1652 |
22 May 07 |
gregory |
2673 |
if (s_fileExt.equalsIgnoreCase("bcpio")) |
1652 |
22 May 07 |
gregory |
2674 |
return "application/x-bcpio"; |
1652 |
22 May 07 |
gregory |
2675 |
if (s_fileExt.equalsIgnoreCase("bin")) |
1652 |
22 May 07 |
gregory |
2676 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2677 |
if (s_fileExt.equalsIgnoreCase("bmp")) |
1652 |
22 May 07 |
gregory |
2678 |
return "image/x-xbitmap"; |
1652 |
22 May 07 |
gregory |
2679 |
if (s_fileExt.equalsIgnoreCase("cdf")) |
1652 |
22 May 07 |
gregory |
2680 |
return "application/x-netcdf"; |
1652 |
22 May 07 |
gregory |
2681 |
if (s_fileExt.equalsIgnoreCase("class")) |
1652 |
22 May 07 |
gregory |
2682 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2683 |
if (s_fileExt.equalsIgnoreCase("cpio")) |
1652 |
22 May 07 |
gregory |
2684 |
return "application/x-cpio"; |
1652 |
22 May 07 |
gregory |
2685 |
if (s_fileExt.equalsIgnoreCase("cpt")) |
1652 |
22 May 07 |
gregory |
2686 |
return "application/mac-compactpro"; |
1652 |
22 May 07 |
gregory |
2687 |
if (s_fileExt.equalsIgnoreCase("csh")) |
1652 |
22 May 07 |
gregory |
2688 |
return "application/x-csh"; |
1652 |
22 May 07 |
gregory |
2689 |
if (s_fileExt.equalsIgnoreCase("css")) |
1652 |
22 May 07 |
gregory |
2690 |
return "text/css"; |
1652 |
22 May 07 |
gregory |
2691 |
if (s_fileExt.equalsIgnoreCase("dcr")) |
1652 |
22 May 07 |
gregory |
2692 |
return "application/x-director"; |
1652 |
22 May 07 |
gregory |
2693 |
if (s_fileExt.equalsIgnoreCase("dir")) |
1652 |
22 May 07 |
gregory |
2694 |
return "application/x-director"; |
1652 |
22 May 07 |
gregory |
2695 |
if (s_fileExt.equalsIgnoreCase("dll")) |
1652 |
22 May 07 |
gregory |
2696 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2697 |
if (s_fileExt.equalsIgnoreCase("dms")) |
1652 |
22 May 07 |
gregory |
2698 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2699 |
if (s_fileExt.equalsIgnoreCase("doc")) |
1652 |
22 May 07 |
gregory |
2700 |
return "application/msword"; |
1652 |
22 May 07 |
gregory |
2701 |
if (s_fileExt.equalsIgnoreCase("dtd")) |
1652 |
22 May 07 |
gregory |
2702 |
return "text/xml"; |
1652 |
22 May 07 |
gregory |
2703 |
if (s_fileExt.equalsIgnoreCase("dvi")) |
1652 |
22 May 07 |
gregory |
2704 |
return "application/x-dvi"; |
1652 |
22 May 07 |
gregory |
2705 |
if (s_fileExt.equalsIgnoreCase("dwg")) |
1652 |
22 May 07 |
gregory |
2706 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2707 |
if (s_fileExt.equalsIgnoreCase("wax")) |
1652 |
22 May 07 |
gregory |
2708 |
return "audio/x-ms-wax"; |
1652 |
22 May 07 |
gregory |
2709 |
if (s_fileExt.equalsIgnoreCase("wma")) |
1652 |
22 May 07 |
gregory |
2710 |
return "audio/x-ms-wma"; |
1652 |
22 May 07 |
gregory |
2711 |
if (s_fileExt.equalsIgnoreCase("asf")) |
1652 |
22 May 07 |
gregory |
2712 |
return "video/x-ms-asf"; |
1652 |
22 May 07 |
gregory |
2713 |
if (s_fileExt.equalsIgnoreCase("asx")) |
1652 |
22 May 07 |
gregory |
2714 |
return "video/x-ms-asf"; |
1652 |
22 May 07 |
gregory |
2715 |
if (s_fileExt.equalsIgnoreCase("wmv")) |
1652 |
22 May 07 |
gregory |
2716 |
return "video/x-ms-wmv"; |
1652 |
22 May 07 |
gregory |
2717 |
if (s_fileExt.equalsIgnoreCase("wvx")) |
1652 |
22 May 07 |
gregory |
2718 |
return "video/x-ms-wvx"; |
1652 |
22 May 07 |
gregory |
2719 |
if (s_fileExt.equalsIgnoreCase("wm")) |
1652 |
22 May 07 |
gregory |
2720 |
return "video/x-ms-wm"; |
1652 |
22 May 07 |
gregory |
2721 |
if (s_fileExt.equalsIgnoreCase("wmx")) |
1652 |
22 May 07 |
gregory |
2722 |
return "video/x-ms-wmx"; |
1652 |
22 May 07 |
gregory |
2723 |
if (s_fileExt.equalsIgnoreCase("wmz")) |
1652 |
22 May 07 |
gregory |
2724 |
return "application/x-ms-wmz"; |
1652 |
22 May 07 |
gregory |
2725 |
if (s_fileExt.equalsIgnoreCase("wmd")) |
1652 |
22 May 07 |
gregory |
2726 |
return "application/x-ms-wmd"; |
2143 |
16 Oct 07 |
gregory |
2727 |
if (s_fileExt.equalsIgnoreCase("smi") || s_fileExt |
2143 |
16 Oct 07 |
gregory |
2728 |
.equalsIgnoreCase("smil")) |
1652 |
22 May 07 |
gregory |
2729 |
return "application/smil"; |
1652 |
22 May 07 |
gregory |
2730 |
if (s_fileExt.equalsIgnoreCase("rv")) |
1652 |
22 May 07 |
gregory |
2731 |
return "audio/vnd.rn-realvideo"; |
1652 |
22 May 07 |
gregory |
2732 |
if (s_fileExt.equalsIgnoreCase("dxr")) |
1652 |
22 May 07 |
gregory |
2733 |
return "application/x-director"; |
1652 |
22 May 07 |
gregory |
2734 |
if (s_fileExt.equalsIgnoreCase("eps")) |
1652 |
22 May 07 |
gregory |
2735 |
return "application/postscript"; |
1652 |
22 May 07 |
gregory |
2736 |
if (s_fileExt.equalsIgnoreCase("etx")) |
1652 |
22 May 07 |
gregory |
2737 |
return "text/x-setext"; |
1652 |
22 May 07 |
gregory |
2738 |
if (s_fileExt.equalsIgnoreCase("evy")) |
1652 |
22 May 07 |
gregory |
2739 |
return "application/x-envoy"; |
1652 |
22 May 07 |
gregory |
2740 |
if (s_fileExt.equalsIgnoreCase("fif")) |
1652 |
22 May 07 |
gregory |
2741 |
return "application/fractals"; |
1652 |
22 May 07 |
gregory |
2742 |
if (s_fileExt.equalsIgnoreCase("fli")) |
1652 |
22 May 07 |
gregory |
2743 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2744 |
if (s_fileExt.equalsIgnoreCase("gl")) |
1652 |
22 May 07 |
gregory |
2745 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2746 |
if (s_fileExt.equalsIgnoreCase("gtar")) |
1652 |
22 May 07 |
gregory |
2747 |
return "application/x-gtar"; |
1652 |
22 May 07 |
gregory |
2748 |
if (s_fileExt.equalsIgnoreCase("gz")) |
1652 |
22 May 07 |
gregory |
2749 |
return "application/x-gzip"; |
1652 |
22 May 07 |
gregory |
2750 |
if (s_fileExt.equalsIgnoreCase("hdf")) |
1652 |
22 May 07 |
gregory |
2751 |
return "application/x-hdf"; |
1652 |
22 May 07 |
gregory |
2752 |
if (s_fileExt.equalsIgnoreCase("hpx")) |
1652 |
22 May 07 |
gregory |
2753 |
return "application/mac-binhex40"; |
1652 |
22 May 07 |
gregory |
2754 |
if (s_fileExt.equalsIgnoreCase("hqx")) |
1652 |
22 May 07 |
gregory |
2755 |
return "application/mac-binhex40"; |
1652 |
22 May 07 |
gregory |
2756 |
if (s_fileExt.equalsIgnoreCase("ice")) |
1652 |
22 May 07 |
gregory |
2757 |
return "x-conference/x-cooltalk"; |
1652 |
22 May 07 |
gregory |
2758 |
if (s_fileExt.equalsIgnoreCase("ief")) |
1652 |
22 May 07 |
gregory |
2759 |
return "image/ief"; |
1652 |
22 May 07 |
gregory |
2760 |
if (s_fileExt.equalsIgnoreCase("iges")) |
1652 |
22 May 07 |
gregory |
2761 |
return "model/iges"; |
1652 |
22 May 07 |
gregory |
2762 |
if (s_fileExt.equalsIgnoreCase("igs")) |
1652 |
22 May 07 |
gregory |
2763 |
return "model/iges"; |
1652 |
22 May 07 |
gregory |
2764 |
if (s_fileExt.equalsIgnoreCase("isv")) |
1652 |
22 May 07 |
gregory |
2765 |
return "bws-internal/intrasrv-urlencoded"; |
1652 |
22 May 07 |
gregory |
2766 |
if (s_fileExt.equalsIgnoreCase("jfm")) |
1652 |
22 May 07 |
gregory |
2767 |
return "bws-internal/intrasrv-form"; |
1652 |
22 May 07 |
gregory |
2768 |
if (s_fileExt.equalsIgnoreCase("jrp")) |
1652 |
22 May 07 |
gregory |
2769 |
return "bws-internal/intrasrv-report"; |
1652 |
22 May 07 |
gregory |
2770 |
if (s_fileExt.equalsIgnoreCase("kar")) |
1652 |
22 May 07 |
gregory |
2771 |
return "audio/midi"; |
1652 |
22 May 07 |
gregory |
2772 |
if (s_fileExt.equalsIgnoreCase("latex")) |
1652 |
22 May 07 |
gregory |
2773 |
return "application/x-latex"; |
1652 |
22 May 07 |
gregory |
2774 |
if (s_fileExt.equalsIgnoreCase("lha")) |
1652 |
22 May 07 |
gregory |
2775 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2776 |
if (s_fileExt.equalsIgnoreCase("ls")) |
1652 |
22 May 07 |
gregory |
2777 |
return "application/x-javascript"; |
1652 |
22 May 07 |
gregory |
2778 |
if (s_fileExt.equalsIgnoreCase("lzh")) |
1652 |
22 May 07 |
gregory |
2779 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2780 |
if (s_fileExt.equalsIgnoreCase("man")) |
1652 |
22 May 07 |
gregory |
2781 |
return "application/x-troff-man"; |
1652 |
22 May 07 |
gregory |
2782 |
if (s_fileExt.equalsIgnoreCase("me")) |
1652 |
22 May 07 |
gregory |
2783 |
return "application/x-troff-me"; |
1652 |
22 May 07 |
gregory |
2784 |
if (s_fileExt.equalsIgnoreCase("mesh")) |
1652 |
22 May 07 |
gregory |
2785 |
return "model/mesh"; |
1652 |
22 May 07 |
gregory |
2786 |
if (s_fileExt.equalsIgnoreCase("mid")) |
1652 |
22 May 07 |
gregory |
2787 |
return "audio/midi"; |
1652 |
22 May 07 |
gregory |
2788 |
if (s_fileExt.equalsIgnoreCase("mif")) |
1652 |
22 May 07 |
gregory |
2789 |
return "application/x-mif"; |
1652 |
22 May 07 |
gregory |
2790 |
if (s_fileExt.equalsIgnoreCase("movie")) |
1652 |
22 May 07 |
gregory |
2791 |
return "video/x-sgi-movie"; |
1652 |
22 May 07 |
gregory |
2792 |
if (s_fileExt.equalsIgnoreCase("mocha")) |
1652 |
22 May 07 |
gregory |
2793 |
return "application/x-javascript"; |
1652 |
22 May 07 |
gregory |
2794 |
if (s_fileExt.equalsIgnoreCase("ms")) |
1652 |
22 May 07 |
gregory |
2795 |
return "application/x-troff-ms"; |
1652 |
22 May 07 |
gregory |
2796 |
if (s_fileExt.equalsIgnoreCase("msh")) |
1652 |
22 May 07 |
gregory |
2797 |
return "model/mesh"; |
1652 |
22 May 07 |
gregory |
2798 |
if (s_fileExt.equalsIgnoreCase("nc")) |
1652 |
22 May 07 |
gregory |
2799 |
return "application/x-netcdf"; |
1652 |
22 May 07 |
gregory |
2800 |
if (s_fileExt.equalsIgnoreCase("oda")) |
1652 |
22 May 07 |
gregory |
2801 |
return "application/oda"; |
1652 |
22 May 07 |
gregory |
2802 |
if (s_fileExt.equalsIgnoreCase("pac")) |
1652 |
22 May 07 |
gregory |
2803 |
return "application/x-ns-proxy-autoconfig"; |
1652 |
22 May 07 |
gregory |
2804 |
if (s_fileExt.equalsIgnoreCase("pbm")) |
1652 |
22 May 07 |
gregory |
2805 |
return "image/x-portable-bitmap"; |
1652 |
22 May 07 |
gregory |
2806 |
if (s_fileExt.equalsIgnoreCase("pdb")) |
1652 |
22 May 07 |
gregory |
2807 |
return "chemical/x-pdb"; |
1652 |
22 May 07 |
gregory |
2808 |
if (s_fileExt.equalsIgnoreCase("pgm")) |
1652 |
22 May 07 |
gregory |
2809 |
return "image/x-portable-graymap"; |
1652 |
22 May 07 |
gregory |
2810 |
if (s_fileExt.equalsIgnoreCase("pnm")) |
1652 |
22 May 07 |
gregory |
2811 |
return "image/x-portable-anymap"; |
1652 |
22 May 07 |
gregory |
2812 |
if (s_fileExt.equalsIgnoreCase("ppm")) |
1652 |
22 May 07 |
gregory |
2813 |
return "image/x-portable-pixmap"; |
1652 |
22 May 07 |
gregory |
2814 |
if (s_fileExt.equalsIgnoreCase("ppt")) |
1652 |
22 May 07 |
gregory |
2815 |
return "application/powerpoint"; |
1652 |
22 May 07 |
gregory |
2816 |
if (s_fileExt.equalsIgnoreCase("qt")) |
1652 |
22 May 07 |
gregory |
2817 |
return "video/quicktime"; |
1652 |
22 May 07 |
gregory |
2818 |
if (s_fileExt.equalsIgnoreCase("ras")) |
1652 |
22 May 07 |
gregory |
2819 |
return "image/x-cmu-raster"; |
1652 |
22 May 07 |
gregory |
2820 |
if (s_fileExt.equalsIgnoreCase("rgb")) |
1652 |
22 May 07 |
gregory |
2821 |
return "image/x-rgb"; |
1652 |
22 May 07 |
gregory |
2822 |
if (s_fileExt.equalsIgnoreCase("roff")) |
1652 |
22 May 07 |
gregory |
2823 |
return "application/x-troff"; |
1652 |
22 May 07 |
gregory |
2824 |
if (s_fileExt.equalsIgnoreCase("rpm")) |
1652 |
22 May 07 |
gregory |
2825 |
return "audio/x-pn-realaudio-plugin"; |
1652 |
22 May 07 |
gregory |
2826 |
if (s_fileExt.equalsIgnoreCase("rtf")) |
1652 |
22 May 07 |
gregory |
2827 |
return "application/rtf"; |
1652 |
22 May 07 |
gregory |
2828 |
if (s_fileExt.equalsIgnoreCase("rtx")) |
1652 |
22 May 07 |
gregory |
2829 |
return "text/richtext"; |
1652 |
22 May 07 |
gregory |
2830 |
if (s_fileExt.equalsIgnoreCase("scm")) |
1652 |
22 May 07 |
gregory |
2831 |
return "application/octet-stream"; |
1652 |
22 May 07 |
gregory |
2832 |
if (s_fileExt.equalsIgnoreCase("sgm")) |
1652 |
22 May 07 |
gregory |
2833 |
return "text/x-sgml"; |
1652 |
22 May 07 |
gregory |
2834 |
if (s_fileExt.equalsIgnoreCase("sgml")) |
1652 |
22 May 07 |
gregory |
2835 |
return "text/x-sgml"; |
1652 |
22 May 07 |
gregory |
2836 |
if (s_fileExt.equalsIgnoreCase("sh")) |
1652 |
22 May 07 |
gregory |
2837 |
return "application/x-sh"; |
1652 |
22 May 07 |
gregory |
2838 |
if (s_fileExt.equalsIgnoreCase("shar")) |
1652 |
22 May 07 |
gregory |
2839 |
return "application/x-shar"; |
1652 |
22 May 07 |
gregory |
2840 |
if (s_fileExt.equalsIgnoreCase("silo")) |
1652 |
22 May 07 |
gregory |
2841 |
return "model/mesh"; |
1652 |
22 May 07 |
gregory |
2842 |
if (s_fileExt.equalsIgnoreCase("sit")) |
1652 |
22 May 07 |
gregory |
2843 |
return "application/stuffit"; |
1652 |
22 May 07 |
gregory |
2844 |
if (s_fileExt.equalsIgnoreCase("sit")) |
1652 |
22 May 07 |
gregory |
2845 |
return "application/x-stuffit"; |
1652 |
22 May 07 |
gregory |
2846 |
if (s_fileExt.equalsIgnoreCase("skd")) |
1652 |
22 May 07 |
gregory |
2847 |
return "application/x-koan"; |
1652 |
22 May 07 |
gregory |
2848 |
if (s_fileExt.equalsIgnoreCase("skm")) |
1652 |
22 May 07 |
gregory |
2849 |
return "application/x-koan"; |
1652 |
22 May 07 |
gregory |
2850 |
if (s_fileExt.equalsIgnoreCase("skp")) |
1652 |
22 May 07 |
gregory |
2851 |
return "application/x-koan"; |
1652 |
22 May 07 |
gregory |
2852 |
if (s_fileExt.equalsIgnoreCase("skt")) |
1652 |
22 May 07 |
gregory |
2853 |
return "application/x-koan"; |
1652 |
22 May 07 |
gregory |
2854 |
if (s_fileExt.equalsIgnoreCase("snd")) |
1652 |
22 May 07 |
gregory |
2855 |
return "audio/basic"; |
1652 |
22 May 07 |
gregory |
2856 |
if (s_fileExt.equalsIgnoreCase("src")) |
1652 |
22 May 07 |
gregory |
2857 |
return "application/x-wais-source"; |
1652 |
22 May 07 |
gregory |
2858 |
if (s_fileExt.equalsIgnoreCase("sv4cpio")) |
1652 |
22 May 07 |
gregory |
2859 |
return "application/x-sv4cpio"; |
1652 |
22 May 07 |
gregory |
2860 |
if (s_fileExt.equalsIgnoreCase("sv4crc")) |
1652 |
22 May 07 |
gregory |
2861 |
return "application/x-sv4crc"; |
1652 |
22 May 07 |
gregory |
2862 |
if (s_fileExt.equalsIgnoreCase("t")) |
1652 |
22 May 07 |
gregory |
2863 |
return "application/x-troff"; |
1652 |
22 May 07 |
gregory |
2864 |
if (s_fileExt.equalsIgnoreCase("tcl")) |
1652 |
22 May 07 |
gregory |
2865 |
return "application/x-tcl"; |
1652 |
22 May 07 |
gregory |
2866 |
if (s_fileExt.equalsIgnoreCase("tex")) |
1652 |
22 May 07 |
gregory |
2867 |
return "application/x-tex"; |
1652 |
22 May 07 |
gregory |
2868 |
if (s_fileExt.equalsIgnoreCase("texi")) |
1652 |
22 May 07 |
gregory |
2869 |
return "application/x-texinfo"; |
1652 |
22 May 07 |
gregory |
// if ( s_fileExt.equalsIgnoreCase("texi")) |
1652 |
22 May 07 |
gregory |
// return "application/x-textinfo"; |
1652 |
22 May 07 |
gregory |
2872 |
if (s_fileExt.equalsIgnoreCase("texinfo")) |
1652 |
22 May 07 |
gregory |
2873 |
return "application/x-textinfo"; |
1652 |
22 May 07 |
gregory |
2874 |
if (s_fileExt.equalsIgnoreCase("tif")) |
1652 |
22 May 07 |
gregory |
2875 |
return "image/tiff"; |
1652 |
22 May 07 |
gregory |
2876 |
if (s_fileExt.equalsIgnoreCase("tiff")) |
1652 |
22 May 07 |
gregory |
2877 |
return "image/tiff"; |
1652 |
22 May 07 |
gregory |
2878 |
if (s_fileExt.equalsIgnoreCase("tr")) |
1652 |
22 May 07 |
gregory |
2879 |
return "application/x-troff"; |
1652 |
22 May 07 |
gregory |
2880 |
if (s_fileExt.equalsIgnoreCase("tsp")) |
1652 |
22 May 07 |
gregory |
2881 |
return "application/dsptype"; |
1652 |
22 May 07 |
gregory |
2882 |
if (s_fileExt.equalsIgnoreCase("tsv")) |
1652 |
22 May 07 |
gregory |
2883 |
return "text/tab-separated-values"; |
1652 |
22 May 07 |
gregory |
2884 |
if (s_fileExt.equalsIgnoreCase("ustar")) |
1652 |
22 May 07 |
gregory |
2885 |
return "application/x-ustar"; |
1652 |
22 May 07 |
gregory |
2886 |
if (s_fileExt.equalsIgnoreCase("vcd")) |
1652 |
22 May 07 |
gregory |
2887 |
return "application/x-cdlink"; |
1652 |
22 May 07 |
gregory |
2888 |
if (s_fileExt.equalsIgnoreCase("vox")) |
1652 |
22 May 07 |
gregory |
2889 |
return "audio/voxware"; |
1652 |
22 May 07 |
gregory |
2890 |
if (s_fileExt.equalsIgnoreCase("vrml")) |
1652 |
22 May 07 |
gregory |
2891 |
return "model/vrml"; |
1652 |
22 May 07 |
gregory |
2892 |
if (s_fileExt.equalsIgnoreCase("wrl")) |
1652 |
22 May 07 |
gregory |
2893 |
return "model/vrml"; |
1652 |
22 May 07 |
gregory |
2894 |
if (s_fileExt.equalsIgnoreCase("xbm")) |
1652 |
22 May 07 |
gregory |
2895 |
return "image/x-xbitmap"; |
1652 |
22 May 07 |
gregory |
2896 |
if (s_fileExt.equalsIgnoreCase("xml")) |
1652 |
22 May 07 |
gregory |
2897 |
return "text/xml"; |
1652 |
22 May 07 |
gregory |
2898 |
if (s_fileExt.equalsIgnoreCase("xpm")) |
1652 |
22 May 07 |
gregory |
2899 |
return "image/x-xpixmap"; |
1652 |
22 May 07 |
gregory |
2900 |
if (s_fileExt.equalsIgnoreCase("xwd")) |
1652 |
22 May 07 |
gregory |
2901 |
return "image/x-xwindowdump"; |
1652 |
22 May 07 |
gregory |
2902 |
if (s_fileExt.equalsIgnoreCase("xyz")) |
1652 |
22 May 07 |
gregory |
2903 |
return "chemical/x-pdb"; |
1652 |
22 May 07 |
gregory |
2904 |
if (s_fileExt.equalsIgnoreCase("z")) |
1652 |
22 May 07 |
gregory |
2905 |
return "application/x-compress"; |
1652 |
22 May 07 |
gregory |
2906 |
return "text/plain"; // Default |
741 |
10 Oct 06 |
olle |
2907 |
} |
741 |
10 Oct 06 |
olle |
2908 |
|
2143 |
16 Oct 07 |
gregory |
2909 |
|
1652 |
22 May 07 |
gregory |
2910 |
/* |
1652 |
22 May 07 |
gregory |
* private void exceptionOccured(Exception e) { |
1652 |
22 May 07 |
gregory |
* System.out.println(b_isRunningScript+" <==> "+e); if (b_isRunningScript) { |
1652 |
22 May 07 |
gregory |
* rs_process.killProcess(); } } |
1652 |
22 May 07 |
gregory |
2914 |
*/ |
1652 |
22 May 07 |
gregory |
// Testing... |
2386 |
14 Nov 07 |
gregory |
2916 |
@Override |
2143 |
16 Oct 07 |
gregory |
2917 |
protected void finalize() |
2143 |
16 Oct 07 |
gregory |
2918 |
throws Throwable |
2143 |
16 Oct 07 |
gregory |
2919 |
{ |
2143 |
16 Oct 07 |
gregory |
2920 |
if (so_userConnection != null) |
2143 |
16 Oct 07 |
gregory |
2921 |
{ |
1652 |
22 May 07 |
gregory |
// System.out.println("so_userConnection �r inte null."); |
2143 |
16 Oct 07 |
gregory |
2923 |
try |
2143 |
16 Oct 07 |
gregory |
2924 |
{ |
1652 |
22 May 07 |
gregory |
2925 |
if (so_userConnection.getOutputStream() != null) |
741 |
10 Oct 06 |
olle |
2926 |
so_userConnection.getOutputStream().flush(); |
2143 |
16 Oct 07 |
gregory |
2927 |
} |
2143 |
16 Oct 07 |
gregory |
2928 |
catch (Exception e) |
2143 |
16 Oct 07 |
gregory |
2929 |
{ |
1652 |
22 May 07 |
gregory |
// System.out.println("so_userConnection.getOutputStream() kan |
1652 |
22 May 07 |
gregory |
// inte flush:as."); |
741 |
10 Oct 06 |
olle |
2932 |
} |
741 |
10 Oct 06 |
olle |
2933 |
so_userConnection.close(); |
1652 |
22 May 07 |
gregory |
2934 |
so_userConnection = null; |
741 |
10 Oct 06 |
olle |
2935 |
} |
741 |
10 Oct 06 |
olle |
2936 |
} |
741 |
10 Oct 06 |
olle |
2937 |
} |