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.

366 lines
12 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' nicinterface_prop.asp: Serve the NIC Configuration Object Task Selector
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. '28-Feb-01 Creation date
  11. '13-Mar-01 Modified date
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual="/admin/inc_framework.asp" -->
  15. <!-- #include virtual="/admin/ots_main.asp" -->
  16. <!-- #include file="loc_nicspecific.asp" -->
  17. <!-- #include file="inc_network.asp" -->
  18. <%
  19. '-------------------------------------------------------------------------
  20. ' Global Constants
  21. '-------------------------------------------------------------------------
  22. Const NIC_DIM = 6
  23. Const NIC_ID = 0
  24. Const NIC_DESC = 1
  25. Const NIC_NAME = 2
  26. Const NIC_IPADDRESS = 3
  27. Const NIC_DHCP_ENABLED = 4
  28. CONST NIC_SETTINGID = 5
  29. Const NICCARDS_PER_PAGE = 19 'holds max not cards that can
  30. 'displayed on to the OTS
  31. '-------------------------------------------------------------------------
  32. ' Global Variables
  33. '-------------------------------------------------------------------------
  34. Dim rc ' to hold return code for page
  35. Dim page ' to hold page object
  36. Dim g_bSortRequested
  37. Dim g_iSortCol
  38. Dim g_sSortSequence
  39. Dim g_AppTalkInstalled ' whether appletalk protocol is installed
  40. Dim SOURCE_FILE
  41. SOURCE_FILE = SA_GetScriptFileName()
  42. '======================================================
  43. ' Entry point
  44. '======================================================
  45. ' Create Page
  46. call SA_CreatePage(L_NIC_OTS_PAGE_TITLE, "", PT_AREA, page )
  47. ' Show page
  48. call SA_ShowPage( page )
  49. '======================================================
  50. ' Web Framework Event Handlers
  51. '======================================================
  52. '---------------------------------------------------------------------
  53. ' Function name: OnInitPage
  54. ' Description: Called to signal first time processing for this page.
  55. ' Input Variables: PageIn and EventArg
  56. ' Output Variables: PageIn, EventArg
  57. ' Return Values: TRUE to indicate initialization was successful. FALSE to indicate
  58. ' errors. Returning FALSE will cause the page to be abandoned.
  59. ' Global Variables: None
  60. ' Called to signal first time processing for this page. Use this method
  61. ' to do first time initialization tasks.
  62. '---------------------------------------------------------------------
  63. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  64. Call SA_TraceOut(SOURCE_FILE, "OnInitPage")
  65. ' Sort first column in ascending sequence
  66. g_iSortCol = 0
  67. g_sSortSequence = "A"
  68. End Function
  69. '---------------------------------------------------------------------
  70. ' Function name: OnServeAreaPage
  71. ' Description: Called when the page needs to be served.
  72. ' Input Variables: PageIn, EventArg
  73. ' Output Variables: PageIn, EventArg
  74. ' Return Values: TRUE to indicate no problems occured. FALSE to indicate errors.
  75. ' Returning FALSE will cause the page to be abandoned.
  76. ' Global Variables: In:L_(*)-Localization Strings
  77. ' Called when the page needs to be served. Use this method to serve content.
  78. '---------------------------------------------------------------------
  79. Public Function OnServeAreaPage(ByRef PageIn, ByRef EventArg)
  80. Err.Clear
  81. on error resume next
  82. Dim table 'to hold table object
  83. Dim colFlags 'to hold flag value
  84. Dim nCount 'to hold count for the loop of NIC collection
  85. Dim count 'to hold count for the loop of NIC collection
  86. Dim cardCount 'to hold card count
  87. Dim cards 'to hold Collection of NIC cards
  88. Dim Connectionstatus 'to hold Connection status of NIC Card
  89. Dim objConnStatus
  90. set objConnStatus = server.CreateObject("MediaStatus.MediaState")
  91. if Err.number <> 0 then
  92. SA_ServeFailurePage L_UNABLETOCREATEOBJECT_ERRORMESSAGE
  93. exit function
  94. end if
  95. Call SA_TraceOut(SOURCE_FILE, "OnServeAreaPage")
  96. ' Create the table
  97. table = OTS_CreateTable("","")
  98. ' Create columns and add them to the table
  99. 'Add hidden column for AdapterID
  100. colFlags = (OTS_COL_FLAG_HIDDEN OR OTS_COL_KEY)
  101. Call OTS_AddTableColumn(table, OTS_CreateColumn( L_ADAPTERID_TEXT, "left",colFlags))
  102. 'Column containing Description value for each NIC Card
  103. colFlags = OTS_COL_SORT
  104. Call OTS_AddTableColumn(table, OTS_CreateColumnEx( L_NIC_OTS_COLUMN_NAME, "left",colFlags,20))
  105. 'Column containing Type value for each NIC Card
  106. colFlags = OTS_COL_SORT
  107. Call OTS_AddTableColumn(table, OTS_CreateColumnEx( L_NIC_OTS_COLUMN_TYPE, "left",colFlags,20))
  108. 'Column containing IP value for each NIC Card
  109. colFlags = OTS_COL_SORT
  110. Call OTS_AddTableColumn(table, OTS_CreateColumnEx( L_NIC_OTS_COLUMN_IPADDRESS,"left", colFlags,15))
  111. 'Column containing Configuration for each NIC Card
  112. colFlags = OTS_COL_SORT
  113. Call OTS_AddTableColumn(table, OTS_CreateColumnEx( L_NIC_OTS_COLUMN_CURRENT_CONFIG, "left", colFlags,6))
  114. 'Column containing Status for each NIC Card
  115. colFlags = OTS_COL_SORT
  116. Call OTS_AddTableColumn(table, OTS_CreateColumnEx( L_STATUS_TEXT, "left", colFlags,12))
  117. 'Get the NICCardCollection
  118. cardCount = GetNICCardCollection(cards)
  119. 'Navigation logic
  120. For count = 0 to (cardCount - 1)
  121. Dim nicCard
  122. Dim strTCPIPConfigStatus
  123. nicCard = cards(count)
  124. If ( nicCard(NIC_DHCP_ENABLED) ) Then
  125. strTCPIPConfigStatus = L_NIC_OTS_CONFIG_DHCP
  126. Else
  127. strTCPIPConfigStatus = L_NIC_OTS_CONFIG_MANUAL
  128. End If
  129. if objConnStatus.IsConnected(nicCard(NIC_SETTINGID)) then
  130. Connectionstatus = L_CONNECTED_TEXT
  131. else
  132. Connectionstatus = L_DISCONNECTED_TEXT
  133. end if
  134. nCount = nCount + 1
  135. ' select the rows
  136. Call OTS_AddTableRow( table, Array(nicCard(NIC_ID), nicCard(NIC_NAME), nicCard(NIC_DESC), nicCard(NIC_IPADDRESS),strTCPIPConfigStatus,Connectionstatus))
  137. if Count = NICCARDS_PER_PAGE then Exit For
  138. Next
  139. 'Add Task title
  140. Call OTS_SetTableTasksTitle(table, L_NIC_OTS_TASK_TITLE)
  141. 'Add Rename Task
  142. Call OTS_AddTableTask( table, OTS_CreateTask(L_NIC_OTS_TASK_RENAME, _
  143. L_NIC_OTS_TASK_RENAME_DESC, _
  144. "Network/nicRename_prop.asp",_
  145. OTS_PT_PROPERTY) )
  146. 'Add IP Task
  147. Call OTS_AddTableTask( table, OTS_CreateTask(L_NIC_OTS_TASK_IP, _
  148. L_NIC_OTS_TASK_IP_DESC, _
  149. "Network/nicip_prop.asp",_
  150. OTS_PT_TABBED_PROPERTY) )
  151. 'Add DNS task
  152. Call OTS_AddTableTask( table, OTS_CreateTask(L_NIC_OTS_TASK_DNS, _
  153. L_NIC_OTS_TASK_DNS_DESC, _
  154. "Network/nicdns_prop.asp",_
  155. OTS_PT_PROPERTY) )
  156. 'Add WINS task
  157. Call OTS_AddTableTask( table, OTS_CreateTask(L_NIC_OTS_TASK_WINS, _
  158. L_NIC_OTS_TASK_WINS_DESC, _
  159. "Network/nicwins_prop.asp",_
  160. OTS_PT_PROPERTY) )
  161. 'Add AppleTalk task if appletalk protocol is installed
  162. if g_AppTalkInstalled = true then
  163. Call OTS_AddTableTask( table, OTS_CreateTask(L_NIC_OTS_TASK_APPLETALK, _
  164. L_NIC_OTS_TASK_APPLETALK_DESC, _
  165. "Network/nicappletalk_prop.asp",_
  166. OTS_PT_PROPERTY) )
  167. end if
  168. ' Enable paging feature
  169. Call OTS_EnablePaging(table, FALSE)
  170. ' Enable sorting
  171. Call OTS_SortTable(table, g_iSortCol, g_sSortSequence, SA_RESERVED)
  172. ' Send table to the response stream
  173. Call OTS_ServeTable(table)
  174. OnServeAreaPage = TRUE
  175. 'Release the objects
  176. set objConnStatus = nothing
  177. End Function
  178. '---------------------------------------------------------------------
  179. ' Function: OnSortNotify()
  180. '
  181. ' Synopsis: Sorting notification event handler. This event is triggered in one of
  182. ' the following scenarios:
  183. '
  184. ' 1) The user presses the search Go button.
  185. ' 2) The user presses either the page next or page previous buttons
  186. ' 3) The user requests a table column sort
  187. '
  188. ' The EventArg indicates the source of this notification event which can
  189. ' be either a sorting change event (scenario 1) or a post back event
  190. ' (scenarios 2 or 3)
  191. '
  192. ' The sortCol argument indicated which column the user would like to sort
  193. ' and the sortSeq argument indicates the desired sort sequence which can
  194. ' be either ascending or descending.
  195. '
  196. ' Returns: Always returns TRUE
  197. '
  198. '---------------------------------------------------------------------
  199. Public Function OnSortNotify(ByRef PageIn, _
  200. ByRef EventArg, _
  201. ByVal sortCol, _
  202. ByVal sortSeq )
  203. OnSortNotify = TRUE
  204. '
  205. ' User pressed column sort
  206. '
  207. If SA_IsChangeEvent(EventArg) Then
  208. Call SA_TraceOut("nicinterface_prop", "OnSortNotify() Change Event Fired")
  209. g_iSortCol = sortCol
  210. g_sSortSequence = sortSeq
  211. g_bSortRequested = TRUE
  212. '
  213. ' User presed the search GO button OR clicked either the page next or page prev button
  214. ElseIf SA_IsPostBackEvent(EventArg) Then
  215. Call SA_TraceOut("nicinterface_prop", "OnSortNotify() Postback Event Fired")
  216. g_iSortCol = sortCol
  217. g_sSortSequence = sortSeq
  218. g_bSortRequested = TRUE
  219. '
  220. ' Unknown event source
  221. Else
  222. Call SA_TraceOut("nicinterface_prop", "Unrecognized Event in OnSearchNotify()")
  223. End IF
  224. End Function
  225. '-------------------------------------------------------------------------
  226. 'Function: GetNICCardCollection
  227. 'Description: Get Array of IP Enabled NIC Cards for this System
  228. 'Input Variables: NICCardCollectionOut Array to receive list of NIC Cards
  229. 'Output Variables: NICCardCollectionOut
  230. 'Returns: Collection of NIC cards
  231. 'Global Variables: None
  232. '-------------------------------------------------------------------------
  233. Function GetNICCardCollection(ByRef NICCardCollectionOut)
  234. Err.clear
  235. On Error Resume Next
  236. Dim nicCardCollection() 'hold NIC collection
  237. Dim objService 'hold connection object
  238. Dim objNICCollection 'hold NIC collection
  239. Dim objNICConfig 'holds NIC config object
  240. Dim nicCardCount 'holds NIC card count
  241. Dim objAppTalk 'hold appletalk object
  242. g_AppTalkInstalled = False
  243. Call SA_TraceOut(SOURCE_FILE, "GetNICCardCollection")
  244. Set objService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  245. Set objNICCollection = objService.ExecQuery("SELECT * from Win32_NetworkAdapterConfiguration where IPEnabled=True")
  246. nicCardCount = 0
  247. For each objNICConfig in objNICCollection
  248. Dim nicCard
  249. Dim aIPAddress
  250. ReDim nicCard(NIC_DIM)
  251. nicCard(NIC_NAME) = GetNicName(objNICConfig.Index)
  252. 'checking for the nullname and discarding
  253. if nicCard(NIC_NAME) <> "" Then
  254. nicCard(NIC_ID) = objNICConfig.Index
  255. nicCard(NIC_DESC) = objNICConfig.Description
  256. nicCard(NIC_DHCP_ENABLED) = objNICConfig.DHCPEnabled
  257. aIPAddress = objNICConfig.IPAddress
  258. If IsArray( aIPAddress ) Then
  259. nicCard(NIC_IPADDRESS) = aIPAddress(0)
  260. Else
  261. nicCard(NIC_IPADDRESS) = aIPAddress
  262. End If
  263. nicCard(NIC_SETTINGID) = objNICConfig.SettingID
  264. nicCardCount = nicCardCount + 1
  265. ReDim Preserve nicCardCollection(nicCardCount)
  266. nicCardCollection(nicCardCount-1) = nicCard
  267. End IF
  268. Next
  269. If ( nicCardCount > 0 ) Then
  270. NICCardCollectionOut = nicCardCollection
  271. End If
  272. GetNICCardCollection = nicCardCount
  273. 'Check whether Appletalk protocol is installed or not
  274. set objAppTalk = objService.Get("Win32_NetworkProtocol.Name='MSAFD AppleTalk [PAP]'")
  275. if isobject(objAppTalk) then
  276. g_AppTalkInstalled = true
  277. end if
  278. 'Release the objects
  279. set objService = nothing
  280. set objNICCollection = nothing
  281. set objAppTalk = nothing
  282. End Function
  283. %>