Scripting Part 2: Terminal Emulators and Web Scripting
Novell Cool Solutions: Feature
Reader Rating 
|
Digg This -
Slashdot This
Posted: 5 May 2005 |
Note: This article is based on BrainShare TUT248. For more information on scripting techniques, see TUT248 or the Cool Solutions article SecureLogin Scripting Techniques.
Emulator Types
There are four basic emulator types in scripting:
- Generic
- Advanced Generic
- HLLAPI
- DDE
These types are divided into two groups: Generic and Advanced, and HLLAPI and DDE.
Generic and Advanced Generic
The Generic and Advanced Generic emulators rely on "screen scrape," which means that they read the complete screen, cutting and pasting information. The drawbacks include screen flash, and the fact that the script must be stopped before the user can operate.
Screen scrape uses a repeat-loop mechanism that searches for password-related messages as well as for the first user menu. Password change within an application is not supported.
HLLAPI and DDE
HLLAPI stands for High Level Language Application Programming Interface. This interface was defined by IBM several decades ago to deal with terminal communications. DDE is Dynamic Data Exchange, a form of inter-process communication.
With HLLAPI and DDE, there is no screen scraping. Specific portions of the screen are read, such as the ReadText ?Variable Column Row. HLLAPI supports standard messages (IBM S/390) and removes screen blinking. Specific messages are handled as they occur, and password change is supported while the application is running (not possible with screen scrape).
Emulation Scripts
Here are some things to look for when building emulation scripts:
- Login
- Password - Failure or Expiry
- MOTD (Message of the Day) - Standard or Informational
- Partial Text
Example Emulation Script
WaitForText ?ogin:? Type $Username Type @E WaitForText ?assword:? Type $Password Type @E
Example Emulation Script 2
WaitForText ?ogin:?
Type $Username
Type @E
WaitForText ?assword:?
Type $Password
Type @E
Repeat
# Check for failed login
Increment ?ScreenCount
If ?ScreenCount eq 1
If -Text "ogin incorrect"
Increment ?RunCount
if ?RunCount eq 1
DisplayVariables "Please re-enter your ID and Password?
Type $Username
Type @E
Delay 500
WaitForText "assword:"
Type $Password
Type @E
Endif
EndIf
#Check for password expiry
If -Text "New Password:"
If ?PasswordChange eq
Set ?PasswordChange 1
ChangePassword ?NewPassword "Your password must be changed."
Type ?NewPassword
Type @E
Endif
Endif
EndIf
If ?PasswordChange eq 1
If -Text "e-enter new Password:"
Type ?NewPassword
Type @E
Endif
Endif
If -Text "Press RETURN key to continue....."
Type @E
Endif
If -Text "MENU"
EndSplashScreen
if ?PasswordChange eq 1
Set $Password ?NewPassword
Set ?NewPassword
endif
Set ?PasswordChange
Set ?ScreenCount
break
endif
EndRepeat
EndSplashScreen
if ?PasswordChange eq 1
Set $Password ?NewPassword
Set ?NewPassword
endif
Set ?PasswordChange
Set ?ScreenCount
break
endif
EndRepeat
Web Scripts
Simple Web Scripts
A simple Web script inserts the username and password. It uses Field Names, such as "Type $Username" or "Type $Password password". It can use an automatic mode (Submit) or a manual mode (user click).
However, there are a few issues with these simple scripts. For example, a login can be unnecessarily trigged after logging out. Web scripts may not be active on some pages, and the username and password may be inserted on the wrong pages. Also, password control usually only works when the password field is visible.
Intelligent Web Scripts
Intelligent Web scripts provide a more flexible solution. They enable the script to determine what to do, such as:
- Don't log in after logout
- Determine the page that is being viewed
- Determine if there a password field
Web applications consist of two key structural elements: address (unique URL or IP address), and a series of pages, each offering different data views and operations. To detect a page, SecureLogin generally does a combination of the following things:
- Check the URL
- Match for a page title
- Match for specific text within the HTML
- Look at the names of input fields within forms
SecureLogin can be told to handle the pages from a web site in two ways:
- Platform-per-page approach. Using this approach, each page that requires some action has its own SecureLogin platform. For example: http:\\127.0.0.1\login.html, or http:\\127.0.0.1\changepassword.html
- Platform-per-site approach. Alternatively, SecureLogin can monitor every page at a specific web site, with the script determining which page(s) to process, such as http:\\127.0.0.1
Generally, the second option is typically simpler, more robust and easier to maintain. Using the platform-per-site approach, the following basic structure is suggested:
if ?text ?page 1 unique text?
commands
endif
if ?text ?page 2 unique text?
commands
endif
Note: Make sure you deselect the "Password must exist" option. Otherwise, if the page you want to process doesn't have a password, nothing will happen! Using this approach, SecureLogin will run the script against each page on the web site.
Example Web Script
###########################################################
# Standard login window handling
if -text "PDS-SLD-Login"
type $Username #1
type $Password #2
submit
endif
###########################################################
# Password expiration handling
if -text "PDS-SLD-PasswordExpired
messagebox "SecureLogin has detected that your password has expired - it will be automatically reset"
click #2
endif
###########################################################
# Password change handling
if -text "PDS-SLD-ChangePassword"
Set ?oldpass $password
OnException ChangePasswordCancelled Call UserCancelled
ChangePassword $password random
Type ?oldpass #1
Type $password #2
Type $password #3
Submit
endif
Sub UserCancelled
Messagebox "You cannot cancel the password change dialog box. Please change your password"
OnException ChancePasswordCancelled Call UserCancelled
ChangePassword $Password
Type ?oldpass #1
Type $password #2
Type $password #3
Submit
EndSub
###########################################################
# Locked account
if -text "PDS-SLD-AccountLocked"
messagebox "Sorry, your account has now been suspended for security reasons. Please contact the help desk."
killapp "iexplore.exe"
endscript
endif
###########################################################
# Incorrect credentials handling
if -text "PDS-SLD-BadCredentials"
displayvariables "Sorry, but your password is not correct...Please enter your correct password"
gotourl http:\\127.0.0.1\sld-htmllogin.html
endscript
endif
###########################################################
# End of script
click #200
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com
