📄 mindtermlite.java
字号:
proxyClass = "com.mindbright.net.SocksProxySocket"; method = "getSocks5Proxy"; } else { throw new IOException("Unknown proxy type " + prxType); } Class c = cl.loadClass(proxyClass); Class paramTypes[] = { String.class, int.class, String.class, int.class, Class.forName("com.mindbright.net.ProxyAuthenticator"), String.class, }; Method getProxy = c.getMethod(method, paramTypes); int prxPort = Integer.parseInt(getProperty("proxy-port")); Object params[] = {host, new Integer(port), getProperty("proxy-host"), new Integer(prxPort), this, getAppName()}; socket = (Socket)getProxy.invoke(null, params); } catch (InvocationTargetException e) { throw new IOException("Error in proxy connect: " + e.getTargetException()); } catch (Exception e) { throw new IOException("Error in proxy connect: " + e); } } else { socket = new Socket(host, port); } SSH2Transport transport = new SSH2Transport(socket, new SSH2Preferences(settings), secureRandom); transport.setEventHandler(new SSH2TransportEventAdapter() { public boolean kexAuthenticateHost(SSH2Transport tp, SSH2Signature serverHostKey) { return fingerprintMatch(serverHostKey); } public void gotConnectInfoText(SSH2Transport tp, String text) { alert(text); } public void normalDisconnect(SSH2Transport tp, String description, String languageTag) { if(autoSave) { try { FileOutputStream file = new FileOutputStream(saveLocation); settings.save(file, getAppName() + " settings"); } catch (IOException e) { alert("Error saving settings: " + e.getMessage()); } } disconnect(); } public void fatalDisconnect(SSH2Transport tp, int reason, String description, String languageTag) { alert("Disconnecting: " + description); disconnect(); } public void peerDisconnect(SSH2Transport tp, int reason, String description, String languageTag) { alert("Server disconnected: " + description); disconnect(); } }); if("password".equals(choiceAuthTyp.getSelectedItem())) { client = new SSH2SimpleClient(transport, username, password); password = null; } else if("publickey".equals(choiceAuthTyp.getSelectedItem())) { /* !!! TODO publickey */ } else { client = new SSH2SimpleClient(transport, username, this); } if(frame != null) { frame.setTitle(getAppName() + " " + VERSION + " (connected)"); } if(logo != null) { logo.setImage(connImg); } for(int i = 0; i < modCnt; i++) { modules[i].connected(this); } } public void disconnect() { if(logo != null) { logo.setImage(discImg); } for(int i = 0; i < modCnt; i++) { modules[i].disconnected(this); } if(frame != null) { frame.setTitle(getAppName() + " " + VERSION); } enableButtons(); } public synchronized void windowClosing(WindowEvent e) { if(!isConnected()) { if(!weAreAnApplet) { frame.dispose(); System.exit(0); } } } public void initSeedGenerator() { RandomSeed seed = getRandomSeed(); seed.addEntropyGenerator(container); if(secureRandom == null) { byte[] s = seed.getBytesBlocking(20, false); secureRandom = new SecureRandomAndPad(new SecureRandom(s)); } else { int bytes = seed.getAvailableBits() / 8; secureRandom.setSeed(seed.getBytesBlocking(bytes > 20 ? 20 : bytes)); } secureRandom.setPadSeed(seed.getBytes(20)); } public boolean fingerprintMatch(SSH2Signature serverHostKey) { String fp = settings.getProperty("fingerprint"); if(fp == null) { fp = settings.getProperty("fingerprint." + host + "." + port); } byte[] blob = null; try { blob = serverHostKey.getPublicKeyBlob(); } catch (SSH2SignatureException e) { alert(e.toString()); return false; } String fpMD5Hex = SSH2KeyFingerprint.md5Hex(blob); boolean confirmed = false; if(fp != null) { if(SSH2HostKeyVerifier.compareFingerprints(fp, serverHostKey)) { return true; } if(strictHostKeyCheck()) { return false; } confirmed = confirm("WARNING: HOST IDENTIFICATION HAS CHANGED!\n" + "Do you want to replace existing key with:\n" + "'" + fpMD5Hex + "'", false); } else { confirmed = confirm("Accept key:\n'" + fpMD5Hex + "'\nfor host " + host + "?", true); } if(confirmed) { setProperty("fingerprint", fpMD5Hex); setProperty("fingerprint." + host + "." + port, fpMD5Hex); } return confirmed; } boolean strictHostKeyCheck() { return Boolean.valueOf(getProperty("strict-hostid")).booleanValue(); } public ByteArrayOutputStream readResource(String name) { InputStream in = getClass().getResourceAsStream(name); ByteArrayOutputStream baos = null; if(in != null) { baos = new ByteArrayOutputStream(); try { int c; while((c = in.read()) >= 0) baos.write(c); } catch(IOException e) { // !!! System.err.println("ERROR reading resource " + name + " : " + e); } } return baos; } public Image createImage(String file) { ByteArrayOutputStream baos = readResource(file); Image img = null; if(baos != null) { byte[] raw = baos.toByteArray(); img = Toolkit.getDefaultToolkit().createImage(raw); } return img; } public String promptLine(String prompt, boolean echo) throws SSH2UserCancelException { String[] answer = promptMulti(new String[] { prompt }, new boolean[] { echo });; return answer[0]; } public String[] promptMulti(String[] prompts, boolean[] echos) throws SSH2UserCancelException { return promptMultiFull(getAppName(), null, prompts, echos); } // !!! OUCH Clean out and move to gui or sshcommon or some such static volatile boolean pressedCancel; static volatile Dialog promptDialog; public String[] promptMultiFull(String name, String instruction, String[] prompts, boolean[] echos) throws SSH2UserCancelException { promptDialog = new Dialog(getParentFrame(), name, true); AWTGridBagContainer grid = new AWTGridBagContainer(promptDialog); Label lbl; int i; TextField[] fields = new TextField[prompts.length]; ActionListener al; if(instruction != null) { if(instruction.length() > 40) { grid.add(new TextArea(instruction, 4, 40, TextArea.SCROLLBARS_VERTICAL_ONLY), 0, 4); } else { grid.add(new Label(instruction), 0, 4); } } for(i = 0; i < prompts.length; i++) { lbl = new Label(prompts[i]); grid.add(lbl, 1 + i, 2); fields[i] = new TextField("", 16); grid.add(fields[i], 1 + i, 2); } Button okBut, cancBut; Panel bp = new Panel(new FlowLayout()); bp.add(okBut = new Button("OK")); okBut.addActionListener(al = new Actions(-3)); bp.add(cancBut = new Button("Cancel")); cancBut.addActionListener(al); grid.add(bp, prompts.length + 2, GridBagConstraints.REMAINDER); promptDialog.setResizable(true); promptDialog.pack(); promptDialog.setVisible(true); if(pressedCancel) { throw new SSH2UserCancelException("User cancel"); } String[] answers = new String[prompts.length]; for(i = 0; i < answers.length; i++) { answers[i] = fields[i].getText(); fields[i].setText(""); } return answers; } public int promptList(String name, String instruction, String[] choices) throws SSH2UserCancelException { promptDialog = new Dialog(getParentFrame(), name, true); AWTGridBagContainer grid = new AWTGridBagContainer(promptDialog); ActionListener al; if(instruction != null) { if(instruction.length() > 40) { grid.add(new TextArea(instruction, 4, 40, TextArea.SCROLLBARS_VERTICAL_ONLY), 0, 4); } else { grid.add(new Label(instruction), 0, 4); } } Choice choice = new Choice(); for(int i = 0; i < choices.length; i++) { choice.add(choices[i]); } grid.add(choice, 1, 4); Button okBut, cancBut; Panel bp = new Panel(new FlowLayout()); bp.add(okBut = new Button("OK")); okBut.addActionListener(al = new Actions(-3)); bp.add(cancBut = new Button("Cancel")); cancBut.addActionListener(al); grid.add(bp, 2, GridBagConstraints.REMAINDER); promptDialog.setResizable(true); promptDialog.pack(); promptDialog.setVisible(true); if(pressedCancel) { throw new SSH2UserCancelException("User cancel"); } return choice.getSelectedIndex(); } // // MindTermApp interface implementation // public String getHost() { return host; } public int getPort() { return port; } public Properties getProperties() { return settings; } public String getProperty(String name) { return settings.getProperty(name); } public void setProperty(String name, String value) { settings.put(name, value); } public String getUserName() { return username; } public Frame getParentFrame() { Frame parent = frame; if(parent == null) { Component comp = this; do { comp = comp.getParent(); } while(!(comp instanceof Frame)); parent = (Frame)comp; } return parent; } public String getAppName() { return "MindTermLT"; } public synchronized RandomSeed getRandomSeed() { if(randomSeed == null) { randomSeed = new RandomSeed("/dev/random", "/dev/urandom"); } return randomSeed; } public SSH2Interactor getInteractor() { return this; } public void alert(String message) { AlertDialog.show(getAppName() + " - Alert", message, getParentFrame()); } public boolean confirm(String message, boolean defAnswer) { boolean ret = false; if(message.length() > 35) { boolean scrollbar = (message.length() > 120); ret = ConfirmDialog.show(getAppName() + " - Confirmation", message, 3, 40, "Yes", "No", defAnswer, getParentFrame(), scrollbar); } else { ret = ConfirmDialog.show(getAppName() + " - Confirmation", message, 0, 0, "Yes", "No", defAnswer, getParentFrame(), false); } return ret; } public boolean isConnected() { return (client != null && client.getTransport() != null && client.getTransport().isConnected()); } public boolean isApplet() { return weAreAnApplet; } public AppletContext getAppletContext() { AppletContext ctx = null; if(weAreAnApplet) { ctx = super.getAppletContext(); } return ctx; } public SSH2Transport getTransport() { return client.getTransport(); } public SSH2Connection getConnection() { return client.getConnection(); } public SSHConsoleRemote getConsoleRemote() { return new SSH2ConsoleRemote(getConnection()); } // // ProxyAuthenticator interface implementation // public String getProxyUsername(String type, String challenge) throws IOException { return getProperty("proxy-user"); } public String getProxyPassword(String type, String challenge) throws IOException { return getProperty("proxy-password"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -