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 ONMAINWINDOW_H 19 #define ONMAINWINDOW_H 20 21 #include "x2goclientconfig.h" 22 //#include "CallbackInterface.h" 23 #include <QMainWindow> 24 #include <QList> 25 #include <QPushButton> 26 #include <QPixmap> 27 #include <QProcess> 28 #include <QTreeView> 29 #include "LDAPSession.h" 30 #include <QToolBar> 31 #include <QSystemTrayIcon> 32 #include <QTranslator> 33 #include <QLocale> 34 #include <QProcessEnvironment> 35 #include <QDirIterator> 36 #include <QApplication> 37 #include <QDesktopWidget> 38 #include <libssh/callbacks.h> 39 #include "sshmasterconnection.h" 40 #include "non_modal_messagebox.h" 41 42 43 #ifdef Q_OS_WIN 44 #include <windows.h> 45 #include <QSysInfo> 46 #endif 47 48 #if defined (Q_OS_DARWIN) || defined (Q_OS_WIN) 49 #include "pulsemanager.h" 50 #endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */ 51 52 /** 53 @author Oleksandr Shneyder 54 */ 55 class QToolButton; 56 class QTemporaryFile; 57 class QLineEdit; 58 class QFrame; 59 class QVBoxLayout; 60 class QHBoxLayout; 61 class QScrollArea; 62 class UserButton; 63 class QTextEdit; 64 class SessionButton; 65 class QLabel; 66 class QProcess; 67 class QFile; 68 class SVGFrame; 69 class SessionButton; 70 class QAction; 71 class QCheckBox; 72 class QModelIndex; 73 class SshMasterConnection; 74 class IMGFrame; 75 class QStandardItemModel; 76 class HttpBrokerClient; 77 class QMenu; 78 class QComboBox; 79 class InteractionDialog; 80 81 class SessionExplorer; 82 struct user 83 { 84 int uin; 85 QString uid; 86 QString name; 87 QPixmap foto; lessThenuser88 static bool lessThen ( user u1,user u2 ) 89 { 90 return u1.uid < u2.uid; 91 } 92 }; 93 94 struct directory 95 { 96 QString key; 97 QString dstKey; 98 QString dirList; 99 bool isRemovable; 100 int pid; 101 }; 102 103 struct serv 104 { 105 QString name; 106 float factor; 107 float sess; 108 bool connOk; 109 bool operator < ( const struct serv it ) 110 { 111 return ( it.sess < sess ); 112 } ltserv113 static bool lt ( const struct serv it, const struct serv it1 ) 114 { 115 return it.sess<it1.sess; 116 } 117 QString sshPort; 118 }; 119 120 struct Application 121 { 122 QString name; 123 QString comment; 124 QString exec; 125 QPixmap icon; 126 enum {MULTIMEDIA, DEVELOPMENT, EDUCATION, GAME, 127 GRAPHICS, NETWORK, OFFICE, 128 SETTINGS, SYSTEM, UTILITY, OTHER, TOP 129 } category; lessThenApplication130 static bool lessThen(Application t1, Application t2) 131 { 132 return (t1.name.compare(t2.name,Qt::CaseInsensitive)<0); 133 } 134 }; 135 136 struct x2goSession 137 { 138 QString agentPid; 139 QString sessionId; 140 QString display; 141 QString server; 142 QString status; 143 QString crTime; 144 QString cookie; 145 QString clientIp; 146 QString grPort; 147 QString sndPort; 148 QString fsPort; 149 QString brokerUser; 150 uint connectedSince; 151 bool published; 152 int colorDepth; 153 bool fullscreen; 154 enum {DESKTOP,ROOTLESS,SHADOW, KDRIVE} sessionType; 155 QString command; 156 void operator = ( const x2goSession& s ); 157 }; 158 159 struct ConfigFile 160 { 161 QString session; 162 QString user; 163 QString brokerUser; 164 QString brokerPass; 165 QString brokerUserId; 166 QString brokerName; 167 QString sshBrokerBin; 168 bool brokerAuthenticated; 169 bool brokerNoAuth; 170 bool brokerAutologin; 171 bool brokerAutologoff; 172 bool brokerKrbLogin; 173 bool brokerEvents; //Send events to broker and get control commands 174 uint brokerLiveEventsTimeout; //(seconds)How often send alive events, 0 - do not send 175 QString brokerSshKey; 176 QString brokerCaCertFile; 177 QString iniFile; 178 QString server; 179 QString serverIp;//Can be different from server (use for load balancing) 180 QString sshport; 181 QString command; 182 QString key; 183 bool rootless; 184 QString cookie; 185 QString connectionts; 186 QString brokerurl; 187 QString sessiondata; 188 bool checkexitstatus; 189 bool showtermbutton; 190 bool showexpbutton; 191 bool showextconfig; 192 bool showconfig; 193 bool showstatusbar; 194 bool showtoolbar; 195 196 //if true - use cfg values, else default or client settings 197 bool confSnd; 198 bool confFS; 199 bool confConSpd; 200 bool confCompMet; 201 bool confImageQ; 202 bool confDPI; 203 bool confKbd; 204 // 205 bool useSnd; 206 bool useFs; 207 bool published; 208 int conSpeed; 209 QString compMet; 210 int imageQ; 211 int dpi; 212 QString kbdLay; 213 QString kbdType; 214 // 215 bool useproxy; 216 SshMasterConnection::ProxyType proxyType; 217 QString proxyserver; 218 int proxyport; 219 QString proxylogin; 220 QString proxypassword; 221 QString proxyKey; 222 bool proxyAutologin; 223 bool proxyKrbLogin; 224 225 }; 226 227 228 struct sshKey 229 { 230 QString server; 231 QString port; 232 QString user; 233 QString key; 234 }; 235 236 237 class SessTreeView : public QTreeView 238 { 239 Q_OBJECT 240 241 public: QTreeView(parent)242 SessTreeView ( QWidget* parent = 0 ) : QTreeView ( parent ) {} 243 selectionChanged(const QItemSelection & selected,const QItemSelection & deselected)244 virtual void selectionChanged ( const QItemSelection& selected, 245 const QItemSelection& deselected ) { 246 emit this->selected ( currentIndex() ); 247 QTreeView::selectionChanged ( selected, deselected ); 248 } 249 250 Q_SIGNALS: 251 void selected ( const QModelIndex& index ); 252 }; 253 254 255 class ClickLineEdit; 256 class ONMainWindow : public QMainWindow 257 { 258 friend class HttpBrokerClient; 259 friend class SessionButton; 260 Q_OBJECT 261 public: 262 enum 263 { 264 S_DISPLAY, 265 S_STATUS, 266 S_COMMAND, 267 S_TYPE, 268 S_SERVER, 269 S_CRTIME, 270 S_IP, 271 S_ID 272 }; 273 enum 274 { 275 MODEM, 276 ISDN, 277 ADSL, 278 WAN, 279 LAN 280 }; 281 enum 282 { 283 D_USER, 284 D_DISPLAY 285 }; 286 enum 287 { 288 SHADOW_VIEWONLY, 289 SHADOW_FULL 290 }; 291 enum 292 { 293 PULSE, 294 ARTS, 295 ESD 296 }; 297 298 enum key_types { 299 RSA_KEY_TYPE, 300 DSA_KEY_TYPE, 301 ECDSA_KEY_TYPE, 302 ED25519_KEY_TYPE, 303 UNKNOWN_KEY_TYPE 304 }; 305 306 enum client_events { 307 CONNECTING, 308 CONNECTED, 309 SUSPENDING, 310 TERMINATING, 311 FINISHED, 312 ALIVE 313 }; 314 315 static bool debugging; 316 static bool libssh_debugging; 317 static bool libssh_packetlog; 318 319 static bool portable; 320 ONMainWindow ( QWidget *parent = 0 ); 321 ~ONMainWindow(); 322 static void installTranslator(); 323 QString iconsPath ( const QString &fname ) const; 324 QString images_resource_path (const QString &filename, const QString &base = "") const; 325 static bool isServerRunning ( int port ); 326 void startNewSession(); 327 void suspendSession ( QString sessId ); 328 void suspendBrokerSession ( const QString& sessId, const QString& host ); 329 bool termSession ( QString sessId, 330 bool warn=true ); 331 void termBrokerSession ( const QString& sessId, const QString& host ); getInteractionDialog()332 InteractionDialog* getInteractionDialog() 333 { 334 return interDlg; 335 } 336 void setStatStatus ( QString status=QString::null ); 337 x2goSession getNewSessionFromString ( const QString& string ); 338 void runCommand(); 339 long findWindow ( QString text ); retUseLdap()340 bool retUseLdap() 341 { 342 return useLdap; 343 } retMiniMode()344 bool retMiniMode() 345 { 346 return miniMode; 347 } retLdapServer()348 QString retLdapServer() 349 { 350 return ldapServer; 351 } retLdapPort()352 int retLdapPort() 353 { 354 return ldapPort; 355 } retLdapDn()356 QString retLdapDn() 357 { 358 return ldapDn; 359 } retLdapServer1()360 QString retLdapServer1() 361 { 362 return ldapServer1; 363 } retLdapPort1()364 int retLdapPort1() 365 { 366 return ldapPort1; 367 } retLdapServer2()368 QString retLdapServer2() 369 { 370 return ldapServer2; 371 } retLdapPort2()372 int retLdapPort2() 373 { 374 return ldapPort2; 375 } mainLayout()376 QHBoxLayout* mainLayout() 377 { 378 return mainL; 379 } mainWidget()380 QWidget* mainWidget() 381 { 382 return ( QWidget* ) fr; 383 } 384 getPortable()385 static bool getPortable() 386 { 387 return portable; 388 } getHomeDirectory()389 static QString getHomeDirectory() 390 { 391 return homeDir; 392 } getShowAdvOption()393 bool getShowAdvOption() 394 { 395 return config.showextconfig; 396 } getUsePGPCard()397 bool getUsePGPCard() 398 { 399 return usePGPCard; 400 } getCardLogin()401 QString getCardLogin() 402 { 403 return cardLogin; 404 } getDefaultCmd()405 QString getDefaultCmd() 406 { 407 return defaultCmd; 408 } getDefaultSshPort()409 QString getDefaultSshPort() 410 { 411 return defaultSshPort; 412 } getDefaultClipboardMode()413 QString getDefaultClipboardMode() 414 { 415 return defaultClipboardMode; 416 } getDefaultKbdType()417 QString getDefaultKbdType() 418 { 419 return defaultKbdType; 420 } getDefaultLayout()421 QStringList getDefaultLayout() 422 { 423 return defaultLayout; 424 } getDefaultPack()425 QString getDefaultPack() 426 { 427 return defaultPack; 428 } getDefaultQuality()429 int getDefaultQuality() 430 { 431 return defaultQuality; 432 } 433 getDefaultDPI()434 uint getDefaultDPI() 435 { 436 return defaultDPI; 437 } 438 getDefaultSetDPI()439 bool getDefaultSetDPI() 440 { 441 return defaultSetDPI; 442 } 443 getEmbedMode()444 bool getEmbedMode() 445 { 446 return embedMode; 447 } 448 getDefaultLink()449 int getDefaultLink() 450 { 451 return defaultLink; 452 } getDefaultWidth()453 int getDefaultWidth() 454 { 455 return defaultWidth; 456 } getDefaultHeight()457 int getDefaultHeight() 458 { 459 return defaultHeight; 460 } getDefaultSetKbd()461 bool getDefaultSetKbd() 462 { 463 return defaultSetKbd; 464 } getDefaultUseSound()465 bool getDefaultUseSound() 466 { 467 return defaultUseSound; 468 } getDefaultFullscreen()469 bool getDefaultFullscreen() 470 { 471 return defaultFullscreen; 472 } sessionEditEnabled()473 bool sessionEditEnabled() 474 { 475 return !noSessionEdit; 476 } getApplications()477 const QList<Application>& getApplications() 478 { 479 return applications; 480 } getSessionConf()481 static QString getSessionConf() 482 { 483 return sessionCfg; 484 } getHideFolderSharing()485 bool getHideFolderSharing() 486 { 487 return hideFolderSharing; 488 } 489 getSessionExplorer()490 SessionExplorer* getSessionExplorer() 491 { 492 return sessionExplorer; 493 } 494 getBrokerMode()495 bool getBrokerMode() 496 { 497 return brokerMode; 498 } 499 getMiniMode()500 bool getMiniMode() 501 { 502 return miniMode; 503 } 504 getAcceptRSA()505 bool getAcceptRSA() 506 { 507 return acceptRsa; 508 } 509 getUsersArea()510 QScrollArea* getUsersArea() 511 { 512 return users; 513 } 514 getUsersFrame()515 QFrame* getUsersFrame() 516 { 517 return uframe; 518 } 519 getCentralFrame()520 IMGFrame* getCentralFrame() 521 { 522 return fr; 523 } 524 getConfig()525 ConfigFile* getConfig() 526 { 527 return &config; 528 } 529 530 #if defined (Q_OS_DARWIN) || defined (Q_OS_WIN) getSystemDisablePARecord()531 bool getSystemDisablePARecord() 532 { 533 return systemDisablePARecord; 534 } getSystemDisablePA()535 bool getSystemDisablePA() 536 { 537 return systemDisablePA; 538 } 539 #endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */ 540 541 void runApplication(QString exec); 542 543 544 SshMasterConnection* findServerSshConnection(QString host); 545 void cleanServerSshConnections(); 546 547 void showHelp(); 548 void showVersion(); 549 void showTextFile(QString file, QString title); 550 void showGit(); 551 void showChangelog(); 552 void showHelpPack(); 553 void exportDirs ( QString exports,bool removable=false ); 554 void reloadUsers(); 555 void setWidgetStyle ( QWidget* widget ); internApplicationsNames()556 QStringList internApplicationsNames() 557 { 558 return _internApplicationsNames; 559 } transApplicationsNames()560 QStringList transApplicationsNames() 561 { 562 return _transApplicationsNames; 563 } 564 QString transAppName ( const QString& internAppName, 565 bool* found=0l ); 566 QString internAppName ( const QString& transAppName, 567 bool* found=0l ); 568 void setEmbedSessionActionsEnabled ( bool enable ); 569 bool startSshd (key_types key_type = RSA_KEY_TYPE); 570 QSize getEmbedAreaSize(); 571 #ifdef Q_OS_WIN 572 static QString cygwinPath ( const QString& winPath ); 573 void startXOrg(std::size_t start_offset = 0); 574 static bool haveCygwinEntry(); 575 static void removeCygwinEntry(); U3DevicePath()576 static QString U3DevicePath() 577 { 578 return u3Device; 579 } 580 #endif 581 582 583 private: 584 InteractionDialog* interDlg; 585 QString m_x2goconfig; 586 QStringList _internApplicationsNames; 587 QStringList _transApplicationsNames; 588 QString portableDataPath; 589 QString proxyErrString; 590 bool haveTerminal; 591 bool proxyRunning; 592 bool drawMenu; 593 bool extStarted; 594 bool startMaximized; 595 bool closeDisconnect; 596 bool startHidden; 597 bool keepTrayIcon; 598 bool hideFolderSharing; 599 bool brokerNoauthWithSessionUsername; 600 bool brokerCredsForSession; 601 bool defaultUseSound; 602 bool defaultXinerama; 603 bool cardStarted; 604 bool defaultSetKbd; 605 bool autoresume; 606 bool showExport; 607 bool usePGPCard; 608 bool miniMode; 609 bool managedMode; 610 bool brokerMode; 611 bool changeBrokerPass; 612 bool connTest; 613 bool embedMode; 614 bool thinMode; 615 QString statusString; 616 QStringList autostartApps; 617 bool cmdAutologin; 618 int defaultLink; 619 int defaultQuality; 620 int defaultWidth; 621 int defaultHeight; 622 bool defaultFullscreen; 623 bool acceptRsa; 624 bool startEmbedded; 625 bool extLogin; 626 bool printSupport; 627 bool showTbTooltip; 628 bool noSessionEdit; 629 bool cleanAllFiles; 630 bool PGPInited; 631 bool resumeAfterSuspending; 632 QString sshPort; 633 QString clientSshPort; 634 QString defaultSshPort; 635 #ifdef Q_OS_WIN 636 QString sshLog; 637 #endif 638 QVBoxLayout* selectSesDlgLayout; 639 SshMasterConnection* sshConnection; 640 QList<SshMasterConnection*> serverSshConnections; 641 bool closeEventSent; 642 int shadowMode; 643 QString shadowUser; 644 QString shadowDisplay; 645 QString defaultPack; 646 QStringList defaultLayout; 647 QString selectedLayout; 648 QString defaultKbdType; 649 QString defaultClipboardMode; 650 QString defaultCmd; 651 bool defaultSetDPI; 652 uint defaultDPI; 653 QStringList listedSessions; 654 QString appDir; 655 QString localGraphicPort; 656 static QString homeDir; 657 int retSessions; 658 QList<serv> x2goServers; 659 QList<Application> applications; 660 QList<sshKey> cmdSshKeys; 661 bool forceToShowTrayicon; //true if --tray-icon passed in command line 662 663 QPushButton* bSusp; 664 QPushButton* bTerm; 665 QPushButton* bNew; 666 QPushButton* bShadow; 667 QPushButton* bShadowView; 668 QPushButton* bCancel; 669 670 671 QPushButton *bBrokerLogout; 672 673 674 QLabel* selectSessionLabel; 675 SessTreeView* sessTv; 676 677 QLineEdit* desktopFilter; 678 QCheckBox* desktopFilterCb; 679 680 SessionExplorer* sessionExplorer; 681 682 IMGFrame* fr; 683 SVGFrame *bgFrame; 684 SVGFrame *on; 685 QLineEdit* uname; 686 ClickLineEdit* pass; 687 ClickLineEdit* login; 688 QFrame* uframe; 689 SVGFrame *passForm; 690 QSize mwSize; 691 bool mwMax; 692 QPoint mwPos; 693 SVGFrame *selectSessionDlg; 694 SVGFrame *sessionStatusDlg; 695 QLabel* u; 696 QLabel* fotoLabel; 697 QLabel* nameLabel; 698 QLabel* passPrompt; 699 QLabel* loginPrompt; 700 QLabel* layoutPrompt; 701 QLabel* slName; 702 QLabel* slVal; 703 QComboBox* cbLayout; 704 QPushButton* ok; 705 QPushButton* cancel; 706 QString readExportsFrom; 707 QString readLoginsFrom; 708 QPushButton* sOk; 709 QToolButton* sbSusp; 710 QToolButton* sbExp; 711 QToolButton* sbTerm; 712 QToolButton* sbApps; 713 QCheckBox* sbAdv; 714 QPushButton* sCancel; 715 QString resolution; 716 QString kdeIconsPath; 717 QScrollArea* users; 718 QVBoxLayout* userl; 719 QHBoxLayout* mainL; 720 QHBoxLayout* bgLay; 721 QList<UserButton*> names; 722 UserButton* lastUser; 723 QString prevText; 724 QString onserver; 725 QString id; 726 QString selectedCommand; 727 QString currentKey; 728 QTimer *exportTimer; 729 QTimer *extTimer; 730 QTimer *spoolTimer; 731 QTimer *proxyWinTimer; 732 QTimer *xineramaTimer; 733 QTimer *brokerAliveTimer; 734 short xinSizeInc; 735 QRect lastDisplayGeometry; 736 QList <QRect> xineramaScreens; 737 QStyle* widgetExtraStyle; 738 bool isPassShown; 739 bool xmodExecuted; 740 long proxyWinId; 741 bool embedControlChanged; 742 bool embedTbVisible; 743 QLabel* statusLabel; 744 ConfigFile config; 745 QStandardItemModel* model; 746 QStandardItemModel* modelDesktop; 747 748 QAction *act_set; 749 QAction *act_abclient; 750 QAction *act_support; 751 QAction *act_shareFolder; 752 QAction *act_showApps; 753 QAction *act_suspend; 754 QAction *act_terminate; 755 QAction *act_reconnect; 756 QAction *act_embedContol; 757 QAction *act_embedToolBar; 758 QAction *act_changeBrokerPass; 759 QAction *act_testCon; 760 QList <QAction*> topActions; 761 762 QToolBar *stb; 763 764 QString sessionStatus; 765 QString spoolDir; 766 QString sessionRes; 767 QHBoxLayout* username; 768 QList <user> userList; 769 QList <directory> exportDir; 770 QString nick; 771 QString nfsPort; 772 QString mntPort; 773 static QString sessionCfg; 774 QProcess* ssh; 775 QProcess* soundServer; 776 QProcess* scDaemon; 777 QProcess* gpg; 778 LDAPSession* ld; 779 long embedParent; 780 long embedChild; 781 bool proxyWinEmbedded; 782 bool useLdap; 783 bool showToolBar; 784 bool showHaltBtn; 785 bool showBrokerLogoutBtn; 786 bool newSession; 787 bool runStartApp; 788 bool ldapOnly; 789 #ifdef Q_OS_UNIX 790 bool directRDP; 791 #endif 792 793 bool startSessSound; 794 int startSessSndSystem; 795 796 bool fsInTun; 797 bool fsTunReady; 798 799 QString fsExportKey; 800 bool fsExportKeyReady; 801 802 QString ldapServer; 803 int ldapPort; 804 QString ldapServer1; 805 int ldapPort1; 806 QString ldapServer2; 807 int ldapPort2; 808 QString ldapDn; 809 QString sessionCmd; 810 811 QString supportMenuFile; 812 QString BGFile; 813 QString OnFile; 814 QString SPixFile; 815 816 QString LDAPSndSys; 817 QString LDAPSndPort; 818 bool LDAPSndStartServer; 819 820 bool LDAPPrintSupport; 821 822 QAction *act_edit; 823 QAction *act_new; 824 QAction *act_sessicon; 825 QProcess *nxproxy; 826 #ifndef Q_OS_WIN 827 QProcess *sshd; 828 #else 829 QProcess *xorg; 830 PROCESS_INFORMATION sshd; 831 bool winSshdStarted; 832 static QString u3Device; 833 834 int xDisplay; 835 int sshdPort; 836 bool winServersReady; 837 QString oldEtcDir; 838 QString oldBinDir; 839 QString oldTmpDir; 840 841 bool cyEntry; 842 843 bool maximizeProxyWin; 844 int proxyWinWidth; 845 int proxyWinHeight; 846 QTimer* xorgLogTimer; 847 QString xorgLogFile; 848 QMutex xorgLogMutex; 849 #endif 850 QString lastFreeServer; 851 QString cardLogin; 852 QTextEdit* stInfo; 853 int localDisplayNumber; 854 855 #if defined (Q_OS_DARWIN) || defined (Q_OS_WIN) 856 QThread *pulseManagerThread; 857 PulseManager *pulseManager; 858 bool systemDisablePARecord; 859 bool systemDisablePA; 860 #endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */ 861 862 863 SVGFrame* ln; 864 int tunnel; 865 int sndTunnel; 866 int fsTunnel; 867 QList<x2goSession> selectedSessions; 868 QStringList selectedDesktops; 869 x2goSession resumingSession; 870 bool startSound; 871 bool restartResume; 872 bool runRemoteCommand; 873 bool shadowSession; 874 int firstUid; 875 int lastUid; 876 bool cardReady; 877 HttpBrokerClient* broker; 878 client_events lastBrokerEvent; 879 QString lastBrokerEventSession; 880 881 882 #if defined ( Q_OS_WIN) //&& defined (CFGCLIENT ) 883 void xorgSettings(); 884 bool startXorgOnStart; 885 bool useInternalX; 886 enum {VCXSRV, XMING} internalX; 887 QString xorgExe; 888 QString xorgOptions; 889 QString xorgWinOptions; 890 QString xorgFSOptions; 891 QString xorgSAppOptions; 892 QString xorgMDOptions; 893 enum {WIN,FS,SAPP,MULTIDISPLAY} xorgMode; 894 QString xorgWidth; 895 QString xorgHeight; 896 int waitingForX; 897 std::size_t x_start_tries_; 898 std::size_t x_start_limit_; 899 QRect dispGeometry; 900 #endif 901 902 #ifdef Q_OS_UNIX 903 long image, shape; 904 #endif 905 906 // Tray icon stuff based on patch from Joachim Langenbach <joachim@falaba.de> 907 QSystemTrayIcon *trayIcon; 908 QMenu *trayIconMenu; 909 QMenu *trayIconActiveConnectionMenu; 910 911 QAction* appSeparator; 912 QMenu* appMenu[Application::OTHER+1]; 913 914 bool trayEnabled; 915 bool trayMinToTray; 916 bool trayNoclose; 917 bool trayMinCon; 918 bool trayMaxDiscon; 919 bool trayAutoHidden; 920 921 //server connection type 922 // DEFAULT - start X2GO session 923 // SUSPEND - open connection to suspend broker session 924 // TERMINATE - open connection to terminate broker session 925 typedef enum {DEFAULT, SUSPEND, TERMINATE} CONTYPE; 926 927 CONTYPE connectionType; 928 QString suspendTerminateHostFromBroker; 929 QString suspendTerminateSessionFromBroker; 930 931 void sendEventToBroker(client_events ev); 932 void suspendFromBroker(const QString& sid); 933 void terminateFromBroker(const QString& sid); 934 QString findSshKeyForServer(QString user, QString server, QString port); 935 void loadSettings(); 936 void showPass ( UserButton* user ); 937 void clean(); 938 bool defaultSession; 939 QString defaultSessionName; 940 QString defaultSessionId; 941 QString defaultUserName; 942 bool defaultUser; 943 QString getKdeIconsPath(); 944 QString findTheme ( QString theme ); 945 bool initLdapSession ( bool showBox=true ); 946 bool startSession ( const QString& id, CONTYPE conType=DEFAULT); 947 x2goSession getSessionFromString ( const QString& string ); 948 void resumeSession ( const x2goSession& s ); 949 void selectSession ( QStringList& sessions ); 950 x2goSession getSelectedSession(); 951 bool parseParameter ( QString param ); 952 bool linkParameter ( QString value ); 953 bool clipboardParameter ( QString value ); 954 bool geometry_par ( QString value ); 955 bool setKbd_par ( QString value ); 956 bool ldapParameter ( QString value ); 957 bool ldap1Parameter ( QString value ); 958 bool ldap2Parameter ( QString value ); 959 bool packParameter ( QString value ); 960 bool soundParameter ( QString val ); 961 void printError ( QString param ); 962 void exportDefaultDirs(); 963 directory* getExpDir ( QString key ); 964 bool findInList ( const QString& uid ); 965 void setUsersEnabled ( bool enable ); 966 void externalLogout ( const QString& logoutDir ); 967 void externalLogin ( const QString& loginDir ); 968 void startGPG(); 969 void GPGCardLogin ( const QString& cardLogin); 970 void closeClient(); 971 void continueNormalSession(); 972 void continueLDAPSession(); 973 SshMasterConnection* startSshConnection ( QString host, QString port, 974 bool acceptUnknownHosts, QString login, 975 QString password, bool autologin, bool krbLogin, bool getSrv=false, bool useproxy=false, 976 SshMasterConnection::ProxyType type=SshMasterConnection::PROXYSSH, 977 QString proxyserver=QString::null, quint16 proxyport=0, 978 QString proxylogin=QString::null, QString proxypassword=QString::null, QString proxyKey=QString::null, 979 bool proxyAutologin=false, bool proxyKrbLogin=false ); 980 void setProxyWinTitle(); 981 QRect proxyWinGeometry(); 982 void readApplications(); 983 void removeAppsFromTray(); 984 void plugAppsInTray(); 985 QMenu* initTrayAppMenu(QString text, QPixmap icon); 986 void setTrayIconToSessionIcon(QString info); 987 988 /* 989 * Tries to get the most suitable translator for the running system. 990 * 991 * The first parameter file_name_start denotes the start of a potential 992 * translation file name. Locale values will be appended to this. 993 * 994 * On Qt 4.7 and lower, only tries to fetch a translator for the 995 * main language as returned by QLocale::system(). 996 * On Qt 4.8 and higher, tries to fetch the first available translator 997 * for the list returned by QLocale::uiLanguages(). 998 * 999 * If no translator is available OR the best available translator 1000 * is for an English locale, returns false and doesn't touch 1001 * the passed translator object. 1002 * Otherwise returns true and sets the translator object to loaded 1003 * translation. 1004 */ 1005 static bool get_translator (const QString file_name_start, QTranslator **translator); 1006 1007 1008 protected: 1009 virtual void closeEvent ( QCloseEvent* event ); 1010 virtual void hideEvent ( QHideEvent* event); 1011 1012 #ifndef Q_OS_WIN 1013 virtual void mouseReleaseEvent ( QMouseEvent * event ); 1014 #else 1015 private slots: 1016 void slotSetWinServersReady(); 1017 void startWinServers(key_types key_type = RSA_KEY_TYPE); 1018 void slotCheckXOrgLog(); 1019 void slotCheckXOrgConnection(); 1020 #endif 1021 1022 #if defined (Q_OS_DARWIN) || defined (Q_OS_WIN) 1023 private slots: 1024 void pulseManagerWrapper (); 1025 #endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */ 1026 1027 private slots: 1028 void slotAppDialog(); 1029 void slotShowPassForm(); 1030 void displayUsers(); 1031 void slotAppMenuTriggered ( QAction * action ); 1032 void slotPassChanged(const QString& result); 1033 void slotResize ( const QSize sz ); 1034 void slotUnameChanged ( const QString& text ); 1035 void slotPassEnter(); 1036 void slotChangeBrokerPass(); 1037 void slotTestConnection(); 1038 void slotCheckPortableDir(); 1039 void readUsers(); 1040 void slotSelectedFromList ( UserButton* user ); 1041 void slotUnameEntered(); 1042 void slotClosePass(); 1043 void slotReadSessions(); 1044 void slotManage(); 1045 void displayToolBar ( bool ); 1046 void showSessionStatus(); 1047 void slotSshConnectionError ( QString message, QString lastSessionError ); 1048 void slotSshServerAuthError ( int error, QString sshMessage, SshMasterConnection* connection ); 1049 void slotSshServerAuthPassphrase ( SshMasterConnection* connection, SshMasterConnection::passphrase_types passphrase_type ); 1050 void slotSshInteractionStart ( SshMasterConnection* connection, QString prompt ); 1051 void slotSshInteractionUpdate ( SshMasterConnection* connection, QString output ); 1052 void slotSshInteractionFinish ( SshMasterConnection* connection); 1053 void slotSshServerAuthChallengeResponse( SshMasterConnection* connection, QString Challenge ); 1054 void slotCloseInteractionDialog(); 1055 void slotSshUserAuthError ( QString error ); 1056 void slotSshConnectionOk(); 1057 void slotServSshConnectionOk(QString server); 1058 void slotChangeKbdLayout(const QString& layout); 1059 void slotSyncX(); 1060 void slotShutdownThinClient(); 1061 void slotBrokerLogoutButton (); 1062 void slotReadApplications(bool result, QString output, int pid ); 1063 1064 public slots: 1065 void slotConfig(); 1066 void slotNewSession(); 1067 void slotEmbedControlAction(); 1068 void slotDetachProxyWindow(); 1069 void slotActivateWindow(); 1070 void setFocus(); 1071 void slotEnableBrokerLogoutButton (); 1072 1073 private slots: 1074 void slotSendBrokerAlive(); 1075 void slotShowPAMSGDialog(bool error, const QString& main_text, const QString& info_text, bool modal); 1076 void slotSnameChanged ( const QString& ); 1077 void slotSelectedFromList ( SessionButton* session ); 1078 void slotSessEnter(); 1079 void slotCloseSelectDlg(); 1080 void slotActivated ( const QModelIndex& index ); 1081 void slotResumeSess(); 1082 void slotSuspendSess(); 1083 void slotTermSessFromSt(); 1084 void slotSuspendSessFromSt(); 1085 void slotTermSess(); 1086 void slotNewSess(); 1087 void slotGetBrokerAuth(); 1088 void slotGetBrokerSession(); 1089 void slotCmdMessage ( bool result,QString output, 1090 int ); 1091 void slotListSessions ( bool result,QString output, 1092 int ); 1093 void slotRetSuspSess ( bool value,QString message, 1094 int ); 1095 void slotRetTermSess ( bool result,QString output, 1096 int ); 1097 void slotRetResumeSess ( bool result,QString output, 1098 int ); 1099 void slotTunnelFailed ( bool result,QString output, 1100 int ); 1101 void slotFsTunnelFailed ( bool result,QString output, 1102 int ); 1103 void slotSndTunnelFailed ( bool result,QString output, 1104 int ); 1105 void slotCopyKey ( bool result,QString output,int ); 1106 void slotTunnelOk(int = 0); 1107 void slotFsTunnelOk(int ); 1108 void slotProxyError ( QProcess::ProcessError err ); 1109 void slotProxyFinished ( int result,QProcess::ExitStatus st ); 1110 void slotProxyStderr(); 1111 void slotProxyStdout(); 1112 void slotResumeDoubleClick ( const QModelIndex& ); 1113 void slotShowAdvancedStat(); 1114 void slotRestartProxy(); 1115 void slotTestSessionStatus(); 1116 void SlotRunCommand(bool, QString output, int); 1117 void slotRetRunCommand ( bool result, QString output, 1118 int ); 1119 void slotGetServers ( bool result, QString output, 1120 int ); 1121 void slotListAllSessions ( bool result,QString output, 1122 int ); 1123 void slotRetExportDir ( bool result,QString output, 1124 int ); 1125 void slotResize(); 1126 void slotExportDirectory(); 1127 void slotExportTimer(); 1128 void slotAboutQt(); 1129 void slotAbout(); 1130 void slotSupport(); 1131 1132 //trayIcon stuff 1133 void trayIconActivated(QSystemTrayIcon::ActivationReason reason); 1134 void trayMessageClicked(); 1135 void trayQuit(); 1136 void trayIconInit(); 1137 1138 1139 private slots: 1140 void slotSetProxyWinFullscreen(); 1141 void slotCheckPrintSpool(); 1142 void slotRereadUsers(); 1143 void slotExtTimer(); 1144 void slotStartPGPAuth(); 1145 void slotScDaemonStdOut(); 1146 void slotScDaemonStdErr(); 1147 void slotGpgFinished ( int exitCode, 1148 QProcess::ExitStatus exitStatus ); 1149 void slotScDaemonFinished ( int exitCode, 1150 QProcess::ExitStatus exitStatus ); 1151 void slotScDaemonError (QProcess::ProcessError error); 1152 void slotGpgError(); 1153 void slotExecXmodmap(); 1154 void slotCreateSessionIcon(); 1155 void slotFindProxyWin(); 1156 void slotConfigXinerama(); 1157 void slotXineramaConfigured(); 1158 void slotAttachProxyWindow(); 1159 void slotEmbedIntoParentWindow(); 1160 void slotEmbedWindow(); 1161 void slotPCookieReady ( bool result,QString output, 1162 int proc ); 1163 void slotEmbedToolBar(); 1164 void slotEmbedToolBarToolTip(); 1165 void slotHideEmbedToolBarToolTip(); 1166 void slotDesktopFilterChanged ( const QString& text ) ; 1167 void slotDesktopFilterCb ( int state ) ; 1168 void slotShadowViewSess(); 1169 void slotShadowSess(); 1170 void slotReconnectSession(); 1171 void slotStartBroker(); 1172 void slotStartNewBrokerSession (); 1173 void slotInitLibssh (); 1174 #ifdef Q_OS_DARWIN 1175 void slotSetModMap(); 1176 void handle_xmodmap_error (QProcess &proc); 1177 private: 1178 QTimer* modMapTimer; 1179 QString kbMap; 1180 #endif 1181 1182 private: 1183 void resizeProxyWinOnDisplay(int display); 1184 #ifdef Q_OS_UNIX 1185 long X11FindWindow ( QString text, long rootWin=0 ); 1186 #endif 1187 void addToAppNames ( QString intName, QString transName ); 1188 bool checkAgentProcess(); 1189 bool isColorDepthOk ( int disp, int sess ); 1190 void check_cmd_status(); 1191 int startSshFsTunnel(); 1192 void startX2goMount(); 1193 void cleanPrintSpool(); 1194 void cleanAskPass(); 1195 void initWidgetsEmbed(); 1196 void initWidgetsNormal(); 1197 QString getCurrentUname(); 1198 QString getCurrentPass(); 1199 void processSessionConfig(); 1200 void processCfgLine ( QString line ); 1201 void initSelectSessDlg(); 1202 void initStatusDlg(); 1203 void initPassDlg(); 1204 void printSshDError_startupFailure(); 1205 void printSshDError_noHostPubKey(); 1206 void printSshDError_noExportPubKey(); 1207 void printSshDError_noAuthorizedKeysFile(); 1208 void loadPulseModuleNativeProtocol(); 1209 void initEmbedToolBar(); 1210 #ifdef Q_OS_UNIX 1211 void startDirectRDP(); 1212 #endif 1213 void filterDesktops ( const QString& filter, 1214 bool strict=false ); 1215 void generateEtcFiles(); 1216 QString u3DataPath(); 1217 void cleanPortable(); 1218 void removeDir ( QString path ); 1219 #ifdef Q_OS_WIN 1220 void saveCygnusSettings(); 1221 void restoreCygnusSettings(); 1222 #endif 1223 #if defined (Q_OS_WIN) || defined (Q_OS_DARWIN) 1224 QString getXDisplay(); 1225 #endif 1226 1227 key_types check_key_type (key_types key_type); 1228 QString key_type_to_string (key_types key_type); 1229 std::size_t default_size_for_key_type (key_types key_type); 1230 QString generateKey (key_types key_type, bool host_key = false); 1231 QString createKeyBundle (key_types key_type = RSA_KEY_TYPE); 1232 }; 1233 1234 #ifdef Q_OS_WIN 1235 #include <QThread> 1236 #include <QMutex> 1237 class ONMainWindow; 1238 class WinServerStarter: public QThread 1239 { 1240 public: 1241 enum daemon {X,SSH}; 1242 WinServerStarter ( daemon server, ONMainWindow * par ); 1243 void run(); 1244 void set_ssh_key_type (ONMainWindow::key_types key_type); 1245 ONMainWindow::key_types get_ssh_key_type (); 1246 private: 1247 daemon mode; 1248 ONMainWindow* parent; 1249 ONMainWindow::key_types ssh_key_type_; 1250 }; 1251 #endif 1252 1253 #endif 1254