-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxy.js
138 lines (117 loc) · 3.89 KB
/
xy.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* @author Nikola Lukic
* @description Remote Desktop XY Coordinator Server
* for WebControlSystem. Used webSocket.
*/
const fs = require("fs");
const WebSocket = require("ws");
let wss = null;
let HttpsServer;
let XYCORDSOCKS = {};
let eventEmitter;
let isSSL = true;
if(process.platform == 'win32') {
options = {};
} else {
options = {
key: fs.readFileSync("/etc/letsencrypt/live/maximumroulette.com/privkey.pem"),
cert: fs.readFileSync("/etc/letsencrypt/live/maximumroulette.com/fullchain.pem")
};
console.log('#SSL XY')
}
if(isSSL == true) {
HttpsServer = require('https').createServer;
var server = HttpsServer(options, function(request, response) {
response.connection.setTimeout(0);
console.log('XY TEST SSL CONNECT');
}).listen(20002);
wss = new WebSocket.Server({server: server});
} else {
wss = new WebSocket.Server({port: 20002});
}
var INJECTOR = function(arg) {
eventEmitter = arg;
eventEmitter.on('new-stream', (e) => {
console.log('STREAM NEW XY ->>>', e.id);
});
eventEmitter.on('end-stream', (e) => {
console.log('STREAM END XY ->>>', e.id);
console.log('STREAM END EXPLORE1 ->>>', typeof XYCORDSOCKS[e.id]);
console.log('STREAM END EXPLORE2 ->>>', typeof XYCORDSOCKS[e.id + "/STREAMER"]);
if(XYCORDSOCKS[e.id + "/STREAMER"] && XYCORDSOCKS[e.id + "/STREAMER"].close) XYCORDSOCKS[e.id + "/STREAMER"].close();
if(XYCORDSOCKS[e.id] && XYCORDSOCKS[e.id].close) XYCORDSOCKS[e.id].close();
console.log('STREAM END AFTER ALL');
});
console.log("Emiiteter" + eventEmitter);
};
wss.createUniqueID = function() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + "-" + s4() + "-" + s4();
};
wss.on("connection", function connection(ws, upgradeReq) {
// console.log(`connection [XY] -> ${upgradeReq.url}`);
var incommingSecret = upgradeReq.url.toString().substring(1);
console.log(`Conn Url on [XY] -test incommingSecret >>>>>>>>>>>>>>>>>> ${incommingSecret}`);
if(incommingSecret == '') {
console.log(`[close] Conn Url on [XY] COMES FROM STREMER HOST DESK IS EMPTY POTENCIAL DANGERUS! -> ${incommingSecret}`);
ws.close();
return;
}
ws.info = {};
ws.info.id = wss.createUniqueID();
console.info(" New user with id -> ", ws.info);
XYCORDSOCKS[incommingSecret] = ws;
ws.on("message", function incoming(data) {
var buf = Buffer.from(data);
// console.log("->", buf.toString());
if(buf.toString().indexOf("WIZARD-NIDZA-") !== -1) {
var getID = buf.toString().replace("WIZARD-NIDZA-", "");
// console.log("One wizard client with id -> ", getID);
ws.info._type = "WIZARD-SERVER";
ws.info.secret = getID;
var constPath = "./public/secret-wizard-" + getID + ".html";
if(!fs.existsSync(constPath)) {
fs.copyFile("secret.html", constPath, err => {
if(err) throw err;
console.log("Secret link created for ", getID);
});
return;
}
/** No need TEST */
return;
}
if(XYCORDSOCKS[incommingSecret].readyState === WebSocket.OPEN) {
for (var key in XYCORDSOCKS) {
// console.log("XYCORDSOCKS-[key]", key);
}
// console.log("XYCORDSOCKS- income secret ", incommingSecret);
XYCORDSOCKS[incommingSecret + "/STREAMER"].send(data);
// XYCORDSOCKS[incommingSecret]
XYCORDSOCKS[incommingSecret].send(data);
}
});
// detect close
ws.on("close", function(code, message) {
console.log("Disconnected XY WebSocket (code err) => ", code);
console.log("Disconnected XY WebSocket (message err) => ", message);
eventEmitter.emit('endDetectedFromXY', {
detail: {
msg: {
code: code,
message: message
}
}
});
});
});
console.log("YX running.. explore XYCORDSOCKS=[] .");
wssXYCords = wss;
module.exports = {
XYCORDSOCKS,
INJECTOR,
wssXYCords
};