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

📄 tcpinterceptor.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Axis" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
package org.apache.axis.utils;


import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.*;
import javax.swing.plaf.basic.BasicButtonListener;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * @author Doug Davis (dug@us.ibm.com)
 * @author Chris Betts (chris.betts@ca.com) - added interceptor capability to TCPMon program; also cleaned some stuff up.
 */

public class TCPInterceptor extends JFrame
{
    private JTabbedPane notebook = null;

    private static int STATE_COLUMN = 0;
    private static int TIME_COLUMN = 1;
    private static int INHOST_COLUMN = 2;
    private static int OUTHOST_COLUMN = 3;
    private static int REQ_COLUMN = 4;

    class AdminPage extends JPanel
    {
        public JRadioButton listenerButton, proxyButton;
        public JLabel hostLabel, tportLabel;
        public JTextField port, host, tport;
        public JTabbedPane noteb;
        public JCheckBox HTTPProxyBox;
        public JTextField HTTPProxyHost, HTTPProxyPort;
        public JLabel HTTPProxyHostLabel, HTTPProxyPortLabel;

        public AdminPage(JTabbedPane notebook, String name)
        {
            JPanel mainPane = null;
            JButton addButton = null;

            this.setLayout(new BorderLayout());
            noteb = notebook;

            GridBagLayout layout = new GridBagLayout();
            GridBagConstraints c = new GridBagConstraints();

            mainPane = new JPanel(layout);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(new JLabel(getMessage("newTCP00", "Create a new TCP/IP Monitor...") + " "), c);

            // Add some blank space
            mainPane.add(Box.createRigidArea(new Dimension(1, 5)), c);

            // The listener info
            ///////////////////////////////////////////////////////////////////
            JPanel tmpPanel = new JPanel(new GridBagLayout());

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = 1;
            tmpPanel.add(new JLabel(getMessage("listenPort00", "Listen Port #") + " "), c);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            tmpPanel.add(port = new JTextField(4), c);

            mainPane.add(tmpPanel, c);

            mainPane.add(Box.createRigidArea(new Dimension(1, 5)), c);

            // Group for the radio buttons
            ButtonGroup btns = new ButtonGroup();

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(new JLabel(getMessage("actAs00", "Act as a...")), c);

            // Target Host/Port section
            ///////////////////////////////////////////////////////////////////
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;

            final String listener = getMessage("listener00", "Listener");

            mainPane.add(listenerButton = new JRadioButton(listener), c);
            btns.add(listenerButton);
            listenerButton.setSelected(true);

            listenerButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    if (listener.equals(event.getActionCommand()))
                    {
                        boolean state = listenerButton.isSelected();

                        tport.setEnabled(state);
                        host.setEnabled(state);
                        hostLabel.setForeground(state ? Color.black : Color.gray);
                        tportLabel.setForeground(state ? Color.black : Color.gray);
                    }
                }
            }
            );

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = 1;
            mainPane.add(Box.createRigidArea(new Dimension(25, 0)));
            mainPane.add(hostLabel = new JLabel(getMessage("targetHostname00", "Target Hostname") + " "), c);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(host = new JTextField(30), c);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = 1;
            mainPane.add(Box.createRigidArea(new Dimension(25, 0)));
            mainPane.add(tportLabel = new JLabel(getMessage("targetPort00", "Target Port #") + " "), c);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(tport = new JTextField(4), c);

            // Act as proxy section
            ///////////////////////////////////////////////////////////////////
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            final String proxy = getMessage("proxy00", "Proxy");

            mainPane.add(proxyButton = new JRadioButton(proxy), c);
            btns.add(proxyButton);

            proxyButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    if (proxy.equals(event.getActionCommand()))
                    {
                        boolean state = proxyButton.isSelected();

                        tport.setEnabled(!state);
                        host.setEnabled(!state);
                        hostLabel.setForeground(state ? Color.gray : Color.black);
                        tportLabel.setForeground(state ? Color.gray : Color.black);
                    }
                }
            }
            );

            // Spacer
            /////////////////////////////////////////////////////////////////
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(Box.createRigidArea(new Dimension(1, 10)), c);

            // Options section
            ///////////////////////////////////////////////////////////////////
            JPanel opts = new JPanel(new GridBagLayout());

            opts.setBorder(new TitledBorder(getMessage("options00", "Options")));
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            mainPane.add(opts, c);

            // HTTP Proxy Support section
            ///////////////////////////////////////////////////////////////////
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            final String proxySupport = getMessage("proxySupport00", "HTTP Proxy Support");

            opts.add(HTTPProxyBox = new JCheckBox(proxySupport), c);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = 1;
            opts.add(HTTPProxyHostLabel = new JLabel(getMessage("hostname00", "Hostname") + " "), c);
            HTTPProxyHostLabel.setForeground(Color.gray);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            opts.add(HTTPProxyHost = new JTextField(30), c);
            HTTPProxyHost.setEnabled(false);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = 1;
            opts.add(HTTPProxyPortLabel = new JLabel(getMessage("port00", "Port #") + " "), c);
            HTTPProxyPortLabel.setForeground(Color.gray);

            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            opts.add(HTTPProxyPort = new JTextField(4), c);
            HTTPProxyPort.setEnabled(false);

            HTTPProxyBox.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    if (proxySupport.equals(event.getActionCommand()))
                    {
                        boolean b = HTTPProxyBox.isSelected();
                        Color color = b ? Color.black : Color.gray;

                        HTTPProxyHost.setEnabled(b);
                        HTTPProxyPort.setEnabled(b);
                        HTTPProxyHostLabel.setForeground(color);
                        HTTPProxyPortLabel.setForeground(color);
                    }
                }
                ;
            }
            );

            // Set default proxy values...
            String tmp = System.getProperty("http.proxyHost");

            if (tmp != null && tmp.equals(""))
                tmp = null;

            HTTPProxyBox.setSelected(tmp != null);
            HTTPProxyHost.setEnabled(tmp != null);
            HTTPProxyPort.setEnabled(tmp != null);
            HTTPProxyHostLabel.setForeground(tmp != null ? Color.black : Color.gray);
            HTTPProxyPortLabel.setForeground(tmp != null ? Color.black : Color.gray);

            if (tmp != null)
            {
                HTTPProxyBox.setSelected(true);
                HTTPProxyHost.setText(tmp);
                tmp = System.getProperty("http.proxyPort");
                if (tmp != null && tmp.equals("")) tmp = null;
                if (tmp == null) tmp = "80";
                HTTPProxyPort.setText(tmp);
            }

            // Spacer
            //////////////////////////////////////////////////////////////////
            mainPane.add(Box.createRigidArea(new Dimension(1, 10)), c);

            // ADD Button
            ///////////////////////////////////////////////////////////////////
            c.anchor = GridBagConstraints.WEST;
            c.gridwidth = GridBagConstraints.REMAINDER;
            final String add = getMessage("add00", "Add");

            mainPane.add(addButton = new JButton(add), c);


            this.add(new JScrollPane(mainPane), BorderLayout.CENTER);

            // addButton.setEnabled( false );
            addButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    if (add.equals(event.getActionCommand()))
                    {
                        String text;
                        Listener l = null;
                        int lPort = Integer.parseInt(port.getText());
                        String tHost = host.getText();
                        int tPort = 0;

                        text = tport.getText();
                        if (text != null && !text.equals(""))
                            tPort = Integer.parseInt(text);
                        l = new Listener(noteb, null, lPort, tHost, tPort,
                                proxyButton.isSelected());

                        // Pick-up the HTTP Proxy settings
                        ///////////////////////////////////////////////////
                        text = HTTPProxyHost.getText();
                        if ("".equals(text)) text = null;
                        l.HTTPProxyHost = text;
                        text = HTTPProxyPort.getText();
                        if ("".equals(text)) text = null;
                        if (text != null)
                            l.HTTPProxyPort = Integer.parseInt(text);

                        port.setText(null);
                        host.setText(null);
                        tport.setText(null);
                    }
                }
                ;
            }
            );

⌨️ 快捷键说明

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