~x2go/x2go/x2goclient_master

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
/**************************************************************************
*   Copyright (C) 2005-2020 by Oleksandr Shneyder                         *
*                              <o.shneyder@phoca-gmbh.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.                                   *
*   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, see <https://www.gnu.org/licenses/>. *
***************************************************************************/

#ifndef HTTPBROKERCLIENT_H
#define HTTPBROKERCLIENT_H
#include "x2goclientconfig.h"
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSslError>
#include <QBuffer>
#include <QObject>
#include <QDateTime>
#include <QSslSocket>
#include "sshmasterconnection.h"
/**
	@author Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>
*/
class QNetworkAccessManager;
struct ConfigFile;
class ONMainWindow;

class HttpBrokerClient: public QObject
{
    Q_OBJECT
public:
    HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg );
    ~HttpBrokerClient();
    void selectUserSession(const QString& session, const QString& loginName);
    void changePassword(QString newPass);
    void testConnection();
    void closeSSHInteractionDialog();
    void sendEvent(const QString& ev, const QString& id, const QString& server, const QString& client,
                   const QString& login, const QString& cmd, const QString& display, const QString& start, uint connectionTime);
    void resumeSession(const QString& id, const QString& server);
private:
    QNetworkAccessManager* http;
    QNetworkRequest* netRequest;
    QSslSocket* sslSocket;
    QNetworkReply* sessionsRequest;
    QNetworkReply* selSessRequest;
    QNetworkReply* chPassRequest;
    QNetworkReply* testConRequest;
    QNetworkReply* eventRequest;
    //List of replies with http resources (icons)
    QList<QNetworkReply*> resReplies;
    QString nextAuthId;
    QString newBrokerPass;
    ConfigFile* config;
    ONMainWindow* mainWindow;
    QTime requestTime;
    bool sshBroker;
    SshMasterConnection* sshConnection;
    QStringList suspendedSession;
private:
    void createIniFile(const QString& raw_content);
    void processClientConfig(const QString& raw_content);
    void parseSession(QString sInfo);
    void createSshConnection();
    bool checkAccess(QString answer);
    QString scramblePwd(const QString& req);
    QString getResource(QString resURL);
    QString resourceFname(const QUrl& url);
    bool isResRequested(const QUrl& url);
    void clearResRequests();

private slots:
    void slotRequestFinished ( QNetworkReply*  reply );
    void slotSslErrors ( QNetworkReply* netReply, const QList<QSslError> & errors ) ;
    QString getHexVal ( const QByteArray& ba );
    void slotSshConnectionError ( QString message, QString lastSessionError );
    void slotSshServerAuthError ( int error, QString sshMessage, SshMasterConnection* connection );
    void slotSshServerAuthPassphrase ( SshMasterConnection* connection, SshMasterConnection::passphrase_types passphrase_type = SshMasterConnection::PASSPHRASE_PRIVKEY );
    void slotSshUserAuthError ( QString error );
    void slotSshConnectionOk();
    void slotListSessions ( bool success, QString answer, int pid);
    void slotSelectSession ( bool success, QString answer, int pid);
    void slotPassChanged ( bool success, QString answer, int pid);
    void slotEventSent ( bool success, QString answer, int pid);
    void slotConnectionTest( bool success, QString answer, int pid);
    void slotSshIoErr(SshProcess* caller, QString error, QString lastSessionError);

public slots:
    void getUserSessions();

signals:
    void haveSshKey ( QString );
    void fatalHttpError();
    void authFailed();
    void sessionsLoaded();
    void sessionSelected( );
    void passwordChanged( QString );
    void connectionTime(int, int);
    void enableBrokerLogoutButton ();
};

#endif