mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Implements zshare.net and filesonic.com services
This commit is contained in:
24
httpchannel-captcha/httpchannel-captcha-recaptcha/pom.xml
Normal file
24
httpchannel-captcha/httpchannel-captcha-recaptcha/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<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-capcha</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-captcha-recaptcha</artifactId>
|
||||
<name>HttpChannel/CaptchaService/ReCaptcha</name>
|
||||
<description>This module provides captcha resolving for Google ReCaptcha</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.AbstractImageCaptcha;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ReCaptcha extends AbstractImageCaptcha {
|
||||
public ReCaptcha(URL url, String ID) {
|
||||
super(url, ID);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
19
httpchannel-captcha/pom.xml
Normal file
19
httpchannel-captcha/pom.xml
Normal file
@@ -0,0 +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-captcha</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>
|
||||
Reference in New Issue
Block a user