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
|
/***************************************************************************
configuration.cpp
-------------------
begin : Tue Dec 11 2001
copyright : (C) 2001-2003 by Tim Jansen
email : tim@tjansen.de
***************************************************************************/
/***************************************************************************
* *
* 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 "configuration.h"
#include "kinetinterface.h"
#include <kglobal.h>
#include <klocale.h>
#include <kapplication.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <ksockaddr.h>
#include <kactivelabel.h>
#include <tqdatastream.h>
#include <dcopclient.h>
#include <dcopref.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqlineedit.h>
#include <tqcheckbox.h>
#include <krun.h>
/**
* Note that this class is used and provides GUI in every mode:
* - for the invitation dialogs
* - for the kcontrol module
* - for the running krfb instance
*/
Configuration::Configuration(krfb_mode mode) :
m_mode(mode),
invMngDlg(0, 0, true),
invDlg(0, "InviteDialog"),
persInvDlg(0, "PersonalInviteDialog"),
portNum(-1),
kinetdRef("kded", "kinetd")
{
kinetdRef.setDCOPClient(KApplication::dcopClient());
loadFromKConfig();
saveToDialogs();
doKinetdConf();
connectDCOPSignal( 0, "KRFB::ConfigChanged", "KRFB_ConfigChanged()",
"updateKConfig()", false );
connect(invMngDlg.newPersonalInvitationButton, TQT_SIGNAL(clicked()),
TQT_SLOT(showPersonalInvitationDialog()));
connect(invMngDlg.newEmailInvitationButton, TQT_SIGNAL(clicked()), TQT_SLOT(inviteEmail()));
connect(invMngDlg.deleteOneButton, TQT_SIGNAL(clicked()), TQT_SLOT(invMngDlgDeleteOnePressed()));
connect(invMngDlg.deleteAllButton, TQT_SIGNAL(clicked()), TQT_SLOT(invMngDlgDeleteAllPressed()));
invMngDlg.listView->setSelectionMode(TQListView::Extended);
invMngDlg.listView->setMinimumSize(TQSize(400, 100)); // TQTs size is much to small
connect(&invDlg, TQT_SIGNAL(createInviteClicked()),
TQT_SLOT(showPersonalInvitationDialog()));
connect(&invDlg, TQT_SIGNAL(emailInviteClicked()),
TQT_SLOT(inviteEmail()));
connect(&invDlg, TQT_SIGNAL(manageInviteClicked()),
TQT_SLOT(showManageInvitationsDialog()));
connect(&invDlg, TQT_SIGNAL(configureClicked()),
TQT_SLOT(showConfigurationModule()));
connect(this, TQT_SIGNAL(invitationNumChanged(int)),
&invDlg, TQT_SLOT(setInviteCount(int)));
connect(this, TQT_SIGNAL(invitationNumChanged(int)),
&invMngDlg, TQT_SLOT(listSizeChanged(int)));
emit invitationNumChanged(invitationList.size());
connect(&refreshTimer, TQT_SIGNAL(timeout()), TQT_SLOT(refreshTimeout()));
refreshTimer.start(1000*60);
}
Configuration::~Configuration() {
save();
}
void Configuration::updateKConfig()
{
loadFromKConfig();
}
void Configuration::setKInetdEnabled(bool enabled) {
kinetdRef.send("setEnabled", TQString("krfb"), enabled);
kinetdRef.send("setEnabled", TQString("krfb_httpd"), enabled);
}
void Configuration::setKInetdEnabled(const TQDateTime &date) {
kinetdRef.send("setEnabled", TQString("krfb"), date);
kinetdRef.send("setEnabled", TQString("krfb_httpd"), date);
}
void Configuration::setKInetdServiceRegistrationEnabled(bool enabled) {
kinetdRef.send("setServiceRegistrationEnabled",
TQString("krfb"), enabled);
kinetdRef.send("setServiceRegistrationEnabled",
TQString("krfb_httpd"), enabled);
}
void Configuration::getPortFromKInetd() {
DCOPReply r = kinetdRef.call("port", TQString("krfb"));
if (!r.isValid())
return; // nice error msg here?
r.get(portNum);
}
void Configuration::setKInetdPort(int p) {
DCOPReply r = kinetdRef.call("setPort",
TQString("krfb"), p, 1);
// nice error msg here?
}
void Configuration::removeInvitation(TQValueList<Invitation>::iterator it) {
invitationList.remove(it);
save();
}
void Configuration::doKinetdConf() {
setKInetdPort(preferredPortNum);
if (allowUninvitedFlag) {
setKInetdEnabled(true);
setKInetdServiceRegistrationEnabled(enableSLPFlag);
getPortFromKInetd();
return;
}
TQDateTime lastExpiration;
TQValueList<Invitation>::iterator it = invitationList.begin();
while (it != invitationList.end()) {
Invitation &ix = (*it);
TQDateTime t = ix.expirationTime();
if (t > lastExpiration)
lastExpiration = t;
it++;
}
if (lastExpiration.isNull() || (lastExpiration < TQDateTime::tqcurrentDateTime())) {
setKInetdEnabled(false);
portNum = -1;
}
else {
setKInetdServiceRegistrationEnabled(false);
setKInetdEnabled(lastExpiration);
getPortFromKInetd();
}
}
void Configuration::loadFromKConfig() {
KConfig c("krfbrc");
allowUninvitedFlag = c.readBoolEntry("allowUninvited", false);
enableSLPFlag = c.readBoolEntry("enableSLP", true);
askOnConnectFlag = c.readBoolEntry("confirmUninvitedConnection", true);
allowDesktopControlFlag = c.readBoolEntry("allowDesktopControl", false);
preferredPortNum = c.readNumEntry("preferredPort", -1);
disableBackgroundFlag = c.readBoolEntry("disableBackground", false);
disableXShmFlag = c.readBoolEntry("disableXShm", false);
if (c.hasKey("uninvitedPasswordCrypted"))
passwordString = cryptStr(c.readEntry("uninvitedPasswordCrypted", ""));
else
passwordString = c.readEntry("uninvitedPassword", "");
unsigned int invNum = invitationList.size();
invitationList.clear();
c.setGroup("invitations");
int num = c.readNumEntry("invitation_num", 0);
for (int i = 0; i < num; i++)
invitationList.push_back(Invitation(&c, i));
invalidateOldInvitations();
if (invNum != invitationList.size())
emit invitationNumChanged(invitationList.size());
}
void Configuration::saveToKConfig() {
KConfig c("krfbrc");
c.writeEntry("confirmUninvitedConnection", askOnConnectFlag);
c.writeEntry("allowDesktopControl", allowDesktopControlFlag);
c.writeEntry("allowUninvited", allowUninvitedFlag);
c.writeEntry("enableSLP", enableSLPFlag);
c.writeEntry("preferredPort", preferredPortNum);
c.writeEntry("disableBackground", disableBackgroundFlag);
c.writeEntry("disableXShm", disableXShmFlag);
c.writeEntry("uninvitedPasswordCrypted", cryptStr(passwordString));
c.deleteEntry("uninvitedPassword");
c.setGroup("invitations");
int num = invitationList.count();
c.writeEntry("invitation_num", num);
int i = 0;
while (i < num) {
invitationList[i].save(&c, i);
i++;
}
}
void Configuration::saveToDialogs() {
invalidateOldInvitations();
TQValueList<Invitation>::iterator it = invitationList.begin();
while (it != invitationList.end()) {
Invitation &inv = *(it++);
if (!inv.getViewItem())
inv.setViewItem(new KListViewItem(invMngDlg.listView,
inv.creationTime().toString(Qt::LocalDate),
inv.expirationTime().toString(Qt::LocalDate)));
}
invMngDlg.adjustSize();
}
void Configuration::save() {
saveToKConfig();
saveToDialogs();
doKinetdConf();
}
void Configuration::update() {
loadFromKConfig();
saveToDialogs();
}
Invitation Configuration::createInvitation() {
Invitation inv;
invitationList.push_back(inv);
return inv;
}
void Configuration::invalidateOldInvitations() {
TQValueList<Invitation>::iterator it = invitationList.begin();
while (it != invitationList.end()) {
if (!(*it).isValid())
it = invitationList.remove(it);
else
it++;
}
}
void Configuration::refreshTimeout() {
unsigned int invNum = invitationList.size();
loadFromKConfig();
saveToDialogs();
if (invNum != invitationList.size())
emit invitationNumChanged(invitationList.size());
}
TQString Configuration::hostname() const
{
KInetSocketAddress *a = KInetInterface::getPublicInetAddress();
TQString hostName;
if (a) {
hostName = a->nodeName();
delete a;
}
else
hostName = "localhost";
return hostName;
}
///////// properties ///////////////////////////
krfb_mode Configuration::mode() const {
return m_mode;
}
bool Configuration::askOnConnect() const {
return askOnConnectFlag;
}
bool Configuration::allowDesktopControl() const {
return allowDesktopControlFlag;
}
bool Configuration::allowUninvitedConnections() const {
return allowUninvitedFlag;
}
bool Configuration::enableSLP() const {
return enableSLPFlag;
}
TQString Configuration::password() const {
return passwordString;
}
TQValueList<Invitation> &Configuration::invitations() {
return invitationList;
}
bool Configuration::disableBackground() const {
return disableBackgroundFlag;
}
bool Configuration::disableXShm() const {
return disableXShmFlag;
}
void Configuration::setAllowUninvited(bool allowUninvited) {
allowUninvitedFlag = allowUninvited;
}
void Configuration::setEnableSLP(bool e) {
enableSLPFlag = e;
}
void Configuration::setAskOnConnect(bool askOnConnect)
{
askOnConnectFlag = askOnConnect;
}
void Configuration::setAllowDesktopControl(bool allowDesktopControl)
{
allowDesktopControlFlag = allowDesktopControl;
}
void Configuration::setPassword(TQString password)
{
passwordString = password;
}
int Configuration::port() const
{
if ((portNum < 5900) || (portNum >= 6000))
return portNum;
else
return portNum - 5900;
}
// use p=-1 for defaults
void Configuration::setPreferredPort(int p)
{
preferredPortNum = p;
}
int Configuration::preferredPort() const
{
return preferredPortNum;
}
void Configuration::setDisableBackground(bool disable) {
disableBackgroundFlag = disable;
}
void Configuration::setDisableXShm(bool disable) {
disableXShmFlag = disable;
}
////////////// invitation manage dialog //////////////////////////
void Configuration::showManageInvitationsDialog() {
loadFromKConfig();
saveToDialogs();
invMngDlg.exec();
}
void Configuration::invMngDlgDeleteOnePressed() {
TQValueList<Invitation>::iterator it = invitationList.begin();
while (it != invitationList.end()) {
Invitation &ix = (*it);
KListViewItem *iv = ix.getViewItem();
if (iv && iv->isSelected())
it = invitationList.remove(it);
else
it++;
}
saveToKConfig();
doKinetdConf();
emit invitationNumChanged(invitationList.size());
}
void Configuration::invMngDlgDeleteAllPressed() {
invitationList.clear();
saveToKConfig();
doKinetdConf();
emit invitationNumChanged(invitationList.size());
}
////////////// invitation dialog //////////////////////////
void Configuration::showInvitationDialog() {
invDlg.exec();
emit invitationFinished();
saveToKConfig();
}
////////////// personal invitation dialog //////////////////////////
void Configuration::showPersonalInvitationDialog() {
loadFromKConfig();
Invitation inv = createInvitation();
save();
emit invitationNumChanged(invitationList.size());
invDlg.enableInviteButton(false);
invMngDlg.newPersonalInvitationButton->setEnabled(false);
persInvDlg.setHost(hostname(), port());
persInvDlg.setPassword(inv.password());
persInvDlg.setExpiration(inv.expirationTime());
persInvDlg.exec();
invDlg.enableInviteButton(true);
invMngDlg.newPersonalInvitationButton->setEnabled(true);
}
////////////// invite email //////////////////////////
void Configuration::inviteEmail() {
int r = KMessageBox::warningContinueCancel(0,
i18n("When sending an invitation by email, note that everybody who reads this email "
"will be able to connect to your computer for one hour, or until the first "
"successful connection took place, whichever comes first. \n"
"You should either encrypt the email or at least send it only in a "
"secure network, but not over the Internet."),
i18n("Send Invitation via Email"),
KStdGuiItem::cont(),
"showEmailInvitationWarning");
if (r == KMessageBox::Cancel)
return;
loadFromKConfig();
Invitation inv = createInvitation();
save();
emit invitationNumChanged(invitationList.size());
KApplication *app = KApplication::kApplication();
app->invokeMailer(TQString(), TQString(), TQString(),
i18n("Desktop Sharing (VNC) invitation"),
i18n("You have been invited to a VNC session. If you have the KDE Remote "
"Desktop Connection installed, just click on the link below.\n\n"
"vnc://invitation:%1@%2:%3\n\n"
"Otherwise you can use any VNC client with the following parameters:\n\n"
"Host: %4:%5\n"
"Password: %6\n\n"
"Alternatively you can click on the link below to start the VNC session\n"
"within your web browser.\n"
"\n"
" http://%7:%8/\n"
"\n"
"For security reasons this invitation will expire at %9.")
.tqarg(inv.password())
.tqarg(hostname())
.tqarg(port())
.tqarg(hostname())
.tqarg(port())
.tqarg(inv.password())
.tqarg(hostname())
.tqarg(5800) // determine with dcop ... later ...
.tqarg(KGlobal::locale()->formatDateTime(inv.expirationTime())));
}
////////////// invoke kcontrol module //////////////////////////
void Configuration::showConfigurationModule() {
KRun::run( "kcmshell kcmkrfb", KURL::List() );
}
#include "configuration.moc"
|