mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-02 16:49:10 +00:00
Remove Proxy Support
This commit is contained in:
@@ -4,8 +4,6 @@ import org.parabot.core.Context;
|
|||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.network.NetworkInterface;
|
import org.parabot.core.network.NetworkInterface;
|
||||||
import org.parabot.core.network.proxy.ProxySocket;
|
|
||||||
import org.parabot.core.network.proxy.ProxyType;
|
|
||||||
import org.parabot.core.ui.BotUI;
|
import org.parabot.core.ui.BotUI;
|
||||||
import org.parabot.core.ui.utils.UILog;
|
import org.parabot.core.ui.utils.UILog;
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ public final class Landing {
|
|||||||
switch (arg.toLowerCase()) {
|
switch (arg.toLowerCase()) {
|
||||||
case "-createdirs":
|
case "-createdirs":
|
||||||
Directories.validate();
|
Directories.validate();
|
||||||
System.out.println("Directories created, you can now run parabot.");
|
System.out.println("Directories created, you can now run " + Configuration.BOT_TITLE + ".");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
case "-dump":
|
case "-dump":
|
||||||
@@ -87,15 +85,6 @@ public final class Landing {
|
|||||||
}
|
}
|
||||||
NetworkInterface.setMac(mac);
|
NetworkInterface.setMac(mac);
|
||||||
break;
|
break;
|
||||||
case "-proxy":
|
|
||||||
ProxyType type = ProxyType.valueOf(args[++i].toUpperCase());
|
|
||||||
ProxySocket.setProxy(type, args[++i], Integer.parseInt(args[++i]));
|
|
||||||
break;
|
|
||||||
case "-proxy_auth":
|
|
||||||
case "-auth":
|
|
||||||
ProxySocket.auth = true;
|
|
||||||
ProxySocket.setLogin(args[++i], args[++i]);
|
|
||||||
break;
|
|
||||||
case "-no_sec":
|
case "-no_sec":
|
||||||
Core.disableSec();
|
Core.disableSec();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ public class ClassRemapper extends Remapper {
|
|||||||
private static final HashMap<String, String> remapNames = new HashMap<String, String>();
|
private static final HashMap<String, String> remapNames = new HashMap<String, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
remapNames.put("java/net/Socket", "org/parabot/core/network/proxy/ProxySocket");
|
|
||||||
remapNames.put("java/net/NetworkInterface", "org/parabot/core/network/NetworkInterface");
|
remapNames.put("java/net/NetworkInterface", "org/parabot/core/network/NetworkInterface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,321 +0,0 @@
|
|||||||
package org.parabot.core.network.proxy;
|
|
||||||
|
|
||||||
import org.parabot.core.Core;
|
|
||||||
import org.parabot.core.ui.utils.UILog;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.channels.SocketChannel;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
public class ProxySocket extends Socket {
|
|
||||||
|
|
||||||
private static final List<ProxySocket> connections = new ArrayList<ProxySocket>();
|
|
||||||
public static boolean auth = false;
|
|
||||||
private static ProxyType proxyType = ProxyType.NONE;
|
|
||||||
private static int proxyPort = 0;
|
|
||||||
private static String username = null, password = null;
|
|
||||||
private static InetAddress proxyInetAddress = null;
|
|
||||||
private InetAddress addr;
|
|
||||||
private int port;
|
|
||||||
private InetSocketAddress cachedAddr;
|
|
||||||
|
|
||||||
public ProxySocket(InetAddress addr, int port) throws IOException {
|
|
||||||
super(addr, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxySocket() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxySocket(String host, int port) throws IOException {
|
|
||||||
super(host, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int closeConnections() {
|
|
||||||
int value = 0;
|
|
||||||
for (ProxySocket socket : connections) {
|
|
||||||
try {
|
|
||||||
connections.remove(socket);
|
|
||||||
if (socket.isClosed()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
socket.close();
|
|
||||||
value++;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Core.verbose("Error closing proxy connection: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProxy(ProxyType type, String host, int port) {
|
|
||||||
try {
|
|
||||||
proxyInetAddress = InetAddress.getByName(host);
|
|
||||||
proxyPort = port;
|
|
||||||
proxyType = type;
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InetAddress getProxyAddress() {
|
|
||||||
return proxyInetAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getProxyPort() {
|
|
||||||
return proxyPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ProxyType getProxyType() {
|
|
||||||
return proxyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setType(ProxyType pt) {
|
|
||||||
proxyType = pt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getConnectionCount() {
|
|
||||||
return connections.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setLogin(String user, char[] pass) {
|
|
||||||
setLogin(user, new String(pass));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setLogin(String user, String pass) {
|
|
||||||
username = user;
|
|
||||||
password = pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connect(SocketAddress addr) throws IOException {
|
|
||||||
connections.add(this);
|
|
||||||
if (addr instanceof InetSocketAddress) {
|
|
||||||
InetSocketAddress isa = (InetSocketAddress) addr;
|
|
||||||
this.addr = InetAddress.getByName(isa.getHostString());
|
|
||||||
this.port = isa.getPort();
|
|
||||||
}
|
|
||||||
if (proxyType != ProxyType.NONE) {
|
|
||||||
try {
|
|
||||||
super.connect(cachedAddr = new InetSocketAddress(
|
|
||||||
proxyInetAddress, proxyPort));
|
|
||||||
initProxy();
|
|
||||||
} catch (Exception e) {
|
|
||||||
UILog.log("Proxy Error", e.getMessage(),
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.connect(addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
return super.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InetAddress getInetAddress() {
|
|
||||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
return super.getInetAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SocketAddress getRemoteSocketAddress() {
|
|
||||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
|
||||||
return cachedAddr;
|
|
||||||
}
|
|
||||||
return super.getRemoteSocketAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SocketChannel getChannel() {
|
|
||||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return super.getChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
connections.remove(this);
|
|
||||||
super.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initProxy() throws IOException {
|
|
||||||
System.out.println("Proxying:" + addr + ":" + port + " Over:"
|
|
||||||
+ proxyInetAddress + ":" + proxyPort + " Type:" + proxyType);
|
|
||||||
switch (proxyType) {
|
|
||||||
case HTTP:
|
|
||||||
http_connect();
|
|
||||||
break;
|
|
||||||
case SOCKS4:
|
|
||||||
socks4_connect();
|
|
||||||
break;
|
|
||||||
case SOCKS5:
|
|
||||||
socks5_connect();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IOException("Unsupported proxy type:" + proxyType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void http_connect() throws IOException {
|
|
||||||
InputStream in = getInputStream();
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
||||||
OutputStream out = getOutputStream();
|
|
||||||
out.write(("CONNECT " + addr.getHostAddress() + ":" + port + "\r\n")
|
|
||||||
.getBytes());
|
|
||||||
// out.write("Connection:keep-alive\r\n".getBytes());
|
|
||||||
out.write("\r\n".getBytes());
|
|
||||||
String str;
|
|
||||||
while ((str = br.readLine()) != null) {
|
|
||||||
if (str.length() == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!str.startsWith("HTTP")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int code = Integer.parseInt(str.substring(9, 12));
|
|
||||||
switch (code) {
|
|
||||||
case 404:
|
|
||||||
throw new IOException(
|
|
||||||
"Proxy seems to think we're connecting to a webpage...");
|
|
||||||
case 403:
|
|
||||||
throw new IOException(
|
|
||||||
"Proxy doesn't support connecting to port: " + port
|
|
||||||
+ "! Try a different proxy.");
|
|
||||||
}
|
|
||||||
if (code / 100 != 2) {
|
|
||||||
throw new IOException(
|
|
||||||
"Unable to connect to proxy server! HTTP Error code:"
|
|
||||||
+ code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void socks4_connect() throws IOException {
|
|
||||||
DataOutputStream out = new DataOutputStream(getOutputStream());
|
|
||||||
DataInputStream in = new DataInputStream(getInputStream());
|
|
||||||
|
|
||||||
out.write(0x04);
|
|
||||||
out.write(0x01); // connection type (TCP stream)
|
|
||||||
out.writeShort(port);
|
|
||||||
byte[] b = addr.getAddress();
|
|
||||||
if (b.length != 4) {
|
|
||||||
throw new IOException("Unsupported IP type for socksv4!");
|
|
||||||
}
|
|
||||||
out.write(b);
|
|
||||||
out.write(0); // the userID stuff, 0 means end of string (null
|
|
||||||
// terminated)
|
|
||||||
out.flush();
|
|
||||||
|
|
||||||
if (in.read() != 0x00) // null byte
|
|
||||||
{
|
|
||||||
throw new IOException("Proxy server dun goofed");
|
|
||||||
}
|
|
||||||
if (in.read() != 0x5a) {
|
|
||||||
throw new IOException(
|
|
||||||
"Proxy server was unable to connect to server!");
|
|
||||||
}
|
|
||||||
|
|
||||||
in.readShort(); // ignored
|
|
||||||
in.readFully(b); // ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
private void socks5_connect() throws IOException {
|
|
||||||
DataOutputStream out = new DataOutputStream(getOutputStream());
|
|
||||||
DataInputStream in = new DataInputStream(getInputStream());
|
|
||||||
out.write(0x05); // the version
|
|
||||||
out.write(auth ? 2 : 1); // number of authentication methods (no auth
|
|
||||||
// for now)
|
|
||||||
out.write(0); // the authentication (none)
|
|
||||||
if (auth) {
|
|
||||||
out.write(2);
|
|
||||||
}
|
|
||||||
out.flush();
|
|
||||||
if (in.read() != 0x05) // remote proxy version
|
|
||||||
{
|
|
||||||
throw new IOException("Proxy server is not supported!");
|
|
||||||
}
|
|
||||||
switch (in.read()) { // auth method
|
|
||||||
case 0:
|
|
||||||
break; // no auth
|
|
||||||
case 2:
|
|
||||||
// username and pass stuff
|
|
||||||
out.write(0x01); // user/pass version #
|
|
||||||
out.write(username.length());
|
|
||||||
out.write(username.getBytes());
|
|
||||||
out.write(password.length());
|
|
||||||
out.write(password.getBytes());
|
|
||||||
out.flush();
|
|
||||||
in.read(); // skip the version
|
|
||||||
if (in.read() == 0) // Successful login, continue
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IOException("Proxy server declined request!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// now to write the actual request
|
|
||||||
out.write(0x05); // again the socks version
|
|
||||||
out.write(0x01); // the connection type (0x01 = TCP Connection)
|
|
||||||
out.write(0x00); // the reserve byte, un-used
|
|
||||||
byte[] b = addr.getAddress();
|
|
||||||
out.write(b.length == 4 ? 0x01 : 0x04); // if ipv4 or ipv6 (0x03 =
|
|
||||||
// domain name, but that's
|
|
||||||
// unsupported as of yet)
|
|
||||||
out.write(b);
|
|
||||||
out.writeShort(port);
|
|
||||||
out.flush();
|
|
||||||
|
|
||||||
// now to read the server's reply
|
|
||||||
if (in.read() != 0x05) // socks version (again)
|
|
||||||
{
|
|
||||||
throw new IOException("Proxy server dun goofed");
|
|
||||||
}
|
|
||||||
int reply = in.read();
|
|
||||||
if (reply == 0x08) {
|
|
||||||
throw new IOException("Bad address sent to proxy server");
|
|
||||||
}
|
|
||||||
if (reply != 0x00) {
|
|
||||||
throw new IOException("Unable to connect to server!");
|
|
||||||
}
|
|
||||||
in.read(); // reserve byte
|
|
||||||
int addrType = in.read();
|
|
||||||
b = new byte[4];
|
|
||||||
switch (addrType) {
|
|
||||||
case 0x01:
|
|
||||||
b = new byte[4];
|
|
||||||
break;
|
|
||||||
case 0x04:
|
|
||||||
b = new byte[16];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IOException("Bad address type from proxy server!");
|
|
||||||
}
|
|
||||||
in.readFully(b);
|
|
||||||
in.readShort(); // the returned port #, ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package org.parabot.core.network.proxy;
|
|
||||||
|
|
||||||
public enum ProxyType {
|
|
||||||
NONE, SOCKS5, SOCKS4, HTTP
|
|
||||||
}
|
|
||||||
@@ -136,9 +136,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
case "Exit":
|
case "Exit":
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
case "Network":
|
|
||||||
NetworkUI.getInstance().setVisible(true);
|
|
||||||
break;
|
|
||||||
case "Randoms":
|
case "Randoms":
|
||||||
ArrayList<String> randoms = new ArrayList<>();
|
ArrayList<String> randoms = new ArrayList<>();
|
||||||
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
||||||
@@ -298,7 +295,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
features = new JMenu("Features");
|
features = new JMenu("Features");
|
||||||
|
|
||||||
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
||||||
JMenuItem proxy = new JMenuItem("Network");
|
|
||||||
JMenuItem randoms = new JMenuItem("Randoms");
|
JMenuItem randoms = new JMenuItem("Randoms");
|
||||||
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
||||||
JMenuItem logger = new JCheckBoxMenuItem("Logger");
|
JMenuItem logger = new JCheckBoxMenuItem("Logger");
|
||||||
@@ -328,7 +324,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png")));
|
notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png")));
|
||||||
|
|
||||||
screenshot.addActionListener(this);
|
screenshot.addActionListener(this);
|
||||||
proxy.addActionListener(this);
|
|
||||||
randoms.addActionListener(this);
|
randoms.addActionListener(this);
|
||||||
dialog.addActionListener(this);
|
dialog.addActionListener(this);
|
||||||
logger.addActionListener(this);
|
logger.addActionListener(this);
|
||||||
@@ -342,7 +337,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
stop.addActionListener(this);
|
stop.addActionListener(this);
|
||||||
|
|
||||||
file.add(screenshot);
|
file.add(screenshot);
|
||||||
file.add(proxy);
|
|
||||||
file.add(randoms);
|
file.add(randoms);
|
||||||
file.add(dialog);
|
file.add(dialog);
|
||||||
file.add(logger);
|
file.add(logger);
|
||||||
|
|||||||
@@ -1,372 +0,0 @@
|
|||||||
package org.parabot.core.ui;
|
|
||||||
|
|
||||||
import org.parabot.core.network.NetworkInterface;
|
|
||||||
import org.parabot.core.network.proxy.ProxySocket;
|
|
||||||
import org.parabot.core.network.proxy.ProxyType;
|
|
||||||
import org.parabot.core.ui.utils.UILog;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.KeyListener;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPasswordField;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import javax.swing.event.DocumentEvent;
|
|
||||||
import javax.swing.event.DocumentListener;
|
|
||||||
import javax.swing.text.AttributeSet;
|
|
||||||
import javax.swing.text.BadLocationException;
|
|
||||||
import javax.swing.text.Document;
|
|
||||||
import javax.swing.text.PlainDocument;
|
|
||||||
|
|
||||||
public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
|
||||||
DocumentListener {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private static NetworkUI instance;
|
|
||||||
|
|
||||||
private JComboBox<ProxyType> proxyType;
|
|
||||||
private JTextField proxyHost;
|
|
||||||
private IntTextField proxyPort;
|
|
||||||
private JButton submitButton;
|
|
||||||
|
|
||||||
private JList<String>[] macList;
|
|
||||||
private JScrollPane[] macScrollList;
|
|
||||||
|
|
||||||
private JCheckBox authCheckBox;
|
|
||||||
private JTextField authUsername;
|
|
||||||
private JPasswordField authPassword;
|
|
||||||
private JButton randomize;
|
|
||||||
|
|
||||||
private NetworkUI() {
|
|
||||||
initGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NetworkUI getInstance() {
|
|
||||||
return instance == null ? instance = new NetworkUI() : instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setVisible(boolean b) {
|
|
||||||
BotUI.getInstance().setEnabled(!b);
|
|
||||||
if (ProxySocket.getProxyAddress() != null) {
|
|
||||||
proxyHost.setText(ProxySocket.getProxyAddress().getHostName());
|
|
||||||
}
|
|
||||||
proxyPort.setText("" + ProxySocket.getProxyPort());
|
|
||||||
proxyType.setSelectedItem(ProxySocket.getProxyType());
|
|
||||||
authCheckBox.setSelected(ProxySocket.auth);
|
|
||||||
setLocationRelativeTo(BotUI.getInstance());
|
|
||||||
super.setVisible(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
Object source = e.getSource();
|
|
||||||
if (source == proxyPort || source == proxyHost) {
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
|
||||||
actionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyTyped(KeyEvent arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void changedUpdate(DocumentEvent arg0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertUpdate(DocumentEvent arg0) {
|
|
||||||
if (proxyPort.isValid()) {
|
|
||||||
proxyPort.setText("" + proxyPort.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUpdate(DocumentEvent arg0) {
|
|
||||||
insertUpdate(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
boolean b = false;
|
|
||||||
|
|
||||||
if (arg0.getSource() == proxyType) {
|
|
||||||
Object o = proxyType.getSelectedItem();
|
|
||||||
authCheckBox.setEnabled(o == ProxyType.SOCKS5);
|
|
||||||
proxyHost.setEnabled(o != ProxyType.NONE);
|
|
||||||
proxyPort.setEnabled(o != ProxyType.NONE);
|
|
||||||
b = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b || arg0.getSource() == authCheckBox) {
|
|
||||||
b = authCheckBox.isSelected() && authCheckBox.isEnabled();
|
|
||||||
ProxySocket.auth = b;
|
|
||||||
authUsername.setEnabled(b);
|
|
||||||
authPassword.setEnabled(b);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (proxyType.getSelectedItem() != ProxyType.NONE) {
|
|
||||||
if (proxyPort.getText().equals("")
|
|
||||||
|| proxyHost.getText().equals("")) {
|
|
||||||
UILog.log("Error", "Please supply proxy information!",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String username = authUsername.getText();
|
|
||||||
char[] password = authPassword.getPassword();
|
|
||||||
|
|
||||||
ProxySocket
|
|
||||||
.setLogin(username, password);
|
|
||||||
|
|
||||||
byte[] mac = new byte[macList.length];
|
|
||||||
for (int i = 0; i < mac.length; i++) {
|
|
||||||
mac[i] = (byte) Short.parseShort(
|
|
||||||
macList[i].getSelectedValue(), 16);
|
|
||||||
}
|
|
||||||
NetworkInterface.setMac(mac);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (ProxySocket.getConnectionCount() > 0) {
|
|
||||||
try {
|
|
||||||
System.out.println("Closing Existing Connections...");
|
|
||||||
ProxySocket.closeConnections();
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ProxyType type = (ProxyType) proxyType.getSelectedItem();
|
|
||||||
String host = proxyHost.getText();
|
|
||||||
int port = proxyPort.getValue();
|
|
||||||
|
|
||||||
ProxySocket.setProxy(type, host, port);
|
|
||||||
UILog.log("Info", "Network settings have been set!");
|
|
||||||
} catch (Exception e) {
|
|
||||||
UILog.log("Error",
|
|
||||||
"Unable to set proxy info!\n\nReason:" + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void initGUI() {
|
|
||||||
proxyType = new JComboBox<ProxyType>(ProxyType.values());
|
|
||||||
proxyType.setSelectedItem(ProxySocket.getProxyType());
|
|
||||||
|
|
||||||
proxyType.addActionListener(this);
|
|
||||||
|
|
||||||
proxyHost = new JTextField();
|
|
||||||
proxyHost.addKeyListener(this);
|
|
||||||
|
|
||||||
proxyPort = new IntTextField(80, 5);
|
|
||||||
proxyPort.setColumns(5);
|
|
||||||
proxyPort.addKeyListener(this);
|
|
||||||
|
|
||||||
submitButton = new JButton("Submit");
|
|
||||||
submitButton.addActionListener(this);
|
|
||||||
|
|
||||||
byte[] mac = new byte[6];
|
|
||||||
mac = NetworkInterface.mac;
|
|
||||||
macList = new JList[mac.length];
|
|
||||||
macScrollList = new JScrollPane[mac.length];
|
|
||||||
for (int i = 0; i < mac.length; i++) {
|
|
||||||
int value = mac[i] & 0xFF;
|
|
||||||
macList[i] = createMacList();
|
|
||||||
macList[i].setSelectedIndex(value);
|
|
||||||
macScrollList[i] = new JScrollPane(macList[i]);
|
|
||||||
macList[i].ensureIndexIsVisible(value > 0 ? value - 1 : value);
|
|
||||||
}
|
|
||||||
|
|
||||||
randomize = new JButton("Randomize MAC");
|
|
||||||
randomize.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Random rand = new Random();
|
|
||||||
byte[] macAddr = new byte[6];
|
|
||||||
rand.nextBytes(macAddr);
|
|
||||||
macAddr[0] = (byte) (macAddr[0] & (byte) 254);
|
|
||||||
for (int i = 0; i < macAddr.length; i++) {
|
|
||||||
int value = macAddr[i] & 0xFF;
|
|
||||||
macList[i].setSelectedIndex(value);
|
|
||||||
macList[i].ensureIndexIsVisible(value > 0 ? value - 1 : value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
authCheckBox = new JCheckBox("Auth");
|
|
||||||
authCheckBox.setSelected(ProxySocket.auth);
|
|
||||||
authCheckBox.addActionListener(this);
|
|
||||||
|
|
||||||
authUsername = new JTextField();
|
|
||||||
authPassword = new JPasswordField();
|
|
||||||
|
|
||||||
authUsername.setEnabled(authCheckBox.isSelected());
|
|
||||||
authPassword.setEnabled(authCheckBox.isSelected());
|
|
||||||
|
|
||||||
JPanel p = createPanelUI();
|
|
||||||
add(p);
|
|
||||||
setResizable(false);
|
|
||||||
setDefaultCloseOperation(HIDE_ON_CLOSE);
|
|
||||||
pack();
|
|
||||||
setTitle("Network Settings");
|
|
||||||
}
|
|
||||||
|
|
||||||
private JPanel createPanelUI() {
|
|
||||||
JPanel ret = new JPanel();
|
|
||||||
ret.setLayout(new BoxLayout(ret, BoxLayout.LINE_AXIS));
|
|
||||||
Box main = Box.createVerticalBox();
|
|
||||||
|
|
||||||
Box type = Box.createHorizontalBox();
|
|
||||||
type.add(new JLabel("Proxy Type: "));
|
|
||||||
type.add(proxyType);
|
|
||||||
|
|
||||||
Box host = Box.createHorizontalBox();
|
|
||||||
host.add(new JLabel("Proxy Host: "));
|
|
||||||
host.add(proxyHost);
|
|
||||||
|
|
||||||
Box port = Box.createHorizontalBox();
|
|
||||||
port.add(new JLabel("Proxy Port: "));
|
|
||||||
port.add(proxyPort);
|
|
||||||
|
|
||||||
Box auth = Box.createHorizontalBox();
|
|
||||||
auth.add(authCheckBox);
|
|
||||||
|
|
||||||
auth.add(Box.createHorizontalStrut(3));
|
|
||||||
|
|
||||||
auth.add(new JLabel("User:"));
|
|
||||||
auth.add(authUsername);
|
|
||||||
|
|
||||||
auth.add(Box.createHorizontalStrut(3));
|
|
||||||
|
|
||||||
auth.add(new JLabel("Pass:"));
|
|
||||||
auth.add(authPassword);
|
|
||||||
|
|
||||||
Box macBox = Box.createHorizontalBox();
|
|
||||||
macBox.add(new JLabel("MAC:"));
|
|
||||||
for (int i = 0; i < macList.length; i++) {
|
|
||||||
macBox.add(new JScrollPane(macList[i]));
|
|
||||||
macBox.add(Box.createHorizontalStrut(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
Box submit = Box.createHorizontalBox();
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
submit.add(randomize);
|
|
||||||
submit.add(submitButton);
|
|
||||||
|
|
||||||
main.add(type);
|
|
||||||
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
main.add(host);
|
|
||||||
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
main.add(port);
|
|
||||||
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
main.add(auth);
|
|
||||||
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
main.add(macBox);
|
|
||||||
|
|
||||||
main.add(Box.createVerticalStrut(5));
|
|
||||||
main.add(submit);
|
|
||||||
|
|
||||||
ret.add(main);
|
|
||||||
ret.setBorder(new EmptyBorder(10, 10, 10, 10));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JList<String> createMacList() {
|
|
||||||
String[] hexStrings = new String[256];
|
|
||||||
for (int i = 0; i < 256; i++) {
|
|
||||||
hexStrings[i] = String.format("%02X", i);
|
|
||||||
}
|
|
||||||
JList<String> ret = new JList<String>(hexStrings);
|
|
||||||
ret.setVisibleRowCount(3);
|
|
||||||
ret.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
class IntTextField extends JTextField {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public IntTextField(int defval, int size) {
|
|
||||||
super("" + defval, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValid() {
|
|
||||||
try {
|
|
||||||
int i = Integer.parseInt(getText());
|
|
||||||
return i > 0 && i <= 25565;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue() {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(getText());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Document createDefaultModel() {
|
|
||||||
return new IntTextDocument();
|
|
||||||
}
|
|
||||||
|
|
||||||
class IntTextDocument extends PlainDocument {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public void insertString(int offs, String str, AttributeSet a)
|
|
||||||
throws BadLocationException {
|
|
||||||
if (str == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String oldString = getText(0, getLength());
|
|
||||||
String newString = oldString.substring(0, offs) + str
|
|
||||||
+ oldString.substring(offs);
|
|
||||||
try {
|
|
||||||
Integer.parseInt(newString.replace("-", "") + "0");
|
|
||||||
super.insertString(offs, str, a);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user