Commit 5ec5f382 authored by Alexander Lohnau's avatar Alexander Lohnau
Browse files

Remove dead webinterface plugin

This has not been ported to KF5 and from a bugzilla
search one can assume that it is not dearly missed.
Consequently we should remove it.
parent 3f950530
......@@ -16,7 +16,6 @@ endif()
if (HAVE_Qt5WebEngineWidgets)
macro_kt_plugin(ENABLE_SEARCH_PLUGIN search search)
endif()
#macro_kt_plugin(ENABLE_WEBINTERFACE_PLUGIN webinterface webinterface)
macro_kt_plugin(ENABLE_SCANFOLDER_PLUGIN scanfolder scanfolder)
macro_kt_plugin(ENABLE_SCANFOLDER_PLUGIN scanforlostfiles scanforlostfiles)
if(HAVE_QT5_Test)
......
set(ktwebinterfaceplugin_SRC
httpresponseheader.cpp
httpclienthandler.cpp
httpserver.cpp
webinterfaceprefwidget.cpp
webinterfaceplugin.cpp
webcontentgenerator.cpp
globaldatagenerator.cpp
torrentlistgenerator.cpp
torrentfilesgenerator.cpp
challengegenerator.cpp
settingsgenerator.cpp
loginhandler.cpp
logouthandler.cpp
actionhandler.cpp
iconhandler.cpp
torrentposthandler.cpp)
ki18n_wrap_ui(ktwebinterfaceplugin_SRC webinterfaceprefwidget.ui)
kconfig_add_kcfg_files(ktwebinterfaceplugin_SRC webinterfacepluginsettings.kcfgc)
add_library(ktwebinterfaceplugin MODULE ${ktwebinterfaceplugin_SRC})
target_link_libraries(
ktwebinterfaceplugin
ktcore
${LIBKTORRENT_LIBRARIES}
)
install(TARGETS ktwebinterfaceplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES ktwebinterfaceplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
add_subdirectory(www)
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <QTimer>
#include <QXmlStreamWriter>
#include <KApplication>
#include "actionhandler.h"
#include "httpclienthandler.h"
#include "httpresponseheader.h"
#include "httpserver.h"
#include <dht/dhtbase.h>
#include <interfaces/coreinterface.h>
#include <interfaces/functions.h>
#include <interfaces/torrentfileinterface.h>
#include <interfaces/torrentinterface.h>
#include <net/socketmonitor.h>
#include <peer/peermanager.h>
#include <settings.h>
#include <torrent/choker.h>
#include <torrent/globals.h>
#include <torrent/queuemanager.h>
#include <torrent/server.h>
#include <tracker/udptrackersocket.h>
#include <util/log.h>
using namespace bt;
namespace kt
{
ActionHandler::ActionHandler(CoreInterface *core, HttpServer *server)
: WebContentGenerator(server, "/action", LOGIN_REQUIRED)
, core(core)
{
}
ActionHandler::~ActionHandler()
{
}
void ActionHandler::get(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr)
{
KUrl url;
url.setEncodedPathAndQuery(hdr.path());
bool ret = false;
const QMap<QString, QString> &params = url.queryItems();
for (QMap<QString, QString>::const_iterator it = params.begin(); it != params.end(); ++it) {
ret = doCommand(it.key(), it.value());
if (!ret)
break;
}
HttpResponseHeader rhdr(200);
server->setDefaultResponseHeaders(rhdr, "text/xml", true);
QByteArray output_data;
QXmlStreamWriter out(&output_data);
out.setAutoFormatting(true);
out.writeStartDocument();
out.writeStartElement("result");
out.writeCharacters(ret ? "OK" : "Failed");
out.writeEndElement();
out.writeEndDocument();
hdlr->send(rhdr, output_data);
}
bool ActionHandler::doCommand(const QString &cmd, const QString &arg)
{
if (cmd == "dht")
return dht(arg);
else if (cmd == " encryption")
return encryption(arg);
else if (cmd == "global_connection") {
Settings::setMaxTotalConnections(arg.toInt());
PeerManager::connectionLimits().setLimits(Settings::maxTotalConnections(), Settings::maxConnections());
return true;
} else if (cmd == "load_torrent" && arg.length() > 0) {
core->loadSilently(QUrl::fromPercentEncoding(arg.toLocal8Bit()), QString());
return true;
} else if (cmd == "maximum_downloads") {
int max = arg.toInt();
core->getQueueManager()->setMaxDownloads(max);
Settings::setMaxDownloads(max);
return true;
} else if (cmd == "maximum_seeds") {
core->getQueueManager()->setMaxSeeds(arg.toInt());
Settings::setMaxSeeds(arg.toInt());
return true;
} else if (cmd == "maximum_connection_per_torrent") {
PeerManager::connectionLimits().setLimits(Settings::maxTotalConnections(), arg.toInt());
Settings::setMaxConnections(arg.toInt());
return true;
} else if (cmd == "maximum_upload_rate") {
Settings::setMaxUploadRate(arg.toInt());
net::SocketMonitor::setUploadCap(Settings::maxUploadRate() * 1024);
return true;
} else if (cmd == "maximum_download_rate") {
Settings::setMaxDownloadRate(arg.toInt());
net::SocketMonitor::setDownloadCap(Settings::maxDownloadRate() * 1024);
return true;
} else if (cmd == "maximum_share_ratio") {
Settings::setMaxRatio(arg.toInt());
return true;
} else if (cmd == "number_of_upload_slots") {
Settings::setNumUploadSlots(arg.toInt());
Choker::setNumUploadSlots(Settings::numUploadSlots());
return true;
} else if (cmd == "port") {
Settings::setPort(arg.toInt());
core->changePort(Settings::port());
} else if (cmd == "port_udp_tracker") {
Settings::setUdpTrackerPort(arg.toInt());
UDPTrackerSocket::setPort(Settings::udpTrackerPort());
return true;
} else if (cmd == "remove") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (arg.toInt() == k) {
core->remove((*i), false);
return true;
}
}
} else if (cmd == "stopall" && !arg.isEmpty()) {
core->stopAll();
return true;
} else if (cmd == "startall" && !arg.isEmpty()) {
core->startAll();
return true;
} else if (cmd == "stop") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (arg.toInt() == k) {
core->stop(*i);
return true;
}
}
} else if (cmd == "start") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (arg.toInt() == k) {
core->start(*i);
return true;
}
}
} else if (cmd.startsWith(QLatin1String("file_"))) {
return file(cmd, arg);
} else if (cmd.startsWith(QLatin1String("shutdown"))) {
QTimer::singleShot(500, qApp, &QCoreApplication::quit);
return true;
}
return false;
}
void ActionHandler::post(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr, const QByteArray &data)
{
Q_UNUSED(data);
get(hdlr, hdr);
}
bool ActionHandler::dht(const QString &arg)
{
if (arg == "start") {
Settings::setDhtSupport(true);
} else {
Settings::setDhtSupport(false);
}
dht::DHTBase &ht = Globals::instance().getDHT();
if (Settings::dhtSupport() && !ht.isRunning()) {
ht.start(kt::DataDir() + "dht_table", kt::DataDir() + "dht_key", Settings::dhtPort());
return true;
} else if (!Settings::dhtSupport() && ht.isRunning()) {
ht.stop();
return true;
} else if (Settings::dhtSupport() && ht.getPort() != Settings::dhtPort()) {
ht.stop();
ht.start(kt::DataDir() + "dht_table", kt::DataDir() + "dht_key", Settings::dhtPort());
return true;
}
return false;
}
bool ActionHandler::encryption(const QString &arg)
{
if (arg == "start") {
Settings::setUseEncryption(true);
} else {
Settings::setUseEncryption(false);
}
if (Settings::useEncryption()) {
ServerInterface::enableEncryption(Settings::allowUnencryptedConnections());
} else {
ServerInterface::disableEncryption();
}
return true;
}
bool ActionHandler::file(const QString &cmd, const QString &arg)
{
QString torrent_num;
QString file_num;
// parse argument into torrent number and file number
int separator_loc = arg.indexOf('-');
QString parse = arg;
torrent_num.append(parse.left(separator_loc));
file_num.append(parse.right(parse.length() - (separator_loc + 1)));
if (cmd == "file_lp") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (torrent_num.toInt() == k) {
TorrentFileInterface &file = (*i)->getTorrentFile(file_num.toInt());
file.setPriority(LAST_PRIORITY);
return true;
}
}
} else if (cmd == "file_np") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (torrent_num.toInt() == k) {
TorrentFileInterface &file = (*i)->getTorrentFile(file_num.toInt());
file.setPriority(NORMAL_PRIORITY);
return true;
}
}
} else if (cmd == "file_hp") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (torrent_num.toInt() == k) {
TorrentFileInterface &file = (*i)->getTorrentFile(file_num.toInt());
file.setPriority(FIRST_PRIORITY);
return true;
}
}
} else if (cmd == "file_stop") {
QList<TorrentInterface *>::iterator i = core->getQueueManager()->begin();
for (int k = 0; i != core->getQueueManager()->end(); i++, k++) {
if (torrent_num.toInt() == k) {
TorrentFileInterface &file = (*i)->getTorrentFile(file_num.toInt());
file.setPriority(ONLY_SEED_PRIORITY);
return true;
}
}
}
return false;
}
}
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KTACTIONHANDLER_H
#define KTACTIONHANDLER_H
#include <webcontentgenerator.h>
namespace kt
{
/**
Handles actions coming from the client
*/
class ActionHandler : public WebContentGenerator
{
public:
ActionHandler(CoreInterface *core, HttpServer *server);
virtual ~ActionHandler();
virtual void get(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr);
virtual void post(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr, const QByteArray &data);
private:
bool doCommand(const QString &cmd, const QString &arg);
bool dht(const QString &arg);
bool encryption(const QString &arg);
bool file(const QString &cmd, const QString &arg);
private:
CoreInterface *core;
};
}
#endif
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <QXmlStreamWriter>
#include "challengegenerator.h"
#include "httpclienthandler.h"
#include "httpresponseheader.h"
#include "httpserver.h"
namespace kt
{
ChallengeGenerator::ChallengeGenerator(HttpServer *server)
: WebContentGenerator(server, "/login/challenge.xml", PUBLIC)
{
}
ChallengeGenerator::~ChallengeGenerator()
{
}
void ChallengeGenerator::get(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr)
{
Q_UNUSED(hdr);
HttpResponseHeader rhdr(200);
server->setDefaultResponseHeaders(rhdr, "text/xml", false);
QByteArray output_data;
QXmlStreamWriter out(&output_data);
out.setAutoFormatting(true);
out.writeStartDocument();
out.writeStartElement("challenge");
out.writeCharacters(server->challengeString());
out.writeEndElement();
out.writeEndDocument();
hdlr->send(rhdr, output_data);
}
void ChallengeGenerator::post(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr, const QByteArray &data)
{
Q_UNUSED(data);
get(hdlr, hdr);
}
}
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KTCHALLENGEGENERATOR_H
#define KTCHALLENGEGENERATOR_H
#include <webcontentgenerator.h>
namespace kt
{
/**
Generates XML containing the challenge field for login pages
*/
class ChallengeGenerator : public WebContentGenerator
{
public:
ChallengeGenerator(HttpServer *server);
virtual ~ChallengeGenerator();
virtual void get(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr);
virtual void post(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr, const QByteArray &data);
};
}
#endif
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <QXmlStreamWriter>
#include "globaldatagenerator.h"
#include "httpclienthandler.h"
#include "httpresponseheader.h"
#include "httpserver.h"
#include <interfaces/coreinterface.h>
#include <settings.h>
#include <util/functions.h>
#include <util/sha1hash.h>
using namespace bt;
namespace kt
{
GlobalDataGenerator::GlobalDataGenerator(CoreInterface *core, HttpServer *server)
: WebContentGenerator(server, "/data/global.xml", LOGIN_REQUIRED)
, core(core)
{
}
GlobalDataGenerator::~GlobalDataGenerator()
{
}
void GlobalDataGenerator::get(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr)
{
Q_UNUSED(hdr);
HttpResponseHeader rhdr(200);
server->setDefaultResponseHeaders(rhdr, "text/xml", true);
CurrentStats s = core->getStats();
QByteArray output_data;
QXmlStreamWriter out(&output_data);
out.setAutoFormatting(true);
out.writeStartDocument();
out.writeStartElement("global_data");
writeElement(out, "transferred_down", BytesToString(s.bytes_downloaded));
writeElement(out, "transferred_up", BytesToString(s.bytes_uploaded));
writeElement(out, "speed_down", BytesPerSecToString(s.download_speed));
writeElement(out, "speed_up", BytesPerSecToString(s.upload_speed));
writeElement(out, "dht", Settings::dhtSupport() ? "1" : "0");
writeElement(out, "encryption", Settings::useEncryption() ? "1" : "0");
out.writeEndElement();
out.writeEndDocument();
hdlr->send(rhdr, output_data);
}
void GlobalDataGenerator::post(HttpClientHandler *hdlr, const QHttpRequestHeader &hdr, const QByteArray &data)
{
Q_UNUSED(data);
get(hdlr, hdr);
}
void GlobalDataGenerator::writeElement(QXmlStreamWriter &out, const QString &name, const QString &value)
{
out.writeStartElement(name);
out.writeCharacters(value);
out.writeEndElement();
}
}
/***************************************************************************
* Copyright (C) 2008 by Joris Guisson and Ivan Vasic *
* joris.guisson@gmail.com *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KTGLOBALDATAGENERATOR_H
#define KTGLOBALDATAGENERATOR_H
#include "webcontentgenerator.h"
class QXmlStreamWriter;
namespace kt
{
class CoreInterface;
/**
Generates global data in an xml format, data contains stuff like current
speeds, the total amount data transferred ...
*/
class GlobalDataGenerator : public WebContentGenerator
{
public:
GlobalDataGenerator(CoreInterface *core, HttpServer *server);