#!/usr/bin/perl -w use strict; ############################################################################# # # # pwdhide.pl # # # # Keyboard echo on terminal (TTY) screen switcher. # # Prepina medzi pisanim/nepisanim klavesnice na obrazovku terminalu. # # # # Wolcano [13/03/2002] # # Nepto [24/06/2002] # # # ############################################################################# # # output (1 or 0) # my $OUTPUT = 0; # # verbose (1 or 0) # my $VERBOSE = 1; ############################################################################# # # program name # my $PRG = __FILE__; # # silenced flag # my $SIL = 0; # # parent process ID (PID) # my $PPID = getppid(); # # parent terminal (TTY) # my $TTY = `ps --no-headers -otty '$PPID'`; chomp $TTY; # to remove ending newline # # command variables # my $CMD_BASE = "stty --file '/dev/$TTY'"; # # do_stty() subroutine # sub do_stty { my $cmd; my $onoff; if ($SIL) { $onoff = 'on'; $cmd = "$CMD_BASE echo"; } else { $onoff = 'off'; $cmd = "$CMD_BASE -echo"; } system($cmd); print STDERR "$PRG: turning $onoff echo ($cmd)\n" if $VERBOSE; $SIL = !$SIL; } # # line variables # my $input_data; my $raw_line; my $line; # # command line parameters test (@ARGV doesn't contain program name) # if (scalar(@ARGV) < 1) { print("pwdhide.pl - written and copyrights by Nepto & Wolcano\n"); print("Usage: $PRG \n"); exit 1; } # # string to hide # my $STR = $ARGV[0]; # # System init # select(STDIN); $| = 1; # make unbuffered select(STDERR); $| = 1; # make unbuffered select(STDOUT); $| = 1; # make unbuffered print STDERR "$PRG: starting...\n" if $VERBOSE; # # main loop # while ( $input_data = ) { foreach $raw_line ( split ( /\n/, $input_data ) ) { $line = $raw_line; $line =~ s/^\s*//g; $line =~ s/\s*$//g; next if !length($line); do_stty() if ($SIL != 0); do_stty() if ( $SIL == 0 && $line =~ /$STR/ ); # print '*******************'.$_."%%\n" if $OUTPUT; print STDOUT $raw_line if $OUTPUT; } } # restore input echo if it is turned off do_stty() if ($SIL != 0); print STDERR "$PRG: terminating...\n" if $VERBOSE;