Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-31-2005, 06:22 AM
s.balon s.balon is offline
Registered User
 
Join Date: Aug 2005
Posts: 1
Convert .csf to .vsb

Hi folks.

I have a lot of script in .csf format.

Not complicate but only to logon onto devices.

It basicly like that :

send("********\r");
expect(">");
send("enable\r");
expect("assword:");
send("********\r");


the most impressive is like that :-) :

expect("ord:");
send("*****\r");
expect(">");
send("enable\r");
expect("assword:");
send("*****\r");
send("telnet 172.16.0.2 /sour f 0/0\r");
expect(":");
send("******\r");
expect(">");
send("enable\r");
expect("assword:");
send("*****\r");

Do you have a script or a tools to convert into .vbs or something readable by SecureCRT 5.x

Thank in advance.

Steve Balon
Reply With Quote
  #2  
Old 09-01-2005, 12:41 PM
bocks's Avatar
bocks bocks is offline
VanDyke Customer Support
 
Join Date: Jan 2004
Location: Albuquerque, NM
Posts: 184
Hello Steve,
Quote:
Originally Posted by s.balon
Do you have a script or a tools to convert into .vbs or something readable by SecureCRT 5.x

Thank in advance.

Steve Balon
Due to the complexities involved in going from a .csf script to a .vbs script, we do not have a tool that can accomplish this. The translations will need to be done by hand. However, if the .csf script is comprised of simple expect and send phrases, with no comments, I might have a script that may help.

A while back, we wrote an example script to show simple file access and handling routines. It was designed to read a file, process the data line by line, and output another file. As an example, the script was designed to read .csf format send and expect statements and output the corresponding .vbs command. I will post it below as an example, but you may be able to use it as a base to help convert your files.
Code:
' csf-vbscript-converter.vbs
'
' DESCRIPTION: Script that will convert basic expect/send
'              .csf files to equivalent vbscript files.
'
'   USAGE:
'           (Windows XP and newer): Run the script and you
'           will be able to browse to the file you wish to
'           convert. Alternatively, drag and drop files
'           from Windows Explorer onto a shortcut to this
'           script.
'
'           (Earlier Windows OS versions): Drag and drop .csf
'           files from Windows Explorer onto a shortcut to
'           this script.
'
'  Outputs: each .csf file provided is read in and an
'           equivalent .vbs file is saved in the same folder
'           as the existing file. Currently the only lines that
'           are converted are lines that consist of send(); or
'           expect(); statements.
'
' Example .CSF scripts
' 
'     send("********\r");
'     expect(">");
'     send("enable\r");
'     expect("assword:");
'     send("********\r");
'
'
'     expect("ord:");
'     send("apassword\r");
'     expect(">");
'     send("enable\r");
'     expect("assword:");
'     send("mypassword\r");
'     send("telnet 192.168.0.1\r");
'     expect(":");
'     send("superpwd\r");
'     expect(">");
'     send("enable\r");
'     expect("assword:");
'     send("extrapwd\r");


Dim g_vArgs, g_shell, g_fso
Set g_vArgs = WScript.Arguments
Set g_shell = CreateObject("WScript.Shell")
Set g_fso   = CreateObject("Scripting.FileSystemObject")

Main

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()
    Dim nIndex, szArgs

    szResults = "Results of the script converter:" & vblf & _
                "------------------------------------------" & vblf
    
    If g_vArgs.Count < 1 then
        ' See if we can successfully browse for a file...
        szFileToConvert = BrowseForFile
        
        if szFileToConvert = "" then exit sub
        
        if szFileToConvert = "__NO_BROWSER__" then        
            MsgBox "Select a list of files in Windows Explorer," & vblf & _
                 "then drag-and-drop them onto a shortcut to this script."
            exit sub
        end if
        
        MsgBox szResults & ConvertFile(szFileToConvert)
        exit sub
    end if

    For nIndex = 0 To g_vArgs.Count - 1
        szResults = szResults & ConvertFile(g_vArgs(nIndex)) & vblf
    Next
    
    MsgBox szResults

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ConvertFile(szFile)
    If g_fso.FileExists(szFile) <> True then
        ConvertFile = "File not found: " & szFile
        exit function
    end if
    
    If Instr(g_fso.GetExtensionName(szFile), "csf") < 1 then
        ConvertFile = "Skipped non .csf file: " & szFile
        exit function
    end if
    
    ' Set up a filestream object so that we can read in the entire .csf file and
    ' perform massive REPLACE operations on the data.  Then, we'll write the
    ' modified version out to a file with the same basename + .vbs extension.
    Dim objFileStream
    Set objFileStream = g_fso.OpenTextFile(szFile, 1, False)
    szOldFileText = objFileStream.ReadAll
    objFileStream.Close    
    Set objFileStream = Nothing
    
    szNewFileText = "# $language = ""VBScript""" & vbcrlf & _
                    "# $interface = ""1.0""" & vbcrlf & _
                    "' Converted from .csf file: " & szFile & vbcrlf & _
                    "' on " & Date & vbcrlf & vbcrlf & _
                    "crt.Screen.Synchronous = true" & vbcrlf & vbcrlf & _
                    szOldFileText
     
    szNewFileText = Replace(szNewFileText, "send(", "crt.screen.send(")
    szNewFileText = Replace(szNewFileText, ");", ")")
    szNewFileText = Replace(szNewFileText, "expect(", "crt.screen.WaitForString(")
    szNewFileText = Replace(szNewFileText, "\r", """ & vbcr & """)
    szNewFileText = Replace(szNewFileText, "& vbcr & """"", "& vbcr")
    
    szNewFileName = g_fso.GetParentFolderName(szFile) & _
                    "\" & g_fso.GetBaseName(szFile) & _
                    ".vbs"
                    
    Set objFileStream = g_fso.OpenTextFile(szNewFileName, 2, true)
    objFileStream.Write szNewFileText
    objFileStream.Close
    
    ConvertFile = "Converted: " & szNewFileName        
End function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function BrowseForFile()
    On Error Resume Next
    ' Based on information obtained from
    ' http://blogs.msdn.com/gstemp/archive/2004/02/17/74868.aspx
    ' NOTE: Will only work with WindowsXP since other OS's
    '       don't have a UserAccounts.CommonDialog ActiveX
    '       object registered.
    Set objDialog = CreateObject("UserAccounts.CommonDialog")
    If Err.Number <> 0 then
        ' The UserAccounts.CommonDialog is available by default
        ' on Windows XP, but not earlier.
        BrowseForFile = "__NO_BROWSER__"
        On Error Goto 0
        exit function
    end if
    
    On Error Goto 0
        
    objDialog.Filter = "CSF Script Files|*.csf|All Files|*.*"
    objDialog.FilterIndex = 1
    objDialog.InitialDir = "C:\Temp"
    nResult = objDialog.ShowOpen

    If nResult = 0 Then
        MsgBox "Cancel"
    Else
        BrowseForFile = objDialog.FileName
    End If

End function
Please let me know if this example helps.


Thanks,

-bocks
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:25 AM.