#209822 - 2015-01-14 01:32 PM
Another VBS to KIX...
|
ahven
Just in Town
Registered: 2013-10-30
Posts: 3
Loc: Croatia
|
Please help!! I have a .vbs script I have to push to a group of users. I've been reading topics about how to do that, but with no result...I'm only dumber and dumber... I am a newbie in scripting and I really need help. I have found an UDF to automatically do that, but I can't make it to work... Please help!!
This is the script i need to push or convert in .kix format...
'Name: firefox_ntlm_preference_conf.vbs
'Author: Matt Martz <mdmartz@sivel.net>
'Date: 2007-05-29
'
'This script is designed to allow an organization to manage a list of sites that Firefox will send
'NTLM authentication to. This list is similar to the Local Intranet zone located in the Internet
'Explorer configuration options. With this preference enabled users will be automatically
'authenticated to sites which Internet Explorer would automatically be authenticated to.
'
'Note from the author:
' 1) I don't claim that this (script) is well written. It started as a script to just append the
' proposed site list to the end of the file and grew into a beast that would add the proposed
' site list and and sites that were configured by the user that didn't exist in the proposed
' site list
' 2) VBScript sucks at parsing and editing files. It wasn't meant for this purpose but with
' some innovation can be made to do what you want. Once again this is sloppy code and it
' would be more efficient written in a different language. But VBScript is natively supported
' on Windows which makes it easy for group policy deployment
' 3) I'm sure something else sucks about this script but I just haven't found it yet...So if you
' find something else that sucks you can let me know at the above email address and I'll see
' if I can make it suck less.
'
'Define Variables
option explicit
Dim fsObj, WshShell, fullpath, SubFolders, prefsfile, strLine
Dim strSiteList, strAppData, strFireProf, strProfFolder, strSearchString
Dim Folder, i, arrSiteFirst, arrSiteLast, strNewContents
Dim intMatchNTLM, strLineResult, intMatchLine, strAddExistSiteList
Dim arrCurSiteList, intCurSiteArrayLength, strExistSiteList
Dim arrSiteList, intSiteArrayLength, i_addsite, intExistSiteListLen
'Configure Environment
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject( "WScript.Shell" )
'Define the path to the profiles directory for Firefox
strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%")
strFireProf = "\Mozilla\Firefox\Profiles\"
'Check if firefox even has a profiles directory, if not than quit
If fsObj.FolderExists(strAppData & strFireProf) = False Then
wscript.quit
End If
'Define the proposed site list, split it into an array and determine length of array
'strSiteList should be a list of sites beginning with http:// or https://
'Only the DNS portion of the site should follow and there should be no trailing slash
'THIS (strSiteList) SHOULD BE THE ONLY VARIABLE THAT NEEDS CONFIGURATION
strSiteList = "http://10.1.0.154:8080/more/"
arrSiteList = Split(strSiteList, ",", -1, 1)
intSiteArrayLength = UBound(arrSiteList)
'Create an array of the subfolders in the profiles directory (there should only be one)
Set fullpath = fsObj.GetFolder(strAppData & strFireProf)
Set Subfolders = fullpath.subfolders
'Set the full path of the prefs.js file
For Each Folder in Subfolders
strProfFolder=Folder
Set prefsfile = fsObj.OpenTextFile(Folder & "\prefs.js", 1, True)
Next
'Lets load the prefsfile as a string for easy searching and then search for the preference we are looking for
'If found intMatchNTLM will be greater than 0
strSearchString = prefsfile.ReadAll
intMatchNTLM = InStr(strSearchString, "network.automatic-ntlm-auth.trusted-uris")
prefsfile.close
'Lets reopen the prefs.js file so we are at the beginning
Set prefsfile = fsObj.OpenTextFile(strProfFolder & "\prefs.js", 1, True)
'Now we do a while loop to parse the file and look for the ntlm preference
do while prefsfile.AtEndOfStream = 0
'Read in the current line and check for presence of the preference name
'If found intMatchLine will be greater than 0
strLineResult = prefsfile.ReadLine
intMatchLine = InStr(strLineResult, "network.automatic-ntlm-auth.trusted-uris")
'Check if the preference exists and if so...
if intMatchLine>0 Then
'Format the string, removing unwanted characters so delimiting is easier and convert to an array
strLineResult = Replace(strLineResult, chr(34), "")
strLineResult = Replace(strLineResult, ")", "")
strLineResult = Replace(strLineResult, ";", "")
arrCurSiteList = Split(strLineResult, ",", -1, 1)
'Get the length of the array and loop it to create a list of sites that are in the existing list but not in the proposed list
intCurSiteArrayLength = UBound(arrCurSiteList)
for i=1 to intCurSiteArrayLength
strExistSiteList = strExistSiteList & "," & arrCurSiteList(i)
Next
intExistSiteListLen = Len(strExistSiteList)
strExistSiteList = Right(strExistSiteList, intExistSiteListLen-2)
strAddExistSiteList = strExistSiteList
for i_addsite=0 to intSiteArrayLength
strAddExistSiteList = Replace(strAddExistSiteList,arrSiteList(i_addsite), "")
next
'Continuing with the above comment we need to check for formatting issues caused by removing records and fix them
strAddExistSiteList = Replace(strAddExistSiteList,",,", ",")
if InStr(strAddExistSiteList, ",") = 1 then
strAddExistSiteList = Right(strAddExistSiteList, Len(strAddExistSiteList)-1)
end if
if InStrRev(strAddExistSiteList, ",") = Len(strAddExistSiteList) and InStrRev(strAddExistSiteList, ",") <> 0 then
strAddExistSiteList = Left(strAddExistSiteList, Len(strAddExistSiteList)-1)
end if
if Len(strAddExistSiteList) = 0 Then
strSiteList = strSiteList
strSiteList = Replace(strSiteList,",,", ",")
else
strSiteList = strSiteList & "," & strAddExistSiteList
strSiteList = Replace(strSiteList,",,", ",")
end if
end If
Loop
'Now that we have the list of sites to match the proposed list plus the sites that didn't overlap between existing and proposed
'If the preference was not set at all we add just the proposed list
if intMatchNTLM<1 Then
'Open the file for appending as we aren't editing the contents
Set prefsfile = fsObj.OpenTextFile(strProfFolder & "\prefs.js", 8, True)
prefsfile.writeline("user_pref(" & chr(34) & "network.automatic-ntlm-auth.trusted-uris" & chr(34) & ", " & chr(34) & strSiteList & chr(34) & ");")
prefsfile.close
else
'If the existing list is longer than the proposed list and the existing list contains sites then quit
if Len(strExistSiteList) >= Len(strSiteList) and Len(strAddExistSiteList) = 0 Then
wscript.quit
'else lets check to see how we add the list
else
'Open the file for reading
Set prefsfile = fsObj.OpenTextFile(strProfFolder & "\prefs.js", 1, True)
'Loop the file writing all lines excluding the preference we are writing to a string for easy manipulation
Do Until prefsfile.AtEndOfStream
strLine = prefsfile.Readline
strLine = Trim(strLine)
If strLine <> "user_pref(" & chr(34) & "network.automatic-ntlm-auth.trusted-uris" & chr(34) & ", " & chr(34) & strExistSiteList & chr(34) & ");" Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
prefsfile.close
'Lets reopen the file in editing mode and write the contents of the file minus the preference we are setting
Set prefsfile = fsObj.OpenTextFile(strProfFolder & "\prefs.js", 2, True)
prefsfile.write strNewContents
prefsfile.close
'Now lets reopen the file in append mode and append the preference we are setting to the end
Set prefsfile = fsObj.OpenTextFile(strProfFolder & "\prefs.js", 8, True)
prefsfile.writeline("user_pref(" & chr(34) & "network.automatic-ntlm-auth.trusted-uris" & chr(34) & ", " & chr(34) & strSiteList & chr(34) & ");")
prefsfile.close
end if
end If
|
|
Top
|
|
|
|
#209827 - 2015-01-14 03:03 PM
Re: Another VBS to KIX...
[Re: Lonkero]
|
ahven
Just in Town
Registered: 2013-10-30
Posts: 3
Loc: Croatia
|
If you could help me I would probably live a few year more...:D Thank you...
Btw...how is that suppose to work? http://www.kixtart.org/udf/
|
|
Top
|
|
|
|
#209828 - 2015-01-14 05:00 PM
Re: Another VBS to KIX...
[Re: ahven]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Just out of boredom, I translated the script. I did not test or optimize any code however, use at your own risk.
;Name: firefox_ntlm_preference_conf.vbs
;Author: Matt Martz
;Date: 2007-05-29
;
;This script is designed to allow an organization to manage a list of sites that Firefox will send
;NTLM authentication to. This list is similar to the Local Intranet zone located in the Internet
;Explorer configuration options. With this preference enabled users will be automatically
;authenticated to sites which Internet Explorer would automatically be authenticated to.
;
;Note from the author:
; 1) I don't claim that this (script) is well written. It started as a script to just append the
; proposed site list to the end of the file and grew into a beast that would add the proposed
; site list and and sites that were configured by the user that didn't exist in the proposed
; site list
; 2) VBScript sucks at parsing and editing files. It wasn't meant for this purpose but with
; some innovation can be made to do what you want. Once again this is sloppy code and it
; would be more efficient written in a different language. But VBScript is natively supported
; on Windows which makes it easy for group policy deployment
; 3) I'm sure something else sucks about this script but I just haven't found it yet...So if you
; find something else that sucks you can let me know at the above email address and I'll see
; if I can make it suck less.
;
;Define Variables
$=SetOption('Explicit','On')
Dim $fsObj, $WshShell, $fullpath, $SubFolders, $prefsfile, $strLine
Dim $strSiteList, $strAppData, $strFireProf, $strProfFolder, $strSearchString
Dim $Folder, $i, $strNewContents
Dim $intMatchNTLM, $strLineResult, $intMatchLine, $strAddExistSiteList
Dim $arrCurSiteList, $intCurSiteArrayLength, $strExistSiteList
Dim $arrSiteList, $intSiteArrayLength, $i_addsite, $intExistSiteListLen
;Configure Environment
$fsObj = CreateObject("Scripting.FileSystemObject")
$WshShell = CreateObject( "WScript.Shell" )
;Define the path to the profiles directory for Firefox
$strAppData = $WshShell.ExpandEnvironmentStrings("%APPDATA%")
$strFireProf = "\Mozilla\Firefox\Profiles\"
;Check if firefox even has a profiles directory, if not than quit
If NOT $fsObj.FolderExists($strAppData + $strFireProf)
Exit 0
EndIf
;Define the proposed site list, split it into an array and determine length of array
;$strSiteList should be a list of sites beginning with http:// or https://
;Only the DNS portion of the site should follow and there should be no trailing slash
;THIS ($strSiteList) SHOULD BE THE ONLY VARIABLE THAT NEEDS CONFIGURATION
$strSiteList = "http://10.1.0.154:8080/more/"
$arrSiteList = Split($strSiteList, ",", -1, 1)
$intSiteArrayLength = UBound($arrSiteList)
;Create an array of the subfolders in the profiles directory (there should only be one)
$fullpath = $fsObj.GetFolder($strAppData + $strFireProf)
$SubFolders = $fullpath.subfolders
;Set the full path of the prefs.js file
For Each $Folder in $SubFolders
$strProfFolder=$Folder
$prefsfile = $fsObj.OpenTextFile($Folder + "\prefs.js", 1, 1)
Next
;Lets load the prefsfile as a string for easy searching and then search for the preference we are looking for
;If found $intMatchNTLM will be greater than 0
$strSearchString = $prefsfile.ReadAll
$intMatchNTLM = InStr($strSearchString, "network.automatic-ntlm-auth.trusted-uris")
$prefsfile.close
;Lets reopen the prefs.js file so we are at the beginning
$prefsfile = $fsObj.OpenTextFile($strProfFolder + "\prefs.js", 1, 1)
;Now we do a while loop to parse the file and look for the ntlm preference
While $prefsfile.AtEndOfStream = 0
;Read in the current line and check for presence of the preference name
;If found $intMatchLine will be greater than 0
$strLineResult = $prefsfile.ReadLine
$intMatchLine = InStr($strLineResult, "network.automatic-ntlm-auth.trusted-uris")
;Check if the preference exists and if so...
If $intMatchLine>0
;Format the string, removing unwanted characters so delimiting is easier and convert to an array
$strLineResult = Replace($strLineResult, chr(34), "")
$strLineResult = Replace($strLineResult, ")", "")
$strLineResult = Replace($strLineResult, ";", "")
$arrCurSiteList = Split($strLineResult, ",", -1, 1)
;Get the length of the array and loop it to create a list of sites that are in the existing list but not in the proposed list
$intCurSiteArrayLength = UBound($arrCurSiteList)
For i=1 to $intCurSiteArrayLength
$strExistSiteList = $strExistSiteList + "," + $arrCurSiteList[$i]
Next
$intExistSiteListLen = Len($strExistSiteList)
$strExistSiteList = Right($strExistSiteList, $intExistSiteListLen-2)
$strAddExistSiteList = $strExistSiteList
For $i_addsite=0 to $intSiteArrayLength
$strAddExistSiteList = Replace($strAddExistSiteList,$arrSiteList[$i_addsite], "")
Next
;Continuing with the above comment we need to check for formatting issues caused by removing records and fix them
$strAddExistSiteList = Replace($strAddExistSiteList,",,", ",")
If InStr($strAddExistSiteList, ",") = 1
$strAddExistSiteList = Right($strAddExistSiteList, Len($strAddExistSiteList)-1)
EndIf
If InStrRev($strAddExistSiteList, ",") = Len($strAddExistSiteList) and InStrRev($strAddExistSiteList, ",") <> 0
$strAddExistSiteList = Left($strAddExistSiteList, Len($strAddExistSiteList)-1)
EndIf
If Len($strAddExistSiteList) = 0
$strSiteList = $strSiteList
$strSiteList = Replace($strSiteList,",,", ",")
Else
$strSiteList = $strSiteList + "," + $strAddExistSiteList
$strSiteList = Replace($strSiteList,",,", ",")
EndIf
EndIf
Loop
;Now that we have the list of sites to match the proposed list plus the sites that didn't overlap between existing and proposed
;If the preference was not set at all we add just the proposed list
If $intMatchNTLM<1
;Open the file for appending as we aren't editing the contents
$prefsfile = $fsObj.OpenTextFile($strProfFolder + "\prefs.js", 8, 1)
$prefsfile.writeline("user_pref(" + chr(34) + "network.automatic-ntlm-auth.trusted-uris" + chr(34) + ", " + chr(34) + $strSiteList + chr(34) + ");")
$prefsfile.close
Else
;If the existing list is longer than the proposed list and the existing list contains sites then quit
If Len($strExistSiteList) >= Len($strSiteList) and Len($strAddExistSiteList) = 0
Exit 0
;else lets check to see how we add the list
Else
;Open the file for reading
$prefsfile = $fsObj.OpenTextFile($strProfFolder + "\prefs.js", 1, 1)
;Loop the file writing all lines excluding the preference we are writing to a string for easy manipulation
Do Until $prefsfile.AtEndOfStream
$strLine = $prefsfile.Readline
$strLine = Trim($strLine)
If $strLine <> "user_pref(" + chr(34) + "network.automatic-ntlm-auth.trusted-uris" + chr(34) + ", " + chr(34) + $strExistSiteList + chr(34) + ");"
$strNewContents = $strNewContents + $strLine + @CRLF
EndIf
Loop
$prefsfile.close
;Lets reopen the file in editing mode and write the contents of the file minus the preference we are setting
$prefsfile = $fsObj.OpenTextFile($strProfFolder + "\prefs.js", 2, 1)
$prefsfile.write($strNewContents)
$prefsfile.close
;Now lets reopen the file in append mode and append the preference we are setting to the end
$prefsfile = $fsObj.OpenTextFile($strProfFolder + "\prefs.js", 8, 1)
$prefsfile.writeline("user_pref(" + chr(34) + "network.automatic-ntlm-auth.trusted-uris" + chr(34) + ", " + chr(34) + $strSiteList + chr(34) + ");")
$prefsfile.close
EndIf
EndIf
Edited by Arend_ (2015-01-15 09:25 AM) Edit Reason: Fixed a comment
|
|
Top
|
|
|
|
#209836 - 2015-01-15 11:57 AM
Re: Another VBS to KIX...
[Re: Arend_]
|
ahven
Just in Town
Registered: 2013-10-30
Posts: 3
Loc: Croatia
|
Thank you so much guya...I came through and got it to work... Thanx for your help...:)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|