Skip to content

Latest commit

 

History

History
executable file
·
136 lines (113 loc) · 4.35 KB

IcculusFinger_webinterface.pl

File metadata and controls

executable file
·
136 lines (113 loc) · 4.35 KB
 
Jan 11, 2002
Jan 11, 2002
1
#!/usr/bin/perl -w
Jan 29, 2002
Jan 29, 2002
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#-----------------------------------------------------------------------------
#
# Copyright (C) 2000 Ryan C. Gordon (icculus@icculus.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-----------------------------------------------------------------------------
Jan 11, 2002
Jan 11, 2002
21
22
23
24
25
use strict;
use warnings;
use IO::Socket;
Jan 29, 2002
Jan 29, 2002
26
27
28
29
#-----------------------------------------------------------------------------#
# CONFIGURATION VARIABLES: Change to suit your needs... #
#-----------------------------------------------------------------------------#
Jan 11, 2002
Jan 11, 2002
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Define which host(s) the finger request goes to. If $host == false,
# then users may finger any system on the Internet by specifying a hostname:
# user=dimwit@doofus.com, for example. Not setting $host at all like that
# could leave a mild exploit available.
#my $host = undef; # Makes this script work as a web interface to finger.
#my $host = "icculus.org"; # limit queries to users @icculus.org
my $host = $ENV{SERVER_NAME}; # This is good for VirtualHost setups.
#-----------------------------------------------------------------------------#
# The rest is probably okay without you laying yer dirty mits on it. #
#-----------------------------------------------------------------------------#
# Mainline.
$host =~ tr/A-Z/a-z/ if defined $host;
my $user = '';
Oct 7, 2007
Oct 7, 2007
48
my $rss = 0;
Jan 11, 2002
Jan 11, 2002
49
50
51
52
53
my $finger_query = 'web=1';
my $web_query = $ENV{QUERY_STRING};
$web_query = '' if (not defined $web_query);
chomp($web_query);
Oct 7, 2007
Oct 7, 2007
54
55
if ($web_query =~ s/(\?|&|\A)user=(.*?)(\Z|&)//) {
$user = $2;
Jan 11, 2002
Jan 11, 2002
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$user =~ tr/A-Z/a-z/;
}
if ((not defined $ENV{GATEWAY_INTERFACE}) or ($ENV{GATEWAY_INTERFACE} eq '')) {
print("\n\nThis is a cgi-bin script. Please treat it accordingly.\n\n");
exit 0;
}
if ((defined $ENV{HTTP_USER_AGENT}) and ($ENV{HTTP_USER_AGENT} ne "")) {
if (not $web_query =~ /(\A|\?|&)browser=/) {
my $browser = $ENV{HTTP_USER_AGENT};
1 while ($browser =~ s/&//);
$finger_query .= "&browser=$browser";
}
}
if (not $web_query =~ /(\A|\?|&)html=/) {
$finger_query .= "&html=1";
}
Oct 7, 2007
Oct 7, 2007
76
77
78
79
if ($web_query =~ /(\A|\?|&)rss=/) {
$rss = 1;
}
Jan 11, 2002
Jan 11, 2002
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
my $requested_host = undef;
if ($user =~ s/\@(.*)//) {
$requested_host = $1;
}
$web_query .= '&' if ($web_query ne '');
$finger_query = "$user?$web_query$finger_query";
my $errormsg = undef;
if ($user eq '') {
$errormsg = "No user specified.";
} elsif ((not defined $host) and (not defined $requested_host)) {
$errormsg = "No host specified.";
} elsif ((defined $host) and (defined $requested_host)) {
if ($host ne $requested_host) {
$errormsg = "You aren't permitted to specify a hostname, just a user.";
}
} else {
$host = $requested_host if not defined $host;
my $remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $host,
PeerPort => "finger"
);
if (not $remote) {
$errormsg = "cannot connect to finger daemon on $host";
} else {
$remote->autoflush(1);
print $remote "$finger_query\015\012";
Oct 7, 2007
Oct 7, 2007
110
111
if ($rss) {
Nov 4, 2007
Nov 4, 2007
112
print("Content-type: application/rss+xml; charset=UTF-8\n\n");
Oct 7, 2007
Oct 7, 2007
113
114
115
116
} else {
print("Content-type: text/html; charset=UTF-8\n\n");
}
Jan 11, 2002
Jan 11, 2002
117
118
119
120
121
122
123
124
while (<$remote>) {
print $_;
}
close($remote);
}
}
if (defined $errormsg) {
Oct 7, 2007
Oct 7, 2007
125
print("Content-type: text/html; charset=UTF-8\n\n");
Jan 11, 2002
Jan 11, 2002
126
127
128
129
130
131
132
133
134
135
print("<html><head><title>Problem</title></head><body>\n");
print("<center><h1>$errormsg</h1></center>\n");
print("</body></html>\n");
print("\n");
exit 0;
}
exit 0;
# end of IcculusFinger_webinterface.pl ...