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

📄 vpnlauncher.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        launcher.setLocalProxyURL(localProxyURL);
                        launcher.prepare();
                        System.out.println("Prepared launcher");
                        
                        SynchronizationThread sync = new SynchronizationThread(launcher);
                        System.out.println("Starting synchronization thread");
                        sync.start();
                        // Give the connection time to get established
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException ie) {
                            ie.printStackTrace();
                        }

                        launcher.start();

                        /**
                         * Monitor the process if required
                         */
                        if (monitor) {
                            System.out.println("Monitoring " + appName + " process");
                            processMonitor = launcher.getApplicationType().getProcessMonitor();
                            if (processMonitor != null) {
                                MonitorOutputStream out = new MonitorOutputStream();
                                finishedLaunch();
                                int exitcode = processMonitor.watch(out, out);
                                System.out.println(appName + " exited with value " + exitcode);
                            } else {
                                System.out.println("No process monitor.");
                            }
                        }

                    } catch (Exception ex) {
                        // Show an error message .....
                        ex.printStackTrace();
                    } finally {
                        finishedLaunch();
                    }
                }
            };

            thread.start();
        } catch (Exception e) {
            e.printStackTrace();
            //addLaunchButton(); // Add the launch button in case the vpn client
            // is closed during the lifetime of this applet
        }

    }
    
    protected static void setIfNotEmpty(String name, Hashtable p) {
        String v = System.getProperty(name);
        if (v != null && !v.equals("")) {
            p.put(name, v);
        }
    }

    private void setMessage(String text) {
        mainPanel.invalidate();
        mainPanel.removeAll();
        mainPanel.add(new Label(text));
        mainPanel.validate();

    }

    public void addLaunchButton() {

        mainPanel.invalidate();
        mainPanel.removeAll();
        launch = new Button("Launch");
        launch.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                launch();
            }
        });
        mainPanel.add(launch);
        mainPanel.validate();
    }

    // Get Applet information
    public String getAppletInfo() {
        return "Applet Information";
    }

    // Get parameter info
    public String[][] getParameterInfo() {
        String[][] pinfo = { { "ticket", "String", "" }, };
        return pinfo;
    }

    public void startDownload(long totalNumBytes) {
        progress.setMessage("Downloading files");
        this.totalNumBytes = totalNumBytes;
        progress.setMessage("Downloading files");
        progress.updateValue(1L);
        progress.updateValue(20);
    }

    public void progressedDownload(long bytesSoFar) {
        int percent = (int) (((float) bytesSoFar / (float) totalNumBytes) * 70f) + 20;
        progress.updateValue(percent);
    }

    public void completedDownload() {
        progress.setMessage("Download complete");
        progress.updateValue(90);
    }

    public void executingApplication(String name, String cmdline) {
        progress.setMessage("Launching " + name);
        progress.updateValue(95);
    }

    public Tunnel createTunnel(String name, String hostToConnect, int portToConnect, boolean usePreferredPort,
                               boolean singleConnection) {
        // We should not be creating any tunnels
        return null;
    }

    public void closeTunnel(Tunnel tunnel) {

    }

    public void debug(String msg) {
        System.out.println(msg);
    }

    public void startingLaunch(String application) {
        progress = new ProgressBar(this, "Launching " + application, "SSL-Explorer", 100L, false);
        progress.updateValue(7L);
    }

    public void processingDescriptor() {
        progress.updateValue(14L);
        progress.setMessage("Processing application descriptor");
    }

    public void finishedLaunch() {
        if (progress.getCurrentValue() != 100) {
            progress.setMessage("Launched SSL-Explorer Agent");
            progress.updateValue(100);
            Thread t = new Thread() {
                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                    }
                    progress.dispose();
                }
            };

            t.start();
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.applet.Applet#destroy()
     */
    public void destroy() {
        System.out.println("Destroying launcher applet");
        super.destroy();
    }

    class SynchronizationThread extends Thread {

        ApplicationLauncher launcher;

        SynchronizationThread(ApplicationLauncher launcher) {
            this.launcher = launcher;
        }

        public void run() {
            
            try {
                
                String returnTo = getParameter("returnTo", "");
                
                if(!isAgent) {
                    /**
                     * This is not an agent so no synchronization is needed.
                     */
                    URL returnToUrl = returnTo.equals("") ? getDocumentBase() : new URL(getDocumentBase(), returnTo);
                    returnToUrl = new URL(addRedirectParameter(returnToUrl.toExternalForm(), "vpnMessage", appName + " launched."));
                    System.out.println("Redirecting to " + returnToUrl.toExternalForm());
                    getAppletContext().showDocument(returnToUrl);
                    setMessage("Complete.");
                    
                } else {
            
                    setMessage("Synchronizing");
                    
                    /**
                     * Connect to the server to synchronize with the VPN session.
                     * This will allow us to refresh the browser page once we get
                     * notification that the client has registered with the server
                     * or kill the process after the timeout has elasped.
                     */
                    URL url = new URL("https", VPNLauncher.this.getCodeBase().getHost().equals("") ? "localhost" : VPNLauncher.this
                                    .getCodeBase().getHost(), VPNLauncher.this.getCodeBase().getPort() == -1 ? 443 : VPNLauncher.this
                                    .getCodeBase().getPort(), "/registerClientSynchronization.do?ticket=" + ticket);
                    System.out.println("Sending sync. message to " + url);
    
                    URLConnection con = url.openConnection();
    
                    con.connect();
                    System.out.println("Connected to " + url + ", waiting for results");
    
                    XMLElement result = new XMLElement();
                    result.parseFromReader(new InputStreamReader(con.getInputStream()));
    
                    if (result.getName().equalsIgnoreCase("success")) {
                        System.out.println("Synchronized OK.");
                        
    
                        /*
                         * TODO A nasty hack - If the returnTo points back to the
                         * VPN Client, then make sure the port is correct (the
                         * server would not have known the port for the client at
                         * the point the returnTO link was created).
                         */
                        URL returnToUrl = returnTo.equals("") ? getDocumentBase() : new URL(getDocumentBase(), returnTo);
                        if (returnToUrl.getProtocol().equals("http") && returnToUrl.getHost().equals("localhost")
                                        && returnToUrl.getPort() == -1) {
                            returnToUrl = new URL(returnToUrl.getProtocol(), returnToUrl.getHost(), Integer.parseInt(result
                                            .getAttribute("clientPort").toString()), returnToUrl.getFile());
                        }
                        returnToUrl = new URL(addRedirectParameter(returnToUrl.toExternalForm(), "vpnMessage", appName + " launched."));
                        System.out.println("Redirecting to " + returnToUrl.toExternalForm());
                        getAppletContext().showDocument(returnToUrl);
                        setMessage("Complete.");
    
                    } else {
                        // Show an error message and kill the process
                        System.out.println("Failed to synchronize.");
                        System.out.println(result.getContent());
                        ProcessMonitor monitor = launcher.getApplicationType().getProcessMonitor();
                        if (monitor != null) {
                            // We cant kill the process as there may be error
                            // dialogs
                            // monitor.kill();
                            setMessage("Failed to sync.");
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                addLaunchButton(); // Add the launch button in case the vpn
                                    // client is closed during the lifetime of
                                    // this applet
            } finally {
                progress.dispose();
            }

        }
    }

    private String addRedirectParameter(String redirect, String name, String value) {
        StringBuffer buf = new StringBuffer(redirect);
        int idx = redirect.indexOf('?');
        if (idx == -1) {
            buf.append("?");
        } else {
            buf.append("&");
        }
        buf.append(name);
        buf.append('=');
        buf.append(URLEncoder.encode(value));
        return buf.toString();
    }

    class MonitorOutputStream extends OutputStream {
        public void write(int b) throws IOException {
            System.out.write(b);
        }

        public void write(byte[] buf, int off, int len) throws IOException {
            System.out.write(buf, off, len);
        }
    }

}

⌨️ 快捷键说明

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