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.

460 lines
16 KiB

  1. <%
  2. '-------------------------------------------------------------------------
  3. ' nfssimplemaps_prop.asp: display and update Simple Map properties
  4. '
  5. ' Copyright (c) Microsoft Corporation. All rights reserved.
  6. '
  7. ' Date Description
  8. ' 25 Sep 2000 Creation Date.
  9. '-------------------------------------------------------------------------
  10. Err.Clear
  11. On Error Resume Next
  12. '-------------------------------------------------------------------------
  13. 'Form Variables
  14. '-------------------------------------------------------------------------
  15. Dim F_strSMapCheckBox_Status ' stores "CHECKED" or "" - CheckBox state
  16. Dim F_intSMapCheckBox_EnableSMap ' to Check or UnCheck CheckBox
  17. Dim F_strSMap_WindowsDomain ' to store the Windows Domain(from Combo)
  18. ' initialize
  19. F_strSMapCheckBox_Status = CONST_CHECKBOX_NOT_CHECKED_STATUS
  20. F_intSMapCheckBox_EnableSMap = CONST_CHECKBOX_IS_NOT_CHECKED
  21. F_strSMap_WindowsDomain = ""
  22. '-------------------------------------------------------------------------
  23. 'Constants
  24. '-------------------------------------------------------------------------
  25. Const CONST_CHECKBOX_CHECKED_STATUS = "CHECKED" ' to "Check" the CheckBox
  26. Const CONST_CHECKBOX_NOT_CHECKED_STATUS = "" ' to "UnCheck" CheckBox
  27. Const CONST_LISTITEM_NOT_SELECTED_STATUS = "" ' to NOT-Select the ListItem
  28. Const CONST_LISTITEM_SELECTED_STATUS = "SELECTED" ' to Select the ListItem
  29. Const CONST_CHECKBOX_IS_CHECKED = 1 ' to maintain state of CheckBox-Checked
  30. Const CONST_CHECKBOX_IS_NOT_CHECKED = 0 ' to maintain state of CheckBox-UnChecked
  31. Const ENUM_NTDOMAINS = 0 ' to pass as input to activex object
  32. Const ENUM_NTGROUPS = 2 ' to pass as input to activex object
  33. Const SFU_ADMIN_MAPPER_WRAPPER = "MapManager.1" ' activex object
  34. Const WMI_SFU_OBJECT_QUERY = "Mapper_Settings.KeyName='CurrentVersion'" ' wmi query
  35. ' the "User Name Mapping" service (MapSvc) must be installed for the
  36. ' maps to be enabled. If the service is not installed, display the
  37. ' SA_ServeFailurePage with the message
  38. If NOT isMapServiceInstalled(GetWMIConnection("root\CIMV2")) Then
  39. SA_ServeFailurePage L_USERMAPPING_SERVICE_NOT_INSTALLED_ERRORMESSAGE
  40. End If
  41. %>
  42. <SCRIPT LANGUAGE="JavaScript">
  43. // Set the initial form values
  44. function SMAPInit()
  45. {
  46. // enable or disable the windows-domain ComboBox
  47. EnableOrDisableWinDomain(document.frmTask.chkEnableSMap);
  48. }// end of function SMAPInit()
  49. // validate the page form values
  50. // returns true, form submits - if all values are valid.
  51. // returns false, form not submitted, shows error message if error.
  52. function SMAPValidatePage()
  53. {
  54. // no validation is required here
  55. // update all the hidden variables
  56. // ("OK" is clicked or another tab is clicked)
  57. UpdateSMapHiddenVariables();
  58. return true;
  59. } // end of SMAPValidatePage()
  60. // dummy function to support framework
  61. function SMAPSetData()
  62. {
  63. // all the hidden variables are set in the
  64. // SMAPValidatePage() function. No data to set here.
  65. } // end of SMAPSetData()
  66. // function to set the hidden varibales to be sent to the server
  67. function UpdateSMapHiddenVariables()
  68. {
  69. var objSMapForm = eval("document.frmTask");
  70. // store the state of the checkBox in the hidden variable
  71. // 1 = Checked
  72. // 0 = NOT Checked
  73. if(objSMapForm.chkEnableSMap.checked)
  74. {
  75. objSMapForm.hdnintSMap_EnableSMap.value = "1";
  76. }
  77. else
  78. {
  79. objSMapForm.hdnintSMap_EnableSMap.value = "0";
  80. }
  81. // store the windows domain value in the hidden variable
  82. objSMapForm.hdnstrSMap_WindowsDomain.value = objSMapForm.lstWindowsDomain.value;
  83. }
  84. // function to enable or disable the (Windows doamin) ComboBox.
  85. // enable if CheckBox is CHECKED, else disable
  86. function EnableOrDisableWinDomain(objCheckBox)
  87. {
  88. if(objCheckBox.checked)
  89. {
  90. document.frmTask.lstWindowsDomain.disabled = false;
  91. }
  92. else
  93. {
  94. document.frmTask.lstWindowsDomain.disabled = true;
  95. }
  96. }
  97. </SCRIPT>
  98. <%
  99. '-------------------------------------------------------------------------
  100. ' Function name: ServeSMAPPage(ByRef PageIn, ByVal bIsVisible)
  101. ' Description: Serves in displaying the page Header, Middle and
  102. ' Footer Parts (the User Interface)
  103. ' Input Variables: PageIn
  104. ' bIsVisible - the tab page be displayed?
  105. ' Output Variables: None
  106. ' Returns: None
  107. ' Global Variables: L_(*) - Localization content
  108. ' F_(*) - Form Variables
  109. '-------------------------------------------------------------------------
  110. Function ServeSMAPPage(ByRef PageIn, ByVal bIsVisible)
  111. Err.Clear
  112. On Error Resume Next
  113. If bIsVisible Then
  114. %>
  115. <TABLE VALIGN="middle" ALIGN="left" BORDER=0 CELLSPACING=1 CELLPADDING=2 CLASS="TasksBody" width=500>
  116. <TR>
  117. <TD CLASS="TasksBody" align="right">
  118. <INPUT NAME="chkEnableSMap" Class="FormField" TYPE="CHECKBOX" <%=F_strSMapCheckBox_Status%> OnClick="EnableOrDisableWinDomain(this)">
  119. </TD>
  120. <TD CLASS="TasksBody" align="left" nowrap>
  121. <%=L_ENABLE_SIMPLEMAPS_LABEL_TEXT%>
  122. </TD>
  123. </TR>
  124. <TR>
  125. <TD CLASS="TasksBody">
  126. &nbsp;
  127. <!-- space left for the gap created by the checkBox above -->
  128. </TD>
  129. <TD CLASS="TasksBody" align="left" colspan=2>
  130. <%=L_SIMPLEMAPS_NOTE_TEXT%>
  131. </TD>
  132. </TR>
  133. <TR>
  134. <TD CLASS="TasksBody">
  135. &nbsp;
  136. <!-- space left for the gap created by the checkBox above -->
  137. </TD>
  138. <TD CLASS="TasksBody" align="left">
  139. <%=L_WINDOWS_DOMAIN_LABEL_TEXT%>
  140. &nbsp;&nbsp;
  141. </TD>
  142. <TD CLASS="TasksBody">
  143. <SELECT ROWS=1 Name="lstWindowsDomain" class="FormField" style="width:200">
  144. <% Call getWinDomainsAsComboValues(F_strSMap_WindowsDomain) %>
  145. </SELECT>
  146. </TD>
  147. </TR>
  148. </TABLE>
  149. <%
  150. End If
  151. ServeSMAPFooter()
  152. ServeSMAPPage = gc_ERR_SUCCESS
  153. End Function
  154. '-------------------------------------------------------------------------
  155. ' SubRoutine name: GetSMAPVariablesFromForm
  156. ' Description: Serves in getting the values from previous form
  157. ' Input Variables: None
  158. ' Output Variables: None
  159. ' Return Values: None
  160. ' Global Variables: F_(*) - Form variables
  161. '-------------------------------------------------------------------------
  162. Sub GetSMAPVariablesFromForm
  163. Err.Clear
  164. On Error Resume Next
  165. F_intSMapCheckBox_EnableSMap = Request.Form("hdnintSMap_EnableSMap")
  166. F_strSMap_WindowsDomain = Request.Form("hdnstrSMap_WindowsDomain")
  167. ' if the checkBox was previously CHECKED, "Check" the CheckBox
  168. If CInt(F_intSMapCheckBox_EnableSMap) = CONST_CHECKBOX_IS_CHECKED Then
  169. F_strSMapCheckBox_Status = CONST_CHECKBOX_CHECKED_STATUS
  170. Else
  171. F_strSMapCheckBox_Status = CONST_CHECKBOX_NOT_CHECKED_STATUS
  172. End If
  173. End sub
  174. '-------------------------------------------------------------------------
  175. ' SubRoutine name: GetSMAPVariablesFromSystem
  176. ' Description: Serves in getting the values from system
  177. ' Input Variables: None
  178. ' Output Variables: None
  179. ' Return Values: None
  180. ' Global Variables: F_(*) - Form variables
  181. '-------------------------------------------------------------------------
  182. Sub GetSMAPVariablesFromSystem
  183. Err.Clear
  184. On Error Resume Next
  185. Dim objWMIService ' the service object
  186. Dim objInstance ' the instance object
  187. ' get the wmi connection (service object) for the SFUAdmin namespace
  188. Set objWMIService = GetWMIConnection(WMI_SFUADMIN_NAMESPACE)
  189. ' get the object from the wmi
  190. Set objInstance = objWMIService.Get(WMI_SFU_OBJECT_QUERY)
  191. If Err.number <> 0 Then
  192. SA_ServeFailurePage L_READFROM_WMI_FAILED_ERRORMESSAGE
  193. End If
  194. ' assign the values to the form variables
  195. F_strSMap_WindowsDomain = objInstance.NTDomain
  196. ' if simple maps is enables, check the checkBox, else don't
  197. ' objInstance.AuthType = 0 or 1, Enable SimpleMaps else Disable
  198. If (objInstance.AuthType = 0 OR objInstance.AuthType = 1) Then
  199. F_intSMapCheckBox_EnableSMap = CONST_CHECKBOX_IS_CHECKED
  200. F_strSMapCheckBox_Status = CONST_CHECKBOX_CHECKED_STATUS
  201. Else
  202. F_intSMapCheckBox_EnableSMap = CONST_CHECKBOX_IS_NOT_CHECKED
  203. F_strSMapCheckBox_Status = CONST_CHECKBOX_NOT_CHECKED_STATUS
  204. End if
  205. ' clean up
  206. Set objInstance = Nothing
  207. Set objWMIService = Nothing
  208. End Sub
  209. '-------------------------------------------------------------------------
  210. ' Function name: SetSMAPProp
  211. ' Description: To set the simple map properties
  212. ' Input Variables: None
  213. ' Output Variables: None
  214. ' Returns: True on success, False on error (and error msg
  215. ' will be set by SetErrMsg)
  216. ' Global Variables: F_(*) - form values
  217. '-------------------------------------------------------------------------
  218. Function SetSMAPProp()
  219. Err.Clear
  220. On Error resume next
  221. Dim objWMIService ' the service object
  222. Dim objInstance ' the instance object
  223. ' get the wmi connection (service object) for the SFUAdmin namespace
  224. Set objWMIService = GetWMIConnection(WMI_SFUADMIN_NAMESPACE)
  225. ' get the object from the wmi
  226. Set objInstance = objWMIService.Get(WMI_SFU_OBJECT_QUERY)
  227. If Err.number <> 0 Then
  228. SetErrMsg L_READFROM_WMI_FAILED_ERRORMESSAGE & " (" & Hex(Err.number) & ")"
  229. SetSMAPProp = False
  230. Exit Function
  231. End If
  232. ' assign the form values to the Object
  233. objInstance.NTDomain = F_strSMap_WindowsDomain
  234. ' if Simple maps enabled, AuthType = 0, Else 2
  235. If CInt(F_intSMapCheckBox_EnableSMap) = CONST_CHECKBOX_IS_CHECKED Then
  236. ' here have a serious error, fixed by lustar, 3/1/2001
  237. If objInstance.ServerType = 0 Then
  238. objInstance.AuthType = 0
  239. Else
  240. objInstance.AuthType = 1
  241. End If
  242. Else
  243. objInstance.AuthType = 2
  244. End if
  245. ' Save the changes on the object
  246. objInstance.Put_
  247. If Err.number Then
  248. SetErrMsg L_WRITETO_WMI_FAILED_ERRORMESSAGE & " (" & Hex(Err.number) & ")"
  249. SetSMAPProp = False
  250. Else
  251. SetSMAPProp = True
  252. End If
  253. ' clean up
  254. Set objInstance = Nothing
  255. Set objWMIService = Nothing
  256. End Function
  257. '-------------------------------------------------------------------------
  258. 'Function name: getConnectedDomain
  259. 'Description: gets the domain in which the machine is present.
  260. 'Input Variables: Connection to the WMI
  261. 'Output Variables: None
  262. 'Returns: Domain Name
  263. '-------------------------------------------------------------------------
  264. Function getConnectedDomain(objService)
  265. Err.Clear
  266. On Error resume next
  267. Dim objColletionofSystem ' to get the collection from wmi
  268. Dim objSystem ' used in the loop
  269. Dim strDomainName ' the return value
  270. strDomainName =""
  271. Set objColletionofSystem = objService.InstancesOf ("Win32_ComputerSystem")
  272. For each objSystem in objColletionofSystem
  273. If objSystem.DomainRole <> 2 Then
  274. strDomainName=objSystem.Domain
  275. End IF
  276. Next
  277. If Err.number <> 0 then
  278. Err.Clear
  279. getConnectedDomain = strDomainName
  280. Exit Function
  281. End If
  282. getConnectedDomain = strDomainName
  283. Set objColletionofSystem = Nothing ' clean up
  284. End Function
  285. '-------------------------------------------------------------------------
  286. ' SubRoutine name: getWinDomainsAsComboValues
  287. ' Description: Outputs the Windows domains as ComboBox Values
  288. ' Input Variables: In: valueToBeSelected - which domain to select
  289. ' Output Variables: None
  290. ' Returns: None
  291. ' Global Variables: F_(*) - form values
  292. ' This sub routine outputs HTML text. This populates the Windows Domains
  293. ' obtained from the Activex Object as <OPTION> values.
  294. '-------------------------------------------------------------------------
  295. Sub getWinDomainsAsComboValues(valueToBeSelected)
  296. On Error Resume Next
  297. Err.Clear
  298. Dim objMapper ' the mapper object
  299. Dim nNTDomains ' the number of Win Domains available
  300. Dim nIndex ' loop variable
  301. Dim strSelectStatus ' to select the Option in the ComboBox or Not
  302. Dim blnConnectedDomainListed ' to check if Connected Domain is listed
  303. Dim strConnectedDomain ' to store the connected domain name
  304. blnConnectedDomainListed = False ' initialize
  305. ' get the connected domain
  306. strConnectedDomain = getConnectedDomain(GetWMIConnection("root\CIMV2"))
  307. ' get the mapper object
  308. Set objMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  309. ' get the trusted NT domains
  310. objMapper.LoadNTDomainList()
  311. If Err.number <> 0 Then
  312. SA_ServeFailurePage L_CREATEOBJECTFAILED_ERRORMESSAGE
  313. End If
  314. ' enum NT domains
  315. objMapper.Mode = ENUM_NTDOMAINS
  316. nNTDomains = objMapper.EnumCount
  317. objMapper.moveFirst()
  318. ' add the NT Domains to the ComboBox
  319. For nIndex = 0 To nNTDomains - 1
  320. ' if the input value matches the domain, Select it, else don't
  321. If LCase(objMapper.EnumValue) = LCase(valueToBeSelected) Then
  322. strSelectStatus = CONST_LISTITEM_SELECTED_STATUS
  323. Else
  324. strSelectStatus = CONST_LISTITEM_NOT_SELECTED_STATUS
  325. End If
  326. ' check if the connected domain is listed
  327. If LCase(objMapper.EnumValue) = LCase(strConnectedDomain) Then
  328. blnConnectedDomainListed = True
  329. End If
  330. ' output the HTML
  331. Response.Write"<OPTION value =" & Chr(34)& objMapper.EnumValue & Chr(34)& " " & strSelectStatus & " >" & Server.HTMLEncode(objMapper.EnumValue) & "</OPTION>"
  332. objMapper.moveNext()
  333. Next
  334. ' print the Connected Domain if it is not listed
  335. If NOT blnConnectedDomainListed Then
  336. strSelectStatus = CONST_LISTITEM_NOT_SELECTED_STATUS
  337. If LCase(valueToBeSelected) = LCase(strConnectedDomain) Then
  338. strSelectStatus = CONST_LISTITEM_SELECTED_STATUS
  339. End If
  340. Response.Write"<OPTION value =" & Chr(34)& strConnectedDomain & Chr(34)& " " & strSelectStatus & " >" & Server.HTMLEncode(strConnectedDomain) & "</OPTION>"
  341. End If
  342. ' clean up
  343. Set objMapper = Nothing
  344. End Sub
  345. '-------------------------------------------------------------------------
  346. 'Function name: isMapServiceInstalled
  347. 'Description: Checks if the instance is valid(exists)
  348. 'Input Variables: objService - object to WMI
  349. 'Output Variables: None
  350. 'Returns: True if Mapping service is installed
  351. ' False if not installed (or error occurs in getting it)
  352. ' Checks whether the given instance is valid in WMI.Returns true on valid
  353. ' false on invalid(or Error)
  354. '-------------------------------------------------------------------------
  355. Function isMapServiceInstalled(objService)
  356. Err.Clear
  357. On Error Resume Next
  358. Dim objInstance ' the wmi instance object
  359. ' get the service by executing the query
  360. Set objInstance = objservice.Get("Win32_Service.Name='MapSvc'")
  361. ' if Object is Null or Not found, return false, else return true
  362. If IsNull(objInstance) OR Err.number <> 0 Then
  363. isMapServiceInstalled = False
  364. Err.Clear
  365. Else
  366. isMapServiceInstalled = True
  367. End If
  368. 'clean objects
  369. Set objInstance= Nothing
  370. End Function
  371. '-------------------------------------------------------------------------
  372. ' Function name: ServeSMAPFooter
  373. ' Description: Serves the hidden form variables
  374. ' Input Variables: None
  375. ' Output Variables: None
  376. ' Returns: None
  377. ' Global Variables: F_(*) - form values
  378. ' This function serves the hidden variables of the form.
  379. ' These are used to get the form values when the form is submitted.
  380. '-------------------------------------------------------------------------
  381. Function ServeSMAPFooter
  382. On Error Resume Next
  383. Err.Clear
  384. %>
  385. <input type="hidden" name="hdnintSMap_EnableSMap" value="<%=F_intSMapCheckBox_EnableSMap%>">
  386. <input type="hidden" name="hdnstrSMap_WindowsDomain" value="<%=Server.HTMLEncode(F_strSMap_WindowsDomain)%>">
  387. <%
  388. End Function
  389. %>