• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krfb

  • sources
  • kde-4.14
  • kdenetwork
  • krfb
  • krfb
invitationsrfbserver.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009-2010 Collabora Ltd <info@collabora.co.uk>
3  @author George Goldberg <george.goldberg@collabora.co.uk>
4  @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
5  Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
6  Copyright (C) 2001-2003 by Tim Jansen <tim@tjansen.de>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "invitationsrfbserver.h"
22 #include "invitationsrfbclient.h"
23 #include "krfbconfig.h"
24 #include "rfbservermanager.h"
25 #include <QtCore/QTimer>
26 #include <QtGui/QApplication>
27 #include <QtNetwork/QHostInfo>
28 #include <KNotification>
29 #include <KLocale>
30 #include <KMessageBox>
31 #include <KUser>
32 #include <KRandom>
33 #include <KStringHandler>
34 #include <KWallet/Wallet>
35 #include <DNSSD/PublicService>
36 using KWallet::Wallet;
37 
38 //static
39 InvitationsRfbServer *InvitationsRfbServer::instance;
40 
41 //static
42 void InvitationsRfbServer::init()
43 {
44  instance = new InvitationsRfbServer;
45  instance->m_publicService = new DNSSD::PublicService(
46  i18n("%1@%2 (shared desktop)",
47  KUser().loginName(),
48  QHostInfo::localHostName()),
49  "_rfb._tcp",
50  KrfbConfig::port());
51  instance->setListeningAddress("0.0.0.0");
52  instance->setListeningPort(KrfbConfig::port());
53  instance->setPasswordRequired(true);
54 
55  instance->m_wallet = Wallet::openWallet(
56  Wallet::NetworkWallet(), 0, Wallet::Asynchronous);
57  if(instance->m_wallet) {
58  connect(instance->m_wallet, SIGNAL(walletOpened(bool)),
59  instance, SLOT(walletOpened(bool)));
60  }
61 }
62 
63 const QString& InvitationsRfbServer::desktopPassword() const
64 {
65  return m_desktopPassword;
66 }
67 
68 void InvitationsRfbServer::setDesktopPassword(const QString& password)
69 {
70  m_desktopPassword = password;
71 }
72 
73 const QString& InvitationsRfbServer::unattendedPassword() const
74 {
75  return m_unattendedPassword;
76 }
77 
78 void InvitationsRfbServer::setUnattendedPassword(const QString& password)
79 {
80  m_unattendedPassword = password;
81 }
82 
83 bool InvitationsRfbServer::allowUnattendedAccess() const
84 {
85  return m_allowUnattendedAccess;
86 }
87 
88 bool InvitationsRfbServer::start()
89 {
90  if(RfbServer::start()) {
91  if(KrfbConfig::publishService())
92  m_publicService->publishAsync();
93  return true;
94  }
95  return false;
96 }
97 
98 void InvitationsRfbServer::stop(bool disconnectClients)
99 {
100  if(m_publicService->isPublished())
101  m_publicService->stop();
102  RfbServer::stop(disconnectClients);
103 }
104 
105 void InvitationsRfbServer::toggleUnattendedAccess(bool allow)
106 {
107  m_allowUnattendedAccess = allow;
108 }
109 
110 InvitationsRfbServer::InvitationsRfbServer()
111 {
112  m_desktopPassword = readableRandomString(4)+"-"+readableRandomString(3);
113  m_unattendedPassword = readableRandomString(4)+"-"+readableRandomString(3);
114  KSharedConfigPtr config = KGlobal::config();
115  KConfigGroup krfbConfig(config,"Security");
116  m_allowUnattendedAccess = krfbConfig.readEntry(
117  "allowUnattendedAccess", QVariant(false)).toBool();
118 }
119 
120 InvitationsRfbServer::~InvitationsRfbServer()
121 {
122  stop();
123  KSharedConfigPtr config = KGlobal::config();
124  KConfigGroup krfbConfig(config,"Security");
125  krfbConfig.writeEntry("allowUnattendedAccess",m_allowUnattendedAccess);
126  if(m_wallet && m_wallet->isOpen()) {
127 
128  if( (m_wallet->currentFolder()=="krfb") ||
129  ((m_wallet->hasFolder("krfb") || m_wallet->createFolder("krfb")) &&
130  m_wallet->setFolder("krfb")) ) {
131 
132  m_wallet->writePassword("desktopSharingPassword",m_desktopPassword);
133  m_wallet->writePassword("unattendedAccessPassword",m_unattendedPassword);
134  }
135 
136  } else {
137  krfbConfig.writeEntry("desktopPassword",
138  KStringHandler::obscure(m_desktopPassword));
139  krfbConfig.writeEntry("unattendedPassword",
140  KStringHandler::obscure(m_unattendedPassword));
141  krfbConfig.writeEntry("allowUnattendedAccess",
142  m_allowUnattendedAccess);
143  }
144 }
145 
146 PendingRfbClient* InvitationsRfbServer::newClient(rfbClientPtr client)
147 {
148  return new PendingInvitationsRfbClient(client, this);
149 }
150 
151 void InvitationsRfbServer::walletOpened(bool opened)
152 {
153  QString desktopPassword;
154  QString unattendedPassword;
155  Q_ASSERT(m_wallet);
156  if( opened &&
157  ( m_wallet->hasFolder("krfb") || m_wallet->createFolder("krfb") ) &&
158  m_wallet->setFolder("krfb") ) {
159 
160  if(m_wallet->readPassword("desktopSharingPassword", desktopPassword)==0 &&
161  !desktopPassword.isEmpty()) {
162  m_desktopPassword = desktopPassword;
163  emit passwordChanged(m_desktopPassword);
164  }
165 
166  if(m_wallet->readPassword("unattendedAccessPassword", unattendedPassword)==0 &&
167  !unattendedPassword.isEmpty()) {
168  m_unattendedPassword = unattendedPassword;
169  }
170 
171  } else {
172 
173  kDebug() << "Could not open KWallet, Falling back to config file";
174  KSharedConfigPtr config = KGlobal::config();
175  KConfigGroup krfbConfig(config,"Security");
176 
177  desktopPassword = KStringHandler::obscure(krfbConfig.readEntry(
178  "desktopPassword", QString()));
179  if(!desktopPassword.isEmpty()) {
180  m_desktopPassword = desktopPassword;
181  emit passwordChanged(m_desktopPassword);
182  }
183 
184  unattendedPassword = KStringHandler::obscure(krfbConfig.readEntry(
185  "unattendedPassword", QString()));
186  if(!unattendedPassword.isEmpty()) {
187  m_unattendedPassword = unattendedPassword;
188  }
189 
190  }
191 }
192 
193 // a random string that doesn't contain i, I, o, O, 1, l, 0
194 // based on KRandom::randomString()
195 QString InvitationsRfbServer::readableRandomString(int length)
196 {
197  QString str;
198  while (length) {
199  int r = KRandom::random() % 62;
200  r += 48;
201  if (r > 57) {
202  r += 7;
203  }
204  if (r > 90) {
205  r += 6;
206  }
207  char c = char(r);
208  if ((c == 'i') ||
209  (c == 'I') ||
210  (c == '1') ||
211  (c == 'l') ||
212  (c == 'o') ||
213  (c == 'O') ||
214  (c == '0')) {
215  continue;
216  }
217  str += c;
218  length--;
219  }
220  return str;
221 }
222 
223 #include "invitationsrfbserver.moc"
InvitationsRfbServer::init
static void init()
Definition: invitationsrfbserver.cpp:42
InvitationsRfbServer::start
bool start()
Definition: invitationsrfbserver.cpp:88
InvitationsRfbServer::~InvitationsRfbServer
virtual ~InvitationsRfbServer()
Definition: invitationsrfbserver.cpp:120
InvitationsRfbServer::setUnattendedPassword
void setUnattendedPassword(const QString &)
Definition: invitationsrfbserver.cpp:78
RfbServer::setListeningPort
void setListeningPort(int port)
Definition: rfbserver.cpp:78
InvitationsRfbServer::allowUnattendedAccess
bool allowUnattendedAccess() const
Definition: invitationsrfbserver.cpp:83
InvitationsRfbServer::InvitationsRfbServer
InvitationsRfbServer()
Definition: invitationsrfbserver.cpp:110
_rfbClientRec
Definition: libvncserver/rfb/rfb.h:417
KrfbConfig::publishService
static bool publishService()
Get Announce the service on the local network.
Definition: krfbconfig.h:41
InvitationsRfbServer::desktopPassword
const QString & desktopPassword() const
Definition: invitationsrfbserver.cpp:63
InvitationsRfbServer::toggleUnattendedAccess
void toggleUnattendedAccess(bool allow=true)
Definition: invitationsrfbserver.cpp:105
InvitationsRfbServer::newClient
virtual PendingRfbClient * newClient(rfbClientPtr client)
Definition: invitationsrfbserver.cpp:146
krfbconfig.h
RfbServer::start
virtual bool start()
Definition: rfbserver.cpp:88
InvitationsRfbServer
Definition: invitationsrfbserver.h:33
QString::isEmpty
bool isEmpty() const
RfbServer::stop
virtual void stop(bool disconnectClients=true)
Definition: rfbserver.cpp:146
KrfbConfig::port
static int port()
Get This is the port on which krfb will listen.
Definition: krfbconfig.h:31
QString
RfbServer::setPasswordRequired
void setPasswordRequired(bool passwordRequired)
Definition: rfbserver.cpp:83
InvitationsRfbServer::passwordChanged
void passwordChanged(const QString &)
invitationsrfbclient.h
InvitationsRfbServer::stop
void stop(bool disconnectClients=true)
Definition: invitationsrfbserver.cpp:98
InvitationsRfbServer::setDesktopPassword
void setDesktopPassword(const QString &)
Definition: invitationsrfbserver.cpp:68
InvitationsRfbServer::instance
static InvitationsRfbServer * instance
Definition: invitationsrfbserver.h:37
RfbServer::setListeningAddress
void setListeningAddress(const QByteArray &address)
Definition: rfbserver.cpp:73
PendingInvitationsRfbClient
Definition: invitationsrfbclient.h:31
InvitationsRfbServer::unattendedPassword
const QString & unattendedPassword() const
Definition: invitationsrfbserver.cpp:73
QHostInfo::localHostName
QString localHostName()
invitationsrfbserver.h
PendingRfbClient
Definition: krfb/rfbclient.h:72
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
rfbservermanager.h
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krfb

Skip menu "krfb"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal