From bc877802cc0aa47468a6a00bf3fec3df60cbc867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Wed, 11 Dec 2013 18:10:39 +0100 Subject: [PATCH] Start check submission script --- check.pl | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 check.pl diff --git a/check.pl b/check.pl new file mode 100755 index 00000000..2c12913a --- /dev/null +++ b/check.pl @@ -0,0 +1,80 @@ +#!/usr/bin/env perl + +use v5.10.1; +use strict; +use warnings; +use DBI; + +use Data::Dumper; + +# First, read PHP configuration to extract some settings +my $profile; +my $submission_dir; + +open my $conf, "<", "onyx/config/root.xml"; +for my $p (<$conf>) +{ + if ($p =~ /<(?:option|var) name="(.*)">(.*)<\/(?:option|var)>/) + { + $profile = $2 if ($1 eq "profile"); + $submission_dir = $2 if ($1 eq "submission_dir"); + } +} +close $conf; + +die("No DB profile found") if ! $profile; +die("submission_dir is not a directory") if ! $submission_dir || ! -d $submission_dir; + +# Read db settings +my %db_settings; +open my $dbprof, "<", "onyx/db/$profile.profile.php"; +while (<$dbprof>) +{ + if (/\$___profile\[['"](.+)['"]\] = ['"](.+)['"]/) + { + $db_settings{$1} = $2; + } +} +close $dbprof; + +my $dbh; +# List all files to treat +opendir(my $dh, $submission_dir) || die "Can't opendir submission_dir: $!"; +for my $f (readdir $dh) +{ + if ($f =~ /^([0-9]+)-([0-9]+)-([0-9]+)$/) + { + my $team = $1; + my $theme = $2; + my $exercice = $3; + + open my $fh, "<", "$submission_dir/$f"; + my $solution = <$fh>; + close $fh; + + $dbh = DBI->connect("DBI:mysql:database=$db_settings{db};host=$db_settings{host};port=3306", + $db_settings{user}, $db_settings{pass}, + {'RaiseError' => 1, 'PrintError' => 1}) + or die $DBI::errstr if !$dbh; + + my $sth = query($dbh, "SELECT format, value FROM exercice_keys WHERE id_exercice = ".int($exercice)); + + while (my $row = get_row($sth)) + { + say Dumper($row); + } + } +} +closedir $dh; + +$dbh->disconnect() if $dbh; + +sub query +{ + my $sth = $_[0]->prepare($_[1]); + $sth->execute(); + + die($_[0]->errstr) if (!$sth); + + return $sth; +}