# Python, web and SSH sandbox **For educational purpose only! None of this software is industry grade quality.** # How to use it? ## Install docker CF the interweb TODO ## Run it ``` docker run --name pythonsandbox --rm --network-mode host -v ./production_eleves:/app/python_app/modules -v ./data:/app/data adrianamaglio/pythonsandbox ``` (Logs will flow in your terminal, CTRL+C will stop the process). ## Initialize it The directory `data` must contain a `users.txt` containing one username per line, or a `passwords.txt` file, containing `username=password` lines. If you do not provide a password file, it will be generated from user file. The password file is the database from which users/passwords are created in the system. Additionnaly, you can add a file named `./data/init.sh` which will be executed before starting the servers. It is usefull for debuging or customisation purposes! ## Use it You can now ssh into your localhost (and others computer on the same network can ssh into your host). Usernames and passwords are the one provided in the password file. Students home directories are then listed in the `production_eleves` directory. # The docker image ## Build the docker image ``` docker build . -t adrianamaglio/pythonsandbox ``` or pull it ``` TODO: send image to hub ``` ## Run the docker image ``` docker run -it --network host --name pythonsandbox pythonsandbox ``` Or if you want to save student work outside of the container: ``` docker run -it --network host --name pythonsandbox -v "$(pwd)"/app/modules:/usr/share/app/modules pythonsandbox ``` And with user list file ``` docker run -it --network host --name pythonsandbox -v "$(pwd)"/app/modules:/usr/share/app/modules -v "$(pwd)"/app/users.txt:/usr/share/app/users.txt pythonsandbox ``` # How does it works? ## A python script It run with uwsgi (CF dockerfile CMD line) and load python modules files according to URL. For instance, when you get `/test/my_function` the function `my_function` is executed from the file `test.py`. Default behavior: - if `test` is a directory, we will try to load default function `index` from file `test/my_function.py` - if `test/my_function` is a directory, we will try to load default function `index` from file `test/my_function/main.py` GET arguments (the ones in URL), are passed as function parameter (only if the parameters name matches the arguments name). ## SSH server Allow student to connect via SSH or SFTP to add python files and play with bash. ## A docker image To bundle everything in one place. This docker image is not a pretty one, we should split those services into several containers. But that would be harder to run, so forget that. Also, as this is poorly tested, the docker system make sure the environment is stable.