maximillianx

Configure-Pidgin-with-LDAP.vbs

Jul 28th, 2015
1,101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'This script is intended to help automate account setups for Openfire
  2. ' (XMPP) chat server + Pidgin implementations in a corporate network.
  3. ' You can use this script to execute after the Pidgin install (or
  4. ' at Windows logon to configure an XMPP account for a local server.
  5. '
  6. 'Instructions:
  7. ' In the same folder where this script "scriptfolder" is stored,
  8. ' mimic the following structure
  9. '   x:\scriptfolder
  10. '       \thisscript.vbs
  11. '       \xml
  12. '       \plugins
  13. '       \files
  14. '
  15. '**** Making the account template XML ****
  16. 'On a workstation, install and configure Pidgin as you would for
  17. ' your users.  Select the plugins you wish to use, configure
  18. ' settings etc.  Note that this script doesn't yet copy over
  19. ' custom (non-native installed) emoticons, sounds, themes, etc.
  20. '
  21. 'Where the account profile is stored:
  22. ' XP: c:\documents and settings\username\application data\.purple
  23. ' Vista/7: C:\Users\username\appdata\Roaming\.purple
  24. '
  25. 'NOTE: The general account setup is saved in 'accounts.xml.'  
  26. ' Overall client preferences are stored in 'prefs.xml.'
  27. '
  28. '**** Copy the connection certificates to your scriptfolder ****
  29. 'From a working system that has already been set up with Pidgin and
  30. ' your XMPP server, you will want to find the 'certificates' folder
  31. ' from your profile.
  32. '
  33. 'Browse into the .purple folder and copy the 'certificates'
  34. ' folder to the 'files' subfolder where your script resides.
  35. '
  36. ' -- you should now see x:\scriptfolder\files\certificates
  37. '
  38. 'From the main .purple folder, copy 'prefs.xml' and 'accounts.xml'
  39. ' to the main folder where your script resides.
  40. '
  41. ' -- i.e. x:\scriptfolder\prefs.xml, x:\scriptfolder\accounts.xml
  42. '
  43. '**** Clean up your accounts.xml template file ****
  44. 'NOTE that you will want to clean up the accounts.xml file before
  45. ' using it as a template.  This will be used if Pidgin is installed
  46. ' but no XMPP account has been set up yet - i.e. the script copies
  47. ' this file into the user's account folder and makes it a framework
  48. ' by which to work with for the rest of the script.
  49. '
  50. '**** Got plugins? ****
  51. 'Copy any plugins you wish to deploy to the client (defaults to
  52. ' Pidgin path\plugins) into the 'plugins' subfolder where your
  53. ' script resides.  Note that you may need to enable these manually
  54. ' - unless you've configured it already and it has been stored
  55. ' in prefs.xml.
  56. '
  57. ' -- i.e. x:\scriptfolder\plugins\plugin.dll
  58. If instr(lcase(Wscript.FullName),"wscript.exe") then
  59.     bDebug = false
  60. Else
  61.     bDebug = true
  62. End If
  63.  
  64. on error goto 0
  65.  
  66. Dim objShell, objFSO
  67. Dim sComputerName, sUserName, sServerName, sFileTransferProxy, sDomain, iPort, sConnectionSecurity
  68. Dim bSetBlankPassword
  69.  
  70. '=============================================================================
  71. 'Set up some variables that we need to use for our environment
  72. sServerName         = "im.yourdomain.com"
  73. sFileTransferProxy  = "im.yourdomain.com"
  74. sDomain             = "yourdomain"
  75. iPort               = "5222"
  76. bSetBlankPassword   = true
  77.  
  78. 'Options:   opportunistic_tls   ("Use encryption if available")
  79. '           require_tls         ("Require encryption")
  80. '           old_ssl             ("Use old-style SSL")
  81. sConnectionSecurity = "require_tls"
  82. '=============================================================================
  83.  
  84. Set objShell        = CreateObject("Wscript.shell")
  85. Set objFso          = CreateObject("Scripting.FileSystemObject")
  86. Set WshNetwork      = CreateObject("WScript.Network")
  87.  
  88. 'Get local computer and username running this script
  89. sComputerName       = WshNetwork.ComputerName
  90. sUserName           = WshNetwork.UserName
  91.  
  92. On Error Resume Next
  93.  
  94. 'Place path of Pidgin installation into variable.  This is pulled via the
  95. ' registry.  If Pidgin is installed correctly, it should give us a full
  96. ' path to the exe.
  97. sPidginPath         = lcase(getAppPath())
  98.  
  99. 'If we have any errors getting to the registry key, then quit the script.
  100. If Err.Number <> 0 then Wscript.Quit
  101.  
  102. On Error Goto 0
  103.  
  104. 'If the key returns a path, let's check to see if pidgin.exe is found.
  105. If reportfilestatus(sPidginPath) = true then
  106.     if bdebug = true then wscript.echo "Pidgin.exe found at " & sPidginPath
  107.     sPidginPath = replace(sPidginPath,"pidgin.exe","")
  108.  
  109. 'If Pidgin is NOT installed correctly, then quit.
  110. Else
  111.     if bdebug = true then wscript.echo "Pidgin.exe not found."
  112.     wscript.quit
  113. End if
  114.  
  115. 'Get current working directory of script
  116. 'sScriptPath        = objShell.CurrentDirectory & "\"
  117. sScriptPath         = "\\roasccm\source$\SWD\Pidgin\ConfigurePidgin"
  118. if bdebug = true then wscript.echo "Using source path of " & sScriptPath & " for configuration files."
  119.  
  120. 'Get user's profile location:
  121. sProfilePath        = lcase(objShell.ExpandEnvironmentStrings("%UserProfile%"))
  122. if bdebug = true then wscript.echo "User's profile path: " & sProfilePath
  123.  
  124. 'Windows 7/Vista
  125. If instr(lcase(sProfilePath),"users\") then
  126.  
  127.     'If the settings folder doesn't exist, then create it (at this point we should
  128.     ' have already determined if Pidgin was installed or not
  129.     If ReportFolderStatus(sProfilePath & "\appdata\roaming\.purple") = false then
  130.         if bdebug = true then wscript.echo "Creating Pidgin profile folder..."
  131.         objfso.CreateFolder(sProfilePath & "\appdata\roaming\.purple")
  132.         'Copy the cert to the settings folder.
  133.         objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\appdata\roaming\.purple",true       
  134.     End if
  135.    
  136.     'If the settings folder already exists, lets see if it has an accounts.xml
  137.     ' created.  If not, copy a generic accounts.xml from our source folder to
  138.     ' edit later.
  139.     If ReportFileStatus(sProfilePath & "\appdata\roaming\.purple\accounts.xml") = false then
  140.         if bdebug = true then wscript.echo "Can't find accounts.xml, generating..."
  141.         objfso.CopyFolder sScriptPath & "\xml", sProfilePath & "\appdata\roaming\.purple",true
  142.         objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\appdata\roaming\.purple",true           
  143.     End If
  144.  
  145.     'Specify the final path for the accounts.xml
  146.     sAccountsXML = sProfilePath & "\appdata\roaming\.purple\accounts.xml"
  147.  
  148. 'XP
  149. ElseIf instr(lcase(sProfilePath),"documents and settings\") then
  150.  
  151.     'If the settings folder doesn't exist, then create it (at this point we should
  152.     ' have already determined if Pidgin was installed or not
  153.     If ReportFolderStatus(sProfilePath & "\application data\.purple") = false then
  154.         if bdebug = true then wscript.echo "Creating Pidgin profile folder..."
  155.         objfso.CreateFolder(sProfilePath & "\application data\.purple")
  156.         'Copy the cert to the settings folder.
  157.         objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\application data\.purple",true  
  158.     End If
  159.    
  160.     'If the settings folder already exists, lets see if it has an accounts.xml
  161.     ' created.  If not, copy a generic accounts.xml from our source folder to
  162.     ' edit later.
  163.     if bdebug = true then wscript.echo "Configuring Pidgin chat profile..."
  164.     If ReportFileStatus(sProfilePath & "\application data\.purple\accounts.xml") = false then
  165.         if bdebug = true then wscript.echo "Can't find accounts.xml, generating..."
  166.         objfso.CopyFolder sScriptPath & "\files", sProfilePath & "\application data\.purple",true  
  167.         objfso.CopyFolder sScriptPath & "\xml", sProfilePath & "\application data\.purple",true
  168.     End If
  169.  
  170.     'Specify the final path for the accounts.xml
  171.     sAccountsXML = sProfilePath & "\application data\.purple\accounts.xml"
  172. End If
  173.  
  174. On Error Resume Next
  175.  
  176. 'lets copy any plugins from the 'plugins' folder in our source location
  177. ' to the program's plugins folder.
  178. if bdebug = true then wscript.echo "Now copying plugins from " & sScriptPath & "\plugins to " & sPidginPath & "\plugins"
  179. objFSO.CopyFile sScriptPath & "\plugins\*.*",sPidginPath & "\plugins"
  180.  
  181. On Error Goto 0
  182. Dim nAccountName, nAccountServer,nFileTransferProxy, nPort, nConnectionSecurity
  183.  
  184. 'Create XMLDoc object
  185. Set xmlDoc = CreateObject("Microsoft.XMLDOM")
  186.  
  187. 'load up the XML file and place it into xmldoc
  188. if bdebug = true then wscript.echo "============================================="
  189. if bdebug = true then wscript.echo "     BEGINNING PIDGIN PROFILE CREATION"
  190. if bdebug = true then wscript.echo "           " & now
  191. if bdebug = true then wscript.echo "============================================="
  192. if bdebug = true then wscript.echo ""
  193. if bdebug = true then wscript.echo "Attempting to load accounts.xml..."
  194. xmlDoc.load sAccountsXML
  195.  
  196. 'This allows us to perform a filter when selecting nodes
  197. xmlDoc.setProperty "SelectionLanguage", "XPath"
  198.  
  199. 'msgbox sAccountsXML
  200. 'Select the node we want to edit
  201. 'The text IS case sensitive
  202. Set nAccountName = xmlDoc.selectsinglenode ("//account/account/name")
  203.  
  204. 'If the current user is already specified in the accounts file, then quit.
  205. If instr(nAccountName.text,sUserName & "@" & sDomain) then
  206.     If bdebug = true then wscript.echo sUserName & "@" & sDomain & " already specified in accounts.xml, aborting."
  207.    
  208.     On Error Resume Next
  209.     Set nAccountPassword = xmlDoc.selectsinglenode ("//account/account/password")
  210.     On Error Goto 0
  211.    
  212.     If err.number <> 0 Then
  213.         If nAccountPassword.text <> "" and bSetBlankPassword = true then
  214.             If bdebug = true then wscript.echo "Removing saved password"
  215.             nAccountPassword.text = ""
  216.  
  217.         End If
  218.     End If
  219.     If bdebug = true then wscript.echo "Saving accounts.xml..."
  220.     strResult = xmldoc.save(sAccountsXML)
  221.     wscript.quit
  222. End If
  223.  
  224. 'Set the text node with the new value
  225. if bdebug = true then wscript.echo "Setting username to " & sUsername & "@" & sDomain & "/" & sComputerName
  226. nAccountName.text = sUserName & "@" & sDomain & "/" & sComputerName
  227.  
  228. 'grab the node that specifies the server address
  229. Set nAccountServer = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'connect_server']")
  230.  
  231. 'Set the text node with the new value
  232. if bdebug = true then wscript.echo "Setting server name to " & sServerName
  233. nAccountServer.text = sServerName
  234.  
  235. 'grab the node that specifies the file transfer proxy
  236. Set nFileTransferProxy = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'ft_proxies']")
  237.  
  238. 'Set the text node with the new value
  239. if bdebug = true then wscript.echo "Setting file transfer proxy to " & sFileTransferProxy
  240. nFileTransferProxy.text = sFileTransferProxy
  241.  
  242. 'grab the node that specifies the connection port
  243. Set nPort = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'port']")
  244.  
  245. 'Set the text node with the new value
  246. if bdebug = true then wscript.echo "Setting connection port to " & iPort
  247. nPort.text = iPort
  248.  
  249. 'grab the node that specifies the connection port
  250. Set nConnectionSecurity = xmlDoc.selectsinglenode ("//account/account/settings/setting [@name = 'connection_security']")
  251.  
  252. 'Set the text node with the new value
  253. if bdebug = true then wscript.echo "Setting connection security to " & chr(34) & sConnectionSecurity & chr(34)
  254. nConnectionSecurity.text = sConnectionSecurity
  255.  
  256. wscript.sleep 1000
  257.  
  258. 'Save the xml document with the new settings.
  259. if bdebug = true then wscript.echo "Saving accounts.xml..."
  260. strResult = xmldoc.save(sAccountsXML)
  261. wscript.sleep 1000
  262. if bdebug = true then wscript.echo "Finished!"
  263.  
  264. wscript.sleep 5000
  265.  
  266. Function ReportFileStatus(filespec)
  267.    Dim msg
  268.    If (objFSO.FileExists(filespec)) Then
  269.       msg = true
  270.    Else
  271.       msg = false
  272.    End If
  273.    ReportFileStatus = msg
  274. End Function
  275.  
  276. Function ReportFolderStatus(fldr)
  277.    Dim msg
  278.    If (objFSO.FolderExists(fldr)) Then
  279.       ReportFolderStatus = true
  280.    Else
  281.       ReportFolderStatus = false
  282.    End If
  283. End Function
  284.  
  285. Function getAppPath()
  286.     'borrowed this
  287.     bKey = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\pidgin.exe\")
  288.     If Err.Number > 0 Then
  289.         getApps = False
  290.         Err.Clear
  291.         wscript.quit
  292.         'Exit Function
  293.     End If
  294.     getAppPath = bkey
  295. End Function
RAW Paste Data