Python function block

Don't use this code! Anyone can call sys.exit(0).

Anyways, I made a C++ function block here.

const express = require('express');
const app = express();
const fs = require('fs');
const { exec } = require('child_process');
const { v4: uuidv4 } = require('uuid');
app.get('/', (req,res) => {
  res.send("Send a GET request to /run?code=yourcode to run C++. <br> You can add an optional stdin=yourstdin parameter in the querystring to specify standard input.");
});
app.get('/run', (req,res) => {
  res.set('Access-Control-Allow-Origin', '*');
  if(!req.query.code) {
    res.send('Add a code parameter to the querystring to run some C++ code. If you have a code parameter then you probably forgot to url encode the code.');
    return; 
  }
  const code = req.query.code;
  const id = uuidv4();
  fs.writeFile(`programs/${id}.cpp`, code, err => {
    if (err) {
      res.status(500).send("An internal server error occured. <br>" + err.message);
    } else {
      const proc = exec(`g++ -o compiled/${id} programs/${id}.cpp && ./compiled/${id}`, {timeout: 120000}, (err,stdout,stderr) => {
        if (err) {
          res.json({status: 1, error: err.message})
        } else if (stderr) {
          res.json({status: 1, error: stderr.message})
        } else {
          res.json({status: 0, stdout: stdout});
        }
        ['programs/' + id + '.cpp', 'compiled/' + id].forEach(file => {
          fs.unlink(file, err => {
            if (err && err.code !== 'ENOENT') throw err;
          });
        });
      });
      if (req.query.stdin) {
        proc.stdin.write(req.query.stdin);
        proc.stdin.end();
      }
    }
  });
});
app.listen(8080);

But won't that only effect this actual repl instance?

That's why I've published it because I'm not worried about it being attacked
[edit]
I just tried it out and it errored but then just carried on with new requests

I'm certain that someone could bring it down but hoping that due to repl.it sandboxing, that it shouldn't cause any major disturbance to my other repls
[/edit]

import sys;sys.exit()

To everyone - maybe don't go publishing suggested attacks? :slight_smile:

Be good people :slight_smile:

That gave the result as:

so unsuccessful :slight_smile:

Offtopic. Closing.