mirror of https://github.com/kurisufriend/Clover
Replaced all calls that required the old HttpClient with the equivalent OkHttp equivalent. All request are now made with the User-Agent Clover/version The captcha is now done through a WebView, loading up the code for recaptcha v2 with loadDataWithBaseURL see CaptchaLayout for details.captchafix2
parent
57db717afb
commit
899834f849
Binary file not shown.
@ -0,0 +1,41 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta name=viewport content="width=device-width, initial-scale=1"> |
||||||
|
<style type="text/css"> |
||||||
|
body.light { |
||||||
|
background: #ffffff; |
||||||
|
} |
||||||
|
|
||||||
|
body.dark { |
||||||
|
background: #000000; |
||||||
|
} |
||||||
|
|
||||||
|
#loadingCaptcha { |
||||||
|
font-family: sans-serif; |
||||||
|
font-size: 20px; |
||||||
|
} |
||||||
|
</style> |
||||||
|
<script src='https://www.google.com/recaptcha/api.js?onload=globalOnCaptchaLoaded&render=explicit'></script> |
||||||
|
</head> |
||||||
|
<body class="__theme__"> |
||||||
|
<div id="captcha-loading">Loading captcha...</div> |
||||||
|
<div id="captcha-container"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
window.globalOnCaptchaEntered = function(res) { |
||||||
|
CaptchaCallback.onCaptchaEntered(res); |
||||||
|
} |
||||||
|
|
||||||
|
window.globalOnCaptchaLoaded = function() { |
||||||
|
grecaptcha.render('captcha-container', { |
||||||
|
'sitekey': '__site_key__', |
||||||
|
'theme': '__theme__', |
||||||
|
'callback': globalOnCaptchaEntered |
||||||
|
}); |
||||||
|
CaptchaCallback.onCaptchaLoaded(); |
||||||
|
document.getElementById('captcha-loading').style.display = 'none'; |
||||||
|
} |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -1,28 +0,0 @@ |
|||||||
/* |
|
||||||
* Clover - 4chan browser https://github.com/Floens/Clover/
|
|
||||||
* Copyright (C) 2014 Floens |
|
||||||
* |
|
||||||
* This program is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, either version 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
package org.floens.chan.core.model; |
|
||||||
|
|
||||||
public class Pass { |
|
||||||
public String token = ""; |
|
||||||
public String pin = ""; |
|
||||||
|
|
||||||
public Pass(String token, String pin) { |
|
||||||
this.token = token; |
|
||||||
this.pin = pin; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,130 @@ |
|||||||
|
/* |
||||||
|
* Clover - 4chan browser https://github.com/Floens/Clover/
|
||||||
|
* Copyright (C) 2014 Floens |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
package org.floens.chan.ui.layout; |
||||||
|
|
||||||
|
import android.annotation.SuppressLint; |
||||||
|
import android.content.Context; |
||||||
|
import android.text.TextUtils; |
||||||
|
import android.util.AttributeSet; |
||||||
|
import android.webkit.JavascriptInterface; |
||||||
|
import android.webkit.WebSettings; |
||||||
|
import android.webkit.WebView; |
||||||
|
|
||||||
|
import org.floens.chan.ChanApplication; |
||||||
|
import org.floens.chan.utils.IOUtils; |
||||||
|
import org.floens.chan.utils.Utils; |
||||||
|
|
||||||
|
public class CaptchaLayout extends WebView { |
||||||
|
private CaptchaCallback callback; |
||||||
|
private boolean loaded = false; |
||||||
|
private String baseUrl; |
||||||
|
private String siteKey; |
||||||
|
private boolean lightTheme; |
||||||
|
|
||||||
|
public CaptchaLayout(Context context) { |
||||||
|
super(context); |
||||||
|
} |
||||||
|
|
||||||
|
public CaptchaLayout(Context context, AttributeSet attrs) { |
||||||
|
super(context, attrs); |
||||||
|
} |
||||||
|
|
||||||
|
public CaptchaLayout(Context context, AttributeSet attrs, int defStyle) { |
||||||
|
super(context, attrs, defStyle); |
||||||
|
} |
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled") |
||||||
|
public void initCaptcha(String baseUrl, String siteKey, boolean lightTheme, CaptchaCallback callback) { |
||||||
|
this.callback = callback; |
||||||
|
this.baseUrl = baseUrl; |
||||||
|
this.siteKey = siteKey; |
||||||
|
this.lightTheme = lightTheme; |
||||||
|
|
||||||
|
WebSettings settings = getSettings(); |
||||||
|
settings.setJavaScriptEnabled(true); |
||||||
|
settings.setUserAgentString(ChanApplication.getReplyManager().getUserAgent()); |
||||||
|
|
||||||
|
addJavascriptInterface(new CaptchaInterface(this), "CaptchaCallback"); |
||||||
|
} |
||||||
|
|
||||||
|
public void load() { |
||||||
|
if (!loaded) { |
||||||
|
loaded = true; |
||||||
|
|
||||||
|
String html = IOUtils.assetAsString(getContext(), "captcha/captcha.html"); |
||||||
|
html = html.replace("__site_key__", siteKey); |
||||||
|
html = html.replace("__theme__", lightTheme ? "light" : "dark"); |
||||||
|
|
||||||
|
loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void reset() { |
||||||
|
if (loaded) { |
||||||
|
loadUrl("javascript:grecaptcha.reset()"); |
||||||
|
} else { |
||||||
|
load(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void onCaptchaLoaded() { |
||||||
|
callback.captchaLoaded(this); |
||||||
|
} |
||||||
|
|
||||||
|
private void onCaptchaEntered(String response) { |
||||||
|
if (TextUtils.isEmpty(response)) { |
||||||
|
reset(); |
||||||
|
} else { |
||||||
|
callback.captchaEntered(this, response); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public interface CaptchaCallback { |
||||||
|
public void captchaLoaded(CaptchaLayout captchaLayout); |
||||||
|
|
||||||
|
public void captchaEntered(CaptchaLayout captchaLayout, String response); |
||||||
|
} |
||||||
|
|
||||||
|
public static class CaptchaInterface { |
||||||
|
private final CaptchaLayout layout; |
||||||
|
|
||||||
|
public CaptchaInterface(CaptchaLayout layout) { |
||||||
|
this.layout = layout; |
||||||
|
} |
||||||
|
|
||||||
|
@JavascriptInterface |
||||||
|
public void onCaptchaLoaded() { |
||||||
|
Utils.runOnUiThread(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
layout.onCaptchaLoaded(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@JavascriptInterface |
||||||
|
public void onCaptchaEntered(final String response) { |
||||||
|
Utils.runOnUiThread(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
layout.onCaptchaEntered(response); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,48 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?><!-- |
|
||||||
Clover - 4chan browser https://github.com/Floens/Clover/ |
|
||||||
Copyright (C) 2014 Floens |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||||
--> |
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:orientation="vertical" |
|
||||||
android:padding="16dp"> |
|
||||||
|
|
||||||
<TextView |
|
||||||
android:id="@+id/reply_captcha_text" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:paddingBottom="16dp" |
|
||||||
android:text="@string/reply_captcha_tap_to_reload" |
|
||||||
android:textSize="14sp" /> |
|
||||||
|
|
||||||
<org.floens.chan.ui.view.LoadView |
|
||||||
android:id="@+id/reply_captcha_container" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="100dp" |
|
||||||
android:layout_gravity="center" /> |
|
||||||
|
|
||||||
<EditText |
|
||||||
android:id="@+id/reply_captcha" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:hint="@string/reply_captcha" |
|
||||||
android:imeOptions="flagNoFullscreen" |
|
||||||
android:inputType="textNoSuggestions|textVisiblePassword" |
|
||||||
android:minHeight="40dp" |
|
||||||
android:textSize="14sp" /> |
|
||||||
|
|
||||||
</LinearLayout> |
|
Loading…
Reference in new issue