;Multiple Telnet v1.02 Allows multiple sessions. ;***************************************************************************** ;* * ;* MULTEL.WAS * ;* Copyright (C) 1995 Datastorm Technologies, Inc. * ;* All rights reserved. * ;* * ;* This script takes a connection to a UNIX machine, whether it be through * ;* TCP/IP connection or dial-up internet access, and uses the one connection * ;* to allow multiple hosts to be connected at once through the UNIX operating* ;* systems tasking. It can be particularly handy if you need to connect * ;* one place for information and another to paste the information. * ;* * ;* This ASPECT SCRIPT is intended only as a sample of ASPECT programming. * ;* DATASTORM makes no warranty of any kind, express or implied, including * ;* without limitation, any warranties of merchantability and/or fitness * ;* for a particular purpose. Use of this program is at your own risk. * ;* * ;***************************************************************************** ;***************************************************************************** ;* GLOBAL VARIABLES * ;***************************************************************************** integer SesCur[50][3] string Chost, Thost ;***************************************************************************** ;* * ;* MAIN * ;* The Main procedure calls the main procedures and determines which to call * ;* based on results from Update procedure. Takes care of initial things * ;* such as making a temp directory and and checking if currently logged into * ;* a UNIX system. This is where procedures are called due to button presses * ;* in main dialog box. * ;* * ;* Calls: Closem, Updatem, Alldone, ConHost, SwitchEm * ;* * ;* Modifies globals: None * ;* * ;***************************************************************************** proc Main string OrPrompt integer Arow, Acol, Event, Choice, JobNum, MaxJob MaxJob=0 ;Init MaxJob mkdir "C:\TELTEMP" ;Create screen dir JobNum = -99 ;Set special condition ;of first time transmit "^M" ;Transmit carriage ;return getcur Arow, Acol ;Get cursor location locate Arow, 0 ;Position cursor at ;beginning of line termreads OrPrompt Acol ;Get original prompt transmit "set prompt='*root*%'^M" ;Set prompt for root pause 1 ;Wait a sec while Choice !=2 ;Continue loop until ;user choice is cancel(2) ;if not cancel transmit "^M" ;Redisplay prompt if not waitfor "*root*%" 3 ;If not responding ;proper, display error sdlgmsgbox "ERROR" "Not UNIX system/Not Responding." STOP RETRYCANCEL Choice else exitwhile ;Get out of loop endif endwhile if Choice == 2 exit ;Leave program endif Updatem(&JobNum) ;Create dialog box while 1 ;Keep looping dlgevent 1 Event ;Look for dialog event switch Event ;Prepare for case case 0 endcase ;Keep going if nothing case 1 ;An item was chosen endcase case 3 ;Switch was chosen SwitchEm() Updatem(&JobNum) endcase case 4 ;Close host Closem() ;Close session Updatem(&JobNum) ;Update session list endcase case 5 ;New connection ConHost(&MaxJob) ;Connect to new host Updatem(&JobNum) ;Update session list endcase case 6 ;Exit chosen Alldone(OrPrompt) ;See if that is it endcase endswitch endwhile ;Continue looping endproc ;***************************************************************************** ;* * ;* CLOSEM() * ;* The procedure CLOSEM is used to close the session that was selected. * ;* * ;* Calls: None * ;* Called by: Main * ;* * ;* Modifies globals: None * ;* * ;***************************************************************************** proc Closem string NumStr integer JobNum atoi Chost JobNum ;Find out job number if JobNum!=0 ;Make sure job was read transmit "^M^Mfg [" ;If so, switch to that itoa JobNum NumStr ;job and close it transmit NumStr transmit "]^M" waitfor "telnet" transmit "^]" waitfor "telnet" transmit "close^M" strfmt NumStr "C:\TELTEMP\%d.TMP" JobNum ;Create file string delfile NumStr ;Deletes the specified screen file else errormsg "Cannot close session 'Root'!" ;If root was selected, endif ;cannot close. clear ;Clear screen endproc ;***************************************************************************** ;* * ;* UPDATEM(JobNum) * ;* This procedure redraws the menu list and resets the terminal and other * ;* tasks that are necessary between menu selections. * ;* * ;* Calls: None * ;* Called by: Main * ;* * ;* Modifies globals: Chost, Thost * ;* * ;***************************************************************************** proc Updatem param integer JobNum integer Arow, Acol string Red if JobNum == -99 ;If not first time, dlgdestroy 1 CANCEL ;get rid of dialog box endif Thost = "(0) Root" ;Initiate list termreset ;Reset terminal pause 1 ;Wait a sec transmit "jobs^M" ;Display jobs waitfor "*root*%" ;Wait for *root* prompt getcur Arow, Acol ;Get cursor position JobNum=-1 ;Initiate job number while JobNum!=0 ;Continue while lines ;are found Acol = 0 ;Set column to 0 Arow = Arow - 1 ;Go up a row locate Arow, Acol ;Change to new position termreads Red ;Read the line atoi Red JobNum ;Find job # if JobNum !=0 ;Verify it is a job line substr Chost, Red, 35, 20 ;Pull out session name strfmt Thost "%s,(%d) %s" Thost JobNum Chost ;Construct list endif endwhile clear ;Clear screen dialogbox 1 123 58 137 115 0 ;Bring up main dialog listbox 1 2 22 84 80 Thost SINGLE Chost SORT ;box text 2 16 8 54 8 "Telnet Sessions" LEFT pushbutton 3 92 22 40 14 "Switch To" pushbutton 4 92 43 40 14 "Close" pushbutton 5 92 65 40 14 "New" pushbutton 6 92 88 40 14 "Exit" enddialog endproc ;***************************************************************************** ;* * ;* ALLDONE(OrPrompt) * ;* This procedure terminates execution of the script when selected * ;* * ;* Calls: None * ;* Called by: Main * ;* * ;* Modifies globals: None * ;* * ;***************************************************************************** proc Alldone param string OrPrompt if not stricmp Thost "(0) Root" ;Verify no sessions errormsg "Must close all sessions first (sorry)" ;Give error message else clear ;Clear screen rmdir "C:\TELTEMP" ;Remove screen dir strfmt OrPrompt "set prompt='%s'^M" OrPrompt ;Construct prompt str transmit OrPrompt ;Set prompt back exit ;and exit endif endproc ;***************************************************************************** ;* * ;* ConHost(MaxJob) * ;* This procedure prompts for a host (session) to connect to and then * ;* connects to that host. Control stops here until the host disconnects * ;* or a break is issued. * ;* * ;* Calls: ConDialog, ScreenSave * ;* Called by: Main * ;* * ;* Modifies globals: None * ;* * ;***************************************************************************** proc ConHost param integer MaxJob integer Event, Choice ConDialog(Event) ;Create dialog box if Event != -1 transmit "clear^Mtelnet " ;Connect to host transmit Chost transmit "^M" Choice = 0 ;Reset Choice while Choice != 2 ;Continue while cancel ;is not chosen if not waitfor "]'." 4 ;If connected did not ;appear, error sdlgmsgbox "ERROR" "Remote Host Not Responding" STOP RETRYCANCEL Choice else exitwhile ;Get out of while endif endwhile if Choice == 2 transmit "^C" ;If cancel was selected errormsg "Aborted!!" ;cancel operation. transmit "^M" else clear ;Otherwise give the ;good message and clear usermsg "Connected! Hit CTRL-BREAK to go to menu." endif if waitfor "*root*%" FOREVER ;Wait here until need ;script again clear ;If host session ;terminated, clear else MaxJob = MaxJob + 1 ;Increment maximum job # ScreenSave(MaxJob) ;Save screen and cursor endif endif endproc ;***************************************************************************** ;* * ;* SwitchEm() * ;* This procedure switches to a currently open session. Control remains * ;* here until session terminates or a user break is issued. * ;* * ;* Calls: ScreenSave * ;* Called by: Main * ;* * ;* Modifies globals: None * ;* * ;***************************************************************************** proc SwitchEm integer JobNum string NumStr dlgdestroy 1 CANCEL ;Remove main dialog box atoi Chost JobNum ;Determine job # if JobNum!=0 ;Make sure not root transmit "^M^Mfg [" ;Switch to it if not itoa JobNum NumStr transmit NumStr transmit "]^M" waitfor "telnet" ;Pause for clear screen pause 1 ;Wait a sec clear ;Clear screen strfmt NumStr "C:\TELTEMP\%d.TMP" JobNum ;Creates file string transmit "^L" if not waitfor " " 1 ;If ^L had no effect transmit "^H" ;delete ^L pause 1 ;Wait a sec playback NumStr ;Brings back screen locate SesCur [JobNum][1],SesCur [JobNum][2] ;and locate cursor endif usermsg "Reconnected! Hit CTRL-BREAK to go to menu." ;Signify connected if not waitfor "*root*%" FOREVER ;Wait for root prompt ;indefinitely ScreenSave(JobNum) ;Save screen and cursor else delfile NumStr ;Remove the screen file endif else transmit "clear^M" ;Clears screen usermsg "Type '&&&' and return to continue." ;If root is selected, waitfor "&&&^M" FOREVER ;special exit procedure endif clear ;Clear screen endproc ;***************************************************************************** ;* * ;* SCREENSAVE(JobNum) * ;* This procedure saves the contents of the current screen to a file * ;* corresponding to the Job Number (JobNum). The screen snapshot is saved * ;* in the created directory c:\teltemp and the cursor position is saved in * ;* the array SesCur. * ;* * ;* Calls: None * ;* Called by: SwitchEm, ConHost * ;* * ;* Modifies globals: SesCur * ;* * ;***************************************************************************** proc ScreenSave param integer JobNum integer Index, Num string NumStr, FileStr getcur SesCur [JobNum][1],SesCur [JobNum][2] ;Save cursor position strfmt NumStr "C:\TELTEMP\%d.TMP" JobNum ;Build file save string snapshot FILE NumStr ;Save screen to file fopen 1 NumStr READ ;Opens snapshot file fopen 2 "C:\TELTEMP\TEMP" CREATE ;Opens buffer file for Num = 1 upto 23 ;Read the first 23 lines fgets 1 FileStr ;one at a time and then fputs 2 FileStr ;puts them into the temp endfor fgets 1 FileStr ;Reads string strchr FileStr 13 Index ;Find a carriage return strdelete FileStr Index+1 1 ;and strip it fputs 2 FileStr ;Puts string in file fclose 1 fclose 2 ;Close files copyfile "C:\TELTEMP\TEMP" NumStr ;Copy temp file delfile "C:\TELTEMP\TEMP" ;Remove temp file transmit "^]" ; waitfor "telnet" ;Suspends the session ; transmit "send escape^M" ;If telneted to unix host waitfor "telnet" ;uncomment these 2 lines transmit "z^M" clear ;Clears the screen. endproc ;***************************************************************************** ;* * ;* CONDIALOG(Event) * ;* This procedure creates the new host connection dialog box and control * ;* stays here until a selection is chosen from the dialog box that is * ;* in this procedure. * ;* * ;* Calls: None * ;* Called by: ConHost * ;* * ;* Modifies globals: Chost * ;* * ;***************************************************************************** proc ConDialog param integer Event dlgdestroy 1 CANCEL ;Remove main dialog box dialogbox 0 90 73 196 45 2 "Telnet" ;Bring up connect editbox 1 40 9 115 12 Chost pushbutton 2 81 25 40 14 "Connect" ;dialog box text 3 9 11 21 8 "Host" LEFT enddialog while 1 ;Loop (and loop) dlgevent 0 Event ;Prepare to compare switch Event case 0 ;Nothing happened endcase ;Keep looping default ;If option one chosen exitwhile ;then get out of loop endcase endswitch endwhile ;Keep looping dlgdestroy 0 CANCEL ;Remove dialog box endproc