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.

498 lines
16 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' POP3 Mail Add-in - Master Settings
  6. ' Copyright (C) Microsoft Corporation. All rights reserved.
  7. '-------------------------------------------------------------------------
  8. %>
  9. <!-- #include virtual="/admin/inc_framework.asp" -->
  10. <!-- #include virtual="/admin/ots_main.asp" -->
  11. <!-- #include file="p3cminc.asp" -->
  12. <%
  13. '-------------------------------------------------------------------------
  14. ' Global Constants
  15. '-------------------------------------------------------------------------
  16. Dim SOURCE_FILE
  17. SOURCE_FILE = SA_GetScriptFileName()
  18. Const c_nMaxPort = 65535
  19. Const FLD_AUTHENTICATION = "fldAuthentication"
  20. Const FLD_PORT = "fldPort"
  21. Const FLD_LOGGING = "fldLogging"
  22. Const FLD_MAILROOT = "fldMailRoot"
  23. Const FLD_REQUIRESPA = "fldRequireSPA"
  24. Const FLD_SERVICERESTART = "fldServiceRestart"
  25. Const SERVICE_RESTART_NONE = 0
  26. Const SERVICE_RESTART_POP3SVC = 1
  27. Const SERVICE_RESTART_POP3SVC_SMTP = 2
  28. Const SERVICE_CONTROL_STOP = 1
  29. '-------------------------------------------------------------------------
  30. ' Global Variables
  31. '-------------------------------------------------------------------------
  32. Dim g_page
  33. Dim g_nAuthentication
  34. Dim g_nPort
  35. Dim g_nLoggingLevel
  36. Dim g_strMailRoot
  37. Dim g_bSPARequired
  38. Dim g_nDomains
  39. Dim g_iServiceRestart
  40. '----------------------------------------------------------------------
  41. ' Global Localized Strings
  42. '----------------------------------------------------------------------
  43. Dim l_strPageTitle
  44. l_strPageTitle = GetLocString(RES_DLL_NAME, _
  45. POP3_PAGETITLE_MASTERSETTINGS, _
  46. "")
  47. Dim l_strCaptionAuthentication
  48. l_strCaptionAuthentication = GetLocString(RES_DLL_NAME, _
  49. POP3_CAPTION_MASTERSETTINGS_AUTHENTICATION, _
  50. "")
  51. Dim l_astrAuthentication(3)
  52. l_astrAuthentication(AUTH_AD) = GetLocString(RES_DLL_NAME, _
  53. POP3_AUTHENTICATION_ACTIVEDIRECTORY, _
  54. "")
  55. l_astrAuthentication(AUTH_SAM) = GetLocString(RES_DLL_NAME, _
  56. POP3_AUTHENTICATION_WINDOWSACCOUNTS, _
  57. "")
  58. l_astrAuthentication(AUTH_FILE) = GetLocString(RES_DLL_NAME, _
  59. POP3_AUTHENTICATION_FILE, _
  60. "")
  61. Dim l_strCaptionPort
  62. l_strCaptionPort = GetLocString(RES_DLL_NAME, _
  63. POP3_CAPTION_MASTERSETTINGS_PORT, _
  64. "")
  65. Dim l_strCaptionLoggingLevel
  66. l_strCaptionLoggingLevel = GetLocString(RES_DLL_NAME, _
  67. POP3_CAPTION_MASTERSETTINGS_LOGGING, _
  68. "")
  69. Dim l_astrLogging(3)
  70. l_astrLogging(LOGGING_NONE) = GetLocString(RES_DLL_NAME, _
  71. POP3_LOGGING_NONE, _
  72. "")
  73. l_astrLogging(LOGGING_MINIMUM) = GetLocString(RES_DLL_NAME, _
  74. POP3_LOGGING_MINIMUM, _
  75. "")
  76. l_astrLogging(LOGGING_MEDIUM) = GetLocString(RES_DLL_NAME, _
  77. POP3_LOGGING_MEDIUM, _
  78. "")
  79. l_astrLogging(LOGGING_MAXIMUM) = GetLocString(RES_DLL_NAME, _
  80. POP3_LOGGING_MAXIMUM, _
  81. "")
  82. Dim l_strCaptionMailRoot
  83. l_strCaptionMailRoot = GetLocString(RES_DLL_NAME, _
  84. POP3_CAPTION_MASTERSETTINGS_MAILROOT, _
  85. "")
  86. Dim l_strConfirmNewMailRoot
  87. l_strConfirmNewMailRoot = GetLocString(RES_DLL_NAME, _
  88. POP3_PROMPT_MAILROOTCONFIRM, _
  89. "")
  90. Dim l_strConfirmPOP3ServiceRestart
  91. l_strConfirmPOP3ServiceRestart = GetLocString(RES_DLL_NAME, _
  92. POP3_PROMPT_SERVICERESTART_POP3SVC, _
  93. "")
  94. Dim l_strConfirmPOP3SMTPServiceRestart
  95. l_strConfirmPOP3SMTPServiceRestart = GetLocString(RES_DLL_NAME, _
  96. POP3_PROMPT_SERVICERESTART_POP3SVC_SMTP, _
  97. "")
  98. Dim l_strCaptionRequireSPA
  99. l_strCaptionRequireSPA = GetLocString ( RES_DLL_NAME, _
  100. POP3_CAPTION_MASTERSETTINGS_REQUIRESPA, _
  101. "" )
  102. Dim l_strErrInvalidPort
  103. l_strErrInvalidPort = GetLocString(RES_DLL_NAME, _
  104. POP3_E_INVALIDPORT, _
  105. "")
  106. '**********************************************************************
  107. '* E N T R Y P O I N T
  108. '**********************************************************************
  109. Call SA_CreatePage(l_strPageTitle, "", PT_PROPERTY, g_page)
  110. Call SA_ShowPage (g_page)
  111. '**********************************************************************
  112. '* H E L P E R S U B R O U T I N E S
  113. '**********************************************************************
  114. '---------------------------------------------------------------------
  115. ' ServeCommonJavaScript
  116. '---------------------------------------------------------------------
  117. Function ServeCommonJavaScript()
  118. %>
  119. <script language="JavaScript" src="../inc_global.js">
  120. </script>
  121. <script language="JavaScript">
  122. var g_strOriginalMailRoot;
  123. function Init()
  124. {
  125. g_strOriginalMailRoot = document.getElementsByName("<%=FLD_MAILROOT%>").item(0).value;
  126. g_nPort = document.getElementsByName("<%=FLD_PORT%>").item(0).value;
  127. g_nLoggingLevel = document.getElementsByName("<%=FLD_LOGGING%>").item(0).value;
  128. // Update the checkbox enabled state.
  129. OnAuthenticationChanged();
  130. g_bSPARequired = document.getElementsByName("<%=FLD_REQUIRESPA%>").item(0).checked;
  131. }
  132. function ValidatePage()
  133. {
  134. var strPort = document.getElementsByName("<%=FLD_PORT%>").item(0).value;
  135. var strLoggingLevel = document.getElementsByName("<%=FLD_LOGGING%>").item(0).value;
  136. var strSPARequired = document.getElementsByName("<%=FLD_REQUIRESPA%>").item(0).checked;
  137. var strNewMailRoot = document.getElementsByName("<%=FLD_MAILROOT%>").item(0).value;
  138. try
  139. {
  140. var nPort = parseInt(strPort);
  141. if ( isNaN(nPort) || 1 > nPort || <%= c_nMaxPort %> < nPort || nPort != strPort )
  142. {
  143. SA_DisplayErr("<%=SA_EncodeQuotes(Server.HTMLEncode(l_strErrInvalidPort))%>");
  144. return false;
  145. }
  146. }
  147. catch(e)
  148. {
  149. SA_DisplayErr("<%=SA_EncodeQuotes(Server.HTMLEncode(l_strErrInvalidPort))%>");
  150. return false;
  151. }
  152. var nDomains = document.getElementsByName("fldNumDomains").item(0).value;
  153. var bRC = true;
  154. if(strNewMailRoot != g_strOriginalMailRoot && nDomains > 0)
  155. {
  156. bRC = confirm("<%=SA_EncodeQuotes( l_strConfirmNewMailRoot )%>");
  157. }
  158. if ( bRC )
  159. {
  160. var nServiceRestart = "<%=SERVICE_RESTART_NONE%>";
  161. if ( strPort != g_nPort || strSPARequired != g_bSPARequired )
  162. {
  163. nServiceRestart = "<%=SERVICE_RESTART_POP3SVC%>";
  164. }
  165. if ( strNewMailRoot != g_strOriginalMailRoot || strLoggingLevel != g_nLoggingLevel )
  166. {
  167. nServiceRestart = "<%=SERVICE_RESTART_POP3SVC_SMTP%>";
  168. }
  169. if ( "<%=SERVICE_RESTART_POP3SVC%>" == nServiceRestart )
  170. {
  171. if ( confirm("<%=SA_EncodeQuotes( l_strConfirmPOP3ServiceRestart )%>"))
  172. {
  173. document.getElementsByName("<%=FLD_SERVICERESTART%>").item(0).value = nServiceRestart;
  174. }
  175. }
  176. if ( "<%=SERVICE_RESTART_POP3SVC_SMTP%>" == nServiceRestart )
  177. {
  178. if ( confirm("<%=SA_EncodeQuotes( l_strConfirmPOP3SMTPServiceRestart )%>"))
  179. {
  180. document.getElementsByName("<%=FLD_SERVICERESTART%>").item(0).value = nServiceRestart;
  181. }
  182. }
  183. }
  184. return bRC;
  185. }
  186. function SetData(){}
  187. </script>
  188. <%
  189. End Function
  190. '**********************************************************************
  191. '* E V E N T H A N D L E R S
  192. '**********************************************************************
  193. '---------------------------------------------------------------------
  194. ' OnInitPage
  195. '---------------------------------------------------------------------
  196. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  197. On Error Resume Next
  198. OnInitPage = TRUE
  199. Dim oConfig
  200. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  201. g_nLoggingLevel = oConfig.LoggingLevel
  202. g_strMailRoot = oConfig.MailRoot
  203. g_nPort = CLng(oConfig.Service.Port)
  204. g_nAuthentication = oConfig.Authentication.CurrentAuthMethod
  205. g_nDomains = oConfig.Domains.Count
  206. g_bSPARequired = oConfig.Service.SPARequired
  207. g_iServiceRestart = CInt(SERVICE_RESTART_NONE)
  208. If (Err.number <> 0) Then
  209. Call SA_SetErrMsg( HandleUnexpectedError() )
  210. End If
  211. End Function
  212. '---------------------------------------------------------------------
  213. ' OnServePropertyPage
  214. '---------------------------------------------------------------------
  215. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  216. On Error Resume Next
  217. '
  218. ' Emit Javascript functions required by Web Framework
  219. Call ServeCommonJavaScript()
  220. OnServePropertyPage = TRUE
  221. '
  222. ' Disable the authentication dropdown unless no domains have been
  223. ' created for this server.
  224. '
  225. Dim strAuthenticationDisabled
  226. If (g_nDomains > 0) Then
  227. strAuthenticationDisabled = "DISABLED"
  228. Else
  229. strAuthenticationDisabled = ""
  230. End If
  231. Dim strSelected ' Used to select the current value in the dropdowns below.
  232. strSelected = ""
  233. Dim oConfig, iType, iCount
  234. Dim iAuthFileType
  235. iAuthFileType = -1
  236. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  237. iCount = oConfig.Authentication.Count
  238. For iType = 1 To iCount
  239. If ( AUTH_FILE = oConfig.Authentication.Item(CLng(iType)).ID ) Then
  240. iAuthFileType = iCount
  241. End If
  242. Next
  243. %>
  244. <SCRIPT LANGUAGE="javascript">
  245. function OnAuthenticationChanged()
  246. {
  247. var oDropDown = document.getElementsByName("<%=FLD_AUTHENTICATION%>").item(0);
  248. var oRequireSPA = document.getElementsByName("<%=FLD_REQUIRESPA%>").item(0);
  249. var nAuthentication = oDropDown.options(oDropDown.selectedIndex).value;
  250. if ( nAuthentication == "<%=iAuthFileType%>" )
  251. {
  252. oRequireSPA.disabled = true ;
  253. oRequireSPA.checked = false ;
  254. }
  255. else
  256. {
  257. oRequireSPA.disabled = false ;
  258. oRequireSPA.checked = <%= CStr(g_bSPARequired) %> ;
  259. }
  260. }
  261. </SCRIPT>
  262. <TABLE CLASS="TasksBody" CELLPADDING=0 CELLSPACING=0>
  263. <TR>
  264. <TD CLASS="TasksBody">
  265. <%=Server.HTMLEncode(l_strCaptionAuthentication)%>
  266. </TD>
  267. <TD CLASS="TasksBody">
  268. <SELECT CLASS="FormField"
  269. NAME="<%=FLD_AUTHENTICATION%>"
  270. ONCHANGE="OnAuthenticationChanged();"
  271. <%=strAuthenticationDisabled%>>
  272. <%
  273. 'Dim oConfig, iType, iCount
  274. 'Set oConfig = Server.CreateObject("P3Admin.P3Config")
  275. 'iCount = oConfig.Authentication.Count
  276. For iType = 1 To iCount
  277. If (iType = oConfig.Authentication.CurrentAuthMethod) Then
  278. strSelected = "SELECTED"
  279. Else
  280. strSelected = ""
  281. End If
  282. %>
  283. <OPTION <%=strSelected%>
  284. VALUE="<%=iType%>"><%=Server.HTMLEncode(oConfig.Authentication.Item(CLng(iType)).Name)%></OPTION>
  285. <%
  286. Next
  287. %>
  288. </SELECT>
  289. </TD>
  290. </TR>
  291. <TR>
  292. <TD CLASS="TasksBody">
  293. <%=Server.HTMLEncode(l_strCaptionPort)%>
  294. </TD>
  295. <TD CLASS="TasksBody">
  296. <INPUT TYPE="text"
  297. CLASS="FormField"
  298. NAME="<%=FLD_PORT%>"
  299. VALUE="<%=g_nPort%>"
  300. SIZE="5"
  301. MAXLENGTH="5">
  302. </TD>
  303. </TR>
  304. <TR>
  305. <TD CLASS="TasksBody">
  306. <%=Server.HTMLEncode(l_strCaptionLoggingLevel)%>
  307. </TD>
  308. <TD CLASS="TasksBody">
  309. <SELECT CLASS="FormField" NAME="<%=FLD_LOGGING%>">
  310. <%
  311. Dim iLevel
  312. For iLevel = 0 To 3
  313. If (iLevel = g_nLoggingLevel) Then
  314. strSelected = "SELECTED"
  315. Else
  316. strSelected = ""
  317. End If
  318. %>
  319. <OPTION <%=strSelected%>
  320. VALUE="<%=iLevel%>"><%=Server.HTMLEncode(l_astrLogging(iLevel))%></OPTION>
  321. <%
  322. Next
  323. %>
  324. </SELECT>
  325. </TD>
  326. </TR>
  327. </TABLE>
  328. <BR>
  329. <TABLE>
  330. <TR>
  331. <TD CLASS="TasksBody" COLSPAN="2">
  332. <%=Server.HTMLEncode(l_strCaptionMailRoot)%>
  333. </TD>
  334. </TR>
  335. <TR>
  336. <TD CLASS="TasksBody">
  337. <INPUT TYPE="text"
  338. CLASS="FormField"
  339. NAME="<%=FLD_MAILROOT%>"
  340. VALUE="<%=Server.HTMLEncode(g_strMailRoot)%>"
  341. MAXLENGTH="1024"
  342. STYLE="width: 350px">
  343. </TD>
  344. </TR>
  345. <TR>
  346. <TD CLASS="TasksBody" colspan="2">
  347. <INPUT type="checkbox" CLASS="FormField" NAME="<%=FLD_REQUIRESPA%>" ID="<%=FLD_REQUIRESPA%>">
  348. <%=Server.HTMLEncode(l_strCaptionRequireSPA)%>
  349. </TD>
  350. </TR>
  351. </TABLE>
  352. <BR>
  353. <INPUT TYPE="HIDDEN" NAME="fldNumDomains" VALUE="<%=g_nDomains%>">
  354. <INPUT TYPE="HIDDEN" NAME="<%=FLD_SERVICERESTART%>" VALUE="<%=g_iServiceRestart%>">
  355. <%
  356. If (Err.number <> 0) Then
  357. Call SA_SetErrMsg( HandleUnexpectedError() )
  358. End If
  359. End Function
  360. '---------------------------------------------------------------------
  361. ' OnPostBackPage
  362. '---------------------------------------------------------------------
  363. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  364. On Error resume next
  365. OnPostBackPage = TRUE
  366. Dim oConfig
  367. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  368. '
  369. ' Get the authentication method, if it wasn't disabled. Otherwise,
  370. ' just get the current value from the Config object.
  371. '
  372. If (Request.Form(FLD_AUTHENTICATION).Count > 0) Then
  373. g_nAuthentication = CInt(Request.Form(FLD_AUTHENTICATION).Item(1))
  374. Else
  375. g_nAuthentication = oConfig.Authentication.CurrentAuthMethod
  376. End If
  377. '
  378. ' Get the rest of the form values.
  379. '
  380. If ( StrComp(Request.Form(FLD_REQUIRESPA), "on", vbTextCompare) = 0 ) Then
  381. g_bSPARequired = True
  382. Else
  383. g_bSPARequired = False
  384. End If
  385. g_nPort = CLng(Request.Form(FLD_PORT).Item(1))
  386. g_nLoggingLevel = CInt(Request.Form(FLD_LOGGING).Item(1))
  387. g_strMailRoot = CStr(Request.Form(FLD_MAILROOT).Item(1))
  388. g_iServiceRestart = CInt(Request.Form(FLD_SERVICERESTART).Item(1))
  389. g_nDomains = oConfig.Domains.Count
  390. If (Err.number <> 0) Then
  391. Call SA_SetErrMsg( HandleUnexpectedError() )
  392. End If
  393. End Function
  394. '---------------------------------------------------------------------
  395. ' OnSubmitPage
  396. '---------------------------------------------------------------------
  397. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  398. On Error Resume Next
  399. Dim oConfig, oAuthMethods
  400. Set oConfig = Server.CreateObject("P3Admin.P3Config")
  401. Set oAuthMethods = oConfig.Authentication
  402. ' set Authmethod.
  403. oAuthMethods.CurrentAuthMethod = CLng(g_nAuthentication)
  404. oAuthMethods.Save ()
  405. ' set main settings
  406. oConfig.LoggingLevel = g_nLoggingLevel
  407. oConfig.MailRoot = g_strMailRoot
  408. oConfig.Service.Port = CLng(g_nPort)
  409. If ( g_bSPARequired = True ) Then
  410. oConfig.Service.SPARequired = 1
  411. Else
  412. oConfig.Service.SPARequired = 0
  413. End If
  414. ' cycle the services
  415. If (Err.number = 0) Then
  416. If ( SERVICE_RESTART_POP3SVC = g_iServiceRestart Or SERVICE_RESTART_POP3SVC_SMTP = g_iServiceRestart ) Then
  417. If ( SERVICE_CONTROL_STOP <> oConfig.Service.POP3ServiceStatus ) Then
  418. oConfig.Service.StopPOP3Service()
  419. oConfig.Service.StartPOP3Service()
  420. End If
  421. End If
  422. End If
  423. If (Err.number = 0) Then
  424. If ( SERVICE_RESTART_POP3SVC_SMTP = g_iServiceRestart ) Then
  425. If ( SERVICE_CONTROL_STOP <> oConfig.Service.SMTPServiceStatus ) Then
  426. oConfig.Service.StopSMTPService()
  427. oConfig.Service.StartSMTPService()
  428. End If
  429. End If
  430. End If
  431. If (Err.number <> 0) Then
  432. Call SA_SetErrMsg( HandleUnexpectedError() )
  433. OnSubmitPage = FALSE
  434. Else
  435. OnSubmitPage = TRUE
  436. End If
  437. End Function
  438. '---------------------------------------------------------------------
  439. ' OnClosePage
  440. '---------------------------------------------------------------------
  441. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  442. OnClosePage = TRUE
  443. End Function
  444. %>