mirror of
https://github.com/mirror/jdownloader.git
synced 2024-11-23 12:09:43 +00:00
- updated SubPanelLiveHeaderReconnect & SubPanelCLRReconnect panels
- removed unadded AutoConfig button and old router-autoconfig-fragments - updated miglayout to 3.7.3.1 and added code resources to this new version git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@11292 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
parent
d122b2eec1
commit
5d615a9017
@ -9,7 +9,11 @@
|
||||
<classpathentry kind="lib" path="ressourcen/libs/js.jar"/>
|
||||
<classpathentry kind="lib" path="ressourcen/libs/savemytube.jar"/>
|
||||
<classpathentry kind="lib" path="ressourcen/libs/cobra.jar"/>
|
||||
<classpathentry kind="lib" path="ressourcen/libs/miglayout.jar"/>
|
||||
<classpathentry kind="lib" path="ressourcen/libs/miglayout.jar" sourcepath="ressourcen/code-ressourcen/miglayout-3.7.3.1-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/JDownloader/ressourcen/code-ressourcen/miglayout-3.7.3.1-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="ressourcen/libs/swingworker.jar" sourcepath="ressourcen/code-ressourcen/swing-worker-src-1.2.zip">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/jd/ressourcen/code-ressourcen/swing-worker-doc-1.2.zip!/"/>
|
||||
|
BIN
ressourcen/code-ressourcen/miglayout-3.7.3.1-javadoc.jar
Normal file
BIN
ressourcen/code-ressourcen/miglayout-3.7.3.1-javadoc.jar
Normal file
Binary file not shown.
BIN
ressourcen/code-ressourcen/miglayout-3.7.3.1-sources.jar
Normal file
BIN
ressourcen/code-ressourcen/miglayout-3.7.3.1-sources.jar
Normal file
Binary file not shown.
Binary file not shown.
@ -20,6 +20,7 @@ import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
@ -294,7 +295,7 @@ public class MethodSelection extends ConfigPanel implements ActionListener {
|
||||
|
||||
};
|
||||
cp.initPanel();
|
||||
cp.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
|
||||
return cp;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import jd.config.ConfigContainer;
|
||||
import jd.config.ConfigEntry;
|
||||
@ -42,8 +40,6 @@ public class SubPanelCLRReconnect extends ConfigPanel implements ActionListener
|
||||
|
||||
private GUIConfigEntry ip;
|
||||
|
||||
private GUIConfigEntry script;
|
||||
|
||||
public SubPanelCLRReconnect(Configuration configuration) {
|
||||
super();
|
||||
this.configuration = configuration;
|
||||
@ -59,35 +55,19 @@ public class SubPanelCLRReconnect extends ConfigPanel implements ActionListener
|
||||
|
||||
@Override
|
||||
public void initPanel() {
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
buttons.setLayout(new MigLayout("ins 0, wrap 3"));
|
||||
|
||||
// JDUtilities.addToGridBag(panel, btnSelectRouter, 0, 0, 1, 1, 0, 1,
|
||||
// insets, GridBagConstraints.NONE, GridBagConstraints.WEST);
|
||||
|
||||
btnFindIP = new JButton(JDL.L("gui.config.liveHeader.btnfindip", "Fetch Router IP"));
|
||||
btnFindIP.addActionListener(this);
|
||||
buttons.add(btnFindIP, "width 160!");
|
||||
|
||||
panel.add(buttons, "spanx,gapleft 0,gaptop 10");
|
||||
panel.setLayout(new MigLayout("ins 5, wrap 2", "[fill]10[grow,fill]"));
|
||||
panel.add(btnFindIP, "wrap");
|
||||
|
||||
addGUIConfigEntry(new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_USER, JDL.L("gui.config.liveheader.user", "Login User (->%%%user%%%)"))));
|
||||
addGUIConfigEntry(new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_PASSWORDFIELD, configuration, Configuration.PARAM_HTTPSEND_PASS, JDL.L("gui.config.liveheader.password", "Login Password (->%%%pass%%%)"))));
|
||||
addGUIConfigEntry(ip = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_IP, JDL.L("gui.config.liveheader.routerip", "RouterIP (->%%%routerip%%%)"))));
|
||||
addGUIConfigEntry(new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTAREA, configuration, Configuration.PARAM_HTTPSEND_REQUESTS_CLR, null)));
|
||||
|
||||
panel.add(new JScrollPane((script = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTAREA, configuration, Configuration.PARAM_HTTPSEND_REQUESTS_CLR, JDL.L("gui.config.liveheader.script", "HTTP Script")))).getInput()[0]), "gaptop 10,spanx,gapright 20,pushy, growy");
|
||||
|
||||
script.setData(configuration.getStringProperty(Configuration.PARAM_HTTPSEND_REQUESTS_CLR));
|
||||
// routerScript = new GUIConfigEntry();
|
||||
// this.entries.add(routerScript);
|
||||
|
||||
add(panel);
|
||||
// add(routerScript);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSpecial() {
|
||||
configuration.setProperty(Configuration.PARAM_HTTPSEND_REQUESTS_CLR, script.getText());
|
||||
this.setBorder(null);
|
||||
this.add(panel);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
@ -34,7 +34,6 @@ import jd.gui.swing.dialog.ImportRouterDialog;
|
||||
import jd.gui.swing.jdgui.views.settings.ConfigPanel;
|
||||
import jd.gui.swing.jdgui.views.settings.GUIConfigEntry;
|
||||
import jd.router.FindRouterIP;
|
||||
import jd.router.GetRouterInfo;
|
||||
import jd.router.reconnectrecorder.Gui;
|
||||
import jd.utils.locale.JDL;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
@ -45,8 +44,6 @@ public class SubPanelLiveHeaderReconnect extends ConfigPanel implements ActionLi
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
private JButton btnAutoConfig;
|
||||
|
||||
private JButton btnFindIP;
|
||||
|
||||
private JButton btnSelectRouter;
|
||||
@ -128,60 +125,36 @@ public class SubPanelLiveHeaderReconnect extends ConfigPanel implements ActionLi
|
||||
if (pw == null || pw.matches("[\\s]*")) {
|
||||
pass.setData(data[5]);
|
||||
}
|
||||
|
||||
}
|
||||
} else if (e.getSource() == btnAutoConfig) {
|
||||
GetRouterInfo.autoConfig(pass, user, ip, script);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPanel() {
|
||||
JPanel buttons = new JPanel(new MigLayout("ins 0"));
|
||||
|
||||
this.setLayout(new MigLayout("ins 0 20 0 20, wrap 2", "[grow 20,fill][grow,fill]", "[]5[]5[]"));
|
||||
btnSelectRouter = new JButton(JDL.L("gui.config.liveheader.selectrouter", "Select Router"));
|
||||
btnSelectRouter.addActionListener(this);
|
||||
add(btnSelectRouter, "gaptop 10");
|
||||
add(panel, "spany 3,gapbottom 20");
|
||||
buttons.add(btnSelectRouter, "sizegroup btns");
|
||||
|
||||
btnFindIP = new JButton(JDL.L("gui.config.liveheader.btnfindip", "Fetch Router IP"));
|
||||
btnFindIP.addActionListener(this);
|
||||
add(btnFindIP);
|
||||
// JDUtilities.addToGridBag(panel, btnFindIP, 1, 0, 1, 1, 0, 1, insets,
|
||||
// GridBagConstraints.NONE, GridBagConstraints.WEST);
|
||||
buttons.add(btnFindIP, "sizegroup btns");
|
||||
|
||||
btnAutoConfig = new JButton(JDL.L("gui.config.liveheader.autoconfig", "Config router automatically"));
|
||||
btnAutoConfig.addActionListener(this);
|
||||
|
||||
// add(btnAutoConfig,"aligny top");
|
||||
// JDUtilities.addToGridBag(panel, btnAutoConfig, 2, 0,
|
||||
// GridBagConstraints.REMAINDER, 1, 0, 1, insets,
|
||||
// GridBagConstraints.NONE, GridBagConstraints.WEST);
|
||||
btnRouterRecorder = new JButton(JDL.L("gui.config.liveheader.recorder", "Create Reconnect Script"));
|
||||
btnRouterRecorder.addActionListener(this);
|
||||
add(btnRouterRecorder, "aligny top");
|
||||
panel.setLayout(new MigLayout("ins 10 10 10 0,wrap 2", "[fill,grow 10]10[fill,grow]"));
|
||||
user = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_USER, JDL.L("gui.config.httpliveheader.user", "User")));
|
||||
addGUIConfigEntry(user);
|
||||
pass = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_PASSWORDFIELD, configuration, Configuration.PARAM_HTTPSEND_PASS, JDL.L("gui.config.httpliveheader.password", "Password")));
|
||||
addGUIConfigEntry(pass);
|
||||
ip = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_IP, JDL.L("gui.config.httpliveheader.routerip", "Router's ip")));
|
||||
addGUIConfigEntry(ip);
|
||||
buttons.add(btnRouterRecorder, "sizegroup btns");
|
||||
|
||||
add(new JScrollPane((script = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTAREA, configuration, Configuration.PARAM_HTTPSEND_REQUESTS, JDL.L("gui.config.httpliveheader.script", "Reconnection Script")))).getInput()[0]), "gaptop 10,spanx,gapright 20,pushy, growy");
|
||||
panel.setLayout(new MigLayout("ins 5, wrap 2", "[fill]10[grow,fill]"));
|
||||
panel.add(buttons, "spanx");
|
||||
|
||||
script.setData(configuration.getStringProperty(Configuration.PARAM_HTTPSEND_REQUESTS));
|
||||
// sp.setBorder(null);
|
||||
// routerScript = new GUIConfigEntry();
|
||||
// this.entries.add(routerScript);
|
||||
addGUIConfigEntry(user = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_USER, JDL.L("gui.config.httpliveheader.user", "User"))));
|
||||
addGUIConfigEntry(pass = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_PASSWORDFIELD, configuration, Configuration.PARAM_HTTPSEND_PASS, JDL.L("gui.config.httpliveheader.password", "Password"))));
|
||||
addGUIConfigEntry(ip = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTFIELD, configuration, Configuration.PARAM_HTTPSEND_IP, JDL.L("gui.config.httpliveheader.routerip", "Router's ip"))));
|
||||
addGUIConfigEntry(script = new GUIConfigEntry(new ConfigEntry(ConfigContainer.TYPE_TEXTAREA, configuration, Configuration.PARAM_HTTPSEND_REQUESTS, null)));
|
||||
|
||||
// add(routerScript);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSpecial() {
|
||||
configuration.setProperty(Configuration.PARAM_HTTPSEND_REQUESTS, script.getText());
|
||||
this.setBorder(null);
|
||||
this.add(panel);
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import jd.nrouter.RouterUtils;
|
||||
import jd.utils.locale.JDL;
|
||||
|
||||
public class FindRouterIP {
|
||||
|
||||
public static String findIP(GUIConfigEntry ip) {
|
||||
final ProgressController progress = new ProgressController(JDL.L("gui.config.routeripfinder.featchIP", "Search for routers hostname..."), 100, null);
|
||||
|
||||
@ -49,9 +50,8 @@ public class FindRouterIP {
|
||||
}
|
||||
|
||||
public FindRouterIP(final GUIConfigEntry ip) {
|
||||
|
||||
new Thread() {
|
||||
// @Override
|
||||
@Override
|
||||
public void run() {
|
||||
findIP(ip);
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2009 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import jd.controlling.JDLogger;
|
||||
import jd.nutils.OSDetector;
|
||||
import jd.parser.Regex;
|
||||
import jd.utils.JDUtilities;
|
||||
import jd.utils.StringUtil;
|
||||
|
||||
public final class GetMacAdress {
|
||||
/**
|
||||
* Don't let anyone instantiate this class.
|
||||
*/
|
||||
private GetMacAdress() {
|
||||
}
|
||||
|
||||
public static String getMacAddress() throws Exception {
|
||||
try {
|
||||
return GetMacAdress.getMacAddress(RouterInfoCollector.getRouterIP());
|
||||
} catch (Exception e) {
|
||||
JDLogger.exception(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMacAddress(final InetAddress hostAddress) throws Exception {
|
||||
final String resultLine = callArpTool(hostAddress.getHostAddress());
|
||||
String rd = new Regex(resultLine, "..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?").getMatch(-1).replaceAll("-", ":");
|
||||
if (rd == null) return null;
|
||||
rd = rd.replaceAll("\\s", "0");
|
||||
final String[] d = rd.split("[:\\-]");
|
||||
final StringBuilder ret = new StringBuilder(18);
|
||||
for (final String string : d) {
|
||||
if (string.length() < 2) {
|
||||
ret.append('0');
|
||||
}
|
||||
ret.append(string);
|
||||
ret.append(':');
|
||||
}
|
||||
return ret.toString().substring(0, 17);
|
||||
}
|
||||
|
||||
private static String callArpTool(final String ipAddress) throws Exception {
|
||||
if (OSDetector.isWindows()) return callArpToolWindows(ipAddress);
|
||||
return callArpToolDefault(ipAddress);
|
||||
}
|
||||
|
||||
private static String callArpToolWindows(final String ipAddress) throws Exception {
|
||||
final ProcessBuilder pb = new ProcessBuilder(new String[] { "ping", ipAddress });
|
||||
pb.start();
|
||||
final String[] parts = JDUtilities.runCommand("arp", new String[] { "-a" }, null, 10).split(StringUtil.LINE_SEPARATOR);
|
||||
pb.directory();
|
||||
for (final String part : parts) {
|
||||
if (part.indexOf(ipAddress) > -1) { return part; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String callArpToolDefault(final String ipAddress) throws Exception {
|
||||
String out = null;
|
||||
final InetAddress hostAddress = InetAddress.getByName(ipAddress);
|
||||
ProcessBuilder pb = null;
|
||||
try {
|
||||
pb = new ProcessBuilder(new String[] { "ping", ipAddress });
|
||||
pb.start();
|
||||
out = JDUtilities.runCommand("arp", new String[] { ipAddress }, null, 10);
|
||||
pb.directory();
|
||||
if (!out.matches("(?is).*((" + hostAddress.getHostName() + "|" + hostAddress.getHostAddress() + ").*..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?|.*..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?.*(" + hostAddress.getHostName() + "|" + hostAddress.getHostAddress() + ")).*")) out = null;
|
||||
} catch (Exception e) {
|
||||
if (pb != null) pb.directory();
|
||||
}
|
||||
if (out == null || out.trim().length() == 0) {
|
||||
try {
|
||||
pb = new ProcessBuilder(new String[] { "ping", ipAddress });
|
||||
pb.start();
|
||||
out = JDUtilities.runCommand("ip", new String[] { "neigh", "show" }, null, 10);
|
||||
pb.directory();
|
||||
if (out != null) {
|
||||
if (!out.matches("(?is).*((" + hostAddress.getHostName() + "|" + hostAddress.getHostAddress() + ").*..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?|.*..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?[:\\-]..?.*(" + hostAddress.getHostName() + "|" + hostAddress.getHostAddress() + ")).*")) {
|
||||
out = null;
|
||||
} else {
|
||||
out = new Regex(out, "(" + hostAddress.getHostName() + "|" + hostAddress.getHostAddress() + ")[^\r\n]*").getMatch(-1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (pb != null) {
|
||||
pb.directory();
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
@ -1,399 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2008 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import jd.config.Configuration;
|
||||
import jd.controlling.JDLogger;
|
||||
import jd.controlling.reconnect.ReconnectMethod;
|
||||
import jd.controlling.reconnect.Reconnecter;
|
||||
import jd.gui.UserIO;
|
||||
import jd.gui.swing.GuiRunnable;
|
||||
import jd.gui.swing.dialog.ProgressDialog;
|
||||
import jd.gui.swing.jdgui.views.settings.GUIConfigEntry;
|
||||
import jd.gui.userio.DummyFrame;
|
||||
import jd.http.Browser;
|
||||
import jd.nutils.JDFlags;
|
||||
import jd.nutils.Threader;
|
||||
import jd.nutils.Threader.WorkerListener;
|
||||
import jd.nutils.jobber.JDRunnable;
|
||||
import jd.utils.JDUtilities;
|
||||
import jd.utils.locale.JDL;
|
||||
|
||||
public class GetRouterInfo {
|
||||
|
||||
private Threader threader = null;
|
||||
private Threader th2 = null;
|
||||
private boolean cancel = false;
|
||||
|
||||
public void cancel() {
|
||||
cancel = true;
|
||||
if (threader != null) {
|
||||
try {
|
||||
threader.interrupt();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else if (th2 != null) {
|
||||
try {
|
||||
th2.interrupt();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Logger logger = JDLogger.getLogger();
|
||||
|
||||
public String username = null;
|
||||
|
||||
public String password = null;
|
||||
|
||||
private ProgressDialog progressBar;
|
||||
|
||||
public GetRouterInfo(ProgressDialog progress) {
|
||||
progressBar = progress;
|
||||
if (progressBar != null) {
|
||||
progressBar.setMaximum(100);
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedHashMap<RInfo, Integer> sortByIntegrety(Map<RInfo, Integer> map) {
|
||||
LinkedList<Entry<RInfo, Integer>> list = new LinkedList<Entry<RInfo, Integer>>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<RInfo, Integer>>() {
|
||||
public int compare(Entry<RInfo, Integer> o1, Entry<RInfo, Integer> o2) {
|
||||
if (o1.getValue().equals((o2).getValue())) {
|
||||
return o2.getKey().compareTo(o1.getKey());
|
||||
} else
|
||||
return o1.getValue().compareTo(o2.getValue());
|
||||
}
|
||||
});
|
||||
LinkedHashMap<RInfo, Integer> result = new LinkedHashMap<RInfo, Integer>();
|
||||
for (Entry<RInfo, Integer> entry : list) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private RInfo checkRouters(HashMap<RInfo, Integer> routers) {
|
||||
int retries = JDUtilities.getConfiguration().getIntegerProperty(ReconnectMethod.PARAM_RETRIES, 5);
|
||||
int wipchange = JDUtilities.getConfiguration().getIntegerProperty(ReconnectMethod.PARAM_WAITFORIPCHANGE, 20);
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_RETRIES, 0);
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_WAITFORIPCHANGE, 10);
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_USER, username);
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_PASS, password);
|
||||
int size = routers.size();
|
||||
int i = 0;
|
||||
for (Entry<RInfo, Integer> info2 : routers.entrySet()) {
|
||||
if (cancel) return null;
|
||||
if (info2.getKey().getReconnectMethode() != null) {
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_RECONNECT_TYPE, ReconnectMethod.LIVEHEADER);
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_REQUESTS, info2.getKey().getReconnectMethode());
|
||||
} else if (info2.getKey().getReconnectMethodeClr() != null) {
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_RECONNECT_TYPE, ReconnectMethod.CLR);
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_REQUESTS_CLR, info2.getKey().getReconnectMethodeClr());
|
||||
} else
|
||||
continue;
|
||||
setProgressText(JDL.L("gui.config.routeripfinder.status.testingrouter", "Testing router") + " " + info2.getKey().getRouterName() + " ...");
|
||||
setProgress(i++ * 100 / size);
|
||||
|
||||
JDUtilities.getConfiguration().save();
|
||||
if (Reconnecter.waitForNewIP(1, true)) {
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_RETRIES, retries);
|
||||
JDUtilities.getConfiguration().setProperty(ReconnectMethod.PARAM_WAITFORIPCHANGE, wipchange);
|
||||
JDUtilities.getConfiguration().save();
|
||||
setProgress(100);
|
||||
return info2.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public RInfo getRouterData() {
|
||||
|
||||
setProgressText(JDL.L("gui.config.routeripfinder.status.collectingrouterinfo", "Collecting router information..."));
|
||||
|
||||
final RInfo infos = RouterInfoCollector.getRInfo(RouterInfoCollector.RInfo_ROUTERSEARCH);
|
||||
infos.setReconnectMethode(null);
|
||||
infos.setReconnectMethodeClr(null);
|
||||
th2 = new Threader();
|
||||
final class isalvs {
|
||||
boolean isAlv = true;
|
||||
ArrayList<String> meths = null;
|
||||
HashMap<String, String> SCPDs = null;
|
||||
}
|
||||
final isalvs isalv = new isalvs();
|
||||
final JDRunnable jupnp = new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
|
||||
try {
|
||||
UPnPInfo upnp = new UPnPInfo(InetAddress.getByName(infos.getRouterHost()));
|
||||
if (upnp.met != null && upnp.met.size() != 0) {
|
||||
isalv.SCPDs = upnp.SCPDs;
|
||||
isalv.meths = upnp.met;
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
isalv.isAlv = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
th2.getBroadcaster().addListener(new WorkerListener() {
|
||||
|
||||
public void onThreadException(Threader th, JDRunnable job, Throwable e) {
|
||||
}
|
||||
|
||||
public void onThreadFinished(Threader th, JDRunnable runnable) {
|
||||
if (runnable == jupnp) {
|
||||
isalv.isAlv = false;
|
||||
th2.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void onThreadStarts(Threader threader, JDRunnable runnable) {
|
||||
}
|
||||
|
||||
});
|
||||
th2.add(jupnp);
|
||||
th2.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
try {
|
||||
|
||||
LinkedHashMap<RInfo, Integer> routers = new LinkedHashMap<RInfo, Integer>();
|
||||
int upnp = 0;
|
||||
Browser br = new Browser();
|
||||
LinkedHashMap<String, String> he = new LinkedHashMap<String, String>();
|
||||
if (infos.getRouterHost() != null) he.put("RouterHost", infos.getRouterHost());
|
||||
if (infos.getRouterHost() != null) he.put("RouterMAC", infos.getRouterMAC());
|
||||
if (infos.getPageHeader() != null) he.put("PageHeader", SQLRouterData.replaceTimeStamps(infos.getPageHeader()));
|
||||
if (infos.getRouterErrorPage() != null) he.put("RouterErrorPage", SQLRouterData.replaceTimeStamps(infos.getRouterErrorPage()));
|
||||
he.put("HTMLTagCount", "" + infos.countHtmlTags());
|
||||
ArrayList<RInfo> ra;
|
||||
try {
|
||||
setProgressText(JDL.L("gui.config.routeripfinder.status.downloadlingsimilarmethods", "Downloading similar router methods..."));
|
||||
String st = br.postPage("http://service.jdownloader.org/routerdb/getRouters.php", he);
|
||||
ra = (ArrayList<RInfo>) JDUtilities.xmlStringToObjekt(st);
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
setProgressText(JDL.L("gui.config.routeripfinder.status.sortingmethods", "Sorting router methods..."));
|
||||
for (RInfo info : ra) {
|
||||
if (info.isHaveUpnpReconnect()) upnp++;
|
||||
|
||||
if (info.getReconnectMethodeClr() != null) {
|
||||
Integer b = info.compare(infos);
|
||||
info.setIntegrety(200);
|
||||
routers.put(info, b);
|
||||
} else if (info.getReconnectMethode() != null) {
|
||||
Integer b = info.compare(infos);
|
||||
if (info.getIntegrety() > 3) {
|
||||
routers.put(info, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
routers = sortByIntegrety(routers);
|
||||
HashMap<String, RInfo> methodes = new HashMap<String, RInfo>();
|
||||
Iterator<Entry<RInfo, Integer>> inter = routers.entrySet().iterator();
|
||||
while (inter.hasNext()) {
|
||||
Map.Entry<RInfo, Integer> entry = inter.next();
|
||||
RInfo meth = methodes.get(entry.getKey().getReconnectMethode());
|
||||
if (meth != null) {
|
||||
meth.setIntegrety(meth.getIntegrety() + entry.getKey().getIntegrety());
|
||||
inter.remove();
|
||||
} else
|
||||
methodes.put(entry.getKey().getReconnectMethode(), entry.getKey());
|
||||
}
|
||||
routers = sortByIntegrety(routers);
|
||||
if (upnp > 0) {
|
||||
while (isalv.isAlv) {
|
||||
try {
|
||||
wait();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
if (isalv.meths == null) {
|
||||
|
||||
UserIO.setCountdownTime(600);
|
||||
int ret = UserIO.getInstance().requestConfirmDialog(0, null, JDL.LF("gui.config.liveheader.warning.upnpinactive", "Please activate UPnP support in your router's network configuration. <br><a href=\"http://%s\">Go to Router</a><br><a href=\"http://jdownloader.org/knowledge/wiki/reconnect/upnp\">Wiki article: Upnp in Router</a><br>Click OK when you activate UPnP support in router or Cancel to skip.", infos.getRouterHost()), UserIO.getInstance().getIcon(UserIO.ICON_WARNING), null, null);
|
||||
UserIO.setCountdownTime(-1);
|
||||
if (JDFlags.hasAllFlags(ret, UserIO.RETURN_OK)) {
|
||||
try {
|
||||
setProgressText(JDL.L("gui.config.routeripfinder.status.testingupnp", "Testing UPnP..."));
|
||||
for (int i = 0; i < 30 && !cancel; i++) {
|
||||
setProgress(i++ * 100 / 30);
|
||||
UPnPInfo upnpd = new UPnPInfo(InetAddress.getByName(infos.getRouterHost()), 10000);
|
||||
if (upnpd.met != null) {
|
||||
infos.setUPnPSCPDs(upnpd.SCPDs);
|
||||
if (upnpd.met != null && upnpd.met.size() != 0) {
|
||||
|
||||
isalv.SCPDs = upnpd.SCPDs;
|
||||
isalv.meths = upnpd.met;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_IP, infos.getRouterHost());
|
||||
RInfo router = null;
|
||||
if (isalv.meths != null) {
|
||||
HashMap<RInfo, Integer> upnprouters = new HashMap<RInfo, Integer>();
|
||||
for (String info : isalv.meths) {
|
||||
RInfo tempinfo = new RInfo();
|
||||
tempinfo.setRouterHost(infos.getRouterHost());
|
||||
tempinfo.setRouterIP(infos.getRouterIP());
|
||||
tempinfo.setUPnPSCPDs(isalv.SCPDs);
|
||||
tempinfo.setReconnectMethode(info);
|
||||
tempinfo.setRouterName("UPNP:" + tempinfo.getRouterName());
|
||||
upnprouters.put(tempinfo, 1);
|
||||
}
|
||||
router = checkRouters(upnprouters);
|
||||
|
||||
}
|
||||
if (router == null) {
|
||||
router = checkRouters(routers);
|
||||
}
|
||||
setProgress(100);
|
||||
if (router != null) {
|
||||
infos.setRouterName(router.getRouterName());
|
||||
infos.setReconnectMethode(router.getReconnectMethode());
|
||||
infos.setReconnectMethodeClr(router.getReconnectMethodeClr());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JDLogger.exception(e);
|
||||
}
|
||||
setProgress(100);
|
||||
}
|
||||
});
|
||||
th2.startAndWait();
|
||||
if (infos.getReconnectMethode() != null || infos.getReconnectMethodeClr() != null)
|
||||
return infos;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setProgress(final int val) {
|
||||
new GuiRunnable<Object>() {
|
||||
|
||||
// @Override
|
||||
public Object runSave() {
|
||||
if (progressBar != null) {
|
||||
progressBar.setValue(val);
|
||||
} else {
|
||||
logger.info(val + "%");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
private void setProgressText(String text) {
|
||||
if (progressBar != null) {
|
||||
progressBar.setString(text);
|
||||
progressBar.setStringPainted(true);
|
||||
} else {
|
||||
logger.info(text);
|
||||
}
|
||||
}
|
||||
|
||||
public static void autoConfig(final Object pass, final Object user, final Object ip, final Object routerScript) {
|
||||
|
||||
final ProgressDialog progress = new ProgressDialog(DummyFrame.getDialogParent(), JDL.L("gui.config.liveheader.progress.message", "JDownloader will search for your router settings"), null, false, true);
|
||||
final GetRouterInfo routerInfo = new GetRouterInfo(progress);
|
||||
final Thread th = new Thread() {
|
||||
// @Override
|
||||
public void run() {
|
||||
String pw = "";
|
||||
String username = "";
|
||||
String ipadresse = null;
|
||||
if (pass instanceof GUIConfigEntry) {
|
||||
pw = (String) ((GUIConfigEntry) pass).getText();
|
||||
username = (String) ((GUIConfigEntry) user).getText();
|
||||
ipadresse = (String) ((GUIConfigEntry) ip).getText();
|
||||
} else if (pass instanceof JTextField) {
|
||||
pw = ((JTextField) pass).getText();
|
||||
username = ((JTextField) user).getText();
|
||||
ipadresse = ((JTextField) ip).getText();
|
||||
}
|
||||
if (ipadresse != null && !ipadresse.matches("\\s*")) JDUtilities.getConfiguration().getStringProperty(Configuration.PARAM_HTTPSEND_IP, ipadresse);
|
||||
if (username != null && !username.matches("[\\s]*")) {
|
||||
routerInfo.username = username;
|
||||
}
|
||||
if (pw != null && !pw.matches("[\\s]*")) {
|
||||
routerInfo.password = pw;
|
||||
}
|
||||
RInfo data = routerInfo.getRouterData();
|
||||
if (data == null) {
|
||||
progress.setVisible(false);
|
||||
progress.dispose();
|
||||
UserIO.getInstance().requestMessageDialog(JDL.L("gui.config.liveheader.warning.notfound", "JDownloader can't detect your router settings."));
|
||||
return;
|
||||
}
|
||||
if (routerScript != null && routerScript instanceof GUIConfigEntry) {
|
||||
((GUIConfigEntry) routerScript).setData(data.getReconnectMethode());
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_ROUTERNAME, data.getRouterName());
|
||||
}
|
||||
|
||||
JDUtilities.getConfiguration().setProperty(Configuration.PARAM_HTTPSEND_ROUTERNAME, data.getRouterName());
|
||||
progress.setVisible(false);
|
||||
progress.dispose();
|
||||
UserIO.getInstance().requestMessageDialog(JDL.LF("gui.config.liveheader.warning.routertype", "You have a %s", data.getRouterName()));
|
||||
|
||||
}
|
||||
};
|
||||
th.start();
|
||||
progress.setThread(th);
|
||||
progress.setVisible(true);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
while (th.isAlive()) {
|
||||
try {
|
||||
th.wait();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
routerInfo.cancel();
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,223 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2009 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import jd.parser.Regex;
|
||||
import jd.utils.EditDistance;
|
||||
import jd.utils.JDUtilities;
|
||||
|
||||
public class RInfo implements Serializable, Comparable<RInfo> {
|
||||
|
||||
private static final long serialVersionUID = -2119228262137830055L;
|
||||
|
||||
private boolean haveUpnp = false;
|
||||
private boolean haveUpnpReconnect = false;
|
||||
private int id;
|
||||
private int integrety;
|
||||
private String pageHeader;
|
||||
private String reconnectMethode;
|
||||
private String reconnectMethodeClr;
|
||||
private String routerErrorPage;
|
||||
private String routerHost;
|
||||
private String routerIP;
|
||||
private String routerMAC = null;
|
||||
private String routerName = null;
|
||||
private String routerPage;
|
||||
private String routerPageLoggedIn;
|
||||
|
||||
public transient boolean setPlaceholder = false;
|
||||
|
||||
public int compare(RInfo rInfo) {
|
||||
int ret = 0;
|
||||
if (routerIP != null && !routerIP.equals(rInfo.routerIP)) ret += 50;
|
||||
if (routerHost != null && !routerHost.equals(rInfo.routerHost)) ret += 100;
|
||||
if (routerMAC != null && !routerMAC.equals(rInfo.routerMAC)) ret += 100;
|
||||
ret += EditDistance.getLevenshteinDistance(pageHeader, rInfo.pageHeader);
|
||||
ret += EditDistance.getLevenshteinDistance(routerErrorPage, rInfo.routerErrorPage);
|
||||
ret += EditDistance.getLevenshteinDistance(routerPage, rInfo.routerPage);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int countHtmlTags() {
|
||||
if (routerPage == null) return 0;
|
||||
return new Regex(routerPage, "<[^>]*>").count();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getIntegrety() {
|
||||
return integrety;
|
||||
}
|
||||
|
||||
public String getPageHeader() {
|
||||
return pageHeader;
|
||||
}
|
||||
|
||||
public String getReconnectMethode() {
|
||||
return reconnectMethode;
|
||||
}
|
||||
|
||||
public String getReconnectMethodeClr() {
|
||||
return reconnectMethodeClr;
|
||||
}
|
||||
|
||||
public String getRouterErrorPage() {
|
||||
return routerErrorPage;
|
||||
}
|
||||
|
||||
public String getRouterHost() {
|
||||
return routerHost;
|
||||
}
|
||||
|
||||
public String getRouterIP() {
|
||||
return routerIP;
|
||||
}
|
||||
|
||||
public String getRouterMAC() {
|
||||
return routerMAC;
|
||||
}
|
||||
|
||||
public String getRouterName() {
|
||||
return routerName;
|
||||
}
|
||||
|
||||
public String getRouterPage() {
|
||||
return routerPage;
|
||||
}
|
||||
|
||||
public String getRouterPageLoggedIn() {
|
||||
return routerPageLoggedIn;
|
||||
}
|
||||
|
||||
public boolean isHaveUpnp() {
|
||||
return haveUpnp;
|
||||
}
|
||||
|
||||
public boolean isHaveUpnpReconnect() {
|
||||
return haveUpnpReconnect;
|
||||
}
|
||||
|
||||
public void setHaveUpnp(boolean haveUpnp) {
|
||||
this.haveUpnp = haveUpnp;
|
||||
}
|
||||
|
||||
public void setHaveUpnpReconnect(boolean haveUpnpReconnect) {
|
||||
this.haveUpnpReconnect = haveUpnpReconnect;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = Integer.parseInt(id);
|
||||
}
|
||||
|
||||
public void setIntegrety(int integrety) {
|
||||
this.integrety = integrety;
|
||||
}
|
||||
|
||||
public void setIntegrety(String integrety) {
|
||||
this.integrety = Integer.parseInt(integrety);
|
||||
}
|
||||
|
||||
public void setPageHeader(String pageHeader) {
|
||||
this.pageHeader = SQLRouterData.replaceTimeStamps(pageHeader);
|
||||
}
|
||||
|
||||
public void setReconnectMethode(String reconnectMethode) {
|
||||
this.reconnectMethode = reconnectMethode;
|
||||
}
|
||||
|
||||
public void setReconnectMethodeClr(String reconnectMethodeClr) {
|
||||
this.reconnectMethodeClr = reconnectMethodeClr;
|
||||
}
|
||||
|
||||
public void setRouterErrorPage(String routerErrorPage) {
|
||||
this.routerErrorPage = SQLRouterData.replaceTimeStamps(routerErrorPage);
|
||||
}
|
||||
|
||||
public void setRouterHost(String routerHost) {
|
||||
this.routerHost = routerHost;
|
||||
}
|
||||
|
||||
public void setRouterIP(String routerIP) {
|
||||
this.routerIP = routerIP;
|
||||
}
|
||||
|
||||
public void setRouterMAC(String routerMAC) {
|
||||
if (this.routerMAC == null) {
|
||||
this.routerMAC = routerMAC.replaceAll(" ", "0");
|
||||
if (this.routerMAC.length() > 8) this.routerMAC = this.routerMAC.substring(0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRouterName(String routerName) {
|
||||
this.routerName = routerName;
|
||||
}
|
||||
|
||||
public void setRouterPage(String routerPage) {
|
||||
this.routerPage = SQLRouterData.replaceTimeStamps(routerPage);
|
||||
}
|
||||
|
||||
public void setRouterPageLoggedIn(String routerPageLoggedIn) {
|
||||
this.routerPageLoggedIn = SQLRouterData.replaceTimeStamps(routerPageLoggedIn);
|
||||
}
|
||||
|
||||
public void setUPnPSCPDs(HashMap<String, String> UPnPSCPDs) {
|
||||
|
||||
if (UPnPSCPDs != null) {
|
||||
haveUpnp = true;
|
||||
haveUpnpReconnect = SQLRouterData.haveUpnpReconnect(UPnPSCPDs);
|
||||
String[] infoupnp = SQLRouterData.getNameFormUPnPSCPDs(UPnPSCPDs);
|
||||
String name = null;
|
||||
if (infoupnp != null) {
|
||||
name = infoupnp[0];
|
||||
if (infoupnp[1] != null) name += " " + infoupnp[1];
|
||||
}
|
||||
if (name != null) setRouterName(name);
|
||||
if (getRouterMAC() == null || getRouterMAC().length() == 0) {
|
||||
try {
|
||||
routerMAC = infoupnp[2].replaceAll(" ", "0");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUPnPSCPDs(String pnPSCPDs) {
|
||||
if (pnPSCPDs == null) { return; }
|
||||
HashMap<String, String> UPnPSCPDs = null;
|
||||
try {
|
||||
if (pnPSCPDs != null && pnPSCPDs.length() > 0) UPnPSCPDs = (HashMap<String, String>) JDUtilities.xmlStringToObjekt(pnPSCPDs);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
setUPnPSCPDs(UPnPSCPDs);
|
||||
}
|
||||
|
||||
public int compareTo(RInfo o) {
|
||||
return Integer.valueOf(getIntegrety()).compareTo(Integer.valueOf(o.getIntegrety()));
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2008 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import jd.config.Configuration;
|
||||
import jd.controlling.JDLogger;
|
||||
import jd.controlling.reconnect.HTTPLiveHeader;
|
||||
import jd.controlling.reconnect.ReconnectMethod;
|
||||
import jd.http.Browser;
|
||||
import jd.nrouter.RouterUtils;
|
||||
import jd.nutils.Threader;
|
||||
import jd.nutils.jobber.JDRunnable;
|
||||
import jd.parser.Regex;
|
||||
import jd.utils.JDUtilities;
|
||||
|
||||
public class RouterInfoCollector {
|
||||
|
||||
protected static String reconnectMethode = null;
|
||||
protected static String reconnectMethodeClr = null;
|
||||
public final static int RInfo_UPNP = 1 << 1;
|
||||
public final static int RInfo_MAC = 1 << 2;
|
||||
public final static int RInfo_METHODENAME = 1 << 3;
|
||||
public final static int RInfo_ROUTERPAGE = 1 << 4;
|
||||
public final static int RInfo_ROUTERERROR = 1 << 5;
|
||||
public final static int RInfo_HOSTNAME = 1 << 6;
|
||||
public final static int RInfo_ALL = RInfo_UPNP | RInfo_MAC | RInfo_METHODENAME | RInfo_ROUTERPAGE | RInfo_ROUTERERROR | RInfo_HOSTNAME;
|
||||
public final static int RInfo_ROUTERSEARCH = RInfo_MAC | RInfo_ROUTERPAGE | RInfo_ROUTERERROR | RInfo_HOSTNAME;
|
||||
|
||||
public static boolean isLiveheader() {
|
||||
reconnectMethode = JDUtilities.getConfiguration().getStringProperty(Configuration.PARAM_HTTPSEND_REQUESTS, null);
|
||||
return ((JDUtilities.getConfiguration().getIntegerProperty(ReconnectMethod.PARAM_RECONNECT_TYPE, ReconnectMethod.LIVEHEADER) == ReconnectMethod.LIVEHEADER) && reconnectMethode != null);
|
||||
}
|
||||
|
||||
public static boolean isClr() {
|
||||
reconnectMethodeClr = JDUtilities.getConfiguration().getStringProperty(Configuration.PARAM_HTTPSEND_REQUESTS_CLR, null);
|
||||
return ((JDUtilities.getConfiguration().getIntegerProperty(ReconnectMethod.PARAM_RECONNECT_TYPE, ReconnectMethod.LIVEHEADER) == ReconnectMethod.CLR) && reconnectMethodeClr != null);
|
||||
}
|
||||
|
||||
public static InetAddress getRouterIP() {
|
||||
String routerIp = JDUtilities.getConfiguration().getStringProperty(Configuration.PARAM_HTTPSEND_IP, null);
|
||||
if (routerIp == null || routerIp.matches("\\s*")) return RouterUtils.getAddress(false);
|
||||
try {
|
||||
return InetAddress.getByName(routerIp);
|
||||
} catch (UnknownHostException e) {
|
||||
JDLogger.exception(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RInfo getRInfo(final int infoToCollect) {
|
||||
final RInfo info = new RInfo();
|
||||
final Browser br = new Browser();
|
||||
final InetAddress ia = getRouterIP();
|
||||
try {
|
||||
info.setRouterIP(getRouterIP().getHostAddress());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
Threader th = new Threader();
|
||||
if ((infoToCollect & RInfo_UPNP) != 0) {
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
|
||||
try {
|
||||
UPnPInfo up = new UPnPInfo(ia);
|
||||
info.setUPnPSCPDs(up.SCPDs);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
if ((infoToCollect & RInfo_HOSTNAME) != 0) {
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
try {
|
||||
info.setRouterIP(ia.getHostAddress());
|
||||
info.setRouterHost(ia.getHostName());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
if ((infoToCollect & RInfo_ROUTERERROR) != 0) {
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
try {
|
||||
info.setRouterErrorPage(br.getPage("http://" + ia.getHostName() + "/error404"));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if ((infoToCollect & RInfo_MAC) != 0) {
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
try {
|
||||
info.setRouterMAC(GetMacAdress.getMacAddress(ia));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void go() throws Exception {
|
||||
if ((infoToCollect & RInfo_ROUTERPAGE) != 0) {
|
||||
try {
|
||||
info.setRouterPage(br.getPage("http://" + ia.getHostName()));
|
||||
|
||||
StringBuilder pageHeader = new StringBuilder();
|
||||
Map<String, List<String>> he = br.getHttpConnection().getHeaderFields();
|
||||
for (Entry<String, List<String>> b : he.entrySet()) {
|
||||
if (b.getKey() != null) {
|
||||
pageHeader.append(b.getKey());
|
||||
pageHeader.append(new char[] { ':', ' ' });
|
||||
}
|
||||
boolean bs = false;
|
||||
for (Iterator<String> iterator = b.getValue().iterator(); iterator.hasNext();) {
|
||||
String type = iterator.next();
|
||||
if (bs) {
|
||||
pageHeader.append(';');
|
||||
}
|
||||
pageHeader.append(type);
|
||||
|
||||
bs = true;
|
||||
}
|
||||
pageHeader.append(new char[] { '\r', '\n' });
|
||||
}
|
||||
info.setPageHeader(pageHeader.toString().trim());
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
if ((infoToCollect & RInfo_METHODENAME) != 0) {
|
||||
if (isLiveheader()) {
|
||||
String rn = JDUtilities.getConfiguration().getStringProperty(Configuration.PARAM_HTTPSEND_ROUTERNAME, null);
|
||||
if (info.getRouterName() == null) {
|
||||
if (rn != null) {
|
||||
{
|
||||
if (!rn.equals("Reconnect Recorder Methode")) info.setRouterName(info.getRouterName());
|
||||
}
|
||||
} else if (!reconnectMethode.matches("\\s")) {
|
||||
for (String[] script : HTTPLiveHeader.getLHScripts()) {
|
||||
if (script[2].trim().equals(reconnectMethode.trim()) && (info.getRouterName() == null || !info.getRouterName().contains(script[0] + " - " + script[1]))) info.setRouterName(info.getRouterName() == null ? script[0] + " - " + script[1] : info.getRouterName() + " | " + script[0] + " - " + script[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rn == null || rn.equals("Reconnect Recorder Methode"))
|
||||
info.setReconnectMethode(SQLRouterData.setPlaceHolder(reconnectMethode));
|
||||
else
|
||||
info.setReconnectMethode(reconnectMethode);
|
||||
|
||||
}
|
||||
if (isClr()) {
|
||||
if (info.getRouterName() == null) {
|
||||
info.setRouterName(new Regex(info.getReconnectMethodeClr(), "<Router name=\"(.*?)\" />").getMatch(0));
|
||||
}
|
||||
info.setReconnectMethodeClr(reconnectMethodeClr);
|
||||
}
|
||||
if (info.getRouterName() == null && info.getRouterPage() != null) {
|
||||
info.setRouterName(new Regex(info.getRouterPage(), "<title>(.*?)</title>").getMatch(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
th.startAndWait();
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2009 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import jd.parser.Regex;
|
||||
|
||||
public class SQLRouterData {
|
||||
|
||||
public static String setPlaceHolder(String data) {
|
||||
if (data == null) return null;
|
||||
String reg = new Regex(data, "(\\&aa|password|pws|passwor|pass|\\@\\&ps|^p1|^t1|pswd)=([^\\&]*?)([\\s]+\\[\\[\\[| HTTP|$)").getMatch(1);
|
||||
String pwpat = "%%%pass%%%";
|
||||
if (reg != null && reg.length() == 32 && reg.matches("[a-zA-Z0-9]*")) pwpat = "MD5PasswordL(%%%pass%%%)";
|
||||
data = data.replaceAll("(?is)(\\&aa|password|pws|passwor|pass|\\@\\&ps|^p1|^t1|pswd)=([^\\&$]*?)([\\s]+\\[\\[\\[|\\[\\[\\[| HTTP|$)", "$1=" + pwpat + "$3").replaceAll("(?is)(username|(?<!router)name|user)\\=([^\\&]*?)([\\s]+\\[\\[\\[|\\[\\[\\[| HTTP|$)", "$1=%%%user%%%$3").replaceAll("(?is)=NAME([^\\&]*)\\&PASSWOR", "=NAME%%%user%%%&PASSWOR").replaceAll("(?is)RC=@D=([^\\=]*)=([^\\=]*) HTTP", "RC=@D=%%%pass%%%=%%%user%%% HTTP").replaceAll("(?is)RC=@D([^\\=].*?) HTTP", "RC=@D%%%pass%%%%%%user%%% HTTP");
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String replaceTimeStamps(String data) {
|
||||
if (data == null) return null;
|
||||
return data.replaceAll("[A-Z][a-z]{1,2}, \\d{2} [A-Z][a-z]{1,2} \\d{4} \\d{2}:\\d{2}:\\d{2}( [A-Z]{2,3})", "");
|
||||
}
|
||||
|
||||
public static boolean haveUpnpReconnect(HashMap<String, String> UPnPSCPDs) {
|
||||
if (UPnPSCPDs == null) return false;
|
||||
for (Entry<String, String> element : UPnPSCPDs.entrySet()) {
|
||||
if (element.getValue().contains("ForceTermination")) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String[] getNameFormUPnPSCPDs(HashMap<String, String> UPnPSCPDs) {
|
||||
if (UPnPSCPDs == null) return null;
|
||||
for (Entry<String, String> element : UPnPSCPDs.entrySet()) {
|
||||
if (element.getValue().contains("<modelName>")) {
|
||||
String model = new Regex(element.getValue(), "<modelName>(.*?)</modelName>").getMatch(0);
|
||||
String mac = new Regex(element.getValue(), "<UDN>.*?-.*?-.*?-.*?-([a-zA-Z0-9]{12})").getMatch(0);
|
||||
if (mac != null) mac = mac.replaceAll("..", "$0:").substring(0, 8);
|
||||
String version = null;
|
||||
version = new Regex(element.getValue(), "<modelNumber>(.*?)</modelNumber>").getMatch(0);
|
||||
if (version == null) version = new Regex(element.getValue(), "<friendlyName>[^<]*" + model + " (.*?)[\r\n]?</friendlyName>").getMatch(0);
|
||||
return new String[] { model, version, mac };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
// jDownloader - Downloadmanager
|
||||
// Copyright (C) 2008 JD-Team support@jdownloader.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package jd.router;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import jd.controlling.JDLogger;
|
||||
import jd.http.Browser;
|
||||
import jd.nutils.Threader;
|
||||
import jd.nutils.jobber.JDRunnable;
|
||||
import jd.parser.Regex;
|
||||
|
||||
import org.cybergarage.upnp.ControlPoint;
|
||||
import org.cybergarage.upnp.device.SearchResponseListener;
|
||||
import org.cybergarage.upnp.ssdp.SSDPPacket;
|
||||
import org.hsqldb.lib.StringInputStream;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class UPnPInfo {
|
||||
|
||||
private InetAddress host = null;
|
||||
private SSDPPacket ssdpP = null;
|
||||
public ArrayList<String> met = new ArrayList<String>();
|
||||
public HashMap<String, String> SCPDs = null;
|
||||
|
||||
private void getSCPDURLs(String location) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
String page = new Browser().getPage(location);
|
||||
StringInputStream input = new StringInputStream(page);
|
||||
Document document = builder.parse(input);
|
||||
|
||||
if (SCPDs == null) SCPDs = new HashMap<String, String>();
|
||||
SCPDs.put(location, page);
|
||||
// ---- Get list of nodes to given element tag name ----
|
||||
NodeList ndList = document.getElementsByTagName("SCPDURL");
|
||||
for (int i = 0; i < ndList.getLength(); i++) {
|
||||
getSCPDURLs(ssdpP.getLocation().replaceFirst("(http://.*?)/.*", "$1/" + ndList.item(i).getTextContent().replaceFirst("^\\/", "")));
|
||||
}
|
||||
}
|
||||
|
||||
public UPnPInfo(InetAddress ipadress) {
|
||||
this(ipadress, 10000);
|
||||
}
|
||||
|
||||
private static ArrayList<String> createUpnpReconnect(HashMap<String, String> SCPDs, String desc) throws Exception {
|
||||
|
||||
StringInputStream input = new StringInputStream(SCPDs.get(desc));
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(input);
|
||||
ArrayList<String> terminations = new ArrayList<String>();
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
for (Entry<String, String> ent : SCPDs.entrySet()) {
|
||||
if (ent.getValue().contains("<name>ForceTermination</name>")) {
|
||||
terminations.add(ent.getKey().replaceFirst(".*?\\:\\d+", ""));
|
||||
}
|
||||
|
||||
}
|
||||
if (terminations.size() == 0) return ret;
|
||||
NodeList ndList = document.getElementsByTagName("SCPDURL");
|
||||
|
||||
Node node = null;
|
||||
for (int j = 0; j < ndList.getLength(); j++) {
|
||||
node = ndList.item(j);
|
||||
if (node.getTextContent() != null) {
|
||||
for (String string : terminations) {
|
||||
if (node.getFirstChild().getTextContent().contains(string)) {
|
||||
NodeList cl = node.getParentNode().getChildNodes();
|
||||
HashMap<String, String> meth = new HashMap<String, String>();
|
||||
// System.out.println(cl.getLength());
|
||||
for (int i = 0; i < cl.getLength(); i++) {
|
||||
Node cln = cl.item(i);
|
||||
if (cln.hasChildNodes()) {
|
||||
meth.put(cln.getNodeName(), cln.getTextContent().trim());
|
||||
}
|
||||
}
|
||||
if (!meth.containsKey("serviceType") || !meth.containsKey("controlURL") || !meth.containsKey("SCPDURL")) {
|
||||
continue;
|
||||
}
|
||||
String mett = "[[[HSRC]]]\r\n[[[STEP]]]\r\n[[[REQUEST]]]\r\n";
|
||||
mett += "POST " + meth.get("controlURL") + " HTTP/1.1\r\n";
|
||||
String hostport = new Regex(SCPDs.keySet().iterator().next(), ".*(\\:[\\d]+)").getMatch(0);
|
||||
mett += "Host: %%%routerip%%%" + hostport + "\r\n";
|
||||
mett += "Content-Type: text/xml; charset=\"utf-8\"\r\n";
|
||||
mett += "SoapAction:" + meth.get("serviceType") + "#ForceTermination\r\n\r\n";
|
||||
mett += "<?xml version='1.0' encoding='utf-8'?> <s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <u:ForceTermination xmlns:u='" + meth.get("serviceType") + "' /> </s:Body> </s:Envelope>\r\n";
|
||||
mett += "[[[/REQUEST]]]\r\n[[[/STEP]]]\r\n[[[/HSRC]]]";
|
||||
ret.add(mett);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node = null;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> createUpnpReconnect(HashMap<String, String> SCPDs) throws Exception {
|
||||
for (Entry<String, String> ent : SCPDs.entrySet()) {
|
||||
if (ent.getValue().contains("</UDN>")) { return createUpnpReconnect(SCPDs, ent.getKey()); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UPnPInfo(InetAddress ipaddress, final long waittime) {
|
||||
this.host = ipaddress;
|
||||
if (host == null) host = RouterInfoCollector.getRouterIP();
|
||||
if (host == null) return;
|
||||
final ControlPoint c = new ControlPoint();
|
||||
c.start();
|
||||
final Threader th = new Threader();
|
||||
th.add(new JDRunnable() {
|
||||
|
||||
public void go() throws Exception {
|
||||
try {
|
||||
Thread.sleep(waittime);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
c.stop();
|
||||
th.interrupt();
|
||||
|
||||
}
|
||||
});
|
||||
c.addSearchResponseListener(new SearchResponseListener() {
|
||||
|
||||
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket) {
|
||||
InetAddress ia = ssdpPacket.getRemoteInetAddress();
|
||||
if (ia.getHostAddress().equals(host.getHostAddress())) {
|
||||
ssdpP = ssdpPacket;
|
||||
c.stop();
|
||||
th.interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
th.startAndWait();
|
||||
if (ssdpP == null) return;
|
||||
try {
|
||||
// ---- Parse XML file ----
|
||||
if (ssdpP.getLocation() == null) return;
|
||||
getSCPDURLs(ssdpP.getLocation());
|
||||
met = createUpnpReconnect(SCPDs, ssdpP.getLocation());
|
||||
// ---- Error handling ----
|
||||
} catch (SAXException sxe) {
|
||||
Exception e = (sxe.getException() != null) ? sxe.getException() : sxe;
|
||||
JDLogger.exception(e);
|
||||
} catch (Exception ioe) {
|
||||
JDLogger.exception(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user