Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nthiery/wims-info
  • medimegh/wims-info
  • ventos/wims-info
  • bokaris/wims-info
4 results
Show changes
Commits on Source (99)
Showing
with 348 additions and 222 deletions
*.answer
test~coding~readingCppPrograms.fr/data/index
core
Modules:
- `<U2~coding~oefprogramC.fr/>`_: un dérivé du module éponyme déjà
existant dans WIMS, avec quelques menues améliorations.
- `Compréhension de programmes C++ <test~coding~readingCppPrograms.fr/>`_:
deviner l'entrée ou la sortie d'un programme
Le répertoire `<data/>`_ contient des programmes C++, qui peuvent être de deux types.
Pour les programmes du premier type, l'utilisateur doit deviner la sortie du programme.
Ces programmes sont nommés sous la forme ``<theme>_<nom>.cpp``.
Les programme du deuxième type doivent lire un entier entre 0 et 99 sur l'entrée standard, et l'utilisateur doit deviner lequel donne 42; pour l'instant cet entier doit être unique.
Ces programmes sont nommés ``<theme>_<nom>_input.cpp``
Pour les deux types de programme, le thème peut être constitué d'un thème principal et de sous-thèmes, séparés par des ``_`` (p. ex. ``loop_for``, ``loop_while``).
Les noms de fichiers ne doivent contenir que des caractères alphanumériques et le caractère ``_``.
* Liste des thèmes :
file
function
if
io
loop
procedure
struct
variable
vector1D
vector2D
* Sous-thèmes :
1. struct_simple : seulement un type de structure, dans un main (pas de fonction ou procédure)
2. struct_fonction : fonction manipulant et renvoyant des structures
3. struct_procedure : procédures manipulant des structures
4. struct_profond : structure contenant une structure (pas de fonction ou procédure)
5. struct_tableaux : structure contenant un tableau (pas de fonction ou procédure)
6. struct_tableau_struct : structure contenant un tableau contenant des structures (pas de fonction ou procédure)
7. struct_gros : structure contenant un tableau contenant des structures, avec fonctions
8. struct_hard : programmes difficiles manipulant des structures
* Liste et descriptif des programmes par thème :
Thème vector1D_recherche : recherche d'un élément dans un tableau. Les variations a, b, et c l'appliquent sur un tableau contenant 1, 2 ou 0 occurrences de l'élément.
recherche_1 : parcours du tableau de gauche à droite, avec return direct, correct.
recherche_2 : parcours du tableau de gauche à droite, avec return direct, non correct.
recherche_3 : parcours du tableau de gauche à droite, avec variable locale, correct.
recherche_4 : parcours du tableau de gauche à droite, avec variable locale, non correct.
recherche_5 : parcours du tableau de droite à gauche, avec variable locale, non correct.
recherche_6 : parcours du tableau de droite à gauche, avec return direct, correct.
recherche_7 : parcours du tableau de droite à gauche, avec variable locale, correct.
Thème vector1D_tri : teste si un tableau est trié. Les variations a, b, et c l'appliquent sur divers tableaux
tri_1 : avec return direct, correct (tri croissant). Tests sur 2358 8532 2538
tri_2 : avec return direct, non correct (tri croissant). Tests sur 2835 2583 5238
tri_3 : avec variable locale, correct (tri croissant). Tests sur 2358 8532 2538
tri_4 : avec variable locale, non correct (tri croissant). Tests sur 2835 2583 5238
tri_5 : avec return direct, correct (tri décroissant). Tests sur 2358 8532 8352
tri_6 : avec return direct, non correct (tri décroissant). Tests sur 5283 5328 5832
tri_7 : avec variable locale, correct (tri décroissant). Tests sur 2358 8532 8352
tri_8 : avec variable locale, non correct (tri décroissant). Tests sur 5283 5328 5832
* WIMS questions
- create temporary file
- pass data to input
- boolean arithmetic
* QCM Question logique
- [ ] pour ***que*** l'expression suivante ***retourne*** true.
- [ ]
......
CXXFLAGS=-g -Wall -std=c++0x
BASE_DOCKER_IMAGE=crosbymichael/build-essential
WIMSHOST=wimstest
#DOCKERHOST=134.158.75.87# wimsdocker
#DOCKERHOSTADMIN=debian
DOCKERHOST=sage-docker# sage-docker
DOCKERHOSTADMIN=ubuntu
SSH=ssh -x
docker-compile-and-run: docker-compile-and-run.cpp
docker-compile-and-run-remote: docker-compile-and-run-remote.cpp
preinstall::
ssh root@wimstest "groupadd docker; service docker restart; docker pull $(BASE_DOCKER_IMAGE)"
tests: test-compile-and-run.sh test-docker-compile-and-run test-docker-compile-and-run-client
#scp wimstest2-developers-config wims@wimstest:log/.developers
test-%:
@echo running tests for $*
@echo | $* prog.cpp > prog.out.obtained 2> /dev/null && diff prog.out prog.out.obtained
@echo coucou | $* prog-stdin.cpp > prog-stdin.out.obtained 2> /dev/null && diff prog-stdin.out prog-stdin.out.obtained
@rm prog.out.obtained prog-stdin.out.obtained
test-docker-compile-and-run-client: start-server
stop-server:
-killall docker-compile-and-run-server
start-server: #stop-server
docker-compile-and-run-server &
# ssh wims@$(WIMSHOST) "(echo Host wimsdockerhost; echo Hostname $(DOCKERHOST); echo IdentityFile ~/.ssh/id_rsa_docker) >> .ssh/config; chmod 600 .ssh/config"
dockerhost-preinstall:
scp dockerhost-setup.sh root@$(DOCKERHOST):
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo bash dockerhost-setup.sh
dockerhost-clean: # TODO Add a test that DOCKERHOST <-> WIMSHOST
ssh root@$(DOCKERHOST) userdel -r wims
#scp wimstest2-developers-config wims@$(DOCKERHOST):log/.developers
#ssh root@wimstest service httpd restart
install:
scp compile-and-run.sh wims@wimstest:other/bin
scp docker-compile-and-run-wrapper.sh wims@wimstest:public_html/bin/docker-compile-and-run
ssh wims@wimstest chmod 755 other/bin/compile-and-run.sh public_html/bin/docker-compile-and-run
scp docker-compile-and-run.cpp wims@wimstest:
ssh wims@wimstest "g++ $(CXXFLAGS) docker-compile-and-run.cpp -o docker-compile-and-run; mv docker-compile-and-run other/bin; rm docker-compile-and-run.cpp"
ssh root@wimstest "chown wims:docker ~wims/other/bin/docker-compile-and-run; chmod 2755 ~wims/other/bin/docker-compile-and-run"
ssh root@wimstest "service docker restart; service httpd restart"
testinstall:
scp prog.cpp wims@wimstest:
ssh wims@wimstest ./other/bin/docker-compile-and-run prog.cpp
dockerhost-install:
$(SSH) wims@$(DOCKERHOST) mkdir -p other/bin
scp compile-and-run.sh docker-compile-and-run-server wims@$(DOCKERHOST):other/bin
$(SSH) wims@$(DOCKERHOST) chmod 755 other/bin/compile-and-run.sh other/bin/docker-compile-and-run-server
scp docker-compile-and-run.cpp wims@$(DOCKERHOST):
$(SSH) wims@$(DOCKERHOST) "g++ $(CXXFLAGS) docker-compile-and-run.cpp -o other/bin/docker-compile-and-run && rm docker-compile-and-run.cpp"
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) "sudo chown wims:docker ~wims/other/bin/docker-compile-and-run; sudo chmod 2755 ~wims/other/bin/docker-compile-and-run"
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo service docker restart
dockerhost-run:
$(SSH) wims@$(DOCKERHOST) other/bin/docker-compile-and-run-server
dockerhost-test:
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) docker run hello-world
scp prog.cpp wims@$(DOCKERHOST):
$(SSH) wims@$(DOCKERHOST) ./other/bin/docker-compile-and-run prog.cpp < /dev/null
docker-compile-and-run-client prog.cpp < /dev/null
wimshost-install:
scp docker-compile-and-run-client wims@$(WIMSHOST):other/bin/docker-compile-and-run
scp docker-compile-and-run-wrapper.sh wims@$(WIMSHOST):public_html/bin/docker-compile-and-run
# $(SSH) root@$(WIMSHOST) service httpd restart
wimshost-test: # Needs to be updated
scp prog.cpp wims@$(WIMSHOST):
$(SSH) wims@$(WIMSHOST) ./other/bin/docker-compile-and-run prog.cpp < /dev/null
install-remote:
xxx
......@@ -15,9 +15,11 @@ if [ x"$1" = "x" ]; then
exit 0
fi
ulimit -H -t 10
# -H does not seem to always work
#ulimit -H -t 100
ulimit -t 5
if g++ $CXXFLAGS $1; then
# ulimit -H -t 1 # Apparently -t takes a number >= 10 for hard limit
# ulimit -H -t 1 # Apparently -H -t takes a number >= 10 for hard limit
ulimit -t 1
./a.out
else
......
File deleted
#!/bin/sh
#host=134.158.75.87 # wims-docker
host=134.158.75.207 # sage-docker
#host=localhost
port=8080
file=$1
curl --form "code=<$file" --form "input=<-" $host:$port/compile-and-run
#!/usr/bin/python
import tempfile
import popen2
import os
from flask import Flask, redirect, url_for, request
docker_compile_and_run="/home/wims/other/bin/docker-compile-and-run"
#docker_compile_and_run="docker-compile-and-run"
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Web service for compiling and running a c++ program in a remote sandbox.\nPost on /compile-and-run with the c++ program uploaded as form input `code` and input as form input `input`\n'
@app.route('/compile-and-run',methods=['POST'])
def compile_and_run():
input = request.form['input']
code = request.form['code']
fd = tempfile.NamedTemporaryFile(suffix=".cpp", prefix="docker-compile-and-run-")
fd.write(code)
fd.flush()
(child_out, child_in) = popen2.popen2(docker_compile_and_run+" "+fd.name)
child_in.write(input)
child_in.flush()
child_in.close()
result = child_out.read()
return result
if __name__ == '__main__':
#app.run(debug=True)
app.run(host="0.0.0.0", port=8080)
......@@ -125,7 +125,7 @@ string docker_run(string container, string cmd, vector<string> args) {
vector<string> docker_args = {"run",
"--detach=true", // Run in background
// With 10M, the compilation and run is much slower
"--memory", "100M", "--memory-swap", "-1",
"--memory", "100M", "--memory-swap", "100M",
// Not available with docker 1.7?
// "--kernel-memory", "50M",
// "--cpu-quota" "50000", // Allow for using max 50% of the CPU
......@@ -140,8 +140,10 @@ string docker_run(string container, string cmd, vector<string> args) {
return ID;
}
void docker_exec(string docker_id, vector<string> args) {
vector<string> docker_args = {"exec", "-i", docker_id};
void docker_exec(string docker_id, vector<string> args, bool interactive) {
vector<string> docker_args = {"exec"};
if (interactive) docker_args.push_back("-i");
docker_args.push_back(docker_id);
for (unsigned int i=0; i<args.size(); i++)
docker_args.push_back(args[i]);
my_system(docker, docker_args);
......@@ -181,10 +183,11 @@ int main(int argc, char **argv) {
cerr << "Current directory: ";
my_system("/bin/pwd", {});
}
docker_cp(docker_id, bin_dir+compile_and_run, compile_and_run);
docker_cp(docker_id, program, program_in_docker);
docker_exec(docker_id, vector<string>({ "chmod", "700", compile_and_run }));
docker_exec(docker_id, vector<string>({ "./"+compile_and_run, program_in_docker}));
docker_exec(docker_id, vector<string>({ "chmod", "700", compile_and_run }), false);
docker_exec(docker_id, vector<string>({ "./"+compile_and_run, program_in_docker}), true);
docker_rm(docker_id);
return 0;
}
#include<iostream>
using namespace std;
void saisie(int a){
cout<<"Tapez un entier ";
cin>>a;
if((a%3==0) && (a/3==42)) cout<<"la saisie est bonne : " << a/3 <<endl;
else cout<<"la saisie est n'est pas bonne"<<endl;
}
int main()
{
int a;
saisie(a);
return 0;
}
#include<iostream>
using namespace std;
void saisie(int a){
while (a%3!=0){
cout<<"Tapez un entier ";
cin>>a;
}
while (a/4!=42){
cout<<"Tapez un entier ";
cin>>a;
}
cout<<"la saisie est bonne : " << a/4 <<endl;
}
int main()
{
int a;
saisie(a);
return 0;
}
\ No newline at end of file
#include<iostream>
using namespace std;
void saisie(int *a, int* b, int N){
int i,j, t, o;
int c[2*N];
for(i=0;i<N;i++){cout<<"Tapez un entier ";cin>>a[i];}
for(i=0;i<N;i++){cout<<"Tapez un entier ";cin>>b[i];}
o=true;
i=0;
while(o && i<N-1)if(a[i]>a[i+1])o=false; else i++;
if(!o)cout<<"Erreur"<<endl;
o=true;
i=0;
while(o && i<N-1)if(b[i]>b[i+1])o=false; else i++;
if(!o)cout<<"Erreur"<<endl;
for(i=0;i<2*N;i++){
if(i<N)c[i]=a[i];
else c[i]=b[i-N];
}
for(i = 1; i < 2*N; ++i)
for(j = 2*N-1; j >= i; --j) {
if(c[ j-1] > c[j]) {
t = c[j-1];
c[j-1] = c[j];
c[j] = t;
}
}
for(i=0;i<2*N;i++)cout<<c[i]<<" ";
cout<<endl;
}
int main()
{
const int N=4;
int a[N];
int b[N];
saisie(a,b,N);
return 0;
}
#include<iostream>
using namespace std;
void saisie(int a){
cout<<"Tapez un entier ";
cin>>a ;
while (a/3!=42){
cout<<"Tapez un entier ";
cin>>a;
}
cout<<"la saisie est bonne : " << a/3 <<endl;
}
int main()
{
int a;
saisie(a);
return 0;
}
#include<iostream>
using namespace std;
void saisie(int a){
cout<<"Tapez un entier ";
cin>>a ;
while (a/3!=42){
cout<<"Tapez un entier ";
cin>>a;
}
cout<<"la saisie est bonne : " << a/3 <<endl;
}
int main()
{
int a;
saisie(a);
return 0;
}
\ No newline at end of file
#include<iostream>
using namespace std;
void saisie(int a){
while (a%3!=0){
cout<<"Tapez un entier ";
cin>>a;
}
while (a/4!=42){
cout<<"Tapez un entier ";
cin>>a;
}
cout<<"la saisie est bonne : " << a/4 <<endl;
}
int main()
{
int a;
saisie(a);
return 0;
}
\ No newline at end of file
#include<iostream>
using namespace std;
void saisie(int *a, int* b, int N){
int i,j, t, o;
int c[2*N];
for(i=0;i<N;i++){cout<<"Tapez un entier ";cin>>a[i];}
for(i=0;i<N;i++){cout<<"Tapez un entier ";cin>>b[i];}
o=true;
i=0;
while(o && i<N-1)if(a[i]>a[i+1])o=false; else i++;
if(!o)cout<<"Erreur"<<endl;
o=true;
i=0;
while(o && i<N-1)if(b[i]>b[i+1])o=false; else i++;
if(!o)cout<<"Erreur"<<endl;
for(i=0;i<2*N;i++){
if(i<N)c[i]=a[i];
else c[i]=b[i-N];
}
for(i=0;i<2*N;i++)cout<<c[i]<<" ";
cout<<endl;
}
int main()
{
const int N=4;
int a[N];
int b[N];
saisie(a,b,N);
return 0;
}
\ No newline at end of file
CXXFLAGS=-g -Wall -std=c++0x
WIMSHOST=wimstest
#DOCKERHOST=134.158.75.87# wimsdocker
DOCKERHOSTADMIN=debian
DOCKERHOST=134.158.75.92
SSH=ssh -x
tests: test-compile-and-run.sh test-docker-compile-and-run test-docker-compile-and-run-client
test-%:
@echo running tests for $*
@echo | $* prog.cpp > prog.out.obtained 2> /dev/null && diff prog.out prog.out.obtained
@echo coucou | $* prog-stdin.cpp > prog-stdin.out.obtained 2> /dev/null && diff prog-stdin.out prog-stdin.out.obtained
@rm prog.out.obtained prog-stdin.out.obtained
dockerhost-preinstall:
scp dockerhost_setup.sh secure_exec_local secure_exec_server $(DOCKERHOSTADMIN)@$(DOCKERHOST):
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo bash dockerhost-setup.sh
dockerhost-update:
scp secure_exec_local secure_exec_server $(DOCKERHOSTADMIN)@$(DOCKERHOST):
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo cp secure_exec_server secure_exec_local /usr/local/bin
dockerhost-clean: # TODO Add a test that DOCKERHOST <-> WIMSHOST
ssh root@$(DOCKERHOST) userdel -r www
dockerhost-run:
$(SSH) wims@$(DOCKERHOST) other/bin/docker-compile-and-run-server
dockerhost-test:
@echo == Testing docker ===============
$(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo docker run hello-world
@echo == Testing secure_exec_local ====
tar czf - -C tests/dir . | $(SSH) $(DOCKERHOSTADMIN)@$(DOCKERHOST) sudo -u www super secure_exec_local ./monscript
@echo == Testing server ===============
tar czf archive.tgz -C tests/dir .
curl --form "archive=@archive.tgz" --form "cmd=./monscript" "http://$(DOCKERHOST):8080/secure_exec"
wimshost-install:
scp secure_exec wims@$(WIMSHOST):other/bin
scp secure_exec_wrapper.sh wims@$(WIMSHOST):public_html/bin/secure_exec
# $(SSH) root@$(WIMSHOST) service httpd restart
wimshost-test: # Needs to be updated
scp prog.cpp wims@$(WIMSHOST):
$(SSH) wims@$(WIMSHOST) ./other/bin/docker-compile-and-run prog.cpp < /dev/null
install-remote:
xxx
# Secure execution of a command in a sandbox
This implements a web service allowing to execute a command in a
docker sandbox with reasonable security.
## Usage of the client
This assumes that the webservice is running and its url is set in
[](secure_exec).
The following command uses the webservice to create a new sandbox,
initialize it with a copy of the content of `dir` in the sandbox, run
`cmd` in it, and print the output:
secure_exec <dir> <cmd>
## Installation of the webservice
This assumes that you have access to some remote machine running some
variant of debian, under a user with sudo permission.
- Edit the [](Makefile) to point DOCKERHOST to the ip address of the
server and DOCKERHOSTADMIN to the user
- Run:
make dockerhost-preinstall
make dockerhost-run
- (optional) Run
make dockerhost-test
## Updating the webservice
Run:
make dockerhost-update
## Tests
The directory `tests` contains a collection of tests scripts:
- Test 1 assumes that docker is installed.
- Tests 2 and 3 assume in addition that `secure_exec_local` has been
installed in `/usr/local/bin` and `/etc/super.tab` has been
configured locally as in `super.tab`.
- Test 4 assumes that the web service is running on some (remote)
server, and that its url is set in `secure_exec`.
In addition, the following command runs some tests on the webservice:
make dockerhost-test
## TODO
- More documentation
- Security review
- Truncation of output
- Authentication between client and server
A minima: firewall setup to restrict incoming connections from the client
- Resource limitations
- The created temporary archive should be in a temporary directory and cleaned up
Or could we avoid the temporary file?
#!/bin/bash
BASE_DOCKER_IMAGE=crosbymichael/build-essential
# Taken from https://docs.docker.com/engine/installation/linux/docker-ce/debian/#install-using-the-repository
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common \
super python3-flask
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
#sudo groupadd docker # aready exists
#sudo service docker restart
sudo docker pull $BASE_DOCKER_IMAGE
sudo useradd www
sudo cp secure_exec_local secure_exec_server /usr/local/bin
sudo sh -c 'echo "secure_exec_local /usr/local/bin/secure_exec_local u=nobody g=docker www" >> /etc/super.tab'
# At boot time run the server as www
sudo sh -c '#!/bin/sh echo "su -c /usr/local/bin/secure_exec_server www" >> /etc/rc.local'
# TODO