Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Finger Me!

by FouRPlaY (Monk)
on Oct 25, 2000 at 01:57 UTC ( [id://38236]=perlquestion: print w/replies, xml ) Need Help??

FouRPlaY has asked for the wisdom of the Perl Monks concerning the following question:

I'm hesitant to make this post, I seem to lack the ability to distinguish between "good" and "bad" posts. I've made one really good one, and one totally moronic one. But I digress....

I've been trying to get the information via the unix finger command outputed to HTML. So far I've only had success by using system () to create an empty file, then using system again to send the output of the finger command to that file. Then, I read in the file, get rid of any spaces greater than 2 (since HTML ignores it anyway) and print it out on seperate lines. Here's what I've got:
use CGI; $cgi = new CGI; $cgi->use_named_parameters; $name = $ENV{'QUERY_STRING'}; $thefile = "/u/sdrupert/public_html/cgi-bin/tempout.finger"; $create = "/usr/bin/touch " . $thefile; $run = "/.software/local/.admin/bins/bin/finger " . $name . "\@math >> + " . $thefile; $gone = "rm " . $thefile; system ($create); system ($run); open (INFO, "<$thefile"); @ffile = <INFO>; close (INFO); system ($gone); print $cgi->header; print $cgi->start_html(-title=>'Finger ' . $name . '@math',-bgcolor=>' +white'); foreach $line (@ffile) { $line =~ s/[ ]{2,}/!/g; @new = split (/!/, $line); foreach $newline (@new) { print $newline . "<br>"; } } print $cgi->end_html;

This works, but a) doesn't look great; and b) I'm sure there's a better way out there.

So, if you tried this before, or have any suggestions, or you even think this post makes up for the last one, please leave a comment/response/suggestion/flame. Thanks.

Replies are listed 'Best First'.
Re: Finger Me!
by btrott (Parson) on Oct 25, 2000 at 02:03 UTC
    You could pipe from finger, then print the output. I don't know about security issues re: finger, but you should definitely untaint the stuff you're passing into the system. You should do a safe pipe open as described in perlipc.

    Or perhaps there's a module for finger... aha: Net::Finger. From the docs:

    $response = finger('corbeau@execpc.com'); unless ($response) { warn "Finger problem: $Net::Finger::error"; }
    Probably best off using that then.
Re: Finger Me!
by merlyn (Sage) on Oct 25, 2000 at 02:11 UTC
    Untested...
    use CGI qw(:all); $ENV{PATH} = ""; if (my ($name) = query_string =~ /(\w+)/) { print header, h1("Results of finger"), pre(escapeHTML(`/usr/ucb/fing +er $name`)); } else { print header(-status => '403 Forbidden'); }
    You might also want to consider Net::Finger.

    -- Randal L. Schwartz, Perl hacker


    updated.... (tested {grin}):
    #!/usr/bin/perl -Tw use CGI::Carp qw(fatalsToBrowser); use CGI qw(:all); $ENV{PATH} = ""; if (my ($name) = param('keywords') =~ /(\w+)/) { print header, h1("Results of finger"), pre(escapeHTML(scalar `/usr/bin/finger $name`)); } else { print header(-status => '403 Forbidden'); }
Re: Finger Me!
by Fastolfe (Vicar) on Oct 25, 2000 at 02:25 UTC
    As mentioned in the other thread on this topic, HTML::FromText would do a nice job of making output like this look nice. Since fingers are typically plain text, and many people publish things in their .plan/whatever with the assumption that it will be viewed as plain-text, some HTML-ized finger texts are going to look as bad as a SoPW post sans <code> tags. HTML::FromText will do a fair job, but still not the best...
Re: Finger Me!
by Malach (Scribe) on Oct 25, 2000 at 02:05 UTC
    System calls always strike me as ugly....... Have you considered using Net::Finger?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://38236]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found