#208661 - 2014-03-04 01:24 PM
How do I get script to read multiple settings from one file?
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
Hi guys, I am busy trying to tidy up security in my coding today and while this coding works, its not really what I want.
Basically what this code does is it runs the function setpass which will set the username and password for IE Proxy server settings depending on the user logged on.
My problem is twofold. One I have to create a file for the proxy username and a separate file for the proxy password. The second problem is that I have to create a username file and password file for every proxy user. I currently only have about five proxy users (which will mean ten text files) as active directory groups are using one proxy username per group. For example students get the USA proxy username and staff get the China proxy username.
Is it possible to create ONE text file and have the script read that one file and allocate the username and password based on what active directory group they belong to? I am not sure if you can do that when you are reading normal text files.
The reason why I want the script to read the usernames and passwords from a text file is so that I can have one script that applies to all my clients and the clients have different usernames and passwords on site. The secondary consideration is that I want to ultimately encrypt the text file so that nobody snooping on the network can get the passwords.
Thanks Rob
;==================================================================================================================
; IE11 proxy authentication
;==================================================================================================================
setpass ("adminuser.txt", "adminpass.txt")
;================================================================================================
; Sets the default proxy username and password for IE for the logged on user
;================================================================================================
Function SetPass($PrintFile1, $PrintFile2)
$Handle = Freefilehandle ()
if $handle > 0
if Open ($handle, $ServerName + "\proxies\" + $Printfile1) = 0
$proxyuser = Readline($handle)
? $proxyuser
; WHILE @ERROR = 0
Close($handle)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF
if $handle > 0
if Open ($handle, $ServerName + "\proxies\" + $Printfile2) = 0
$proxypass = Readline($handle)
? $proxypass
; WHILE @ERROR = 0
Close($handle)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF
$shellcmd = 'cmdkey /generic: $ProxyServer /user: $proxyuser /pass: + $proxypass'
Shell $ShellCMD
EndFunction
|
Top
|
|
|
|
#208664 - 2014-03-04 04:25 PM
Re: How do I get script to read multiple settings from one file?
[Re: Glenn Barnas]
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
You people are so clever! I never really understood how kixtart uses INI files before, but this is a great example of how to get Kixtart to read very specific data within a file! I will definitely use this concept again. Mart I have used your suggestion as my proxy settings are not linked to any user accounts per se. So I have modified the script accordingly. The shiny new script is here!
proxyauthenticate ($inifile)
And the function
;================================================================================================
; Sets the default proxy username and password for IE for the logged on user
;================================================================================================
Function proxyauthenticate ($inifile)
$inifile = $ServerName + "\XXX\proxyauth.ini"
$groups = "Robert", "Is", "Wise", "And", "Wonderful"
For Each $group in $groups
If InGroup($group)
$proxyuser = ReadProfileString($inifile, $group, "username")
$proxypass = ReadProfileString($inifile, $group, "password")
$shellcmd = 'cmdkey /generic: $ProxyServer /user: $proxyuser /pass: + $proxypass'
Shell $ShellCMD
EndIf
Next
EndFunction
|
Top
|
|
|
|
#208671 - 2014-03-04 07:56 PM
Re: How do I get script to read multiple settings from one file?
[Re: Robdutoit]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
1. The argument list of a function is optional.. you can define 0 or more arguments, and define both required or Optional arguments.
2. OK
3. Once you have a config file, use it for everything. I usually have a "COMMON" section for general config settings.
4. Using Read/WriteProfileString handles all open/close operations - you don't need to do anything to use these commands. Because the Open, Read or Write, Close happens for each call, performance on large INI files, and any network based file (especially WAN!!) is mediocre to poor. This can be helped by either caching the content locally, enumerating the entire section with a single read (see EnumINI UDFs); or using my INIArray UDF, which reads the entire INI file into an in-memory array. The latter option helps on large network based files or INI files that exceed the 64KB limit.
You need to search for the WMIGetAV function - it was never published. I've used it internally with some customized/updated INI files, but what's in the Advanced Scripting forum is as current as what I have internally. You will need to review the instructions and update the INI file for the current versions of the AV software you use, but no code changes should be needed.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|