client/ftpd/src/se/lu/thep/coreftpd/webserver/InstallXerver.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
741 10 Oct 06 olle 26 //  Xerver Free Web Server
741 10 Oct 06 olle 27 //  Copyright (C) 2002-2005 Omid Rouhani
741 10 Oct 06 olle 28 //
741 10 Oct 06 olle 29 //
741 10 Oct 06 olle 30 //  This program is free software; you can redistribute it and/or
741 10 Oct 06 olle 31 //  modify it under the terms of the GNU General Public License
741 10 Oct 06 olle 32 //  as published by the Free Software Foundation; either version 2
741 10 Oct 06 olle 33 //  of the License, or (at your option) any later version.
741 10 Oct 06 olle 34 //
741 10 Oct 06 olle 35 //  This program is distributed in the hope that it will be useful,
741 10 Oct 06 olle 36 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
741 10 Oct 06 olle 37 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
741 10 Oct 06 olle 38 //  GNU General Public License for more details.
741 10 Oct 06 olle 39 //
741 10 Oct 06 olle 40 //  You should have received a copy of the GNU General Public License
741 10 Oct 06 olle 41 //  along with this program; if not, write to the Free Software
741 10 Oct 06 olle 42 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
741 10 Oct 06 olle 43 //
741 10 Oct 06 olle 44 //
741 10 Oct 06 olle 45 //  #############################################################
741 10 Oct 06 olle 46 //  ##  YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT:          ##
741 10 Oct 06 olle 47 //  ##  HTTP://WWW.JAVASCRIPT.NU/XERVER/                       ##
741 10 Oct 06 olle 48 //  ##                                                         ##
741 10 Oct 06 olle 49 //  ##  IF YOUR SOFTWARE IS NOT RELEASED UNDER THE             ##
741 10 Oct 06 olle 50 //  ##  GNU GENERAL PUBLIC LICENSE (GPL),                      ##
741 10 Oct 06 olle 51 //  ##  PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!!   ##
741 10 Oct 06 olle 52 //  ##                                                         ##
741 10 Oct 06 olle 53 //  ##  FOR FULL LICENSE, PLEASE READ "XERVER LICENSE".        ##
741 10 Oct 06 olle 54 //  #############################################################
741 10 Oct 06 olle 55
1652 22 May 07 gregory 56 package se.lu.thep.coreftpd.webserver;
741 10 Oct 06 olle 57
741 10 Oct 06 olle 58 import java.io.BufferedReader;
741 10 Oct 06 olle 59 import java.io.File;
741 10 Oct 06 olle 60 import java.io.InputStreamReader;
741 10 Oct 06 olle 61 import javax.swing.UIManager;
741 10 Oct 06 olle 62
741 10 Oct 06 olle 63 /**
1652 22 May 07 gregory 64  * 
1652 22 May 07 gregory 65  * <B>About this class:</B> <BR>
1652 22 May 07 gregory 66  * This class creates the directories that Xerver needs and moves files into
1652 22 May 07 gregory 67  * these directories when Xerver is installed. <BR>
741 10 Oct 06 olle 68  * You can also (safety) run this class when Xerver already has been installed.
1652 22 May 07 gregory 69  * 
741 10 Oct 06 olle 70  * @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a>
741 10 Oct 06 olle 71  * @version 1.0
741 10 Oct 06 olle 72  */
741 10 Oct 06 olle 73
1652 22 May 07 gregory 74 final public class InstallXerver {
1652 22 May 07 gregory 75   private String hiddenFolder = "data" + File.separator;
741 10 Oct 06 olle 76
1652 22 May 07 gregory 77   private String errorFilesFolder = "errorHTML" + File.separator;
741 10 Oct 06 olle 78
1652 22 May 07 gregory 79   private String helpFilesFolder = "help" + File.separator;
741 10 Oct 06 olle 80
1652 22 May 07 gregory 81   private final String zipFileName = "filesZipped.zip";
1652 22 May 07 gregory 82
1652 22 May 07 gregory 83   private final static boolean b_showErrors = false;
1652 22 May 07 gregory 84
1652 22 May 07 gregory 85   public static void main(String[] s) {
1652 22 May 07 gregory 86     try {
1652 22 May 07 gregory 87       // UIManager.setLookAndFeel(
1652 22 May 07 gregory 88       // UIManager.getCrossPlatformLookAndFeelClassName());
1652 22 May 07 gregory 89       UIManager
1652 22 May 07 gregory 90           .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // Try
1652 22 May 07 gregory 91                                               // to
1652 22 May 07 gregory 92                                               // use
1652 22 May 07 gregory 93                                               // Windows
1652 22 May 07 gregory 94                                               // interface
1652 22 May 07 gregory 95     } catch (Exception e) {
1652 22 May 07 gregory 96     }
1652 22 May 07 gregory 97
741 10 Oct 06 olle 98     new InstallXerver();
741 10 Oct 06 olle 99   }
741 10 Oct 06 olle 100
741 10 Oct 06 olle 101   /**
1652 22 May 07 gregory 102    * Run the main method to start this constructor which is only used to start
1652 22 May 07 gregory 103    * an terminal based install program where the user is asked where to
1652 22 May 07 gregory 104    * install Xerver.
1652 22 May 07 gregory 105    */
1652 22 May 07 gregory 106   InstallXerver() {
1652 22 May 07 gregory 107     String indata = null;
741 10 Oct 06 olle 108     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
741 10 Oct 06 olle 109     System.out.println("What do you want to do?");
1652 22 May 07 gregory 110     System.out
1652 22 May 07 gregory 111         .println("[1]  Start Xerver installer (require a graphical interface). (RECOMMENDED)");
741 10 Oct 06 olle 112     System.out.println("[2]  Install Xerver in the current directory.");
1652 22 May 07 gregory 113     System.out
1652 22 May 07 gregory 114         .println("[3]  I want to enter a location where Xerver shall be installed.");
741 10 Oct 06 olle 115     System.out.println("");
1652 22 May 07 gregory 116     do {
741 10 Oct 06 olle 117       System.out.println("Please enter 1, 2, 3 or \"exit\" to quit:");
741 10 Oct 06 olle 118       try {
1652 22 May 07 gregory 119         indata = in.readLine();
741 10 Oct 06 olle 120
741 10 Oct 06 olle 121         if (indata.toLowerCase().equals("exit"))
741 10 Oct 06 olle 122           System.exit(0);
1652 22 May 07 gregory 123         else if (indata.equals("1")) {
741 10 Oct 06 olle 124           System.out.println("Starting Xerver installer...");
741 10 Oct 06 olle 125           new SetupWindow();
1652 22 May 07 gregory 126           System.out
1652 22 May 07 gregory 127               .println("Start Xerver Setup with \"java SetupXerver\".");
741 10 Oct 06 olle 128           System.out.println("Start Xerver with \"java Start\".");
1652 22 May 07 gregory 129         } else if (indata.equals("2")) {
741 10 Oct 06 olle 130           System.out.println("Installing in progress...");
741 10 Oct 06 olle 131           new InstallXerver("");
741 10 Oct 06 olle 132           System.out.println("Installing done!");
741 10 Oct 06 olle 133           System.out.println("");
741 10 Oct 06 olle 134           System.out.println("Starting Xerver Setup:");
741 10 Oct 06 olle 135           new SetupXerver();
1652 22 May 07 gregory 136         } else if (indata.equals("3")) {
741 10 Oct 06 olle 137           System.out.println("Where do you want to install Xerver:");
1652 22 May 07 gregory 138           String s_installPathEntered = in.readLine();
1652 22 May 07 gregory 139           File f_installPathEntered = new File(s_installPathEntered);
1652 22 May 07 gregory 140           if (f_installPathEntered.isDirectory()
1652 22 May 07 gregory 141               && !s_installPathEntered.equals("")) {
741 10 Oct 06 olle 142             System.out.println("Installing in progress...");
741 10 Oct 06 olle 143             new InstallXerver(f_installPathEntered.getPath());
741 10 Oct 06 olle 144             System.out.println("Installing done!");
1652 22 May 07 gregory 145             System.out.println("When you are in "
1652 22 May 07 gregory 146                 + f_installPathEntered.getAbsolutePath()
1652 22 May 07 gregory 147                 + ", you can use these commands:");
1652 22 May 07 gregory 148             System.out
1652 22 May 07 gregory 149                 .println("\"java SetupXerver\" - Start Xerver Setup"); // Note,
1652 22 May 07 gregory 150                                             // we
1652 22 May 07 gregory 151                                             // can't
1652 22 May 07 gregory 152                                             // start
1652 22 May 07 gregory 153                                             // "new
1652 22 May 07 gregory 154                                             // SetupXerver()"
1652 22 May 07 gregory 155                                             // automatically
1652 22 May 07 gregory 156                                             // as
1652 22 May 07 gregory 157                                             // it
1652 22 May 07 gregory 158                                             // might
1652 22 May 07 gregory 159                                             // not
1652 22 May 07 gregory 160                                             // have
1652 22 May 07 gregory 161                                             // been
1652 22 May 07 gregory 162                                             // installed
1652 22 May 07 gregory 163                                             // (extracted)
1652 22 May 07 gregory 164                                             // Xerver
1652 22 May 07 gregory 165                                             // in
1652 22 May 07 gregory 166                                             // the
1652 22 May 07 gregory 167                                             // "present
1652 22 May 07 gregory 168                                             // working
1652 22 May 07 gregory 169                                             // directory"...
741 10 Oct 06 olle 170             System.out.println("\"java Start\" - Start Xerver");
1652 22 May 07 gregory 171           } else {
1652 22 May 07 gregory 172             indata = "dummy value"; // not 1, 2 or 3
1652 22 May 07 gregory 173             System.out.println(f_installPathEntered.getPath()
1652 22 May 07 gregory 174                 + " does not exists! Try again!");
741 10 Oct 06 olle 175           }
741 10 Oct 06 olle 176         }
1652 22 May 07 gregory 177       } catch (Exception e) {
1652 22 May 07 gregory 178         if (b_showErrors)
1652 22 May 07 gregory 179           System.out.println("An error occured:\n" + e.getMessage());
1652 22 May 07 gregory 180       }
1652 22 May 07 gregory 181     } while (!indata.equals("1") && !indata.equals("2")
1652 22 May 07 gregory 182         && !indata.equals("3"));
741 10 Oct 06 olle 183   }
741 10 Oct 06 olle 184
741 10 Oct 06 olle 185   /**
1652 22 May 07 gregory 186    * This installs Xerver into <CODE>s_installPath</CODE>. Make sure the
1652 22 May 07 gregory 187    * zip file <CODE>zipFileName</CODE> is located in the "current working
1652 22 May 07 gregory 188    * directory" (usually the same folder as this class file is located).
1652 22 May 07 gregory 189    * <CODE>s_installPath</CODE> must be a valid path or "" ("" = install in
1652 22 May 07 gregory 190    * "present working directory")
1652 22 May 07 gregory 191    */
1652 22 May 07 gregory 192   InstallXerver(String s_installPath) {
1652 22 May 07 gregory 193     if (s_installPath == null)
1652 22 May 07 gregory 194       s_installPath = "";
741 10 Oct 06 olle 195     else if ((new File(s_installPath)).exists())
1652 22 May 07 gregory 196       s_installPath = (new File(s_installPath)).getPath()
1652 22 May 07 gregory 197           + File.separator;
741 10 Oct 06 olle 198     else
1652 22 May 07 gregory 199       s_installPath = "";
741 10 Oct 06 olle 200
1652 22 May 07 gregory 201     // System.out.println("*******************************************");
1652 22 May 07 gregory 202     // System.out.println("**** Xerver is being installed! ****");
1652 22 May 07 gregory 203     // System.out.println("*******************************************");
1652 22 May 07 gregory 204     // System.out.println("");
1652 22 May 07 gregory 205     // System.out.print("* Extracting \""+zipFileName+"...\" ");
1652 22 May 07 gregory 206     new ExtractZipFileInstall(zipFileName, true, s_installPath); // true=overwrite
1652 22 May 07 gregory 207                                     // files
1652 22 May 07 gregory 208                                     // (ExtractZipFileInstall
1652 22 May 07 gregory 209                                     // will
1652 22 May 07 gregory 210                                     // never
1652 22 May 07 gregory 211                                     // owerwrite
1652 22 May 07 gregory 212                                     // "xerver.cfg")
1652 22 May 07 gregory 213     moveAllFiles(s_installPath); // In case the user has unzipped the
1652 22 May 07 gregory 214                     // zip-file manually or if someone only
1652 22 May 07 gregory 215                     // got all files coming with the source
1652 22 May 07 gregory 216                     // files in one folder.
1652 22 May 07 gregory 217     // System.out.println("[ DONE! ]");
1652 22 May 07 gregory 218     // System.out.println("");
1652 22 May 07 gregory 219     // System.out.println("* Running Xerver Setup [ DONE! ]");
1652 22 May 07 gregory 220     // System.out.println("");
1652 22 May 07 gregory 221     // (new Thread(new SetupXerverKernel())).start();
1652 22 May 07 gregory 222     // System.out.println("[NOTE: Visit http://localhost:32123/ now!]");
1652 22 May 07 gregory 223     // System.out.println("");
1652 22 May 07 gregory 224     // System.out.print("* Starting Xerver ");
1652 22 May 07 gregory 225     // new Start();
1652 22 May 07 gregory 226     // System.out.println("[ DONE! ]");
1652 22 May 07 gregory 227     // System.out.println("");
1652 22 May 07 gregory 228     // System.out.println("* Install is finished!");
741 10 Oct 06 olle 229   }
741 10 Oct 06 olle 230
741 10 Oct 06 olle 231   /**
1652 22 May 07 gregory 232    * Move all files Xerver uses to the correct directories. This is actually
1652 22 May 07 gregory 233    * not used during a normal install, as <CODE>ExtractZipFileInstall</CODE>
1652 22 May 07 gregory 234    * takes care of that, but this is useful for example when someone already
1652 22 May 07 gregory 235    * has extracted all files in one directory and now runs the "java
1652 22 May 07 gregory 236    * InstallXerver" to move all files to the correct directories.
1652 22 May 07 gregory 237    */
1652 22 May 07 gregory 238   private void moveAllFiles(String s_installPath) {
1652 22 May 07 gregory 239     String[] filesThatShallBeHidden = { "AddAliasSetup.html",
1652 22 May 07 gregory 240         "AddDirSetup.html", "AddExtSetup.html", "AddIndSetup.html",
1652 22 May 07 gregory 241         "AddProtDirSetup.html", "AddProtFrameSetup.html",
1652 22 May 07 gregory 242         "AddProtSetup.html", "AddProtUserSetup.html",
1652 22 May 07 gregory 243         "AddScriptExtSetup.html", "empty.html",
1652 22 May 07 gregory 244         "WizGeneralSettings.html", "WizFrames.html", "WizMenu.html",
1652 22 May 07 gregory 245         "WizStep1.html", "WizStep2.html", "WizStep3.html",
1652 22 May 07 gregory 246         "WizStep4.html", "WizStep5.html", "WizStep6.html",
1652 22 May 07 gregory 247         "WizStep7.html", "WizStep8.html", "WizStep9.html",
1652 22 May 07 gregory 248         "WizardHelp.html", "Xerver.cfg", "Xerver.cfg.txt",
1652 22 May 07 gregory 249         "empty.html", "imagefileicon.gif", "imagefolder.gif",
1652 22 May 07 gregory 250         "imageinvisible.gif", "imagelogo.gif", "imagestartbutton.gif",
1652 22 May 07 gregory 251         "imagestartsetupbutton.gif", "imagestopbutton.gif",
1652 22 May 07 gregory 252         "imagestopsetupbutton.gif", "imagewizardbig.gif",
1652 22 May 07 gregory 253         "imagewizardsmall.gif", "imagexerverlogo.gif" };
741 10 Oct 06 olle 254
1652 22 May 07 gregory 255     String[] filesThatCanBeEdited = { "error400badrequest.html",
1652 22 May 07 gregory 256         "error401notauthorized.html",
1652 22 May 07 gregory 257         "error403hiddenfilenotshared.html",
1652 22 May 07 gregory 258         "error403noaccessextension.html",
1652 22 May 07 gregory 259         "error403noaccessfolder.html",
1652 22 May 07 gregory 260         "error403nodirectorylisting.html",
1652 22 May 07 gregory 261         "error403webservercantreadfile.html",
1652 22 May 07 gregory 262         "error404filedoesnotexist.html", "error505unknownhttp.html" };
741 10 Oct 06 olle 263
1652 22 May 07 gregory 264     String[] helpFiles = { "help403forbidden.html", "helpcantrunperl.html",
1652 22 May 07 gregory 265         "helpcantrunphp.html", "helpdifferentrunmodes.html",
1652 22 May 07 gregory 266         "helpfriendscantbrowse.html", "helpisxerverfree.html",
1652 22 May 07 gregory 267         "helpjavainstalled.html", "helplowsystemresources.html",
1652 22 May 07 gregory 268         "helpownerrorpages.html", "helppasswordtofolders.html",
1652 22 May 07 gregory 269         "helpperlhelloworld.html", "helpperlwontrun.html",
1652 22 May 07 gregory 270         "helpphphelloworld.html", "helpphpwontrun.html",
1652 22 May 07 gregory 271         "helpproblemwithscripts.html", "helprunotherscripts.html",
1652 22 May 07 gregory 272         "helprunxerver.html", "helpstartxerver.html",
1652 22 May 07 gregory 273         "helpuninstall.html", "helpwhatisxerver.html", "index.html",
1652 22 May 07 gregory 274         "main.html", "menu.html" };
741 10 Oct 06 olle 275
741 10 Oct 06 olle 276     createFolders(s_installPath);
741 10 Oct 06 olle 277     moveFiles(hiddenFolder, filesThatShallBeHidden, s_installPath);
741 10 Oct 06 olle 278     moveFiles(errorFilesFolder, filesThatCanBeEdited, s_installPath);
741 10 Oct 06 olle 279     moveFiles(helpFilesFolder, helpFiles, s_installPath);
741 10 Oct 06 olle 280   }
741 10 Oct 06 olle 281
741 10 Oct 06 olle 282   /**
1652 22 May 07 gregory 283    * This creates all necessary directories for Xerver at <CODE>s_installPath</CODE>.
1652 22 May 07 gregory 284    * <CODE>s_installPath</CODE> shall be "" if you want create the
1652 22 May 07 gregory 285    * directories in the "present working directory".
1652 22 May 07 gregory 286    */
1652 22 May 07 gregory 287   private void createFolders(String s_installPath) {
1652 22 May 07 gregory 288     (new File(s_installPath + hiddenFolder)).mkdir();
1652 22 May 07 gregory 289     (new File(s_installPath + errorFilesFolder)).mkdir();
1652 22 May 07 gregory 290     (new File(s_installPath + helpFilesFolder)).mkdir();
741 10 Oct 06 olle 291   }
741 10 Oct 06 olle 292
741 10 Oct 06 olle 293   /**
1652 22 May 07 gregory 294    * Moves all files located at <CODE>s_installPath</CODE> and listed in
1652 22 May 07 gregory 295    * <CODE>filesToHide</CODE> into a folder called <CODE>s_installPath</CODE>+<CODE>folder</CODE>.
1652 22 May 07 gregory 296    * <CODE>s_installPath</CODE> can, but must not, end with an \ or /. For
1652 22 May 07 gregory 297    * example: "C:\dir" works as well as "C:\dir\". <CODE>s_installPath</CODE>
1652 22 May 07 gregory 298    * might be "" if you want to use relative path's (relative from "present
1652 22 May 07 gregory 299    * working directory") in <CODE>folder</CODE> and <CODE>filesToHide</CODE>.
1652 22 May 07 gregory 300    */
1652 22 May 07 gregory 301   private void moveFiles(String folder, String[] filesToHide,
1652 22 May 07 gregory 302       String s_installPath) {
1652 22 May 07 gregory 303     if (s_installPath == null)
1652 22 May 07 gregory 304       s_installPath = "";
741 10 Oct 06 olle 305
1652 22 May 07 gregory 306     if (s_installPath != "" || (new File(s_installPath)).exists()) {
1652 22 May 07 gregory 307       s_installPath = (new File(s_installPath)).getPath()
1652 22 May 07 gregory 308           + File.separator;
1652 22 May 07 gregory 309       for (int i = 0, filesToHideLength = filesToHide.length; i < filesToHideLength; i++) // Optimization...
741 10 Oct 06 olle 310       {
1652 22 May 07 gregory 311         File theFile = new File(s_installPath + filesToHide[i]);
1652 22 May 07 gregory 312         if (theFile.exists() && theFile.isFile()) // Om filen man ska
1652 22 May 07 gregory 313                               // flytta finns
741 10 Oct 06 olle 314         {
1652 22 May 07 gregory 315           File theFileToReplace = new File(s_installPath + folder
1652 22 May 07 gregory 316               + filesToHide[i]);
1652 22 May 07 gregory 317           if (theFileToReplace.exists()
1652 22 May 07 gregory 318               && !filesToHide[i].toLowerCase().equals(
1652 22 May 07 gregory 319                   "xerver.cfg")) // If a file already exists
1652 22 May 07 gregory 320                           // (and if it isn't
1652 22 May 07 gregory 321                           // "xerver.cfg"), remove
1652 22 May 07 gregory 322                           // it... (so you don't have
1652 22 May 07 gregory 323                           // to remove it manually
1652 22 May 07 gregory 324                           // when you update Xerver;
1652 22 May 07 gregory 325                           // However, do not replace
1652 22 May 07 gregory 326                           // "Xerver.cfg", as it's a
1652 22 May 07 gregory 327                           // data file)
741 10 Oct 06 olle 328           {
741 10 Oct 06 olle 329             theFileToReplace.delete();
741 10 Oct 06 olle 330           }
1652 22 May 07 gregory 331           theFile.renameTo(new File(s_installPath + folder
1652 22 May 07 gregory 332               + filesToHide[i])); // Flytta filen
741 10 Oct 06 olle 333         }
1652 22 May 07 gregory 334         // else the file doesn't exists, which means that the
1652 22 May 07 gregory 335         // installation has already been done
741 10 Oct 06 olle 336       }
741 10 Oct 06 olle 337     }
741 10 Oct 06 olle 338   }
741 10 Oct 06 olle 339 }