4580213 [rkeene@sledge /home/rkeene/devel/reverse-utils]$ cat -n rtelnetd.tcl
   1: #!/usr/bin/tcl -n
   2: set host [lindex $argv 0]
   3: set port [lindex $argv 1]
   4: set comm [lindex $argv 2]
   5: set pass [lindex $argv 3]
   6: 
   7: if {$comm==""} { 
   8:   puts "Usage:\n\t$argv0 <host> <port> <command> \[<password-file>\]"
   9:   exit 1 
  10: }
  11: if {[fork]!=0} { exit 0 }
  12: close stderr
  13: 
  14: if {$pass!=""} {
  15:   set passId [open $pass r]
  16:   gets $passId passwd
  17:   close $passId
  18: } else {
  19:   set passwd ""
  20: }
  21: 
  22: proc bgerror {error} {
  23:   catch { puts "Crashed!  restarting" }
  24:   exec $argv0 $argv \&
  25:   exit
  26: }
  27: 
  28: proc copyline {inId outId} {
  29:   global forever
  30:   catch {
  31:     gets $inId ln
  32:     puts $outId $ln
  33:     flush $outId
  34:   }
  35:   if {[eof $inId] || [eof $outId]} { set forever 1 }
  36: }
  37: 
  38: while {1} {
  39:   set checkpass ""
  40:   set sockId ""
  41:   cd "~"
  42:   catch { set sockId [socket $host $port] }
  43:   if {$sockId!=""} {
  44:     fconfigure $sockId -blocking 1
  45:     if {$passwd!=""} {
  46:       puts $sockId "Enter your password: "
  47:       flush $sockId
  48:       gets $sockId checkpass
  49:     } else {
  50:       set checkpass ""
  51:     }
  52:     if {$checkpass==$passwd} { 
  53:       set commId [open "|$comm" a+]
  54:       fileevent $sockId readable "copyline $sockId $commId"
  55:       fileevent $commId readable "copyline $commId $sockId"
  56:       vwait forever
  57:     }
  58:     catch { close $sockId }
  59:     catch { close $commId }
  60:   }
  61:   sleep 15
  62: }

rtelnetd.tcl is the server (firewalled) side of rtelnet.
4580214 [rkeene@sledge /home/rkeene/devel/reverse-utils]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 1999-10-09 01:49:35