This repository was archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathExecuteServerCommand.pl
executable file
·111 lines (93 loc) · 2.29 KB
/
ExecuteServerCommand.pl
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/local/bin/perl
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
use strict;
use FileHandle;
use CGI;
use Socket;
BEGIN {
my @path_elems = split("/", $0);
pop @path_elems;
push @INC, join("/", @path_elems);
}
use Blocks;
my $query = new CGI;
my $what = $query->param("what");
my $host = $query->param("host");
my $port = $query->param("port");
my $cmd = $query->param("cmd");
if ($what eq "exec") {
DoExec();
} else {
print "Content-type: text/html\n\n";
DoForm();
}
######################################################################
sub CatchPipe {
print STDERR "Caught PIPE signal\n";
}
$SIG{PIPE} = \&CatchPipe;
######################################################################
sub DoForm {
print qq!
<head>
</head>
<form action=\"ExecuteServerCommand.pl\" method=POST>
<input type=hidden name=what value=exec>
host: <input type=text size=30 name=host><br>
port: <input type=text size=6 name=port><br>
command: <input type=text size=60 name=cmd><br>
<input type=submit>
</form>
<body>
</body>
!;
}
######################################################################
sub DoExec {
my $proto = getprotobyname('tcp');
my $request = $cmd;
my $fh = new FileHandle;
if ($host eq "") {
print "Content-type: text/html\n\n";
print "host missing\n";
DoForm();
exit;
}
if ($port eq "") {
print "Content-type: text/html\n\n";
print "port missing\n";
DoForm();
exit;
}
if ($host !~ /\./) {
$host .= ".nci.nih.gov";
}
my $iaddr = gethostbyname($host);
my $sin = sockaddr_in($port, $iaddr);
if( !socket($fh, PF_INET, SOCK_STREAM, $proto) ) {
print "Content-type: text/html\n\n";
print "Cannot open socket to $host:$port\n";
DoForm();
exit;
}
if( !connect($fh, $sin) ) {
print "Content-type: text/html\n\n";
print "Cannot connect to $host:$port, $!\n";
DoForm();
exit;
}
if( !SendBlocks($fh, \$request) ) {
print "Content-type: text/html\n\n";
print "SendBlocks failed for $host:$port\n";
DoForm();
exit;
}
my $response;
RecvBlocks($fh, \$response);
close($fh);
print "Content-type: text/plain\n\n";
print $response;
}