Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) UserID from environment? (Read 3765 times)
albeamer
Member
Members
*
Offline


No personal text

Posts: 20
Joined: Dec 2nd, 2002
UserID from environment?
Apr 15th, 2005 at 1:01am
Print Post Print Post  
Is there a way to pull the UserID from the environment?  My users must use a UserID and password to log in to our Citrix network, and I would like to eliminate the need for them to log in again for Sesame, though I need to use security based on security groups and userID.
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #1 - Apr 15th, 2005 at 2:16am
Print Post Print Post  
Try using @Shell to run SET command and redirect the SET output to a text file.  Read the contents of the text file.

Here is a basic structure, something like this:

vOK = @Shell("SET  > userid.txt")

Make a loop to read each line.
vFileHandle = fileOpen(userid.txt)
FileReadLn(vFileHandle,vSetString)

If vSetString contains "USERID" then parse out the value

Close the File
FileClose(vFileHandle)

----------------------------------
May also want to check out XSET utility for general management of system variables.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #2 - Apr 15th, 2005 at 2:27am
Print Post Print Post  
After I posted the earlier message, this problem seemed familar to me.  I just found this in my notes, dated 3/20/05.  I was trying to get the value of the Sesame Report Path so that I could redefine it dynamically.  It is currently untested, and was written on a Palm unit without access to Sesame at the time.  I ultimately dropped it when I came up with another solution.  It may be enough to get you started.
==================================
NOTE:  After I posted the code below, I did get around to making it correct in the next message.  You can generally ignore all of the code that follows in this message below.  Too many errors, but acceptable code follows in the next message, based on this outltine which was still basically correct, but still was a preliminary work in progrss.
=========================================
Code
Select All
/*
SESAME GET ENVIRONMENT VARIABLE
Reference for testing:
SESAME_REPORT_PATH=C:\Windows\Temp
*/

Function RetrieveSystemVariable(vEnvVariable) as String

	//Set variables for function
	var vEnvVariable as String		//System Environment Variable to get the value for
	var vEnvFile = "GetEnvValue.txt"	//Temp file name to hold system variable info
	var vSuccess as Int			//For @SHELL
	var vFileHandle as Int			//Identifier for temp file to be opened
	var vEnvValueString			//File string containing system variable info
	var vEnvValue as String			//Value for the specified system variable
	var vRetreiveSystemVariable as String	//Value returned from the function for the variable

	//var vEnvVariable = "SESAME_REPORT_PATH"//Reference for now

	//If file exists for someone else then wait 5 seconds and try again.
	WHILE FILEEXISTS(vEnvFile) THEN {
		LOITER(5000)
		//Need a timeout if stuck in loop
		}

	//Redirect SET to a file
	vSuccess = @SHELL("SET" + vEnvVariable + "> " + vEnvFile)

	//Read the file line and delete the file
	vFileHandle = OPENFILE(GetEnvFile)
	FILEREADLN(vFileHandle,1,vEnvValueSring)
	FILECLOSE(vFileHandle)
	FILEDELETE(vEnvFile)

	//Parse out the variable, length of file line less length of variable name plus 1
	vEnvValue = @RIGHT(vEnvValueString, @LENGTH(vEnvValueString) - @LENGTH(vEnvVariable) + 1)
	vRetrieveSystemVariable - vEnvValue

	Return vRetrieveSystemVariable

End Function 




« Last Edit: Apr 17th, 2005 at 2:36am by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #3 - Apr 17th, 2005 at 2:20am
Print Post Print Post  
Hello albeamer......

I made some time to work on the suggested outline above. 
Here is the final result, a function that can be called to return the value of a system environment variable:
Code
Select All
Function fnGetEnvVariable(vEnvVariable as String) as String

/* NOTE: This will not work in WIN9X environments.
It will work in XP/2K environments with the following qualification.
Sending SET plus a variable name will return ALL names that begin with the name asked for.
Example SET Temp may return many names that start with Temp.
Check your own operating system for more infor re the SET command.
In Microsoft systems type SET /? into the command prompt window or on the Start,Run utility
*/

