package yoonforh.dir; /** * DirServletSSI.java * Copyright (c) 1998 Yoon Kyung Koo. All rights reserved. * * contact via yoonforh@moon.daewoo.co.kr * * first release date 1998/08/22 * @version 1.1 1998/09/28 * @author Yoon Kyung Koo */ import java.io.*; import java.util.*; import java.net.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; // import sun.security.x509.*; /** * DirServletSSI class */ public class DirServletSSI extends HttpServlet { public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { //value chosen to limit denial of service if (req.getContentLength() > 8*1024) { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); out.println("Too big"); out.println("

Error - content length >8k not "); out.println("

"); } else { doGet(req, res); } } public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); String urlBase=req.getParameter("URLBASE"); String path=req.getParameter("PATH"); boolean recursive=true; String param=req.getParameter("RECURSIVE"); if (param!=null && param.equalsIgnoreCase("OFF")) recursive=false; File file=new File(path); if (!file.exists()) { out.println("

Invalid path

"); return; } listFiles(out, file, urlBase, path, recursive); } private void listFiles(ServletOutputStream out, File file, String baseURL, String path, boolean recursive) throws IOException { String[] files=file.list(); // first list up files and then directories out.println(""); for (int i=0; i"); out.println(""); out.print(""); out.print(""); out.print(""); out.println(""); } else continue; } out.println("
\"*\""); out.println(""+convertToASCII(files[i])+""); out.println(String.valueOf(newFile.length())+convertToASCII(" ¹ÙÀÌÆ®")+""); out.println(convertToASCII(DateFormat.getDateTimeInstance().format(new Date(newFile.lastModified())))+"
"); for (int i=0; i\"+\""); out.println(""); out.println(baseURL+"/"+convertToASCII(files[i])+""); listFiles(out, newFile, baseURL+"/"+convertToASCII(files[i]), newFileName, recursive); } else { out.println("

\"+\""); out.println(""); out.println(""+convertToASCII(files[i])+""); } } else continue; } } /** * convertToASCII() * this method converts Cp949 encoded character to ISO8859_1 encoded * @param String string to converted * @return String converted string */ public String convertToASCII(String str) { try { byte[] kscBytes=str.getBytes("Cp949"); str=new String(kscBytes, "8859_1"); } catch (java.io.UnsupportedEncodingException e) { System.err.println(e.toString()); } return str; } public String getServletInfo() { return "A servlet that displays directory contents"; } }