home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / network / nwlogin / genfld.cmd next >
OS/2 REXX Batch file  |  1992-09-22  |  13KB  |  250 lines

  1. /* Generic Folder Builder                                                    */
  2. /* Version 1.2                                                               */
  3. /*                                                                           */
  4. /* Builds folder and program objects on the OS/2 desktop based upon Novell   */
  5. /* group membership.  All previous objects created by this program are       */
  6. /* replaced by new ones or deleted if not in user's groups.                  */ 
  7. /*                                                                           */
  8. /* Novell group membership is determined by calling WHOAMI.EXE, which is     */
  9. /* assumed to be located in the PATH.  Map Z: to \PUBLIC\OS2, then add Z:    */
  10. /* to your PATH in CONFIG.SYS.                                               */
  11. /*                                                                           */
  12. /* This program requires one parameter and has an optional second parameter. */
  13. /*  Required: server name                                                    */
  14. /*  Optional: verbose flag (only checks for existence of third parameter)    */
  15. /* Verbose mode displays status of all object creations and deletions.       */
  16. /* Format:                                                                   */
  17. /*  GENFLDR server [verbose]                                                 */
  18. /* Examples:                                                                 */
  19. /*  Regular:                                                                 */
  20. /*   GENFLDR pcatd                                                           */
  21. /*  Verbose:                                                                 */
  22. /*   GENFLDR pcatd x                                                         */
  23. /*                                                                           */
  24. /* Folder and program objects are defined in a data file named OBJECTS.DAT.  */
  25. /* Each line in the data file represents one object and uses the format:     */
  26. /*    GROUP~LOCATION~CLASSNAME~TITLE~OBJECTID~SETUP~INITCMD                  */
  27. /* where these values, except for INITCMD, are defined in the CRTOBJ.TXT     */
  28. /* document.  INITCMD is the name of a batch file or program to run when the */
  29. /* object is created.  This command is run asynchronously from this file.    */
  30. /*                                                                           */
  31. /* Below are some sample records.                                            */
  32. /*                                                                           */
  33. /*  Create a folder named "LAN Folder" for members of group EVERYONE         */
  34. /*    EVERYONE~<WP_DESKTOP>~WPFolder~LAN Folder~<LAN_FOLDER>                 */
  35. /*                                                                           */
  36. /*  Create a program object for SYSCON to run in a window for members of     */
  37. /*  group EVERYONE in the previously created "LAN Folder".                   */
  38. /*    EVERYONE~<LAN_FOLDER>~WPProgram~Syscon~<LAN_SYSCON>~EXENAME=Z:SYSCON.EXE;PROGTYPE=WINDOWABLEVIO;  */
  39. /*                                                                           */
  40. /*  Create a program object for a DOS application that requires a customized */
  41. /*  batch to be created for the user.  The DOS batch file is SPECIAL.BAT and */
  42. /*  is generated by GENSPEC.CMD.                                             */
  43. /*    EVERYONE~<LAN_FOLDER>~WPProgram~Special~<LAN_SPECIAL>~EXENAME=D:\SPECIAL.BAT;PROGTYPE=WINDOWEDVDM;~GENSPEC.CMD */
  44. /*                                                                           */
  45. /*  To include comments, just begin the line with a tilde (~).               */
  46. /*    ~Create LAN Folder                                                     */
  47. /*                                                                           */
  48. /*  If a program or folder will no longer be included in the login process,  */
  49. /*  leave it in the data file, but give it a non-existent group name.  This  */
  50. /*  will still delete it, but won't create a new object for it.              */
  51. /*    REMOVED~<LAN_FOLDER>~WPProgram~WP 5.0~<LAN_WP50>                       */
  52. /*                                                                           */
  53. /* General Notes:                                                            */
  54. /*                                                                           */
  55. /*  If a folder is destroyed, then all of its contents are also destroyed.   */
  56. /*                                                                           */
  57. /*  The current version of the NetWare Requester contains a "feature" that   */
  58. /*  makes setting the NETWARE_RESOURCES tricky to use.  The setting is a     */
  59. /*  fixed length field, unlike all the other DOS Session settings.  The      */
  60. /*  field has a size of 7 characters, which is equal to the length of its    */
  61. /*  largest value, PRIVATE.  To change the setting to GLOBAL or NONE, append */
  62. /*  1 or 3 spaces.                                                           */
  63. /*     Example: SET NETWARE_RESOURCES=NONE   ;                               */
  64. /*                                                                           */
  65. /* Version History                                                           */
  66. /*  1.0   Initial version .                                                  */
  67. /*  1.1   Eliminated need for temporary file and used WHOAMI to determine    */
  68. /*        group membership.                                                  */
  69. /*  1.1a  Changed brute force method of deleting all objects to just         */
  70. /*        deleting objects that are not created.                             */
  71. /*  1.2   Added data file option for an initialization command to be run     */
  72. /*        when the object is created.                                        */
  73. /*                                                                           */
  74. /* Lee S. Fields                                                             */
  75.  
  76. /*trace('I')*/
  77.  
  78. /* verify at least one parameter, server name, was passed */
  79. parse upper arg server verbose
  80. if (server = '') then
  81.   ErrorMessage('Server name is required.')
  82.  
  83. /* check for verbose parameter */
  84. if verbose = '' then verbose = 0 
  85. else verbose = 1
  86.  
  87. /* read user's group membership */
  88. call readgroups server
  89.  
  90. /* Load REXXUTIL */
  91. call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
  92. call sysloadfuncs
  93.  
  94. /* load the object data from the specified file, OBJECTS.DAT */
  95. call LoadObj 'objects.dat'
  96.  
  97. say 'Managing LAN objects...'
  98.  
  99. /* create all objects */
  100. do j = 1 to objectcount
  101.   if MemberOf(groups.j) then do
  102.     call BldObj classnames.j, titles.j, locations.j, 'OBJECTID='objectids.j';'setups.j
  103.     if initcmds.j \= '' then '@start' initcmds.j
  104.     else nop
  105.     end
  106.   else
  107.     call DelObj objectids.j
  108. end
  109.  
  110. Exit
  111.  
  112.  
  113.  
  114. /*****************************************************************************/
  115. /* Subroutines:                                                              */
  116. /*****************************************************************************/
  117.  
  118. /*****************************************************************************/
  119. /* BldObj - Build object                                                     */
  120. /*                                                                           */
  121. /* Parameters: classname, title, location, and setup                         */
  122. /* Uses:       verbose                                                       */
  123. /* Modifies:                                                                 */
  124. /* Returns:                                                                  */
  125. /*****************************************************************************/
  126. BldObj: procedure expose verbose
  127. if verbose then call charout ,'Building: 'arg(2)
  128.  
  129. /* Build object using REPLACE as duplicateflag */
  130. result = SysCreateObject(arg(1), arg(2), arg(3), arg(4), 'R')
  131.  
  132. if verbose then do 
  133.   If result=1 Then call charout ,'...   Object created!'
  134.   Else             call charout ,'...   Not created! Return code='result
  135.  
  136.   Say '';
  137. end
  138. Return
  139.  
  140.  
  141. /*****************************************************************************/
  142. /* DelObj - Destroy object                                                   */
  143. /*                                                                           */
  144. /* Parameters: full path name or object id                                   */
  145. /* Uses:       verbose                                                       */
  146. /* Modifies:                                                                 */
  147. /* Returns:                                                                  */
  148. /*****************************************************************************/
  149. DelObj: procedure expose verbose
  150. if verbose then call charout ,'Destroying: 'arg(1)
  151.  
  152. result = SysDestroyObject(arg(1))
  153.  
  154. if verbose then do
  155.   If result=1 Then call charout ,'...   Object destroyed!'
  156.   Else             call charout ,'...   Not destroyed! Return code='result
  157.   Say '';
  158. end
  159. Return
  160.  
  161.  
  162. /*****************************************************************************/
  163. /* LoadObj - Load object data                                                */
  164. /*                                                                           */
  165. /* Parameters: file name                                                     */
  166. /* Uses:       objectcount, groups, classnames, titles, locations, objectids */
  167. /*             setups initcmds                                               */
  168. /* Modifies:   objectcount, groups, classnames, titles, locations, objectids */
  169. /*             setups initcmds                                               */
  170. /* Returns:                                                                  */
  171. /*****************************************************************************/
  172. LoadObj: procedure expose groups. classnames. titles. locations. objectids. setups. initcmds. objectcount
  173. objectfile = arg(1)
  174. /* verify name passed and file existence */
  175. if objectfile = '' then 
  176.   ErrorMessage('Data file of objects not specified.')
  177. if stream(objectfile,'c','query exists') = '' then 
  178.   ErrorMessage('Unable to open object data file')
  179.  
  180. objectcount = 0
  181. /* open file */
  182. call linein objectfile 1 0
  183. do while lines(objectfile)
  184.   objectcount = objectcount + 1
  185.   parse value linein(objectfile) with groups.objectcount '~' locations.objectcount '~' classnames.objectcount '~' titles.objectcount '~' objectids.objectcount '~' setups.objectcount '~' initcmds.objectcount
  186.   if groups.objectcount = '' then objectcount = objectcount - 1
  187. end
  188. call lineout objectfile /* close file */
  189. return
  190.  
  191.  
  192. /*****************************************************************************/
  193. /* ReadGroups - Reads list of user's groups                                  */
  194. /*                                                                           */
  195. /* Parameters: server                                                        */
  196. /* Uses:       usergroups                                                    */
  197. /* Modifies:   usergroups                                                    */
  198. /* Returns:                                                                  */
  199. /* Note:       Requires access to GROUPS.EXE                                 */
  200. /*****************************************************************************/
  201. ReadGroups: procedure expose usergroups.
  202. /* clear queue */
  203. '@rxqueue /clear'
  204.  
  205. /* run GROUPS to get group list in queue */
  206. '@whoami' arg(1) '/G |RXQUEUE'
  207.  
  208. counter = 1
  209. do i = 1 to lines("QUEUE:")
  210.   parse value linein("QUEUE:") with usergroups.counter stuff .
  211.   if stuff = '' then do
  212.     usergroups.0 = counter
  213.     counter = counter + 1
  214.   end
  215. end
  216.  
  217. if counter = 1 then
  218.   ErrorMessage('Unable to determine group membership.')
  219.  
  220. return
  221.  
  222.  
  223. /*****************************************************************************/
  224. /* MemberOf - Tests if user is member of a group                             */
  225. /*                                                                           */
  226. /* Parameters: test group                                                    */
  227. /* Uses:       usergroups                                                    */
  228. /* Modifies:                                                                 */
  229. /* Returns:    1 if member, 0 if not                                         */
  230. /*****************************************************************************/
  231. MemberOf: procedure expose usergroups.
  232. do i = 1 to usergroups.0
  233.   if usergroups.i = arg(1) then return 1
  234. end
  235. return 0
  236.  
  237.  
  238. /*****************************************************************************/
  239. /* ErrorMessage - Display error message and exit                             */
  240. /*                                                                           */
  241. /* Parameters: error message                                                 */
  242. /* Uses:                                                                     */
  243. /* Modifies:                                                                 */
  244. /* Returns:    DOES NOT RETURN                                               */
  245. /*****************************************************************************/
  246. ErrorMessage: procedure
  247. say arg(1)
  248. say 'No objects loaded, contact your LAN Administrator.'
  249. exit
  250.