Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'This script is intended to help automate account setups for Openfire
- ' (XMPP) chat server + Pidgin implementations in a corporate network.
- ' You can use this script to execute after the Pidgin install (or
- ' at Windows logon to configure an XMPP account for a local server.
- '
- 'Instructions:
- ' In the same folder where this script "scriptfolder" is stored,
- ' mimic the following structure
- ' x:\scriptfolder
- ' \thisscript.vbs
- ' \xml
- ' \plugins
- ' \files
- '
- '**** Making the account template XML ****
- 'On a workstation, install and configure Pidgin as you would for
- ' your users. Select the plugins you wish to use, configure
- ' settings etc. Note that this script doesn't yet copy over
- ' custom (non-native installed) emoticons, sounds, themes, etc.
- '
- 'Where the account profile is stored:
- ' XP: c:\documents and settings\username\application data\.purple
- ' Vista/7: C:\Users\username\appdata\Roaming\.purple
- '
- 'NOTE: The general account setup is saved in 'accounts.xml.'
- ' Overall client preferences are stored in 'prefs.xml.'
- '
- '**** Copy the connection certificates to your scriptfolder ****
- 'From a working system that has already been set up with Pidgin and
- ' your XMPP server, you will want to find the 'certificates' folder
- ' from your profile.
- '
- 'Browse into the .purple folder and copy the 'certificates'
- ' folder to the 'files' subfolder where your script resides.
- '
- ' -- you should now see x:\scriptfolder\files\certificates
- '
- 'From the main .purple folder, copy 'prefs.xml' and 'accounts.xml'
- ' to the main folder where your script resides.
- '
- ' -- i.e. x:\scriptfolder\prefs.xml, x:\scriptfolder\accounts.xml
- '
- '**** Clean up your accounts.xml template file ****
- 'NOTE that you will want to clean up the accounts.xml file before
- ' using it as a template. This will be used if Pidgin is installed
- ' but no XMPP account has been set up yet - i.e. the script copies
- ' this file into the user's account folder and makes it a framework
- ' by which to work with for the rest of the script.
- '
- '**** Got plugins? ****
- 'Copy any plugins you wish to deploy to the client (defaults to
- ' Pidgin path\plugins) into the 'plugins' subfolder where your
- ' script resides. Note that you may need to enable these manually
- ' - unless you've configured it already and it has been stored
- ' in prefs.xml.
- '
- ' -- i.e. x:\scriptfolder\plugins\plugin.dll
- If instr(lcase(Wscript.FullName),"wscript.exe") then
- bDebug = false
- Else
- bDebug = true
- End If
- on error goto 0
- Dim objShell, objFSO
- Dim sComputerName, sUserName, sServerName, sFileTransferProxy, sDomain, iPort, sConnectionSecurity
- Dim bSetBlankPassword
- '=============================================================================
- 'Set up some variables that we need to use for our environment
- sServerName = "im.yourdomain.com"
- sFileTransferProxy = "im.yourdomain.com"
- sDomain = "yourdomain"
- iPort = "5222"
- bSetBlankPassword = true
- 'Options: opportunistic_tls ("Use encryption if available")
- ' require_tls ("Require encryption")
- ' old_ssl ("Use old-style SSL")
- sConnectionSecurity = "require_tls"
- '=============================================================================
- Set objShell = CreateObject("Wscript.shell")
- Set objFso = CreateObject("Scripting.FileSystemObject")
- Set WshNetwork = CreateObject("WScript.Network")
- 'Get local computer and username running this script
- sComputerName = WshNetwork.ComputerName
- sUserName = WshNetwork.UserName
- On Error Resume Next
- 'Place path of Pidgin installation into variable. This is pulled via the
- ' registry. If Pidgin is installed correctly, it should give us a full
- ' path to the exe.
- sPidginPath = lcase(getAppPath())
- 'If we have any errors getting to the registry key, then quit the script.
- If Err.Number <> 0 then Wscript.Quit
- On Error Goto 0
- 'If the key returns a path, let's check to see if pidgin.exe is found.
- If reportfilestatus(sPidginPath) = true then
- if bdebug = true then wscript.echo "Pidgin.exe found at " & sPidginPath
- sPidginPath = replace(sPidginPath,"pidgin.exe","")
- 'If Pidgin is NOT installed correctly, then quit.
- Else
- if bdebug = true then wscript.echo "Pidgin.exe not found."
- wscript.quit
- End if
- 'Get current working directory of script
- 'sScriptPath = objShell.CurrentDirectory & "\"
- sScriptPath = "\\roasccm\source$\SWD\Pidgin\ConfigurePidgin"
- if bdebug = true then wscript.echo "Using source path of " & sScriptPath & " for configuration files."
- 'Get user's profile location:
- sProfilePath = lcase(objShell.ExpandEnvironmentStrings("%UserProfile%"))
- if bdebug = true then wscript.echo "User's profile path: " & sProfilePath
- 'Windows 7/Vista
- If instr(lcase(sProfilePath),"users\") then
- 'If the settings folder doesn't exist, then create it (at this point we should
- ' have already determined if Pidgin was installed or not
- If ReportFolderStatus(sProfilePath & "\appdata\roaming\.purple") = false then
- if bdebug = true then wscript.echo "Creating Pidgin profile folder..."
- objfso.CreateFolder(sProfilePath & "\appdata\roaming\.purple")
- 'Copy the cert to the settings folder.
- objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\appdata\roaming\.purple",true
- End if
- 'If the settings folder already exists, lets see if it has an accounts.xml
- ' created. If not, copy a generic accounts.xml from our source folder to
- ' edit later.
- If ReportFileStatus(sProfilePath & "\appdata\roaming\.purple\accounts.xml") = false then
- if bdebug = true then wscript.echo "Can't find accounts.xml, generating..."
- objfso.CopyFolder sScriptPath & "\xml", sProfilePath & "\appdata\roaming\.purple",true
- objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\appdata\roaming\.purple",true
- End If
- 'Specify the final path for the accounts.xml
- sAccountsXML = sProfilePath & "\appdata\roaming\.purple\accounts.xml"
- 'XP
- ElseIf instr(lcase(sProfilePath),"documents and settings\") then
- 'If the settings folder doesn't exist, then create it (at this point we should
- ' have already determined if Pidgin was installed or not
- If ReportFolderStatus(sProfilePath & "\application data\.purple") = false then
- if bdebug = true then wscript.echo "Creating Pidgin profile folder..."
- objfso.CreateFolder(sProfilePath & "\application data\.purple")
- 'Copy the cert to the settings folder.
- objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\application data\.purple",true
- End If
- 'If the settings folder already exists, lets see if it has an accounts.xml
- ' created. If not, copy a generic accounts.xml from our source folder to
- ' edit later.
- if bdebug = true then wscript.echo "Configuring Pidgin chat profile..."
- If ReportFileStatus(sProfilePath & "\application data\.purple\accounts.xml") = false then
- if bdebug = true then wscript.echo "Can't find accounts.xml, generating..."
- objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\application data\.purple",true
- objfso.CopyFolder sScriptPath & "\xml", sProfilePath & "\application data\.purple",true
- End If
- 'Specify the final path for the accounts.xml
- sAccountsXML = sProfilePath & "\application data\.purple\accounts.xml"
- End If
- On Error Resume Next
- 'lets copy any plugins from the 'plugins' folder in our source location
- ' to the program's plugins folder.
- if bdebug = true then wscript.echo "Now copying plugins from " & sScriptPath & "\plugins to " & sPidginPath & "\plugins"
- objFSO.CopyFile sScriptPath & "\plugins\*.*",sPidginPath & "\plugins"
- On Error Goto 0
- Dim nAccountName, nAccountServer,nFileTransferProxy, nPort, nConnectionSecurity
- 'Create XMLDoc object
- Set xmlDoc = CreateObject("Microsoft.XMLDOM")
- 'load up the XML file and place it into xmldoc
- if bdebug = true then wscript.echo "============================================="
- if bdebug = true then wscript.echo " BEGINNING PIDGIN PROFILE CREATION"
- if bdebug = true then wscript.echo " " & now
- if bdebug = true then wscript.echo "============================================="
- if bdebug = true then wscript.echo ""
- if bdebug = true then wscript.echo "Attempting to load accounts.xml..."
- xmlDoc.load sAccountsXML
- 'This allows us to perform a filter when selecting nodes
- xmlDoc.setProperty "SelectionLanguage", "XPath"
- 'msgbox sAccountsXML
- 'Select the node we want to edit
- 'The text IS case sensitive
- Set nAccountName = xmlDoc.selectsinglenode ("//account/account/name")
- 'If the current user is already specified in the accounts file, then quit.
- If instr(nAccountName.text,sUserName & "@" & sDomain) then
- If bdebug = true then wscript.echo sUserName & "@" & sDomain & " already specified in accounts.xml, aborting."
- On Error Resume Next
- Set nAccountPassword = xmlDoc.selectsinglenode ("//account/account/password")
- On Error Goto 0
- If err.number <> 0 Then
- If nAccountPassword.text <> "" and bSetBlankPassword = true then
- If bdebug = true then wscript.echo "Removing saved password"
- nAccountPassword.text = ""
- End If
- End If
- If bdebug = true then wscript.echo "Saving accounts.xml..."
- strResult = xmldoc.save(sAccountsXML)
- wscript.quit
- End If
- 'Set the text node with the new value
- if bdebug = true then wscript.echo "Setting username to " & sUsername & "@" & sDomain & "/" & sComputerName
- nAccountName.text = sUserName & "@" & sDomain & "/" & sComputerName
- 'grab the node that specifies the server address
- Set nAccountServer = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'connect_server']")
- 'Set the text node with the new value
- if bdebug = true then wscript.echo "Setting server name to " & sServerName
- nAccountServer.text = sServerName
- 'grab the node that specifies the file transfer proxy
- Set nFileTransferProxy = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'ft_proxies']")
- 'Set the text node with the new value
- if bdebug = true then wscript.echo "Setting file transfer proxy to " & sFileTransferProxy
- nFileTransferProxy.text = sFileTransferProxy
- 'grab the node that specifies the connection port
- Set nPort = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'port']")
- 'Set the text node with the new value
- if bdebug = true then wscript.echo "Setting connection port to " & iPort
- nPort.text = iPort
- 'grab the node that specifies the connection port
- Set nConnectionSecurity = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'connection_security']")
- 'Set the text node with the new value
- if bdebug = true then wscript.echo "Setting connection security to " & chr(34) & sConnectionSecurity & chr(34)
- nConnectionSecurity.text = sConnectionSecurity
- wscript.sleep 1000
- 'Save the xml document with the new settings.
- if bdebug = true then wscript.echo "Saving accounts.xml..."
- strResult = xmldoc.save(sAccountsXML)
- wscript.sleep 1000
- if bdebug = true then wscript.echo "Finished!"
- wscript.sleep 5000
- Function ReportFileStatus(filespec)
- Dim msg
- If (objFSO.FileExists(filespec)) Then
- msg = true
- Else
- msg = false
- End If
- ReportFileStatus = msg
- End Function
- Function ReportFolderStatus(fldr)
- Dim msg
- If (objFSO.FolderExists(fldr)) Then
- ReportFolderStatus = true
- Else
- ReportFolderStatus = false
- End If
- End Function
- Function getAppPath()
- 'borrowed this
- bKey = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\pidgin.exe\")
- If Err.Number > 0 Then
- getApps = False
- Err.Clear
- wscript.quit
- 'Exit Function
- End If
- getAppPath = bkey
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement