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