summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/genericinterface/kmfgenericinterfacenat.cpp
blob: c9fb6e808586816fa5b3d3a66c94dca8b6069e7f (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
//
// C++ Implementation: $MODULE$
//
// Description:
//
//
// Author: Christian Hubinger <chubinger@irrsinnig.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
/***************************************************************************
 *                                                                         *
 *   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 "kmfgenericinterfacenat.h"


// QT includes
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqcheckbox.h>
#include <tqlistview.h>

// KDE includes
#include <kdebug.h>
#include <tdelocale.h>
#include <kcombobox.h>
#include <knuminput.h>
#include <tdelistview.h>

// Project includes
#include "../core/kmfnetwork.h"
#include "../core/kmftarget.h"
#include "../core/kmftargetconfig.h"
#include "../core/kmfgenericdoc.h"
#include "../core/kmfconfig.h"
namespace KMF {
KMFGenericInterfaceNat::KMFGenericInterfaceNat( TQWidget *parent, const char *name, WFlags f )
		: KMyFirewallGenericInterfaceNATWidget( parent, name, f ) {

connect( m_c_enable_nat, TQ_SIGNAL( toggled( bool ) ),
	this, TQ_SLOT( slotNatEnabled( bool ) ) );
connect( m_c_use_masquerade, TQ_SIGNAL( toggled( bool ) ),
	this, TQ_SLOT( slotMasqueradeEnabled( bool ) ) );


connect( m_sb_addr_1, TQ_SIGNAL( valueChanged( const TQString& ) ),
	this, TQ_SLOT( slotAddressChanged( const TQString& ) ) );
connect( m_sb_addr_2, TQ_SIGNAL( valueChanged( const TQString& ) ),
	this, TQ_SLOT( slotAddressChanged( const TQString& ) ) );
connect( m_sb_addr_3, TQ_SIGNAL( valueChanged( const TQString& ) ),
	this, TQ_SLOT( slotAddressChanged( const TQString& ) ) );
connect( m_sb_addr_4, TQ_SIGNAL( valueChanged( const TQString& ) ),
	this, TQ_SLOT( slotAddressChanged( const TQString& ) ) );

connect( m_cb_external_interface, TQ_SIGNAL(  activated( const TQString& ) ),
	this, TQ_SLOT( slotExternalInterfaceChanged( const TQString& ) ) );
}


KMFGenericInterfaceNat::~KMFGenericInterfaceNat() {}

void KMFGenericInterfaceNat::slotUpdateView( NetfilterObject* ) {
	kdDebug() << "KMFGenericInterfaceNat::slotUpdateView( NetfilterObject* )" << endl;
	if ( ! m_doc ) {
		kdDebug() << "WRINING: m_doc == 0" << endl;
		return;
	}
	slotUpdateView();
}
void KMFGenericInterfaceNat::slotUpdateView() {
	kdDebug() << "void KMFGenericInterfaceNat::slotUpdateView()" << endl;
	if ( ! m_doc ) {
		kdDebug() << "WRINING: m_doc == 0" << endl;
		return;
	}
	m_c_enable_nat->setChecked( m_doc->currentDocAsGenericDoc()->useNat() );
	m_c_use_masquerade->setChecked( m_doc->currentDocAsGenericDoc()->useMasquerade() );
// 	m_c_restrict_nat->setChecked( m_doc->restrictNat() );
	m_sb_addr_1->blockSignals( true );
	m_sb_addr_2->blockSignals( true );
	m_sb_addr_3->blockSignals( true );
	m_sb_addr_4->blockSignals( true );
	m_sb_addr_1->setValue( m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 0 ) );
	m_sb_addr_2->setValue( m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 1 ) );
	m_sb_addr_3->setValue( m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 2 ) );
	m_sb_addr_4->setValue( m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 3 ) );
	kdDebug() << "Setting Address Fields to: " << m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 0 ) << "." <<
					 m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 1 ) << "." << m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 2 ) << "." <<
					  m_doc->currentDocAsGenericDoc()->natAddress()->getDigit( 3 ) << endl;
	m_sb_addr_1->blockSignals( false );
	m_sb_addr_2->blockSignals( false );
	m_sb_addr_3->blockSignals( false );
	m_sb_addr_4->blockSignals( false );

	TQStringList interfaces =  m_doc->currentTarget()->config()->interfaces();
	m_cb_external_interface->clear();
	m_cb_external_interface->insertStringList( interfaces );

	TQString interf = m_doc->currentDocAsGenericDoc()->outgoingInterface();

	interf = m_doc->currentDocAsGenericDoc()->outgoingInterface();
	bool found = false;
	int i = 0;
	for ( TQStringList::Iterator it = interfaces.begin(); it != interfaces.end() && ! found; ++it ) {
		if ( *it == interf ) {
			m_cb_external_interface->setCurrentItem( i );
		}
		i++;
    }

}

/*!
    \fn KMFGenericInterfaceNat::loadDoc( KMFGenericDoc* )
 */
void KMFGenericInterfaceNat::loadDoc( KMFNetwork* doc ) {
	kdDebug() << "void KMFGenericInterfaceNat::loadDoc( KMFGenericDoc* )" << endl;
	m_doc = doc;
	slotUpdateView();
}


/*!
    \fn KMFGenericInterfaceNat::slotNatEnabled( bool )
 */
void KMFGenericInterfaceNat::slotNatEnabled( bool onoff ) {
	KMFUndoEngine::instance()->startTransaction(
		m_doc->currentDocAsGenericDoc(),
		i18n( "%1 NAT." ).arg( onoff ? i18n( "Enable" ) : i18n( "Disable" ) )
	);
	
	m_doc->currentDocAsGenericDoc()->setUseNat( onoff );
	m_doc->currentDocAsGenericDoc()->setOutgoingInterface( m_cb_external_interface->currentText () );
	KMFUndoEngine::instance()->endTransaction();
}

/*!
    \fn KMFGenericInterfaceNat::slotMasqueradeEnabled( bool )
 */
void KMFGenericInterfaceNat::slotMasqueradeEnabled( bool onoff ) {
	if ( m_doc->currentDocAsGenericDoc()->useMasquerade() == onoff ) {
		return;
	}
	KMFUndoEngine::instance()->startTransaction(
		m_doc->currentDocAsGenericDoc(),
		i18n( "%1 MASQUERADE target for NAT." ).arg( onoff ? i18n( "Enable" ) : i18n( "Disable" ) )
	);
	m_doc->currentDocAsGenericDoc()->setUseMasquerade( onoff );
	KMFUndoEngine::instance()->endTransaction();
}


/*!
    \fn KMFGenericInterfaceNat::slotAddressChanged( const TQString& )
 */
void KMFGenericInterfaceNat::slotAddressChanged( const TQString& ) {
	TQString address = "" + m_sb_addr_1->text() + "." +  m_sb_addr_2->text() + "." +  m_sb_addr_3->text() + "." +  m_sb_addr_4->text();
	if ( address == m_doc->currentDocAsGenericDoc()->natAddress()->toString() ) {
		return;
	}
	
	kdDebug() << "Updating NAT external address to: " << address << endl;
	KMFUndoEngine::instance()->startTransaction(
		m_doc->currentDocAsGenericDoc(),
		i18n( "Set NAT adddress to %1." ).arg( address )
	);
	m_doc->currentDocAsGenericDoc()->natAddress()->setAddress( m_sb_addr_1->value(),
														m_sb_addr_2->value(),
														m_sb_addr_3->value(),
														m_sb_addr_4->value() );
	KMFUndoEngine::instance()->endTransaction();
}
/*!
    \fn KMFGenericInterfaceNat::slotOutgoingInterfaceChanged( const TQString& )
 */
void KMFGenericInterfaceNat::slotExternalInterfaceChanged( const TQString& str ) {
	if ( m_doc->currentDocAsGenericDoc()->outgoingInterface() == str ) {
		return;
	}
	
	KMFUndoEngine::instance()->startTransaction(
		m_doc->currentDocAsGenericDoc(),
		i18n( "Change NAT outgoing interface to %1." ).arg( str )
	);
	m_doc->currentDocAsGenericDoc()->setOutgoingInterface( str );
	KMFUndoEngine::instance()->endTransaction();
	slotUpdateView();
}

}
#include "kmfgenericinterfacenat.moc"