Add a Dockerfile for frontend test container; adapt code to simplify synchronization or Docker linkage
This commit is contained in:
parent
6c69867bcc
commit
bca09af2e0
15 changed files with 329 additions and 218 deletions
30
front/Dockerfile
Normal file
30
front/Dockerfile
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# DOCKER-VERSION 1.1.0
|
||||
|
||||
# /!\ WARNING: the container generated through this Dockerfile is made only for development purpose; it is NOT SAFE or production ready.
|
||||
|
||||
FROM debian:wheezy
|
||||
MAINTAINER Pierre-Olivier Mercier <nemunaire@nemunai.re>
|
||||
|
||||
# Install packages ####################################################
|
||||
|
||||
RUN apt-get -y update && \
|
||||
apt-get install -y \
|
||||
nginx-full \
|
||||
php5-fpm \
|
||||
php5-mcrypt \
|
||||
&& \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# Copying files #######################################################
|
||||
|
||||
ADD . /var/www/fic-server/front/
|
||||
|
||||
# Configure softwares #################################################
|
||||
|
||||
RUN ln -sf /var/www/fic-server/front/nginx.conf /etc/nginx/sites-enabled/default
|
||||
RUN ln -sf /var/www/fic-server/front/php-fpm.conf /etc/php5/fpm/pool.d/www.conf
|
||||
|
||||
# ENVIRONNEMENT #######################################################
|
||||
|
||||
EXPOSE 80/tcp 443/tcp
|
||||
CMD ["sh", "-c", "service nginx start && service php5-fpm start && /bin/bash"]
|
||||
108
front/nginx.conf
Normal file
108
front/nginx.conf
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
server_tokens off;
|
||||
client_header_buffer_size 512;
|
||||
client_max_body_size 512;
|
||||
|
||||
server {
|
||||
listen 80 default;
|
||||
listen [::]:80 ipv6only=on default;
|
||||
|
||||
rewrite ^ https://$host$uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ipv6only=on ssl;
|
||||
|
||||
root /var/www/fic-server/out/htdocs/;
|
||||
|
||||
access_log /var/log/nginx/fic.access_log;
|
||||
error_log /var/log/nginx/fic.error_log;
|
||||
|
||||
ssl_certificate /var/www/fic-server/misc/shared/server.crt;
|
||||
ssl_certificate_key /var/www/fic-server/misc/shared/server.key;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_prefer_server_ciphers on;
|
||||
# ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!ADH:!AECDH:!MD5:!DSS;
|
||||
ssl_ciphers AES256+EECDH:AES256+EDH;
|
||||
ssl_client_certificate /var/www/fic-server/misc/shared/cacert.crt;
|
||||
ssl_verify_client optional;
|
||||
ssl_crl /var/www/fic-server/misc/shared/crl.pem;
|
||||
|
||||
add_header Strict-Transport-Security "max-age=2592000; includeSubdomains";
|
||||
add_header X-Frame-Options DENY;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
|
||||
error_page 400 /errors/400/index.html;
|
||||
error_page 403 /errors/403/index.html;
|
||||
error_page 404 /errors/404/index.html;
|
||||
error_page 413 414 /errors/413/index.html;
|
||||
error_page 500 503 /errors/500/index.html;
|
||||
error_page 502 504 /errors/502/index.html;
|
||||
|
||||
location /
|
||||
{
|
||||
default_type text/html;
|
||||
expires epoch;
|
||||
|
||||
set $team 0;
|
||||
|
||||
include /var/www/fic-server/misc/shared/nginx-teams.conf;
|
||||
|
||||
if ($team) {
|
||||
root /var/www/fic-server/out/teams/$team$1;
|
||||
rewrite ^/([0-9]+-?[a-zA-Z0-9_-]*)/([a-zA-Z0-9_]+)/submission$ /submission.php?team=$team&theme=$1&exercice=$2 last;
|
||||
}
|
||||
if ($team = 0) {
|
||||
root /var/www/fic-server/out/htdocs/;
|
||||
}
|
||||
}
|
||||
|
||||
location /errors
|
||||
{
|
||||
root /var/www/fic-server/out/;
|
||||
}
|
||||
|
||||
location /connected
|
||||
{
|
||||
return 403;
|
||||
}
|
||||
|
||||
location /files
|
||||
{
|
||||
root /var/www/fic-server/;
|
||||
|
||||
# option to accelerate file delivery, require a custom nginx
|
||||
#aio on;
|
||||
directio 512;
|
||||
output_buffers 1 128k;
|
||||
}
|
||||
|
||||
location ~* \favicon.ico$ {
|
||||
root /var/www/fic-server/out/htdocs/;
|
||||
access_log off;
|
||||
expires 1d;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
location ~ ^/(assets|img|js|css|fonts)/ {
|
||||
root /var/www/fic-server/out/htdocs/;
|
||||
access_log off;
|
||||
expires 7d;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
location ~ /(\.ht|\.git|\.svn|\.onyx) {
|
||||
return 403;
|
||||
}
|
||||
|
||||
location /submission.php
|
||||
{
|
||||
root /var/www/fic-server/front/;
|
||||
|
||||
limit_rate 4k;
|
||||
|
||||
include /etc/nginx/fastcgi_params;
|
||||
fastcgi_pass unix:/var/run/php-fpm.sock;
|
||||
break;
|
||||
}
|
||||
}
|
||||
81
front/php-fpm.conf
Normal file
81
front/php-fpm.conf
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
; Start a new pool named 'www'.
|
||||
; the variable $pool can we used in any directive and will be replaced by the
|
||||
; pool name ('www' here)
|
||||
[www]
|
||||
|
||||
; Unix user/group of processes
|
||||
; Note: The user is mandatory. If the group is not set, the default user's group
|
||||
; will be used.
|
||||
user = www-data
|
||||
group = www-data
|
||||
|
||||
; The address on which to accept FastCGI requests.
|
||||
; Valid syntaxes are:
|
||||
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
|
||||
; a specific port;
|
||||
; 'port' - to listen on a TCP socket to all addresses on a
|
||||
; specific port;
|
||||
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||
; Note: This value is mandatory.
|
||||
listen = /var/run/php-fpm.sock
|
||||
|
||||
; Set permissions for unix socket, if one is used. In Linux, read/write
|
||||
; permissions must be set in order to allow connections from a web server. Many
|
||||
; BSD-derived systems allow connections regardless of permissions.
|
||||
; Default Values: user and group are set as the running user
|
||||
; mode is set to 0666
|
||||
listen.owner = www-data
|
||||
listen.group = www-data
|
||||
listen.mode = 0640
|
||||
|
||||
; Choose how the process manager will control the number of child processes.
|
||||
; Possible Values:
|
||||
; static - a fixed number (pm.max_children) of child processes;
|
||||
; dynamic - the number of child processes are set dynamically based on the
|
||||
; following directives. With this process management, there will be
|
||||
; always at least 1 children.
|
||||
; pm.max_children - the maximum number of children that can
|
||||
; be alive at the same time.
|
||||
; pm.start_servers - the number of children created on startup.
|
||||
; pm.min_spare_servers - the minimum number of children in 'idle'
|
||||
; state (waiting to process). If the number
|
||||
; of 'idle' processes is less than this
|
||||
; number then some children will be created.
|
||||
; pm.max_spare_servers - the maximum number of children in 'idle'
|
||||
; state (waiting to process). If the number
|
||||
; of 'idle' processes is greater than this
|
||||
; number then some children will be killed.
|
||||
; ondemand - no children are created at startup. Children will be forked when
|
||||
; new requests will connect. The following parameter are used:
|
||||
; pm.max_children - the maximum number of children that
|
||||
; can be alive at the same time.
|
||||
; pm.process_idle_timeout - The number of seconds after which
|
||||
; an idle process will be killed.
|
||||
; Note: This value is mandatory.
|
||||
pm = dynamic
|
||||
|
||||
; The number of child processes to be created when pm is set to 'static' and the
|
||||
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
|
||||
; This value sets the limit on the number of simultaneous requests that will be
|
||||
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
|
||||
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
|
||||
; CGI. The below defaults are based on a server without much resources. Don't
|
||||
; forget to tweak pm.* to fit your needs.
|
||||
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
|
||||
; Note: This value is mandatory.
|
||||
pm.max_children = 200
|
||||
|
||||
; The number of child processes created on startup.
|
||||
; Note: Used only when pm is set to 'dynamic'
|
||||
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
|
||||
pm.start_servers = 10
|
||||
|
||||
; The desired minimum number of idle server processes.
|
||||
; Note: Used only when pm is set to 'dynamic'
|
||||
; Note: Mandatory when pm is set to 'dynamic'
|
||||
pm.min_spare_servers = 5
|
||||
|
||||
; The desired maximum number of idle server processes.
|
||||
; Note: Used only when pm is set to 'dynamic'
|
||||
; Note: Mandatory when pm is set to 'dynamic'
|
||||
pm.max_spare_servers = 10
|
||||
50
front/submission.php
Normal file
50
front/submission.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
// When running only on one machine, team/exercice.php overwrite the following function
|
||||
if (!function_exists("show_submission_result"))
|
||||
{
|
||||
function show_submission_result($path)
|
||||
{
|
||||
if (file_exists(__DIR__."/../out/teams/".$path."/index.html"))
|
||||
print file_get_contents(__DIR__."/../out/teams/".$path."/index.html");
|
||||
else
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
}
|
||||
}
|
||||
|
||||
$filename = intval($_GET["team"])."-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]);
|
||||
$file = __DIR__."/../submission/".$filename;
|
||||
|
||||
|
||||
if (file_exists($file))
|
||||
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/serr");
|
||||
|
||||
else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["theme"]) && !empty($_GET["exercice"]))
|
||||
{
|
||||
$algos = array("md5", "sha1", "sha256", "sha384", "sha512", "whirlpool");
|
||||
$content = "";
|
||||
foreach($algos as $algo)
|
||||
{
|
||||
$cnt = hash($algo, $filename, true);
|
||||
// Encrypt twice on long key
|
||||
$key = hash($algo, $_POST["solution"]);
|
||||
|
||||
$kfirst = pack('H*', substr($key, 0, 64));
|
||||
$cnt = mcrypt_encrypt(MCRYPT_SERPENT, $kfirst, $cnt, MCRYPT_MODE_ECB);
|
||||
|
||||
if (strlen($key) > 64)
|
||||
{
|
||||
$ksec = pack('H*', substr($key, 64, 64));
|
||||
$cnt = mcrypt_encrypt(MCRYPT_SERPENT, $ksec, $cnt, MCRYPT_MODE_ECB);
|
||||
}
|
||||
|
||||
$content .= bin2hex($cnt)."\n";
|
||||
}
|
||||
|
||||
file_put_contents($file, $content, LOCK_EX);
|
||||
|
||||
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission");
|
||||
}
|
||||
|
||||
else
|
||||
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/gerr");
|
||||
Reference in a new issue