summaryrefslogtreecommitdiff
path: root/source4/scripting/bin/smbstatus
blob: 4dfc3365a17496e8e55ddb779dfe7423a94e3b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
/*
  provide information on connected users and open files
  Copyright Andrew Tridgell 2005
  Released under the GNU GPL version 3 or later
*/	

libinclude("base.js");
libinclude("management.js");

var options = new Object();

options = GetOptions(ARGV,
		"POPT_AUTOHELP",
		"POPT_COMMON_SAMBA",
		"POPT_COMMON_VERSION",
		"nbt");
if (options == undefined) {
	println("Failed to parse options: " + options.ERROR);
	return -1;
}

/*
  show open sessions
*/
function show_sessions()
{
	var sessions = smbsrv_sessions();
	var i;
	var sys = sys_init();
	if (sessions == undefined) {
		println("No sessions open");
		return;
	}
	printf("User                                  Client      Connected at\n");
	printf("-------------------------------------------------------------------------------\n");
	for (i=0;i<sessions.length;i++) {
		var info = sessions[i];
		var fulluser = sprintf("%s/%s", info.account_name, info.domain_name);
		printf("%-30s %16s   %s\n", 
		       fulluser, info.client_ip, sys.httptime(info.connect_time));
	}
	printf("\n");
}

/*
  show open tree connects
*/
function show_tcons()
{
	var tcons = smbsrv_tcons();
	var sys = sys_init();
	if (tcons == undefined) {
		println("No tree connects");
		return;
	}
	printf("Share                                 Client      Connected at\n");
	printf("-------------------------------------------------------------------------------\n");
	for (i=0;i<tcons.length;i++) {
		var info = tcons[i];
		printf("%-30s %16s   %s\n", 
		       info.share_name, info.client_ip, sys.httptime(info.connect_time));
	}
}

/*
  show nbtd information
*/
function show_nbt()
{
	var stats = nbtd_statistics();
	if (stats == undefined) {
		println("nbt server not running");
		return;
	}
	var r;
	println("NBT server statistics:");
	for (r in stats) {
		print("\t" + r + ":\t" + stats[r] + "\n");
	}
	println("");
}

var lp = loadparm_init();

printf("%s\n\n", lp.get("server string"));

if (options['nbt'] != undefined) {
	show_nbt();
} else {
	show_sessions();
	show_tcons();
}

return 0;