Removed Ext Browser

Installed Security Sandbox for sun.org.mozilla.javascript.internal Rhino Engine.
Added HTMLUnit Rhino mod 
Removed ExtBrowser. Env.js will do that job someday

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@25767 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
coalado 2014-06-04 10:28:17 +00:00
parent 33820e3e02
commit 31816d47a0
47 changed files with 835 additions and 17559 deletions

View File

@ -10,9 +10,6 @@
</attributes>
</classpathentry>
<classpathentry kind="lib" path="ressourcen/libs/irclib.jar"/>
<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/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!/"/>
@ -86,5 +83,7 @@
<classpathentry kind="lib" path="ressourcen/libs/UPNP/seamless-util.jar"/>
<classpathentry kind="lib" path="ressourcen/libs/UPNP/seamless-xml.jar"/>
<classpathentry kind="lib" path="/AppWorkUtils/libs/proxyVole.jar" sourcepath="C:/Users/Thomas/Downloads/proxy-vole_20131209_src.zip"/>
<classpathentry kind="lib" path="ressourcen/libs/htmlunit-core-js-2.14.jar"/>
<classpathentry kind="lib" path="ressourcen/libs/savemytube.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

View File

@ -1,95 +0,0 @@
package jd;
import java.net.URL;
import jd.http.ext.security.JSPermissionRestricter;
import org.appwork.exceptions.WTFException;
import org.appwork.utils.IO;
import org.jdownloader.scripting.envjs.EnvJS;
public class EnvTest {
public static Object connection(Object a, Object b, Object c) {
return null;
}
public static String readFromFile(String url) {
System.out.println("Read File: " + url);
try {
return IO.readURLToString(new URL(url));
} catch (Throwable e) {
throw new WTFException(e);
}
}
public static void main(String[] args) {
// Init Javascript Sandbox
JSPermissionRestricter.init();
final EnvJS env = new EnvJS() {
public String xhrRequest(String url, String method, String data, String requestHeaders) throws java.io.IOException {
if (url.endsWith("fb.html")) {
return "";
}
return super.xhrRequest(url, method, data, requestHeaders);
};
};
try {
final String link = "http://uploaded......";
// load env.js library
env.init();
env.eval(" var w = new Window(__this__);");
env.eval("console.log(w);");
env.eval("console.log(w.document);");
env.eval("console.log(window);");
env.eval("console.log(document);");
env.eval("document.location = '" + link + "';");
env.eval("try{Envjs.eventLoop();}catch(e){console.log(e+\"\");}");
System.out.println(env.getDocument());
// load page
// String html = br.getPage(link);
// evaluate page
;
// jd.http.ext.security.JSPermissionRestricter.evaluateTrustedString(cx, scope, "document.location = '" + link + "';", "js", 1,
// null);
//
// // actually this js is NOT trusted.
// jd.http.ext.security.JSPermissionRestricter.evaluateTrustedString(cx, scope, js, "js", 1, null);
//
// Object result = cx.evaluateString(scope, "var f=function(){return document.innerHTML;}; f();", "js", 1, null);
// System.out.println("Result:\r\n" + result);
// System.out.println("Duration: " + (System.currentTimeMillis() - start));
// script = org.mozilla.javascript.tools.shell.Main.loadScriptFromSource(cx, "console.log(Recaptcha.th3.exec())", "<stdin>",
// 1, null);
// result = org.mozilla.javascript.tools.shell.Main.evaluateScript(script, cx, scope);
// script = org.mozilla.javascript.tools.shell.Main.loadScriptFromSource(cx, "", "<stdin>", 1, null);
// result = org.mozilla.javascript.tools.shell.Main.evaluateScript(script, cx, scope);
// rcBr.getPage("http://www.google.com/recaptcha/api/reload?c=" + this.challenge + "&k=" + site +
// "&reason=i&type=image&lange=de&th=,8bAyAuXRtl-Wibb4_zT-yMiUdPAAAAAjoAAAAAnYANOWaB2DMBDRXVkfCch7hT43TFM3Xr26pNeEzrB6XjYschGfGhUqLRI5RpsAsFOY6RPG0AEdhmw0WDLzUquOfmkuBSJYD5PvVARPMbDhK1FcztXrpMy0hcjPRGdh1376dJUJ0P_FonFDsd5cfXjJXE7RORlO2mUvesDihcNITxYmqbR2r607dOeZRryJ7oj_-pPcLDqV4OBc3ey2Nnbz5tOYpC-ekM8VUTS8ea5vwzw_uxKytqYrFE6gzPfK6LsEwlqoNcBhvrDDDIAB2EC75toZ4zMJ");
//
// script = org.mozilla.javascript.tools.shell.Main.loadScriptFromSource(cx, rcBr.toString(), "<stdin>", 1, null);
// result = org.mozilla.javascript.tools.shell.Main.evaluateScript(script, cx, scope);
// script = org.mozilla.javascript.tools.shell.Main.loadScriptFromSource(cx, "console.log(Recaptcha.th3.exec());",
// "<stdin>", 1, null);
// result = org.mozilla.javascript.tools.shell.Main.evaluateScript(script, cx, scope);
} catch (Throwable e) {
e.printStackTrace();
}
}
}

View File

@ -1,106 +0,0 @@
package jd;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.appwork.utils.swing.dialog.Dialog;
import org.appwork.utils.swing.dialog.DialogCanceledException;
import org.appwork.utils.swing.dialog.DialogClosedException;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class HTMLUnitTest {
public static void main(String[] args) throws Throwable {
// testUploaded();
testRecaptcha();
}
private static void testRecaptcha() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException, DialogClosedException, DialogCanceledException {
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "trace");
final WebClient webClient = new WebClient(BrowserVersion.CHROME) {
public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
System.out.println("Load " + webRequest.getUrl());
WebResponse ret = super.loadWebResponse(webRequest);
// System.out.println(ret.getContentAsString());
return ret;
}
};
final HtmlPage page = webClient.getPage("https://www.google.com/recaptcha/demo/ajax");
List<DomElement> buttons = page.getElementsByTagName("input");
((HtmlButtonInput) buttons.get(0)).click();
Thread.sleep(10000);
System.out.println(1);
String pageAsXml = page.asXml();
HtmlImage image = (HtmlImage) page.getElementById("recaptcha_challenge_image");
File file = new File("recaptcha_" + System.currentTimeMillis() + ".png");
image.saveAs(file);
Dialog.getInstance().showConfirmDialog(0, "Imagee", "", new ImageIcon(ImageIO.read(file)), null, null);
System.out.println(1);
//
// pageAsText = page.asText();
// HtmlImage image = (HtmlImage) page.getElementById("recaptcha_challenge_image");
// image.saveAs(new File("D:\\recaptcha" + System.currentTimeMillis() + ".png"));
// // Page img = webClient.getPage(image.getSrcAttribute());
// webClient.closeAllWindows();
}
private static void testUploaded() throws Throwable {
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "trace");
final WebClient webClient = new WebClient(BrowserVersion.CHROME) {
public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
System.out.println("Load " + webRequest.getUrl());
WebResponse ret = super.loadWebResponse(webRequest);
System.out.println(ret.getContentAsString());
return ret;
}
};
final HtmlPage page = webClient.getPage("http://uploaded.net/fi....");
String pageAsXml = page.asXml();
String pageAsText = page.asText();
DomNodeList<DomElement> buttons = page.getElementsByTagName("button");
for (int i = 0; i < buttons.size(); i++) {
HtmlButton bt = (HtmlButton) buttons.get(i);
Page res = bt.click();
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(1);
break;
}
pageAsXml = page.asXml();
pageAsText = page.asText();
HtmlImage image = (HtmlImage) page.getElementById("recaptcha_challenge_image");
image.saveAs(new File("D:\\recaptcha" + System.currentTimeMillis() + ".png"));
// Page img = webClient.getPage(image.getSrcAttribute());
webClient.closeAllWindows();
}
}

View File

@ -55,7 +55,6 @@ import jd.controlling.proxy.ProxyController;
import jd.gui.swing.MacOSApplicationAdapter;
import jd.gui.swing.jdgui.JDGui;
import jd.http.Browser;
import jd.http.ext.security.JSPermissionRestricter;
import jd.plugins.DownloadLink;
import jd.utils.JDUtilities;
@ -110,6 +109,8 @@ import org.jdownloader.images.NewTheme;
import org.jdownloader.logging.LogController;
import org.jdownloader.osevents.OperatingSystemEventSender;
import org.jdownloader.plugins.controller.host.HostPluginController;
import org.jdownloader.scripting.JSHtmlUnitPermissionRestricter;
import org.jdownloader.scripting.JSPermissionRestricter;
import org.jdownloader.settings.AutoDownloadStartOption;
import org.jdownloader.settings.GeneralSettings;
import org.jdownloader.settings.GraphicalUserInterfaceSettings;
@ -257,7 +258,20 @@ public class SecondLevelLaunch {
public static void mainStart(final String args[]) {
SecondLevelLaunch.LOG = LogController.GL;
/* setup JSPermission */
try {
JSPermissionRestricter.init();
} catch (final Throwable e) {
SecondLevelLaunch.LOG.log(e);
}
try {
JSHtmlUnitPermissionRestricter.init();
} catch (final Throwable e) {
SecondLevelLaunch.LOG.log(e);
}
// Mac OS specific
if (CrossSystem.isMac()) {
// Set MacApplicationName
@ -629,12 +643,6 @@ public class SecondLevelLaunch {
}
});
CrossSystem.setBrowserCommandLine(CFG_GENERAL.BROWSER_COMMAND_LINE.getValue());
/* setup JSPermission */
try {
JSPermissionRestricter.init();
} catch (final Throwable e) {
SecondLevelLaunch.LOG.log(e);
}
// init

View File

@ -1,73 +0,0 @@
package jd.http.ext;
import java.util.ArrayList;
import java.util.regex.Pattern;
import jd.http.Request;
import org.appwork.utils.logging.Log;
public class AdBlocker implements AdBlockerInterface {
private static final AdBlocker INSTANCE = new AdBlocker();
public static AdBlocker getInstance() {
return INSTANCE;
}
private java.util.List<Pattern> blackList;
private java.util.List<Pattern> whiteList;
private AdBlocker() {
this.blackList = new ArrayList<Pattern>();
// Google & Adsense
blackList.add(Pattern.compile(".*\\.doubleclick\\..*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*partner\\.googleadservices\\..*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*\\.googlesyndication\\..*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*\\.google\\..*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*harrenmedianetwork.*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*rubiconproject.*", Pattern.CASE_INSENSITIVE));
blackList.add(Pattern.compile(".*scorecardresearch.*", Pattern.CASE_INSENSITIVE));
// addthis
blackList.add(Pattern.compile(".*\\.addthis\\.com.*", Pattern.CASE_INSENSITIVE));
this.whiteList = new ArrayList<Pattern>();
// google login
whiteList.add(Pattern.compile("https://www.google.com/accounts/ServiceLogin.*"));
}
public boolean doBlockRequest(Request request) {
String url = request.getUrl();
for (Pattern p : whiteList) {
if (p.matcher(url).matches()) {
//
Log.L.info("ADWhitelist: " + url);
return false;
//
}
}
for (Pattern p : blackList) {
if (p.matcher(url).matches()) {
//
Log.L.info("Adblocked: " + url);
return true;
//
}
}
return false;
}
public String prepareScript(String text, String source) {
// TODO Auto-generated method stub
if (source != null) { return text; }
String rez = text.replaceAll("(\\s*G._google[^;]*.)", "\r\n/*BlockedByAdblocker $1*/");
rez = rez.replaceAll("(\\s*google_ad[^;]*.)", "\r\n/*BlockedByAdblocker $1*/");
rez = rez.replace("<!--", "");
rez = rez.replace("-->", "");
if (!rez.equals(text)) {
System.out.println(rez);
}
return rez;
}
}

View File

@ -1,11 +0,0 @@
package jd.http.ext;
import jd.http.Request;
public interface AdBlockerInterface {
boolean doBlockRequest(Request request);
String prepareScript(String text, String source);
}

View File

@ -1,146 +0,0 @@
package jd.http.ext;
import java.security.Policy;
import jd.http.Request;
import jd.http.ext.interfaces.BrowserEnviroment;
import jd.parser.Regex;
import org.lobobrowser.html.domimpl.HTMLScriptElementImpl;
public class BasicBrowserEnviroment implements BrowserEnviroment {
private String[] blackList = null;
private String[] whiteList = null;
private AdBlockerInterface adblocker;
public BasicBrowserEnviroment(String[] blackList, String[] whitelist) {
this.blackList = blackList;
this.whiteList = whitelist;
this.setAdblocker(AdBlocker.getInstance());
}
private void setAdblocker(AdBlockerInterface instance) {
adblocker = instance;
}
public AdBlockerInterface getAdblocker() {
return adblocker;
}
public boolean doLoadContent(Request request) {
boolean ret = false;
if (whiteList != null) {
for (String b : whiteList) {
String m = new Regex(request.getUrl().toString(), b).getMatch(-1);
if (m != null && m.equals(request.getUrl().toString())) {
ret = true;
System.out.println("WHITE: " + b);
break;
}
}
}
if (!ret) {
if (adblocker.doBlockRequest(request)) return false;
ret = true;
if (blackList != null) {
for (String b : blackList) {
String m = new Regex(request.getUrl().toString(), b).getMatch(-1);
if (m != null && m.equals(request.getUrl().toString())) {
ret = false;
System.out.println("FILTERED BLACK: " + b);
break;
}
}
}
}
System.out.println("Filter: Accept: " + request.getUrl() + "? choosen : " + ret);
return ret;
}
public void prepareContents(Request request) {
try {
if (request.getHtmlCode() != null) {
request.setHtmlCode(request.getHtmlCode().replaceAll("(filter: progid:DXImageTransform\\.Microsoft\\..*?;)", "/* CSSParserFilter $1*/"));
}
} catch (Exception e) {
}
}
public boolean isImageLoadingEnabled() {
// TODO Auto-generated method stub
return false;
}
public String getAppCodeName() {
// TODO Auto-generated method stub
return "Mozilla";
}
public boolean isAutoProcessSubFrames() {
// TODO Auto-generated method stub
return true;
}
public String getAppMinorVersion() {
// TODO Auto-generated method stub
return null;
}
public String getAppName() {
// TODO Auto-generated method stub
return "Netscape";
}
public String getAppVersion() {
// TODO Auto-generated method stub
return "5.0 (Windows; de)";
}
public String getPlatform() {
// TODO Auto-generated method stub
return "Win32";
}
public String getProduct() {
// TODO Auto-generated method stub
return "Gecko";
}
public Policy getSecurityPolicy() {
// TODO Auto-generated method stub
return null;
}
public String getVendor() {
return null;
}
public boolean isExternalCSSEnabled() {
// TODO Auto-generated method stub
return false;
}
public boolean isInternalCSSEnabled() {
// TODO Auto-generated method stub
return false;
}
public boolean isScriptingEnabled() {
// TODO Auto-generated method stub
return true;
}
public String doScriptFilter(HTMLScriptElementImpl htmlScriptElementImpl, String text) {
if (getAdblocker() == null) return text;
return getAdblocker().prepareScript(text, htmlScriptElementImpl.getSrc());
}
}

View File

@ -1,92 +0,0 @@
package jd.http.ext;
import java.net.URL;
import org.appwork.utils.logging.Log;
import org.lobobrowser.html.domimpl.NodeImpl;
import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Window;
import org.lobobrowser.js.JavaScript;
import org.mozilla.javascript.BaseFunction;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.w3c.dom.Document;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
public class DOMEventListener implements EventListener {
private FrameController owner;
private Object node;
private String type;
private BaseFunction action;
private Object useCapture;
public DOMEventListener(FrameController htmlFrameController, Object nodeImpl, String type, BaseFunction listener, Object useCapture2) {
this.owner = htmlFrameController;
this.node = nodeImpl;
this.type = type;
this.action = listener;
this.useCapture = useCapture2;
}
public FrameController getOwner() {
return owner;
}
public Object getNode() {
return node;
}
public String getType() {
return type;
}
public BaseFunction getAction() {
return action;
}
public Object isUseCapture() {
return useCapture;
}
public void handleEvent(Event evt) {
Context ctx = null;
try {
Document doc = owner.getDocument();
if (doc == null) { throw new IllegalStateException("Element does not belong to a document."); }
if (node instanceof Window) {
ctx = Executor.createContext(new URL(((Window) node).getDocumentNode().getDocumentURI()), ((Window) node).getUserAgentContext());
} else {
ctx = Executor.createContext(((NodeImpl) node).getDocumentURL(), ((NodeImpl) node).getUserAgentContext());
}
Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
if (scope == null) { throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY); }
JavaScript js = JavaScript.getInstance();
Scriptable thisScope = (Scriptable) js.getJavascriptObject(node, scope);
Scriptable eventScriptable = (Scriptable) js.getJavascriptObject(null, thisScope);
// e={bubbles:true,cancelable:true}
// ScriptableObject.defineProperty(thisScope, "event",
// eventScriptable, ScriptableObject.READONLY);
System.out.println("Run Function \r\n" + ctx.decompileFunction(action, 1));
Object result = action.call(ctx, thisScope, thisScope, new Object[1]);
} catch (Throwable thrown) {
Log.exception(thrown);
} finally {
if (ctx != null) Context.exit();
}
}
public void handleEvent() {
handleEvent(null);
}
}

