summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/ruleoptionplugins/log_target_option/kmfruleedittargetlog.cpp
blob: 34635625eb8f6385ca0c507f194deb9c806604f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/***************************************************************************
 begin                : Wed May 22 2002
 copyright            : (C) 2002 by Christian Hubinger
 email                : chubinger@irrsinnig.org
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kmfruleedittargetlog.h" 

// QT includes
#include <qstring.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlineedit.h>

// kde includes
#include <kapplication.h>
#include <kdebug.h>
#include <klocale.h> 

// MY includes
#include "../../core/xmlnames.h"
#include "../../core/iptrule.h"
#include "../../core/iptruleoption.h"
#include "../../core/iptchain.h"
#include "../../core/iptable.h"
#include "../../core/kmfdoc.h"
#include "../../core/kmfiptdoc.h"
#include "../../core/kmfnetwork.h"
#include "../../core/kmfundoengine.h"
namespace KMF {
KMFRuleEditTargetLog::KMFRuleEditTargetLog( QWidget *parent, const char *name, WFlags fl ) : KMyFirewallRuleEditorTargetLog( parent, name, fl ) {}
KMFRuleEditTargetLog::~KMFRuleEditTargetLog() {}

void KMFRuleEditTargetLog::loadRule( IPTRule* rule ) {
	kdDebug() << "void KMFRuleEditTargetLog::loadRule( IPTRule* rule )" << endl;
	c_log_tcp_seq->setChecked( false );
	c_log_tcp_options-> setChecked( false );
	c_log_ip_options->setChecked( false );
	c_log_prefix-> setChecked( false );
	c_log_level ->setChecked( false );
	cb_log_level->setCurrentItem( 0 );
	t_log_prefix->clear();
	m_rule = rule;
	IPTRuleOption *opt = 0;
	opt = m_rule->getOptionForName("target_log_opt");
	if (opt) {
		QStringList vals = opt->getValues();
		QString prefix = "";
		QString level = "";
		QString tcp_seq = "";
		QString tcp_opt = "";
		QString ip_opt = "";
		prefix = *vals.at(0);
		level = *vals.at(1);
		tcp_seq = *vals.at(2);
		tcp_opt = *vals.at(3);
		ip_opt =* vals.at(4);
		if ( !prefix.isEmpty() && prefix != XML::Undefined_Value && prefix != XML::BoolOff_Value ) {
			c_log_prefix->setChecked( true );
			prefix = prefix.right( prefix.length() -1);
			prefix = prefix.left( prefix.length() -1 );
			t_log_prefix->setText( prefix );
		} else {
			c_log_prefix->setChecked( false );
 			t_log_prefix->setText( "" );
		}
		if ( !level.isEmpty() && level != XML::Undefined_Value && prefix != XML::BoolOff_Value) {
			c_log_level->setChecked( true );
			cb_log_level ->setCurrentText( level );
		} else {
			c_log_level->setChecked( false );
			cb_log_level ->setCurrentText( "" );
		}

		if ( tcp_seq == XML::BoolOn_Value )
			c_log_tcp_seq->setChecked( true );
		else
			c_log_tcp_seq->setChecked( false );

		if ( tcp_opt == XML::BoolOn_Value )
			c_log_tcp_options->setChecked( true );
		else
			c_log_tcp_options->setChecked( false );

		if ( ip_opt == XML::BoolOn_Value )
			c_log_ip_options->setChecked( true );
		else
			c_log_ip_options->setChecked( false );
	}
}

void KMFRuleEditTargetLog::accept() {
	KMFUndoEngine::instance()->startTransaction( 
		m_rule,
		i18n("Edit Rule: %1 Target Log Option").arg( m_rule->name() ) 
	);
	QPtrList<QString>* args = new QPtrList<QString>;
	QString* name = new QString( "target_log_opt" );

	if ( c_log_prefix->isChecked() ) {
		QString val = t_log_prefix->text();
		val.prepend("\"");
		val.append("\"");
		args->append( ( new QString( val ) ) );
	} else {
		args->append( ( new QString("") ) );
	}

	if ( c_log_level->isChecked() ) {
		QString val = cb_log_level->currentText();
		args->append( ( new QString( val ) ) );
	} else {
		args->append( ( new QString("") ) );
	}

	if ( c_log_tcp_seq->isChecked() ) {
		QString val = XML::BoolOn_Value;
		args->append( ( new QString( val ) ) );
	} else {
		args->append( ( new QString("") ) );
	}

	if ( c_log_tcp_options->isChecked() ) {
		QString val = XML::BoolOn_Value;
		args->append( ( new QString( val ) ) );
	} else {
		args->append( ( new QString("") ) );
	}

	if ( c_log_ip_options->isChecked() ) {
		QString val = XML::BoolOn_Value;
		args->append( ( new QString( val ) ) );
	} else {
		args->append( ( new QString("") ) );
	}

	// emit sigAddTargetOpt(name,args);
	m_rule->addTargetOption( *name, *args );
	emit sigDocumentChanged();
	KMFUndoEngine::instance()->endTransaction();
	emit sigHideMe();
}

void KMFRuleEditTargetLog::slotHelp() {
	kdDebug() << "void KMFRuleEditTargetLog::slotHelp()" << endl;
	kapp->invokeHelp( "targets" );
}
void KMFRuleEditTargetLog::reject() {
	kdDebug() << "void KMFRuleEditTargetLog::slotreject()" << endl;
	emit sigHideMe();
}

}

#include "kmfruleedittargetlog.moc"