private boolean fixFile(File file) {
    String content = JDIO.readFileToString(file);
    if (content.contains(LICENSE_PREFIX_TRIMMED)) return false;

    StringBuilder sb = new StringBuilder();
    sb.append(LICENSE);
    sb.append(content);

    return JDIO.writeLocalFile(file, sb.toString());
  }
 public void quickCheck() {
   String content;
   int count;
   for (File file : getSourceFiles(dir)) {
     content = JDIO.readFileToString(file);
     count = new Regex(content, LICENSE_PREFIX_TRIMMED).count();
     if (count > 1) {
       System.out.println(prepareFilename(file));
     }
   }
 }
 @Override
 public String toString() {
   final File infoxml = this.getJacinfoXml();
   String ret = null;
   try {
     if (infoxml.exists()) {
       ret = new Regex(JDIO.readFileToString(infoxml), "name=\"([^\"]*)").getMatch(0);
     }
   } catch (final Exception e) {
     // e.printStackTrace();
   }
   if (ret == null) {
     ret = this.file.getName();
   }
   return ret;
 }
  public boolean copyExampleImage() {
    final File exf = this.getExampleImage();
    if (exf == null || !exf.exists()) {
      final File[] listF =
          this.getCaptchaFolder()
              .listFiles(
                  new FilenameFilter() {

                    public boolean accept(final File dir, final String name) {
                      return name.matches("(?is).*\\.(jpg|png|gif)");
                    }
                  });
      if (listF != null && listF.length > 1) {
        JDIO.copyFile(listF[0], new File(this.file, "example." + this.getCaptchaType(false)));
        return true;
      }
    }
    return false;
  }
  public HeaderChecker(File dir) {
    LICENSE = JDIO.readFileToString(HeaderChecker.LICENSE_FILE);
    LICENSE_PREFIX = LICENSE.substring(0, Math.min(LICENSE.indexOf('\r'), LICENSE.indexOf('\n')));
    LICENSE_PREFIX_TRIMMED = LICENSE_PREFIX.substring(2).trim();

    if (dir == null || !dir.exists()) {
      JFileChooser fc = new JFileChooser();
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      fc.setCurrentDirectory(new File("."));
      if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        dir = fc.getSelectedFile();
      } else {
        System.out.println("Keine Datei ausgewählt!");
        System.exit(0);
      }
    }

    this.dir = dir;
    this.files = HeaderChecker.getSourceFiles(dir);
  }