View File

@ -1,344 +0,0 @@
package jd.http.ext;
import java.net.URL;
import java.util.ArrayList;
import jd.http.Browser;
import jd.http.ext.events.ExtBrowserEvent;
import jd.http.ext.events.ExtBrowserEventSender;
import jd.http.ext.events.ExtBrowserListener;
import jd.http.ext.events.JSInteraction;
import jd.http.ext.interfaces.BrowserEnviroment;
import jd.http.ext.security.JSPermissionRestricter;
import jd.parser.Regex;
import org.appwork.utils.logging.Log;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.domimpl.HTMLDocumentImpl;
import org.lobobrowser.html.domimpl.HTMLFrameElementImpl;
import org.lobobrowser.html.domimpl.HTMLIFrameElementImpl;
import org.w3c.dom.html2.HTMLCollection;
public class ExtBrowser {
static {
// this is important to disallow js to execute java methods/classes
try {
JSPermissionRestricter.init();
} catch (Throwable e) {
}
}
public static void main(String args[]) throws ExtBrowserException, InterruptedException {
ExtBrowser br = new ExtBrowser();
br.setBrowserEnviroment(new FullBrowserEnviroment());
Browser.setGlobalLogger(Log.L);
Browser.setGlobalVerbose(true);
br.getCommContext().forceDebug(true);
ExtBrowser eb = new ExtBrowser();
eb.setBrowserEnviroment(new jd.http.ext.BasicBrowserEnviroment(new String[] { ".*templates/linkto.*", ".*cdn.mediafire.com/css/.*", ".*/blank.html" }, null));
try {
eb.getPage("http://www.mediafire.com/?dzmzuzmh2md");
eb.waitForFrame("workframe2", 10000);
System.out.println(eb.getHtmlText());
HTMLCollection links = eb.getDocument().getLinks();
for (int i = 0; i < links.getLength(); i++) {
org.lobobrowser.html.domimpl.HTMLLinkElementImpl l = (org.lobobrowser.html.domimpl.HTMLLinkElementImpl) links.item(i);
System.out.println(l.getOuterHTML());
if (RendererUtilities.isVisible(l)) {
String inner = l.getInnerHTML();
if (inner.toLowerCase().contains("start download")) {
String myURL = l.getAbsoluteHref();
eb.getCommContext().openGetConnection(myURL);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
// br.getPage("http://ifile.it/uvkog7y");
// br.getPage("http://jdownloader.net:8081/advert/jstest.html");
// java.util.List<HTMLFormElementImpl> forms = br.getForms(null);
// String text = br.getHtmlText();
// HTMLSpanElementImpl button = (HTMLSpanElementImpl)
// br.getElementByID(null, "req_btn2");
// br.getInputController().click(button);
// // br.getInputController().mouseClick(button, null, 1, 4);
//
// br = br;
// String str = br.getHtmlText();
// str = str;
// HTMLCollection links = br.getDocument().getLinks();
// for (int i = 0; i < links.getLength(); i++) {
// HTMLLinkElementImpl l = (HTMLLinkElementImpl) links.item(i);
//
// if (l.toString().startsWith("http://download")) {
// HTMLDivElementImpl div = (HTMLDivElementImpl) l.getParentNode();
// AbstractCSS2Properties s = div.getStyle();
// if (s.getTop() == null || !s.getTop().equals("-250px")) {
// String myURL = l.getAbsoluteHref();
// System.out.println("\r\n\r\n" + myURL);
// }
//
// }
// }
// for (int i = 0; i < frames.getLength(); i++) {
// Node frame = frames.item(i);
// if (frame.getAttributes().getNamedItem("id") != null)
// System.out.println("ID: " +
// frame.getAttributes().getNamedItem("id").getNodeValue() + " : " +
// frame.getAttributes().getNamedItem("src").getNodeValue());
//
// }
}
/**
* TODO: this should use AppWorks Statemachine later
*/
public void waitForFrame(final String frameID, int msTimeout) throws InterruptedException {
for (ExtHTMLFrameImpl frame : this.getFrames(null)) {
if (frameID.equalsIgnoreCase(frame.getID()) && frame.getInternalFrameController().isLoaded()) {
System.out.println("Frame already loaded");
return;
}
}
ExtBrowserListener listener = new ExtBrowserListener() {
public void onFrameEvent(ExtBrowserEvent event) {
if (event instanceof FrameStatusEvent) {
if (((FrameStatusEvent) event).getType() == FrameStatusEvent.Types.EVAL_END && frameID.equalsIgnoreCase(((ExtHTMLFrameElement) ((FrameStatusEvent) event).getCaller()).getID())) {
synchronized (this) {
this.notify();
}
}
}
}
};
this.getEventSender().addListener(listener);
synchronized (listener) {
listener.wait(msTimeout);
}
}
// private Element getElementByID(ExtHTMLFrameElement frame, String id) {
// if (frame == null) frame = this.getFrameController();
// Element ret = frame.getDocument().getElementById(id);
// return ret;
// }
// private java.util.List<HTMLFormElementImpl> getForms(ExtHTMLFrameElement
// frame) {
// if (frame == null) frame = this.getFrameController();
// HTMLCollection forms = frame.getDocument().getForms();
// return getList(forms, new ArrayList<HTMLFormElementImpl>());
// }
// @SuppressWarnings("unchecked")
// private <E> java.util.List<E> getList(HTMLCollection forms, java.util.List<E>
// arrayList) {
// for (int i = 0; i < forms.getLength(); i++) {
// arrayList.add((E) forms.item(i));
// }
// return arrayList;
// }
/**
*
* @return The root {@link jd.http.ext.FrameController} of thes Instance
*/
public FrameController getFrameController() {
return this.htmlFrameController;
}
public String getHtmlText() {
return this.getDocument().getInnerHTML();
}
public HTMLDocumentImpl getDocument() {
return this.htmlFrameController.getDocument();
}
// private HTMLDocumentImpl document;
private FrameController htmlFrameController;
private UserAgentDelegate uac;
private Browser commContext;
private String url;
// private InputController inputController;
private ExtBrowserEventSender eventSender;
public ExtBrowser() {
this(new Browser());
}
public ExtBrowserEventSender getEventSender() {
return eventSender;
}
// public void setInputController(InputController inputController) {
// this.inputController = inputController;
// }
public Regex getRegex(final String pattern) {
return htmlFrameController.getRegex(pattern);
}
public ExtBrowser(Browser br) {
uac = new UserAgentDelegate(this);
eventSender = new ExtBrowserEventSender();
// Context.enter().setDebugger(new ExtDebugger(), null);
commContext = br.cloneBrowser();
commContext.setFollowRedirects(true);
commContext.setCookiesExclusive(true);
htmlFrameController = new FrameController(this);
// inputController = new InputController();
}
public void getPage(String url) throws ExtBrowserException {
this.url = url;
try {
htmlFrameController.submitForm("GET", new URL(commContext.getURL(url)), null, null, null);
} catch (Exception e) {
throw new ExtBrowserException(e);
}
}
// private HTMLDocumentImpl createDocument(String url) {
//
// // HTMLDocumentImpl document = new HTMLDocumentImpl(uac, renderContext,
// null, url);
//
// return document;
// }
private BrowserEnviroment browserEnviroment = new BasicBrowserEnviroment(null, null);
public BrowserEnviroment getBrowserEnviroment() {
return browserEnviroment;
}
public void setBrowserEnviroment(BrowserEnviroment userAgent) {
this.browserEnviroment = userAgent;
commContext.setCookiesExclusive(false);
commContext.setCookiesExclusive(true);
}
public UserAgentContext getUserAgentContext() {
return uac;
}
public Browser getCommContext() {
return commContext;
}
public void eval(Browser br) throws ExtBrowserException {
this.url = br.getURL();
commContext = br.cloneBrowser();
commContext.setFollowRedirects(true);
commContext.setCookiesExclusive(true);
commContext.setRequest(br.getRequest());
htmlFrameController.setCommContext(commContext);
try {
htmlFrameController.eval();
} catch (Exception e) {
throw new ExtBrowserException(e);
}
}
public String getUrl() {
return url;
}
/**
* Returns all Subframes of the givven baseFrame
*
* @param baseFrame
* @return
*/
public java.util.List<ExtHTMLFrameImpl> getFrames(ExtHTMLFrameElement baseFrame) {
if (baseFrame == null) baseFrame = getFrameController();
HTMLCollection frames = baseFrame.getHtmlFrameController().getFrames();
java.util.List<ExtHTMLFrameImpl> ret = new ArrayList<ExtHTMLFrameImpl>();
for (int i = 0; i < frames.getLength(); i++) {
if (frames.item(i) instanceof HTMLFrameElementImpl) {
ret.add(new ExtHTMLFrameImpl((HTMLFrameElementImpl) frames.item(i)));
} else {
if (frames.item(i) instanceof HTMLIFrameElementImpl) {
ret.add(new ExtHTMLFrameImpl((HTMLIFrameElementImpl) frames.item(i)));
}
}
}
return ret;
}
public String getScriptableVariable(String string) {
return this.getFrameController().getScriptableVariable(string);
}
public void cleanUp() {
// TODO Auto-generated method stub
}
public void onFrameEvalStart(FrameController htmlFrameController2) {
getEventSender().fireEvent(new FrameStatusEvent(this, htmlFrameController2, FrameStatusEvent.Types.EVAL_START));
}
public void onFrameLoadStart(FrameController htmlFrameController2) {
getEventSender().fireEvent(new FrameStatusEvent(this, htmlFrameController2, FrameStatusEvent.Types.LOAD_START));
}
public void onFrameLoadEnd(FrameController htmlFrameController2) {
getEventSender().fireEvent(new FrameStatusEvent(this, htmlFrameController2, FrameStatusEvent.Types.LOAD_END));
}
public void onFrameEvalEnd(FrameController htmlFrameController2) {
getEventSender().fireEvent(new FrameStatusEvent(this, htmlFrameController2, FrameStatusEvent.Types.EVAL_END));
}
public void onAlert(FrameController htmlFrameController2, String arg0) {
getEventSender().fireEvent(new JSInteraction(this, htmlFrameController2, JSInteraction.Types.ALERT, arg0));
}
public boolean onConfirm(String arg0, FrameController htmlFrameController) {
JSInteraction event = new JSInteraction(this, htmlFrameController, JSInteraction.Types.CONFIRM, arg0);
getEventSender().fireEvent(event);
return event.getAnswer() == JSInteraction.AnswerTypes.OK;
}
public String onPrompt(String arg0, String arg1, FrameController htmlFrameController2) {
JSInteraction event = new JSInteraction(this, htmlFrameController2, JSInteraction.Types.PROMPT, arg0, arg1);
getEventSender().fireEvent(event);
return event.getAnswerString();
}
}

View File

@ -1,15 +0,0 @@
package jd.http.ext;
public class ExtBrowserException extends Exception {
private static final long serialVersionUID = -2957611433056761360L;
public ExtBrowserException(String message) {
super(message);
}
public ExtBrowserException(Throwable cause) {
super(cause);
}
}

View File

@ -1,41 +0,0 @@
package jd.http.ext;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.domimpl.HTMLDocumentImpl;
import org.lobobrowser.html.domimpl.HTMLIFrameElementImpl;
import org.lobobrowser.html.io.WritableLineReader;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
public class ExtHTMLDocumentImpl extends HTMLDocumentImpl {
public ExtHTMLDocumentImpl(UserAgentContext userAgentContext, FrameController htmlFrameController, WritableLineReader wis, String string) {
super(userAgentContext, htmlFrameController, wis, string);
}
public void write(String text) {
super.write(text);
}
public Element createElement(String tagName) throws DOMException {
Element ret = super.createElement(tagName);
if ("iframe".equalsIgnoreCase(tagName)) {
((HTMLIFrameElementImpl) ret).setBrowserFrame(((FrameController) getHtmlRendererContext()).createParentFrameController(new ExtHTMLFrameImpl((HTMLIFrameElementImpl) ret)));
}
return ret;
}
public Element getElementById(String elementId) {
if (elementId.equals("workframe2")) {
System.out.println("workframe2");
}
return super.getElementById(elementId);
}
public void writeln(String text) {
super.writeln(text);
}
}

View File

@ -1,32 +0,0 @@
package jd.http.ext;
import org.lobobrowser.html.domimpl.HTMLDocumentImpl;
import org.lobobrowser.html.domimpl.HTMLElementImpl;
public interface ExtHTMLFrameElement {
public String getFrameBorder();
public String getHeight();
public String getMarginHeight();
public String getMarginWidth();
public String getName();
public String getScrolling();
public String getSrc();
public String getWidth();
public HTMLDocumentImpl getDocument();
public FrameController getHtmlFrameController();
public HTMLElementImpl getImpl();
public String getID();
}

View File

@ -1,131 +0,0 @@
package jd.http.ext;
import org.lobobrowser.html.BrowserFrame;
import org.lobobrowser.html.domimpl.HTMLDocumentImpl;
import org.lobobrowser.html.domimpl.HTMLElementImpl;
import org.lobobrowser.html.domimpl.HTMLFrameElementImpl;
import org.lobobrowser.html.domimpl.HTMLIFrameElementImpl;
public class ExtHTMLFrameImpl implements ExtHTMLFrameElement {
public static enum Type {
IFRAME, FRAME
}
private HTMLElementImpl _impl;
private Type type;
public ExtHTMLFrameImpl(HTMLElementImpl item) {
this._impl = item;
type = (_impl instanceof HTMLFrameElementImpl) ? Type.FRAME : Type.IFRAME;
}
public Type getType() {
return type;
}
public String getFrameBorder() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getFrameBorder();
} else {
return ((HTMLIFrameElementImpl) _impl).getFrameBorder();
}
}
public String getHeight() {
if (type == Type.FRAME) {
return "0 px";
} else {
return ((HTMLIFrameElementImpl) _impl).getHeight();
}
}
public FrameController getHtmlFrameController() {
if (type == Type.FRAME) {
return (FrameController) ((HTMLFrameElementImpl) _impl).getHtmlRendererContext();
} else {
return (FrameController) ((HTMLIFrameElementImpl) _impl).getHtmlRendererContext();
}
}
public HTMLElementImpl getImpl() {
return _impl;
}
public String getMarginHeight() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getMarginHeight();
} else {
return ((HTMLIFrameElementImpl) _impl).getMarginHeight();
}
}
public String getMarginWidth() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getMarginWidth();
} else {
return ((HTMLIFrameElementImpl) _impl).getMarginWidth();
}
}
public String getName() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getName();
} else {
return ((HTMLIFrameElementImpl) _impl).getName();
}
}
public String getScrolling() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getScrolling();
} else {
return ((HTMLIFrameElementImpl) _impl).getScrolling();
}
}
public String getSrc() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getSrc();
} else {
return ((HTMLIFrameElementImpl) _impl).getSrc();
}
}
public String getWidth() {
if (type == Type.FRAME) {
return "0 px";
} else {
return ((HTMLIFrameElementImpl) _impl).getWidth();
}
}
public void setBrowserFrame(BrowserFrame createBrowserFrame) {
if (type == Type.FRAME) {
((HTMLFrameElementImpl) _impl).setBrowserFrame(createBrowserFrame);
} else {
((HTMLIFrameElementImpl) _impl).setBrowserFrame(createBrowserFrame);
}
}
public HTMLDocumentImpl getDocument() {
return this.getHtmlFrameController().getDocument();
}
public String getID() {
if (type == Type.FRAME) {
return ((HTMLFrameElementImpl) _impl).getId();
} else {
return ((HTMLIFrameElementImpl) _impl).getId();
}
}
public FrameController getInternalFrameController() {
if (type == Type.FRAME) {
return (FrameController) ((HTMLFrameElementImpl) _impl).getBrowserFrame();
} else {
return (FrameController) ((HTMLIFrameElementImpl) _impl).getBrowserFrame();
}
}
}

View File

