Example #1
0
  public static ProxyStatusItem isProxyValidHostname(String proxyHost) {
    try {
      if (TextUtils.isEmpty(proxyHost)) {
        return new ProxyStatusItem(
            ProxyStatusProperties.PROXY_VALID_HOSTNAME,
            CheckStatusValues.CHECKED,
            false,
            APL.getContext().getString(R.string.status_hostname_empty));
      } else {
        Matcher match = APLConstants.HOSTNAME_PATTERN.matcher(proxyHost);
        if (match.matches()) {
          String hostnameValidMsg = APL.getContext().getString(R.string.status_hostname_valid);
          String msg = String.format("%s %s", hostnameValidMsg, proxyHost);
          return new ProxyStatusItem(
              ProxyStatusProperties.PROXY_VALID_HOSTNAME, CheckStatusValues.CHECKED, true, msg);
        }
      }
    } catch (Exception e) {
      APL.getEventReport().send(e);
    }

    return new ProxyStatusItem(
        ProxyStatusProperties.PROXY_VALID_HOSTNAME,
        CheckStatusValues.CHECKED,
        false,
        APL.getContext().getString(R.string.status_hostname_notvalid));
  }
Example #2
0
  public static ProxyStatusItem isProxyValidExclusionList(String[] proxyExclusionList) {
    try {
      for (int i = 0; i < proxyExclusionList.length; i++) {
        String s = proxyExclusionList[i].trim();
        ProxyStatusItem status = isProxyValidExclusionAddress(s);

        if (!status.result) {
          return new ProxyStatusItem(
              ProxyStatusProperties.PROXY_VALID_EXCLUSION_LIST,
              CheckStatusValues.CHECKED,
              true,
              APL.getContext().getString(R.string.status_exclusion_list_notvalid));
        }
      }

      String msg =
          String.format(
              "%s %s",
              APL.getContext().getString(R.string.status_exclusion_item_valid),
              TextUtils.join(",", proxyExclusionList));
      return new ProxyStatusItem(
          ProxyStatusProperties.PROXY_VALID_EXCLUSION_ITEM, CheckStatusValues.CHECKED, true, msg);
    } catch (Exception e) {
      APL.getEventReport().send(e);
    }

    return new ProxyStatusItem(
        ProxyStatusProperties.PROXY_VALID_EXCLUSION_ITEM,
        CheckStatusValues.CHECKED,
        false,
        APL.getContext().getString(R.string.status_exclusion_item_notvalid));
  }
Example #3
0
  public static ProxyStatusItem isProxyValidExclusionAddress(String proxyExclusionAddress) {
    try {
      //            if (TextUtils.isEmpty(proxyExclusionAddress))
      //            {
      //                return new ProxyStatusItem(ProxyStatusProperties.PROXY_VALID_EXCLUSION_ITEM,
      // CheckStatusValues.CHECKED, false,
      // APL.getContext().getString(R.string.status_exclusion_item_empty));
      //            }
      //            else
      //            {
      Matcher match = APLConstants.EXCLUSION_PATTERN.matcher(proxyExclusionAddress);
      if (match.matches()) {
        String msg =
            String.format(
                "%s %s",
                APL.getContext().getString(R.string.status_exclusion_item_valid),
                proxyExclusionAddress);
        return new ProxyStatusItem(
            ProxyStatusProperties.PROXY_VALID_EXCLUSION_ITEM, CheckStatusValues.CHECKED, true, msg);
      }
      //            }
    } catch (Exception e) {
      APL.getEventReport().send(e);
    }

    return new ProxyStatusItem(
        ProxyStatusProperties.PROXY_VALID_EXCLUSION_ITEM,
        CheckStatusValues.CHECKED,
        false,
        APL.getContext().getString(R.string.status_exclusion_item_notvalid));
  }
Example #4
0
  protected static ProxyStatusItem isWifiEnabled(ProxyConfiguration conf) {
    ProxyStatusItem result = null;

    if (APL.getWifiManager().isWifiEnabled()) {
      NetworkInfo ni = APL.getConnectivityManager().getActiveNetworkInfo();
      if (ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI) {
        String status = APL.getContext().getString(R.string.status_wifi_enabled);
        result =
            new ProxyStatusItem(
                ProxyStatusProperties.WIFI_ENABLED, CheckStatusValues.CHECKED, true, true, status);
      } else {
        result =
            new ProxyStatusItem(
                ProxyStatusProperties.WIFI_ENABLED,
                CheckStatusValues.CHECKED,
                false,
                true,
                APL.getContext().getString(R.string.status_wifi_enabled_disconnected));
      }
    } else {
      result =
          new ProxyStatusItem(
              ProxyStatusProperties.WIFI_ENABLED,
              CheckStatusValues.CHECKED,
              false,
              true,
              APL.getContext().getString(R.string.status_wifi_not_enabled));
    }

    return result;
  }
Example #5
0
  public static boolean lowLevelPingHost(Proxy proxy) {
    int exitValue;
    Runtime runtime = Runtime.getRuntime();
    Process proc;

    String cmdline = null;
    String proxyAddress = null;

    try {
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxy.address();
      proxyAddress = proxySocketAddress.getAddress().getHostAddress();
    } catch (Exception e) {
      APL.getEventReport()
          .send(
              new Exception(
                  "ProxyUtils.lowLevelPingHost() Exception calling getAddress().getHostAddress() on proxySocketAddress : ",
                  e));
    }

    if (proxyAddress == null) {
      try {
        InetSocketAddress proxySocketAddress = (InetSocketAddress) proxy.address();
        proxyAddress = proxySocketAddress.toString();
      } catch (Exception e) {
        APL.getEventReport()
            .send(
                new Exception(
                    "ProxyUtils.lowLevelPingHost() Exception calling toString() on proxySocketAddress",
                    e));
      }
    }

    if (proxyAddress != null) {
      cmdline = "ping -c 1 -w 1 " + proxyAddress;

      try {
        proc = runtime.exec(cmdline);
        proc.waitFor();
        exitValue = proc.exitValue();

        LogWrapper.d(TAG, "Ping exit value: " + exitValue);

        if (exitValue == 0) {
          return true;
        } else {
          return false;
        }
      } catch (IOException e) {
        APL.getEventReport().send(new Exception("ProxyUtils.lowLevelPingHost() IOException", e));
      } catch (InterruptedException e) {
        APL.getEventReport()
            .send(new Exception("ProxyUtils.lowLevelPingHost() InterruptedException", e));
      }
    }

    return false;
  }
Example #6
0
  public static void connectToAP(ProxyConfiguration conf) throws Exception {
    if (APL.getWifiManager() != null && APL.getWifiManager().isWifiEnabled()) {
      if (conf != null && conf.ap != null && conf.ap.getLevel() > -1) {
        // Connect to AP only if it's available
        ReflectionUtils.connectToWifi(APL.getWifiManager(), conf.ap.networkId);

        APL.getWifiManager().enableNetwork(conf.ap.networkId, true);
      }
    }
  }
Example #7
0
  protected static ProxyStatusItem isProxyEnabled(ProxyConfiguration conf) {
    ProxyStatusItem result;

    if (Build.VERSION.SDK_INT >= 12) {
      // On API version > Honeycomb 3.1 (HONEYCOMB_MR1)
      // Proxy is disabled by default on Mobile connection
      ConnectivityManager cm = APL.getConnectivityManager();
      if (cm != null) {
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE) {
          result =
              new ProxyStatusItem(
                  ProxyStatusProperties.PROXY_ENABLED,
                  CheckStatusValues.CHECKED,
                  false,
                  APL.getContext().getString(R.string.status_proxy_mobile_disabled));
          return result;
        }
      }
    }

    if (conf.getProxySettings() == ProxySetting.UNASSIGNED
        || conf.getProxySettings() == ProxySetting.NONE) {
      result =
          new ProxyStatusItem(
              ProxyStatusProperties.PROXY_ENABLED,
              CheckStatusValues.CHECKED,
              false,
              APL.getContext().getString(R.string.status_proxy_disabled));
    } else {
      // if (proxyHost != null && proxyPort != null)
      // {
      // HTTP or SOCKS proxy
      result =
          new ProxyStatusItem(
              ProxyStatusProperties.PROXY_ENABLED,
              CheckStatusValues.CHECKED,
              true,
              APL.getContext().getString(R.string.status_proxy_enabled));
      // }
      // else
      // {
      // result = new ProxyStatusItem(ProxyStatusProperties.PROXY_ENABLED,
      // CheckStatusValues.CHECKED, false);
      // }
    }

    return result;
  }
Example #8
0
 private static void broadCastUpdatedStatus() {
   //        LogWrapper.d(TAG, "Sending broadcast intent: " +
   // APLConstants.APL_UPDATED_PROXY_STATUS_CHECK);
   Intent intent = new Intent(APLIntents.APL_UPDATED_PROXY_STATUS_CHECK);
   // intent.putExtra(APLConstants.ProxyStatus, status);
   APL.getContext().sendBroadcast(intent);
 }
Example #9
0
 protected static ProxyStatusItem isWebReachable(ProxyConfiguration conf, int timeout) {
   Boolean result = ProxyUtils.canGetWebResources(conf, timeout);
   if (result) {
     return new ProxyStatusItem(
         ProxyStatusProperties.WEB_REACHABLE,
         CheckStatusValues.CHECKED,
         true,
         APL.getContext().getString(R.string.status_web_reachable));
   } else {
     return new ProxyStatusItem(
         ProxyStatusProperties.WEB_REACHABLE,
         CheckStatusValues.CHECKED,
         false,
         APL.getContext().getString(R.string.status_web_not_reachable));
   }
 }
Example #10
0
 /**
  * Try to set the Proxy Settings for active WebViews. This works only for devices with API version
  * < 12.
  */
 public static void setWebViewProxy(Context context, ProxyConfiguration proxyConf) {
   if (Build.VERSION.SDK_INT >= 12) {
     // On newer devices do nothing!
   } else {
     // On older devices try to set or clear the proxy settings, depending on the argument
     // configuration
     try {
       if (proxyConf != null
           && proxyConf.getProxyType() == Type.HTTP
           && APL.getDeviceVersion() < 12) {
         setProxy(context, proxyConf.getProxyIPHost(), proxyConf.getProxyPort());
       } else {
         resetProxy(context);
       }
     } catch (Exception e) {
       APL.getEventReport().send(e);
     }
   }
 }
Example #11
0
  public static boolean standardAPIPingHost(Proxy proxy) {
    try {
      InetSocketAddress proxySocketAddress = (InetSocketAddress) proxy.address();
      return InetAddress.getByName(proxySocketAddress.toString().split(":")[0]).isReachable(100000);
      //			return proxySocketAddress.getAddress().isReachable(100000);
    } catch (Exception e) {
      APL.getEventReport().send(new Exception("ProxyUtils.standardAPIPingHost() Exception", e));
    }

    return false;
  }
Example #12
0
  public static ProxyStatusItem isProxyValidPort(Integer proxyPort) {
    if ((proxyPort == null)) {
      return new ProxyStatusItem(
          ProxyStatusProperties.PROXY_VALID_PORT,
          CheckStatusValues.CHECKED,
          false,
          APL.getContext().getString(R.string.status_port_empty));
    }

    if ((proxyPort < 1) || (proxyPort > 65535)) {
      return new ProxyStatusItem(
          ProxyStatusProperties.PROXY_VALID_PORT,
          CheckStatusValues.CHECKED,
          false,
          APL.getContext().getString(R.string.status_port_notvalid));
    }

    String msg =
        String.format("%s %d", APL.getContext().getString(R.string.status_port_valid), proxyPort);
    return new ProxyStatusItem(
        ProxyStatusProperties.PROXY_VALID_PORT, CheckStatusValues.CHECKED, true, msg);
  }
Example #13
0
  protected static ProxyStatusItem isWifiSelected(ProxyConfiguration conf) {
    ProxyStatusItem result = null;

    if (conf.isCurrentNetwork()) {
      result =
          new ProxyStatusItem(
              ProxyStatusProperties.WIFI_SELECTED,
              CheckStatusValues.CHECKED,
              true,
              true,
              APL.getContext().getString(R.string.status_wifi_selected, conf.ap.ssid));
    } else {
      result =
          new ProxyStatusItem(
              ProxyStatusProperties.WIFI_SELECTED,
              CheckStatusValues.CHECKED,
              false,
              true,
              APL.getContext().getString(R.string.status_wifi_not_selected));
    }

    return result;
  }
Example #14
0
 /** Try to PING the HOST specified in the current proxy configuration */
 protected static ProxyStatusItem isProxyReachable(ProxyConfiguration conf) {
   if (conf.getProxy() != null && conf.getProxyType() != Proxy.Type.DIRECT) {
     Boolean result = ProxyUtils.isHostReachable(conf.getProxy());
     if (result) {
       return new ProxyStatusItem(
           ProxyStatusProperties.PROXY_REACHABLE,
           CheckStatusValues.CHECKED,
           true,
           APL.getContext().getString(R.string.status_proxy_reachable));
     } else {
       return new ProxyStatusItem(
           ProxyStatusProperties.PROXY_REACHABLE,
           CheckStatusValues.CHECKED,
           false,
           APL.getContext().getString(R.string.status_proxy_not_reachable));
     }
   } else {
     return new ProxyStatusItem(
         ProxyStatusProperties.PROXY_REACHABLE,
         CheckStatusValues.CHECKED,
         false,
         APL.getContext().getString(R.string.status_proxy_not_valid_informations));
   }
 }
Example #15
0
 private static boolean setProxy(Context ctx, String host, int port) {
   boolean ret = false;
   try {
     Object requestQueueObject = getRequestQueue(ctx);
     if (requestQueueObject != null) {
       // Create Proxy config object and set it into request Q
       HttpHost httpHost = new HttpHost(host, port, "http");
       setDeclaredField(requestQueueObject, "mProxyHost", httpHost);
       // LogWrapper.d("Webkit Setted Proxy to: " + host + ":" + port);
       ret = true;
     }
   } catch (Exception e) {
     APL.getEventReport().send(new Exception("Exception setting WebKit proxy settings", e));
   }
   return ret;
 }
Example #16
0
  public static int testHTTPConnection(
      URI uri, ProxyConfiguration proxyConfiguration, int timeout) {
    int step = 0;
    while (step < 5) {
      try {
        URL url = uri.toURL();

        if (proxyConfiguration != null && proxyConfiguration.getProxyType() == Type.HTTP) {
          System.setProperty("http.proxyHost", proxyConfiguration.getProxyIPHost());
          System.setProperty("http.proxyPort", proxyConfiguration.getProxyPort().toString());
        } else {
          System.setProperty("http.proxyHost", "");
          System.setProperty("http.proxyPort", "");
        }

        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

        httpURLConnection.setReadTimeout(timeout);
        httpURLConnection.setConnectTimeout(timeout);

        int result = httpURLConnection.getResponseCode();
        return result;
      } catch (Exception e) {
        LogWrapper.w(TAG, e.toString());
      }

      step++;

      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        APL.getEventReport().send(e);
        return -1;
      }
    }

    return -1;
  }
Example #17
0
 public static void startWifiScan() {
   if (APL.getWifiManager() != null && APL.getWifiManager().isWifiEnabled()) {
     APL.getWifiManager().startScan();
   }
 }
Example #18
0
 public static NetworkInfo getCurrentWiFiInfo() {
   NetworkInfo ni = APL.getConnectivityManager().getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   return ni;
 }
Example #19
0
 public static NetworkInfo getCurrentNetworkInfo() {
   NetworkInfo ni = APL.getConnectivityManager().getActiveNetworkInfo();
   return ni;
 }