summaryrefslogtreecommitdiffstats
path: root/plugins/ipfilter
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
commit9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch)
treed088b5210e77d9fa91d954d8550e00e372b47378 /plugins/ipfilter
downloadktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.tar.gz
ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.zip
Updated to final KDE3 ktorrent release (2.2.6)
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'plugins/ipfilter')
-rw-r--r--plugins/ipfilter/Makefile.am31
-rw-r--r--plugins/ipfilter/antip2p.cpp237
-rw-r--r--plugins/ipfilter/antip2p.h117
-rw-r--r--plugins/ipfilter/convert_dlg.ui157
-rw-r--r--plugins/ipfilter/convertdialog.cpp262
-rw-r--r--plugins/ipfilter/convertdialog.h52
-rw-r--r--plugins/ipfilter/ipblockingpref.ui204
-rw-r--r--plugins/ipfilter/ipblockingprefpage.cpp258
-rw-r--r--plugins/ipfilter/ipblockingprefpage.h83
-rw-r--r--plugins/ipfilter/ipfilterplugin.cpp129
-rw-r--r--plugins/ipfilter/ipfilterplugin.h73
-rw-r--r--plugins/ipfilter/ipfilterpluginsettings.kcfgc7
-rw-r--r--plugins/ipfilter/ktipfilterplugin.desktop56
-rw-r--r--plugins/ipfilter/ktipfilterplugin.kcfg18
14 files changed, 1684 insertions, 0 deletions
diff --git a/plugins/ipfilter/Makefile.am b/plugins/ipfilter/Makefile.am
new file mode 100644
index 0000000..02b193a
--- /dev/null
+++ b/plugins/ipfilter/Makefile.am
@@ -0,0 +1,31 @@
+INCLUDES = -I$(srcdir)/../../libktorrent $(all_includes)
+METASOURCES = AUTO
+kde_module_LTLIBRARIES = ktipfilterplugin.la
+noinst_HEADERS = ipfilterplugin.h ipblockingprefpage.h antip2p.h \
+ convertdialog.h
+ktipfilterplugin_la_SOURCES = ipfilterplugin.cpp ipblockingpref.ui \
+ ipblockingprefpage.cpp ipfilterpluginsettings.kcfgc antip2p.cpp convert_dlg.ui \
+ convertdialog.cpp
+
+# Libs needed by the plugin
+ktipfilterplugin_la_LIBADD = $(LIB_KHTML) $(LIB_KPARTS) \
+ ../../libktorrent/libktorrent.la $(LIB_QT) \
+ $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KFILE)
+
+
+
+# LD flags for the plugin
+# -module says: this is a module, i.e. something you're going to dlopen
+# so e.g. it has no version number like a normal shared lib would have.
+ktipfilterplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+# rc file containing the GUI for the plugin
+# pluginsdir = $(kde_datadir)/ktsearchplugin
+# plugins_DATA = ktsearchpluginui.rc
+
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = ktipfilterplugin.desktop
+
+kde_kcfg_DATA = ktipfilterplugin.kcfg
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/plugins/ipfilter/antip2p.cpp b/plugins/ipfilter/antip2p.cpp
new file mode 100644
index 0000000..28f9b24
--- /dev/null
+++ b/plugins/ipfilter/antip2p.cpp
@@ -0,0 +1,237 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 "antip2p.h"
+
+#include <torrent/globals.h>
+#include <util/log.h>
+#include <util/constants.h>
+#include <util/mmapfile.h>
+
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+using namespace bt;
+
+namespace kt
+{
+
+ bool IPBlock::operator < (const IPBlock & b) const
+ {
+ if (ip2 < b.ip1) // a range is before b range
+ return true;
+ else if (b.ip2 < ip1) // b range is before a range
+ return false;
+ else
+ return ip1 < b.ip1;// a and b intersect
+ }
+
+ Uint32 AntiP2P::toUint32(const QString& ip)
+ {
+ bool test;
+ Uint32 ret = ip.section('.',0,0).toULongLong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',1,1).toULong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',2,2).toULong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',3,3).toULong(&test);
+
+ return ret;
+ }
+
+ QString fromUint32(Uint32 ip)
+ {
+ Uint32 tmp = ip;
+ QString out;
+
+ tmp = ip;
+ tmp &= 0x000000FF;
+ out.prepend(QString("%1").arg(tmp));
+ ip >>= 8;
+ tmp = ip;
+ tmp &= 0x000000FF;
+ out.prepend(QString("%1.").arg(tmp));
+ ip >>= 8;
+ tmp = ip;
+ tmp &= 0x000000FF;
+ out.prepend(QString("%1.").arg(tmp));
+ ip >>= 8;
+ tmp = ip;
+ tmp &= 0x000000FF;
+ out.prepend(QString("%1.").arg(tmp));
+
+ return out;
+ }
+
+ AntiP2P::AntiP2P()
+ {
+ header_loaded = false;
+ load();
+ }
+
+ AntiP2P::~AntiP2P()
+ {
+ if(file)
+ delete file;
+
+ Out(SYS_IPF|LOG_ALL) << "Anti-P2P filter unloaded." << endl;
+ }
+
+ void AntiP2P::load()
+ {
+ file = new MMapFile();
+ if(! file->open(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1.dat", MMapFile::READ) )
+ {
+ Out(SYS_IPF|LOG_NOTICE) << "Anti-p2p file not loaded." << endl;
+ file = 0;
+ return;
+ }
+ Out(SYS_IPF|LOG_ALL) << "Loading Anti-P2P filter..." << endl;
+ }
+
+ void AntiP2P::loadHeader()
+ {
+ if(!file)
+ return;
+
+ Uint32 nrElements = file->getSize() / sizeof(IPBlock);
+ uint blocksize = nrElements < 100 ? 10 : 100; // number of entries that each HeaderBlock holds. If total number is < 100, than this value is 10.
+ HeaderBlock hb;
+
+ for(Uint64 i = 0; i < file->getSize() ; i+= sizeof(IPBlock)*(blocksize) )
+ {
+ IPBlock ipb;
+ hb.offset = i;
+ file->seek(MMapFile::BEGIN, i);
+ file->read(&ipb, sizeof(IPBlock));
+ hb.ip1 = ipb.ip1;
+ if ( i + (blocksize-1)*sizeof(IPBlock) > file->getSize() ) //last entry
+ {
+ file->seek(MMapFile::BEGIN, file->getSize() - sizeof(IPBlock));
+ file->read(&ipb, sizeof(IPBlock));
+ hb.ip2 = ipb.ip2;
+ hb.nrEntries = nrElements % blocksize;
+
+ blocks.push_back(hb);
+ break;
+ }
+ file->seek(MMapFile::BEGIN, i + (blocksize-1)*sizeof(IPBlock));
+ file->read(&ipb, sizeof(IPBlock));
+ hb.ip2 = ipb.ip2;
+ hb.nrEntries = blocksize;
+ blocks.push_back(hb);
+ }
+
+ Out(SYS_IPF|LOG_NOTICE) << "AntiP2P header loaded." << endl;
+ header_loaded = true;
+ }
+
+ bool AntiP2P::exists()
+ {
+ return file != 0;
+ }
+
+ bool AntiP2P::isBlockedIP(const QString& ip )
+ {
+ Uint32 test = toUint32(ip);
+ return isBlockedIP(test);
+ }
+
+ int AntiP2P::searchHeader(Uint32& ip, int start, int end)
+ {
+ if (end == 0)
+ return -1; //empty list
+
+ if (end == 1)
+ {
+ if (blocks[start].ip1 <= ip && blocks[start].ip2 >= ip) //then our IP is somewhere in between
+ {
+ if (blocks[start].ip1 == ip || blocks[start].ip2 == ip)
+ return -2; //Return -2 to signal that this IP matches either IP from header. No need to search mmaped file in that case.
+ else
+ return start; //else return block index
+ }
+ else
+ return -1; //not found
+ }
+ else
+ {
+ int i = start + end/2;
+ if (blocks[i].ip1 <= ip)
+ return searchHeader(ip, i, end - end/2);
+ else
+ return searchHeader(ip, start, end/2);
+ }
+ }
+
+ bool AntiP2P::isBlockedIP( Uint32& ip )
+ {
+ if (!header_loaded)
+ {
+ Out(SYS_IPF|LOG_IMPORTANT) << "Tried to check if IP was blocked, but no AntiP2P header was loaded." << endl;
+ return false;
+ }
+
+ int in_header = searchHeader(ip, 0, blocks.count());
+ switch (in_header)
+ {
+ case -1:
+ return false; //ip is not blocked
+ case -2:
+ return true; //ip is blocked (we're really lucky to find it in header already)
+ default:
+ //search mmapped file
+ HeaderBlock to_be_searched = blocks[in_header];
+ Uint8* fptr = (Uint8*) file->getDataPointer();
+ fptr += to_be_searched.offset;
+ IPBlock* file_blocks = (IPBlock*) fptr;
+ return searchFile(file_blocks, ip, 0, to_be_searched.nrEntries);
+ break;
+ }
+ return false;
+ }
+
+ bool AntiP2P::searchFile(IPBlock* file_blocks, Uint32& ip, int start, int end)
+ {
+ if (end == 0)
+ return false; //empty list, so not found
+
+ if (end == 1)
+ {
+ if (file_blocks[start].ip1 <= ip && file_blocks[start].ip2 >= ip) //we have a match!
+ return true;
+ else
+ return false; //IP is not found.
+ }
+
+ else
+ {
+ int i = start + end/2;
+ if (file_blocks[i].ip1 <= ip)
+ return searchFile(file_blocks, ip, i, end - end/2);
+ else
+ return searchFile(file_blocks, ip, start, end/2);
+ }
+ }
+}
diff --git a/plugins/ipfilter/antip2p.h b/plugins/ipfilter/antip2p.h
new file mode 100644
index 0000000..48350e3
--- /dev/null
+++ b/plugins/ipfilter/antip2p.h
@@ -0,0 +1,117 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 ANTIP2P_H
+#define ANTIP2P_H
+
+#include <util/mmapfile.h>
+#include <util/constants.h>
+
+#include <qvaluelist.h>
+#include <qstring.h>
+
+namespace kt
+{
+ typedef struct
+ {
+ bt::Uint32 ip1;
+ bt::Uint32 ip2;
+ bt::Uint64 offset;
+ bt::Uint32 nrEntries;
+ } HeaderBlock;
+
+ struct IPBlock
+ {
+ bt::Uint32 ip1;
+ bt::Uint32 ip2;
+
+ bool operator < (const IPBlock & b) const;
+ };
+
+ /**
+ * @author Ivan Vasic <ivasic@gmail.com>
+ * @brief This class is used to manage anti-p2p filter list, so called level1.
+ */
+ class AntiP2P
+ {
+ public:
+ AntiP2P();
+ ~AntiP2P();
+
+ /**
+ * Checks if anti-p2p file is present. Used to check if we should use level1 list
+ **/
+ bool exists();
+
+
+ /**
+ * Creates and loads the header from antip2p filter file.
+ **/
+ void loadHeader();
+
+
+ /**
+ * Checks if specified IP is listed in filter file.
+ * @return TRUE if IP should be blocked, FALSE otherwise
+ * @param ip QString representation of IP to be checked
+ **/
+ bool isBlockedIP(const QString& ip);
+
+ /**
+ * Overloaded function. Uses Uint32 IP to be checked
+ **/
+ bool isBlockedIP(bt::Uint32& ip);
+
+ /**
+ * This function converts QString IP to Uint32 format.
+ **/
+ static bt::Uint32 toUint32(const QString& ip);
+
+ private:
+ bt::MMapFile* file;
+ QValueList<HeaderBlock> blocks;
+
+ ///Is AntiP2P header loaded
+ bool header_loaded;
+
+ /**
+ * Loads filter file
+ */
+ void load();
+
+ /**
+ * Binary searches AntiP2P::blocks to find range where IP could be.
+ * @returns
+ * -1 if IP cannot be in the list
+ * -2 if IP is already found in blocks
+ * or index of HeaderBlock in AntiP2P::blocks which will be used for direct file search.
+ **/
+ int searchHeader(bt::Uint32& ip, int start, int end);
+
+
+ /**
+ * Binary searches AntiP2P::file to find IP.
+ * @returns TRUE if IP should be blocked FALSE otherwise
+ **/
+ bool searchFile(IPBlock* file_blocks, bt::Uint32& ip, int start, int end);
+
+ };
+}
+#endif
diff --git a/plugins/ipfilter/convert_dlg.ui b/plugins/ipfilter/convert_dlg.ui
new file mode 100644
index 0000000..cc246ed
--- /dev/null
+++ b/plugins/ipfilter/convert_dlg.ui
@@ -0,0 +1,157 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>ConvertingDlg</class>
+<widget class="QDialog">
+ <property name="name">
+ <cstring>ConvertingDlg</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>414</width>
+ <height>156</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="caption">
+ <string>Converting...</string>
+ </property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="resizeMode">
+ <enum>Fixed</enum>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Click on the 'convert' button to start converting antip2p file. NOTE: This process could take a while even on fast machines and during that time you will not be able to use KTorrent.</string>
+ </property>
+ <property name="textFormat">
+ <enum>AutoText</enum>
+ </property>
+ <property name="scaledContents">
+ <bool>false</bool>
+ </property>
+ <property name="alignment">
+ <set>WordBreak|AlignVCenter</set>
+ </property>
+ <property name="indent">
+ <number>-2</number>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>lbl_progress</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KProgress" row="2" column="0">
+ <property name="name">
+ <cstring>kProgress1</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>390</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget" row="3" column="0">
+ <property name="name">
+ <cstring>layout6</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>label1</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>btnClose</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Close</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>btnCancel</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>C&amp;ancel</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </grid>
+</widget>
+<connections>
+ <connection>
+ <sender>btnClose</sender>
+ <signal>clicked()</signal>
+ <receiver>ConvertingDlg</receiver>
+ <slot>btnClose_clicked()</slot>
+ </connection>
+ <connection>
+ <sender>btnCancel</sender>
+ <signal>clicked()</signal>
+ <receiver>ConvertingDlg</receiver>
+ <slot>btnCancel_clicked()</slot>
+ </connection>
+</connections>
+<slots>
+ <slot>btnClose_clicked()</slot>
+ <slot>btnCancel_clicked()</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kprogress.h</includehint>
+</includehints>
+</UI>
diff --git a/plugins/ipfilter/convertdialog.cpp b/plugins/ipfilter/convertdialog.cpp
new file mode 100644
index 0000000..6fed40f
--- /dev/null
+++ b/plugins/ipfilter/convertdialog.cpp
@@ -0,0 +1,262 @@
+/***************************************************************************
+* Copyright (C) 2005 by Joris Guisson *
+* joris.guisson@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 "convertdialog.h"
+
+#include <kapplication.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <klocale.h>
+#include <kurl.h>
+#include <kmessagebox.h>
+#include <kio/netaccess.h>
+#include <kprogress.h>
+#include <kmimetype.h>
+
+#include <util/log.h>
+#include <util/constants.h>
+#include <torrent/globals.h>
+#include <interfaces/coreinterface.h>
+
+#include <qfile.h>
+#include <qstringlist.h>
+#include <qtextstream.h>
+#include <qregexp.h>
+#include <qvalidator.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qevent.h>
+#include <qurloperator.h>
+#include "antip2p.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+
+ Uint32 toUint32(QString& ip)
+ {
+ bool test;
+ Uint32 ret = ip.section('.',0,0).toULongLong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',1,1).toULong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',2,2).toULong(&test);
+ ret <<= 8;
+ ret |= ip.section('.',3,3).toULong(&test);
+
+ return ret;
+ }
+
+ IPBlock RangeToBlock(const QString& range)
+ {
+ IPBlock block;
+ QStringList ls = QStringList::split('-', range);
+ block.ip1 = toUint32(ls[0]);
+ block.ip2 = toUint32(ls[1]);
+ return block;
+ }
+
+ ConvertDialog::ConvertDialog( IPFilterPlugin* p, QWidget *parent, const char *name )
+ : ConvertingDlg( parent, name )
+ {
+ m_plugin = p;
+ btnClose->setText(i18n("Convert"));
+ to_convert = true;
+ converting = false;
+ canceled = false;
+ kProgress1->setEnabled(false);
+ }
+
+ void ConvertDialog::convert()
+ {
+ QFile source( KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.txt" );
+ QFile target( KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat" );
+ QFile temp( KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat.tmp" );
+
+ if(target.exists())
+ {
+ //make backup
+ KIO::NetAccess::file_copy(KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat", KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat.tmp", -1, true);
+ }
+
+ /* READ INPUT FILE */
+ QValueList<IPBlock> list;
+ lbl_progress->setText( i18n( "Loading txt file..." ) );
+ label1->setText( i18n("Please wait...") );
+ ulong source_size = source.size();
+ btnClose->setEnabled( false );
+ converting = true;
+
+ int counter = 0;
+
+ if ( source.open( IO_ReadOnly ) )
+ {
+ QTextStream stream( &source );
+ kProgress1->setEnabled(true);
+
+ int i = 0;
+ QRegExp rx( "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}-[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" );
+ QRegExpValidator v( rx, 0 );
+ int poz = 0;
+
+ while ( !stream.atEnd() )
+ {
+ if(canceled)
+ return;
+
+ KApplication::kApplication() ->processEvents();
+ QString line = stream.readLine();
+ i += line.length() * sizeof( char ); //rough estimation of string size
+ kProgress1->setProgress( i * 100 / source_size );
+ ++i;
+
+ QString ip_part = line.section( ':' , -1 );
+ if ( v.validate( ip_part, poz ) != QValidator::Acceptable )
+ continue;
+ else
+ ++counter;
+
+ list += RangeToBlock(ip_part);
+ }
+ source.close();
+ }
+ else
+ {
+ Out(SYS_IPF|LOG_IMPORTANT) << "Cannot find level1 file" << endl;
+ btnClose->setEnabled( true );
+ btnClose->setText(i18n("&Close"));
+ label1->setText("");
+ to_convert = false;
+ converting = false;
+ return ;
+ }
+
+ if ( counter != 0 )
+ {
+ qHeapSort(list);
+ lbl_progress->setText( i18n( "Converting..." ) );
+ if ( m_plugin )
+ m_plugin->unloadAntiP2P();
+
+ ulong blocks = list.count();
+
+ /** WRITE TO OUTPUT **/
+ if ( !target.open( IO_WriteOnly ) )
+ {
+ Out(SYS_IPF|LOG_IMPORTANT) << "Unable to open file for writing" << endl;
+ btnClose->setEnabled( true );
+ btnClose->setText(i18n("&Close"));
+ label1->setText("");
+ to_convert = false;
+ converting = false;
+ return ;
+ }
+
+ Out(SYS_IPF|LOG_NOTICE) << "Loading finished. Starting conversion..." << endl;
+
+ QValueList<IPBlock>::iterator iter;
+ int i = 0;
+ for (iter = list.begin(); iter != list.end(); ++iter, ++i)
+ {
+ IPBlock & block = *iter;
+ target.writeBlock( ( char* ) & block, sizeof( IPBlock ) );
+ if ( i % 1000 == 0 )
+ {
+ kProgress1->setProgress( ( int ) 100 * i / blocks );
+ if ( i % 10000 == 0 )
+ Out(SYS_IPF|LOG_DEBUG) << "Block " << i << " written." << endl;
+ }
+ KApplication::kApplication()->processEvents();
+
+ if(canceled)
+ return;
+ }
+ kProgress1->setProgress(100);
+ Out(SYS_IPF|LOG_NOTICE) << "Finished converting." << endl;
+ lbl_progress->setText( i18n( "File converted." ) );
+ target.close();
+ }
+ else
+ {
+ lbl_progress->setText( "<font color=\"#ff0000\">" + i18n( "Could not load filter:" ) + "</font>" + i18n( "Bad filter file. It may be corrupted or has a bad format." ) );
+ target.remove();
+ source.remove();
+ btnClose->setEnabled( true );
+ btnClose->setText(i18n("&Close"));
+ label1->setText("");
+ to_convert = false;
+ converting = false;
+ }
+
+ KApplication::kApplication()->processEvents();
+ //reload level1 filter
+ if ( m_plugin )
+ m_plugin->loadAntiP2P();
+
+ btnClose->setEnabled( true );
+ to_convert = false;
+ converting = false;
+ btnClose->setText(i18n("&Close"));
+ label1->setText("");
+ }
+
+ void ConvertDialog::btnClose_clicked()
+ {
+ if(to_convert)
+ convert();
+ else
+ this->close();
+ }
+
+ void ConvertDialog::closeEvent(QCloseEvent* e)
+ {
+ if(!converting)
+ e->accept();
+ else
+ e->ignore();
+ }
+
+ void ConvertDialog::btnCancel_clicked()
+ {
+ if(converting)
+ {
+ QFile target( KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat" );
+ if(target.exists())
+ target.remove();
+
+ QFile temp( KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat.tmp");
+ if(temp.exists())
+ {
+ KIO::NetAccess::file_copy(KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat.tmp", KGlobal::dirs() ->saveLocation( "data", "ktorrent" ) + "level1.dat", -1, true);
+ temp.remove();
+ }
+
+ canceled = true;
+ Out(SYS_IPF|LOG_NOTICE) << "Conversion canceled." << endl;
+ }
+
+
+ this->reject();
+ }
+
+}
+
+#include "convertdialog.moc"
diff --git a/plugins/ipfilter/convertdialog.h b/plugins/ipfilter/convertdialog.h
new file mode 100644
index 0000000..be451f3
--- /dev/null
+++ b/plugins/ipfilter/convertdialog.h
@@ -0,0 +1,52 @@
+/***************************************************************************
+* Copyright (C) 2005 by Joris Guisson *
+* joris.guisson@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 CONVERTDIALOG_H
+#define CONVERTDIALOG_H
+
+#include "convert_dlg.h"
+#include "ipfilterplugin.h"
+
+#include <qevent.h>
+
+namespace kt
+{
+ class ConvertDialog: public ConvertingDlg
+ {
+ Q_OBJECT
+
+ public:
+ ConvertDialog( IPFilterPlugin* p, QWidget *parent = 0, const char *name = 0 );
+
+ public slots:
+ virtual void btnClose_clicked();
+
+ private:
+ void convert();
+ IPFilterPlugin* m_plugin;
+ bool to_convert;
+ bool converting;
+ bool canceled;
+
+ private slots:
+ void closeEvent(QCloseEvent* e);
+ virtual void btnCancel_clicked();
+ };
+}
+#endif
diff --git a/plugins/ipfilter/ipblockingpref.ui b/plugins/ipfilter/ipblockingpref.ui
new file mode 100644
index 0000000..43870f0
--- /dev/null
+++ b/plugins/ipfilter/ipblockingpref.ui
@@ -0,0 +1,204 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>IPBlockingPref</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>IPBlockingPref</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>564</width>
+ <height>444</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>IPBlocking Preferences</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer row="2" column="0">
+ <property name="name">
+ <cstring>spacer7</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QGroupBox" row="0" column="0">
+ <property name="name">
+ <cstring>groupBox1</cstring>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="title">
+ <string>Select PeerGuardian Filter File </string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox" row="0" column="0">
+ <property name="name">
+ <cstring>checkUseLevel1</cstring>
+ </property>
+ <property name="text">
+ <string>Use PeerGuardian filter?</string>
+ </property>
+ <property name="accel">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget" row="1" column="0">
+ <property name="name">
+ <cstring>layout5</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3</cstring>
+ </property>
+ <property name="text">
+ <string>IP filter file:</string>
+ </property>
+ </widget>
+ <widget class="KURLRequester">
+ <property name="name">
+ <cstring>m_url</cstring>
+ </property>
+ <property name="url" stdset="0">
+ <string>http://www.bluetack.co.uk/modules.php?name=Downloads&amp;d_op=getit&amp;lid=8</string>
+ </property>
+ <property name="showLocalProtocol">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget" row="2" column="0">
+ <property name="name">
+ <cstring>layout3</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer>
+ <property name="name">
+ <cstring>spacer3</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>361</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>btnDownload</cstring>
+ </property>
+ <property name="text">
+ <string>Dow&amp;nload/Convert</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLabel" row="3" column="0">
+ <property name="name">
+ <cstring>textLabel1_2</cstring>
+ </property>
+ <property name="text">
+ <string>Download PeerGuardian filter from bluetack.co.uk or blocklist.org.
+NOTE: ZIP file from bluetack.co.uk is supported.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="0">
+ <property name="name">
+ <cstring>lbl_status1</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <spacer row="4" column="0">
+ <property name="name">
+ <cstring>spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+ </widget>
+ </grid>
+</widget>
+<customwidgets>
+</customwidgets>
+<connections>
+ <connection>
+ <sender>btnDownload</sender>
+ <signal>clicked()</signal>
+ <receiver>IPBlockingPref</receiver>
+ <slot>btnDownload_clicked()</slot>
+ </connection>
+ <connection>
+ <sender>checkUseLevel1</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>IPBlockingPref</receiver>
+ <slot>checkUseLevel1_toggled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>checkUseLevel1</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>textLabel1_2</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>checkUseLevel1</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>textLabel1_3</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+</connections>
+<slots>
+ <slot>btnDownload_clicked()</slot>
+ <slot>checkUseLevel1_toggled(bool)</slot>
+ <slot>checkUseKTfilter_toggled(bool)</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kurlrequester.h</includehint>
+ <includehint>kpushbutton.h</includehint>
+</includehints>
+</UI>
diff --git a/plugins/ipfilter/ipblockingprefpage.cpp b/plugins/ipfilter/ipblockingprefpage.cpp
new file mode 100644
index 0000000..6d06d1b
--- /dev/null
+++ b/plugins/ipfilter/ipblockingprefpage.cpp
@@ -0,0 +1,258 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 "ipblockingprefpage.h"
+#include "ipblockingpref.h"
+#include "ipfilterpluginsettings.h"
+#include "ipfilterplugin.h"
+#include "convertdialog.h"
+
+#include <kapplication.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kurlrequester.h>
+#include <kurl.h>
+#include <kmessagebox.h>
+#include <kio/netaccess.h>
+#include <kprogress.h>
+#include <kmimetype.h>
+
+#include <util/log.h>
+#include <torrent/globals.h>
+#include <interfaces/coreinterface.h>
+
+#include <qthread.h>
+#include <qlabel.h>
+#include <qcheckbox.h>
+#include <qregexp.h>
+#include <qvalidator.h>
+#include <qlayout.h>
+#include <qdialog.h>
+#include <qobject.h>
+
+using namespace bt;
+
+#define MAX_RANGES 500
+
+namespace kt
+{
+ IPBlockingPrefPageWidget::IPBlockingPrefPageWidget(QWidget* parent) : IPBlockingPref(parent)
+ {
+ m_url->setURL(IPBlockingPluginSettings::filterURL());
+ if (m_url->url() == "")
+ m_url->setURL(QString("http://www.bluetack.co.uk/config/splist.zip"));
+
+ bool use_level1 = IPBlockingPluginSettings::useLevel1();
+
+ checkUseLevel1->setChecked(use_level1);
+
+ if(use_level1)
+ {
+ lbl_status1->setText(i18n("Status: Loaded and running."));
+ m_url->setEnabled(true);
+ btnDownload->setEnabled(true);
+ }
+ else
+ {
+ lbl_status1->setText(i18n("Status: Not loaded."));
+ m_url->setEnabled(false);
+ btnDownload->setEnabled(false);
+ }
+
+ m_plugin = 0;
+ }
+
+ void IPBlockingPrefPageWidget::apply()
+ {
+ IPBlockingPluginSettings::setFilterURL(m_url->url());
+ IPBlockingPluginSettings::setUseLevel1(checkUseLevel1->isChecked());
+ IPBlockingPluginSettings::writeConfig();
+
+ if(checkUseLevel1->isChecked())
+ {
+ QFile target(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1.dat");
+ if(target.exists())
+ lbl_status1->setText(i18n("Status: Loaded and running."));
+ else
+ lbl_status1->setText(i18n("Status: <font color=\"#ff0000\">Filter file not found.</font> Download and convert filter file."));
+ }
+ else
+ lbl_status1->setText(i18n("Status: Not loaded."));
+ }
+
+ void IPBlockingPrefPageWidget::btnDownload_clicked()
+ {
+ QString target(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1");
+ QFile target_file(target);
+ QFile txtfile(target + ".txt");
+ KURL url(m_url->url());
+ KURL dest(target);
+ KURL temp(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1.tmp");
+ if(KIO::NetAccess::exists(temp,false, this))
+ KIO::NetAccess::del(temp,this);
+
+ bool download = true;
+
+ if(txtfile.exists())
+ {
+ if((KMessageBox::questionYesNo(this, i18n("Selected file already exists, do you want to download it again?"),i18n("File Exists")) == 4))
+ download = false;
+ else
+ KIO::NetAccess::move(target, temp);
+ }
+
+ if(download)
+ {
+ if(!url.isLocalFile())
+ {
+ if (KIO::NetAccess::download(url,target,NULL))
+ {
+ //Level1 list successfully downloaded, remove temporary file
+ KIO::NetAccess::removeTempFile(target);
+ KIO::NetAccess::del(temp, this);
+ }
+ else
+ {
+ QString err = KIO::NetAccess::lastErrorString();
+ if(err != QString::null)
+ KMessageBox::error(0,KIO::NetAccess::lastErrorString(),i18n("Error"));
+ else
+ KIO::NetAccess::move(temp, target);
+
+
+ //we don't want to convert since download failed
+ return;
+ }
+ }
+ else
+ {
+ if (!KIO::NetAccess::file_copy(url,dest, -1, true))
+ {
+ KMessageBox::error(0,KIO::NetAccess::lastErrorString(),i18n("Error"));
+ return;
+ }
+ }
+
+ //now determine if it's ZIP or TXT file
+ KMimeType::Ptr ptr = KMimeType::findByPath(target);
+ if(ptr->name() == "application/x-zip")
+ {
+ KURL zipfile("zip:" + target + "/splist.txt");
+ KURL destinationfile(target + ".txt");
+ KIO::NetAccess::file_copy(zipfile,destinationfile, -1, true);
+ }
+ else
+ {
+ KURL zipfile(target);
+ KURL destinationfile(target + ".txt");
+ KIO::NetAccess::file_copy(zipfile,destinationfile, -1, true);
+ }
+
+ }
+ convert();
+ }
+
+ void IPBlockingPrefPageWidget::checkUseLevel1_toggled(bool check)
+ {
+ if(check)
+ {
+ m_url->setEnabled(true);
+ btnDownload->setEnabled(true);
+ }
+ else
+ {
+ lbl_status1->setText("");
+ m_url->setEnabled(false);
+ btnDownload->setEnabled(false);
+ }
+ }
+
+ void IPBlockingPrefPageWidget::convert()
+ {
+ QFile target(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1.dat");
+ if(target.exists())
+ {
+ if((KMessageBox::questionYesNo(this,i18n("Filter file (level1.dat) already exists, do you want to convert it again?"),i18n("File Exists")) == 4))
+ return;
+// else
+// KIO::NetAccess::del(KGlobal::dirs()->saveLocation("data","ktorrent") + "level1.dat", NULL);
+ }
+ ConvertDialog dlg(m_plugin);
+ dlg.exec();
+ }
+
+ void IPBlockingPrefPageWidget::setPlugin(IPFilterPlugin* p)
+ {
+ m_plugin = p;
+ }
+
+ void IPBlockingPrefPageWidget::setPrefPage( IPBlockingPrefPage * p )
+ {
+ m_prefpage = p;
+ }
+
+ void IPBlockingPrefPageWidget::setConverting(bool enable)
+ {
+ btnDownload->setEnabled(enable);
+ lbl_status1->setText("");
+ }
+
+
+ ////////////////////////////////////////////////////////////////////////////////////
+
+ IPBlockingPrefPage::IPBlockingPrefPage(CoreInterface* core, IPFilterPlugin* p)
+ : PrefPageInterface(i18n("IPBlocking Filter"), i18n("IPBlocking Filter Options"), KGlobal::iconLoader()->loadIcon("filter",KIcon::NoGroup)), m_core(core), m_plugin(p)
+ {
+ widget = 0;
+ }
+
+ IPBlockingPrefPage::~IPBlockingPrefPage()
+ {}
+
+ bool IPBlockingPrefPage::apply()
+ {
+ widget->apply();
+
+ if(IPBlockingPluginSettings::useLevel1())
+ m_plugin->loadAntiP2P();
+ else
+ m_plugin->unloadAntiP2P();
+
+ return true;
+ }
+
+ void IPBlockingPrefPage::createWidget(QWidget* parent)
+ {
+ widget = new IPBlockingPrefPageWidget(parent);
+ widget->setPlugin(m_plugin);
+ widget->setPrefPage(this);
+ }
+
+ void IPBlockingPrefPage::deleteWidget()
+ {
+ delete widget;
+ widget = 0;
+ }
+
+ void IPBlockingPrefPage::updateData()
+ {}
+}
diff --git a/plugins/ipfilter/ipblockingprefpage.h b/plugins/ipfilter/ipblockingprefpage.h
new file mode 100644
index 0000000..3779965
--- /dev/null
+++ b/plugins/ipfilter/ipblockingprefpage.h
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 IPBLOCKINGPREFPAGE_H
+#define IPBLOCKINGPREFPAGE_H
+
+#include <interfaces/prefpageinterface.h>
+#include "ipblockingpref.h"
+#include "ipfilterplugin.h"
+#include <interfaces/coreinterface.h>
+#include <qthread.h>
+#include <qobject.h>
+
+class KProgress;
+
+namespace kt
+{
+ class IPFilterPlugin;
+ class IPBlockingPrefPage;
+
+ /**
+ @author Ivan Vasic
+ */
+ class IPBlockingPrefPageWidget : public IPBlockingPref
+ {
+ public:
+ IPBlockingPrefPageWidget(QWidget *parent = 0);
+ void apply();
+ void convert();
+ void setPlugin(IPFilterPlugin* p);
+ void setPrefPage(IPBlockingPrefPage* p);
+
+ //used with ConvertThread to enable/disable controls while converting
+ void setConverting(bool enable);
+
+ public slots:
+ virtual void btnDownload_clicked();
+ virtual void checkUseLevel1_toggled(bool);
+
+ private:
+ IPFilterPlugin* m_plugin;
+ IPBlockingPrefPage* m_prefpage;
+ };
+
+ /**
+ * @author Ivan Vasic
+ * @brief IPBlocking plugin interface page
+ **/
+ class IPBlockingPrefPage : public PrefPageInterface
+ {
+ public:
+ IPBlockingPrefPage(CoreInterface* core, IPFilterPlugin* p);
+ virtual ~IPBlockingPrefPage();
+
+ virtual bool apply();
+ virtual void createWidget(QWidget* parent);
+ virtual void updateData();
+ virtual void deleteWidget();
+
+ private:
+ CoreInterface* m_core;
+ IPBlockingPrefPageWidget* widget;
+ IPFilterPlugin* m_plugin;
+ };
+}
+#endif
diff --git a/plugins/ipfilter/ipfilterplugin.cpp b/plugins/ipfilter/ipfilterplugin.cpp
new file mode 100644
index 0000000..2f53197
--- /dev/null
+++ b/plugins/ipfilter/ipfilterplugin.cpp
@@ -0,0 +1,129 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 <kgenericfactory.h>
+
+#include <interfaces/coreinterface.h>
+#include <interfaces/guiinterface.h>
+#include <util/constants.h>
+#include <torrent/ipblocklist.h>
+
+#include <qstring.h>
+
+#include "ipfilterplugin.h"
+#include "ipfilterpluginsettings.h"
+#include "antip2p.h"
+
+using namespace bt;
+
+K_EXPORT_COMPONENT_FACTORY(ktipfilterplugin,KGenericFactory<kt::IPFilterPlugin>("ipfilterplugin"))
+
+namespace kt
+{
+ const QString NAME = "IP Filter";
+ const QString AUTHOR = "Ivan Vasic";
+ const QString EMAIL = "ivasic@gmail.com";
+ const QString DESCRIPTION = i18n("Filters out unwanted peers based on their IP address");
+
+ IPFilterPlugin::IPFilterPlugin(QObject* parent, const char* name, const QStringList& args)
+ : Plugin(parent, name, args,NAME,i18n("IP Filter"),AUTHOR,EMAIL,DESCRIPTION,"filter")
+ {
+ // setXMLFile("ktpluginui.rc");
+ level1 = 0;
+ }
+
+
+ IPFilterPlugin::~IPFilterPlugin()
+ {
+ //...just in case something goes wrong...
+ IPBlocklist& ipblist = IPBlocklist::instance();
+ ipblist.unsetPluginInterfacePtr();
+ }
+
+ void IPFilterPlugin::load()
+ {
+ pref = new IPBlockingPrefPage(getCore(), this);
+ getGUI()->addPrefPage(pref);
+
+ if(IPBlockingPluginSettings::useLevel1())
+ loadAntiP2P();
+
+ //now we need to set a pointer to the IPBlocklist
+ IPBlocklist& ipblist = IPBlocklist::instance();
+ ipblist.setPluginInterfacePtr(this);
+ }
+
+ void IPFilterPlugin::unload()
+ {
+ //First unset pointer in IPBlocklist
+ IPBlocklist& ipblist = IPBlocklist::instance();
+ ipblist.unsetPluginInterfacePtr();
+
+ getGUI()->removePrefPage(pref);
+ delete pref;
+ pref = 0;
+ if(level1)
+ {
+ delete level1;
+ level1 = 0;
+ }
+ }
+
+ bool IPFilterPlugin::loadAntiP2P()
+ {
+ if(level1 != 0)
+ return true;
+ level1 = new AntiP2P();
+ if(!level1->exists())
+ {
+ delete level1;
+ level1 = 0;
+ return false;
+ }
+ level1->loadHeader();
+ return true;
+ }
+
+ bool IPFilterPlugin::unloadAntiP2P()
+ {
+ if(level1 != 0)
+ {
+ delete level1;
+ level1 = 0;
+ return true;
+ }
+ else
+ //anything else to check?
+ return true;
+ }
+
+ bool IPFilterPlugin::isBlockedIP(const QString& ip)
+ {
+ if (level1 == 0)
+ return false;
+
+ return level1->isBlockedIP(ip);
+ }
+
+ bool IPFilterPlugin::versionCheck(const QString & version) const
+ {
+ return version == KT_VERSION_MACRO;
+ }
+}
diff --git a/plugins/ipfilter/ipfilterplugin.h b/plugins/ipfilter/ipfilterplugin.h
new file mode 100644
index 0000000..2e9c984
--- /dev/null
+++ b/plugins/ipfilter/ipfilterplugin.h
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * 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 KTIPFILTERPLUGIN_H
+#define KTIPFILTERPLUGIN_H
+
+#include <interfaces/plugin.h>
+#include <interfaces/ipblockinginterface.h>
+
+#include "ipblockingprefpage.h"
+#include "antip2p.h"
+
+class QString;
+
+namespace kt
+{
+ class IPBlockingPrefPage;
+
+ /**
+ * @author Ivan Vasic <ivasic@gmail.com>
+ * @brief IP filter plugin
+ *
+ * This plugin will load IP ranges from specific files into KT IPBlocklist.
+ */
+ class IPFilterPlugin : public Plugin, public kt::IPBlockingInterface
+ {
+ Q_OBJECT
+ public:
+ IPFilterPlugin(QObject* parent, const char* name, const QStringList& args);
+ virtual ~IPFilterPlugin();
+
+ virtual void load();
+ virtual void unload();
+
+ ///Loads the KT format list filter
+ void loadFilters();
+
+ ///Loads the anti-p2p filter list
+ bool loadAntiP2P();
+
+ ///Unloads the anti-p2p filter list
+ bool unloadAntiP2P();
+
+
+ ///Checks if IP is listed in AntiP2P filter list.
+ bool isBlockedIP(const QString& ip);
+
+ bool versionCheck(const QString & version) const;
+ private:
+ IPBlockingPrefPage* pref;
+ AntiP2P* level1;
+ };
+
+}
+
+#endif
diff --git a/plugins/ipfilter/ipfilterpluginsettings.kcfgc b/plugins/ipfilter/ipfilterpluginsettings.kcfgc
new file mode 100644
index 0000000..b9aeaeb
--- /dev/null
+++ b/plugins/ipfilter/ipfilterpluginsettings.kcfgc
@@ -0,0 +1,7 @@
+# Code generation options for kconfig_compiler
+File=ktipfilterplugin.kcfg
+ClassName=IPBlockingPluginSettings
+Namespace=kt
+Singleton=true
+Mutators=true
+# will create the necessary code for setting those variables \ No newline at end of file
diff --git a/plugins/ipfilter/ktipfilterplugin.desktop b/plugins/ipfilter/ktipfilterplugin.desktop
new file mode 100644
index 0000000..3c442a9
--- /dev/null
+++ b/plugins/ipfilter/ktipfilterplugin.desktop
@@ -0,0 +1,56 @@
+[Desktop Entry]
+Name=IPFilterPlugin
+Name[bg]=Приставка за IP-филтриране
+Name[br]=Lugent Sil IP
+Name[de]=IP-Filter-Modul
+Name[el]=Πρόσθετο φίλτρου IP
+Name[es]=Filtro de IP
+Name[et]=IP-filtri plugin
+Name[it]=Plugin filtro ip
+Name[nb]=IP-filtermodul
+Name[nds]="IP-Filter"-Moduul
+Name[nl]=IPFilter-plugin
+Name[pl]=Wtyczka filtru IP
+Name[pt]=Filtro de IPs
+Name[pt_BR]=Plugin de Filtro de IP
+Name[sk]=IPFilter Plugin
+Name[sr]=Прикључак IP филтера
+Name[sr@Latn]=Priključak IP filtera
+Name[sv]=IP-filterinsticksprogram
+Name[tr]=IP Filtre Eklentisi
+Name[xx]=xxIPFilterPluginxx
+Name[zh_CN]=IP 过滤器插件
+Name[zh_TW]=IPFilter外掛程式
+Comment=IP filter plugin for KTorrent
+Comment[ar]=قابس مرشح IP لِــ KTorrent
+Comment[bg]=Приставка за IP-филтриране (KTorrent)
+Comment[br]=Lugent sil IP evit KTorrentt
+Comment[ca]=Connector de filtres d'IP per a Ktorrent
+Comment[cs]=IP filtr modul pro KTorrent
+Comment[de]=IP-Filter-Modul für KTorrent
+Comment[el]=Πρόσθετο φίλτρου IP για το KTorrent
+Comment[es]=Complemento de filtro de IP de KTorrent
+Comment[et]=KTorrenti IP-filtri plugin
+Comment[fa]=وصلۀ پالایۀ IP برای KTorrent
+Comment[gl]=Plugin de filtrado de IPs para KTorrent
+Comment[it]=Plugin filtro ip per KTorrent
+Comment[ja]=KTorrent のための IP フィルタプラグイン
+Comment[ka]=KTorrent-ის IP ფილტრაციის მოდული
+Comment[nb]=IP-filtermodul for KTorrent
+Comment[nds]="IP-Filter"-Moduul för KTorrent
+Comment[nl]=Plugin om op IP-adressen te filteren in KTorrent
+Comment[pl]=Wtyczka filtru IP dla KTorrent
+Comment[pt]='Plugin' de filtragem de IPs do KTorrent
+Comment[pt_BR]=Plugin de Filtro de IP para o KTorrent
+Comment[sk]=IP filter plugin pre KTorrent
+Comment[sr]=Прикључак IP филтера за KTorrent
+Comment[sr@Latn]=Priključak IP filtera za KTorrent
+Comment[sv]=IP-filterinsticksprogram för Ktorrent
+Comment[tr]=KTorrent için IP filtre eklentisi
+Comment[uk]=Втулок фільтрування IP для KTorrent
+Comment[xx]=xxIP filter plugin for KTorrentxx
+Comment[zh_CN]=KTorrent 的 IP 过滤器插件
+Comment[zh_TW]=KTorrent IP 過濾器外掛程式
+ServiceTypes=KTorrent/Plugin
+Type=Service
+X-KDE-Library=ktipfilterplugin
diff --git a/plugins/ipfilter/ktipfilterplugin.kcfg b/plugins/ipfilter/ktipfilterplugin.kcfg
new file mode 100644
index 0000000..18ab419
--- /dev/null
+++ b/plugins/ipfilter/ktipfilterplugin.kcfg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+
+ <kcfgfile name="ktipfilterpluginrc"/>
+ <group name="general">
+ <entry name="filterURL" type="String">
+ <label>Level1 filter url</label>
+ <default></default>
+ </entry>
+ <entry name="useLevel1" type="Bool">
+ <label>Use level1 filter?</label>
+ <default>FALSE</default>
+ </entry>
+ </group>
+</kcfg>