1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
Unix SMB/Netbios implementation.
Version 1.9.
web status page
Copyright (C) Andrew Tridgell 1997-1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
static char *tstring(time_t t)
{
static pstring buf;
pstrcpy(buf, asctime(LocalTime(&t)));
all_string_sub(buf," "," ",sizeof(buf));
return buf;
}
static void print_share_mode(share_mode_entry *e, char *fname)
{
printf("<tr><td>%d</td>",(int)e->pid);
printf("<td>");
switch ((e->share_mode>>4)&0xF) {
case DENY_NONE: printf("DENY_NONE"); break;
case DENY_ALL: printf("DENY_ALL "); break;
case DENY_DOS: printf("DENY_DOS "); break;
case DENY_READ: printf("DENY_READ "); break;
case DENY_WRITE:printf("DENY_WRITE "); break;
}
printf("</td>");
printf("<td>");
switch (e->share_mode&0xF) {
case 0: printf("RDONLY "); break;
case 1: printf("WRONLY "); break;
case 2: printf("RDWR "); break;
}
printf("</td>");
printf("<td>");
if((e->op_type &
(EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
(EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
printf("EXCLUSIVE+BATCH ");
else if (e->op_type & EXCLUSIVE_OPLOCK)
printf("EXCLUSIVE ");
else if (e->op_type & BATCH_OPLOCK)
printf("BATCH ");
else if (e->op_type & LEVEL_II_OPLOCK)
printf("LEVEL_II ");
else
printf("NONE ");
printf("</td>");
printf("<td>%s</td><td>%s</td></tr>\n",
dos_to_unix(fname,False),tstring(e->time.tv_sec));
}
/* show the current server status */
void status_page(void)
{
struct connect_record crec;
pstring fname;
FILE *f;
char *v;
int autorefresh=0;
int refresh_interval=30;
if (cgi_variable("smbd_restart")) {
if (smbd_running())
stop_smbd();
start_smbd();
}
if (cgi_variable("smbd_start")) {
start_smbd();
}
if (cgi_variable("smbd_stop")) {
stop_smbd();
}
if (cgi_variable("nmbd_restart")) {
if (nmbd_running())
stop_nmbd();
start_nmbd();
}
if (cgi_variable("nmbd_start")) {
start_nmbd();
}
if (cgi_variable("nmbd_stop")) {
stop_nmbd();
}
if (cgi_variable("autorefresh")) {
autorefresh = 1;
} else if (cgi_variable("norefresh")) {
autorefresh = 0;
} else if (cgi_variable("refresh")) {
autorefresh = 1;
}
if ((v=cgi_variable("refresh_interval"))) {
refresh_interval = atoi(v);
}
pstrcpy(fname,lp_lockdir());
standard_sub_basic(fname);
trim_string(fname,"","/");
pstrcat(fname,"/STATUS..LCK");
f = sys_fopen(fname,"r");
if (f) {
while (!feof(f)) {
if (fread(&crec,sizeof(crec),1,f) != 1) break;
if (crec.magic == 0x280267 && crec.cnum == -1 &&
process_exists(crec.pid)) {
char buf[30];
slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid);
if (cgi_variable(buf)) {
kill_pid(crec.pid);
}
}
}
fclose(f);
}
printf("<H2>Server Status</H2>\n");
printf("<FORM method=post>\n");
if (!autorefresh) {
printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
printf("<br>Refresh Interval: ");
printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
refresh_interval);
} else {
printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
printf("<br>Refresh Interval: %d\n", refresh_interval);
printf("<input type=hidden name=refresh value=1>\n");
}
printf("<p>\n");
f = sys_fopen(fname,"r");
if (!f) {
/* open failure either means no connections have been
made or status=no */
if (!lp_status(-1))
printf("You need to have status=yes in your smb config file\n");
}
printf("<table>\n");
printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
fflush(stdout);
printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not ");
if (geteuid() == 0) {
if (smbd_running()) {
printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n");
} else {
printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n");
}
printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n");
}
printf("</tr>\n");
fflush(stdout);
printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not ");
if (geteuid() == 0) {
if (nmbd_running()) {
printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n");
} else {
printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n");
}
printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n");
}
printf("</tr>\n");
printf("</table>\n");
fflush(stdout);
printf("<p><h3>Active Connections</h3>\n");
printf("<table border=1>\n");
printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th>\n");
if (geteuid() == 0) {
printf("<th>Kill</th>\n");
}
printf("</tr>\n");
while (f && !feof(f)) {
if (fread(&crec,sizeof(crec),1,f) != 1)
break;
if (crec.magic == 0x280267 &&
crec.cnum == -1 &&
process_exists(crec.pid)) {
printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
(int)crec.pid,
crec.machine,crec.addr,
tstring(crec.start));
if (geteuid() == 0) {
printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
(int)crec.pid);
}
printf("</tr>\n");
}
}
printf("</table><p>\n");
if (f) fseek(f, 0, SEEK_SET);
printf("<p><h3>Active Shares</h3>\n");
printf("<table border=1>\n");
printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
while (f && !feof(f)) {
if (fread(&crec,sizeof(crec),1,f) != 1)
break;
if (crec.cnum == -1) continue;
if (crec.magic == 0x280267 && process_exists(crec.pid)) {
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
crec.name,uidtoname(crec.uid),
gidtoname(crec.gid),(int)crec.pid,
crec.machine,
tstring(crec.start));
}
}
printf("</table><p>\n");
printf("<h3>Open Files</h3>\n");
printf("<table border=1>\n");
printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
locking_init(1);
share_mode_forall(print_share_mode);
locking_end();
printf("</table>\n");
if (f) fclose(f);
printf("</FORM>\n");
if (autorefresh) {
/* this little JavaScript allows for automatic refresh
of the page. There are other methods but this seems
to be the best alternative */
printf("<script language=\"JavaScript\">\n");
printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
cgi_baseurl(),
refresh_interval,
refresh_interval*1000);
printf("//-->\n</script>\n");
}
}
|