diff options
author | Björn Hagemeister | 2014-11-11 14:11:52 +0100 |
---|---|---|
committer | Björn Hagemeister | 2014-11-11 14:11:52 +0100 |
commit | 91d32290d336e615e2d8ef7f009e753e146136bb (patch) | |
tree | 9ee96a1b70e5ba46f52c1d6a46e537849f252152 /src | |
parent | Fixed several things for successful up and download of images after using all... (diff) | |
download | satellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.tar.gz satellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.tar.xz satellite-daemon-91d32290d336e615e2d8ef7f009e753e146136bb.zip |
Implemented possible connection to master server via proxy server.
Currently proxy server is found by DNS searching.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/App.java | 60 | ||||
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/Globals.java | 33 |
2 files changed, 90 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 4a6bb7b..e43c9a1 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -1,16 +1,24 @@ package org.openslx.satellitedaemon; import java.math.BigInteger; +import java.net.Authenticator; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.ProxySelector; import java.security.NoSuchAlgorithmException; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; -import java.util.Random; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; +import org.openslx.network.StaticProxyAuthenticator; +import org.openslx.network.StaticProxySelector; import org.openslx.satellitedaemon.filetransfer.FileDownloadWorker; import org.openslx.satellitedaemon.filetransfer.FileUploadWorker; +import com.btr.proxy.search.wpad.WpadProxySearchStrategy; +import com.btr.proxy.util.ProxyException; + /***********************************************************************************************/ /** * Main class for uploading images from the HS-Server to the Satellite Server. @@ -102,15 +110,63 @@ public class App } } else if ( args.length == 0 ) { // No Option choosed, try to load existing identity. + if ( !tryLoadIdentity() ) { System.exit( 2 ); } } - + if ( !Globals.masterServerSslContextInit() ) { log.error( "Problem with initializing the SSLContext" ); System.exit( 1 ); } + + log.info( "Configure proxy settings ..." ); + // Configuring proxy settings. First read options from config file. + String proxyConfiguration = Globals.getProxyConf(); + if ((proxyConfiguration.equals( "AUTO")) || (proxyConfiguration.equals( "" ))) { + log.info( "Configuring proxy settings automatically..." ); + // Configuring proxy settings automatically. + WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy(); + try { + ProxySelector pS = wPSS.getProxySelector(); + ProxySelector.setDefault(pS); + } catch (ProxyException e) { + log.error( "Setting proxy configuration automatically failed.", e ); + } + } else if (proxyConfiguration.equals( "YES" )) { + // Take the proxy settings from config file. + // First check if one of the following necessary options might not be set. + if (Globals.checkProxySettings()) { + String proxyAddress = Globals.getProxyAddress(); + int proxyPort = Globals.getProxyPort(); + if (Globals.getProxyUsername().equals( "" ) || Globals.getProxyPassword().equals("")) { + log.info( "Configuring proxy settings manually without authentication..." ); + // use Proxy without authentication. + Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); + + StaticProxySelector sPS = new StaticProxySelector(proxy); + ProxySelector.setDefault( sPS ); + } else { + log.info( "Configuring proxy settings manually with authentication..." ); + // Use proxy with authentication. + String proxyUname = Globals.getProxyUsername(); + String proxyPass = Globals.getProxyPassword(); + + Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); + + StaticProxySelector sPS = new StaticProxySelector( proxy ); + ProxySelector.setDefault( sPS ); + + // Set authentication. + StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass ); + Authenticator.setDefault( sPA ); + } + } + } + log.info( "... proxy settings are done." ); + + // Start Up- and Download. Thread uploadWorker = new Thread( new FileUploadWorker() ); uploadWorker.start(); diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java index 0b0d287..d75459b 100644 --- a/src/main/java/org/openslx/satellitedaemon/Globals.java +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -50,6 +50,26 @@ public class Globals { return properties.getProperty( "IMAGE_FOLDER" ); } + + public static String getProxyConf() + { + return properties.getProperty( "PROXY_CONF" ); + } + + public static String getProxyAddress() + { + return properties.getProperty( "PROXY_ADDR" ); + } + + public static String getProxyUsername() + { + return properties.getProperty( "PROXY_USERNAME" ); + } + + public static String getProxyPassword() + { + return properties.getProperty( "PROXY_PASSWORD" ); + } // Integers // @@ -58,6 +78,11 @@ public class Globals return tryToParseInt( properties.getProperty( "THRIFT_PORT" ) ); } + public static int getProxyPort() + { + return tryToParseInt( properties.getProperty( "PROXY_PORT" ) ); + } + /** * Load properties */ @@ -129,7 +154,7 @@ public class Globals * Tries to parse an int. Returns 0 on error. * * @param s - * The strig to parse + * The string to parse * @return The parsed int or 0 on error */ public static int tryToParseInt( String s ) @@ -140,4 +165,10 @@ public class Globals return 0; } } + + public static boolean checkProxySettings() { + return ( + (getProxyAddress() != "") && + (getProxyPort() != 0)); + } } |