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 = SMB_MALLOC_P(PIDMAP)) == NULL) {
65 /* XXX need error message for this?
66 if malloc fails, PID is always shown */
71 newmap->machine = SMB_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, "%lu", (unsigned long)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)
111 int deny_mode = map_share_mode_to_deny_mode(e->share_access,
114 printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
116 switch ((deny_mode>>4)&0xF) {
117 case DENY_NONE: printf("DENY_NONE"); break;
118 case DENY_ALL: printf("DENY_ALL "); break;
119 case DENY_DOS: printf("DENY_DOS "); break;
120 case DENY_FCB: printf("DENY_FCB "); break;
121 case DENY_READ: printf("DENY_READ "); break;
122 case DENY_WRITE:printf("DENY_WRITE "); break;
127 if (e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA)) {
128 printf("%s", _("RDWR "));
129 } else if (e->access_mask & FILE_WRITE_DATA) {
130 printf("%s", _("WRONLY "));
132 printf("%s", _("RDONLY "));
138 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
139 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
140 printf("EXCLUSIVE+BATCH ");
141 else if (e->op_type & EXCLUSIVE_OPLOCK)
142 printf("EXCLUSIVE ");
143 else if (e->op_type & BATCH_OPLOCK)
145 else if (e->op_type & LEVEL_II_OPLOCK)
151 push_utf8_allocate(&utf8_fname, fname);
152 printf("<td>%s</td><td>%s</td></tr>\n",
153 utf8_fname,tstring(e->time.tv_sec));
154 SAFE_FREE(utf8_fname);
158 /* kill off any connections chosen by the user */
159 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
161 struct connections_data crec;
163 if (dbuf.dsize != sizeof(crec))
166 memcpy(&crec, dbuf.dptr, sizeof(crec));
168 if (crec.cnum == -1 && process_exists(crec.pid)) {
170 slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid);
171 if (cgi_variable(buf)) {
179 /* traversal fn for showing machine connections */
180 static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
182 struct connections_data crec;
184 if (dbuf.dsize != sizeof(crec))
187 memcpy(&crec, dbuf.dptr, sizeof(crec));
189 if (crec.cnum == -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid))
192 addPid2Machine (crec.pid, crec.machine);
194 printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
196 crec.machine,crec.addr,
197 tstring(crec.start));
198 if (geteuid() == 0) {
199 printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
207 /* traversal fn for showing share connections */
208 static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
210 struct connections_data crec;
212 if (dbuf.dsize != sizeof(crec))
215 memcpy(&crec, dbuf.dptr, sizeof(crec));
217 if (crec.cnum == -1 || !process_exists(crec.pid))
220 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
221 crec.name,uidtoname(crec.uid),
222 gidtoname(crec.gid),(int)crec.pid,
224 tstring(crec.start));
229 /* show the current server status */
230 void status_page(void)
234 int refresh_interval=30;
239 smbd_pid = pidfile_pid("smbd");
241 if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
247 if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
252 if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
257 if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
262 if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
267 if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
273 if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
279 if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
284 if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
289 /* wait for daemons to start/stop */
293 if (cgi_variable("autorefresh")) {
295 } else if (cgi_variable("norefresh")) {
297 } else if (cgi_variable("refresh")) {
301 if ((v=cgi_variable("refresh_interval"))) {
302 refresh_interval = atoi(v);
305 if (cgi_variable("show_client_in_col_1")) {
309 if (cgi_variable("show_pid_in_col_1")) {
313 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
314 if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
318 printf("<H2>%s</H2>\n", _("Server Status"));
320 printf("<FORM method=post>\n");
323 printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh"));
324 printf("<br>%s", _("Refresh Interval: "));
325 printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n",
328 printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing"));
329 printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval);
330 printf("<input type=hidden name=\"refresh\" value=\"1\">\n");
336 /* open failure either means no connections have been
343 printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING);
346 printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
347 if (geteuid() == 0) {
348 if (smbd_running()) {
350 printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd"));
352 printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd"));
354 printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd"));
359 printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running"));
360 if (geteuid() == 0) {
361 if (nmbd_running()) {
363 printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd"));
365 printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd"));
367 printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd"));
373 printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
374 if (geteuid() == 0) {
375 if (winbindd_running()) {
377 printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
379 printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
381 printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
386 if (geteuid() == 0) {
387 printf("<tr><td></td><td></td>\n");
388 if (nr_running >= 1) {
389 /* stop, restart all */
390 printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All"));
391 printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All"));
393 else if (nr_running == 0) {
395 printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All"));
399 printf("</table>\n");
402 printf("<p><h3>%s</h3>\n", _("Active Connections"));
403 printf("<table border=1>\n");
404 printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date"));
405 if (geteuid() == 0) {
406 printf("<th>%s</th>\n", _("Kill"));
410 if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);
412 printf("</table><p>\n");
414 printf("<p><h3>%s</h3>\n", _("Active Shares"));
415 printf("<table border=1>\n");
416 printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
417 _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
419 if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);
421 printf("</table><p>\n");
423 printf("<h3>%s</h3>\n", _("Open Files"));
424 printf("<table border=1>\n");
425 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"));
428 share_mode_forall(print_share_mode);
430 printf("</table>\n");
432 if (tdb) tdb_close(tdb);
434 printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1"));
435 printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1"));
440 /* this little JavaScript allows for automatic refresh
441 of the page. There are other methods but this seems
442 to be the best alternative */
443 printf("<script language=\"JavaScript\">\n");
444 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
447 refresh_interval*1000);
448 printf("//-->\n</script>\n");