Skip to content

Commit

Permalink
Implement new ip parameter for captcha check
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Oct 26, 2019
1 parent 8a589a5 commit aa21e0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ext {
gravitySnapHelperVersion = "2.2.0"

// Utils
proxerLibVersion = "70ee4f0858"
proxerLibVersion = "891bb378a4"
threetenVersion = "1.2.1"
hawkVersion = "7a1a625455"
glideVersion = "4.10.0"
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/me/proxer/app/base/BaseContentFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import me.proxer.app.R
import me.proxer.app.util.ErrorUtils.ErrorAction
import me.proxer.app.util.ErrorUtils.ErrorAction.Companion.ACTION_MESSAGE_DEFAULT
import me.proxer.app.util.ErrorUtils.ErrorAction.Companion.ACTION_MESSAGE_HIDE
import me.proxer.app.util.Utils
import me.proxer.app.util.compat.isConnected
import me.proxer.app.util.extension.resolveColor
import me.proxer.library.enums.Device
Expand Down Expand Up @@ -150,7 +151,7 @@ abstract class BaseContentFragment<T>(@LayoutRes contentLayoutId: Int) : BaseFra
true -> {
isSolvingCaptcha = true

showPage(ProxerUrls.captchaWeb(Device.MOBILE))
showPage(ProxerUrls.captchaWeb(Utils.getIpAddress(), Device.MOBILE))
}
false -> action.toClickListener(hostingActivity)?.onClick(errorButton) ?: viewModel.load()
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/me/proxer/app/util/ErrorUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ object ErrorUtils : KoinComponent {
}

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

fun toIntent() = when (buttonAction) {
CAPTCHA -> Intent(Intent.ACTION_VIEW, ProxerUrls.captchaWeb(Device.MOBILE).androidUri())
CAPTCHA -> Intent(
Intent.ACTION_VIEW,
ProxerUrls.captchaWeb(Utils.getIpAddress(), Device.MOBILE).androidUri()
)
else -> null
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/me/proxer/app/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import me.proxer.app.util.extension.androidUri
import okhttp3.HttpUrl
import org.threeten.bp.format.DateTimeFormatter
import timber.log.Timber
import java.net.NetworkInterface

/**
* @author Ruben Gees
Expand All @@ -32,6 +33,18 @@ object Utils {
null
}

fun getIpAddress(): String? = try {
NetworkInterface.getNetworkInterfaces().asSequence()
.flatMap { it.inetAddresses.asSequence() }
.filterNot { it.isLoopbackAddress || it.isLinkLocalAddress }
.map { it.hostAddress }
.firstOrNull()
} catch (error: Throwable) {
Timber.e("Error trying to get ip address", error)

null
}

fun getNativeAppPackage(context: Context, url: HttpUrl): Set<String> {
val browserActivityIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.generic.com"))
val genericResolvedList = extractPackageNames(
Expand Down

0 comments on commit aa21e0e

Please sign in to comment.