Advertisement
Fenix14977

Untitled

Apr 8th, 2020
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. 'use strict';
  2. const https = require('https');
  3. const WebSocket = require('ws');
  4.  
  5. const isJSON = function (str) {
  6. try {
  7. const data = JSON.parse(str);
  8. if(data === null) {
  9. return false;
  10. }
  11. return typeof(data) === "object"? true : false;
  12. } catch (e) {
  13. return false;
  14. }
  15. };
  16.  
  17. const ws = new WebSocket('wss://zentroidz.com/socket/');
  18.  
  19. ws.on('open', function open() {
  20. ws.send(JSON.stringify({hub: "zentroidz-hub"}));
  21. //super secret line of code here
  22. ws.send(JSON.stringify({request: "id"}));
  23. });
  24.  
  25. var serverid;
  26.  
  27. const createOptions = function (options) {
  28. if (options.url !== undefined) {
  29. if (options.url.startsWith("https://")) {
  30. options.port = 443;
  31. options.url = options.url.slice(8, Infinity);
  32. } else {
  33. options.port = 80;
  34. }
  35. if (options.url.startsWith("http://")) {
  36. options.url = options.url.slice(7, Infinity);
  37. }
  38. options.hostname = options.url.split("/")[0];
  39. options.path = options.url.split("/").slice(1, Infinity).join("/");
  40. delete options.url;
  41. } else {
  42. if (options.port === undefined) {
  43. options.port = 80;
  44. }
  45. if (options.path === undefined) {
  46. options.path = "/";
  47. }
  48. }
  49. if (options.method === undefined) {
  50. options.method = "GET";
  51. }
  52. return options;
  53. };
  54.  
  55. ws.on('message', function (jsonData) {
  56. if (isJSON(jsonData)) {
  57. var data = JSON.parse(jsonData).data;
  58. var id = JSON.parse(jsonData).id;
  59. try {
  60. if (data.id && serverid === undefined) {
  61. serverid = data.id;
  62. }
  63. } catch (e) {}
  64. if (isJSON(data)) {
  65. var obj = JSON.parse(data);
  66. if (obj.request === true && typeof obj.payload === "object") {
  67. var payload = obj.payload;
  68. const req = https.request(createOptions(payload), (res) => {
  69. res.on('data', (data) => {
  70. // ws.send(JSON.stringify({id: id, message: JSON.stringify({
  71. // headers: res.headersdata,
  72. // statusCode: res.statusCode,
  73. // data: data
  74. // })}));
  75. });
  76. });
  77. req.end();
  78. }
  79. }
  80. }
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement