Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-07-2021, 05:21 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
ConnectInTab is preventing further session changes

Hi all,

I have a relatively simple script in VBS that catches a session pre-login and changes the credentials to match a template session in order to automate password changes across multiple random devices.
I have managed to achieve this by disconnecting the current session, then changing the config and spawning the new session in a new tab as below.

Most code has been omitted for brevity.

Code:
        crt.Session.Disconnect
        Call OSCCurrent.SetOption("Username", OSCCredential.GetOption("Username"))
        Call OSCCurrent.SetOption("Password", OSCCredential.GetOption("Password"))
        Call OSCCurrent.SetOption("Session Password Saved", true)
        Call OSCCurrent.SetOption("Use Script File", false)
        OSCCurrent.ConnectInTab
        Call OSCCurrent.SetOption("Use Script File", true)
        OSCCurrent.Save(crt.Session.Path)
It is working almost perfectly, however the issue I am having is that once the ConnectInTab method is called, the following SetOption to reenable the script afterwards is not being saved to the config file.
My guess is that the ConnectInTab method is either locking the config file so that subsequent changes are not processed, or that the connected session is constantly overwriting the config file with it's operating options. All prior changes are saved to the config file normally.

Any help to figure this out would be much appreciated.
  #2  
Old 04-07-2021, 07:45 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi oliver366370,

How is OSCCurrent object defined?

How many connected tabs are there after you call ConnectInTab()?

It would probably be best if you posted the entire script. If there is sensitive data you don't want to post to the forums, please send a copy to support@vandyke.com and reference Attn Brenda - Forum Thread #14490 in the subject line. You can redact sensitive data but leave enough info we can determine the intent (ie: it's an IP or hostname).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #3  
Old 04-07-2021, 08:00 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
Quote:
Originally Posted by bgagnon View Post
Hi oliver366370,

How is OSCCurrent object defined?

How many connected tabs are there after you call ConnectInTab()?

It would probably be best if you posted the entire script. If there is sensitive data you don't want to post to the forums, please send a copy to support@vandyke.com and reference Attn Brenda - Forum Thread #14490 in the subject line. You can redact sensitive data but leave enough info we can determine the intent (ie: it's an IP or hostname).
Hi Brenda, thanks for getting back to me so quickly.

OSCCurrent is defined by setting it to a instance of the OpenSessionConfiguration, and handing it the he current session path via crt.Session.Path.
During my testing the open session is the only one open, which is replaced with the new tabbed session as it is disconnected in script.
The script is not too long and does not contain sensitive information so I have put it below.

Code:
#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True

Sub Main()
    If crt.Arguments.Count <> 1 Then
        crt.Dialog.MessageBox("Incorrect number of arguments")
        Exit Sub
    End If

    Dim strCredentialPath, OSCCredential, OSCCurrent
    strCredentialPath = crt.Arguments.GetArg(0)
    
    On Error Resume Next
    Set OSCCredential = crt.OpenSessionConfiguration(strCredentialPath)
    Set OSCCurrent = crt.OpenSessionConfiguration(crt.Session.Path)
    
    If (OSCCurrent.GetOption("Username") <> OSCCredential.GetOption("Username")) Or (OSCCurrent.GetOption("Password") <> OSCCredential.GetOption("Password")) Or (OSCCurrent.GetOption("Session Password Saved") <> true) Then
        crt.Session.Disconnect
        Call OSCCurrent.SetOption("Username", OSCCredential.GetOption("Username"))
        Call OSCCurrent.SetOption("Password", OSCCredential.GetOption("Password"))
        Call OSCCurrent.SetOption("Session Password Saved", true)
        Call OSCCurrent.SetOption("Use Script File", false)
        OSCCurrent.ConnectInTab
        Call OSCCurrent.SetOption("Use Script File", true)
        OSCCurrent.Save(crt.Session.Path)
    End If
    
    If Err.Number <> 0 Then
        crt.Dialog.MessageBox("An error has occured while replicating the credentials from the template session")
        'crt.Dialog.MessageBox(Err.Description)
        Exit Sub
    End If
End Sub
  #4  
Old 04-07-2021, 03:59 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi oliver366370,

The developers are investigating the Logon script option not being enabled by the script.

We feel this feature request would be helpful in accomplishing the objective also.

I have added this thread to a feature request in our product enhancement database for the ability to run logon script prior to or without initiating the Connect process. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include Feature Request - Forum Thread #14490 in the subject line or use this form from the support page of our website.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #5  
Old 04-08-2021, 02:45 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
Quote:
Originally Posted by bgagnon View Post
Hi oliver366370,

