New script to generate nginx.conf part

This commit is contained in:
nemunaire 2014-01-21 03:08:08 +01:00
parent cc588d51f9
commit 8d7394b833
7 changed files with 108 additions and 29 deletions

View File

@ -5,8 +5,40 @@ use strict;
use warnings; use warnings;
use DBI; use DBI;
use File::Basename; use File::Basename;
use Digest::MD5 qw(md5_hex); use Digest;
use Digest::SHA qw(sha1_hex sha224_hex sha256_hex sha384_hex sha512_hex); use Digest::MD5 qw(md5);
use Digest::SHA qw(sha1 sha224 sha256 sha384 sha512);
use Mcrypt qw(:ALGORITHMS :MODES :FUNCS);
sub encrypt
{
my ($algo, $key, $data, $mode) = @_;
my $td = mcrypt_load( $algo, "", $mode, '' );
mcrypt_init($td, $key, "");
my $encrypted = mcrypt_encrypt($td, $data);
mcrypt_end($td);
return $encrypted;
}
sub my_crypt
{
my ($key, $content) = @_;
my $kfirst = pack('H*', substr($key, 0, 64));
$content = encrypt(SERPENT, $kfirst, $content, ECB);
if (length $key > 64)
{
my $ksec = pack('H*', substr($key, 64, 64));
$content = encrypt(SERPENT, $ksec, $content, ECB);
}
return unpack('H*', $content);
}
#Return number of good solutions #Return number of good solutions
my $exit = 0; my $exit = 0;
@ -70,9 +102,18 @@ for my $f (readdir $dh)
my $exercice = $3; my $exercice = $3;
open my $fh, "<", "$submission_dir/$f"; open my $fh, "<", "$submission_dir/$f";
my $solution = <$fh>; my %solution;
$solution{md5} = <$fh>; chomp( $solution{md5} );
$solution{sha1} = <$fh>; chomp( $solution{sha1} );
$solution{sha256} = <$fh>; chomp( $solution{sha256} );
$solution{sha384} = <$fh>; chomp( $solution{sha384} );
$solution{sha512} = <$fh>; chomp( $solution{sha512} );
$solution{whirlpool} = <$fh>; chomp( $solution{whirlpool} );
close $fh; close $fh;
use Data::Dumper;
print STDERR Dumper(\%solution);
$dbh = DBI->connect("DBI:mysql:database=$db_settings{db};host=$db_settings{host};port=3306", $dbh = DBI->connect("DBI:mysql:database=$db_settings{db};host=$db_settings{host};port=3306",
$db_settings{user}, $db_settings{pass}, $db_settings{user}, $db_settings{pass},
{'RaiseError' => 1, 'PrintError' => 1}) {'RaiseError' => 1, 'PrintError' => 1})
@ -89,39 +130,40 @@ for my $f (readdir $dh)
my $type = @$row[0]; my $type = @$row[0];
my $sol = @$row[1]; my $sol = @$row[1];
my $filh; my $tmp_solution;
my $tmp_solution = $solution;
if ($type eq "md5") { if ($type eq "md5") {
$tmp_solution = md5_hex($solution); $filh = md5($f);
} }
elsif ($type eq "sha1") { elsif ($type eq "sha1") {
$tmp_solution = sha1_hex($solution); $filh = sha1($f);
} }
elsif ($type eq "sha224") { elsif ($type eq "sha224") {
$tmp_solution = sha224_hex($solution); $filh = sha224($f);
} }
elsif ($type eq "sha256") { elsif ($type eq "sha256") {
$tmp_solution = sha256_hex($solution); $filh = sha256($f);
} }
elsif ($type eq "sha384") { elsif ($type eq "sha384") {
$tmp_solution = sha384_hex($solution); $filh = sha384($f);
} }
elsif ($type eq "sha512") { elsif ($type eq "sha512") {
$tmp_solution = sha512_hex($solution); $filh = sha512($f);
} }
elsif ($type eq "whirlpool") { elsif ($type eq "whirlpool") {
my $hash = Digest->new( 'Whirlpool' ); my $hash = Digest->new( 'Whirlpool' );
$hash->add( $solution ); $hash->add( $f );
$tmp_solution = $hash->hexdigest; $filh = $hash->digest;
} }
elsif ($type ne "raw") { else {
warn "$type not implemented"; warn "$type not implemented";
} }
say STDERR "check: $sol vs $tmp_solution"; $tmp_solution = my_crypt($sol, $filh) if ($filh);
if ($sol ne $tmp_solution) say STDERR "check $type: $solution{$type} vs $tmp_solution";
if ($solution{$type} ne $tmp_solution)
{ {
$good = 0; $good = 0;
last; last;

View File

@ -12,10 +12,12 @@ fi
touch ./logs/checks.log touch ./logs/checks.log
tail -f ./logs/checks.log & tail -f ./logs/checks.log &
KP1=$!
TMPF=`mktemp` TMPF=`mktemp`
tail -f "$TMPF" | ./gen_site.pl -d -s /tmp/test.sock -o ./out & tail -f "$TMPF" | ./gen_site.pl -d -s /tmp/test.sock -o ./out &
KP2=$!
while ! [ -f /tmp/stop ]; while ! [ -f /tmp/stop ];
do do
@ -23,6 +25,7 @@ do
if [ `ls submission | wc -l` -gt 1 ] if [ `ls submission | wc -l` -gt 1 ]
then then
./clear_cache.sh top
./check.pl 2>> ./logs/checks.log >> "$TMPF" ./check.pl 2>> ./logs/checks.log >> "$TMPF"
else else
@ -30,4 +33,6 @@ do
fi fi
done done
kill -9 $KP1 $KP2
rm -rf "$TMPF" rm -rf "$TMPF"

View File

@ -45,15 +45,29 @@ server {
set $team 0; set $team 0;
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=bombal_s/") { set $team 161; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Amin_Martin/") { set $team 343; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_1/") { set $team 166; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Bernard_Angoustures/") { set $team 344; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_2/") { set $team 167; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Cacace_Diallo/") { set $team 345; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_3/") { set $team 168; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Delaporte_Notebaert/") { set $team 346; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_4/") { set $team 169; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Dibe/") { set $team 347; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_5/") { set $team 170; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Dubief_Roccia/") { set $team 348; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_6/") { set $team 171; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Ezzahoui/") { set $team 349; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_7/") { set $team 172; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Fall/") { set $team 350; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Groupe_8/") { set $team 173; } if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Guerin_Chapiron/") { set $team 351; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Hugot_Hincelin/") { set $team 352; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Jawor_Giraud/") { set $team 353; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Konan/") { set $team 354; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Le_Mignan_Yadaba/") { set $team 355; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Michel-villaz_Gzenayi/") { set $team 356; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Muller_Perrin/") { set $team 357; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Pourcelot/") { set $team 358; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Quint_Kaczmarek/") { set $team 359; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Ruff_Czarny/") { set $team 360; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Sinet_Girault/") { set $team 361; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Therrode/") { set $team 362; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Sabono_Calmeji/") { set $team 363; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=Renaud_Vandemeulebroucke/") { set $team 364; }
if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=De_Priest_Tjonck/") { set $team 365; }
if ($team) { if ($team) {
root /var/www/fic2014-server/teams/$team$1; root /var/www/fic2014-server/teams/$team$1;
@ -105,7 +119,7 @@ server {
{ {
root /var/www/fic2014-server/; root /var/www/fic2014-server/;
limit_rate 1k; limit_rate 4k;
include /etc/nginx/fastcgi.conf; include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_pass unix:/var/run/php-fpm.sock;

3
nginx_gen_team.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl http://localhost/admin/teams/export 2> /dev/null | grep "<name id" | sed -E 's@^.*id="([0-9]+)".*>(.*)<.*$@ if ($ssl_client_s_dn ~ "/C=FR/ST=France/O=Epita/OU=SRS/CN=\2/") { set $team \1; }@'

View File

@ -2,7 +2,7 @@
<teams> <teams>
{foreach from=$teams item=t} {foreach from=$teams item=t}
<team> <team>
<name>{$t->team_name}</name> <name id="{$t->id}">{$t->team_name}</name>
{if $t->slogan}<slogan>{$t->slogan}</slogan>{/if} {if $t->slogan}<slogan>{$t->slogan}</slogan>{/if}
{if $t->get_members()} {if $t->get_members()}
{foreach from=$t->get_members() item=m} {foreach from=$t->get_members() item=m}

View File

@ -20,7 +20,22 @@ else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["th
$algos = array("md5", "sha1", "sha256", "sha384", "sha512", "whirlpool"); $algos = array("md5", "sha1", "sha256", "sha384", "sha512", "whirlpool");
$content = ""; $content = "";
foreach($algos as $algo) foreach($algos as $algo)
$content .= mcrypt_encrypt(MCRYPT_SERPENT_256, hash($algo, $_POST["solution"]), hash($algo, $filename), MCRYPT_MODE_ECB)."\n"; {
$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); file_put_contents($file, $content, LOCK_EX);

View File

@ -19,7 +19,7 @@ rsync -e ssh -av $OPTS out/errors phobos:~/
rsync -e ssh -av $OPTS out/htdocs phobos:~/ rsync -e ssh -av $OPTS out/htdocs phobos:~/
rsync -e ssh -av $OPTS out/teams phobos:~/ rsync -e ssh -av $OPTS out/teams phobos:~/
rsync -e ssh -avL $OPTS files phobos:~/ rsync -e ssh -avL $OPTS files phobos:~/
rsync -e ssh -av $OPTS nginx.conf submission.php misc/server.* misc/pki/cacert.crt misc/pki/crl.pem phobos:~/ rsync -e ssh -av $OPTS nginx.conf submission.php misc/server.crt misc/server.key misc/pki/cacert.crt misc/pki/crl.pem phobos:~/
rsync -e ssh -av phobos:~/submission/ submission/ rsync -e ssh -av phobos:~/submission/ submission/
ssh phobos "rm -fv ~/submission/*" ssh phobos "rm -fv ~/submission/*"