ShareBaseTo: added filecheckapi, accountcheck api and changed premium download

mod_ipcheck.c: ipcheck modul for lighttpd

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@8960 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
jiaz 2009-10-08 15:22:38 +00:00
parent 8bb68d3e7a
commit b081ac6475
2 changed files with 224 additions and 38 deletions

View File

@ -18,10 +18,8 @@ package jd.plugins.hoster;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.regex.Pattern;
import jd.PluginWrapper;
import jd.nutils.JDHash;
import jd.nutils.encoding.Encoding;
import jd.parser.Regex;
import jd.parser.html.Form;
@ -35,7 +33,7 @@ import jd.plugins.PluginForHost;
import jd.plugins.DownloadLink.AvailableStatus;
import jd.utils.locale.JDL;
@HostPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "sharebase.to" }, urls = { "http://[\\w\\.]*?sharebase\\.(de|to)/files/[\\w]+\\.html" }, flags = { 2 })
@HostPlugin(revision = "$Revision$", interfaceVersion = 2, names = { "sharebase.to" }, urls = { "http://[\\w\\.]*?sharebase\\.(de|to)/(files/|1,)[\\w]+\\.html" }, flags = { 2 })
public class ShareBaseTo extends PluginForHost {
public ShareBaseTo(PluginWrapper wrapper) {
@ -50,32 +48,28 @@ public class ShareBaseTo extends PluginForHost {
@Override
public void correctDownloadLink(DownloadLink link) throws MalformedURLException {
/* damit neue links mit .de als .to in die liste kommen */
link.setUrlDownload(link.getDownloadURL().replaceAll("sharebase\\.de", "sharebase\\.to"));
}
@Override
public AvailableStatus requestFileInformation(DownloadLink downloadLink) throws IOException, PluginException {
/* damit neue links mit .de als .to in die liste kommen */
setBrowserExclusive();
br.getPage(downloadLink.getDownloadURL());
if (br.containsHTML("Der Download existiert nicht")) { throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); }
if (br.containsHTML("Der erforderliche Download-Server ist derzeit nicht verf.*bar")) { throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE); }
String downloadName = br.getRegex("<title>(.*) @ ShareBase\\.to</title><meta").getMatch(0);
String downloadSize = br.getRegex("</span>\\((.*?)\\)</td>").getMatch(0);
if (downloadName == null || downloadSize == null) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
downloadLink.setName(downloadName.trim());
downloadLink.setDownloadSize(Regex.getSize(downloadSize.trim()));
br.getPage("http://sharebase.to/apito/jd.php?f=" + downloadLink.getDownloadURL());
String[] info = Regex.getLines(br.toString());
if (info.length != 3 || info[0].matches("NONE")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
downloadLink.setFinalFileName(info[0]);
downloadLink.setDownloadSize(Regex.getSize(info[1]));
if (info[2].matches("OFFLINE")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
if (!info[2].matches("ONLINE")) throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE);
return AvailableStatus.TRUE;
}
public void login(Account account) throws IOException, PluginException {
setBrowserExclusive();
br.setCookie("http://" + getHost(), "memm", Encoding.urlEncode(account.getUser()));
br.setCookie("http://" + getHost(), "memp", JDHash.getMD5(account.getPass()));
br.getPage("http://sharebase.to/members/");
String points = br.getRegex(Pattern.compile("<td>Premiumpunkte:</td>.*?<td><input.*cleanform.*value=\"([\\d\\.]+) Punkte\"></td>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)).getMatch(0);
String expire = br.getRegex(Pattern.compile("<td>Premium bis:</td>.*?<td><input.*?cleanform.*? value=\"(.*?)\"></td>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)).getMatch(0);
if (points == null || expire == null) throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
br.getPage("http://sharebase.to/apito/jd.php?u=" + Encoding.urlEncode(account.getUser()) + "&p=" + Encoding.urlEncode(account.getPass()));
String[] info = Regex.getLines(br.toString());
if (info.length != 3 || info[0].matches("FALSE") || !info[0].matches("PREMIUM")) throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
}
@Override
@ -87,10 +81,9 @@ public class ShareBaseTo extends PluginForHost {
account.setValid(false);
return ai;
}
String points = br.getRegex(Pattern.compile("<td>Premiumpunkte:</td>.*?<td><input.*cleanform.*value=\"([\\d\\.]+) Punkte\"></td>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)).getMatch(0);
String expire = br.getRegex(Pattern.compile("<td>Premium bis:</td>.*?<td><input.*?cleanform.*? value=\"(.*?)\"></td>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)).getMatch(0);
ai.setValidUntil(Regex.getMilliSeconds(expire, "dd.MM.yy / hh:mm", null));
ai.setPremiumPoints(Long.parseLong(points.replaceAll("\\.", "")));
String[] info = Regex.getLines(br.toString());
ai.setValidUntil(Long.parseLong(info[1]) * 1000l);
ai.setPremiumPoints(Long.parseLong(info[2]));
return ai;
}
@ -98,23 +91,23 @@ public class ShareBaseTo extends PluginForHost {
public void handlePremium(DownloadLink downloadLink, Account account) throws Exception {
requestFileInformation(downloadLink);
login(account);
br.getPage(downloadLink.getDownloadURL());
if (br.containsHTML("werden derzeit Wartungsarbeiten vorgenommen")) {
logger.severe("ShareBaseTo Error: Maintenance");
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, JDL.L("plugins.hoster.sharebaseto.errors.maintenance", "Maintenance works in progress"), 30 * 60 * 1000l);
String id = new Regex(downloadLink.getDownloadURL(), "/files/([\\w]+\\.html)").getMatch(0);
if (id != null) {
br.getPage("http://sharebase.to/files/" + id + "," + Encoding.urlEncode(account.getUser() + "," + Encoding.urlEncode(account.getPass())));
} else {
id = new Regex(downloadLink.getDownloadURL(), "/1,([\\w]+\\.html)").getMatch(0);
if (id == null) throw new PluginException(LinkStatus.ERROR_FATAL);
br.getPage("http://sharebase.to/1," + id + "," + Encoding.urlEncode(account.getUser() + "," + Encoding.urlEncode(account.getPass())));
}
if (!br.containsHTML("favorite")) {
logger.severe("ShareBaseTo Error: Premium account expired");
String dlUrl = br.getRedirectLocation();
if (dlUrl == null) throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dlUrl, true, 0);
br.setFollowRedirects(true);
if (dl.getConnection() == null || dl.getConnection().getContentType().contains("html")) {
br.followConnection();
logger.severe("PremiumError: " + br.toString());
throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
}
dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, br.getForm(1));
if (dl.getConnection() == null) {
logger.severe("ServerError");
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, JDL.L("plugins.hoster.sharebaseto.errors.servicenotavailable", "Service not available"), 10 * 60 * 1000l);
}
dl.startDownload();
}
@ -169,8 +162,6 @@ public class ShareBaseTo extends PluginForHost {
@Override
public void resetDownloadlink(DownloadLink link) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,195 @@
#define _GNU_SOURCE
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <stdio.h>
#include "server.h"
#include "connections.h"
#include "response.h"
#include "connections.h"
#include "log.h"
#include "plugin.h"
#include "inet_ntop_cache.h"
#include "version.h"
/*
* IPCheck Modul for lighttpd ,Copyright (C) 2009 by Jiaz (jiaz@jdownloader.org)
* INTSTALL:
* 1.) copy to src folder
* 2.) add
lib_LTLIBRARIES += mod_ipcheck.la
mod_ipcheck_la_SOURCES = mod_ipcheck.c
mod_ipcheck_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
mod_ipcheck_la_LIBADD = $(common_libadd)
* to Makefile.am
*
* 3.)autoreconf -fi and ./configure ...
*
*/
typedef struct {
buffer *ipcheck_url;
} plugin_config;
typedef struct {
PLUGIN_DATA;
buffer *module_list;
plugin_config **config_storage;
plugin_config conf;
} plugin_data;
INIT_FUNC(mod_ipcheck_init) {
plugin_data *p;
p = calloc(1, sizeof(*p));
p->module_list = buffer_init();
return p;
}
FREE_FUNC(mod_ipcheck_free) {
plugin_data *p = p_d;
UNUSED(srv);
if (!p) return HANDLER_GO_ON;
buffer_free(p->module_list);
if (p->config_storage) {
size_t i;
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s = p->config_storage[i];
buffer_free(s->ipcheck_url);
free(s);
}
free(p->config_storage);
}
free(p);
return HANDLER_GO_ON;
}
SETDEFAULTS_FUNC(mod_ipcheck_set_defaults) {
plugin_data *p = p_d;
size_t i;
config_values_t cv[] = {
{ "ipcheck.ipcheck-url", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION},
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET}
};
if (!p) return HANDLER_ERROR;
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s;
s = calloc(1, sizeof(plugin_config));
s->ipcheck_url = buffer_init();
cv[0].destination = s->ipcheck_url;
p->config_storage[i] = s;
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
return HANDLER_ERROR;
}
}
return HANDLER_GO_ON;
}
static handler_t mod_ipcheck_handle_server_status(server *srv, connection *con,
void *p_d) {
plugin_data *p = p_d;
buffer *b = p->module_list;
b = chunkqueue_get_append_buffer(con->write_queue);
buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
con->http_status = 200;
con->file_finished = 1;
return HANDLER_FINISHED;
}
#define PATCH(x) \
p->conf.x = s->x;
static int mod_ipcheck_patch_connection(server *srv, connection *con,
plugin_data *p) {
size_t i, j;
plugin_config *s = p->config_storage[0];
PATCH(ipcheck_url);
/* skip the first, the global context */
for (i = 1; i < srv->config_context->used; i++) {
data_config *dc = (data_config *) srv->config_context->data[i];
s = p->config_storage[i];
/* condition didn't match */
if (!config_check_cond(srv, con, dc))
continue;
/* merge config */
for (j = 0; j < dc->value->used; j++) {
data_unset *du = dc->value->data[j];
if (buffer_is_equal_string(du->key, CONST_STR_LEN(
"ipcheck.ipcheck-url"))) {
PATCH(ipcheck_url);
}
}
}
return 0;
}
static handler_t mod_ipcheck_handler(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
if (con->mode != DIRECT)
return HANDLER_GO_ON;
mod_ipcheck_patch_connection(srv, con, p);
if (!buffer_is_empty(p->conf.ipcheck_url) && buffer_is_equal(
p->conf.ipcheck_url, con->uri.path)) {
return mod_ipcheck_handle_server_status(srv, con, p_d);
}
return HANDLER_GO_ON;
}
int mod_ipcheck_plugin_init(plugin *p);
int mod_ipcheck_plugin_init(plugin *p) {
p->version = LIGHTTPD_VERSION_ID;
p->name = buffer_init_string("ipcheck");
p->init = mod_ipcheck_init;
p->cleanup = mod_ipcheck_free;
p->set_defaults = mod_ipcheck_set_defaults;
p->handle_uri_clean = mod_ipcheck_handler;
p->data = NULL;
return 0;
}