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.

442 lines
15 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' telnetadmin_prop.asp : get's and set's the telnet service properties.
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 28-Feb-01 Creation date
  11. '-------------------------------------------------------------------------
  12. %>
  13. <!-- #include virtual="/admin/inc_framework.asp" -->
  14. <%
  15. '-------------------------------------------------------------------------
  16. ' Global Constants and Variables
  17. '-------------------------------------------------------------------------
  18. Dim rc 'framework variables
  19. Dim page 'framework variables
  20. Dim idTabGeneral 'framework variables
  21. Const WBEMFLAG = 131072 'Wmi constant to save wmi settings
  22. '-------------------------------------------------------------------------
  23. ' Global Form Variables
  24. '-------------------------------------------------------------------------
  25. Dim F_strTelnetSvc 'contains Value True if telnet service is running
  26. ' else contains false
  27. Dim F_strEnableTelnetAccess 'Used to set the Telnet Service properties
  28. '------------------------------------------------------------------------
  29. 'Start of localization content
  30. '------------------------------------------------------------------------
  31. Dim L_PAGETITLE_TEXT 'Page title text
  32. Dim L_GENERALTAB_TEXT 'General Tab text
  33. Dim L_ENABLETELNETACCESS_TEXT 'Enable telnet access checkbox text
  34. 'error messages
  35. Dim L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE 'if telnet service is not installed
  36. 'this error message will be displayed
  37. Dim L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE 'if unable to set properties
  38. 'this error message will be displayed
  39. L_PAGETITLE_TEXT = GetLocString("telnet.dll", "&H40360003", "")
  40. L_GENERALTAB_TEXT=GetLocString("telnet.dll", "&H40360004", "")
  41. L_ENABLETELNETACCESS_TEXT=GetLocString("telnet.dll", "&H40360005", "")
  42. L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE=GetLocString("telnet.dll", "&HC0360007", "")
  43. L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE=GetLocString("telnet.dll", "&HC0360006", "")
  44. '------------------------------------------------------------------------
  45. 'END of localization content
  46. '------------------------------------------------------------------------
  47. ' Create a Tabbed Property Page
  48. rc = SA_CreatePage(L_PAGETITLE_TEXT,"", PT_TABBED, page )
  49. ' Add one tab
  50. rc = SA_AddTabPage( page, L_GENERALTAB_TEXT, idTabGeneral)
  51. ' Show the page
  52. rc = SA_ShowPage( page )
  53. '-------------------------------------------------------------------------
  54. 'Function: OnInitPage()
  55. 'Description: Called to signal first time processing for this page.
  56. ' Use this method to do first time initialization tasks
  57. 'Input Variables: PageIn,EventArg
  58. 'Output Variables: PageIn,EventArg
  59. 'Returns: True/False
  60. 'Global Variables: In:L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE-Displays
  61. ' error message when telnet service is not installed.
  62. '-------------------------------------------------------------------------
  63. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  64. Call SA_TraceOut( "telnetadmin_prop.asp", "OnInitPage")
  65. 'checking whether Telnet service is installed or not.
  66. If Not isServiceInstalled(getWMIConnection(CONST_WMI_WIN32_NAMESPACE),"TlntSvr") Then
  67. Call SA_TraceOut( "telnetadmin_prop.asp", "Telnet service is not Installed")
  68. Call SA_ServeFailurePage( L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE)
  69. Exit Function
  70. OnInitPage=False
  71. End If
  72. 'getting default telnet service properties
  73. GetTelenetSvcProp()
  74. OnInitPage = TRUE
  75. End Function
  76. '-------------------------------------------------------------------------
  77. 'Function: OnPostBackPage()
  78. 'Description: Called to signal that the page has been posted-back.
  79. 'Input Variables: PageIn,EventArg
  80. 'Output Variables: None
  81. 'Returns: True/False
  82. 'Global Variables: In:F_strTelnetSvc
  83. ' Out:F_strEnableTelnetAccess
  84. '-------------------------------------------------------------------------
  85. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  86. Call SA_TraceOut( "telnetadmin_prop.asp", "OnPostBackPage")
  87. 'getting the value when the form is submitted
  88. F_strTelnetSvc= Request.form("chkEnableTelnetAccess")
  89. 'checking whether the enable telnet checkbox is enabled or not
  90. If F_strTelnetSvc then
  91. F_strEnableTelnetAccess="CHECKED"
  92. Else
  93. F_strEnableTelnetAccess=""
  94. End If
  95. OnPostBackPage = TRUE
  96. End Function
  97. '-------------------------------------------------------------------------
  98. 'Function: OnServeTabbedPropertyPage()
  99. 'Description: Called when the page needs to be served.Use this
  100. ' method to serve content
  101. 'Input Variables: PageIn,EventArg,iTab,bIsVisible
  102. 'Output Variables: PageIn,EventArg
  103. 'Returns: True/False
  104. 'Global Variables: None
  105. ' TRUE to indicate not problems occured. FALSE to indicate errors.
  106. ' Returning FALSE will cause the page to be abandoned.
  107. '-------------------------------------------------------------------------
  108. Public Function OnServeTabbedPropertyPage(ByRef PageIn, _
  109. ByVal iTab, _
  110. ByVal bIsVisible, ByRef EventArg)
  111. Call SA_TraceOut( "telnetadmin_prop.asp", "OnServeTabbedPropertyPage")
  112. ' Emit Web Framework required functions
  113. If (iTab = 0) Then
  114. Call ServeCommonJavaScript()
  115. End If
  116. ' Emit content for the requested tab
  117. Select Case iTab
  118. Case idTabGeneral
  119. Call ServeTab1(PageIn, bIsVisible)
  120. Case Else
  121. SA_TraceOut "telnetadmin_prop.asp", _
  122. "OnServeTabbedPropertyPage unrecognized tab id: " + CStr(iTab)
  123. End Select
  124. OnServeTabbedPropertyPage = TRUE
  125. End Function
  126. '-------------------------------------------------------------------------
  127. 'Function: OnSubmitPage()
  128. 'Description: Called when the page has been submitted for processing.
  129. ' Use this method to process the submit request.
  130. 'Input Variables: PageIn,EventArg
  131. 'Output Variables: None
  132. 'Returns: True/False
  133. 'Global Variables: None
  134. '-------------------------------------------------------------------------
  135. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  136. Call SA_TraceOut( "telnetadmin_prop.asp", "OnSubmitPage")
  137. OnSubmitPage =SetTelenetSvcProp()
  138. End Function
  139. '-------------------------------------------------------------------------
  140. 'Function: OnClosePage()
  141. 'Description: Called when the page is about closed.Use this method
  142. ' to perform clean-up processing
  143. 'Input Variables: PageIn,EventArg
  144. 'Output Variables: PageIn,EventArg
  145. 'Returns: True/False
  146. 'Global Variables: None
  147. '-------------------------------------------------------------------------
  148. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  149. Call SA_TraceOut( "telnetadmin_prop.asp", "OnClosePage")
  150. OnClosePage = TRUE
  151. End Function
  152. '-------------------------------------------------------------------------
  153. 'Function name: GetTelenetSvcProp
  154. 'Description: Get TelnetService properties from the appliance
  155. 'Input Variables: None
  156. 'Output Variables: None
  157. 'Returns: True/False
  158. 'Global Variables: In:L_(*)-Localization content
  159. ' Out:F_strTelnetSvc
  160. ' Out:F_strEnableTelnetAccess
  161. '--------------------------------------------------------------------------
  162. Function GetTelenetSvcProp
  163. Err.Clear
  164. on Error resume next
  165. Dim objService 'To get wmi connection
  166. Dim strWMIpath 'To get wmi path
  167. Dim objTelnetSvc 'To get wmi class instance
  168. 'Getting wmi connection
  169. Set objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  170. If Err.number<>0 then
  171. Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi connection Failed-GetTelenetSvcProp()")
  172. Call SA_ServeFailurePage( L_WMI_CONNECTIONFAIL_ERRORMESSAGE)
  173. GetTelenetSvcProp=False
  174. Exit Function
  175. End If
  176. 'Telnet service path
  177. strWMIpath = "Win32_Service.Name='TlntSvr'"
  178. 'taking the instance of telnet service class
  179. Set objTelnetSvc=objService.get(strWMIpath)
  180. If Err.number<>0 then
  181. Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi Class Instance Failed-GetTelenetSvcProp()")
  182. Call SA_ServeFailurePage( L_WMI_INSTANCEFAIL_ERRORMESSAGE)
  183. GetTelenetSvcProp=False
  184. Exit Function
  185. End If
  186. 'objTelnetSvc.Started returns true if telnet service is running.
  187. ' otherewise returns false
  188. F_strTelnetSvc=objTelnetSvc.Started
  189. If F_strTelnetSvc then
  190. F_strEnableTelnetAccess="CHECKED"
  191. Else
  192. F_strEnableTelnetAccess=""
  193. End If
  194. GetTelenetSvcProp=True
  195. 'Destroying dynamically created objects
  196. Set objService=Nothing
  197. Set objTelnetSvc=Nothing
  198. End function
  199. '-------------------------------------------------------------------------
  200. 'Function name: SetTelenetSvcProp
  201. 'Description: Setting the properties of the Telnet service
  202. 'Input Variables: None
  203. 'Output Variables: None
  204. 'Returns: (True / Flase )
  205. 'Global Variables: In:F_strTelnetSvc-'contains Value True if telnet service
  206. ' is running else contains false
  207. ' In:L_(*)-Localization content
  208. '--------------------------------------------------------------------------
  209. Function SetTelenetSvcProp
  210. Err.Clear
  211. on Error resume next
  212. Dim objService 'To get wmi connection
  213. Dim strWMIpath 'To get wmi path
  214. Dim objTelnetSvc 'To get wmi class instance
  215. 'Getting wmi connection
  216. Set objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  217. If Err.number<>0 then
  218. Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi connection Failed-SetTelenetSvcProp()")
  219. Call SA_ServeFailurePage( L_WMI_CONNECTIONFAIL_ERRORMESSAGE)
  220. SetTelenetSvcProp=False
  221. Exit Function
  222. End If
  223. 'Telnet service path
  224. strWMIpath = "Win32_Service.Name='TlntSvr'"
  225. 'taking the instance of telnet service instance
  226. Set objTelnetSvc=objService.get(strWMIpath)
  227. If Err.number<>0 then
  228. Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi Class Instance Failed-SetTelenetSvcProp()")
  229. Call SA_ServeFailurePage(L_WMI_INSTANCEFAIL_ERRORMESSAGE)
  230. SetTelenetSvcProp=False
  231. Exit Function
  232. End If
  233. 'setting the telnet service properties
  234. If F_strTelnetSvc then
  235. 'if enable telnet access checkbox is checked,setting the telnet service to automatic,
  236. ' and starting the service.
  237. If Lcase(objTelnetSvc.StartMode) <> Lcase("Auto") then
  238. objTelnetSvc.ChangeStartMode("Automatic")
  239. end If
  240. objTelnetSvc.StartService()
  241. Else
  242. 'if enable telnet access checkbox is not checked,setting the telnet service to disabled,
  243. ' and stopping the service.
  244. objTelnetSvc.ChangeStartMode("Disabled")
  245. objTelnetSvc.StopService()
  246. End If
  247. 'saving the wmi settings
  248. 'objTelnetSvc.Put_(WBEMFLAG)
  249. If Err.number <> 0 then
  250. Call SA_TraceOut( "telnetadmin_prop.asp", "Failed to Set TelnetService Properties" )
  251. SetErrMsg L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE
  252. SetTelenetSvcProp = false
  253. Exit function
  254. End If
  255. SetTelenetSvcProp=True
  256. 'Destroying dynamically created objects
  257. Set objService=Nothing
  258. Set objTelnetSvc=Nothing
  259. End Function
  260. '-------------------------------------------------------------------------
  261. 'Function: ServeTab1
  262. 'Description: Serves in getting the page for tab1
  263. 'Input Variables: PageIn,bIsVisible
  264. 'Output Variables: PageIn
  265. 'Returns: gc_ERR_SUCCESS
  266. 'Global Variables: L_(*)All
  267. ' F_(*) All
  268. '-------------------------------------------------------------------------
  269. Function ServeTab1(ByRef PageIn, ByVal bIsVisible)
  270. If ( bIsVisible ) Then
  271. %>
  272. <TABLE WIDTH=300 VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2 class="TasksBody">
  273. <TR>
  274. <TD>
  275. <INPUT TYPE="CHECKBOX" NAME ="chkEnableTelnetAccess" VALUE="<%=F_strTelnetSvc%>" <%=F_strEnableTelnetAccess%> onclick="storeEnableAccessVals()">
  276. <%=L_ENABLETELNETACCESS_TEXT%>
  277. </TD>
  278. <TR>
  279. </TABLE>
  280. <%else%>
  281. <INPUT TYPE="hidden" NAME ="chkEnableTelnetAccess" VALUE="<%=F_strTelnetSvc%>">
  282. <%
  283. End If
  284. ServeTab1 = gc_ERR_SUCCESS
  285. End Function
  286. '-------------------------------------------------------------------------
  287. 'Function: ServeCommonJavaScript
  288. 'Description: Serves in initialiging the values,setting the form
  289. ' data and validating the form values
  290. 'Input Variables: None
  291. 'Output Variables: None
  292. 'Returns: None
  293. 'Global Variables: L_PASSWORDNOTMATCH_ERRORMESSAGE
  294. '-------------------------------------------------------------------------
  295. Function ServeCommonJavaScript()
  296. %>
  297. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  298. </script>
  299. <script language="JavaScript">
  300. // Init Function
  301. function Init()
  302. {
  303. return true;
  304. }
  305. function storeEnableAccessVals()
  306. {
  307. var objForm = eval("document.frmTask")
  308. var objEnableAccess = objForm.chkEnableTelnetAccess
  309. if(objEnableAccess.checked == true)
  310. objForm.chkEnableTelnetAccess.value = "true"
  311. else
  312. objForm.chkEnableTelnetAccess.value= "false"
  313. }
  314. // ValidatePage Function
  315. // Returns: True if the page is OK, false if error(s) exist.
  316. function ValidatePage()
  317. {
  318. return true;
  319. }
  320. // SetData Function
  321. function SetData()
  322. {
  323. return true;
  324. }
  325. </script>
  326. <%
  327. End Function
  328. '-------------------------------------------------------------------------
  329. 'Function name: isServiceInstalled
  330. 'Description:helper Function to chek whether the function is there or not
  331. 'Input Variables: objService - object to WMI
  332. ' strServiceName - Service name
  333. 'Output Variables: None
  334. 'Returns: (True/Flase)
  335. 'GlobalVariables: None
  336. '-------------------------------------------------------------------------
  337. Function isServiceInstalled(ObjWMI,strServiceName)
  338. Err.clear
  339. on error resume next
  340. Dim strService
  341. strService = "name=""" & strServiceName & """"
  342. isServiceInstalled = IsValidWMIInstance(ObjWMI,"Win32_Service",strService)
  343. end Function
  344. '-------------------------------------------------------------------------
  345. 'Function name: IsValidWMIInstance
  346. 'Description: Checks the instance for valid ness.
  347. 'Input Variables: objService - object to WMI
  348. ' strClassName - WMI class name
  349. ' strPropertyName - Property name of the class
  350. '
  351. 'Output Variables: None
  352. 'Returns: Returns true on Valid Instance ,
  353. ' False on invalid and also on Error
  354. ' Checks whether the given instance is valid in WMI.Returns true on valid
  355. ' false on invalid or Error.
  356. '-------------------------------------------------------------------------
  357. Function IsValidWMIInstance(objService,strClassName,strPropertyName)
  358. Err.Clear
  359. On Error Resume Next
  360. Dim strInstancePath
  361. Dim objInstance
  362. strInstancePath = strClassName & "." & strPropertyName
  363. Set objInstance = objservice.Get(strInstancePath)
  364. if NOT isObject(objInstance) or Err.number <> 0 Then
  365. IsValidWMIInstance = FALSE
  366. Err.Clear
  367. Else
  368. IsValidWMIInstance = TRUE
  369. End If
  370. 'clean objects
  371. Set objInstance=nothing
  372. End Function
  373. %>