The online compiler?

Want to write your online compiler for C++. The principle of operation I understand. The person enters his code on the website in the form, then this code is sent to the server, compiled there and back the result. How to send a file to the server clear, and how to make it there opened, started up and gave a result? Where to start, where you can read about it and what you can do?
March 23rd 20 at 19:26
5 answers
March 23rd 20 at 19:28
If you know how to compile from the terminal — exec(). Another question you are protected from malicious code on the server, and that you just will not be able to do.
Before the first of the Trojan, and then he's going to learn a ton of material on this issue - Doris.Swaniawski commented on March 23rd 20 at 19:31
and then what to do? - Tevin.Ritchie41 commented on March 23rd 20 at 19:34
@Tevin.Ritchie41, to modify the compiler to call dangerous functions, Sandboxie compilers. Ways many and too complex for the person asking these questions. In other words — to score. - Elinor.Langosh commented on March 23rd 20 at 19:37
@Tevin.Ritchie41,
and then what to do?
there is a relatively simple method - the isolation of the foreign code in a sandbox. Safer and easiest way to do this using virtualization, ie collect virtual machine (minimal set of packages which may be needed for those who will use your service), without any access to the world (just stdin/stdout), then create a copy of it (better to use a snapshot, they are in any modern virtualization environment) and pour it in a custom application trigger, waiting for the completion of work or on timeout, stop the virtual machine and show the result on the website. In practice, the user waiting for start virtual machine, you can start it beforehand in standby mode, when the user.

The isolation of the virtual machine the most reliable and the simplest to use but very resource hungry, because you actually pretend a full car. This is especially true if you keep the pool running machines waiting for user applications to run (and users can be many).

As an alternative, if you restrict the environment of linux, you can configure the cgroup and user rights, so that launching the app it will be the most limited. Actually this is based on the same lxc containers or Docker or a bunch of others. - ryley commented on March 23rd 20 at 19:40
March 23rd 20 at 19:30
Use a third-party compiler and guess
to make it there opened, started up and gave a result of
Have used. He showed me the result code. And I want to know how it works on the server as it's started - Tevin.Ritchie41 commented on March 23rd 20 at 19:33
I want to know how it works on the server
@Tevin.Ritchie41, works fine, normally. - Brigitte.Keebler commented on March 23rd 20 at 19:36
nafig you do it? if you don't want to help, you don't need to write anything here. - Tevin.Ritchie41 commented on March 23rd 20 at 19:39
@Tevin.Ritchie41, you're hard to help, your question is vague. How it works there - well, and works like a chimney - chug-chug-chug. - Brigitte.Keebler commented on March 23rd 20 at 19:42
@Tevin.Ritchie41, 00110111010101011010110101101001010101101100111111 - Jackeline93 commented on March 23rd 20 at 19:45
March 23rd 20 at 19:32
Need to write a script in PHP that will be on the server to run the compile with the command shell_exec().
But of course it would be unsafe to execute on server arbitrary code. Therefore, compilation and execution should be done in a virtual machine.
And another language is impossible? Only PHP? - lazaro.Abbo commented on March 23rd 20 at 19:35
It is theoretically possible to use any language that is available through CGI-BIN, but in practice such a script is very difficult to debug. In case of any error, the server will just issue a 500: Internal Server Error. In PHP to write and debug your scripts much easier. - rowan_Sip commented on March 23rd 20 at 19:38
March 23rd 20 at 19:34
Chet directly a barrage of similar questions.

to make it there opened, started up and gave a result?

PHP.
March 23rd 20 at 19:36
For example this: https://github.com/mattgodbolt/compiler-explorer
Well, the project online: https://godbolt.org/

By the way, most of the professional C++ developers use this tool.

Find more questions by tags Web DevelopmentC++