-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolserver.h
77 lines (66 loc) · 1.68 KB
/
controlserver.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
#ifndef CONTROLSERVER_H
#define CONTROLSERVER_H
#include <QObject>
#include <QtNetwork/QTcpServer>
#include <QTcpSocket>
#include "global.h"
#include "myfunctions.h"
#include "http.h"
struct HtmlPage{
QByteArray top;
QByteArray bottom;
QByteArray menu;
QByteArray indexJS;
QByteArray colorCSS;
QByteArray buttonsCSS;
QByteArray indexCSS;
QByteArray admin;
QByteArray state;
QByteArray index;
QByteArray downArrowIMG;
QByteArray upArrowIMG;
};
namespace ControlServerResoucres{
extern HtmlPage pages;
}
class ControlServer : public QTcpServer
{
Q_OBJECT
public:
ControlServer(QObject *parent = nullptr);
~ControlServer();
bool run();
void stop();
protected:
void incomingConnection(qintptr socketDescriptor);
signals:
void signal_stopAll();
};
class ControlClient : public QObject
{
Q_OBJECT
public:
explicit ControlClient(qintptr descriptor, QObject *parent = 0);
void run() { slot_start(); }
signals:
void signal_finished();
public slots:
void slot_start();
void slot_stop();
private slots:
void slot_clientReadyRead();
private:
QTcpSocket* m_pClient;
bool m_auth;
QByteArray m_buff;
void sendToClient(const QByteArray &data);
bool parsAuthPkt(QByteArray &data);
bool parsInfoPkt(QByteArray &data, QByteArray &sendData);
void sendRawResponse(const uint16_t code, const QString &comment, const QByteArray &data, const QString &mimeType);
void sendResponse(const uint16_t code, const QString &comment);
void processingRequest(const http::pkt &pkt);
QString getUserNetStatsString(const User &user);
void getGlobalBlockedDomains(QByteArray &buff, const QString ¶m);
QByteArray getHtmlPage(const QString &title, const QByteArray &content);
};
#endif // CONTROLSERVER_H