1 19 20 package com.sslexplorer.agent.client.tunneling; 21 22 import java.text.MessageFormat ; 23 24 import com.maverick.multiplex.Channel; 25 import com.maverick.multiplex.ChannelListener; 26 import com.sslexplorer.agent.client.Agent; 27 import com.sslexplorer.agent.client.PortMonitor; 28 29 public class RemoteTunnelChannelListener implements ChannelListener { 30 31 private Agent agent; 32 private PortMonitor portMonitor; 33 34 public RemoteTunnelChannelListener(Agent agent) { 35 this.agent = agent; 36 portMonitor = this.agent.getGUI().getPortMonitor(); 37 } 38 39 public void onChannelClose(Channel channel) { 40 RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel; 41 if(agent.getConfiguration().isDisplayInformationPopups()) { 42 agent.getGUI() 43 .popup(null, 44 MessageFormat.format(Messages.getString("RemoteForwardingChannelListener.closingRemoteTunnel"), new Object [] { rfc.getConfiguration().getName(), String.valueOf(rfc.getConfiguration().getSourcePort()), 46 rfc.getConfiguration().getDestinationHost() + ":" + rfc.getConfiguration().getDestinationPort() }), Messages.getString("Agent.title"), "popup-tunnel", -1); } 50 synchronized (portMonitor) { 51 int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId()); 52 AbstractPortItem portItem = idx == -1 ? null : portMonitor.getItemAt(idx); 53 if (portItem != null) { 54 portItem.decreaseActive(); 55 portMonitor.updateItemAt(idx); 56 } 57 } 58 } 59 60 public void onChannelData(Channel channel, byte[] buf, int off, int len) { 61 RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel; 62 synchronized (portMonitor) { 63 int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId()); 64 if (idx != -1) { 65 portMonitor.updateItemAt(idx); 66 } 67 } 68 } 69 70 public void onChannelOpen(Channel channel) { 71 final RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel; 72 if(agent.getConfiguration().isDisplayInformationPopups()) { 73 agent.getGUI() 74 .popup(null, 75 MessageFormat.format(Messages.getString("RemoteForwardingChannelListener.openedRemoteTunnel"), new Object [] { rfc.getConfiguration().getName(), String.valueOf(rfc.getConfiguration().getSourcePort()), rfc.getConfiguration().getDestinationHost() + ":" + rfc.getConfiguration().getDestinationPort() }), Messages.getString("Agent.title"), "popup-tunnel", -1); } 80 81 synchronized (portMonitor) { 82 int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId()); 83 RemotePortItem portItem = idx == -1 ? null : (RemotePortItem)portMonitor.getItemAt(idx); 84 if (portItem == null) { 85 portItem = new RemotePortItem(rfc.getConfiguration()); 86 portItem.addChannel(rfc); 87 portMonitor.addPortItem(portItem); 88 } else { 89 portItem.addChannel(rfc); 90 portMonitor.updateItemAt(idx); 91 } 92 } 93 } 94 95 } 96 | Popular Tags |