Skip to content

Commit

Permalink
Add node captcha in Allchan
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilhart authored and miku-nyan committed Jun 19, 2016
1 parent 5f928dc commit 3155351
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/nya/miku/wishmaster/chans/allchan/AllchanModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ public class AllchanModule extends CloudflareChanModule {
private static final String DOMAIN = "allchan.su";

private static final String[] CAPTCHA_TYPES = new String[] {
"Google Recaptcha 2", "Google Recaptcha 2 (fallback)", "Google Recaptcha" };
"Node captcha", "Google Recaptcha 2", "Google Recaptcha 2 (fallback)", "Google Recaptcha" };
private static final String[] CAPTCHA_TYPES_KEYS = new String[] {
"recaptcha", "recaptcha-fallback", "recaptchav1" };
private static final String CAPTCHA_TYPE_DEFAULT = "recaptchav1";
"node-captcha", "recaptcha", "recaptcha-fallback", "recaptchav1" };
private static final String CAPTCHA_TYPE_DEFAULT = "recaptcha";

private static final int CAPTCHA_RECAPTCHA = 1;
private static final int CAPTCHA_RECAPTCHA_FALLBACK = 2;
private static final int CAPTCHA_RECAPTCHA_V1 = 3;
private static final int CAPTCHA_NODE = 1;
private static final int CAPTCHA_RECAPTCHA = 2;
private static final int CAPTCHA_RECAPTCHA_FALLBACK = 3;
private static final int CAPTCHA_RECAPTCHA_V1 = 4;

private static final String RECAPTCHA_PUBLIC_KEY = "6LfKRgcTAAAAAIe-bmV_pCbMzvKvBZGbZNRsfmED";

Expand All @@ -100,6 +101,7 @@ public class AllchanModule extends CloudflareChanModule {
private HashMap<String, BoardModel> boardsMap;

private int captchaType;
private String nodeCaptchaKey;
private Recaptcha recaptchaV1;

public AllchanModule(SharedPreferences preferences, Resources resources) {
Expand Down Expand Up @@ -182,6 +184,8 @@ private int getUsingCaptchaType() {
String key = preferences.getString(getSharedKey(PREF_KEY_CAPTCHA_TYPE), CAPTCHA_TYPE_DEFAULT);
if (Arrays.asList(CAPTCHA_TYPES_KEYS).indexOf(key) == -1) key = CAPTCHA_TYPE_DEFAULT;
switch (key) {
case "node-captcha":
return CAPTCHA_NODE;
case "recaptcha":
return preferences.getBoolean(getSharedKey(PREF_KEY_USE_PROXY), false) ?
CAPTCHA_RECAPTCHA_FALLBACK :
Expand Down Expand Up @@ -472,13 +476,25 @@ public CaptchaModel getNewCaptcha(String boardName, String threadNumber, Progres
CaptchaModel captchaModel;
int captchaType = getUsingCaptchaType();
switch (captchaType) {
case CAPTCHA_NODE:
String url = getUsingUrl() + "api/nodeCaptchaImage.json";
JSONObject json = downloadJSONObject(url, false, listener, task);
String challenge = json.getString("challenge");
String captchaUrl = getUsingUrl() + "node-captcha/" + json.getString("fileName");
captchaModel = downloadCaptcha(captchaUrl, listener, task);
captchaModel.type = CaptchaModel.TYPE_NORMAL_DIGITS;
this.captchaType = captchaType;
this.nodeCaptchaKey = challenge;
return captchaModel;
case CAPTCHA_RECAPTCHA:
case CAPTCHA_RECAPTCHA_FALLBACK:
this.captchaType = captchaType;
this.nodeCaptchaKey = null;
this.recaptchaV1 = null;
return null;
case CAPTCHA_RECAPTCHA_V1:
this.captchaType = captchaType;
this.nodeCaptchaKey = null;
this.recaptchaV1 = Recaptcha.obtain(RECAPTCHA_PUBLIC_KEY, task, httpClient, useHttps() ? "https" : "http");
captchaModel = new CaptchaModel();
captchaModel.type = CaptchaModel.TYPE_NORMAL;
Expand All @@ -498,6 +514,9 @@ public String sendPost(SendPostModel model, ProgressListener listener, Cancellab
postEntityBuilder.addString("threadNumber", model.threadNumber);
}
switch (captchaType) {
case CAPTCHA_NODE:
postEntityBuilder.addString("nodeCaptchaChallenge", nodeCaptchaKey).addString("nodeCaptchaResponse", model.captchaAnswer);
break;
case CAPTCHA_RECAPTCHA:
case CAPTCHA_RECAPTCHA_FALLBACK:
postEntityBuilder.addString("captchaEngine", "google-recaptcha");
Expand Down

0 comments on commit 3155351

Please sign in to comment.