r23178: add simple js code I use for testing and which starts to look like
[ira/wip.git] / testprogs / ejs / ejsnet / netusr.js
1 function PrintNetUsrHelp(options)
2 {
3         println("User management - available commands:");
4         println("\t list - list users in specified domain");
5         println("\t info - display user account information");
6 }
7
8
9 function ListUsers(usrCtx)
10 {
11         var list, user;
12         var finished = false;
13
14         for (list = usrCtx.List(list); list.Status.is_ok && !finished; list = usrCtx.List(list)) {
15                 for (i = 0; i < list.Count; i++) {
16                         user = list.Users[i];
17                         printf("%s\n", user.Username);
18                 }
19                 
20                 finished = list.EndOfList;
21         }
22
23         printf("\nResult: %s\n", list.Status.errstr);
24 }
25
26
27 function UserInfo(usrCtx, username)
28 {
29         var info;
30
31         info = usrCtx.Info(username);
32         if (info == null) {
33                 println("Account unknown");
34                 return -1;
35         }
36
37         println("User account info:\n");
38         printf("AccountName = %s\n", info.AccountName);
39         printf("Description = %s\n", info.Description);
40         printf("FullName    = %s\n", info.FullName);
41         printf("AcctExpiry  = %s\n", info.AcctExpiry);
42 }
43
44
45 function UserManager(ctx, options)
46 {
47         var usrCtx;
48
49         if (options.ARGV.length < 2) {
50                 PrintNetUsrHelp(options);
51                 return -1;
52
53         }
54         
55         var usrCmd = options.ARGV[1];
56
57         if (usrCmd == "create") {
58
59         } else if (usrCmd == "info") {
60                 var userName;
61
62                 if (options.ARGV.length > 2) {
63                         userName = options.ARGV[2];
64                 } else {
65                         println("No username provided");
66                         return -1;
67                 }
68                 usrCtx = ctx.UserMgr();
69
70                 UserInfo(usrCtx, userName);
71
72         } else if (usrCmd == "list") {
73
74                 if (options.ARGV.length > 2) {
75                         usrCtx = ctx.UserMgr(options.ARGV[2]);
76                 } else {
77                         usrCtx = ctx.UserMgr();
78                 }
79
80                 ListUsers(usrCtx);
81
82         } else {
83                 println("Unknown command specified.");
84                 PrintNetUsrHelp(options);
85         }
86 }