0

Here is my problem : I have a docker container that contain a function inside. I need to write on the terminal this commands in order to launch my function :

docker run -p 80:8080 -it custom_docker bin/bash
/home/prog/executable_script -command 'string'

I would like to put this function inside a textarea in a php script, but how am I suppose to write it correctly in order to make it appear in my localhost ?

I've tried this but it didn't worked:

<html>
<body>
<textarea id="strings" name="chain" style="border: solid 1px #99bb99; width: 100%; margin: 0px; padding: 2px;" rows="25" cols="45">

<?php

    echo '<pre>';
    $content = system("sudo docker run -it custom_docker /bin/bash -w /home/prog/executable_script -command 'string');
    echo '</pre>';
?>
</textarea>
</body>
</html>

Only <pre></pre> is written as output...

Thanks for helping!

Also sorry for my bad English

Mohamed Salah
  • 959
  • 10
  • 40
  • 1) Giving PHP / web server sudo access is a no-no. It can be done, but shouldn't. 2) Why is docker needed for this at all? 3) Is `'string'` meant to be variable somehow? I.e. is the textarea specifically relevant to your question? – Jonnix Jun 11 '19 at 13:53
  • 1) Ok, I heard it could provoke some security issues 2) This fonction is inside the docker and my internship tutor told me to do that way ^^ 3) the 'string' here is a variable, you're right I don't think the textarea is relevant :/ – BillyPocheo Jun 11 '19 at 13:55

1 Answers1

0

You are never echoing your $content variable, so it always writes <pre></pre> to the content.

To send the output of the command:

echo system("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");

or

passthru("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");

To ensure that your script runs correctly with sudo privileges, edit the sudoers file and add a rule to allow the web server to call your script:

www-data ALL=NOPASSWD: /path/to/your/docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'
Maxime Launois
  • 928
  • 6
  • 19
  • It doesn't work for me... I've checked the errol log file and it's written that "the input device is not a TTY", so I removed -it from the command line and now I got this message " /bin/bash: -w: invalid option" any idea ? – BillyPocheo Jun 12 '19 at 07:29
  • You're right: `-w` is invalid option for bash. As well, you cannot use the `-t` option in `docker` because it's in a web server, and you cannot use `-i` because it's not interactive. I updated my answer to reflect these changes. – Maxime Launois Jun 12 '19 at 13:04