1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | web status page
|
---|
4 | Copyright (C) Andrew Tridgell 1997-1998
|
---|
5 |
|
---|
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 3 of the License, or
|
---|
9 | (at your option) any later version.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "web/swat_proto.h"
|
---|
22 | #include "libcli/security/security.h"
|
---|
23 | #include "locking/proto.h"
|
---|
24 |
|
---|
25 | #define _(x) lang_msg_rotate(talloc_tos(),x)
|
---|
26 |
|
---|
27 | #define PIDMAP struct PidMap
|
---|
28 |
|
---|
29 | /* how long to wait for start/stops to take effect */
|
---|
30 | #define SLEEP_TIME 3
|
---|
31 |
|
---|
32 | PIDMAP {
|
---|
33 | PIDMAP *next, *prev;
|
---|
34 | struct server_id pid;
|
---|
35 | char *machine;
|
---|
36 | };
|
---|
37 |
|
---|
38 | static PIDMAP *pidmap;
|
---|
39 | static int PID_or_Machine; /* 0 = show PID, else show Machine name */
|
---|
40 |
|
---|
41 | static struct server_id smbd_pid;
|
---|
42 |
|
---|
43 | /* from 2nd call on, remove old list */
|
---|
44 | static void initPid2Machine (void)
|
---|
45 | {
|
---|
46 | /* show machine name rather PID on table "Open Files"? */
|
---|
47 | if (PID_or_Machine) {
|
---|
48 | PIDMAP *p, *next;
|
---|
49 |
|
---|
50 | for (p = pidmap; p != NULL; p = next) {
|
---|
51 | next = p->next;
|
---|
52 | DLIST_REMOVE(pidmap, p);
|
---|
53 | SAFE_FREE(p->machine);
|
---|
54 | SAFE_FREE(p);
|
---|
55 | }
|
---|
56 |
|
---|
57 | pidmap = NULL;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | /* add new PID <-> Machine name mapping */
|
---|
62 | static void addPid2Machine (struct server_id pid, const char *machine)
|
---|
63 | {
|
---|
64 | /* show machine name rather PID on table "Open Files"? */
|
---|
65 | if (PID_or_Machine) {
|
---|
66 | PIDMAP *newmap;
|
---|
67 |
|
---|
68 | if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
|
---|
69 | /* XXX need error message for this?
|
---|
70 | if malloc fails, PID is always shown */
|
---|
71 | return;
|
---|
72 | }
|
---|
73 |
|
---|
74 | newmap->pid = pid;
|
---|
75 | newmap->machine = SMB_STRDUP(machine);
|
---|
76 |
|
---|
77 | DLIST_ADD(pidmap, newmap);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* lookup PID <-> Machine name mapping */
|
---|
82 | static char *mapPid2Machine (struct server_id pid)
|
---|
83 | {
|
---|
84 | static char pidbuf [64];
|
---|
85 | PIDMAP *map;
|
---|
86 |
|
---|
87 | /* show machine name rather PID on table "Open Files"? */
|
---|
88 | if (PID_or_Machine) {
|
---|
89 | for (map = pidmap; map != NULL; map = map->next) {
|
---|
90 | if (procid_equal(&pid, &map->pid)) {
|
---|
91 | if (map->machine == NULL) /* no machine name */
|
---|
92 | break; /* show PID */
|
---|
93 |
|
---|
94 | return map->machine;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* PID not in list or machine name NULL? return pid as string */
|
---|
100 | snprintf (pidbuf, sizeof (pidbuf) - 1, "%s",
|
---|
101 | procid_str_static(&pid));
|
---|
102 | return pidbuf;
|
---|
103 | }
|
---|
104 |
|
---|
105 | static const char *tstring(TALLOC_CTX *ctx, time_t t)
|
---|
106 | {
|
---|
107 | char *buf;
|
---|
108 | buf = talloc_strdup(ctx, time_to_asc(t));
|
---|
109 | if (!buf) {
|
---|
110 | return "";
|
---|
111 | }
|
---|
112 | buf = talloc_all_string_sub(ctx,
|
---|
113 | buf,
|
---|
114 | " ",
|
---|
115 | " ");
|
---|
116 | if (!buf) {
|
---|
117 | return "";
|
---|
118 | }
|
---|
119 | return buf;
|
---|
120 | }
|
---|
121 |
|
---|
122 | static void print_share_mode(const struct share_mode_entry *e,
|
---|
123 | const char *sharepath,
|
---|
124 | const char *fname,
|
---|
125 | void *dummy)
|
---|
126 | {
|
---|
127 | char *utf8_fname;
|
---|
128 | char *utf8_sharepath;
|
---|
129 | int deny_mode;
|
---|
130 | size_t converted_size;
|
---|
131 |
|
---|
132 | if (!is_valid_share_mode_entry(e)) {
|
---|
133 | return;
|
---|
134 | }
|
---|
135 |
|
---|
136 | deny_mode = map_share_mode_to_deny_mode(e->share_access,
|
---|
137 | e->private_options);
|
---|
138 |
|
---|
139 | printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
|
---|
140 | printf("<td>%u</td>",(unsigned int)e->uid);
|
---|
141 | printf("<td>");
|
---|
142 | switch ((deny_mode>>4)&0xF) {
|
---|
143 | case DENY_NONE: printf("DENY_NONE"); break;
|
---|
144 | case DENY_ALL: printf("DENY_ALL "); break;
|
---|
145 | case DENY_DOS: printf("DENY_DOS "); break;
|
---|
146 | case DENY_FCB: printf("DENY_FCB "); break;
|
---|
147 | case DENY_READ: printf("DENY_READ "); break;
|
---|
148 | case DENY_WRITE:printf("DENY_WRITE "); break;
|
---|
149 | }
|
---|
150 | printf("</td>");
|
---|
151 |
|
---|
152 | printf("<td>");
|
---|
153 | if (e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA)) {
|
---|
154 | printf("%s", _("RDWR "));
|
---|
155 | } else if (e->access_mask & FILE_WRITE_DATA) {
|
---|
156 | printf("%s", _("WRONLY "));
|
---|
157 | } else {
|
---|
158 | printf("%s", _("RDONLY "));
|
---|
159 | }
|
---|
160 | printf("</td>");
|
---|
161 |
|
---|
162 | printf("<td>");
|
---|
163 | if((e->op_type &
|
---|
164 | (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
|
---|
165 | (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
|
---|
166 | printf("EXCLUSIVE+BATCH ");
|
---|
167 | else if (e->op_type & EXCLUSIVE_OPLOCK)
|
---|
168 | printf("EXCLUSIVE ");
|
---|
169 | else if (e->op_type & BATCH_OPLOCK)
|
---|
170 | printf("BATCH ");
|
---|
171 | else if (e->op_type & LEVEL_II_OPLOCK)
|
---|
172 | printf("LEVEL_II ");
|
---|
173 | else
|
---|
174 | printf("NONE ");
|
---|
175 | printf("</td>");
|
---|
176 |
|
---|
177 | push_utf8_talloc(talloc_tos(), &utf8_fname, fname, &converted_size);
|
---|
178 | push_utf8_talloc(talloc_tos(), &utf8_sharepath, sharepath,
|
---|
179 | &converted_size);
|
---|
180 | printf("<td>%s</td><td>%s</td><td>%s</td></tr>\n",
|
---|
181 | utf8_sharepath,utf8_fname,tstring(talloc_tos(),e->time.tv_sec));
|
---|
182 | TALLOC_FREE(utf8_fname);
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | /* kill off any connections chosen by the user */
|
---|
187 | static int traverse_fn1(const struct connections_key *key,
|
---|
188 | const struct connections_data *crec,
|
---|
189 | void *private_data)
|
---|
190 | {
|
---|
191 | if (crec->cnum == -1 && process_exists(crec->pid)) {
|
---|
192 | char buf[30];
|
---|
193 | slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec->pid));
|
---|
194 | if (cgi_variable(buf)) {
|
---|
195 | kill_pid(crec->pid);
|
---|
196 | sleep(SLEEP_TIME);
|
---|
197 | }
|
---|
198 | }
|
---|
199 | return 0;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /* traversal fn for showing machine connections */
|
---|
203 | static int traverse_fn2(const struct connections_key *key,
|
---|
204 | const struct connections_data *crec,
|
---|
205 | void *private_data)
|
---|
206 | {
|
---|
207 | if (crec->cnum == -1 || !process_exists(crec->pid) ||
|
---|
208 | procid_equal(&crec->pid, &smbd_pid))
|
---|
209 | return 0;
|
---|
210 |
|
---|
211 | addPid2Machine (crec->pid, crec->machine);
|
---|
212 |
|
---|
213 | printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n",
|
---|
214 | procid_str_static(&crec->pid),
|
---|
215 | crec->machine, crec->addr,
|
---|
216 | tstring(talloc_tos(),crec->start));
|
---|
217 | if (geteuid() == 0) {
|
---|
218 | printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n",
|
---|
219 | procid_str_static(&crec->pid));
|
---|
220 | }
|
---|
221 | printf("</tr>\n");
|
---|
222 |
|
---|
223 | return 0;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /* traversal fn for showing share connections */
|
---|
227 | static int traverse_fn3(const struct connections_key *key,
|
---|
228 | const struct connections_data *crec,
|
---|
229 | void *private_data)
|
---|
230 | {
|
---|
231 | if (crec->cnum == -1 || !process_exists(crec->pid))
|
---|
232 | return 0;
|
---|
233 |
|
---|
234 | printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
|
---|
235 | crec->servicename, uidtoname(crec->uid),
|
---|
236 | gidtoname(crec->gid),procid_str_static(&crec->pid),
|
---|
237 | crec->machine,
|
---|
238 | tstring(talloc_tos(),crec->start));
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | /* show the current server status */
|
---|
244 | void status_page(void)
|
---|
245 | {
|
---|
246 | const char *v;
|
---|
247 | int autorefresh=0;
|
---|
248 | int refresh_interval=30;
|
---|
249 | int nr_running=0;
|
---|
250 | bool waitup = False;
|
---|
251 | TALLOC_CTX *ctx = talloc_stackframe();
|
---|
252 | const char form_name[] = "status";
|
---|
253 |
|
---|
254 | smbd_pid = pid_to_procid(pidfile_pid("smbd"));
|
---|
255 |
|
---|
256 | if (!verify_xsrf_token(form_name)) {
|
---|
257 | goto output_page;
|
---|
258 | }
|
---|
259 |
|
---|
260 | if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
|
---|
261 | stop_smbd();
|
---|
262 | start_smbd();
|
---|
263 | waitup=True;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
|
---|
267 | start_smbd();
|
---|
268 | waitup=True;
|
---|
269 | }
|
---|
270 |
|
---|
271 | if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
|
---|
272 | stop_smbd();
|
---|
273 | waitup=True;
|
---|
274 | }
|
---|
275 |
|
---|
276 | if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
|
---|
277 | stop_nmbd();
|
---|
278 | start_nmbd();
|
---|
279 | waitup=True;
|
---|
280 | }
|
---|
281 | if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
|
---|
282 | start_nmbd();
|
---|
283 | waitup=True;
|
---|
284 | }
|
---|
285 |
|
---|
286 | if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
|
---|
287 | stop_nmbd();
|
---|
288 | waitup=True;
|
---|
289 | }
|
---|
290 |
|
---|
291 | #ifdef WITH_WINBIND
|
---|
292 | if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
|
---|
293 | stop_winbindd();
|
---|
294 | start_winbindd();
|
---|
295 | waitup=True;
|
---|
296 | }
|
---|
297 |
|
---|
298 | if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
|
---|
299 | start_winbindd();
|
---|
300 | waitup=True;
|
---|
301 | }
|
---|
302 |
|
---|
303 | if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
|
---|
304 | stop_winbindd();
|
---|
305 | waitup=True;
|
---|
306 | }
|
---|
307 | #endif
|
---|
308 | /* wait for daemons to start/stop */
|
---|
309 | if (waitup)
|
---|
310 | sleep(SLEEP_TIME);
|
---|
311 |
|
---|
312 | if (cgi_variable("autorefresh")) {
|
---|
313 | autorefresh = 1;
|
---|
314 | } else if (cgi_variable("norefresh")) {
|
---|
315 | autorefresh = 0;
|
---|
316 | } else if (cgi_variable("refresh")) {
|
---|
317 | autorefresh = 1;
|
---|
318 | }
|
---|
319 |
|
---|
320 | if ((v=cgi_variable("refresh_interval"))) {
|
---|
321 | refresh_interval = atoi(v);
|
---|
322 | }
|
---|
323 |
|
---|
324 | if (cgi_variable("show_client_in_col_1")) {
|
---|
325 | PID_or_Machine = 1;
|
---|
326 | }
|
---|
327 |
|
---|
328 | if (cgi_variable("show_pid_in_col_1")) {
|
---|
329 | PID_or_Machine = 0;
|
---|
330 | }
|
---|
331 |
|
---|
332 | connections_forall_read(traverse_fn1, NULL);
|
---|
333 |
|
---|
334 | initPid2Machine ();
|
---|
335 |
|
---|
336 | output_page:
|
---|
337 | printf("<H2>%s</H2>\n", _("Server Status"));
|
---|
338 |
|
---|
339 | printf("<FORM method=post>\n");
|
---|
340 | print_xsrf_token(cgi_user_name(), cgi_user_pass(), form_name);
|
---|
341 |
|
---|
342 | if (!autorefresh) {
|
---|
343 | printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh"));
|
---|
344 | printf("<br>%s", _("Refresh Interval: "));
|
---|
345 | printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n",
|
---|
346 | refresh_interval);
|
---|
347 | } else {
|
---|
348 | printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing"));
|
---|
349 | printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval);
|
---|
350 | printf("<input type=hidden name=\"refresh\" value=\"1\">\n");
|
---|
351 | }
|
---|
352 |
|
---|
353 | printf("<p>\n");
|
---|
354 |
|
---|
355 | printf("<table>\n");
|
---|
356 |
|
---|
357 | printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), samba_version_string());
|
---|
358 |
|
---|
359 | fflush(stdout);
|
---|
360 | printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
|
---|
361 | if (geteuid() == 0) {
|
---|
362 | if (smbd_running()) {
|
---|
363 | nr_running++;
|
---|
364 | printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd"));
|
---|
365 | } else {
|
---|
366 | printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd"));
|
---|
367 | }
|
---|
368 | printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd"));
|
---|
369 | }
|
---|
370 | printf("</tr>\n");
|
---|
371 |
|
---|
372 | fflush(stdout);
|
---|
373 | printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running"));
|
---|
374 | if (geteuid() == 0) {
|
---|
375 | if (nmbd_running()) {
|
---|
376 | nr_running++;
|
---|
377 | printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd"));
|
---|
378 | } else {
|
---|
379 | printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd"));
|
---|
380 | }
|
---|
381 | printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd"));
|
---|
382 | }
|
---|
383 | printf("</tr>\n");
|
---|
384 |
|
---|
385 | #ifdef WITH_WINBIND
|
---|
386 | fflush(stdout);
|
---|
387 | printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
|
---|
388 | if (geteuid() == 0) {
|
---|
389 | if (winbindd_running()) {
|
---|
390 | nr_running++;
|
---|
391 | printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
|
---|
392 | } else {
|
---|
393 | printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
|
---|
394 | }
|
---|
395 | printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
|
---|
396 | }
|
---|
397 | printf("</tr>\n");
|
---|
398 | #endif
|
---|
399 |
|
---|
400 | if (geteuid() == 0) {
|
---|
401 | printf("<tr><td></td><td></td>\n");
|
---|
402 | if (nr_running >= 1) {
|
---|
403 | /* stop, restart all */
|
---|
404 | printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All"));
|
---|
405 | printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All"));
|
---|
406 | }
|
---|
407 | else if (nr_running == 0) {
|
---|
408 | /* start all */
|
---|
409 | printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All"));
|
---|
410 | }
|
---|
411 | printf("</tr>\n");
|
---|
412 | }
|
---|
413 | printf("</table>\n");
|
---|
414 | fflush(stdout);
|
---|
415 |
|
---|
416 | printf("<p><h3>%s</h3>\n", _("Active Connections"));
|
---|
417 | printf("<table border=1>\n");
|
---|
418 | printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date"));
|
---|
419 | if (geteuid() == 0) {
|
---|
420 | printf("<th>%s</th>\n", _("Kill"));
|
---|
421 | }
|
---|
422 | printf("</tr>\n");
|
---|
423 |
|
---|
424 | connections_forall_read(traverse_fn2, NULL);
|
---|
425 |
|
---|
426 | printf("</table><p>\n");
|
---|
427 |
|
---|
428 | printf("<p><h3>%s</h3>\n", _("Active Shares"));
|
---|
429 | printf("<table border=1>\n");
|
---|
430 | printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
|
---|
431 | _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
|
---|
432 |
|
---|
433 | connections_forall_read(traverse_fn3, NULL);
|
---|
434 |
|
---|
435 | printf("</table><p>\n");
|
---|
436 |
|
---|
437 | printf("<h3>%s</h3>\n", _("Open Files"));
|
---|
438 | printf("<table border=1>\n");
|
---|
439 | printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
|
---|
440 | _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("Share"), _("File"), _("Date"));
|
---|
441 |
|
---|
442 | locking_init_readonly();
|
---|
443 | share_mode_forall(print_share_mode, NULL);
|
---|
444 | locking_end();
|
---|
445 | printf("</table>\n");
|
---|
446 |
|
---|
447 | printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1"));
|
---|
448 | printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1"));
|
---|
449 |
|
---|
450 | printf("</FORM>\n");
|
---|
451 |
|
---|
452 | if (autorefresh) {
|
---|
453 | /* this little JavaScript allows for automatic refresh
|
---|
454 | of the page. There are other methods but this seems
|
---|
455 | to be the best alternative */
|
---|
456 | printf("<script language=\"JavaScript\">\n");
|
---|
457 | printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
|
---|
458 | cgi_baseurl(),
|
---|
459 | refresh_interval,
|
---|
460 | refresh_interval*1000);
|
---|
461 | printf("//-->\n</script>\n");
|
---|
462 | }
|
---|
463 | TALLOC_FREE(ctx);
|
---|
464 | }
|
---|