The developers are investigating the Logon script option not being enabled by the script.

We feel this feature request would be helpful in accomplishing the objective also.

I have added this thread to a feature request in our product enhancement database for the ability to run logon script prior to or without initiating the Connect process. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include Feature Request - Forum Thread #14490 in the subject line or use this form from the support page of our website.
Hi Brenda, thank you for looking into this for me.

Is it then fair to say that not being able to set the "Use Script File" option to true in script may be a unintentional bug and not a result of my misunderstanding of the SecureCRT object methods?
I do agree that having the option to run a script pre-connection would be incredibly useful. At the moment how I have gotten this to work, is by using the option to display login prompts on screen. This allows the script to run pre-login and complete the logic needed. Ending and restarting the session pretty well accomplished what I need to do to run the session with the new options.
The script disable and script enable options are in theory to prevent an infinite script invocation loop occurring when the script invokes a connection of the session. During testing I saw that SecureCRT seems to prevent a script running that already has an instance running. This means I should be able to effectively work around the issue by suppressing warnings on the child session invocation, however I generally wouldn't call this best practice and could cause issues down the line.
I will keep an eye out for the developers input as this is the last part that is preventing this incredibly useful script from working.

Edit: What I put down about alert suppression seems to be false. In addition through more testing I have determined that the ConnectInTab method is indeed the culprit for the following SetOption not running. If the ConnectInTab is never called then the setting of the use script option is completed successfully.
Is there any way to work around this issue? I have tried declaring the ConnectInTab as a session object and looping until connected becomes false, however this spiked the CPU to 100% while it is stuck in the loop.
Attached Images
File Type: png mrnSpab.png (23.5 KB, 1236 views)

Last edited by jdev; 05-18-2021 at 07:15 AM. Reason: Do not link to third party sites for images. Upload images and link to them as per https://forums.vandyke.com/showthread.php?t=14212
  #6  
Old 04-08-2021, 11:44 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi oliver366370,
Quote:
Is it then fair to say that not being able to set the "Use Script File" option to true in script may be a unintentional bug and not a result of my misunderstanding of the SecureCRT object methods?
Yes, we believe it is changed behavior. That is why the developers are investigating. I will post here when I have further news.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #7  
Old 05-18-2021, 06:49 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
Hi Brenda,

Hope you are doing well.
Has there been any updates from the investigation? Is there a workaround that can be used to spawn a new session without activating the logon script?

Kind regards,
Oliver
  #8  
Old 05-19-2021, 03:21 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Oliver,

Sorry, I am checking ...
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #9  
Old 05-21-2021, 12:39 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Oliver,

The product manager said they are still investigating the issue.

We did think there were a few more feature requests that could help you accomplish the task if they get implemented in the future.
  • Credentials substitution database
  • Add Sessions object to scripting API for iterating over all sessions in the Connect dialog
  • Allow the user to run an alternate script, either before or after connecting to a Proxy Server (pre-connect script)
Should a future release of SecureCRT include any of these features, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread 14490" in the subject line or use this form from the support page of our website.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #10  
Old 06-09-2021, 09:03 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Oliver,

The SessionConfiguration Object Help topic is going to be updated to clarify the expected behavior.

However, the developers did suggest one change to your script that might help.

Code:
    If (OSCCurrent.GetOption("Username") <> OSCCredential.GetOption("Username")) Or (OSCCurrent.GetOption("Password") <> OSCCredential.GetOption("Password")) Or (OSCCurrent.GetOption("Session Password Saved") <> true) Then
        crt.Session.Disconnect
        OSCCurrent.SetOption "Username", OSCCredential.GetOption("Username")
        OSCCurrent.SetOption "Password", OSCCredential.GetOption("Password")
        OSCCurrent.SetOption "Session Password Saved", true
        OSCCurrent.SetOption "Use Script File", false
        OSCCurrent.Save
        OSCCurrent.ConnectInTab
        crt.Dialog.MessageBox("We are supposedly ""connected"" now.")

        Set OSCCurrent = crt.Session.Config
        OSCCurrent.SetOption "Use Script File", true
        OSCCurrent.Save
    End If
The line in red is what you would want to add.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #11  
Old 07-08-2021, 04:56 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
Success!

Hi Bredna,

Apologies for the delay, I didn't have email alerts set for this thread.
The change the devs recommended has worked!
I believe a more elegant solution should be in place (for example an encrypted credential library where you can assign credential objects to the logins of an individual session).
However, in the meantime this works well as a workaround using dummy sessions.
Thank you and the devs for all your assistance!

Kind regards,
Oliver
Closed Thread

Tags
vbs

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 11:14 PM.