Compare commits

...

4 Commits

Author SHA1 Message Date
c35bc143e3 path fix 2021-03-10 21:40:45 +01:00
853b0e0a7d update 2021-03-03 16:49:58 +01:00
c7cf872d9c cleaner 2021-02-17 14:25:56 +01:00
0685e81bb0 better doc 2021-02-17 14:22:21 +01:00
8 changed files with 45 additions and 29 deletions

View File

@ -18,6 +18,7 @@ While in this file directory, open a terminal and run the following command (the
docker run -it --name pythonsandbox --rm --network host -v "$(pwd)"/production_eleves:/app/python_app/modules -v "$(pwd)"/config:/app/config jeancloud/pythonsandbox
```
(Logs will flow in your terminal, CTRL+C will stop the process).
Read carefuly the first messages!
## Use it
@ -42,6 +43,9 @@ Also, as this is poorly tested, the docker system make sure the environment is s
docker build . -t jeancloud/pythonsandbox
```
or pull it
```
docker pull jeancloud/pythonsandbox
```
## Volumes
- `/app/modules` is where python scripts will be executed on some URL calls.

View File

@ -1,5 +1,13 @@
#!/bin/bash
echo INIIIIT
echo " ------------------------------ init.sh file ------------------------------"
# Allow SSH as root
if [ -z "$(grep '^PermitRootLogin yes' /etc/ssh/sshd_config)" ] ; then
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
fi
# set root passwd
echo -e "root\nroot" | passwd
echo " ------------------------------ init.sh end -------------------------------"

View File

@ -1,2 +1,3 @@
218-amine=TPA6eMfztS
218-chems=osjMQQ8rXd
test=bRqy6jlnM6

View File

@ -1,2 +1,3 @@
218-amine
218-chems
test

View File

@ -6,3 +6,4 @@ services:
- ./config:/app/config
- ./production_eleves:/app/python_app/modules
network_mode: "host"
restart: "unless-stopped"

View File

@ -6,7 +6,7 @@ PASSWD_LIST="/app/config/passwords.txt"
CUSTOM_SCRIPT="/app/config/init.sh"
separator="=" # Must be ascii for cut
forbidden_chars=". /"
forbidden_chars=". / : # = \ "
# Check we got user list
if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then
@ -15,40 +15,38 @@ if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then
fi
for c in $forbidden_chars ; do
for file in "$USERS_LIST" "$PASSWD_LIST" ; do
if [ -n "$(cat "$USERS_LIST" | grep -F $c)" ] ; then
echo "Le fichier « $file » ne doit pas contenir le caractère « $c » !"
exit 1
fi
done
if [ -n "$(cat "$USERS_LIST" | grep -F $c)" ] ; then
echo "Le fichier « $USERS_LIST » ne doit pas contenir le caractère « $c » !"
exit 1
fi
done
# Generate passwords if not done yet
genPassowrd () {
tr -dc A-Za-z0-9 </dev/urandom | head -c $1
}
if [ ! -f $PASSWD_LIST ] ; then
for user in $(cat "$USERS_LIST") ; do
echo "$user$separator$(genPassowrd 10)" >> $PASSWD_LIST
done
fi
for user in $(cat "$USERS_LIST") ; do
if [ -z "$user" ] || [ -n "$(cat $PASSWD_LIST | grep "$user$separator")" ] ; then continue ; fi
echo "$user$separator$(genPassowrd 10)" >> $PASSWD_LIST
done
# Create users, home dirs, change passwords and home owners
for line in $(cat $PASSWD_LIST) ; do
name="$(echo "$line" | cut -d "$separator" -f 1)"
pass="$(echo "$line" | cut -d "$separator" -f 2)"
if [ -z "$name" ] || [ -z "$pass" ] ; then echo "Malformed line skipped: '$line'" ; continue ; fi
home="$HOME_BASE/$name"
mkdir -p "$home"
#useradd --home-dir "$home" --no-user-group -G eleve --shell /bin/bash --root "$home" "$name"
useradd --home-dir "$home" --no-user-group -G eleve --shell /bin/bash "$name"
$ret="$?"
if [ "$ret" -ne 0 ] && [ "$ret" -ne 9 ] ; then
echo "Cant create user '$name'. Error '$ret'."
continue
fi
echo "$pass\n$pass" | passwd "$name" &> /dev/null
chown "$name":eleve "$home"
done
# Allow SSH as root
if [ -z "$(grep '^PermitRootLogin yes' /etc/ssh/sshd_config)" ] ; then
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
fi
echo "\nFin de la préparation des utilisateurs.\n"
@ -67,4 +65,8 @@ nginx -c '/etc/nginx/nginx.conf'
/usr/sbin/sshd -E /dev/stderr
# Start watever the container should be doing
/bin/sh -c "$*"
/bin/sh -c "$*" &
pid="$!"
trap "kill -INT $pid" INT
trap "kill -TERM $pid" TERM
wait "$pid"

View File

@ -30,17 +30,17 @@ server {
listen 80;
listen [::]:80;
root /usr/share/app/python_app/modules/;
root /app/python_app/modules/;
location ~ favicon.ico {
root /usr/share/app/;
}
location / {
# index index.html main.py;
# try_files $uri $uri/ =404;
# }
index index.html main.py;
try_files $uri $uri/ =404;
}
#location ~ \.py {
location ~ \.py {
include uwsgi_params;
#uwsgi_param PATH_INFO "$1";
#uwsgi_param SCRIPT_NAME /;

View File

@ -29,14 +29,13 @@ def application(env, start_response):
path = path_minus_one
function = path_elements[-1]
elif os.path.isfile(BASE_MODULE_PATH + path):
path = path_minus_one + '/main'
function = 'index'
elif os.path.isdir(BASE_MODULE_PATH + path):
path += '/main'
function = 'index'
else:
return htmlresp(404, 'Le dossier <em>{}</em> na pas été trouvé.'.format(path), start_response)
return htmlresp(404, 'Le fichier ou dossier <em>{}</em> na pas été trouvé.'.format(path), start_response)
# Module full path
module_path = BASE_MODULE_PATH + path
@ -47,7 +46,7 @@ def application(env, start_response):
m = importlib.import_module(module_path)
importlib.reload(m)
except ModuleNotFoundError:
#print('Le fichier {} na pas été trouvé. {}'.format(module_path, str(path_elements)))
print('Le fichier {} na pas été trouvé. {}'.format(module_path, str(path_elements)))
return htmlresp(404, 'Le fichier <em>{}</em> na pas été trouvé.'.format(path), start_response)
# Find which parameters the function needs