📄 mindterm.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.io.*;import java.applet.Applet;import java.applet.AppletContext;import java.awt.*;import java.awt.event.*;import java.util.Properties;import java.util.Hashtable;import java.util.Enumeration;import com.mindbright.ssh.*;import com.mindbright.sshcommon.*;import com.mindbright.terminal.*;public class MindTerm extends Applet implements Runnable, WindowListener { static Properties paramTermProps = new Properties(); static Properties paramSSHProps = new Properties(); public static String javaVersion = "<unknown>"; public static String javaVendor = "<unknown>"; public static String osName = "<unknown>"; public static String osArch = "<unknown>"; public static String osVersion = "<unknown>"; Frame frame; TerminalWin term; SSHInteractiveClient client; SSHInteractiveClient sshClone; SSHStdIO console; Thread clientThread; boolean mergedTermProps; Properties sshProps; Properties termProps; String[] cmdLineArgs; String commandLine = null; String sshHomeDir = null; String propsFile = null; boolean usePopMenu = false; boolean haveMenus = true; boolean haveGUI = true; boolean exitOnLogout = false; boolean quiet = true; boolean doSCP = false; boolean recursiveSCP = false; boolean toRemote = true; int firstArg = 0; boolean autoSaveProps = true; boolean autoLoadProps = true; boolean savePasswords = false; int popButtonNum = 3; boolean isClosing = false; // !!! boolean separateFrame = true; public boolean weAreAnApplet = false; static Hashtable terminals = new Hashtable(); static synchronized boolean isLastTerminal() { return terminals.isEmpty(); } static synchronized void addTerminal(MindTerm mindterm) { terminals.put(mindterm, mindterm); } static synchronized void removeTerminal(MindTerm mindterm) { terminals.remove(mindterm); } public MindTerm() { super(); this.sshProps = paramSSHProps; this.termProps = paramTermProps; addTerminal(this); } public MindTerm(Properties sshProps, Properties termProps) { this.sshProps = sshProps; this.termProps = termProps; addTerminal(this); } public static void main(String[] argv) { MindTerm controller = new MindTerm(paramSSHProps, paramTermProps); controller.cmdLineArgs = argv; try { controller.getApplicationParams(); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); System.exit(1); } try { controller.run(); } catch (Exception e) { System.out.println("Error, please email the stack trace below to mt-support@appgate.com"); e.printStackTrace(); } } public void init() { if (com.mindbright.util.Util.isNetscapeJava()) { try { netscape.security.PrivilegeManager.enablePrivilege("TerminalEmulator"); } catch (netscape.security.ForbiddenTargetException e) { } } weAreAnApplet = true; autoSaveProps = false; autoLoadProps = false; savePasswords = false; getAppletParams(); (new Thread(this, "MindTerm.init")).start(); }// private final static void listThreads() {// Thread t = Thread.currentThread();// ThreadGroup tmp, tg = t.getThreadGroup();// while ((tmp=tg.getParent()) != null)// tg = tmp;// Thread ts[] = new Thread[tg.activeCount()];// tg.enumerate(ts, true);// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");// for (int i=0; i<ts.length; i++) {// if (ts[i] != null)// System.out.println(i+"="+ts[i]);// }// } public void run() {// Thread tl = new Thread(new Runnable() {// public void run() {// for(;;) {// try {// Thread.sleep(5000);// } catch (Throwable t) {// }// listThreads();// }// }}, "listThreads");// tl.setDaemon(true);// tl.start(); try { if(sshClone != null) { if(!sshClone.isSSH2) { client = new SSHInteractiveClient(sshClone); sshClone = null; } else { client = null; sshClone.newShell(); removeTerminal(this); return; } } else { // Default when running single command is not to allocate a PTY // if(commandLine != null && sshProps.getProperty("force-pty") == null) { sshProps.put("force-pty", "false"); } SSHPropertyHandler propsHandler = new SSHPropertyHandler(sshProps, true); if(propsFile != null) { // !!! REMOVE (todo: fix password!) try { propsHandler = SSHPropertyHandler.fromFile(propsFile, ""); } catch (SSHClient.AuthFailException e) { throw new Exception("Sorry, can only use passwordless settings files for now"); } propsHandler.mergeProperties(sshProps); } client = new SSHInteractiveClient(quiet, exitOnLogout, propsHandler); } if(weAreAnApplet && client.getPropertyHandler().getDefaultProperty("server") == null) { client.getPropertyHandler().setDefaultProperty("server", getCodeBase().getHost()); } if(client.getPropertyHandler().getDefaultProperty("username") == null) { try { client.getPropertyHandler().setDefaultProperty("username", System.getProperty("user.name", "")); } catch (Throwable t) { // !!! } } console = (SSHStdIO)client.getConsole(); // If we loaded a specific property-file we merge the termProps from there // if(client.getPropertyHandler().getInitTerminalProperties() != null) { Properties newTermProps = new Properties(client.getPropertyHandler().getInitTerminalProperties()); if(termProps != null && !termProps.isEmpty()) { Enumeration enum = termProps.keys(); while(enum.hasMoreElements()) { String name = (String)enum.nextElement(); newTermProps.put(name, termProps.getProperty(name)); } mergedTermProps = true; } termProps = newTermProps; } // First we initialize the GUI if we have one (to be able to set // properties to terminal // if(haveGUI) { initGUI(); console.setTerminal(term); console.setOwnerContainer(frame); console.setOwnerName(SSH.VER_MINDTERM); console.updateTitle(); try { while(!frame.isShowing()) Thread.sleep(50); } catch(InterruptedException e) { // !!! } // !!! When we are in the Panel of the Applet we don't get a // componentShown event so we have to "emulate" it since we // depend on it to be correctly drawn // if(!separateFrame) { term.emulateComponentShown(); } } if(!client.getPropertyHandler().setSSHHomeDir(sshHomeDir)) { throw new Exception("License not accepted, exiting"); } client.getPropertyHandler().setAutoSaveProps(autoLoadProps); client.getPropertyHandler().setAutoLoadProps(autoSaveProps); client.getPropertyHandler().setSavePasswords(savePasswords); client.updateMenus(); if(commandLine != null) { if(!doSCP) { client.doSingleCommand(commandLine); } else { if((cmdLineArgs.length - firstArg) < 2) throw new Exception("scp must have at least two arguments (<source> <destination>)"); String[] fileList = new String[cmdLineArgs.length - firstArg - 1]; String target, source = commandLine.substring(0, commandLine.lastIndexOf(' ')); for(int i = firstArg; i < cmdLineArgs.length - 1; i++) { fileList[i - firstArg] = cmdLineArgs[i]; } target = cmdLineArgs[cmdLineArgs.length - 1]; String srvHost = client.getPropertyHandler().getSrvHost(); int srvPort = client.getPropertyHandler().getSrvPort(); SSHSCPClient scp = new SSHSCPClient(srvHost, srvPort, client.getPropertyHandler(), (SSH.DEBUG ? client : null), new File("."), SSH.DEBUG); if(SSH.DEBUG) { scp.scp1().setProgress(new SSHSCPStdoutProgress()); } if(toRemote) { scp.scp1().copyToRemote(fileList, target, recursiveSCP); } else { scp.scp1().copyToLocal(target, source, recursiveSCP); } } } else { try { clientThread = new Thread(client, "MindTerm"); clientThread.start(); clientThread.join(); } catch(InterruptedException e) { // !!! } } } catch (IllegalArgumentException ae) { if(client != null) client.alert(ae.getMessage()); System.out.println(ae.getMessage()); } catch (FileNotFoundException fe) { System.out.println("Settings-file not found: " + fe.getMessage()); } catch (Exception e) { if(client != null) client.alert("Error: " + e.getMessage()); System.out.println("Error: " + e.getMessage()); if(SSH.DEBUGMORE) { System.out.println("Please send the below stack-trace to mt-support@appgate.com"); e.printStackTrace(); } } windowClosing(null); if(isLastTerminal()) doExit(); } public void getAppletParams() { String name; String value; String param; int i; try { separateFrame = (new Boolean(getParameter("sepframe"))).booleanValue(); } catch (Exception e) { separateFrame = true; } try { SSH.DEBUG = (new Boolean(getParameter("verbose"))).booleanValue(); } catch (Exception e) { SSH.DEBUG = false; } try { SSH.DEBUGMORE = (new Boolean(getParameter("debug"))).booleanValue(); SSH.DEBUG = SSH.DEBUGMORE; } catch (Exception e) { } try { quiet = (new Boolean(getParameter("quiet"))).booleanValue(); } catch (Exception e) { quiet = true; } try { exitOnLogout = (new Boolean(getParameter("exit-on-logout"))).booleanValue(); } catch (Exception e) { exitOnLogout = false; } try { savePasswords = (new Boolean(getParameter("savepasswords"))).booleanValue(); } catch (Exception e) { savePasswords = false; } param = getParameter("menus"); if(param != null) { if(param.equals("no")) haveMenus = false; else if(param.startsWith("pop")) { getPopupButtonNumber(param); usePopMenu = true; } } param = getParameter("autoprops"); if(param != null) { if(param.equals("save")) { autoSaveProps = true; autoLoadProps = false; } else if(param.equals("load")) { autoSaveProps = false; autoLoadProps = true; } else if(param.equals("both")) { autoSaveProps = true; autoLoadProps = true; } } sshHomeDir = getParameter("sshhome"); propsFile = getParameter("propsfile"); commandLine = getParameter("commandline"); getDefaultParams(); for(i = 0; i < SSHPropertyHandler.defaultPropDesc.length; i++) { name = SSHPropertyHandler.defaultPropDesc[i][SSHPropertyHandler.PROP_NAME]; value = getParameter(name); if(value != null) paramSSHProps.put(name, value); } i = 0; while((value = getParameter("local" + i)) != null) { paramSSHProps.put("local" + i, value); i++; } i = 0; while((value = getParameter("remote" + i)) != null) { paramSSHProps.put("remote" + i, value); i++; } for(i = 0; i < TerminalDefProps.defaultPropDesc.length; i++) { name = TerminalDefProps.defaultPropDesc[i][TerminalDefProps.PROP_NAME]; value = getParameter(name); if(value != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -