Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
11 KiB

  1. <%
  2. '------------------------------------------------------------
  3. '
  4. ' Microsoft Internet Printing Project
  5. '
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '
  8. '------------------------------------------------------------
  9. Const SNMP_ALERT_SEVERITY = 0
  10. Const SNMP_ALERT_INDEX = 1
  11. Const SNMP_ALERT_SUBUNIT = 2
  12. Const SNMP_ALERT_DESCRIPTION = 3
  13. Const SNMP_ALERT_CODE = 4
  14. Const SNMP_ALERT_TRAINING = 5
  15. Const SNMP_ALERT_ATTRIBUTES = 5
  16. Const SNMP_INTRAY_TYPE = 0
  17. Const SNMP_INTRAY_UNITS = 1
  18. Const SNMP_INTRAY_MAX = 2
  19. Const SNMP_INTRAY_CURRENT = 3
  20. Const SNMP_INTRAY_STATE = 4
  21. Const SNMP_INTRAY_MEDIA = 5
  22. Const SNMP_INTRAY_UNIT = 6
  23. Const SNMP_INTRAY_NAME = 7
  24. Const SNMP_INTRAY_ATTRIBUTES = 7
  25. Const SNMP_LIGHT_ON = 0
  26. Const SNMP_LIGHT_OFF = 1
  27. Const SNMP_LIGHT_COLOR = 2
  28. Const SNMP_LIGHT_DESCRIPTION = 3
  29. Const SNMP_LIGHT_ATTRIBUTES = 3
  30. Function rgSNMPGetState(objSNMP, iDevice)
  31. Dim rgFetchList, rgState, StrDevice, rgFetchValue, hrPrintDetectedState
  32. On Error Resume Next
  33. Err.Clear
  34. StrDevice = CStr(iDevice)
  35. rgFetchList = Array("25.3.2.1.5." & StrDevice, "25.3.5.1.1." & StrDevice)
  36. hrPrintDetectedState = objSNMP.GetAsByte ("25.3.5.1.2." & StrDevice)
  37. If Err Then Exit Function
  38. rgFetchValue = objSNMP.GetList(rgFetchList)
  39. If Err Then Exit Function
  40. rgState = Array (rgFetchValue(0), rgFetchValue(1), hrPrintDetectedState)
  41. If Err Then Exit Function
  42. rgSNMPGetState = rgState
  43. End Function
  44. Function GetLastNode (strMib)
  45. Dim strTmp, j
  46. For j = 1 To Len (strMib)
  47. strTmp = Right (strMib, j)
  48. If Left (strTmp, 1) = "." Then
  49. GetLastNode = strTmp
  50. Exit Function
  51. End If
  52. Next
  53. GetLastNode = ""
  54. End Function
  55. Function rgSNMPGetAlerts(objSNMP, objHelper, iDevice, iAlerts)
  56. Dim rgTmp, rgAlerts()
  57. Dim i, StrDevice
  58. On Error Resume Next
  59. iAlerts = -1
  60. StrDevice = CStr(iDevice)
  61. rgTmp = objSNMP.GetTree("43.18.1.1.2." & StrDevice) 'alert severities
  62. If Err Then 'assume there is not alert table
  63. Err.Clear
  64. Exit Function
  65. End If
  66. If UBound(rgTmp, 2) >= 0 Then
  67. iAlerts = UBound(rgTmp, 2)
  68. ReDim rgAlerts(SNMP_ALERT_ATTRIBUTES, iAlerts)
  69. For i = 0 to iAlerts
  70. rgAlerts(SNMP_ALERT_INDEX, i) = i
  71. rgAlerts(SNMP_ALERT_SEVERITY, i) = rgTmp(1, i)
  72. Next
  73. 'rgTmp = objSNMP.GetTree("43.18.1.1.3." & StrDevice)
  74. 'If UBound(rgTmp,2) = iAlerts Then
  75. ' For i = 0 to iAlerts
  76. ' rgAlerts(SNMP_ALERT_TRAINING, i) = rgTmp(1, i)
  77. ' Next
  78. 'End If
  79. rgTmp = objSNMP.GetTree("43.18.1.1.4." & StrDevice)
  80. If UBound(rgTmp,2) = iAlerts Then
  81. For i = 0 to iAlerts
  82. rgAlerts(SNMP_ALERT_SUBUNIT, i) = rgTmp(1, i)
  83. Next
  84. End If
  85. rgTmp = objSNMP.GetTree("43.18.1.1.5." & StrDevice)
  86. If UBound(rgTmp,2) = iAlerts Then
  87. For i = 0 to iAlerts
  88. rgAlerts(SNMP_ALERT_INDEX, i) = rgTmp(1, i)
  89. Next
  90. End If
  91. rgTmp = objSNMP.GetTree("43.18.1.1.7." & StrDevice)
  92. If UBound(rgTmp,2) = iAlerts Then
  93. For i = 0 to iAlerts
  94. rgAlerts(SNMP_ALERT_CODE, i) = rgTmp(1, i)
  95. Next
  96. For i = 0 to iAlerts
  97. If rgTmp(1,i) = 1 Then 'Other Error
  98. rgAlerts(SNMP_ALERT_DESCRIPTION, i) = objSNMP.Get ("43.18.1.1.8." & StrDevice & GetLastNode (rgTmp (0, i)))
  99. If rgAlerts(SNMP_ALERT_DESCRIPTION, i) = "" Then
  100. rgAlerts(SNMP_ALERT_DESCRIPTION, i) = objHelper.MibErrorDscp (rgTmp(1, i))
  101. End If
  102. Else
  103. rgAlerts(SNMP_ALERT_DESCRIPTION, i) = objHelper.MibErrorDscp (rgTmp(1, i))
  104. If rgAlerts(SNMP_ALERT_DESCRIPTION, i) = "" Then
  105. rgAlerts(SNMP_ALERT_DESCRIPTION, i) = objSNMP.Get ("43.18.1.1.8." & StrDevice & GetLastNode (rgTmp (0, i)))
  106. End If
  107. End If
  108. Next
  109. End If
  110. rgSNMPGetAlerts = rgAlerts
  111. End If
  112. End Function
  113. Function rgSNMPGetInputTrays(objSNMP, iDevice, iTrays)
  114. Dim rgWork, iFetch, StrDevice, i, rgTrays()
  115. Dim j
  116. Dim rgFetchOid(7)
  117. On Error Resume Next
  118. Err.Clear
  119. StrDevice = CStr(iDevice)
  120. rgFetchOid(0) = "43.8.2.1.2." & StrDevice 'type
  121. rgFetchOid(1) = "43.8.2.1.8." & StrDevice 'units
  122. rgFetchOid(2) = "43.8.2.1.9." & StrDevice 'max
  123. rgFetchOid(3) = "43.8.2.1.10." & StrDevice 'current
  124. rgFetchOid(4) = "43.8.2.1.11." & StrDevice 'state
  125. rgFetchOid(5) = "43.8.2.1.12." & StrDevice 'media
  126. rgFetchOid(6) = "43.8.2.1.13." & StrDevice 'input unit
  127. rgFetchOid(7) = "43.8.2.1.18." & StrDevice 'trayname
  128. rgWork = objSNMP.GetTree(rgFetchOid(0))
  129. If Err Then Exit Function
  130. iTrays = UBound(rgWork, 2)
  131. If iTrays >= 0 Then
  132. ReDim rgTrays(SNMP_INTRAY_ATTRIBUTES, iTrays)
  133. For j = 0 To 7
  134. If j <> 0 Then
  135. rgWork = objSNMP.GetTree(rgFetchOid(j))
  136. If Err Then Exit Function
  137. End If
  138. For i = 0 To UBound(rgWork, 2)
  139. rgTrays(j, i) = rgWork(1, i)
  140. Next
  141. Next
  142. rgSNMPGetInputTrays = rgTrays
  143. End If
  144. End Function
  145. Function strAppendStr (strBody, strTail)
  146. Dim L_Comma_Text
  147. L_Comma_Text = ", "
  148. If strBody = "" Then
  149. strAppendStr = strTail
  150. Else
  151. strAppendStr = strBody & L_Comma_Text & strTail
  152. End If
  153. End Function
  154. Function strSNMPStatus(rgState)
  155. Dim strHTML
  156. Dim str1, str2, strSubject
  157. Dim bDisplay
  158. Dim L_DeviceStatus_Text
  159. Dim L_UpRunning_Text, L_Warning_Text, L_Tested_Text, L_UnAvailable_Text
  160. Dim L_IdleState_Text, L_Printing_Text, L_WarmingUp_Text
  161. Const strIndent = "&nbsp;"
  162. L_DeviceStatus_Text = "<B>Status:</b> "
  163. L_UpRunning_Text = "<font color = red>Up and Running</font>"
  164. L_Warning_Text = "<font color = red>Functioning but has one or more warnings</font>"
  165. L_Tested_Text = "<font color = red>Being tested</font>"
  166. L_UnAvailable_Text = "<font color = red>Unavailable for any use</font>"
  167. L_IdleState_Text = "<p>In an idle state</p>"
  168. L_Printing_Text = " Printing documents "
  169. L_WarmingUp_Text = " Warming up "
  170. strHTML = "<table><tr><td>" & strIndent & "</td><td>" & DEF_FONT_TAG
  171. Select Case rgState(1)
  172. Case 4
  173. str2 = L_Printing_Text
  174. Case 5
  175. str2 = L_WarmingUp_Text
  176. Case Else
  177. str2 = ""
  178. End Select
  179. If str2 <> "" Then
  180. strHTML = strHTML & " - " & str2
  181. End If
  182. bDisplay = TRUE
  183. Select Case rgState(0)
  184. Case 2
  185. str1 = L_UpRunning_Text
  186. Case 3
  187. str1 = L_Warning_Text
  188. Case 4
  189. str1 = L_Tested_Text
  190. Case 5
  191. str1 = L_UnAvailable_Text
  192. Case Else
  193. bDisplay = FALSE
  194. End Select
  195. If bDisplay Then
  196. strHTML = strHTML & str1
  197. End If
  198. strHTML = strHTML & "</font></td></tr>"
  199. If (rgState(0) = 3 Or rgState(0) = 5) Then
  200. Dim lErrState, lMask, lNumMsg
  201. Dim L_ErrMsg_Text(7)
  202. Const L_DetectedWarn_Text = "<b>Warnings:</b> "
  203. Const L_DetectedErr_Text = "<b>Errors:</b> "
  204. L_ErrMsg_Text(0) = "service requested"
  205. L_ErrMsg_Text(1) = "offline"
  206. L_ErrMsg_Text(2) = "paper jammed"
  207. L_ErrMsg_Text(3) = "door open"
  208. L_ErrMsg_Text(4) = "no toner"
  209. L_ErrMsg_Text(5) = "toner low"
  210. L_ErrMsg_Text(6) = "out of paper"
  211. L_ErrMsg_Text(7) = "low paper"
  212. lErrState = CInt (rgState(2))
  213. str1 = ""
  214. lMask = 1
  215. lNumMsg = 0
  216. For i = 0 To 7
  217. If lErrState And lMask Then
  218. str1 = strAppendStr (str1, L_ErrMsg_Text(i))
  219. lNumMsg = lNumMsg + 1
  220. End If
  221. lMask = lMask * 2
  222. Next
  223. If lNumMsg > 0 Then
  224. strHTML = strHTML & "<tr><td>" & strIndent & "</td><td>" & DEF_FONT_TAG
  225. If rgState(0) = 3 Then
  226. strHTML = strHTML & L_DetectedWarn_Text
  227. Else
  228. strHTML = strHTML & L_DetectedErr_Text
  229. End If
  230. strHTML = strHTML & str1 & "</font></td></tr>"
  231. End If
  232. End If
  233. strHTML = strHTML & "</table>"
  234. strSNMPStatus = strHTML
  235. End Function
  236. Function rgSNMPConsole(objSNMP, iDevice, iRow, iColumn, rgConText, strLang)
  237. Const prtConsoleLocalization = "43.5.1.1.10."
  238. Const prtConsoleNumberOfDisplayLines = "43.5.1.1.11."
  239. Const prtConsoleNumberOfDisplayChars = "43.5.1.1.12."
  240. Const prtConsoleDisplayBufferText = "43.16.5.1.2."
  241. Const prtLocalizationLanguage = "43.7.1.1.3."
  242. Dim StrDevice, i, rgOidList, rgConsole
  243. StrDevice = CStr(iDevice)
  244. rgSNMPConsole = False
  245. rgConText = ""
  246. rgOidList = Array(prtConsoleLocalization & StrDevice, prtConsoleNumberOfDisplayLines & StrDevice, prtConsoleNumberOfDisplayChars & StrDevice)
  247. rgConsole = objSNMP.GetList(rgOidList)
  248. If Err.Number <> 0 Then Exit Function
  249. iRow = rgConsole(1)
  250. iColumn = rgConsole(2)
  251. if iRow <> 0 Then
  252. ReDim rgConTextOidList(iRow - 1)
  253. For i = 0 To iRow - 1
  254. rgConTextOidList(i) = prtConsoleDisplayBufferText & StrDevice & "." & CStr(i + 1)
  255. Next
  256. rgConText = objSNMP.GetList(rgConTextOidList)
  257. If Err.Number <> 0 Then Exit Function
  258. strLang = objSNMP.Get (prtLocalizationLanguage & StrDevice & "." & rgConsole(0))
  259. If Err.Number <> 0 Then Exit Function
  260. End If
  261. rgSNMPConsole = True
  262. End Function
  263. Function rgSNMPLights(objSNMP, iDevice, iLights)
  264. Dim rgWork
  265. Dim rgFetchOid(4)
  266. Dim StrDevice
  267. StrDevice = CStr(iDevice)
  268. On Error Resume Next
  269. rgFetchOid(0) = "43.17.6.1.2." & StrDevice & "."
  270. rgFetchOid(1) = "43.17.6.1.3." & StrDevice & "."
  271. rgFetchOid(2) = "43.17.6.1.4." & StrDevice & "."
  272. rgFetchOid(3) = "43.17.6.1.5." & StrDevice & "."
  273. rgWork = objSNMP.GetTree(rgFetchOid(0))
  274. If Err Then Exit Function
  275. iLights = UBound(rgWork, 2)
  276. If iLights >= 0 Then
  277. Dim i, j
  278. ReDim rgLights(SNMP_LIGHT_ATTRIBUTES, iLights)
  279. For j = 0 To 3
  280. If j <> 0 Then
  281. rgWork = objSNMP.GetTree(rgFetchOid(j))
  282. If Err Then Exit Function
  283. End If
  284. For i = 0 To UBound(rgWork, 2)
  285. rgLights(j, i) = rgWork(1, i)
  286. Next
  287. Next
  288. rgSNMPLights = rgLights
  289. End If
  290. End Function
  291. %>