summaryrefslogtreecommitdiffstats
path: root/src/hidsrvwizard.ui.h
blob: 3cb31a81cc41c77cbbd375daaedd339fe8ff5476 (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
/***************************************************************************
 *   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.              *
 ***************************************************************************/

#include "tork.h"
#include "functions.h"
#include <ntqtimer.h>
#include <kmessagebox.h>
#include <cstdlib>

bool local;
TQString thttpd;


void HidSrvWizard::init()
{
    local=false;
    setAppropriate ( LocalWebService, false );
    setAppropriate ( LocalWebServiceFiles, false );
    setAppropriate ( ServiceName, true );
    setAppropriate ( RedirectService, true );

    TQString location = getenv("HOME");
    location += "/.tork";
    TQDir torkdir(location);
    if (!torkdir.exists() && !torkdir.mkdir(location)){
        KMessageBox::information (this,TQString("Couldn't create directory: %1. Check the permissions!").arg(location));
        reject();
    }


}
void HidSrvWizard::localWeb_toggled( bool state)
{



    if (state){
        const char *paths = ":/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
        thttpd = getFullLocation(paths,"thttpd");
   
        if (thttpd)
            setAppropriate ( LocalWebService, !state );
        else
            setAppropriate ( LocalWebService, state );
    }else
        setAppropriate ( LocalWebService, state );

    setAppropriate ( LocalWebServiceFiles, state );
    setAppropriate ( RedirectService, !state );
    local = state;


}


void HidSrvWizard::downloadThttpd_clicked()
{
    TorkUpdate* updater = new TorkUpdate(this);
    updater->downloadThttpd();

}


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


    if (currentPage() == this->GatherDetails){
        if (local)
            emit createService(TQString("%1/.tork/%2/").arg(getenv("HOME")).arg(Nick->text()), TQString("%1 localhost:%2").arg(WebPort->text()).arg(localWebPort->text()));
        else
            emit createService(TQString("%1/.tork/%2/").arg(getenv("HOME")).arg(Nick->text()), TQString("%1 %2:%3").arg(NonWebPort->text()).arg(RedirectAddress->text()).arg(RedirectPort->text()));
        GatheringDetailsText->setText("Please wait while Tor attempts to create the service.");
        TQTimer::singleShot( 3000, this, SLOT(checkServiceDetails()) );
        finishButton()->setEnabled(false);
    }

}

void
HidSrvWizard::checkServiceDetails()
{

    TQString hostname;
    TQFile inf(TQString("%1/.tork/%2/hostname").arg(getenv("HOME")).arg(Nick->text()));
    if ( inf.open(IO_ReadOnly) ) {
        inf.readLine(hostname,50);
        inf.close();
    }else{
        GatheringDetailsText->setText("Failed. Click Back and Next to try again.");
        return;
    }

    hostname.replace("\n","");

    cancelButton()->setEnabled(false);

    TQString serviceDetails = "Hidden Service Hostname: ";
    serviceDetails += hostname;
    serviceDetails += "<br>";
    if (local){
        serviceDetails += "Serving files in:";
        serviceDetails += FilesToServe->url();
        serviceDetails += "<br>";
        serviceDetails += "Public Facing Port:"; 
        serviceDetails += WebPort->text();
        serviceDetails += "<br>";
        serviceDetails += "Tor Facing Port:"; 
        serviceDetails += localWebPort->text();
        emit addService(Nick->text(),WebPort->text(),TQString("localhost:%1").arg(localWebPort->text()),hostname,FilesToServe->url(),TQString("%1/.tork/%2/").arg(getenv("HOME")).arg(Nick->text()));

    }else{
        serviceDetails += "Redirecting to:";
        serviceDetails += RedirectAddress->text();
        serviceDetails += "<br>";
        serviceDetails += "On Port:";
        serviceDetails  += RedirectPort->text();
        serviceDetails += "<br>";
        serviceDetails += "Serving Tor Network with Port:";
        serviceDetails  += NonWebPort->text();
        serviceDetails += "<br>";
        emit addService(Nick->text(),NonWebPort->text(),TQString("%1:%2").arg(RedirectAddress->text()).arg(RedirectPort->text()),hostname,"",TQString("%1/.tork/%2/").arg(getenv("HOME")).arg(Nick->text()));

    }


    GatheringDetailsText->setText(serviceDetails);
    finishButton()->setEnabled(true);

}

void
HidSrvWizard::accept()
{
    TQDialog::accept();
}

void
HidSrvWizard::reject()
{
    TQDialog::reject();
}