Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-11-2012, 09:15 AM
tard01 tard01 is offline
Registered User
 
Join Date: Sep 2012
Posts: 3
Config t prompt, change command

Hey guys. I was looking for some advice/assistance. I've never worked with these tools before, so know little about what i'm about to ask.

I was looking for a tool that when i enter config t mode on a cisco box, it prompts a box for a ticket number. If the box is closed, it exits config mode. If a ticket is entered, it changes the snmp contact string to show the ticket number.


this way we have an additional layer to track changes made by people.


I've mixed and matched other code i've seen posted around the internet and have a bit of what i think i will need, but looking for improvement/guidance but mostly i want to know of the best way to get this applied to hundreds of users across the globe. I'm not sure how to do that. Not sure if i can make it a script that gets loaded when the PC boots up, or if it becomes a part of CRT, or how to enforce its use, etc. If anyone has insight into how to distribute it and ensure it actually gets used other than relying on people to execute it, i'd appreciate it (i dont trust the users to do it, so i want to make sure it's forced).


Here's the base code i grabbed and hope it works... i'd love input to fix/improve it. Hell, i'd also like to know what software to use because quite frankly i have only picked and pulled. This isn't exactly my territory/comfort zone. but mainly i'm interested in figuring out a method to force the users to use it and make it a part of their system.


Code:
# $language = "VBScript"

# $interface = "1.0"
Dim ticket, host, srow, readline
Dim waitStrs, conf
conf = "Enter configuration commands, one per line.  End with CNTL/Z." & Chr(13) & "" 

waitStrs = Array( conf )


Sub Hostname
  'Gets the hostname from Cisco IOS devices

  Dim i,x, screenrow, read

  x = crt.Screen.CurrentColumn

  screenrow = crt.Screen.CurrentRow

  For i = 1 to (x - 10)

    read = crt.Screen.Get(screenrow, i, screenrow, i)

    host = host & read
  Next  

End Sub




Sub snmp
  'Sets the snmp-server contact field for change reconciliation

  Dim str

  str = "snmp-server contact Reconciliation ->" & ticket & "<-" & Chr(13)

  crt.Screen.Send str
End Sub


Sub Main
Do

    While True
      Dim result

      result = crt.Screen.WaitForStrings( waitStrs )  

      
      If result = 1 Then
        'Looks like we entered Cisco IOS config terminal mode
        crt.Screen.Synchronous = True
        Do 
          While true
            Dim cresult,cend,cread,crow,chost

            x = crt.Screen.CurrentColumn

            cend = x - 1

            cwaitStrs = Array( Chr(10), "#" )
            cresult = crt.Screen.WaitForStrings( cwaitStrs )
            
            If cresult = 2 and host = "" Then
              'Config banner finished, get the ticket number for the changes to satisfy reconciliation
              ticket = crt.Dialog.Prompt("Enter the ticket type and number for the changes", "Reconciliation", "", False)
If ticket = IDCANCEL then
                'Ticket field was blank or user hit cancel, exit config mode
                crt.Screen.Send Chr(26)
              Else
                'Ticket field had input
                crt.Dialog.MessageBox( "Ticket recorded in snmp contact."")
                snmp
              End If              
ElseIf ( cresult = 1 and host <> "" ) Then
              'Detected new line, make sure we are still in config mode
              crow = crt.Screen.CurrentRow - 1
              cread = crt.Screen.Get(crow, 1, crow, cend )
              chost = host & "#"

Else
                'Still in config mode, write the last line to the log
                srow = crt.Screen.CurrentRow - 1

                readline = crt.Screen.Get(srow, 1, srow, 132 )      

		log.Write readline & vbCrLf

              End If

            End If
          Wend

        Loop
        crt.Screen.Synchronous = False        

      End If
    Wend

  Loop



End Sub











again, my biggest concern is distributing this and how. what software is needed, what tools/method can i use to deploy this globally and make sure my people are using it and aren't relied upon doing it manually.
Reply With Quote
  #2  
Old 09-11-2012, 01:20 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi tard01,

SecureCRT does not have a way to force a user to run scripts. Further, I am not aware of a way to force a user to run a particular program.
How do you envision restricting use to just running the scripts?
Quote:
Here's the base code i grabbed and hope it works
Are you indicating that you have posted code that you haven't tested?

Are you encountering a problem running your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-11-2012, 04:13 PM
tard01 tard01 is offline
Registered User
 
Join Date: Sep 2012
Posts: 3
rtb,
the computers we use are locked down so only securecrt is available for use. Putty is available, but not readily. they can not install the app, only use the web run version, so its use it sparse.


As far as forcing users to do it, i know it's possible. I've seen it deployed. User made no effort and when they installed securecrt, it already had the built in script as part of the program. How they got it embedded is a mystery to me, part of what i'm trying to figure out. The script was invisible to the user, minus the pop up asking for the ticket.



The code i posted is not tested. Nor does it work. It actually has a permanent loop on the prompt box. it was just pasted as an example of the goal i'm trying to use to hopefully give some clue to anyone wondering. I basically took versions from other pieces of things ive seen and meshed them together. I've gotten the script to work (minus the loop i had issues with, but will work on later - likely a syntax thing).

I've seen it deployed as such that...
user logged into a PC, it was pre-loaded with applications (includes securecrt).
user loads securecrt
upon entering config t, user is prompted by a window asking for ticket
if no ticket, the program ends config mode
if ticket, the script records all output until config mode ends.
When config mode ends, the "snmp contact" string is changed/updated to reflect the ticket number .... following that, a log file/server was updated with the changes made, and later we added an email was sent to the shift lead on duty automatically.


ideally i'd like to replicate that efficiency. Just starting the ground work on determining how to go about accomplishing it using the tools/resources available to me.
Reply With Quote
  #4  
Old 09-11-2012, 05:00 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi tard01,

Thanks for the information.
Quote:
As far as forcing users to do it, i know it's possible. I've seen it deployed. User made no effort and when they installed securecrt, it already had the built in script as part of the program.
Having used SecureCRT for some time, I can say with certainty that there is really no way to "force" a user to run a script. You can manipulate things such that the way to work around running the script can be obfuscated, but it can't be forced. SecureCRT is not designed to work like that. As I think about it, it may be possible to do a little more than just obfuscate things, but this would require disabling much of SecureCRT's functionality. Do you want the users to have access to tabs? What version of SecureCRT are you using in your organization?

If you just want the script to run when a connection is established, then you can enable the Logon script: option located in the Connection / Logon Actions category of the Session Options dialog.

If you have the ability to access the place where you have seen your goal achieved, please get the information. I would certainly be interested in knowing what they have done.
Quote:
The code i posted is not tested. Nor does it work. It actually has a permanent loop on the prompt box. it was just pasted as an example of the goal i'm trying to use to hopefully give some clue to anyone wondering. I basically took versions from other pieces of things ive seen and meshed them together. I've gotten the script to work (minus the loop i had issues with, but will work on later - likely a syntax thing).
You can add a conditional statement to exit the loop so you don't have an infinite loop. For example:
Code:
Exit Do
Quote:
user loads securecrt
upon entering config t, user is prompted by a window asking for ticket
Would you provide more explicit details between these two steps? Knowing the exact work flow is important to be able to provide suggestions to accomplish your goal.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 09-11-2012, 05:24 PM
tard01 tard01 is offline
Registered User
 
Join Date: Sep 2012
Posts: 3
Quote:
Would you provide more explicit details between these two steps? Knowing the exact work flow is important to be able to provide suggestions to accomplish your goal.
the steps of the script is the easy part, it's already functional (minus the loop) in the code posted earlier. i'm less concerned about getting the function of the script working. (though i do plan on expanding to figuring out how to send an email, like our last project did).



the reason i was posting here was in hopes of figuring out how it was 'hidden'. For instance, the users never clicked the scripts tab to turn it off/on. If they opened securecrt, it was automatically ready to go. How they accomplished that is a complete mystery to me. The only way i knew to bypass it was to use a different tool, which was a big no-no there. Unfortunately i do not recall if there was anything even visible in the scripts tab. I never checked.

As far as removing functionality, i never noticed any hindrances (at least for the purposes we use securecrt for). We could still use tabs, change settings, add login scripts, add hotkeys, etc.

I wish i could provide more info regarding what was used before, that would be helpful to me as well, hah. The burden is knowing it's possible, but not knowing the bridge to get there. That's what i'm aiming to figure out.
Reply With Quote
  #6  
Old 09-12-2012, 12:17 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi tard01,

As mentioned previously, you can automatically launch a script upon connecting by defining a Logon script for the session (or Default Session if you are using Quick Connect). This is easy to circumvent, but it is one way you can allow a user to connect and run a script without any user interaction other than connecting.

Another way that is as easily circumvented is to launch the script from the command-line, but this only applies to the first tab. If the user launches another session in another tab, then they will not have the script running.

Here is an example command-line that will launch a script when starting SecureCRT:
Code:
C:\Program Files\VanDyke Software\SecureCRT>SecureCRT /script c:\Users\<username>\Desktop\ticket.vbs
Scripts are currently scoped to the tab on which they are running rather than for the entire SecureCRT instance. It is possible to iterate over tabs using a single script from the first tab (or the tab on which the script was started), but this is not terribly useful when a user is trying to interact with a specific tab. Imagine the situation where the user is typing something in a specific tab and the script changed focus to another tab as it was iterating over all open tabs, this could be a simple irritation or a disaster depending on how things progressed.

Do either of these options sound like they might work for you?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 02:34 AM.