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 { private static final Logger log = Logger.getLogger( Global.class ); public static final String TASK_PACKAGE_NAME = "org.openslx.taskmanager.tasks"; public static final long MAX_TASK_AGE = 24l * 3600l * 1000l; 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 { InetAddress la; try { la = Inet4Address.getByName( "127.0.0.1" ); } catch ( UnknownHostException e ) { la = null; 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; } }