⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pluginapplicationtype.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/* HEADER  */
package com.sslexplorer.vpn.util.types;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Vector;

import com.sslexplorer.vpn.util.ApplicationLauncher;
import com.sslexplorer.vpn.util.ApplicationLauncherEvents;
import com.sslexplorer.vpn.util.ApplicationType;
import com.sslexplorer.vpn.util.ProcessMonitor;
import com.sslexplorer.vpn.util.XMLElement;
//import java.net.URLClassLoader;

public class PluginApplicationType implements ApplicationType {

  private ApplicationLauncherEvents events;
  private ApplicationLauncher launcher;
  //private String classpath = "";
  private String extensionClass;
  //private File workingDir;
  //private String[] jvm;
  //private Vector programArgs = new Vector();
  //private Vector jvmArgs = new Vector();
  //private ProcessMonitor process;


  /* (non-Javadoc)
   * @see com.sslexplorer.vpn.util.ApplicationType#prepare(com.sslexplorer.vpn.util.ApplicationLauncher, com.sslexplorer.vpn.util.XMLElement)
   */
  public void prepare(ApplicationLauncher launcher, ApplicationLauncherEvents events, XMLElement element) throws IOException {
    this.launcher = launcher;
    this.events = events;


    String jre = (String) element.getAttribute("jre");

    if(events!=null)
      events.debug("Checking our version against the required application version "
                   + jre);

    if (!ApplicationLauncher.checkVersion(jre)) {
      throw new IOException("Application requires Java Runtime Environment " +
                            jre);
    }

    Enumeration e = element.enumerateChildren();

    while (e.hasMoreElements()) {
      XMLElement el = (XMLElement) e.nextElement();

      if (el.getName().equalsIgnoreCase("classpath")) {
        buildClassPath(el);
      }
      else if (el.getName().equalsIgnoreCase("plugin")) {
        extensionClass = (String) el.getAttribute("class");
        if(events!=null)
          events.debug("Plug-in class is " + extensionClass);
      }
    }
    if(events!=null)
      events.debug("Finished preparing application descriptor.");
  }

  public void start() {

  }

  private void addClasspathEntry(XMLElement e) throws IOException {


    String shared = (String)e.getAttribute("shared");
    File entry;
    if(shared!=null && shared.equalsIgnoreCase("true")) {
      entry = launcher.addShared(e);
    } else {
      entry = launcher.addFile(e);
    }

    if(events!=null)
      events.debug("Adding " + entry.getAbsolutePath() + " to CLASSLOADER");
    // The entry may be null because were not the correct platform


  }

  private void buildClassPath(XMLElement element) throws IOException {


    if(events!=null)
      events.debug("Building classpath");
    Enumeration en = element.enumerateChildren();
    XMLElement e;


    while(en.hasMoreElements()) {
      e = (XMLElement) en.nextElement();
      if(e.getName().equalsIgnoreCase("jar")) {
        addClasspathEntry(e);
      } else if(e.getName().equals("if")) {

        String jre = (String)e.getAttribute("jre");
        if(jre==null) {
          String parameter = (String)e.getAttribute("parameter");

          if(parameter!=null) {
            String requiredValue = (String) e.getAttribute("value");
            boolean not = "true".equalsIgnoreCase(((String)e.getAttribute("not")));

            // Check the parameter
            String value = (String)launcher.getDescriptorParams().get(parameter);

            if ((!not && requiredValue.equalsIgnoreCase(value)) || (not && !requiredValue.equalsIgnoreCase(value)) ) {
              buildClassPath(e);
            }

          } else
            throw new IOException("<if> element requires jre or parameter attribute");
        } else {

          if (isSupportedJRE(jre)) {
            buildClassPath(e);
          }
        }
      } else
        throw new IOException("Invalid element <" + e.getName() + "> found in <classpath>");
    }

  }

  private boolean isSupportedJRE(String jre) {

    int[] ourVersion = ApplicationLauncher.getVersion(System.getProperty("java.version"));

    if(jre.startsWith(">")) {

      // Our JRE must be greater than the value specified
      int[] requiredVersion = ApplicationLauncher.getVersion(jre.substring(1));
      for(int i=0;i<ourVersion.length && i<requiredVersion.length;i++) {
       if(ourVersion[i] < requiredVersion[i])
         return false;
      }
      return true;

    } else if(jre.startsWith("<")) {
      // Our JRE must be less than the value specified
      int[] requiredVersion = ApplicationLauncher.getVersion(jre.substring(1));
      for(int i=0;i<ourVersion.length && i<requiredVersion.length;i++) {
       if(ourVersion[i] > requiredVersion[i])
         return false;
      }
      return true;

    } else {
      // Direct comparison
      int[] requiredVersion = ApplicationLauncher.getVersion(jre);
      for(int i=0;i<ourVersion.length && i<requiredVersion.length;i++) {
       if(ourVersion[i] != requiredVersion[i])
         return false;
      }
      return true;

    }

  }



  /* (non-Javadoc)
   * @see com.sslexplorer.vpn.util.ApplicationType#checkFileCondition(com.sslexplorer.vpn.util.XMLElement)
   */
  public boolean checkFileCondition(XMLElement el) throws IOException,IllegalArgumentException {
    String jre = (String)el.getAttribute("jre");
    if(jre == null) {
      throw new IllegalArgumentException("No supported attributes in condition.");
    }
    else {
      return isSupportedJRE(jre);
    }
  }

  /* (non-Javadoc)
   * @see com.sslexplorer.vpn.util.ApplicationType#getProcessMonitor()
   */
  public ProcessMonitor getProcessMonitor() {
    return null;
  }

  /* (non-Javadoc)
   * @see com.sslexplorer.vpn.util.ApplicationType#getRedirectParameters()
   */
  public String getRedirectParameters() {
    return null;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -