summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-10-09 17:39:31 +0200
committerSimon Rettberg2019-10-09 17:39:31 +0200
commit535f454a9acce1219ef1c5a50f04a61266e5a715 (patch)
tree350687997a18b79e976aef17c581623515c4f180
parent[DeleteFile] Allow deleting files in HTTP boot dir (diff)
downloadtmlite-bwlp-535f454a9acce1219ef1c5a50f04a61266e5a715.tar.gz
tmlite-bwlp-535f454a9acce1219ef1c5a50f04a61266e5a715.tar.xz
tmlite-bwlp-535f454a9acce1219ef1c5a50f04a61266e5a715.zip
[DeleteDirectory] New task
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/DeleteDirectory.java61
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java5
2 files changed, 63 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/DeleteDirectory.java b/src/main/java/org/openslx/taskmanager/tasks/DeleteDirectory.java
new file mode 100644
index 0000000..1a0de05
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/DeleteDirectory.java
@@ -0,0 +1,61 @@
+package org.openslx.taskmanager.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.openslx.satserver.util.Util;
+import org.openslx.taskmanager.api.AbstractTask;
+
+import com.google.gson.annotations.Expose;
+
+public class DeleteDirectory extends AbstractTask
+{
+
+ protected static final String[] ALLOWED_DIRS =
+ { "/tmp/", "/srv/openslx/www/boot/" };
+
+ @Expose
+ private String path = null;
+ @Expose
+ private boolean recursive = false;
+
+ private Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.setStatusObject( status );
+ this.path = FilenameUtils.normalize( this.path );
+ if ( this.path == null || !Util.startsWith( this.path, ALLOWED_DIRS )
+ || Arrays.asList( ALLOWED_DIRS ).contains( this.path ) ) {
+ status.error = "Directory not in allowed directory";
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected boolean execute()
+ {
+ try {
+ FileUtils.deleteDirectory( new File( this.path ) );
+ } catch ( Exception e1 ) {
+ status.error = e1.toString();
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Output - contains additional status data of this task
+ */
+ @SuppressWarnings( "unused" )
+ private static class Output
+ {
+ protected String error = null;
+ }
+
+}
diff --git a/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java b/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java
index 08e7af0..ba9c3a5 100644
--- a/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java
+++ b/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java
@@ -1,6 +1,5 @@
package org.openslx.taskmanager.tasks;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -14,7 +13,7 @@ public class DeleteFile extends AbstractTask
{
protected static final String[] ALLOWED_DIRS =
- { "/tmp/", "/opt/openslx/configs/", "/srv/openslx/www/boot" };
+ { "/tmp/", "/opt/openslx/configs/" };
@Expose
private String file = null;
@@ -38,7 +37,7 @@ public class DeleteFile extends AbstractTask
{
try {
Files.deleteIfExists( Paths.get( this.file ) );
- } catch ( IOException e1 ) {
+ } catch ( Exception e1 ) {
status.error = e1.toString();
return false;
}