2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1997-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static pid_t smbd_pid;
26 static char *tstring(time_t t)
29 pstrcpy(buf, asctime(LocalTime(&t)));
30 all_string_sub(buf," "," ",sizeof(buf));
34 static void print_share_mode(share_mode_entry *e, char *fname)
36 printf("<tr><td>%d</td>",(int)e->pid);
38 switch ((e->share_mode>>4)&0xF) {
39 case DENY_NONE: printf("DENY_NONE"); break;
40 case DENY_ALL: printf("DENY_ALL "); break;
41 case DENY_DOS: printf("DENY_DOS "); break;
42 case DENY_READ: printf("DENY_READ "); break;
43 case DENY_WRITE:printf("DENY_WRITE "); break;
48 switch (e->share_mode&0xF) {
49 case 0: printf("RDONLY "); break;
50 case 1: printf("WRONLY "); break;
51 case 2: printf("RDWR "); break;
57 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
58 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
59 printf("EXCLUSIVE+BATCH ");
60 else if (e->op_type & EXCLUSIVE_OPLOCK)
62 else if (e->op_type & BATCH_OPLOCK)
64 else if (e->op_type & LEVEL_II_OPLOCK)
70 printf("<td>%s</td><td>%s</td></tr>\n",
71 fname,tstring(e->time.tv_sec));
75 /* kill off any connections chosen by the user */
76 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
78 struct connections_data crec;
80 if (dbuf.dsize != sizeof(crec))
83 memcpy(&crec, dbuf.dptr, sizeof(crec));
85 if (crec.cnum == -1 && process_exists(crec.pid)) {
87 slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid);
88 if (cgi_variable(buf)) {
95 /* traversal fn for showing machine connections */
96 static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
98 struct connections_data crec;
100 if (dbuf.dsize != sizeof(crec))
103 memcpy(&crec, dbuf.dptr, sizeof(crec));
105 if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid))
108 printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
110 crec.machine,crec.addr,
111 tstring(crec.start));
112 if (geteuid() == 0) {
113 printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
121 /* traversal fn for showing share connections */
122 static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
124 struct connections_data crec;
126 if (dbuf.dsize != sizeof(crec))
129 memcpy(&crec, dbuf.dptr, sizeof(crec));
131 if (crec.cnum == -1 || !process_exists(crec.pid))
134 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
135 crec.name,uidtoname(crec.uid),
136 gidtoname(crec.gid),(int)crec.pid,
138 tstring(crec.start));
143 /* show the current server status */
144 void status_page(void)
148 int refresh_interval=30;
151 smbd_pid = pidfile_pid("smbd");
153 if (cgi_variable("smbd_restart")) {
158 if (cgi_variable("smbd_start")) {
162 if (cgi_variable("smbd_stop")) {
166 if (cgi_variable("nmbd_restart")) {
170 if (cgi_variable("nmbd_start")) {
174 if (cgi_variable("nmbd_stop")) {
178 if (cgi_variable("autorefresh")) {
180 } else if (cgi_variable("norefresh")) {
182 } else if (cgi_variable("refresh")) {
186 if ((v=cgi_variable("refresh_interval"))) {
187 refresh_interval = atoi(v);
190 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
191 if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
193 printf("<H2>Server Status</H2>\n");
195 printf("<FORM method=post>\n");
198 printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
199 printf("<br>Refresh Interval: ");
200 printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
203 printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
204 printf("<br>Refresh Interval: %d\n", refresh_interval);
205 printf("<input type=hidden name=refresh value=1>\n");
211 /* open failure either means no connections have been
218 printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
221 printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not ");
222 if (geteuid() == 0) {
223 if (smbd_running()) {
224 printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n");
226 printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n");
228 printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n");
233 printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not ");
234 if (geteuid() == 0) {
235 if (nmbd_running()) {
236 printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n");
238 printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n");
240 printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n");
244 printf("</table>\n");
247 printf("<p><h3>Active Connections</h3>\n");
248 printf("<table border=1>\n");
249 printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th>\n");
250 if (geteuid() == 0) {
251 printf("<th>Kill</th>\n");
255 if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);
257 printf("</table><p>\n");
259 printf("<p><h3>Active Shares</h3>\n");
260 printf("<table border=1>\n");
261 printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
263 if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);
265 printf("</table><p>\n");
267 printf("<h3>Open Files</h3>\n");
268 printf("<table border=1>\n");
269 printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
272 share_mode_forall(print_share_mode);
274 printf("</table>\n");
276 if (tdb) tdb_close(tdb);
281 /* this little JavaScript allows for automatic refresh
282 of the page. There are other methods but this seems
283 to be the best alternative */
284 printf("<script language=\"JavaScript\">\n");
285 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
288 refresh_interval*1000);
289 printf("//-->\n</script>\n");