var vEnvFile as String			//Temp file name to hold system variable info
var vOK as Int			   //For @SHELL
var vFileHandle as Int		   //Identifier for temp file to be opened
var vEnvValueString as String		  //File string containing system variable info
var vEnvValue as String		   //Value for the specified system variable

var vPos as Int				//Position indicator in string
var vLen as Int				//Length of a string

vEnvFile = "GetEnvValue.txt"
vEnvValueString = ""

//If file exists for someone else then wait 5 seconds and try again.
While FileExists(vEnvFile) {
	LOITER(5000)
	FileDelete(vEnvFile)
	}

//Redirect SET to a file
vOK = @Shell("SET " + vEnvVariable + " > " + vEnvFile)
If @Error then {
	vEnvValue = "Environment variable " + vEnvVariable + " not defined"
	} ELSE {
	//Read the file line and delete the file
	vFileHandle = FileOpen(vEnvFile)
	FileSeek(vFileHandle,0)
	FileReadLn(vFileHandle, vEnvValueString)
	FileClose(vFileHandle)
	FileDelete(vEnvFile)

	//Parse out the variable, from position of "=" to end of string
	vLen = @Len(vEnvValueString)
	vPos = @InStr(vEnvValueString,"=")
	If vPos = 0 THEN {
		vEnvValue = "Environment variable " + vEnvVariable + " not defined"
		} ELSE {
		vEnvValue = @MID(vEnvValueString, vPos+1, vLen-vPos)
		 }
	}

Return vEnvValue

End Function 



This can be easily tested by adding the following program to a command button on a form:
Code
Select All
var vInput as String
var vResult as String

vInput = @PromptForUserInput("Enter a VALID environmental variable name to get its value","USERNAME")

vResult = fnGetEnvVariable(vInput)

@MsgBox("The value of " + vInput,"","is " + vResult) 

This will prompt you for an input, but use the default value of USERNAME.

This is also limited to XP/NT/2K OS systems.  I do not about Linux, but WIN9X and earlier will not return the value of "SET vEnvVariable"

This works fine unless you ask for an environment value that does not exist.  I have been playing with error traps for @Shell with SET without any success.  Rather than holding this up for that correction, I thought I would provide this portion for you.  Unfortunately, you will see a brief "black box flash" as @Shell is executed.  This will not run with @ASynchShell which is supposed to eliminate the "black box flash".

I will also delete/annotate  the earlier code since it was not correct, and needed a lot of corrections.  At least the structure was correct.




« Last Edit: Apr 17th, 2005 at 4:21pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #4 - Apr 17th, 2005 at 3:09am
Print Post Print Post  
I also just realized that you wanted a value before the user started using Sesame, needed for login.  In that case the function above could be called in the StartUp programming if that programming runs before login is called for.  I doubt that it runs first, I would suspect that authentication happens before that programming section.  I cannot test that right now, so I have no definite answer.

I do not know of any Startup Switch in Seseame that allows you to send the name/password as parameters, but that sounds like a good tool for next release. Many other programs do allow that.  I like the way you think! Roll Eyes

So, without a Startup Switch, I don't see how you could create a batch file or a script to start Sesame without having to log in if security is set.  If you could do that then you could just use %USERNAME% as I was extracting in the function that I created.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: UserID from environment?
Reply #5 - Apr 17th, 2005 at 11:38am
Print Post Print Post  
Bob,
On linux, you should replace:
Code
Select All
 vOK = @Shell("SET " + vEnvVariable + " > " + vEnvFile) 

with:
Code
Select All
 vOK = @Shell("set | grep -i " + vEnvVariable + " > " + vEnvFile) 

or with:
Code
Select All
 vOK = @Shell("printenv | grep -i " + vEnvVariable + " > " + vEnvFile) 

depending on which shell (sh, ksh, csh, bash, tcsh, ...), the user is running.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #6 - Apr 17th, 2005 at 4:30pm
Print Post Print Post  
Thanks Mark, I will add those lines to my notes as other options.

