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.

313 lines
9.3 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 printer view.
  10. '
  11. '------------------------------------------------------------
  12. option explicit
  13. %>
  14. <!-- #include file = "ipp_util.inc" -->
  15. <%
  16. Const PRINTER_FOLDER = "pfld"
  17. Const L_PrinterAction_Text = "Printer Action"
  18. Const L_JobAction_Text = "Job Action"
  19. Const L_CancelAction_Text = "The document could not be cancelled. It might have been printed already, or cancelled by another user."
  20. Const L_OpenHelperName_Text = "Open Helper: %1"
  21. Const L_OpenHelper_Text = "Open Helper"
  22. Dim strEncodedPrinter, strURLPrinter, strASP1, strSNMP, strIPAddress, strCommunity
  23. Dim strDevice, strPortname, strModel, bEnableConnect
  24. Randomize
  25. Sub Redirect (strView, strStart, strEnd)
  26. Dim strURL
  27. strURL = "ipp_0004.asp?eprinter=" & strEncodedPrinter & VIEW_EQUALS & strView & ATPAGE & CStr(Int(Rnd*10000))
  28. If strView = "q" Then
  29. If (strStart <> "" And strEnd <> "") Then
  30. strURL = strURL & "&startid=" & strStart & "&endid=" & strEnd
  31. End If
  32. End If
  33. Response.Redirect (strURL)
  34. End Sub
  35. Sub SetPrinterVariables (objHelper, strPrinter)
  36. On Error Resume Next
  37. Dim str
  38. strUrlPrinter = Server.URLEncode(strPrinter)
  39. str = objHelper.ASPPage(1)
  40. If Err Then
  41. strASP1 = ""
  42. Else
  43. strASP1 = str
  44. End If
  45. If CBool( objHelper.IsTCPMonSupported ) Then
  46. bSNMP = CBool( objHelper.SNMPSupported )
  47. strSNMP = CStr( bSNMP )
  48. strIPAddress = CStr( objHelper.IPAddress )
  49. If bSNMP Then
  50. strCommunity = objHelper.Community
  51. strDevice = CStr( objHelper.SNMPdevice )
  52. End If
  53. Else
  54. strSNMP = ""
  55. strIPAddress = ""
  56. strCommunity = ""
  57. strDevice = ""
  58. End If
  59. session(LOCAL_SERVER) = request.ServerVariables("SERVER_NAME")
  60. session(DHTML_ENABLED) = bDHTMLSupported
  61. strPortname = OleCvt.EncodeUnicodeName( objHelper.PortName )
  62. session(DEFAULT_PAGE) = "/printers/Page1.asp"
  63. strModel = OleCvt.EncodeUnicodeName( objHelper.DriverName )
  64. If objHelper.DriverName = FAXDRIVER Then
  65. bEnableConnect = FALSE
  66. Else
  67. bEnableConnect = TRUE
  68. end If
  69. End Sub
  70. Function SetView (strClient, strPrinter, strView, strStart, strEnd)
  71. dim bDeviceStatus
  72. bDeviceStatus = False
  73. if Session("StartInstall") = 1 Then
  74. strView = "p"
  75. strInitial = "ipp_0010.asp?eprinter=" & Request ("eprinter")
  76. Else
  77. if strClient = PRINTER_FOLDER Then
  78. If strASP1 <> "" Then
  79. strView = "q"
  80. strInitial = strASP1
  81. Else
  82. strView = "p"
  83. strInitial = PROPERTY_VIEW
  84. End If
  85. Else
  86. if strView = "" Then strView = "d"
  87. Select Case strView
  88. Case "p"
  89. strInitial = PROPERTY_VIEW
  90. Case "q"
  91. strInitial = QUEUE_VIEW
  92. Case "d"
  93. strInitial = strASP1
  94. If strInitial = "" Then
  95. strView = "q"
  96. strInitial = QUEUE_VIEW
  97. End If
  98. case Else
  99. strView = "q"
  100. strInitial = QUEUE_VIEW
  101. End Select
  102. End If
  103. if strInitial = strASP1 then
  104. bDeviceStatus = True
  105. end if
  106. strInitial = strInitial & "?eprinter=" & strEncodedPrinter & VIEW_EQUALS & strView
  107. if bDeviceStatus then
  108. strInitial = strInitial & ATPRINTER & strEncodedPrinter & ATURLPRINTER & strURLPrinter &_
  109. ATSNMP & strSNMP & ATIPADDRESS & strIPAddress &_
  110. ATCOMMUNITY & strCommunity & ATDEVICE & strDevice &_
  111. ATPORTNAME & strPortname & ATMODEL & strModel
  112. End If
  113. strInitial = strInitial & ATASP1 & strASP1
  114. strInitial = strInitial & ATPAGE & CStr(Int(Rnd*10000))
  115. If strStart <> "" And strEnd <> "" Then
  116. strInitial = strInitial & "&startid=" & strStart & "&endid=" & strEnd
  117. End If
  118. End If
  119. SetView = strView
  120. End Function
  121. Function FindJob (objJobs, strJobid, objJob)
  122. FindJob = FALSE
  123. If strJobid = "" Then Exit Function
  124. For Each objJob In objJobs
  125. If objJob.Name = strJobid Then
  126. FindJob = True
  127. Exit For
  128. End If
  129. Next
  130. End Function
  131. Sub DoAction (strAction, objQueue, strJobid, strStart, strEnd)
  132. On Error Resume Next
  133. Err.Clear
  134. Dim objJobs, objJob
  135. Select Case strAction
  136. Case "pause"
  137. objQueue.Pause
  138. If Err Then Call ErrorHandler (L_PrinterAction_Text)
  139. Redirect "p", strStart, strEnd
  140. Case "resume"
  141. objQueue.Resume
  142. If Err Then Call ErrorHandler (L_PrinterAction_Text)
  143. Redirect "p", strStart, strEnd
  144. Case "purge"
  145. objQueue.Purge
  146. If Err Then Call ErrorHandler (L_PrinterAction_Text)
  147. Redirect "q", strStart, strEnd
  148. Case "canceljob"
  149. Set objJobs = objQueue.PrintJobs
  150. If FindJob (objJobs, strJobid, objJob) Then
  151. objJobs.Remove CStr(strJobid)
  152. Else
  153. Call ErrorHandler(L_CancelAction_Text)
  154. End if
  155. If Err Then Call ErrorHandler (L_JobAction_Text)
  156. Redirect "q", strStart, strEnd
  157. Case "resumejob"
  158. Set objJobs = objQueue.PrintJobs
  159. If FindJob (objJobs, strJobid, objJob) Then objJob.resume
  160. If Err Then Call ErrorHandler (L_JobAction_Text)
  161. Redirect "q", strStart, strEnd
  162. Case "pausejob"
  163. Set objJobs = objQueue.PrintJobs
  164. If FindJob (objJobs, strJobid, objJob) Then objJob.pause
  165. If Err Then Call ErrorHandler (L_JobAction_Text)
  166. Redirect "q", strStart, strEnd
  167. End Select
  168. End Sub
  169. Dim strPrinter, objHelper, str, bSNMP, strInitial, strView, strClient, strAction
  170. Dim strComputer
  171. On Error Resume Next
  172. Err.Clear
  173. Rem
  174. Rem Parse the input variable
  175. Rem
  176. strEncodedPrinter = strCleanRequest ("eprinter")
  177. if strEncodedPrinter = "" Then
  178. Response.Redirect ("ipp_0001.asp")
  179. Else
  180. Rem
  181. Rem Decode the printer name
  182. Rem
  183. strPrinter = OleCvt.DecodeUnicodeName (strEncodedPrinter)
  184. End If
  185. Set objHelper = Server.CreateObject(PROGID_HELPER)
  186. If Err Then Call ErrorHandler(ERR_CREATE_HELPER_OBJ)
  187. strComputer = request.ServerVariables("SERVER_NAME")
  188. If strComputer = "localhost" Or strComputer = "127.0.0.1" or Not CBool(objHelper.IsCluster) Then
  189. strComputer = objHelper.ComputerName
  190. End If
  191. session(COMPUTER) = strComputer
  192. objHelper.open "\\" & strComputer & "\" & strPrinter
  193. if Err Then
  194. Call ErrorHandler(RepString1(L_OpenHelperName_Text, strPrinter) )
  195. End If
  196. strPrinter = objHelper.ShareName
  197. strEncodedPrinter = OleCvt.EncodeUnicodeName (strPrinter)
  198. Dim objQueue
  199. Set objQueue = GetObject("WinNT://" & strComputer & "/" & strPrinter & ",PrintQueue")
  200. If Err Then
  201. Err.Number = &H80070709
  202. Call ErrorHandler(L_OpenHelper_Text)
  203. End If
  204. strAction = Request("action")
  205. If strAction <> "" Then
  206. Call DoAction (strAction, objQueue, Request ("jobid"), Request ("StartId"), Request ("EndId"))
  207. End If
  208. strClient = Request("Client")
  209. Call SetPrinterVariables (objHelper, strPrinter)
  210. objHelper.Close
  211. strView = SetView (strClient, strPrinter, Request ("View"), Request ("StartId"), Request ("EndId"))
  212. Response.Expires = 0
  213. %>
  214. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  215. <html lang=<%=L_Language%>>
  216. <head>
  217. <Meta Http-equiv="Content-Type" Content="text/html; CHARSET=UTF-8">
  218. <%
  219. Dim strTitle
  220. Dim strLeftPaneUrl
  221. Dim strConnect
  222. const L_Title_Text = "<title>%1 on %2</title>"
  223. const L_FramesWarning_Text = "This web page uses frames, but your browser doesn't support them."
  224. strTitle = RepString2(L_Title_Text, strCleanString( GetFriendlyName (objQueue.PrinterName, session(COMPUTER))), session(LOCAL_SERVER) )
  225. If bEnableConnect Then
  226. strConnect = "1"
  227. Else
  228. strConnect = "0"
  229. End If
  230. strLeftPaneUrl = "ipp_0005.asp?eprinter=" & strEncodedPrinter & VIEW_EQUALS & strView & ATCONNECT & strConnect & ATURLPRINTER & strURLPrinter
  231. strLeftPaneUrl = strLeftPaneUrl & ATASP1 & strASP1 & ATPAGE & CStr(Int(Rnd*10000))
  232. %>
  233. <% =Write (strTitle) %>
  234. </head>
  235. <frameset frameborder="0" framespacing="10" cols="180,*">
  236. <frame src="<%=strLeftPaneUrl%>" name="contents" scrolling="auto" noresize>
  237. <frameset frameborder="0" framespacing="0" rows="100,*">
  238. <frame scrolling="auto" src="ipp_0002.asp?eprinter=<%=strEncodedPrinter%>&page=<%=CStr(Int(Rnd*10000))%>" frameborder="0" name="banner" scrolling="no" noresize>
  239. <frame src="<% =strinitial%>" frameborder="0" name="main" scrolling="auto">
  240. </frameset>
  241. <noframes>
  242. <body>
  243. <p><%=Write(L_FramesWarning_Text)%></p>
  244. </body>
  245. </noframes>
  246. </frameset>
  247. </html>