📄 vpnclient.java
字号:
if (userAgent != null) {
// TODO support more browsers
BrowserProxySettings proxySettings = null;
if (userAgent.indexOf("MSIE") != -1) {
try {
/* DEBUG */log.info("Looking for IE");
proxySettings = ProxyUtil.lookupIEProxySettings();
} catch (Throwable t) {
/* DEBUG */log.error("Failed to get IE proxy settings, trying Firefox.", t);
}
}
if (proxySettings == null && userAgent.indexOf("Firefox") != -1) {
try {
/* DEBUG */log.info("Looking for Firefox");
proxySettings = ProxyUtil.lookupFirefoxProxySettings();
} catch (Throwable t) {
/* DEBUG */log.error("Failed to get Firefox proxy settings.", t);
}
}
if (proxySettings != null) {
/* DEBUG */log.info("Found some proxy settings.");
ProxyInfo[] proxyInfo = proxySettings.getProxies();
for (int i = 0; proxyInfo != null && i < proxyInfo.length; i++) {
/* DEBUG */log.info("Checking if " + proxyInfo[i].toUri() + " is suitable.");
if (proxyInfo[i].getProtocol().equals("ssl") || proxyInfo[i].getProtocol().equals("https")
|| proxyInfo[i].getProtocol().equals("all")) {
StringBuffer buf = new StringBuffer("http://");
if (proxyInfo[i].getUsername() != null && !proxyInfo[i].getUsername().equals("")) {
buf.append(proxyInfo[i].getUsername());
if (proxyInfo[i].getPassword() != null && !proxyInfo[i].getPassword().equals("")) {
buf.append(":");
buf.append(proxyInfo[i].getPassword());
}
buf.append("@");
}
buf.append(proxyInfo[i].getHostname());
if (proxyInfo[i].getPort() != 0) {
buf.append(":");
buf.append(proxyInfo[i].getPort());
}
if (uri.getHost() != null) {
buf.append("?");
buf.append(uri.getHost());
}
proxyURL = buf.toString();
break;
}
}
} else {
/* DEBUG */log.warn("No useragent supplied, automatic proxy could not check for browse type.");
}
// Use the proxy supplied by the plugin if it is
// available
if (proxyURL == null && pluginProxyURL != null && !pluginProxyURL.equals("")) {
/* DEBUG */log.info("Using plugin supplied proxy settings.");
proxyURL = pluginProxyURL;
}
}
if (proxyURL != null) {
/* DEBUG */log.info("Setting local proxy URL to " + obfuscateURL(proxyURL));
vpn.setLocalProxyURL(proxyURL);
}
}
}
if (heartbeat > -1)
vpn.HEARTBEAT_PERIOD = heartbeat;
if (shutdown > -1)
vpn.SHUTDOWN_PERIOD = shutdown;
vpn.WEBFORWARD_INACTIVITY = webforwardInactivity;
vpn.TUNNEL_INACTIVITY = tunnelInactivity;
if (browserCommand != null && !browserCommand.equals("")) {
/* DEBUG */log.info("Setting browser to '" + browserCommand + "'");
BrowserLauncher.setBrowserCommand(browserCommand);
}
vpn.init(hostname, port, username, ticket);
if(extensionClasses!=null)
vpn.startExtensions(extensionClasses);
} catch (Throwable t) {
// Catch any nasties to make sure we exit
/* DEBUG */log.error("Critical error, shutting down.", t);
System.exit(0);
}
}
static class ConsoleOutputStream extends OutputStream {
StringBuffer buf = new StringBuffer();
Frame frame;
TextArea textArea;
Method deleteMethod;
ConsoleOutputStream() {
try {
deleteMethod = StringBuffer.class.getMethod("delete", new Class[] {
int.class, int.class
});
} catch (Throwable t) {
}
textArea = new TextArea();
textArea.setEditable(false);
Panel panel = new Panel(new BorderLayout());
panel.add(textArea, BorderLayout.CENTER);
Panel buttonPanel = new Panel(new FlowLayout(FlowLayout.RIGHT));
Button clear = new Button("Clear");
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
clear();
}
});
buttonPanel.add(clear);
Button close = new Button("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frame.hide();
}
});
buttonPanel.add(close);
panel.add(buttonPanel, BorderLayout.SOUTH);
frame = new Frame("SSL-Explorer Console");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
frame.hide();
}
});
frame.add(panel);
frame.pack();
frame.setLocation(100, 100);
frame.setSize(300, 400);
}
void clear() {
synchronized (buf) {
buf.setLength(0);
if (frame.isVisible()) {
textArea.setText(buf.toString());
textArea.setCaretPosition(buf.length());
}
}
}
public void show() {
textArea.setText(buf.toString());
frame.show();
}
void append(String text) {
synchronized (buf) {
buf.append(text);
if (buf.length() > 65535) {
if (deleteMethod != null) {
try {
deleteMethod.invoke(buf, new Object[] {
new Integer(0), new Integer(buf.length() - 65535)
});
} catch (Throwable t) {
String newBuf = buf.toString().substring(buf.length() - 65535);
buf.setLength(0);
buf.append(newBuf);
}
} else {
String newBuf = buf.toString().substring(buf.length() - 65535);
buf.setLength(0);
buf.append(newBuf);
}
}
if (frame.isVisible()) {
textArea.setText(buf.toString());
textArea.setCaretPosition(buf.length());
}
}
}
public void write(int b) throws IOException {
append(String.valueOf((char) b));
}
public void write(byte[] buf, int off, int len) throws IOException {
append(new String(buf, off, len));
}
}
class MyGUIListener implements VPNClientGUIListener {
public void exit() {
startShutdownProcedure(true, true);
}
public void open() {
try {
/* DEBUG */log.info("Opening browser to https://" + getSSLExplorerHost() + ":" + getSSLExplorerPort());
BrowserLauncher.openURL("https://" + getSSLExplorerHost() + ":" + getSSLExplorerPort());
} catch (IOException ioe) {
/* DEBUG */log.error(ioe);
}
}
public void console() {
CONSOLE.show();
}
public void ports() {
PORTS.setVisible(true);
}
}
class ApplicationEventListener implements ApplicationLauncherEvents {
ProgressBar progress;
String application;
long totalNumBytes;
public void startingLaunch(String application) {
this.application = application;
progress = new ProgressBar(gui == null ? null : gui.getGUIComponent(), "Launching " + application, "SSL-Explorer",
100L, false);
progress.updateValue(7L);
}
public void processingDescriptor() {
progress.setMessage("Processing " + application + " descriptor");
progress.updateValue(14L);
}
public void startDownload(long totalNumBytes) {
this.totalNumBytes = totalNumBytes;
progress.setMessage("Downloading files");
progress.updateValue(20);
}
public void progressedDownload(long bytesSoFar) {
// The the file download takes up 70% of the total progress
int percent = (int) (((float) bytesSoFar / (float) totalNumBytes) * 70f) + 20;
progress.updateValue(percent);
}
public void completedDownload() {
progress.setMessage("Download complete");
progress.updateValue(90);
}
public void executingApplication(String name, String cmdline) {
progress.setMessage("Launching " + name);
progress.updateValue(95);
}
public void finishedLaunch() {
Thread t = new Thread() {
public void run() {
progress.updateValue(100);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
progress.dispose();
}
};
t.start();
}
public Tunnel createTunnel(String name, String hostToConnect, int portToConnect, boolean usePreferredPort,
boolean singleConnection) {
VPNConnectionListener l = createTemporaryListeningSocket(hostToConnect, portToConnect, false,
usePreferredPort ? portToConnect : -1, 10, singleConnection);
if (l == null) {
return null;
} else {
int actualPort = l.getLocalPort();
DefaultTunnel tunnel = new DefaultTunnel(l.getId(), Tunnel.LOCAL_TUNNEL, false, Tunnel.TCP_TUNNEL, getUsername(),
actualPort, portToConnect, hostToConnect, false, false, true, name, false);
getTunnels().addElement(tunnel);
updateInformation();
return tunnel;
}
}
public void closeTunnel(Tunnel tunnel) {
/* DEBUG */log.info("Closing application tunnel to " + tunnel.getDestinationHost() + " :"
/* DEBUG */+ tunnel.getDestinationPort());
getTunnels().removeElement(tunnel);
updateInformation();
}
public void debug(String msg) {
/* DEBUG */log.info(msg);
}
}
class Application extends Thread {
Hashtable parameters;
boolean running = false;
String name;
Application
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -