X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=source3%2Fweb%2Fstatuspage.c;h=5314f3343269f5d7bdd4a2f384cf9345245f68dd;hb=aef5fcbfc74ab1e078d7133169215aeef1fab30e;hp=ddbe658a6cb4ba9f03e4d27b2803c50004320b89;hpb=9c6e58869f45dd2be0904b9ecf9e757b2b3841d6;p=samba.git diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index ddbe658a6cb..5314f334326 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -5,7 +5,7 @@ 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 2 of the License, or + 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, @@ -14,34 +14,41 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -#include "../web/swat_proto.h" +#include "web/swat_proto.h" +#include "libcli/security/security.h" +#include "locking/proto.h" + +#define _(x) lang_msg_rotate(talloc_tos(),x) #define PIDMAP struct PidMap +/* how long to wait for start/stops to take effect */ +#define SLEEP_TIME 3 + PIDMAP { PIDMAP *next, *prev; - pid_t pid; + struct server_id pid; char *machine; }; static PIDMAP *pidmap; static int PID_or_Machine; /* 0 = show PID, else show Machine name */ -static pid_t smbd_pid; +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; + PIDMAP *p, *next; - for (p = pidmap; p != NULL; ) { + for (p = pidmap; p != NULL; p = next) { + next = p->next; DLIST_REMOVE(pidmap, p); SAFE_FREE(p->machine); SAFE_FREE(p); @@ -52,27 +59,27 @@ static void initPid2Machine (void) } /* add new PID <-> Machine name mapping */ -static void addPid2Machine (pid_t pid, char *machine) +static void addPid2Machine (struct server_id pid, const char *machine) { /* show machine name rather PID on table "Open Files"? */ if (PID_or_Machine) { PIDMAP *newmap; - if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) { + 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 = strdup (machine); + newmap->machine = SMB_STRDUP(machine); DLIST_ADD(pidmap, newmap); } } /* lookup PID <-> Machine name mapping */ -static char *mapPid2Machine (pid_t pid) +static char *mapPid2Machine (struct server_id pid) { static char pidbuf [64]; PIDMAP *map; @@ -80,7 +87,7 @@ static char *mapPid2Machine (pid_t pid) /* 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 (procid_equal(&pid, &map->pid)) { if (map->machine == NULL) /* no machine name */ break; /* show PID */ @@ -90,125 +97,145 @@ static char *mapPid2Machine (pid_t pid) } /* PID not in list or machine name NULL? return pid as string */ - snprintf (pidbuf, sizeof (pidbuf) - 1, "%d", pid); + snprintf (pidbuf, sizeof (pidbuf) - 1, "%s", + procid_str_static(&pid)); return pidbuf; } -static char *tstring(time_t t) +static const char *tstring(TALLOC_CTX *ctx, time_t t) { - static pstring buf; - pstrcpy(buf, asctime(LocalTime(&t))); - all_string_sub(buf," "," ",sizeof(buf)); + char *buf; + buf = talloc_strdup(ctx, time_to_asc(t)); + if (!buf) { + return ""; + } + buf = talloc_all_string_sub(ctx, + buf, + " ", + " "); + if (!buf) { + return ""; + } return buf; } -static void print_share_mode(share_mode_entry *e, char *fname) +static void print_share_mode(const struct share_mode_entry *e, + const char *sharepath, + const char *fname, + void *dummy) { - d_printf("%s",_(mapPid2Machine(e->pid))); - d_printf(""); - switch ((e->share_mode>>4)&0xF) { - case DENY_NONE: d_printf("DENY_NONE"); break; - case DENY_ALL: d_printf("DENY_ALL "); break; - case DENY_DOS: d_printf("DENY_DOS "); break; - case DENY_READ: d_printf("DENY_READ "); break; - case DENY_WRITE:d_printf("DENY_WRITE "); break; + char *utf8_fname; + char *utf8_sharepath; + int deny_mode; + size_t converted_size; + + if (!is_valid_share_mode_entry(e)) { + return; } - d_printf(""); - d_printf(""); - switch (e->share_mode&0xF) { - case 0: d_printf("RDONLY "); break; - case 1: d_printf("WRONLY "); break; - case 2: d_printf("RDWR "); break; + 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; } - d_printf(""); + printf(""); - d_printf(""); + printf(""); + if (e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA)) { + printf("%s", _("RDWR ")); + } else if (e->access_mask & FILE_WRITE_DATA) { + printf("%s", _("WRONLY ")); + } else { + printf("%s", _("RDONLY ")); + } + printf(""); + + printf(""); if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) - d_printf("EXCLUSIVE+BATCH "); + printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) - d_printf("EXCLUSIVE "); + printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) - d_printf("BATCH "); + printf("BATCH "); else if (e->op_type & LEVEL_II_OPLOCK) - d_printf("LEVEL_II "); + printf("LEVEL_II "); else - d_printf("NONE "); - d_printf(""); - - d_printf("%s%s\n", - fname,tstring(e->time.tv_sec)); + printf("NONE "); + printf(""); + + push_utf8_talloc(talloc_tos(), &utf8_fname, fname, &converted_size); + push_utf8_talloc(talloc_tos(), &utf8_sharepath, sharepath, + &converted_size); + printf("%s%s%s\n", + utf8_sharepath,utf8_fname,tstring(talloc_tos(),e->time.tv_sec)); + TALLOC_FREE(utf8_fname); } /* kill off any connections chosen by the user */ -static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn1(const struct connections_key *key, + const struct connections_data *crec, + void *private_data) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 && process_exists(crec.pid)) { + if (crec->cnum == -1 && process_exists(crec->pid)) { char buf[30]; - slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); + slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec->pid)); if (cgi_variable(buf)) { - kill_pid(crec.pid); + kill_pid(crec->pid); + sleep(SLEEP_TIME); } } return 0; } /* traversal fn for showing machine connections */ -static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn2(const struct connections_key *key, + const struct connections_data *crec, + void *private_data) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid)) + if (crec->cnum == -1 || !process_exists(crec->pid) || + procid_equal(&crec->pid, &smbd_pid)) return 0; - addPid2Machine (crec.pid, crec.machine); + addPid2Machine (crec->pid, crec->machine); - d_printf("%d%s%s%s\n", - (int)crec.pid, - crec.machine,crec.addr, - tstring(crec.start)); + printf("%s%s%s%s\n", + procid_str_static(&crec->pid), + crec->machine, crec->addr, + tstring(talloc_tos(),crec->start)); if (geteuid() == 0) { - d_printf("\n", - (int)crec.pid); + printf("\n", + procid_str_static(&crec->pid)); } - d_printf("\n"); + printf("\n"); return 0; } /* traversal fn for showing share connections */ -static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn3(const struct connections_key *key, + const struct connections_data *crec, + void *private_data) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 || !process_exists(crec.pid)) + if (crec->cnum == -1 || !process_exists(crec->pid)) return 0; - d_printf("%s%s%s%d%s%s\n", - crec.name,uidtoname(crec.uid), - gidtoname(crec.gid),(int)crec.pid, - crec.machine, - tstring(crec.start)); + printf("%s%s%s%s%s%s\n", + crec->servicename, uidtoname(crec->uid), + gidtoname(crec->gid),procid_str_static(&crec->pid), + crec->machine, + tstring(talloc_tos(),crec->start)); return 0; } @@ -219,50 +246,69 @@ void status_page(void) const char *v; int autorefresh=0; int refresh_interval=30; - TDB_CONTEXT *tdb; int nr_running=0; + bool waitup = False; + TALLOC_CTX *ctx = talloc_stackframe(); + const char form_name[] = "status"; - smbd_pid = pidfile_pid("smbd"); + smbd_pid = pid_to_procid(pidfile_pid("smbd")); + + if (!verify_xsrf_token(form_name)) { + goto output_page; + } 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")) { @@ -279,153 +325,140 @@ void status_page(void) 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); - + if (cgi_variable("show_pid_in_col_1")) { + PID_or_Machine = 0; + } + + connections_forall_read(traverse_fn1, NULL); + initPid2Machine (); - d_printf("

%s

\n", _("Server Status")); +output_page: + printf("

%s

\n", _("Server Status")); - d_printf("
\n"); + printf("\n"); + print_xsrf_token(cgi_user_name(), cgi_user_pass(), form_name); if (!autorefresh) { - d_printf("\n", _("Auto Refresh")); - d_printf("
%s", _("Refresh Interval: ")); - d_printf("\n", + printf("\n", _("Auto Refresh")); + printf("
%s", _("Refresh Interval: ")); + printf("\n", refresh_interval); } else { - d_printf("\n", _("Stop Refreshing")); - d_printf("
%s%d\n", _("Refresh Interval: "), refresh_interval); - d_printf("\n"); + printf("\n", _("Stop Refreshing")); + printf("
%s%d\n", _("Refresh Interval: "), refresh_interval); + printf("\n"); } - d_printf("

\n"); + printf("

\n"); - if (!tdb) { - /* open failure either means no connections have been - made */ - } - - - d_printf("\n"); + printf("
\n"); - d_printf("", _("version:"), VERSION); + printf("", _("version:"), samba_version_string()); fflush(stdout); - d_printf("\n", _("smbd:"), smbd_running()?_("running"):_("not running")); + printf("\n", _("smbd:"), smbd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (smbd_running()) { nr_running++; - d_printf("\n", _("Stop smbd")); + printf("\n", _("Stop smbd")); } else { - d_printf("\n", _("Start smbd")); + printf("\n", _("Start smbd")); } - d_printf("\n", _("Restart smbd")); + printf("\n", _("Restart smbd")); } - d_printf("\n"); + printf("\n"); fflush(stdout); - d_printf("\n", _("nmbd:"), nmbd_running()?_("running"):_("not running")); + printf("\n", _("nmbd:"), nmbd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (nmbd_running()) { nr_running++; - d_printf("\n", _("Stop nmbd")); + printf("\n", _("Stop nmbd")); } else { - d_printf("\n", _("Start nmbd")); + printf("\n", _("Start nmbd")); } - d_printf("\n", _("Restart nmbd")); -#ifndef WITH_WINBIND - if (nr_running >= 1) { - /* stop, restart all */ - d_printf("\n"); - d_printf("\n", _("Stop All")); - d_printf("\n", _("Restart All")); - } - else if (nr_running == 0) { - /* start all */ - d_printf("\n"); - d_printf("\n", _("Start All")); - } -#endif + printf("\n", _("Restart nmbd")); } - d_printf("\n"); + printf("\n"); #ifdef WITH_WINBIND fflush(stdout); - d_printf("\n", _("winbindd:"), winbindd_running()?_("running"):_("not running")); + printf("\n", _("winbindd:"), winbindd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (winbindd_running()) { nr_running++; - d_printf("\n", _("Stop winbindd")); + printf("\n", _("Stop winbindd")); } else { - d_printf("\n", _("Start winbindd")); + printf("\n", _("Start winbindd")); } - d_printf("\n", _("Restart winbindd")); + printf("\n", _("Restart winbindd")); + } + printf("\n"); +#endif + + if (geteuid() == 0) { + printf("\n"); if (nr_running >= 1) { /* stop, restart all */ - d_printf("\n"); - d_printf("\n", _("Stop All")); - d_printf("\n", _("Restart All")); + printf("\n", _("Stop All")); + printf("\n", _("Restart All")); } else if (nr_running == 0) { /* start all */ - d_printf("\n"); - d_printf("\n", _("Start All")); + printf("\n", _("Start All")); } - + printf("\n"); } - d_printf("\n"); -#endif - - d_printf("
%s%s
%s%s
%s%s
%s%s
%s%s
%s%s
%s%s
%s%s
\n"); + printf("\n"); fflush(stdout); - d_printf("

