diff --git a/pom.xml b/pom.xml index 7633b9fba..e73454601 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.tonikelope MegaBasterd - 7.17 + 7.18 jar diff --git a/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java b/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java index 15b46147d..447860a78 100644 --- a/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java +++ b/src/main/java/com/tonikelope/megabasterd/LabelTranslatorSingleton.java @@ -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"); diff --git a/src/main/java/com/tonikelope/megabasterd/MainPanel.java b/src/main/java/com/tonikelope/megabasterd/MainPanel.java index 4b2809ec6..f4237ab76 100644 --- a/src/main/java/com/tonikelope/megabasterd/MainPanel.java +++ b/src/main/java/com/tonikelope/megabasterd/MainPanel.java @@ -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); }); diff --git a/src/main/java/com/tonikelope/megabasterd/SettingsDialog.form b/src/main/java/com/tonikelope/megabasterd/SettingsDialog.form index 7280c8182..5148a071a 100644 --- a/src/main/java/com/tonikelope/megabasterd/SettingsDialog.form +++ b/src/main/java/com/tonikelope/megabasterd/SettingsDialog.form @@ -185,7 +185,7 @@ - + @@ -556,7 +556,7 @@ - + diff --git a/src/main/java/com/tonikelope/megabasterd/SettingsDialog.java b/src/main/java/com/tonikelope/megabasterd/SettingsDialog.java index a6b36b492..1f4a460db 100644 --- a/src/main/java/com/tonikelope/megabasterd/SettingsDialog.java +++ b/src/main/java/com/tonikelope/megabasterd/SettingsDialog.java @@ -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))) diff --git a/src/main/java/com/tonikelope/megabasterd/SmartMegaProxyManager.java b/src/main/java/com/tonikelope/megabasterd/SmartMegaProxyManager.java index f826b9c4c..eb178dda9 100644 --- a/src/main/java/com/tonikelope/megabasterd/SmartMegaProxyManager.java +++ b/src/main/java/com/tonikelope/megabasterd/SmartMegaProxyManager.java @@ -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 _proxy_list; + private static final HashMap 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 custom_clean_list = new LinkedHashMap<>();; + LinkedHashMap custom_clean_list = new LinkedHashMap<>(); + + HashMap 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; + } + } + } diff --git a/src/main/resources/images/mbasterd_screen.png b/src/main/resources/images/mbasterd_screen.png index 533babf09..c56f2d48e 100644 Binary files a/src/main/resources/images/mbasterd_screen.png and b/src/main/resources/images/mbasterd_screen.png differ