Skip to content

Commit

Permalink
3.3.11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
c0re100 committed Mar 17, 2017
1 parent 7e39a71 commit 5ba9f87
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 133 deletions.
9 changes: 5 additions & 4 deletions dist/windows/license.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(qBittorrent Enhanced Edition For Auto Ban Badass by Husky)
Function:
Features:
1. Auto Ban Xunlei, QQ, Baidu, Xfplay client
2. Reset IPFilter When qBittorrent Closed
3. IP filter API for advanced user
4. Logging Failed WebUI/API Login Attempts
2. Temporary IP Filter API for advanced user
3. Logging Failed WebUI/API Login Attempts
4. Reset IPFilter When Exit Option
5. Update MessageBox with changelog if NEW version is available

qBittorrent is licensed under the GNU General Public License version 2 with the
addition of the following special exception:
Expand Down
2 changes: 1 addition & 1 deletion dist/windows/options.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ XPStyle on
!define CSIDL_APPDATA '0x1A' ;Application Data path
!define CSIDL_LOCALAPPDATA '0x1C' ;Local Application Data path

!define PROG_VERSION "3.3.11.2"
!define PROG_VERSION "3.3.11.3"
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION PageFinishRun
!define MUI_FINISHPAGE_RUN_TEXT $(launch_qbt)
Expand Down
49 changes: 0 additions & 49 deletions src/base/bittorrent/peerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,55 +201,6 @@ PeerAddress PeerInfo::address() const

QString PeerInfo::client() const
{
/*Old Method
QString ip = QString::fromStdString(m_nativeInfo.ip.address().to_string());
QString client = Utils::String::fromStdString(m_nativeInfo.client);
QRegularExpression re("Xunlei");
QRegularExpressionMatch match = re.match(client);
QRegularExpression re2("XL");
QRegularExpressionMatch match2 = re2.match(client);
if(client >= "0.0.0.0" && client <= "9.99.99.9999" || match.hasMatch() || match2.hasMatch()) {
qDebug("Auto Banning Xunlei peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xunlei peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re3("Xf");
QRegularExpressionMatch match3 = re3.match(client);
if(match3.hasMatch()) {
qDebug("Auto Banning Xfplay peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xfplay peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re4("QQ");
QRegularExpressionMatch match4 = re4.match(client);
if(match4.hasMatch())
{
qDebug("Auto Banning QQDownload peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning QQDownload peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re6("Baidu");
QRegularExpressionMatch match6 = re6.match(client);
if(match6.hasMatch())
{
qDebug("Auto Banning Baidu peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Baidu peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re5("Unknown");
QRegularExpressionMatch match5 = re5.match(client);
if(match5.hasMatch())
{
qDebug("Auto Banning Unknown peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Unknown peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}*/

return Utils::String::fromStdString(m_nativeInfo.client);
}

Expand Down
11 changes: 11 additions & 0 deletions src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,17 @@ void Session::banIP(const QString &ip)
}
}

void Session::blockIP(const QString &ip)
{
libt::ip_filter filter = m_nativeSession->get_ip_filter();
boost::system::error_code ec;
libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec);
Q_ASSERT(!ec);
if (ec) return;
filter.add_rule(addr, addr, libt::ip_filter::blocked);
m_nativeSession->set_ip_filter(filter);
}

void Session::unbanIP()
{
SettingsStorage::instance()->storeValue("Preferences/IPFilter/BannedIPs", QString());
Expand Down
1 change: 1 addition & 0 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ namespace BitTorrent

void banIP(const QString &ip);
void unbanIP();
void blockIP(const QString &ip);

bool isKnownTorrent(const InfoHash &hash) const;
bool addTorrent(QString source, const AddTorrentParams &params = AddTorrentParams());
Expand Down
2 changes: 1 addition & 1 deletion src/base/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Preferences::setConfirmOnExit(bool confirm)

bool Preferences::speedInTitleBar() const
{
return value("Preferences/General/SpeedInTitleBar", false).toBool();
return value("Preferences/General/SpeedInTitleBar", true).toBool();
}

void Preferences::showSpeedInTitleBar(bool show)
Expand Down
49 changes: 21 additions & 28 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->actionAutoHibernate->setDisabled(true);
#endif
m_ui->actionAutoExit->setChecked(pref->shutdownqBTWhenDownloadsComplete());
m_ui->actionResetIPFilter->setChecked(false);

if (!autoShutdownGroup->checkedAction())
m_ui->actionAutoShutdownDisabled->setChecked(true);
Expand Down Expand Up @@ -888,7 +889,7 @@ void MainWindow::on_actionExit_triggered()
// Ask for UI lock password
if (!unlockUI()) return;

BitTorrent::Session::instance()->unbanIP();
//BitTorrent::Session::instance()->unbanIP();
m_forceExit = true;
close();
}
Expand Down Expand Up @@ -1029,10 +1030,11 @@ void MainWindow::closeEvent(QCloseEvent *e)
m_forceExit = false;
return;
}
if (confirmBox.clickedButton() == alwaysBtn)
if (confirmBox.clickedButton() == alwaysBtn) {
// Remember choice
BitTorrent::Session::instance()->unbanIP();
//BitTorrent::Session::instance()->unbanIP();
Preferences::instance()->setConfirmOnExit(false);
}
}
}

