aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/smtk2ssrf.pl
blob: ae10b6ee0d8a3acdbf4b85bec923c6563953f219 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl

use CGI;

$CGI::POST_MAX = 1024 * 1024 * 10;

# Change this to the correct path to binary.
my $smtk2ssrf = "../build/smtk2ssrf";
my $logfile = '/tmp/smtk2ssrf.log';

my $q = CGI->new;

if ($q->upload("uploaded_file")) {
        my $original_filename = $q->param("uploaded_file");
        my $converted = `$smtk2ssrf $tmp_filename -`;
        my $tmp_filename = $q->tmpFileName($original_filename);
        my $new_filename = $original_filename;
        $new_filename =~ s/.*[\/\\]//;
        $new_filename =~ s/\..*$/.ssrf/;

	if (length($converted) > 5) {

	        print "Content-Disposition: attachment; filename=\"$new_filename\"\n";
		print "Content-type: subsurface/xml\n\n";
		print $converted;
	} else {
		print "Content-type: text/html\n\n";
		print "<H1>Conversion failed</H1>";
		print 'Please contact <a href=mailto:helling@atdotde.de>Robert Helling (robert@thetheoreticaldiver.org)</a> if the problem persits.';
	}
} else {
        print "Content-type: text/html\n\n";

# Here we could print some header stuff to fit better in the subsurface webspace context. Do do so uncomment
# open (IN, "filename_header.html);
# while (<IN>) {
#         print;
# }
# close(IN);

        print $q->start_multipart_form();

        print $q->h1("Convert Smartrack files to Subsurface");

        print $q->filefield( -name => "uploaded_file",
                             -size => 50,
                             -maxlength => 200);
        print $q->submit();
        print $q->end_form();

# Here we could print some footer stuff as above

}