%s

\n", _("Active Connections")); - d_printf("\n"); - d_printf("\n", _("PID"), _("Client"), _("IP address"), _("Date")); + printf("

%s

\n", _("Active Connections")); + printf("
%s%s%s%s
\n"); + printf("\n", _("PID"), _("Client"), _("IP address"), _("Date")); if (geteuid() == 0) { - d_printf("\n", _("Kill")); + printf("\n", _("Kill")); } - d_printf("\n"); + printf("\n"); - if (tdb) tdb_traverse(tdb, traverse_fn2, NULL); + connections_forall_read(traverse_fn2, NULL); - d_printf("
%s%s%s%s%s%s

\n"); + printf("

\n"); - d_printf("

%s

\n", _("Active Shares")); - d_printf("\n"); - d_printf("\n\n", + printf("

%s

\n", _("Active Shares")); + printf("
%s%s%s%s%s%s
\n"); + printf("\n\n", _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date")); - if (tdb) tdb_traverse(tdb, traverse_fn3, NULL); + connections_forall_read(traverse_fn3, NULL); - d_printf("
%s%s%s%s%s%s

\n"); + printf("

\n"); - d_printf("

%s

\n", _("Open Files")); - d_printf("\n"); - d_printf("\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date")); + printf("

%s

\n", _("Open Files")); + printf("
%s%s%s%s%s%s
\n"); + printf("\n", + _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("Share"), _("File"), _("Date")); - locking_init(1); - share_mode_forall(print_share_mode); + locking_init_readonly(); + share_mode_forall(print_share_mode, NULL); locking_end(); - d_printf("
%s%s%s%s%s%s%s%s
\n"); - - if (tdb) tdb_close(tdb); + printf("\n"); - d_printf("
\n"); - d_printf("\n"); + printf("
\n", _("Show Client in col 1")); + printf("\n", _("Show PID in col 1")); - d_printf("
\n"); + 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 */ - d_printf("\n"); + printf("//-->\n\n"); } + TALLOC_FREE(ctx); }