summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2018-04-13 10:11:49 +0200
committerSimon Rettberg2018-04-13 10:11:49 +0200
commitd512a805133d83ca55eb8d72da6ff61c44509e3b (patch)
tree6731b7b1ad304107847d4c55f5fe7b4d72187263 /src
parentFiletransfer: Support calculating dnbd3 crc32 list (diff)
downloadmaster-sync-shared-d512a805133d83ca55eb8d72da6ff61c44509e3b.tar.gz
master-sync-shared-d512a805133d83ca55eb8d72da6ff61c44509e3b.tar.xz
master-sync-shared-d512a805133d83ca55eb8d72da6ff61c44509e3b.zip
Remove unused proxy-vole classes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/network/ProxyConfiguration.java72
-rw-r--r--src/main/java/org/openslx/network/ProxyProperties.java89
-rw-r--r--src/main/java/org/openslx/network/StaticProxyAuthenticator.java23
-rw-r--r--src/main/java/org/openslx/network/StaticProxySelector.java115
4 files changed, 0 insertions, 299 deletions
diff --git a/src/main/java/org/openslx/network/ProxyConfiguration.java b/src/main/java/org/openslx/network/ProxyConfiguration.java
deleted file mode 100644
index ecf800f..0000000
--- a/src/main/java/org/openslx/network/ProxyConfiguration.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.openslx.network;
-
-import java.net.Authenticator;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.ProxySelector;
-
-import org.apache.log4j.Logger;
-
-import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
-
-/**
- * Class for configuring proxy settings system wide, if necessary.
- *
- * @author bjoern
- *
- */
-public class ProxyConfiguration
-{
- private static final Logger log = Logger.getLogger( ProxyConfiguration.class );
-
- public static void configProxy()
- {
- // Reset proxy settings first
- ProxySelector.setDefault( null );
- Authenticator.setDefault( null );
-
- // Configuring proxy settings. First read options from config file.
- ProxyProperties.load();
- String proxyConfiguration = ProxyProperties.getProxyConf();
-
- if ( proxyConfiguration.equals( "AUTO" ) || proxyConfiguration.isEmpty() ) {
- log.info( "Configuring proxy settings automatically..." );
- // Configuring proxy settings automatically.
- WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy();
- try {
- ProxySelector pS = wPSS.getProxySelector();
- ProxySelector.setDefault( pS );
- } catch ( Throwable e ) {
- log.error( "Setting proxy configuration automatically failed.", e );
- }
- return;
- }
-
- 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 ( ProxyProperties.hasProxyAddress() ) {
- String proxyAddress = ProxyProperties.getProxyAddress();
- int proxyPort = ProxyProperties.getProxyPort();
-
- // Configure proxy.
- Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) );
- StaticProxySelector sPS = new StaticProxySelector( proxy );
- ProxySelector.setDefault( sPS );
-
- if ( !ProxyProperties.hasProxyCredentials() ) {
- log.info( "Configuring proxy settings manually WITH authentication..." );
- // use Proxy with authentication.
- String proxyUname = ProxyProperties.getProxyUsername();
- String proxyPass = ProxyProperties.getProxyPassword();
-
- // Set authentication.
- StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass );
- Authenticator.setDefault( sPA );
- }
- }
- }
-
- }
-
-}
diff --git a/src/main/java/org/openslx/network/ProxyProperties.java b/src/main/java/org/openslx/network/ProxyProperties.java
deleted file mode 100644
index 5dacc57..0000000
--- a/src/main/java/org/openslx/network/ProxyProperties.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.openslx.network;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.Properties;
-
-import org.apache.log4j.Logger;
-import org.openslx.util.Util;
-
-public class ProxyProperties
-{
- private static Logger log = Logger.getLogger( ProxyProperties.class );
- private static final Properties properties = new Properties();
-
- // Getting the proxy settings from config file stored in
- // "/opt/openslx/proxy/conf".
- 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 //
- public static int getProxyPort()
- {
- return Util.parseInt( properties.getProperty( "PROXY_PORT", "0" ), 0 );
- }
-
- static
- {
- load();
- }
-
- /**
- * Load properties
- */
- public static void load()
- {
- InputStreamReader stream = null;
- try {
- properties.clear();
- // Load all entries of the config file into properties
- stream = new InputStreamReader(
- new FileInputStream( "/opt/openslx/proxy/config" ), StandardCharsets.UTF_8 );
- properties.load( stream );
- stream.close();
- } catch ( IOException e ) {
- log.warn( "Could not load proxy properties from '/opt/openslx/proxy/conf'." );
- } finally {
- Util.safeClose( stream );
- }
- }
-
- /**
- * Check proxy settings for being not empty.
- *
- * @return true if address and port are set
- */
- public static boolean hasProxyAddress()
- {
- return !getProxyAddress().isEmpty() && getProxyPort() != 0;
- }
-
- /**
- * Check if a username or password is configured.
- *
- * @return true if either username or password (or both) are set
- */
- public static boolean hasProxyCredentials()
- {
- return !getProxyUsername().isEmpty() || !getProxyPassword().isEmpty();
- }
-}
diff --git a/src/main/java/org/openslx/network/StaticProxyAuthenticator.java b/src/main/java/org/openslx/network/StaticProxyAuthenticator.java
deleted file mode 100644
index c1d8da7..0000000
--- a/src/main/java/org/openslx/network/StaticProxyAuthenticator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.openslx.network;
-
-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
-
-public class StaticProxyAuthenticator extends Authenticator
-{
- private final String username, password;
-
- public StaticProxyAuthenticator( String username, String password )
- {
- this.username = username;
- this.password = password;
- }
-
- protected PasswordAuthentication getPasswordAuthentication()
- {
- if ( getRequestorType() != RequestorType.PROXY )
- return super.getPasswordAuthentication();
- return new PasswordAuthentication(
- this.username, this.password.toCharArray() );
- }
-}
diff --git a/src/main/java/org/openslx/network/StaticProxySelector.java b/src/main/java/org/openslx/network/StaticProxySelector.java
deleted file mode 100644
index d7d76ac..0000000
--- a/src/main/java/org/openslx/network/StaticProxySelector.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package org.openslx.network;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.Proxy;
-import java.net.ProxySelector;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-public class StaticProxySelector extends ProxySelector
-{
- private static Logger log = Logger.getLogger( StaticProxySelector.class );
-
- private final Proxy proxy;
- private Set<String> localAddresses = null;
- private long nextAddressGet = 0;
-
- public StaticProxySelector( Proxy proxy )
- {
- this.proxy = proxy;
- }
-
- @Override
- public void connectFailed( URI uri, SocketAddress sa, IOException ioe )
- {
- // Just one fix proxy. So no code is necessary here for deactivating proxy.
- }
-
- @Override
- public List<Proxy> select( URI uri )
- {
- List<Proxy> proxyList = new ArrayList<Proxy>();
-
- String host = uri.getHost();
- if ( host == null ) // Host not set? Well, we can only guess then, so try to use the proxy
- return proxyList;
-
- host = host.replaceFirst( "%\\d+$", "" );
- if ( host.equals( "localhost" ) || host.startsWith( "127." )
- || host.startsWith( "::1" ) || host.startsWith( "0:0:0:0:0:0:0:1" ) ) // Localhost = no proxy
- return proxyList;
-
- final Set<String> addrs;
- synchronized ( this ) {
- addrs = getLocalAddresses();
- }
- if ( !addrs.contains( host ) ) {
- proxyList.add( this.proxy );
- }
-
- return proxyList;
- }
-
- /**
- * Get all local (IP) addresses
- *
- * @return
- */
- private Set<String> getLocalAddresses()
- {
- long now = System.currentTimeMillis();
- if ( now < nextAddressGet )
- return localAddresses;
- nextAddressGet = now + 60000;
-
- List<NetworkInterface> interfaces = getNetworkInterfaces();
- if ( interfaces == null )
- return localAddresses; // Fallback on last known data
- // iterate over network interfaces and get all addresses
- Set<String> addrs = new HashSet<>();
- for ( NetworkInterface iface : interfaces ) {
- Enumeration<InetAddress> e = iface.getInetAddresses();
- // iterate over InetAddresses of current interface
- while ( e.hasMoreElements() ) {
- addrs.add( e.nextElement().getHostAddress().replaceFirst( "%\\d+$", "" ) );
- }
- }
- synchronized ( this ) {
- localAddresses = addrs;
- }
- return localAddresses;
- }
-
- /**
- * Get a list of all local network interfaces
- *
- * @return
- */
- private List<NetworkInterface> getNetworkInterfaces()
- {
- ArrayList<NetworkInterface> retList = new ArrayList<NetworkInterface>();
- Enumeration<NetworkInterface> e = null;
- try {
- e = NetworkInterface.getNetworkInterfaces();
- } catch ( SocketException e1 ) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- return null;
- }
- while ( e.hasMoreElements() ) {
- retList.add( e.nextElement() );
- }
- return retList;
- }
-
-}