Added support for proxies with authentication in the SmartProxy custom list

Format is -> IP:PORT[@user:password_b64] (PASSWORD NEEDS TO BE BASE64 ENCODED)

Example of proxy with 'myuser:mypass' -> 192.168.1.1:12345@myuser:bXlwYXNzd29yZA==
This commit is contained in:
tonikelope 2020-02-25 13:14:58 +01:00
parent 8f78d0bfdf
commit 6976c7ce3e
7 changed files with 84 additions and 9 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>7.17</version>
<version>7.18</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -39,7 +39,7 @@ public class LabelTranslatorSingleton {
private void Spanish() {
_addTranslation("Execute this command when MEGA download limit is reached:", "Ejecutar este comando cuando se alcance el límite de descarga de MEGA:");
_addTranslation("Use this proxy list (instead of the one included in MegaBasterd) Format is PROXY:PORT", "Usar esta lista de proxys (en vez de la incluida en MegaBasterd) El formato es PROXY:PUERTO");
_addTranslation("Use this proxy list (instead of the one included in MegaBasterd) Format is IP:PORT[@user:password_b64]", "Usar esta lista de proxys (en vez de la incluida en MegaBasterd) El formato es IP:PUERTO[@usuario:password_b64]");
_addTranslation("Waiting for completion handler ... ***DO NOT EXIT MEGABASTERD NOW***", "Esperando manejador de finalización ... ***NO CIERRES MEGABASTERD EN ESTE MOMENTO***");
_addTranslation("Finishing calculating CBC-MAC code (this could take a while) ... ***DO NOT EXIT MEGABASTERD NOW***", "Terminando de calcular código CBC-MAC (esto podría llevar tiempo) ... ***NO CIERRES MEGABASTERD EN ESTE MOMENTO***");
_addTranslation("Split content in different uploads", "Separar contenido en diferentes subidas");

View File

@ -2,6 +2,7 @@ package com.tonikelope.megabasterd;
import static com.tonikelope.megabasterd.DBTools.*;
import static com.tonikelope.megabasterd.MiscTools.*;
import com.tonikelope.megabasterd.SmartMegaProxyManager.SmartProxyAuthenticator;
import static com.tonikelope.megabasterd.Transference.*;
import java.awt.AWTException;
import java.awt.Color;
@ -21,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import static java.lang.Integer.parseInt;
import static java.lang.System.exit;
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
@ -55,7 +57,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
public static final String VERSION = "7.17";
public static final String VERSION = "7.18";
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
@ -357,6 +359,8 @@ public final class MainPanel {
MainPanel tthis = this;
THREAD_POOL.execute(() -> {
Authenticator.setDefault(new SmartProxyAuthenticator());
_proxy_manager = new SmartMegaProxyManager(null, tthis);
});

View File

@ -185,7 +185,7 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="rec_smart_proxy_label" max="32767" attributes="0"/>
<Component id="rec_smart_proxy_label" min="-2" pref="542" max="-2" attributes="0"/>
<Component id="custom_proxy_list_label" alignment="0" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" max="32767" attributes="0"/>
</Group>
@ -556,7 +556,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="12" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Use this proxy list (instead of the one included in MegaBasterd) Format is PROXY:PORT"/>
<Property name="text" type="java.lang.String" value="Use this proxy list (instead of the one included in MegaBasterd) Format is IP:PORT[@user:password_b64]"/>
</Properties>
</Component>
</SubComponents>

View File

@ -832,7 +832,7 @@ public class SettingsDialog extends javax.swing.JDialog {
custom_proxy_textarea.addMouseListener(new ContextMenuMouseListener());
custom_proxy_list_label.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
custom_proxy_list_label.setText("Use this proxy list (instead of the one included in MegaBasterd) Format is PROXY:PORT");
custom_proxy_list_label.setText("Use this proxy list (instead of the one included in MegaBasterd) Format is IP:PORT[@user:password_b64]");
javax.swing.GroupLayout downloads_panelLayout = new javax.swing.GroupLayout(downloads_panel);
downloads_panel.setLayout(downloads_panelLayout);
@ -883,7 +883,7 @@ public class SettingsDialog extends javax.swing.JDialog {
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, downloads_panelLayout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(downloads_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(rec_smart_proxy_label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(rec_smart_proxy_label, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(custom_proxy_list_label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1))))
.addGap(0, 0, Short.MAX_VALUE)))

View File

@ -3,11 +3,16 @@ package com.tonikelope.megabasterd;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.logging.Level;
@ -25,6 +30,7 @@ public final class SmartMegaProxyManager {
private static final Logger LOG = Logger.getLogger(SmartMegaProxyManager.class.getName());
private volatile String _proxy_list_url;
private final LinkedHashMap<String, Long> _proxy_list;
private static final HashMap<String, String> PROXY_LIST_AUTH = new HashMap<>();
private final MainPanel _main_panel;
public SmartMegaProxyManager(String proxy_list_url, MainPanel main_panel) {
@ -89,7 +95,9 @@ public final class SmartMegaProxyManager {
String custom_proxy_list = DBTools.selectSettingValue("custom_proxy_list");
LinkedHashMap<String, Long> custom_clean_list = new LinkedHashMap<>();;
LinkedHashMap<String, Long> custom_clean_list = new LinkedHashMap<>();
HashMap<String, String> custom_clean_list_auth = new HashMap<>();
if (custom_proxy_list != null) {
@ -101,7 +109,17 @@ public final class SmartMegaProxyManager {
for (String proxy : custom_list) {
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
System.out.println(proxy);
if (proxy.trim().contains("@")) {
String[] proxy_parts = proxy.trim().split("@");
custom_clean_list_auth.put(proxy_parts[0], proxy_parts[1]);
custom_clean_list.put(proxy_parts[0], current_time);
} else if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
custom_clean_list.put(proxy, current_time);
}
}
@ -114,6 +132,13 @@ public final class SmartMegaProxyManager {
_proxy_list.putAll(custom_clean_list);
}
if (!custom_clean_list_auth.isEmpty()) {
PROXY_LIST_AUTH.clear();
PROXY_LIST_AUTH.putAll(custom_clean_list_auth);
}
}
if (custom_clean_list.isEmpty() && _proxy_list_url != null && _proxy_list_url.length() > 0) {
@ -146,10 +171,24 @@ public final class SmartMegaProxyManager {
_proxy_list.clear();
PROXY_LIST_AUTH.clear();
Long current_time = System.currentTimeMillis();
for (String proxy : proxy_list) {
if (proxy.trim().contains("@")) {
String[] proxy_parts = proxy.trim().split("@");
PROXY_LIST_AUTH.put(proxy_parts[0], proxy_parts[1]);
_proxy_list.put(proxy_parts[0], current_time);
} else if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
_proxy_list.put(proxy, current_time);
}
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
_proxy_list.put(proxy, current_time);
}
@ -167,6 +206,8 @@ public final class SmartMegaProxyManager {
LOG.log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
}
System.out.println(PROXY_LIST_AUTH);
} catch (MalformedURLException ex) {
LOG.log(Level.SEVERE, ex.getMessage());
} catch (IOException ex) {
@ -179,4 +220,34 @@ public final class SmartMegaProxyManager {
}
}
public static class SmartProxyAuthenticator extends Authenticator {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
String auth_data;
if ((auth_data = PROXY_LIST_AUTH.get(ipaddr.getHostAddress() + ":" + String.valueOf(port))) != null) {
try {
String[] auth_data_parts = auth_data.split(":");
String user = auth_data_parts[0];
String password = new String(MiscTools.BASE642Bin(auth_data_parts[1]), "UTF-8");
return new PasswordAuthentication(user, password.toCharArray());
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(SmartMegaProxyManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 KiB

After

Width:  |  Height:  |  Size: 199 KiB