From c3b707c026782768bd8c0e6ae6b574fe8a36802d Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 17 Feb 2010 01:04:17 +0000 Subject: Added old abandoned KDE3 version of kmyfirewall git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmyfirewall@1091559 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- KMFSysTray/Makefile.am | 22 ++ KMFSysTray/README | 4 + KMFSysTray/app.cpp | 63 +++++ KMFSysTray/app.h | 27 +++ KMFSysTray/details.cpp | 109 +++++++++ KMFSysTray/details.h | 54 +++++ KMFSysTray/details_designer.ui | 484 ++++++++++++++++++++++++++++++++++++++ KMFSysTray/kmfiptwatcher.cpp | 306 ++++++++++++++++++++++++ KMFSysTray/kmfiptwatcher.h | 73 ++++++ KMFSysTray/kmfsystray.cpp | 166 +++++++++++++ KMFSysTray/kmfsystray.desktop | 36 +++ KMFSysTray/kmfsystray.h | 80 +++++++ KMFSysTray/main.cpp | 57 +++++ KMFSysTray/mainwidget.cpp | 74 ++++++ KMFSysTray/mainwidget.h | 61 +++++ KMFSysTray/mainwidget_designer.ui | 88 +++++++ 16 files changed, 1704 insertions(+) create mode 100644 KMFSysTray/Makefile.am create mode 100644 KMFSysTray/README create mode 100644 KMFSysTray/app.cpp create mode 100644 KMFSysTray/app.h create mode 100644 KMFSysTray/details.cpp create mode 100644 KMFSysTray/details.h create mode 100644 KMFSysTray/details_designer.ui create mode 100644 KMFSysTray/kmfiptwatcher.cpp create mode 100644 KMFSysTray/kmfiptwatcher.h create mode 100644 KMFSysTray/kmfsystray.cpp create mode 100644 KMFSysTray/kmfsystray.desktop create mode 100644 KMFSysTray/kmfsystray.h create mode 100644 KMFSysTray/main.cpp create mode 100644 KMFSysTray/mainwidget.cpp create mode 100644 KMFSysTray/mainwidget.h create mode 100644 KMFSysTray/mainwidget_designer.ui (limited to 'KMFSysTray') diff --git a/KMFSysTray/Makefile.am b/KMFSysTray/Makefile.am new file mode 100644 index 0000000..a1fb991 --- /dev/null +++ b/KMFSysTray/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES= -I$(srcdir)/../kmyfirewall/core -I$(srcdir)/../kmyfirewall/kmfwidgets -I$(srcdir)/../kmyfirewall/interfaces $(all_includes) +METASOURCES = AUTO + +bin_PROGRAMS = kmfsystray + + + + + +kmfsystray_LDFLAGS = $(KDE_RPATH) $(all_libraries) +kmfsystray_LDADD = ../kmyfirewall/core/libkmfcore.la ../kmyfirewall/kmfwidgets/libkmfwidgets.la $(LIB_KDEUI) $(LIB_KPARTS) + +kmfsystray_DATA = kmfsystray.desktop +kmfsystraydir = $(kde_datadir)/kicker/applets + +messages: rc.cpp + $(EXTRACTRC) `find . -name \*.ui -o -name \*.rc` > rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kmfsystray.pot + + +kmfsystray_SOURCES = kmfsystray.cpp app.cpp mainwidget.cpp \ + mainwidget_designer.ui details.cpp details_designer.ui kmfiptwatcher.cpp main.cpp diff --git a/KMFSysTray/README b/KMFSysTray/README new file mode 100644 index 0000000..8aadbd2 --- /dev/null +++ b/KMFSysTray/README @@ -0,0 +1,4 @@ +KMFSysTray +---------- + +Systray applet that show the running iptables configuration in KMF's iptables rule view. It communicates with the KMFIPTInterface to fetch the running iptables configuration. diff --git a/KMFSysTray/app.cpp b/KMFSysTray/app.cpp new file mode 100644 index 0000000..bacfda0 --- /dev/null +++ b/KMFSysTray/app.cpp @@ -0,0 +1,63 @@ +// +// C++ Implementation: app +// +// Description: +// +// +// Author: Christian Hubinger , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "app.h" + +// #include +// #include +// +// // KDE includes +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include + + +/* +#include "kmfsystray.h" +#include "kmfiptwatcher.h" +#include "mainwidget.h" +*/ + +MainApp::MainApp() : KApplication() { + + + // Get the current application configuration handle +// KMessageBox::information( 0, i18n( "Starting Deamon" ) ); + +// KConfig *ksConfig = config(); +// KMFIPTWatcher *watch = new KMFIPTWatcher( this, "KMFIPTWatcher" ); +// MainWidget *mainWid = new MainWidget( 0 ); +// connect( watch, SIGNAL( sigUpdateActive( bool ) ), mainWid, SLOT( slotSetRunningStatus( bool ) ) ); +// connect( watch, SIGNAL( sigUpdateRuleCount( const QString&, const QString&, int ) ), +// mainWid, SIGNAL( sigUpdateRuleCount( const QString&, const QString&, int ) ) ); + +// connect( mainWid, SIGNAL( sigQueryDetails( bool ) ), watch, SLOT( slotQueryDetails( bool ) ) ); +/* + QHBoxLayout *_layout = new QHBoxLayout(this); + _layout->add(mainWid);*/ + + + + + +} + + +MainApp::~MainApp() {} + + diff --git a/KMFSysTray/app.h b/KMFSysTray/app.h new file mode 100644 index 0000000..2056072 --- /dev/null +++ b/KMFSysTray/app.h @@ -0,0 +1,27 @@ +// +// C++ Interface: app +// +// Description: +// +// +// Author: Christian Hubinger , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef APP_H +#define APP_H + +#include + +/** +@author Christian Hubinger +*/ +class MainApp : public KApplication { +public: + MainApp(); + ~MainApp(); + +}; + +#endif diff --git a/KMFSysTray/details.cpp b/KMFSysTray/details.cpp new file mode 100644 index 0000000..067d697 --- /dev/null +++ b/KMFSysTray/details.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** +* Copyright (C) 2005 by Christian Hubinger * +* e9806056@student.tuwien.ac.at * +* * +* 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 "details.h" + +// QT includes +#include + +// KDE includes +#include +#include + +Details::Details( QWidget* parent, const char* name, WFlags fl ) + : DetailsDesigner( parent, name, fl ) { + + QObject::connect( m_cmd_close, SIGNAL( clicked() ), this, SLOT ( close() ) ); + +} + +Details::~Details() {} + +/*$SPECIALIZATION$*/ + +void Details::close() { + kdDebug() << "void Details::close()" << endl; + emit closing(); + QWidget::close(); +} + +void Details::show() { + kdDebug() << "void Details::show()" << endl; + emit showing(); + QWidget::show(); +} + +void Details::hide() { + kdDebug() << "void Details::hide()" << endl; + emit closing(); + QWidget::hide(); +} + +void Details::slotUpdateRuleCount( const QString& table, const QString& chain, int num ) { + kdDebug() << "slotUpdateRuleCount( const QString& " << table << ", const QString& " << chain << ", int " << num << " )" << endl; + QLCDNumber *lcd = 0; + if ( table == "filter" ) { + if ( chain == "INPUT" ) { + lcd = m_lcd_numRulesIn_Filter_Input; + } + if ( chain == "OUTPUT" ) { + lcd = m_lcd_numRulesIn_Filter_Output; + } + if ( chain == "FORWARD" ) { + lcd = m_lcd_numRulesIn_Filter_Forward; + } + } else if ( table == "nat" ) { + if ( chain == "OUTPUT" ) { + lcd = m_lcd_numRulesIn_Nat_Output; + } + if ( chain == "PREROUTING" ) { + lcd = m_lcd_numRulesIn_Nat_Prerouting; + } + if ( chain == "POSTROUTING" ) { + lcd = m_lcd_numRulesIn_Nat_Postrouting; + } + } else if ( table == "mangle" ) { + if ( chain == "INPUT" ) { + lcd = m_lcd_numRulesIn_Mangle_Input; + } + if ( chain == "OUTPUT" ) { + lcd = m_lcd_numRulesIn_Mangle_Output; + } + if ( chain == "FORWARD" ) { + lcd = m_lcd_numRulesIn_Mangle_Forward; + } + if ( chain == "PREROUTING" ) { + lcd = m_lcd_numRulesIn_Mangle_Prerouting; + } + if ( chain == "POSTROUTING" ) { + lcd = m_lcd_numRulesIn_Mangle_Postrouting; + } + + } + if ( ! lcd ) { + kdDebug() << "ERROR unknown chain or table" << endl; + return; + } + lcd->display( num ); +} + +#include "details.moc" + diff --git a/KMFSysTray/details.h b/KMFSysTray/details.h new file mode 100644 index 0000000..b468f09 --- /dev/null +++ b/KMFSysTray/details.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* Copyright (C) 2005 by Christian Hubinger * +* e9806056@student.tuwien.ac.at * +* * +* 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 DETAILS_H +#define DETAILS_H + +#include "details_designer.h" + +class Details : public DetailsDesigner { + Q_OBJECT + +public: + Details( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~Details(); + /*$PUBLIC_FUNCTIONS$*/ + +public slots: + /*$PUBLIC_SLOTS$*/ + void close(); + void show(); + void hide(); + void slotUpdateRuleCount( const QString&, const QString&, int ); +protected: + /*$PROTECTED_FUNCTIONS$*/ + +protected slots: + /*$PROTECTED_SLOTS$*/ + + +signals: + void closing(); + void showing(); + +}; + +#endif + diff --git a/KMFSysTray/details_designer.ui b/KMFSysTray/details_designer.ui new file mode 100644 index 0000000..9a5b1f9 --- /dev/null +++ b/KMFSysTray/details_designer.ui @@ -0,0 +1,484 @@ + +DetailsDesigner + + + DetailsDesigner + + + + 0 + 0 + 314 + 217 + + + + + unnamed + + + 2 + + + 2 + + + + m_cmd_close + + + Close &Window + + + + + m_cmd_help + + + &Help + + + + + widgetStack1 + + + + 5 + 3 + 0 + 0 + + + + + WStackPage + + + 0 + + + + unnamed + + + + m_lbl_numRules_Filter_Input + + + INPUT: + + + + + m_lcd_numRulesIn_Filter_Input + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRules_Filter_Output + + + OUTPUT: + + + + + m_lcd_numRulesIn_Filter_Output + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRules_Filter_Forward + + + FORWARD: + + + + + m_lcd_numRulesIn_Filter_Forward + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInfilter_2_3_5_3 + + + POLICY: + + + + + m_lbl_numRulesInfilter_2_3_5_2 + + + POLICY: + + + + + m_lbl_policy_filter_output + + + <Policy> + + + + + m_lbl_policy_filter_forward + + + <Policy> + + + + + m_lbl_numRulesInfilter_2_3_5 + + + POLICY: + + + + + m_lbl_policy_filter_input + + + <Policy> + + + + + + + WStackPage + + + 1 + + + + unnamed + + + + m_lbl_numRulesInfilter_2 + + + OUTPUT: + + + + + m_lbl_policy_nat_output + + + <Policy> + + + + + m_lcd_numRulesIn_Nat_Output + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInfilter_2_3 + + + POLICY: + + + + + m_lbl_numRulesInfilter_2_3_2 + + + POLICY: + + + + + m_lcd_numRulesIn_Nat_Prerouting + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInNat_2_2 + + + PREROUTING: + + + + + m_lbl_policy_nat_prerouting + + + <Policy> + + + + + m_lcd_numRulesIn_Nat_Postrouting + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInfilter_2_3_3 + + + POLICY: + + + + + m_lbl_policy_filter_nat_postrouting + + + <Policy> + + + + + m_lbl_numRulesInNat_2 + + + POSTROUTING: + + + + + + + WStackPage + + + 2 + + + + unnamed + + + + m_lcd_numRulesIn_Mangle_Input + + + + 1 + 0 + 0 + 0 + + + + + + m_lcd_numRulesIn_Mangle_Output + + + + 1 + 0 + 0 + 0 + + + + + + m_lcd_numRulesIn_Mangle_Forward + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInMangle_2_2 + + + FORWARD: + + + + + m_lbl_numRulesInfilter_2_2 + + + OUTPUT: + + + + + m_lbl_numRulesInfilter_2_2_2 + + + INPUT: + + + + + m_lbl_numRulesInNat_2_2_2 + + + PREROUTING: + + + + + m_lcd_numRulesIn_Mangle_Postrouting + + + + 1 + 0 + 0 + 0 + + + + + + m_lbl_numRulesInNat_2_3 + + + POSTROUTING: + + + + + m_lcd_numRulesIn_Mangle_Prerouting + + + + 1 + 0 + 0 + 0 + + + + + + + + + lbl_table + + + Table: + + + AlignVCenter + + + + + + Filter + + + + + Nat + + + + + Mangle + + + + kComboBox1 + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 51 + 20 + + + + + + + + kComboBox1 + activated(int) + widgetStack1 + raiseWidget(int) + + + + + kpushbutton.h + kpushbutton.h + kcombobox.h + + diff --git a/KMFSysTray/kmfiptwatcher.cpp b/KMFSysTray/kmfiptwatcher.cpp new file mode 100644 index 0000000..c2f8c1a --- /dev/null +++ b/KMFSysTray/kmfiptwatcher.cpp @@ -0,0 +1,306 @@ +/*************************************************************************** +* Copyright (C) 2005 by Christian Hubinger * +* e9806056@student.tuwien.ac.at * +* * +* 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 "kmfiptwatcher.h" + + +// QT includes +#include + +// KDE includes +#include +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "../core/kmfiptdoc.h" +#include "../core/kmferror.h" +#include "../core/iptable.h" +#include "../core/iptchain.h" +#include "../core/iptrule.h" +#include "../core/iptruleoption.h" + +KMFIPTWatcher::KMFIPTWatcher( QObject *parent, const char *name ) + : QObject( parent, name ) { + m_queryExtendedInfo = true; + m_doc = new KMFIPTDoc( 0, "iptdoc" ); + go(); +} + + +KMFIPTWatcher::~KMFIPTWatcher() {} + + +void KMFIPTWatcher::go() { + // KMessageBox::information( 0, i18n( "go()" ) ); + m_timer = new QTimer(); + QObject::connect( m_timer, SIGNAL( timeout() ), this, SLOT( timeout() ) ); + m_timer->start( 3000, false ); +} + +void KMFIPTWatcher::timeout() { +// kdDebug() << "timeout()" << endl; + + + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + QString arg = "filter"; + stream << arg; + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "numChainsInTable(QString)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + + // KMessageBox::information( 0, i18n( "Error with DCOP: %1" ).arg( kapp->dcopClient() ->appId() ) ); + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "int" ) { + int result; + answer >> result; + // KMessageBox::information( 0, i18n( "Got answer %1" ).arg(result) ); + emit sigUpdateActive( result > 0 ); + } else + KMessageBox::information( 0, i18n( "Calling over DCOP succeeded, but the answer had wrong type!" ) ); + } + + if ( m_queryExtendedInfo ) { + queryExtendedInfo(); + } +} + +void KMFIPTWatcher::queryExtendedInfo() { + queryChainsInTable( "filter", m_doc ); + queryChainsInTable( "nat", m_doc ); + queryChainsInTable( "mangle", m_doc ); + kdDebug() << "emit sigUpdateIPTDoc( m_doc )" << endl; + emit sigUpdateIPTDoc( m_doc ); +} + +void KMFIPTWatcher::queryChainsInTable( const QString& table, KMFIPTDoc* iptdoc ) { + kdDebug() << "queryNumRulesInChain( const QString& table, const QString& chain )" << endl; + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + stream << table; + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "getChainsInTable(QString)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "QStringList" ) { + QStringList result; + answer >> result; + IPTable *tableObj = iptdoc->table( table ); + kdDebug() << "Filling Table: " << tableObj->name() << endl; + QPtrList *used = new QPtrList; + for ( QStringList::Iterator it = result.begin(); it != result.end(); ++it ) { + kdDebug() << "Found Chain" << *it << endl; + IPTChain *chain = tableObj->chainForName( *it ); + if ( ! chain ) { + QString tg = "ACCEPT"; + tableObj->addChain( *it, tg, false, new KMFError() ); + } + fetchChainPolicy( tableObj->chainForName( *it ) ); + fetchRulesInChain( tableObj->chainForName( *it ) ); + used->append( tableObj->chainForName( *it ) ); + } + + QPtrListIterator it_chains( tableObj->chains() ); + IPTChain* found_chain = 0; + while ( it_chains.current() ) { + found_chain = it_chains.current(); + bool found = false; + for ( QStringList::Iterator it_all = result.begin(); it_all != result.end(); ++it_all ) { + if ( *it_all == found_chain->name() ) { + found = true; + } + } + kdDebug() << "Found chain: " << found_chain->name() << " " << found << endl; + if ( ! found ) { + tableObj->delChain( found_chain ); + } + ++it_chains; + } + + + } else { + KMessageBox::information( 0, i18n( "Calling over DCOP succeeded, but the answer had wrong type!" ) ); + } + } +} + +void KMFIPTWatcher::fetchChainPolicy( IPTChain* chain ) { + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + stream << chain->table()->name() << chain->name(); + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "getChainPolicy(QString,QString)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "QString" ) { + QString result; + answer >> result; + kdDebug() << "Found Chain Policy: " << chain->table()->name() << " " << chain->name() << " " << result << endl; + chain->setDefaultTarget( result ); + } + } +} + +void KMFIPTWatcher::fetchRulesInChain( IPTChain* chain ) { + kdDebug() << "fetchRulesInChain( const QString& table, const QString& chain )" << endl; + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + stream << chain->table()->name() << chain->name(); + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "numRulesInChain(QString,QString)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "int" ) { + int result; + answer >> result; + QPtrList *used = new QPtrList; + for ( int i = 0; i < result; i++ ) { + QString rn = QString("rule_%1").arg( i ); + IPTRule *rule = 0; + rule = chain->ruleForName( rn ); + if ( ! rule ) { + rule = chain->addRule( rn , new KMFError() ); + } + fetchRulesProperties( rule, i ); + used->append( rule ); + } + + QPtrListIterator it_rules( chain->chainRuleset() ); + IPTRule* found_rule = 0; + while ( it_rules.current() ) { + found_rule = it_rules.current(); + bool found = false; + for ( int i = 0; i < result; i++ ) { + QString rn = QString("rule_%1").arg( i ); + if ( rn == found_rule->name() ) { + found = true; + } + } + if ( ! found ) { + chain->delRule( found_rule ); + } + ++it_rules; + } + } else { + KMessageBox::information( 0, i18n( "Calling over DCOP succeeded, but the answer had wrong type!" ) ); + } + } +} + +void KMFIPTWatcher::fetchRulesProperties( IPTRule* rule, int index ) { + kdDebug() << "queryNumRulesInChain( const QString& table, const QString& chain )" << endl; + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + stream << rule->chain()->table()->name() << rule->chain()->name() << index; + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "getRuleProperties(QString,QString,int)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "QStringList" ) { + QStringList result; + answer >> result; + if ( *result.at( 0 ) == "ERROR" ) { + return; + } + rule->setTarget( *result.at( 0 ) ); + + + } else { + KMessageBox::information( 0, i18n( "Calling over DCOP succeeded, but the answer had wrong type!" ) ); + } + } + +} + + +void KMFIPTWatcher::queryNumRulesInChain( const QString& table, const QString& chain, KMFIPTDoc* doc ) { + kdDebug() << "queryNumRulesInChain( const QString& table, const QString& chain )" << endl; + DCOPClient *client = kapp->dcopClient(); + QCString reply_type; + QByteArray params; + QDataStream stream( params, IO_WriteOnly ); + stream << table << chain; + QByteArray reply_data; + + if ( ! client->call( *( new QCString( "kmfiptinterface" ) ), + *( new QCString( "KMFIPTInterface" ) ), + *( new QCString( "numRulesInChain(QString,QString)" ) ), params, + reply_type, reply_data, false, 10000 ) ) { + emit sigUpdateActive( false ); + } else { + QDataStream answer( reply_data, IO_ReadOnly ); + if ( reply_type == "int" ) { + int result; + answer >> result; + + } else + KMessageBox::information( 0, i18n( "Calling over DCOP succeeded, but the answer had wrong type!" ) ); + } +} + +void KMFIPTWatcher::worked() { + KMessageBox::information( 0, i18n( "Callback Worked" ) ); +} + +void KMFIPTWatcher::slotQueryDetails( bool on ) { + kdDebug() << "slotQueryDetails( bool " << on << " )" << endl; + m_queryExtendedInfo = on; +} +#include "kmfiptwatcher.moc" diff --git a/KMFSysTray/kmfiptwatcher.h b/KMFSysTray/kmfiptwatcher.h new file mode 100644 index 0000000..c6c27f8 --- /dev/null +++ b/KMFSysTray/kmfiptwatcher.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christian Hubinger * + * e9806056@student.tuwien.ac.at * + * * + * 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 KMFIPTWATCHER_H +#define KMFIPTWATCHER_H + +#include + +/** +@author Christian Hubinger +*/ + +class QTimer; +class KMFIPTDoc; +class IPTChain; +class IPTable; +class IPTRule; +class IPTRuleOption; + +class KMFIPTWatcher : public QObject +{ +Q_OBJECT +public: + KMFIPTWatcher(QObject *parent = 0, const char *name = 0); + + ~KMFIPTWatcher(); + +public slots: + void slotQueryDetails( bool ); + +private slots: + void timeout(); + void worked(); + + +private: + void go(); + void queryExtendedInfo(); + void queryNumRulesInChain( const QString& /*table*/, const QString& /*Chain*/, KMFIPTDoc* /* doc */ ); + void queryChainsInTable( const QString& /*table*/, KMFIPTDoc* /* doc */ ); + + QTimer *m_timer; + bool m_queryExtendedInfo; + + void fetchChainPolicy( IPTChain* ); + void fetchRulesInChain( IPTChain* ); + void fetchRulesProperties( IPTRule*, int ); + + KMFIPTDoc *m_doc; +signals: + void sigUpdateIPTDoc( KMFIPTDoc* ); + void sigUpdateActive( bool ); + void sigUpdateRuleCount( const QString& /*table*/, const QString& /*Chain*/, int ); + +}; + +#endif diff --git a/KMFSysTray/kmfsystray.cpp b/KMFSysTray/kmfsystray.cpp new file mode 100644 index 0000000..bea6399 --- /dev/null +++ b/KMFSysTray/kmfsystray.cpp @@ -0,0 +1,166 @@ +/************************************************************************** +* Copyright (C) 2005 by Christian Hubinger * +* e9806056@student.tuwien.ac.at * +* * +* 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. * +***************************************************************************/ + + +// QT includes +#include +#include + +// KDE includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "kmfsystray.h" +#include "kmfiptwatcher.h" +#include "mainwidget.h" + +#include "../core/kmfiptdoc.h" +#include "../core/kmfappstate.h" + +KMFSysTray::KMFSysTray( QWidget* w ) : KSystemTray ( w ) , DCOPObject( "KMFSysTray" ) { + mainView = w; + ksConfig = kapp->config(); + KMFIPTWatcher *watch = new KMFIPTWatcher( this, "KMFIPTWatcher" ); + + baseIcon = KSystemTray::loadIcon( "kmyfirewall" ); + setPixmap( baseIcon ); + + // Connect the watch deamon + connect( watch, SIGNAL( sigUpdateActive( bool ) ), this, SLOT( slotSetRunningStatus( bool ) ) ); + connect( watch, SIGNAL( sigUpdateRuleCount( const QString&, const QString&, int ) ), + this, SIGNAL( sigUpdateRuleCount( const QString&, const QString&, int ) ) ); + + connect( watch, SIGNAL( sigUpdateIPTDoc( KMFIPTDoc* ) ), + this, SIGNAL( sigUpdateIPTDoc( KMFIPTDoc* ) ) ); + + connect( this, SIGNAL( sigQueryDetails( bool ) ), watch, SLOT( slotQueryDetails( bool ) ) ); + + // Connect view + connect( w, SIGNAL( closing() ), this, SLOT ( slotDetailsClosed() ) ); + connect( w, SIGNAL( showing() ), this, SLOT ( slotQueryDetails() ) ); + connect( this, SIGNAL( sigUpdateIPTDoc( KMFIPTDoc* ) ), w, SLOT( slotLoadDoc( KMFIPTDoc* ) ) ); + + + initMenu(); + + show(); + emit sigQueryDetails( false ); + KMFAppState::setUpAndRunning( true ); + KMFAppState::setHasOpenDoc( true ); +} + + +KMFSysTray::~KMFSysTray() {} + +void KMFSysTray::initMenu() { + KPopupMenu* menu = contextMenu (); + menu->insertItem( KGlobal::iconLoader()->loadIcon( "kmyfirewall", KIcon::Small ), i18n( "Launch KMyFirewall..."), this, SLOT( slotLaunchKMF() ), CTRL+Key_K ); + +} + +void KMFSysTray::slotSetRunningStatus( bool on ) { + if ( on ) { + baseIcon = KSystemTray::loadIcon( "kmyfirewall" ); + } else { + baseIcon = KSystemTray::loadIcon( "kmyfirewall" ); + } + setPixmap( baseIcon ); +} + + + +void KMFSysTray::slotLaunchKMF () { + KProcess *childproc = new KProcess(); + *childproc << "kdesu"; + *childproc << "kmyfirewall"; + childproc->start( KProcess:: DontCare, KProcess::NoCommunication ); +} + +void KMFSysTray::slotShowDetails() { + kdDebug() << "MFSysTray::slotshowDetails()" << endl; + slotQueryDetails(); + mainView->show(); + +} + +void KMFSysTray::slotQueryDetails() { + emit sigQueryDetails( true ); +} + +void KMFSysTray::slotDetailsClosed() { + kdDebug() << "KMFSysTray::slotDetailsClosed()" << endl; + emit sigQueryDetails( false ); +} + +void KMFSysTray::about() { +/* if(!_aboutData) { + _aboutData = new KAboutData("KMFSysTray", I18N_NOOP("KMFSysTray"), + "1.0", I18N_NOOP("KMyFirewall Pannel Applet.\n\n" + "Some basic informaddAuthor("Christian Hubinger", 0, "e9806056@student.tuwien.ac.at"); + + } + KAboutApplication dialog(_aboutData); + dialog.show();*/ +} + + +void KMFSysTray::help() { + KMessageBox::information( 0, i18n( "This is a help box" ) ); +} + + +void KMFSysTray::preferences() { + KMessageBox::information( 0, i18n( "This is a preferences box" ) ); +} + +int KMFSysTray::widthForHeight( int ) const { + return width(); +} + +int KMFSysTray::heightForWidth( int ) const { + return height(); +} + +void KMFSysTray::resizeEvent( QResizeEvent *e ) {} + + +// extern "C" { +// KPanelApplet * init( QWidget * parent, const QString & configFile ) { +// KGlobal::locale() ->insertCatalogue( "kmfsystray" ); +// return new KMFSysTray( configFile, KPanelApplet::Normal, +// KPanelApplet::About | KPanelApplet::Help | KPanelApplet::Preferences, +// parent, "kmfsystray" ); +// } +// } + + diff --git a/KMFSysTray/kmfsystray.desktop b/KMFSysTray/kmfsystray.desktop new file mode 100644 index 0000000..6c6d0b7 --- /dev/null +++ b/KMFSysTray/kmfsystray.desktop @@ -0,0 +1,36 @@ +[Desktop Entry] +Encoding=UTF-8 +Comment=A panel applet called $NAME$ +Comment[bg]=Аплет с име $NAME$ +Comment[br]=Un arloadig panell a vez graet $NAME$ +Comment[ca]=Un applet del plafó anomenat $NAME$ +Comment[cs]=Applet panelu $NAME$ +Comment[cy]=Rhaglennig panel o'r enw $NAME$ +Comment[da]=En applet for panelet som hedder $NAME$ +Comment[de]=Eine Bedienfläche mit dem Namen $NAME$ +Comment[el]=Μία μικροεφαρμογή πίνακα με όνομα $NAME$ +Comment[es]=Una miniaplicación para el panel llamada $NAME$ +Comment[et]=Paneeliaplett $NAME$ +Comment[fr]=Une applet appelée $NAME$ +Comment[ga]=Feidhmchláirín painéil darbh ainm $NAME$ +Comment[gl]=Unha applet do painel chamada $NAME$ +Comment[it]=Un applet per il pannello chiamato $NAME$ +Comment[ka]=პანელის აპლეტი სახელად $NAME$ +Comment[lt]=Pulto įskiepis, vadinamas $NAME$ +Comment[nl]=Een paneelapplet genaamd $NAME$ +Comment[pt]=Um 'applet' para o painel chamado $NAME$ +Comment[pt_BR]=Um mini-aplicativo para o painel chamado $NAME$ +Comment[sr]=Аплет за панел назван $NAME$ +Comment[sr@Latn]=Aplet za panel nazvan $NAME$ +Comment[sv]=Ett miniprogram för panelen som heter $NAME$ +Comment[tr]=$NAME$ isimli panel küçük uygulaması +Comment[uk]=Аплет панелі $NAME$ +Comment[xx]=xxA panel applet called $NAME$xx +Name=KMFSysTray +Name[da]=KFTPGrabber +Name[pt_BR]=Mini-aplicativo de painel +Name[sv]=Min brandväggs systembricka +Name[tr]=KMF Sistem Çekmecesi +Name[xx]=xxKMFSysTrayxx +X-KDE-Library=kmfsystray_panelapplet +X-KDE-UniqueApplet = true diff --git a/KMFSysTray/kmfsystray.h b/KMFSysTray/kmfsystray.h new file mode 100644 index 0000000..9eb4b8a --- /dev/null +++ b/KMFSysTray/kmfsystray.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christian Hubinger * + * e9806056@student.tuwien.ac.at * + * * + * 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 KMFSYSTRAY_H +#define KMFSYSTRAY_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +// QT includes +#include +#include + +// KDE Includes +#include +#include +#include +#include + +class KAboutData; +class KMFIPTDoc; + +class KMFSysTray : public KSystemTray, public DCOPObject +{ + Q_OBJECT + +public: + KMFSysTray( QWidget * ); + virtual ~KMFSysTray(); + virtual int widthForHeight(int height) const; + virtual int heightForWidth(int width) const; + virtual void about(); + virtual void help(); + virtual void preferences(); + +public slots: + void slotSetRunningStatus( bool on ); + void slotLaunchKMF(); + void slotShowDetails(); + void slotQueryDetails(); + void slotDetailsClosed(); + +protected: + void resizeEvent(QResizeEvent *); + +private: // Methods + void initMenu(); + +private: + KAboutData *_aboutData; + KConfig *ksConfig; + QWidget *mainView; + QPixmap baseIcon; + +signals: + void sigUpdateIPTDoc( KMFIPTDoc* ); + void sigQueryDetails( bool ); + void sigUpdateRuleCount( const QString&, const QString&, int ); +}; + +#endif diff --git a/KMFSysTray/main.cpp b/KMFSysTray/main.cpp new file mode 100644 index 0000000..fe24ce8 --- /dev/null +++ b/KMFSysTray/main.cpp @@ -0,0 +1,57 @@ +// +// C++ Implementation: main +// +// Description: +// +// +// Author: Christian Hubinger , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include + +#include +#include +#include +#include +#include +#include +#include + + +#include "../kmyfirewall/version.h" +#include "../kmyfirewall/kmfwidgets/kmfiptdocview.h" + + +#include "kmfsystray.h" +#include "kmfiptwatcher.h" +#include "details.h" + + +static const char description[] = I18N_NOOP( "KMFSysTray - IPTables monitor" ); + + +static KCmdLineOptions options[] = { + { "+[URL]", I18N_NOOP( "Files/URLs to Open." ), 0 }, + { "--test ", I18N_NOOP("A short option which takes an argument."), 0 }, + { 0, 0, 0} +}; + +int main( int argc, char *argv[] ) { + KAboutData aboutData( "kmfsystray", I18N_NOOP( "KMFSysTray" ), + KMYFIREWALL_VERSION, description, KAboutData::License_GPL, + COPYRIGHT_STRING, 0, 0, "e9806056@student.tuwien.ac.at" ); + aboutData.addAuthor( "Christian Hubinger", 0, "e9806056@student.tuwien.ac.at" ); + aboutData.setHomepage( "http://kmyfirewall.sourceforge.net" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + KApplication a; + // Details *mainWid = new Details( 0 ); + + KMFIPTDocView *mainWid = new KMFIPTDocView( 0 ); + KMFSysTray *st = new KMFSysTray( mainWid ); + return a.exec(); +} diff --git a/KMFSysTray/mainwidget.cpp b/KMFSysTray/mainwidget.cpp new file mode 100644 index 0000000..5eeded9 --- /dev/null +++ b/KMFSysTray/mainwidget.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christian Hubinger * + * e9806056@student.tuwien.ac.at * + * * + * 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 "mainwidget.h" + +// QT includes +#include +#include +#include + +// KDE includes +#include +#include + +// Project Includes +#include "details.h" + +MainWidget::MainWidget(QWidget* parent, const char* name, WFlags fl) +: MainWidgetDesigner(parent,name,fl) +{ + m_ledActive->off(); + m_cmd_info->setEnabled( false ); + m_wid_details = new Details( 0 ); + connect( m_wid_details, SIGNAL( closing() ), this, SLOT ( slotDetailsClosed() ) ); + connect( this, SIGNAL( sigUpdateRuleCount( const QString&, const QString&, int ) ), + m_wid_details, SLOT( slotUpdateRuleCount( const QString&, const QString&, int ) ) ); + connect( m_cmd_info, SIGNAL( clicked() ), this, SLOT( slotShowDetails() ) ) ; +} + +MainWidget::~MainWidget() +{ +} + +void MainWidget::slotSetRunningStatus( bool on ) { + m_ledActive->on(); + m_cmd_info->setEnabled( on ); + if ( on ) { + m_ledActive -> setColor( QColor(0, 255, 0) ); + } else { + m_ledActive -> setColor( QColor(255, 0, 0) ); + } +} + + +void MainWidget::slotDetailsClosed() { + emit sigQueryDetails( false ); +} + +void MainWidget::slotShowDetails() { + emit sigQueryDetails( true ); + m_wid_details->show(); + m_wid_details->raise(); +} + +#include "mainwidget.moc" + diff --git a/KMFSysTray/mainwidget.h b/KMFSysTray/mainwidget.h new file mode 100644 index 0000000..aeae571 --- /dev/null +++ b/KMFSysTray/mainwidget.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2005 by Christian Hubinger * + * e9806056@student.tuwien.ac.at * + * * + * 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 MAINWIDGET_H +#define MAINWIDGET_H + +#include "mainwidget_designer.h" + +class Details; + + +class MainWidget : public MainWidgetDesigner +{ + Q_OBJECT + +public: + MainWidget(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~MainWidget(); + /*$PUBLIC_FUNCTIONS$*/ + +public slots: + void slotSetRunningStatus( bool ); + void slotDetailsClosed(); + +protected: + /*$PROTECTED_FUNCTIONS$*/ + +protected slots: + /*$PROTECTED_SLOTS$*/ + +private slots: + void slotShowDetails(); + +private: + Details *m_wid_details; + + +signals: + void sigQueryDetails( bool ); + void sigUpdateRuleCount( const QString&, const QString&, int ); +}; + +#endif + diff --git a/KMFSysTray/mainwidget_designer.ui b/KMFSysTray/mainwidget_designer.ui new file mode 100644 index 0000000..abdb834 --- /dev/null +++ b/KMFSysTray/mainwidget_designer.ui @@ -0,0 +1,88 @@ + +MainWidgetDesigner + + + MainWidgetDesigner + + + + 0 + 0 + 124 + 34 + + + + ParentOrigin + + + + unnamed + + + 2 + + + 2 + + + + m_ledActive + + + + 0 + 5 + 0 + 0 + + + + + 30 + 30 + + + + + 30 + 30 + + + + On + + + Circular + + + Flat + + + 300 + + + + + m_cmd_info + + + + 3 + 1 + 1 + 0 + + + + Info + + + + + + + kled.h + kpushbutton.h + + -- cgit v1.2.1