1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

* update samples

This commit is contained in:
Reinhard Pointner 2013-10-17 07:11:32 +00:00
parent 02cd92d842
commit 5b839d1ca8
2 changed files with 18 additions and 23 deletions

View File

@ -1,9 +1,8 @@
package net.sourceforge.filebot.format; package net.sourceforge.filebot.format;
import java.io.File; import java.io.File;
import java.io.FilePermission; import java.io.FilePermission;
import java.lang.management.ManagementPermission;
import java.net.SocketPermission; import java.net.SocketPermission;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessControlException; import java.security.AccessControlException;
@ -22,12 +21,11 @@ import javax.script.ScriptException;
import net.sourceforge.tuned.ExceptionUtilities; import net.sourceforge.tuned.ExceptionUtilities;
public class SecureCompiledScript extends CompiledScript { public class SecureCompiledScript extends CompiledScript {
public static PermissionCollection getDefaultSandboxPermissions() { public static PermissionCollection getDefaultSandboxPermissions() {
Permissions permissions = new Permissions(); Permissions permissions = new Permissions();
permissions.add(new RuntimePermission("createClassLoader")); permissions.add(new RuntimePermission("createClassLoader"));
permissions.add(new RuntimePermission("modifyThread")); permissions.add(new RuntimePermission("modifyThread"));
permissions.add(new FilePermission("<<ALL FILES>>", "read")); permissions.add(new FilePermission("<<ALL FILES>>", "read"));
@ -35,7 +33,8 @@ public class SecureCompiledScript extends CompiledScript {
permissions.add(new PropertyPermission("*", "read")); permissions.add(new PropertyPermission("*", "read"));
permissions.add(new RuntimePermission("getenv.*")); permissions.add(new RuntimePermission("getenv.*"));
permissions.add(new RuntimePermission("getFileSystemAttributes")); permissions.add(new RuntimePermission("getFileSystemAttributes"));
permissions.add(new ManagementPermission("monitor"));
// write permissions for temp and cache folders // write permissions for temp and cache folders
try { try {
permissions.add(new FilePermission(new File(System.getProperty("java.io.tmpdir")).getAbsolutePath() + File.separator + "-", "write, delete")); permissions.add(new FilePermission(new File(System.getProperty("java.io.tmpdir")).getAbsolutePath() + File.separator + "-", "write, delete"));
@ -43,30 +42,27 @@ public class SecureCompiledScript extends CompiledScript {
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
return permissions; return permissions;
} }
private final CompiledScript compiledScript; private final CompiledScript compiledScript;
private final AccessControlContext sandbox; private final AccessControlContext sandbox;
public SecureCompiledScript(CompiledScript compiledScript) { public SecureCompiledScript(CompiledScript compiledScript) {
this(compiledScript, new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, getDefaultSandboxPermissions()) })); this(compiledScript, new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, getDefaultSandboxPermissions()) }));
} }
public SecureCompiledScript(CompiledScript compiledScript, AccessControlContext sandbox) { public SecureCompiledScript(CompiledScript compiledScript, AccessControlContext sandbox) {
this.compiledScript = compiledScript; this.compiledScript = compiledScript;
this.sandbox = sandbox; this.sandbox = sandbox;
} }
@Override @Override
public Object eval(final ScriptContext context) throws ScriptException { public Object eval(final ScriptContext context) throws ScriptException {
try { try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override @Override
public Object run() throws ScriptException { public Object run() throws ScriptException {
return compiledScript.eval(context); return compiledScript.eval(context);
@ -74,22 +70,21 @@ public class SecureCompiledScript extends CompiledScript {
}, sandbox); }, sandbox);
} catch (PrivilegedActionException e) { } catch (PrivilegedActionException e) {
AccessControlException accessException = ExceptionUtilities.findCause(e, AccessControlException.class); AccessControlException accessException = ExceptionUtilities.findCause(e, AccessControlException.class);
// try to unwrap AccessControlException // try to unwrap AccessControlException
if (accessException != null) if (accessException != null)
throw new ExpressionException(accessException); throw new ExpressionException(accessException);
// forward ScriptException // forward ScriptException
// e.getException() should be an instance of ScriptException, // e.getException() should be an instance of ScriptException,
// as only "checked" exceptions will be "wrapped" in a PrivilegedActionException // as only "checked" exceptions will be "wrapped" in a PrivilegedActionException
throw (ScriptException) e.getException(); throw (ScriptException) e.getException();
} }
} }
@Override @Override
public ScriptEngine getEngine() { public ScriptEngine getEngine() {
return compiledScript.getEngine(); return compiledScript.getEngine();
} }
} }

View File

@ -158,9 +158,9 @@
}</code></pre>Fetch subtitles, rename and compute checksums for all media folders in the file hierarchy.</div> }</code></pre>Fetch subtitles, rename and compute checksums for all media folders in the file hierarchy.</div>
<div class="description"> <div class="description">
<pre><code>[<span class="string">'E:/tvshows'</span>].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'tvrage'</span>) } <pre><code>[<span class="string">'E:/TV Shows'</span> as File].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'TheTVDB'</span>) }
[<span class="string">'E:/anime'</span>].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'anidb'</span>) } [<span class="string">'E:/Anime'</span> as File].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'AniDB'</span>) }
[<span class="string">'E:/movies'</span>].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'opensubtitles'</span>) } [<span class="string">'E:/Movies'</span> as File].<span class="method">eachMediaFolder</span>{ <span class="method">rename</span>(<span class="property">folder</span>:it, <span class="property">db</span>:<span class="string">'TheMovieDB'</span>) }
</code></pre>Run rename on different folder hierarchies using different episode/movie datasources.</div> </code></pre>Run rename on different folder hierarchies using different episode/movie datasources.</div>
<div class="description"> <div class="description">