CustomizedScriptEngineManager:

-updated constructor
JSRhinoPermissionRestricter:
-updated logging
ScriptEngineFactoryService.html:
-serviceloader for CustomRhinoScriptEngineFactory for Java >=15
-fixes #89444
JDClassLoaderLauncher:
-added serviceloader hack for ScriptEngineFactoryService for Java >=15
-fixes #89444
PluginForHost:
-updated updateDownloadLink to use DownloadLink.resume
DeepbridCom:
-updated error handling
LinkCrawlerDeepInspector:
-added support for binary/octet-stream content type
jsyntaxpane.jar:
-updated Action js and removed example code, caused security violation in our rhino sandbox

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@43740 ebf7c1c2-ba36-0410-9fe8-c592906822b4

Former-commit-id: 215fc630d7bcc449d7ad55aa80d35a6feb6a0173
This commit is contained in:
jiaz 2021-02-04 17:15:35 +00:00
parent f6a22d571c
commit 7a915f0cdc
15 changed files with 403 additions and 379 deletions

Binary file not shown.

View File

@ -595,15 +595,15 @@ public class DownloadController extends PackageController<FilePackage, DownloadL
private final ArrayList<IndexedDownloadLink> downloadLinks = new ArrayList<IndexedDownloadLink>();
private final static Comparator<IndexedDownloadLink> COMPARATOR = new Comparator<IndexedDownloadLink>() {
private final int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
private final int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
@Override
public int compare(IndexedDownloadLink o1, IndexedDownloadLink o2) {
return compare(o1.getIndex(), o2.getIndex());
}
};
@Override
public int compare(IndexedDownloadLink o1, IndexedDownloadLink o2) {
return compare(o1.getIndex(), o2.getIndex());
}
};
private FilePackage getLoadedPackage() {
final FilePackage filePackage = this.filePackage;
@ -1187,6 +1187,7 @@ public class DownloadController extends PackageController<FilePackage, DownloadL
break;
case NAME:
case RESET:
case RESUME:
case ENABLED:
case AVAILABILITY:
case PRIORITY:

View File

@ -50,6 +50,8 @@ public abstract class LinkCrawlerDeepInspector {
}
} else if (hasContentType && (!isTextContent(urlConnection) && contentType.matches("(?i)^(application|audio|video|image)/.+"))) {
return true;
} else if (hasContentType && (!isTextContent(urlConnection) && contentType.matches("(?i)^binary/octet-stream"))) {
return true;
} else if (!hasContentType && completeContentLength > 0 && hasStrongEtag) {
return true;
} else if (!hasContentType && completeContentLength > 0 && allowsByteRanges) {

View File

@ -30,6 +30,19 @@ import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Pattern;
import jd.config.Property;
import jd.controlling.downloadcontroller.DownloadLinkCandidate;
import jd.controlling.downloadcontroller.DownloadWatchDog;
import jd.controlling.downloadcontroller.HistoryEntry;
import jd.controlling.downloadcontroller.SingleDownloadController;
import jd.controlling.linkcrawler.CheckableLink;
import jd.controlling.packagecontroller.AbstractNodeNotifier;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.plugins.DownloadLinkDatabindingInterface.Key;
import jd.plugins.download.DownloadInterface;
import jd.plugins.download.HashInfo;
import jd.plugins.download.HashInfo.TYPE;
import org.appwork.exceptions.WTFException;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
@ -59,19 +72,6 @@ import org.jdownloader.plugins.SkipReason;
import org.jdownloader.settings.GeneralSettings;
import org.jdownloader.settings.staticreferences.CFG_GENERAL;
import jd.config.Property;
import jd.controlling.downloadcontroller.DownloadLinkCandidate;
import jd.controlling.downloadcontroller.DownloadWatchDog;
import jd.controlling.downloadcontroller.HistoryEntry;
import jd.controlling.downloadcontroller.SingleDownloadController;
import jd.controlling.linkcrawler.CheckableLink;
import jd.controlling.packagecontroller.AbstractNodeNotifier;
import jd.controlling.packagecontroller.AbstractPackageChildrenNode;
import jd.plugins.DownloadLinkDatabindingInterface.Key;
import jd.plugins.download.DownloadInterface;
import jd.plugins.download.HashInfo;
import jd.plugins.download.HashInfo.TYPE;
/**
* Hier werden alle notwendigen Informationen zu einem einzelnen Download festgehalten. Die Informationen werden dann in einer Tabelle
* dargestellt
@ -84,7 +84,6 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
FALSE(_GUI.T.linkgrabber_onlinestatus_offline()),
UNCHECKABLE(_GUI.T.linkgrabber_onlinestatus_uncheckable()),
TRUE(_GUI.T.linkgrabber_onlinestatus_online());
private final String exp;
private AvailableStatus(String exp) {
@ -965,7 +964,7 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
/*
* Gibt zurueck ob Dieser Link schon auf verfuegbarkeit getestet wurde.+ Diese FUnktion fuehrt keinen!! Check durch. Sie prueft nur ob
* schon geprueft worden ist. anschiessend kann mit isAvailable() die verfuegbarkeit ueberprueft werden
*
*
* @return Link wurde schon getestet (true) nicht getestet(false)
*/
public boolean isAvailabilityStatusChecked() {
@ -1102,7 +1101,7 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
setConditionalSkipReason(null);
setEnabled(true);
if (resetPlugins != null) {
for (PluginForHost resetPlugin : resetPlugins) {
for (final PluginForHost resetPlugin : resetPlugins) {
try {
resetPlugin.resumeDownloadlink(this);
} catch (final Throwable e) {
@ -1110,6 +1109,9 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
}
}
}
if (hasNotificationListener()) {
notifyChanges(AbstractNodeNotifier.NOTIFY.PROPERTY_CHANCE, new DownloadLinkProperty(this, DownloadLinkProperty.Property.RESUME, null));
}
}
public void setAvailable(boolean available) {

View File

@ -2,6 +2,7 @@ package jd.plugins;
public class DownloadLinkProperty {
public static enum Property {
RESUME,
RESET,
NAME,
PRIORITY,
@ -16,7 +17,6 @@ public class DownloadLinkProperty {
LINKSTATUS,
ARCHIVE_ID,
DOWNLOAD_CONTROLLER,
CHUNKS,
SPEED_LIMIT,
DOWNLOAD_PASSWORD,

View File

@ -186,14 +186,14 @@ import org.jdownloader.updatev2.UpdateController;
public abstract class PluginForHost extends Plugin {
private static final String COPY_MOVE_FILE = "CopyMoveFile";
private static final Pattern[] PATTERNS = new Pattern[] {
/**
* these patterns should split filename and fileextension (extension must include the
* point)
*/
// multipart rar archives
Pattern.compile("(.*)(\\.pa?r?t?\\.?[0-9]+.*?\\.rar$)", Pattern.CASE_INSENSITIVE),
// normal files with extension
Pattern.compile("(.*)(\\..*?$)", Pattern.CASE_INSENSITIVE) };
/**
* these patterns should split filename and fileextension (extension must include the
* point)
*/
// multipart rar archives
Pattern.compile("(.*)(\\.pa?r?t?\\.?[0-9]+.*?\\.rar$)", Pattern.CASE_INSENSITIVE),
// normal files with extension
Pattern.compile("(.*)(\\..*?$)", Pattern.CASE_INSENSITIVE) };
private LazyHostPlugin lazyP = null;
/**
* Is true if the user has answered a captcha challenge. Does not say anything whether or not the answer was correct.
@ -1281,16 +1281,16 @@ public abstract class PluginForHost extends Plugin {
public void handleMultiHost(DownloadLink downloadLink, Account account) throws Exception {
/*
* fetchAccountInfo must fill ai.setMultiHostSupport to signal all supported multiHosts
*
*
* please synchronized on accountinfo and the ArrayList<String> when you change something in the handleMultiHost function
*
*
* in fetchAccountInfo we don't have to synchronize because we create a new instance of AccountInfo and fill it
*
*
* if you need customizable maxDownloads, please use getMaxSimultanDownload to handle this you are in multihost when account host
* does not equal link host!
*
*
*
*
*
*
* will update this doc about error handling
*/
logger.severe("invalid call to handleMultiHost: " + downloadLink.getName() + ":" + downloadLink.getHost() + " to " + getHost() + ":" + this.getVersion() + " with " + account);
@ -2079,7 +2079,7 @@ public abstract class PluginForHost extends Plugin {
if (downloadLink != null && url != null) {
downloadLink.setPluginPatternMatcher(url);
downloadLink.setDomainInfo(null);
downloadLink.setAvailableStatus(AvailableStatus.UNCHECKED);
downloadLink.resume(Arrays.asList(new PluginForHost[] { this }));
final LinkChecker<CheckableLink> linkChecker = new LinkChecker<CheckableLink>(true);
linkChecker.check(checkableLink);
}

View File

@ -19,10 +19,6 @@ import java.util.ArrayList;
import java.util.Locale;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.appwork.utils.StringUtils;
import org.jdownloader.plugins.components.antiDDoSForDecrypt;
import jd.PluginWrapper;
import jd.controlling.ProgressController;
@ -33,6 +29,10 @@ import jd.plugins.DecrypterPlugin;
import jd.plugins.DownloadLink;
import jd.plugins.FilePackage;
import org.appwork.utils.StringUtils;
import org.jdownloader.plugins.components.antiDDoSForDecrypt;
import org.jdownloader.scripting.JavaScriptEngineFactory;
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "asbook.info" }, urls = { "https?://(www\\.)?(asbook\\.info|asbookonline\\.com)/[^/]+/?" })
public class AsBook extends antiDDoSForDecrypt {
public AsBook(PluginWrapper wrapper) {
@ -57,7 +57,7 @@ public class AsBook extends antiDDoSForDecrypt {
getPage(br2, iframeURL);
String[][] trackDetails = br2.getRegex("<a[^>]+href\\s*=\\s*\"([^\"]+)\"[^>]+data-code\\s*=\\s*\"([^\"]+)\"[^>]*>").getMatches();
final String decryptJS = getDecryptJS(br2);
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
final ScriptEngine engine = JavaScriptEngineFactory.getScriptEngineManager(null).getEngineByName("js");
engine.eval("var res = \"\";");
engine.eval(decryptJS);
if (trackDetails != null && trackDetails.length > 0) {
@ -72,8 +72,8 @@ public class AsBook extends antiDDoSForDecrypt {
String decodedLink = "";
engine.eval("res = d(f(d(i(\"" + datacode + "\"), p())), c());");
engine.eval("res = n(res);"); // Throws an "org.mozilla.javascript.ConsString cannot be cast to java.lang.String"
// error in the Rhino engine, but works fine in Nashorn, so we're using the latter
// above even though it's deprecated as of JDK 11.
// error in the Rhino engine, but works fine in Nashorn, so we're using the latter
// above even though it's deprecated as of JDK 11.
decodedLink = (String) engine.get("res");
decodedLink = decodedLink.replaceAll("^//", "https://");
DownloadLink dl = createDownloadlink(decodedLink);

View File

@ -22,18 +22,6 @@ import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.utils.DebugMode;
import org.appwork.utils.IO;
import org.appwork.utils.StringUtils;
import org.appwork.utils.formatter.SizeFormatter;
import org.appwork.utils.formatter.TimeFormatter;
import org.jdownloader.captcha.v2.challenge.recaptcha.v2.CaptchaHelperHostPluginRecaptchaV2;
import org.jdownloader.plugins.components.antiDDoSForHost;
import org.jdownloader.plugins.controller.host.LazyHostPlugin.FEATURE;
import org.jdownloader.scripting.JavaScriptEngineFactory;
import jd.PluginWrapper;
import jd.config.Property;
import jd.http.Browser;
@ -55,6 +43,18 @@ import jd.plugins.PluginException;
import jd.plugins.components.MultiHosterManagement;
import jd.plugins.components.PluginJSonUtils;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.utils.DebugMode;
import org.appwork.utils.IO;
import org.appwork.utils.StringUtils;
import org.appwork.utils.formatter.SizeFormatter;
import org.appwork.utils.formatter.TimeFormatter;
import org.jdownloader.captcha.v2.challenge.recaptcha.v2.CaptchaHelperHostPluginRecaptchaV2;
import org.jdownloader.plugins.components.antiDDoSForHost;
import org.jdownloader.plugins.controller.host.LazyHostPlugin.FEATURE;
import org.jdownloader.scripting.JavaScriptEngineFactory;
@HostPlugin(revision = "$Revision$", interfaceVersion = 3, names = { "deepbrid.com" }, urls = { "https?://(?:www\\.)?deepbrid\\.com/dl\\?f=([a-f0-9]{32})" })
public class DeepbridCom extends antiDDoSForHost {
private static final String API_BASE = "https://www.deepbrid.com/backend-dl/index.php";
@ -452,6 +452,7 @@ public class DeepbridCom extends antiDDoSForHost {
errorCode = JavaScriptEngineFactory.toLong(entries.get("error"), 0);
errorMsg = (String) entries.get("message");
} catch (final Throwable e) {
logger.log(e);
}
if (errorCode == 0) {
/* All ok */
@ -479,9 +480,12 @@ public class DeepbridCom extends antiDDoSForHost {
} else {
throw new AccountUnavailableException(errorMsg, 5 * 60 * 1000l);
}
} else if (errorCode == 10) {
/* Filehoster under maintenance on our site */
mhm.putError(account, link, 60 * 60 * 1000l, errorMsg);
} else if (errorCode == 9) {
/* Hosters limit reached for this day */
mhm.putError(account, link, 10 * 60 * 1000l, errorMsg);
mhm.putError(account, link, 60 * 60 * 1000l, errorMsg);
} else if (errorCode == 15) {
/* Service detected usage of proxy which they do not tolerate */
/*

View File

@ -53,7 +53,6 @@ import org.jdownloader.myjdownloader.client.bindings.interfaces.DownloadsEventsI
import org.jdownloader.plugins.FinalLinkState;
public class DownloadControllerEventPublisher implements EventPublisher, DownloadControllerListener, LocalEventsAPIListener, DownloadControllerEventPublisherInterface, DownloadWatchdogListener {
private enum BASIC_EVENT {
REFRESH_STRUCTURE,
REMOVE_CONTENT,
@ -70,18 +69,16 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
private final CopyOnWriteArraySet<RemoteAPIEventsSender> remoteEventSenders = new CopyOnWriteArraySet<RemoteAPIEventsSender>();
private static final List<String> EVENT_ID_LIST;
private final CopyOnWriteArraySet<DownloadLink> linksWithPluginProgress = new CopyOnWriteArraySet<DownloadLink>();
private final CopyOnWriteArrayList<ChannelCollector> collectors = new CopyOnWriteArrayList<ChannelCollector>();
protected final static List<String> INTERVAL_EVENT_ID_LIST = new ArrayList<String>();
private ScheduledExecutorService executer;
private final EventsAPI eventsAPI;
private final AtomicLong backEndChangeID = new AtomicLong(-1);
private final AtomicLong contentChangesCounter = new AtomicLong(-1);
private final Queue queue = new Queue("DownloadControllerEventPublisher") {
public void killQueue() {
};
};
public void killQueue() {
};
};
static {
EVENT_ID_LIST = new ArrayList<String>();
for (BASIC_EVENT t : BASIC_EVENT.values()) {
@ -92,18 +89,15 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
for (Entry<String, Object> es : map.entrySet()) {
EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + "." + es.getKey());
}
map = new SimpleMapper().convert(new PackageQueryStorableDummy(), TypeRef.HASHMAP);
for (Entry<String, Object> es : map.entrySet()) {
EVENT_ID_LIST.add(BASIC_EVENT.PACKAGE_UPDATE.name() + "." + es.getKey());
}
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + ".speed");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + ".bytesLoaded");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + ".eta");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + ".bytesTotal");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.LINK_UPDATE.name() + ".status");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.PACKAGE_UPDATE.name() + ".speed");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.PACKAGE_UPDATE.name() + ".bytesLoaded");
INTERVAL_EVENT_ID_LIST.add(BASIC_EVENT.PACKAGE_UPDATE.name() + ".eta");
@ -280,6 +274,8 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
private static final String LINK_UPDATE_finished = BASIC_EVENT.LINK_UPDATE.name() + ".finished";
private static final String LINK_UPDATE_reset = BASIC_EVENT.LINK_UPDATE.name() + ".reset";
private static final String PACKAGE_UPDATE_reset = BASIC_EVENT.PACKAGE_UPDATE.name() + ".reset";
private static final String LINK_UPDATE_resume = BASIC_EVENT.LINK_UPDATE.name() + ".resume";
private static final String PACKAGE_UPDATE_resume = BASIC_EVENT.PACKAGE_UPDATE.name() + ".resume";
private static final String LINK_UPDATE_running = BASIC_EVENT.LINK_UPDATE.name() + ".running";
private static final String PACKAGE_UPDATE_running = BASIC_EVENT.PACKAGE_UPDATE.name() + ".running";
private static final String PACKAGE_UPDATE_status = BASIC_EVENT.PACKAGE_UPDATE.name() + ".status";
@ -442,7 +438,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
} else {
if (linksWithPluginProgress.add(dl)) {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
updateExecuter(true);
@ -477,6 +472,22 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
flush = true;
}
break;
case RESUME:
if (hasSubscriptionFor(LINK_UPDATE_resume)) {
final HashMap<String, Object> dls = new HashMap<String, Object>();
dls.put("uuid", dl.getUniqueID().getID());
dls.put("resume", "true");
fire(LINK_UPDATE_resume, dls, LINK_UPDATE_resume + "." + dl.getUniqueID().getID());
flush = true;
}
if (hasSubscriptionFor(PACKAGE_UPDATE_reset)) {
final HashMap<String, Object> dls = new HashMap<String, Object>();
dls.put("uuid", dl.getUniqueID().getID());
dls.put("resume", "true");
fire(PACKAGE_UPDATE_resume, dls, PACKAGE_UPDATE_resume + "." + parent.getUniqueID().getID());
flush = true;
}
break;
case RESUMABLE:
break;
case SHA1:
@ -506,7 +517,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
break;
case VARIANTS_ENABLED:
break;
}
}
if (hasContentChanges() && hasSubscriptionFor(BASIC_EVENT.REFRESH_CONTENT.name())) {
@ -551,7 +561,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
private void fire(final String eventID, final Object dls, final String collapseKey) {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
final SimpleEventObject eventObject = new SimpleEventObject(DownloadControllerEventPublisher.this, eventID, dls, collapseKey);
@ -560,7 +569,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
}
return null;
}
});
}
@ -664,7 +672,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
}
final boolean finalExecute = execute;
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
updateExecuter(finalExecute);
@ -678,7 +685,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
synchronized (this) {
if (b) {
if (executer == null) {
executer = Executors.newScheduledThreadPool(1);
executer.scheduleAtFixedRate(new Runnable() {
int terminationRounds = 0;
@ -764,7 +770,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
protected void flushBuffer() {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
if (buffer.size() > 0) {
@ -858,7 +863,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
}
if (collectors.size() > 0) {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
for (final ChannelCollector collector : collectors) {
@ -892,7 +896,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
private void cleanup(DownloadLink dl2) {
if (collectors.size() > 0) {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
final HashSet<DownloadLink> linksToProcess = new HashSet<DownloadLink>();
@ -913,7 +916,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
if (collectors.size() > 0) {
final FilePackage parent = dl.getParentNode();
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
for (final ChannelCollector collector : collectors) {
@ -948,7 +950,6 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
private void pushToBuffer(final ChannelCollector collector, final EventObject eventObject) {
if (collector != null) {
queue.add(new QueueAction<Void, RuntimeException>() {
@Override
protected Void run() throws RuntimeException {
final Object dls = eventObject.getEventdata();
@ -978,5 +979,4 @@ public class DownloadControllerEventPublisher implements EventPublisher, Downloa
public DownloadListDiffStorable queryLinks(LinkQueryStorable queryParams, int diffID) throws BadParameterException {
throw new WTFException("Not Implemented");
}
}

View File

@ -52,7 +52,6 @@ import org.jdownloader.settings.staticreferences.CFG_GENERAL;
import org.jdownloader.settings.staticreferences.CFG_RECONNECT;
public class JDAnywhereEventPublisher implements EventPublisher, AccountControllerListener, DownloadWatchdogListener, DownloadControllerListener, StateEventListener, LinkCollectorListener, CaptchaAPISolverListener {
private CopyOnWriteArraySet<RemoteAPIEventsSender> eventSenders = new CopyOnWriteArraySet<RemoteAPIEventsSender>();
private EventsAPI eventsApi = new EventsAPI();
HashMap<Long, String> linkStatusMessages = new HashMap<Long, String>();
@ -91,131 +90,119 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
}
GenericConfigEventListener<Integer> downloadSpeedLimitEventListener = new GenericConfigEventListener<Integer>() {
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Limitspeed");
data.put("data", CFG_GENERAL.DOWNLOAD_SPEED_LIMIT.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "DOWNLOAD_SPEED_LIMIT");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
// JDAnywhereController.getInstance().getEventsapi().publishEvent(new
// EventObject("SettingsChanged", data), null);
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Limitspeed");
data.put("data", CFG_GENERAL.DOWNLOAD_SPEED_LIMIT.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "DOWNLOAD_SPEED_LIMIT");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
// JDAnywhereController.getInstance().getEventsapi().publishEvent(new
// EventObject("SettingsChanged", data), null);
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
GenericConfigEventListener<Boolean> downloadSpeedLimitEnabledEventListener = new GenericConfigEventListener<Boolean>() {
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "LimitspeedActivated");
data.put("data", CFG_GENERAL.DOWNLOAD_SPEED_LIMIT_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "DOWNLOAD_SPEED_LIMIT_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "LimitspeedActivated");
data.put("data", CFG_GENERAL.DOWNLOAD_SPEED_LIMIT_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "DOWNLOAD_SPEED_LIMIT_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
GenericConfigEventListener<Integer> maxSimultaneDownloadsEventListenr = new GenericConfigEventListener<Integer>() {
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxDL");
data.put("data", CFG_GENERAL.MAX_SIMULTANE_DOWNLOADS.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_SIMULTANE_DOWNLOADS");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxDL");
data.put("data", CFG_GENERAL.MAX_SIMULTANE_DOWNLOADS.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_SIMULTANE_DOWNLOADS");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
GenericConfigEventListener<Integer> maxChunksPerFileEventListener = new GenericConfigEventListener<Integer>() {
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConDL");
data.put("data", CFG_GENERAL.MAX_CHUNKS_PER_FILE.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_CHUNKS_PER_FILE");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConDL");
data.put("data", CFG_GENERAL.MAX_CHUNKS_PER_FILE.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_CHUNKS_PER_FILE");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
GenericConfigEventListener<Integer> maxSiumultaneDownloadsPerHostEventListener = new GenericConfigEventListener<Integer>() {
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConHost");
data.put("data", CFG_GENERAL.MAX_SIMULTANE_DOWNLOADS_PER_HOST.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_SIMULTANE_DOWNLOADS_PER_HOST");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValueModified(KeyHandler<Integer> keyHandler, Integer newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConHost");
data.put("data", CFG_GENERAL.MAX_SIMULTANE_DOWNLOADS_PER_HOST.getValue());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_SIMULTANE_DOWNLOADS_PER_HOST");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
public void onConfigValidatorError(KeyHandler<Integer> keyHandler, Integer invalidValue, ValidationException validateException) {
}
};
GenericConfigEventListener<Boolean> maxDownloadsPerHostEnbledEventListener = new GenericConfigEventListener<Boolean>() {
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConHostActivated");
data.put("data", CFG_GENERAL.MAX_DOWNLOADS_PER_HOST_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_DOWNLOADS_PER_HOST_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "MaxConHostActivated");
data.put("data", CFG_GENERAL.MAX_DOWNLOADS_PER_HOST_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "MAX_DOWNLOADS_PER_HOST_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
GenericConfigEventListener<Boolean> autioReconnectEnabledEventListener = new GenericConfigEventListener<Boolean>() {
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Reconnect");
data.put("data", CFG_RECONNECT.AUTO_RECONNECT_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "AUTO_RECONNECT_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Reconnect");
data.put("data", CFG_RECONNECT.AUTO_RECONNECT_ENABLED.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "AUTO_RECONNECT_ENABLED");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
GenericConfigEventListener<Boolean> useAvailableAccountEventListener = new GenericConfigEventListener<Boolean>() {
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValidatorError(KeyHandler<Boolean> keyHandler, Boolean invalidValue, ValidationException validateException) {
}
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Premium");
data.put("data", CFG_GENERAL.USE_AVAILABLE_ACCOUNTS.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "USE_AVAILABLE_ACCOUNTS");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
public void onConfigValueModified(KeyHandler<Boolean> keyHandler, Boolean newValue) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("message", "Premium");
data.put("data", CFG_GENERAL.USE_AVAILABLE_ACCOUNTS.isEnabled());
SimpleEventObject eventObject = new SimpleEventObject(JDAnywhereEventPublisher.this, EVENTID.SETTINGSCHANGED.name(), data, "USE_AVAILABLE_ACCOUNTS");
for (RemoteAPIEventsSender eventSender : eventSenders) {
eventSender.publishEvent(eventObject, null);
}
}
};
private void publishEvent(EVENTID eventID, Object data, String id) {
SimpleEventObject eventObject = new SimpleEventObject(this, eventID.name(), data, id);
@ -285,23 +272,18 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
private void sendEvent(SolverJob<?> job, String type) {
if (job.getChallenge() instanceof ImageCaptchaChallenge) {
long captchCount = 0;
for (SolverJob<?> entry : CaptchaAPISolver.getInstance().listJobs()) {
if (entry.getChallenge() instanceof ImageCaptchaChallenge) {
captchCount++;
}
}
ImageCaptchaChallenge<?> challenge = (ImageCaptchaChallenge<?>) job.getChallenge();
CaptchaJob apiJob = new CaptchaJob();
if (challenge.getResultType().isAssignableFrom(String.class)) {
apiJob.setType("Text");
} else {
apiJob.setType("Click");
}
apiJob.setID(challenge.getId().getID());
apiJob.setHoster(challenge.getPlugin().getHost());
apiJob.setCaptchaCategory(challenge.getExplain());
@ -337,7 +319,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
for (CrawledLink link : links) {
linkIDs.add(link.getDownloadLink().getUniqueID().toString());
}
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("linkIDs", linkIDs);
publishEvent(EVENTID.LINKCOLLECTORLINKREMOVED, data);
@ -401,9 +382,7 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
id = "CRAWLEDLINK_AVAILABILITY_" + cl.getUniqueID().getID();
publishEvent(EVENTID.CRAWLEDLINKSTATUSCHANGED, data, id);
break;
}
}
}
} else if (event.getParameter() instanceof CrawledPackage) {
@ -506,7 +485,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
@Override
public void onAPIJobDone(SolverJob<?> job) {
sendEvent(job, "expired");
}
@Override
@ -521,7 +499,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
eventSenders.add(eventsAPI);
if (wasEmpty && eventSenders.isEmpty() == false) {
DownloadController.getInstance().addListener(this, true);
CaptchaAPISolver.getInstance().getEventSender().addListener(this);
LinkCollector.getInstance().getEventsender().addListener(this, true);
DownloadWatchDog.getInstance().getStateMachine().addListener(this);
@ -608,7 +585,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
data.put("packageID", dl.getFilePackage().getUniqueID().toString());
data.put("action", "Stopped");
publishEvent(EVENTID.LINKSTATUSCHANGED, data, "DOWNLOADLINK_STOPPED" + dl.getUniqueID().getID());
if (FinalLinkState.CheckFinished(dl.getFinalLinkState())) {
data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("linkID", dl.getUniqueID().getID());
@ -628,7 +604,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
@Override
public void onDownloadControllerAddedPackage(FilePackage pkg) {
downloadApiPackageAdded(pkg);
}
@Override
@ -652,7 +627,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
public void onDownloadControllerRemovedLinklist(List<DownloadLink> list) {
for (DownloadLink link : list) {
downloadApiLinkRemoved(link);
}
}
@ -663,9 +637,7 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
if (dl != null) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
// final DownloadLink dl = dlProperty.getDownloadLink();
switch (dlProperty.getProperty()) {
case AVAILABILITY:
data.put("linkID", dl.getUniqueID().getID());
data.put("packageID", dl.getFilePackage().getUniqueID().toString());
@ -728,6 +700,12 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
data.put("action", "Reset");
publishEvent(EVENTID.LINKCHANGED, data, "DOWNLOADLINK_RESET_" + dl.getUniqueID().getID());
break;
case RESUME:
data.put("linkID", dl.getUniqueID().getID());
data.put("packageID", dl.getFilePackage().getUniqueID().toString());
data.put("action", "Resume");
publishEvent(EVENTID.LINKCHANGED, data, "DOWNLOADLINK_RESUME_" + dl.getUniqueID().getID());
break;
default:
break;
}
@ -753,7 +731,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
@Override
public void onDownloadControllerUpdatedData(FilePackage pkg, FilePackageProperty property) {
if (pkg != null) {
org.jdownloader.myjdownloader.client.json.JsonMap data = new org.jdownloader.myjdownloader.client.json.JsonMap();
data.put("packageID", pkg.getUniqueID().toString());
@ -809,7 +786,6 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
break;
default:
break;
}
publishEvent(EVENTID.ACCOUNTCHANGED, data, "ACCOUNT_" + event.getAccount().getId().toString());
}
@ -818,5 +794,4 @@ public class JDAnywhereEventPublisher implements EventPublisher, AccountControll
@Override
public void onLinkCrawlerFinished() {
}
}

View File

@ -0,0 +1,149 @@
package org.jdownloader.scripting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import org.jdownloader.logging.LogController;
import org.jdownloader.scripting.JavaScriptEngineFactory.RhinoScriptEngine;
public class CustomRhinoScriptEngineFactory implements ScriptEngineFactory {
public CustomRhinoScriptEngineFactory() {
}
public Object getParameter(String key) {
if (key == null) {
throw new IllegalArgumentException("Invalid key:null");
} else if (key.equals(ScriptEngine.NAME)) {
return "javascript";
} else if (key.equals(ScriptEngine.ENGINE)) {
return "Mozilla Rhino";
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
return "1.6 release 2";
} else if (key.equals(ScriptEngine.LANGUAGE)) {
return "javascript";
} else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
return "1.6";
} else if (key.equals("THREADING")) {
return "MULTITHREADED";
} else {
throw new IllegalArgumentException("Invalid key:" + key);
}
}
public ScriptEngine getScriptEngine() {
try {
final RhinoScriptEngine ret = new RhinoScriptEngine();
ret.setEngineFactory(this);
return ret;
} catch (RuntimeException e) {
LogController.CL().log(e);
throw e;
}
}
public String getMethodCallSyntax(String obj, String method, String... args) {
String ret = obj + "." + method + "(";
int len = args.length;
if (len == 0) {
ret += ")";
return ret;
}
for (int i = 0; i < len; i++) {
ret += args[i];
if (i != len - 1) {
ret += ",";
} else {
ret += ")";
}
}
return ret;
}
public String getOutputStatement(String toDisplay) {
StringBuffer buf = new StringBuffer();
int len = toDisplay.length();
buf.append("print(\"");
for (int i = 0; i < len; i++) {
char ch = toDisplay.charAt(i);
switch (ch) {
case '"':
buf.append("\\\"");
break;
case '\\':
buf.append("\\\\");
break;
default:
buf.append(ch);
break;
}
}
buf.append("\")");
return buf.toString();
}
public String getProgram(String... statements) {
int len = statements.length;
String ret = "";
for (int i = 0; i < len; i++) {
ret += statements[i] + ";";
}
return ret;
}
private static final List<String> NAMES;
private static final List<String> MIME_TYPES;
private static final List<String> EXTENSIONS;
static {
final List<String> names = new ArrayList<String>(6);
names.add("js");
names.add("rhino");
names.add("JavaScript");
names.add("javascript");
NAMES = Collections.unmodifiableList(names);
final List<String> mimeTypes = new ArrayList<String>(4);
mimeTypes.add("application/javascript");
mimeTypes.add("application/ecmascript");
mimeTypes.add("text/javascript");
mimeTypes.add("text/ecmascript");
MIME_TYPES = Collections.unmodifiableList(mimeTypes);
final List<String> extensions = new ArrayList<String>(1);
extensions.add("js");
EXTENSIONS = Collections.unmodifiableList(extensions);
}
public String getName() {
return "javascript";
}
public String getEngineName() {
return "Mozilla Rhino";
}
public String getEngineVersion() {
return "1.6 release 2";
}
public String getLanguageName() {
return "javascript";
}
public String getLanguageVersion() {
return "1.6";
}
public List<String> getExtensions() {
return EXTENSIONS;
}
public List<String> getMimeTypes() {
return MIME_TYPES;
}
public List<String> getNames() {
return NAMES;
}
}

View File

@ -2,6 +2,7 @@ package org.jdownloader.scripting;
import java.util.concurrent.ConcurrentHashMap;
import org.jdownloader.logging.LogController;
import org.mozilla.javascript.Callable;
import org.mozilla.javascript.ClassShutter;
import org.mozilla.javascript.Context;
@ -100,7 +101,6 @@ import org.mozilla.javascript.tools.shell.Global;
*/
public class JSRhinoPermissionRestricter {
static public class SandboxContextFactory extends ContextFactory {
static public class MyContext extends Context {
private volatile long startTime = -1;
}
@ -134,38 +134,32 @@ public class JSRhinoPermissionRestricter {
boolean trusted = TRUSTED_THREAD.containsKey(cur);
if (cur instanceof JSShutterDelegate) {
if (((JSShutterDelegate) cur).isClassVisibleToScript(trusted, className)) {
return true;
} else {
return false;
}
}
if (trusted) {
org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().severe("Trusted Thread Loads: " + className);
LogController.CL().severe("Trusted Thread Loads: " + className + "|Thread:" + cur);
return true;
}
if (className.startsWith("adapter")) {
return true;
} else if (className.startsWith("org.mozilla.javascript.ConsString")) {
return true;
} else if (className.equals("org.mozilla.javascript.EcmaError")) {
org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().severe("Javascript error occured");
LogController.CL().severe("Javascript error occured");
return true;
} else {
throw new RuntimeException("Security Violation " + className);
throw new RuntimeException("Security Violation " + className + "|Thread:" + cur);
}
}
});
return cx;
}
}
public static class SandboxWrapFactory extends WrapFactory {
@SuppressWarnings("rawtypes")
@Override
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
@ -174,37 +168,30 @@ public class JSRhinoPermissionRestricter {
}
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")) {
org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().severe("JS Security Exception");
return NOT_FOUND;
}
return super.get(name, start);
}
}
public static ConcurrentHashMap<Thread, Boolean> TRUSTED_THREAD = new ConcurrentHashMap<Thread, Boolean>();
public static final ConcurrentHashMap<Thread, Boolean> TRUSTED_THREAD = new ConcurrentHashMap<Thread, Boolean>();
public static Object evaluateTrustedString(Context cx, Global scope, String source, String sourceName, int lineno, Object securityDomain) {
try {
TRUSTED_THREAD.put(Thread.currentThread(), true);
return cx.evaluateString(scope, source, sourceName, lineno, securityDomain);
} finally {
TRUSTED_THREAD.remove(Thread.currentThread());
@ -212,7 +199,6 @@ public class JSRhinoPermissionRestricter {
}
public static void init() {
try {
ContextFactory.initGlobal(new SandboxContextFactory());
// let's do a test
@ -220,13 +206,10 @@ public class JSRhinoPermissionRestricter {
Context cx = null;
try {
cx = ContextFactory.getGlobal().enterContext();
cx.evaluateString(cx.initStandardObjects(), "java.lang.System.out.println('TEST')", "<cmd>", 1, null);
} finally {
Context.exit();
}
throw new SecurityException("Could not install the sun.org.mozilla.javascript.internal Sandbox!");
} catch (NullPointerException e) {
throw e;
@ -238,13 +221,9 @@ public class JSRhinoPermissionRestricter {
} else {
// test successfull. Security Sandbox successfully initialized
}
}
} catch (Throwable e) {
e.printStackTrace();
LogController.CL().log(e);
}
}
}

View File

@ -9,7 +9,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -927,158 +926,48 @@ public class JavaScriptEngineFactory {
}
}
public static class CustomRhinoScriptEngineFactory implements ScriptEngineFactory {
public CustomRhinoScriptEngineFactory() {
}
public Object getParameter(String key) {
if (key.equals(ScriptEngine.NAME)) {
return "javascript";
} else if (key.equals(ScriptEngine.ENGINE)) {
return "Mozilla Rhino";
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
return "1.6 release 2";
} else if (key.equals(ScriptEngine.LANGUAGE)) {
return "javascript";
} else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
return "1.6";
} else if (key.equals("THREADING")) {
return "MULTITHREADED";
} else {
throw new IllegalArgumentException("Invalid key");
}
}
public ScriptEngine getScriptEngine() {
try {
RhinoScriptEngine ret = new RhinoScriptEngine();
ret.setEngineFactory(this);
return ret;
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
}
}
public String getMethodCallSyntax(String obj, String method, String... args) {
String ret = obj + "." + method + "(";
int len = args.length;
if (len == 0) {
ret += ")";
return ret;
}
for (int i = 0; i < len; i++) {
ret += args[i];
if (i != len - 1) {
ret += ",";
} else {
ret += ")";
}
}
return ret;
}
public String getOutputStatement(String toDisplay) {
StringBuffer buf = new StringBuffer();
int len = toDisplay.length();
buf.append("print(\"");
for (int i = 0; i < len; i++) {
char ch = toDisplay.charAt(i);
switch (ch) {
case '"':
buf.append("\\\"");
break;
case '\\':
buf.append("\\\\");
break;
default:
buf.append(ch);
break;
}
}
buf.append("\")");
return buf.toString();
}
public String getProgram(String... statements) {
int len = statements.length;
String ret = "";
for (int i = 0; i < len; i++) {
ret += statements[i] + ";";
}
return ret;
}
private static List<String> NAMES;
private static List<String> MIME_TYPES;
private static List<String> EXTENSIONS;
static {
NAMES = new ArrayList<String>(6);
NAMES.add("js");
NAMES.add("rhino");
NAMES.add("JavaScript");
NAMES.add("javascript");
NAMES = Collections.unmodifiableList(NAMES);
MIME_TYPES = new ArrayList<String>(4);
MIME_TYPES.add("application/javascript");
MIME_TYPES.add("application/ecmascript");
MIME_TYPES.add("text/javascript");
MIME_TYPES.add("text/ecmascript");
MIME_TYPES = Collections.unmodifiableList(MIME_TYPES);
EXTENSIONS = new ArrayList<String>(1);
EXTENSIONS.add("js");
EXTENSIONS = Collections.unmodifiableList(EXTENSIONS);
}
public String getName() {
return "javascript";
}
public String getEngineName() {
return "Mozilla Rhino";
}
public String getEngineVersion() {
return "1.6 release 2";
}
public String getLanguageName() {
return "javascript";
}
public String getLanguageVersion() {
return "1.6";
}
public List<String> getExtensions() {
return EXTENSIONS;
}
public List<String> getMimeTypes() {
return MIME_TYPES;
}
public List<String> getNames() {
return NAMES;
}
}
public static class CustomizedScriptEngineManager extends ScriptEngineManager {
@Override
public ScriptEngine getEngineByName(String shortName) {
final ScriptEngine ret = super.getEngineByName(shortName);
if (ret instanceof RhinoScriptEngine) {
return ret;
} else {
throw new RuntimeException("Bad ScriptEngine:name=" + shortName + "|" + ret.getClass());
}
}
@Override
public ScriptEngine getEngineByExtension(String extension) {
final ScriptEngine ret = super.getEngineByExtension(extension);
if (ret instanceof RhinoScriptEngine) {
return ret;
} else {
throw new RuntimeException("Bad ScriptEngine:extension=" + extension + "|" + ret.getClass());
}
}
@Override
public ScriptEngine getEngineByMimeType(String mimeType) {
final ScriptEngine ret = super.getEngineByMimeType(mimeType);
if (ret instanceof RhinoScriptEngine) {
return ret;
} else {
throw new RuntimeException("Bad ScriptEngine:mime=" + mimeType + "|" + ret.getClass());
}
throw new RuntimeException("Bad ScriptEngine: " + ret.getClass());
}
public CustomizedScriptEngineManager() {
final CustomRhinoScriptEngineFactory factory = new CustomRhinoScriptEngineFactory();
this.registerEngineName("javascript", factory);
this.registerEngineName("js", factory);
this.registerEngineName("JavaScript", factory);
for (String name : factory.getNames()) {
registerEngineName(name, factory);
}
for (String extension : factory.getExtensions()) {
registerEngineExtension(extension, factory);
}
for (String mimeType : factory.getMimeTypes()) {
registerEngineMimeType(mimeType, factory);
}
}
}

View File

@ -0,0 +1 @@
org.jdownloader.scripting.CustomRhinoScriptEngineFactory

View File

@ -5,6 +5,8 @@ import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
@ -23,6 +25,26 @@ public class JDClassLoaderLauncher {
return name.equals(getClass().getName());
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (JVMVersion.isMinimum(JVMVersion.JAVA_15) && "META-INF/services/javax.script.ScriptEngineFactory".equals(name)) {
final Enumeration<URL> resources = super.getResources(name);
final List<URL> ret = new ArrayList<URL>();
while (resources != null && resources.hasMoreElements()) {
final URL url = resources.nextElement();
ret.add(url);
}
// Nashorn JS engine no longer available
final URL scriptEngineHack = getResource("org/jdownloader/scripting/ScriptEngineFactoryService.html");
if (scriptEngineHack != null) {
ret.add(scriptEngineHack);
}
return Collections.enumeration(ret);
} else {
return super.getResources(name);
}
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {