android: Import proxy server settings
This commit is contained in:
+42
-45
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016-2020 Tobias Brunner
|
* Copyright (C) 2016-2025 Tobias Brunner
|
||||||
*
|
*
|
||||||
* Copyright (C) secunet Security Networks AG
|
* Copyright (C) secunet Security Networks AG
|
||||||
*
|
*
|
||||||
@@ -556,6 +556,14 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
flags |= VpnProfile.FLAGS_IPv6_TRANSPORT;
|
flags |= VpnProfile.FLAGS_IPv6_TRANSPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSONObject proxy = obj.optJSONObject("proxy");
|
||||||
|
if (proxy != null)
|
||||||
|
{
|
||||||
|
profile.setProxyHost(proxy.optString("host"));
|
||||||
|
profile.setProxyPort(getInteger(proxy, "port", 1, 65535));
|
||||||
|
profile.setProxyExclusions(getFlatStringList(proxy, "exclusions"));
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject split = obj.optJSONObject("split-tunneling");
|
JSONObject split = obj.optJSONObject("split-tunneling");
|
||||||
if (split != null)
|
if (split != null)
|
||||||
{
|
{
|
||||||
@@ -569,8 +577,8 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
profile.setSplitTunneling(st == 0 ? null : st);
|
profile.setSplitTunneling(st == 0 ? null : st);
|
||||||
}
|
}
|
||||||
/* only one of these can be set, prefer specific apps */
|
/* only one of these can be set, prefer specific apps */
|
||||||
String selectedApps = getApps(obj.optJSONArray("apps"));
|
String selectedApps = getFlatStringList(obj, "apps");
|
||||||
String excludedApps = getApps(obj.optJSONArray("excluded-apps"));
|
String excludedApps = getFlatStringList(obj, "excluded-apps");
|
||||||
if (!TextUtils.isEmpty(selectedApps))
|
if (!TextUtils.isEmpty(selectedApps))
|
||||||
{
|
{
|
||||||
profile.setSelectedApps(selectedApps);
|
profile.setSelectedApps(selectedApps);
|
||||||
@@ -606,24 +614,8 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private String getSubnets(JSONObject split, String key) throws JSONException
|
private String getSubnets(JSONObject split, String key) throws JSONException
|
||||||
{
|
{
|
||||||
ArrayList<String> subnets = new ArrayList<>();
|
ArrayList<String> subnets = getStringList(split, key);
|
||||||
JSONArray arr = split.optJSONArray(key);
|
if (!subnets.isEmpty())
|
||||||
if (arr != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < arr.length(); i++)
|
|
||||||
{ /* replace all spaces, e.g. in "192.168.1.1 - 192.168.1.10" */
|
|
||||||
subnets.add(arr.getString(i).replace(" ", ""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String value = split.optString(key, null);
|
|
||||||
if (!TextUtils.isEmpty(value))
|
|
||||||
{
|
|
||||||
subnets.add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (subnets.size() > 0)
|
|
||||||
{
|
{
|
||||||
String joined = TextUtils.join(" ", subnets);
|
String joined = TextUtils.join(" ", subnets);
|
||||||
IPRangeSet ranges = IPRangeSet.fromString(joined);
|
IPRangeSet ranges = IPRangeSet.fromString(joined);
|
||||||
@@ -639,25 +631,8 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private String getAddressList(JSONObject obj, String key) throws JSONException
|
private String getAddressList(JSONObject obj, String key) throws JSONException
|
||||||
{
|
{
|
||||||
ArrayList<String> addrs = new ArrayList<>();
|
ArrayList<String> addrs = getStringList(obj, key);
|
||||||
JSONArray arr = obj.optJSONArray(key);
|
if (!addrs.isEmpty())
|
||||||
if (arr != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < arr.length(); i++)
|
|
||||||
{
|
|
||||||
String addr = arr.getString(i).replace(" ", "");
|
|
||||||
addrs.add(addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String value = obj.optString(key, null);
|
|
||||||
if (!TextUtils.isEmpty(value))
|
|
||||||
{
|
|
||||||
Collections.addAll(addrs, value.split("\\s+"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (addrs.size() > 0)
|
|
||||||
{
|
{
|
||||||
for (String addr : addrs)
|
for (String addr : addrs)
|
||||||
{
|
{
|
||||||
@@ -675,17 +650,39 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApps(JSONArray arr) throws JSONException
|
private String getFlatStringList(JSONObject obj, String key) throws JSONException
|
||||||
{
|
{
|
||||||
ArrayList<String> apps = new ArrayList<>();
|
ArrayList<String> list = getStringList(obj, key);
|
||||||
|
if (!list.isEmpty())
|
||||||
|
{
|
||||||
|
return TextUtils.join(" ", list);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of strings, either retrieved from an array or from a space-separated string.
|
||||||
|
*/
|
||||||
|
private ArrayList<String> getStringList(JSONObject obj, String key) throws JSONException
|
||||||
|
{
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
JSONArray arr = obj.optJSONArray(key);
|
||||||
if (arr != null)
|
if (arr != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < arr.length(); i++)
|
for (int i = 0; i < arr.length(); i++)
|
||||||
{
|
{ /* replace all spaces, including e.g. in "192.168.1.1 - 192.168.1.10" */
|
||||||
apps.add(arr.getString(i));
|
list.add(arr.getString(i).replace(" ", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TextUtils.join(" ", apps);
|
else
|
||||||
|
{
|
||||||
|
String value = obj.optString(key, null);
|
||||||
|
if (!TextUtils.isEmpty(value))
|
||||||
|
{
|
||||||
|
Collections.addAll(list, value.split("\\s+"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user