Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

CGI to Telnet Interprocess Fun Stuff

by Pedro Picasso (Sexton)
on Aug 08, 2001 at 23:32 UTC ( #103188=perlquestion: print w/replies, xml ) Need Help??

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

I'm doing a project for the big boss here at work. Basically he wants to access a telnettable machine somewhere and pass it commands from a cute looking web form.

i.e. I click the "Turn 'A' On" checkbox on a form and submit, and the CGI perl script telnets to the remote machine, passes the "turnon -function A" command, then gathers the output from that command to display on the returned HTML.

Thanks to the wonders of CGI and Net::Telnet, this works wonderfully, but slowly. Initiating a telnet session during every page load sucks even if I'm the only one using it.

What I'd like to do is have a Perl telnet program running a constant session and message it with I/O from my CGI script when the need arises.

Most of the interprocess tips that I read have to do with open(), exec(), and system(), but I need a way to have a constant session running instead of generating one all the time, and these don't help.

I've got one server running Apache mod_perl under NT, and another running it under RedHat, so I can do Unix/Win32 specific things if need be. I'd like to avoid writing my own Apache module unless it's absolutely necessary.

Help me Obi-Monks Kenobi. You're my only hope!

-the Pedro Picasso
(sourceCode == freeSpeech)

Replies are listed 'Best First'.
Re: CGI to Telnet Interprocess Fun Stuff
by Everlasting God (Beadle) on Aug 09, 2001 at 00:04 UTC
    Well, if security isn't much of a concern (and it looks like it isn't if a webpage is gonna be performing telnet commands...) I would suggest a daemon process running the telnet session and listening on some predefined socket, preferably unix domain. Then, whenever it gets some data on that socket it can do it's thing in the telnet session, preferably with a little data laundering.
    Might also be a good idea for the daemon to time out after some long time, and have the client cgi check to see if it's listening on the socket, and if not start the daemon again. That way, there won't always be a telnet session open.

    'The fickle fascination of and Everlasting God' - Billy Corgan, The Smashing Pumpkins
(jeffa) Re: CGI to Telnet Interprocess Fun Stuff
by jeffa (Bishop) on Aug 09, 2001 at 00:44 UTC
    EEK! that's a big security hole you are digging. But i won't bog you down with why i think this is a bad idea.

    Instead I will point you to SOAP::Lite. You could write a server that keeps a persistant connection (via SOAP::Transport::HTTP::Daemon) to a Net::Telnet session. The client would then call the server with a command and print the results back to the browser:

    diagram: ------------- ------------- ------------ --------- |Net::Telnet|<-->|SOAP Daemon|<-->|web script|<-->|browser| ------------- ------------- ------------ ---------
    This is just a suggestion - i have not actually written anything like this myself . . . but i think this is definately do-able. The big question is - WHY!?! It's horribly unsafe!


Re: CGI to Telnet Interprocess Fun Stuff
by trantor (Chaplain) on Aug 09, 2001 at 09:55 UTC

    From what I understand, security is not a concern in your case.

    You may want to have a look at Net::Rexec which does what you want without the burden of opening and closing a telnet session each time.

    It's considered highly insecure, but in these time of cut-and-paste hackers a telnet daemon is not any better.

    For a more secure and pragmatic approach, have a look at ssh support for Perl.

    I haven't tried these modules for secure authentication and remote command execution, but the ssh command allows that, and so may this code.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2023-10-01 03:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found