Removed Socks Proxy setup from App.java, added new class Proxy under com.rarchives.ripme.utils which allows to set both HTTP Proxy and SOCKS Proxy
This commit is contained in:
parent
75f9c448ea
commit
34ee3a6f60
@ -7,9 +7,7 @@ import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import java.net.Authenticator;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -29,6 +27,7 @@ import com.rarchives.ripme.ui.History;
|
||||
import com.rarchives.ripme.ui.HistoryEntry;
|
||||
import com.rarchives.ripme.ui.MainWindow;
|
||||
import com.rarchives.ripme.ui.UpdateUtils;
|
||||
import com.rarchives.ripme.utils.Proxy;
|
||||
import com.rarchives.ripme.utils.RipUtils;
|
||||
import com.rarchives.ripme.utils.Utils;
|
||||
|
||||
@ -99,26 +98,12 @@ public class App {
|
||||
|
||||
if (cl.hasOption('s')) {
|
||||
String sservfull = cl.getOptionValue('s').trim();
|
||||
if (sservfull.lastIndexOf("@") != -1) {
|
||||
int sservli = sservfull.lastIndexOf("@");
|
||||
String userpw = sservfull.substring(0, sservli);
|
||||
String[] usersplit = userpw.split(":");
|
||||
String user = usersplit[0];
|
||||
String password = usersplit[1];
|
||||
Authenticator.setDefault(new Authenticator(){
|
||||
protected PasswordAuthentication getPasswordAuthentication(){
|
||||
PasswordAuthentication p = new PasswordAuthentication(user, password.toCharArray());
|
||||
return p;
|
||||
}
|
||||
});
|
||||
Proxy.setSocks(sservfull);
|
||||
}
|
||||
|
||||
sservfull = sservfull.substring(sservli + 1);
|
||||
}
|
||||
String[] servsplit = sservfull.split(":");
|
||||
if (servsplit.length == 2) {
|
||||
System.setProperty("socksProxyPort", servsplit[1]);
|
||||
}
|
||||
System.setProperty("socksProxyHost", servsplit[0]);
|
||||
if (cl.hasOption('p')) {
|
||||
String proxyserverfull = cl.getOptionValue('p').trim();
|
||||
Proxy.setHTTPProxy(proxyserverfull);
|
||||
}
|
||||
|
||||
if (cl.hasOption('t')) {
|
||||
@ -269,7 +254,8 @@ public class App {
|
||||
opts.addOption("n", "no-prop-file", false, "Do not create properties file.");
|
||||
opts.addOption("f", "urls-file", true, "Rip URLs from a file.");
|
||||
opts.addOption("v", "version", false, "Show current version");
|
||||
opts.addOption("s", "socks-server", true, "Use socks server ([user:password]@host[:port]");
|
||||
opts.addOption("s", "socks-server", true, "Use socks server ([user:password]@host[:port])");
|
||||
opts.addOption("p", "proxy-server", true, "Use HTTP Proxy server ([user:password]@host[:port])");
|
||||
return opts;
|
||||
}
|
||||
|
||||
|
99
src/main/java/com/rarchives/ripme/utils/Proxy.java
Normal file
99
src/main/java/com/rarchives/ripme/utils/Proxy.java
Normal file
@ -0,0 +1,99 @@
|
||||
package com.rarchives.ripme.utils;
|
||||
|
||||
import java.net.Authenticator;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Proxy/Socks setter
|
||||
*/
|
||||
public class Proxy {
|
||||
private Proxy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the proxy server settings from string, using the format
|
||||
* [user:password]@host[:port].
|
||||
*
|
||||
* @param fullproxy the string to parse
|
||||
* @return HashMap containing proxy server, port, user and password
|
||||
*/
|
||||
private static Map<String, String> parseServer(String fullproxy) {
|
||||
Map<String, String> proxy = new HashMap<String, String>();
|
||||
|
||||
if (fullproxy.lastIndexOf("@") != -1) {
|
||||
int sservli = fullproxy.lastIndexOf("@");
|
||||
String userpw = fullproxy.substring(0, sservli);
|
||||
String[] usersplit = userpw.split(":");
|
||||
proxy.put("user", usersplit[0]);
|
||||
proxy.put("password", usersplit[1]);
|
||||
fullproxy = fullproxy.substring(sservli + 1);
|
||||
}
|
||||
String[] servsplit = fullproxy.split(":");
|
||||
if (servsplit.length == 2) {
|
||||
proxy.put("port", servsplit[1]);
|
||||
}
|
||||
proxy.put("server", servsplit[0]);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a HTTP Proxy.
|
||||
* WARNING: Authenticated HTTP Proxy won't work from jdk1.8.111 unless
|
||||
* passing the flag -Djdk.http.auth.tunneling.disabledSchemes="" to java
|
||||
* see https://stackoverflow.com/q/41505219
|
||||
*
|
||||
* @param fullproxy the proxy, using format [user:password]@host[:port]
|
||||
*/
|
||||
public static void setHTTPProxy(String fullproxy) {
|
||||
Map<String, String> proxyServer = parseServer(fullproxy);
|
||||
|
||||
if (proxyServer.get("user") != null && proxyServer.get("password") != null) {
|
||||
Authenticator.setDefault(new Authenticator(){
|
||||
protected PasswordAuthentication getPasswordAuthentication(){
|
||||
PasswordAuthentication p = new PasswordAuthentication(proxyServer.get("user"), proxyServer.get("password").toCharArray());
|
||||
return p;
|
||||
}
|
||||
});
|
||||
System.setProperty("http.proxyUser", proxyServer.get("user"));
|
||||
System.setProperty("http.proxyPassword", proxyServer.get("password"));
|
||||
System.setProperty("https.proxyUser", proxyServer.get("user"));
|
||||
System.setProperty("https.proxyPassword", proxyServer.get("password"));
|
||||
}
|
||||
|
||||
if (proxyServer.get("port") != null) {
|
||||
System.setProperty("http.proxyPort", proxyServer.get("port"));
|
||||
System.setProperty("https.proxyPort", proxyServer.get("port"));
|
||||
}
|
||||
|
||||
System.setProperty("http.proxyHost", proxyServer.get("server"));
|
||||
System.setProperty("https.proxyHost", proxyServer.get("server"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Socks Proxy Server (globally).
|
||||
*
|
||||
* @param fullsocks the socks server, using format [user:password]@host[:port]
|
||||
*/
|
||||
public static void setSocks(String fullsocks) {
|
||||
|
||||
Map<String, String> socksServer = parseServer(fullsocks);
|
||||
if (socksServer.get("user") != null && socksServer.get("password") != null) {
|
||||
Authenticator.setDefault(new Authenticator(){
|
||||
protected PasswordAuthentication getPasswordAuthentication(){
|
||||
PasswordAuthentication p = new PasswordAuthentication(socksServer.get("user"), socksServer.get("password").toCharArray());
|
||||
return p;
|
||||
}
|
||||
});
|
||||
System.setProperty("java.net.socks.username", socksServer.get("user"));
|
||||
System.setProperty("java.net.socks.password", socksServer.get("password"));
|
||||
}
|
||||
if (socksServer.get("port") != null) {
|
||||
System.setProperty("socksProxyPort", socksServer.get("port"));
|
||||
}
|
||||
|
||||
System.setProperty("socksProxyHost", socksServer.get("server"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user