@ -1,281 +0,0 @@
package jd.http.ext;
import java.awt.Image;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.CharacterCodingException;
import java.util.ArrayList;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import jd.http.Browser;
import jd.http.Request;
import jd.http.URLConnectionAdapter;
import org.jdownloader.logging.LogController;
import org.lobobrowser.html.HttpRequest;
import org.lobobrowser.html.ReadyStateChangeListener;
import org.w3c.dom.Document;
public class ExtHTTPRequest implements HttpRequest {
private ExtBrowser browser;
private java.util.List<ReadyStateChangeListener> listener;
private int readyState = NetworkRequest.STATE_UNINITIALIZED;
private Request request;
private boolean asyncFlag;
private Browser br;
private Image image = null;
public ExtHTTPRequest(ExtBrowser browser) {
this.browser = browser;
listener = new ArrayList<ReadyStateChangeListener>();
}
public void abort() {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void addReadyStateChangeListener(ReadyStateChangeListener listener) {
this.listener.add(listener);
}
public String getAllResponseHeaders() {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
private void changeReadyState(int newState) {
boolean dif = newState > 0 && newState != readyState;
if (newState > 0) {
this.readyState = newState;
}
if (dif) {
for (ReadyStateChangeListener l : listener) {
l.readyStateChanged();
}
}
}
public int getReadyState() {
return readyState;
}
public String getResponseHeader(String headerName) {
return request.getResponseHeader(headerName);
}
public Image getResponseImage() {
byte[] byteArray = getResponseBytes();
URLConnectionAdapter connection = request.getHttpConnection();
final String ct = connection.getContentType();
/* check for image content */
if (ct != null && !Pattern.compile("images?/\\w*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(ct).matches()) { throw new IllegalStateException("Content-Type: " + ct); }
// TODO..this is just quick and dirty.. may result in memory leaks
if (this.image == null && byteArray != null) {
final InputStream fake = new ByteArrayInputStream(byteArray);
try {
this.image = ImageIO.read(fake);
} catch (final Exception e) {
e.printStackTrace();
}
}
return this.image;
}
public String getResponseText() {
try {
return request.getHtmlCode();
} catch (CharacterCodingException e) {
LogController.CL().log(e);
return null;
}
}
public Document getResponseXML() {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public int getStatus() {
if (request == null || request.getHttpConnection() == null) return 403;
return request.getHttpConnection().getResponseCode();
}
public String getStatusText() {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void open(String method, String url) throws IOException {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void open(String method, URL url) throws IOException {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void open(String method, URL url, boolean asyncFlag) throws IOException {
open(method, url + "", asyncFlag);
}
public void open(final String method, final String url, final boolean asyncFlag) throws IOException {
// TODO use threadpool for asynch
this.asyncFlag = asyncFlag;
if (method.equalsIgnoreCase("GET")) {
br = browser.getCommContext().cloneBrowser();
request = br.createGetRequest(url);
} else {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
this.changeReadyState(NetworkRequest.STATE_LOADING);
}
public void open(String method, URL url, boolean asyncFlag, String userName) throws IOException {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void open(String method, URL url, boolean asyncFlag, String userName, String password) throws IOException {
RuntimeException e = new RuntimeException("Not implemented");
LogController.CL().log(e);
throw e;
}
public void send(String content) throws IOException {
if (browser.getBrowserEnviroment().doLoadContent(request)) {
if (asyncFlag) {
// use pool
new Thread("Asynchloader") {
public void run() {
try {
br.openRequestConnection(request);
br.loadConnection(null);
browser.getBrowserEnviroment().prepareContents(br.getRequest());
changeReadyState(NetworkRequest.STATE_LOADED);
changeReadyState(NetworkRequest.STATE_INTERACTIVE);
changeReadyState(NetworkRequest.STATE_COMPLETE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
} else {
br.openRequestConnection(request);
changeReadyState(NetworkRequest.STATE_LOADED);
String htmlCode = read(request.getHttpConnection());
request.setHtmlCode(htmlCode);
browser.getBrowserEnviroment().prepareContents(br.getRequest());
changeReadyState(NetworkRequest.STATE_INTERACTIVE);
changeReadyState(NetworkRequest.STATE_COMPLETE);
}
}
}
public static String read(URLConnectionAdapter con) throws IOException {
BufferedReader rd;
InputStreamReader isr;
InputStream is = con.getInputStream();
if (is == null) return null;
String cs = con.getCharset();
if (cs == null) {
/* default encoding ist ISO-8859-1, falls nicht anders angegeben */
isr = new InputStreamReader(is, "ISO-8859-1");
} else {
cs = cs.toUpperCase();
try {
isr = new InputStreamReader(is, cs);
} catch (Exception e) {
// jd.controlling.JDLogger.getLogger().log(java.util.logging.Level.SEVERE,
// "Could not Handle Charset " + cs, e);
try {
isr = new InputStreamReader(is, cs.replace("-", ""));
} catch (Exception e2) {
// jd.controlling.JDLogger.getLogger().log(java.util.logging.Level.SEVERE,
// "Could not Handle Charset " + cs, e);
isr = new InputStreamReader(is);
}
}
}
rd = new BufferedReader(isr);
String line;
StringBuilder htmlCode = new StringBuilder();
/* workaround for premature eof */
try {
while ((line = rd.readLine()) != null) {
htmlCode.append(line + "\r\n");
}
} catch (EOFException e) {
LogController.CL().severe("Try workaround for ");
LogController.CL().log(e);
} catch (IOException e) {
if (e.toString().contains("end of ZLIB") || e.toString().contains("Premature")) {
LogController.CL().severe("Try workaround for ");
LogController.CL().log(e);
} else
throw e;
} finally {
try {
rd.close();
} catch (Exception e) {
}
}
return htmlCode.toString();
}
public byte[] getResponseBytes() {
return this.request.getResponseBytes();
}
}

View File

@ -1,739 +0,0 @@
package jd.http.ext;
import java.awt.Component;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import jd.http.Browser;
import jd.http.Request;
import jd.parser.Regex;
import jd.parser.html.Form;
import jd.parser.html.InputField;
import org.appwork.utils.logging.Log;
import org.lobobrowser.html.BrowserFrame;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.HtmlObject;
import org.lobobrowser.html.HtmlRendererContext;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.domimpl.HTMLDocumentImpl;
import org.lobobrowser.html.domimpl.HTMLElementImpl;
import org.lobobrowser.html.domimpl.HTMLFrameElementImpl;
import org.lobobrowser.html.domimpl.HTMLIFrameElementImpl;
import org.lobobrowser.html.io.WritableLineReader;
import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Window;
import org.lobobrowser.html.js.event.BasicEvent;
import org.lobobrowser.html.js.event.JSEventListener;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.w3c.dom.Document;
import org.w3c.dom.html2.HTMLCollection;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLLinkElement;
/**
* This class represents a single Frame, and thus a single rendercontext. A frame may contain various subframes.
*
* Subframes may work on the DOM of it's parentframe.
*
* @author thomas
*
*/
public class FrameController implements HtmlRendererContext, ExtHTMLFrameElement, BrowserFrame {
// private static final String DOM_CONTENT_LOADED = "DOMContentLoaded";
private ExtBrowser extBrowser;
private HTMLDocumentImpl htmlDocument;
private FrameController parentFrameController;
private ExtHTMLFrameImpl frame = null;
private HashMap<String, ArrayList<JSEventListener>> listenerMap = new HashMap<String, ArrayList<JSEventListener>>();
private boolean loaded;
private Browser comContext;
public ExtHTMLFrameImpl getFrame() {
return frame;
}
public FrameController(ExtBrowser extBrowser) {
this.extBrowser = extBrowser;
comContext = extBrowser.getCommContext();
}
public FrameController(ExtBrowser extBrowser, ExtHTMLFrameImpl f) {
this.extBrowser = extBrowser;
comContext = extBrowser.getCommContext().cloneBrowser();
frame = f;
}
public void alert(String arg0) {
this.extBrowser.onAlert(this, arg0);
}
public void back() {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void blur() {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void close() {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean confirm(String arg0) {
return this.extBrowser.onConfirm(arg0, this);
}
public void focus() {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void forward() {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public String getCurrentURL() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public String getDefaultStatus() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
/**
* For internal use only. Use {@link ExtBrowser#getFrames(FrameController)} or {@link ExtBrowser#getFrames(HTMLFrameElementImpl)}
*/
public HTMLCollection getFrames() {
return htmlDocument.getFrames();
}
public int getHistoryLength() {
// TODO Auto-generated method stub
return 0;
}
public HtmlObject getHtmlObject(HTMLElement arg0) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public String getName() {
if (frame == null) {
return "";
} else {
return frame.getName();
}
}
public String getNextURL() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public HtmlRendererContext getOpener() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public HtmlRendererContext getParent() {
// TODO Auto-generated method stub
return parentFrameController;
}
public String toString() {
if (htmlDocument == null) return "no Doc";
return this.htmlDocument.getInnerHTML();
}
public String getPreviousURL() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public String getStatus() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public HtmlRendererContext getTop() {
HtmlRendererContext ancestor = this.parentFrameController;
if (ancestor == null) { return this; }
return ancestor.getTop();
}
public UserAgentContext getUserAgentContext() {
// TODO Auto-generated method stub
return extBrowser.getUserAgentContext();
}
public void goToHistoryURL(String arg0) {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean isClosed() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean isImageLoadingEnabled() {
// TODO Auto-generated method stub
return extBrowser.getBrowserEnviroment().isImageLoadingEnabled();
}
public boolean isVisitedLink(HTMLLinkElement arg0) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void linkClicked(HTMLElement arg0, URL arg1, String arg2) {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void moveInHistory(int arg0) {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void navigate(URL arg0, String arg1) {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean onContextMenu(HTMLElement arg0, MouseEvent arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean onDoubleClick(HTMLElement arg0, MouseEvent arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean onMouseClick(HTMLElement arg0, MouseEvent arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void onMouseOut(HTMLElement arg0, MouseEvent arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void onMouseOver(HTMLElement arg0, MouseEvent arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public HtmlRendererContext open(String arg0, String arg1, String arg2, boolean arg3) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public HtmlRendererContext open(URL arg0, String arg1, String arg2, boolean arg3) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public String prompt(String arg0, String arg1) {
return this.extBrowser.onPrompt(arg0, arg1, this);
}
public void reload() {
// TODO Auto-generated method stub
// TODO: we do not reload
}
public void resizeBy(int arg0, int arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void resizeTo(int arg0, int arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void scroll(int arg0, int arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void scrollBy(int arg0, int arg1) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void setDefaultStatus(String arg0) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void setOpener(HtmlRendererContext arg0) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void setStatus(String arg0) {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public void submitForm(String method, URL action, String target, String encoding, FormInput[] formInputs) {
try {
this.extBrowser.onFrameLoadStart(this);
final String actualMethod = method.toUpperCase();
if (actualMethod.equals("GET")) {
if (formInputs == null || formInputs.length == 0) {
Request request = comContext.createGetRequest(action + "");
if (extBrowser.getBrowserEnviroment().doLoadContent(request)) {
comContext.openRequestConnection(request);
String htmlCode = ExtHTTPRequest.read(request.getHttpConnection());
request.setHtmlCode(htmlCode);
extBrowser.getBrowserEnviroment().prepareContents(comContext.getRequest());
} else {
return;
}
} else {
Form form = new Form();
form.setAction(action + "");
form.setMethod(Form.MethodType.GET);
for (FormInput i : formInputs) {
if (i.isFile()) {
InputField iff = new InputField(i.getName(), i.getTextValue());
iff.setFileToPost(i.getFileValue());
iff.setType("file");
form.addInputField(iff);
} else {
form.addInputField(new InputField(i.getName(), i.getTextValue()));
}
}
Request request = comContext.createFormRequest(form);
if (extBrowser.getBrowserEnviroment().doLoadContent(request)) {
comContext.openRequestConnection(request);
comContext.loadConnection(null);
} else {
return;
}
}
} else {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
this.extBrowser.onFrameLoadEnd(this);
eval();
} catch (Exception e) {
Log.exception(e);
}
}
public HTMLDocumentImpl getDocument() {
return htmlDocument;
}
public void eval() throws ExtBrowserException {
this.extBrowser.onFrameEvalStart(this);
WritableLineReader wis = new WritableLineReader(new StringReader(comContext + "")) {
public void write(String text) throws IOException {
super.write(text);
System.out.println("Wrote to doc:\r\n" + text);
}
public int read() throws IOException {
int ret = super.read();
// System.out.print(new String(new byte[] { (byte) ret }));
return ret;
}
/*
* (non-Javadoc) Note: Not implicitly thread safe.
*
* @see java.io.Reader#read(byte[], int, int)
*/
public int read(char[] b, int off, int len) throws IOException {
int ret = super.read(b, off, len);
System.out.println("Read " + new String(b));
return ret;
}
};
htmlDocument = new ExtHTMLDocumentImpl(this.getUserAgentContext(), this, wis, comContext.getURL() + "");
try {
htmlDocument.load();
loaded = true;
System.out.println("Load Frames");
if (extBrowser.getBrowserEnviroment().isAutoProcessSubFrames()) {
processFrames();
}
if (this.frame != null) {
if (frame.getSrc() != null && frame.getSrc().length() > 0) {
dispatch(new BasicEvent("load", frame.getImpl()));
}
} else {
dispatch(new BasicEvent("DOMContentLoaded", this.getDocument()));
dispatch(new BasicEvent("load", Window.getWindow(this)));
}
} catch (Exception e) {
throw new ExtBrowserException(e);
} finally {
this.extBrowser.onFrameEvalEnd(this);
}
}
private synchronized ArrayList<JSEventListener> getListenerList(String eventName) {
ArrayList<JSEventListener> ret = listenerMap.get(eventName);
if (ret == null) {
ret = new ArrayList<JSEventListener>();
listenerMap.put(eventName, ret);
}
return ret;
}
public void processFrames() throws ExtBrowserException {
for (ExtHTMLFrameImpl frame : extBrowser.getFrames(this)) {
if (RendererUtilities.isVisible(frame.getImpl())) {
System.out.println("Load frame " + frame.getSrc());
processFrame(frame);
} else {
System.out.println("Frame not loaded... not visible " + frame.getSrc());
}
}
}
public ExtHTMLFrameImpl processFrame(ExtHTMLFrameImpl f) throws ExtBrowserException {
if (f.getImpl() instanceof HTMLIFrameElementImpl) {
if (f.getSrc() != null) {
try {
((FrameController) ((HTMLIFrameElementImpl) f.getImpl()).getBrowserFrame()).submitForm("GET", new URL(comContext.getURL(f.getSrc())), null, null, null);
return f;
} catch (Exception e) {
throw new ExtBrowserException(e);
}
}
}
// TODO normal frames
return null;
}
public Regex getRegex(String pattern) {
// TODO Auto-generated method stub
return new Regex(htmlDocument.getInnerHTML(), pattern);
}
public String getFrameBorder() {
// TODO Auto-generated method stub
return null;
}
public String getHeight() {
// TODO Auto-generated method stub
return null;
}
public FrameController getHtmlFrameController() {
// TODO Auto-generated method stub
return this;
}
public HTMLElementImpl getImpl() {
// TODO Auto-generated method stub
return null;
}
public String getMarginHeight() {
// TODO Auto-generated method stub
return null;
}
public String getMarginWidth() {
// TODO Auto-generated method stub
return null;
}
public String getScrolling() {
// TODO Auto-generated method stub
return null;
}
public String getSrc() {
// TODO Auto-generated method stub
return this.htmlDocument.getDocumentURI();
}
public String getWidth() {
// TODO Auto-generated method stub
return null;
}
public Scriptable getScriptableScope() {
return Window.getWindow(this).getWindowScope();
}
public String evalAndReturn(String script) throws ExtBrowserException {
Scriptable scope = getScriptableScope();
Context cx = null;
try {
cx = Executor.createContext(new URL(this.getDocument().getURL()), extBrowser.getUserAgentContext());
Object result = cx.evaluateString(scope, "function qwertfbkdsiebdfia432hjfd83j(){return " + script + ";} qwertfbkdsiebdfia432hjfd83j();", "<cmd>", 1, null);
String ret = Context.toString(result);
return ret;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
throw new ExtBrowserException(e);
} finally {
if (cx != null) Context.exit();
}
}
public String getScriptableVariable(String string) {
Scriptable scope = getScriptableScope();
return (String) scope.get(string, scope);
}
public void addEventListener(JSEventListener jsEventListener) {
System.out.println("Listener " + jsEventListener);
removeEventListener(jsEventListener);
this.getListenerList(jsEventListener.getName()).add(jsEventListener);
}
public void removeEventListener(JSEventListener jsEventListener) {
java.util.List<JSEventListener> listener = this.getListenerList(jsEventListener.getName());
for (Iterator<JSEventListener> it = listener.iterator(); it.hasNext();) {
JSEventListener l = it.next();
if (l.getName().equals(jsEventListener.getName()) && (l.getCallback() == jsEventListener.getCallback()) && l.getOwner() == jsEventListener.getOwner()) {
it.remove();
return;
}
}
}
public void removeEventListeners(String name) {
this.getListenerList(name).clear();
}
@SuppressWarnings("unchecked")
public boolean dispatch(BasicEvent basicEvent) {
java.util.List<JSEventListener> listener = (ArrayList<JSEventListener>) this.getListenerList(basicEvent.getType()).clone();
boolean ret = false;
for (Iterator<JSEventListener> it = listener.iterator(); it.hasNext();) {
ret |= it.next().dispatch(basicEvent);
// how to handle ret value?
}
return ret;
}
public Component getComponent() {
// TODO Auto-generated method stub
return null;
}
public Document getContentDocument() {
// TODO Auto-generated method stub
return this.getDocument();
}
public HtmlRendererContext getHtmlRendererContext() {
// TODO Auto-generated method stub
return this;
}
public void loadURL(final URL url) {
if (this.getParent() != null && !((FrameController) getParent()).loaded) {
System.out.println("NOT LOADED FRAME " + url + " not loaded yet. QUEUED");
return;
}
// TODO blacklist/(whitelist from browser env
if (extBrowser.getBrowserEnviroment().isAutoProcessSubFrames()) {
System.out.println(this.frame.getImpl() + ".src=" + url);
// AbstractCSS2Properties style = this.frame.getImpl().getStyle();
// String st = this.frame.getImpl().getAttribute("style");
// String vis = style.getVisibility();
// vis = vis;
new Thread("URLLOADER") {
public void run() {
submitForm("GET", url, null, null, null);
}
}.start();
}
}
public void setDefaultMarginInsets(Insets insets) {
// TODO Auto-generated method stub
}
public void setDefaultOverflowX(int overflowX) {
// TODO Auto-generated method stub
}
public void setDefaultOverflowY(int overflowY) {
// TODO Auto-generated method stub
}
public FrameController createParentFrameController(ExtHTMLFrameImpl extHTMLFrameImpl) {
FrameController rContext = new FrameController(this.extBrowser, extHTMLFrameImpl);
rContext.parentFrameController = this;
return rContext;
}
public BrowserFrame createBrowserFrame() {
// TODO Auto-generated method stub
return null;
}
public String getID() {
if (frame == null) return null;
return frame.getID();
}
public boolean isLoaded() {
return this.loaded;
}
public void setCommContext(Browser commContext) {
this.comContext = commContext;
}
// public void addEventListener(Object nodeImpl, String type, BaseFunction
// listener, Object useCapture) {
//
// System.out.println("Registered event " + type + " on " + nodeImpl +
// ": \r\n" + listener);
// removeEventListener(nodeImpl, type, listener, useCapture);
// this.getEventListener(type).add(new DOMEventListener(this, nodeImpl,
// type, listener, useCapture));
//
// }
//
// public void removeEventListener(Object htmlElementImpl, String type,
// BaseFunction listener, Object useCapture) {
// java.util.List<DOMEventListener> list = getEventListener(type);
// for (Iterator<DOMEventListener> it = list.iterator(); it.hasNext();) {
// DOMEventListener next = it.next();
// if (next.getAction() == listener && next.getNode() == htmlElementImpl) {
// it.remove();
// }
// }
//
// }
}

View File

@ -1,36 +0,0 @@
package jd.http.ext;
import jd.http.ext.events.ExtBrowserEvent;
public class FrameStatusEvent extends ExtBrowserEvent {
public FrameStatusEvent(ExtBrowser extBrowser, FrameController htmlFrameController2, Types evalEnd) {
super(extBrowser, htmlFrameController2, evalEnd.ordinal(), null);
}
public Types getType() {
return Types.values()[this.getEventID()];
}
public static enum Types {
/**
* Frame has been loaded and evaluated completly. Only Async calls my
* cange it now
*/
EVAL_END,
/**
* JS EValuation of the frame contents start now
*/
EVAL_START,
/**
* Download of the fram's main content starts now
*/
LOAD_START,
/**
* Download of the frames main content is finished LOAD_END
*/
LOAD_END
}
}

View File

@ -1,16 +0,0 @@
package jd.http.ext;
public class FullBrowserEnviroment extends BasicBrowserEnviroment {
public FullBrowserEnviroment() {
super(null, null);
// TODO Auto-generated constructor stub
}
public boolean isImageLoadingEnabled() {
// TODO Auto-generated method stub
return true;
}
}

View File

@ -1,299 +0,0 @@
package jd.http.ext;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.HtmlRendererContext;
import org.lobobrowser.html.domimpl.HTMLAbstractUIElement;
import org.lobobrowser.html.domimpl.HTMLButtonElementImpl;
import org.lobobrowser.html.domimpl.HTMLInputElementImpl;
import org.lobobrowser.html.domimpl.HTMLLinkElementImpl;
import org.lobobrowser.html.domimpl.HTMLSelectElementImpl;
import org.lobobrowser.html.domimpl.ModelNode;
import org.lobobrowser.html.js.Event;
import org.lobobrowser.html.js.Executor;
import org.mozilla.javascript.Function;
class HtmlController {
private static final Logger logger = Logger.getLogger(HtmlController.class.getName());
private static final HtmlController instance = new HtmlController();
static HtmlController getInstance() {
return instance;
}
/**
* @return True to propagate further and false if the event was consumed.
*/
public boolean onEnterPressed(ModelNode node, InputEvent event) {
if (node instanceof HTMLInputElementImpl) {
HTMLInputElementImpl hie = (HTMLInputElementImpl) node;
if (hie.isSubmittableWithEnterKey()) {
hie.submitForm(null);
return false;
}
}
// No propagation
return false;
}
/**
* @return True to propagate further and false if the event was consumed.
*/
public boolean onMouseClick(ModelNode node, MouseEvent event, int x, int y) {
if (logger.isLoggable(Level.INFO)) {
logger.info("onMouseClick(): node=" + node + ",class=" + node.getClass().getName());
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOnclick();
if (f != null) {
Event jsEvent = new Event("click", uiElement, event, x, y);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return false; }
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
if (!rcontext.onMouseClick(uiElement, event)) { return false; }
}
}
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).navigate();
return false;
} else if (node instanceof HTMLButtonElementImpl) {
HTMLButtonElementImpl button = (HTMLButtonElementImpl) node;
String rawType = button.getAttribute("type");
String type;
if (rawType == null) {
type = "submit";
} else {
type = rawType.trim().toLowerCase();
}
if ("submit".equals(type)) {
FormInput[] formInputs;
String name = button.getName();
if (name == null) {
formInputs = null;
} else {
formInputs = new FormInput[] { new FormInput(name, button.getValue()) };
}
button.submitForm(formInputs);
} else if ("reset".equals(type)) {
button.resetForm();
} else {
// NOP for "button"!
}
return false;
}
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onMouseClick(parent, event, x, y);
}
public boolean onContextMenu(ModelNode node, MouseEvent event, int x, int y) {
if (logger.isLoggable(Level.INFO)) {
logger.info("onContextMenu(): node=" + node + ",class=" + node.getClass().getName());
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOncontextmenu();
if (f != null) {
Event jsEvent = new Event("contextmenu", uiElement, event, x, y);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return false; }
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
// Needs to be done after Javascript, so the script
// is able to prevent it.
if (!rcontext.onContextMenu(uiElement, event)) { return false; }
}
}
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onContextMenu(parent, event, x, y);
}
public void onMouseOver(ModelNode node, MouseEvent event, int x, int y, ModelNode limit) {
while (node != null) {
if (node == limit) {
break;
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
uiElement.setMouseOver(true);
Function f = uiElement.getOnmouseover();
if (f != null) {
Event jsEvent = new Event("mouseover", uiElement, event, x, y);
Executor.executeFunction(uiElement, f, jsEvent);
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
rcontext.onMouseOver(uiElement, event);
}
}
node = node.getParentModelNode();
}
}
public void onMouseOut(ModelNode node, MouseEvent event, int x, int y, ModelNode limit) {
while (node != null) {
if (node == limit) {
break;
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
uiElement.setMouseOver(false);
Function f = uiElement.getOnmouseout();
if (f != null) {
Event jsEvent = new Event("mouseout", uiElement, event, x, y);
Executor.executeFunction(uiElement, f, jsEvent);
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
rcontext.onMouseOut(uiElement, event);
}
}
node = node.getParentModelNode();
}
}
/**
* @return True to propagate further, false if consumed.
*/
public boolean onDoubleClick(ModelNode node, MouseEvent event, int x, int y) {
if (logger.isLoggable(Level.INFO)) {
logger.info("onDoubleClick(): node=" + node + ",class=" + node.getClass().getName());
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOndblclick();
if (f != null) {
Event jsEvent = new Event("dblclick", uiElement, event, x, y);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return false; }
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
if (!rcontext.onDoubleClick(uiElement, event)) { return false; }
}
}
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onDoubleClick(parent, event, x, y);
}
/**
* @return True to propagate further, false if consumed.
*/
public boolean onMouseDisarmed(ModelNode node, MouseEvent event) {
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null);
return false;
}
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onMouseDisarmed(parent, event);
}
/**
* @return True to propagate further, false if consumed.
*/
public boolean onMouseDown(ModelNode node, MouseEvent event, int x, int y) {
boolean pass = true;
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOnmousedown();
if (f != null) {
Event jsEvent = new Event("mousedown", uiElement, event, x, y);
pass = Executor.executeFunction(uiElement, f, jsEvent);
}
}
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor("#9090FF80");
return false;
}
if (!pass) { return false; }
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onMouseDown(parent, event, x, y);
}
/**
* @return True to propagate further, false if consumed.
*/
public boolean onMouseUp(ModelNode node, MouseEvent event, int x, int y) {
boolean pass = true;
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOnmouseup();
if (f != null) {
Event jsEvent = new Event("mouseup", uiElement, event, x, y);
pass = Executor.executeFunction(uiElement, f, jsEvent);
}
}
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null);
return false;
}
if (!pass) { return false; }
ModelNode parent = node.getParentModelNode();
if (parent == null) { return true; }
return this.onMouseUp(parent, event, x, y);
}
/**
* @param node
* The node generating the event.
* @param x
* For images only, x coordinate of mouse click.
* @param y
* For images only, y coordinate of mouse click.
* @return True to propagate further, false if consumed.
*/
public boolean onPressed(ModelNode node, InputEvent event, int x, int y) {
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOnclick();
if (f != null) {
Event jsEvent = new Event("click", uiElement, event, x, y);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return false; }
}
}
if (node instanceof HTMLInputElementImpl) {
HTMLInputElementImpl hie = (HTMLInputElementImpl) node;
if (hie.isSubmitInput()) {
FormInput[] formInputs;
String name = hie.getName();
if (name == null) {
formInputs = null;
} else {
formInputs = new FormInput[] { new FormInput(name, hie.getValue()) };
}
hie.submitForm(formInputs);
} else if (hie.isImageInput()) {
String name = hie.getName();
String prefix = name == null ? "" : name + ".";
FormInput[] extraFormInputs = new FormInput[] { new FormInput(prefix + "x", String.valueOf(x)), new FormInput(prefix + "y", String.valueOf(y)) };
hie.submitForm(extraFormInputs);
} else if (hie.isResetInput()) {
hie.resetForm();
}
}
// No propagate
return false;
}
public boolean onChange(ModelNode node) {
if (node instanceof HTMLSelectElementImpl) {
HTMLSelectElementImpl uiElement = (HTMLSelectElementImpl) node;
Function f = uiElement.getOnchange();
if (f != null) {
Event jsEvent = new Event("change", uiElement);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return false; }
}
}
// No propagate
return false;
}
}

View File

@ -1,267 +0,0 @@
package jd.http.ext;
import java.awt.event.MouseEvent;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.HtmlRendererContext;
import org.lobobrowser.html.domimpl.HTMLAbstractUIElement;
import org.lobobrowser.html.domimpl.HTMLButtonElementImpl;
import org.lobobrowser.html.domimpl.HTMLLinkElementImpl;
import org.lobobrowser.html.domimpl.HTMLSpanElementImpl;
import org.lobobrowser.html.domimpl.ModelNode;
import org.lobobrowser.html.js.Event;
import org.lobobrowser.html.js.Executor;
import org.mozilla.javascript.Function;
public class InputController {
public InputController() {
}
// public void enterPressed(ModelNode node) {
// if (node instanceof HTMLInputElementImpl) {
// HTMLInputElementImpl hie = (HTMLInputElementImpl) node;
// if (hie.isSubmittableWithEnterKey()) {
// hie.submitForm(null);
//
// }
// }
//
// }
public void mouseClick(ModelNode node, MouseEvent event, int x, int y) {
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
Function f = uiElement.getOnclick();
if (f != null) {
Event jsEvent = new Event("click", uiElement, event, x, y);
if (!Executor.executeFunction(uiElement, f, jsEvent)) { return; }
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
if (!rcontext.onMouseClick(uiElement, event)) { return; }
}
}
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).navigate();
return;
} else if (node instanceof HTMLButtonElementImpl) {
HTMLButtonElementImpl button = (HTMLButtonElementImpl) node;
String rawType = button.getAttribute("type");
String type;
if (rawType == null) {
type = "submit";
} else {
type = rawType.trim().toLowerCase();
}
if ("submit".equals(type)) {
FormInput[] formInputs;
String name = button.getName();
if (name == null) {
formInputs = null;
} else {
formInputs = new FormInput[] { new FormInput(name, button.getValue()) };
}
button.submitForm(formInputs);
} else if ("reset".equals(type)) {
button.resetForm();
} else {
// NOP for "button"!
}
return;
}
// not consumed? delegate
ModelNode parent = node.getParentModelNode();
if (parent != null) {
mouseClick(parent, event, x, y);
}
}
// public void contextMenu(ModelNode node, MouseEvent event, int x, int y) {
//
// if (node instanceof HTMLAbstractUIElement) {
// HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
// Function f = uiElement.getOncontextmenu();
// if (f != null) {
// Event jsEvent = new Event("contextmenu", uiElement, event, x, y);
// if (!Executor.executeFunction(uiElement, f, jsEvent)) { return; }
// }
// HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
// if (rcontext != null) {
// // Needs to be done after Javascript, so the script
// // is able to prevent it.
// if (!rcontext.onContextMenu(uiElement, event)) { return; }
// }
// }
// ModelNode parent = node.getParentModelNode();
// if (parent != null) {
// contextMenu(parent, event, x, y);};
// }
public void mouseOver(ModelNode node, MouseEvent event, int x, int y, ModelNode limit) {
while (node != null) {
if (node == limit) {
break;
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
uiElement.setMouseOver(true);
Function f = uiElement.getOnmouseover();
if (f != null) {
Event jsEvent = new Event("mouseover", uiElement, event, x, y);
Executor.executeFunction(uiElement, f, jsEvent);
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
rcontext.onMouseOver(uiElement, event);
}
}
node = node.getParentModelNode();
}
}
public void mouseOut(ModelNode node, MouseEvent event, int x, int y, ModelNode limit) {
while (node != null) {
if (node == limit) {
break;
}
if (node instanceof HTMLAbstractUIElement) {
HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
uiElement.setMouseOver(false);
Function f = uiElement.getOnmouseout();
if (f != null) {
Event jsEvent = new Event("mouseout", uiElement, event, x, y);
Executor.executeFunction(uiElement, f, jsEvent);
}
HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
rcontext.onMouseOut(uiElement, event);
}
}
node = node.getParentModelNode();
}
}
public void click(HTMLSpanElementImpl button) {
}
// public void doubleClick(ModelNode node, MouseEvent event, int x, int y) {
//
// if (node instanceof HTMLAbstractUIElement) {
// HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
// Function f = uiElement.getOndblclick();
// if (f != null) {
// Event jsEvent = new Event("dblclick", uiElement, event, x, y);
// if (!Executor.executeFunction(uiElement, f, jsEvent)) { return; }
// }
// HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
// if (rcontext != null) {
// if (!rcontext.onDoubleClick(uiElement, event)) { return; }
// }
// }
// ModelNode parent = node.getParentModelNode();
// if (parent == null) { return; }
// doubleClick(parent, event, x, y);
// }
// public void mouseDisarmed(ModelNode node, MouseEvent event) {
// if (node instanceof HTMLLinkElementImpl) {
// ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null);
// return;
// }
// ModelNode parent = node.getParentModelNode();
// if (parent == null) { return ; }
// mouseDisarmed(parent, event);
// }
// public void mouseDown(ModelNode node, MouseEvent event, int x, int y) {
// boolean pass = true;
// if (node instanceof HTMLAbstractUIElement) {
// HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
// Function f = uiElement.getOnmousedown();
// if (f != null) {
// Event jsEvent = new Event("mousedown", uiElement, event, x, y);
// pass = Executor.executeFunction(uiElement, f, jsEvent);
// }
// }
// if (node instanceof HTMLLinkElementImpl) {
// ((HTMLLinkElementImpl)
// node).getCurrentStyle().setOverlayColor("#9090FF80");
// return ;
// }
// if (!pass) { return ; }
// ModelNode parent = node.getParentModelNode();
// if (parent == null) { return; }
// mouseDown(parent, event, x, y);
// }
// public void mouseUp(ModelNode node, MouseEvent event, int x, int y) {
// boolean pass = true;
// if (node instanceof HTMLAbstractUIElement) {
// HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
// Function f = uiElement.getOnmouseup();
// if (f != null) {
// Event jsEvent = new Event("mouseup", uiElement, event, x, y);
// pass = Executor.executeFunction(uiElement, f, jsEvent);
// }
// }
// if (node instanceof HTMLLinkElementImpl) {
// ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null);
// return;
// }
// if (!pass) { return; }
// ModelNode parent = node.getParentModelNode();
// if (parent == null) { return; }
// mouseUp(parent, event, x, y);
// }
// public void press(ModelNode node, InputEvent event, int x, int y) {
// if (node instanceof HTMLAbstractUIElement) {
// HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node;
// Function f = uiElement.getOnclick();
// if (f != null) {
// Event jsEvent = new Event("click", uiElement, event, x, y);
// if (!Executor.executeFunction(uiElement, f, jsEvent)) { return; }
// }
// }
// if (node instanceof HTMLInputElementImpl) {
// HTMLInputElementImpl hie = (HTMLInputElementImpl) node;
// if (hie.isSubmitInput()) {
// FormInput[] formInputs;
// String name = hie.getName();
// if (name == null) {
// formInputs = null;
// } else {
// formInputs = new FormInput[] { new FormInput(name, hie.getValue()) };
// }
// hie.submitForm(formInputs);
// } else if (hie.isImageInput()) {
// String name = hie.getName();
// String prefix = name == null ? "" : name + ".";
// FormInput[] extraFormInputs = new FormInput[] { new FormInput(prefix +
// "x", String.valueOf(x)), new FormInput(prefix + "y", String.valueOf(y))
// };
// hie.submitForm(extraFormInputs);
// } else if (hie.isResetInput()) {
// hie.resetForm();
// }
// }
//
// }
// public void change(ModelNode node) {
// if (node instanceof HTMLSelectElementImpl) {
// HTMLSelectElementImpl uiElement = (HTMLSelectElementImpl) node;
// Function f = uiElement.getOnchange();
// if (f != null) {
// Event jsEvent = new Event("change", uiElement);
// if (!Executor.executeFunction(uiElement, f, jsEvent)) { return ; }
// }
// }
//
// }
}

View File

@ -1,29 +0,0 @@
package jd.http.ext;
public class NetworkRequest {
/**
* The uninitialized request state.
*/
public static final int STATE_UNINITIALIZED = 0;
/**
* The loading request state. The <code>open</code> method has been called,
* but a response has not been received yet.
*/
public static final int STATE_LOADING = 1;
/**
* The loaded request state. Headers and status are now available.
*/
public static final int STATE_LOADED = 2;
/**
* The interactive request state. Downloading response.
*/
public static final int STATE_INTERACTIVE = 3;
/**
* The complete request state. All operations are finished.
*/
public static final int STATE_COMPLETE = 4;
}

View File

@ -1,69 +0,0 @@
package jd.http.ext;
import java.util.ArrayList;
import jd.parser.Regex;
import org.lobobrowser.html.domimpl.HTMLElementImpl;
import org.lobobrowser.html.style.AbstractCSS2Properties;
public class RendererUtilities {
/**
* This method has to evaluate if the element impl is visible on screen.
*
* @param impl
* @return
*/
public static boolean isVisible(HTMLElementImpl impl) {
java.util.List<HTMLElementImpl> styles = getPath(impl);
int x = 0;
int y = 0;
for (HTMLElementImpl p : styles) {
AbstractCSS2Properties style = p.getComputedStyle(null);
if ("none".equalsIgnoreCase(style.getDisplay())) {
//
System.out.println("NO DISPLAY");
return false;
}
if ("absolute".equalsIgnoreCase(style.getPosition())) {
x = y = 0;
}
if (style.getTop() != null) {
y += covertToPixel(style.getTop());
}
if (style.getLeft() != null) {
x += covertToPixel(style.getLeft());
}
}
if (y < 0) {
System.out.println("y<0" + " " + x + " - " + y);
return false;
}
return true;
}
private static int covertToPixel(String top) {
if (top == null) return 0;
if (top.toLowerCase().trim().endsWith("px")) { return Integer.parseInt(top.substring(0, top.length() - 2)); }
String value = new Regex(top, "([\\-\\+]?\\s*\\d+)").getMatch(0);
if (value == null) return 0;
return Integer.parseInt(value);
}
private static java.util.List<HTMLElementImpl> getPath(HTMLElementImpl impl) {
java.util.List<HTMLElementImpl> styles = new ArrayList<HTMLElementImpl>();
HTMLElementImpl p = impl;
while (p != null) {
styles.add(0, p);
p = p.getParent("*");
}
return styles;
}
}

View File

@ -1,144 +0,0 @@
package jd.http.ext;
import java.net.URL;
import java.security.Policy;
import jd.http.Cookie;
import jd.http.Cookies;
import org.appwork.utils.logging.Log;
import org.lobobrowser.html.HttpRequest;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.domimpl.HTMLScriptElementImpl;
public class UserAgentDelegate implements UserAgentContext {
private ExtBrowser browser;
public UserAgentDelegate(ExtBrowser extBrowser) {
browser = extBrowser;
}
public HttpRequest createHttpRequest() {
// TODO Auto-generated method stub
return new ExtHTTPRequest(browser);
}
public String getAppCodeName() {
return browser.getBrowserEnviroment().getAppCodeName();
}
public String getAppMinorVersion() {
return browser.getBrowserEnviroment().getAppMinorVersion();
}
public String getAppName() {
return browser.getBrowserEnviroment().getAppName();
}
public String getAppVersion() {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().getAppVersion();
}
public String getBrowserLanguage() {
// TODO Auto-generated method stub
return browser.getCommContext().getAcceptLanguage();
}
public String getCookie(URL arg0) {
// TODO Auto-generated method stub
Cookies cookies = this.browser.getCommContext().getCookies(arg0 + "");
StringBuilder c = new StringBuilder();
boolean b = false;
for (Cookie cookie : cookies.getCookies()) {
if (b == true) {
c.append("; ");
} else
b = true;
c.append(cookie.getKey() + "=" + cookie.getValue());
}
return c.toString();
}
public String getPlatform() {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().getPlatform();
}
public String getProduct() {
return browser.getBrowserEnviroment().getProduct();
}
public int getScriptingOptimizationLevel() {
return 9;
}
/**
* Returns <code>null</code>. This method must be overridden if JavaScript
* code is untrusted.
*/
public Policy getSecurityPolicy() {
return browser.getBrowserEnviroment().getSecurityPolicy();
}
public String getUserAgent() {
// TODO Auto-generated method stub
return browser.getCommContext().getRequest().getHeaders().get("User-Agent");
}
public String getVendor() {
return browser.getBrowserEnviroment().getVendor();
}
public boolean isCookieEnabled() {
// TODO Auto-generated method stub
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean isExternalCSSEnabled() {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().isExternalCSSEnabled();
}
public boolean isMedia(String arg0) {
RuntimeException e = new RuntimeException("Not implemented");
Log.exception(e);
throw e;
}
public boolean isScriptingEnabled() {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().isScriptingEnabled();
}
/**
* gets called if js sets a cookie
*/
public void setCookie(URL arg0, String arg1) {
// date is null..since js time is localtime anyway
Cookies cookies = Cookies.parseCookies(arg1, arg0.getHost(), null);
// cookies = cookies;
browser.getCommContext().getCookies(arg0.toString()).add(cookies);
}
public boolean isInternalCSSEnabled() {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().isInternalCSSEnabled();
}
public String doScriptFilter(HTMLScriptElementImpl htmlScriptElementImpl, String text) {
// TODO Auto-generated method stub
return browser.getBrowserEnviroment().doScriptFilter(htmlScriptElementImpl, text);
}
}

View File

@ -1,20 +0,0 @@
package jd.http.ext.events;
import jd.http.ext.ExtBrowser;
import org.appwork.utils.event.DefaultIntEvent;
public class ExtBrowserEvent extends DefaultIntEvent {
private final ExtBrowser browser;
public ExtBrowserEvent(ExtBrowser browser, Object caller, int eventID, Object parameter) {
super(caller, eventID, parameter);
this.browser = browser;
}
public ExtBrowser getBrowser() {
return browser;
}
}

View File

@ -1,13 +0,0 @@
package jd.http.ext.events;
import org.appwork.utils.event.Eventsender;
public class ExtBrowserEventSender extends Eventsender<ExtBrowserListener, ExtBrowserEvent> {
@Override
protected void fireEvent(ExtBrowserListener listener, ExtBrowserEvent event) {
listener.onFrameEvent(event);
}
}

View File

@ -1,9 +0,0 @@
package jd.http.ext.events;
import java.util.EventListener;
public interface ExtBrowserListener extends EventListener {
public void onFrameEvent(ExtBrowserEvent event);
}

View File

@ -1,56 +0,0 @@
package jd.http.ext.events;
import jd.http.ext.ExtBrowser;
import jd.http.ext.FrameController;
public class JSInteraction extends ExtBrowserEvent {
public static enum AnswerTypes {
CANCEL, OK, SKIP
}
public static enum Types {
ALERT, CONFIRM, PROMPT
}
private AnswerTypes answer = AnswerTypes.CANCEL;
private String answerString = null;
private String message = null;
public JSInteraction(ExtBrowser extBrowser, FrameController caller, Types type, String msg) {
this(extBrowser, caller, type, msg, null);
}
public JSInteraction(ExtBrowser owner, FrameController caller, Types type, String msg, String def) {
super(owner, caller, type.ordinal(), null);
this.message = msg;
answerString = def;
}
public AnswerTypes getAnswer() {
return answer;
}
public String getAnswerString() {
return answerString;
}
public String getMessage() {
return message;
}
public Types getType() {
return Types.values()[this.getEventID()];
}
public void setAnswer(AnswerTypes answer) {
this.answer = answer;
}
public void setAnswerString(String answerString) {
this.answerString = answerString;
}
}

View File

@ -1,43 +0,0 @@
package jd.http.ext.interfaces;
import java.security.Policy;
import jd.http.Request;
import org.lobobrowser.html.domimpl.HTMLScriptElementImpl;
public interface BrowserEnviroment {
public boolean doLoadContent(Request request);
public void prepareContents(Request request);
public boolean isImageLoadingEnabled();
public boolean isAutoProcessSubFrames();
public String getAppCodeName();
public String getAppMinorVersion();
public String getAppName();
public String getAppVersion();
public String getPlatform();
public String getProduct();
public Policy getSecurityPolicy();
public String getVendor();
public boolean isExternalCSSEnabled();
public boolean isScriptingEnabled();
public boolean isInternalCSSEnabled();
public String doScriptFilter(HTMLScriptElementImpl htmlScriptElementImpl, String text);
}

View File

@ -16,16 +16,9 @@
package jd.plugins;
import java.nio.charset.CharacterCodingException;
import jd.gui.UserIO;
import jd.http.Browser;
import org.appwork.utils.logging.Log;
import org.jdownloader.translate._JDT;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
/**
* Little Helper class for often used Plugin issues
@ -45,7 +38,9 @@ public class PluginUtils {
// with null message, long urls will push out the length of the dialog. Lets prevent that.
if (message == null) {
message = link.getCryptedUrl();
if (message.length() >= 120) message = message.substring(0, 117) + "...";
if (message.length() >= 120) {
message = message.substring(0, 117) + "...";
}
message = _JDT._.jd_plugins_PluginUtils_askPassword(message);
}
final String password = askPassword(message, link.getDecrypterPassword());
@ -57,26 +52,27 @@ public class PluginUtils {
return UserIO.getInstance().requestInputDialog(0, message, defaultmessage);
}
public static void evalJSPacker(final Browser br) {
final String regex = "eval\\((.*?\\,\\{\\}\\))\\)";
final String[] containers = br.getRegex(regex).getColumn(0);
String htmlcode;
try {
htmlcode = br.getRequest().getHtmlCode();
for (String c : containers) {
final Context cx = ContextFactory.getGlobal().enterContext();
final Scriptable scope = cx.initStandardObjects();
c = c.replaceAll("return p\\}\\(", " return p} f(").replaceAll("function\\s*\\(p\\,a\\,c\\,k\\,e\\,d\\)", "function f(p,a,c,k,e,d)");
final Object result = cx.evaluateString(scope, c, "<cmd>", 1, null);
final String code = Context.toString(result);
htmlcode = htmlcode.replaceFirst(regex, code);
}
br.getRequest().setHtmlCode(htmlcode);
} catch (CharacterCodingException e) {
Log.exception(e);
}
}
// public static void evalJSPacker(final Browser br) {
// final String regex = "eval\\((.*?\\,\\{\\}\\))\\)";
// final String[] containers = br.getRegex(regex).getColumn(0);
//
// String htmlcode;
// try {
// htmlcode = br.getRequest().getHtmlCode();
//
// for (String c : containers) {
// final Context cx = ContextFactory.getGlobal().enterContext();
// final Scriptable scope = cx.initStandardObjects();
// c = c.replaceAll("return p\\}\\(", " return p} f(").replaceAll("function\\s*\\(p\\,a\\,c\\,k\\,e\\,d\\)",
// "function f(p,a,c,k,e,d)");
// final Object result = cx.evaluateString(scope, c, "<cmd>", 1, null);
// final String code = Context.toString(result);
// htmlcode = htmlcode.replaceFirst(regex, code);
// }
// br.getRequest().setHtmlCode(htmlcode);
// } catch (CharacterCodingException e) {
// Log.exception(e);
// }
// }
}

View File

@ -23,6 +23,9 @@ import java.util.logging.Level;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jd.PluginWrapper;
import jd.controlling.DistributeData;
@ -36,10 +39,6 @@ import jd.plugins.DownloadLink;
import jd.plugins.PluginForDecrypt;
import jd.utils.JDHexUtils;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "Click n Load", "Click n Load" }, urls = { "cnl://.*?\\..*?/.*?/", "http://jdownloader\\.org/cnl/.*?/" }, flags = { 0, 0 })
public class CNL extends PluginForDecrypt {
@ -101,16 +100,22 @@ public class CNL extends PluginForDecrypt {
final byte[] key;
if (jk != null) {
Context cx = null;
try {
cx = ContextFactory.getGlobal().enterContext();
final Scriptable scope = cx.initStandardObjects();
final String fun = jk + " f()";
final Object result = cx.evaluateString(scope, fun, "<cmd>", 1, null);
key = JDHexUtils.getByteArray(Context.toString(result));
try {
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("javascript");
final String fun = jk + " f()";
final Object result = engine.eval(fun);
key = JDHexUtils.getByteArray(result + "");
} catch (ScriptException e) {
getLogger().log(e);
throw new RuntimeException(e);
} finally {
if (cx != null) Context.exit();
}
} else {
key = JDHexUtils.getByteArray(k);
@ -122,7 +127,9 @@ public class CNL extends PluginForDecrypt {
final ArrayList<DownloadLink> links = new DistributeData(Encoding.htmlDecode(decryted)).findLinks();
for (final DownloadLink link : links) {
if (passwords != null && passwords.size() > 0) link.setSourcePluginPasswordList(passwords);
if (passwords != null && passwords.size() > 0) {
link.setSourcePluginPasswordList(passwords);
}
}
for (final DownloadLink l : links) {
if (source != null) {

View File

@ -31,16 +31,16 @@ import jd.plugins.DecrypterPlugin;
import jd.plugins.DownloadLink;
import jd.plugins.FilePackage;
import jd.plugins.PluginForDecrypt;
import net.sourceforge.htmlunit.corejs.javascript.ClassShutter;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.utils.encoding.Base64;
import org.appwork.utils.formatter.HexFormatter;
import org.appwork.utils.logging.Log;
import org.mozilla.javascript.ClassShutter;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 3, names = { "dummycnl.jdownloader.org" }, urls = { "http://dummycnl\\.jdownloader\\.org/[a-f0-9A-F]+" }, flags = { 0 })
public class DummyCNL extends PluginForDecrypt {

View File

@ -21,15 +21,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import jd.PluginWrapper;
import jd.captcha.specials.Linksave;
import jd.controlling.ProgressController;
import jd.http.Browser;
import jd.http.RandomUserAgent;
import jd.http.URLConnectionAdapter;
import jd.http.ext.BasicBrowserEnviroment;
import jd.http.ext.ExtBrowser;
import jd.http.ext.ExtBrowserException;
import jd.nutils.encoding.Encoding;
import jd.nutils.io.JDIO;
import jd.parser.Regex;
@ -47,28 +47,34 @@ import org.appwork.utils.formatter.HexFormatter;
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "Linksave.in" }, urls = { "https?://(www\\.)?linksave\\.in/(view.php\\?id=)?(?!dl\\-)[\\w]+" }, flags = { 0 })
public class Lnksvn extends PluginForDecrypt {
private boolean isExternInterfaceActive() {
// DO NOT check for the plugin here. compatzibility reasons to 0.9*
// better: check port 9666 for a httpserver
return true;
}
public Lnksvn(final PluginWrapper wrapper) {
super(wrapper);
}
private static final String INVALIDLINKS = "http://(www\\.)?linksave\\.in/(news|api|partner|usercp|protect|faq|contact|language).*?";
@Override
public ArrayList<DownloadLink> decryptIt(final CryptedLink param, final ProgressController progress) throws Exception {
br.setRequestIntervalLimit(getHost(), 1000);
ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>() {
@Override
public boolean add(DownloadLink e) {
distribute(e);
return super.add(e);
}
};
setBrowserExclusive();
final String parameter = param.toString().replace("https://", "http://");
br.forceDebug(true);
br.getHeaders().put("User-Agent", RandomUserAgent.generate());
br.setCookie("http://linksave.in/", "Linksave_Language", "german");
br.setRequestIntervalLimit("linksave.in", 1000);
@ -86,14 +92,14 @@ public class Lnksvn extends PluginForDecrypt {
getCaptcha(param, "");
// CNL
/* old CNL handling found in revision 13753 */
if (br.getRegex("cnl\\.jpg").matches() && isExternInterfaceActive()) {
if (br.getRegex("cnl\\.jpg").matches() && isExternInterfaceActive() && false) {
final Form cnlform = br.getForm(0);
/* 0.95xx comp */
final String jkvalue = cnlform.getRegex("<INPUT TYPE=\"hidden\" NAME=\"jk\" VALUE=\"(.*?)\"").getMatch(0);
cnlform.put("jk", Encoding.formEncoding(jkvalue));
if (jkvalue != null) {
if (System.getProperty("jd.revision.jdownloaderrevision") != null) {
HashMap<String, String> infos = new HashMap<String, String>();
infos.put("crypted", Encoding.urlDecode(cnlform.getInputField("crypted").getValue(), false));
@ -120,7 +126,9 @@ public class Lnksvn extends PluginForDecrypt {
cnlbr.getHeaders().put("jd.randomNumber", System.getProperty("jd.randomNumber"));
try {
cnlbr.submitForm(cnlform);
if (cnlbr.containsHTML("success")) { return decryptedLinks; }
if (cnlbr.containsHTML("success")) {
return decryptedLinks;
}
} catch (final Throwable e) {
}
}
@ -128,7 +136,7 @@ public class Lnksvn extends PluginForDecrypt {
}
// Container handling (DLC)
String[] container = br.getRegex("\\.href\\=unescape\\(\\'(.*?)\\'\\)\\;").getColumn(0);
if (container != null && container.length > 0) {
if (container != null && container.length > 0 && false) {
for (final String c : container) {
final Browser clone = br.cloneBrowser();
final String test = Encoding.htmlDecode(c);
@ -167,7 +175,9 @@ public class Lnksvn extends PluginForDecrypt {
}
}
}
if (decryptedLinks != null && decryptedLinks.size() > 0) { return decryptedLinks; }
if (decryptedLinks != null && decryptedLinks.size() > 0) {
return decryptedLinks;
}
// if containersearch did not work
final ArrayList<String> allLinks = new ArrayList<String>();
int pages = 1;
@ -207,15 +217,16 @@ public class Lnksvn extends PluginForDecrypt {
Browser browser;
String result;
volatile boolean done = false;
public LsDirektLinkTH(final Browser browser) {
this.browser = browser;
}
@Override
public void run() {
try {
result = getDirektLink(browser);
distribute(createDownloadlink(result));
} catch (final IOException e) {
e.printStackTrace();
} finally {
@ -237,7 +248,7 @@ public class Lnksvn extends PluginForDecrypt {
logger.info("Link " + i + " von " + dlinks.length);
}
for (final LsDirektLinkTH lsDirektLinkTH : dlinks) {
while (lsDirektLinkTH.isAlive() || lsDirektLinkTH.done) {
while (lsDirektLinkTH.isAlive() && !lsDirektLinkTH.done) {
synchronized (lsDirektLinkTH) {
try {
lsDirektLinkTH.wait(5000);
@ -252,13 +263,15 @@ public class Lnksvn extends PluginForDecrypt {
}
}
if (decryptedLinks.size() == 0) {
if (br.getRegex("cnl\\.jpg").matches() && !isExternInterfaceActive()) { return decryptedLinks; }
if (br.getRegex("cnl\\.jpg").matches() && !isExternInterfaceActive()) {
return decryptedLinks;
}
logger.warning("Decrypter out of date for link: " + parameter);
return null;
}
return decryptedLinks;
}
private void getCaptcha(final CryptedLink param, final String extras) throws Exception {
Form form = br.getFormbyProperty("name", "form");
for (int retry = 0; retry < 5; retry++) {
@ -300,76 +313,112 @@ public class Lnksvn extends PluginForDecrypt {
}
}
}
private String getDirektLink(final Browser br) throws IOException {
final String link = br.getRegex("<frame scrolling=\"auto\" noresize src=\"([^\"]*)\">").getMatch(0);
final String url = br.getURL().toString();
if (link != null) {
br.getPage(link);
}
String link2 = Encoding.htmlDecode(br.getRegex("iframe src=\"([^\"]*)\"").getMatch(0));
if (link2 != null) { return link2.trim(); }
br.getRequest().setHtmlCode(br.toString().replaceFirst("<script type=\"text/javascript\" src=\"[^\"]*.js\">", ""));
// Start Evaluation of br
try {
// this is a workaround to use ExtBrowser Insteadof old
// JavaScript class.
final ExtBrowser eb = new ExtBrowser();
// settings: blacklist allows nothing. this means that only
// whitelisted links will be loaded
eb.setBrowserEnviroment(new BasicBrowserEnviroment(new String[] { ".*" }, new String[] { ".*linksave.in.*" }) {
@Override
public boolean isAutoProcessSubFrames() {
return false;
}
});
eb.eval(br);
link2 = eb.getRegex("location.replace\\('([^\']*)").getMatch(0);
if (link2 == null) {
link2 = eb.getRegex("src=\"([^\"]*)\"").getMatch(0);
}
if (link2 == null) {
link2 = eb.getRegex("URL=([^\"]*)\"").getMatch(0);
}
eb.getCommContext().setFollowRedirects(false);
eb.getPage(link2);
eb.getCommContext().setFollowRedirects(true);
link2 = Encoding.htmlDecode(eb.getRegex("iframe .*?src=\"([^\"]*)\"").getMatch(0));
if (link2 == null && br.getRedirectLocation() != null) {
link2 = eb.getCommContext().getRedirectLocation();
}
if (link2 == null) {
link2 = eb.getCommContext().getHttpConnection().getHeaderField("Location");
}
if (link2 == null && eb.getCommContext().getHttpConnection().getContentType().contains("html")) {
if (eb.getCommContext().containsHTML("404 - Not Found")) {
logger.info("404 - File: \"" + url + "\" not found!");
return null;
}
}
if (link2 != null) {
return link2.trim();
// TODO: old code is below... did not find an example about that
// if (link2 == null) {
// js = new JavaScript(br);
// js.runPage();
// br.getRequest().setHtmlCode(js.getDocment().getContent());
// link2 = br.getForm(0).getAction();
// }
// if (link2 != null) return link2.trim();
// } catch (SAXException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
} catch (final ExtBrowserException e) {
e.printStackTrace();
}
return null;
String js = br.getRegex("<script type=\"text/javascript\">(.+?)</script>").getMatch(0);
try {
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("javascript");
engine.eval("document = {};document.text=\"\";document.write= function (a) { document.text+=a;};");
engine.eval(js);
Object html = engine.eval("document.text");
link2 = new Regex(html, "location.replace\\('([^\']*)").getMatch(0);
if (link2 == null) {
link2 = new Regex(html, "src=\"([^\"]*)\"").getMatch(0);
}
if (link2 == null) {
link2 = new Regex(html, "URL=([^\"]*)\"").getMatch(0);
}
br.setFollowRedirects(false);
br.getPage(link2);
link2 = Encoding.htmlDecode(new Regex(br, "iframe .*?src=\"([^\"]*)\"").getMatch(0));
if (link2 == null && br.getRedirectLocation() != null) {
link2 = br.getRedirectLocation();
}
if (link2 == null) {
link2 = br.getHttpConnection().getHeaderField("Location");
}
} catch (Throwable e) {
e.printStackTrace();
e.printStackTrace();
}
if (link2 == null) {
return null;
}
// Start Evaluation of br
// this is a workaround to use ExtBrowser Insteadof old
// JavaScript class.
// final ExtBrowser eb = new ExtBrowser();
// // settings: blacklist allows nothing. this means that only
// // whitelisted links will be loaded
// eb.setBrowserEnviroment(new BasicBrowserEnviroment(new String[] { ".*" }, new String[] { ".*linksave.in.*" }) {
// @Override
// public boolean isAutoProcessSubFrames() {
// return false;
// }
// });
// eb.eval(br);
// link2 = new Regex(html,"location.replace\\('([^\']*)").getMatch(0);
// if (link2 == null) {
// link2 = new Regex(html,"src=\"([^\"]*)\"").getMatch(0);
// }
// if (link2 == null) {
// link2 = new Regex(html,"URL=([^\"]*)\"").getMatch(0);
// }
// eb.getCommContext().setFollowRedirects(false);
// eb.getPage(link2);
// eb.getCommContext().setFollowRedirects(true);
// link2 = Encoding.htmlDecode(new Regex(html,"iframe .*?src=\"([^\"]*)\"").getMatch(0));
// if (link2 == null && br.getRedirectLocation() != null) {
// link2 = eb.getCommContext().getRedirectLocation();
// }
// if (link2 == null) {
// link2 = eb.getCommContext().getHttpConnection().getHeaderField("Location");
// }
// if (link2 == null && eb.getCommContext().getHttpConnection().getContentType().contains("html")) {
// if (eb.getCommContext().containsHTML("404 - Not Found")) {
// logger.info("404 - File: \"" + url + "\" not found!");
// return null;
// }
// }
return link2.trim();
// TODO: old code is below... did not find an example about that
// if (link2 == null) {
// js = new JavaScript(br);
// js.runPage();
// br.getRequest().setHtmlCode(js.getDocment().getContent());
// link2 = br.getForm(0).getAction();
// }
// if (link2 != null) return link2.trim();
// } catch (SAXException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
}
/* NO OVERRIDE!! */
public boolean hasCaptcha(CryptedLink link, jd.plugins.Account acc) {
return true;
}
}

View File

@ -17,6 +17,8 @@ import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
@ -63,9 +65,6 @@ import org.appwork.utils.net.httpconnection.HTTPProxyStorable;
import org.jdownloader.gui.translate._GUI;
import org.jdownloader.logging.LogController;
import org.jdownloader.plugins.config.PluginJsonConfig;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
public class YoutubeHelper {
@ -732,27 +731,20 @@ public class YoutubeHelper {
final String func = "function " + descrambler + "\\(([^)]+)\\)\\{(.+?return.*?)\\}";
des = new Regex(jsContent, Pattern.compile(func)).getMatch(1);
try {
Context cx = null;
try {
cx = ContextFactory.getGlobal().enterContext();
} catch (java.lang.SecurityException e) {
/* in case classshutter already set */
}
if (cx != null) {
Scriptable scope = cx.initStandardObjects();
String all = new Regex(jsContent, Pattern.compile("function " + descrambler + "\\(([^)]+)\\)\\{(.+?return.*?)\\}.*?\\{.*?\\}")).getMatch(-1);
Object result = cx.evaluateString(scope, all + " " + descrambler + "(\"" + sig + "\")", "<cmd>", 1, null);
if (result != null) {
return result.toString();
}
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("javascript");
String all = new Regex(jsContent, Pattern.compile("function " + descrambler + "\\(([^)]+)\\)\\{(.+?return.*?)\\}.*?\\{.*?\\}")).getMatch(-1);
Object result = engine.eval(all + " " + descrambler + "(\"" + sig + "\")");
if (result != null) {
return result.toString();
}
} catch (final Throwable e) {
logger.log(e);
} finally {
try {
Context.exit();
} catch (final Throwable e) {
}
}
String s = sig;
try {

View File

@ -221,6 +221,16 @@ public class BillionUploadsCom extends PluginForHost {
getPage(downloadLink.getDownloadURL());
checkIncapsulate(downloadLink);
// Context cx = Context.enter();
//
// Global scope = new Global(cx);
// cx.setOptimizationLevel(-1);
// cx.setLanguageVersion(Context.VERSION_1_5);
//
// String[] scripts = br.getRegex("<script>(.*?)</script>").getColumn(0);
// cx.evaluateString(scope, scripts[0], "script_0", 1, null);
if (br.getURL().matches(".+(\\?|&)op=login(.*)?")) {
ArrayList<Account> accounts = AccountController.getInstance().getAllAccounts(this.getHost());
Account account = null;
@ -289,6 +299,33 @@ public class BillionUploadsCom extends PluginForHost {
return getAvailableStatus(downloadLink);
}
private void checkIncapsulate(DownloadLink downloadLink) throws Exception {
if (br.containsHTML("Request unsuccessful\\. Incapsula incident ID")) {
String iframe = br.getRegex("iframe src=\"([^\"]+)").getMatch(0);
Browser iframeBr = br.cloneBrowser();
iframeBr.getPage(iframe);
logger.info("Incapsula Captcha protection!");
final PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP");
final jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(iframeBr);
final String id = iframeBr.getRegex("\\?k=([A-Za-z0-9%_\\+\\- ]+)\"").getMatch(0);
if (inValidate(id)) {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
}
rc.setId(id);
rc.load();
Form form = iframeBr.getForm(0);
final File cf = rc.downloadCaptcha(getLocalCaptchaFile());
final String c = getCaptchaCode(cf, downloadLink);
form.put("recaptcha_challenge_field", rc.getChallenge());
form.put("recaptcha_response_field", Encoding.urlEncode(c));
iframeBr.submitForm(form);
br.getPage(br.getURL());
System.out.println(1);
}
}
private String[] scanInfo(final DownloadLink downloadLink, final String[] fileInfo) {
// standard traits from base page
if (inValidate(fileInfo[0])) {
@ -1246,8 +1283,23 @@ public class BillionUploadsCom extends PluginForHost {
if (page == null) {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
}
br.clearCookies(page);
try {
br.getPage(page);
int retries = 10;
while (retries-- > 0) {
br.getPage(page);
if (!br.containsHTML("http\\:\\/\\/content\\.incapsula\\.com\\/jsTest\\.html")) {
// the first request sets a cookie. the second should work.
break;
}
Thread.sleep((10 - retries) * 500);
}
if (br.containsHTML("http\\:\\/\\/content\\.incapsula\\.com\\/jsTest\\.html")) {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
}
} catch (Exception e) {
if (e instanceof PluginException) {
throw (PluginException) e;
@ -1260,6 +1312,7 @@ public class BillionUploadsCom extends PluginForHost {
throw e;
}
}
// prevention is better than cure
if (br.getHttpConnection() != null && br.getHttpConnection().getResponseCode() == 503 && br.getHttpConnection().getHeaderFields("server").contains("cloudflare-nginx")) {
String host = new Regex(page, "https?://([^/]+)(:\\d+)?/").getMatch(0);

View File

@ -27,6 +27,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jd.PluginWrapper;
import jd.config.Property;
import jd.controlling.AccountController;
@ -52,9 +56,6 @@ import jd.utils.locale.JDL;
import org.appwork.utils.formatter.SizeFormatter;
import org.appwork.utils.formatter.TimeFormatter;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
@HostPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "filefactory.com" }, urls = { "https?://(www\\.)?filefactory\\.com(/|//)(file/[\\w]+/?|(trafficshare|digitalsales)/[a-f0-9]{32}/.+/?)" }, flags = { 2 })
public class FileFactory extends PluginForHost {
@ -411,7 +412,7 @@ public class FileFactory extends PluginForHost {
return 200;
}
public String getUrl() throws IOException, PluginException {
public String getUrl() throws IOException, PluginException, ScriptException {
String url = br.getRegex("\"(http://[a-z0-9\\-]+\\.filefactory\\.com/dl/[^<>\"]*?)\"").getMatch(0);
if (url == null) {
url = br.getRegex("id=\"downloadLinkTarget\" style=\"display: none;\">[\t\n\r ]+<a href=\"(http://[^<>\"]*?)\"").getMatch(0);
@ -424,31 +425,27 @@ public class FileFactory extends PluginForHost {
}
}
if (url == null) {
Context cx = null;
try {
cx = ContextFactory.getGlobal().enterContext();
final Scriptable scope = cx.initStandardObjects();
final String[] eval = br.getRegex("var (.*?) = (.*?), (.*?) = (.*?)+\"(.*?)\", (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?);").getRow(0);
if (eval != null) {
// first load js
Object result = cx.evaluateString(scope, "function g(){return " + eval[1] + "} g();", "<cmd>", 1, null);
final String link = "/file" + result + eval[4];
br.getPage(COOKIE_HOST + link);
final String[] row = br.getRegex("var (.*?) = '';(.*;) (.*?)=(.*?)\\(\\);").getRow(0);
result = cx.evaluateString(scope, row[1] + row[3] + " ();", "<cmd>", 1, null);
if (result.toString().startsWith("http")) {
url = result + "";
} else {
url = COOKIE_HOST + result;
}
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("javascript");
final String[] eval = br.getRegex("var (.*?) = (.*?), (.*?) = (.*?)+\"(.*?)\", (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?), (.*?) = (.*?);").getRow(0);
if (eval != null) {
// first load js
Object result = engine.eval("function g(){return " + eval[1] + "} g();");
final String link = "/file" + result + eval[4];
br.getPage(COOKIE_HOST + link);
final String[] row = br.getRegex("var (.*?) = '';(.*;) (.*?)=(.*?)\\(\\);").getRow(0);
result = engine.eval(row[1] + row[3] + " ();");
if (result.toString().startsWith("http")) {
url = result + "";
} else {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
}
} finally {
if (cx != null) {
Context.exit();
url = COOKIE_HOST + result;
}
} else {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
}
}
return url;

View File

@ -47,6 +47,7 @@ public class Zippysharecom extends PluginForHost {
}
public void correctDownloadLink(final DownloadLink link) {
final String addedLink = link.getDownloadURL();
if (addedLink.matches("http://www\\d{0,}\\.zippyshare\\.com/downloadMusic\\?key=\\d+")) {
link.setUrlDownload(addedLink.replace("downloadMusic?key=", "view.jsp?key="));

View File

@ -27,6 +27,10 @@ import jd.plugins.Plugin;
import jd.plugins.PluginForHost;
import jd.utils.JDUtilities;
import net.sf.image4j.codec.ico.ICOEncoder;
import net.sourceforge.htmlunit.corejs.javascript.ClassShutter;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import org.appwork.net.protocol.http.HTTPConstants;
import org.appwork.remoteapi.RemoteAPI;
@ -56,15 +60,11 @@ import org.jdownloader.api.myjdownloader.MyJDownloaderSettings;
import org.jdownloader.images.NewTheme;
import org.jdownloader.plugins.controller.host.HostPluginController;
import org.jdownloader.plugins.controller.host.LazyHostPlugin;
import org.mozilla.javascript.ClassShutter;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
private final static String jdpath = JDUtilities.getJDHomeDirectoryFromEnvironment().getAbsolutePath() + File.separator + "JDownloader.jar";
public void crossdomainxml(RemoteAPIResponse response) throws InternalApiException {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\"?>\r\n");
@ -74,7 +74,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
sb.append("</cross-domain-policy>\r\n");
writeString(response, null, sb.toString(), false);
}
/**
* writes given String to response and sets content-type to text/html
*
@ -88,7 +88,9 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
response.getResponseHeaders().add(new HTTPHeader(HTTPConstants.HEADER_REQUEST_CONTENT_TYPE, "text/html", false));
out = RemoteAPI.getOutputStream(response, request, false, true);
if (wrapCallback && request.getJqueryCallback() != null) {
if (string == null) string = "";
if (string == null) {
string = "";
}
string = "{\"content\": \"" + string.trim() + "\"}";
}
out.write(string.getBytes("UTF-8"));
@ -101,14 +103,14 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
}
}
public void jdcheckjs(RemoteAPIResponse response) throws InternalApiException {
StringBuilder sb = new StringBuilder();
sb.append("jdownloader=true;\r\n");
sb.append("var version='" + JDUtilities.getRevision() + "';\r\n");
writeString(response, null, sb.toString(), false);
}
public void jdcheckjson(RemoteAPIResponse response) throws InternalApiException {
MyJDownloaderSettings set = JsonConfig.create(MyJDownloaderSettings.class);
JSonObject obj = new JSonObject();
@ -117,7 +119,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
obj.put("name", new JSonValue(set.getDeviceName()));
writeString(response, null, obj.toString(), false);
}
public void addcrypted2(RemoteAPIResponse response, RemoteAPIRequest request) throws InternalApiException {
try {
askPermission(request);
@ -135,7 +137,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
writeString(response, request, "failed " + e.getMessage() + "\r\n", true);
}
}
// For My JD API
public void addcrypted2Remote(String crypted, String jk, String source) {
String urls = decrypt(crypted, jk, null);
@ -143,7 +145,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
job.setCustomSourceUrl(source);
LinkCollector.getInstance().addCrawlerJob(job);
}
private void clickAndLoad2Add(LinkOriginDetails origin, String urls, RemoteAPIRequest request) throws IOException {
final String finalPasswords = request.getParameterbyKey("passwords");
String source = request.getParameterbyKey("source");
@ -160,15 +162,17 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
pws.add(finalPasswords);
}
}
private PackageInfo getPackageInfo(CrawledLink link) {
PackageInfo packageInfo = link.getDesiredPackageInfo();
if (packageInfo != null) return packageInfo;
if (packageInfo != null) {
return packageInfo;
}
packageInfo = new PackageInfo();
link.setDesiredPackageInfo(packageInfo);
return packageInfo;
}
@Override
public void modifyCrawledLink(CrawledLink link) {
if (StringUtils.isNotEmpty(finalDestination)) {
@ -181,7 +185,9 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
DownloadLink dlLink = link.getDownloadLink();
if (dlLink != null) {
if (StringUtils.isNotEmpty(finalComment)) dlLink.setComment(finalComment);
if (StringUtils.isNotEmpty(finalComment)) {
dlLink.setComment(finalComment);
}
}
if (pws != null && pws.size() > 0) {
link.getArchiveInfo().getExtractionPasswords().addAll(pws);
@ -190,7 +196,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
});
LinkCollector.getInstance().addCrawlerJob(job);
}
/* decrypt given bytearray with given aes key */
public static String decrypt(byte[] b, byte[] key) {
Cipher cipher;
@ -205,7 +211,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
return null;
}
/* decrypt given crypted string with js encrypted aes key */
public static String decrypt(String crypted, final String jk, String k) {
byte[] key = null;
@ -244,7 +250,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
byte[] baseDecoded = Base64.decode(crypted);
return decrypt(baseDecoded, key).trim();
}
public void add(RemoteAPIResponse response, RemoteAPIRequest request) throws InternalApiException {
try {
askPermission(request);
@ -255,7 +261,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
writeString(response, request, "failed " + e.getMessage() + "\r\n", true);
}
}
// For My JD API
@Override
public void add(String passwords, String source, String urls) throws InternalApiException {
@ -267,12 +273,12 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
job.setCustomSourceUrl(source);
// job.setCustomComment(comment);
// job.setPackageName(HttpRequest.getParameterbyKey(request, "package"));
if (StringUtils.isNotEmpty(passwords)) {
final HashSet<String> pws = new HashSet<String>();
pws.add(passwords);
job.setCrawledLinkModifier(new CrawledLinkModifier() {
@Override
public void modifyCrawledLink(CrawledLink link) {
if (pws != null && pws.size() > 0) {
@ -283,12 +289,14 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
LinkCollector.getInstance().addCrawlerJob(job);
}
public void addcrypted(RemoteAPIResponse response, RemoteAPIRequest request) throws InternalApiException {
try {
askPermission(request);
String dlcContent = request.getParameterbyKey("crypted");
if (dlcContent == null) throw new IllegalArgumentException("no DLC Content available");
if (dlcContent == null) {
throw new IllegalArgumentException("no DLC Content available");
}
String dlc = dlcContent.trim().replace(" ", "+");
File tmp = Application.getTempResource("jd_" + System.currentTimeMillis() + ".dlc");
IO.writeToFile(tmp, dlc.getBytes("UTF-8"));
@ -299,7 +307,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
writeString(response, request, "failed " + e.getMessage() + "\r\n", true);
}
}
private synchronized void askPermission(HttpRequestInterface request) throws IOException, DialogNoAnswerException {
HTTPHeader jdrandomNumber = request.getRequestHeaders().get("jd.randomnumber");
if (jdrandomNumber != null && jdrandomNumber.getValue() != null && jdrandomNumber.getValue().equalsIgnoreCase(System.getProperty("jd.randomNumber"))) {
@ -355,17 +363,19 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
if (url != null) {
/* we can only save permission if an url is available */
if (allowed == null) allowed = new ArrayList<String>();
if (allowed == null) {
allowed = new ArrayList<String>();
}
allowed.add(url);
JsonConfig.create(RemoteAPIConfig.class).setExternInterfaceAuth(allowed);
}
}
public void alive(RemoteAPIResponse response, RemoteAPIRequest request) throws InternalApiException {
writeString(response, request, "JDownloader\r\n", true);
}
public void favicon(RemoteAPIResponse response) throws InternalApiException {
OutputStream out = null;
try {
@ -382,7 +392,7 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
}
}
public void flashgot(RemoteAPIResponse response, RemoteAPIRequest request) throws InternalApiException {
try {
askPermission(request);
@ -405,27 +415,33 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
LinkCollectingJob job = new LinkCollectingJob(new LinkOriginDetails(LinkOrigin.FLASHGOT, request.getRequestHeaders().getValue("user-agent")), null);
final String finalPackageName = request.getParameterbyKey("package");
final String finalDestination = request.getParameterbyKey("dir");
job.setCrawledLinkModifier(new CrawledLinkModifier() {
private HashSet<String> pws = null;
{
if (archivePasswords != null) {
pws = new HashSet<String>();
for (String p : archivePasswords) {
if (StringUtils.isNotEmpty(p)) pws.add(p);
if (StringUtils.isNotEmpty(p)) {
pws.add(p);
}
}
if (pws.size() == 0) {
pws = null;
}
if (pws.size() == 0) pws = null;
}
}
private PackageInfo getPackageInfo(CrawledLink link) {
PackageInfo packageInfo = link.getDesiredPackageInfo();
if (packageInfo != null) return packageInfo;
if (packageInfo != null) {
return packageInfo;
}
packageInfo = new PackageInfo();
link.setDesiredPackageInfo(packageInfo);
return packageInfo;
}
@Override
public void modifyCrawledLink(CrawledLink link) {
if (StringUtils.isNotEmpty(finalPackageName)) {
@ -445,10 +461,10 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
}
});
LazyHostPlugin lazyp = HostPluginController.getInstance().get("DirectHTTP");
final PluginForHost defaultplg = lazyp.getPrototype(null);
java.util.List<CrawledLink> links = new ArrayList<CrawledLink>();
for (int index = 0; index <= urls.length - 1; index++) {
CrawledLink link = new CrawledLink(urls[index]);
@ -461,22 +477,28 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
}
}
final String downloadPassword = tmpDownloadPassword;
final int index2 = index;
link.setCustomCrawledLinkModifier(new CrawledLinkModifier() {
public void modifyCrawledLink(CrawledLink link) {
DownloadLink dl = link.getDownloadLink();
if (downloadPassword != null) {
dl.setDownloadPassword(downloadPassword);
}
if (!dl.gotBrowserUrl()) dl.setBrowserUrl(referer);
if (index2 < desc.length) dl.setComment(desc[index2]);
if (index2 < fnames.length) dl.forceFileName(fnames[index2]);
if (!dl.gotBrowserUrl()) {
dl.setBrowserUrl(referer);
}
if (index2 < desc.length) {
dl.setComment(desc[index2]);
}
if (index2 < fnames.length) {
dl.forceFileName(fnames[index2]);
}
}
});
link.setUnknownHandler(new UnknownCrawledLinkHandler() {
/*
* this handler transforms unknown links into directhttp links with all information given by flashgot
*/
@ -492,11 +514,15 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
if (downloadPassword != null) {
direct.setDownloadPassword(downloadPassword);
}
if (index2 < desc.length) direct.setComment(desc[index2]);
if (index2 < desc.length) {
direct.setComment(desc[index2]);
}
direct.setProperty("cookies", cookies);
direct.setProperty("post", post);
direct.setProperty("referer", referer);
if (index2 < fnames.length) direct.setProperty("fixName", fnames[index2]);
if (index2 < fnames.length) {
direct.setProperty("fixName", fnames[index2]);
}
try {
defaultplg.correctDownloadLink(direct);
} catch (final Throwable e) {
@ -516,5 +542,5 @@ public class ExternInterfaceImpl implements Cnl2APIBasics, Cnl2APIFlash {
throw new InternalApiException(e);
}
}
}

View File

@ -1,16 +1,17 @@
package jd.http.ext.security;
package org.jdownloader.scripting;
import java.util.concurrent.ConcurrentHashMap;
import net.sourceforge.htmlunit.corejs.javascript.ClassShutter;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.EcmaError;
import net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject;
import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
import net.sourceforge.htmlunit.corejs.javascript.WrapFactory;
import net.sourceforge.htmlunit.corejs.javascript.tools.shell.Global;
import org.appwork.utils.logging.Log;
import org.mozilla.javascript.ClassShutter;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.EcmaError;
import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.WrapFactory;
import org.mozilla.javascript.tools.shell.Global;
/**
* from http://codeutopia.net/blog/2009/01/02/sandboxing-rhino-in-java/
@ -96,7 +97,7 @@ import org.mozilla.javascript.tools.shell.Global;
* @author thomas
*
*/
public class JSPermissionRestricter {
public class JSHtmlUnitPermissionRestricter {
static public class SandboxContextFactory extends ContextFactory {
@Override
protected Context makeContext() {
@ -113,7 +114,7 @@ public class JSPermissionRestricter {
if (className.startsWith("adapter")) {
return true;
} else if (className.equals("org.mozilla.javascript.EcmaError")) {
} else if (className.equals("net.sourceforge.htmlunit.corejs.javascript.EcmaError")) {
Log.L.severe("Javascript error occured");
return true;
} else {
@ -146,6 +147,7 @@ public class JSPermissionRestricter {
private static final long serialVersionUID = -2783084485265910840L;
public SandboxNativeJavaObject(Scriptable scope, Object javaObject, Class<?> staticType) {
super(scope, javaObject, staticType);
}
@ -168,11 +170,11 @@ public class JSPermissionRestricter {
private static ConcurrentHashMap<Thread, Boolean> TRUSTED_THREAD = new ConcurrentHashMap<Thread, Boolean>();
public static void evaluateTrustedString(Context cx, Global scope, String source, String sourceName, int lineno, Object securityDomain) {
public static Object evaluateTrustedString(Context cx, Global scope, String source, String sourceName, int lineno, Object securityDomain) {
try {
TRUSTED_THREAD.put(Thread.currentThread(), true);
cx.evaluateString(scope, source, sourceName, lineno, securityDomain);
return cx.evaluateString(scope, source, sourceName, lineno, securityDomain);
} finally {
TRUSTED_THREAD.remove(Thread.currentThread());
}

View File

@ -0,0 +1,238 @@
package org.jdownloader.scripting;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.appwork.exceptions.WTFException;
import org.appwork.utils.logging.Log;
import sun.org.mozilla.javascript.internal.ClassShutter;
import sun.org.mozilla.javascript.internal.Context;
import sun.org.mozilla.javascript.internal.ContextFactory;
import sun.org.mozilla.javascript.internal.EcmaError;
import sun.org.mozilla.javascript.internal.NativeJavaObject;
import sun.org.mozilla.javascript.internal.Scriptable;
import sun.org.mozilla.javascript.internal.WrapFactory;
/**
* from http://codeutopia.net/blog/2009/01/02/sandboxing-rhino-in-java/
*
* ============================================================================ =========
*
* Sandboxing Rhino in Java January 2, 2009 12:07 am Tags: Java, JavaScript, Security Ive been working on a Java app which needed Rhino
* for scripting. The app would need to run untrusted JavaScript code from 3rd parties, so I had to find a way to block access to all Java
* methods, except the ones I wanted. This would not be a problem if there was an easy way to disable LiveConnect - the feature of Rhino
* which provides java access to scripts - but there is no such thing.
*
* However, after a lot of digging around, I finally found a way to do this without too much hacking. In fact, it can be done by just
* extending a few of the Rhino classes, and using the setters provided to override some of the default ones.
*
*
* ClassShutter
*
* Lets first look at the ClassShutter, which can be used to restrict access to Java packages and classes.
*
* //cx is the Context instance you're using to run scripts cx.setClassShutter(new ClassShutter() { public boolean visibleToScripts(String
* className) { if(className.startsWith("adapter")) return true;
*
* return false; } }); The above will effectively disable access to all Java classes onwards from the point where the shutter was set.
* However, if you run any scripts before setting the shutter, classes accessed there can still be used! You can use this to your advantage,
* for example to provide specific classes in the scripts under different names or such.
*
* You probably noticed the comparison to adapter in the shutter. This is for when you implement interfaces or extend Java classes. Rhino
* will create new classes based on those interfaces/classes, and they will be called adapterN, where N is a number. If you block access to
* classes starting with adapter, you cant implement or extend, and my use-case required that.
*
* However, there is a limitation in the ClassShutter
*
* Reflection
*
* As you may know, you can use someInstance.getClass().forName(some.package.Class).newInstance() to get a new instance of
* some.package.Class.
*
* This will not get blocked by the ClassShutter! We need to disable access to getClass() to block this.
*
* While the ClassShutter is relatively well documented, doing this required more research. A post in the Rhino mailing list finally pushed
* me to the right direction: Overriding certain NativeJavaObject methods and creating a custom ContextFactory and WrapFactory for that.
*
* Here is an extended NativeJavaObject, which blocks access to getClass. You could use this approach to block access to other methods too:
*
* public static class SandboxNativeJavaObject extends NativeJavaObject { public SandboxNativeJavaObject(Scriptable scope, Object
* javaObject, Class staticType) { super(scope, javaObject, staticType); }
*
* @Override public Object get(String name, Scriptable start) { if (name.equals("getClass")) { return NOT_FOUND; }
*
* return super.get(name, start); } } To make the above class work, you need two more classes:
*
* A WrapFactory which returns our SandboxNativeJavaObjects
*
* public static class SandboxWrapFactory extends WrapFactory {
* @Override public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { return new
* SandboxNativeJavaObject(scope, javaObject, staticType); } } And a ContextFactory, which returns Contexts which use
* SandboxWrapFactory:
*
* public class SandboxContextFactory extends ContextFactory {
* @Override protected Context makeContext() { Context cx = super.makeContext(); cx.setWrapFactory(new SandboxWrapFactory()); return cx; } }
* Finally, to make all this work, we need to tell Rhino the global ContextFactory:
*
* ContextFactory.initGlobal(new SandboxContextFactory()); With this, we are done. Now, when you use
* ContextFactory.getGlobal().enterContext(), you will get sandboxing contexts. But why did we need to set it globally? This is
* because it would appear that certain things, such as the adapter classes, use the global context factory to get some context
* for themselves, and without setting the global factory, they would get unlimited access.
*
* In closing
*
* I hope this is useful for someone. It took me a long time to figure it all out, so here it is now, all documented in one place.
* =)
*
* The mailing list post where I found the direction for blocking getClass can be found here. Thanks to Charles Lowell.
*
* There is also the SecurityController, which may be useful in further securing the class.
*
* And as a final warning, while this approach works for me, and I havent yet found any way to get past the sandboxing and into
* Java-land but there may be a way, and if you find one, do let me know.
*
*
*
* ================================================================== == =================
* @author thomas
*
*/
public class JSPermissionRestricter {
static public class SandboxContextFactory extends ContextFactory {
private ContextFactory rhinoFactory;
private Method makeContextMethod;
public SandboxContextFactory(ContextFactory rhinoFactory) throws NoSuchMethodException, SecurityException {
this.rhinoFactory = rhinoFactory;
makeContextMethod = ContextFactory.class.getDeclaredMethod("makeContext", new Class[] {});
makeContextMethod.setAccessible(true);
}
@Override
protected Context makeContext() {
Context cx;
try {
cx = (Context) makeContextMethod.invoke(rhinoFactory, new Object[] {});
Field classShutterInstance = Context.class.getDeclaredField("classShutter");
classShutterInstance.setAccessible(true);
final ClassShutter oldShutter = (ClassShutter) classShutterInstance.get(cx);
cx.setWrapFactory(new SandboxWrapFactory(cx.getWrapFactory()));
classShutterInstance.set(cx, new ClassShutter() {
public boolean visibleToScripts(String className) {
if (!oldShutter.visibleToScripts(className)) {
return false;
}
Thread cur = Thread.currentThread();
if (TRUSTED_THREAD.containsKey(cur)) {
Log.L.severe("Trusted Thread Loads: " + className);
return true;
}
if (className.startsWith("adapter")) {
return true;
} else if (className.equals("sun.org.mozilla.javascript.internal.EcmaError")) {
Log.L.severe("Javascript error occured");
return true;
} else {
throw new RuntimeException("Security Violation " + className);
}
}
});
return cx;
} catch (Throwable e) {
throw new WTFException(e);
}
}
}
public static class SandboxWrapFactory extends WrapFactory {
private WrapFactory rhinoFactory;
public SandboxWrapFactory(WrapFactory wrapFactory) {
this.rhinoFactory = wrapFactory;
}
@SuppressWarnings("rawtypes")
@Override
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
if (javaObject instanceof EcmaError) {
Log.exception((EcmaError) javaObject);
}
return new SandboxNativeJavaObject(scope, javaObject, staticType);
}
}
public static class SandboxNativeJavaObject extends NativeJavaObject {
private static final long serialVersionUID = -2783084485265910840L;
public SandboxNativeJavaObject(Scriptable scope, Object javaObject, Class<?> staticType) {
super(scope, javaObject, staticType);
}
@Override
public Object get(String name, Scriptable start) {
if (name.equals("getClass")) {
Log.L.severe("JS Security Exception");
return NOT_FOUND;
}
return super.get(name, start);
}
}
public static void init() {
// this is onlypossible before RhineScriptEngine is loaded
// GlobalSetter getGlobalSetter = ContextFactory.getGlobalSetter();
try {
// force init
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
engine.eval("java.lang.System.out.println('TEST')");
Field globalField = ContextFactory.class.getDeclaredField("global");
globalField.setAccessible(true);
Object global = globalField.get(null);
globalField.set(null, new SandboxContextFactory((ContextFactory) global));
// try again. now this native call should throw an exception.
try {
manager = new ScriptEngineManager();
engine = manager.getEngineByName("javascript");
engine.eval("java.lang.System.out.println('TEST')");
throw new SecurityException("Could not install the sun.org.mozilla.javascript.internal Sandbox!");
} catch (RuntimeException e) {
// this time, an exception is fine
}
} catch (Throwable e) {
e.printStackTrace();
}
}
private static ConcurrentHashMap<Thread, Boolean> TRUSTED_THREAD = new ConcurrentHashMap<Thread, Boolean>();
}

View File

@ -12,6 +12,10 @@ import java.util.concurrent.atomic.AtomicLong;
import jd.http.Browser;
import jd.http.Cookies;
import jd.http.Request;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.EcmaError;
import net.sourceforge.htmlunit.corejs.javascript.tools.shell.Global;
import org.appwork.exceptions.WTFException;
import org.appwork.storage.JSonStorage;
@ -20,11 +24,12 @@ import org.appwork.utils.IO;
import org.appwork.utils.logging2.LogSource;
import org.appwork.utils.net.HTTPHeader;
import org.jdownloader.logging.LogController;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.EcmaError;
import org.mozilla.javascript.tools.shell.Global;
import org.jdownloader.scripting.JSHtmlUnitPermissionRestricter;
public class EnvJS {
static {
JSHtmlUnitPermissionRestricter.init();
}
private Context cx;
private Global scope;
private long id;
@ -75,6 +80,7 @@ public class EnvJS {
if ("get".equalsIgnoreCase(method)) {
br.getPage(url);
}
XHRResponse ret = new XHRResponse();
for (Entry<String, List<String>> s : br.getRequest().getResponseHeaders().entrySet()) {
ret.getResponseHeader().put(s.getKey(), s.getValue().get(0));
@ -92,6 +98,9 @@ public class EnvJS {
INSTANCES.put(id, new WeakReference<EnvJS>(this));
logger = LogController.getInstance().getLogger(EnvJS.class.getName());
ContextFactory gs = ContextFactory.getGlobal();
System.out.println(gs);
}
public void breakIt() {
@ -151,7 +160,9 @@ public class EnvJS {
if ("css".equals(path)) {
return IO.readURLToString(EnvJS.class.getResource(path + ".js"));
}
if ("base64".equals(path)) {
return IO.readURLToString(EnvJS.class.getResource(path + ".js"));
}
throw new WTFException("Unknown Resource required: " + path);
}
@ -164,7 +175,8 @@ public class EnvJS {
cx.setLanguageVersion(Context.VERSION_1_5);
br = new Browser();
// org.mozilla.javascript.EcmaError: ReferenceError: "JSON" is not defined. (js#508) exceptions in the log are ok.
// net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "JSON" is not defined. (js#508) exceptions in the log are
// ok.
try {
evaluateTrustedString(cx, scope, "var EnvJSinstanceID=" + id + ";", "setInstance", 1, null);
// evaluateTrustedString(cx, scope, IO.readURLToString(EnvJS.class.getResource("env.rhino.js")), "oldRhino", 1, null);
@ -178,10 +190,10 @@ public class EnvJS {
}
}
public void eval(String js) {
public Object eval(String js) {
// cx.evaluateString(scope, js, "js", 1, null);
evaluateTrustedString(cx, scope, js, "eval", 1, null);
return evaluateTrustedString(cx, scope, js, "eval", 1, null);
}
public void setDocument(String url, String html) {
@ -192,10 +204,10 @@ public class EnvJS {
private LinkedList<String> scriptStack = new LinkedList<String>();
private void evaluateTrustedString(Context cx2, Global scope2, String js, String string, int i, Object object) {
private Object evaluateTrustedString(Context cx2, Global scope2, String js, String string, int i, Object object) {
scriptStack.add(string);
try {
jd.http.ext.security.JSPermissionRestricter.evaluateTrustedString(cx2, scope2, js, string, i, object);
return cx2.evaluateString(scope, js, string, i, object);
} catch (EcmaError e) {
logger.log(e);
throw e;
@ -214,4 +226,12 @@ public class EnvJS {
}
return null;
}
public Browser getBrowser() {
return br;
}
public void require(String string) throws IOException {
JSHtmlUnitPermissionRestricter.evaluateTrustedString(cx, scope, readRequire(string), "setInstance", 1, null);
}
}

View File

@ -0,0 +1,182 @@
/*
* Copyright (c) 2010 Nick Galbreath
* http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/* base64 encode/decode compatible with window.btoa/atob
*
* window.atob/btoa is a Firefox extension to convert binary data (the "b")
* to base64 (ascii, the "a").
*
* It is also found in Safari and Chrome. It is not available in IE.
*
* if (!window.btoa) window.btoa = base64.encode
* if (!window.atob) window.atob = base64.decode
*
* The original spec's for atob/btoa are a bit lacking
* https://developer.mozilla.org/en/DOM/window.atob
* https://developer.mozilla.org/en/DOM/window.btoa
*
* window.btoa and base64.encode takes a string where charCodeAt is [0,255]
* If any character is not [0,255], then an DOMException(5) is thrown.
*
* window.atob and base64.decode take a base64-encoded string
* If the input length is not a multiple of 4, or contains invalid characters
* then an DOMException(5) is thrown.
*/
var base64 = {};
base64.PADCHAR = '=';
base64.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
base64.makeDOMException = function() {
// sadly in FF,Safari,Chrome you can't make a DOMException
var e, tmp;
try {
return new DOMException(DOMException.INVALID_CHARACTER_ERR);
} catch (tmp) {
// not available, just passback a duck-typed equiv
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error/prototype
var ex = new Error("DOM Exception 5");
// ex.number and ex.description is IE-specific.
ex.code = ex.number = 5;
ex.name = ex.description = "INVALID_CHARACTER_ERR";
// Safari/Chrome output format
ex.toString = function() { return 'Error: ' + ex.name + ': ' + ex.message; };
return ex;
}
}
base64.getbyte64 = function(s,i) {
// This is oddly fast, except on Chrome/V8.
// Minimal or no improvement in performance by using a
// object with properties mapping chars to value (eg. 'A': 0)
var idx = base64.ALPHA.indexOf(s.charAt(i));
if (idx === -1) {
throw base64.makeDOMException();
}
return idx;
}
base64.decode = function(s) {
// convert to string
s = '' + s;
var getbyte64 = base64.getbyte64;
var pads, i, b10;
var imax = s.length
if (imax === 0) {
return s;
}
if (imax % 4 !== 0) {
throw base64.makeDOMException();
}
pads = 0
if (s.charAt(imax - 1) === base64.PADCHAR) {
pads = 1;
if (s.charAt(imax - 2) === base64.PADCHAR) {
pads = 2;
}
// either way, we want to ignore this last block
imax -= 4;
}
var x = [];
for (i = 0; i < imax; i += 4) {
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) |
(getbyte64(s,i+2) << 6) | getbyte64(s,i+3);
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff));
}
switch (pads) {
case 1:
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | (getbyte64(s,i+2) << 6);
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff));
break;
case 2:
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12);
x.push(String.fromCharCode(b10 >> 16));
break;
}
return x.join('');
}
base64.getbyte = function(s,i) {
var x = s.charCodeAt(i);
if (x > 255) {
throw base64.makeDOMException();
}
return x;
}
base64.encode = function(s) {
if (arguments.length !== 1) {
throw new SyntaxError("Not enough arguments");
}
var padchar = base64.PADCHAR;
var alpha = base64.ALPHA;
var getbyte = base64.getbyte;
var i, b10;
var x = [];
// convert to string
s = '' + s;
var imax = s.length - s.length % 3;
if (s.length === 0) {
return s;
}
for (i = 0; i < imax; i += 3) {
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8) | getbyte(s,i+2);
x.push(alpha.charAt(b10 >> 18));
x.push(alpha.charAt((b10 >> 12) & 0x3F));
x.push(alpha.charAt((b10 >> 6) & 0x3f));
x.push(alpha.charAt(b10 & 0x3f));
}
switch (s.length - imax) {
case 1:
b10 = getbyte(s,i) << 16;
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) +
padchar + padchar);
break;
case 2:
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8);
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) +
alpha.charAt((b10 >> 6) & 0x3f) + padchar);
break;
}
return x.join('');
}
if (!window.btoa) window.btoa = base64.encode;
if (!window.atob) window.atob = base64.decode;

File diff suppressed because one or more lines are too long

View File

@ -990,11 +990,11 @@ Envjs.tick = function(){
var y, next, fn, arg, file;
log = log||Envjs.logger('Envjs.Core');
log.debug('go through %s events', eventQueue.length);
// log.debug('go through %s events', eventQueue.length);
next = eventQueue.shift();
while( next ){
log.debug('next event %s', next.event);
// log.debug('next event %s', next.event);
if(next.event in eventListeners){
if('exit' === next.event){
@ -1002,9 +1002,9 @@ Envjs.tick = function(){
Envjs.exit();
}
for(y = 0; y < eventListeners[next.event].length; y++){
log.debug('event %s %s', y, next.event);
// log.debug('event %s %s', y, next.event);
fn = eventListeners[next.event][y];
log.debug(fn+"");
// log.debug(fn+"");
fn.apply(fn, next.args);
}
}
@ -2372,12 +2372,12 @@ Envjs.on('tick', function(type, now){
timers = Envjs.timers,
timer,
i;
console.log('handling %s timer(s) in tick', timers.length);
// console.log('handling %s timer(s) in tick', timers.length);
for(i = 0; i < timers.length;){
timer = timers[i];
console.log('scheduled for %s , currently %s', timer.at, now);
// console.log('scheduled for %s , currently %s', timer.at, now);
if(timer.at <= now){
console.log('timer past due: at(%s), now(%s), type(%s)',timer.at, now, timer.type);
// console.log('timer past due: at(%s), now(%s), type(%s)',timer.at, now, timer.type);
switch(timer.type){
case 'timeout':
//we need to remove it from the timers list and add it to the callback list
@ -2398,7 +2398,7 @@ Envjs.on('tick', function(type, now){
i++;
}
}
console.log('timer tick has %s callbacks', callbacks.length);
// console.log('timer tick has %s callbacks', callbacks.length);
//finally we need to execute the callbacks in the order added to this stack
for(i = 0; i < callbacks.length; i++){
timer = callbacks[i];

View File

@ -8,7 +8,7 @@
var Envjs = Envjs || require('envjs/platform/core').Envjs;
require('local_settings');
var __context__ = Packages.org.mozilla.javascript.Context.getCurrentContext();
var __context__ = Packages.net.sourceforge.htmlunit.corejs.javascript.Context.getCurrentContext();
Envjs.platform = "Rhino";
Envjs.revision = "1.7.0.rc2";

View File

@ -32,7 +32,7 @@ javaInstance=Packages.org.jdownloader.scripting.envjs.EnvJS.get(EnvJSinstanceID)
try {
var ctx = org.mozilla.javascript.Context.getCurrentContext();
var ctx = net.sourceforge.htmlunit.corejs.javascript.Context.getCurrentContext();
var func = ctx.evaluateString({}, source, id, 1, null);
func(require, cached[id].exports, cached[id].module);
} finally {

View File

@ -51,9 +51,9 @@ Envjs.once('tick', function(){
* @param {Object} time
*/
exports.setTimeout = setTimeout = function(fn, time){
console.log("timeout "+fn);
log.debug('setTimeout %s', time);
console.log("timeout2 "+fn);
// console.log("timeout "+fn);
// log.debug('setTimeout %s', time);
// console.log("timeout2 "+fn);
return Envjs.timers.addTimerOrInterval(fn, time, 'timeout');
};