summaryrefslogtreecommitdiffstats
path: root/daemon/src/main/java/org/openslx/taskmanager/Global.java
blob: 5be8196b9b39b09086bc01a1970cbf19b76e0921 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
	}

}