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

📄 vpnlauncher.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *  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.launcher;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;

import com.sshtools.ui.awt.ImageCanvas;
import com.sshtools.ui.awt.UIUtil;
import com.sslexplorer.vpn.util.ApplicationLauncher;
import com.sslexplorer.vpn.util.ApplicationLauncherEvents;
import com.sslexplorer.vpn.util.ProcessMonitor;
import com.sslexplorer.vpn.util.ProgressBar;
import com.sslexplorer.vpn.util.Tunnel;
import com.sslexplorer.vpn.util.XMLElement;

public class VPNLauncher extends Applet implements ApplicationLauncherEvents {
    private boolean isStandalone = false;
    String ticket;
    ProgressBar progress;
    String cmdline;
    String name;
    boolean monitor = false;
    boolean debug = false;
    Button launch;
    String localProxyURL;
    ProcessMonitor processMonitor;
    long totalNumBytes;
    String userAgent;
    Panel mainPanel;  
    
    // New properties
    String appName = "SSL-Explorer Agent";
    String extensionId = "VPN Client";
    boolean isAgent = true;
    String launcherImage = "/images/agent.gif";

    // Get a parameter value
    public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def);
    }

    // Construct the applet
    public VPNLauncher() {
    }

    // Initialize the applet
    public void init() {
        System.out.println("Initialising launcher applet");

        // #ifdef MSJAVA
        /*
         * try { if (Class.forName("com.ms.security.PolicyEngine") != null) {
         * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.SYSTEM);
         * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.PROPERTY); } }
         * catch (Throwable cnfe) { cnfe.printStackTrace(); }
         */
        // #endif
        // #ifdef NETSCAPE
        /*
         * try {
         * netscape.security.PrivilegeManager.enablePrivilege("UniversalExecAccess"); }
         * catch (Exception cnfe) {
         * System.out.println("netscape.security.PrivilegeManager class not found"); cnfe.printStackTrace(); }
         */
        // #endif
        
        
        /**
         * This section loads the launcher type information
         */
        System.out.println("Getting launcher type information from parameters");
        
        appName = getParameter("appName", appName);
        extensionId = getParameter("extensionId", extensionId);
        launcherImage = getParameter("launcherImage", launcherImage);
        isAgent = Boolean.valueOf(getParameter("isAgent", String.valueOf(isAgent))).booleanValue();

        if(!isAgent) {
            try {
            // Set a fake codebase so that images are loaded from the root of SSL-Explorer (i.e. in the images folders)
            UIUtil.setCodeBase(new URL(getCodeBase().getProtocol(), getCodeBase().getHost(),
                getCodeBase().getPort()==-1 ? 443 : getCodeBase().getPort(), ""));
            } catch(MalformedURLException ex) { }
        }
        System.out.println("Launch application " + appName + " extensionId=" + extensionId + " image=" + launcherImage + " isAgent=" + isAgent);
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Component initialization
    private void jbInit() throws Exception {
        String background = getParameter("background", "#e6e6e6");
        setBackground(Color.decode(background));
        String foreground = getParameter("foreground", "#000000");
        setForeground(Color.decode(foreground));
        setLayout(new BorderLayout());
        add(new ImageCanvas(UIUtil.loadImage(getClass(), launcherImage)), BorderLayout.WEST);
        mainPanel = new Panel(new BorderLayout());
        add(mainPanel, BorderLayout.CENTER);

        if ("true".equals(getParameter("autoStart", "false"))) {
            mainPanel.add(new Label("Launching .."));
        } /*else {
            addLaunchButton();
        }*/
    }

    public void start() {
        if ("true".equals(getParameter("autoStart", "false"))) {
            System.out.println("Autostart is <true>, launching client");
            launch();
        } else {
            System.out.println("Autostart is *NOT* <true>, *NOT* launching client");
        }
    }

    public void stop() {
        System.out.println("Stopping launcher applet.");
    }

    public void launch() {
        try {

            // Remove me!!! Testing only
            // com.maverick.ssl.https.HTTPSURLStreamHandlerFactory.installHTTPSSupport();

            System.out.println("Launching " + appName);

            // Get the pending VPN session ticket from the browser
            ticket = this.getParameter("ticket", null);

            // We cannot have a null ticket!
            if (ticket == null && isAgent) {
                // Show an error message...
                System.out.println("Ticket is null!");
                return;
            }

            /**
             * Determine if we need to monitor the executed process. If we do
             * then all of the output from the process will be written to
             * System.out which should make it appear in the console.
             * 
             * If are monitoring and we close the applet it causes some problems
             * with the process which results in an unresponsive period. Not
             * sure what this is but once this applet is deployed and tested we
             * should have no need to monitor.
             */
            System.out.println("Retreiving monitor status");
            monitor = Boolean.valueOf(getParameter("monitor", "false")).booleanValue();

            System.out.println("Retreiving debug status");
            debug = Boolean.valueOf(getParameter("debug", "false")).booleanValue();

            // Determine proxy URL
            System.out.println("Checking browser proxy settings");

            userAgent = getParameter("userAgent", "Unknown");
            System.out.println("User agent " + userAgent);
            
            localProxyURL = getParameter("proxyURL", "");
            String pluginProxyURL = "";

            if (localProxyURL.toLowerCase().startsWith("browser://")) {
                System.out.println("No proxy set by user configuration, checking java plugin properties..");

                /* If the launcher is running using the plugin we might be able
                 * to extract the proxy settings from there
                 */
                    String browserProxy = System.getProperty("javaplugin.proxy.config.list");
                    if (browserProxy != null && !browserProxy.equals("")) {
                        StringTokenizer t = new StringTokenizer(browserProxy, ",");
                        while (t.hasMoreTokens()) {
                            String type = t.nextToken();
                            int idx = type.indexOf('=');
                            if (idx != -1) {
                                String value = type.substring(idx + 1);
                                type = type.substring(0, idx);
                                if (type.equals("http")) {
                                    pluginProxyURL = "http://" + value;
                                    break;
                                }
                            } else {
                                // Unknown form
                            }
                        }
                      }
                    
            } else if (localProxyURL != null && !localProxyURL.equals("")) {
                if (!localProxyURL.startsWith("http://") && !localProxyURL.startsWith("https://")
                                && !localProxyURL.startsWith("browser://"))
                    localProxyURL = "http://" + localProxyURL;
            }

            // Add the required parameters for our ApplicationLauncher
            final Hashtable params = new Hashtable();
            params.put("name", extensionId);
            params.put("ticket", ticket);
            
            if(isAgent) {
                params.put("userAgent", userAgent);
                params.put("pluginProxyURL", pluginProxyURL);
                
                setIfNotEmpty("java.version", params);
                setIfNotEmpty("java.vendor", params);
                setIfNotEmpty("sun.os.patch.level", params);
                setIfNotEmpty("os.name", params);
                setIfNotEmpty("os.version", params);
                setIfNotEmpty("os.arch", params);
            }
            Thread thread = new Thread() {

                public void run() {

                    // #ifdef MSJAVA
                    /*
                     * try { System.out.println("Asserting SYSTEM permission");
                     * 
                     * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.SYSTEM);
                     * System.out.println("Asserting FILEIO permission");
                     * 
                     * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.FILEIO);
                     * System.out.println("Asserting EXEC permission");
                     * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.EXEC);
                     * System.out.println("Asserting PROPERTY permission");
                     * 
                     * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.PROPERTY);
                     * System.out.println("Asserting USERFILEIO permission");
                     * 
                     * com.ms.security.PolicyEngine.assertPermission(com.ms.security.PermissionID.USERFILEIO); }
                     * catch(Throwable t) { t.printStackTrace(); }
                     */
                    // #endif
                    System.out.println("Starting application launcher");

                    System.out.println(System.getProperties().toString());
                    try {
                        startingLaunch(appName);

                        ApplicationLauncher launcher = new ApplicationLauncher("https", null, VPNLauncher.this.getCodeBase()
                                        .getHost().equals("") ? "localhost" : VPNLauncher.this.getCodeBase().getHost(),
                                        VPNLauncher.this.getCodeBase().getPort() == -1 ? 443 : VPNLauncher.this.getCodeBase()
                                                        .getPort(), params, VPNLauncher.this);

                        launcher.setDebug(debug);
                        
                        System.out.println("Setting local proxy URL to " + localProxyURL);

⌨️ 快捷键说明

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