From 8ad2982968478d91c9f799808195baf818d4fdae Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 6 Oct 2001 18:03:25 +0000 Subject: merge from 2.2 (This used to be commit 831530d93d606d13a792be1d3d4ac561697504d8) --- source3/web/statuspage.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'source3/web') diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index 61bbf67a13..b49fc7b656 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -22,8 +22,79 @@ #include "includes.h" #include "webintl.h" +#define PIDMAP struct PidMap + +PIDMAP { + PIDMAP *next, *prev; + pid_t pid; + char *machine; +}; + +static PIDMAP *pidmap; +static int PID_or_Machine; /* 0 = show PID, else show Machine name */ + static pid_t smbd_pid; +/* from 2nd call on, remove old list */ +static void initPid2Machine (void) +{ + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + PIDMAP *p, *q; + + for (p = pidmap; p != NULL; ) { + DLIST_REMOVE(pidmap, p); + SAFE_FREE(p->machine); + SAFE_FREE(p); + } + + pidmap = NULL; + } +} + +/* add new PID <-> Machine name mapping */ +static void addPid2Machine (pid_t pid, char *machine) +{ + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + PIDMAP *newmap; + + if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) { + /* XXX need error message for this? + if malloc fails, PID is always shown */ + return; + } + + newmap->pid = pid; + newmap->machine = strdup (machine); + + DLIST_ADD(pidmap, newmap); + } +} + +/* lookup PID <-> Machine name mapping */ +static char *mapPid2Machine (pid_t pid) +{ + static char pidbuf [64]; + PIDMAP *map; + + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + for (map = pidmap; map != NULL; map = map->next) { + if (pid == map->pid) { + if (map->machine == NULL) /* no machine name */ + break; /* show PID */ + + return map->machine; + } + } + } + + /* PID not in list or machine name NULL? return pid as string */ + snprintf (pidbuf, sizeof (pidbuf) - 1, "%d", pid); + return pidbuf; +} + static char *tstring(time_t t) { static pstring buf; @@ -34,7 +105,7 @@ static char *tstring(time_t t) static void print_share_mode(share_mode_entry *e, char *fname) { - printf("%d",(int)e->pid); + printf("%s",_(mapPid2Machine(e->pid))); printf(""); switch ((e->share_mode>>4)&0xF) { case DENY_NONE: printf(_("DENY_NONE")); break; @@ -106,9 +177,11 @@ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid)) return 0; + addPid2Machine (crec.pid, crec.machine); + printf("%d%s%s%s\n", (int)crec.pid, - crec.machine, crec.addr, + crec.machine,crec.addr, tstring(crec.start)); if (geteuid() == 0) { printf("\n", @@ -188,8 +261,14 @@ void status_page(void) refresh_interval = atoi(v); } + if (cgi_variable("show_client_in_col_1")) { + PID_or_Machine = 1; + } + tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); + + initPid2Machine (); printf("

%s

\n", _("Server Status")); @@ -277,6 +356,9 @@ void status_page(void) if (tdb) tdb_close(tdb); + printf("
\n"); + printf("\n"); + printf("\n"); if (autorefresh) { -- cgit