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.
25 static char *tstring(time_t t)
28 pstrcpy(buf, asctime(LocalTime(&t)));
29 string_sub(buf," "," ");
33 static void print_share_mode(share_mode_entry *e, char *fname)
35 printf("<tr><td>%d</td>",e->pid);
37 switch ((e->share_mode>>4)&0xF) {
38 case DENY_NONE: printf("DENY_NONE"); break;
39 case DENY_ALL: printf("DENY_ALL "); break;
40 case DENY_DOS: printf("DENY_DOS "); break;
41 case DENY_READ: printf("DENY_READ "); break;
42 case DENY_WRITE:printf("DENY_WRITE "); break;
47 switch (e->share_mode&0xF) {
48 case 0: printf("RDONLY "); break;
49 case 1: printf("WRONLY "); break;
50 case 2: printf("RDWR "); break;
56 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
57 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
58 printf("EXCLUSIVE+BATCH ");
59 else if (e->op_type & EXCLUSIVE_OPLOCK)
61 else if (e->op_type & BATCH_OPLOCK)
67 printf("<td>%s</td><td>%s</td></tr>\n",
68 fname,tstring(e->time.tv_sec));
72 /* show the current server status */
73 void status_page(void)
75 struct connect_record crec;
80 int refresh_interval=30;
82 if (cgi_variable("smbd_start")) {
86 if (cgi_variable("smbd_stop")) {
90 if (cgi_variable("nmbd_start")) {
94 if (cgi_variable("nmbd_stop")) {
98 if (cgi_variable("autorefresh")) {
100 } else if (cgi_variable("norefresh")) {
102 } else if (cgi_variable("refresh")) {
106 if ((v=cgi_variable("refresh_interval"))) {
107 refresh_interval = atoi(v);
110 pstrcpy(fname,lp_lockdir());
111 standard_sub_basic(fname);
112 trim_string(fname,"","/");
113 strcat(fname,"/STATUS..LCK");
116 f = fopen(fname,"r");
119 if (fread(&crec,sizeof(crec),1,f) != 1) break;
120 if (crec.magic == 0x280267 && crec.cnum == -1 &&
121 process_exists(crec.pid)) {
123 sprintf(buf,"kill_%d", crec.pid);
124 if (cgi_variable(buf)) {
132 printf("<H2>Server Status</H2>\n");
134 printf("<FORM method=post>\n");
137 printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
138 printf("<br>Refresh Interval: ");
139 printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
142 printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
143 printf("<br>Refresh Interval: %d\n", refresh_interval);
144 printf("<input type=hidden name=refresh value=1>\n");
145 /* this little JavaScript allows for automatic refresh
146 of the page. There are other methods but this seems
147 to be the best alternative */
148 printf("<script language=\"JavaScript\">\n");
149 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
152 refresh_interval*1000);
153 printf("//-->\n</script>\n");
158 f = fopen(fname,"r");
160 printf("Couldn't open status file %s\n",fname);
162 printf("You need to have status=yes in your smb config file\n");
169 printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
172 if (smbd_running()) {
173 printf("<tr><td>smbd:</td><td>running</td><td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td></tr>\n");
175 printf("<tr><td>smbd:</td><td>not running</td><td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td></tr>\n");
179 if (nmbd_running()) {
180 printf("<tr><td>nmbd:</td><td>running</td><td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td></tr>\n");
182 printf("<tr><td>nmbd:</td><td>not running</td><td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td></tr>\n");
185 printf("</table>\n");
190 printf("<b>NOTE: You are not logged in as root and won't be able to start/stop the server</b><p>\n");
192 printf("<p><h3>Active Connections</h3>\n");
193 printf("<table border=1>\n");
194 printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th><th>Kill</th></tr>\n");
197 if (fread(&crec,sizeof(crec),1,f) != 1)
199 if (crec.magic == 0x280267 &&
201 process_exists(crec.pid)) {
202 printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td><input type=submit value=\"X\" name=\"kill_%d\"></td></tr>\n",
204 crec.machine,crec.addr,
210 printf("</table><p>\n");
212 fseek(f, 0, SEEK_SET);
214 printf("<p><h3>Active Shares</h3>\n");
215 printf("<table border=1>\n");
216 printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
219 if (fread(&crec,sizeof(crec),1,f) != 1)
221 if (crec.cnum == -1) continue;
222 if (crec.magic == 0x280267 && process_exists(crec.pid)) {
223 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
224 crec.name,uidtoname(crec.uid),
225 gidtoname(crec.gid),crec.pid,
227 tstring(crec.start));
231 printf("</table><p>\n");
233 printf("<h3>Open Files</h3>\n");
234 printf("<table border=1>\n");
235 printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
238 share_mode_forall(print_share_mode);
240 printf("</table>\n");