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

📄 portmonitor.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 java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Enumeration;
import java.util.Vector;

import com.sshtools.ui.awt.grid.Grid;
import com.sshtools.ui.awt.options.Option;
import com.sshtools.ui.awt.options.OptionDialog;
import com.sslexplorer.vpn.base.AbstractVPNClient;
import com.sslexplorer.vpn.base.DefaultTunnel;
import com.sslexplorer.vpn.base.VPNConnectionListener;
import com.sslexplorer.vpn.util.Tunnel;


public class PortMonitor extends Frame {
    
    private Grid portGrid;
    private PortModel model;
    private Button stopButton;
    private Button closeButton;
    private AbstractVPNClient vpnClient;

    public PortMonitor(AbstractVPNClient vpnClient) {
        super("Tunnel Monitor");
        
        this.vpnClient = vpnClient;

        model = new PortModel();
        portGrid = new Grid(model);
        portGrid.setBackground(Color.white);
        portGrid.setForeground(Color.black);
        portGrid.setSelectionBackground(Color.blue.darker());
        portGrid.setSelectionForeground(Color.white);
        portGrid.setColumnWidths(new int[] {  46, 220, 64, 64, 64 } );
        portGrid.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                setAvailableActions();
            }            
        });
        
        closeButton = new Button("Close");
        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                setVisible(false);
            }            
        });
        
        stopButton = new Button("Stop");
        stopButton.addActionListener(new ActionListener() {
            Option stop = new Option("Stop");
           public void actionPerformed(ActionEvent evt) {
               Option opt = OptionDialog.prompt(PortMonitor.this, OptionDialog.WARNING, "Close tunnels",
                   "Are you sure you wish to stop the selected tunnels?\n" +
                   "Any applications that are using them may cease working\n" +
                   "correctly and you may lose work.", new Option[] { stop, OptionDialog.CHOICE_CANCEL } );
               if(opt == stop) {
                   for(Enumeration e = getSelectedPorts().elements(); e.hasMoreElements(); ) {
                       PortItem t = (PortItem)e.nextElement();
                       PortMonitor.this.vpnClient.stopListeningSocket(t.getTunnel().getTicket());
                   }
               }
           }
        });
        
        Panel p = new Panel(new BorderLayout());
        p.add(portGrid, BorderLayout.CENTER);
        
        Panel f = new Panel(new FlowLayout(FlowLayout.RIGHT));
        f.add(stopButton);
        f.add(closeButton);
        
        setLayout(new BorderLayout());
        add(p, BorderLayout.CENTER);
        add(f, BorderLayout.SOUTH);
        pack();
        setAvailableActions();
    }
    
    protected void setAvailableActions() {
        stopButton.setEnabled(portGrid.getSelectedRowCount() != 0);
    }
    
    public Vector getSelectedPorts() {
        int[] r = portGrid.getSelectedRows();
        Vector v = new Vector();
        for(int i = 0 ; i < r.length; i++) {
            v.addElement(model.getItemAt(r[i]));
        }
        return v;
    }
    
    public PortModel getModel() {
        return model;
    }
    
    public static void main(String[] args) throws Exception {
        PortMonitor m = new PortMonitor(null);
        m.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                System.exit(0);
            }            
        });
        m.setVisible(true);
        
        // Test
        Tunnel t = new DefaultTunnel(12321, Tunnel.LOCAL_TUNNEL, true, Tunnel.TCP_TUNNEL,
            System.getProperty("user.name"), 60022, 22, "localhost", true, true, false, "Test tunnel 1", false);
        VPNConnectionListener l = new VPNConnectionListener(null, null, null, t);
        m.getModel().addPortItem(new PortItem(t, l));

        Tunnel t2 = new DefaultTunnel(12321, Tunnel.LOCAL_TUNNEL, true, Tunnel.TCP_TUNNEL,
            System.getProperty("user.name"), 8900, 80, "kenny.southpark.net", false, true, false, "Test tunnel 2", false);
        VPNConnectionListener l2 = new VPNConnectionListener(null, null, null, t);
        m.getModel().addPortItem(new PortItem(t2, l2));
        
    }

}

⌨️ 快捷键说明

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