Commit 43955cbf authored by Lev Walkin's avatar Lev Walkin

better results fetching

parent f65f108f
...@@ -16,6 +16,7 @@ $HashProgramPath = 'md5'; # Program to hash the input ...@@ -16,6 +16,7 @@ $HashProgramPath = 'md5'; # Program to hash the input
$DM = 0750; # Directory mode for all mkdirs. $DM = 0750; # Directory mode for all mkdirs.
$MaxHistoryItems = 5; # Number of items in History $MaxHistoryItems = 5; # Number of items in History
$DynamicHistory = 'yes'; # Full/Short history $DynamicHistory = 'yes'; # Full/Short history
$safeFilename = '^[a-z0-9_-]+[.a-z0-9_-]*$'; # Safe filename
$warn = '<CENTER><FONT SIZE=+1><B>'; $warn = '<CENTER><FONT SIZE=+1><B>';
$unwarn = '</B></FONT></CENTER>'; $unwarn = '</B></FONT></CENTER>';
...@@ -116,6 +117,26 @@ sub prepareChrootEnvironment() { ...@@ -116,6 +117,26 @@ sub prepareChrootEnvironment() {
return 1; return 1;
} }
sub makeArchive($$) {
local $TMPDIR = shift;
local $sandbox = shift;
local $archName = $sandbox . '/+Archive.tgz';
if(! -f $archName) {
system("cd $sandbox && "
. "for i in ./*.[ch]; do if [ -L \$i ]; then"
. " cp $TMPDIR/skeletons/\$i \$i.-;"
. " mv \$i.- \$i;"
. " fi done && tar --dereference --ignore-failed-read --owner nobody --group nobody -zcf +tmp." . $$ . " *.[ch] Makefile* +Compiler.Log *.asn *.asn1"
. " && rm -f ./*.[ch] ./Makefile*"
. " && mv ./+tmp." . $$ . " $archName"
. " || rm -f ./+tmp." . $$);
undef unless -f $archName;
}
$archName;
}
my $EnvironmentSetOK = prepareChrootEnvironment(); my $EnvironmentSetOK = prepareChrootEnvironment();
# #
...@@ -175,32 +196,31 @@ unless($session) { ...@@ -175,32 +196,31 @@ unless($session) {
local $trans = param('trans'); local $trans = param('trans');
local $fetch = param('fetch'); local $fetch = param('fetch');
local $show = param('show'); local $show = param('show');
unless($t =~ /^[0-9TZ:+-]{14,}$/ && $trans =~ /$safeFilename/i) {
unless($t =~ /^[0-9TZ:+-]{14,}$/ && $trans =~ /^[.a-z0-9_-]+$/i) {
$fetch = ''; $fetch = '';
$show = ''; $show = '';
} }
if($fetch =~ /^[.a-z0-9_-]+$/i || $show =~ /^(log|tgz)$/) { if($fetch =~ /$safeFilename/i || $show =~ /^(log|tgz)$/) {
local $fname = $sessionDir . '/' . $t . '--' . $trans; local $sandbox = $sessionDir . '/' . $t . '--' . $trans;
if($show eq 'tgz') { if($show eq 'tgz') {
local $tarball = makeArchive($TMPDIR, $sandbox);
defined $tarball
or bark("Cannot create archive [$sandbox]");
printf("Content-Type: application/x-tar\n"); printf("Content-Type: application/x-tar\n");
printf("Content-Encoding: gzip\n\n"); printf("Content-Encoding: gzip\n\n");
exec("cd $fname && " exec("cat $tarball");
. "for i in *.[ch]; do if [ -L \$i ]; then"
. " cp $TMPDIR/skeletons/\$i \$i.-;"
. " mv \$i.- \$i;"
. " fi done && tar --dereference --owner nobody --group nobody -zcvf - ./*.[ch] ./Makefile*");
exit(0); exit(0);
} }
if($show eq 'log') { if($show eq 'log') {
$fname .= '/+Log'; $sandbox .= '/+Compiler.Log';
} else { } else {
$fname .= '/' . $fetch; $sandbox .= '/' . $fetch;
} }
open(I, "< " . $fname) open(I, "< " . $sandbox)
or bark("Invalid or outdated request: [$fname] [$show] $!"); or bark("Invalid or outdated request: [$sandbox] [$show] $!");
printf "Content-Type: text/plain\n\n"; printf "Content-Type: text/plain\n\n";
while(<I>) { while(<I>) {
print; print;
...@@ -280,13 +300,14 @@ if($#gotSafeNames >= 0) { ...@@ -280,13 +300,14 @@ if($#gotSafeNames >= 0) {
$options .= " -EF" if(param("optEF") eq "on"); $options .= " -EF" if(param("optEF") eq "on");
$options .= " -fnative-types" if(param("optNT") eq "on"); $options .= " -fnative-types" if(param("optNT") eq "on");
my $CompileASN = "$TMPDIR/bin/asn1c -v | sed -e 's/^/-- /'" my $CompileASN = "$TMPDIR/bin/asn1c -v | sed -e 's/^/-- /'"
. " > $sandbox/+Log 2>&1" . " > $sandbox/+Compiler.Log 2>&1"
. "; $SUIDHelper $TMPDIR $inChDir $options @gotSafeNames " . "; $SUIDHelper $TMPDIR $inChDir $options @gotSafeNames "
. " >> $sandbox/+Log 2>&1" . " >> $sandbox/+Compiler.Log 2>&1"
. "; echo \$? > $sandbox/+ExitCode"; . "; echo \$? > $sandbox/+ExitCode";
system($CompileASN); system($CompileASN);
bark("Failed to initiate compilation process: $!") bark("Failed to initiate compilation process: $!")
if(!-r $sandbox . '/+ExitCode'); if(!-r $sandbox . '/+ExitCode');
makeArchive($TMPDIR, $sandbox);
} }
#print join("<BR>\n", `env`); #print join("<BR>\n", `env`);
...@@ -378,21 +399,25 @@ foreach my $trans (sort { $b cmp $a } @transactions) { ...@@ -378,21 +399,25 @@ foreach my $trans (sort { $b cmp $a } @transactions) {
. "Error during compilation: $ec</FONT><BR>\n"; . "Error during compilation: $ec</FONT><BR>\n";
} }
$allowFetchResults = $ec eq "0"
&& (-f $sessionDir . '/' . $trans . '/+Archive.tgz'
|| -f $sessionDir . '/' . $trans . '/Makefile.am.sample');
$results .= "<NOBR>" $results .= "<NOBR>"
. (($ec eq "0") ? '1. ' : '') . ($allowFetchResults ? '1. ' : '')
. "<A HREF=\"$myName?time=" . "<A HREF=\"$myName/$f-$tNum.Log?time="
. escapeHTML($origTime) . escapeHTML($origTime)
. "&trans=$f" . "&trans=$f"
. "&show=log\">" . "&show=log\">"
. "Show compiler log</A></NOBR>"; . "Show compiler log</A></NOBR>";
if($ec eq "0") { $results .= "<BR>\n<NOBR>"
$results .= "<BR>\n<NOBR>" . "2. <A HREF=\"$myName/$f-$tNum.tgz?time="
. "2. <A HREF=\"$myName?time="
. escapeHTML($origTime) . escapeHTML($origTime)
. "&trans=$f" . "&trans=$f"
. "&show=tgz\">" . "&show=tgz\">"
. "Fetch results (.tgz)</A></NOBR>"; . "Fetch results (.tgz)</A></NOBR>"
} else { if $allowFetchResults;
if($ec ne "0") {
$results .= '<P>' $results .= '<P>'
. '<FONT SIZE=-1><A HREF="mailto:asn1c@lionet.info?Subject=asn1c compiler help: ' . '<FONT SIZE=-1><A HREF="mailto:asn1c@lionet.info?Subject=asn1c compiler help: '
. "transaction $tNum (" . "transaction $tNum ("
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment