2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "../web/swat_proto.h"
24 #define PIDMAP struct PidMap
26 /* how long to wait for start/stops to take effect */
35 static PIDMAP *pidmap;
36 static int PID_or_Machine; /* 0 = show PID, else show Machine name */
38 static pid_t smbd_pid;
40 /* from 2nd call on, remove old list */
41 static void initPid2Machine (void)
43 /* show machine name rather PID on table "Open Files"? */
47 for (p = pidmap; p != NULL; ) {
48 DLIST_REMOVE(pidmap, p);
49 SAFE_FREE(p->machine);
57 /* add new PID <-> Machine name mapping */
58 static void addPid2Machine (pid_t pid, char *machine)
60 /* show machine name rather PID on table "Open Files"? */
64 if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) {
65 /* XXX need error message for this?
66 if malloc fails, PID is always shown */
71 newmap->machine = strdup (machine);
73 DLIST_ADD(pidmap, newmap);
77 /* lookup PID <-> Machine name mapping */
78 static char *mapPid2Machine (pid_t pid)
80 static char pidbuf [64];
83 /* show machine name rather PID on table "Open Files"? */
85 for (map = pidmap; map != NULL; map = map->next) {
86 if (pid == map->pid) {
87 if (map->machine == NULL) /* no machine name */
95 /* PID not in list or machine name NULL? return pid as string */
96 snprintf (pidbuf, sizeof (pidbuf) - 1, "%d", pid);
100 static char *tstring(time_t t)
103 pstrcpy(buf, asctime(LocalTime(&t)));
104 all_string_sub(buf," "," ",sizeof(buf));
108 static void print_share_mode(share_mode_entry *e, char *fname)
110 d_printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
112 switch ((e->share_mode>>4)&0xF) {
113 case DENY_NONE: d_printf("DENY_NONE"); break;
114 case DENY_ALL: d_printf("DENY_ALL "); break;
115 case DENY_DOS: d_printf("DENY_DOS "); break;
116 case DENY_READ: d_printf("DENY_READ "); break;
117 case DENY_WRITE:d_printf("DENY_WRITE "); break;
122 switch (e->share_mode&0xF) {
123 case 0: d_printf("RDONLY "); break;
124 case 1: d_printf("WRONLY "); break;
125 case 2: d_printf("RDWR "); break;
131 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
132 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
133 d_printf("EXCLUSIVE+BATCH ");
134 else if (e->op_type & EXCLUSIVE_OPLOCK)
135 d_printf("EXCLUSIVE ");
136 else if (e->op_type & BATCH_OPLOCK)
138 else if (e->op_type & LEVEL_II_OPLOCK)
139 d_printf("LEVEL_II ");
144 d_printf("<td>%s</td><td>%s</td></tr>\n",
145 fname,tstring(e->time.tv_sec));
149 /* kill off any connections chosen by the user */
150 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
152 struct connections_data crec;
154 if (dbuf.dsize != sizeof(crec))
157 memcpy(&crec, dbuf.dptr, sizeof(crec));
159 if (crec.cnum == -1 && process_exists(crec.pid)) {
161 slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid);
162 if (cgi_variable(buf)) {
170 /* traversal fn for showing machine connections */
171 static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
173 struct connections_data crec;
175 if (dbuf.dsize != sizeof(crec))
178 memcpy(&crec, dbuf.dptr, sizeof(crec));
180 if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid))
183 addPid2Machine (crec.pid, crec.machine);
185 d_printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
187 crec.machine,crec.addr,
188 tstring(crec.start));
189 if (geteuid() == 0) {
190 d_printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
198 /* traversal fn for showing share connections */
199 static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
201 struct connections_data crec;
203 if (dbuf.dsize != sizeof(crec))
206 memcpy(&crec, dbuf.dptr, sizeof(crec));
208 if (crec.cnum == -1 || !process_exists(crec.pid))
211 d_printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
212 crec.name,uidtoname(crec.uid),
213 gidtoname(crec.gid),(int)crec.pid,
215 tstring(crec.start));
220 /* show the current server status */
221 void status_page(void)
225 int refresh_interval=30;
230 smbd_pid = pidfile_pid("smbd");
232 if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
238 if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
243 if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
248 if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
253 if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
258 if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
264 if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
270 if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
275 if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
280 /* wait for daemons to start/stop */
284 if (cgi_variable("autorefresh")) {
286 } else if (cgi_variable("norefresh")) {
288 } else if (cgi_variable("refresh")) {
292 if ((v=cgi_variable("refresh_interval"))) {
293 refresh_interval = atoi(v);
296 if (cgi_variable("show_client_in_col_1")) {
300 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
301 if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
305 d_printf("<H2>%s</H2>\n", _("Server Status"));
307 d_printf("<FORM method=post>\n");
310 d_printf("<input type=submit value=\"%s\" name=autorefresh>\n", _("Auto Refresh"));
311 d_printf("<br>%s", _("Refresh Interval: "));
312 d_printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
315 d_printf("<input type=submit value=\"%s\" name=norefresh>\n", _("Stop Refreshing"));
316 d_printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval);
317 d_printf("<input type=hidden name=refresh value=1>\n");
323 /* open failure either means no connections have been
328 d_printf("<table>\n");
330 d_printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), VERSION);
333 d_printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
334 if (geteuid() == 0) {
335 if (smbd_running()) {
337 d_printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd"));
339 d_printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd"));
341 d_printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd"));
346 d_printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running"));
347 if (geteuid() == 0) {
348 if (nmbd_running()) {
350 d_printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd"));
352 d_printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd"));
354 d_printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd"));
360 d_printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
361 if (geteuid() == 0) {
362 if (winbindd_running()) {
364 d_printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
366 d_printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
368 d_printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
373 if (geteuid() == 0) {
374 d_printf("<tr><td></td><td></td>\n");
375 if (nr_running >= 1) {
376 /* stop, restart all */
377 d_printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All"));
378 d_printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All"));
380 else if (nr_running == 0) {
382 d_printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All"));
386 d_printf("</table>\n");
389 d_printf("<p><h3>%s</h3>\n", _("Active Connections"));
390 d_printf("<table border=1>\n");
391 d_printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date"));
392 if (geteuid() == 0) {
393 d_printf("<th>%s</th>\n", _("Kill"));
397 if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);
399 d_printf("</table><p>\n");
401 d_printf("<p><h3>%s</h3>\n", _("Active Shares"));
402 d_printf("<table border=1>\n");
403 d_printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
404 _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
406 if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);
408 d_printf("</table><p>\n");
410 d_printf("<h3>%s</h3>\n", _("Open Files"));
411 d_printf("<table border=1>\n");
412 d_printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));
415 share_mode_forall(print_share_mode);
417 d_printf("</table>\n");
419 if (tdb) tdb_close(tdb);
421 d_printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"Show Client in col 1\">\n");
422 d_printf("<input type=submit name=\"show_pid_in_col_1\" value=\"Show PID in col 1\">\n");
424 d_printf("</FORM>\n");
427 /* this little JavaScript allows for automatic refresh
428 of the page. There are other methods but this seems
429 to be the best alternative */
430 d_printf("<script language=\"JavaScript\">\n");
431 d_printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
434 refresh_interval*1000);
435 d_printf("//-->\n</script>\n");