-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanserver.pl
executable file
·59 lines (54 loc) · 1.25 KB
/
manserver.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
#!/usr/local/bin/perl
#
# rman daemon by [email protected]
#
use Socket;
# touch myself each hour for not removed from /var/tmp (-:
$SIG{ALRM} = sub{
print "ALARMED\n";
alarm 3600;
system("touch $0");
};
alarm 3600;
$SIG{CHLD}={wait;}
#----------------MAIN-------------------
if($0 eq __FILE__){
$port = ($ARGV[0] || 19535);
socket(SH,PF_INET,SOCK_STREAM,0) || die "cant open socket:$!";
setsockopt(SH,SOL_SOCKET,SO_REUSEADDR,1) || die "setsockopt:$!";
bind(SH,sockaddr_in($port,INADDR_ANY)) || die "cant bind to me:$!";
listen(SH,5) || die "cant listen socket:$!";
while(1){
accept(SHA,SH) || die "can't accept socket:$!";
($port,$addr) = unpack_sockaddr_in(getpeername(SHA));
print "host=",inet_ntoa($addr),",port=$port\n";
if($pid=fork()){
close(SHA);
}elsif(defined $pid){
while(<SHA>){
tr/\r\n//d;
print "recieved1[$_]\n";
if(/^$/){last;}
if(/^([^=]+)=(.*)/){
$ENV{$1} = $2;
}
}
@args = ("/usr/bin/man");
while(<SHA>){
tr/\r\n//d;
print "recieved2[$_]\n";
if(/^$/){last;}
push(@args,$_);
}
print "args=(",join(',',@args),")\n";
open(STDOUT,">&SHA");
open(STDIN,"</dev/null");
exec(@args);
close(SHA);
close(STDOUT);
exit(1);
}
}
close(SH);
}
1;