-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsshclient.h
106 lines (70 loc) · 1.69 KB
/
sshclient.h
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
#ifndef SSHCLIENT_H
#define SSHCLIENT_H
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libssh2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <QDebug>
#include <QString>
#include <QThread>
#include <iostream>
using namespace std;
#define READ_BUF_SIZE 32000
#ifdef WIN32
#pragma execution_character_set("utf-8")
#else
#include <arpa/inet.h>
#include <libgen.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <unistd.h>
#endif
class SSHClient : public QThread {
Q_OBJECT
public:
SSHClient(QString hostName, QString port, QString username, QString password);
SSHClient(QString hostName, QString port, QString username,
QString publicKeyPath, QString privateKeyPath, QString passPhrase);
int pty_rows = 0;
int pty_cols = 0;
bool connect();
bool openSession();
bool userauth();
bool open_channel();
void setChannelRequestPtySize(int row, int column);
void free_channel();
void close_session();
void close_connect();
void stop();
void exec(QString shell);
private:
int sock = 0;
unsigned long hostaddr = 0;
int port = 22;
QString hostName;
QString username;
QString password;
QString publicKeyPath;
QString privateKeyPath;
QString passPhrase;
int authType = 1;
struct sockaddr_in sin;
LIBSSH2_SESSION *session = NULL;
LIBSSH2_CHANNEL *channel = NULL;
/* For select on stdin */
fd_set set;
struct timeval timeval_out;
void run() override;
signals:
void errorMsg(QString errMsg);
void readChannelData(QString data);
void connectSuccess();
void disconnected();
void authSuccess();
void openChannelSuccess();
};
#endif // SSHCLIENT_H