|
|
|||||||
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 Code: ;================================================================================================================== ; IE11 proxy authentication ;================================================================================================================== setpass ("adminuser.txt", "adminpass.txt") Code: ;================================================================================================ ; 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 |
||||||||
|
|
|||||||
You could use an ini file for this and use readprofilestring to get the data Eaxmple: Code: Break on $inifile = "pathandfilenamehere" $groups = "GroupA","GroupB" For Each $group in $groups If InGroup($group) $username = ReadProfileString($inifile, $group, @USERID + "username") $password = ReadProfileString($inifile, $group, @USERID + "passoword") ;do more stuff here EndIf Next Example ini file: Quote: [GroupA] usera1username=usernamegoeshere usera1password=passwordgoeshere usera2username=usernamegoeshere usera2password=passwordgoeshere usera3username=usernamegoeshere usera3password=passwordgoeshere [GroupB] userb1username=usernamegoeshere userb1password=passwordgoeshere userb2username=usernamegoeshere userb2password=passwordgoeshere userb3username=usernamegoeshere userb3password=passwordgoeshere The only thing with this that might be an issue is that if a user is a member of GroupA and GroupB the last (GroupB) username and password will be used. |
||||||||
|
|
|||||||
Alternativly: Code: [UserID01] Creds=password Proxy=proxy setting Glenn |
||||||||
|
|
|||||||
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! Code: proxyauthenticate ($inifile) And the function Code: ;================================================================================================ ; 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 |
||||||||
|
|
|||||||
I forgot to mention that I am going to use the cypher udf in the very near future. I will do that when I get around to tokenising all my scripts. At the moment I am busy updating and fixing and patching a lot of things. My next task is to finish completing the conversion of the autoit script that I found to check status of Anti virus. Once I have managed to convert it successfully, I will pop it onto Korg and perhaps you could use the script as a UDF as I am sure that other people would find it useful. |
||||||||
|
|
|||||||
FYI - You don't need to tokenize your script to use the tokenized function. Just call the correct version - 4.53 or 4.6x. As for your function
Glenn |
||||||||
|
|
|||||||
1. Are you saying that you don't need to use the syntax function (argument). The only reason that I passed the $inifile value was because I needed something to put in the (argument) part of the code. I defined inifile within the function as this time round the location of the inifile will be the same for all clients and logged on users, so I didn't want to define the variable each time in the main scripts. Are you saying that I could just use proxyauthenticate without any arguments in the brackets? 2. Servername is defined at the top of my UDF script as Global. The Servername variable is used throughout my scripts so I have defined it once at the top of the UDF.kix script. 3. I agree with point three. I think that I will rewrite the code so as not to hardcode the array. I need to modify the coding anyway as I don't want the function to write the proxy settings username and password every single login. I would rather the function checked whether the proxy authentication were set or not. 4. Oh yes, I forgot to ask how the readprofilestring works with opening and closing files. I will check that as well. I wasn't sure if it worked the same way as the Readline command. I want to tokensise all my scripts anyway, not just the file that contains passwords. I have never used the tokenising ability so I don't actually know how it works anyway. I have booked that in to do after I have finished updating the scripts as there are a number of changes that I need to make this week. I will have a look at that WMIGetAV function now. I didn't notice that one even though I checked the list of functions available. I was probably searching for virus or anti virus rather than AV. Thanks. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Oh I am looking at another function called GetAVinfo written by Lonkero. I thought that was the one that you meant as I could not find the one you mentioned. I think the GetAvinfo does the same thing as the WMIGetAV function. I just need to fix the coding with GetAvinfo as I am getting “Error in expression: this type of array not supported in expressions. The function I am looking at now is GetAVinfo() - retrieve antivirus product and status information! |
||||||||
|
|
|||||||
You can find WMIGetAVI() here. I'll cobble a test together today to insure it runs on W7/8. Glenn |
||||||||
|
|
|||||||
Well do have a look at the GetAVinfo UDF as well as its very simple coding which is great for people like me. I have determined that the problem is that it was designed for Windows Xp and Vista. I have already started modifying the coding to work on Windows 7 upwards, but I had not had time to finish that yet. But I found that udf to be quite simple so do look at that one as well as I think its quite good. Lonks one just uses securitycenter which is why its shorter. I will look at both of them but as I am already half way through fixing Lonkero's UDF which co-incidentally enough is the same script as the autoIT script except the AutoIT script includes the coding for windows 7 as well, so it should be a doddle to figure the rest out. |
||||||||
|
|
|||||||
let me know if you get a working outcome. I have securitycenter disabled, so can't test on my end without some voodoo. |