Do you have any clues on responding to invalid value request?  I know it returns an error code =1 but @ERROR does not seem to trap that.  I put an If @Error statement right after the @Shell with instructions to WriteLn for testing, but it halts before it can WriteLn, and forces Sesame to shut down.

I am thinking now that I may have to create a batch file and trap the error code there instead of catching it in Sesame.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: UserID from environment?
Reply #7 - Apr 17th, 2005 at 5:40pm
Print Post Print Post  
@Shell calls the "system" function call from the operating system library  in both Win32 and Linux. It returns to SBasic the same value that the system() function returns to Sesame - which in turn, returns the value returned by the command interpreter used. @Error only gets set for internal errors in runtime - not for OS errors.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #8 - Apr 18th, 2005 at 1:12am
Print Post Print Post  
Thanks for the clarification Mark. 
I have modified the programming so that is now provides a message to the user when a bad value is asked for.
This is a big improvement over forcing Sesame to shut down.
Code
Select All
Function fnGetEnvVariable(vEnvVariable as String) as String

/*    ==========================
Created by Bob Hansen, Sensible Solutions Inc., Salem NH rmhansense@sensiblesolutions.org

NOTE: This will not work in WIN9X environments.

It will work in XP/2K environments with the following qualification.
Sending SET plus a variable name will return ALL names that begin with the name asked for.
Example SET Temp may return many names that start with Temp.
Check your own operating system for more infor re the SET command.
In Microsoft systems type SET /? into the command prompt window or on the Start,Run utility

vAction has different values remarked out for Linux systems, provided by Mark Lasersohn.
//  ======================================
*/

var vEnvFile as String			  //Temp file name to hold system variable info
var vOK as Int				     //For @SHELL
var vFileHandle1 as Int			    //Identifier for temp file to be opened
var vEnvValueString as String		    //File string containing system variable info
var vEnvValue as String			     //Value for the specified system variable

var vPos as Int				    //Position indicator in string
var vLen as Int				    //Length of a string

var vBatchFile as String			//Name of temp batch file
var vAction as String				//The String to retrieve the environment value

vEnvFile = "GetEnvValue.txt"
vEnvValueString = ""

vBatchFile = "GetEnvValue.bat"

vAction = "SET " + vEnvVariable +" >" + vEnvFile
//For LINUX, use one of the following lines for vAction instead of the line above.
//depending on which shell (sh, ksh, csh, bash, tcsh, ...), is running.
//vAction = "set | grep -i " + vEnvVariable + " > " + vEnvFile
//vAction = "printenv | grep -i " + vEnvVariable + " > " + vEnvFile


//If file exists for someone else then wait 5 seconds and try again.
While FileExists(vEnvFile) {
	LOITER(5000)
	FileDelete(vEnvFile)
	}

//Start Function Execution =======================================

//Delete file if it exists
If FileExists(vBatchFile) THEN {
	FileDelete(vBatchFile)
	}

//Create Temp Batch File =======================
vFileHandle1 = fileOpen(vBatchFile)

//Write to Temp Batch File =======================
FileWriteLn(vFileHandle1,"@echo off")
FileWriteLn(vFileHandle1, vAction)
FileWriteLn(vFileHandle1, "IF errorlevel==1 goto NG")
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, "::OK")
FileWriteLn(vFileHandle1, "goto End")
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, ":NG")
FileWriteLn(vFileHandle1, "echo BAD-BAD-BAD > " + vEnvFile)
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, ":End")

//Close Batch file
FileClose(vFileHandle1)

//Run temp batch file to redirect value to a temp file
vOK=@AsynchShell(vBatchFile)

//Delete File =======================
Loiter(500)
If FileExists(vBatchFile) THEN {
	FileDelete(vBatchFile)
	}

//Read the file line and delete the file
vFileHandle1 = FileOpen(vEnvFile)
FileSeek(vFileHandle1,0)
FileReadLn(vFileHandle1, vEnvValueString)
FileClose(vFileHandle1)
FileDelete(vEnvFile)

