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.

1047 lines
29 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' sh_alertemail.asp: config the alertemail on server appliance
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. '-------------------------------------------------------------------------
  10. %>
  11. <!-- #include virtual="/admin/inc_framework.asp" -->
  12. <!-- METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
  13. NAME="CDO for Windows 2000 Type Library" -->
  14. <!-- METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4"
  15. NAME="ADODB Type Library" -->
  16. <%
  17. Err.Clear
  18. On Error Resume Next
  19. '
  20. ' First check if SMTP is installed/enabled on the server. If it's not
  21. ' redirect to the err page.
  22. '
  23. Dim L_ALERTEMAIL_SMTP_ERR_TEXT
  24. L_ALERTEMAIL_SMTP_ERR_TEXT = _
  25. GetLocString("alertemailmsg.dll", "&H4C00001B","")
  26. If Not SMTPIsReady Then
  27. Call SA_ServeFailurepage(L_ALERTEMAIL_SMTP_ERR_TEXT)
  28. End If
  29. Dim page
  30. Dim rc
  31. '
  32. ' Define the consts
  33. '
  34. CONST mintVT_I4_REG_DWORD = 3
  35. CONST mintVT_BSTR_REG_SZ = 8
  36. CONST ADS_SECURE_AUTHENTICATION = 1
  37. CONST CONST_CONTROL_CHECKED_STATUS = "CHECKED" ' to "Check" the control
  38. CONST CONST_CONTROL_NOT_CHECKED_STATUS = "" ' to "UnCheck" control
  39. CONST CONST_CONTROL_DISABLE_STATUS = "DISABLED" ' to "Disabled" the control
  40. CONST CONST_CONTROL_NOT_DISABLE_STATUS = "" ' to "UnDisabled" control
  41. CONST AE_CRITICAL_ALERT = 2
  42. CONST AE_WARNING_ALERT = 1
  43. CONST AE_INFORMATION_ALERT = 4
  44. CONST SMTP_RUNING_STATUS = 2
  45. CONST SMTP_STOP_STATUS = 4
  46. '-------------------------------------------------------------------------
  47. ' Form Variables
  48. '-------------------------------------------------------------------------
  49. Dim aeEnableAlertEmail
  50. Dim aeDisableCheck
  51. Dim aeEnableCheck
  52. Dim aeDisableAlertEmail
  53. Dim aeSendEmailType
  54. Dim aeSendCriticalCheck
  55. Dim aeSendWarningCheck
  56. Dim aeSendInforCheck
  57. Dim aeReceiverEmailAddress
  58. Dim aeSmartHost
  59. Dim aeSmartHostType
  60. Dim aeEnableDisplaySendInfo
  61. Dim aeEnableDisplaySendErr
  62. Dim mstrCHelperPROGID
  63. Dim mstrRegPathName
  64. Dim mstrEnableAlertEmailValue
  65. Dim mstrSendEmailTypeValue
  66. Dim mstrReceiverEmailAddressValue
  67. '-------------------------------------------------------------------------
  68. ' Start of localization content
  69. '-------------------------------------------------------------------------
  70. Dim L_TASKTITLE_TEXT
  71. Dim L_ALERTEMAIL_TASK_DESCRIPTION
  72. Dim L_ALERTEMAIL_DISABLE_SENDING
  73. Dim L_ALERTEMAIL_ENABLE_SENDING
  74. Dim L_ALERTEMAIL_SEND_CRITICAL
  75. Dim L_ALERTEMAIL_SEND_WARNING
  76. Dim L_ALERTEMAIL_SEND_INFORMATIONAL
  77. Dim L_ALERTEMAIL_TO
  78. Dim L_ALERTEMAIL_ERR_NO_TYPE
  79. Dim L_ALERTEMAIL_ERR_NO_EMAIL_ADDRESS
  80. Dim L_ALERTEMAIL_ERR_SMART_HOST
  81. Dim L_ALERTEMAIL_SMART_HOST
  82. Dim L_ALERTEMAIL_TO_LABLE
  83. Dim L_ALERTEMAIL_WITH_LABLE
  84. Dim L_ALERTEMAIL_TEST_INFORMATION
  85. Dim L_ALERTEMAIL_BUTTON_TEXT
  86. Dim L_ALERTEMAIL_SETTINGS_ERR_SETTASK
  87. 'init localization
  88. L_TASKTITLE_TEXT = _
  89. GetLocString("alertemailmsg.dll","&H4C000003","")
  90. L_ALERTEMAIL_TASK_DESCRIPTION = _
  91. GetLocString("alertemailmsg.dll","&H4C000004","")
  92. L_ALERTEMAIL_DISABLE_SENDING = _
  93. GetLocString("alertemailmsg.dll","&H4C000005","")
  94. L_ALERTEMAIL_ENABLE_SENDING = _
  95. GetLocString("alertemailmsg.dll", "&H4C000006","")
  96. L_ALERTEMAIL_SEND_CRITICAL = _
  97. GetLocString("alertemailmsg.dll", "&H4C000007","")
  98. L_ALERTEMAIL_SEND_WARNING = _
  99. GetLocString("alertemailmsg.dll", "&H4C000008","")
  100. L_ALERTEMAIL_SEND_INFORMATIONAL = _
  101. GetLocString("alertemailmsg.dll", "&H4C000009","")
  102. L_ALERTEMAIL_TO = _
  103. GetLocString("alertemailmsg.dll", "&H4C00000A","")
  104. L_ALERTEMAIL_ERR_NO_TYPE = _
  105. GetLocString("alertemailmsg.dll", "&H4C00000F","")
  106. L_ALERTEMAIL_ERR_NO_EMAIL_ADDRESS= _
  107. GetLocString("alertemailmsg.dll", "&H4C000010","")
  108. L_ALERTEMAIL_ERR_SMART_HOST = _
  109. GetLocString("alertemailmsg.dll", "&H4C000011","")
  110. L_ALERTEMAIL_SMART_HOST = _
  111. GetLocString("alertemailmsg.dll", "&H4C000012","")
  112. L_ALERTEMAIL_TO_LABLE = _
  113. GetLocString("alertemailmsg.dll", "&H4C000013","")
  114. L_ALERTEMAIL_WITH_LABLE = _
  115. GetLocString("alertemailmsg.dll", "&H4C000014","")
  116. L_ALERTEMAIL_TEST_INFORMATION = _
  117. GetLocString("alertemailmsg.dll", "&H4C000017","")
  118. L_ALERTEMAIL_BUTTON_TEXT = _
  119. GetLocString("alertemailmsg.dll", "&H4C000018","")
  120. L_ALERTEMAIL_SETTINGS_ERR_SETTASK = _
  121. GetLocString("alertemailmsg.dll", "&H4C00001A","")
  122. '-------------------------------------------------------------------------
  123. 'END of localization content
  124. '-------------------------------------------------------------------------
  125. '-------------------------------------------------------------------------
  126. ' Property Page of Alert Email
  127. '-------------------------------------------------------------------------
  128. rc = SA_CreatePage( L_TASKTITLE_TEXT, "", PT_PROPERTY, page )
  129. If ( rc = 0 ) Then
  130. SA_ShowPage( page )
  131. End If
  132. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  133. aeEnableDisplaySendInfo = False
  134. aeEnableDisplaySendErr = False
  135. mstrCHelperPROGID = "ServerAppliance.SAHelper.1"
  136. mstrRegPathName = "SOFTWARE\Microsoft\ServerAppliance\AlertEmail\"
  137. mstrEnableAlertEmailValue="EnableAlertEmail"
  138. mstrSendEmailTypeValue="SendEmailType"
  139. mstrReceiverEmailAddressValue="ReceiverEmailAddress"
  140. 'Get vars of alert email
  141. SetVarsFromSystem()
  142. GetSmartHost()
  143. ' create session object
  144. Session("aeOldSmartHost") = aeSmartHost
  145. Session("aeOldSmartHostType") = aeSmartHostType
  146. OnInitPage = TRUE
  147. End Function
  148. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  149. SetVarsFromForm()
  150. If mstrMethod = "TEST" Then
  151. If SMTPIsReady Then
  152. SetSmartHost(False)
  153. If TestMailSend Then
  154. aeEnableDisplaySendInfo = True
  155. Else
  156. ' now do nothing
  157. aeEnableDisplaySendErr = True
  158. End if
  159. Else
  160. aeEnableDisplaySendErr = True
  161. End if
  162. End If
  163. OnPostBackPage = TRUE
  164. End Function
  165. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  166. Call ServeCommonJavaScript()
  167. SetInternalVars()
  168. %>
  169. <input name="EnableAlertEmail" type="hidden">
  170. <input name="SendEmailType" type="hidden">
  171. <input name="ReceiverEmailAddress" type="hidden">
  172. <input name="SmartHost" type="hidden" value>
  173. <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 >
  174. <TR>
  175. <TD class=TasksBody>
  176. <INPUT type="RADIO" class=FormField name="radAlertEmail" value=1 <%=aeDisableCheck%>
  177. onClick="EnableSendAlertEmail(false)">
  178. </INPUT>
  179. </TD>
  180. <TD colspan=2 class=TasksBody>
  181. <%=L_ALERTEMAIL_DISABLE_SENDING%>
  182. </TD>
  183. </TR>
  184. <TR>
  185. <TD class=TasksBody>
  186. <INPUT type="RADIO" class=FormField name="radAlertEmail" value=2 <%=aeEnableCheck%>
  187. onClick="EnableSendAlertEmail(true)">
  188. </INPUT>
  189. </TD>
  190. <TD colspan=2 class=TasksBody>
  191. <%=L_ALERTEMAIL_ENABLE_SENDING%>
  192. </TD>
  193. </TR>
  194. <TR>
  195. <TD>
  196. &nbsp;
  197. </TD>
  198. <TD class=TasksBody>
  199. <INPUT type="CHECKBOX" class=FormField <%=aeDisableAlertEmail%> name="chkCritical"
  200. <%=aeSendCriticalCheck%>>
  201. </INPUT>
  202. </TD>
  203. <TD class=TasksBody>
  204. <%=L_ALERTEMAIL_SEND_CRITICAL%>
  205. </TD>
  206. </TR>
  207. <TR>
  208. <TD>
  209. &nbsp;
  210. </TD>
  211. <TD class=TasksBody>
  212. <INPUT type="CHECKBOX" class=FormField <%=aeDisableAlertEmail%> name="chkWarning"
  213. <%=aeSendWarningCheck%>>
  214. </INPUT>
  215. </TD>
  216. <TD class=TasksBody>
  217. <%=L_ALERTEMAIL_SEND_WARNING%>
  218. </TD>
  219. </TR>
  220. <TR>
  221. <TD>
  222. &nbsp;
  223. </TD>
  224. <TD class=TasksBody>
  225. <INPUT type="CHECKBOX" class=FormField <%=aeDisableAlertEmail%> name="chkInformational"
  226. <%=aeSendInforCheck%>>
  227. </INPUT>
  228. </TD>
  229. <TD class=TasksBody>
  230. <%=L_ALERTEMAIL_SEND_INFORMATIONAL%>
  231. </TD>
  232. </TR>
  233. <TR><td></td><td></td><td><table cellpadding=0 cellspacing=0><tr>
  234. <TD class=TasksBody>
  235. <%=L_ALERTEMAIL_TO%>
  236. </TD>
  237. <TD class=TasksBody>
  238. <INPUT type="TEXT" class=FormField name="txtTargetMailAdress" style="WIDTH:200px"
  239. <%=aeDisableAlertEmail%> value="<%=aeReceiverEmailAddress%>">
  240. </INPUT>
  241. </TD>
  242. <TD noWrap class=TasksBody>
  243. <%=L_ALERTEMAIL_TO_LABLE%>
  244. </TD>
  245. </TR>
  246. <TR>
  247. <TD class=TasksBody><%=L_ALERTEMAIL_SMART_HOST%></TD>
  248. <TD class=TasksBody>
  249. <INPUT type="TEXT" class=FormField name="txtSmartHost" style="WIDTH:200px"
  250. <%=aeDisableAlertEmail%> value="<%=aeSmartHost%>">
  251. </INPUT>
  252. </TD>
  253. <TD noWrap class=TasksBody>
  254. <%=L_ALERTEMAIL_WITH_LABLE%>
  255. </TD>
  256. </TR><TR><TD>&nbsp;</TD></TR>
  257. <TR>
  258. <TD colspan=4 class=TasksBody>
  259. <!-- <INPUT type="BUTTON" class=TaskFrameButtons name="btnTest" style="WIDTH:100px" <%=aeDisableAlertEmail%>
  260. value="<%=L_ALERTEMAIL_BUTTON_TEXT%>" onClick="ClickTest()">
  261. </INPUT> -->
  262. <% Call SA_ServeOnClickButtonEx(L_ALERTEMAIL_BUTTON_TEXT, "", "ClickTest()", 0, 0, aeDisableAlertEmail,"btnTest") %>
  263. </TD>
  264. </TR></table></td></tr>
  265. </TABLE>
  266. <%
  267. OnServePropertyPage = TRUE
  268. End Function
  269. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  270. If SetAlertEmail Then
  271. Session("aeOldSmartHost") =""
  272. OnSubmitPage = TRUE
  273. Else
  274. OnSubmitPage = FALSE
  275. End If
  276. End Function
  277. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  278. If mstrMethod = "CANCEL" Then
  279. SetSmartHost(True)
  280. End If
  281. 'close all session
  282. Session.Contents.Remove("aeOldSmartHost")
  283. Session.Contents.Remove("aeOldSmartHostType")
  284. OnClosePage = TRUE
  285. End Function
  286. Function ServeCommonJavaScript()
  287. %>
  288. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  289. </script>
  290. <script language="JavaScript">
  291. function Init()
  292. {
  293. <%If aeEnableDisplaySendErr Then%>
  294. DisplayErr("<%=Server.HTMLEncode(L_ALERTEMAIL_ERR_SMART_HOST)%>");
  295. <%Else
  296. If aeEnableDisplaySendInfo Then%>
  297. DisplayMsg("<%=Server.HTMLEncode(L_ALERTEMAIL_TEST_INFORMATION)%>");
  298. <%End If%>
  299. <%End If%>
  300. }
  301. function ValidatePage()
  302. {
  303. var bFindInvalidChar;
  304. var RadioSelected = null;
  305. var SendType = 0;
  306. var InvalidChar;
  307. for(var i =0; i < document.frmTask.radAlertEmail.length; i++)
  308. {
  309. if(document.frmTask.radAlertEmail[i].checked)
  310. {
  311. RadioSelected = document.frmTask.radAlertEmail[i].value;
  312. break;
  313. }
  314. }
  315. if(RadioSelected == 1)
  316. {
  317. return true;
  318. }
  319. // will check the selected items
  320. do
  321. {
  322. if(document.frmTask.chkCritical.checked)
  323. {
  324. SendType+=2;
  325. break;
  326. }
  327. else if(document.frmTask.chkWarning.checked)
  328. {
  329. SendType+=1;
  330. break;
  331. }
  332. else if(document.frmTask.chkInformational.checked)
  333. {
  334. SendType+=4;
  335. break;
  336. }
  337. }
  338. while(false);
  339. if(SendType == 0)
  340. {
  341. DisplayErr("<%=Server.HTMLEncode(L_ALERTEMAIL_ERR_NO_TYPE)%>");
  342. document.frmTask.chkCritical.focus();
  343. return false;
  344. }
  345. if(document.frmTask.txtTargetMailAdress.value == "")
  346. {
  347. DisplayErr("<%=Server.HTMLEncode(L_ALERTEMAIL_ERR_NO_EMAIL_ADDRESS)%>");
  348. document.frmTask.txtTargetMailAdress.focus();
  349. return false;
  350. }
  351. else
  352. {
  353. InvalidChar = /[^ ]/g;
  354. bFindInvalidChar = document.frmTask.txtTargetMailAdress.
  355. value.match(InvalidChar);
  356. if(!bFindInvalidChar)
  357. {
  358. DisplayErr("<%=Server.HTMLEncode(L_ALERTEMAIL_ERR_NO_EMAIL_ADDRESS)%>");
  359. document.frmTask.txtTargetMailAdress.value = "";
  360. document.frmTask.txtTargetMailAdress.focus();
  361. return false;
  362. }
  363. }
  364. return true;
  365. }
  366. function SetData()
  367. {
  368. var SearchedChar, pos;
  369. var RadioSelected = null;
  370. var SendType = 0;
  371. document.frmTask.SmartHost.value=
  372. document.frmTask.txtSmartHost.value;
  373. for(var i =0; i < document.frmTask.radAlertEmail.length; i++)
  374. {
  375. if(document.frmTask.radAlertEmail[i].checked)
  376. {
  377. RadioSelected = document.frmTask.radAlertEmail[i].value;
  378. break;
  379. }
  380. }
  381. if(RadioSelected == 1)
  382. {
  383. document.frmTask.EnableAlertEmail.value=0x00000000;
  384. }
  385. else
  386. {
  387. document.frmTask.EnableAlertEmail.value=0xFFFFFFFF;
  388. }
  389. // will check the selected items
  390. if(document.frmTask.chkCritical.checked)
  391. {
  392. SendType+=2;
  393. }
  394. if(document.frmTask.chkWarning.checked)
  395. {
  396. SendType+=1;
  397. }
  398. if(document.frmTask.chkInformational.checked)
  399. {
  400. SendType+=4;
  401. }
  402. document.frmTask.SendEmailType.value=SendType;
  403. SearchedChar = /[^ ]/g;
  404. pos=document.frmTask.txtTargetMailAdress.value.
  405. search(SearchedChar);
  406. document.frmTask.ReceiverEmailAddress.value=
  407. document.frmTask.txtTargetMailAdress.value.substr(pos);
  408. }
  409. //update hiden form and submit data to ASP server
  410. function ClickTest()
  411. {
  412. if(ValidatePage())
  413. {
  414. SetData();
  415. document.frmTask.Method.value = "TEST";
  416. document.frmTask.submit();
  417. }
  418. }
  419. //-----------------------------------------------------------------
  420. //SubRoutine name: EnableSendAlertEmail
  421. //Description: tab between enable and disable send alert email
  422. //Input Variables: BOOLEAN
  423. //Output Variables: None
  424. //Returns: None
  425. //Global Variables: None
  426. //-----------------------------------------------------------------
  427. function EnableSendAlertEmail(bSend)
  428. {
  429. var SendType = 0;
  430. if(bSend)
  431. {
  432. document.frmTask.chkCritical.disabled = false;
  433. document.frmTask.chkWarning.disabled = false;
  434. document.frmTask.chkInformational.disabled = false;
  435. document.frmTask.txtTargetMailAdress.disabled = false;
  436. document.frmTask.txtSmartHost.disabled = false;
  437. document.frmTask.btnTest.disabled = false;
  438. // If no select in checkbox, set critical as default
  439. do
  440. {
  441. if(document.frmTask.chkCritical.checked)
  442. {
  443. SendType+=2;
  444. break;
  445. }
  446. else if(document.frmTask.chkWarning.checked)
  447. {
  448. SendType+=1;
  449. break;
  450. }
  451. else if(document.frmTask.chkInformational.checked)
  452. {
  453. SendType+=4;
  454. break;
  455. }
  456. }
  457. while(false);
  458. if(SendType==0)
  459. document.frmTask.chkCritical.checked = true;
  460. }
  461. else
  462. {
  463. document.frmTask.chkCritical.disabled = true;
  464. document.frmTask.chkWarning.disabled = true;
  465. document.frmTask.chkInformational.disabled = true;
  466. document.frmTask.txtTargetMailAdress.disabled = true;
  467. document.frmTask.txtSmartHost.disabled = true;
  468. document.frmTask.btnTest.disabled = true;
  469. }
  470. }
  471. //--------------------------------------------------------------------
  472. //
  473. // Function : DisplayMsg
  474. //
  475. // Synopsis : Display msg
  476. //
  477. // Arguments: Msg(IN) - msg to display
  478. //
  479. // Returns : None
  480. //
  481. //--------------------------------------------------------------------
  482. function DisplayMsg(Msg)
  483. {
  484. var strMsg = '<table style="font-family:tahoma,arial,verdana,'+
  485. 'sans-serif;font-size:9pt;font-weight: normal;">'+
  486. '<tr><td><img src="' + VirtualRoot +
  487. 'images/information.gif" border=0></td><td>' + Msg +
  488. '</td></tr></table>'
  489. if (IsIE())
  490. {
  491. document.all("divErrMsg").innerHTML = strMsg;
  492. }
  493. else
  494. {
  495. alert(Msg);
  496. }
  497. }
  498. </script>
  499. <%
  500. End Function
  501. '-------------------------------------------------------------------------
  502. '
  503. ' Function : SetAlertEmail
  504. '
  505. ' Synopsis : function to set server alert email
  506. '
  507. ' Arguments: None
  508. '
  509. ' Returns : None
  510. '
  511. '-------------------------------------------------------------------------
  512. Function SetAlertEmail()
  513. Dim objTCtx
  514. Dim Error
  515. on error resume next
  516. Error = ExecuteTask("SetAlertEmail", objTCtx)
  517. if Error <> 0 then
  518. SetErrMsg L_ALERTEMAIL_SETTINGS_ERR_SETTASK
  519. SetAlertEmail = False
  520. Else
  521. SetSmartHost(False)
  522. SetAlertEmail = True
  523. End if
  524. set objTCtx = Nothing
  525. End Function
  526. '-------------------------------------------------------------------------
  527. ' Subprocedure name:SetVarsFromSystem
  528. ' Description: Serves in getting the values from system
  529. ' Input Variables: None
  530. ' Output Variables: None
  531. ' Returns: None
  532. ' Global Variables: Out: aeEnableAlertEmail - alert email
  533. ' Out: aeSendEmailType - send email type
  534. ' Out: aeReceiverEmailAddress - receiver email address
  535. '-------------------------------------------------------------------------
  536. Sub SetVarsFromSystem
  537. Dim objHelper
  538. Err.Clear
  539. '---------------------------------------------------------------------
  540. 'Get old parameter from registry
  541. '---------------------------------------------------------------------
  542. Set objHelper = Server.CreateObject(mstrCHelperPROGID)
  543. If Err.Number <> 0 Then
  544. aeEnableAlertEmail = 0
  545. aeSendEmailType = 0
  546. aeReceiverEmailAddress = ""
  547. Else
  548. Call objHelper.GetRegistryValue(mstrRegPathName, _
  549. mstrEnableAlertEmailValue, _
  550. aeEnableAlertEmail, _
  551. mintVT_I4_REG_DWORD)
  552. Call objHelper.GetRegistryValue(mstrRegPathName, _
  553. mstrSendEmailTypeValue,_
  554. aeSendEmailType, _
  555. mintVT_I4_REG_DWORD)
  556. Call objHelper.GetRegistryValue(mstrRegPathName, _
  557. mstrReceiverEmailAddressValue,_
  558. aeReceiverEmailAddress, _
  559. mintVT_BSTR_REG_SZ)
  560. End if
  561. Set objHelper = Nothing
  562. End Sub
  563. '-------------------------------------------------------------------------
  564. ' Subprocedure name:SetVarsFromForm
  565. ' Description: Serves in getting the values from client
  566. ' Input Variables: None
  567. ' Output Variables: None
  568. ' Returns: None
  569. ' Global Variables: Out: aeEnableAlertEmail - alert email
  570. ' Out: aeSendEmailType - send email type
  571. ' Out: aeReceiverEmailAddress - receiver email address
  572. ' Out: aeSmartHost - Smart host of SMTP server
  573. '-------------------------------------------------------------------------
  574. Sub SetVarsFromForm
  575. aeEnableAlertEmail = Request.Form("EnableAlertEmail")
  576. aeSendEmailType = Request.Form("SendEmailType")
  577. aeReceiverEmailAddress = Request.Form("ReceiverEmailAddress")
  578. aeSmartHost = Trim(Request.Form("SmartHost"))
  579. End Sub
  580. '-------------------------------------------------------------------------
  581. ' Subprocedure name:SetInternalVars
  582. ' Description: Serves internal variables
  583. ' Input Variables: None
  584. ' Output Variables: None
  585. ' Returns: None
  586. ' Global Variables: Out: aeEnableAlertEmail - alert email
  587. ' Out: aeSendEmailType - send email type
  588. ' Out: aeReceiverEmailAddress - receiver email address
  589. ' Out: aeSmartHost - Smart host of SMTP server
  590. '-------------------------------------------------------------------------
  591. Sub SetInternalVars
  592. aeSendCriticalCheck = CONST_CONTROL_NOT_CHECKED_STATUS
  593. aeSendWarningCheck = CONST_CONTROL_NOT_CHECKED_STATUS
  594. aeSendInforCheck = CONST_CONTROL_NOT_CHECKED_STATUS
  595. If aeEnableAlertEmail Then
  596. aeDisableCheck = CONST_CONTROL_NOT_CHECKED_STATUS
  597. aeEnableCheck = CONST_CONTROL_CHECKED_STATUS
  598. aeDisableAlertEmail = CONST_CONTROL_NOT_DISABLE_STATUS
  599. Else
  600. aeDisableCheck = CONST_CONTROL_CHECKED_STATUS
  601. aeEnableCheck = CONST_CONTROL_NOT_CHECKED_STATUS
  602. aeDisableAlertEmail = CONST_CONTROL_DISABLE_STATUS
  603. End if
  604. If aeSendEmailType and AE_CRITICAL_ALERT Then
  605. aeSendCriticalCheck = CONST_CONTROL_CHECKED_STATUS
  606. End if
  607. If aeSendEmailType and AE_WARNING_ALERT Then
  608. aeSendWarningCheck = CONST_CONTROL_CHECKED_STATUS
  609. End if
  610. If aeSendEmailType and AE_INFORMATION_ALERT Then
  611. aeSendInforCheck = CONST_CONTROL_CHECKED_STATUS
  612. End if
  613. End Sub
  614. '-------------------------------------------------------------------------
  615. '
  616. ' Function : SetSmartHost
  617. '
  618. ' Synopsis : function to set smart host
  619. '
  620. ' Arguments:
  621. ' Boolean(IN): True - restore old vale
  622. ' False - save with new value
  623. '
  624. ' Returns : None
  625. '
  626. '-------------------------------------------------------------------------
  627. Function SetSmartHost(bOld)
  628. Dim dso
  629. Dim objAds,tempSmartHost
  630. Call SA_TraceOut("SH_ALERTEMAIL", "Entering SetSmartHost")
  631. Err.Clear
  632. on error resume next
  633. Set dso = GetObject("IIS:")
  634. If Err.Number <> 0 Then
  635. Call SA_TraceOut("SH_ALERTEMAIL", _
  636. "GetObject(IIS:) encountered error: "& _
  637. CStr(Hex(Err.Number))& " "&Err.Description)
  638. SetSmartHost = False
  639. Exit Function
  640. Else
  641. Set objAds = dso.OpenDSObject(_
  642. "IIS://localhost/SmtpSvc/1",_
  643. "",_
  644. "",_
  645. ADS_SECURE_AUTHENTICATION)
  646. If Err.Number <> 0 Then
  647. Call SA_TraceOut("SH_ALERTEMAIL", _
  648. "dso.OpenDSObject encountered error: "& _
  649. CStr(Hex(Err.Number))&" "& Err.Description)
  650. SetSmartHost = False
  651. Exit Function
  652. Else
  653. if bOld Then
  654. objAds.Put "SmartHost", Session("aeOldSmartHost")
  655. objAds.Put "SmartHostType", Session("aeOldSmartHostType")
  656. Else
  657. tempSmartHost = Request.form("SmartHost")
  658. ' Add breckets to the ip address
  659. If IsIPAddress(tempSmartHost) Then
  660. tempSmartHost = "["&tempSmartHost&"]"
  661. End if
  662. objAds.Put "SmartHost", tempSmartHost
  663. '
  664. ' According to the old start host config, determine the
  665. ' value of smarthosttype
  666. '
  667. If tempSmartHost = "" Then
  668. objAds.Put "SmartHostType", 0
  669. Else
  670. If Session("aeOldSmartHostType") = 1 Then
  671. objAds.Put "SmartHostType", 1
  672. Else
  673. objAds.Put "SmartHostType", 2
  674. End if
  675. End if
  676. End if
  677. objAds.SetInfo
  678. SetSmartHost = True
  679. End if
  680. End if
  681. If Err.Number <> 0 Then
  682. Call SA_TraceOut("SH_ALERTEMAIL", _
  683. "SetSmartHost encountered error: "& _
  684. CStr(Hex(Err.Number))&" "&Err.Description)
  685. End If
  686. Set dso = Nothing
  687. Set objAds = Nothing
  688. End Function
  689. '-------------------------------------------------------------------------
  690. '
  691. ' Function : GetSmartHost
  692. '
  693. ' Synopsis : function to get smart host
  694. '
  695. ' Arguments: None
  696. '
  697. ' Returns : None
  698. '
  699. '-------------------------------------------------------------------------
  700. Function GetSmartHost()
  701. Dim dso
  702. Dim objAds
  703. Err.Clear
  704. on error resume next
  705. Set dso = GetObject("IIS:")
  706. If Err.Number <> 0 Then
  707. GetSmartHost = False
  708. Else
  709. Set objAds = dso.OpenDSObject(_
  710. "IIS://localhost/SmtpSvc/1",_
  711. "",_
  712. "",_
  713. ADS_SECURE_AUTHENTICATION)
  714. If Err.Number <> 0 Then
  715. GetSmartHost = False
  716. Else
  717. aeSmartHost = objAds.Get("SmartHost")
  718. 'If is IP address, throw off breackets
  719. If IsBracketsIPAddress(aeSmartHost) Then
  720. aeSmartHost=Mid(aeSmartHost,2,Len(aeSmartHost)-2)
  721. End if
  722. 'Get the type of the smart host
  723. aeSmartHostType = objAds.Get("SmartHostType")
  724. GetSmartHost = True
  725. End if
  726. End if
  727. Set dso = Nothing
  728. Set objAds = Nothing
  729. End Function
  730. '-------------------------------------------------------------------------
  731. '
  732. ' Function : SMTPIsReady
  733. '
  734. ' Synopsis : function to determine the state of SMTP server
  735. '
  736. ' Arguments: None
  737. '
  738. ' Returns : BOOL
  739. '
  740. '-------------------------------------------------------------------------
  741. Function SMTPIsReady()
  742. Dim dso
  743. Dim objAds
  744. Dim smtpState
  745. Err.Clear
  746. on error resume next
  747. SMTPIsReady = True
  748. Set dso = GetObject("IIS:")
  749. If Err.Number <> 0 Then
  750. SMTPIsReady = False
  751. Exit Function
  752. Else
  753. Set objAds = dso.OpenDSObject(_
  754. "IIS://localhost/SmtpSvc/1",_
  755. "",_
  756. "",_
  757. ADS_SECURE_AUTHENTICATION)
  758. If Err.Number <> 0 Then
  759. 'Not exist the service of SMTP
  760. SMTPIsReady = False
  761. Exit Function
  762. Else
  763. smtpState = objAds.Get("ServerState")
  764. 'If the smtp is stop display errinfo
  765. If smtpState = SMTP_STOP_STATUS Then
  766. SMTPIsReady = False
  767. Exit Function
  768. End if
  769. End if
  770. End if
  771. Set dso = Nothing
  772. Set objAds = Nothing
  773. End Function
  774. '-------------------------------------------------------------------------
  775. '
  776. ' Function : TestMailSend
  777. '
  778. ' Synopsis : Test the email settings
  779. '
  780. ' Arguments: None
  781. '
  782. ' Returns : None
  783. '
  784. '-------------------------------------------------------------------------
  785. Function TestMailSend()
  786. Dim iMsg
  787. Dim iConf
  788. Dim comHelper
  789. Dim iComputer
  790. Dim iNow
  791. Dim msgBody
  792. Dim strFrom
  793. Err.Clear
  794. on error resume next
  795. Call SA_TraceOut("SH_ALERTEMAIL", "Entering TestMailSend")
  796. Set iMsg = CreateObject("CDO.Message")
  797. If Err.Number <> 0 Then
  798. Call SA_TraceOut("SH_ALERTEMAIL", _
  799. "CreateObject(CDO.Message) encountered error: "& _
  800. CStr(Hex(Err.Number))&" "&Err.Description)
  801. TestMailSend = False
  802. Exit Function
  803. Else
  804. Set iConf = CreateObject("CDO.Configuration")
  805. If Err.Number <> 0 Then
  806. TestMailSend = False
  807. Call SA_TraceOut("SH_ALERTEMAIL", _
  808. "CreateObject(CDO.Configuration) encountered error: "& _
  809. CStr(Hex(Err.Number))&" "&Err.Description)
  810. Exit Function
  811. Else
  812. iConf.Load cdoIIS
  813. Set comHelper = Server.CreateObject("comhelper.SystemSetting")
  814. If Err.Number <> 0 Then
  815. TestMailSend = False
  816. Call SA_TraceOut("SH_ALERTEMAIL", _
  817. "Server.CreateObject(comhelper.SystemSetting) error: "& _
  818. CStr(Hex(Err.Number))&" "&Err.Description)
  819. Exit Function
  820. Else
  821. Set iComputer = comHelper.Computer
  822. If Err.Number <> 0 Then
  823. TestMailSend = False
  824. Call SA_TraceOut("SH_ALERTEMAIL", _
  825. "comHelper.Computer encountered error: "& _
  826. CStr(Hex(Err.Number))&" "&Err.Description)
  827. Exit Function
  828. Else
  829. iNow = Now
  830. msgBody = SA_GetLocString("alertemailmsg.dll", _
  831. "&H4C000016",_
  832. Array(UCase(iComputer.FullQualifiedComputerName)))
  833. strFrom = GetFromAddressForAlertEmail(iComputer)
  834. With iMsg
  835. Set.Configuration = iConf
  836. .To = aeReceiverEmailAddress
  837. .From = strFrom
  838. .Subject = SA_GetLocString("alertemailmsg.dll", _
  839. "&H4C000015", _
  840. Array(CStr(iNow)))
  841. .BodyPart.Charset = SA_GetCharSet()
  842. .TextBody = msgBody
  843. .Send
  844. End With
  845. If Err.Number <> 0 Then
  846. TestMailSend = False
  847. Call SA_TraceOut("SH_ALERTEMAIL", _
  848. "Set.Configuration encountered error: "& _
  849. CStr(Hex(Err.Number))&" "&Err.Description)
  850. Else
  851. TestMailSend = True
  852. End if
  853. End if
  854. End if
  855. End if
  856. End If
  857. Set comHelper = Nothing
  858. Set iComputer = Nothing
  859. Set iMsg = Nothing
  860. Set iConf = Nothing
  861. End Function
  862. '-------------------------------------------------------------------------
  863. '
  864. ' Function : IsIPAddress
  865. '
  866. ' Synopsis : Is a dot IP address?
  867. '
  868. ' Arguments: ipstring - the string is analysed
  869. '
  870. ' Returns : BOOL
  871. '
  872. '-------------------------------------------------------------------------
  873. Function IsIPAddress(ipstring)
  874. Dim FiledUperBound
  875. Dim FieldArray,LoopIndex
  876. LoopIndex = 0
  877. IsIPAddress = True
  878. FieldArray = Split(ipstring, ".")
  879. FiledUperBound = UBound(FieldArray)
  880. if FiledUperBound = 3 Then
  881. Do while LoopIndex < 4
  882. If not IsNumeric(FieldArray(LoopIndex)) Then
  883. IsIPAddress = False
  884. Exit Do
  885. End if
  886. LoopIndex = LoopIndex + 1
  887. Loop
  888. Else
  889. IsIPAddress = False
  890. End if
  891. End Function
  892. '-------------------------------------------------------------------------
  893. '
  894. ' Function : IsBracketsIPAddress
  895. '
  896. ' Synopsis : Is a dot IP address in brackets?
  897. '
  898. ' Arguments: ipstring - the string is analysed
  899. '
  900. ' Returns : BOOL
  901. '
  902. '-------------------------------------------------------------------------
  903. Function IsBracketsIPAddress(ipstring)
  904. IsBracketsIPAddress = False
  905. If Left(ipstring,1) = "[" and Right(ipstring, 1) = "]" Then
  906. If IsIPAddress(Mid(ipstring,2,Len(ipstring)-2)) Then
  907. IsBracketsIPAddress = True
  908. End if
  909. End if
  910. End Function
  911. '-------------------------------------------------------------------------
  912. '
  913. ' Function : GetFromAddressForAlertEmail()
  914. '
  915. ' Synopsis : Get From Address
  916. '
  917. ' Arguments: NULL
  918. '
  919. ' Returns : INT
  920. '
  921. '-------------------------------------------------------------------------
  922. Function GetFromAddressForAlertEmail( objComputer )
  923. Err.Clear
  924. On Error Resume Next
  925. Dim strFullyQualifiedComputerName
  926. strFullyQualifiedComputerName = objComputer.FullQualifiedComputerName
  927. SA_Traceout "strFullyQualifiedComputerName:", strFullyQualifiedComputerName
  928. GetFromAddressForAlertEmail = GetComputerName()
  929. Dim objADSI
  930. Dim strDomainName
  931. ' The algorithm is
  932. ' Look at the value of "Full Qualified Domain Name" entry in SMTP Delivery tab in MMC.
  933. ' 1) If the value is empty then the e-mail From Address is appliance_name
  934. ' 2) If it is NOT empty use the From Address as appliance_name@"Full Qualified Domain Name"
  935. Set objADSI = GetObject( "IIS://LOCALHOST/SMTPSVC/1")
  936. If Err.Number <> 0 Then
  937. SA_TraceOut "sh_alertemail.asp", " failed to call GetObject"
  938. Exit Function
  939. End If
  940. ' Getting the FullyQualifiedDomainName property
  941. strDomainName = objADSI.Get("FullyQualifiedDomainName")
  942. If Err.Number <> 0 Then
  943. SA_TraceOut "sh_alertemail.asp", " failed to call Get property on FullyQualifiedDomainName"
  944. Exit Function
  945. End If
  946. If lcase( strDomainName) <> lcase(strFullyQualifiedComputerName) Then
  947. GetFromAddressForAlertEmail = GetComputerName() + "@" + strDomainName
  948. End If
  949. End Function
  950. %>