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

Fellow monks,

Here's my situation. At work we have a piece of hardware running an embedded computer with vxWorks. There are two ways of interacting with the embedded computer: through the serial port and via ethernet over telnet. If CTRL-X is pressed in either of two interfaces to the embedded computer, it reboots. I need to prevent that from happening. I have already plugged the hole for the serial interface (easily done by creating a wrapper to the serial port program called tip in Solaris and capturing CTRL-X events). However, now I must do the same for telnet.

The problem is that I cannot use modules like Net::Telnet because they do not provide all the functionality/interface that regular telnet does. So, I tried interacting with telnet through a wrapper, which basically did open(TEL, "| telnet $arg"); and then passing user commands through the <TEL> handle. This almost worked, except that typing in passwords at login time now became visible. Does anyone have any suggestions on how to work around this one issue? Maybe there's a better way to capture CTRL-X and still have all the functionality of telnet?

Thanks.

Replies are listed 'Best First'.
Re: telnet wrapper
by marto (Cardinal) on Jan 23, 2006 at 13:38 UTC
    Hi gri6507,

    Checkout perldoc -q single. Looks like you may want to use Term::ReadKey to write a little function to check the user input making sure that it is not $key=24 (which IIRC belive equates to Ctrl X).
    I can't install this module at the moment (Im at work), but look at the sample code from perldoc -q single which should point you in the right direction.

    Hope this helps.

    Martin
Re: telnet wrapper
by turo (Friar) on Jan 23, 2006 at 13:46 UTC

    Using 'open' and ReadKey could solve your problem :-)

    use Term::ReadKey qw(GetTerminalSize ReadMode); open(TEL, "| telnet $arg"); $username=<> print <TEL> $username; ReadMode 2; chomp($pass=<STDIN>); ReadMode 0; print <TEL> $pass;

    cheers

    perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
      I thought of this approach already. Unfortunately, it requires the wrapper to be cognizant of telnet's output and expect "Password:". Only then can the wrapper safely apply ReadMode settings around the password request. However, since telnet is only opened for writing, the wrapper does not know what telnet outputs and the ReadMode trick can't work. The only way to make that work is if telnet is started with open3 and autoflush is turned on. Even then, I'm not sure if the login "Password:" request would get flushed because it does not contain a new line after it.

        Umm, it was only an idea, i think you have the reason ...

        A lot time ago, i've made a little script in 'Expect' a TCL extension, this expects for patterns or keyword of your program and feed that program with the data you want... maybe the Expect module for perl will help ...

        good luck

        perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
Re: telnet wrapper
by traveler (Parson) on Jan 23, 2006 at 16:33 UTC
    Generally, you do not want to echo anything on the client side. The server should echo characters when it is necessary. There is a telnet protocol command to enable or disable local echo. I don't know enough about the wxWorks telnet server, but it should do all the echoing.

    So, when you start perl your terminal or window is in echo mode. You need to turn it off as telnet does when it is talking directly to a terminal (under most *nix systems the telnet client checks to see if it is on a terminal and only then does it turn off the echo). Doing that should fix your problem.