예제 #6
0
파일: C.java 프로젝트: xiongtec/jdownloader
  // @Override
  public ContainerStatus callDecryption(File lc) {
    ContainerStatus cs = new ContainerStatus(lc);

    // if (!getProperties().getBooleanProperty("USECCFRSDF", false)) {
    Vector<URL> services;
    try {
      services = new Vector<URL>();

      Collections.sort(
          services,
          new Comparator<Object>() {
            public int compare(Object a, Object b) {
              return (int) (Math.random() * 4.0 - 2.0);
            }
          });
      services.add(0, new URL("http://service.jdownloader.net/dlcrypt/getDLC.php"));
      Iterator<URL> it = services.iterator();

      String dlc = null;
      // Ua6LDQoSRm6XrkfussF7t1iM5D+WAT9y5QB0U3gwmkELcT+6+4
      // U0RUeKvv256VUPZdHttMCuf0/C
      // Ua6LDRJGbpeuR+6ywXu3WIzkj5YBP3LlAHRTeDCaQQtxkLr7hTRFR4q+/
      // bnpVQ9l0e20wK5/T8L1

      while (it.hasNext() && dlc == null) {
        URL service = it.next();
        try {
          // RequestInfo ri;
          // requestInfo = Plugin.postRequest(new
          // URL(ri.getLocation()), null, null, null, "src=ccf&data="
          // + data, true);
          Browser br = new Browser();
          br.setDebug(true);
          PostFormDataRequest r = (PostFormDataRequest) br.createPostFormDataRequest(service + "");
          r.addFormData(new FormData("upload", lc.getName(), lc));

          try {
            r.addFormData(
                new FormData(
                    "l",
                    getClass()
                            .forName(getClass().getPackage().getName() + ".Config")
                            .getField("CCF")
                            .get(null)
                        + ""));

          } catch (Throwable e) {

          }
          r.addFormData(new FormData("src", "ccf"));

          br.openRequestConnection(r);

          String ret = br.loadConnection(null) + "";

          if (ret != null && ret.contains("<dlc>")) {
            dlc = new Regex(ret, "<dlc>(.*)</dlc>").getMatch(0);
            if (dlc.length() < 90) {
              dlc = null;
            }
          }

        } catch (Exception e) {
          JDLogger.exception(e);
        }
      }
      if (dlc != null) {
        lc = new File(lc.getAbsolutePath().substring(0, lc.getAbsolutePath().length() - 3) + "dlc");
        JDIO.writeLocalFile(lc, dlc);
        LinkCollector.getInstance()
            .addCrawlerJob(new LinkCollectingJob("file://" + lc.getAbsolutePath()));
        cs.setStatus(ContainerStatus.STATUS_FINISHED);

        return cs;
      }
    } catch (MalformedURLException e) {

    }

    cs.setStatus(ContainerStatus.STATUS_FAILED);

    return cs;
  }
    public void run() {
      try {
        InputStream requestInputStream = Current_Socket.getInputStream();
        BufferedInputStream reader = new BufferedInputStream(requestInputStream);

        String line = null;
        HashMap<String, String> headers = new HashMap<String, String>();

        while ((line = readline(reader)) != null && line.trim().length() > 0) {
          String key = null;
          String value = null;
          if (line.indexOf(": ") > 0) {
            key = line.substring(0, line.indexOf(": ")).toLowerCase();
            value = line.substring(line.indexOf(": ") + 2);
          } else {
            key = null;
            value = line;
          }
          headers.put(key, value);
        }

        if (headers.containsKey(null)) {
          String Method = headers.get(null).split(" ")[0];
          if (Method.compareToIgnoreCase("get") == 0 || Method.compareToIgnoreCase("post") == 0) {
            /* get oder post header gefunden */
            if (headers.containsKey("content-type")) {
              if (headers
                      .get("content-type")
                      .compareToIgnoreCase("application/x-www-form-urlencoded")
                  == 0) {
                if (headers.containsKey("content-length")) {
                  /*
                   * POST Form Daten in GET Format übersetzen,
                   * damit der RequestParams Parser nicht
                   * geändert werden muss
                   */
                  int post_len = new Integer(headers.get("content-length"));
                  int post_len_toread = post_len;
                  int post_len_read = 0;
                  byte[] cbuf = new byte[post_len];
                  int indexstart = 0;
                  while (post_len_toread > 0) {
                    if ((post_len_read = reader.read(cbuf, indexstart, post_len_toread)) == -1) {
                      break;
                    }
                    indexstart = indexstart + post_len_read;
                    post_len_toread = post_len_toread - post_len_read;
                  }
                  String RequestParams = new String(cbuf).trim();
                  if (indexstart == post_len) {
                    /*
                     * alten POST aus Header Liste holen,
                     * neuen zusammenbauen
                     */
                    String request = headers.get(null);
                    String[] requ = request.split(" ");
                    if (Method.compareToIgnoreCase("post") == 0) {
                      headers.put(
                          null, requ[0] + " " + requ[1] + "?" + RequestParams + " " + requ[2]);
                    } else {
                      logger.severe("POST Daten bei nem GET aufruf???");
                    }
                  } else {
                    logger.severe(
                        "POST Fehler postlen soll = "
                            + post_len
                            + " postlen gelesen = "
                            + post_len_read);
                  }
                }
              } else if (headers.get("content-type").contains("multipart/form-data")) {
                /*
                 * POST Form Daten in GET Format übersetzen,
                 * damit der RequestParams Parser nicht geändert
                 * werden muss
                 *
                 * Zusätzlich das File auslesen (die komplette
                 * Verarbeiten findet auf Hex statt!!)
                 */
                if (headers.containsKey("content-length")) {
                  int post_len = new Integer(headers.get("content-length"));
                  int post_len_toread = post_len;
                  int post_len_read = 0;
                  byte[] cbuf = new byte[post_len];
                  int indexstart = 0;
                  String limiter =
                      new Regex(
                              headers.get("content-type"),
                              Pattern.compile("boundary=(.*)", Pattern.CASE_INSENSITIVE))
                          .getMatch(0);
                  if (limiter != null) {
                    /*
                     * nur weitermachen falls ein limiter
                     * vorhanden ist
                     */
                    limiter = "--" + limiter;
                    limiter = JDHexUtils.getHexString(limiter);
                    while (post_len_toread > 0) {
                      if ((post_len_read = reader.read(cbuf, indexstart, post_len_toread)) == -1) {
                        break;
                      }
                      indexstart = indexstart + post_len_read;
                      post_len_toread = post_len_toread - post_len_read;
                    }
                    if (indexstart == post_len) {
                      String RequestParams = "";
                      /*
                       * momentan wird multipart nur für
                       * containerupload genutzt, daher
                       * form-data parsing unnötig
                       */
                      String MultiPartData[][] =
                          new Regex(
                                  JDHexUtils.getHexString(cbuf),
                                  Pattern.compile(
                                      limiter
                                          + JDHexUtils.getHexString("\r")
                                          + "{0,1}"
                                          + JDHexUtils.getHexString("\n")
                                          + "{0,1}"
                                          + JDHexUtils.REGEX_MATCH_ALL_HEX
                                          + "(?="
                                          + ""
                                          + JDHexUtils.getHexString("\r")
                                          + "{0,1}"
                                          + JDHexUtils.getHexString("\n")
                                          + "{0,1}"
                                          + limiter
                                          + ")",
                                      Pattern.CASE_INSENSITIVE | Pattern.DOTALL))
                              .getMatches();
                      for (String[] element : MultiPartData) {
                        if (element[0].contains(
                            JDHexUtils.getHexString(
                                "Content-Disposition: form-data; name=\"container\""))) {
                          String containertyp =
                              new Regex(
                                      element[0],
                                      Pattern.compile(
                                          JDHexUtils.getHexString("filename=\"")
                                              + JDHexUtils.REGEX_FIND_ALL_HEX
                                              + JDHexUtils.getHexString(".")
                                              + JDHexUtils.REGEX_MATCH_ALL_HEX
                                              + JDHexUtils.getHexString("\""),
                                          Pattern.CASE_INSENSITIVE))
                                  .getMatch(0);
                          if (containertyp != null) {
                            containertyp = new String(JDHexUtils.getByteArray(containertyp));
                          }
                          if (containertyp != null
                              && (containertyp.contains("dlc")
                                  || containertyp.contains("ccf")
                                  || containertyp.contains("rsdf")
                                  || containertyp.contains("jdc"))) {
                            File containerfile =
                                JDUtilities.getResourceFile(
                                    "container/" + System.currentTimeMillis() + "." + containertyp);
                            if (JDIO.saveToFile(
                                containerfile,
                                JDHexUtils.getByteArray(
                                    element[0].substring(
                                        element[0].indexOf(JDHexUtils.getHexString("\r\n\r\n"))
                                            + 8)))) {
                              /*
                               * RequestParameter
                               * zusammenbauen
                               */
                              RequestParams =
                                  "do=Upload&file=" + Encoding.urlEncode(containerfile.getName());
                              break;
                            }
                          } else {
                            if (containertyp != null) {
                              logger.severe("unknown container typ: " + containertyp);
                            }
                          }
                        }
                      }
                      /*
                       * alten POST aus Header Liste
                       * holen, neuen zusammenbauen
                       */
                      String request = headers.get(null);
                      String[] requ = request.split(" ");
                      if (Method.compareToIgnoreCase("post") == 0) {
                        headers.put(
                            null, requ[0] + " " + requ[1] + "?" + RequestParams + " " + requ[2]);
                      } else {
                        logger.severe("POST Daten bei nem GET aufruf???");
                      }
                    } else {
                      logger.severe(
                          "POST Fehler postlen soll = "
                              + post_len
                              + " postlen gelesen = "
                              + post_len_read);
                    }
                  }
                }
              }
            }

            JDSimpleWebserverResponseCreator response = new JDSimpleWebserverResponseCreator();
            JDSimpleWebserverRequestHandler request =
                new JDSimpleWebserverRequestHandler(headers, response);
            OutputStream outputStream = Current_Socket.getOutputStream();
            if (NeedAuth == true) {
                /* need authorization */
              if (headers.containsKey("authorization")) {
                if (JDSimpleWebserver.AuthUser.equals(headers.get("authorization"))) {
                  /*
                   * send authorization granted
                   */
                  /* logger.info("pass stimmt"); */
                  request.handle();

                } else {
                    /* send authorization failed */
                  response.setAuth_failed();
                }
              } else {
                  /* send autorization needed */
                response.setAuth_needed();
              }
            } else {
                /* no autorization needed */
              request.handle();
            }

            response.writeToStream(outputStream);
            outputStream.close();
          }
        } else {
          /* kein get oder post header */
          logger.severe("kein post oder get header");
        }
        Current_Socket.close();

      } catch (SocketException e) {
        logger.severe("WebInterface: Socket error");
      } catch (IOException e) {
        logger.severe("WebInterface: I/O Error");
      }
    }
 public boolean isEasyCaptchaMethode() {
   final File js = this.getScriptJas();
   return js.exists()
       && JDIO.readFileToString(js).contains("param.useSpecialGetLetters=EasyCaptcha");
 }