#1
|
|||
|
|||
A script to change password in all stored sessions
Hello experts,
as per changing passwords for specific username post, I'd like to be able to change password for all stored sessions for a specific user. Is this even possible in SecureCRT's VBScript implementation? As per above post's postscript, my sessions are stored in hierarchy on per-function not on per-username structure, so, the hyperlinked "Making Configuration Changes to Multiple Sessions" isn't possible. Unless.... it's somehow possible to organise sessions as virtual sessions (pointing to actual) and group those. R's, Alex |
#2
|
|||
|
|||
![]()
The below code will iterate every session and (might*) update the password where username matches.
You must update the variable SESSION_ROOT with the location of your Sessions directory. Note: I couldn't find a crt.API call that would tell me the config path, so this hard-coded value is present. The following line is commented out which does the actual updating, so code is currently read-only. (AKA, i recommend backing up your sessions before running where it updates) Code:
# change_password(cfg, pw) (might*) - I say this MIGHT update because secure CRT stores passwords encrypted. Using SetOption("Password", password) does not actually store encrypted. The docs say this: Quote:
It's python, so indentation is very important to maintain. Code:
# $language = "Python" # $interface = "1.0" import os # Path to on-disk sessions in order to enumerate them SESSION_ROOT = "c:\\wherever\\your\\VanDyke\\scrt\\config\\Sessions" def ask_username(): return crt.Dialog.Prompt("Username", "") def ask_new_password(): return crt.Dialog.Prompt("New password", "") # update the secure crt session with new password def change_password(sess_cfg, password): sess_cfg.SetOption("Session Password Saved", 1) sess_cfg.SetOption("Password", password) sess_cfg.Save() # convert file system full\path\fname.ini to sCRT session\name def build_session_name(path, fname): # get the relative path to the session name sess_path = path[len(SESSION_ROOT):].lstrip("\\") # strip ".ini" sess_name = fname[:-4] return sess_path + "\\" + sess_name def main(): un = ask_username() if not un: return pw = ask_new_password() if not pw: return total = 0 changed_list = [] for root, dirs, files in os.walk(SESSION_ROOT): for fname in files: if fname == "__FolderData__.ini": continue if not fname.endswith(".ini"): continue total += 1 sess_name = build_session_name(root, fname) try: cfg = crt.OpenSessionConfiguration(sess_name) except Exception: # could not open session continue try: if cfg.GetOption("Username") == un: # change_password(cfg, pw) changed_list.append(sess_name) except Exception: # serial ports, etc don't have Username property continue # some stats message = "Total sessions: %d\n" % total message += "Changed sessions: %d\n" % len(changed_list) message += "\n".join(changed_list) crt.Dialog.MessageBox(message, "Updated Sessions Stats") main() |
#3
|
|||
|
|||
well, it will update the password field, but it will be unencrypted and I don't know if scrt will handle it ok.
Code:
S:"Password V2"=password Code:
S:"Password V2"=02:8438c3217d3f6643da23c64186cafa364a560fc4a6c7fb2501d1bf84018528cc6b868670f94beb4d6895bb9b715239849a23670a2fc8b347a8714c941fa3fe18 |
#4
|
|||
|
|||
![]()
Takeaways:
* It'd be nice if the API had a way to enumerate the sessions without resorting to examining the file system. * Using the API to set the password should encrypt the same as the GUI does. |
#5
|
|||
|
|||
Firstly, thank you for taking the time.
I'm ignorant of python language but it seems that SecureCRT isn't providing any special API, besides SetOption, method to facilitate changing (and encoding) of session password. Quote:
R's, Alex Last edited by epaalx; 06-07-2019 at 02:02 AM. |
#6
|
|||
|
|||
I would say it can already do this through the Connect Session Manager dialog. Either by selecting a top-level folder, or ctrl-clicking individual sessions and then right-click -> properties -> update password -> Ok.
|
#7
|
|||
|
|||
Greetings all,
Thanks for the feedback. I have entered a feature request to allow searching of sessions based on option values such as username, etc. If/when this is ever implemented, we will post here to let you all know!
__________________
Thanks, --Jon VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|