home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 49 / cda49.iso / VNULabs / BrownOrifice / BOHTTPD-0.2 / BOHTTPDConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-11  |  5.2 KB  |  167 lines

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.OutputStream;
  5. import java.io.PrintWriter;
  6. import java.net.URL;
  7. import netscape.net.URLInputStream;
  8.  
  9. class BOHTTPDConnection implements Runnable {
  10.    // $FF: renamed from: cl BOSocket
  11.    public BOSocket field_0 = null;
  12.    // $FF: renamed from: sv BOHTTPD
  13.    public BOHTTPD field_1 = null;
  14.  
  15.    public void dump_to(String var1, OutputStream var2) throws IOException {
  16.       PrintWriter var3 = new PrintWriter(var2, true);
  17.  
  18.       try {
  19.          String var4;
  20.          int var16;
  21.          for(var4 = var1; (var16 = var4.indexOf("%20")) >= 0; var4 = var4.substring(0, var16) + " " + var4.substring(var16 + 3, var4.length())) {
  22.          }
  23.  
  24.          while((var16 = var4.indexOf("%3a")) >= 0) {
  25.             var4 = var4.substring(0, var16) + ":" + var4.substring(var16 + 3, var4.length());
  26.          }
  27.  
  28.          while((var16 = var4.indexOf("%3A")) >= 0) {
  29.             var4 = var4.substring(0, var16) + ":" + var4.substring(var16 + 3, var4.length());
  30.          }
  31.  
  32.          while((var16 = var4.indexOf("%2F")) >= 0) {
  33.             var4 = var4.substring(0, var16) + "/" + var4.substring(var16 + 3, var4.length());
  34.          }
  35.  
  36.          while((var16 = var4.indexOf("%2f")) >= 0) {
  37.             var4 = var4.substring(0, var16) + "/" + var4.substring(var16 + 3, var4.length());
  38.          }
  39.  
  40.          while((var16 = var4.indexOf("%2E")) >= 0) {
  41.             var4 = var4.substring(0, var16) + "." + var4.substring(var16 + 3, var4.length());
  42.          }
  43.  
  44.          while((var16 = var4.indexOf("%2e")) >= 0) {
  45.             var4 = var4.substring(0, var16) + "." + var4.substring(var16 + 3, var4.length());
  46.          }
  47.  
  48.          while(var4.length() >= 1 && var4.startsWith("/")) {
  49.             var4 = var4.substring(1, var4.length());
  50.          }
  51.  
  52.          while(var4.length() >= 2 && var4.endsWith("//")) {
  53.             var4 = var4.substring(0, var4.length() - 1);
  54.          }
  55.  
  56.          if (!var4.startsWith("http:") && !var4.startsWith("https:") && !var4.startsWith("ftp:") && !var4.startsWith("file:")) {
  57.             var4 = "file:/" + var4;
  58.          }
  59.  
  60.          URL var6 = new URL(var4);
  61.          if (var4.equals("file:/")) {
  62.             String var25 = "Rerouted.\n";
  63.             var3.println("HTTP/1.1 302 Found");
  64.             var3.println("Location: http://" + this.field_1.host + ":" + this.field_1.port + "/" + this.field_1.path);
  65.             var3.println("Content-type: text/plain");
  66.             var3.println("Content-length: " + var25.length());
  67.             var3.println("");
  68.             var3.print(var25);
  69.             var3.flush();
  70.             return;
  71.          }
  72.  
  73.          if (var4.startsWith("file:") && !var4.startsWith("file:/" + this.field_1.path) || var4.indexOf("..") >= 0) {
  74.             String var24 = "Permission Denied.\n";
  75.             var3.println("HTTP/1.1 403 Permission Denied");
  76.             var3.println("Content-type: text/plain");
  77.             var3.println("Content-length: " + var24.length());
  78.             var3.println("");
  79.             var3.print(var24);
  80.             var3.flush();
  81.             return;
  82.          }
  83.  
  84.          BOURLConnection var7 = new BOURLConnection(var6);
  85.          BOURLInputStream var8 = new BOURLInputStream(var7);
  86.  
  87.          int var10;
  88.          for(var10 = 0; ((URLInputStream)var8).read() >= 0; ++var10) {
  89.          }
  90.  
  91.          ((URLInputStream)var8).close();
  92.          String var11 = BOMimeType.get(var4);
  93.          String var12 = "";
  94.          String var13 = "";
  95.          if (var11 == "text/html") {
  96.             String var14 = "http://" + this.field_1.remote_host + "/proj/dan/BOHTTPD-0.2";
  97.             var12 = "<link rel=stylesheet href=\"" + var14 + "/BOHTTPD.css\">\n" + "<table bgcolor=white width=640>" + "<tr valign=top>" + "<td><img src=\"" + var14 + "/BOHTTPD_logo.gif\"></td>" + "<td width=100% align=left>" + "<h2>Brown Orifice<br><code>" + var4 + "</code></h2>" + "<ul>" + "<li><a href=\"" + var14 + "/BOHTTPD.cgi\">Brown Orifice HTTPD Homepage</a>" + "<li><a href=\"" + var14 + "/BOHTTPD_search.cgi\">BOHTTPD Search</a>" + "<li><a href=\"" + var14 + "/BOHTTPD_download.cgi\">Download BOHTTPD!</a>" + "</ul>" + "</td>" + "</tr>" + "</table><hr>";
  98.             var13 = "<script>\nvar ss;\nvar ll = document.links.length;\nfor (var i = 0; i < ll; i++) {\n  ss += 'q=' + escape(document.links[i]) + '&';\n}\nvar i = new Image;i.src='" + var14 + "/BOHTTPD_log.cgi?' + ss;" + "</script>";
  99.             var10 += var12.length() + var13.length();
  100.          }
  101.  
  102.          var3.println("HTTP/1.1 200 OK");
  103.          var3.println("Content-type: " + var11);
  104.          var3.println("Content-length: " + var10);
  105.          var3.println("");
  106.          var3.print(var12);
  107.          var3.flush();
  108.          var7 = new BOURLConnection(var6);
  109.          var8 = new BOURLInputStream(var7);
  110.  
  111.          int var9;
  112.          while((var9 = ((URLInputStream)var8).read()) >= 0) {
  113.             var2.write(var9);
  114.          }
  115.  
  116.          var3.print(var13);
  117.          var3.flush();
  118.          ((URLInputStream)var8).close();
  119.       } catch (Exception var15) {
  120.          String var5 = String.valueOf(String.valueOf(var15));
  121.          var3.println("HTTP/1.1 500 Internal Server Error");
  122.          var3.println("Content-type: text/plain");
  123.          var3.println("Content-length: " + var5.length());
  124.          var3.println("");
  125.          var3.print(var5);
  126.          var3.flush();
  127.       }
  128.  
  129.    }
  130.  
  131.    public void run() {
  132.       try {
  133.          new PrintWriter(this.field_0.getOutputStream(), true);
  134.          BufferedReader var2 = new BufferedReader(new InputStreamReader(this.field_0.getInputStream()));
  135.          String var3 = var2.readLine();
  136.  
  137.          while(var2.readLine().length() > 0) {
  138.          }
  139.  
  140.          int var4 = var3.indexOf(" ");
  141.          if (var4 < 0) {
  142.             throw new IOException();
  143.          }
  144.  
  145.          int var5 = var3.indexOf(" HTTP");
  146.          if (var5 < 0) {
  147.             throw new IOException();
  148.          }
  149.  
  150.          String var6 = var3.substring(var4 + 1, var5);
  151.          this.dump_to(var6, this.field_0.getOutputStream());
  152.          this.field_0.close_real();
  153.       } catch (Exception var7) {
  154.          System.out.println(var7);
  155.       }
  156.  
  157.    }
  158.  
  159.    public void setServer(BOHTTPD var1) {
  160.       this.field_1 = var1;
  161.    }
  162.  
  163.    public void setSock(BOSocket var1) {
  164.       this.field_0 = var1;
  165.    }
  166. }
  167.