// For all support, instructions and copyright go to:
// http://e2guardian.org/
// Released under the GPL v2, with the OpenSSL exception described in the README file.
// INCLUDES
#ifdef HAVE_CONFIG_H
#include "e2config.h"
#endif
#include "../DownloadManager.hpp"
#include "../OptionContainer.hpp"
#include "../HTMLTemplate.hpp"
#include "../ConnectionHandler.hpp"
#include "../Logger.hpp"
#include
#include
#include
#include
#include
#include
#include
// GLOBALS
extern OptionContainer o;
// DECLARATIONS
class fancydm : public DMPlugin
{
public:
fancydm(ConfigVar &definition)
: DMPlugin(definition), upperlimit(0), toobig_unscanned(false), toobig_notdownloaded(false){};
int in(DataBuffer *d, Socket *sock, Socket *peersock, HTTPHeader *requestheader,
HTTPHeader *docheader, bool wantall, int *headersent, bool *toobig);
int init(void *args);
bool sendLink(Socket &peersock, String &linkurl, String &prettyurl);
private:
// customisable fancy DM template
HTMLTemplate progresspage;
// upper (non-scanned) file download size limit
// part of "multi-stage" downloads for when content length is unknown:
// - start downloading & hope for the best
// - if too large, warn the user, but keep downloading (won't be scanned)
// - if larger than upper limit also, kill download.
off_t upperlimit;
// was file too large to be scanned?
bool toobig_unscanned;
// was file so large as to not even be downloaded?
bool toobig_notdownloaded;
// format an integer in seconds as hours:minutes:seconds
std::string timestring(const int seconds);
// format a number of bytes as a number of Gb/Mb/Kb
String bytestring(const off_t bytes);
};
// IMPLEMENTATION
// class factory code *MUST* be included in every plugin
DMPlugin *fancydmcreate(ConfigVar &definition)
{
DEBUG_trace("Creating fancy DM");
return new fancydm(definition);
}
// end of Class factory
// initialisation - load the template file
int fancydm::init(void *args)
{
// call inherited init
DMPlugin::init(args);
StoryBoardOptions::SB_entry_map sen;
sen.entry_function = cv["story_function"];
if (sen.entry_function.length() > 0) {
sen.entry_id = ENT_STORYB_DM_FANCY;
story_entry = sen.entry_id;
o.story.dm_entry_dq.push_back(sen);
} else {
E2LOGGER_error("No story_function defined in fancy DM plugin config");
return -1;
}
// read in absolute max download limit
upperlimit = cv["maxdownloadsize"].toOffset() * 1024;
if (upperlimit <= o.content.max_content_filecache_scan_size)
upperlimit = 0;
DEBUG_dwload("Upper download limit: ", upperlimit);
String fname(cv["template"]);
if (fname.length() > 0) {
// read the template file, and return OK on success, error on failure.
fname = o.config.languagepath + fname;
return progresspage.readTemplateFile(fname.toCharArray(), "-FILENAME-|-FILESIZE-|-SERVERIP-") ? 0 : -1;
} else {
// eek! there's no template option in our config.
E2LOGGER_error("Template not specified for fancy download manager");
return -2;
}
}
// call template's downloadlink JavaScript function
bool fancydm::sendLink(Socket &peersock, String &linkurl, String &prettyurl)
{
String mess("\n");
peersock.writeString(mess.toCharArray());
// send text-only version for non-JS-enabled browsers
// 1220 "Scan complete.
Click here to download: "
// 1221 "Download complete; file not scanned.
Click here to download: "
// 1222 "File too large to cache.
Click here to re-download, bypassing virus scanning: "
mess = "";
peersock.writeString(mess.toCharArray());
peersock.writeString("\r\n");
if(!peersock.writeString("