📄 sshmenuhandlerfull.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.ssh;import java.awt.*;import java.awt.event.*;import com.mindbright.application.MindTerm;import com.mindbright.application.MindTermModule;import com.mindbright.terminal.TerminalWin;import com.mindbright.terminal.TerminalMenuListener;import com.mindbright.terminal.TerminalMenuHandlerFull;import com.mindbright.gui.AWTConvenience;import com.mindbright.gui.AWTGridBagContainer;import com.mindbright.ssh2.SSH2Preferences;import com.mindbright.ssh2.SSH2ListUtil;public final class SSHMenuHandlerFull extends SSHMenuHandler implements ActionListener, ItemListener, TerminalMenuListener { protected final static int ACT_CLICK_LIST = 0; protected final static int ACT_SETTINGS2 = 1; protected final static int ACT_PROXY = 2; protected final static int ACT_PREFS = 3; protected final static int ACT_CONNECT = 4; protected final static int ACT_IDFILE = 5; protected final static int ACT_CLOSE_TUNNEL = 6; protected final static int ACT_REFRESH = 7; protected final static int ACT_LOCALADD = 8; protected final static int ACT_LOCALDEL = 9; protected final static int ACT_REMOTEADD = 10; protected final static int ACT_REMOTEDEL = 11; protected final static int ACT_CONNECT2 = 12; protected final static int ACT_NEWSERVER = 13; protected final static int ACT_UPDATE2 = 14; protected final static int ACT_CIPHER = 15; protected final static int ACT_MAC = 16; protected final static int ACT_COMP = 17; protected final static int ACT_UPDATE = 18; protected final static int ACT_MOD_BASE = 32; private class Actions implements ActionListener, ItemListener { private int action; private TextField text; private List list; public Actions(int action, TextField text, List list) { this(action); this.text = text; this.list = list; } public Actions(int action) { this.action = action; } public void actionPerformed(ActionEvent e) { switch(action) { case ACT_CLICK_LIST: text.setText(list.getSelectedItem()); text.requestFocus(); break; case ACT_SETTINGS2: try { String cipherC2S = choiceCipherC2S.getSelectedItem(); String cipherS2C = choiceCipherS2C.getSelectedItem();// String macC2S = choiceMacC2S.getSelectedItem();// String macS2C = choiceMacS2C.getSelectedItem();// boolean comp =// ((choiceCompC2S.getSelectedIndex() > 0) ||// (choiceCompS2C.getSelectedIndex() > 0)); boolean doReKey = (client.isConnected() && client.isSSH2 && !client.transport.incompatibleCantReKey); if(doReKey) { checkSupportedByPeer(); } client.propsHandler.setProperty("protocol", choiceProto.getSelectedItem()); if(choiceHKey.getSelectedIndex() > 0) { client.propsHandler.setProperty("server-host-key-algorithms", choiceHKey.getSelectedItem()); } else { client.propsHandler.resetProperty("server-host-key-algorithms"); } if(choiceCipherC2S.getSelectedIndex() > 0) { client.propsHandler.setProperty("enc-algorithms-cli2srv", cipherC2S); client.propsHandler.setProperty("cipher", cipherC2S); } else { client.propsHandler.resetProperty("enc-algorithms-cli2srv"); client.propsHandler.resetProperty("cipher"); } if(choiceCipherS2C.getSelectedIndex() > 0) { client.propsHandler.setProperty("enc-algorithms-srv2cli", cipherS2C); } else { client.propsHandler.resetProperty("enc-algorithms-srv2cli"); } if(choiceMacC2S.getSelectedIndex() > 0) { client.propsHandler.setProperty("mac-algorithms-cli2srv", choiceMacC2S.getSelectedItem()); } else { client.propsHandler.resetProperty("mac-algorithms-cli2srv"); } if(choiceMacS2C.getSelectedIndex() > 0) { client.propsHandler.setProperty("mac-algorithms-srv2cli", choiceMacS2C.getSelectedItem()); } else { client.propsHandler.resetProperty("mac-algorithms-srv2cli"); } int compLevel = comp2lvl[choiceCompC2S.getSelectedIndex()]; if(compLevel > 0) { client.propsHandler.setProperty("comp-algorithms-cli2srv", "zlib"); } else { client.propsHandler.setProperty("comp-algorithms-cli2srv", "none"); } client.propsHandler.setProperty("compression", String.valueOf(compLevel)); compLevel = choiceCompS2C.getSelectedIndex(); if(compLevel > 0) { client.propsHandler.setProperty("comp-algorithms-srv2cli", "zlib"); } else { client.propsHandler.setProperty("comp-algorithms-srv2cli", "none"); } client.propsHandler.setProperty("display", textDisp.getText()); client.propsHandler.setProperty("x11fwd", String.valueOf(cbX11.getState())); client.propsHandler.setProperty("stricthostid", String.valueOf(cbIdHost.getState())); client.propsHandler.setProperty("key-timing-noise", String.valueOf(cbKeyNoise.getState())); client.propsHandler.setProperty("forcpty", String.valueOf(cbForcPty.getState())); client.propsHandler.setProperty("localhst", String.valueOf(textLocHost.getText())); client.propsHandler.setProperty("alive", textAlive.getText()); if(doReKey) { SSH2Preferences prefs; prefs = new SSH2Preferences(client.propsHandler.getProperties()); client.transport.startKeyExchange(prefs); } settingsDialog2.setVisible(false); } catch (Exception ee) { alertDialog("Error: " + ee.getMessage()); } break; case ACT_PROXY: SSHProxyDialog.show("MindTerm - Proxy Settings", parent, client.propsHandler); break; case ACT_PREFS: sshSettingsDialog2(); break; case ACT_CONNECT: try { String host = null; host = textSrv.getText(); if(host.length() == 0) { alertDialog("Please specify a server to connect to"); return; } if(cbSaveAlias.getState()) { String alias = textAlias.getText(); if(alias == null || alias.trim().length() == 0) { alertDialog("Please specify an alias name for these settings"); return; } if(client.propsHandler.savePasswords) { String pwd = setPasswordDialog("Please set password for alias " + host, "MindTerm - Set File Password"); if(pwd == null) return; client.propsHandler.setPropertyPassword(pwd); } client.propsHandler.setAlias(alias); } client.quiet = true; client.propsHandler.setProperty("server", host); String prxPasswd = client.propsHandler.getProperty("prxpassword"); client.propsHandler.clearPasswords(); if(prxPasswd != null) client.propsHandler.setProperty("prxpassword", prxPasswd); client.propsHandler.clearAllForwards(); String authType = choiceAuthTyp.getSelectedItem(); if(authType.equals("custom list...")) { client.propsHandler.setProperty("authtyp", textAuthList.getText()); } else { client.propsHandler.setProperty("authtyp", authType); } client.propsHandler.setProperty("port", textPort.getText()); client.propsHandler.setProperty("usrname", textUser.getText()); String pwd = textPwd.getText(); if(pwd.length() == 0) { pwd = null; } client.propsHandler.setProperty("password", pwd); client.propsHandler.setProperty("idfile", textId.getText()); client.sshStdIO.breakPromptLine(); settingsDialog.setVisible(false); } catch (Exception ee) { alertDialog("Error: " + ee.getMessage()); } break; case ACT_IDFILE: if(idFileFD == null) { idFileFD = new FileDialog(parent, "MindTerm - Select file with identity (private)", FileDialog.LOAD); idFileFD.setDirectory(client.propsHandler.getSSHHomeDir()); } idFileFD.setVisible(true); if(idFileFD.getFile() != null && idFileFD.getFile().length() > 0) textId.setText(idFileFD.getDirectory() + idFileFD.getFile()); break; case ACT_CLOSE_TUNNEL: { int i = currList.getSelectedIndex(); if(i == -1) { term.doBell(); return; } // !!! Ouch !!! client.closeTunnelFromList(i); Thread.yield(); refreshCurrList(); break; } case ACT_REFRESH: refreshCurrList(); break; case ACT_LOCALADD: try { client.propsHandler.setProperty("local" + client.localForwards.size(), localEdit.getText()); updateAdvancedTunnelLists(); } catch (Exception e1) { localEdit.selectText(); } break; case ACT_LOCALDEL: { int i = localEdit.getSelectedIndex(); if(i != -1) { client.propsHandler.removeLocalTunnelAt(i, true); updateAdvancedTunnelLists(); } break; } case ACT_REMOTEADD: try { client.propsHandler.setProperty("remote" + client.remoteForwards.size(), remoteEdit.getText()); updateAdvancedTunnelLists(); } catch (Exception e2) { remoteEdit.selectText(); } break; case ACT_REMOTEDEL: { int i = remoteEdit.getSelectedIndex(); if(remoteEdit.getItem(i).indexOf(SSHFtpTunnel.TUNNEL_NAME) != -1) { return; } if(i != -1) { client.propsHandler.removeRemoteTunnelAt(i); updateAdvancedTunnelLists(); } break; } case ACT_CONNECT2: { String host = hostList.getSelectedItem(); try { String pwd = ""; do { try { client.propsHandler.setPropertyPassword(pwd); client.propsHandler.loadAliasFile(host, false); client.quiet = true; client.sshStdIO.breakPromptLine(); connectDialog.setVisible(false); break; } catch(SSHClient.AuthFailException ee) { } } while((pwd = passwordDialog("Please give file password for " + host, "MindTerm - File Password")) != null); } catch (Throwable t) { alertDialog("Error loading settings: " + t.getMessage()); } break; } case ACT_NEWSERVER: connectDialog.setVisible(false); try { client.propsHandler.checkSave(); } catch (Throwable t) { alertDialog("Error saving settings: " + t.getMessage()); } client.propsHandler.clearServerSetting(); wantToRunSettingsDialog = true; connectDialog.setVisible(false); break; default: if(action >= ACT_MOD_BASE) { modules[action - ACT_MOD_BASE].activate(client); } } } public void itemStateChanged(ItemEvent e) { switch(action) { case ACT_UPDATE2: updateChoices2(); break; case ACT_CIPHER: choiceCipherS2C.select((String)e.getItem()); break; case ACT_MAC: choiceMacS2C.select((String)e.getItem()); break; case ACT_COMP: if("none".equals(e.getItem())) { choiceCompS2C.select("none"); } else { choiceCompS2C.select("medium"); } break; case ACT_UPDATE: updateChoices(); break; } } } protected class TunnelEditor extends Panel { List list; TextField text; public TunnelEditor(String head, ActionListener alAdd, ActionListener alDel) { super(new BorderLayout(5, 5)); Panel pi; Button b; add(new Label(head), BorderLayout.NORTH); add(list = new List(5, false), BorderLayout.CENTER); pi = new Panel(new FlowLayout()); pi.add(text = new TextField("", 26)); pi.add(b = new Button("Add")); b.addActionListener(alAdd); pi.add(b = new Button("Delete")); b.addActionListener(alDel); add(pi, BorderLayout.SOUTH); list.addActionListener(new Actions(ACT_CLICK_LIST, text, list)); } public int getItemCount() { return list.getItemCount(); } public String getItem(int i) { return list.getItem(i); } public void addToList(String item) { list.add(item); } public int getSelectedIndex() { return list.getSelectedIndex(); } public void selectText() { text.selectAll(); } public String getText() { return text.getText(); } public void removeAll() { list.removeAll(); } } SSHInteractiveClient client; Frame parent; TerminalWin term; MindTerm mindterm; MenuItem[] modMenuItems; MindTermModule[] modules; int modCnt;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -