diff options
Diffstat (limited to 'daemon/src/main/java/org/openslx/taskmanager/Global.java')
-rw-r--r-- | daemon/src/main/java/org/openslx/taskmanager/Global.java | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/daemon/src/main/java/org/openslx/taskmanager/Global.java b/daemon/src/main/java/org/openslx/taskmanager/Global.java index 7ca2c2d..5be8196 100644 --- a/daemon/src/main/java/org/openslx/taskmanager/Global.java +++ b/daemon/src/main/java/org/openslx/taskmanager/Global.java @@ -1,13 +1,23 @@ package org.openslx.taskmanager; +import java.io.FileInputStream; +import java.io.IOException; import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFilePermission; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.openslx.taskmanager.util.Util; public class Global { - public static final int LISTEN_PORT = 9215; + private static final Logger log = Logger.getLogger( Global.class ); public static final String TASK_PACKAGE_NAME = "org.openslx.taskmanager.tasks"; @@ -15,10 +25,17 @@ public class Global public static final InetAddress LISTEN_ADDRESS; + public static final int MAX_REQUEST_SIZE = 1 * 1024 * 1024; // 1 Meg + + public static final String PASSWORD; + + public static final int PORT_UDP; + + public static final int PORT_TCP; + public static volatile boolean doShutdown = false; - static - { + static { InetAddress la; try { la = Inet4Address.getByName( "127.0.0.1" ); @@ -27,6 +44,40 @@ public class Global e.printStackTrace(); } LISTEN_ADDRESS = la; + + String pw = ""; + int udp = 9215, tcp = -1; + Path configPath = Paths.get( "config/config" ); + if ( Files.exists( configPath ) ) { + log.info( "Loading config from " + configPath.toAbsolutePath().toString() ); + Properties p = new Properties(); + try { + p.load( new FileInputStream( configPath.toFile() ) ); + pw = p.getProperty( "password" ); + } catch ( Exception e ) { + log.warn( "Cannot read from config file", e ); + } + udp = Util.parseInt( p.getProperty( "udp", "-1" ), -1 ); + tcp = Util.parseInt( p.getProperty( "tcp", "-1" ), -1 ); + if ( !pw.isEmpty() ) { + try { + if ( Files.getPosixFilePermissions( configPath ).contains( PosixFilePermission.OTHERS_READ ) ) { + log.warn( "******** Config file is world readable" ); + } + } catch ( IOException e1 ) { + e1.printStackTrace(); + } + } + } + if ( udp != -1 ) { + log.warn( "******** Running with passwordless legacy UDP interface" ); + } + if ( tcp != -1 && pw.isEmpty() ) { + log.warn( "******** Running with no password" ); + } + PASSWORD = pw; + PORT_UDP = udp; + PORT_TCP = tcp; } } |