Skip to content

Commit aa21e0e

Browse files
committed
Implement new ip parameter for captcha check
1 parent 8a589a5 commit aa21e0e

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

gradle/versions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ext {
7979
gravitySnapHelperVersion = "2.2.0"
8080

8181
// Utils
82-
proxerLibVersion = "70ee4f0858"
82+
proxerLibVersion = "891bb378a4"
8383
threetenVersion = "1.2.1"
8484
hawkVersion = "7a1a625455"
8585
glideVersion = "4.10.0"

src/main/kotlin/me/proxer/app/base/BaseContentFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import me.proxer.app.R
2323
import me.proxer.app.util.ErrorUtils.ErrorAction
2424
import me.proxer.app.util.ErrorUtils.ErrorAction.Companion.ACTION_MESSAGE_DEFAULT
2525
import me.proxer.app.util.ErrorUtils.ErrorAction.Companion.ACTION_MESSAGE_HIDE
26+
import me.proxer.app.util.Utils
2627
import me.proxer.app.util.compat.isConnected
2728
import me.proxer.app.util.extension.resolveColor
2829
import me.proxer.library.enums.Device
@@ -150,7 +151,7 @@ abstract class BaseContentFragment<T>(@LayoutRes contentLayoutId: Int) : BaseFra
150151
true -> {
151152
isSolvingCaptcha = true
152153

153-
showPage(ProxerUrls.captchaWeb(Device.MOBILE))
154+
showPage(ProxerUrls.captchaWeb(Utils.getIpAddress(), Device.MOBILE))
154155
}
155156
false -> action.toClickListener(hostingActivity)?.onClick(errorButton) ?: viewModel.load()
156157
}

src/main/kotlin/me/proxer/app/util/ErrorUtils.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ object ErrorUtils : KoinComponent {
323323
}
324324

325325
fun toClickListener(activity: BaseActivity) = when (buttonAction) {
326-
CAPTCHA -> View.OnClickListener { activity.showPage(ProxerUrls.captchaWeb(Device.MOBILE)) }
326+
CAPTCHA -> View.OnClickListener {
327+
activity.showPage(ProxerUrls.captchaWeb(Utils.getIpAddress(), Device.MOBILE))
328+
}
327329
NETWORK_SETTINGS -> View.OnClickListener {
328330
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
329331
activity.startActivity(Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY))
@@ -343,7 +345,10 @@ object ErrorUtils : KoinComponent {
343345
}
344346

345347
fun toIntent() = when (buttonAction) {
346-
CAPTCHA -> Intent(Intent.ACTION_VIEW, ProxerUrls.captchaWeb(Device.MOBILE).androidUri())
348+
CAPTCHA -> Intent(
349+
Intent.ACTION_VIEW,
350+
ProxerUrls.captchaWeb(Utils.getIpAddress(), Device.MOBILE).androidUri()
351+
)
347352
else -> null
348353
}
349354

src/main/kotlin/me/proxer/app/util/Utils.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import me.proxer.app.util.extension.androidUri
1010
import okhttp3.HttpUrl
1111
import org.threeten.bp.format.DateTimeFormatter
1212
import timber.log.Timber
13+
import java.net.NetworkInterface
1314

1415
/**
1516
* @author Ruben Gees
@@ -32,6 +33,18 @@ object Utils {
3233
null
3334
}
3435

36+
fun getIpAddress(): String? = try {
37+
NetworkInterface.getNetworkInterfaces().asSequence()
38+
.flatMap { it.inetAddresses.asSequence() }
39+
.filterNot { it.isLoopbackAddress || it.isLinkLocalAddress }
40+
.map { it.hostAddress }
41+
.firstOrNull()
42+
} catch (error: Throwable) {
43+
Timber.e("Error trying to get ip address", error)
44+
45+
null
46+
}
47+
3548
fun getNativeAppPackage(context: Context, url: HttpUrl): Set<String> {
3649
val browserActivityIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.generic.com"))
3750
val genericResolvedList = extractPackageNames(

0 commit comments

Comments
 (0)