diff options
Diffstat (limited to 'source4/scripting/bin/smbstatus')
-rwxr-xr-x | source4/scripting/bin/smbstatus | 159 |
1 files changed, 73 insertions, 86 deletions
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 4dfc3365a1..bbd0e84826 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -1,96 +1,83 @@ -#!/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 -*/ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# provide information on connected users and open files +# Copyright ǒ Jelmer Vernooij 2008 +# +# Based on the original in EJS: +# Copyright Andrew Tridgell 2005 +# Released under the GNU GPL version 3 or later +# -libinclude("base.js"); -libinclude("management.js"); +import os, sys -var options = new Object(); +sys.path.insert(0, "bin/python") -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_VERSION", - "nbt"); -if (options == undefined) { - println("Failed to parse options: " + options.ERROR); - return -1; -} +import optparse +import samba.getopt as options +from samba import irpc, messaging -/* - 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"); -} +def show_sessions(conn): + """show open sessions""" -/* - 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)); - } -} + sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next() + print "User Client Connected at" + print "-------------------------------------------------------------------------------" + for session in sessions: + fulluser = "%s/%s" % (session.account_name, session.domain_name) + print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time)) + print "" -/* - 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(""); -} +def show_tcons(open_connection): + """show open tree connects""" + conn = open_connection("smb_server") + tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next() + print "Share Client Connected at" + print "-------------------------------------------------------------------------------" + for tcon in tcons: + print "%-30s %16s %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) -var lp = loadparm_init(); -printf("%s\n\n", lp.get("server string")); +def show_nbt(open_connection): + """show nbtd information""" + conn = open_connection("nbt_server") + stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next() + print "NBT server statistics:" + fields = [("total_received", "Total received"), + ("total_sent", "Total sent"), + ("query_count", "Query count"), + ("register_count", "Register count"), + ("release_count", "Release count")] + for (field, description) in fields: + print "\t%s:\t%s" % (description, getattr(stats, field)) + print -if (options['nbt'] != undefined) { - show_nbt(); -} else { - show_sessions(); - show_tcons(); -} +parser = optparse.OptionParser("%s [options]" % sys.argv[0]) +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) +parser.add_option("--messaging-path", type="string", metavar="PATH", + help="messaging path") +parser.add_option("--nbt", help="show NetBIOS status", action="store_true") -return 0; +opts, args = parser.parse_args() + +lp = sambaopts.get_loadparm() + +print "%s" % lp.get("server string") + +messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging")) + +def open_connection(name): + return messaging.ClientConnection(name, messaging_path=messaging_path) + +if opts.nbt: + show_nbt(open_connection) +else: + try: + conn = open_connection("smb_server") + except RuntimeError, (num, msg): + if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND': + print "No active connections" + else: + show_sessions(conn) + show_tcons(conn) |