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

📄 vpnapplicationlauncher.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.vpn.client;

import com.sslexplorer.vpn.util.ApplicationLauncher;
import java.util.Hashtable;
import com.sslexplorer.vpn.util.ApplicationLauncherEvents;
import java.io.InputStream;
import java.util.Enumeration;
import com.maverick.http.HttpClient;
import java.io.IOException;
import com.maverick.http.GetMethod;
import com.maverick.http.PostMethod;
import com.maverick.http.HttpResponse;
import com.sslexplorer.vpn.util.XMLElement;
import com.sslexplorer.vpn.base.WinRegistry;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class VPNApplicationLauncher
    extends ApplicationLauncher {


  /* DEBUG */static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(VPNApplicationLauncher.class);

     VPNClient vpn;
     public VPNApplicationLauncher(VPNClient vpn, Hashtable parameters, ApplicationLauncherEvents events) {
       super("https", vpn.getUsername(), vpn.getSSLExplorerHost(), vpn.getSSLExplorerPort(), parameters, events);
       this.vpn = vpn;
     }

     protected boolean processLauncherElement(XMLElement element) {

         if(element.getName().equalsIgnoreCase("registry")) {
             Enumeration e = element.enumerateChildren();

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

               processRegistryElements(el);
             }
             return true;
           } else
             return false;
     }

     
     private void processRegistryElements(XMLElement el) {
         if (el.getName().equalsIgnoreCase("get")) {
			String scope = el.getStringAttribute("scope");
			String key = replaceTokens(el.getStringAttribute("key"));
			String value = replaceTokens(el.getStringAttribute("value"));
			String param = replaceTokens(el.getStringAttribute("parameter"));
			String defaultValue = replaceTokens(el.getStringAttribute("default"));

			addParameter(param, WinRegistry.getRegistryValue(scope, key, value,
					defaultValue == null ? "" : defaultValue));
		} else if (el.getName().equalsIgnoreCase("set")) {
			String scope = el.getStringAttribute("scope");
			String key = replaceTokens(el.getStringAttribute("key"));
			String value = replaceTokens(el.getStringAttribute("value"));
			String arg = replaceTokens(el.getStringAttribute("arg"));

			WinRegistry.setRegistryValue(scope, key, value, arg);

		} else if (el.getName().equalsIgnoreCase("if")) {
			
			String scope = el.getStringAttribute("scope");
			String key = replaceTokens(el.getStringAttribute("key"));
			String value = replaceTokens(el.getStringAttribute("value"));
			String notAttr = el.getStringAttribute("not");
			String existsAttr = el.getStringAttribute("exists");
			String equalsAttr = el.getStringAttribute("equals");

			if (existsAttr != null) {
				boolean exists = Boolean.getBoolean(existsAttr);
				String v = WinRegistry.getRegistryValue(scope, key, value,
						"DEFAULT_VALUE");
				if (v.equals("DEFAULT_VALUE") && !exists) {
					processRegistryElements(el);
				} else if (!v.equals("DEFAULT_VALUE") && exists) {
					processRegistryElements(el);
				}
			} else if (notAttr != null) {
				boolean not = Boolean.getBoolean(notAttr == null ? "false"
						: notAttr);
				String v = WinRegistry.getRegistryValue(scope, key, value, "");

				if (equalsAttr.equals(v) && !not) {
					processRegistryElements(el);
				} else if (!equalsAttr.equals(v) && not) {
					processRegistryElements(el);
				}
			}

		}
	}
     
     public InputStream getApplicationDescriptor() throws IOException {

       if (events != null)
         events.debug("Getting application descriptor using Maverick HTTP client");

       HttpClient client = vpn.getHttpClient();

       PostMethod post = new PostMethod("/getApplication.do");

       Enumeration en = parameters.keys();

       String key;
       while (en.hasMoreElements()) {
         key = (String) en.nextElement();
         post.setParameter(key, (String) parameters.get(key));
       }

      try {
        HttpResponse response = client.execute(post);

        return response.getInputStream();
      }
      catch (Exception ex) {
        throw new IOException(ex.getMessage());
      }
     }

     public InputStream getDownloadFile(String name, String ticket, String filename) throws IOException {

       if (events != null)
         events.debug("Downloading application file using Maverick HTTP client");

       HttpClient client = vpn.getHttpClient();

       GetMethod get = new GetMethod("/getApplicationFile.do"
            + "?name=" + name + "&ticket=" + ticket + "&file=" + filename);

      try {
        HttpResponse response = client.execute(get);

        return response.getInputStream();
      }
      catch (Exception ex) {
        throw new IOException(ex.getMessage());
      }

    }
}

⌨️ 快捷键说明

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