1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Implements uploadhere.com service

This commit is contained in:
2012-01-15 20:23:01 -02:00
parent 23f80b50e6
commit 1719e54b77
34 changed files with 790 additions and 429 deletions

View File

@@ -0,0 +1,36 @@
/**
*
*/
package com.rogiel.httpchannel.captcha.impl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.util.PatternUtils;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AjaxReCaptchaService extends BaseReCaptchaService {
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
.compile("Recaptcha\\.create\\(\"([0-9A-z|_|\\-]*)\", ");
private static final String BASE_URL = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
@Override
public ReCaptcha create(String content) throws MalformedURLException {
final String siteID = PatternUtils
.find(CAPTCHA_URL_PATTERN, content, 1);
try {
return super.create(get(BASE_URL + siteID).asString());
} catch (IOException e) {
return null;
}
}
@Override
public boolean resolve(ReCaptcha captcha) {
// not supported!
return false;
}
}

View File

@@ -0,0 +1,34 @@
/**
*
*/
package com.rogiel.httpchannel.captcha.impl;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.AbstractImageCaptchaService;
import com.rogiel.httpchannel.util.PatternUtils;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseReCaptchaService extends
AbstractImageCaptchaService<ReCaptcha> {
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
.compile("challenge : '(.*)'");
private static final String BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
@Override
public ReCaptcha create(String content) throws MalformedURLException {
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, content, 1);
return new ReCaptcha(new URL(BASE_URL + id), id);
}
@Override
public boolean resolve(ReCaptcha captcha) {
// not supported!
return false;
}
}

View File

@@ -0,0 +1,41 @@
/**
*
*/
package com.rogiel.httpchannel.captcha.impl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class EmbeddedReCaptchaService extends BaseReCaptchaService {
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
@Override
public ReCaptcha create(String content) throws MalformedURLException {
try {
return create(HTMLPage.parse(content));
} catch (IOException e) {
return null;
}
}
public ReCaptcha create(HTMLPage page) throws IOException {
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
if (url == null)
return null;
return super.create(get(url).asString());
}
@Override
public boolean resolve(ReCaptcha captcha) {
// not supported!
return false;
}
}

View File

@@ -1,44 +0,0 @@
/**
*
*/
package com.rogiel.httpchannel.captcha.impl;
import java.io.IOException;
import java.net.URL;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.AbstractImageCaptchaService;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class ReCaptchaService extends AbstractImageCaptchaService<ReCaptcha> {
// http://www.google.com/recaptcha/api/noscript?k=6LdRTL8SAAAAAE9UOdWZ4d0Ky-aeA7XfSqyWDM2m
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
.compile("challenge : '(.*)'");
private static final String BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
@Override
public ReCaptcha create(HTMLPage page) throws IOException {
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
if (url == null)
return null;
final String captchaPage = get(url).asString();
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, captchaPage,
1);
return new ReCaptcha(new URL(BASE_URL + id), id);
}
@Override
public boolean resolve(ReCaptcha captcha) {
// not supported!
return false;
}
}

View File

@@ -0,0 +1,25 @@
/**
*
*/
package com.rogiel.httpchannel.captcha.impl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class AjaxReCaptchaServiceTest {
@Test
public void test() throws MalformedURLException, IOException {
final String content = IOUtils.toString(new URL(
"http://www.uploadking.com/WM3PHD9JAY").openStream());
final AjaxReCaptchaService ajax = new AjaxReCaptchaService();
ajax.create(content);
}
}

View File

@@ -1,16 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-capcha</artifactId>
<name>HttpChannel/CaptchaService</name>
<description>This module provides implementations for captcha resolving</description>
<packaging>pom</packaging>
<modules>
<module>httpchannel-captcha-recaptcha</module>
</modules>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-capcha</artifactId>
<packaging>pom</packaging>
<name>HttpChannel/CaptchaService</name>
<description>This module provides implementations for captcha resolving</description>
<modules>
<module>httpchannel-captcha-recaptcha</module>
</modules>
</project>