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.

390 lines
13 KiB

  1. <%
  2. '------------------------------------------------------------
  3. '
  4. ' Microsoft Internet Printing Project
  5. '
  6. ' Copyright (c) Microsoft Corporation. All rights reserved.
  7. '
  8. '------------------------------------------------------------
  9. %>
  10. <%
  11. ' Replace EN-US with localized language code. E.g. "HE" -- Hebrew.
  12. Const L_Language = "EN-US"
  13. Const L_DocumentList_Text = "Document List"
  14. Const L_DerivedFont_Text = " face=""Tahoma, Verdana, Arial, MS Sans Serif"" "
  15. Const L_DoubleDevFont_Text = " face=""""Tahoma, Verdana, Arial, MS Sans Serif"""" "
  16. Const PROGID_CLIENT_HELPER = "OlePrn.PrinterURL"
  17. Const PROGID_SNMP = "OlePrn.OleSNMP"
  18. Const PROGID_HELPER = "OlePrn.AspHelp"
  19. Const PROGID_CONVERTER = "OlePrn.OleCvt"
  20. Const PROGID_ADDPRINTER = "OlePrn.AddPrint"
  21. Const VIEW_EQUALS = "&view="
  22. Const ONCLICK_EQUALS = " onclick="
  23. Const QUOTE = """"
  24. Const QUEUE_VIEW = "ipp_0007.asp"
  25. Const PROPERTY_VIEW = "ipp_0006.asp"
  26. Const UNAUTHORIZED_401 = "401 Unauthorized"
  27. Const FAXDRIVER = "Microsoft Shared Fax Driver"
  28. Const COMPUTER = "MS_Computer"
  29. Const LOCAL_SERVER = "MS_LocalServer"
  30. Const DHTML_ENABLED = "MS_DHTMLEnabled"
  31. Const DEFAULT_PAGE = "MS_DefaultPage"
  32. Const PRINTER = "MS_Printer"
  33. Const URLPRINTER = "MS_URLPrinter"
  34. Const SNMP = "MS_SNMP"
  35. Const IPADDRESS = "MS_IPAddress"
  36. Const COMMUNITY = "MS_Community"
  37. Const DEVICE = "MS_Device"
  38. Const PORTNAME = "MS_Portname"
  39. Const MODEL = "MS_Model"
  40. Const ASP1 = "MS_ASP1"
  41. Const CONNECT = "showconnect"
  42. Const ATPRINTER = "&MS_Printer="
  43. Const ATURLPRINTER = "&MS_URLPrinter="
  44. Const ATSNMP = "&MS_SNMP="
  45. Const ATIPADDRESS = "&MS_IPAddress="
  46. Const ATCOMMUNITY = "&MS_Community="
  47. Const ATDEVICE = "&MS_Device="
  48. Const ATPORTNAME = "&MS_Portname="
  49. Const ATMODEL = "&MS_Model="
  50. Const ATASP1 = "&MS_ASP1="
  51. Const ATPAGE = "&page="
  52. Const ATCONNECT = "&showconnect="
  53. Dim DEF_FONT, DEF_BASEFONT_TAG, DEF_FONT_TAG, LARGE_FONT_TAG, MENU_FONT_TAG
  54. Dim SUBMENU_FONT, SUBMENU_FONT_TAG, CLIENT_FONT, DEF_DOUBLEFONT, DEF_DOUBLEFONT_TAG
  55. DEF_FONT = L_DerivedFont_Text
  56. DEF_DOUBLEFONT = L_DoubleDevFont_Text
  57. DEF_BASEFONT_TAG = "<basefont " & L_DerivedFont_Text & " size=2>"
  58. DEF_FONT_TAG = "<font " & L_DerivedFont_Text & " size=2>"
  59. LARGE_FONT_TAG = "<font " & L_DerivedFont_Text & " size=4>"
  60. MENU_FONT_TAG = "<font " & L_DerivedFont_Text & " size=2 color=white>"
  61. SUBMENU_FONT = L_DerivedFont_Text & " size=1 "
  62. SUBMENU_FONT_TAG = "<font " & L_DerivedFont_Text & " size=2>"
  63. CLIENT_FONT = "<font " & L_DerivedFont_Text & ">"
  64. Const END_FONT = "</font>"
  65. Dim OleCvt
  66. Set OleCvt = Server.CreateObject (PROGID_CONVERTER)
  67. Session.Codepage = 65001
  68. Function Write (strUnicode)
  69. Write = strUnicode
  70. End Function
  71. Function SubstituteString(strIn, strPattern, strReplacement)
  72. Dim iStrPos
  73. iStrPos = InStr(strIn,strPattern)
  74. SubstituteString = Left(strIn, iStrPos-1) & strReplacement & Mid(strIn, iStrPos + Len(strPattern))
  75. End Function
  76. Function RepString1( strIn, strRep )
  77. RepString1 = SubStituteString( strIn, "%1", strRep)
  78. End Function
  79. Function RepString2( strIn, strRep1, strRep2 )
  80. RepString2 = SubStituteString( RepString1(strIn, strRep1) , "%2", strRep2)
  81. End Function
  82. Function RepString3( strIn, strRep1, strRep2, strRep3 )
  83. RepString3 = SubStituteString( RepString2(strIn, strRep1, StrRep2), "%3", strRep3)
  84. End Function
  85. Function GenErrorPage (iCode, strSource, strDscp, strNote)
  86. Dim strHTML
  87. Const L_ErrCode_Text = "<b>Error Code:</b>"
  88. Const L_ErrDscp_Text = "<b>Description:</b>"
  89. Const L_ErrNote_Text = "<b>Note:</b>"
  90. Const L_ErrTitle_Text = "Internet Printing Error"
  91. Const L_ErrSource_Text = "The error occurred in <b>%1</b>"
  92. Const L_ErrOccurProc_Text = "<p>An <b>error</b> occurred processing your request.</p>"
  93. strHTML = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
  94. strHTML = strHTML & "<html lang=" & L_Language & ">"
  95. strHTML = strHTML & "<head>"
  96. strHTML = strHTML & "<Meta Http-equiv=""Content-Type"" Content=""text/html; CHARSET=UTF-8"">"
  97. strHTML = strHTML & "<title>" & L_ErrTitle_Text & "</title>"
  98. strHTML = strHTML & "</head><body bgcolor=#FFFFFF>" & DEF_BASEFONT_TAG
  99. strHTML = strHTML & L_ErrOccurProc_Text
  100. If strSource <> "" Then
  101. strHTML = strHTML & RepString1(L_ErrSource_Text, strSource)
  102. End If
  103. strHTML = strHTML & "<table>"
  104. strHTML = strHTML & "<tr><td>" & L_ErrCode_Text & "</td><td>" & (Hex (iCode)) & "</td></tr>"
  105. If strDscp <> "" Then
  106. strHTML = strHTML & "<tr><td>" & L_ErrDscp_Text & "</td><td>" & strDscp & "</td></tr>"
  107. End If
  108. If strNote <> "" Then
  109. strHTML = strHTML & "<tr><td>" & L_ErrNote_Text & "</td><td>" & strNote & "</td></tr>"
  110. End If
  111. strHTML = strHTML & "</table></body></html>"
  112. GenErrorPage = strHTML
  113. End Function
  114. Sub ErrorHandler(strNotes)
  115. Dim strDscp, strSource
  116. Dim str401Error
  117. If Err.Number = 70 Or Err.Number = &H80070005 Then
  118. Const L_ErrTitle_Text = "Internet Printing Authentication Error"
  119. Const L_ErrTitle2_Text = "Authentication Failed"
  120. Const L_ErrLine1_Text = "The error indicates that the action you chose requires a higher privilege than what you have with your account."
  121. Const L_ErrLine2_Text = "Please contact your system administrator to verify that you have the privilege on the requested action."
  122. str401Error = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" &_
  123. "<html lang=" & L_Language & ">" &_
  124. "<head>" &_
  125. "<Meta Http-equiv=""Content-Type"" Content=""text/html; CHARSET=UTF-8"">" &_
  126. "<title>" & L_ErrTitle_Text & "</title>" & "</head>" &_
  127. "<body bgcolor=#FFFFFF>" &_
  128. DEF_FONT_TAG &_
  129. "<p><H2>" & L_ErrTitle2_Text & "</H2></p>" &_
  130. "<p>" & L_ErrLine1_Text &_
  131. "<br>" &_
  132. "<br>" & L_ErrLine2_Text & "</p>" &_
  133. "</font></body></html>"
  134. response.write (Write(str401Error))
  135. response.status = UNAUTHORIZED_401
  136. Else
  137. If Err.Number = &H80070709 Then
  138. Const L_ErrInvalidName_Text = "Printer not found on server, unable to connect."
  139. Err.Description = L_ErrInvalidName_Text
  140. End If
  141. response.write(Write(GenErrorPage (Err.Number, Err.Source, Err.Description, strCleanString(strNotes))))
  142. End If
  143. response.Expires = 0
  144. response.end
  145. End Sub
  146. Function bDHTMLSupported()
  147. On Error Resume Next
  148. Err.Clear
  149. Dim objBrowcap
  150. Set objBrowcap = server.CreateObject("MSWC.browsertype")
  151. If Not Err And objBrowcap.browser = "IE" And objBrowcap.majorver >= "4" Then
  152. bDHTMLSupported = True
  153. Else
  154. bDHTMLSupported = False
  155. End If
  156. End Function
  157. Sub CheckSession()
  158. ' check to see if the session has timed out
  159. If Session(COMPUTER) = "" Then
  160. response.redirect ("ipp_0003.asp")
  161. response.end
  162. End If
  163. End Sub
  164. Function strPrinterStatus(iStatus)
  165. Dim L_PrinterStatus_Text(24)
  166. Const L_Seperator_Text = " - "
  167. Const L_PrinterReady_Text = "Ready"
  168. L_PrinterStatus_Text(0) = "Paused"
  169. L_PrinterStatus_Text(1) = "Error"
  170. L_PrinterStatus_Text(2) = "Deleting"
  171. L_PrinterStatus_Text(3) = "Paper Jam"
  172. L_PrinterStatus_Text(4) = "Out of Paper"
  173. L_PrinterStatus_Text(5) = "Manual Feed Required"
  174. L_PrinterStatus_Text(6) = "Paper Problem"
  175. L_PrinterStatus_Text(7) = "Printer Offline"
  176. L_PrinterStatus_Text(8) = "IO Active"
  177. L_PrinterStatus_Text(9) = "Busy"
  178. L_PrinterStatus_Text(10) = "Printing"
  179. L_PrinterStatus_Text(11) = "Output Bin Full"
  180. L_PrinterStatus_Text(12) = "Not Available"
  181. L_PrinterStatus_Text(13) = "Waiting"
  182. L_PrinterStatus_Text(14) = "Processing"
  183. L_PrinterStatus_Text(15) = "Initializing"
  184. L_PrinterStatus_Text(16) = "Warming Up"
  185. L_PrinterStatus_Text(17) = "Toner Low"
  186. L_PrinterStatus_Text(18) = "No Toner"
  187. L_PrinterStatus_Text(19) = "Page Punt"
  188. L_PrinterStatus_Text(20) = "User Intervention Required"
  189. L_PrinterStatus_Text(21) = "Out of Memory"
  190. L_PrinterStatus_Text(22) = "Door Open"
  191. L_PrinterStatus_Text(23) = "Server Status Unknown"
  192. L_PrinterStatus_Text(24) = "Power Save Mode"
  193. Dim bit, i
  194. bit = 1
  195. i = 0
  196. Dim strHTML, bFirst
  197. bFirst = True
  198. strHTML = ""
  199. For i = 0 To 24
  200. If iStatus And bit Then
  201. If Not bFirst Then
  202. strHTML = strHTML + L_Seperator_Text
  203. End If
  204. strHTML = strHTML + L_PrinterStatus_Text(i)
  205. bFirst = False
  206. End If
  207. bit = bit * 2
  208. Next
  209. If bFirst Then
  210. strHTML = "<font color=green>" & L_PrinterReady_Text & "</font>"
  211. Else
  212. strHTML = "<font color=red>" & strHTML & "</font>"
  213. End If
  214. strPrinterStatus = strHTML
  215. End Function
  216. Function strFormatJobSize(iJobSize)
  217. Const L_Bytes_Text = "%1 bytes"
  218. Const L_KiloBytes_Text = "%1 Kb"
  219. Const L_MegaBytes_Text = "%1 Mb"
  220. If iJobSize < 1024 Then
  221. strFormatJobSize = RepString1(L_Bytes_Text, CStr(iJobSize) )
  222. ElseIf iJobSize < 1048576 Then
  223. strFormatJobSize = RepString1(L_KiloBytes_Text, formatnumber(iJobSize / 1024, 1) )
  224. Else
  225. strFormatJobSize = RepString1(L_MegaBytes_Text, formatnumber(iJobSize / (1024 * 1024), 1) )
  226. End If
  227. End Function
  228. Function strFormatString(str)
  229. If str = "" Then
  230. strFormatString = "&nbsp;"
  231. Else
  232. strFormatString = str
  233. End If
  234. End Function
  235. Function strCleanString (str)
  236. Dim strClean, i, iLength, ch
  237. strClean = ""
  238. iLength = Len (str)
  239. For i = 1 To iLength
  240. ch = Mid (str, i, 1)
  241. Select Case ch
  242. Case "<"
  243. strClean = strClean & "&lt;"
  244. Case ">"
  245. strClean = strClean & "&gt;"
  246. Case """"
  247. strClean = strClean & "&quot;"
  248. Case "&"
  249. strClean = strClean & "&amp;"
  250. Case Else
  251. strClean = strClean & ch
  252. End Select
  253. Next
  254. strCleanString = strClean
  255. End Function
  256. Function strCleanRequest (str)
  257. strCleanRequest = strCleanString (Request(str))
  258. End Function
  259. Function JobEtaInfo (objPrinter)
  260. Dim strTime, iJobCount, iMinute
  261. Dim strHTML
  262. Const L_NoJobPending_Text = "&nbsp;&nbsp;&nbsp;&nbsp;<b>Waiting Time:</b> 0 <br><b>Pending Documents:</b> 0 "
  263. Const L_ErrorNoJobCompletion_Text = "<font color=red>Error in printing</font> "
  264. Const L_LongHour_Text = "> 8 hr"
  265. Const L_About_Text = "about "
  266. Const L_Hour_Text = " hr"
  267. Const L_Minute_Text = " min"
  268. Const L_QueueStatus_Text = "<b>Printer Queue:</b> "
  269. Const L_WaitingTime_Text = " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Waiting Time:</b> "
  270. Const L_Unknown_Text = "Unknown"
  271. Const L_JobPending_Text = "<b>Pending Documents:</b> "
  272. Const L_AvgSize_Text = " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Average size:</b> "
  273. Const L_Pages_Text = " page(s)"
  274. strHTML = L_QueueStatus_Text & strPrinterStatus (objPrinter.Status) & L_WaitingTime_Text
  275. objPrinter.CalcJobETA
  276. If ( objPrinter.Status And &H9F ) Then
  277. strHTML = strHTML & L_Unknown_Text
  278. 'End If
  279. 'If 1 Then
  280. Else
  281. If objPrinter.PendingJobCount = 0 Then
  282. strHTML = strHTML & "0"
  283. Else
  284. iMinute = objPrinter.JobCompletionMinute
  285. 'iMinute = 240 'For testing purpose
  286. If iMinute <> -1 Then
  287. If iMinute > 480 Then
  288. strTime = L_LongHour_Text
  289. Elseif iMinute > 60 Then
  290. strTime = L_About_Text & CStr (Int (iMinute / 60)) & L_Hour_Text
  291. Else
  292. strTime = L_About_Text & CStr (iMinute) & L_Minute_Text
  293. End If
  294. strHTML = strHTML & strTime
  295. Else
  296. strHTML = strHTML & L_Unknown_Text
  297. End If
  298. End If
  299. End If
  300. strHTML = strHTML & "<br>"
  301. iJobCount = objPrinter.PendingJobCount
  302. strHTML = strHTML & L_JobPending_Text & CStr (iJobCount)
  303. If iJobCount > 0 Then
  304. strHTML = strHTML & L_AvgSize_Text
  305. If ObjPrinter.AvgJobSizeUnit = 1 Then 'Page
  306. strHTML = strHTML & CStr (ObjPrinter.AvgJobSize) + L_Pages_Text
  307. Else
  308. strHTML = strHTML & strFormatJobSize(ObjPrinter.AvgJobSize)
  309. End If
  310. End If
  311. JobEtaInfo = "<font " & DEF_FONT & "size= -1>" & strHTML & "</font>"
  312. End Function
  313. Function GetFriendlyName (strPrtName, strComputer)
  314. Dim lOffset, strServerName
  315. If Left (strPrtName, 2) = "\\" Then
  316. lOffset = InStr (3, strPrtName, "\")
  317. strServerName = Mid (strPrtName, 3, lOffset - 3)
  318. If strServerName = strComputer Then 'Cut the server name only if it is same as the computer name
  319. strPrtName = Mid (strPrtName, lOffset + 1)
  320. End If
  321. End If
  322. GetFriendlyName = strPrtName
  323. End Function
  324. %>