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 #define PIDMAP struct PidMap
32 static PIDMAP
*pidmap
;
33 static int PID_or_Machine
; /* 0 = show PID, else show Machine name */
35 static pid_t smbd_pid
;
37 /* from 2nd call on, remove old list */
38 static void initPid2Machine (void)
40 /* show machine name rather PID on table "Open Files"? */
44 for (p
= pidmap
; p
!= NULL
; ) {
45 DLIST_REMOVE(pidmap
, p
);
46 SAFE_FREE(p
->machine
);
54 /* add new PID <-> Machine name mapping */
55 static void addPid2Machine (pid_t pid
, char *machine
)
57 /* show machine name rather PID on table "Open Files"? */
61 if ((newmap
= (PIDMAP
*) malloc (sizeof (PIDMAP
))) == NULL
) {
62 /* XXX need error message for this?
63 if malloc fails, PID is always shown */
68 newmap
->machine
= strdup (machine
);
70 DLIST_ADD(pidmap
, newmap
);
74 /* lookup PID <-> Machine name mapping */
75 static char *mapPid2Machine (pid_t pid
)
77 static char pidbuf
[64];
80 /* show machine name rather PID on table "Open Files"? */
82 for (map
= pidmap
; map
!= NULL
; map
= map
->next
) {
83 if (pid
== map
->pid
) {
84 if (map
->machine
== NULL
) /* no machine name */
92 /* PID not in list or machine name NULL? return pid as string */
93 snprintf (pidbuf
, sizeof (pidbuf
) - 1, "%d", pid
);
97 static char *tstring(time_t t
)
100 pstrcpy(buf
, asctime(LocalTime(&t
)));
101 all_string_sub(buf
," "," ",sizeof(buf
));
105 static void print_share_mode(share_mode_entry
*e
, char *fname
)
107 printf("<tr><td>%s</td>", mapPid2Machine (e
->pid
));
109 switch ((e
->share_mode
>>4)&0xF) {
110 case DENY_NONE
: printf("DENY_NONE"); break;
111 case DENY_ALL
: printf("DENY_ALL "); break;
112 case DENY_DOS
: printf("DENY_DOS "); break;
113 case DENY_READ
: printf("DENY_READ "); break;
114 case DENY_WRITE
:printf("DENY_WRITE "); break;
119 switch (e
->share_mode
&0xF) {
120 case 0: printf("RDONLY "); break;
121 case 1: printf("WRONLY "); break;
122 case 2: printf("RDWR "); break;
128 (EXCLUSIVE_OPLOCK
|BATCH_OPLOCK
)) ==
129 (EXCLUSIVE_OPLOCK
|BATCH_OPLOCK
))
130 printf("EXCLUSIVE+BATCH ");
131 else if (e
->op_type
& EXCLUSIVE_OPLOCK
)
132 printf("EXCLUSIVE ");
133 else if (e
->op_type
& BATCH_OPLOCK
)
135 else if (e
->op_type
& LEVEL_II_OPLOCK
)
141 printf("<td>%s</td><td>%s</td></tr>\n",
142 dos_to_unix_static(fname
),tstring(e
->time
.tv_sec
));
146 /* kill off any connections chosen by the user */
147 static int traverse_fn1(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
, void* state
)
149 struct connections_data crec
;
151 if (dbuf
.dsize
!= sizeof(crec
))
154 memcpy(&crec
, dbuf
.dptr
, sizeof(crec
));
156 if (crec
.cnum
== -1 && process_exists(crec
.pid
)) {
158 slprintf(buf
,sizeof(buf
)-1,"kill_%d", (int)crec
.pid
);
159 if (cgi_variable(buf
)) {
166 /* traversal fn for showing machine connections */
167 static int traverse_fn2(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
, void* state
)
169 struct connections_data crec
;
171 if (dbuf
.dsize
!= sizeof(crec
))
174 memcpy(&crec
, dbuf
.dptr
, sizeof(crec
));
176 if (crec
.cnum
!= -1 || !process_exists(crec
.pid
) || (crec
.pid
== smbd_pid
))
179 addPid2Machine (crec
.pid
, crec
.machine
);
181 printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
183 crec
.machine
,crec
.addr
,
184 tstring(crec
.start
));
185 if (geteuid() == 0) {
186 printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
194 /* traversal fn for showing share connections */
195 static int traverse_fn3(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
, void* state
)
197 struct connections_data crec
;
199 if (dbuf
.dsize
!= sizeof(crec
))
202 memcpy(&crec
, dbuf
.dptr
, sizeof(crec
));
204 if (crec
.cnum
== -1 || !process_exists(crec
.pid
))
207 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
208 crec
.name
,uidtoname(crec
.uid
),
209 gidtoname(crec
.gid
),(int)crec
.pid
,
211 tstring(crec
.start
));
216 /* show the current server status */
217 void status_page(void)
221 int refresh_interval
=30;
224 smbd_pid
= pidfile_pid("smbd");
226 if (cgi_variable("smbd_restart")) {
231 if (cgi_variable("smbd_start")) {
235 if (cgi_variable("smbd_stop")) {
239 if (cgi_variable("nmbd_restart")) {
243 if (cgi_variable("nmbd_start")) {
247 if (cgi_variable("nmbd_stop")) {
251 if (cgi_variable("autorefresh")) {
253 } else if (cgi_variable("norefresh")) {
255 } else if (cgi_variable("refresh")) {
259 if ((v
=cgi_variable("refresh_interval"))) {
260 refresh_interval
= atoi(v
);
263 if (cgi_variable("show_client_in_col_1")) {
267 tdb
= tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT
, O_RDONLY
, 0);
268 if (tdb
) tdb_traverse(tdb
, traverse_fn1
, NULL
);
272 printf("<H2>Server Status</H2>\n");
274 printf("<FORM method=post>\n");
277 printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
278 printf("<br>Refresh Interval: ");
279 printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
282 printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
283 printf("<br>Refresh Interval: %d\n", refresh_interval
);
284 printf("<input type=hidden name=refresh value=1>\n");
290 /* open failure either means no connections have been
293 printf("You need to have status=yes in your smb config file\n");
299 printf("<tr><td>version:</td><td>%s</td></tr>",VERSION
);
302 printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not ");
303 if (geteuid() == 0) {
304 if (smbd_running()) {
305 printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n");
307 printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n");
309 printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n");
314 printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not ");
315 if (geteuid() == 0) {
316 if (nmbd_running()) {
317 printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n");
319 printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n");
321 printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n");
325 printf("</table>\n");
328 printf("<p><h3>Active Connections</h3>\n");
329 printf("<table border=1>\n");
330 printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th>\n");
331 if (geteuid() == 0) {
332 printf("<th>Kill</th>\n");
336 if (tdb
) tdb_traverse(tdb
, traverse_fn2
, NULL
);
338 printf("</table><p>\n");
340 printf("<p><h3>Active Shares</h3>\n");
341 printf("<table border=1>\n");
342 printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
344 if (tdb
) tdb_traverse(tdb
, traverse_fn3
, NULL
);
346 printf("</table><p>\n");
348 printf("<h3>Open Files</h3>\n");
349 printf("<table border=1>\n");
350 printf("<tr><th>%s</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n", PID_or_Machine
? "Client" : "PID");
353 share_mode_forall(print_share_mode
);
355 printf("</table>\n");
357 if (tdb
) tdb_close(tdb
);
359 printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"Show Client in col 1\">\n");
360 printf("<input type=submit name=\"show_pid_in_col_1\" value=\"Show PID in col 1\">\n");
365 /* this little JavaScript allows for automatic refresh
366 of the page. There are other methods but this seems
367 to be the best alternative */
368 printf("<script language=\"JavaScript\">\n");
369 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
372 refresh_interval
*1000);
373 printf("//-->\n</script>\n");