Compare commits

..

No commits in common. "c35bc143e37ef5dbf1defade186e9f2f481e5730" and "7eb4e46ff39deba2a0cec32d983fffb664689971" have entirely different histories.

8 changed files with 29 additions and 45 deletions

View File

@ -18,7 +18,6 @@ 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
@ -43,9 +42,6 @@ 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,13 +1,5 @@
#!/bin/bash
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
echo INIIIIT
# set root passwd
echo -e "root\nroot" | passwd
echo " ------------------------------ init.sh end -------------------------------"

View File

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

View File

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

View File

@ -6,4 +6,3 @@ 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,38 +15,40 @@ if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then
fi
for c in $forbidden_chars ; do
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
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
done
# Generate passwords if not done yet
genPassowrd () {
tr -dc A-Za-z0-9 </dev/urandom | head -c $1
}
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
if [ ! -f $PASSWD_LIST ] ; then
for user in $(cat "$USERS_LIST") ; do
echo "$user$separator$(genPassowrd 10)" >> $PASSWD_LIST
done
fi
# 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"
@ -65,8 +67,4 @@ nginx -c '/etc/nginx/nginx.conf'
/usr/sbin/sshd -E /dev/stderr
# Start watever the container should be doing
/bin/sh -c "$*" &
pid="$!"
trap "kill -INT $pid" INT
trap "kill -TERM $pid" TERM
wait "$pid"
/bin/sh -c "$*"

View File

@ -30,17 +30,17 @@ server {
listen 80;
listen [::]:80;
root /app/python_app/modules/;
root /usr/share/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,13 +29,14 @@ 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 fichier ou dossier <em>{}</em> na pas été trouvé.'.format(path), start_response)
return htmlresp(404, 'Le dossier <em>{}</em> na pas été trouvé.'.format(path), start_response)
# Module full path
module_path = BASE_MODULE_PATH + path
@ -46,7 +47,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