/* Unix SMB/Netbios implementation. Version 2.2. 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" static pid_t smbd_pid; static char *tstring(time_t t) { static pstring buf; pstrcpy(buf, asctime(LocalTime(&t))); all_string_sub(buf," "," ",sizeof(buf)); return buf; } static void print_share_mode(share_mode_entry *e, char *fname) { printf("%d",(int)e->pid); printf(""); switch ((e->share_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_READ: printf("DENY_READ "); break; case DENY_WRITE:printf("DENY_WRITE "); break; } printf(""); printf(""); switch (e->share_mode&0xF) { case 0: printf("RDONLY "); break; case 1: printf("WRONLY "); break; case 2: printf("RDWR "); break; } printf(""); printf(""); if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); else if (e->op_type & LEVEL_II_OPLOCK) printf("LEVEL_II "); else printf("NONE "); printf(""); printf("%s%s\n", fname,tstring(e->time.tv_sec)); } /* kill off any connections chosen by the user */ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) { 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)) { char buf[30]; slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); if (cgi_variable(buf)) { kill_pid(crec.pid); } } return 0; } /* traversal fn for showing machine connections */ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) { 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)) return 0; printf("%d%s%s%s\n", (int)crec.pid, crec.machine,crec.addr, tstring(crec.start)); if (geteuid() == 0) { printf("\n", (int)crec.pid); } 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) { 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)) return 0; printf("%s%s%s%d%s%s\n", crec.name,uidtoname(crec.uid), gidtoname(crec.gid),(int)crec.pid, crec.machine, tstring(crec.start)); return 0; } /* show the current server status */ void status_page(void) { char *v; int autorefresh=0; int refresh_interval=30; TDB_CONTEXT *tdb; smbd_pid = pidfile_pid("smbd"); if (cgi_variable("smbd_restart")) { stop_smbd(); start_smbd(); } if (cgi_variable("smbd_start")) { start_smbd(); } if (cgi_variable("smbd_stop")) { stop_smbd(); } if (cgi_variable("nmbd_restart")) { stop_nmbd(); start_nmbd(); } if (cgi_variable("nmbd_start")) { start_nmbd(); } if (cgi_variable("nmbd_stop")) { stop_nmbd(); } 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); } tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0); if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); printf("

Server Status

\n"); printf("
\n"); if (!autorefresh) { printf("\n"); printf("
Refresh Interval: "); printf("\n", refresh_interval); } else { printf("\n"); printf("
Refresh Interval: %d\n", refresh_interval); printf("\n"); } printf("

\n"); if (!tdb) { /* open failure either means no connections have been made or status=no */ if (!lp_status(-1)) printf("You need to have status=yes in your smb config file\n"); } printf("\n"); printf("",VERSION); fflush(stdout); printf("\n",smbd_running()?"":"not "); if (geteuid() == 0) { if (smbd_running()) { printf("\n"); } else { printf("\n"); } printf("\n"); } printf("\n"); fflush(stdout); printf("\n",nmbd_running()?"":"not "); if (geteuid() == 0) { if (nmbd_running()) { printf("\n"); } else { printf("\n"); } printf("\n"); } printf("\n"); printf("
version:%s
smbd:%srunning
nmbd:%srunning
\n"); fflush(stdout); printf("

Active Connections

\n"); printf("\n"); printf("\n"); if (geteuid() == 0) { printf("\n"); } printf("\n"); if (tdb) tdb_traverse(tdb, traverse_fn2, NULL); printf("
PIDClientIP addressDateKill

\n"); printf("

Active Shares

\n"); printf("\n"); printf("\n\n"); if (tdb) tdb_traverse(tdb, traverse_fn3, NULL); printf("
ShareUserGroupPIDClientDate

\n"); printf("

Open Files

\n"); printf("\n"); printf("\n"); locking_init(1); share_mode_forall(print_share_mode); locking_end(); printf("
PIDSharingR/WOplockFileDate
\n"); if (tdb) tdb_close(tdb); 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"); } }