add more spacing
[personal-kdebase.git] / runtime / kioslave / finger / kio_finger.pl
blob8965ea523c2c0bd244d08b2e12531ca02c7033e5
1 ##!/usr/bin/perl
3 # Copyright Andreas Schlapbach, schlpbch@iam.unibe.ch, 2001
4 # http://iamexwiwww.unibe.ch/studenten/kfinger
6 # Touch at your own risk.
9 # Highlight mail addresses or url
11 $mails = '<A HREF="mailto:';
12 $urls = '<A HREF="';
13 $urlspace = '">';
14 $urlend = '</A>';
16 # Highlight various information, configurable via the CSS file,
18 $finger = '<CODE class="finger">';
19 $domainName = '<CODE class="domainName">';
20 $ipNumber = '<CODE class="ipNumber">';
21 $os = '<CODE class="os">';
22 $username = '<CODE class="username">';
23 $directory = '<CODE class="directory">';
24 $shell = '<CODE class="shell">';
25 $notLoggedIn = '<CODE class="Login">';
26 $loggedIn = '<CODE class="noLogin">';
27 $newMail = '<CODE class="newMail">';
28 $plan = '<CODE class="plan">';
29 $noNewMail = '<CODE class="noNewMail">';
30 $noPlan = '<CODE class="noPlan">';
31 $close = '</CODE>';
33 # Those names get skipped, so if there's a user with such a name, bad luck.
35 @keywords=('Welcome','Login','finger','No');
36 $keywordlist = join '|', @keywords;
38 $FINGERCMD = "$ARGV[0]"; # The complete path to the finger cmd
39 $CSSFILE = "$ARGV[1]"; # The complete path to the CSS file
40 $REFRESHRATE = "$ARGV[2]"; # The intervals in seconds until the page gets updated
41 $HOST = "$ARGV[3]"; # host name
42 $USER = "$ARGV[4]"; # user name
44 $HOST =~ s/&/&amp;/g;
45 $HOST =~ s/</&lt;/g;
46 $HOST =~ s/>/&gt;/g;
48 $USER =~ s/&/&amp;/g;
49 $USER =~ s/</&lt;/g;
50 $USER =~ s/>/&gt;/g;
52 # HTML Header
54 print <<HTMLHeader;
55 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
56 <HTML>
57 <HEAD>
58 <meta http-equiv="refresh" content="$REFRESHRATE">
59 <TITLE>finger $USER\@$HOST</TITLE>
60 <LINK type="text/css" rel="stylesheet" href="file:$CSSFILE">
61 </HEAD>
62 <BODY>
63 <TABLE class="mainTable" cellspacing="0">
64 <TR>
65 <TH colspan="1">
66 <H1>finger $USER\@$HOST</H1>
67 </TH>
68 </TR>
69 <TR>
70 <TH>
71 <TABLE class="courierText" cellpadding="0" cellspacing="2">
72 HTMLHeader
74 # Run finger command and save it into a buffer
76 open(F, "-|") || exec $FINGERCMD, "$USER\@$HOST";
77 @lines = <F>;
78 close(F);
80 # Do highlighting using perl regular expressions on every line received.
81 # Order is important here.
83 foreach $output (@lines)
85 $output =~ s/((\w)+\@((\w)+(.))*(\w)+)/$mails$1$urlspace$1$urlend/gi; # Highlight email address
86 $output =~ s/((http|ftp)(:\/\/)(\S)+)/$urls$1$urlspace$1$urlend/gi; # Highlight urls
87 $output =~ s/((\d)+\.(\d)+\.(\d)+\.(\d)+)/$ipNumber$1$close/gi; # Highlight IP number
88 $output =~ s/((\w)+\.(\w)+\.(\w|-)+\s)/$domainName$1$close/gi; # Highlight domain name (\s is important)
89 $output =~ s/(finger:)/$finger$1$close/gim; # Highlight finger
90 $output =~ s/(Linux)/$os$1$close/gim; # Highlight Linux
91 if ($USER) # is $USER nil ?
93 $output =~ s/^Login:\s*(\w*)/Login: $mails$1\@$HOST$urlspace$1$urlend/gi;
94 $output =~ s/^Login Name:\s*(\w*)/Login Name:$mails$1\@$HOST$urlspace$1$urlend/gi;
95 $output =~ s/Name:(((\s*)(\w+))+\n)/Name:$username$1$close\n/gi; # Linux
96 $output =~ s/In real life:(((\s*)(\w+))+\n)/In real life:$username$1$close\n/gi; # Solaris
97 $output =~ s/^Directory:((\s*)(\/(\w)+)+)/Directory:$directory$1$close/gi; # Highlight Directory
98 $output =~ s/Shell:((\s*)(\/(\w)+)+)/Shell:$shell$1$close/gi; # Highlight Shell
99 $output =~ s/(not presently logged)/$notLoggedIn$1$close/gi;
100 $output =~ s/con (\w*)/con $loggedIn$1$close/gi;
101 $output =~ s/^(New mail)/$newMail$1$close/gi;
102 $output =~ s/^(No mail.)/$noNewMail$1$close/gim;
103 $output =~ s/^(Plan:)/$plan$1$close/gi;
104 $output =~ s/^(No plan.)/$noPlan$1$close/gim;
106 else
108 $output =~ s/^(\w+)/$mails$1\@$HOST$urlspace$1$urlend/m unless ($output =~ m/$keywordlist/m);
110 # line consists of white space only?
111 if ($output =~ m/\S/gi)
113 print " <TR><TD><PRE>$output</PRE></TD></TR>\n";
115 else
117 print " <TR><TD><PRE> </PRE></TD></TR>\n";
121 print " </TABLE>\n";
122 print " </TH>\n";
124 # Finger-Talk options
126 if ($USER) # is $USER nil ?
128 print <<UserQuery;
129 </TR>
130 <TR>
131 <TH class="commandText" colspan="2">
132 <A HREF='finger://$USER\@$HOST'>finger</A>
133 </TH>
134 </TR>
135 UserQuery
137 else
139 print <<HostQueryHead;
140 <TH>
141 <TABLE class="courierText" cellpadding="0" cellspacing="2">
142 HostQueryHead
144 @lines = split /^/m, $buffer;
145 foreach $output2 (@lines)
147 if ($output2 =~ m/^(\w+)/gi and not ($output2 =~ m/$keywordlist/m))
149 $USER = $&;
150 print " <TR><TD><PRE><A HREF='finger://$USER\@$HOST'>finger</A>\n</PRE></TD></TR>\n";
151 # - <A HREF='talk://$USER\@$HOST'>talk</A>\n</PRE></TD></TR>\n";
153 else
155 print " <TR><TD><PRE> </PRE></TD></TR>\n";
159 print <<HostQueryTail;
160 </TABLE>
161 </TH>
162 </TR>
163 HostQueryTail
166 # HTMLTail
168 print <<HTMLTail;
169 <TR>
170 <TH class="niceText">refresh rate: $REFRESHRATE seconds.</TH>
171 </TR>
172 </TABLE>
173 </BODY>
174 </HTML>
175 HTMLTail