//Parse out the variable, from position of "=" to end of string
vLen = @Len(vEnvValueString)
vPos = @InStr(vEnvValueString,"=")
If vPos = 0 THEN {
	vEnvValue = "Environment variable " + vEnvVariable + " is not defined"
	} ELSE {
	vEnvValue = @MID(vEnvValueString, vPos+1, vLen-vPos)
	}

Return vEnvValue

End Function
//============================================================= 


I have been unable to stop the "black box flash", but that is a minor inconvenience right now.

I have also placed this programming into the forum section for Programming Examples, under the subject: Get Environment Variable Value as a general purpose function.  Additional notes and history are included at that location.
« Last Edit: Apr 19th, 2005 at 9:48pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #9 - Apr 18th, 2005 at 2:31am
Print Post Print Post  
Hello albeamer..

I just finished a first draft of a utility that starts a Sesame database, goes to the Login Window and automatically enters the UserID and Password, and goes directly into Sesame as the appllication is programmed.

1.  It gets the UserID from the environment variables. 

2.  The Sesame is in a prompt window with a hard-coded default, and a browse button to select a different application if needed.

3.  The password is hardcoded.  But it could be set up to read the password from another source, perhaps a registry setting, an INI file, a password protected hidden file, another database with restricted access, etc.

4.  This could be set up to start immediately at login time, or it could be an icon on a desktop, or an icon on a Start Menu and called on demand.

5.  It could also be set up to default or load specific Sesame applications based on the User, Time of day, day of month, or other variables that could be defined.

Is this the type of utility you are looking for?



  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
albeamer
Member
Members
*
Offline


No personal text

Posts: 20
Joined: Dec 2nd, 2002
Re: UserID from environment?
Reply #10 - Apr 18th, 2005 at 3:20am
Print Post Print Post  
Absolutely.  I appreciate all of the work and trouble you are going through.  It looks like you will end up with a utility that will be useful to many developers.
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #11 - Apr 18th, 2005 at 3:58am
Print Post Print Post  
That might be possible, but I need to know what the product specs should be.  Getting the passwords automatically is probably the most difficult.  Since you have an immediate need, how would you suggest that the passwords get picked up?  Do you have access to all users passwords or is that under control of IT staff?  Is there an existing database, list, etc. that is available now?  Can you make a document/list , database, etc. that we can use for a lookup source?  We can make it hidden, readonly, and password protected so only anthorized users could maintain the list..

But there are problems with doing auto password entry, especially based on current user because users frequently forget to logout and other users are on line under another users name.  So using a utility like this has some security drawbacks.

What I am working on now could be set up to at least start the application, fill in the username and move to the password field and wait for password entry at that point.  It saves some mouse movement and data entry, and still provides some level of security.

Your thoughts?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
albeamer
Member
Members
*
Offline


No personal text

Posts: 20
Joined: Dec 2nd, 2002
Re: UserID from environment?
Reply #12 - Apr 18th, 2005 at 4:09am
Print Post Print Post  
I agree that it would be safer and better to just pull the userID from the environment and let the user enter the password.
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: UserID from environment?
Reply #13 - Apr 18th, 2005 at 4:49am
Print Post Print Post  
In your situation, what is the name of the environment variable that should be picked up for the value? 

Remember that Sesame passwords are Case Sensitive and must match exactly with the system value.

If you can provide me with the variable name, and a path and name of a Sesame application, I may be able to send you something in the next few days.  Picking away when some spare time comes up.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
albeamer
Member
Members
*
Offline


No personal text

Posts: 20
Joined: Dec 2nd, 2002
Re: UserID from environment?
Reply #14 - Apr 19th, 2005 at 7:20pm
Print Post Print Post  
The item that I would most like to pull would be
%USERNAME%

A couple of others that would be helpful would be
%HOMEPATH% and
%USERPROFILE%

The application is in the \Sesame\Data folder and is named Titleworx.

Thanks again.





  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print