1 /************************************************************************** 2 * Copyright (C) 2005-2020 by Oleksandr Shneyder * 3 * <o.shneyder@phoca-gmbh.de> * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. * 16 ***************************************************************************/ 17 18 #ifndef HTTPBROKERCLIENT_H 19 #define HTTPBROKERCLIENT_H 20 #include "x2goclientconfig.h" 21 #include <QNetworkAccessManager> 22 #include <QUrl> 23 #include <QNetworkRequest> 24 #include <QNetworkReply> 25 #include <QSslError> 26 #include <QBuffer> 27 #include <QObject> 28 #include <QDateTime> 29 #include <QSslSocket> 30 #include "sshmasterconnection.h" 31 /** 32 @author Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de> 33 */ 34 class QNetworkAccessManager; 35 struct ConfigFile; 36 class ONMainWindow; 37 38 class HttpBrokerClient: public QObject 39 { 40 Q_OBJECT 41 public: 42 HttpBrokerClient ( ONMainWindow* wnd, ConfigFile* cfg ); 43 ~HttpBrokerClient(); 44 void selectUserSession(const QString& session, const QString& loginName); 45 void changePassword(QString newPass); 46 void testConnection(); 47 void closeSSHInteractionDialog(); 48 void sendEvent(const QString& ev, const QString& id, const QString& server, const QString& client, 49 const QString& login, const QString& cmd, const QString& display, const QString& start, uint connectionTime); 50 void resumeSession(const QString& id, const QString& server); 51 private: 52 QNetworkAccessManager* http; 53 QNetworkRequest* netRequest; 54 QSslSocket* sslSocket; 55 QNetworkReply* sessionsRequest; 56 QNetworkReply* selSessRequest; 57 QNetworkReply* chPassRequest; 58 QNetworkReply* testConRequest; 59 QNetworkReply* eventRequest; 60 QString nextAuthId; 61 QString newBrokerPass; 62 ConfigFile* config; 63 ONMainWindow* mainWindow; 64 QTime requestTime; 65 bool sshBroker; 66 SshMasterConnection* sshConnection; 67 QStringList suspendedSession; 68 private: 69 void createIniFile(const QString& raw_content); 70 void processClientConfig(const QString& raw_content); 71 void parseSession(QString sInfo); 72 void createSshConnection(); 73 bool checkAccess(QString answer); 74 QString scramblePwd(const QString& req); 75 76 private slots: 77 void slotRequestFinished ( QNetworkReply* reply ); 78 void slotSslErrors ( QNetworkReply* netReply, const QList<QSslError> & errors ) ; 79 QString getHexVal ( const QByteArray& ba ); 80 void slotSshConnectionError ( QString message, QString lastSessionError ); 81 void slotSshServerAuthError ( int error, QString sshMessage, SshMasterConnection* connection ); 82 void slotSshServerAuthPassphrase ( SshMasterConnection* connection, SshMasterConnection::passphrase_types passphrase_type = SshMasterConnection::PASSPHRASE_PRIVKEY ); 83 void slotSshUserAuthError ( QString error ); 84 void slotSshConnectionOk(); 85 void slotListSessions ( bool success, QString answer, int pid); 86 void slotSelectSession ( bool success, QString answer, int pid); 87 void slotPassChanged ( bool success, QString answer, int pid); 88 void slotEventSent ( bool success, QString answer, int pid); 89 void slotConnectionTest( bool success, QString answer, int pid); 90 void slotSshIoErr(SshProcess* caller, QString error, QString lastSessionError); 91 92 public slots: 93 void getUserSessions(); 94 95 signals: 96 void haveSshKey ( QString ); 97 void fatalHttpError(); 98 void authFailed(); 99 void sessionsLoaded(); 100 void sessionSelected( ); 101 void passwordChanged( QString ); 102 void connectionTime(int, int); 103 void enableBrokerLogoutButton (); 104 }; 105 106 #endif 107