Added Network command args (-auth for authentication, -mac for mac address, and -proxy to set proxy)

This commit is contained in:
matt123337@hotmail.com
2015-03-05 13:22:46 -05:00
parent 8a09818828
commit 5fb9fa3826
3 changed files with 150 additions and 109 deletions
+133 -103
View File
@@ -4,12 +4,16 @@ import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.forum.AccountManager;
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.ServerSelector;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -23,117 +27,143 @@ import java.net.URL;
* @see <a href="http://www.parabot.org">Homepage</a>
*/
public final class Landing {
private static String username;
private static String password;
private static String username;
private static String password;
public static void main(String... args) throws IOException {
parseArgs(args);
public static void main(String... args) throws IOException {
parseArgs(args);
Core.verbose("Debug mode: " + Core.inDebugMode());
Core.verbose("Debug mode: " + Core.inDebugMode());
try {
Core.verbose("Setting look and feel: "
+ UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable t) {
t.printStackTrace();
}
try {
Core.verbose("Setting look and feel: "
+ UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable t) {
t.printStackTrace();
}
if (!Core.inDebugMode() && !Core.isValid()) {
UILog.log(
"Updates",
"Please download the newest version of parabot at http://www.parabot.org/",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!Core.inDebugMode() && !Core.isValid()) {
UILog.log(
"Updates",
"Please download the newest version of parabot at http://www.parabot.org/",
JOptionPane.INFORMATION_MESSAGE);
return;
}
Core.verbose("Validating directories...");
Directories.validate();
Core.verbose("Validating account manager...");
AccountManager.validate();
Core.verbose("Validating directories...");
Directories.validate();
Core.verbose("Validating account manager...");
AccountManager.validate();
if (getCredentials() != null && getCredentials().length == 2){
if ((username = getCredentials()[0]) != null && (password = getCredentials()[1]) != null){
new BotUI(username, password);
}
username = null;
password = null;
}else if (username != null && password != null) {
new BotUI(username, password);
username = null;
password = null;
return;
}
if (getCredentials() != null && getCredentials().length == 2) {
if ((username = getCredentials()[0]) != null
&& (password = getCredentials()[1]) != null) {
new BotUI(username, password);
}
username = null;
password = null;
} else if (username != null && password != null) {
new BotUI(username, password);
username = null;
password = null;
return;
}
Core.verbose("Starting login gui...");
new BotUI(null, null);
}
Core.verbose("Starting login gui...");
new BotUI(null, null);
}
/**
* TODO
* Returns an array of string containing only the username and password
* @return String array with username and password
*/
private static String[] getCredentials(){
try {
BufferedReader bufferedReader = WebUtil.getReader(new URL(Configuration.GET_PASSWORD));
if (bufferedReader.readLine() != null){
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static void parseArgs(String... args) {
for (int i = 0; i < args.length; i++) {
final String arg = args[i].toLowerCase();
switch (arg.toLowerCase()) {
case "-createdirs":
Directories.validate();
System.out.println("Directories created, you can now run parabot.");
System.exit(0);
break;
case "-debug":
Core.setDebug(true);
break;
case "-v":
case "-verbose":
Core.setVerbose(true);
break;
case "-server":
ServerSelector.initServer = args[++i];
break;
case "-login":
username = args[++i];
password = args[++i];
break;
case "-loadlocal":
Core.setLoadLocal(true);
break;
case "-dump":
Core.setDump(true);
break;
case "-scriptsbin":
Directories.setScriptCompiledDirectory(new File(args[++i]));
break;
case "-serversbin":
Directories.setServerCompiledDirectory(new File(args[++i]));
break;
case "-clearcache":
File[] cache = Directories.getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
if (f.exists() && f.canWrite()) {
f.delete();
}
}
}
break;
}
}
}
/**
* TODO Returns an array of string containing only the username and password
*
* @return String array with username and password
*/
private static String[] getCredentials() {
try {
BufferedReader bufferedReader = WebUtil.getReader(new URL(
Configuration.GET_PASSWORD));
if (bufferedReader.readLine() != null) {
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static void parseArgs(String... args) {
for (int i = 0; i < args.length; i++) {
final String arg = args[i].toLowerCase();
switch (arg.toLowerCase()) {
case "-createdirs":
Directories.validate();
System.out
.println("Directories created, you can now run parabot.");
System.exit(0);
break;
case "-debug":
Core.setDebug(true);
break;
case "-v":
case "-verbose":
Core.setVerbose(true);
break;
case "-server":
ServerSelector.initServer = args[++i];
break;
case "-login":
username = args[++i];
password = args[++i];
break;
case "-loadlocal":
Core.setLoadLocal(true);
break;
case "-dump":
Core.setDump(true);
break;
case "-scriptsbin":
Directories.setScriptCompiledDirectory(new File(args[++i]));
break;
case "-serversbin":
Directories.setServerCompiledDirectory(new File(args[++i]));
break;
case "-clearcache":
File[] cache = Directories.getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
if (f.exists() && f.canWrite()) {
f.delete();
}
}
}
break;
case "-mac":
byte[] mac = new byte[6];
String str = args[++i];
if (str.toLowerCase().equals("random")) {
new java.util.Random().nextBytes(mac);
} else {
for(int j = 0; j < 6;j++){
mac[j] = Byte.parseByte(args[++i], 16); // parses a hex number
}
}
NetworkInterface.setMac(mac);
break;
case "-proxy":
ProxyType type = ProxyType.valueOf(args[i++].toUpperCase());
if(type == null){
System.err.println("Invalid proxy type:" + args[i]);
System.exit(1);
return;
}
ProxySocket.setProxy(type, args[++i], Integer.parseInt(args[++i]));
break;
case "-auth":
ProxySocket.auth = true;
ProxySocket.setLogin(args[++i], args[++i]);
break;
}
}
}
}
@@ -59,4 +59,19 @@ public class NetworkInterface {
cached = new NetworkInterface();
return cached;
}
public static void setMac(byte[] mac2) {
System.out.println("Setting mac address to:" + formatMac(mac2));
mac = mac2;
}
public static String formatMac(byte[] mac){
StringBuffer b = new StringBuffer();
for(int i = 0; i < 6;i++){
b.append(String.format("%02X", mac[i]));
if(i < 5)
b.append(':');
}
return b.toString();
}
}
@@ -90,11 +90,7 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
submitButton.addActionListener(this);
byte[] mac = new byte[6];
try {
mac = NetworkInterface.getRealHardwareAddress();
} catch (SocketException e) {
e.printStackTrace();
}
mac = NetworkInterface.mac;
macList = new JList[mac.length];
macScrollList = new JScrollPane[mac.length];
for (int i = 0; i < mac.length; i++) {
@@ -259,7 +255,7 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
for (int i = 0; i < mac.length; i++)
mac[i] = (byte) Short.parseShort(
(String) macList[i].getSelectedValue(), 16);
NetworkInterface.mac = mac;
NetworkInterface.setMac(mac);
try {
if (ProxySocket.getConnectionCount() > 0) {