client/ftpd/src/se/lu/thep/coreftpd/webserver/NewConnection.java

Code
Comments
Other
Rev Date Author Line
741 10 Oct 06 olle 1 /*
1652 22 May 07 gregory 2  $Id$
741 10 Oct 06 olle 3
1916 31 Aug 07 jari 4  Copyright (C) 2006 Olle Mansson
1916 31 Aug 07 jari 5  Copyright (C) 2007 Gregory Vincic
741 10 Oct 06 olle 6
1652 22 May 07 gregory 7  This file is part of Proteios.
1652 22 May 07 gregory 8  Available at http://www.proteios.org/
741 10 Oct 06 olle 9
1652 22 May 07 gregory 10  Proteios is free software; you can redistribute it and/or modify it
1652 22 May 07 gregory 11  under the terms of the GNU General Public License as published by
1652 22 May 07 gregory 12  the Free Software Foundation; either version 2 of the License, or
1652 22 May 07 gregory 13  (at your option) any later version.
741 10 Oct 06 olle 14
1652 22 May 07 gregory 15  Proteios is distributed in the hope that it will be useful, but
1652 22 May 07 gregory 16  WITHOUT ANY WARRANTY; without even the implied warranty of
1652 22 May 07 gregory 17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1652 22 May 07 gregory 18  General Public License for more details.
741 10 Oct 06 olle 19
1652 22 May 07 gregory 20  You should have received a copy of the GNU General Public License
1652 22 May 07 gregory 21  along with this program; if not, write to the Free Software
1652 22 May 07 gregory 22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1652 22 May 07 gregory 23  02111-1307, USA.
1652 22 May 07 gregory 24  */
741 10 Oct 06 olle 25 //  Xerver Free Web Server
741 10 Oct 06 olle 26 //  Copyright (C) 2002-2005 Omid Rouhani
741 10 Oct 06 olle 27 //
741 10 Oct 06 olle 28 //
741 10 Oct 06 olle 29 //  This program is free software; you can redistribute it and/or
741 10 Oct 06 olle 30 //  modify it under the terms of the GNU General Public License
741 10 Oct 06 olle 31 //  as published by the Free Software Foundation; either version 2
741 10 Oct 06 olle 32 //  of the License, or (at your option) any later version.
741 10 Oct 06 olle 33 //
741 10 Oct 06 olle 34 //  This program is distributed in the hope that it will be useful,
741 10 Oct 06 olle 35 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
741 10 Oct 06 olle 36 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
741 10 Oct 06 olle 37 //  GNU General Public License for more details.
741 10 Oct 06 olle 38 //
741 10 Oct 06 olle 39 //  You should have received a copy of the GNU General Public License
741 10 Oct 06 olle 40 //  along with this program; if not, write to the Free Software
741 10 Oct 06 olle 41 //  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 45 //  ##  YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT:          ##
741 10 Oct 06 olle 46 //  ##  HTTP://WWW.JAVASCRIPT.NU/XERVER/                       ##
741 10 Oct 06 olle 47 //  ##                                                         ##
741 10 Oct 06 olle 48 //  ##  IF YOUR SOFTWARE IS NOT RELEASED UNDER THE             ##
741 10 Oct 06 olle 49 //  ##  GNU GENERAL PUBLIC LICENSE (GPL),                      ##
741 10 Oct 06 olle 50 //  ##  PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!!   ##
741 10 Oct 06 olle 51 //  ##                                                         ##
741 10 Oct 06 olle 52 //  ##  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 72  * <B>About this class:</B> <BR>
2143 16 Oct 07 gregory 73  * Every time a connection is established to Xerver, a
2143 16 Oct 07 gregory 74  * <CODE>NewConnection</CODE> is created. <BR>
1652 22 May 07 gregory 75  * <CODE>NewConnection</CODE> is a <CODE>Thread</CODE> and reads what the
1652 22 May 07 gregory 76  * user requested and gives the user an appropriate response to his/her request.
741 10 Oct 06 olle 77  * <BR>
1652 22 May 07 gregory 78  * This is the most "important class" in Xerver and is probably the class you
1652 22 May 07 gregory 79  * shall rewrite if you want to add more features to Xerver. <BR>
1652 22 May 07 gregory 80  * 
741 10 Oct 06 olle 81  * @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a>
741 10 Oct 06 olle 82  * @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 91   // and only if you are
2143 16 Oct 07 gregory 92   // debugging and want to
2143 16 Oct 07 gregory 93   // see what is happening
2143 16 Oct 07 gregory 94   // 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 102    * Number of bytes sent via headers/directory listings etc. are NOT
2143 16 Oct 07 gregory 103    * included. Only number of bytes from files are content. (HOWEVER:
2143 16 Oct 07 gregory 104    * directory listing does show icons, which are downloaded as regular files,
2143 16 Oct 07 gregory 105    * so a directory listing with an browser supporting images WILL result in
2143 16 Oct 07 gregory 106    * 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 121   // will be opened. If this is
2143 16 Oct 07 gregory 122   // false, the awt-window will be
2143 16 Oct 07 gregory 123   // used. NOTE: When you start
2143 16 Oct 07 gregory 124   // this class from the Swing
2143 16 Oct 07 gregory 125   // interface, this will be set
2143 16 Oct 07 gregory 126   // to true so that the
2143 16 Oct 07 gregory 127   // AWT-window won't popup //When
2143 16 Oct 07 gregory 128   // you call the
2143 16 Oct 07 gregory 129   // XerverKernel()-constructor
2143 16 Oct 07 gregory 130   // this varaiable will be set to
2143 16 Oct 07 gregory 131   // true/false depending on what
2143 16 Oct 07 gregory 132   // you have choosed in the
2143 16 Oct 07 gregory 133   // setup-file: true=[0=you have
2143 16 Oct 07 gregory 134   // choosen to run with no
2143 16 Oct 07 gregory 135   // "window"]; false=[1 = you
2143 16 Oct 07 gregory 136   // have choosen to use a static
2143 16 Oct 07 gregory 137   // window (AWT); 2 = you have
2143 16 Oct 07 gregory 138   // choosen to use the most
2143 16 Oct 07 gregory 139   // advanced interface (with
2143 16 Oct 07 gregory 140   // 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 147    * b_isRunningScript is used so we know if a script is being run. If a
2143 16 Oct 07 gregory 148    * script is being run, NewConnection shall not close the OutputStream, but
2143 16 Oct 07 gregory 149    * ReadInputStreamSTDERR/STDOUT shall close the stream. //b_isRunningScript
2143 16 Oct 07 gregory 150    * is also used to that if an exception occur so that the NewConnection
2143 16 Oct 07 gregory 151    * thread will terminate then we shall kill the script-process so that we
2143 16 Oct 07 gregory 152    * 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 158    * This can be set to anything you believe is suitable. This is to make sure
2143 16 Oct 07 gregory 159    * we don't read and buffer very long header-lines sent by browser (in case
2143 16 Oct 07 gregory 160    * 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 164       // is only used when
2143 16 Oct 07 gregory 165       // someone visits
2143 16 Oct 07 gregory 166       // "http://server.com/folder"
2143 16 Oct 07 gregory 167       // and shall be
2143 16 Oct 07 gregory 168       // redirected to
2143 16 Oct 07 gregory 169       // "http://server.com/folder/".
2143 16 Oct 07 gregory 170       // This is a MUST when
2143 16 Oct 07 gregory 171       // the folder contains
2143 16 Oct 07 gregory 172       // for example the
2143 16 Oct 07 gregory 173       // swedish letters ���.
1652 22 May 07 gregory 174       // if someone visits "http://server.com/folder/folder2/file.txt" the
1652 22 May 07 gregory 175       // 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 183       // "HTTP/0.9"
1652 22 May 07 gregory 184       s_requestQueryString, // "file.htm?hello" ==> "hello", otherwise
2143 16 Oct 07 gregory 185       // 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 187       // a whole realm
1652 22 May 07 gregory 188       s_encryptedPasswordGiven, // Format: "encryptedPassword"
2143 16 Oct 07 gregory 189       // (actually, it is "user:pass" but
2143 16 Oct 07 gregory 190       // encrypted)
1652 22 May 07 gregory 191       s_visitorUsername, // Note: the username for this login:
2143 16 Oct 07 gregory 192       // [user:Donald; pass:Duck] can be
2143 16 Oct 07 gregory 193       // "anOtherUsername" (it can of course also be
2143 16 Oct 07 gregory 194       // "Donald")
1652 22 May 07 gregory 195       s_hostnameGivenByBrowser = null; // The string sent by browser in
2143 16 Oct 07 gregory 196   // "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 199    * For each and every time you are going to use any of these, call
2143 16 Oct 07 gregory 200    * "createEnvironmentVariables()" (after you have called
2143 16 Oct 07 gregory 201    * "createEnvironmentVariables()" once, you can call
2143 16 Oct 07 gregory 202    * "createEnvironmentVariables()" several times without wasteing system
2143 16 Oct 07 gregory 203    * 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 207   // path
2143 16 Oct 07 gregory 208   // ==>
2143 16 Oct 07 gregory 209   // "/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 217    * Maximum number of environment variables the browser can tell us* to
2143 16 Oct 07 gregory 218    * create. (Note: We might have more than 200 environment variables; because
2143 16 Oct 07 gregory 219    * we don't only create environment variables that the browser tell us to
2143 16 Oct 07 gregory 220    * create). If a browser gives more than 200 environment variables, we just
2143 16 Oct 07 gregory 221    * 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 225   // 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 230   // create these all the
2143 16 Oct 07 gregory 231   // 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 242   // IOException
741 10 Oct 06 olle 243   {
1652 22 May 07 gregory 244     super(argThreadGroup, "Connection");
1652 22 May 07 gregory 245     // 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 257       /* 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 266       // 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 270       /* 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 297         // matters to what. This will be
2143 16 Oct 07 gregory 298         // sent together with the header for
2143 16 Oct 07 gregory 299         // 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 307       // "readHeaderSentByBrowser();"
2143 16 Oct 07 gregory 308       // before you run
2143 16 Oct 07 gregory 309       // 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 312       // important to make sure that a
2143 16 Oct 07 gregory 313       // password protected folder wont be
2143 16 Oct 07 gregory 314       // listed when entering "GET
2143 16 Oct 07 gregory 315       // /secretFolderWITHOUTslashAtEnd
2143 16 Oct 07 gregory 316       // HTTP/1.1"! Without this the server
2143 16 Oct 07 gregory 317       // first sends the 302 Redirected
2143 16 Oct 07 gregory 318       // header, and then the listing of the
2143 16 Oct 07 gregory 319       // folder (which won't be listed with a
2143 16 Oct 07 gregory 320       // normal browser, as the 302-header is
2143 16 Oct 07 gregory 321       // sent first, but still, the hidden
2143 16 Oct 07 gregory 322       // data is being showed! (with this we
2143 16 Oct 07 gregory 323       // have prevented this scenario))
741 10 Oct 06 olle 324       {
1652 22 May 07 gregory 325         // 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 327       // //s_requestDocument has to be set when you run
2143 16 Oct 07 gregory 328       // checkForReservedPaths
2143 16 Oct 07 gregory 329       else if (checkForReservedPaths())
2143 16 Oct 07 gregory 330       {
1652 22 May 07 gregory 331         // "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 352       // folder and there is
2143 16 Oct 07 gregory 353       // no index-file to
2143 16 Oct 07 gregory 354       // 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 357           // 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 392         // "/folder/" and don't count the reserved paths
2143 16 Oct 07 gregory 393         // (when the user is downloading an image while
2143 16 Oct 07 gregory 394         // 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 400         // 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 408       // script we shall use Keep-Alive. Otherwise
2143 16 Oct 07 gregory 409       // ReadInputStreamSTDERR/STDOUT should close
2143 16 Oct 07 gregory 410       // the stream.
741 10 Oct 06 olle 411       {
1652 22 May 07 gregory 412         // yield();//Do I want this line or not??
1652 22 May 07 gregory 413         // sleep(150); //Wait before we close the OutputStream so that
1652 22 May 07 gregory 414         // all data actually get sent before we close the OutputStream
1652 22 May 07 gregory 415         // so_userConnection.getOutputStream().close();
1652 22 May 07 gregory 416         // so_userConnection.close();
1652 22 May 07 gregory 417         // This is faster than closing the connection (without
1652 22 May 07 gregory 418         // 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 425         // has been running (but an old
2143 16 Oct 07 gregory 426         // browser without
2143 16 Oct 07 gregory 427         // 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 443     // null as ReadInputStreamxxx can call this
2143 16 Oct 07 gregory 444     // 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 447         // correctly (for example: not a
2143 16 Oct 07 gregory 448         // "404 error" or a "redirect"
2143 16 Oct 07 gregory 449         // 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 460        * Use intern to use less memory (it does really use less memory? I
2143 16 Oct 07 gregory 461        * 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 468   // The following variables will be set here:
1652 22 May 07 gregory 469   // s_requestedHTTP
1652 22 May 07 gregory 470   // s_requestMethod
1652 22 May 07 gregory 471   // 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 477       // ##########################READ INFORMATION GIVEN BY
1652 22 May 07 gregory 478       // BROWSER####################
1652 22 May 07 gregory 479       // NOTE:
1652 22 May 07 gregory 480       // The first line in the Header-data that the browser sends is:
1652 22 May 07 gregory 481       // "GET /folder/file.txt HTTP/1.1"
1652 22 May 07 gregory 482       // However, if you run the command "lynx myserver.com", Lynx
1652 22 May 07 gregory 483       // establishes two connections.
1652 22 May 07 gregory 484       // The first one sends this first line header:
1652 22 May 07 gregory 485       // "GET /folder/ HTTP/1.0"
1652 22 May 07 gregory 486       // The second time it sends this line, which is a HTTP/0.9-syntax:
1652 22 May 07 gregory 487       // "GET /folder/"
741 10 Oct 06 olle 488       //
1652 22 May 07 gregory 489       // Also beware, a request for a folder such as "/dir with space/" is
1652 22 May 07 gregory 490       // sent as:
1652 22 May 07 gregory 491       // "GET /dir with space/ HTTP/1.0"
1652 22 May 07 gregory 492       // and then (which also is a HTTP/0.9-syntax):
1652 22 May 07 gregory 493       // "GET /dir with space/"
741 10 Oct 06 olle 494       //
1652 22 May 07 gregory 495       // Note, no headers shall be sent when a HTTP/0.9 request is
1652 22 May 07 gregory 496       // received, a valid request/response might be:
1652 22 May 07 gregory 497       // "GET /foo.txt"
1652 22 May 07 gregory 498       // "This is a one-line file."
741 10 Oct 06 olle 499       //
1652 22 May 07 gregory 500       // But Xerver don't care about this and sends an valid
1652 22 May 07 gregory 501       // HTTP/1.1-response to a HTTP/0.9-request.
1652 22 May 07 gregory 502       // The reason for this is that (for example) Lynx sends
1652 22 May 07 gregory 503       // 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 509        * "GET /mapp/fil.txt HTTP/1.1" //i_maxLineLengthReadFromHeader*4
2143 16 Oct 07 gregory 510        * can be anything that you believe is long enough to store an URL
2143 16 Oct 07 gregory 511        * and the GET-data which might come with it, but not so long that a
2143 16 Oct 07 gregory 512        * hacker would try to use all our memory by sending a very large
2143 16 Oct 07 gregory 513        * 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 519       // are
2143 16 Oct 07 gregory 520       // two
2143 16 Oct 07 gregory 521       // " "
2143 16 Oct 07 gregory 522       // in
2143 16 Oct 07 gregory 523       // 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 527         // firstLineIndata
2143 16 Oct 07 gregory 528         // ends
2143 16 Oct 07 gregory 529         // with
2143 16 Oct 07 gregory 530         // "HTTP/0.9",
2143 16 Oct 07 gregory 531         // "HTTP/1.0"
2143 16 Oct 07 gregory 532         // or
2143 16 Oct 07 gregory 533         // "HTTP/1.1"
2143 16 Oct 07 gregory 534         // //(everything
2143 16 Oct 07 gregory 535         // is
2143 16 Oct 07 gregory 536         // 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 549         // A request such as "GET /dir with space/" has been
2143 16 Oct 07 gregory 550         // made (probably by lynx, but might also happen with
2143 16 Oct 07 gregory 551         // 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 560           // you want, it doesn't
2143 16 Oct 07 gregory 561           // 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 565       // Lynx sometimes sends a stupid request like "GET /", which
2143 16 Oct 07 gregory 566       // will result in... (This is a valid HTTP/0.9-syntax, but I
2143 16 Oct 07 gregory 567       // 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 576         // want, it doesn't
2143 16 Oct 07 gregory 577         // 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 589        * "/folder/ " ==> "/folder/" (This line is in case someone makes a
2143 16 Oct 07 gregory 590        * request such as "GET /folder/ HTTP/1.0", which would result in
2143 16 Oct 07 gregory 591        * 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 606       // "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 616       // 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 621          * s_requestDocument="/"; //Set this to something... don't
1652 22 May 07 gregory 622          * matters to what. This will be sent together with the header
1652 22 May 07 gregory 623          * for the "400 Bad Request". b_logThisHit=false;
1652 22 May 07 gregory 624          * s_errorStatus="400 Bad Request"; showError("The client has
1652 22 May 07 gregory 625          * sent an invalid
1652 22 May 07 gregory 626          * 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 632         // 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 640   // From Opera:
1652 22 May 07 gregory 641   // GET /?y4errewfdpp HTTP/1.1
1652 22 May 07 gregory 642   // User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0 [sv]
1652 22 May 07 gregory 643   // Host: localhost:12345
1652 22 May 07 gregory 644   // Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
1652 22 May 07 gregory 645   // Accept-Language: sv
1652 22 May 07 gregory 646   // Accept-Charset: windows-1252;q=1.0, utf-8;q=1.0, utf-16;q=1.0,
1652 22 May 07 gregory 647   // iso-8859-1;q=0.6, *;q=0.1
1652 22 May 07 gregory 648   // Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
1652 22 May 07 gregory 649   // Cache-Control: no-cache
1652 22 May 07 gregory 650   // Connection: Keep-Alive, TE
1652 22 May 07 gregory 651   // TE: deflate, gzip, chunked, identity, trailers
1652 22 May 07 gregory 652   private void setLocationParts(String relativePath,
2143 16 Oct 07 gregory 653       String rootLocationWithoutSlashAtEnd)
2143 16 Oct 07 gregory 654   {
741 10 Oct 06 olle 655     String s_fileOrFolderThatIsReadOnHardDrive;
1652 22 May 07 gregory 656     String fileExtension = "", folderLocation = "", fileName = "";
741 10 Oct 06 olle 657     File thisFolder;
741 10 Oct 06 olle 658     int sizeOfAliasName;
1652 22 May 07 gregory 659     int fileStatus = -1;
1652 22 May 07 gregory 660     sizeOfAliasName = myHT_allAliases.giveBiggestKeySize(relativePath); // gives
2143 16 Oct 07 gregory 661     // the
2143 16 Oct 07 gregory 662     // size
2143 16 Oct 07 gregory 663     // of
2143 16 Oct 07 gregory 664     // the
2143 16 Oct 07 gregory 665     // alias
2143 16 Oct 07 gregory 666     // name...
2143 16 Oct 07 gregory 667     // ("/alias/folder/file.txt"
2143 16 Oct 07 gregory 668     // ==>
2143 16 Oct 07 gregory 669     // "7")
1652 22 May 07 gregory 670     // ##############Start giving values to the variables##############
1652 22 May 07 gregory 671     if (sizeOfAliasName == -1) // You are not visiting an alias
741 10 Oct 06 olle 672     {
2143 16 Oct 07 gregory 673       s_fileOrFolderThatIsReadOnHardDrive = rootLocationWithoutSlashAtEnd + relativePath
2143 16 Oct 07 gregory 674         .replace('/', File.separatorChar);
2143 16 Oct 07 gregory 675     }
2143 16 Oct 07 gregory 676     else
2143 16 Oct 07 gregory 677     // you are visiting an alias
1652 22 May 07 gregory 678     {
1652 22 May 07 gregory 679       s_fileOrFolderThatIsReadOnHardDrive = getCorrectFolderFromAlias(relativePath
2143 16 Oct 07 gregory 680         .substring(0, sizeOfAliasName)) + relativePath.substring(
2143 16 Oct 07 gregory 681         sizeOfAliasName).replace('/', File.separatorChar);
741 10 Oct 06 olle 682     }
1652 22 May 07 gregory 683     thisFolder = new File(s_fileOrFolderThatIsReadOnHardDrive);
2143 16 Oct 07 gregory 684     if (thisFolder.exists())
2143 16 Oct 07 gregory 685     {
2143 16 Oct 07 gregory 686       if (thisFolder.isFile() && !relativePath.endsWith("/"))
2143 16 Oct 07 gregory 687       {
1652 22 May 07 gregory 688         fileStatus = ISFILE;
1652 22 May 07 gregory 689         folderLocation = s_fileOrFolderThatIsReadOnHardDrive.substring(
2143 16 Oct 07 gregory 690           0, s_fileOrFolderThatIsReadOnHardDrive
2143 16 Oct 07 gregory 691             .lastIndexOf(File.separatorChar) + 1);
1652 22 May 07 gregory 692         fileName = s_fileOrFolderThatIsReadOnHardDrive
2143 16 Oct 07 gregory 693           .substring(s_fileOrFolderThatIsReadOnHardDrive
2143 16 Oct 07 gregory 694             .lastIndexOf(File.separatorChar) + 1);
2143 16 Oct 07 gregory 695         while (fileName.endsWith("."))
2143 16 Oct 07 gregory 696         {
1652 22 May 07 gregory 697           fileName = fileName.substring(0, fileName.length() - 1);
1652 22 May 07 gregory 698         } // "script.pl..." ==> "script.pl" (since Xerver consider
2143 16 Oct 07 gregory 699         // "script.pl..." to be the filename (and null is the file
2143 16 Oct 07 gregory 700         // extension), but the file system will show the content of
2143 16 Oct 07 gregory 701         // "script.pl" when xerver asks for the content of
2143 16 Oct 07 gregory 702         // "script.pl...", so you can see source code of arbitrary
2143 16 Oct 07 gregory 703         // script file)
1652 22 May 07 gregory 704         fileExtension = fileName
2143 16 Oct 07 gregory 705           .substring(fileName.lastIndexOf('.') + 1);
2143 16 Oct 07 gregory 706       }
2143 16 Oct 07 gregory 707       else if (thisFolder.isDirectory())
2143 16 Oct 07 gregory 708       {
1652 22 May 07 gregory 709         fileStatus = ISFOLDER;
1652 22 May 07 gregory 710         folderLocation = s_fileOrFolderThatIsReadOnHardDrive;
1652 22 May 07 gregory 711         fileName = giveNameOfIndexFile(folderLocation); // Returns the
2143 16 Oct 07 gregory 712         // name of the
2143 16 Oct 07 gregory 713         // correct
2143 16 Oct 07 gregory 714         // index-file,
2143 16 Oct 07 gregory 715         // if there is
2143 16 Oct 07 gregory 716         // any.
2143 16 Oct 07 gregory 717         // Otherwise
2143 16 Oct 07 gregory 718         // this returns
2143 16 Oct 07 gregory 719         // ""
1652 22 May 07 gregory 720         fileExtension = "";
2143 16 Oct 07 gregory 721       }
2143 16 Oct 07 gregory 722       else
2143 16 Oct 07 gregory 723       // someone is visiting "/folder/fileExists.txt/".
2143 16 Oct 07 gregory 724       // thisFolder.exists() tells this is a file, but as the
2143 16 Oct 07 gregory 725       // visitor did request "/folder/fileExists.txt/" (and not
2143 16 Oct 07 gregory 726       // "/folder/fileExists.txt") we pretend the file doesn't
2143 16 Oct 07 gregory 727       // exists
741 10 Oct 06 olle 728       {
1652 22 May 07 gregory 729         fileStatus = DOESNOTEXISTS;
1652 22 May 07 gregory 730         folderLocation = s_fileOrFolderThatIsReadOnHardDrive;
1652 22 May 07 gregory 731         fileName = "";
1652 22 May 07 gregory 732         fileExtension = "";
741 10 Oct 06 olle 733       }
2143 16 Oct 07 gregory 734     }
2143 16 Oct 07 gregory 735     else
2143 16 Oct 07 gregory 736     {
1652 22 May 07 gregory 737       fileStatus = DOESNOTEXISTS;
1652 22 May 07 gregory 738       folderLocation = s_fileOrFolderThatIsReadOnHardDrive;
1652 22 May 07 gregory 739       fileName = "";
1652 22 May 07 gregory 740       fileExtension = "";
741 10 Oct 06 olle 741     }
1652 22 May 07 gregory 742     // ##############At this line, all variables shall have been
1652 22 May 07 gregory 743     // set##############
1652 22 May 07 gregory 744     // Finally, set the local variables to the global variables
1652 22 May 07 gregory 745     s_requestedFolderLocation = folderLocation;
1652 22 May 07 gregory 746     s_requestedFileName = fileName;
1652 22 May 07 gregory 747     s_requestedFileExtension = fileExtension;
1652 22 May 07 gregory 748     i_fileStatus = fileStatus;
2143 16 Oct 07 gregory 749     if (fileStatus == ISFOLDER && !s_requestDocument.endsWith("/"))
2143 16 Oct 07 gregory 750       /*
2143 16 Oct 07 gregory 751        * If [Visiting a folder] AND [the URL entered does NOT end with "/" ],
2143 16 Oct 07 gregory 752        * then... //NOTE: You CAN'T change "s_requestDocument" to
2143 16 Oct 07 gregory 753        * "relativePath". (reason: lets say you visit
2143 16 Oct 07 gregory 754        * "http://server.com/alias" (relativePath=="/alias"), and this
2143 16 Oct 07 gregory 755        * doesn't match any file/folder on the hard drive, then we check
2143 16 Oct 07 gregory 756        * 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 759     // "http://server.com/folder" ==>
2143 16 Oct 07 gregory 760     // "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 763        * If [the file/folder doesn't exists] AND [the URL entered does NOT
2143 16 Oct 07 gregory 764        * end with "/" ], then... //(reason for this check: lets say you
2143 16 Oct 07 gregory 765        * visit "http://server.com/alias" (relativePath=="/alias"), and
2143 16 Oct 07 gregory 766        * this doesn't match any file/folder on the hard drive, then we
2143 16 Oct 07 gregory 767        * 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 774   // is found
2143 16 Oct 07 gregory 775   // returns null,
2143 16 Oct 07 gregory 776   // otherwise the
2143 16 Oct 07 gregory 777   // path given by
2143 16 Oct 07 gregory 778   // 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 794     // "/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 810       // ENV-variables we set after we
2143 16 Oct 07 gregory 811       // have read what the browser
2143 16 Oct 07 gregory 812       // has given us. For example
2143 16 Oct 07 gregory 813       // both CONTENT_TYPE and
2143 16 Oct 07 gregory 814       // HTTP_CONTENT_TYPE are set
2143 16 Oct 07 gregory 815       // when we have read
2143 16 Oct 07 gregory 816       // "CONTENT_TYPE". The number of
2143 16 Oct 07 gregory 817       // lines given to us from the
2143 16 Oct 07 gregory 818       // browser is not necessey (and
2143 16 Oct 07 gregory 819       // probably not)
2143 16 Oct 07 gregory 820       // ==numberOfENVGivenByBrowser
1652 22 May 07 gregory 821       String tmpStr = "_"; // Set this to any none-empty string (!="")
2143 16 Oct 07 gregory 822       // (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 825        * (assume: maxNumbersOfENVAccepted=200) less than 199 because it is
2143 16 Oct 07 gregory 826        * possible to run "numberOfENVGivenByBrowser++" twice in this loop.
2143 16 Oct 07 gregory 827        * (If we start the loop with 199 and run
2143 16 Oct 07 gregory 828        * "numberOfENVGivenByBrowser++" twice we will try to write to index
2143 16 Oct 07 gregory 829        * 200 (no, not 201; reason: we don't have
2143 16 Oct 07 gregory 830        * "++numberOfENVGivenByBrowser"), but the last index of the array
2143 16 Oct 07 gregory 831        * is 199 ==> exception is thrown!!!).
2143 16 Oct 07 gregory 832        */
741 10 Oct 06 olle 833       {
1652 22 May 07 gregory 834         // First I only had the
1652 22 May 07 gregory 835         // "tmpStr=br_theInputWeGetFromBrowser.readLine();" line here,
1652 22 May 07 gregory 836         // and it worked OK. But after a while I saw I sometimes got
1652 22 May 07 gregory 837         // problems: "tmpStr=br_theInputWeGetFromBrowser.readLine();"
1652 22 May 07 gregory 838         // did never quit, the Thread had stopped here. I don't know for
1652 22 May 07 gregory 839         // sure, but the reason might be that the browser never sends a
1652 22 May 07 gregory 840         // "\n" or "\r" at the end of the line, so it never becomes a
1652 22 May 07 gregory 841         // "line". However, now we instead read
1652 22 May 07 gregory 842         // "i_valueOfHttpContentLength" from the stream after we have
1652 22 May 07 gregory 843         // read one empty line (==""). This seems to work without any
1652 22 May 07 gregory 844         // problems. //(BTW: the problem occured after I had implemented
1652 22 May 07 gregory 845         // the "401 Not Authorized"-support (so the browser sends a
1652 22 May 07 gregory 846         // "AUTHORIZATION=Basic enctyptedPass" line now). Is it possible
1652 22 May 07 gregory 847         // this has anything to do with that the browser doesn't send an
1652 22 May 07 gregory 848         // \n after the POST-data? (Did the browser send a \n after the
1652 22 May 07 gregory 849         // 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 851           // 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 855         // line before the
2143 16 Oct 07 gregory 856         // POST-line
1652 22 May 07 gregory 857         {
1652 22 May 07 gregory 858           // Next line is the POST-data
1652 22 May 07 gregory 859           // // Was used before:
1652 22 May 07 gregory 860           // // char[] cbuf=new char[i_valueOfHttpContentLength];
1652 22 May 07 gregory 861           // // br_theInputWeGetFromBrowser.read( cbuf, 0,
1652 22 May 07 gregory 862           // i_valueOfHttpContentLength);
1652 22 May 07 gregory 863           // // 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 867           // This happenes if there is no "CONTENT_LENGTH"-line in the
1652 22 May 07 gregory 868           // browser request. So this won't happen with a valid
1652 22 May 07 gregory 869           // 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 874           // is a line such as
2143 16 Oct 07 gregory 875           // "HTTP_Connection:
2143 16 Oct 07 gregory 876           // Keep-Alive". Otherwise
2143 16 Oct 07 gregory 877           // this is the empty line
2143 16 Oct 07 gregory 878           // before the POST-line
1652 22 May 07 gregory 879           {
1652 22 May 07 gregory 880             // "tmpStr" has this format: "CONTENT_LENGTH=65" (after
1652 22 May 07 gregory 881             // 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 889             // 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 895               // length of the
2143 16 Oct 07 gregory 896               // 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 910               // "encryptedPassword"
2143 16 Oct 07 gregory 911               // (actually, it
2143 16 Oct 07 gregory 912               // is
2143 16 Oct 07 gregory 913               // "user:pass"
2143 16 Oct 07 gregory 914               // encrypted)
1652 22 May 07 gregory 915             }
1652 22 May 07 gregory 916             // else if (tmpStr.startsWith("COOKIE="))
1652 22 May 07 gregory 917             // s_cookiesFromBrowser=tmpStr.substring("COOKIE=".length());
1652 22 May 07 gregory 918             // //We don't need this
741 10 Oct 06 olle 919           }
1652 22 May 07 gregory 920           // Next 5 lines not in use anymore; was in use:
1652 22 May 07 gregory 921           // else if (s_requestMethod.equals(CONSTANT_POST) &&
1652 22 May 07 gregory 922           // !tmpStr.equals("")) //If, and only if, a POST-request has
1652 22 May 07 gregory 923           // been made there is POST-data to read... (If tmpStr is
1652 22 May 07 gregory 924           // empty we are at the empty line before the POST-data
1652 22 May 07 gregory 925           // {
1652 22 May 07 gregory 926           // s_stdinDataForPOSTRequests=tmpStr.substring(0,i_valueOfHttpContentLength);
1652 22 May 07 gregory 927           // //Guaranty that "s_stdinDataForPOSTRequests" doesn't
1652 22 May 07 gregory 928           // contain more than "i_valueOfHttpContentLength" chars
1652 22 May 07 gregory 929           // break; //With a correct request, this is not necessey, as
1652 22 May 07 gregory 930           // 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 936        * for (int i=0; i<numberOfENVGivenByBrowser; i++)
1652 22 May 07 gregory 937        * 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 941       // List all ENV from browser:
1652 22 May 07 gregory 942       // for (int i=0; i<numberOfENVGivenByBrowser; i++)
1652 22 May 07 gregory 943       // System.out.println("data "+allENVVariables[i]);
1652 22 May 07 gregory 944       // From Opera:
1652 22 May 07 gregory 945       // GET /?y4errewfdpp HTTP/1.1
1652 22 May 07 gregory 946       // User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera
1652 22 May 07 gregory 947       // 6.0 [sv]
1652 22 May 07 gregory 948       // Host: localhost:12345
1652 22 May 07 gregory 949       // Accept: text/html, image/png, image/jpeg, image/gif,
1652 22 May 07 gregory 950       // image/x-xbitmap, */*
1652 22 May 07 gregory 951       // Accept-Language: sv
1652 22 May 07 gregory 952       // Accept-Charset: windows-1252;q=1.0, utf-8;q=1.0, utf-16;q=1.0,
1652 22 May 07 gregory 953       // iso-8859-1;q=0.6, *;q=0.1
1652 22 May 07 gregory 954       // Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
1652 22 May 07 gregory 955       // Cache-Control: no-cache
1652 22 May 07 gregory 956       // Connection: Keep-Alive, TE
1652 22 May 07 gregory 957       // TE: deflate, gzip, chunked, identity, trailers
2143 16 Oct 07 gregory 958     }
2143 16 Oct 07 gregory 959     catch (Exception e)
2143 16 Oct 07 gregory 960     {
1652 22 May 07 gregory 961       if (b_showErrors)
1652 22 May 07 gregory 962         System.out
2143 16 Oct 07 gregory 963           .println("An error occured @ getEnvironmentVariablesGivenByBrowser:\n" + e
2143 16 Oct 07 gregory 964             .getMessage());
1652 22 May 07 gregory 965     }
1652 22 May 07 gregory 966     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 970   // s_requestDocument has to be set when you run checkForReservedPaths
1652 22 May 07 gregory 971   // Returns true if there is a reserved path, otherwise false
2143 16 Oct 07 gregory 972   private boolean checkForReservedPaths()
2143 16 Oct 07 gregory 973   {
2143 16 Oct 07 gregory 974     if (s_requestDocument.equals("/Image:showFolder"))
2143 16 Oct 07 gregory 975     {
1652 22 May 07 gregory 976       b_logThisHit = false;
1652 22 May 07 gregory 977       s_requestedFolderLocation = (new File(hiddenFolder))
2143 16 Oct 07 gregory 978         .getAbsolutePath() + File.separator;
1652 22 May 07 gregory 979       s_requestedFileName = "imagefolder.gif";
1652 22 May 07 gregory 980       s_requestedFileExtension = "gif";
1652 22 May 07 gregory 981       returnThisPage(s_requestedFolderLocation + s_requestedFileName);
741 10 Oct 06 olle 982       return true;
741 10 Oct 06 olle 983     }
2143 16 Oct 07 gregory 984     if (s_requestDocument.equals("/Image:showFileicon"))
2143 16 Oct 07 gregory 985     {
1652 22 May 07 gregory 986       b_logThisHit = false;
1652 22 May 07 gregory 987       s_requestedFolderLocation = (new File(hiddenFolder))
2143 16 Oct 07 gregory 988         .getAbsolutePath() + File.separator;
1652 22 May 07 gregory 989       s_requestedFileName = "imagefileicon.gif";
1652 22 May 07 gregory 990       s_requestedFileExtension = "gif";
1652 22 May 07 gregory 991       returnThisPage(s_requestedFolderLocation + s_requestedFileName);
741 10 Oct 06 olle 992       return true;
741 10 Oct 06 olle 993     }
1652 22 May 07 gregory 994     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 998   private String[] getAllEnvironmentVariables() // Se
2143 16 Oct 07 gregory 999   // http://hoohoo.ncsa.uiuc.edu/cgi/env.html
741 10 Oct 06 olle 1000   {
1652 22 May 07 gregory 1001     String[] envVariables, envVariablesTMP;
1652 22 May 07 gregory 1002     int variablesGivenByBrowserLength = as_variablesGivenByBrowser.length;
2143 16 Oct 07 gregory 1003     int maxNumberOfEnvironmentVariables = maxNumbersOfENVAccepted + variablesGivenByBrowserLength;
741 10 Oct 06 olle 1004     String s_tmpStr;
1652 22 May 07 gregory 1005     envVariablesTMP = new String[maxNumberOfEnvironmentVariables];
741 10 Oct 06 olle 1006     /*
1652 22 May 07 gregory 1007      * for (;i<variablesGivenByBrowserLength; i++) //Optimization... {
1652 22 May 07 gregory 1008      * 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 1014     // the
2143 16 Oct 07 gregory 1015     // default
2143 16 Oct 07 gregory 1016     // value to
2143 16 Oct 07 gregory 1017     // ".", in
2143 16 Oct 07 gregory 1018     // case we
2143 16 Oct 07 gregory 1019     // don't get
2143 16 Oct 07 gregory 1020     // anything
2143 16 Oct 07 gregory 1021     // from
2143 16 Oct 07 gregory 1022     // "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 1029        * Without this line we will get an error while using MySQL (I have
2143 16 Oct 07 gregory 1030        * tried PHPBB with MySQL, and it said: "Warning: mysql_connect():
2143 16 Oct 07 gregory 1031        * Can't create TCP/IP socket (10106) in <b>d:\folder\file.php</b>
2143 16 Oct 07 gregory 1032        * 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 1067     // ## For PHP 5 for Windows:
1652 22 May 07 gregory 1068     // ## This is enough to run PHP scripts:
1652 22 May 07 gregory 1069     // ## C:\>set
1652 22 May 07 gregory 1070     // ## PATH=c:/program files/php
1652 22 May 07 gregory 1071     // ## SCRIPT_FILENAME=C:\files\test.php
1652 22 May 07 gregory 1072     // ## C:\>php-cgi
1652 22 May 07 gregory 1073     // ## Content-type: text/html
1652 22 May 07 gregory 1074     // ## X-Powered-By: PHP/5.0.3
1652 22 May 07 gregory 1075     // ##
1652 22 May 07 gregory 1076     // ## Hello World
1652 22 May 07 gregory 1077     // #######################################
1652 22 May 07 gregory 1078     // #######################################
1652 22 May 07 gregory 1079     // ## For PHP 5 for Windows:
1652 22 May 07 gregory 1080     // ## However, when we have the SERVER_NAME
1652 22 May 07 gregory 1081     // ## variable we also need set the
1652 22 May 07 gregory 1082     // ## REDIRECT_STATUS variable,
1652 22 May 07 gregory 1083     // ## otherwise we get error ("Security Alert!").
1652 22 May 07 gregory 1084     // ## C:\>set
1652 22 May 07 gregory 1085     // ## PATH=c:/program files/php
1652 22 May 07 gregory 1086     // ## SCRIPT_FILENAME=C:\files\test.php
1652 22 May 07 gregory 1087     // ## SERVER_NAME=Xerver
1652 22 May 07 gregory 1088     // ## REDIRECT_STATUS=200
1652 22 May 07 gregory 1089     // ## C:\>php-cgi
1652 22 May 07 gregory 1090     // ## Content-type: text/html
1652 22 May 07 gregory 1091     // ## X-Powered-By: PHP/5.0.3
1652 22 May 07 gregory 1092     // ##
1652 22 May 07 gregory 1093     // ## Hello World
1652 22 May 07 gregory 1094     // #######################################
1652 22 May 07 gregory 1095     // EXAMPLE PATH_INFO:
1652 22 May 07 gregory 1096     // http://server/dir/file.pl ==> "/dir/file.pl"
1652 22 May 07 gregory 1097     // 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 1099     // EXAMPLE PATH_TRANSLATED
1652 22 May 07 gregory 1100     // http://server/dir/file.pl ==> "d:\root\path\dir\file.pl"
1652 22 May 07 gregory 1101     // http://site.com/script.pl/extra/folder/ ==>
1652 22 May 07 gregory 1102     // "/path/to/root/extra/folder/"
2143 16 Oct 07 gregory 1103     envVariablesTMP[i++] = "PATH_TRANSLATED=" + s_requestedFolderLocation + s_requestedFileName;
1652 22 May 07 gregory 1104     // EXAMPLE SCRIPT_NAME
1652 22 May 07 gregory 1105     // http://server/dir/file.pl ==> "/dir/file.pl"
1652 22 May 07 gregory 1106     // 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 1108     // SCRIPT_FILENAME is what PHP uses to execute scripts.
1652 22 May 07 gregory 1109     // SCRIPT_FILENAME can be c:\scripts\php\test.php
1652 22 May 07 gregory 1110     // 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 1112     // local
2143 16 Oct 07 gregory 1113     // path
2143 16 Oct 07 gregory 1114     // to
2143 16 Oct 07 gregory 1115     // the
2143 16 Oct 07 gregory 1116     // 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 1124        * "This variable is not set if the server failed to look up the
2143 16 Oct 07 gregory 1125        * 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 1133     // visited a
2143 16 Oct 07 gregory 1134     // password
2143 16 Oct 07 gregory 1135     // 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 1138       // authentication being
2143 16 Oct 07 gregory 1139       // used to limit access
2143 16 Oct 07 gregory 1140       // to the current
2143 16 Oct 07 gregory 1141       // document. E.g.
2143 16 Oct 07 gregory 1142       // "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 1146        * "REMOTE_USER is only set for pages in a directory or subdirectory
2143 16 Oct 07 gregory 1147        * 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 1150     // envVariablesTMP[i++]="REMOTE_IDENT=aaaaa"; //"If the HTTP server
1652 22 May 07 gregory 1151     // supports RFC 931 identification, then this variable will be set to
1652 22 May 07 gregory 1152     // the remote user name retrieved from the server. Usage of this
1652 22 May 07 gregory 1153     // variable should be limited to logging only."
1652 22 May 07 gregory 1154     // envVariablesTMP[i++]="CONTENT_TYPE=aaaaa"; //This will be set
1652 22 May 07 gregory 1155     // automatically when POST has been used
1652 22 May 07 gregory 1156     // envVariablesTMP[i++]="CONTENT_LENGTH=aaaaa"; //This will be set
1652 22 May 07 gregory 1157     // automatically when POST has been used
1652 22 May 07 gregory 1158     envVariablesTMP[i++] = "REDIRECT_STATUS=" + s_errorStatus;
1652 22 May 07 gregory 1159     // envVariablesTMP[i++]="redirect_status_env=0";//PHP STUFF!!!!!
1652 22 May 07 gregory 1160     // envVariablesTMP[i++]="PHP_DOCUMENT_ROOT=e:\\";//PHP STUFF!!!!!
1652 22 May 07 gregory 1161     // envVariablesTMP[i++]="DOCUMENT_ROOT=e:\\";//PHP STUFF!!!!!
1652 22 May 07 gregory 1162     // envVariablesTMP[i++]="DOC_ROOT=e:\\";//PHP STUFF!!!!!
1652 22 May 07 gregory 1163     // 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 1166      * for (int k=0; k<i; k++) { envVariables[k]=envVariablesTMP[k];
1652 22 May 07 gregory 1167      * 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 1175   // before the page is
2143 16 Oct 07 gregory 1176   // showed, or the page won't
2143 16 Oct 07 gregory 1177   // work with for example
2143 16 Oct 07 gregory 1178   // Netscape 1 //You can
2143 16 Oct 07 gregory 1179   // safely run
2143 16 Oct 07 gregory 1180   // initializeRequestedFileExtension
2143 16 Oct 07 gregory 1181   // more than once if you
2143 16 Oct 07 gregory 1182   // 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 1187      * If there is no file extension s_requestedFileExtension is the same as
2143 16 Oct 07 gregory 1188      * 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 1192      * s_requestedFileType=(String)HM_allFileExt.get(s_requestedFileExtension);
1652 22 May 07 gregory 1193      * if (s_requestedFileType==null) { s_requestedFileType="text/html";
1652 22 May 07 gregory 1194      * //Default }
1652 22 May 07 gregory 1195      */
741 10 Oct 06 olle 1196     /*
1652 22 May 07 gregory 1197      * //The most common types are at top... if
1652 22 May 07 gregory 1198      * (s_requestedFileName.equals("")) s_requestedFileType="text/html";
1652 22 May 07 gregory 1199      * else if ( s_requestedFileExtension.equalsIgnoreCase("htm") ||
1652 22 May 07 gregory 1200      * s_requestedFileExtension.equalsIgnoreCase("shtml") ||
1652 22 May 07 gregory 1201      * s_requestedFileExtension.equalsIgnoreCase("html") ||
1652 22 May 07 gregory 1202      * s_requestedFileExtension.equalsIgnoreCase("shtm") ||
1652 22 May 07 gregory 1203      * s_requestedFileExtension.equalsIgnoreCase("asp"))
1652 22 May 07 gregory 1204      * s_requestedFileType="text/html"; else if (
1652 22 May 07 gregory 1205      * s_requestedFileExtension.equalsIgnoreCase("txt") ||
1652 22 May 07 gregory 1206      * s_requestedFileExtension.equalsIgnoreCase("text") ||
1652 22 May 07 gregory 1207      * s_requestedFileExtension.equalsIgnoreCase("ini") ||
1652 22 May 07 gregory 1208      * s_requestedFileExtension.equalsIgnoreCase("c") ||
1652 22 May 07 gregory 1209      * s_requestedFileExtension.equalsIgnoreCase("cc") ||
1652 22 May 07 gregory 1210      * s_requestedFileExtension.equalsIgnoreCase("c++") ||
1652 22 May 07 gregory 1211      * s_requestedFileExtension.equalsIgnoreCase("h") ||
1652 22 May 07 gregory 1212      * s_requestedFileExtension.equalsIgnoreCase("pl") ||
1652 22 May 07 gregory 1213      * s_requestedFileExtension.equalsIgnoreCase("java") ||
1652 22 May 07 gregory 1214      * s_requestedFileExtension.equalsIgnoreCase("webl") ||
1652 22 May 07 gregory 1215      * s_requestedFileExtension.equalsIgnoreCase("inf"))
1652 22 May 07 gregory 1216      * s_requestedFileType="text/plain"; else if (
1652 22 May 07 gregory 1217      * s_requestedFileExtension.equalsIgnoreCase("jpeg") ||
1652 22 May 07 gregory 1218      * s_requestedFileExtension.equalsIgnoreCase("jpg") ||
1652 22 May 07 gregory 1219      * s_requestedFileExtension.equalsIgnoreCase("jpe"))
1652 22 May 07 gregory 1220      * s_requestedFileType="image/jpeg"; else if (
1652 22 May 07 gregory 1221      * s_requestedFileExtension.equalsIgnoreCase("gif"))
1652 22 May 07 gregory 1222      * s_requestedFileType="image/gif"; else if (
1652 22 May 07 gregory 1223      * s_requestedFileExtension.equalsIgnoreCase("png"))
1652 22 May 07 gregory 1224      * s_requestedFileType="image/png"; else if (
1652 22 May 07 gregory 1225      * s_requestedFileExtension.equalsIgnoreCase("uu") ||
1652 22 May 07 gregory 1226      * s_requestedFileExtension.equalsIgnoreCase("exe"))
1652 22 May 07 gregory 1227      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1228      * s_requestedFileExtension.equalsIgnoreCase("ps"))
1652 22 May 07 gregory 1229      * s_requestedFileType="application/postscript"; else if (
1652 22 May 07 gregory 1230      * s_requestedFileExtension.equalsIgnoreCase("zip"))
1652 22 May 07 gregory 1231      * s_requestedFileType="application/zip"; else if (
1652 22 May 07 gregory 1232      * s_requestedFileExtension.equalsIgnoreCase("sh"))
1652 22 May 07 gregory 1233      * s_requestedFileType="application/x-shar"; else if (
1652 22 May 07 gregory 1234      * s_requestedFileExtension.equalsIgnoreCase("tar"))
1652 22 May 07 gregory 1235      * s_requestedFileType="application/x-tar"; else if (
1652 22 May 07 gregory 1236      * s_requestedFileExtension.equalsIgnoreCase("au") ||
1652 22 May 07 gregory 1237      * s_requestedFileExtension.equalsIgnoreCase("snd"))
1652 22 May 07 gregory 1238      * s_requestedFileType="audio/basic"; else if (
1652 22 May 07 gregory 1239      * s_requestedFileExtension.equalsIgnoreCase("wav"))
1652 22 May 07 gregory 1240      * s_requestedFileType="audio/x-wav"; else if (
1652 22 May 07 gregory 1241      * s_requestedFileExtension.equalsIgnoreCase("xml"))
1652 22 May 07 gregory 1242      * s_requestedFileType="text/xml"; else if (
1652 22 May 07 gregory 1243      * s_requestedFileExtension.equalsIgnoreCase("hqx"))
1652 22 May 07 gregory 1244      * s_requestedFileType="application/mac-binhex40"; else if (
1652 22 May 07 gregory 1245      * s_requestedFileExtension.equalsIgnoreCase("cpt"))
1652 22 May 07 gregory 1246      * s_requestedFileType="application/mac-compactpro"; else if (
1652 22 May 07 gregory 1247      * s_requestedFileExtension.equalsIgnoreCase("ai"))
1652 22 May 07 gregory 1248      * s_requestedFileType="application/postscript"; else if (
1652 22 May 07 gregory 1249      * s_requestedFileExtension.equalsIgnoreCase("aif"))
1652 22 May 07 gregory 1250      * s_requestedFileType="audio/x-aiff"; else if (
1652 22 May 07 gregory 1251      * s_requestedFileExtension.equalsIgnoreCase("aifc"))
1652 22 May 07 gregory 1252      * s_requestedFileType="audio/x-aiff"; else if (
1652 22 May 07 gregory 1253      * s_requestedFileExtension.equalsIgnoreCase("aiff"))
1652 22 May 07 gregory 1254      * s_requestedFileType="audio/x-aiff"; else if (
1652 22 May 07 gregory 1255      * s_requestedFileExtension.equalsIgnoreCase("au"))
1652 22 May 07 gregory 1256      * s_requestedFileType="audio/basic"; else if (
1652 22 May 07 gregory 1257      * s_requestedFileExtension.equalsIgnoreCase("avi"))
1652 22 May 07 gregory 1258      * s_requestedFileType="video/x-msvideo"; else if (
1652 22 May 07 gregory 1259      * s_requestedFileExtension.equalsIgnoreCase("bcpio"))
1652 22 May 07 gregory 1260      * s_requestedFileType="application/x-bcpio"; else if (
1652 22 May 07 gregory 1261      * s_requestedFileExtension.equalsIgnoreCase("bin"))
1652 22 May 07 gregory 1262      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1263      * s_requestedFileExtension.equalsIgnoreCase("bmp"))
1652 22 May 07 gregory 1264      * s_requestedFileType="image/x-xbitmap"; else if (
1652 22 May 07 gregory 1265      * s_requestedFileExtension.equalsIgnoreCase("cdf"))
1652 22 May 07 gregory 1266      * s_requestedFileType="application/x-netcdf"; else if (
1652 22 May 07 gregory 1267      * s_requestedFileExtension.equalsIgnoreCase("class"))
1652 22 May 07 gregory 1268      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1269      * s_requestedFileExtension.equalsIgnoreCase("cpio"))
1652 22 May 07 gregory 1270      * s_requestedFileType="application/x-cpio"; else if (
1652 22 May 07 gregory 1271      * s_requestedFileExtension.equalsIgnoreCase("cpt"))
1652 22 May 07 gregory 1272      * s_requestedFileType="application/mac-compactpro"; else if (
1652 22 May 07 gregory 1273      * s_requestedFileExtension.equalsIgnoreCase("csh"))
1652 22 May 07 gregory 1274      * s_requestedFileType="application/x-csh"; else if (
1652 22 May 07 gregory 1275      * s_requestedFileExtension.equalsIgnoreCase("css"))
1652 22 May 07 gregory 1276      * s_requestedFileType="text/css"; else if (
1652 22 May 07 gregory 1277      * s_requestedFileExtension.equalsIgnoreCase("dcr"))
1652 22 May 07 gregory 1278      * s_requestedFileType="application/x-director"; else if (
1652 22 May 07 gregory 1279      * s_requestedFileExtension.equalsIgnoreCase("dir"))
1652 22 May 07 gregory 1280      * s_requestedFileType="application/x-director"; else if (
1652 22 May 07 gregory 1281      * s_requestedFileExtension.equalsIgnoreCase("dll"))
1652 22 May 07 gregory 1282      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1283      * s_requestedFileExtension.equalsIgnoreCase("dms"))
1652 22 May 07 gregory 1284      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1285      * s_requestedFileExtension.equalsIgnoreCase("doc"))
1652 22 May 07 gregory 1286      * s_requestedFileType="application/msword"; else if (
1652 22 May 07 gregory 1287      * s_requestedFileExtension.equalsIgnoreCase("dtd"))
1652 22 May 07 gregory 1288      * s_requestedFileType="text/xml"; else if (
1652 22 May 07 gregory 1289      * s_requestedFileExtension.equalsIgnoreCase("dvi"))
1652 22 May 07 gregory 1290      * s_requestedFileType="application/x-dvi"; else if (
1652 22 May 07 gregory 1291      * s_requestedFileExtension.equalsIgnoreCase("dwg"))
1652 22 May 07 gregory 1292      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1293      * s_requestedFileExtension.equalsIgnoreCase("dxr"))
1652 22 May 07 gregory 1294      * s_requestedFileType="application/x-director"; else if (
1652 22 May 07 gregory 1295      * s_requestedFileExtension.equalsIgnoreCase("eps"))
1652 22 May 07 gregory 1296      * s_requestedFileType="application/postscript"; else if (
1652 22 May 07 gregory 1297      * s_requestedFileExtension.equalsIgnoreCase("etx"))
1652 22 May 07 gregory 1298      * s_requestedFileType="text/x-setext"; else if (
1652 22 May 07 gregory 1299      * s_requestedFileExtension.equalsIgnoreCase("evy"))
1652 22 May 07 gregory 1300      * s_requestedFileType="application/x-envoy"; else if (
1652 22 May 07 gregory 1301      * s_requestedFileExtension.equalsIgnoreCase("exe"))
1652 22 May 07 gregory 1302      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1303      * s_requestedFileExtension.equalsIgnoreCase("fif"))
1652 22 May 07 gregory 1304      * s_requestedFileType="application/fractals"; else if (
1652 22 May 07 gregory 1305      * s_requestedFileExtension.equalsIgnoreCase("fli"))
1652 22 May 07 gregory 1306      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1307      * s_requestedFileExtension.equalsIgnoreCase("gl"))
1652 22 May 07 gregory 1308      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1309      * s_requestedFileExtension.equalsIgnoreCase("gtar"))
1652 22 May 07 gregory 1310      * s_requestedFileType="application/x-gtar"; else if (
1652 22 May 07 gregory 1311      * s_requestedFileExtension.equalsIgnoreCase("gz"))
1652 22 May 07 gregory 1312      * s_requestedFileType="application/x-gzip"; else if (
1652 22 May 07 gregory 1313      * s_requestedFileExtension.equalsIgnoreCase("hdf"))
1652 22 May 07 gregory 1314      * s_requestedFileType="application/x-hdf"; else if (
1652 22 May 07 gregory 1315      * s_requestedFileExtension.equalsIgnoreCase("hpx"))
1652 22 May 07 gregory 1316      * s_requestedFileType="application/mac-binhex40"; else if (
1652 22 May 07 gregory 1317      * s_requestedFileExtension.equalsIgnoreCase("hqx"))
1652 22 May 07 gregory 1318      * s_requestedFileType="application/mac-binhex40"; else if (
1652 22 May 07 gregory 1319      * s_requestedFileExtension.equalsIgnoreCase("ice"))
1652 22 May 07 gregory 1320      * s_requestedFileType="x-conference/x-cooltalk"; else if (
1652 22 May 07 gregory 1321      * s_requestedFileExtension.equalsIgnoreCase("ief"))
1652 22 May 07 gregory 1322      * s_requestedFileType="image/ief"; else if (
1652 22 May 07 gregory 1323      * s_requestedFileExtension.equalsIgnoreCase("iges"))
1652 22 May 07 gregory 1324      * s_requestedFileType="model/iges"; else if (
1652 22 May 07 gregory 1325      * s_requestedFileExtension.equalsIgnoreCase("igs"))
1652 22 May 07 gregory 1326      * s_requestedFileType="model/iges"; else if (
1652 22 May 07 gregory 1327      * s_requestedFileExtension.equalsIgnoreCase("isv"))
1652 22 May 07 gregory 1328      * s_requestedFileType="bws-internal/intrasrv-urlencoded"; else if (
1652 22 May 07 gregory 1329      * s_requestedFileExtension.equalsIgnoreCase("jfm"))
1652 22 May 07 gregory 1330      * s_requestedFileType="bws-internal/intrasrv-form"; else if (
1652 22 May 07 gregory 1331      * s_requestedFileExtension.equalsIgnoreCase("jrp"))
1652 22 May 07 gregory 1332      * s_requestedFileType="bws-internal/intrasrv-report"; else if (
1652 22 May 07 gregory 1333      * s_requestedFileExtension.equalsIgnoreCase("js"))
1652 22 May 07 gregory 1334      * s_requestedFileType="application/x-javascript"; else if (
1652 22 May 07 gregory 1335      * s_requestedFileExtension.equalsIgnoreCase("kar"))
1652 22 May 07 gregory 1336      * s_requestedFileType="audio/midi"; else if (
1652 22 May 07 gregory 1337      * s_requestedFileExtension.equalsIgnoreCase("latex"))
1652 22 May 07 gregory 1338      * s_requestedFileType="application/x-latex"; else if (
1652 22 May 07 gregory 1339      * s_requestedFileExtension.equalsIgnoreCase("lha"))
1652 22 May 07 gregory 1340      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1341      * s_requestedFileExtension.equalsIgnoreCase("ls"))
1652 22 May 07 gregory 1342      * s_requestedFileType="application/x-javascript"; else if (
1652 22 May 07 gregory 1343      * s_requestedFileExtension.equalsIgnoreCase("lzh"))
1652 22 May 07 gregory 1344      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1345      * s_requestedFileExtension.equalsIgnoreCase("man"))
1652 22 May 07 gregory 1346      * s_requestedFileType="application/x-troff-man"; else if (
1652 22 May 07 gregory 1347      * s_requestedFileExtension.equalsIgnoreCase("me"))
1652 22 May 07 gregory 1348      * s_requestedFileType="application/x-troff-me"; else if (
1652 22 May 07 gregory 1349      * s_requestedFileExtension.equalsIgnoreCase("mesh"))
1652 22 May 07 gregory 1350      * s_requestedFileType="model/mesh"; else if (
1652 22 May 07 gregory 1351      * s_requestedFileExtension.equalsIgnoreCase("mid"))
1652 22 May 07 gregory 1352      * s_requestedFileType="audio/midi"; else if (
1652 22 May 07 gregory 1353      * s_requestedFileExtension.equalsIgnoreCase("midi"))
1652 22 May 07 gregory 1354      * s_requestedFileType="audio/midi"; else if (
1652 22 May 07 gregory 1355      * s_requestedFileExtension.equalsIgnoreCase("mif"))
1652 22 May 07 gregory 1356      * s_requestedFileType="application/x-mif"; else if (
1652 22 May 07 gregory 1357      * s_requestedFileExtension.equalsIgnoreCase("mocha"))
1652 22 May 07 gregory 1358      * s_requestedFileType="application/x-javascript"; else if (
1652 22 May 07 gregory 1359      * s_requestedFileExtension.equalsIgnoreCase("mov"))
1652 22 May 07 gregory 1360      * s_requestedFileType="video/quicktime"; else if (
1652 22 May 07 gregory 1361      * s_requestedFileExtension.equalsIgnoreCase("movie"))
1652 22 May 07 gregory 1362      * s_requestedFileType="video/x-sgi-movie"; else if (
1652 22 May 07 gregory 1363      * s_requestedFileExtension.equalsIgnoreCase("mp2"))
1652 22 May 07 gregory 1364      * s_requestedFileType="audio/mpeg"; else if (
1652 22 May 07 gregory 1365      * s_requestedFileExtension.equalsIgnoreCase("mp3"))
1652 22 May 07 gregory 1366      * s_requestedFileType="audio/mpeg"; else if (
1652 22 May 07 gregory 1367      * s_requestedFileExtension.equalsIgnoreCase("mpe"))
1652 22 May 07 gregory 1368      * s_requestedFileType="video/mpeg"; else if (
1652 22 May 07 gregory 1369      * s_requestedFileExtension.equalsIgnoreCase("mpeg"))
1652 22 May 07 gregory 1370      * s_requestedFileType="video/mpeg"; else if (
1652 22 May 07 gregory 1371      * s_requestedFileExtension.equalsIgnoreCase("mpg"))
1652 22 May 07 gregory 1372      * s_requestedFileType="video/mpeg"; else if (
1652 22 May 07 gregory 1373      * s_requestedFileExtension.equalsIgnoreCase("mpga"))
1652 22 May 07 gregory 1374      * s_requestedFileType="audio/mpeg"; else if (
1652 22 May 07 gregory 1375      * s_requestedFileExtension.equalsIgnoreCase("ms"))
1652 22 May 07 gregory 1376      * s_requestedFileType="application/x-troff-ms"; else if (
1652 22 May 07 gregory 1377      * s_requestedFileExtension.equalsIgnoreCase("msh"))
1652 22 May 07 gregory 1378      * s_requestedFileType="model/mesh"; else if (
1652 22 May 07 gregory 1379      * s_requestedFileExtension.equalsIgnoreCase("nc"))
1652 22 May 07 gregory 1380      * s_requestedFileType="application/x-netcdf"; else if (
1652 22 May 07 gregory 1381      * s_requestedFileExtension.equalsIgnoreCase("oda"))
1652 22 May 07 gregory 1382      * s_requestedFileType="application/oda"; else if (
1652 22 May 07 gregory 1383      * s_requestedFileExtension.equalsIgnoreCase("pac"))
1652 22 May 07 gregory 1384      * s_requestedFileType="application/x-ns-proxy-autoconfig"; else if (
1652 22 May 07 gregory 1385      * s_requestedFileExtension.equalsIgnoreCase("pbm"))
1652 22 May 07 gregory 1386      * s_requestedFileType="image/x-portable-bitmap"; else if (
1652 22 May 07 gregory 1387      * s_requestedFileExtension.equalsIgnoreCase("pdb"))
1652 22 May 07 gregory 1388      * s_requestedFileType="chemical/x-pdb"; else if (
1652 22 May 07 gregory 1389      * s_requestedFileExtension.equalsIgnoreCase("pdf"))
1652 22 May 07 gregory 1390      * s_requestedFileType="application/pdf"; else if (
1652 22 May 07 gregory 1391      * s_requestedFileExtension.equalsIgnoreCase("pgm"))
1652 22 May 07 gregory 1392      * s_requestedFileType="image/x-portable-graymap"; else if (
1652 22 May 07 gregory 1393      * s_requestedFileExtension.equalsIgnoreCase("php3"))
1652 22 May 07 gregory 1394      * s_requestedFileType="application/x-httpd-php3"; else if (
1652 22 May 07 gregory 1395      * s_requestedFileExtension.equalsIgnoreCase("phtml-msql2"))
1652 22 May 07 gregory 1396      * s_requestedFileType="application/x-httpd-php-msql2"; else if (
1652 22 May 07 gregory 1397      * s_requestedFileExtension.equalsIgnoreCase("phtml"))
1652 22 May 07 gregory 1398      * s_requestedFileType="application/x-httpd-php"; else if (
1652 22 May 07 gregory 1399      * s_requestedFileExtension.equalsIgnoreCase("pnm"))
1652 22 May 07 gregory 1400      * s_requestedFileType="image/x-portable-anymap"; else if (
1652 22 May 07 gregory 1401      * s_requestedFileExtension.equalsIgnoreCase("ppm"))
1652 22 May 07 gregory 1402      * s_requestedFileType="image/x-portable-pixmap"; else if (
1652 22 May 07 gregory 1403      * s_requestedFileExtension.equalsIgnoreCase("ppt"))
1652 22 May 07 gregory 1404      * s_requestedFileType="application/powerpoint"; else if (
1652 22 May 07 gregory 1405      * s_requestedFileExtension.equalsIgnoreCase("ps"))
1652 22 May 07 gregory 1406      * s_requestedFileType="application/postscript"; else if (
1652 22 May 07 gregory 1407      * s_requestedFileExtension.equalsIgnoreCase("qt"))
1652 22 May 07 gregory 1408      * s_requestedFileType="video/quicktime"; else if (
1652 22 May 07 gregory 1409      * s_requestedFileExtension.equalsIgnoreCase("ra"))
1652 22 May 07 gregory 1410      * s_requestedFileType="audio/x-realaudio"; else if (
1652 22 May 07 gregory 1411      * s_requestedFileExtension.equalsIgnoreCase("ram"))
1652 22 May 07 gregory 1412      * s_requestedFileType="audio/x-pn-realaudio"; else if (
1652 22 May 07 gregory 1413      * s_requestedFileExtension.equalsIgnoreCase("ras"))
1652 22 May 07 gregory 1414      * s_requestedFileType="image/x-cmu-raster"; else if (
1652 22 May 07 gregory 1415      * s_requestedFileExtension.equalsIgnoreCase("rgb"))
1652 22 May 07 gregory 1416      * s_requestedFileType="image/x-rgb"; else if (
1652 22 May 07 gregory 1417      * s_requestedFileExtension.equalsIgnoreCase("roff"))
1652 22 May 07 gregory 1418      * s_requestedFileType="application/x-troff"; else if (
1652 22 May 07 gregory 1419      * s_requestedFileExtension.equalsIgnoreCase("rpm"))
1652 22 May 07 gregory 1420      * s_requestedFileType="audio/x-pn-realaudio-plugin"; else if (
1652 22 May 07 gregory 1421      * s_requestedFileExtension.equalsIgnoreCase("rtf"))
1652 22 May 07 gregory 1422      * s_requestedFileType="application/rtf"; else if (
1652 22 May 07 gregory 1423      * s_requestedFileExtension.equalsIgnoreCase("rtx"))
1652 22 May 07 gregory 1424      * s_requestedFileType="text/richtext"; else if (
1652 22 May 07 gregory 1425      * s_requestedFileExtension.equalsIgnoreCase("scm"))
1652 22 May 07 gregory 1426      * s_requestedFileType="application/octet-stream"; else if (
1652 22 May 07 gregory 1427      * s_requestedFileExtension.equalsIgnoreCase("sgm"))
1652 22 May 07 gregory 1428      * s_requestedFileType="text/x-sgml"; else if (
1652 22 May 07 gregory 1429      * s_requestedFileExtension.equalsIgnoreCase("sgml"))
1652 22 May 07 gregory 1430      * s_requestedFileType="text/x-sgml"; else if (
1652 22 May 07 gregory 1431      * s_requestedFileExtension.equalsIgnoreCase("sh"))
1652 22 May 07 gregory 1432      * s_requestedFileType="application/x-sh"; else if (
1652 22 May 07 gregory 1433      * s_requestedFileExtension.equalsIgnoreCase("shar"))
1652 22 May 07 gregory 1434      * s_requestedFileType="application/x-shar"; else if (
1652 22 May 07 gregory 1435      * s_requestedFileExtension.equalsIgnoreCase("silo"))
1652 22 May 07 gregory 1436      * s_requestedFileType="model/mesh"; else if (
1652 22 May 07 gregory 1437      * s_requestedFileExtension.equalsIgnoreCase("sit"))
1652 22 May 07 gregory 1438      * s_requestedFileType="application/stuffit"; else if (
1652 22 May 07 gregory 1439      * s_requestedFileExtension.equalsIgnoreCase("sit"))
1652 22 May 07 gregory 1440      * s_requestedFileType="application/x-stuffit"; else if (
1652 22 May 07 gregory 1441      * s_requestedFileExtension.equalsIgnoreCase("skd"))
1652 22 May 07 gregory 1442      * s_requestedFileType="application/x-koan"; else if (
1652 22 May 07 gregory 1443      * s_requestedFileExtension.equalsIgnoreCase("skm"))
1652 22 May 07 gregory 1444      * s_requestedFileType="application/x-koan"; else if (
1652 22 May 07 gregory 1445      * s_requestedFileExtension.equalsIgnoreCase("skp"))
1652 22 May 07 gregory 1446      * s_requestedFileType="application/x-koan"; else if (
1652 22 May 07 gregory 1447      * s_requestedFileExtension.equalsIgnoreCase("skt"))
1652 22 May 07 gregory 1448      * s_requestedFileType="application/x-koan"; else if (
1652 22 May 07 gregory 1449      * s_requestedFileExtension.equalsIgnoreCase("snd"))
1652 22 May 07 gregory 1450      * s_requestedFileType="audio/basic"; else if (
1652 22 May 07 gregory 1451      * s_requestedFileExtension.equalsIgnoreCase("src"))
1652 22 May 07 gregory 1452      * s_requestedFileType="application/x-wais-source"; else if (
1652 22 May 07 gregory 1453      * s_requestedFileExtension.equalsIgnoreCase("sv4cpio"))
1652 22 May 07 gregory 1454      * s_requestedFileType="application/x-sv4cpio"; else if (
1652 22 May 07 gregory 1455      * s_requestedFileExtension.equalsIgnoreCase("sv4crc"))
1652 22 May 07 gregory 1456      * s_requestedFileType="application/x-sv4crc"; else if (
1652 22 May 07 gregory 1457      * s_requestedFileExtension.equalsIgnoreCase("swf"))
1652 22 May 07 gregory 1458      * s_requestedFileType="application/x-shockwave-flash"; else if (
1652 22 May 07 gregory 1459      * s_requestedFileExtension.equalsIgnoreCase("t"))
1652 22 May 07 gregory 1460      * s_requestedFileType="application/x-troff"; else if (
1652 22 May 07 gregory 1461      * s_requestedFileExtension.equalsIgnoreCase("tar"))
1652 22 May 07 gregory 1462      * s_requestedFileType="application/x-tar"; else if (
1652 22 May 07 gregory 1463      * s_requestedFileExtension.equalsIgnoreCase("tcl"))
1652 22 May 07 gregory 1464      * s_requestedFileType="application/x-tcl"; else if (
1652 22 May 07 gregory 1465      * s_requestedFileExtension.equalsIgnoreCase("tex"))
1652 22 May 07 gregory 1466      * s_requestedFileType="application/x-tex"; else if (
1652 22 May 07 gregory 1467      * s_requestedFileExtension.equalsIgnoreCase("texi"))
1652 22 May 07 gregory 1468      * s_requestedFileType="application/x-texinfo"; // else if (
1652 22 May 07 gregory 1469      * s_requestedFileExtension.equalsIgnoreCase("texi")) //
1652 22 May 07 gregory 1470      * s_requestedFileType="application/x-textinfo"; else if (
1652 22 May 07 gregory 1471      * s_requestedFileExtension.equalsIgnoreCase("texinfo"))
1652 22 May 07 gregory 1472      * s_requestedFileType="application/x-textinfo"; else if (
1652 22 May 07 gregory 1473      * s_requestedFileExtension.equalsIgnoreCase("tif"))
1652 22 May 07 gregory 1474      * s_requestedFileType="image/tiff"; else if (
1652 22 May 07 gregory 1475      * s_requestedFileExtension.equalsIgnoreCase("tiff"))
1652 22 May 07 gregory 1476      * s_requestedFileType="image/tiff"; else if (
1652 22 May 07 gregory 1477      * s_requestedFileExtension.equalsIgnoreCase("tr"))
1652 22 May 07 gregory 1478      * s_requestedFileType="application/x-troff"; else if (
1652 22 May 07 gregory 1479      * s_requestedFileExtension.equalsIgnoreCase("tsp"))
1652 22 May 07 gregory 1480      * s_requestedFileType="application/dsptype"; else if (
1652 22 May 07 gregory 1481      * s_requestedFileExtension.equalsIgnoreCase("tsv"))
1652 22 May 07 gregory 1482      * s_requestedFileType="text/tab-separated-values"; else if (
1652 22 May 07 gregory 1483      * s_requestedFileExtension.equalsIgnoreCase("txt"))
1652 22 May 07 gregory 1484      * s_requestedFileType="text/plain"; else if (
1652 22 May 07 gregory 1485      * s_requestedFileExtension.equalsIgnoreCase("ustar"))
1652 22 May 07 gregory 1486      * s_requestedFileType="application/x-ustar"; else if (
1652 22 May 07 gregory 1487      * s_requestedFileExtension.equalsIgnoreCase("vcd"))
1652 22 May 07 gregory 1488      * s_requestedFileType="application/x-cdlink"; else if (
1652 22 May 07 gregory 1489      * s_requestedFileExtension.equalsIgnoreCase("vox"))
1652 22 May 07 gregory 1490      * s_requestedFileType="audio/voxware"; else if (
1652 22 May 07 gregory 1491      * s_requestedFileExtension.equalsIgnoreCase("vrml"))
1652 22 May 07 gregory 1492      * s_requestedFileType="model/vrml"; else if (
1652 22 May 07 gregory 1493      * s_requestedFileExtension.equalsIgnoreCase("wrl"))
1652 22 May 07 gregory 1494      * s_requestedFileType="model/vrml"; else if (
1652 22 May 07 gregory 1495      * s_requestedFileExtension.equalsIgnoreCase("xbm"))
1652 22 May 07 gregory 1496      * s_requestedFileType="image/x-xbitmap"; else if (
1652 22 May 07 gregory 1497      * s_requestedFileExtension.equalsIgnoreCase("xml"))
1652 22 May 07 gregory 1498      * s_requestedFileType="text/xml"; else if (
1652 22 May 07 gregory 1499      * s_requestedFileExtension.equalsIgnoreCase("xpm"))
1652 22 May 07 gregory 1500      * s_requestedFileType="image/x-xpixmap"; else if (
1652 22 May 07 gregory 1501      * s_requestedFileExtension.equalsIgnoreCase("xwd"))
1652 22 May 07 gregory 1502      * s_requestedFileType="image/x-xwindowdump"; else if (
1652 22 May 07 gregory 1503      * s_requestedFileExtension.equalsIgnoreCase("xyz"))
1652 22 May 07 gregory 1504      * s_requestedFileType="chemical/x-pdb"; else if (
1652 22 May 07 gregory 1505      * s_requestedFileExtension.equalsIgnoreCase("z"))
1652 22 May 07 gregory 1506      * s_requestedFileType="application/x-compress"; else
1652 22 May 07 gregory 1507      * 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 1516     // and we have password protected both "/abc/"
2143 16 Oct 07 gregory 1517     // and "/abc/def/" only the password for
2143 16 Oct 07 gregory 1518     // "/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 1521     // We have removed this so we shall not receive a "401 not authorized"
1652 22 May 07 gregory 1522     // error when someone tries to download
1652 22 May 07 gregory 1523     // "http://www.sida.com/folder/../../secretfile.txt"
1652 22 May 07 gregory 1524     // if (folder.indexOf("..")!=-1) //You have tried to reach a folder with
1652 22 May 07 gregory 1525     // "http://www.sida.com/folder/../../secretfile.txt"
1652 22 May 07 gregory 1526     // 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 1529       // 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 1533       // Format of as_xerverPasswd[i]:
1652 22 May 07 gregory 1534       // "/path/to/folder/*=realmName=user1:pass1;user2:pass2"
1652 22 May 07 gregory 1535       String tmpDir = as_xerverPasswd[i];
1652 22 May 07 gregory 1536       tmpDir = tmpDir.substring(0, tmpDir.indexOf("<<@>>")); // Format:
2143 16 Oct 07 gregory 1537       // "/path/to/folder/*"
1652 22 May 07 gregory 1538       if (tmpDir.endsWith("*")) // If you are allowed to view the
2143 16 Oct 07 gregory 1539       // content of subfolders as well... (if
2143 16 Oct 07 gregory 1540       // the name ends with an *
2143 16 Oct 07 gregory 1541       // ("/mapp1/mapp2/*"))
741 10 Oct 06 olle 1542       {
1652 22 May 07 gregory 1543         if (tmpDir.regionMatches(true, 0, folder, 0,
2143 16 Oct 07 gregory 1544           tmpDir.length() - 1)) // If [the first
2143 16 Oct 07 gregory 1545         // "tmpDir.length()-1"
2143 16 Oct 07 gregory 1546         // characters of the two strings
2143 16 Oct 07 gregory 1547         // are equal (case
2143 16 Oct 07 gregory 1548         // insensitive)]...
741 10 Oct 06 olle 1549         {
2143 16 Oct 07 gregory 1550           if (tmpDir.length() > longestPath)
2143 16 Oct 07 gregory 1551           /*
2143 16 Oct 07 gregory 1552            * If the visitor is visiting "/abc/def/ghi/" and we have
2143 16 Oct 07 gregory 1553            * password protected both "/abc/" and "/abc/def/" only the
2143 16 Oct 07 gregory 1554            * 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 1562             // "*" 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 1569         // visiting "/abc/def/ghi/"
2143 16 Oct 07 gregory 1570         // and we have password
2143 16 Oct 07 gregory 1571         // protected both "/abc/"
2143 16 Oct 07 gregory 1572         // and "/abc/def/" only the
2143 16 Oct 07 gregory 1573         // password for "/abc/def/"
2143 16 Oct 07 gregory 1574         // 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 1587       // "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 1591        * The folder we are visiting is password protected, demand a
2143 16 Oct 07 gregory 1592        * 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 1597     // 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 1603     // of
2143 16 Oct 07 gregory 1604     // "allUsersAndPasswords[i]":
2143 16 Oct 07 gregory 1605     // "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 1614         // choose to log
2143 16 Oct 07 gregory 1615         // his
2143 16 Oct 07 gregory 1616         // activites,
2143 16 Oct 07 gregory 1617         // the webserver
2143 16 Oct 07 gregory 1618         // actually
2143 16 Oct 07 gregory 1619         // doesn't need
2143 16 Oct 07 gregory 1620         // 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 1633       // "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 1639       // content of subfolders as well... (if
2143 16 Oct 07 gregory 1640       // the name ends with an *
2143 16 Oct 07 gregory 1641       // ("/mapp1/mapp2/*"))
741 10 Oct 06 olle 1642       {
1652 22 May 07 gregory 1643         if (tmpDir.regionMatches(true, 0, folder, 0,
2143 16 Oct 07 gregory 1644           tmpDir.length() - 1)) // If [the first
2143 16 Oct 07 gregory 1645           // "tmpDir.length()-1"
2143 16 Oct 07 gregory 1646           // characters of the two strings
2143 16 Oct 07 gregory 1647           // are equal (case
2143 16 Oct 07 gregory 1648           // insensitive)]...
741 10 Oct 06 olle 1649           return true;
2143 16 Oct 07 gregory 1650       }
2143 16 Oct 07 gregory 1651       else if (tmpDir.equalsIgnoreCase(folder))
741 10 Oct 06 olle 1652         return true;
741 10 Oct 06 olle 1653     }
741 10 Oct 06 olle 1654     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 1658   private boolean isFileExtensionAllowed(String fileExtension)
2143 16 Oct 07 gregory 1659   {
1652 22 May 07 gregory 1660     if (fileExtension == null) // be safe, make a check
741 10 Oct 06 olle 1661       return false;
1652 22 May 07 gregory 1662     // NOTE: If you receive an error saying "You have tried to download a
1652 22 May 07 gregory 1663     // file with an extension that you are not allowed to download." when
1652 22 May 07 gregory 1664     // you actually have requested a folder it's because an index file was
1652 22 May 07 gregory 1665     // found in the folder, but the extension of this index file is not
1652 22 May 07 gregory 1666     // allowed to be viewed. This is good, as you are not allowed to view
1652 22 May 07 gregory 1667     // the content of a folder with an index file with an extension you are
1652 22 May 07 gregory 1668     // not allowed to view.
1652 22 May 07 gregory 1669     for (int i = 0, fileExtensionsLength = as_fileExtensions.length; i < fileExtensionsLength; i++)
1652 22 May 07 gregory 1670       // Optimization...
741 10 Oct 06 olle 1671       if (as_fileExtensions[i].equals(fileExtension))
1652 22 May 07 gregory 1672         return b_allowTheseFileExtensions; // If
2143 16 Oct 07 gregory 1673     // b_allowTheseFileExtensions==true,
2143 16 Oct 07 gregory 1674     // then you are only allowed
2143 16 Oct 07 gregory 1675     // to download files with an
2143 16 Oct 07 gregory 1676     // extension listed in
2143 16 Oct 07 gregory 1677     // "as_fileExtensions".
2143 16 Oct 07 gregory 1678     // Otherwise you are not
2143 16 Oct 07 gregory 1679     // allowed to download these
2143 16 Oct 07 gregory 1680     // file extensions.
741 10 Oct 06 olle 1681     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 1685   private boolean accessToFileIsOK(String fileName)
2143 16 Oct 07 gregory 1686   {
1652 22 May 07 gregory 1687     File theDocument = new File(fileName);
741 10 Oct 06 olle 1688     if (theDocument.canRead())
741 10 Oct 06 olle 1689       return true;
741 10 Oct 06 olle 1690     else
741 10 Oct 06 olle 1691       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 1695   private boolean isHTTPFormatRecognized(String httpRequest)
2143 16 Oct 07 gregory 1696   {
1652 22 May 07 gregory 1697     if (httpRequest == null) // be safe, make a check
741 10 Oct 06 olle 1698       return false;
741 10 Oct 06 olle 1699     if (httpRequest.toUpperCase().startsWith("HTTP"))
741 10 Oct 06 olle 1700       return true;
741 10 Oct 06 olle 1701     else
741 10 Oct 06 olle 1702       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 1706   private boolean isHTTPrecognized(String httpRequest)
2143 16 Oct 07 gregory 1707   {
1652 22 May 07 gregory 1708     if (httpRequest == null) // be safe, make a check
741 10 Oct 06 olle 1709       return false;
2143 16 Oct 07 gregory 1710     if (httpRequest.equalsIgnoreCase(CONSTANT_HTTP11) || httpRequest
2143 16 Oct 07 gregory 1711       .equalsIgnoreCase(CONSTANT_HTTP10) || httpRequest
2143 16 Oct 07 gregory 1712       .equalsIgnoreCase(CONSTANT_HTTP09))
2143 16 Oct 07 gregory 1713       /*
2143 16 Oct 07 gregory 1714        * 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 1723   // the index file, if
2143 16 Oct 07 gregory 1724   // there is no index
2143 16 Oct 07 gregory 1725   // 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 1728     // 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 1740     // If UNIX, Linux etc...
741 10 Oct 06 olle 1741     {
1652 22 May 07 gregory 1742       // First make the fast search for a file with correct CaSe
1652 22 May 07 gregory 1743       // 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 1752       // Now make a slow search for a file with incorrect CaSe SeNsItIvItY
1652 22 May 07 gregory 1753       // (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 1761          * Optimization or not?? I don't know... The ".toLowerCase()" is
2143 16 Oct 07 gregory 1762          * not needed as we make a ".equalsIgnoreCase()" comparison, but
2143 16 Oct 07 gregory 1763          * as the ".equalsIgnoreCase()" is made very many times (it is
2143 16 Oct 07 gregory 1764          * called as many times as there are files in the folder), and
2143 16 Oct 07 gregory 1765          * the ".toLowerCase()" is only made once it might be worth to
2143 16 Oct 07 gregory 1766          * make one ".toLowerCase()" to speed up the
2143 16 Oct 07 gregory 1767          * ".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 1790       // invalid header is given, then
2143 16 Oct 07 gregory 1791       // s_requestedFileName might not
2143 16 Oct 07 gregory 1792       // have been set.
1652 22 May 07 gregory 1793       returnThisPage(folder + showThisFile);
1652 22 May 07 gregory 1794       // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 1795       // NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before
1652 22 May 07 gregory 1796       // all data has been sent
1652 22 May 07 gregory 1797       // 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 1811    * There is no reason to set b_createConstantEnvironmentVariables==true
2143 16 Oct 07 gregory 1812    * unless you call "createEnvironmentVariables" just before you run a script
2143 16 Oct 07 gregory 1813    * (before you call "RunScript"). "createEnvironmentVariables(true)"
2143 16 Oct 07 gregory 1814    * ("b_createConstantEnvironmentVariables"==true) MUST be set to true and
2143 16 Oct 07 gregory 1815    * called (at least) ONCE before you run a script, or the environment
2143 16 Oct 07 gregory 1816    * variables WON'T BE SET!! (you can run this more than once, but it's
2143 16 Oct 07 gregory 1817    * 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 1834       // 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 1837       // 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 1840        * while (bis.available()>0) { System.out.print((char)bis.read()); }
1652 22 May 07 gregory 1841        * 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 1862        * If [you are not allowed to run scripts] OR [The file is not
2143 16 Oct 07 gregory 1863        * 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 1871          * This will make sure that the connection doesn't close
2143 16 Oct 07 gregory 1872          * immediately after the file download. Why this?: Because if we
2143 16 Oct 07 gregory 1873          * didn't have this, and lets say ".getSoTimeout()" is 5 sec,
2143 16 Oct 07 gregory 1874          * then a file download on for example 6 seconds would result in
2143 16 Oct 07 gregory 1875          * that the connection has been closed as soon as we had reached
2143 16 Oct 07 gregory 1876          * a ".read(xxx)"-method. Now we set this to 0 (infinity) before
2143 16 Oct 07 gregory 1877          * we send data and we set this back to for example 5 seconds
2143 16 Oct 07 gregory 1878          * 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 1883         // "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 1895         // theOutput.write(("\r\n").getBytes());
1652 22 May 07 gregory 1896         // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 1897         // NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close
1652 22 May 07 gregory 1898         // before all data has been sent
741 10 Oct 06 olle 1899         theOutput.flush();
1652 22 May 07 gregory 1900         // REMOVE ALL CLOSE: theOutput.close();
2143 16 Oct 07 gregory 1901       }
2143 16 Oct 07 gregory 1902       else
2143 16 Oct 07 gregory 1903       // The file is runnable and you have permission to run the
2143 16 Oct 07 gregory 1904       // 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 1909         // RunScript is started will make sure
2143 16 Oct 07 gregory 1910         // 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 1915         // set
2143 16 Oct 07 gregory 1916         // "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 1925         // 'perl
2143 16 Oct 07 gregory 1926         // "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 1935         // 'perl
2143 16 Oct 07 gregory 1936         // 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 1940        * This make sure that the next time we read form the inputstream
2143 16 Oct 07 gregory 1941        * (read what the browser has sent to us) we will only wait for 5
2143 16 Oct 07 gregory 1942        * 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 1959       // 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 1963       // and this value seems to give
2143 16 Oct 07 gregory 1964       // a very high speed when you
2143 16 Oct 07 gregory 1965       // 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 1971           // We add all "n" to a variable to know how many bytes have
1652 22 May 07 gregory 1972           // 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 1975           // downloading reserved paths ( ==>
2143 16 Oct 07 gregory 1976           // "/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 1981           // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 1982           // This is not necessery anymore. It works fine now:
1652 22 May 07 gregory 1983           // sleep(25); //I noticed that without this for example some
1652 22 May 07 gregory 1984           // large pictures (~200-300k) won't be shown. This might
1652 22 May 07 gregory 1985           // (but I don't know for sure) be valid also for other large
1652 22 May 07 gregory 1986           // files.
741 10 Oct 06 olle 1987         }
741 10 Oct 06 olle 1988       }
1652 22 May 07 gregory 1989       // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 1990       // NO MORE TIMEOUT STUFF: sleep(50); //Be safe, don't close before
1652 22 May 07 gregory 1991       // all data has been sent
1652 22 May 07 gregory 1992       // 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 2007          * Important: This must be reached no matter what! Even if an
2143 16 Oct 07 gregory 2008          * exception occurs in the try block, whis must be reached.
2143 16 Oct 07 gregory 2009          * Otherwise the file will be locked by Xerver (locked by
2143 16 Oct 07 gregory 2010          * Java.exe) until the garbage collector is runned (and you
2143 16 Oct 07 gregory 2011          * don't know when it will run) and detects that the file (the
2143 16 Oct 07 gregory 2012          * object "fileStreamed") is no longer referenced from anywhere
2143 16 Oct 07 gregory 2013          * else and it release the file by automatic. Until this
2143 16 Oct 07 gregory 2014          * happenes, no other application can write to or rename this
2143 16 Oct 07 gregory 2015          * 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 2032     // String filAndelse=fileName.substring(fileName.lastIndexOf(".")+1);
1652 22 May 07 gregory 2033     // 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 2038      * If b_allowTheseFileExtensions==true, then you are only allowed to
2143 16 Oct 07 gregory 2039      * download files with extensions that can be found in
2143 16 Oct 07 gregory 2040      * "as_fileExtensions". Otwerwise these file extionsions shall not be
2143 16 Oct 07 gregory 2041      * 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 2047   // 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 2055        * This will make sure that the connection doesn't close immediately
2143 16 Oct 07 gregory 2056        * after the file download. Why this?: Because if we didn't have
2143 16 Oct 07 gregory 2057        * this, and lets say ".getSoTimeout()" is 5 sec, then a file
2143 16 Oct 07 gregory 2058        * download on for example 6 seconds would result in that the
2143 16 Oct 07 gregory 2059        * connection has been closed as soon as we had reached a
2143 16 Oct 07 gregory 2060        * ".read(xxx)"-method. Now we set this to 0 (infinity) before we
2143 16 Oct 07 gregory 2061        * send data and we set this back to for example 5 seconds before we
2143 16 Oct 07 gregory 2062        * 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 2068       // "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 2075           // "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 2079       // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 2080       // NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before
1652 22 May 07 gregory 2081       // all data has been sent
1652 22 May 07 gregory 2082       theOutput.flush();
1652 22 May 07 gregory 2083       // 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 2086        * This make sure that the next time we read form the inputstream
2143 16 Oct 07 gregory 2087        * (read what the browser has sent to us) we will only wait for 5
2143 16 Oct 07 gregory 2088        * 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 2112       // connection doesn't close
2143 16 Oct 07 gregory 2113       // immediately after the file
2143 16 Oct 07 gregory 2114       // download. Why this?: Because
2143 16 Oct 07 gregory 2115       // if we didn't have this, and
2143 16 Oct 07 gregory 2116       // lets say ".getSoTimeout()" is
2143 16 Oct 07 gregory 2117       // 5 sec, then a file download
2143 16 Oct 07 gregory 2118       // on for example 6 seconds
2143 16 Oct 07 gregory 2119       // would result in that the
2143 16 Oct 07 gregory 2120       // connection has been closed as
2143 16 Oct 07 gregory 2121       // soon as we had reached a
2143 16 Oct 07 gregory 2122       // ".read(xxx)"-method. Now we
2143 16 Oct 07 gregory 2123       // set this to 0 (infinity)
2143 16 Oct 07 gregory 2124       // before we send data and we
2143 16 Oct 07 gregory 2125       // set this back to for example
2143 16 Oct 07 gregory 2126       // 5 seconds before we read data
2143 16 Oct 07 gregory 2127       // (call the
2143 16 Oct 07 gregory 2128       // ".read(xxx)"-method).
1652 22 May 07 gregory 2129       // DataOutputStream theOutput =new DataOutputStream(new
1652 22 May 07 gregory 2130       // BufferedOutputStream(so_userConnection.getOutputStream())); //I
1652 22 May 07 gregory 2131       // "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 2135       // data
2143 16 Oct 07 gregory 2136       // transfer
2143 16 Oct 07 gregory 2137       // is
2143 16 Oct 07 gregory 2138       // supported
2143 16 Oct 07 gregory 2139       // only
2143 16 Oct 07 gregory 2140       // with
2143 16 Oct 07 gregory 2141       // 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 2148             // "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 2150             // HTTP/1.1-browser
2143 16 Oct 07 gregory 2151             // will
2143 16 Oct 07 gregory 2152             // 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 2155         // WE
2143 16 Oct 07 gregory 2156         // MUST
2143 16 Oct 07 gregory 2157         // HAVE
2143 16 Oct 07 gregory 2158         // "false"
2143 16 Oct 07 gregory 2159         // WHEN
2143 16 Oct 07 gregory 2160         // SENDING
2143 16 Oct 07 gregory 2161         // THE
2143 16 Oct 07 gregory 2162         // HEADERS!
2143 16 Oct 07 gregory 2163         // Otherwise
2143 16 Oct 07 gregory 2164         // the
2143 16 Oct 07 gregory 2165         // Hexadecimal
2143 16 Oct 07 gregory 2166         // value
2143 16 Oct 07 gregory 2167         // will
2143 16 Oct 07 gregory 2168         // come
2143 16 Oct 07 gregory 2169         // before
2143 16 Oct 07 gregory 2170         // all
2143 16 Oct 07 gregory 2171         // the
2143 16 Oct 07 gregory 2172         // headers.
2143 16 Oct 07 gregory 2173         // It
2143 16 Oct 07 gregory 2174         // MUST
2143 16 Oct 07 gregory 2175         // come
2143 16 Oct 07 gregory 2176         // just
2143 16 Oct 07 gregory 2177         // before
2143 16 Oct 07 gregory 2178         // the
2143 16 Oct 07 gregory 2179         // raw
2143 16 Oct 07 gregory 2180         // data
2143 16 Oct 07 gregory 2181         // instead.
1652 22 May 07 gregory 2182         // "Content-Type: text/html;
1652 22 May 07 gregory 2183         // charset=ISO-8859-1\r\n\r\n",false);//NOTE: WE MUST HAVE
1652 22 May 07 gregory 2184         // "false" WHEN SENDING THE HEADERS! Otherwise the Hexadecimal
1652 22 May 07 gregory 2185         // value will come before all the headers. It MUST come just
1652 22 May 07 gregory 2186         // 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 2211             // NOTE: A link to a file called "abc%def.txt" won't
1652 22 May 07 gregory 2212             // work! All "%" has to be replaced with "%25". However,
1652 22 May 07 gregory 2213             // to check all filenames for a % during the listing
1652 22 May 07 gregory 2214             // does take to much time, so we won't bother about
1652 22 May 07 gregory 2215             // this. Note, this "problem" is a common problem (also
1652 22 May 07 gregory 2216             // 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 2224         // IF [no file extensions added to the list] AND [we allow all
1652 22 May 07 gregory 2225         // extensions], then we don't need to call
1652 22 May 07 gregory 2226         // "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 2237             // [you
2143 16 Oct 07 gregory 2238             // want
2143 16 Oct 07 gregory 2239             // share
2143 16 Oct 07 gregory 2240             // hidden
2143 16 Oct 07 gregory 2241             // files]
2143 16 Oct 07 gregory 2242             // OR
2143 16 Oct 07 gregory 2243             // [this
2143 16 Oct 07 gregory 2244             // is
2143 16 Oct 07 gregory 2245             // not a
2143 16 Oct 07 gregory 2246             // hidden
2143 16 Oct 07 gregory 2247             // file],
2143 16 Oct 07 gregory 2248             // 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 2283       // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 2284       // NO MORE TIMEOUT STUFF: sleep(125); //Be safe, don't close before
1652 22 May 07 gregory 2285       // 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 2288       // make
2143 16 Oct 07 gregory 2289       // sure
2143 16 Oct 07 gregory 2290       // that
2143 16 Oct 07 gregory 2291       // the
2143 16 Oct 07 gregory 2292       // next
2143 16 Oct 07 gregory 2293       // time
2143 16 Oct 07 gregory 2294       // we
2143 16 Oct 07 gregory 2295       // read
2143 16 Oct 07 gregory 2296       // form
2143 16 Oct 07 gregory 2297       // the
2143 16 Oct 07 gregory 2298       // inputstream
2143 16 Oct 07 gregory 2299       // (read
2143 16 Oct 07 gregory 2300       // what
2143 16 Oct 07 gregory 2301       // the
2143 16 Oct 07 gregory 2302       // browser
2143 16 Oct 07 gregory 2303       // has
2143 16 Oct 07 gregory 2304       // sent
2143 16 Oct 07 gregory 2305       // to
2143 16 Oct 07 gregory 2306       // us)
2143 16 Oct 07 gregory 2307       // we
2143 16 Oct 07 gregory 2308       // will
2143 16 Oct 07 gregory 2309       // only
2143 16 Oct 07 gregory 2310       // wait
2143 16 Oct 07 gregory 2311       // for
2143 16 Oct 07 gregory 2312       // 5
2143 16 Oct 07 gregory 2313       // seconds.
1652 22 May 07 gregory 2314       // 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("&nbsp;  <B>"); // &nbsp;
2143 16 Oct 07 gregory 2330     // required, or
2143 16 Oct 07 gregory 2331     // Opera 7 will
2143 16 Oct 07 gregory 2332     // ignore the
2143 16 Oct 07 gregory 2333     // first spaces
2143 16 Oct 07 gregory 2334     // on each line,
2143 16 Oct 07 gregory 2335     // so start with
2143 16 Oct 07 gregory 2336     // &nbsp;
2143 16 Oct 07 gregory 2337     // 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 2346         // 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 2355         // 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 2381       // we have two "
2143 16 Oct 07 gregory 2382       // " beside the
2143 16 Oct 07 gregory 2383       // <IMG ...> and
2143 16 Oct 07 gregory 2384       // </A>
2143 16 Oct 07 gregory 2385       // //Optimization...
1652 22 May 07 gregory 2386       for (int i = 0; i < forGoesTo; i++)
1652 22 May 07 gregory 2387         // 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 2396       // because
2143 16 Oct 07 gregory 2397       // we
2143 16 Oct 07 gregory 2398       // have
2143 16 Oct 07 gregory 2399       // two "
2143 16 Oct 07 gregory 2400       // "
2143 16 Oct 07 gregory 2401       // beside
2143 16 Oct 07 gregory 2402       // the
2143 16 Oct 07 gregory 2403       // <IMG
2143 16 Oct 07 gregory 2404       // ...>
2143 16 Oct 07 gregory 2405       // and
2143 16 Oct 07 gregory 2406       // </A>
2143 16 Oct 07 gregory 2407       // //Optimization...
1652 22 May 07 gregory 2408       for (int i = 0; i < forGoesTo; i++)
1652 22 May 07 gregory 2409         // Optimization...
741 10 Oct 06 olle 2410         strBuf.append(" ");
741 10 Oct 06 olle 2411     }
1652 22 May 07 gregory 2412     // strBuf.append(fileName);
1652 22 May 07 gregory 2413     // int
1652 22 May 07 gregory 2414     // forGoesTo=argMaximumFileNameSize+16-fileName.length()-fileSize.length();
1652 22 May 07 gregory 2415     // //Optimization...
1652 22 May 07 gregory 2416     // for (int i=0; i<forGoesTo; i++) //Optimization...
1652 22 May 07 gregory 2417     // 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 2426   // only s_requestedDocumentWithoutUnescape needs to be set (not the other
1652 22 May 07 gregory 2427   // 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 2435       // 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 2437       // connection doesn't close
2143 16 Oct 07 gregory 2438       // immediately after the file
2143 16 Oct 07 gregory 2439       // download. Why this?: Because
2143 16 Oct 07 gregory 2440       // if we didn't have this, and
2143 16 Oct 07 gregory 2441       // lets say ".getSoTimeout()" is
2143 16 Oct 07 gregory 2442       // 5 sec, then a file download
2143 16 Oct 07 gregory 2443       // on for example 6 seconds
2143 16 Oct 07 gregory 2444       // would result in that the
2143 16 Oct 07 gregory 2445       // connection has been closed as
2143 16 Oct 07 gregory 2446       // soon as we had reached a
2143 16 Oct 07 gregory 2447       // ".read(xxx)"-method. Now we
2143 16 Oct 07 gregory 2448       // set this to 0 (infinity)
2143 16 Oct 07 gregory 2449       // before we send data and we
2143 16 Oct 07 gregory 2450       // set this back to for example
2143 16 Oct 07 gregory 2451       // 5 seconds before we read data
2143 16 Oct 07 gregory 2452       // (call the
2143 16 Oct 07 gregory 2453       // ".read(xxx)"-method).
1652 22 May 07 gregory 2454       // Vid test av fel i Explorer d� man bes�ker "/katalogUtanSlash" och
1652 22 May 07 gregory 2455       // man inte redirectas till "/katalogUtanSlash/".
1652 22 May 07 gregory 2456       // s_requestedHTTP=CONSTANT_HTTP10;
1652 22 May 07 gregory 2457       // b_useKeepAlive=false;
1652 22 May 07 gregory 2458       // i_sendWhatData=DATATYPE_HEADONLY;
1652 22 May 07 gregory 2459       // Note, a bug in Internet Explorer:
1652 22 May 07 gregory 2460       // The behaviour of Internet Explorer is:
1652 22 May 07 gregory 2461       // It sends a request for "/abc%20def" (this bug is only valid for
1652 22 May 07 gregory 2462       // folders with spaces in the name
1652 22 May 07 gregory 2463       // (maybe other special charaters as well)) and then Xerver responds
1652 22 May 07 gregory 2464       // with
1652 22 May 07 gregory 2465       // "HTTP/1.1 301 Moved Permanently" and with a new location which is
1652 22 May 07 gregory 2466       // "/abc%20def/".
1652 22 May 07 gregory 2467       // If the new request that Internet Explorer sends to "/abc%20def/"
1652 22 May 07 gregory 2468       // gives a 403 error response
1652 22 May 07 gregory 2469       // then Explorer will try again and again infinite times!!!
1652 22 May 07 gregory 2470       //
1652 22 May 07 gregory 2471       // So once again, if (1) explorer asks for a folder with a space in
1652 22 May 07 gregory 2472       // the name
1652 22 May 07 gregory 2473       // and (2) it ask for the folder name without the last slash (so it
1652 22 May 07 gregory 2474       // recieves a
1652 22 May 07 gregory 2475       // 301 Moved Permanently message) and (3) the folder itself will
1652 22 May 07 gregory 2476       // return an error message,
1652 22 May 07 gregory 2477       // then explorer will go on forever and try to get the folder,
1652 22 May 07 gregory 2478       // 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 2482       // data
2143 16 Oct 07 gregory 2483       // transfer
2143 16 Oct 07 gregory 2484       // is
2143 16 Oct 07 gregory 2485       // supported
2143 16 Oct 07 gregory 2486       // only
2143 16 Oct 07 gregory 2487       // with
2143 16 Oct 07 gregory 2488       // HTTP/1.1
1652 22 May 07 gregory 2489       // theOutput.writeBytes( "HTTP/1.0 303 See Other \r\n"+
1652 22 May 07 gregory 2490       // theOutput.writeBytes( s_requestedHTTP+" 302 Redirected\n"+
1652 22 May 07 gregory 2491       // //WARNING!!!! THIS MUST BE "\n", CAN NOT BE "\r\n" HERE, OR IT
1652 22 May 07 gregory 2492       // WON'T WORK WITH ALL BROWSERS, FOR EXAMPLE NETSCAPE 1, EXPLORER 5
1652 22 May 07 gregory 2493       // 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 2501             // HTTP/1.1-browser
2143 16 Oct 07 gregory 2502             // will
2143 16 Oct 07 gregory 2503             // 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 2515       // NO MORE TIMEOUT STUFF: yield();
1652 22 May 07 gregory 2516       // NO MORE TIMEOUT STUFF: sleep(50); //Be safe, don't close before
1652 22 May 07 gregory 2517       // all data has been sent
1652 22 May 07 gregory 2518       // REMOVE ALL CLOSE: theOutput.close();
1652 22 May 07 gregory 2519       so_userConnection.setSoTimeout(i_soTimeoutAfterKeepAliveTransfer);// This
2143 16 Oct 07 gregory 2520       // make
2143 16 Oct 07 gregory 2521       // sure
2143 16 Oct 07 gregory 2522       // that
2143 16 Oct 07 gregory 2523       // the
2143 16 Oct 07 gregory 2524       // next
2143 16 Oct 07 gregory 2525       // time
2143 16 Oct 07 gregory 2526       // we
2143 16 Oct 07 gregory 2527       // read
2143 16 Oct 07 gregory 2528       // form
2143 16 Oct 07 gregory 2529       // the
2143 16 Oct 07 gregory 2530       // inputstream
2143 16 Oct 07 gregory 2531       // (read
2143 16 Oct 07 gregory 2532       // what
2143 16 Oct 07 gregory 2533       // the
2143 16 Oct 07 gregory 2534       // browser
2143 16 Oct 07 gregory 2535       // has
2143 16 Oct 07 gregory 2536       // sent
2143 16 Oct 07 gregory 2537       // to
2143 16 Oct 07 gregory 2538       // us)
2143 16 Oct 07 gregory 2539       // we
2143 16 Oct 07 gregory 2540       // will
2143 16 Oct 07 gregory 2541       // only
2143 16 Oct 07 gregory 2542       // wait
2143 16 Oct 07 gregory 2543       // for
2143 16 Oct 07 gregory 2544       // 5
2143 16 Oct 07 gregory 2545       // 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 2558    * private void crateHashTableWithFileExtensions() { HM_allFileExt=new
1652 22 May 07 gregory 2559    * HashMap(); String val; val="text/html"; HM_allFileExt.put("htm",val);
1652 22 May 07 gregory 2560    * HM_allFileExt.put("shtml",val); HM_allFileExt.put("html",val);
1652 22 May 07 gregory 2561    * HM_allFileExt.put("shtm",val); HM_allFileExt.put("asp",val);
1652 22 May 07 gregory 2562    * val="text/html"; HM_allFileExt.put("txt",val);
1652 22 May 07 gregory 2563    * HM_allFileExt.put("text",val); HM_allFileExt.put("c++",val);
1652 22 May 07 gregory 2564    * HM_allFileExt.put("ini",val); HM_allFileExt.put("pl",val);
1652 22 May 07 gregory 2565    * HM_allFileExt.put("java",val); HM_allFileExt.put("inf",val);
1652 22 May 07 gregory 2566    * HM_allFileExt.put("cc",val); HM_allFileExt.put("c",val);
1652 22 May 07 gregory 2567    * val="image/jpeg"; HM_allFileExt.put("jpg",val);
1652 22 May 07 gregory 2568    * HM_allFileExt.put("jpeg",val); HM_allFileExt.put("jpe",val);
1652 22 May 07 gregory 2569    * val="image/gif"; HM_allFileExt.put("gif",val); val="image/png";
1652 22 May 07 gregory 2570    * 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 2575       // "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 2870     // if ( s_fileExt.equalsIgnoreCase("texi"))
1652 22 May 07 gregory 2871     // 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 2911    * private void exceptionOccured(Exception e) {
1652 22 May 07 gregory 2912    * System.out.println(b_isRunningScript+" <==> "+e); if (b_isRunningScript) {
1652 22 May 07 gregory 2913    * rs_process.killProcess(); } }
1652 22 May 07 gregory 2914    */
1652 22 May 07 gregory 2915   // 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 2922       // 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 2930         // System.out.println("so_userConnection.getOutputStream() kan
1652 22 May 07 gregory 2931         // 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 }