Convert some more files to GPLv3.
[jra/samba/.git] / source4 / scripting / bin / smbstatus
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4   provide information on connected users and open files
5   Copyright Andrew Tridgell 2005
6   Released under the GNU GPL version 3 or later
7 */      
8
9 libinclude("base.js");
10 libinclude("management.js");
11
12 var options = new Object();
13
14 options = GetOptions(ARGV,
15                 "POPT_AUTOHELP",
16                 "POPT_COMMON_SAMBA",
17                 "POPT_COMMON_VERSION",
18                 "nbt");
19 if (options == undefined) {
20         println("Failed to parse options: " + options.ERROR);
21         return -1;
22 }
23
24 /*
25   show open sessions
26 */
27 function show_sessions()
28 {
29         var sessions = smbsrv_sessions();
30         var i;
31         var sys = sys_init();
32         if (sessions == undefined) {
33                 println("No sessions open");
34                 return;
35         }
36         printf("User                                  Client      Connected at\n");
37         printf("-------------------------------------------------------------------------------\n");
38         for (i=0;i<sessions.length;i++) {
39                 var info = sessions[i];
40                 var fulluser = sprintf("%s/%s", info.account_name, info.domain_name);
41                 printf("%-30s %16s   %s\n", 
42                        fulluser, info.client_ip, sys.httptime(info.connect_time));
43         }
44         printf("\n");
45 }
46
47 /*
48   show open tree connects
49 */
50 function show_tcons()
51 {
52         var tcons = smbsrv_tcons();
53         var sys = sys_init();
54         if (tcons == undefined) {
55                 println("No tree connects");
56                 return;
57         }
58         printf("Share                                 Client      Connected at\n");
59         printf("-------------------------------------------------------------------------------\n");
60         for (i=0;i<tcons.length;i++) {
61                 var info = tcons[i];
62                 printf("%-30s %16s   %s\n", 
63                        info.share_name, info.client_ip, sys.httptime(info.connect_time));
64         }
65 }
66
67 /*
68   show nbtd information
69 */
70 function show_nbt()
71 {
72         var stats = nbtd_statistics();
73         if (stats == undefined) {
74                 println("nbt server not running");
75                 return;
76         }
77         var r;
78         println("NBT server statistics:");
79         for (r in stats) {
80                 print("\t" + r + ":\t" + stats[r] + "\n");
81         }
82         println("");
83 }
84
85 var lp = loadparm_init();
86
87 printf("%s\n\n", lp.get("server string"));
88
89 if (options['nbt'] != undefined) {
90         show_nbt();
91 } else {
92         show_sessions();
93         show_tcons();
94 }
95
96 return 0;