-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordSyncServer.qml
More file actions
executable file
·93 lines (79 loc) · 3.17 KB
/
PasswordSyncServer.qml
File metadata and controls
executable file
·93 lines (79 loc) · 3.17 KB
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
import QtQuick 2.9
import QtWebSockets 1.1
WebSocketServer {
id: passwordSyncServer
property var aClients: [];
listen: false
accept: true
//host: ""
//port: 3002
onClientConnected: {
aClients.push({ bAuthorized: false, sCommand: "" });
var iClientId = aClients.length - 1;
webSocket
.onTextMessageReceived
.connect(function(sCommand)
{
console.log("sCommand: "+sCommand);
aClients[iClientId].sCommand = sCommand;
if (aClients[iClientId].bAuthorized) {
console.log("aClients[iClientId].bAuthorized ", iClientId, aClients[iClientId].bAuthorized);
if (sCommand == "SYNC_0" || sCommand == "SYNC_1" || sCommand == "SYNC_2") {
webSocket.sendBinaryMessage(oPasswordListModel.fnToByteArray());
}
}
});
webSocket
.onBinaryMessageReceived
.connect(function(sMessage)
{
var sCommand = aClients[iClientId].sCommand;
console.log("onBinaryMessageReceived - sCommand: "+sCommand);
if (sCommand == "AUTH") {
if (oPasswordListModel.fnCheckPassword(sMessage)) {
aClients[iClientId].bAuthorized = true;
webSocket.sendTextMessage("AUTH_OK");
console.log("sendTextMessage AUTH_OK");
} else {
webSocket.sendTextMessage("AUTH_ERROR");
console.log("sendTextMessage AUTH_ERROR");
}
}
if (aClients[iClientId].bAuthorized) {
if (sCommand == "SYNC_3" || sCommand == "SYNC_4" || sCommand == "SYNC_5") {
var iResult = oPasswordListModel.fnFromByteArray(sMessage, {SYNC_3:0, SYNC_4:1, SYNC_5:2}[sCommand]);
if (iResult != 1) {
webSocket.sendTextMessage("SYNC_ERROR");
}
if (iResult == 1) {
oPasswordListModel.fnSave();
webSocket.sendTextMessage("SYNC_OK");
}
}
}
});
}
onErrorStringChanged: {
stackView.settingsPageServerStatusLabelText = "Server status: Error "+errorString
}
onHostChanged: {
console.log("onHostChanged", host);
if (listen) {
stackView.settingsPageServerStatusLabelText = "Server status: listening "+host+":"+port;
}
}
onPortChanged: {
console.log("onPortChanged", port);
if (listen) {
stackView.settingsPageServerStatusLabelText = "Server status: listening "+host+":"+port;
}
}
onListenChanged: {
if (listen) {
stackView.settingsPageServerStatusLabelText = "Server status: listening "+host+":"+port;
} else {
stackView.settingsPageServerStatusLabelText = "Server status: stoped";
}
console.log(stackView.settingsPageServerStatusLabelText);
}
}