summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java b/src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java
new file mode 100644
index 0000000..686cb9b
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/LinkConfigTgz.java
@@ -0,0 +1,61 @@
+package org.openslx.taskmanager.tasks;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+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 LinkConfigTgz extends AbstractTask
+{
+
+ protected static final String[] ALLOWED_DIRS =
+ { "/tmp/", "/opt/openslx/configs/" };
+
+ @Expose
+ private String destination = null;
+
+ private Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.setStatusObject( status );
+ this.destination = FilenameUtils.normalize( this.destination );
+ if ( this.destination == null || !Util.startsWith( this.destination, ALLOWED_DIRS ) ) {
+ status.error = "File not in allowed directory";
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected boolean execute()
+ {
+ try {
+ Files.deleteIfExists( Paths.get( "/srv/openslx/www/boot/default/config.tgz" ) );
+ } catch ( IOException e1 ) {
+ }
+ try {
+ Files.createSymbolicLink( Paths.get( "/srv/openslx/www/boot/default/config.tgz" ), Paths.get( this.destination ) );
+ } catch ( IOException e ) {
+ status.error = e.toString();
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Output - contains additional status data of this task
+ */
+ @SuppressWarnings( "unused" )
+ private static class Output
+ {
+ protected String error = null;
+ }
+
+}