proxy-vole-20121203

16:51:06.369 INFO  jd.cli.Main - Decompiling proxy-vole-20121203.jar
package com.btr.proxy.search;

import com.btr.proxy.util.Logger.LogBackEnd;
import com.btr.proxy.util.Logger.LogLevel;
import java.io.PrintStream;
import java.text.MessageFormat;

final class ProxySearch$1
  implements Logger.LogBackEnd
{
  public void log(Class<?> clazz, Logger.LogLevel loglevel, String msg, Object... params)
  {
    System.out.println(MessageFormat.format(msg, params));
  }
  
  public boolean isLogginEnabled(Logger.LogLevel logLevel)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.ProxySearch.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search;

class ProxySearch$2 {}

/* Location:
 * Qualified Name:     com.btr.proxy.search.ProxySearch.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search;

public enum ProxySearch$Strategy
{
  OS_DEFAULT,  BROWSER,  FIREFOX,  IE,  ENV_VAR,  WIN,  KDE,  GNOME,  JAVA;
  
  private ProxySearch$Strategy() {}
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.ProxySearch.Strategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search;

import com.btr.proxy.search.browser.firefox.FirefoxProxySearchStrategy;
import com.btr.proxy.search.browser.ie.IEProxySearchStrategy;
import com.btr.proxy.search.desktop.DesktopProxySearchStrategy;
import com.btr.proxy.search.desktop.gnome.GnomeProxySearchStrategy;
import com.btr.proxy.search.desktop.kde.KdeProxySearchStrategy;
import com.btr.proxy.search.desktop.win.WinProxySearchStrategy;
import com.btr.proxy.search.env.EnvProxySearchStrategy;
import com.btr.proxy.search.java.JavaProxySearchStrategy;
import com.btr.proxy.selector.misc.BufferedProxySelector;
import com.btr.proxy.selector.misc.ProxyListFallbackSelector;
import com.btr.proxy.selector.pac.PacProxySelector;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogBackEnd;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.ProxyException;
import java.awt.GraphicsEnvironment;
import java.io.PrintStream;
import java.net.ProxySelector;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

public class ProxySearch
  implements ProxySearchStrategy
{
  private static final int DEFAULT_PAC_CACHE_SIZE = 20;
  private static final long DEFAULT_PAC_CACHE_TTL = 600000L;
  private List<ProxySearchStrategy> strategies;
  private int pacCacheSize;
  private long pacCacheTTL;
  
  public static enum Strategy
  {
    OS_DEFAULT,  BROWSER,  FIREFOX,  IE,  ENV_VAR,  WIN,  KDE,  GNOME,  JAVA;
    
    private Strategy() {}
  }
  
  public ProxySearch()
  {
    strategies = new ArrayList();
    pacCacheSize = 20;
    pacCacheTTL = 600000L;
  }
  
  public static ProxySearch getDefaultProxySearch()
  {
    ProxySearch s = new ProxySearch();
    
    boolean headless = GraphicsEnvironment.isHeadless();
    if (headless)
    {
      s.addStrategy(Strategy.JAVA);
      s.addStrategy(Strategy.OS_DEFAULT);
      s.addStrategy(Strategy.ENV_VAR);
    }
    else
    {
      s.addStrategy(Strategy.JAVA);
      s.addStrategy(Strategy.BROWSER);
      s.addStrategy(Strategy.OS_DEFAULT);
      s.addStrategy(Strategy.ENV_VAR);
    }
    Logger.log(ProxySearch.class, Logger.LogLevel.TRACE, "Using default search priority: {0}", new Object[] { s });
    
    return s;
  }
  
  public void addStrategy(Strategy strategy)
  {
    switch (strategy)
    {
    case OS_DEFAULT: 
      strategies.add(new DesktopProxySearchStrategy());
      break;
    case BROWSER: 
      strategies.add(getDefaultBrowserStrategy());
      break;
    case FIREFOX: 
      strategies.add(new FirefoxProxySearchStrategy());
      break;
    case IE: 
      strategies.add(new IEProxySearchStrategy());
      break;
    case ENV_VAR: 
      strategies.add(new EnvProxySearchStrategy());
      break;
    case WIN: 
      strategies.add(new WinProxySearchStrategy());
      break;
    case KDE: 
      strategies.add(new KdeProxySearchStrategy());
      break;
    case GNOME: 
      strategies.add(new GnomeProxySearchStrategy());
      break;
    case JAVA: 
      strategies.add(new JavaProxySearchStrategy());
      break;
    default: 
      throw new IllegalArgumentException("Unknown strategy code!");
    }
  }
  
  public void setPacCacheSettings(int size, long ttl)
  {
    pacCacheSize = size;
    pacCacheTTL = ttl;
  }
  
  private ProxySearchStrategy getDefaultBrowserStrategy()
  {
    switch (com.btr.proxy.util.PlatformUtil.getDefaultBrowser())
    {
    case IE: 
      return new IEProxySearchStrategy();
    case FIREFOX: 
      return new FirefoxProxySearchStrategy();
    }
    return null;
  }
  
  public ProxySelector getProxySelector()
  {
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Executing search strategies to find proxy selector", new Object[0]);
    for (ProxySearchStrategy strat : strategies) {
      try
      {
        ProxySelector selector = strat.getProxySelector();
        if (selector != null) {
          return installBufferingAndFallbackBehaviour(selector);
        }
      }
      catch (ProxyException e)
      {
        Logger.log(getClass(), Logger.LogLevel.DEBUG, "Strategy {0} failed trying next one.", new Object[] { e });
      }
    }
    return null;
  }
  
  private ProxySelector installBufferingAndFallbackBehaviour(ProxySelector selector)
  {
    if ((selector instanceof PacProxySelector))
    {
      if (pacCacheSize > 0) {
        selector = new BufferedProxySelector(pacCacheSize, pacCacheTTL, selector);
      }
      selector = new ProxyListFallbackSelector(selector);
    }
    return selector;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder("Proxy search: ");
    for (ProxySearchStrategy strat : strategies)
    {
      sb.append(strat);
      sb.append(" ");
    }
    return sb.toString();
  }
  
  public static void main(String[] args)
  {
    ProxySearch ps = getDefaultProxySearch();
    Logger.setBackend(new Logger.LogBackEnd()
    {
      public void log(Class<?> clazz, Logger.LogLevel loglevel, String msg, Object... params)
      {
        System.out.println(MessageFormat.format(msg, params));
      }
      
      public boolean isLogginEnabled(Logger.LogLevel logLevel)
      {
        return true;
      }
    });
    ps.getProxySelector();
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.ProxySearch
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search;

import com.btr.proxy.util.ProxyException;
import java.net.ProxySelector;

public abstract interface ProxySearchStrategy
{
  public abstract ProxySelector getProxySelector()
    throws ProxyException;
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.ProxySearchStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.firefox;

import java.io.File;
import java.io.IOException;

abstract interface FirefoxProfileSource
{
  public abstract File getProfileFolder()
    throws IOException;
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.firefox.FirefoxProfileSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.firefox;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.search.desktop.DesktopProxySearchStrategy;
import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
import com.btr.proxy.selector.direct.NoProxySelector;
import com.btr.proxy.selector.fixed.FixedProxySelector;
import com.btr.proxy.selector.fixed.FixedSocksSelector;
import com.btr.proxy.selector.misc.ProtocolDispatchSelector;
import com.btr.proxy.selector.pac.PacProxySelector;
import com.btr.proxy.selector.pac.UrlPacScriptSource;
import com.btr.proxy.selector.whitelist.ProxyBypassListSelector;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.PlatformUtil;
import com.btr.proxy.util.PlatformUtil.Platform;
import com.btr.proxy.util.ProxyException;
import java.io.IOException;
import java.net.ProxySelector;
import java.util.Properties;

public class FirefoxProxySearchStrategy
  implements ProxySearchStrategy
{
  private FirefoxProfileSource profileScanner;
  private FirefoxSettingParser settingsParser;
  
  public FirefoxProxySearchStrategy()
  {
    if (PlatformUtil.getCurrentPlattform() == PlatformUtil.Platform.WIN) {
      profileScanner = new WinFirefoxProfileSource();
    } else {
      profileScanner = new LinuxFirefoxProfileSource();
    }
    settingsParser = new FirefoxSettingParser();
  }
  
  public ProxySelector getProxySelector()
    throws ProxyException
  {
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Detecting Firefox settings.", new Object[0]);
    
    Properties settings = readSettings();
    
    ProxySelector result = null;
    int type = Integer.parseInt(settings.getProperty("network.proxy.type", "-1"));
    switch (type)
    {
    case -1: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses system settings", new Object[0]);
      result = new DesktopProxySearchStrategy().getProxySelector();
      break;
    case 0: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses no proxy", new Object[0]);
      result = NoProxySelector.getInstance();
      break;
    case 1: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses manual settings", new Object[0]);
      result = setupFixedProxySelector(settings);
      break;
    case 2: 
      String pacScriptUrl = settings.getProperty("network.proxy.autoconfig_url", "");
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses script (PAC) {0}", new Object[] { pacScriptUrl });
      result = new PacProxySelector(new UrlPacScriptSource(pacScriptUrl));
      break;
    case 3: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Netscape compability mode -> uses no proxy", new Object[0]);
      result = NoProxySelector.getInstance();
      break;
    case 4: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses automatic detection (WPAD)", new Object[0]);
      result = new WpadProxySearchStrategy().getProxySelector();
      break;
    }
    String noProxyList = settings.getProperty("network.proxy.no_proxies_on", null);
    if ((result != null) && (noProxyList != null) && (noProxyList.trim().length() > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox uses proxy bypass list for: {0}", new Object[] { noProxyList });
      result = new ProxyBypassListSelector(noProxyList, result);
    }
    return result;
  }
  
  public Properties readSettings()
    throws ProxyException
  {
    try
    {
      return settingsParser.parseSettings(profileScanner);
    }
    catch (IOException e)
    {
      Logger.log(getClass(), Logger.LogLevel.ERROR, "Error parsing settings", new Object[] { e });
      throw new ProxyException(e);
    }
  }
  
  private ProxySelector setupFixedProxySelector(Properties settings)
  {
    ProtocolDispatchSelector ps = new ProtocolDispatchSelector();
    installHttpProxy(ps, settings);
    if (isProxyShared(settings))
    {
      installSharedProxy(ps);
    }
    else
    {
      installFtpProxy(ps, settings);
      installSecureProxy(ps, settings);
      installSocksProxy(ps, settings);
    }
    return ps;
  }
  
  private void installFtpProxy(ProtocolDispatchSelector ps, Properties settings)
    throws NumberFormatException
  {
    installSelectorForProtocol(ps, settings, "ftp");
  }
  
  private void installHttpProxy(ProtocolDispatchSelector ps, Properties settings)
    throws NumberFormatException
  {
    installSelectorForProtocol(ps, settings, "http");
  }
  
  private boolean isProxyShared(Properties settings)
  {
    return Boolean.TRUE.toString().equals(settings.getProperty("network.proxy.share_proxy_settings", "false").toLowerCase());
  }
  
  private void installSharedProxy(ProtocolDispatchSelector ps)
  {
    ProxySelector httpProxy = ps.getSelector("http");
    if (httpProxy != null) {
      ps.setFallbackSelector(httpProxy);
    }
  }
  
  private void installSocksProxy(ProtocolDispatchSelector ps, Properties settings)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("network.proxy.socks", null);
    int proxyPort = Integer.parseInt(settings.getProperty("network.proxy.socks_port", "0"));
    if ((proxyHost != null) && (proxyPort != 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox socks proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("socks", new FixedSocksSelector(proxyHost, proxyPort));
    }
  }
  
  private void installSecureProxy(ProtocolDispatchSelector ps, Properties settings)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("network.proxy.ssl", null);
    int proxyPort = Integer.parseInt(settings.getProperty("network.proxy.ssl_port", "0"));
    if ((proxyHost != null) && (proxyPort != 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox secure proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("https", new FixedProxySelector(proxyHost, proxyPort));
      ps.setSelector("sftp", new FixedProxySelector(proxyHost, proxyPort));
    }
  }
  
  private void installSelectorForProtocol(ProtocolDispatchSelector ps, Properties settings, String protocol)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("network.proxy." + protocol, null);
    int proxyPort = Integer.parseInt(settings.getProperty("network.proxy." + protocol + "_port", "0"));
    if ((proxyHost != null) && (proxyPort != 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox " + protocol + " proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector(protocol, new FixedProxySelector(proxyHost, proxyPort));
    }
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.firefox.FirefoxProxySearchStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.firefox;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

class FirefoxSettingParser
{
  public Properties parseSettings(FirefoxProfileSource source)
    throws IOException
  {
    File profileFolder = source.getProfileFolder();
    
    File settingsFile = new File(profileFolder, "prefs.js");
    
    BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(settingsFile)));
    
    Properties result = new Properties();
    try
    {
      String line = fin.readLine();
      while (line != null)
      {
        line = line.trim();
        if (line.startsWith("user_pref(\"network.proxy"))
        {
          line = line.substring(10, line.length() - 2);
          int index = line.indexOf(",");
          String key = line.substring(0, index).trim();
          if (key.startsWith("\"")) {
            key = key.substring(1);
          }
          if (key.endsWith("\"")) {
            key = key.substring(0, key.length() - 1);
          }
          String value = line.substring(index + 1).trim();
          if (value.startsWith("\"")) {
            value = value.substring(1);
          }
          if (value.endsWith("\"")) {
            value = value.substring(0, value.length() - 1);
          }
          result.put(key, value);
        }
        line = fin.readLine();
      }
    }
    finally
    {
      fin.close();
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.firefox.FirefoxSettingParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.firefox;

import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import java.io.File;

class LinuxFirefoxProfileSource
  implements FirefoxProfileSource
{
  public File getProfileFolder()
  {
    File userDir = new File(System.getProperty("user.home"));
    File cfgDir = new File(userDir, ".mozilla" + File.separator + "firefox" + File.separator);
    if (!cfgDir.exists())
    {
      Logger.log(getClass(), Logger.LogLevel.DEBUG, "Firefox settings folder not found!", new Object[0]);
      return null;
    }
    File[] profiles = cfgDir.listFiles();
    if ((profiles == null) || (profiles.length == 0))
    {
      Logger.log(getClass(), Logger.LogLevel.DEBUG, "Firefox settings folder not found!", new Object[0]);
      return null;
    }
    for (File p : profiles) {
      if (p.getName().endsWith(".default"))
      {
        Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox settings folder is {0}", new Object[] { p });
        return p;
      }
    }
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox settings folder is {0}", new Object[] { profiles[0] });
    return profiles[0];
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.firefox.LinuxFirefoxProfileSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.firefox;

import com.btr.proxy.search.desktop.win.Win32ProxyUtils;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import java.io.File;
import java.io.IOException;

class WinFirefoxProfileSource
  implements FirefoxProfileSource
{
  private String getAppFolder()
  {
    return new Win32ProxyUtils().readUserHomedir();
  }
  
  public File getProfileFolder()
    throws IOException
  {
    File appDataDir = new File(getAppFolder());
    File cfgDir = new File(appDataDir, "Mozilla" + File.separator + "Firefox" + File.separator + "Profiles");
    if (!cfgDir.exists())
    {
      Logger.log(getClass(), Logger.LogLevel.DEBUG, "Firefox windows settings folder not found.", new Object[0]);
      return null;
    }
    File[] profiles = cfgDir.listFiles();
    if ((profiles == null) || (profiles.length == 0))
    {
      Logger.log(getClass(), Logger.LogLevel.DEBUG, "Firefox windows settings folder not found.", new Object[0]);
      return null;
    }
    for (File p : profiles) {
      if (p.getName().endsWith(".default"))
      {
        Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox windows settings folder is {0}.", new Object[] { p });
        return p;
      }
    }
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Firefox windows settings folder is {0}.", new Object[] { profiles[0] });
    return profiles[0];
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.firefox.WinFirefoxProfileSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.ie;

import com.btr.proxy.util.UriFilter;
import java.net.URI;

public class IELocalByPassFilter
  implements UriFilter
{
  public boolean accept(URI uri)
  {
    if (uri == null) {
      return false;
    }
    String host = uri.getAuthority();
    return (host != null) && (!host.contains("."));
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.ie.IELocalByPassFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.browser.ie;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.search.desktop.win.Win32IESettings;
import com.btr.proxy.search.desktop.win.Win32ProxyUtils;
import com.btr.proxy.selector.fixed.FixedProxySelector;
import com.btr.proxy.selector.misc.ProtocolDispatchSelector;
import com.btr.proxy.selector.pac.PacProxySelector;
import com.btr.proxy.selector.pac.UrlPacScriptSource;
import com.btr.proxy.selector.whitelist.ProxyBypassListSelector;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.ProxyException;
import com.btr.proxy.util.ProxyUtil;
import com.btr.proxy.util.UriFilter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.ProxySelector;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class IEProxySearchStrategy
  implements ProxySearchStrategy
{
  public ProxySelector getProxySelector()
    throws ProxyException
  {
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Detecting IE proxy settings", new Object[0]);
    
    Win32IESettings ieSettings = readSettings();
    
    ProxySelector result = createPacSelector(ieSettings);
    if (result == null) {
      result = createFixedProxySelector(ieSettings);
    }
    return result;
  }
  
  public Win32IESettings readSettings()
  {
    Win32IESettings ieSettings = new Win32ProxyUtils().winHttpGetIEProxyConfigForCurrentUser();
    return ieSettings;
  }
  
  private PacProxySelector createPacSelector(Win32IESettings ieSettings)
  {
    String pacUrl = null;
    if (ieSettings.isAutoDetect())
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Autodetecting script URL.", new Object[0]);
      
      pacUrl = new Win32ProxyUtils().winHttpDetectAutoProxyConfigUrl(3);
    }
    if (pacUrl == null) {
      pacUrl = ieSettings.getAutoConfigUrl();
    }
    if ((pacUrl != null) && (pacUrl.trim().length() > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "IE uses script: " + pacUrl, new Object[0]);
      if ((pacUrl.startsWith("file://")) && (!pacUrl.startsWith("file:///"))) {
        pacUrl = "file:///" + pacUrl.substring(7);
      }
      return new PacProxySelector(new UrlPacScriptSource(pacUrl));
    }
    return null;
  }
  
  private ProxySelector createFixedProxySelector(Win32IESettings ieSettings)
    throws ProxyException
  {
    String proxyString = ieSettings.getProxy();
    String bypassList = ieSettings.getProxyBypass();
    if (proxyString == null) {
      return null;
    }
    Logger.log(getClass(), Logger.LogLevel.TRACE, "IE uses manual settings: {0} with bypass list: {1}", new Object[] { proxyString, bypassList });
    
    Properties p = parseProxyList(proxyString);
    
    ProtocolDispatchSelector ps = new ProtocolDispatchSelector();
    addSelectorForProtocol(p, "http", ps);
    addSelectorForProtocol(p, "https", ps);
    addSelectorForProtocol(p, "ftp", ps);
    addSelectorForProtocol(p, "gopher", ps);
    addSelectorForProtocol(p, "socks", ps);
    addFallbackSelector(p, ps);
    
    ProxySelector result = setByPassListOnSelector(bypassList, ps);
    return result;
  }
  
  private ProxySelector setByPassListOnSelector(String bypassList, ProtocolDispatchSelector ps)
  {
    if ((bypassList != null) && (bypassList.trim().length() > 0))
    {
      ProxyBypassListSelector result;
      ProxyBypassListSelector result;
      if ("<local>".equals(bypassList.trim()))
      {
        result = buildLocalBypassSelector(ps);
      }
      else
      {
        bypassList = bypassList.replace(';', ',');
        result = new ProxyBypassListSelector(bypassList, ps);
      }
      return result;
    }
    return ps;
  }
  
  private ProxyBypassListSelector buildLocalBypassSelector(ProtocolDispatchSelector ps)
  {
    List<UriFilter> localBypassFilter = new ArrayList();
    localBypassFilter.add(new IELocalByPassFilter());
    return new ProxyBypassListSelector(localBypassFilter, ps);
  }
  
  private void addFallbackSelector(Properties settings, ProtocolDispatchSelector ps)
  {
    String proxy = settings.getProperty("default");
    if (proxy != null) {
      ps.setFallbackSelector(ProxyUtil.parseProxySettings(proxy));
    }
  }
  
  private void addSelectorForProtocol(Properties settings, String protocol, ProtocolDispatchSelector ps)
  {
    String proxy = settings.getProperty(protocol);
    if (proxy != null)
    {
      FixedProxySelector protocolSelector = ProxyUtil.parseProxySettings(proxy);
      ps.setSelector(protocol, protocolSelector);
    }
  }
  
  private Properties parseProxyList(String proxyString)
    throws ProxyException
  {
    Properties p = new Properties();
    if (proxyString.indexOf('=') == -1) {
      p.setProperty("default", proxyString);
    } else {
      try
      {
        proxyString = proxyString.replace(';', '\n');
        p.load(new ByteArrayInputStream(proxyString.getBytes("ISO-8859-1")));
      }
      catch (IOException e)
      {
        Logger.log(getClass(), Logger.LogLevel.ERROR, "Error reading IE settings as properties: {0}", new Object[] { e });
        
        throw new ProxyException(e);
      }
    }
    return p;
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.browser.ie.IEProxySearchStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.desktop;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.search.desktop.gnome.GnomeProxySearchStrategy;
import com.btr.proxy.search.desktop.kde.KdeProxySearchStrategy;
import com.btr.proxy.search.desktop.osx.OsxProxySearchStrategy;
import com.btr.proxy.search.desktop.win.WinProxySearchStrategy;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.PlatformUtil;
import com.btr.proxy.util.PlatformUtil.Desktop;
import com.btr.proxy.util.PlatformUtil.Platform;
import com.btr.proxy.util.ProxyException;
import java.net.ProxySelector;

public class DesktopProxySearchStrategy
  implements ProxySearchStrategy
{
  public ProxySelector getProxySelector()
    throws ProxyException
  {
    PlatformUtil.Platform pf = PlatformUtil.getCurrentPlattform();
    PlatformUtil.Desktop dt = PlatformUtil.getCurrentDesktop();
    
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Detecting system settings.", new Object[0]);
    if (pf == PlatformUtil.Platform.WIN)
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "We are running on Windows.", new Object[0]);
      return new WinProxySearchStrategy().getProxySelector();
    }
    if (dt == PlatformUtil.Desktop.KDE)
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "We are running on KDE.", new Object[0]);
      return new KdeProxySearchStrategy().getProxySelector();
    }
    if (dt == PlatformUtil.Desktop.GNOME)
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "We are running on Gnome.", new Object[0]);
      return new GnomeProxySearchStrategy().getProxySelector();
    }
    if (dt == PlatformUtil.Desktop.MAC_OS)
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "We are running on Mac OSX.", new Object[0]);
      return new OsxProxySearchStrategy().getProxySelector();
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.desktop.DesktopProxySearchStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.desktop.gnome;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.selector.direct.NoProxySelector;
import com.btr.proxy.selector.fixed.FixedProxySelector;
import com.btr.proxy.selector.misc.ProtocolDispatchSelector;
import com.btr.proxy.selector.pac.PacProxySelector;
import com.btr.proxy.selector.pac.UrlPacScriptSource;
import com.btr.proxy.selector.whitelist.ProxyBypassListSelector;
import com.btr.proxy.util.EmptyXMLResolver;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.ProxyException;
import java.io.File;
import java.io.IOException;
import java.net.ProxySelector;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class GnomeProxySearchStrategy
  implements ProxySearchStrategy
{
  public ProxySelector getProxySelector()
    throws ProxyException
  {
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Detecting Gnome proxy settings", new Object[0]);
    
    Properties settings = readSettings();
    
    String type = settings.getProperty("/system/proxy/mode");
    ProxySelector result = null;
    if (type == null)
    {
      String useProxy = settings.getProperty("/system/http_proxy/use_http_proxy");
      if (useProxy == null) {
        return null;
      }
      type = Boolean.parseBoolean(useProxy) ? "manual" : "none";
    }
    if ("none".equals(type))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome uses no proxy", new Object[0]);
      result = NoProxySelector.getInstance();
    }
    if ("manual".equals(type))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome uses manual proxy settings", new Object[0]);
      result = setupFixedProxySelector(settings);
    }
    if ("auto".equals(type))
    {
      String pacScriptUrl = settings.getProperty("/system/proxy/autoconfig_url", "");
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome uses autodetect script {0}", new Object[] { pacScriptUrl });
      result = new PacProxySelector(new UrlPacScriptSource(pacScriptUrl));
    }
    String noProxyList = settings.getProperty("/system/http_proxy/ignore_hosts", null);
    if ((result != null) && (noProxyList != null) && (noProxyList.trim().length() > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome uses proxy bypass list: {0}", new Object[] { noProxyList });
      result = new ProxyBypassListSelector(noProxyList, result);
    }
    return result;
  }
  
  public Properties readSettings()
    throws ProxyException
  {
    Properties settings = new Properties();
    try
    {
      parseSettings("/system/proxy/", settings);
      parseSettings("/system/http_proxy/", settings);
    }
    catch (IOException e)
    {
      Logger.log(getClass(), Logger.LogLevel.ERROR, "Gnome settings file error.", new Object[] { e });
      throw new ProxyException(e);
    }
    return settings;
  }
  
  private File findSettingsFile(String context)
  {
    File userDir = new File(System.getProperty("user.home"));
    
    StringBuilder path = new StringBuilder();
    String[] parts = context.split("/");
    for (String part : parts)
    {
      path.append(part);
      path.append(File.separator);
    }
    File settingsFile = new File(userDir, ".gconf" + File.separator + path.toString() + "%gconf.xml");
    if (!settingsFile.exists())
    {
      Logger.log(getClass(), Logger.LogLevel.WARNING, "Gnome settings: {0} not found.", new Object[] { settingsFile });
      return null;
    }
    return settingsFile;
  }
  
  private ProxySelector setupFixedProxySelector(Properties settings)
  {
    if (!hasProxySettings(settings)) {
      return null;
    }
    ProtocolDispatchSelector ps = new ProtocolDispatchSelector();
    installHttpSelector(settings, ps);
    if (useForAllProtocols(settings))
    {
      ps.setFallbackSelector(ps.getSelector("http"));
    }
    else
    {
      installSecureSelector(settings, ps);
      installFtpSelector(settings, ps);
      installSocksSelector(settings, ps);
    }
    return ps;
  }
  
  private boolean useForAllProtocols(Properties settings)
  {
    return Boolean.parseBoolean(settings.getProperty("/system/http_proxy/use_same_proxy", "false"));
  }
  
  private boolean hasProxySettings(Properties settings)
  {
    String proxyHost = settings.getProperty("/system/http_proxy/host", null);
    return (proxyHost != null) && (proxyHost.length() > 0);
  }
  
  private void installHttpSelector(Properties settings, ProtocolDispatchSelector ps)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("/system/http_proxy/host", null);
    int proxyPort = Integer.parseInt(settings.getProperty("/system/http_proxy/port", "0").trim());
    if ((proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome http proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("http", new FixedProxySelector(proxyHost.trim(), proxyPort));
    }
  }
  
  private void installSocksSelector(Properties settings, ProtocolDispatchSelector ps)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("/system/proxy/socks_host", null);
    int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/socks_port", "0").trim());
    if ((proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome socks proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("socks", new FixedProxySelector(proxyHost.trim(), proxyPort));
    }
  }
  
  private void installFtpSelector(Properties settings, ProtocolDispatchSelector ps)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("/system/proxy/ftp_host", null);
    int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/ftp_port", "0").trim());
    if ((proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome ftp proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("ftp", new FixedProxySelector(proxyHost.trim(), proxyPort));
    }
  }
  
  private void installSecureSelector(Properties settings, ProtocolDispatchSelector ps)
    throws NumberFormatException
  {
    String proxyHost = settings.getProperty("/system/proxy/secure_host", null);
    int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/secure_port", "0").trim());
    if ((proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0))
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Gnome secure proxy is {0}:{1}", new Object[] { proxyHost, Integer.valueOf(proxyPort) });
      ps.setSelector("https", new FixedProxySelector(proxyHost.trim(), proxyPort));
      ps.setSelector("sftp", new FixedProxySelector(proxyHost.trim(), proxyPort));
    }
  }
  
  private Properties parseSettings(String context, Properties settings)
    throws IOException
  {
    File settingsFile = findSettingsFile(context);
    if (settingsFile == null) {
      return settings;
    }
    try
    {
      DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      documentBuilder.setEntityResolver(new EmptyXMLResolver());
      Document doc = documentBuilder.parse(settingsFile);
      Element root = doc.getDocumentElement();
      Node entry = root.getFirstChild();
      while (entry != null)
      {
        if (("entry".equals(entry.getNodeName())) && ((entry instanceof Element)))
        {
          String entryName = ((Element)entry).getAttribute("name");
          settings.setProperty(context + entryName, getEntryValue((Element)entry));
        }
        entry = entry.getNextSibling();
      }
    }
    catch (SAXException e)
    {
      Logger.log(getClass(), Logger.LogLevel.ERROR, "Gnome settings parse error", new Object[] { e });
      throw new IOException(e.getMessage());
    }
    catch (ParserConfigurationException e)
    {
      Logger.log(getClass(), Logger.LogLevel.ERROR, "Gnome settings parse error", new Object[] { e });
      throw new IOException(e.getMessage());
    }
    return settings;
  }
  
  private String getEntryValue(Element entry)
  {
    String type = entry.getAttribute("type");
    if (("int".equals(type)) || ("bool".equals(type))) {
      return entry.getAttribute("value");
    }
    if ("string".equals(type))
    {
      NodeList list = entry.getElementsByTagName("stringvalue");
      if (list.getLength() > 0) {
        return list.item(0).getTextContent();
      }
    }
    if ("list".equals(type))
    {
      StringBuilder result = new StringBuilder();
      NodeList list = entry.getElementsByTagName("li");
      for (int i = 0; i < list.getLength(); i++)
      {
        if (result.length() > 0) {
          result.append(",");
        }
        result.append(getEntryValue((Element)list.item(i)));
      }
      return result.toString();
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.btr.proxy.search.desktop.gnome.GnomeProxySearchStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.btr.proxy.search.desktop.kde;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.search.env.EnvProxySearchStrategy;
import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
import com.btr.proxy.selector.direct.NoProxySelector;
import com.btr.proxy.selector.fixed.FixedProxySelector;
import com.btr.proxy.selector.misc.ProtocolDispatchSelector;
import com.btr.proxy.selector.pac.PacProxySelector;
import com.btr.proxy.selector.pac.UrlPacScriptSource;
import com.btr.proxy.selector.whitelist.ProxyBypassListSelector;
import com.btr.proxy.selector.whitelist.UseProxyWhiteListSelector;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.ProxyException;
import com.btr.proxy.util.ProxyUtil;
import java.io.IOException;
import java.net.ProxySelector;
import java.util.Properties;

public class KdeProxySearchStrategy
  implements ProxySearchStrategy
{
  private KdeSettingsParser settingsParser;
  
  public KdeProxySearchStrategy()
  {
    this(new KdeSettingsParser());
  }
  
  public KdeProxySearchStrategy(KdeSettingsParser settingsParser)
  {
    this.settingsParser = settingsParser;
  }
  
  public ProxySelector getProxySelector()
    throws ProxyException
  {
    Logger.log(getClass(), Logger.LogLevel.TRACE, "Detecting Kde proxy settings", new Object[0]);
    
    Properties settings = readSettings();
    if (settings == null) {
      return null;
    }
    ProxySelector result = null;
    int type = Integer.parseInt(settings.getProperty("ProxyType", "-1"));
    switch (type)
    {
    case 0: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde uses no proxy", new Object[0]);
      result = NoProxySelector.getInstance();
      break;
    case 1: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde uses manual proxy settings", new Object[0]);
      result = setupFixedProxySelector(settings);
      break;
    case 2: 
      String pacScriptUrl = settings.getProperty("Proxy Config Script", "");
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde uses autodetect script {0}", new Object[] { pacScriptUrl });
      result = new PacProxySelector(new UrlPacScriptSource(pacScriptUrl));
      break;
    case 3: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde uses WPAD to detect the proxy", new Object[0]);
      result = new WpadProxySearchStrategy().getProxySelector();
      break;
    case 4: 
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde reads proxy from environment", new Object[0]);
      result = setupEnvVarSelector(settings);
      break;
    }
    return result;
  }
  
  private Properties readSettings()
    throws ProxyException
  {
    try
    {
      return settingsParser.parseSettings();
    }
    catch (IOException e)
    {
      Logger.log(getClass(), Logger.LogLevel.ERROR, "Can't parse settings.", new Object[] { e });
      throw new ProxyException(e);
    }
  }
  
  private ProxySelector setupEnvVarSelector(Properties settings)
  {
    ProxySelector result = new EnvProxySearchStrategy(settings.getProperty("httpProxy"), settings.getProperty("httpsProxy"), settings.getProperty("ftpProxy"), settings.getProperty("NoProxyFor")).getProxySelector();
    
    return result;
  }
  
  private ProxySelector setupFixedProxySelector(Properties settings)
  {
    String proxyVar = settings.getProperty("httpProxy", null);
    FixedProxySelector httpPS = ProxyUtil.parseProxySettings(proxyVar);
    if (httpPS == null)
    {
      Logger.log(getClass(), Logger.LogLevel.TRACE, "Kde http proxy is {0}", new Object[] { proxyVar });
      return null;
    }
    ProtocolDispatchSelector ps = new ProtocolDispatchSelector();
    ps.setSelector("http", httpPS);
    
    proxyVar = settings.getProperty("httpsProxy", null);
    FixedProx
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd