mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
revert proxy as requested
This commit is contained in:
@@ -8,8 +8,6 @@ import javax.swing.UIManager;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.proxy.ProxySocket;
|
||||
import org.parabot.core.proxy.ProxyType;
|
||||
import org.parabot.core.ui.LoginUI;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
@@ -87,14 +85,6 @@ public final class Landing {
|
||||
username = args[++i];
|
||||
password = args[++i];
|
||||
break;
|
||||
case "-proxy":
|
||||
String type = args[++i];
|
||||
String ip = args[++i];
|
||||
String port = args[++i];
|
||||
if (!handleProxy(type, ip, port)) {
|
||||
System.exit(1);
|
||||
}
|
||||
break;
|
||||
case "-loadlocal":
|
||||
Core.setLoadLocal(true);
|
||||
break;
|
||||
@@ -103,25 +93,5 @@ public final class Landing {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean handleProxy(String type, String ip, String port) {
|
||||
ProxyType proxyType = null;
|
||||
for (ProxyType pt : ProxyType.values()) {
|
||||
if (pt.name().equalsIgnoreCase(type)) {
|
||||
proxyType = pt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (proxyType == null) {
|
||||
System.err.println("Unknown proxy type:" + type);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int p = Integer.parseInt(port);
|
||||
ProxySocket.setProxy(proxyType, ip, p);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,10 @@ import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
import org.parabot.core.proxy.ClassRemapper;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
|
||||
/**
|
||||
@@ -188,8 +186,7 @@ public class ClassPath {
|
||||
protected void loadClass(InputStream in) throws IOException {
|
||||
ClassReader cr = new ClassReader(in);
|
||||
ClassNode cn = new ClassNode();
|
||||
RemappingClassAdapter adapter = new RemappingClassAdapter(cn,new ClassRemapper());
|
||||
cr.accept(adapter, ClassReader.EXPAND_FRAMES);
|
||||
cr.accept(cn, ClassReader.EXPAND_FRAMES);
|
||||
classes.put(cn.name, cn);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.parabot.core.proxy;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class ClassRemapper extends Remapper {
|
||||
private static HashMap<String, String> remapNames = new HashMap<String, String>();
|
||||
static {
|
||||
remapNames.put("java/net/Socket", "org/matt123337/proxy/ProxySocket");
|
||||
remapNames.put("java/net/NetworkInterface", "org/matt123337/spoofer/NetworkInterface");
|
||||
remapNames.put("java/lang/Runtime", "org/matt123337/spoofer/Runtime");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(String str) {
|
||||
String s = remapNames.get(str);
|
||||
if (s != null) {
|
||||
return s;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
package org.parabot.core.proxy;
|
||||
|
||||
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;
|
||||
|
||||
import org.parabot.core.ui.components.LogArea;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
public class ProxySocket extends Socket {
|
||||
|
||||
private static List<ProxySocket>connections = new ArrayList<ProxySocket>();
|
||||
|
||||
private static ProxyType proxyType = ProxyType.HTTP;
|
||||
|
||||
private static int proxyPort = 0;
|
||||
|
||||
private InetAddress addr;
|
||||
private int port;
|
||||
|
||||
private static InetAddress proxyInetAddress = null;
|
||||
|
||||
private InetSocketAddress cachedAddr;
|
||||
|
||||
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){
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
@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 (proxyInetAddress != null && proxyPort > 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
private void initProxy() throws IOException {
|
||||
LogArea.log("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(1); // number of authentication methods (no auth for now)
|
||||
out.write(0); // the authentication (none)
|
||||
out.flush();
|
||||
|
||||
if (in.read() != 0x05) // remote proxy version
|
||||
throw new IOException("Proxy server is not supported!");
|
||||
if (in.read() != 0x00) // make sure shit is a vaild request
|
||||
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
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
public static void setType(ProxyType pt) {
|
||||
proxyType = pt;
|
||||
}
|
||||
|
||||
public static int getConnectionCount() {
|
||||
return connections.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.parabot.core.proxy;
|
||||
|
||||
public enum ProxyType {
|
||||
SOCKS5,SOCKS4,HTTP
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package org.parabot.core.spoofer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class NetworkInterface {
|
||||
|
||||
public static byte[] mac = new byte[] { 11, 11, 11, 11, 11, 11 };
|
||||
|
||||
private static byte[] realMac;
|
||||
|
||||
private static NetworkInterface cached;
|
||||
|
||||
static {
|
||||
try {
|
||||
mac = getRealHardwareAddress();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getHardwareAddress() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public static byte[] getRealHardwareAddress() throws SocketException {
|
||||
if (realMac != null)
|
||||
return realMac;
|
||||
Enumeration<java.net.NetworkInterface> nis = java.net.NetworkInterface
|
||||
.getNetworkInterfaces();
|
||||
while (nis.hasMoreElements()) {
|
||||
try {
|
||||
byte[] b = nis.nextElement().getHardwareAddress();
|
||||
if (b.length == 0)
|
||||
continue;
|
||||
return realMac = b;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return mac;
|
||||
}
|
||||
|
||||
public static NetworkInterface getByInetAddress(InetAddress addr) {
|
||||
if (cached == null)
|
||||
cached = new NetworkInterface();
|
||||
return cached;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package org.parabot.core.spoofer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.parabot.core.ui.components.LogArea;
|
||||
|
||||
public class Runtime {
|
||||
|
||||
private java.lang.Runtime rt;
|
||||
|
||||
private static Runtime cached;
|
||||
|
||||
private Runtime(java.lang.Runtime rt){
|
||||
this.rt = rt;
|
||||
}
|
||||
|
||||
|
||||
public void addShutdownHook(Thread t){
|
||||
rt.addShutdownHook(t);
|
||||
}
|
||||
|
||||
public int availableProcessors(){
|
||||
return rt.availableProcessors();
|
||||
}
|
||||
|
||||
public void exit(int i){
|
||||
rt.exit(i);
|
||||
}
|
||||
|
||||
public Process exec(String str) throws IOException{
|
||||
LogArea.log("RT:" + str);
|
||||
System.out.println("RT:" + str);
|
||||
return rt.exec(str);
|
||||
}
|
||||
|
||||
public Process exec(String[] cmdarray) throws IOException{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int i = 0; i < cmdarray.length;i++){
|
||||
sb.append(cmdarray[i] + (i < cmdarray.length - 1 ? "," : ""));
|
||||
}
|
||||
LogArea.log("RT: {" + sb + "}");
|
||||
System.out.println("RT: {" + sb + "}");
|
||||
return rt.exec(cmdarray);
|
||||
}
|
||||
|
||||
public long freeMemory(){
|
||||
return rt.freeMemory();
|
||||
}
|
||||
|
||||
public void gc(){
|
||||
rt.gc();
|
||||
}
|
||||
|
||||
public long maxMemory(){
|
||||
return rt.maxMemory();
|
||||
}
|
||||
|
||||
public static Runtime getRuntime(){
|
||||
if(cached == null)
|
||||
cached = new Runtime(java.lang.Runtime.getRuntime());
|
||||
return cached;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,11 +100,6 @@ public class BotUI extends JFrame implements ActionListener {
|
||||
case "Exit":
|
||||
System.exit(0);
|
||||
break;
|
||||
case "Network":
|
||||
NetworkUI proxy = NetworkUI.getInstance();
|
||||
proxy.setLocationRelativeTo(BotUI.getInstance());
|
||||
proxy.setVisible(true);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid command: ");
|
||||
}
|
||||
|
||||
@@ -1,279 +0,0 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.net.SocketException;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
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;
|
||||
|
||||
import org.parabot.core.proxy.ProxySocket;
|
||||
import org.parabot.core.proxy.ProxyType;
|
||||
import org.parabot.core.spoofer.NetworkInterface;
|
||||
import org.parabot.core.ui.components.LogArea;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
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;
|
||||
|
||||
JList<?>[] macList;
|
||||
JScrollPane[] macScrollList;
|
||||
|
||||
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());
|
||||
super.setVisible(b);
|
||||
}
|
||||
|
||||
private void initGUI() {
|
||||
proxyType = new JComboBox<ProxyType>(ProxyType.values());
|
||||
proxyType.setSelectedItem(ProxySocket.getProxyType());
|
||||
|
||||
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];
|
||||
try {
|
||||
mac = NetworkInterface.getRealHardwareAddress();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
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 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();
|
||||
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(macBox);
|
||||
|
||||
main.add(Box.createVerticalStrut(5));
|
||||
main.add(submit);
|
||||
|
||||
ret.add(main);
|
||||
ret.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@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) {
|
||||
byte[] mac = new byte[macList.length];
|
||||
for (int i = 0; i < mac.length; i++)
|
||||
mac[i] = (byte) Short.parseShort((String) macList[i].getSelectedValue(), 16);
|
||||
NetworkInterface.mac = mac;
|
||||
|
||||
try {
|
||||
if(ProxySocket.getConnectionCount() > 0) {
|
||||
try {
|
||||
LogArea.log("Closing Existing Connections...");
|
||||
ProxySocket.closeConnections();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
ProxySocket.setProxy((ProxyType) proxyType.getSelectedItem(),
|
||||
proxyHost.getText(), proxyPort.getValue());
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected Document createDefaultModel() {
|
||||
return new IntTextDocument();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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