home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / ins.cab / rexpire.vbs < prev    next >
Encoding:
Text File  |  1997-08-16  |  8.8 KB  |  390 lines

  1. REM
  2. REM LOCALIZATION
  3. REM
  4.  
  5. L_SWITCH_OPERATION      = "-t"
  6. L_SWITCH_SERVER         = "-s"
  7. L_SWITCH_INSTANCE_ID    = "-v"
  8. L_SWITCH_EXPIRE_ID      = "-i"
  9. L_SWITCH_TIME            = "-h"
  10. L_SWITCH_SIZE           = "-d"
  11. L_SWITCH_NEWSGROUPS     = "-n"
  12. L_SWITCH_NAME           = "-p"
  13.  
  14. L_OP_ADD            = "a"
  15. L_OP_DELETE         = "d"
  16. L_OP_GET            = "g"
  17. L_OP_SET            = "s"
  18. L_OP_ENUMERATE      = "e"
  19.  
  20. L_DESC_PROGRAM      = "rexpire - Set server expiration policies"
  21. L_DESC_ADD          = "add expiration policy"
  22. L_DESC_DELETE       = "delete expiration policy"
  23. L_DESC_GET          = "get expiration policy"
  24. L_DESC_SET          = "set expiration policy"
  25. L_DESC_ENUMERATE    = "enumerate expiration policies"
  26.  
  27. L_DESC_OPERATIONS    = "<operations>"
  28. L_DESC_SERVER       = "<server> Specify computer to configure"
  29. L_DESC_INSTANCE_ID  = "<virtual server id> Specify virtual server id"
  30. L_DESC_EXPIRE_ID    = "<expire id> Specify expiration policy id"
  31. L_DESC_TIME            = "<expire time> Specify number of hours until articles are expired"
  32. L_DESC_SIZE         = "<megabytes> specify megabytes limit for expiration policy"
  33. L_DESC_NEWSGROUPS   = "<newsgroups> Specify newsgroup to which policy is applied"
  34. L_DESC_NAME         = "<policy name> Expire policy name"
  35.  
  36. L_STR_EXPIRE_NAME    = "Name:"
  37. L_STR_EXPIRE_ID        = "Expire ID:"
  38. L_STR_EXPIRE_SIZE    = "Size:"
  39. L_STR_EXPIRE_TIME    = "Time horizon:"
  40. L_STR_NEWSGROUPS    = "Newsgroups:"
  41.  
  42. L_ERR_MUST_ENTER_ID = "You must enter an expire policy ID"
  43. L_ERR_EXPIRE_ID_NOT_FOUND    = "Error: There is no expiration policy with that ID"
  44.  
  45. REM
  46. REM END LOCALIZATION
  47. REM
  48.  
  49. REM
  50. REM --- Globals ---
  51. REM
  52.  
  53. dim g_dictParms
  54. dim    g_admin
  55.  
  56. set g_dictParms = CreateObject ( "Scripting.Dictionary" )
  57. set g_admin = CreateObject ( "NntpAdm.Expiration" )
  58.  
  59. REM
  60. REM --- Set argument defaults ---
  61. REM
  62.  
  63. g_dictParms(L_SWITCH_OPERATION)        = ""
  64. g_dictParms(L_SWITCH_SERVER)        = ""
  65. g_dictParms(L_SWITCH_INSTANCE_ID)    = "1"
  66. g_dictParms(L_SWITCH_EXPIRE_ID)        = ""
  67. g_dictParms(L_SWITCH_TIME)            = "-1"
  68. g_dictParms(L_SWITCH_SIZE)            = "500"
  69. g_dictParms(L_SWITCH_NEWSGROUPS)    = ""
  70. g_dictParms(L_SWITCH_NAME)            = ""
  71.  
  72. REM
  73. REM --- Begin Main Program ---
  74. REM
  75.  
  76. if NOT ParseCommandLine ( g_dictParms, WScript.Arguments ) then
  77.     usage
  78.     WScript.Quit ( 0 )
  79. end if
  80.  
  81. dim cExpires
  82. dim i
  83. dim id
  84. dim index
  85.  
  86. REM
  87. REM    Debug: print out command line arguments:
  88. REM
  89. REM switches = g_dictParms.keys
  90. REM args = g_dictParms.items
  91. REM
  92. REM
  93. REM for i = 0 to g_dictParms.Count - 1
  94. REM     WScript.echo switches(i) & " = " & args(i)
  95. REM next
  96. REM
  97.  
  98. g_admin.Server = g_dictParms(L_SWITCH_SERVER)
  99. g_admin.ServiceInstance = g_dictParms(L_SWITCH_INSTANCE_ID)
  100. g_admin.Enumerate
  101.  
  102. id = g_dictParms ( L_SWITCH_EXPIRE_ID )
  103.  
  104. select case g_dictParms(L_SWITCH_OPERATION)
  105. case L_OP_ENUMERATE
  106.     REM
  107.     REM    List the existing expiration policies:
  108.     REM
  109.  
  110.     cExpires = g_admin.Count
  111.     for i = 0 to cExpires - 1
  112.  
  113.         g_admin.GetNth i
  114.  
  115.         WScript.Echo
  116.         PrintExpire g_admin
  117.  
  118.     next
  119.  
  120. case L_OP_ADD
  121.     REM
  122.     REM    Add a new expiration policy
  123.     REM
  124.  
  125.     if ( g_dictParms ( L_SWITCH_NEWSGROUPS ) = "" ) then
  126.         usage
  127.     else
  128.         g_admin.PolicyName            = g_dictParms ( L_SWITCH_NAME )
  129.         g_admin.ExpireTime            = g_dictParms ( L_SWITCH_TIME )
  130.         g_admin.ExpireSize            = g_dictParms ( L_SWITCH_SIZE )
  131.         g_admin.NewsgroupsVariant    = SemicolonListToArray ( g_dictParms ( L_SWITCH_NEWSGROUPS ) )
  132.  
  133.         g_admin.Add
  134.         PrintExpire g_admin
  135.     end if
  136.  
  137. case L_OP_DELETE
  138.     REM
  139.     REM    Delete an expiration policy
  140.     REM
  141.  
  142.     if id = "" OR NOT IsNumeric ( id ) then
  143.         WScript.Echo L_ERR_MUST_ENTER_ID
  144.         WScript.Quit 0
  145.     end if
  146.  
  147.     index = g_admin.FindID ( id )
  148.     if index = -1 then
  149.         WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  150.         WScript.Quit 0
  151.     end if
  152.  
  153.     g_admin.Remove id
  154.  
  155. case L_OP_GET
  156.     REM
  157.     REM    Get a specific expiration policy:
  158.     REM
  159.  
  160.     index = g_admin.FindID(id)
  161.  
  162.     if index = -1 then
  163.         WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  164.         WScript.Quit 0
  165.     end if
  166.  
  167.     g_admin.GetNth index
  168.  
  169.     WScript.Echo
  170.     PrintExpire g_admin
  171.  
  172. case L_OP_SET
  173.     REM
  174.     REM    Change an existing expiration policy:
  175.     REM
  176.  
  177.     dim strNewName
  178.     dim nNewTime
  179.     dim nNewSize
  180.     dim rgNewGroups
  181.  
  182.     index = g_admin.FindID(id)
  183.  
  184.     if index = -1 then
  185.         WScript.Echo L_ERR_EXPIRE_ID_NOT_FOUND
  186.         WScript.Quit 0
  187.     end if
  188.  
  189.     g_admin.GetNth index
  190.  
  191.     strNewName    = g_admin.PolicyName
  192.     nNewTime    = g_admin.ExpireTime
  193.     nNewSize    = g_admin.ExpireSize
  194.     rgNewGroups    = g_admin.NewsgroupsVariant
  195.  
  196.     if g_dictParms ( L_SWITCH_NAME ) <> "" then
  197.         strNewName = g_dictParms ( L_SWITCH_NAME )
  198.     end if
  199.         
  200.     if g_dictParms ( L_SWITCH_TIME ) <> "" then
  201.         nNewTime = g_dictParms ( L_SWITCH_TIME )
  202.     end if
  203.         
  204.     if g_dictParms ( L_SWITCH_SIZE ) <> "" then
  205.         nNewSize = g_dictParms ( L_SWITCH_SIZE )
  206.     end if
  207.         
  208.     if g_dictParms ( L_SWITCH_NEWSGROUPS ) <> "" then
  209.         rgNewGroups = SemicolonListToArray ( g_dictParms ( L_SWITCH_NEWSGROUPS ) )
  210.     end if
  211.         
  212.     g_admin.PolicyName            = strNewName
  213.     g_admin.ExpireTime            = nNewTime
  214.     g_admin.ExpireSize            = nNewSize
  215.     g_admin.NewsgroupsVariant    = rgNewGroups
  216.  
  217.     g_admin.Set
  218.     PrintExpire g_admin
  219.  
  220. case else
  221.     usage
  222.  
  223. end select
  224.  
  225. WScript.Quit 0
  226.  
  227. REM
  228. REM --- End Main Program ---
  229. REM
  230.  
  231. REM
  232. REM ParseCommandLine ( dictParameters, cmdline )
  233. REM     Parses the command line parameters into the given dictionary
  234. REM
  235. REM Arguments:
  236. REM     dictParameters  - A dictionary containing the global parameters
  237. REM     cmdline - Collection of command line arguments
  238. REM
  239. REM Returns - Success code
  240. REM
  241.  
  242. Function ParseCommandLine ( dictParameters, cmdline )
  243.     dim     fRet
  244.     dim     cArgs
  245.     dim     i
  246.     dim     strSwitch
  247.     dim     strArgument
  248.  
  249.     fRet    = TRUE
  250.     cArgs   = cmdline.Count
  251.     i       = 0
  252.     
  253.     do while (i < cArgs)
  254.  
  255.         REM
  256.         REM Parse the switch and its argument
  257.         REM
  258.  
  259.         if i + 1 >= cArgs then
  260.             REM
  261.             REM Not enough command line arguments - Fail
  262.             REM
  263.  
  264.             fRet = FALSE
  265.             exit do
  266.         end if
  267.  
  268.         strSwitch = cmdline(i)
  269.         i = i + 1
  270.  
  271.         strArgument = cmdline(i)
  272.         i = i + 1
  273.  
  274.         REM
  275.         REM Add the switch,argument pair to the dictionary
  276.         REM
  277.  
  278.         if NOT dictParameters.Exists ( strSwitch ) then
  279.             REM
  280.             REM Bad switch - Fail
  281.             REM
  282.  
  283.             fRet = FALSE
  284.             exit do
  285.         end if 
  286.  
  287.         dictParameters(strSwitch) = strArgument
  288.  
  289.     loop
  290.  
  291.     ParseCommandLine = fRet
  292. end function
  293.  
  294. REM
  295. REM    SemicolonListToArray ( strList )
  296. REM        Converts a semi colon delimited list to an array of strings
  297. REM
  298. REM        eg. str1;str2;str3;str4 -> ["str1", "str2", "str3", "str4"]
  299. REM
  300.  
  301. Function SemicolonListToArray ( strListIn )
  302.  
  303.     dim        rgItems
  304.     dim        strItem
  305.     dim        strList
  306.     dim        index
  307.     dim        i
  308.  
  309.     ReDim rgItems ( 10 )
  310.  
  311.     strList = strListIn
  312.     i = 0
  313.  
  314.     do until strList = ""
  315.  
  316.         REM
  317.         REM Debug: print out newsgroup list as we go:
  318.         REM    WScript.Echo strList
  319.         REM
  320.  
  321.         index = InStr ( strList, ";" )
  322.  
  323.         if index = 0 then
  324.             REM No trailing ";", so use the whole string
  325.  
  326.             strItem = strList
  327.             strList = ""
  328.         else
  329.             REM Use the string up to the ";"
  330.  
  331.             strItem = Left ( strList, index - 1 )
  332.             strList = Right ( strList, Len ( strList ) - index )
  333.         end if
  334.  
  335.         ReDim preserve rgItems ( i )
  336.         rgItems ( i ) = strItem
  337.         i = i + 1
  338.  
  339.     loop
  340.  
  341.     REM return the array
  342.     SemicolonListToArray = rgItems
  343. end function
  344.  
  345. REM
  346. REM Usage ()
  347. REM     prints out the description of the command line arguments
  348. REM
  349.  
  350. Sub Usage
  351.  
  352.     WScript.Echo L_DESC_PROGRAM
  353.     WScript.Echo vbTab & L_SWITCH_OPERATION & " " & L_DESC_OPERATIONS
  354.     WScript.Echo vbTab & vbTab & L_OP_ADD & vbTab & L_DESC_ADD
  355.     WScript.Echo vbTab & vbTab & L_OP_DELETE & vbTab & L_DESC_DELETE
  356.     WScript.Echo vbTab & vbTab & L_OP_GET & vbTab & L_DESC_GET
  357.     WScript.Echo vbTab & vbTab & L_OP_SET & vbTab & L_DESC_SET
  358.     WScript.Echo vbTab & vbTab & L_OP_ENUMERATE & vbTab & L_DESC_ENUMERATE
  359.     WScript.Echo vbTab & L_SWITCH_SERVER & " " & L_DESC_SERVER
  360.     WScript.Echo vbTab & L_SWITCH_INSTANCE_ID & " " & L_DESC_INSTANCE_ID
  361.     WScript.Echo vbTab & L_SWITCH_EXPIRE_ID & " " & L_DESC_EXPIRE_ID
  362.     WScript.Echo vbTab & L_SWITCH_TIME & " " & L_DESC_TIME
  363.     WScript.Echo vbTab & L_SWITCH_SIZE & " " & L_DESC_SIZE
  364.     WScript.Echo vbTab & L_SWITCH_NEWSGROUPS & " " & L_DESC_NEWSGROUPS
  365.     WScript.Echo vbTab & L_SWITCH_NAME & " " & L_DESC_NAME
  366.  
  367. end sub
  368.  
  369. Sub PrintExpire ( admobj )
  370.  
  371.     WScript.Echo L_STR_EXPIRE_ID & " " & admobj.ExpireId
  372.     WScript.Echo L_STR_EXPIRE_NAME & " " & admobj.PolicyName
  373.     WScript.Echo L_STR_EXPIRE_SIZE & " " & admobj.ExpireSize
  374.     WScript.Echo L_STR_EXPIRE_TIME & " " & admobj.ExpireTime
  375.  
  376.     dim newsgroups
  377.     dim    cGroups
  378.     dim i
  379.  
  380.     newsgroups = admobj.NewsgroupsVariant
  381.  
  382.     cGroups = UBound ( newsgroups )
  383.  
  384.     for i = 0 to cGroups
  385.         WScript.Echo L_STR_NEWSGROUPS & " " & newsgroups(i)
  386.     next
  387.  
  388. end sub
  389.  
  390.