summaryrefslogtreecommitdiffstats
path: root/src/configdialog.cpp
blob: 0169e8144eb7a7b7b142126788c1da4e417ae5bc (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
/***************************************************************************
** $Id: configdialog.cpp,v 1.51 2008/07/31 19:56:25 hoganrobert Exp $
*   Copyright (C) 2006 - 2008 Robert Hogan                                *
*   [email protected]                                                *
 *                                                                         *
 *   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 St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/
//Adapted from configdialog.cpp in amaroK:
/***************************************************************************
begin                : 2004/02/07
copyright            : (C) Mark Kretschmann
email                : [email protected]
***************************************************************************/

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

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <tqcombobox.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqmessagebox.h>
#include <tqobjectlist.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
#include <tqtextcodec.h>
#include <tqtooltip.h>
#include <tqvbox.h>
#include <tqlistview.h>
#include <tqcheckbox.h>

#include <tdeapplication.h> //kapp
#include <kcombobox.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <dcopref.h>
#include <tdeconfig.h>
#include <tdemessagebox.h>

#include "configdialog.h"
#include "konqueror.h"
#include "firewallsproxies.h"
#include "paranoia.h"
#include "maxmin.h"
#include "running.h"
#include "torservers.h"
#include "usability.h"
#include "torkconfig.h"
#include "server.h"
#include "quickconfig.h"
#include "hiddensrvs.h"
#include "portsandnames.h"
#include "tork.h"
#include "crypto.h"


//////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC
//////////////////////////////////////////////////////////////////////////////////////////

TorkConfigDialog::TorkConfigDialog( TQWidget *parent, const char* name, TDEConfigSkeleton *config )
        : TDEConfigDialog( parent, name, config ),m_parent(parent)
{
    setWFlags( WDestructiveClose );

    // IMPORTANT Don't simply change the page names, they are used as identifiers in other parts of the app.
        m_firewallsproxies = new FirewallsProxies( 0, "Firewall/Censor Evasion" );
        m_usability = new Usability( 0, "Usability" );
        m_torservers = new TorServers( 0, "My Network View" );
	    m_maxmin = new MaxMin( 0, "My Server Bandwidth" );
	    m_running = new Running( 0, "My Tor Client" );
        m_myserver = new MyServer( this, "My Tor Server" );
        m_myhidden = new MyHidden( 0, "My Hidden" );
        m_quickconfig = new QuickConfig( 0, "Quick Configure" );
        m_konq = new Konq( 0, "Konqueror" );
        m_filtertable = new FilterTable( 0, "FailSafe" );

    // add pages
    addPage( m_quickconfig, i18n( "Quick Configure" ), "cache", i18n( "Quick Configuration" ) );
#ifndef LIVECD
    addPage( m_konq, i18n( "Konqueror" ), "tork_konqueror_play", i18n( "Konqueror and Privacy Proxy" ) );
#endif

#ifndef LIVECD
    addPage( m_running, i18n( "My Tor Client" ), "launch", i18n( "Configure My Client" ) );
#endif
    addPage( m_firewallsproxies, i18n( "Firewall/Censor Evasion" ), "proxy", i18n( "Configure Firewalls Proxies" ) );

    if (TorkConfig::advancedMode()){
#ifndef LIVECD
#ifdef USE_FAILSAFE
      addPage( m_filtertable, i18n( "FailSafe" ), "gv", i18n( "Configure FailSafe Settings" ) );
#endif
#endif
      addPage( m_usability,   i18n( "Usability" ), "idea", i18n( "Configure Usability" ) );
    }
    if ((!TorkConfig::excludeNodes().isEmpty()) ||
        (!TorkConfig::exitNodes().isEmpty())){
        addPage( m_torservers, i18n( "My Network View" ), "network", 
                 i18n( "Configure My Network View" ) );
    }
    if (!TorkConfig::clientOnly()){
        addPage( m_myserver, i18n( "My Tor Server" ), "computer", i18n( "Configure My Server" ) );
        addPage( m_maxmin, i18n( "My Server Bandwidth" ), "filter", i18n( "Configure My Bandwidth" ) );
    }
    if (!TorkConfig::hiddenServices().isEmpty())
        addPage( m_myhidden, i18n( "My Hidden Services" ), "tork_agent", 
                         i18n( "Configure My Hidden Services" ) );
    

    TQObjectList *list = queryList( "TQLabel", "infoPixmap" );
    for( TQObject *label = list->first(); label; label = list->next() )
        static_cast<TQLabel*>(label)->setPixmap( TQMessageBox::standardIcon( TQMessageBox::Information ) );
    delete list;

    //stop TDEFont Requesters getting stupidly large
    list = queryList( "TQLabel", "m_sampleLabel" );
    for( TQObject *label = list->first(); label; label = list->next() )
        static_cast<TQLabel*>(label)->setMaximumWidth( 250 );
    delete list;

    connect( m_usability->LongLivedPorts, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_torservers->ExitNodes, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_torservers->ExcludeNodes, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_torservers->MapAddress, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_torservers->AllowUnverifiedNodes, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_firewallsproxies->ReachableAddresses, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_filtertable->FilterRules, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_running->SOCKSPolicy, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_running->SOCKSBindAddressMany, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_running->PushAdd, SIGNAL( clicked() ), this, SLOT( enableApply() ) );
    connect( m_running->PushAdd2, SIGNAL( clicked() ), this, SLOT( enableApply() ) );
    connect( m_myserver->kcfg_ClientOnly, SIGNAL( toggled(bool) ), this, SLOT( showServerOpts(bool) ) );
    connect( m_usability->TrackHostExits, SIGNAL( selectionChanged() ), this, SLOT( enableApply() ) );
    connect( m_usability->PushAdd, SIGNAL( clicked() ), this, SLOT( enableApply() ) );

    connect( m_quickconfig, SIGNAL( configChanged(const int &) ), this, SLOT( showHidePages(const int &) ) );
    //connect( m_usability, SIGNAL(settingsChanged()), SLOT(updateButtons()) ); 

    // Always apply settings when OK or Apply is pressed.
    //connect( this, SIGNAL(settingsChanged()), this,
    //               SLOT(updateCustomSettings()) );
    connect( this, SIGNAL(okClicked()), this,
                   SLOT(updateCustomSettings()) );
    connect( this, SIGNAL(applyClicked()), this,
                   SLOT(updateCustomSettings()) );
    connect( this, SIGNAL(updateServerButton( )), parent,
                    SLOT(updateServerButton( )) );

    connect( m_firewallsproxies, SIGNAL(uncensorSelected( bool )), parent,
                                 SLOT(toggleServerButton( bool )) );

    if (TorkConfig::currentTorVersion().left(3) == "0.1"){
        m_filtertable->setEnabled(false);
    }
    showHidePages(m_quickconfig->QuickConfigure->currentItem());

}

void TorkConfigDialog::showHidePages( const int &type )
{
    switch (type) {
            case 0 : //Tor client and server with default settings
            case 1 : //Tor client and relay server with default settings
            case 2 : //Tor client and relay server with default settings
            case 3 : //Tor client and relay server with default settings
            case 4 : //Tor client and relay server with default settings
               m_running->setEnabled(false); 
               m_usability->setEnabled(false); 
               m_torservers->setEnabled(false); 
               m_maxmin->setEnabled(false); 
               m_firewallsproxies->setEnabled(true); 
               m_myserver->setEnabled(false); 
               break;
            case 5 : //Use custom settings
            case 6 : //Use custom settings
            case 7 : //Use custom settings
               m_running->setEnabled(true); 
               m_usability->setEnabled(true); 
               m_torservers->setEnabled(true); 
               m_maxmin->setEnabled(true); 
               m_firewallsproxies->setEnabled(true); 
               m_myserver->ServerInfo->setEnabled(!TorkConfig::clientOnly());
               break;

    }

    show();

}

TorkConfigDialog::~TorkConfigDialog()
{
    emit updateServerButton( );
}

void TorkConfigDialog::showServerOpts( bool state)
{
    m_myserver->ServerInfo->setEnabled(!state);
}


/** Show page by object name */
void TorkConfigDialog::showPage( const TQCString& page )
{
    for( uint index = 0; index < m_pageList.count(); index++ ) {
        if ( m_pageList[index]->name() == page ) {
            TDEConfigDialog::showPage( index );
            return;
        }
    }
}

/** Reimplemented from TDEConfigDialog */
void TorkConfigDialog::addPage( TQWidget *page, const TQString &itemName, const TQString &pixmapName, const TQString &header, bool manage )
{
    // Add the widget pointer to our list, for later reference
    m_pageList << page;

    TDEConfigDialog::addPage( page, itemName, pixmapName, header, manage );
}


void TorkConfigDialog::enableApply()
{
    enableButtonApply(true);
}

void TorkConfigDialog::updateCustomSettings()
{

    kdDebug() << "applied config" << endl;

    //When settings are changed in the config dialog, this is called
    //to update all possibly changed values and apply them to Tor.

    //TQListViews need to be handled outside of tdeconfigxt
    TorkConfig::setQuickConfigure( m_quickconfig->QuickConfigure->currentItem() );

    TorkConfig::setAccountingStart(m_myserver->AccountingStart->currentText());
//     TorkConfig::setStatusFetchPeriodUnit(m_torservers->StatusFetchPeriodUnit->currentText());
//     TorkConfig::setDirFetchPeriodUnit(m_torservers->DirFetchPeriodUnit->currentText());

    //Unverified Servers
    if ( m_torservers->AllowUnverifiedNodes->childCount() > 0 ) {
        TQStringList v_allowUnverifiedNodes;
        TQListViewItemIterator it( m_torservers->AllowUnverifiedNodes, TQListViewItemIterator::Selected );
        while ( it.current() ) {
            v_allowUnverifiedNodes.append(it.current()->text(0));
	        ++it;
        }
        TorkConfig::setAllowUnverifiedNodes( v_allowUnverifiedNodes );
    }

    //Friendly Servers
    if ( m_torservers->MapAddress->childCount() > 0 ) {
        TQStringList v_mapAddress;
        TQListViewItemIterator it( m_torservers->MapAddress );
        while ( it.current() ) {
            TQString s_mapAddress = it.current()->text(0) + " " + it.current()->text(0) + "." +
                it.current()->text(1) + "." + it.current()->text(2);
            v_mapAddress.append(s_mapAddress);
	        ++it;
        }
        TorkConfig::setMapAddress( v_mapAddress );
    }else
        TorkConfig::setMapAddress( "" );

    //Exclude Countries
    TQStringList cclist; 
    for (unsigned int index = 0; index != m_torservers->CountryList->count(); ++index){
        cclist.append(m_torservers->ccode(m_torservers->CountryList->item(index)->text()));
    }
    TorkConfig::setExcludeCountries(cclist);

//     Preferred Countries
//     cclist.clear();
//     for (unsigned int index = 0; index != m_torservers->PreferredCountryList->count(); ++index){
//         cclist.append(m_torservers->ccode(m_torservers->PreferredCountryList->item(index)->text()));
//     }
//     TorkConfig::setPreferredCountries(cclist);

    //Enemy Servers
    if ( m_torservers->ExcludeNodes->childCount() > 0 ) {
        TQStringList v_excludeNodes;
        TQStringList v_excludeServersHistory;
        TQListViewItemIterator it( m_torservers->ExcludeNodes );
        while ( it.current() ) {
            v_excludeNodes.append("$"+getFPFromFPDigest(it.current()->text(2)));
            v_excludeServersHistory.append(it.current()->text(1) + "-" + 
                                           it.current()->text(2) + "-" + it.current()->text(3));
	        ++it;
        }
        TorkConfig::setExcludeNodes( v_excludeNodes );
        TorkConfig::setExcludeServersHistory( v_excludeServersHistory );
    }else{
        TorkConfig::setExcludeNodes( TQStringList() );
        TorkConfig::setExcludeServersHistory( TQStringList() );
    }

    //Exit Servers
    if ( m_torservers->ExitNodes->childCount() > 0 ) {
        TQStringList v_exitNodes;
        TQStringList v_includeServersHistory;
        TQListViewItemIterator it( m_torservers->ExitNodes );
        while ( it.current() ) {
            v_exitNodes.append("$"+getFPFromFPDigest(it.current()->text(2)));
            v_includeServersHistory.append(it.current()->text(1) + "-" + 
                                           it.current()->text(2) + "-" + it.current()->text(3));

	        ++it;
        }
        TorkConfig::setExitNodes( v_exitNodes );
        TorkConfig::setIncludeServersHistory( v_includeServersHistory );
    }else{
        TorkConfig::setExitNodes( TQStringList() );
        TorkConfig::setIncludeServersHistory( TQStringList() );
    }

    //Family Servers
    if ( m_myserver->MyFamily->childCount() > 0 ) {
        TQStringList v_myFamily;
        TQListViewItemIterator it( m_myserver->MyFamily, TQListViewItemIterator::Selected );
        while ( it.current() ) {
            v_myFamily.append(it.current()->text(1) + "-" + 
                              it.current()->text(2) + "-" + it.current()->text(3));
	        ++it;
        }
        TorkConfig::setMyFamily( v_myFamily );
    }else{
        TorkConfig::setMyFamily( TQStringList() );
    }

    //Track Host Exits
    if ( m_usability->TrackHostExits->childCount() > 0 ) {
        TQStringList v_trackHostExits;
        TQListViewItemIterator it( m_usability->TrackHostExits );
        while ( it.current() ) {
            v_trackHostExits.append(it.current()->text(0));
	        ++it;
        }
        TorkConfig::setTrackHostExits( v_trackHostExits );
    }else
        TorkConfig::setTrackHostExits( "" );

    //Long Lived Ports
    if ( m_usability->LongLivedPorts->childCount() > 0 ) {
        TQStringList v_longLivedPorts;
        TQListViewItemIterator it( m_usability->LongLivedPorts, TQListViewItemIterator::Selected );
        while ( it.current() ) {
            int i;
            for (i = 0; _port_name[i].port; ++i) {
                portsandnames_t *pics = &_port_name[i];
                if (it.current()->text(0) == pics->name){
                    v_longLivedPorts.append(pics->port);
                }
            }

	        ++it;
        }
        TorkConfig::setLongLivedPorts( v_longLivedPorts );
    }

    //Socks Bind Addresses
    if ( m_running->SOCKSBindAddressMany->childCount() > 0 ) {
        TQStringList v_sOCKSBindAddressMany;
        TQListViewItemIterator it( m_running->SOCKSBindAddressMany );
        while ( it.current() ) {
            TQString s_sOCKSBindAddressMany = it.current()->text(0) + ":" + it.current()->text(1);
            v_sOCKSBindAddressMany.append(s_sOCKSBindAddressMany);
	        ++it;
        }
        TorkConfig::setSOCKSBindAddressMany( v_sOCKSBindAddressMany );
    }else
        TorkConfig::setSOCKSBindAddressMany( "" );

    //Exit Policy
    if ( m_myserver->ExitPolicy->childCount() > 0 ) {
        TQStringList v_exitPolicy;
        TQListViewItemIterator it( m_myserver->ExitPolicy );
        while ( it.current() ) {
            TQString s_exitPolicy = it.current()->text(0) + " " + it.current()->text(1) + ":" + it.current()->text(2);
            v_exitPolicy.append(s_exitPolicy);
	        ++it;
        }
        TorkConfig::setExitPolicy( v_exitPolicy );
    }else
        TorkConfig::setExitPolicy( "" );

    //Socks Policy
    if ( m_running->SOCKSPolicy->childCount() > 0 ) {
        TQStringList v_sOCKSPolicy;
        TQListViewItemIterator it( m_running->SOCKSPolicy );
        while ( it.current() ) {
            TQString s_sOCKSPolicy = it.current()->text(0) + " " + it.current()->text(1) + ":" + it.current()->text(2);
            v_sOCKSPolicy.append(s_sOCKSPolicy);
	        ++it;
        }
        TorkConfig::setSOCKSPolicy( v_sOCKSPolicy );
    }else
        TorkConfig::setSOCKSPolicy( "" );

    //Filter Rules
    if ( m_filtertable->FilterRules->childCount() > 0 ) {
        TQStringList v_filterRules;
        TQListViewItemIterator it( m_filtertable->FilterRules );
        while ( it.current() ) {
            TQString s_filterRules = it.current()->text(0) + "%:%" + it.current()->text(1)+ "%:%" + it.current()->text(2);
            v_filterRules.append(s_filterRules);
	        ++it;
        }
        TorkConfig::setFilterRules( v_filterRules );
    }else
        TorkConfig::setFilterRules( "" );

    //Reachable Address
    if ( m_firewallsproxies->ReachableAddresses->childCount() > 0 ) {
        TQStringList v_reachableAddresses;
        TQListViewItemIterator it( m_firewallsproxies->ReachableAddresses );
        while ( it.current() ) {
            TQString s_reachableAddresses = "*:" + it.current()->text(0);
            v_reachableAddresses.append(s_reachableAddresses);
	        ++it;
        }
        TorkConfig::setReachableAddresses( v_reachableAddresses );
    }else
        TorkConfig::setReachableAddresses( "" );

    //Bridge Addresses
    if ( m_firewallsproxies->Bridge->childCount() > 0 ) {
        TQStringList v_bridges;
        TQListViewItemIterator it( m_firewallsproxies->Bridge );
        while ( it.current() ) {
            TQString s_bridges = it.current()->text(0) + ":" + it.current()->text(1)
                                + " " + it.current()->text(2);
            v_bridges.append(s_bridges);
	        ++it;
        }
        TorkConfig::setBridge( v_bridges );
    }else
        TorkConfig::setBridge( TQStringList() );

    //Hidden Services
//     if ( m_myhidden->servicesList->childCount() > 0 ) {
//         TQStringList v_hiddenServices;
//         TQListViewItemIterator it( m_myhidden->servicesList );
//         while ( it.current() ) {
//             TQString s_hiddenServices = it.current()->text(0) + "\n" + it.current()->text(1)
//                                         + "\n" + it.current()->text(2) + "\n" + it.current()->text(3)
//                                         + "\n" + it.current()->text(4)+ "\n" + it.current()->text(5);
//             v_hiddenServices.append(s_hiddenServices);
// 	        ++it;
//         }
//         TorkConfig::setHiddenServices( v_hiddenServices );
//     }else
//         TorkConfig::setHiddenServices( "" );

    //Bandwidth Slots
    if ( m_maxmin->timedBandwidthList->childCount() > 0 ) {
        TQStringList v_bandwidthSlots;
        TQListViewItemIterator it( m_maxmin->timedBandwidthList );
        while ( it.current() ) {
            TQString s_bandwidthSlots = it.current()->text(0) + "\n" + it.current()->text(1)
                                        + "\n" + it.current()->text(2) + "\n" + it.current()->text(3)
                                        + "\n" + it.current()->text(4);
            v_bandwidthSlots.append(s_bandwidthSlots);
	        ++it;
        }
        TorkConfig::setBandwidthSlots( v_bandwidthSlots );
    }else
        TorkConfig::setBandwidthSlots( "" );

    // If we are to use bridges then TunnelDirConns must be set as well.
    if (m_firewallsproxies->kcfg_UseBridges->isChecked())
      TorkConfig::setTunnelDirConns(true);
    else
      TorkConfig::setTunnelDirConns(false);

    TorkConfig::writeConfig();


    //If you're going to disable this again, explain why here. You have a crap
    //memory.
    //emit settingsChanged(); 
    static_cast<tork*>(m_parent)->applySettingsToRunningTor();
}




#include "configdialog.moc"