* cmdline options for lifting sandbox restrictions in scripting shell
This commit is contained in:
parent
f3912a9eee
commit
6b964043fb
|
@ -61,6 +61,9 @@ public class ArgumentBean {
|
||||||
@Option(name = "-script", usage = "Run Groovy script")
|
@Option(name = "-script", usage = "Run Groovy script")
|
||||||
public String script = null;
|
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]")
|
@Option(name = "--log", usage = "Log level", metaVar = "[all, config, info, warning]")
|
||||||
public String log = "all";
|
public String log = "all";
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class ArgumentProcessor {
|
||||||
bindings.put("args", args.getFiles(false));
|
bindings.put("args", args.getFiles(false));
|
||||||
|
|
||||||
Analytics.trackEvent("CLI", "ExecuteScript", args.getScriptLocation().getProtocol());
|
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);
|
shell.evaluate(script, bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,12 @@ import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
class ScriptShell {
|
class ScriptShell {
|
||||||
|
|
||||||
private final ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
|
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
|
// setup script context
|
||||||
ScriptContext context = new SimpleScriptContext();
|
ScriptContext context = new SimpleScriptContext();
|
||||||
context.setBindings(initializeBindings(cli, args, acc), ScriptContext.GLOBAL_SCOPE);
|
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 {
|
public Object evaluate(final String script, final Bindings bindings) throws Exception {
|
||||||
|
if (trustScript) {
|
||||||
|
return engine.eval(script, bindings);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue