Advertisement
opexxx

sophos-client-install.vbs

Feb 23rd, 2014
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. 'Version: 1.2.1
  2. 'Date Modified: 08-11-2010
  3. '
  4. ' changelog;
  5. ' 1.2 removed the domain section much easier to just obfuscate the entire domain\user evertime
  6. ' 1.2 removed the subfolder the sophos log is added into (not required)
  7. ' 1.2.1 objFSO and wshShell set before CheckOSBit function. Fixed logging to root of c:.
  8. ' 1.3 now outputs event details to Windows Event Log.
  9. 'Developed By:
  10. '
  11. 'Adin Sabic
  12. 'Tim Heldna
  13. 'Simon Sigré
  14. 'Gareth Hill
  15. ' Catholic Education Office South Australia
  16. '
  17. 'Thout Shall Always Use Option Explicit!
  18. Option Explicit
  19. 'On Error Resume Next
  20. '
  21. Dim objFSO, WshShell
  22. Dim strFileSophos9AV, strFileSophos9AU, strFileSophos9RMS
  23. Dim blnFileSophos9AV, blnFileSophos9AU, blnFileSophos9RMS, blnEventLog
  24. Dim strFileSophos9SetupPath, strFileSophos9Flags, strFileSophosInstall
  25. Dim strSophosServer, strSophosDomain, strSophosUser, strSophosPassword, strSophosGroup
  26. Dim strClientString, strServerString, strOSBit
  27. Dim blnReInstall
  28. Dim strCID
  29. Dim strVersion
  30.  
  31. Set objFSO = CreateObject("Scripting.FileSystemObject")
  32. Set WshShell = WScript.CreateObject("WScript.Shell")
  33.  
  34. strVersion = "1.3"
  35.  
  36. '
  37. ' Start School Unique Settings Here
  38. '
  39. 'Set this to true if you have changed your username and password with the Obfuscation tool
  40. 'See http://www.sophos.com/support/knowledgebase/article/13094.html for setup
  41. '
  42. '
  43. 'Sophos server name only (no backslashes)
  44. strSophosServer = "sophosserver.test.domain"
  45. '
  46. '
  47. strSophosUser = "BwjbCTR4tjvoTnhvs2bdQa2GzHEoTIXbViq33795BJscuQRg9xAlTSDQnBSWdW2x9cc="
  48. strSophosPassword = "BwjRxEKGwl/yRiGGkmIKmICg/fLqDaly9bENXngxFD7gVaWvBMACATRn"
  49. '
  50. strSophosGroup = "Workstations"
  51. '
  52. '
  53. ' End School Unique Settings
  54. '
  55. blnReInstall = FALSE
  56. strOSBit = CheckOSBit
  57.  
  58. strSophosGroup = "\" & strSophosServer & "\" & strSophosGroup
  59.  
  60. strFileSophos9SetupPath = "\\" & strSophosServer & "\SophosUpdate\CIDs\S000\SAVSCFXP\"
  61.  
  62. strFileSophos9Flags = "-mng yes -crt R -ouser " & strSophosUser & " -opwd " & strSophosPassword & " -G " & strSophosGroup
  63.  
  64. 'Check exe exist on client
  65. strFileSophos9AV = "C:\Program Files" & strOSBit & "\Sophos\Sophos Anti-Virus\SavMain.exe"
  66. strFileSophos9AU = "C:\Program Files" & strOSBit & "\Sophos\AutoUpdate\ALUpdate.exe"
  67. strFileSophos9RMS = "C:\Program Files" & strOSBit & "\Sophos\Remote Management System\AutoUpdateAgentNT.exe"
  68. blnFileSophos9AV = objFSO.FileExists(strFileSophos9AV)
  69. blnFileSophos9AU = objFSO.FileExists(strFileSophos9AU)
  70. blnFileSophos9RMS = objFSO.FileExists(strFileSophos9RMS)
  71.  
  72. 'Compare the mrinit.conf files on client and server for consistency
  73. strClientString = CheckFile("C:\Program Files" & strOSBit & "\Sophos\Remote Management System\mrinit.conf", "ParentRouterAddress")
  74. strServerString = CheckFile("\\" & strSophosServer & "\SophosUpdate\CIDs\S000\SAVSCFXP\mrinit.conf", "ParentRouterAddress")
  75.  
  76. 'Not used ATM, would be useful if there is a version that cant be upgraded via server.
  77. 'Would also be useful if we could remember why we initially started coding this too.
  78. 'If arrVersion(0) & "." & arrVersion(1) = strCID Then
  79. ' WshShell.LogEvent 0, "Sophos Version Comparison Success."
  80. 'Else
  81. ' blnReInstall = TRUE
  82. ' WshShell.LogEvent 0, "Sophos Version Comparison Failure."
  83. 'End If
  84.  
  85.  
  86. 'If the server String returns empty then the file is not found on the server and do not deploy to client
  87.  
  88. If strServerString <> "" Then
  89. If strClientString <> strServerString Then
  90. blnReInstall = TRUE
  91. Call WriteToLog("mrinit File Comparison Failure", 1)
  92. End If
  93. Else
  94. Call WriteToLog ("Could not find mrinit.exe on server", 1)
  95. End If
  96.  
  97. If blnFileSophos9AV = FALSE Then
  98. blnReInstall = TRUE
  99. Call WriteToLog ("SavMain.exe File not Found.", 1)
  100. End If
  101.  
  102. If blnFileSophos9AU = FALSE Then
  103. blnReInstall = TRUE
  104. Call WriteToLog ("ALUpdate.exe File not Found.", 1)
  105. End If
  106.  
  107. If blnFileSophos9RMS = FALSE Then
  108. blnReInstall = TRUE
  109. Call WriteToLog ("AutoUpdateAgentNT.exe File not Found.", 1)
  110. End If
  111.  
  112. If blnReInstall = TRUE Then
  113. strFileSophosInstall = strFileSophos9SetupPath & "setup.exe " & strFileSophos9Flags
  114.  
  115. Call WriteToLog ("Sophos Install v" + strVersion + " Started", 0)
  116. WshShell.Run strFileSophosInstall, 1, True
  117. End If
  118.  
  119. Function CheckFile(strPath, strCheck)
  120. Dim strFileName,strLine
  121. Dim objFile
  122. Dim arrFileLines()
  123. Dim i
  124.  
  125. i = 0
  126. If objFSO.FileExists(strPath) Then
  127. Set objFile = objFSO.OpenTextFile(strPath, 1)
  128.  
  129. Do Until objFile.AtEndOfStream
  130. Redim Preserve arrFileLines(i)
  131. arrFileLines(i) = objFile.ReadLine
  132.  
  133. 'Check for needed text passed as param
  134. If InStr(arrFileLines(i), strCheck) Then
  135. CheckFile = arrFileLines(i)
  136. Exit Do
  137. End If
  138. i = i + 1
  139. Loop
  140.  
  141. objFile.Close
  142. End If
  143. End Function
  144.  
  145. Sub WriteToLog(strOutput, intType)
  146.  
  147. If blnEventLog Then
  148. WshShell.LogEvent intType, strOutput
  149. Else
  150. Call AddLog (strOutput, intType)
  151. End If
  152.  
  153. End Sub
  154.  
  155.  
  156.  
  157. Function CheckOSBit()
  158.  
  159. blnEventLog = WshShell.LogEvent(0, "Writing to EventLog..")
  160. Dim OsType
  161. OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
  162.  
  163. If (OsType = "x86") Then
  164. CheckOSBit = ""
  165. Call WriteToLog ("Sophos Install Script Initiated for X86", 0)
  166. Else
  167. CheckOSBit = " (x86)"
  168. Call WriteToLog ("Sophos Install Script Initiated for x64 bit Windows.", 0)
  169. End if
  170. End Function
  171.  
  172. Sub CheckSophosVersion
  173. Dim strVersion
  174. strVersion = objFSO.GetFileVersion("C:\Program Files" & CheckOSBit & "\Sophos\Sophos Anti-Virus\SavMain.exe")
  175.  
  176. Dim arrVersion
  177. Dim tempStr
  178.  
  179. arrVersion = Split(strVersion, ".",3)
  180.  
  181. Dim i
  182.  
  183. wscript.echo arrVersion(0) & "." & arrVersion(1)
  184.  
  185. End Sub
  186.  
  187. Sub AddLog(strTextToAdd, intType)
  188. Dim objFolder, objFile, objFileOpen
  189. Dim strFolder, strFile, strErrType
  190. Dim strComputerName, strComputerIP
  191. Const ForAppending = 8
  192.  
  193. strFolder="c:"
  194. strFile = "sophosscriptedinstall.log"
  195.  
  196. If NOT objFSO.FileExists(strFolder & "\" & strFile) Then
  197. Set objFile = objFSO.CreateTextFile(strFolder & "\" & strFile)
  198. objFIle.Close
  199. End If
  200.  
  201.  
  202. strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
  203.  
  204.  
  205. Set objFileOpen = objFSO.OpenTextFile(strFolder & "\" & strFile, ForAppending, True)
  206.  
  207. If intType=1 Then
  208. strErrType = "Error: "
  209. Else
  210. strErrType = "Message: "
  211. End If
  212.  
  213. objFileOpen.WriteLine(strErrType & strTextToAdd & " " & " : " & strComputerName & " : " & NOW() )
  214. objFileOpen.Close
  215.  
  216. set objFolder = nothing
  217. set objFile = nothing
  218. set objFileOpen = nothing
  219. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement