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

📄 moduletelnetproxy.java

📁 一个非常好的ssh客户端实现
💻 JAVA
字号:
/****************************************************************************** * * Copyright (c) 1999-2003 AppGate Network Security AB. All Rights Reserved. *  * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. *  * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE.  If not, write to * AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN * *****************************************************************************/package com.mindbright.application;import java.awt.Dialog;import java.awt.TextField;import java.awt.Label;import java.awt.Button;import java.awt.Panel;import java.awt.GridBagConstraints;import java.awt.FlowLayout;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import com.mindbright.gui.AWTConvenience;import com.mindbright.gui.AWTGridBagContainer;import com.mindbright.ssh2.SSH2TelnetProxyListener;public class ModuleTelnetProxy implements MindTermModule, ActionListener {    private MindTermApp mindterm;    private Dialog      telnetDialog;    private TextField   proxyHost;    private TextField   proxyPort;    private Label       lblStatus;    private Button      startBut, closeBut;    private SSH2TelnetProxyListener telnetProxy;    public void init(MindTermApp mindterm) {	this.mindterm = mindterm;    }    public void activate(MindTermApp mindterm) {	if(telnetDialog == null) {	    Label  lbl;	    Panel  p;	    telnetDialog = new Dialog(mindterm.getParentFrame(),				      mindterm.getAppName() +				      " - Telnet Proxy", false);	    AWTGridBagContainer grid = new AWTGridBagContainer(telnetDialog);	    lbl = new Label("Listen address:");	    grid.add(lbl, 0, 1);	    lbl = new Label("Listen port:");	    grid.add(lbl, 0, 1);	    proxyHost = new TextField("127.0.0.1", 20);	    grid.add(proxyHost, 1, 1);	    proxyPort = new TextField("23", 5);	    grid.add(proxyPort, 1, 1);	    grid.getConstraints().anchor = GridBagConstraints.CENTER;	    lblStatus = new Label("Proxy disabled...", Label.CENTER);	    grid.add(lblStatus, 2, 2);	    p = new Panel(new FlowLayout());	    p.add(startBut = new Button("Enable"));	    startBut.addActionListener(this);	    p.add(closeBut = new Button("Close Dialog"));	    closeBut.addActionListener(				       new AWTConvenience.CloseAction(telnetDialog));	    grid.add(p, 3, GridBagConstraints.REMAINDER);	    telnetDialog.addWindowListener(new AWTConvenience.CloseAdapter(closeBut));	    AWTConvenience.setBackgroundOfChildren(telnetDialog);	    AWTConvenience.setKeyListenerOfChildren(telnetDialog,						    new AWTConvenience.OKCancelAdapter(startBut, closeBut),						    null);	    telnetDialog.setResizable(true);	    telnetDialog.pack();	}	String host = mindterm.getProperty("module.telnetproxy.host");	String port = mindterm.getProperty("module.telnetproxy.port");	if(host != null && !host.equals("")) {	    proxyHost.setText(host);	}	if(port != null && !port.equals("")) {	    proxyPort.setText(port);	}	updateTelnetDialog(false);	AWTConvenience.placeDialog(telnetDialog);	telnetDialog.setVisible(true);    }    public boolean isAvailable(MindTermApp mindterm) {	return (mindterm.isConnected() && (mindterm.getConnection() != null));    }    public void connected(MindTermApp mindterm) {	String proxyHost  = mindterm.getProperty("module.telnetproxy.host");	String proxyPortS = mindterm.getProperty("module.telnetproxy.port");	if(proxyHost != null && proxyHost.trim().length() > 0) {	    try {		int proxyPort = Integer.parseInt(proxyPortS);		telnetProxy =		    new SSH2TelnetProxyListener(proxyHost, proxyPort,						mindterm.getConnection());		mindterm.alert("Starting telnet proxy on " +			       proxyHost + ":" + proxyPort);	    } catch (Exception e) {		mindterm.alert("Error starting telnet proxy on " +			       proxyHost + ":" + proxyPortS + " - " +			       e.getMessage());	    }	}    }    public void disconnected(MindTermApp mindterm) {	if(telnetProxy != null) {	    telnetProxy.stop();	    telnetProxy = null;	}    }    public String description(MindTermApp mindterm) {	return null;    }    private void updateTelnetDialog(boolean preserveMsg) {	if(telnetProxy == null) {	    if(!preserveMsg)		lblStatus.setText("Proxy disabled...");	    proxyPort.setEnabled(true);	    proxyHost.setEnabled(true);	    startBut.setLabel("Enable");	} else {	    if(!preserveMsg)		lblStatus.setText("Proxy running: " +				  proxyHost.getText() + ":" +				  proxyPort.getText());	    proxyPort.setEnabled(false);	    proxyHost.setEnabled(false);	    startBut.setLabel("Disable");	}    }    public void actionPerformed(ActionEvent e) {	if(telnetProxy != null) {	    startBut.setLabel("Enable");	    disconnected(mindterm);	    updateTelnetDialog(false);	    mindterm.setProperty("module.telnetproxy.host", "");	    mindterm.setProperty("module.telnetproxy.port", "");	} else {	    boolean err = false;	    lblStatus.setText("");	    try {		String host = proxyHost.getText();		String port = proxyPort.getText();		mindterm.setProperty("module.telnetproxy.host", host);		mindterm.setProperty("module.telnetproxy.port", port);		connected(mindterm);	    } catch (Exception ex) {		err = true;		disconnected(mindterm);		lblStatus.setText("Error: " + ex.getMessage());	    }	    updateTelnetDialog(err);	}    }}

⌨️ 快捷键说明

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