diff options
author | Simon Rettberg | 2014-11-18 18:40:49 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-11-18 18:40:49 +0100 |
commit | ecb072b02e1a70555db0fdf4ed47375d3080a074 (patch) | |
tree | 75db05621458eee14a96ff2d825a30072eb06e40 /src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java | |
parent | Added class ProxyHandler for for configuring proxy settings system wide once ... (diff) | |
download | tmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.tar.gz tmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.tar.xz tmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.zip |
Many improvements and additions:
- Added task+script for lighttpd https config
- Added task for reloading proxy config
- ldapsearch now supports searching for specific user
- DownloadFile now supports checking file integrity through optional gpg signature
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java b/src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java new file mode 100644 index 0000000..1b5e8e8 --- /dev/null +++ b/src/main/java/org/openslx/taskmanager/tasks/LighttpdHttps.java @@ -0,0 +1,105 @@ +package org.openslx.taskmanager.tasks; + +import java.io.File; + +import org.openslx.satserver.util.Exec; +import org.openslx.satserver.util.Util; +import org.openslx.taskmanager.api.AbstractTask; + +import com.google.gson.annotations.Expose; + +public class LighttpdHttps extends AbstractTask +{ + + private Output status = new Output(); + + @Expose + private String importcert = null; + @Expose + private String importkey = null; + + @Expose + private String proxyip = null; + + @Override + protected boolean initTask() + { + this.setStatusObject( this.status ); + return true; + } + + @Override + protected boolean execute() + { + if ( this.importcert != null && this.importkey != null ) + return createFromInput(); + if ( this.proxyip != null ) + return createRandom(); + return disableHttps(); + } + + private boolean createRandom() + { + int ret = Exec.sync( "sudo", "-n", "-u", "root", "/opt/taskmanager/scripts/install-https", "--random", this.proxyip ); + if ( ret != 0 ) { + status.error = "generator exited with code " + ret; + return false; + } + return true; + } + + private boolean createFromInput() + { + // Import supplied certificate and key. Test if they are valid first + File tmpKey = null; + File tmpCert = null; + try { + try { + tmpKey = File.createTempFile( "bwlp-", ".pem" ); + tmpCert = File.createTempFile( "bwlp-", ".pem" ); + Util.writeStringToFile( tmpCert, this.importcert ); + Util.writeStringToFile( tmpKey, this.importkey ); + } catch ( Exception e ) { + status.error = "Could not create temporary files!"; + return false; + } + int ret; + ret = Exec.sync( "/opt/taskmanager/scripts/install-https", "--test", tmpKey.getAbsolutePath(), tmpCert.getAbsolutePath() ); + if ( ret != 0 ) { + status.error = "Given key and certificate do not match, or have invalid format (exit code: " + ret + ")"; + return false; + } + ret = Exec.sync( "sudo", "-n", "-u", "root", "/opt/taskmanager/scripts/install-https", "--import", tmpKey.getAbsolutePath(), tmpCert.getAbsolutePath() ); + if ( ret != 0 ) { + status.error = "import exited with code " + ret; + return false; + } + return true; + } finally { + if ( tmpKey != null ) + tmpKey.delete(); + if ( tmpCert != null ) + tmpCert.delete(); + } + } + + private boolean disableHttps() + { + int ret = Exec.sync( "sudo", "-n", "-u", "root", "/opt/taskmanager/scripts/install-https", "--disable" ); + if ( ret != 0 ) { + status.error = "import exited with code " + ret; + return false; + } + return true; + } + + /** + * Output - contains additional status data of this task + */ + @SuppressWarnings( "unused" ) + private static class Output + { + protected String error = null; + } + +} |