diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index db4f4c9d..4d7fa8bc 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -61,6 +61,9 @@ public class ArgumentBean { @Option(name = "-script", usage = "Run Groovy script") public String script = null; + @Option(name = "-trust-script", usage = "Lift scripting restrictions") + public boolean trustScript = false; + @Option(name = "--log", usage = "Log level", metaVar = "[all, config, info, warning]") public String log = "all"; diff --git a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java index a9d31586..a45245e9 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java +++ b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java @@ -89,7 +89,7 @@ public class ArgumentProcessor { bindings.put("args", args.getFiles(false)); Analytics.trackEvent("CLI", "ExecuteScript", args.getScriptLocation().getProtocol()); - ScriptShell shell = new ScriptShell(cli, args, AccessController.getContext()); + ScriptShell shell = new ScriptShell(cli, args, args.trustScript, AccessController.getContext()); shell.evaluate(script, bindings); } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.java b/source/net/sourceforge/filebot/cli/ScriptShell.java index e00a8cf1..bc81d394 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.java +++ b/source/net/sourceforge/filebot/cli/ScriptShell.java @@ -34,9 +34,12 @@ import net.sourceforge.filebot.web.MovieIdentificationService; class ScriptShell { private final ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine(); + private final boolean trustScript; - public ScriptShell(CmdlineInterface cli, ArgumentBean args, AccessControlContext acc) throws ScriptException { + public ScriptShell(CmdlineInterface cli, ArgumentBean args, boolean trustScript, AccessControlContext acc) throws ScriptException { + this.trustScript = trustScript; + // setup script context ScriptContext context = new SimpleScriptContext(); context.setBindings(initializeBindings(cli, args, acc), ScriptContext.GLOBAL_SCOPE); @@ -67,6 +70,10 @@ class ScriptShell { public Object evaluate(final String script, final Bindings bindings) throws Exception { + if (trustScript) { + return engine.eval(script, bindings); + } + try { return AccessController.doPrivileged(new PrivilegedExceptionAction() {