mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Added magnet URI support to Web UI
This commit is contained in:
parent
462f6c41cd
commit
25d998f1b5
@ -1445,6 +1445,10 @@ void bittorrent::downloadFromUrl(QString url) {
|
|||||||
downloader->downloadUrl(url);
|
downloader->downloadUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bittorrent::addMagnetSkipAddDlg(QString uri) {
|
||||||
|
addMagnetUri(uri, false);
|
||||||
|
}
|
||||||
|
|
||||||
void bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
void bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
||||||
//emit aboutToDownloadFromUrl(url);
|
//emit aboutToDownloadFromUrl(url);
|
||||||
if(!save_path.isEmpty())
|
if(!save_path.isEmpty())
|
||||||
|
@ -167,6 +167,7 @@ class bittorrent : public QObject {
|
|||||||
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
||||||
void processDownloadedFile(QString, QString);
|
void processDownloadedFile(QString, QString);
|
||||||
void saveTrackerFile(QString hash);
|
void saveTrackerFile(QString hash);
|
||||||
|
void addMagnetSkipAddDlg(QString uri);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void scanDirectory(QString);
|
void scanDirectory(QString);
|
||||||
|
@ -43,11 +43,11 @@
|
|||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent)
|
HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent)
|
||||||
: QObject(parent), socket(socket), parent(parent)
|
: QObject(parent), socket(socket), parent(parent)
|
||||||
{
|
{
|
||||||
socket->setParent(this);
|
socket->setParent(this);
|
||||||
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
|
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
|
||||||
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpConnection::~HttpConnection()
|
HttpConnection::~HttpConnection()
|
||||||
@ -57,7 +57,7 @@ HttpConnection::~HttpConnection()
|
|||||||
|
|
||||||
void HttpConnection::processDownloadedFile(QString url, QString file_path) {
|
void HttpConnection::processDownloadedFile(QString url, QString file_path) {
|
||||||
qDebug("URL %s successfully downloaded !", (const char*)url.toLocal8Bit());
|
qDebug("URL %s successfully downloaded !", (const char*)url.toLocal8Bit());
|
||||||
emit torrentReadyToBeDownloaded(file_path, false, url, false);
|
emit torrentReadyToBeDownloaded(file_path, false, url, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::handleDownloadFailure(QString url, QString reason) {
|
void HttpConnection::handleDownloadFailure(QString url, QString reason) {
|
||||||
@ -66,182 +66,186 @@ void HttpConnection::handleDownloadFailure(QString url, QString reason) {
|
|||||||
|
|
||||||
void HttpConnection::read()
|
void HttpConnection::read()
|
||||||
{
|
{
|
||||||
QByteArray input = socket->readAll();
|
QByteArray input = socket->readAll();
|
||||||
/*qDebug(" -------");
|
/*qDebug(" -------");
|
||||||
qDebug("|REQUEST|");
|
qDebug("|REQUEST|");
|
||||||
qDebug(" -------"); */
|
qDebug(" -------"); */
|
||||||
//qDebug("%s", input.toAscii().constData());
|
//qDebug("%s", input.toAscii().constData());
|
||||||
if(input.size() > 100000) {
|
if(input.size() > 100000) {
|
||||||
qDebug("Request too big");
|
qDebug("Request too big");
|
||||||
generator.setStatusLine(400, "Bad Request");
|
generator.setStatusLine(400, "Bad Request");
|
||||||
write();
|
write();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parser.write(input);
|
parser.write(input);
|
||||||
if(parser.isError())
|
if(parser.isError())
|
||||||
{
|
{
|
||||||
generator.setStatusLine(400, "Bad Request");
|
generator.setStatusLine(400, "Bad Request");
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (parser.isParsable())
|
if (parser.isParsable())
|
||||||
respond();
|
respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::write()
|
void HttpConnection::write()
|
||||||
{
|
{
|
||||||
QByteArray output = generator.toByteArray();
|
QByteArray output = generator.toByteArray();
|
||||||
/*qDebug(" --------");
|
/*qDebug(" --------");
|
||||||
qDebug("|RESPONSE|");
|
qDebug("|RESPONSE|");
|
||||||
qDebug(" --------");
|
qDebug(" --------");
|
||||||
qDebug()<<output;*/
|
qDebug()<<output;*/
|
||||||
socket->write(output);
|
socket->write(output);
|
||||||
socket->disconnectFromHost();
|
socket->disconnectFromHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::respond()
|
void HttpConnection::respond()
|
||||||
{
|
{
|
||||||
//qDebug("Respond called");
|
//qDebug("Respond called");
|
||||||
QStringList auth = parser.value("Authorization").split(" ", QString::SkipEmptyParts);
|
QStringList auth = parser.value("Authorization").split(" ", QString::SkipEmptyParts);
|
||||||
if (auth.size() != 2 || QString::compare(auth[0], "Basic", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth[1].toLocal8Bit()))
|
if (auth.size() != 2 || QString::compare(auth[0], "Basic", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth[1].toLocal8Bit()))
|
||||||
{
|
{
|
||||||
generator.setStatusLine(401, "Unauthorized");
|
generator.setStatusLine(401, "Unauthorized");
|
||||||
generator.setValue("WWW-Authenticate", "Basic realm=\"you know what\"");
|
generator.setValue("WWW-Authenticate", "Basic realm=\"you know what\"");
|
||||||
write();
|
write();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString url = parser.url();
|
QString url = parser.url();
|
||||||
QStringList list = url.split('/', QString::SkipEmptyParts);
|
QStringList list = url.split('/', QString::SkipEmptyParts);
|
||||||
if (list.contains(".") || list.contains(".."))
|
if (list.contains(".") || list.contains(".."))
|
||||||
{
|
{
|
||||||
respondNotFound();
|
respondNotFound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (list.size() == 0)
|
if (list.size() == 0)
|
||||||
list.append("index.html");
|
list.append("index.html");
|
||||||
if (list.size() == 2)
|
if (list.size() == 2)
|
||||||
{
|
{
|
||||||
if (list[0] == "json")
|
if (list[0] == "json")
|
||||||
{
|
{
|
||||||
if (list[1] == "events")
|
if (list[1] == "events")
|
||||||
{
|
{
|
||||||
respondJson();
|
respondJson();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list[0] == "command")
|
if (list[0] == "command")
|
||||||
{
|
{
|
||||||
QString command = list[1];
|
QString command = list[1];
|
||||||
respondCommand(command);
|
respondCommand(command);
|
||||||
generator.setStatusLine(200, "OK");
|
generator.setStatusLine(200, "OK");
|
||||||
write();
|
write();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list[0] == "images")
|
if (list[0] == "images")
|
||||||
list[0] = "Icons";
|
list[0] = "Icons";
|
||||||
else
|
else
|
||||||
list.prepend("webui");
|
list.prepend("webui");
|
||||||
url = ":/" + list.join("/");
|
url = ":/" + list.join("/");
|
||||||
QFile file(url);
|
QFile file(url);
|
||||||
if(!file.open(QIODevice::ReadOnly))
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
respondNotFound();
|
respondNotFound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString ext = list.last();
|
QString ext = list.last();
|
||||||
int index = ext.lastIndexOf('.') + 1;
|
int index = ext.lastIndexOf('.') + 1;
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
ext.remove(0, index);
|
ext.remove(0, index);
|
||||||
else
|
else
|
||||||
ext.clear();
|
ext.clear();
|
||||||
QByteArray data = file.readAll();
|
QByteArray data = file.readAll();
|
||||||
generator.setStatusLine(200, "OK");
|
generator.setStatusLine(200, "OK");
|
||||||
generator.setContentTypeByExt(ext);
|
generator.setContentTypeByExt(ext);
|
||||||
generator.setMessage(data);
|
generator.setMessage(data);
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::respondNotFound()
|
void HttpConnection::respondNotFound()
|
||||||
{
|
{
|
||||||
generator.setStatusLine(404, "File not found");
|
generator.setStatusLine(404, "File not found");
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::respondJson()
|
void HttpConnection::respondJson()
|
||||||
{
|
{
|
||||||
EventManager* manager = parent->eventManager();
|
EventManager* manager = parent->eventManager();
|
||||||
QString string = json::toJson(manager->getEventList());
|
QString string = json::toJson(manager->getEventList());
|
||||||
generator.setStatusLine(200, "OK");
|
generator.setStatusLine(200, "OK");
|
||||||
generator.setContentTypeByExt("js");
|
generator.setContentTypeByExt("js");
|
||||||
generator.setMessage(string);
|
generator.setMessage(string);
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::respondCommand(QString command)
|
void HttpConnection::respondCommand(QString command)
|
||||||
{
|
{
|
||||||
if(command == "download")
|
if(command == "download")
|
||||||
{
|
{
|
||||||
QString urls = parser.post("urls");
|
QString urls = parser.post("urls");
|
||||||
QStringList list = urls.split('\n');
|
QStringList list = urls.split('\n');
|
||||||
foreach(QString url, list){
|
foreach(QString url, list){
|
||||||
url = url.trimmed();
|
url = url.trimmed();
|
||||||
if(!url.isEmpty()){
|
if(!url.isEmpty()){
|
||||||
qDebug("Downloading url: %s", (const char*)url.toLocal8Bit());
|
if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||||||
emit UrlReadyToBeDownloaded(url);
|
emit MagnetReadyToBeDownloaded(url);
|
||||||
}
|
} else {
|
||||||
}
|
qDebug("Downloading url: %s", (const char*)url.toLocal8Bit());
|
||||||
return;
|
emit UrlReadyToBeDownloaded(url);
|
||||||
}
|
|
||||||
if(command == "upload")
|
|
||||||
{
|
|
||||||
QByteArray torrentfile = parser.torrent();
|
|
||||||
// XXX: Trick to get a unique filename
|
|
||||||
QString filePath;
|
|
||||||
QTemporaryFile *tmpfile = new QTemporaryFile();
|
|
||||||
if (tmpfile->open()) {
|
|
||||||
filePath = tmpfile->fileName();
|
|
||||||
}
|
|
||||||
delete tmpfile;
|
|
||||||
// write it to HD
|
|
||||||
QFile torrent(filePath);
|
|
||||||
if(torrent.open(QIODevice::WriteOnly)) {
|
|
||||||
torrent.write(torrentfile);
|
|
||||||
torrent.close();
|
|
||||||
}
|
|
||||||
emit torrentReadyToBeDownloaded(filePath, false, QString(), false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "resumeall") {
|
|
||||||
emit resumeAllTorrents();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "pauseall") {
|
|
||||||
emit pauseAllTorrents();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "resume") {
|
|
||||||
emit resumeTorrent(parser.post("hash"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "pause") {
|
|
||||||
emit pauseTorrent(parser.post("hash"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "delete") {
|
|
||||||
emit deleteTorrent(parser.post("hash"), false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "deletePerm") {
|
|
||||||
emit deleteTorrent(parser.post("hash"), true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "increasePrio") {
|
|
||||||
emit increasePrioTorrent(parser.post("hash"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(command == "decreasePrio") {
|
|
||||||
emit decreasePrioTorrent(parser.post("hash"));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "upload")
|
||||||
|
{
|
||||||
|
QByteArray torrentfile = parser.torrent();
|
||||||
|
// XXX: Trick to get a unique filename
|
||||||
|
QString filePath;
|
||||||
|
QTemporaryFile *tmpfile = new QTemporaryFile();
|
||||||
|
if (tmpfile->open()) {
|
||||||
|
filePath = tmpfile->fileName();
|
||||||
|
}
|
||||||
|
delete tmpfile;
|
||||||
|
// write it to HD
|
||||||
|
QFile torrent(filePath);
|
||||||
|
if(torrent.open(QIODevice::WriteOnly)) {
|
||||||
|
torrent.write(torrentfile);
|
||||||
|
torrent.close();
|
||||||
|
}
|
||||||
|
emit torrentReadyToBeDownloaded(filePath, false, QString(), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "resumeall") {
|
||||||
|
emit resumeAllTorrents();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "pauseall") {
|
||||||
|
emit pauseAllTorrents();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "resume") {
|
||||||
|
emit resumeTorrent(parser.post("hash"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "pause") {
|
||||||
|
emit pauseTorrent(parser.post("hash"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "delete") {
|
||||||
|
emit deleteTorrent(parser.post("hash"), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "deletePerm") {
|
||||||
|
emit deleteTorrent(parser.post("hash"), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "increasePrio") {
|
||||||
|
emit increasePrioTorrent(parser.post("hash"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(command == "decreasePrio") {
|
||||||
|
emit decreasePrioTorrent(parser.post("hash"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ class HttpConnection : public QObject
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void UrlReadyToBeDownloaded(QString url);
|
void UrlReadyToBeDownloaded(QString url);
|
||||||
|
void MagnetReadyToBeDownloaded(QString uri);
|
||||||
void torrentReadyToBeDownloaded(QString, bool, QString, bool);
|
void torrentReadyToBeDownloaded(QString, bool, QString, bool);
|
||||||
void deleteTorrent(QString hash, bool permanently);
|
void deleteTorrent(QString hash, bool permanently);
|
||||||
void resumeTorrent(QString hash);
|
void resumeTorrent(QString hash);
|
||||||
|
@ -72,6 +72,7 @@ void HttpServer::newHttpConnection()
|
|||||||
HttpConnection *connection = new HttpConnection(socket, this);
|
HttpConnection *connection = new HttpConnection(socket, this);
|
||||||
//connect connection to BTSession
|
//connect connection to BTSession
|
||||||
connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), BTSession, SLOT(downloadUrlAndSkipDialog(QString)));
|
connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), BTSession, SLOT(downloadUrlAndSkipDialog(QString)));
|
||||||
|
connect(connection, SIGNAL(MagnetReadyToBeDownloaded(QString)), BTSession, SLOT(addMagnetSkipAddDlg(QString)));
|
||||||
connect(connection, SIGNAL(torrentReadyToBeDownloaded(QString, bool, QString, bool)), BTSession, SLOT(addTorrent(QString, bool, QString, bool)));
|
connect(connection, SIGNAL(torrentReadyToBeDownloaded(QString, bool, QString, bool)), BTSession, SLOT(addTorrent(QString, bool, QString, bool)));
|
||||||
connect(connection, SIGNAL(deleteTorrent(QString, bool)), BTSession, SLOT(deleteTorrent(QString, bool)));
|
connect(connection, SIGNAL(deleteTorrent(QString, bool)), BTSession, SLOT(deleteTorrent(QString, bool)));
|
||||||
connect(connection, SIGNAL(pauseTorrent(QString)), BTSession, SLOT(pauseTorrent(QString)));
|
connect(connection, SIGNAL(pauseTorrent(QString)), BTSession, SLOT(pauseTorrent(QString)));
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<center>
|
<center>
|
||||||
<h1 class="vcenter"><img class="vcenter" title="Download from URL" src="images/skin/url.png"/>Download Torrents from URLs</h1>
|
<h1 class="vcenter"><img class="vcenter" title="Download from URL" src="images/skin/url.png"/>Download Torrents from their URL or Magnet link</h1>
|
||||||
<textarea name="list" id="urls" rows="10" cols="1"></textarea><p>Only One URL per Line</p><a id=downButton>Download</a>
|
<textarea name="list" id="urls" rows="10" cols="1"></textarea><p>Only one link per line</p><a id=downButton>Download</a>
|
||||||
</center>
|
</center>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<div id="desktop">
|
<div id="desktop">
|
||||||
<div id="desktopHeader">
|
<div id="desktopHeader">
|
||||||
<div id="desktopTitlebar">
|
<div id="desktopTitlebar">
|
||||||
<h1 class="applicationTitle">qBittorrent Web User Interface <span class="version">version 1.3.1</span></h1>
|
<h1 class="applicationTitle">qBittorrent Web User Interface <span class="version">version 1.3.2</span></h1>
|
||||||
</div>
|
</div>
|
||||||
<div id="desktopNavbar">
|
<div id="desktopNavbar">
|
||||||
<ul>
|
<ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user