Expand All @@ -1045,7 +1047,9 @@ void MainWindow::closeEvent(QCloseEvent *e)
if (m_systrayIcon)
m_systrayIcon->hide();
// Accept exit
BitTorrent::Session::instance()->unbanIP();
if(m_ui->actionResetIPFilter->isChecked()) {
BitTorrent::Session::instance()->unbanIP();
}
e->accept();
qApp->exit();
}
Expand Down Expand Up @@ -1349,45 +1353,34 @@ void MainWindow::updateGUI()
QString ip = addr.ip.toString();
QString client = peer.client();

QRegularExpression re("Xunlei");
QRegularExpressionMatch match = re.match(client);
QRegularExpression re2("XL");
QRegularExpressionMatch match2 = re2.match(client);
if(client >= "0.0.0.0" && client <= "9.99.99.9999" || match.hasMatch() || match2.hasMatch()) {
if(client >= "0.0.0.0" && client <= "9.99.99.9999" || client.contains("Xunlei") || client.contains("XL")) {
qDebug("Auto Banning Xunlei peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xunlei peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
BitTorrent::Session::instance()->blockIP(ip);
}

QRegularExpression re3("Xf");
QRegularExpressionMatch match3 = re3.match(client);
if(match3.hasMatch()) {
if(client.contains("Xf")) {
qDebug("Auto Banning Xfplay peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xfplay peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
BitTorrent::Session::instance()->blockIP(ip);
}

QRegularExpression re4("QQ");
QRegularExpressionMatch match4 = re4.match(client);
if(match4.hasMatch())
if(client.contains("QQ"))
{
qDebug("Auto Banning QQDownload peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning QQDownload peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
BitTorrent::Session::instance()->blockIP(ip);
}

QRegularExpression re6("Baidu");
QRegularExpressionMatch match6 = re6.match(client);
if(match6.hasMatch())
if(client.contains("Baidu"))
{
qDebug("Auto Banning Baidu peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Baidu peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
BitTorrent::Session::instance()->blockIP(ip);
}

/*QRegularExpression re5("Unknown");
QRegularExpressionMatch match5 = re5.match(client);
if(match5.hasMatch())
/*
if(client.contains("Unknown"))
{
qDebug("Auto Banning Unknown peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Unknown peer '%1'...").arg(ip));
Expand Down Expand Up @@ -1652,12 +1645,12 @@ void MainWindow::on_actionDownloadFromURL_triggered()

#if defined(Q_OS_WIN) || defined(Q_OS_MAC)

void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVersion, bool invokedByUser)
void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVersion, QString newContent, bool invokedByUser)
{
QMessageBox::StandardButton answer = QMessageBox::Yes;
if (updateAvailable) {
answer = QMessageBox::question(this, tr("qBittorrent Update Available"),
tr("A new version is available.\nDo you want to download %1?").arg(newVersion),
tr("A new version is available.\nDo you want to download %1?\n%2").arg(newVersion).arg(newContent),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes) {
// The user want to update, let's download the update
Expand Down Expand Up @@ -1819,7 +1812,7 @@ void MainWindow::checkProgramUpdate()
m_ui->actionCheckForUpdates->setToolTip(tr("Already checking for program updates in the background"));
bool invokedByUser = m_ui->actionCheckForUpdates == qobject_cast<QAction * >(sender());
ProgramUpdater *updater = new ProgramUpdater(this, invokedByUser);
connect(updater, SIGNAL(updateCheckFinished(bool,QString,bool)), SLOT(handleUpdateCheckFinished(bool,QString,bool)));
connect(updater, SIGNAL(updateCheckFinished(bool,QString,QString,bool)), SLOT(handleUpdateCheckFinished(bool,QString,QString,bool)));
updater->checkForUpdates();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private slots:
void askRecursiveTorrentDownloadConfirmation(BitTorrent::TorrentHandle *const torrent);
void optionsSaved();
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
void handleUpdateCheckFinished(bool updateAvailable, QString newVersion, bool invokedByUser);
void handleUpdateCheckFinished(bool updateAvailable, QString newVersion, QString newContent, bool invokedByUser);
#endif
void updateRSSTabLabel(int count);

Expand Down
9 changes: 9 additions & 0 deletions src/gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<addaction name="actionOptions"/>
<addaction name="separator"/>
<addaction name="menuAutoShutdownOnDownloadsCompletion"/>
<addaction name="actionResetIPFilter"/>
</widget>
<widget class="QMenu" name="menuFile">
<property name="title">
Expand Down Expand Up @@ -457,6 +458,14 @@
<string>Critical Messages</string>
</property>
</action>
<action name="actionResetIPFilter">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Reset IPFilter When Exit</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
8 changes: 6 additions & 2 deletions src/gui/programupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &d

qDebug("Finished downloading the new qBittorrent updates RSS");
QString version;
QString content;

QXmlStreamReader xml(data);
bool inItem = false;
Expand All @@ -95,6 +96,8 @@ void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &d
type = getStringValue(xml);
else if (inItem && xml.name() == "version")
version = getStringValue(xml);
else if (inItem && xml.name() == "content")
content = getStringValue(xml);
}
else if (xml.isEndElement()) {
if (inItem && xml.name() == "item") {
Expand All @@ -112,19 +115,20 @@ void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &d
updateLink.clear();
type.clear();
version.clear();
content.clear();
}
}
}

emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser);
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, content, m_invokedByUser);
}

void ProgramUpdater::rssDownloadFailed(const QString &url, const QString &error)
{
Q_UNUSED(url);

qDebug() << "Downloading the new qBittorrent updates RSS failed:" << error;
emit updateCheckFinished(false, QString(), m_invokedByUser);
emit updateCheckFinished(false, QString(), QString(), m_invokedByUser);
}

void ProgramUpdater::updateProgram()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/programupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ProgramUpdater: public QObject
void updateProgram();

signals:
void updateCheckFinished(bool updateAvailable, QString version, bool invokedByUser);
void updateCheckFinished(bool updateAvailable, QString version, QString content, bool invokedByUser);

private slots:
void rssDownloadFinished(const QString &url, const QByteArray &data);
Expand Down
41 changes: 0 additions & 41 deletions src/gui/properties/peerlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,47 +443,6 @@ void PeerListWidget::updatePeer(const QString &ip, BitTorrent::TorrentHandle *co
QStringList downloadingFiles(torrent->info().filesForPiece(peer.downloadingPieceIndex()));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String(";")));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String("\n")), Qt::ToolTipRole);

/*Old Method
QRegularExpression re("Xunlei");
QRegularExpressionMatch match = re.match(peer.client());
QRegularExpression re2("XL");
QRegularExpressionMatch match2 = re2.match(peer.client());
if(peer.client() >= "0.0.0.0" && peer.client() <= "9.99.99.9999" || match.hasMatch() || match2.hasMatch()) {
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Auto Banning Xunlei peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xunlei peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re3("Xf");
QRegularExpressionMatch match3 = re3.match(peer.client());
if(match3.hasMatch()) {
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Auto Banning Xfplay peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Xfplay peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re4("QQ");
QRegularExpressionMatch match4 = re4.match(peer.client());
if(match4.hasMatch())
{
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Auto Banning QQDownload peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning QQDownload peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}
QRegularExpression re5("Unknown");
QRegularExpressionMatch match5 = re5.match(peer.client());
if(match5.hasMatch())
{
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Auto Banning Unknown peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Auto banning Unknown peer '%1'...").arg(ip));
BitTorrent::Session::instance()->banIP(ip);
}*/
}

void PeerListWidget::handleResolved(const QString &ip, const QString &hostname)
Expand Down
7 changes: 3 additions & 4 deletions src/webui/webapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <vector>
#include <QStringList>

#include "base/settingvalue.h"
#include "base/logger.h"
#include "base/iconprovider.h"
#include "base/utils/misc.h"
Expand Down Expand Up @@ -363,14 +362,14 @@ void WebApplication::action_command_banip()
CHECK_URI(0);
QString ip = request().posts["ip"];
QStringList list = SettingsStorage::instance()->loadValue("Preferences/IPFilter/BannedIPs").toStringList();
boost::system::error_code ec;
boost::asio::ip::address::from_string(ip.toStdString(), ec);

if (ip.isEmpty()) {
print(QByteArray("IP field should not be empty."), Http::CONTENT_TYPE_TXT);
return;
}

boost::system::error_code ec;
boost::asio::ip::address::from_string(ip.toStdString(), ec);
if (ec) {
print(QByteArray("The given IP address is not valid."), Http::CONTENT_TYPE_TXT);
return;
Expand All @@ -384,7 +383,7 @@ void WebApplication::action_command_banip()
if (!ip.isEmpty() && !list.contains(ip)) {
qDebug("Banning peer %s via API...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Manually banning peer '%1' via API...").arg(ip));
BitTorrent::Session::instance()->banIP(ip.toLocal8Bit().data());
BitTorrent::Session::instance()->blockIP(ip.toLocal8Bit().data());
print(QByteArray("Done."), Http::CONTENT_TYPE_TXT);
return;
}
Expand Down
Loading

0 comments on commit 5ba9f87

Please sign in to comment.