package Acme.Serve.mrh;

import Acme.Serve.servlet.*;
import Acme.Serve.servlet.http.*;
import java.io.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

public class CrackerServlet extends HttpServlet {
  public void service(HttpServletRequest request,
                      HttpServletResponse response)
      throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("text/html");
    ServletOutputStream out = response.getOutputStream();
    String[] imageFiles = {"Cannon.gif", "Club.gif",
                           "Punch.gif", "Skull.gif",
                           "Yell.gif"};
    int index =
      (int)Math.round(Math.floor(Math.random()*5.0));
    String imageFile = imageFiles[index];
    String imageBase =
      "http://www.apl.jhu.edu/~hall/images/";
    String host = request.getRemoteHost();
    out.println
      ("<!DOCTYPE HTML PUBLIC " +
         "\"-//W3C//DTD HTML 3.2//EN\">\n" +
       "<HTML>\n" +
       "<HEAD>\n" +
       "<TITLE>Depart, Vile Cracker!</TITLE>\n" +
       "</HEAD>\n" +
       "\n" +
       "<BODY BGCOLOR=\"WHITE\">\n" +
       "<CENTER>\n" +
       "<H1>Depart, Vile Cracker!</H1>\n" +
       "<IMG SRC=\"" + imageBase + imageFile + "\">\n" +
       "</CENTER>\n" +
       "<P>\n" +
       "Naturally, we use shadow passwords, so\n" +
       "the password file wouldn't have done you\n" +
       "any good anyhow. But as punishment, we have\n" +
       "notified postmaster@" +
       host + " of your scurrilous activity.\n" +
       "<P>\n" +
       "I hope you get");
    if (host.toUpperCase().endsWith("EDU"))
      out.println("kicked out of school.");
    else
      out.println("fired.");
  }
}
       
