#!/usr/bin/perl # # Copyright Zaher Salman 2023-. # zaher.salman@psi.ch ######## Relevant subdirectories and urls ######## # May need modification on different servers $trimbin="timeout 300 /usr/local/bin/trimspNL"; $workroot="/tmp"; # Nothing need to be changed from here on ####################################################################### ######## Main body of code ######## use CGI; my $in = new CGI; # Collect parameters and their values from CGI my ($name,$value); $content = ""; my $filename = ""; my $rngType = "pcg32"; my $lcount = 0; foreach $name ($in->param) { $value=$in->param($name); if ($name eq "fn") { # This is the file name $filename = $value; @prefix = split(/\//,$filename); $randName = $prefix[2]; $FILENAME = $prefix[3]; } elsif ($name eq "rngType") { # RNG backend passed as the optional second trimspNL argument. if ($value =~ /^(ranlux|pcg32|xoshiro|xoshiro256)$/) { $rngType = $value; } } elsif ( index($name, "line") == 0) { # This is a line start counting #if ($lcount <=14) { # Limit number of lines (15) to avoid abuse $content = $content.$value."\n"; #} $lcount++; } } $workPath = $workroot."/".$randName; if (-d $workPath) { # Directory exists, do nothing } else { $cmd="mkdir ".$workPath; system($cmd); } $filename = $workPath."/".$FILENAME; $fname = $filename; $fname =~ s/\.inp$//; $runBase = $FILENAME; $runBase =~ s/\.inp$//; open (OUTF,q{>}, $filename); print OUTF ($content); close(OUTF); print ("Content-type: text/ascii \n\n"); if (index($filename,"_Seq_Results.dat") != -1) { # This is the final call of a scan $cmd = "cd $workPath; rm -f edist;"; $cmd = $cmd."tar -cvzf ../$randName.tgz *; cd ..; rm -rf $randName;"; } elsif (index($filename,"TrimSP.cfg") != -1) { # Save config file only $cmd = "cd $workPath;"; } else { # This is a call to simulate one step in a scan $cmd = "cd $workPath; $trimbin $runBase $rngType >> /tmp/debug;"; } system($cmd); #print "Written file $filename\n"; #print $content; print "command $cmd\n"; foreach $name ($in->param) { $value=$in->param($name); print $name,"=",$value,"\n"; } exit(0);