mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 18:04:32 +00:00
WebUI: Add command to get the logs
Add /query/getLog and /query/getPeerLog to respectively retrieve the main log and the peer log. GET /query/getLog Params: - normal (bool): include normal messages (default true) - info (bool): include info messages (default true) - warning (bool): include warning messages (default true) - critical (bool): include critical messages (default true) - last_known_id (int): exclude messages with id <= 'last_known_id' GET /query/getPeerLog Params: - last_known_id (int): exclude messages with id <= 'last_known_id'
This commit is contained in:
parent
673b86c6e3
commit
01b73bf704
@ -29,6 +29,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "btjson.h"
|
#include "btjson.h"
|
||||||
|
#include "base/logger.h"
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
@ -198,6 +199,15 @@ static const char KEY_FULL_UPDATE[] = "full_update";
|
|||||||
static const char KEY_RESPONSE_ID[] = "rid";
|
static const char KEY_RESPONSE_ID[] = "rid";
|
||||||
static const char KEY_SUFFIX_REMOVED[] = "_removed";
|
static const char KEY_SUFFIX_REMOVED[] = "_removed";
|
||||||
|
|
||||||
|
// Log keys
|
||||||
|
static const char KEY_LOG_ID[] = "id";
|
||||||
|
static const char KEY_LOG_TIMESTAMP[] = "timestamp";
|
||||||
|
static const char KEY_LOG_MSG_TYPE[] = "type";
|
||||||
|
static const char KEY_LOG_MSG_MESSAGE[] = "message";
|
||||||
|
static const char KEY_LOG_PEER_IP[] = "ip";
|
||||||
|
static const char KEY_LOG_PEER_BLOCKED[] = "blocked";
|
||||||
|
static const char KEY_LOG_PEER_REASON[] = "reason";
|
||||||
|
|
||||||
QVariantMap getTranserInfoMap();
|
QVariantMap getTranserInfoMap();
|
||||||
QVariantMap toMap(BitTorrent::TorrentHandle *const torrent);
|
QVariantMap toMap(BitTorrent::TorrentHandle *const torrent);
|
||||||
void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData);
|
void processMap(QVariantMap prevData, QVariantMap data, QVariantMap &syncData);
|
||||||
@ -887,3 +897,64 @@ QVariantMap generateSyncData(int acceptedResponseId, QVariantMap data, QVariantM
|
|||||||
|
|
||||||
return syncData;
|
return syncData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the log in JSON format.
|
||||||
|
*
|
||||||
|
* The return value is an array of dictionaries.
|
||||||
|
* The dictionary keys are:
|
||||||
|
* - "id": id of the message
|
||||||
|
* - "timestamp": milliseconds since epoch
|
||||||
|
* - "type": type of the message (int, see MsgType)
|
||||||
|
* - "message": text of the message
|
||||||
|
*/
|
||||||
|
QByteArray btjson::getLog(bool normal, bool info, bool warning, bool critical, int lastKnownId)
|
||||||
|
{
|
||||||
|
Logger* const logger = Logger::instance();
|
||||||
|
QVariantList msgList;
|
||||||
|
|
||||||
|
foreach (const Log::Msg& msg, logger->getMessages(lastKnownId)) {
|
||||||
|
if (!((msg.type == Log::NORMAL && normal)
|
||||||
|
|| (msg.type == Log::INFO && info)
|
||||||
|
|| (msg.type == Log::WARNING && warning)
|
||||||
|
|| (msg.type == Log::CRITICAL && critical)))
|
||||||
|
continue;
|
||||||
|
QVariantMap map;
|
||||||
|
map[KEY_LOG_ID] = msg.id;
|
||||||
|
map[KEY_LOG_TIMESTAMP] = msg.timestamp;
|
||||||
|
map[KEY_LOG_MSG_TYPE] = msg.type;
|
||||||
|
map[KEY_LOG_MSG_MESSAGE] = msg.message;
|
||||||
|
msgList.append(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json::toJson(msgList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the peer log in JSON format.
|
||||||
|
*
|
||||||
|
* The return value is an array of dictionaries.
|
||||||
|
* The dictionary keys are:
|
||||||
|
* - "id": id of the message
|
||||||
|
* - "timestamp": milliseconds since epoch
|
||||||
|
* - "ip": IP of the peer
|
||||||
|
* - "blocked": whether or not the peer was blocked
|
||||||
|
* - "reason": reason of the block
|
||||||
|
*/
|
||||||
|
QByteArray btjson::getPeerLog(int lastKnownId)
|
||||||
|
{
|
||||||
|
Logger* const logger = Logger::instance();
|
||||||
|
QVariantList peerList;
|
||||||
|
|
||||||
|
foreach (const Log::Peer& peer, logger->getPeers(lastKnownId)) {
|
||||||
|
QVariantMap map;
|
||||||
|
map[KEY_LOG_ID] = peer.id;
|
||||||
|
map[KEY_LOG_TIMESTAMP] = peer.timestamp;
|
||||||
|
map[KEY_LOG_PEER_IP] = peer.ip;
|
||||||
|
map[KEY_LOG_PEER_BLOCKED] = peer.blocked;
|
||||||
|
map[KEY_LOG_PEER_REASON] = peer.reason;
|
||||||
|
peerList.append(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json::toJson(peerList);
|
||||||
|
}
|
||||||
|
@ -53,6 +53,8 @@ public:
|
|||||||
static QByteArray getFilesForTorrent(const QString& hash);
|
static QByteArray getFilesForTorrent(const QString& hash);
|
||||||
static QByteArray getTransferInfo();
|
static QByteArray getTransferInfo();
|
||||||
static QByteArray getTorrentsRatesLimits(QStringList& hashes, bool downloadLimits);
|
static QByteArray getTorrentsRatesLimits(QStringList& hashes, bool downloadLimits);
|
||||||
|
static QByteArray getLog(bool normal, bool info, bool warning, bool critical, int lastKnownId);
|
||||||
|
static QByteArray getPeerLog(int lastKnownId);
|
||||||
}; // class btjson
|
}; // class btjson
|
||||||
|
|
||||||
#endif // BTJSON_H
|
#endif // BTJSON_H
|
||||||
|
@ -81,6 +81,8 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
|
|||||||
ADD_ACTION(query, propertiesTrackers);
|
ADD_ACTION(query, propertiesTrackers);
|
||||||
ADD_ACTION(query, propertiesWebSeeds);
|
ADD_ACTION(query, propertiesWebSeeds);
|
||||||
ADD_ACTION(query, propertiesFiles);
|
ADD_ACTION(query, propertiesFiles);
|
||||||
|
ADD_ACTION(query, getLog);
|
||||||
|
ADD_ACTION(query, getPeerLog);
|
||||||
ADD_ACTION(sync, maindata);
|
ADD_ACTION(sync, maindata);
|
||||||
ADD_ACTION(sync, torrent_peers);
|
ADD_ACTION(sync, torrent_peers);
|
||||||
ADD_ACTION(command, shutdown);
|
ADD_ACTION(command, shutdown);
|
||||||
@ -270,6 +272,44 @@ void WebApplication::action_query_propertiesFiles()
|
|||||||
print(btjson::getFilesForTorrent(args_.front()), Http::CONTENT_TYPE_JSON);
|
print(btjson::getFilesForTorrent(args_.front()), Http::CONTENT_TYPE_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET params:
|
||||||
|
// - normal (bool): include normal messages (default true)
|
||||||
|
// - info (bool): include info messages (default true)
|
||||||
|
// - warning (bool): include warning messages (default true)
|
||||||
|
// - critical (bool): include critical messages (default true)
|
||||||
|
// - last_known_id (int): exclude messages with id <= 'last_known_id' (default -1)
|
||||||
|
void WebApplication::action_query_getLog()
|
||||||
|
{
|
||||||
|
CHECK_URI(0);
|
||||||
|
bool normal = request().gets["normal"] != "false";
|
||||||
|
bool info = request().gets["info"] != "false";
|
||||||
|
bool warning = request().gets["warning"] != "false";
|
||||||
|
bool critical = request().gets["critical"] != "false";
|
||||||
|
int lastKnownId;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
lastKnownId = request().gets["last_known_id"].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
lastKnownId = -1;
|
||||||
|
|
||||||
|
print(btjson::getLog(normal, info, warning, critical, lastKnownId), Http::CONTENT_TYPE_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET params:
|
||||||
|
// - last_known_id (int): exclude messages with id <= 'last_known_id' (default -1)
|
||||||
|
void WebApplication::action_query_getPeerLog()
|
||||||
|
{
|
||||||
|
CHECK_URI(0);
|
||||||
|
int lastKnownId;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
lastKnownId = request().gets["last_known_id"].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
lastKnownId = -1;
|
||||||
|
|
||||||
|
print(btjson::getPeerLog(lastKnownId), Http::CONTENT_TYPE_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
// GET param:
|
// GET param:
|
||||||
// - rid (int): last response id
|
// - rid (int): last response id
|
||||||
void WebApplication::action_sync_maindata()
|
void WebApplication::action_sync_maindata()
|
||||||
|
@ -54,6 +54,8 @@ private:
|
|||||||
void action_query_propertiesTrackers();
|
void action_query_propertiesTrackers();
|
||||||
void action_query_propertiesWebSeeds();
|
void action_query_propertiesWebSeeds();
|
||||||
void action_query_propertiesFiles();
|
void action_query_propertiesFiles();
|
||||||
|
void action_query_getLog();
|
||||||
|
void action_query_getPeerLog();
|
||||||
void action_sync_maindata();
|
void action_sync_maindata();
|
||||||
void action_sync_torrent_peers();
|
void action_sync_torrent_peers();
|
||||||
void action_command_shutdown();
|
void action_command_shutdown();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user