summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satserver
diff options
context:
space:
mode:
authorSimon Rettberg2014-11-18 18:40:49 +0100
committerSimon Rettberg2014-11-18 18:40:49 +0100
commitecb072b02e1a70555db0fdf4ed47375d3080a074 (patch)
tree75db05621458eee14a96ff2d825a30072eb06e40 /src/main/java/org/openslx/satserver
parentAdded class ProxyHandler for for configuring proxy settings system wide once ... (diff)
downloadtmlite-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/satserver')
-rw-r--r--src/main/java/org/openslx/satserver/util/Exec.java20
-rw-r--r--src/main/java/org/openslx/satserver/util/ProxyHandler.java35
-rw-r--r--src/main/java/org/openslx/satserver/util/Util.java19
3 files changed, 50 insertions, 24 deletions
diff --git a/src/main/java/org/openslx/satserver/util/Exec.java b/src/main/java/org/openslx/satserver/util/Exec.java
index e7b27da..1f810eb 100644
--- a/src/main/java/org/openslx/satserver/util/Exec.java
+++ b/src/main/java/org/openslx/satserver/util/Exec.java
@@ -6,17 +6,23 @@ import java.io.IOException;
public class Exec
{
+ /**
+ * Run command, return exit status of process, or -1 on error
+ *
+ * @param command Command and arguments
+ * @return exit code
+ */
public static int sync( String... command )
{
ProcessBuilder pb = new ProcessBuilder( command );
pb.directory( new File( "/" ) );
- Process p;
- try {
- p = pb.start();
- return p.waitFor();
- } catch ( IOException | InterruptedException e ) {
- return -1;
- }
+ Process p;
+ try {
+ p = pb.start();
+ return p.waitFor();
+ } catch ( IOException | InterruptedException e ) {
+ return -1;
+ }
}
}
diff --git a/src/main/java/org/openslx/satserver/util/ProxyHandler.java b/src/main/java/org/openslx/satserver/util/ProxyHandler.java
index 9a702fe..f70a496 100644
--- a/src/main/java/org/openslx/satserver/util/ProxyHandler.java
+++ b/src/main/java/org/openslx/satserver/util/ProxyHandler.java
@@ -3,19 +3,36 @@ package org.openslx.satserver.util;
import org.openslx.network.ProxyConfiguration;
/**
- * Class for handling proxy configuration in task manager. Just configure proxy
- * setting system wide, if it was not done already.
+ * Class for handling proxy configuration in task manager.
+ *
* @author bjoern
- *
+ *
*/
-public class ProxyHandler {
+public class ProxyHandler
+{
private static boolean hasDoneConfigProxy = false;
+ private static final Object proxyMutex = new Object();
- public static void configProxy() {
- // Just configuring proxy settings system wide, if not done already.
- if (!hasDoneConfigProxy) {
- ProxyConfiguration.configProxy();
- hasDoneConfigProxy = true;
+ /**
+ * Do proxy setup if not done already
+ */
+ public static void configProxy()
+ {
+ configProxy( false );
+ }
+
+ /**
+ * Do proxy setup if not done already, or if explicitly forced.
+ *
+ * @param force Do setup even if already done
+ */
+ public static synchronized void configProxy( boolean force )
+ {
+ synchronized ( proxyMutex ) {
+ if ( !hasDoneConfigProxy || force ) {
+ ProxyConfiguration.configProxy();
+ hasDoneConfigProxy = true;
+ }
}
}
}
diff --git a/src/main/java/org/openslx/satserver/util/Util.java b/src/main/java/org/openslx/satserver/util/Util.java
index fe7eb6e..2df4c73 100644
--- a/src/main/java/org/openslx/satserver/util/Util.java
+++ b/src/main/java/org/openslx/satserver/util/Util.java
@@ -5,6 +5,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
@@ -30,6 +31,7 @@ public class Util
/**
* Close all given Closables. Can handle null references.
+ *
* @param streams one or more closables/streams
*/
public static void multiClose( Closeable... streams )
@@ -64,14 +66,15 @@ public class Util
}
return true;
}
-
- public static String readFileToString(String file)
+
+ public static String readFileToString( String file ) throws IOException
{
- try {
- return FileUtils.readFileToString( new File( file ) );
- } catch ( Exception e ) {
- return null;
- }
+ return FileUtils.readFileToString( new File( file ), StandardCharsets.UTF_8 );
}
-
+
+ public static void writeStringToFile( File file, String string ) throws IOException
+ {
+ FileUtils.writeStringToFile( file, string, StandardCharsets.UTF_8 );
+ }
+
}