/* 
  An adaption of the telnet.cmd editted to perform as a telnetsnoop.

  By Paul Meyer of The Spyders Web BBS 
  
  If you make any worthwhile changes to this script, send me it!
  
  You can reach me at:  pmeyer@ednet.com.au or _Spyder_ on #adept...
  For those without internet access: 3:690/430@fidonet or 55:60/0@Adeptnet

  Copy TelnetSnoop.cmd + TelnetIn.Cmd + TelnetOut.Cmd into your adept\menus
  directory and call TelnetSnoop from a type 10 or 11 menutype or via an
  AdeptChainREXX() or AdeptChainREXXNc().

  It's recommended you use the linetimer.cmd included in this archive to
  enforce time limits.

  Last editted/Released 19th July 1996

*/

LEAVEPORTOPEN       = X2D(00000001)
OPENPORTSHARED      = X2D(00000002)
OPENWRITETHROUGH    = X2D(00000004)
ISPIPESERVER        = X2D(00000010)
ISPIPECLIENT        = X2D(00000020)
IGNORECARRIER       = X2D(00000040)

ISTELNETSERVER      = X2D(00000080)
ISTELNETCLIENT      = X2D(00000100)
ISSERIAL            = X2D(00000200)
ISSOCKETSERVER      = X2D(00000400)
ISSOCKETCLIENT      = X2D(00000800)
DELETECONNECTION    = X2D(00001000)

ARG line

Signal on Halt
Signal on Error

if (line = 0) Then  /* Telnet Script won't work in local mode */
Do
    Call AdeptCLS line
    Call AdeptCurPos line,12,1
    Call AdeptPrint line, "Sorry Telnet only avaliable on nodes > 0\r\n"
    Call AdeptPrint line, "{PB"
    Exit
End


Call AdeptCLS line
Call AdeptLocation line, "Telnet"
Call AdeptSayGen line, "Telnet"

Call AdeptPrint line, "Some popular sites\r\n\r\n"
Call AdeptPrint line, "1> juge.com            - Another great OS/2 BBS (Second only to this one :))\r\n"
address.1 = "juge.com"
port.1 = 23
Call AdeptPrint line, "2> 203.12.117.105      - The Spyders Web BBS         \r\n"
address.2 = "203.12.117.105"
port.2 = 23
Call AdeptPrint line, "3> 203.9.159.202       - Amiga Retreat BBS           \r\n"
address.3 = "203.9.159.202"
port.3 = 23
Call AdeptPrint line, "4> snoval.com          - SnoValley Shareware Exchange\r\n"
address.4 = "snoval.com"
port.4 = 23
Call AdeptPrint line, "5> summitcnty.com      - Summit Central BBS          \r\n"
address.5 = "summitcnty.com"
port.5 = 23
Call AdeptPrint line, "6> USER DEFINED\r\n\r\n"

Choice = AdeptInput(line,,80,,,"Telnet to: ",,,)

if (choice = 6) Then
  Do
    Address.6 = AdeptInput(line,,80,,,"[0m[K\r\n[KTelnet to address: ",,,)
    if ( Address.6 = '' | SPACE(Address.6) = '127.0.0.1' ) then do
        exit
    end
    Port.6 = AdeptInput(line,,12,,,"\r\nPort[Enter for Default]: ",,,)
    if(Port.6 = '') then do
        Port.6 = 23
    End
  End

if (choice = '')
    Then Exit

if (choice > 6 | choice < 1)
    Then Exit


Call AdeptPrint line, "\r\nTrying"
Do 4
  Call AdeptPrint line,"{PA."
  Call AdeptSleep line,128
End

Call AdeptPrint line, "{PA" || Address.Choice || " on port "||Port.Choice

Call AdeptLocation line, Address.Choice
Call AdeptSayGen line, "Telnet: " || Address.Choice

Call AdeptLog line,1,"Telnet: " || Address.Choice
Call AdeptLog line,1,"Port: " || Port.Choice

/* Open the telnet socket */ 
rc = AdeptRawOpenSocket(ISTELNETCLIENT, Address.Choice, Port.Choice, 'Port')

if(port<>0)then
do
  /* Start the in and out threads */
  intid = AdeptStartRexxThread('TelnetIn.Cmd',line,Port)
  outtid = AdeptStartRexxThread('TelnetOut.Cmd',line,Port)

  /* loop until the user hangs up or wants to exit */
  do forever
    Call AdeptSleep line,32

    If(AdeptGetGlobalVar('STATUS')="EXIT")then
      signal outtahere
    If(AdeptRequestsLogoff(line)=1)then
      signal outtahere
  end
end
else
do
  Call AdeptPrint line,"\r\nError: Could not connect to host.\r\n\r\n"
  Call AdeptPrint line,"{PB"
end

/* Cleanup */
Halt:
Error:
outtahere:
  /* Kill the threads we started */
  AdeptKillRexxThread(intid)
  AdeptKillRexxThread(outtid)

  /* Close the Socket */
  Call AdeptRawComClose Port

  /* And drop our global variable */
  Call AdeptDropGlobalVar 'STATUS'

  /* there.. don't we feel neat and clean now?! :) */
exit

