runtest.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * You may redistribute this program and/or modify it under the terms of
  3. * the GNU General Public License as published by the Free Software Foundation,
  4. * either version 3 of the License, or (at your option) any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // THIS SCRIPT IS ESSENTIALLY A BACKDOOR
  15. // DON'T RUN IT ON ANYTHING YOU CARE ABOUT
  16. // This script binds port 8083 and allows remote testing on the system.
  17. var spawn = require('child_process').spawn;
  18. var http = require("http");
  19. var qs = require('querystring');
  20. var os = require("os");
  21. var fs = require("fs");
  22. var PATH = "/home/user/";
  23. var spawnProc = function(file, callback, timeoutMilliseconds) {
  24. var child = spawn(file);
  25. var out = '', err = '';
  26. var to = setTimeout(function() {
  27. child.kill('SIGKILL');
  28. err += "TIMEOUT\n";
  29. callback(1000, out, err);
  30. }, timeoutMilliseconds);
  31. child.stdout.on('data', function (data) { out += data; });
  32. child.stderr.on('data', function (data) { err += data; });
  33. child.on('exit', function (code) {
  34. callback(code, out, err);
  35. });
  36. };
  37. var send = function(response, content) {
  38. response.writeHeader(200, {"Content-Type": "text/plain"});
  39. response.write(content);
  40. response.end();
  41. };
  42. var runTest = function(fileName, response, timeoutMilliseconds) {
  43. fs.chmodSync(fileName, '755');
  44. spawnProc(fileName, function(code, out, err) {
  45. send(response, "d4:codei" + code + "e6:stdout" + out.length + ":" + out + "6:stderr" +
  46. err.length + ":" + err + "e");
  47. fs.unlink(fileName);
  48. }, timeoutMilliseconds);
  49. };
  50. http.createServer(function(request, response) {
  51. if (request.method == 'POST') {
  52. var fileName = PATH + (Math.random() * 0x100000000) + ".exe";
  53. var fsStream = fs.createWriteStream(fileName);
  54. request.on("data", function(chunk) {
  55. fsStream.write(chunk);
  56. });
  57. request.on("end", function() {
  58. fsStream.on("close", function() {
  59. runTest(fileName, response, 10000);
  60. });
  61. fsStream.end();
  62. });
  63. } else {
  64. send(response, "ERROR\nNot a POST");
  65. }
  66. }).listen(8083);