Page 1 of 1 1
Topic Options
#209822 - 2015-01-14 01:32 PM Another VBS to KIX...
ahven Offline
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...

 Code:
'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
#209825 - 2015-01-14 01:56 PM Re: Another VBS to KIX... [Re: ahven]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
That's long! I do the same thing with 4 lines in kixtart... \:o

If you want to save the users current settings, it is a bit more... Let me check back once I get to a computer...
_________________________
!

download KiXnet

Top
#209827 - 2015-01-14 03:03 PM Re: Another VBS to KIX... [Re: Lonkero]
ahven Offline
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_ Moderator Offline
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.
 Code:
;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
#209831 - 2015-01-14 07:27 PM Re: Another VBS to KIX... [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Arend - you missed a comment. \:\) Let's let Ahven find and polish this small amount of tarnish on an otherwise silver platter! \:D

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#209833 - 2015-01-15 04:05 AM Re: Another VBS to KIX... [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Not really translated if it uses wsh and so on. Didn't get my nose of my nfsroot project today but maybe tomorrow
_________________________
!

download KiXnet

Top
#209834 - 2015-01-15 09:22 AM Re: Another VBS to KIX... [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
 Originally Posted By: Glenn Barnas
Arend - you missed a comment. \:\)

You're right, sorry had to fix my own mistake \:\)

 Originally Posted By: Lonkero
Not really translated if it uses wsh and so on.

Like I said, I translated the code.
I also said I did not optimize the code; for the specific reason of people learning what the difference is between code in vbs and in kix.

Top
#209836 - 2015-01-15 11:57 AM Re: Another VBS to KIX... [Re: Arend_]
ahven Offline
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
#209844 - 2015-01-17 03:46 AM Re: Another VBS to KIX... [Re: ahven]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
tried to go all bulletproof and what not, really not tested though...
 Code:
old code removed, see following post for link to UDF with proper one


Edited by Lonkero (2015-01-18 05:23 PM)
_________________________
!

download KiXnet

Top
#209847 - 2015-01-17 04:08 AM Re: Another VBS to KIX... [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
even had to write it up as an udf, so here it is even with headers:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=209846#Post209846
_________________________
!

download KiXnet

Top
#209848 - 2015-01-18 01:11 AM Re: Another VBS to KIX... [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks Lonk - you da man
Top
#209849 - 2015-01-18 05:12 PM Re: Another VBS to KIX... [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
nothing special in that. I was looking at this approach and the reason why my settings are done in only couple of lines is that in my network I affect system-wide settings.
I think the UDF needs to have some additions since these settings are only for the currently loggedin user, do not lock/enforce the settings and per firefox manual shouldn't actually be set this way.
_________________________
!

download KiXnet

Top
#209850 - 2015-01-18 05:26 PM Re: Another VBS to KIX... [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
updated the udf to write to user.js instead.
_________________________
!

download KiXnet

Top
#209851 - 2015-01-18 08:16 PM Re: Another VBS to KIX... [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
updated the UDF with system wide settings with lock-enforce option.

I actually need to take the udf in to production at work since the lock-enforce is the only way to make sure the settings will get applied to new and old profiles


Edited by Lonkero (2015-01-18 08:27 PM)
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.079 seconds in which 0.035 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org