blob: 78162474cdf9feb6518535d1dea2093b3968d681 (
plain) (
tree)
|
|
package org.openslx.taskmanager.tasks;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
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 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 );
if ( this.destination != null && !this.destination.isEmpty() ) {
this.destination = FilenameUtils.normalize( this.destination );
if ( !Util.startsWith( this.destination, ALLOWED_DIRS ) ) {
status.error = "File not in allowed directory";
return false;
}
} else {
this.destination = null;
}
return true;
}
@Override
protected boolean execute()
{
try {
Files.createDirectory( Paths.get( "/srv/openslx/www/boot/default" ) );
} catch ( Exception e ) {
}
try {
FileUtils.deleteQuietly( new File( "/srv/openslx/www/boot/default/config.tgz" ) );
} catch ( Exception e ) {
}
if ( this.destination != null ) {
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;
}
}
|