From 566747efc333681e91c444d79044ee5a86870da7 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 31 Aug 2021 09:04:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20Handle=20Captcha=20Alone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + app/src/main/assets/captcha.json | 46 +++++++++++++++++++ .../java/com/mylloon/mobidl/MainActivity.kt | 15 +++++- .../main/java/com/mylloon/mobidl/Scraper.kt | 8 +++- app/src/main/res/values-fr-rFR/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 app/src/main/assets/captcha.json diff --git a/app/build.gradle b/app/build.gradle index e04b5c6..8f98460 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,4 +39,5 @@ dependencies { // implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.30' implementation 'com.github.kittinunf.fuel:fuel:2.3.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1' + implementation 'com.google.code.gson:gson:2.8.6' } \ No newline at end of file diff --git a/app/src/main/assets/captcha.json b/app/src/main/assets/captcha.json new file mode 100644 index 0000000..a2aa2de --- /dev/null +++ b/app/src/main/assets/captcha.json @@ -0,0 +1,46 @@ +{ + "Which of the following is not a musical instrument? Metronome, violin, banjo, drum.": "Metronome", + "Which of the following is not a cheese? Mozzarella, Cipollina, Brie.": "Cipollina", + "Which of the following cannot be found in the desert? Camel/Bear/Scorpion.": "Bear", + "Which of the following has ancient architecture? Boston, Jerusalem, Seattle.": "Jerusalem", + "Which of the following is not a planet? Mars, Jupiter, Your Mom.": "Your Mom", + "Which of the following is not known for great wine? France, Belgium, Italy.": "Belgium", + "Which of the following is not an ancient civilization? Germany, China, Greece.": "Germany", + "Which of the following is not a flower? Lotus, Rose, Maple.": "Maple", + "Which of the following is not in the US? Beijing, New York City, San Francisco.": "Beijing", + "Who of the following is not an author? Conan Doyle, Hercule Poirot, Agatha Christie.": "Hercule Poirot", + "Which of the following is not a type of meat? Mutton, Beef, Tofu.": "Tofu", + "Who of the following never drove a car? Isaac Newton, Angelina Jolie, The Terminator.": "Isaac Newton", + "Which of the following experiences cold weather? Miami, Moscow, Cairo.": "Moscow", + "Which of the following is not in Europe? Miami, Rome, Barcelona.": "Miami", + "Which of the following has nice beaches? Moscow, Helsinki, Miami.": "Miami", + "Which of the following experiences cold weather? Madagascar, Helsinki, Buenos Aires.": "Helsinki", + "Which of the following has a high alcoholic content? Whiskey, Beer, Wine.": "Whiskey", + "Which of the following is not a whale? Narwhal, Humpback, Your Mom.": "Your Mom", + "Which of the following is not a planet? Hermes, Mercury, Saturn.": "Hermes", + "Who of the following is not a composer? Chopin, Beethoven, Bach, Moriarty.": "Moriarty", + "Which of the following is not a European capital? Paris, Berlin, Washington.": "Washington", + "Who of the following probably never rode in a car? Churchill, Ramses II, Obama.": "Ramses II", + "Which of the following is not a European capital? Paris, Tokyo, Rome.": "Tokyo", + "Which country in Europe is historically neutral in conflicts? Portugal, Switzerland, Austria.": "Switzerland", + "Which of the following countries remained neutral in World War II? Russia, Switzerland, France.": "Switzerland", + "Which one of the following is not in Europe? Paris/London/Chicago.": "Chicago", + "Which of the following is not an ancient civilization? Persia, Parthia, Poland.": "Poland", + "Which of the following languages is most different from English? German, Arabic, Swedish.": "Arabic", + "Which of the following is not made from grapes? Wine, beer, champagne.": "beer", + "Which of the following is not a religion? Judaism, Christianity, Narcissism.": "Narcissism", + "Who of the following has not been prime minister of Great Britain? Merkel, Cameron, Thatcher.": "Merkel", + "Which of the following is not an ancient civilization? Egypt, Inca, Germany.": "Germany", + "Which of the following is an ancient civilization? Spain, Persia, Sweden.": "Persia", + "Which of the following is not an ancient civilization? France, China, Carthage.": "France", + "Which of the following is not a capital of a country? Barcelona, Kyiv, London.": "Barcelona", + "Who of the following never drove a car? Jesus, Bush, Austin Powers.": "Jesus", + "Which of the following is not a fish? Salmon, Shark, Dolphin.": "Shark", + "Which of the following is not a tree? Cranberry, Apple, Orange.": "Cranberry", + "Which of the following is not a cheese? Camembert, Cumberbatch, Brie.": "Cumberbatch", + "Who of the following is not a painter? Dali, Picasso, that cousin who went to art school, Rembrandt.": "that cousin who went to art school", + "Which of the following is not an ancient civilization? Maya, Sumeria, Portugal.": "Portugal", + "Which of the following is not a real animal? Comodo Dragon, Salamander, Unicorn.": "Unicorn", + "Which of the following is a dish? Hamburg, Violin, Sausage": "Sausage", + "Which of the following isn't a colonial power? Portugal, Spain, Switzerland." : "Switzerland" +} \ No newline at end of file diff --git a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt index 7f106a9..2cdf07f 100644 --- a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt +++ b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt @@ -22,6 +22,8 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import kotlinx.coroutines.runBlocking import java.util.* @@ -236,6 +238,15 @@ class MainActivity : AppCompatActivity() { if (returns != null) { // if job is needed if (returns[0] == "errorNotConnected") loginPage() if (returns[0] == "loginAttemptsExceeded") { + if (returns[1] == "null") callScrapper(user, password, app) + val registeredAnswered: Map = Gson().fromJson( + applicationContext.assets.open("captcha.json").bufferedReader() + .use { it.readText() }, + object : TypeToken>() {}.type + ) + for((key, value) in registeredAnswered){ + if (returns[1] == key) return@runBlocking callScrapper(user, password, app, returns[2], value) + } val builder: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder( instance) builder.setTitle("Captcha") @@ -245,8 +256,10 @@ class MainActivity : AppCompatActivity() { builder.setView(input) builder.setPositiveButton(R.string.validate) { _, _ -> callScrapper(user, password, app, returns[2], input.text.toString()) } builder.setNeutralButton(R.string.cancel) { dialog, _ -> dialog.cancel() } - builder.show() + + Toast.makeText(applicationContext(), "${getString(R.string.connectionFailed)}\n${getString(R.string.credentialsDeleted)}.", + Toast.LENGTH_LONG).show() } } } diff --git a/app/src/main/java/com/mylloon/mobidl/Scraper.kt b/app/src/main/java/com/mylloon/mobidl/Scraper.kt index d043671..b401a4c 100644 --- a/app/src/main/java/com/mylloon/mobidl/Scraper.kt +++ b/app/src/main/java/com/mylloon/mobidl/Scraper.kt @@ -66,9 +66,11 @@ class Scraper( private fun error(htmlPage: String): MutableList? { var message = "" var array: MutableList? = null + var lengthTime = Toast.LENGTH_LONG if (errorNotConnected in htmlPage) { if (loginAttemptsExceeded in htmlPage) { - message = applicationContext().getString(R.string.loginAttemptsExceeded) + message = "${applicationContext().getString(R.string.knownCaptcha)}..." + lengthTime = Toast.LENGTH_LONG val qaConfirmID = "(?<=qa_confirm_id\" value=\")(.{32})".toRegex().find(htmlPage)?.value var answer = "(?<=answer\">)(.*)? { if (debug) println("Fetching results for $app...") + Toast.makeText(applicationContext(), "Fetching results for $app...", Toast.LENGTH_SHORT) + .show() // println(htmlPage) return null } diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index d6cf2e5..4fee382 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -22,4 +22,5 @@ Vos identifiants ont été supprimées Vous avez dépassé le nombre maximum de tentatives de connexion, veuillez compléter les captchas Vous n\'êtes pas connecté, redirection vers la page de connexion + Résolution des captchas \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a98ecc0..bf560ac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,4 +29,5 @@ Login failed, change your credentials Your credentials have been deleted You have exceeded the maximum number of connection attempts, please complete captchas + Resolving captchas \ No newline at end of file