random socks5 test
This commit is contained in:
@@ -5,6 +5,7 @@ import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
import static ru.vtosters.lite.utils.ProxyUtils.apiproxy;
|
||||
import static ru.vtosters.lite.utils.ProxyUtils.isRandomSocksEnabled;
|
||||
import static ru.vtosters.lite.utils.ProxyUtils.isZaboronaEnabled;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAlertStyle;
|
||||
@@ -41,40 +42,46 @@ public class ProxyHook {
|
||||
RadioGroup rg = new RadioGroup(ctx);
|
||||
|
||||
RadioButton rgDefault = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgProxy = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgZaborona = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgRandomSocks = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
|
||||
rg.addView(rgDefault);
|
||||
rg.addView(rgProxy);
|
||||
rg.addView(rgZaborona);
|
||||
rg.addView(rgRandomSocks);
|
||||
|
||||
rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgProxy.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgZaborona.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgRandomSocks.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
|
||||
rg.setPadding(dp2px(18f), dp2px(12f), dp2px(18f), 0);
|
||||
|
||||
rgDefault.setText(AndroidUtils.getString("proxy_disable"));
|
||||
rgDefault.setTextColor(getTextAttr());
|
||||
|
||||
rgProxy.setText(AndroidUtils.getString("proxy_enable") + " (Zaborona)");
|
||||
rgProxy.setTextColor(getTextAttr());
|
||||
rgZaborona.setText(AndroidUtils.getString("proxy_enable") + " (Zaborona)");
|
||||
rgZaborona.setTextColor(getTextAttr());
|
||||
|
||||
rgProxy.setChecked(isZaboronaEnabled());
|
||||
rgRandomSocks.setText(AndroidUtils.getString("proxy_enable") + " (RandomSocks)");
|
||||
rgRandomSocks.setTextColor(getTextAttr());
|
||||
|
||||
rgZaborona.setChecked(isZaboronaEnabled());
|
||||
rgDefault.setChecked(!isZaboronaEnabled());
|
||||
rgRandomSocks.setChecked(isRandomSocksEnabled());
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx, getAlertStyle());
|
||||
builder.setTitle(AndroidUtils.getString("vtlproxy"));
|
||||
builder.setMessage(AndroidUtils.getString("proxy_warning"));
|
||||
builder.setView(rg);
|
||||
builder.setPositiveButton(AndroidUtils.getString("vtl_confirm"), ((dialog, which) -> { // Применить
|
||||
if (rgProxy.isChecked()) {
|
||||
if (rgZaborona.isChecked()) {
|
||||
edit().putString("proxy", "zaborona").commit();
|
||||
restartApplication();
|
||||
} else if (rgRandomSocks.isChecked()) {
|
||||
edit().putString("proxy", "randomsocks").commit();
|
||||
restartApplication();
|
||||
} else {
|
||||
if (isZaboronaEnabled()) {
|
||||
edit().putString("proxy", "noproxy").commit();
|
||||
restartApplication();
|
||||
}
|
||||
|
||||
edit().putString("proxy", "noproxy").commit();
|
||||
restartApplication();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.ProxyUtils.setProxyRefl;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class ProxyList{
|
||||
private static final OkHttpClient mClient = new OkHttpClient();
|
||||
|
||||
public static void loadProxy() {
|
||||
Request link = new Request.a()
|
||||
.b("https://raw.githubusercontent.com/hookzof/socks5_list/master/proxy.txt")
|
||||
.a();
|
||||
|
||||
mClient.a(link).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("ProxyList", "Error while getting proxy: " + e);
|
||||
loadError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
try {
|
||||
setData(response);
|
||||
} catch (JSONException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void loadError() {
|
||||
sendToast("Error while getting proxy");
|
||||
}
|
||||
|
||||
static void setData(Response response) throws IOException, JSONException {
|
||||
String resp = response.a().g();
|
||||
|
||||
if (!hasProxy(resp)) {
|
||||
Log.d("ProxyList", "No proxy found");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> proxyList = new ArrayList<>(Arrays.asList(resp.split("\n")));
|
||||
|
||||
Log.d("ProxyList", proxyList.toString());
|
||||
|
||||
String proxy = proxyList.get(new java.util.Random().nextInt(proxyList.size()));
|
||||
|
||||
if (!hasProxy(proxy)) {
|
||||
Log.d("ProxyList", "No proxy port found");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d("ProxyList", "Setting proxy: " + proxy.split(":")[0] + ":" + proxy.split(":")[1]);
|
||||
|
||||
System.setProperty("socksProxyHost", proxy.split(":")[0]);
|
||||
System.setProperty("socksProxyPort", proxy.split(":")[1]);
|
||||
setProxyRefl();
|
||||
}
|
||||
|
||||
static boolean hasProxy(String list) {
|
||||
return list.contains(":"); // proxy format: ip:port
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,10 @@ public class ProxyUtils {
|
||||
return getPrefsValue("proxy").equals("zaborona");
|
||||
}
|
||||
|
||||
public static Boolean isRandomSocksEnabled() {
|
||||
return getPrefsValue("proxy").equals("randomsocks");
|
||||
}
|
||||
|
||||
public static void setProxyRefl() {
|
||||
Log.d("Proxy", "Setting proxy...");
|
||||
try {
|
||||
@@ -76,6 +80,9 @@ public class ProxyUtils {
|
||||
System.setProperty("socksProxyPort", "1488");
|
||||
setProxyRefl();
|
||||
break;
|
||||
case "randomsocks":
|
||||
ProxyList.loadProxy();
|
||||
break;
|
||||
case "socks":
|
||||
System.setProperty("socksProxyHost", proxyHostSocks());
|
||||
System.setProperty("socksProxyPort", proxyPortSocks());
|
||||
|
||||
@@ -595,6 +595,7 @@
|
||||
<string-array name="proxy">
|
||||
<item>Без прокси</item>
|
||||
<item>zaborona.help</item>
|
||||
<item>Рандомный Socks5</item>
|
||||
<item>Сторонний прокси для API</item>
|
||||
<item>Сторонний HTTP</item>
|
||||
<item>Сторонний HTTPS</item>
|
||||
|
||||
@@ -743,6 +743,7 @@
|
||||
<string-array name="proxy">
|
||||
<item>No Proxy</item>
|
||||
<item>zaborona.help</item>
|
||||
<item>Random Socks5</item>
|
||||
<item>Custom API proxy</item>
|
||||
<item>Custom HTTP</item>
|
||||
<item>Custom HTTPS</item>
|
||||
@@ -751,6 +752,7 @@
|
||||
<string-array name="proxy_value">
|
||||
<item>noproxy</item>
|
||||
<item>zaborona</item>
|
||||
<item>randomsocks</item>
|
||||
<item>apiproxy</item>
|
||||
<item>http</item>
|
||||
<item>https</item>
|
||||
|
||||
Reference in New Issue
Block a user