mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
krfb moved away from invitation based model
-Allow user to start/stop the service as needeed -Allow user to change & view password in main UI -Legitimate incoming requests accepted
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "invitationsrfbclient.h"
|
||||
#include "invitationsrfbserver.h"
|
||||
#include "krfbconfig.h"
|
||||
#include "sockethelpers.h"
|
||||
#include "connectiondialog.h"
|
||||
@@ -30,9 +31,9 @@ bool InvitationsRfbClient::checkPassword(const QByteArray & encryptedPassword)
|
||||
QByteArray password ;
|
||||
kDebug() << "about to start autentication";
|
||||
|
||||
//TODO Check password when server is started
|
||||
kWarning() << "This build is broken. No incoming request can be accepted.";
|
||||
return vncAuthCheckPassword(password, encryptedPassword);
|
||||
return vncAuthCheckPassword(
|
||||
InvitationsRfbServer::instance->desktopPassword().toLocal8Bit(),
|
||||
encryptedPassword);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,16 +29,56 @@
|
||||
#include <KLocale>
|
||||
#include <KMessageBox>
|
||||
#include <KUser>
|
||||
#include <KRandom>
|
||||
#include <DNSSD/PublicService>
|
||||
|
||||
//static
|
||||
InvitationsRfbServer *InvitationsRfbServer::instance;
|
||||
|
||||
//static
|
||||
void InvitationsRfbServer::init()
|
||||
{
|
||||
InvitationsRfbServer *server;
|
||||
server = new InvitationsRfbServer;
|
||||
server->setListeningPort(KrfbConfig::port());
|
||||
server->setListeningAddress("0.0.0.0"); // Listen on all available network addresses
|
||||
server->setPasswordRequired(true);
|
||||
QTimer::singleShot(0, server, SLOT(startAndCheck()));
|
||||
instance = new InvitationsRfbServer;
|
||||
instance->m_publicService = new DNSSD::PublicService(
|
||||
i18n("%1@%2 (shared desktop)",
|
||||
KUser().loginName(),
|
||||
QHostInfo::localHostName()),
|
||||
"_rfb._tcp",
|
||||
KrfbConfig::port());
|
||||
instance->setListeningAddress("0.0.0.0");
|
||||
instance->setListeningPort(KrfbConfig::port());
|
||||
instance->setPasswordRequired(true);
|
||||
}
|
||||
|
||||
const QString& InvitationsRfbServer::desktopPassword() const
|
||||
{
|
||||
return m_desktopPassword;
|
||||
}
|
||||
|
||||
void InvitationsRfbServer::setDesktopPassword(const QString& password)
|
||||
{
|
||||
m_desktopPassword = password;
|
||||
}
|
||||
|
||||
bool InvitationsRfbServer::start()
|
||||
{
|
||||
if(RfbServer::start()) {
|
||||
m_publicService->publishAsync();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void InvitationsRfbServer::stop(bool disconnectClients)
|
||||
{
|
||||
if(m_publicService->isPublished())
|
||||
m_publicService->stop();
|
||||
RfbServer::stop(disconnectClients);
|
||||
}
|
||||
|
||||
InvitationsRfbServer::InvitationsRfbServer()
|
||||
{
|
||||
m_desktopPassword = readableRandomString(4)+"-"+readableRandomString(3);
|
||||
}
|
||||
|
||||
PendingRfbClient* InvitationsRfbServer::newClient(rfbClientPtr client)
|
||||
@@ -46,26 +86,34 @@ PendingRfbClient* InvitationsRfbServer::newClient(rfbClientPtr client)
|
||||
return new PendingInvitationsRfbClient(client, this);
|
||||
}
|
||||
|
||||
void InvitationsRfbServer::startAndCheck()
|
||||
// a random string that doesn't contain i, I, o, O, 1, l, 0
|
||||
// based on KRandom::randomString()
|
||||
QString InvitationsRfbServer::readableRandomString(int length)
|
||||
{
|
||||
if (!start()) {
|
||||
KMessageBox::error(0, i18n("Failed to start the krfb server. Invitation-based sharing "
|
||||
"will not work. Try setting another port in the settings and "
|
||||
"restart krfb."));
|
||||
} else {
|
||||
//publish service
|
||||
if (KrfbConfig::publishService()) {
|
||||
DNSSD::PublicService *service = new DNSSD::PublicService(i18n("%1@%2 (shared desktop)",
|
||||
KUser().loginName(),
|
||||
QHostInfo::localHostName()),
|
||||
"_rfb._tcp",
|
||||
listeningPort());
|
||||
service->publishAsync();
|
||||
QString str;
|
||||
while (length) {
|
||||
int r = KRandom::random() % 62;
|
||||
r += 48;
|
||||
if (r > 57) {
|
||||
r += 7;
|
||||
}
|
||||
|
||||
//disconnect when qApp quits
|
||||
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(stop()));
|
||||
if (r > 90) {
|
||||
r += 6;
|
||||
}
|
||||
char c = char(r);
|
||||
if ((c == 'i') ||
|
||||
(c == 'I') ||
|
||||
(c == '1') ||
|
||||
(c == 'l') ||
|
||||
(c == 'o') ||
|
||||
(c == 'O') ||
|
||||
(c == '0')) {
|
||||
continue;
|
||||
}
|
||||
str += c;
|
||||
length--;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#include "invitationsrfbserver.moc"
|
||||
|
||||
@@ -22,21 +22,33 @@
|
||||
|
||||
#include "rfbserver.h"
|
||||
|
||||
namespace DNSSD {
|
||||
class PublicService;
|
||||
}
|
||||
|
||||
class InvitationsRfbServer : public RfbServer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static InvitationsRfbServer *instance;
|
||||
static void init();
|
||||
|
||||
protected:
|
||||
InvitationsRfbServer() : RfbServer(0) {}
|
||||
const QString& desktopPassword() const;
|
||||
void setDesktopPassword(const QString&);
|
||||
|
||||
public Q_SLOTS:
|
||||
bool start();
|
||||
void stop(bool disconnectClients=true);
|
||||
|
||||
protected:
|
||||
InvitationsRfbServer();
|
||||
virtual PendingRfbClient* newClient(rfbClientPtr client);
|
||||
|
||||
private Q_SLOTS:
|
||||
void startAndCheck();
|
||||
|
||||
private:
|
||||
DNSSD::PublicService *m_publicService;
|
||||
QString m_desktopPassword;
|
||||
|
||||
QString readableRandomString(int);
|
||||
Q_DISABLE_COPY(InvitationsRfbServer)
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
#include "mainwindow.h"
|
||||
#include "invitationsrfbserver.h"
|
||||
|
||||
#include "krfbconfig.h"
|
||||
#include "ui_configtcp.h"
|
||||
@@ -22,7 +23,6 @@
|
||||
#include <KToolInvocation>
|
||||
#include <KStandardAction>
|
||||
#include <KActionCollection>
|
||||
#include <KRandom>
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtNetwork/QNetworkInterface>
|
||||
@@ -79,8 +79,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
}
|
||||
|
||||
//Figure out the password
|
||||
m_password = readableRandomString(4) + '-' + readableRandomString(3);
|
||||
m_ui.passwordDisplayLabel->setText(m_password);
|
||||
m_ui.passwordDisplayLabel->setText(
|
||||
InvitationsRfbServer::instance->desktopPassword());
|
||||
|
||||
KStandardAction::quit(QCoreApplication::instance(), SLOT(quit()), actionCollection());
|
||||
KStandardAction::preferences(this, SLOT(showConfiguration()), actionCollection());
|
||||
@@ -100,25 +100,36 @@ void MainWindow::editPassword()
|
||||
if(m_passwordEditable) {
|
||||
m_passwordEditable = false;
|
||||
m_ui.passwordEditButton->setIcon(KIcon("document-properties"));
|
||||
m_password = m_passwordLineEdit->text();
|
||||
m_ui.passwordDisplayLabel->setText(m_password);
|
||||
m_passwordLineEdit->setVisible(false);
|
||||
m_ui.passwordGridLayout->removeWidget(m_passwordLineEdit);
|
||||
InvitationsRfbServer::instance->setDesktopPassword(
|
||||
m_passwordLineEdit->text());
|
||||
m_ui.passwordDisplayLabel->setText(
|
||||
InvitationsRfbServer::instance->desktopPassword());
|
||||
m_passwordLineEdit->setVisible(false);
|
||||
} else {
|
||||
m_passwordEditable = true;
|
||||
m_ui.passwordEditButton->setIcon(KIcon("document-save"));
|
||||
m_passwordLineEdit->setText(m_password);
|
||||
m_passwordLineEdit->setVisible(true);
|
||||
m_ui.passwordGridLayout->addWidget(m_passwordLineEdit,0,0);
|
||||
m_passwordLineEdit->setText(
|
||||
InvitationsRfbServer::instance->desktopPassword());
|
||||
m_passwordLineEdit->setVisible(true);
|
||||
m_passwordLineEdit->setFocus(Qt::MouseFocusReason);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::toggleDesktopSharing(bool enable)
|
||||
{
|
||||
if(enable) {
|
||||
//TODO Start Server
|
||||
kWarning() << "This build is broken. No incoming request can be accepted.";
|
||||
if(!InvitationsRfbServer::instance->start()) {
|
||||
KMessageBox::error(0,
|
||||
i18n("Failed to start the krfb server. Desktop sharing "
|
||||
"will not work. Try setting another port in the settings "
|
||||
"and restart krfb."));
|
||||
}
|
||||
connect(qApp, SIGNAL(aboutToQuit()), InvitationsRfbServer::instance, SLOT(stop()));
|
||||
} else {
|
||||
disconnect(qApp, SIGNAL(aboutToQuit()), InvitationsRfbServer::instance, SLOT(stop()));
|
||||
InvitationsRfbServer::instance->stop();
|
||||
if(m_passwordEditable) {
|
||||
m_passwordEditable = false;
|
||||
m_passwordLineEdit->setVisible(false);
|
||||
@@ -154,34 +165,4 @@ void MainWindow::saveProperties(KConfigGroup& group)
|
||||
KMainWindow::saveProperties(group);
|
||||
}
|
||||
|
||||
// a random string that doesn't contain i, I, o, O, 1, l, 0
|
||||
// based on KRandom::randomString()
|
||||
QString MainWindow::readableRandomString(int length)
|
||||
{
|
||||
QString str;
|
||||
while (length) {
|
||||
int r = KRandom::random() % 62;
|
||||
r += 48;
|
||||
if (r > 57) {
|
||||
r += 7;
|
||||
}
|
||||
if (r > 90) {
|
||||
r += 6;
|
||||
}
|
||||
char c = char(r);
|
||||
if ((c == 'i') ||
|
||||
(c == 'I') ||
|
||||
(c == '1') ||
|
||||
(c == 'l') ||
|
||||
(c == 'o') ||
|
||||
(c == 'O') ||
|
||||
(c == '0')) {
|
||||
continue;
|
||||
}
|
||||
str += c;
|
||||
length--;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#include "mainwindow.moc"
|
||||
|
||||
@@ -37,11 +37,8 @@ class MainWindow : public KXmlGuiWindow
|
||||
|
||||
private:
|
||||
Ui::MainWidget m_ui;
|
||||
QString m_password;
|
||||
bool m_passwordEditable;
|
||||
KLineEdit *m_passwordLineEdit;
|
||||
|
||||
static QString readableRandomString(int length);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,8 +40,8 @@ public:
|
||||
void setPasswordRequired(bool passwordRequired);
|
||||
|
||||
public Q_SLOTS:
|
||||
bool start();
|
||||
void stop(bool disconnectClients = true);
|
||||
virtual bool start();
|
||||
virtual void stop(bool disconnectClients = true);
|
||||
|
||||
void updateScreen(const QList<QRect> & modifiedTiles);
|
||||
void updateCursorPosition(const QPoint & position);
|
||||
|
||||
Reference in New Issue
Block a user