summaryrefslogtreecommitdiffstats
path: root/src/newfirstrunwizard.ui.h
blob: 3b612b81142499a84c92a3d9a7323d1ade8dd0c5 (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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/***************************************************************************
 ** $Id: newfirstrunwizard.ui.h,v 1.29 2008/12/08 19:39:02 hoganrobert Exp $
 *   Copyright (C) 2006 - 2008 Robert Hogan                                *
 *   robert@roberthogan.net                                                *
 *                                                                         *
 *   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.              *
 ***************************************************************************/
 
#include <tqvaluevector.h>
#include <tqpushbutton.h>
#include <tqpixmap.h>
#include <tqtimer.h>

#include <tdeapplication.h>
#include <kstandarddirs.h>
#include <kurl.h>
#include <kprocio.h>
#include <kdebug.h>
#include <dcopref.h>
#include <tdeconfig.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include <krun.h>

#include <stdlib.h>

#include "functions.h"
#include "torkconfig.h"
#include "update.h"
#include "crypto.h"
#include "torclient.h"


TorClient* client;
KProcIO *whichproc;
bool torRunning;
bool privoxyRunning;
TQString tor;
TQString privoxy;
TQString netstat;
TQString torknetstat;

TQString OriginalHttpProxy;
TQString OriginalHttpsProxy;
TQString OriginalFtpProxy;
TQString OriginalProxyType;

TQString KonqHttpProxy;
TQString KonqHttpsProxy;
TQString KonqFtpProxy;
uint KonqHttpProxyPort;
uint KonqHttpsProxyPort;
uint KonqFtpProxyPort;

TQString OriginalCookies;
TQString OriginalUseCache;
TQString OriginalSendUserAgent;
TQString OriginalEnableJavascript;
TQString OriginalEnableJava;
TQString OriginalEnablePlugins;

TQValueVector<TQString> descriptions(6); 

void
FirstRunWizard::init()
{

    torRunning = false;
    privoxyRunning = false;

    descriptions[0] = i18n("This will run a client and an exit server with Tor's default settings.<br>"
                      "An exit server carries the can for traffic leaving the Tor network.");
    descriptions[1] = i18n("This will run a client and a relay server with Tor's default settings.<br>"
                      "A relay server carries traffic along the Tor network but does not transmit"
                      "tor traffic outside the network.");
    descriptions[2] = i18n("This will run an exit server with Tor's default settings.<br>"
                      "An exit server carries the can for traffic leaving the Tor network.");
    descriptions[3] = i18n("This will run a relay server with Tor's default settings.<br>"
                      "A relay server carries traffic along the Tor network but does not transmit"
                      "tor traffic outside the network.");
    descriptions[4] = i18n("This will run a client with Tor's default settings.<br>");
    descriptions[5] = i18n("You're too clever for your own good.<br>");



    settingsDescription->setText(descriptions[0]);

    setAppropriate ( CheckNotUsing, false );
    setAppropriate ( CheckUsing, false );
    setAppropriate ( NonPrivoxyConfirmation, false );
    setAppropriate ( Remote_Tor, false );
    setAppropriate ( Locate_Tor, false );
    setAppropriate ( Locate_Privoxy, false );
    setNextEnabled ( Locate_Tor,false );
    setAppropriate ( TorServer, false );

    TorkConfig::setUser(getenv("USER"));
    const char *paths = ":/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";

    privoxy = getFullLocation(paths,"privoxy");
    tor = getFullLocation(paths,"tor");
    netstat = getFullLocation(paths,"netstat");


    if (!tor)
        setAppropriate ( Locate_Tor, true );
    else
        TorLocation_2->setURL(tor);

    if (!privoxy){
        setAppropriate ( Locate_Privoxy, true );
        whichProxyText->setText(i18n("I did not find an installation of Privoxy on your system."));
    }else{
        PrivoxyLocation_2->setURL(privoxy);
        whichProxyText->setText(i18n("I found an installation of Privoxy on your system."));
    }

    serverName->setText("TorKServer");
    
	TDEConfig emailConf( TQString::fromLatin1("emaildefaults") );
	emailConf.setGroup(TQString::fromLatin1("Defaults"));
	TQString profile = TQString::fromLatin1("PROFILE_");
	profile += emailConf.readEntry(TQString::fromLatin1("Profile"), TQString::fromLatin1("Default"));
	emailConf.setGroup(profile);

	contactMail->setText(emailConf.readEntry(TQString::fromLatin1("EmailAddress")));

    guessDataDir();
    //aesthetics
    cancelButton()->setFixedSize( cancelButton()->sizeHint() );
    helpButton()->hide();


 	whichproc = new KProcIO();
	whichproc->setUseShell(TRUE);
	TQString whichCommand="ps -C tor;ps -C privoxy";

	*whichproc<<whichCommand;

	connect( whichproc, SIGNAL(readReady(KProcIO * )),
		SLOT(processWhich(KProcIO * )) );
	whichproc->start(KProcIO::NotifyOnExit,TRUE);


}

void FirstRunWizard::monitorRemote_toggled( bool remoteTor)
{

    if ((!tor) && (!remoteTor))
        setAppropriate ( Locate_Tor, true );
    else
        setAppropriate ( Locate_Tor, false );
    setAppropriate ( HowDoesTorStart, !remoteTor );
    setAppropriate ( TorUsage, !remoteTor );
    setAppropriate ( TorServer, !remoteTor );
    setAppropriate ( Remote_Tor, remoteTor );
    setAppropriate ( TestingTor, remoteTor );
}

void FirstRunWizard::usingAnotherProxy_toggled( bool state)
{

    setAppropriate ( CheckNotUsing, state );
    setAppropriate ( CheckUsing, state );
    setAppropriate ( NonPrivoxyConfirmation, state );
    setAppropriate ( PrivoxyConfirmation, !state );
    if ((!privoxy) && (!state))
        setAppropriate ( Locate_Privoxy, !state );
    setAppropriate ( HowDoesPrivoxyStart, !state );
    setAppropriate ( PrivoxyConfiguration, !state );
    setAppropriate ( FinalPrivoxy, !state );
}

void FirstRunWizard::torStartsAutomatically_toggled( bool state)
{
    setAppropriate ( TorUsage, !state );
    setAppropriate ( TorServer, !state );
    setAppropriate ( TestingTor , state );
}

void FirstRunWizard::torStartsManually_toggled( bool state)
{
    setAppropriate ( TorUsage, state );
    setAppropriate ( TorServer, state );
    setAppropriate ( TestingTor , !state );
}

void FirstRunWizard::processWhich(KProcIO *whichproc)
{
	TQString item = "";
	int pos;

	while ((pos = (whichproc->readln(item,true))) != -1) {
		if (item.find("tor") != -1)
            torRunning = true;
        if (item.find("privoxy") != -1)
            privoxyRunning = true;
	}
	whichproc->ackRead();

}

void
FirstRunWizard::showPage( TQWidget *w ) //virtual
{
    TQWizard::showPage( w );


    if (currentPage() == HowDoesTorStart){
        torStartsAutomatically->setChecked(torRunning);
        torStartsManually->setChecked(!torRunning);
    }

    if (currentPage() == LocalOrRemote){
        torStartsAutomatically->setChecked(false);
        torStartsManually->setChecked(false);
    }

    if (currentPage() == HowDoesPrivoxyStart){
        privoxyStartsAutomatically->setChecked(privoxyRunning);
        privoxyStartsManually->setChecked(!privoxyRunning);
        if (privoxyRunning){
            privoxyText->setText(i18n("<p>To be honest, I'm not that bright." 
            "It looks as if Privoxy is configured to start up by itself when "
            "your computer boots up, but I can't be sure. So can you help me?"
            "Does Privoxy start by itself at boot-time?</p>"));
        }else{
            privoxyText->setText(i18n("<p>To be honest, I'm not that bright." 
            "It looks as if Privoxy does not start up by itself when "
            "your computer boots up, but I can't be sure. So can you help me?"
            "Does Privoxy start by itself at boot-time?</p>"));

        }
    }

    if (currentPage() == CheckUsing){
        saveAnonymousProxySettings();
    }

    if (currentPage() == TestingTor){
        testTor();
    }


    if (currentPage() == NonPrivoxyConfirmation){
        saveNonAnonymousProxySettings();
    }
    if (currentPage() == PrivoxyConfirmation){
        saveNonAnonymousProxySettings();
    }

    setFinishEnabled ( Final,true );


//    cancelButton()->setText( w == WizardPage_0 ? i18n("&Skip") : i18n("&Cancel") );
}



void FirstRunWizard::downloadPrivoxy_clicked()
{
    TorkUpdate* updater = new TorkUpdate(this);
    updater->checkForNewPrivoxyDirectly();

}


void FirstRunWizard::downloadTor_clicked()
{

    TorkUpdate* updater = new TorkUpdate(this);
    updater->checkForNewTorDirectly(false);

}

void
FirstRunWizard::accept()
{

    TQString paths;
    paths = ":/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
    paths.replace("::",":");

    torknetstat = getFullLocation(paths.local8Bit(), "torknetstat");

    if (!torknetstat.isEmpty())
        TorkConfig::setNetstatLocation("torknetstat");
    else
        TorkConfig::setNetstatLocation("netstat");

    if (torStartsAutomatically->isChecked())
        TorkConfig::setQuickConfigure(7);
    else if (monitorRemote->isChecked())
        TorkConfig::setQuickConfigure(6);
    else
        TorkConfig::setQuickConfigure(WizardQuickConfigure->currentItem());

    TorkConfig::setTorLocation(TorLocation_2->url());
    TorkConfig::setPrivoxyLocation(PrivoxyLocation_2->url());
    TorkConfig::setNickName(serverName->text());
    TorkConfig::setContactInfo(contactMail->text());

    if (monitorRemote->isChecked()){
        TorkConfig::setRemoteTorAddress(RemoteTorAddress->text());
        TorkConfig::setRemoteTorPort(RemoteTorPort->text().toInt());
    }

    if ((usingAnotherProxy->isChecked()) || (privoxyStartsAutomatically->isChecked())){
        TorkConfig::setSystemProxy(true);
        TorkConfig::setTorkProxy(false);
    }else{
        TorkConfig::setSystemProxy(false);
        TorkConfig::setTorkProxy(true);
    }


    //Non-Anon Proxy Settings
    TorkConfig::setOriginalHttpProxy(OriginalHttpProxy);
    TorkConfig::setOriginalHttpsProxy(OriginalHttpsProxy);
    TorkConfig::setOriginalProxyType(OriginalProxyType);
    TorkConfig::setOriginalCookies(OriginalCookies == "true");
    TorkConfig::setOriginalUseCache(OriginalUseCache == "true");
    TorkConfig::setOriginalSendUserAgent(OriginalSendUserAgent == "true");
    TorkConfig::setOriginalEnableJavascript(OriginalEnableJavascript == "true");
    TorkConfig::setOriginalEnableJava(OriginalEnableJava == "true");
    TorkConfig::setOriginalEnablePlugins(OriginalEnablePlugins == "true");

    //Anon Proxy Settings

    TorkConfig::setKonqHttpProxy(KonqHttpProxy);
    TorkConfig::setKonqHttpProxyPort(KonqHttpProxyPort);
    TorkConfig::setKonqHttpsProxy(KonqHttpsProxy);
    TorkConfig::setKonqHttpsProxyPort(KonqHttpsProxyPort);
    TorkConfig::setKonqFtpProxy(KonqFtpProxy);
    TorkConfig::setKonqFtpProxyPort(KonqFtpProxyPort);

    if (!usingAnotherProxy->isChecked()){
        TorkConfig::setKonqHttpProxy("http://localhost");
        TorkConfig::setKonqHttpProxyPort(8118);
        TorkConfig::setKonqHttpsProxy("http://localhost");
        TorkConfig::setKonqHttpsProxyPort(8118);
    }

    TorkConfig::writeConfig();
    TQDialog::accept();
}
void
FirstRunWizard::reject()
{
    TQDialog::reject();
}

void FirstRunWizard::WizardQuickConfigure_activated( int item)
{

    if (item == 4)
        setAppropriate ( TorServer, false );
    else
        setAppropriate ( TorServer, true );

    settingsDescription->setText(descriptions[item]);

}

void
FirstRunWizard::saveNonAnonymousProxySettings()
{


    TDEConfig* config = new TDEConfig("tdeioslaverc", false, false);
    config->setGroup( "Proxy Settings" );
    OriginalHttpProxy = config->readEntry( "httpProxy" );
    OriginalHttpsProxy = config->readEntry( "httpsProxy" );
    OriginalProxyType = config->readEntry( "ProxyType" );
    config = new TDEConfig("kcookiejarrc", false, false);
    config->setGroup( "Cookie Policy" );
    OriginalCookies = config->readEntry( "Cookies" );
    config = new TDEConfig("tdeio_httprc", false, false);
    OriginalUseCache = config->readEntry( "UseCache" );
    OriginalSendUserAgent = config->readEntry( "SendUserAgent" );
    config = new TDEConfig("konquerorrc", false, false);
    config->setGroup( "Java/JavaScript Settings" );
    OriginalEnableJavascript = config->readEntry( "EnableJavaScript" );
    OriginalEnableJava = config->readEntry( "EnableJava" );
    OriginalEnablePlugins = config->readEntry( "EnablePlugins" );

    if (currentPage() == PrivoxyConfirmation){
        KonqHttpProxy = "http://localhost";
        KonqHttpProxyPort = 8118;
        KonqHttpsProxy = "http://localhost";
        KonqHttpsProxyPort = 8118;
        KonqFtpProxy = "http://localhost";
        KonqFtpProxyPort = 8118;
    }

}

void
FirstRunWizard::saveAnonymousProxySettings()
{



    TDEConfig* config = new TDEConfig("tdeioslaverc", false, false);
    config->setGroup( "Proxy Settings" );
    KonqHttpProxy = config->readEntry( "httpProxy" ).section(":",0,1);
    KonqHttpProxyPort = config->readEntry( "httpProxy" ).section(":",-1,-1).toInt();
    KonqHttpsProxy = config->readEntry( "httpsProxy" ).section(":",0,1);
    KonqHttpsProxyPort = config->readEntry( "httpsProxy" ).section(":",-1,-1).toInt();
    KonqFtpProxy = config->readEntry( "ftpProxy" ).section(":",0,1);
    KonqFtpProxyPort = config->readEntry( "ftpProxy" ).section(":",-1,-1).toInt();

}

void FirstRunWizard::TorLocation_textChanged( const TQString & text)
{
    if (text.contains("tor"))
        setNextEnabled ( Locate_Tor,true );
}




void FirstRunWizard::pushButton1_clicked()
{
    KRun::runCommand( "tdecmshell proxy" );

}


void FirstRunWizard::pushButton1_2_clicked()
{
    KRun::runCommand( "tdecmshell proxy" );
}


void FirstRunWizard::pushButton1_3_clicked()
{
    KRun::runCommand( "tdecmshell proxy" );
}

void FirstRunWizard::testTorAgain_clicked()
{
    testTor();
    
}

void FirstRunWizard::testTor()
{
    kdDebug() << "testing tor" << endl;
    TQString host;
    int port;
    if (monitorRemote->isChecked()){
        host = RemoteTorAddress->text();
        port = RemoteTorPort->text().toInt();
        TorkConfig::setCookieAuthentication(false);
    }else{
        host = "localhost";
        port = TorkConfig::controlPort();
        TorkConfig::setCookieAuthentication(false);
    }

    if (!TorPassword->text().isEmpty() && TorPassword->isEnabled())
        TorkConfig::setHashedControlPassword(TorPassword->text());

    if (client)
      delete client;

    client = new TorClient(host,port);
    connect( client, SIGNAL(fatalError()),this, SLOT(cannotContactTor()));
    connect( client, SIGNAL(authenticationFailed()),this, SLOT(cannotContactTor()));
    connect( client, SIGNAL(authenticated()),this, SLOT(contactedTor()) );
    client->authenticate();

}

void FirstRunWizard::modifyConfs_clicked()
{
    examineConfigFiles();
}

void FirstRunWizard::cannotContactTor()
{

    disconnect( client, SIGNAL(fatalError()),this, SLOT(cannotContactTor()));
    disconnect( client, SIGNAL(authenticationFailed()),this, SLOT(cannotContactTor()));
    disconnect( client, SIGNAL(authenticated()),this, SLOT(contactedTor()) );
    if (client != 0L){
        client->socketReadyRead();
        client->deleteLater();
        client = 0L;
    }

    if (monitorRemote->isChecked()){
        torControlStatus->setText(i18n("<p>I can't contact or authenticate to Tor.<br>"
            "This means you will need to modify Tor's settings if it is to be usable by Tork in future.</p>"
            "On the machine that your remote Tor installation runs on add the following to Tor's config file:<br>"
            "<br>"
            "<b>ControlPort %2</b><br>"
            "<br>"
            "Alternatively, you may have entered the wrong password in the previous page.<br>"
            "When you've attempted to fix the problem, click <b>'Test Tor'</b> to try connecting again.")
            .arg(RemoteTorPort->text()));
    }else{
        torControlStatus->setText(i18n("<p>I can't contact or authenticate to Tor.<br>"
            "This means Tork will need to modify Tor's settings if it is to be usable by Tork in future.</p>"
            "To the right is a list of the possible files that Tor may be using for it's configuration.<br>"
            "If you click the <b>'Modify Tor's Control File'</b> button, I'll modify any that exist to make Tor controllable by TorK.<br>"
            "Once that's done you can click <b>'Test Tor'</b> to re-test the connection."));
        modifyConfigs->setEnabled(true);
    }
    testTorAgain->setEnabled(true);

}

void FirstRunWizard::contactedTor()
{

    disconnect( client, SIGNAL(fatalError()),this, SLOT(cannotContactTor()));
    disconnect( client, SIGNAL(authenticated()),this, SLOT(contactedTor()) );
    if (client != 0L){
        client->socketReadyRead();
        client->deleteLater();
        client = 0L;
    }

    if (!monitorRemote->isChecked())
        torControlStatus->setText(i18n("<p>I contacted Tor successfully.<br>"
            "This means TorK can contact and control Tor. That's a good thing.<br>"
            "<b>By default, TorK will secure its session with Tor using a random "
            "password.</b> However, you should consider using a security option on "
            "Tor that will secure it even when you're not using TorK.<br>"
            "See the 'My Tor Client' configuration section for more info"
            " when you're finished the wizard. <br>"
            "You can now click <b>'Next'</b>."));
    else
        torControlStatus->setText(i18n("<p>I contacted Tor successfully.<br>"
            "This means TorK can contact and control Tor. That's a good thing. "
            "As a security precaution, you should configure your remote instance "
            "of Tor to require a password. You can inform TorK of the password "
            "using the 'My Tor Client' configuration section. "
            ));

    modifyConfigs->setEnabled(false);
    testTorAgain->setEnabled(true);
    TorkConfig::setGenerateRandomPassword(true);
//     if (!monitorRemote->isChecked())
//         TQTimer::singleShot( 3000, this, SLOT(examineConfigFiles()) );

}

void FirstRunWizard::examineConfigFiles()
{

    bool foundone = false;

    for (unsigned int index = 0; index != configCandidates->count(); ++index){
		if (TQFile::exists(configCandidates->item(index)->text()))
		{
			appendControlDirective(configCandidates->item(index)->text());
            foundone = true;
		}
    }

    if (!foundone){
        appendControlDirective("/usr/local/etc/tor/torrc");
        appendControlDirective("/etc/tor/torrc");
        appendControlDirective("/usr/etc/tor/torrc");
        torControlStatus->setText(i18n("<p>OK, I didn't find any of the config files in the list.<br>"
            "To make tor usable I'm creating config files in three locations: /usr/local/etc/tor/torrc, /usr/etc/tor/torrc and /etc/tor/torrc."
            "I've also asked Tor to reload and it will catch and use one of these files. "
            "<b> You'll be asked for your root password in a moment. "
            "<b> This is to modify the file and necessary to get Tor working.</b> "
            "When you've entered your password "
            "click <b>'Test Tor'</b> to see if it worked. "));
    }
}

void FirstRunWizard::pushButton6_clicked()
{
    rootifyNetstat();
}

void FirstRunWizard::rootifyNetstat()
{

    TQString newnetstat = TQString(netstat).replace("netstat","torknetstat");

    KProcIO *catproc = new KProcIO();
    catproc->setUseShell(TRUE);
    TQString whichCommand= TQString("tdesu -t -c 'cp %1 %2;chmod u+s %3'").arg(netstat).arg(newnetstat).arg(newnetstat);
    *catproc<<whichCommand;
    catproc->start(KProcIO::NotifyOnExit,TRUE);

}

void FirstRunWizard::sighupTor(const TQString& text)
{

    KProcIO *catproc = new KProcIO();
    catproc->setUseShell(TRUE);
    TQString whichCommand= TQString("killall -s HUP %1").arg(text);
    *catproc<<whichCommand;
    catproc->start(KProcIO::NotifyOnExit,TRUE);

}

void FirstRunWizard::appendControlDirective(const TQString& text)
{

    int result = KMessageBox::questionYesNo(this, 
                 i18n( "<p>I'm going to modify the Tor configuration file: <b>%1</b>.<br>"
                  "This is so that I can ensure"
                  "TorK can communicate with Tor.<br>"
                  " If you say Yes, I may have to ask for your <b>root password</b>.").arg(text));
    switch (result) {
        case KMessageBox::No : 
            return;
    }

    TQFile inf(text);
    if ( inf.open(IO_WriteOnly | IO_Append) ) {

        TQTextStream ts( &inf );

        ts << "ControlPort 9051" << "\n";

        inf.close();
        sighupTor("tor");

    }else{

		TQString directory = KURL(text).directory();
        KProcIO *catproc = new KProcIO();
        catproc->setUseShell(TRUE);
        TQString whichCommand= TQString("tdesu -c \"sh -c 'mkdir -p %1;printf \\\"ControlPort 9051\\n\\\""
                                      " >> %2;killall -s HUP tor'\"").arg(directory).arg(text);
        *catproc<<whichCommand;
        catproc->start(KProcIO::NotifyOnExit,TRUE);
	//-c "sh -c 'printf \"ControlPort 9051\n\" >> /etc/tor/torrc'"

    }

}

void FirstRunWizard::guessDataDir( )
{

    TQStringList dataDirCands;
    dataDirCands << TQString("%1/.tor/").arg(getenv("HOME"));
    dataDirCands << TQString("/var/lib/tor/");

    for ( TQStringList::Iterator it = dataDirCands.begin(); it != dataDirCands.end(); ++it ) {
        TQDir inf((*it));
        if ( inf.exists() ) {
            TorkConfig::setDataDirectory((*it));
            return;
        }
    }
}


void FirstRunWizard::RemoteTorAddress_textChanged( const TQString & text)
{
    if ((text == "127.0.0.1") || (text == "localhost"))
        TorPassword->setEnabled(false);
    else
        TorPassword->setEnabled(true);
}


void FirstRunWizard::modifyConfPrivoxy_clicked()
{
  examinePrivoxyConfigFiles();
}

void FirstRunWizard::examinePrivoxyConfigFiles()
{

    bool foundone = false;

    for (unsigned int index = 0; index != configCandidatesPrivoxy->count(); ++index){
		if (TQFile::exists(configCandidatesPrivoxy->item(index)->text()))
		{
			appendPrivoxyConfig(configCandidatesPrivoxy->item(index)->text());
            foundone = true;
		}
    }


    if (!foundone){
        appendPrivoxyConfig("/etc/privoxy/config");
        privoxyStatus->setText(i18n("<p>OK, I didn't find any of the config files in the list.<br>"
            "Tork has created a basic config in /etc/privoxy/config."
            "This <i>may</i> get things working, but possibly not.<br>"
            "You should:"
            "- Check Privoxy is properly installed."
            "- Re-install privoxy and try running the wizard again."
             ));
    }
}

void FirstRunWizard::appendPrivoxyConfig(const TQString& text)
{

    TQString privoxyConf = TQString(
            "confdir %1\\n"
            "logdir .\\n"
            "listen-address %2:%3\\n"
            "debug   1    # URLs\\n"
            "debug   4096 # Info\\n"
            "debug   8192 # Errors\\n"
            "toggle 1\\n"
            "buffer-limit 4069\\n"
            "forward         192.168.*.*/     .\\n"
            "forward            10.*.*.*/     .\\n"
            "forward           127.*.*.*/     .\\n"
            "forward-socks4a / %4:%5 .\\n")
            .arg(locate("data","tork/privoxy/"))
            .arg(TorkConfig::konqHttpProxy().replace("http://",""))
            .arg(TorkConfig::konqHttpProxyPort())
            .arg(TorkConfig::sOCKSBindAddressHost())
            .arg(TorkConfig::sOCKSBindAddressPort());

    int result = KMessageBox::questionYesNo(this, 
                 i18n( "<p>I'm going to modify the Privoxy configuration file: <b>%1</b>.<br>"
                  "This is so that I can ensure"
                  "Privoxy can communicate with Tor.<br>"
                  " If you say Yes, I'll ask for your root password.").arg(text));
    switch (result) {
        case KMessageBox::No : 
            return;
    }

    TQFile inf(text);
    if ( inf.open(IO_WriteOnly | IO_Append) ) {

        TQTextStream ts( &inf );

        ts << privoxyConf;

        inf.close();
        sighupTor("privoxy");

    }else{

        KProcIO *catproc = new KProcIO();
        catproc->setUseShell(TRUE);
        TQString whichCommand= TQString("tdesu -c \"sh -c 'printf \\\"%1\\\""
                                      " >> %2;killall -s HUP privoxy'\"")
                                      .arg(privoxyConf)
                                      .arg(text);
        *catproc<<whichCommand;
        catproc->start(KProcIO::NotifyOnExit,TRUE);

    }

}