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.

263 lines
6.2 KiB

  1. REM
  2. REM LOCALIZATION
  3. REM
  4. L_SWITCH_OPERATION = "-t"
  5. L_SWITCH_SERVER = "-s"
  6. L_SWITCH_INSTANCE_ID = "-v"
  7. L_SWITCH_USERNAME = "-u"
  8. L_SWITCH_IPADDRESS = "-i"
  9. L_OP_ENUMERATE = "e"
  10. L_OP_DELETE = "d"
  11. L_OP_DELETE_ALL = "a"
  12. L_DESC_PROGRAM = "rsess - Manipulate NNTP server sessions"
  13. L_DESC_ENUMERATE = "enumerate current sessions"
  14. L_DESC_DELETE = "delete a session (must specify -u or -i)"
  15. L_DESC_DELETE_ALL = "delete all sessions"
  16. L_DESC_OPERATIONS = "<operations>"
  17. L_DESC_SERVER = "<server> Specify computer to configure"
  18. L_DESC_INSTANCE_ID = "<virtual server id> Specify virtual server id"
  19. L_DESC_USERNAME = "<username> Username to delete"
  20. L_DESC_IPADDRESS = "<IP Address> IP Address to delete"
  21. L_DESC_EXAMPLES = "Examples:"
  22. L_DESC_EXAMPLE1 = "rsess.vbs -t e -v 1"
  23. L_DESC_EXAMPLE2 = "rsess.vbs -t d -u bad_user"
  24. L_DESC_EXAMPLE3 = "rsess.vbs -t a"
  25. L_STR_SESSION_NAME = "Username:"
  26. L_STR_SESSION_IPADDRESS = "IP Address:"
  27. L_STR_SESSION_START_TIME = "Connect time:"
  28. L_STR_NUM_SESSIONS = "Number of sessions:"
  29. L_ERR_MUST_ENTER_USER_OR_IP = "Error: You must enter either a username or an IP address."
  30. REM
  31. REM END LOCALIZATION
  32. REM
  33. REM
  34. REM --- Globals ---
  35. REM
  36. dim g_dictParms
  37. dim g_admin
  38. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  39. set g_admin = CreateObject ( "NntpAdm.Sessions" )
  40. REM
  41. REM --- Set argument defaults ---
  42. REM
  43. g_dictParms(L_SWITCH_OPERATION) = ""
  44. g_dictParms(L_SWITCH_SERVER) = ""
  45. g_dictParms(L_SWITCH_INSTANCE_ID) = "1"
  46. g_dictParms(L_SWITCH_USERNAME) = ""
  47. g_dictParms(L_SWITCH_IPADDRESS) = ""
  48. REM
  49. REM --- Begin Main Program ---
  50. REM
  51. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  52. usage
  53. WScript.Quit ( 0 )
  54. end if
  55. dim cSessions
  56. dim i
  57. dim id
  58. dim index
  59. REM
  60. REM Debug: print out command line arguments:
  61. REM
  62. REM switches = g_dictParms.keys
  63. REM args = g_dictParms.items
  64. REM
  65. REM
  66. REM for i = 0 to g_dictParms.Count - 1
  67. REM WScript.echo switches(i) & " = " & args(i)
  68. REM next
  69. REM
  70. g_admin.Server = g_dictParms(L_SWITCH_SERVER)
  71. g_admin.ServiceInstance = g_dictParms(L_SWITCH_INSTANCE_ID)
  72. On Error Resume Next
  73. g_admin.Enumerate
  74. if ( Err.Number <> 0 ) then
  75. WScript.echo " Error Enumeration Sessions: " & Err.Description & "(" & Err.Number & ")"
  76. end if
  77. select case g_dictParms(L_SWITCH_OPERATION)
  78. case L_OP_ENUMERATE
  79. REM
  80. REM List the existing expiration policies:
  81. REM
  82. cSessions = g_admin.Count
  83. WScript.Echo L_STR_NUM_SESSIONS & " " & cSessions
  84. for i = 0 to cSessions - 1
  85. On Error Resume Next
  86. g_admin.GetNth i
  87. if ( Err.Number <> 0 ) then
  88. WScript.echo " Error gettomg Session: " & Err.Description & "(" & Err.Number & ")"
  89. else
  90. PrintSession g_admin
  91. end if
  92. REM WScript.Echo
  93. REM PrintSession g_admin
  94. next
  95. case L_OP_DELETE
  96. REM
  97. REM Delete specific current sessions
  98. REM
  99. g_admin.Username = g_dictParms ( L_SWITCH_USERNAME )
  100. g_admin.IPAddress = g_dictParms ( L_SWITCH_IPADDRESS )
  101. if g_admin.Username = "" AND g_admin.IPAddress = "" then
  102. WScript.Echo L_ERR_MUST_ENTER_USER_OR_IP
  103. WScript.Quit 0
  104. end if
  105. On Error Resume Next
  106. g_admin.Terminate
  107. if ( Err.Number <> 0 ) then
  108. WScript.echo " Error Termination Session: " & Err.Description & "(" & Err.Number & ")"
  109. else
  110. PrintSession g_admin
  111. end if
  112. case L_OP_DELETE_ALL
  113. REM
  114. REM Delete all current sessions
  115. REM
  116. On Error Resume Next
  117. g_admin.TerminateAll
  118. if ( Err.Number <> 0 ) then
  119. WScript.echo " Error Termination All Sessions: " & Err.Description & "(" & Err.Number & ")"
  120. else
  121. PrintSession g_admin
  122. end if
  123. case else
  124. usage
  125. end select
  126. WScript.Quit 0
  127. REM
  128. REM --- End Main Program ---
  129. REM
  130. REM
  131. REM ParseCommandLine ( dictParameters, cmdline )
  132. REM Parses the command line parameters into the given dictionary
  133. REM
  134. REM Arguments:
  135. REM dictParameters - A dictionary containing the global parameters
  136. REM cmdline - Collection of command line arguments
  137. REM
  138. REM Returns - Success code
  139. REM
  140. Function ParseCommandLine ( dictParameters, cmdline )
  141. dim fRet
  142. dim cArgs
  143. dim i
  144. dim strSwitch
  145. dim strArgument
  146. fRet = TRUE
  147. cArgs = cmdline.Count
  148. i = 0
  149. do while (i < cArgs)
  150. REM
  151. REM Parse the switch and its argument
  152. REM
  153. if i + 1 >= cArgs then
  154. REM
  155. REM Not enough command line arguments - Fail
  156. REM
  157. fRet = FALSE
  158. exit do
  159. end if
  160. strSwitch = cmdline(i)
  161. i = i + 1
  162. strArgument = cmdline(i)
  163. i = i + 1
  164. REM
  165. REM Add the switch,argument pair to the dictionary
  166. REM
  167. if NOT dictParameters.Exists ( strSwitch ) then
  168. REM
  169. REM Bad switch - Fail
  170. REM
  171. fRet = FALSE
  172. exit do
  173. end if
  174. dictParameters(strSwitch) = strArgument
  175. loop
  176. ParseCommandLine = fRet
  177. end function
  178. REM
  179. REM Usage ()
  180. REM prints out the description of the command line arguments
  181. REM
  182. Sub Usage
  183. WScript.Echo L_DESC_PROGRAM
  184. WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  185. WScript.Echo vbTab & vbTab & L_OP_ENUMERATE & vbTab & L_DESC_ENUMERATE
  186. WScript.Echo vbTab & vbTab & L_OP_DELETE & vbTab & L_DESC_DELETE
  187. WScript.Echo vbTab & vbTab & L_OP_DELETE_ALL & vbTab & L_DESC_DELETE_ALL
  188. WScript.Echo vbTab & L_SWITCH_SERVER & " " & L_DESC_SERVER
  189. WScript.Echo vbTab & L_SWITCH_INSTANCE_ID & " " & L_DESC_INSTANCE_ID
  190. WScript.Echo vbTab & L_SWITCH_USERNAME & " " & L_DESC_USERNAME
  191. WScript.Echo vbTab & L_SWITCH_IPADDRESS & " " & L_DESC_IPADDRESS
  192. WScript.Echo
  193. WScript.Echo L_DESC_EXAMPLES
  194. WScript.Echo L_DESC_EXAMPLE1
  195. WScript.Echo L_DESC_EXAMPLE2
  196. WScript.Echo L_DESC_EXAMPLE3
  197. end sub
  198. Sub PrintSession ( admobj )
  199. WScript.Echo L_STR_SESSION_NAME & " " & admobj.Username
  200. WScript.Echo L_STR_SESSION_IPADDRESS & " " & admobj.IPAddress
  201. WScript.Echo L_STR_SESSION_START_TIME & " " & admobj.StartTime
  202. end sub