[Bio] / FigWebServices / rast_save_sim_output.cgi Repository:
ViewVC logotype

View of /FigWebServices/rast_save_sim_output.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Wed Jun 19 20:06:31 2019 UTC (5 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
New support for submitting sims to the Slurm cluster.

#
# Save the output from a sims run.
#
# Restricted to use by IP addresses inside ANL.
#

use strict;
use Data::Dumper;
use CGI;
use File::Copy;
use Net::CIDR::Set;

#
# Safety net.
#

my $allowed = Net::CIDR::Set->new("140.221.78.0/24", "140.221.84.0/24", "192.5.200.0/25");
my $proxy_allowed = Net::CIDR::Set->new("192.5.200.105", "192.5.200.63", "140.221.78.40-140.221.78.43", "192.5.200.9");

#
# We expect to be proxied
#

my $cgi = new CGI;

my $fwd_from = $ENV{HTTP_X_FORWARDED_FOR};

defined($fwd_from) or &error($cgi, 500, 'no proxy');
$proxy_allowed->contains($ENV{REMOTE_ADDR}) or &error($cgi, 500, "bad proxy $ENV{REMOTE_ADDR}");
$allowed->contains($fwd_from) or &error($cgi, 500, 'bad host');


my $key = $cgi->param('key');
my $job = $cgi->param('job');
my $task_id = $cgi->param('task');

if (($key ne 'output' && $key ne 'error') ||
    $job !~ /^\d+$/ ||
    $task_id !~ /^\d+$/)
{
    &error($cgi, 500, "bad input");
}

#
# Find the task list.
#
my $job_dir = "/vol/rast-prod/jobs/$job";
-d $job_dir or &error($cgi, 500, "");

open(TL, "<", "$job_dir/sims.job/task.list") or &error($cgi, 500, "no tasklist");

my($in, $db, $params, $out, $err);
while (<TL>)
{
    chomp;
    my @a = split(/\t/);
    if ($a[0] == $task_id)
    {
	(undef, $in, $db, $params, $out, $err) = @a;
	last;
    }
}
defined($in) or &error($cgi, 500, "");

my $file = $key eq 'output' ? $out : $err;

if (-s $file)
{
    # &error($cgi, 500, "not overwriting existing file");
}

my $fh = $cgi->upload("file");

if ($fh)
{
    copy($fh->handle(), $file);
}
else
{
    &error($cgi, 500, 'no file');
}

print $cgi->header(-status => 200);
print "ok\n";
exit;

sub error
{
    my($cgi, $stat, $msg) = @_;
    print $cgi->header(-status =>  $stat);
    print "$msg\n";
    exit;
}






MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3