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.

309 lines
10 KiB

  1. <%@ CODEPAGE=65001 %>
  2. <%
  3. '------------------------------------------------------------
  4. '
  5. ' Microsoft Internet Printing Project
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Entry page for queue view.
  10. '
  11. '------------------------------------------------------------
  12. option explicit
  13. %>
  14. <!-- #include file = "ipp_util.inc" -->
  15. <%
  16. Randomize
  17. Response.Expires = 0
  18. Server.ScriptTimeOut = 6000 'Set time out to 10 minites
  19. Const L_Opening_Text = "Opening"
  20. Const L_GetADSI_Message = "Get ADSI Printers"
  21. Const L_AccessDenied_Text = "Access Denied"
  22. Const ADSI_PRINTER_NAME = 1
  23. Const ADSI_PRINTER_LOCATION = 2
  24. Const ADSI_PRINTER_COMMENT = 3
  25. Const ADSI_PRINTER_MODEL = 4
  26. Const ADSI_PRINTER_STATUS = 5
  27. Const ADSI_PRINTER_JOBS = 6
  28. Const ADSI_PRINTER_SHARE = 7
  29. Const ADSI_PRINTER_ACCESS = 8
  30. Const ADSI_PRINTER_ATTRIBUTES = 8
  31. Const PRINTER_ACCESS_DENIED = 0
  32. Const PRINTER_OPENING = 1
  33. Const PRINTER_OK = 2
  34. Const iPrinterLength = 10
  35. Function rgADSIGetPrinters(strComputer, iStart, iEnd)
  36. On Error Resume Next
  37. Err.Clear
  38. Dim objPrinter, objPrinters, iPrinters, dwStatus, rgPrinters()
  39. Dim objHelper, strServerName, i
  40. Dim iTotal, iRevStart, iRevEnd
  41. Set objHelper = Server.CreateObject(PROGID_HELPER)
  42. If strComputer = "localhost" Or strComputer = "127.0.0.1" or Not CBool(objHelper.IsCluster) Then
  43. strComputer = objHelper.ComputerName
  44. End If
  45. Set objPrinters = GetObject("WinNT://" & strComputer & ",computer")
  46. If Err Then Exit Function
  47. strServerName = objPrinters.Name
  48. objPrinters.filter = Array("PrintQueue")
  49. If Err Then Exit Function
  50. ' iterate through all the (shared) printers
  51. iTotal = 0
  52. For Each objPrinter In objPrinters
  53. iTotal = iTotal + 1
  54. Next
  55. iRevStart = iTotal - iEnd + 1
  56. iRevEnd = iTotal - iStart + 1
  57. If iEnd <= iTotal Then bShowNext = TRUE
  58. iPrinters = 0
  59. i = 1
  60. For Each objPrinter In objPrinters
  61. If i > iRevEnd Then Exit For
  62. If i > iRevStart Then
  63. iPrinters = iPrinters + 1
  64. ReDim Preserve rgPrinters(ADSI_PRINTER_ATTRIBUTES, iPrinters)
  65. rgPrinters(ADSI_PRINTER_STATUS, iPrinters) = objPrinter.Status
  66. If Err.Number = &H80070005 Then 'Access Denied
  67. Err.Clear
  68. rgPrinters(ADSI_PRINTER_NAME, iPrinters) = objPrinter.Name
  69. rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_ACCESS_DENIED
  70. rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = ""
  71. rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = ""
  72. rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = "<a href=""ipp_0001.asp?v=1&startid=" &_
  73. CStr (iStart) & "&endid=" & CStr (iEnd) & """>" & L_AccessDenied_Text & "</a>"
  74. rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = 0
  75. Else
  76. If Err.Number <> 0 Then
  77. Err.Clear
  78. rgPrinters(ADSI_PRINTER_NAME, iPrinters) = objPrinter.Name
  79. rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_OPENING
  80. rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = ""
  81. rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = ""
  82. rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = L_Opening_Text
  83. rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = 0
  84. Else
  85. dwStatus = objPrinter.Status
  86. If objPrinter.Attributes And &H400 Then dwStatus = dwStatus Or &H80
  87. rgPrinters(ADSI_PRINTER_NAME, iPrinters) = GetFriendlyName (objPrinter.PrinterName, strServerName)
  88. rgPrinters(ADSI_PRINTER_STATUS, iPrinters) = dwStatus
  89. rgPrinters(ADSI_PRINTER_LOCATION, iPrinters) = strCleanString (objPrinter.Location)
  90. rgPrinters(ADSI_PRINTER_MODEL, iPrinters) = strCleanString (objPrinter.Model)
  91. rgPrinters(ADSI_PRINTER_COMMENT, iPrinters) = strCleanString (objPrinter.Description)
  92. rgPrinters(ADSI_PRINTER_JOBS, iPrinters) = objPrinter.JobCount
  93. If Err Then Exit Function
  94. rgPrinters(ADSI_PRINTER_ACCESS, iPrinters) = PRINTER_OK
  95. End If
  96. End If
  97. End If
  98. i = i + 1
  99. Next
  100. if iPrinters = 0 Then ReDim rgPrinters(ADSI_PRINTER_SHARE, 0)
  101. rgADSIGetPrinters = rgPrinters
  102. End Function
  103. Dim strLocal, rgPrinters, strTitle
  104. Dim iStart, iEnd, bShowNext
  105. 'Verify User Name
  106. If Request("v") = "1" And Session ("PASSWD_TYPED") = FALSE Then
  107. Session ("PASSWD_TYPED") = TRUE
  108. Err.Number = &H80070005
  109. Call ErrorHandler(strADSI)
  110. End If
  111. Session ("PASSWD_TYPED") = FALSE
  112. strLocal = request.ServerVariables("SERVER_NAME")
  113. const L_AllPrinters_Text = "All Printers on %1"
  114. strTitle = RepString1(L_AllPrinters_Text, strLocal)
  115. If Request("startid") = "" Or Request ("endid") = "" Then
  116. iStart = 1
  117. iEnd = iStart+ iPrinterLength
  118. Else
  119. iStart = Int (Request ("startid"))
  120. iEnd = Int (Request ("endid"))
  121. If (iEnd <= iStart) Then
  122. iEnd = iStart + iPrinterLength
  123. End If
  124. End If
  125. bShowNext = FALSE
  126. rgPrinters = rgADSIGetPrinters(strLocal, iStart, iEnd)
  127. If Err.Number <> 0 Then
  128. Dim strADSI
  129. strADSI = L_GetADSI_Message
  130. Call ErrorHandler(strADSI)
  131. End If
  132. %>
  133. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  134. <html lang=<%=L_Language%>>
  135. <head>
  136. <Meta Http-equiv="Content-Type" Content="text/html; CHARSET=UTF-8">
  137. <meta http-equiv="refresh" content="120">
  138. <title><% =Write(strTitle) %></title>
  139. </head>
  140. <%
  141. Dim strPrinterName
  142. strPrinterName = "<H2>" & strTitle & "</H2>"
  143. Function GenTableHead ()
  144. Dim L_TableTitle_Text(5)
  145. Dim strTableTitle(5) 'The reason we have to do this is that when we manipulate the string ,
  146. 'it is not localizable. This works around this problem
  147. Dim i
  148. Dim strHTML
  149. Dim Width
  150. 'Width = Array (200, 80, 200, 37, 194, 194)
  151. Const strSp = "&nbsp;&nbsp;"
  152. L_TableTitle_Text(0) = "Name"
  153. L_TableTitle_Text(1) = "Status"
  154. L_TableTitle_Text(2) = "Location"
  155. L_TableTitle_Text(3) = "Jobs"
  156. L_TableTitle_Text(4) = "Model"
  157. L_TableTitle_Text(5) = "Comment"
  158. For i = 0 to 5
  159. strTableTitle(i) = L_TableTitle_Text(i) & strSp
  160. Next
  161. strHTML = "<tr>"
  162. For i = 0 to 5
  163. strHTML = strHTML & "<td bgcolor=#000000 nowrap>" & MENU_FONT_TAG & "<b>" &_
  164. strTableTitle(i) & "</b>" & END_FONT & "</td>"
  165. Next
  166. strHTML = strHTML & "</tr>"
  167. GenTableHead = strHTML
  168. End Function
  169. Function GenTableBody ()
  170. Dim i
  171. Dim strHTML
  172. Dim TdStart, TdEnd
  173. TdStart = "<td nowrap>" & DEF_FONT_TAG
  174. TdEnd = END_FONT & "</td>"
  175. strHTML = ""
  176. For i = ubound(rgPrinters, 2) To 1 Step -1
  177. 'For i = 1 To ubound(rgPrinters, 2)
  178. strHTML = strHTML & "<tr>"
  179. Select Case rgPrinters(ADSI_PRINTER_ACCESS, i)
  180. Case PRINTER_OPENING
  181. strHTML = strHTML & TdStart & "<a href=""ipp_0001.asp" &_
  182. """ target=""_top"">" & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & "</a>" & TdEnd
  183. Case PRINTER_ACCESS_DENIED
  184. strHTML = strHTML & TdStart & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & TdEnd
  185. Case Else
  186. strHTML = strHTML & TdStart & "<a href=""ipp_0004.asp?view=q&eprinter=" &_
  187. OleCvt.EncodeUnicodeName(rgPrinters(ADSI_PRINTER_NAME, i)) &_
  188. ATPAGE & CStr(Int(Rnd*10000)) &_
  189. """ target=""_top"">" & strCleanString(rgPrinters(ADSI_PRINTER_NAME, i)) & "</a>" & TdEnd
  190. End Select
  191. If rgPrinters(ADSI_PRINTER_ACCESS, i) = PRINTER_OK Then
  192. strHTML = strHTML &_
  193. TdStart & strPrinterStatus (rgPrinters(ADSI_PRINTER_STATUS, i)) & TdEnd &_
  194. TdStart & rgPrinters(ADSI_PRINTER_LOCATION, i) & TdEnd &_
  195. TdStart & rgPrinters(ADSI_PRINTER_JOBS, i ) & TdEnd &_
  196. TdStart & rgPrinters(ADSI_PRINTER_MODEL, i) & TdEnd &_
  197. TdStart & rgPrinters(ADSI_PRINTER_COMMENT, i) & TdEnd
  198. Else
  199. strHTML = strHTML &_
  200. "<td>" & DEF_FONT_TAG & "<font color=""#7F7F7F"">" & rgPrinters(ADSI_PRINTER_COMMENT, i) & "</font>" & END_FONT & "</td>" &_
  201. "<td>&nbsp;</td>" &_
  202. "<td>&nbsp;</td>" &_
  203. "<td>&nbsp;</td>" &_
  204. "<td>&nbsp;</td>"
  205. End If
  206. strHTML = strHTML & "</tr>"
  207. Next
  208. GenTableBody = strHTML
  209. End Function
  210. %>
  211. <body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#808080" alink="#000000"
  212. topmargin="0" leftmargin="0">
  213. <table border="0" cellpadding="0" cellspacing="0" width="100%" height="175">
  214. <tr>
  215. <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="1">
  216. <tr>
  217. <td width="12%"><img src="images/ipp_0002.gif" alt="printers.gif"></td>
  218. <td width="88%"><%=Write(CLIENT_FONT & strPrinterName & END_FONT)%></td>
  219. </tr>
  220. </table>
  221. </td>
  222. </tr>
  223. <tr>
  224. <td height="11"></td>
  225. </tr>
  226. <tr>
  227. <td height="55"><table width=100% border="0" cellspacing="0" cellpadding="2">
  228. <%=Write (GenTableHead)%>
  229. <%=Write (GenTableBody)%>
  230. </table>
  231. </td>
  232. </tr>
  233. </table>
  234. <p>
  235. <%
  236. Dim strUrl
  237. Const L_Prev_Text = "Prev %1 printers"
  238. Const L_Next_Text = "Next %1 printers"
  239. strUrl = "<a target=_top href=ipp_0001.asp?startid=" & CStr(iStart - iPrinterLength) & "&endid=" & CStr(iEnd - iPrinterLength) & ">" & RepString1(L_Prev_Text, CStr (iPrinterLength)) & "</a>&nbsp;&nbsp;&nbsp;&nbsp;"
  240. If iStart > 1 Then
  241. Response.Write ( Write(DEF_FONT_TAG & strUrl & END_FONT))
  242. End If
  243. strUrl = "<a target=_top href=ipp_0001.asp?startid=" & CStr(iStart + iPrinterLength) & "&endid=" & CStr(iEnd+iPrinterLength) & ">" & RepString1(L_Next_Text , CStr (iPrinterLength)) & "</a>"
  244. If bShowNext Then
  245. Response.Write ( Write(DEF_FONT_TAG & strUrl & END_FONT))
  246. End If
  247. %>
  248. </body>
  249. </html>