/*
Unix SMB/CIFS implementation.
web status page
Copyright (C) Andrew Tridgell 1997-1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "includes.h"
#include "web/swat_proto.h"
#define _(x) lang_msg_rotate(x)
#define PIDMAP struct PidMap
/* how long to wait for start/stops to take effect */
#define SLEEP_TIME 3
PIDMAP {
PIDMAP *next, *prev;
struct server_id pid;
char *machine;
};
static PIDMAP *pidmap;
static int PID_or_Machine; /* 0 = show PID, else show Machine name */
static struct server_id 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;
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 (struct server_id pid, char *machine)
{
/* show machine name rather PID on table "Open Files"? */
if (PID_or_Machine) {
PIDMAP *newmap;
if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
/* XXX need error message for this?
if malloc fails, PID is always shown */
return;
}
newmap->pid = pid;
newmap->machine = SMB_STRDUP(machine);
DLIST_ADD(pidmap, newmap);
}
}
/* lookup PID <-> Machine name mapping */
static char *mapPid2Machine (struct server_id 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 (procid_equal(&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, "%s",
procid_str_static(&pid));
return pidbuf;
}
static char *tstring(time_t t)
{
static pstring buf;
pstrcpy(buf, time_to_asc(t));
all_string_sub(buf," "," ",sizeof(buf));
return buf;
}
static void print_share_mode(const struct share_mode_entry *e,
const char *sharepath,
const char *fname,
void *dummy)
{
char *utf8_fname;
int deny_mode;
if (!is_valid_share_mode_entry(e)) {
return;
}
deny_mode = map_share_mode_to_deny_mode(e->share_access,
e->private_options);
printf("
%s
",_(mapPid2Machine(e->pid)));
printf("
%u
",(unsigned int)e->uid);
printf("
");
switch ((deny_mode>>4)&0xF) {
case DENY_NONE: printf("DENY_NONE"); break;
case DENY_ALL: printf("DENY_ALL "); break;
case DENY_DOS: printf("DENY_DOS "); break;
case DENY_FCB: printf("DENY_FCB "); break;
case DENY_READ: printf("DENY_READ "); break;
case DENY_WRITE:printf("DENY_WRITE "); break;
}
printf("
\n",
crec->servicename, uidtoname(crec->uid),
gidtoname(crec->gid),procid_str_static(&crec->pid),
crec->machine,
tstring(crec->start));
return 0;
}
/* show the current server status */
void status_page(void)
{
const char *v;
int autorefresh=0;
int refresh_interval=30;
int nr_running=0;
BOOL waitup = False;
smbd_pid = pid_to_procid(pidfile_pid("smbd"));
if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
stop_smbd();
start_smbd();
waitup=True;
}
if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
start_smbd();
waitup=True;
}
if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
stop_smbd();
waitup=True;
}
if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
stop_nmbd();
start_nmbd();
waitup=True;
}
if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
start_nmbd();
waitup=True;
}
if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
stop_nmbd();
waitup=True;
}
#ifdef WITH_WINBIND
if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
stop_winbindd();
start_winbindd();
waitup=True;
}
if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
start_winbindd();
waitup=True;
}
if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
stop_winbindd();
waitup=True;
}
#endif
/* wait for daemons to start/stop */
if (waitup)
sleep(SLEEP_TIME);
if (cgi_variable("autorefresh")) {
autorefresh = 1;
} else if (cgi_variable("norefresh")) {
autorefresh = 0;
} else if (cgi_variable("refresh")) {
autorefresh = 1;
}
if ((v=cgi_variable("refresh_interval"))) {
refresh_interval = atoi(v);
}
if (cgi_variable("show_client_in_col_1")) {
PID_or_Machine = 1;
}
if (cgi_variable("show_pid_in_col_1")) {
PID_or_Machine = 0;
}
connections_forall(traverse_fn1, NULL);
initPid2Machine ();
printf("
%s
\n", _("Server Status"));
printf("\n");
if (autorefresh) {
/* this little JavaScript allows for automatic refresh
of the page. There are other methods but this seems
to be the best alternative */
printf("\n");
}
}