00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022 #include "web/swat_proto.h"
00023
00024 #define PIDMAP struct PidMap
00025
00026
00027 #define SLEEP_TIME 3
00028
00029 PIDMAP {
00030 PIDMAP *next, *prev;
00031 struct process_id pid;
00032 char *machine;
00033 };
00034
00035 static PIDMAP *pidmap;
00036 static int PID_or_Machine;
00037
00038 static struct process_id smbd_pid;
00039
00040
00041 static void initPid2Machine (void)
00042 {
00043
00044 if (PID_or_Machine) {
00045 PIDMAP *p;
00046
00047 for (p = pidmap; p != NULL; ) {
00048 DLIST_REMOVE(pidmap, p);
00049 SAFE_FREE(p->machine);
00050 SAFE_FREE(p);
00051 }
00052
00053 pidmap = NULL;
00054 }
00055 }
00056
00057
00058 static void addPid2Machine (struct process_id pid, char *machine)
00059 {
00060
00061 if (PID_or_Machine) {
00062 PIDMAP *newmap;
00063
00064 if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
00065
00066
00067 return;
00068 }
00069
00070 newmap->pid = pid;
00071 newmap->machine = SMB_STRDUP(machine);
00072
00073 DLIST_ADD(pidmap, newmap);
00074 }
00075 }
00076
00077
00078 static char *mapPid2Machine (struct process_id pid)
00079 {
00080 static char pidbuf [64];
00081 PIDMAP *map;
00082
00083
00084 if (PID_or_Machine) {
00085 for (map = pidmap; map != NULL; map = map->next) {
00086 if (procid_equal(&pid, &map->pid)) {
00087 if (map->machine == NULL)
00088 break;
00089
00090 return map->machine;
00091 }
00092 }
00093 }
00094
00095
00096 snprintf (pidbuf, sizeof (pidbuf) - 1, "%s",
00097 procid_str_static(&pid));
00098 return pidbuf;
00099 }
00100
00101 static char *tstring(time_t t)
00102 {
00103 static pstring buf;
00104 pstrcpy(buf, time_to_asc(t));
00105 all_string_sub(buf," "," ",sizeof(buf));
00106 return buf;
00107 }
00108
00109 static void print_share_mode(const struct share_mode_entry *e,
00110 const char *sharepath,
00111 const char *fname,
00112 void *dummy)
00113 {
00114 char *utf8_fname;
00115 int deny_mode;
00116
00117 if (!is_valid_share_mode_entry(e)) {
00118 return;
00119 }
00120
00121 deny_mode = map_share_mode_to_deny_mode(e->share_access,
00122 e->private_options);
00123
00124 printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
00125 printf("<td>%u</td>",(unsigned int)e->uid);
00126 printf("<td>");
00127 switch ((deny_mode>>4)&0xF) {
00128 case DENY_NONE: printf("DENY_NONE"); break;
00129 case DENY_ALL: printf("DENY_ALL "); break;
00130 case DENY_DOS: printf("DENY_DOS "); break;
00131 case DENY_FCB: printf("DENY_FCB "); break;
00132 case DENY_READ: printf("DENY_READ "); break;
00133 case DENY_WRITE:printf("DENY_WRITE "); break;
00134 }
00135 printf("</td>");
00136
00137 printf("<td>");
00138 if (e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA)) {
00139 printf("%s", _("RDWR "));
00140 } else if (e->access_mask & FILE_WRITE_DATA) {
00141 printf("%s", _("WRONLY "));
00142 } else {
00143 printf("%s", _("RDONLY "));
00144 }
00145 printf("</td>");
00146
00147 printf("<td>");
00148 if((e->op_type &
00149 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
00150 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
00151 printf("EXCLUSIVE+BATCH ");
00152 else if (e->op_type & EXCLUSIVE_OPLOCK)
00153 printf("EXCLUSIVE ");
00154 else if (e->op_type & BATCH_OPLOCK)
00155 printf("BATCH ");
00156 else if (e->op_type & LEVEL_II_OPLOCK)
00157 printf("LEVEL_II ");
00158 else
00159 printf("NONE ");
00160 printf("</td>");
00161
00162 push_utf8_allocate(&utf8_fname, fname);
00163 printf("<td>%s</td><td>%s</td></tr>\n",
00164 utf8_fname,tstring(e->time.tv_sec));
00165 SAFE_FREE(utf8_fname);
00166 }
00167
00168
00169
00170 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
00171 {
00172 struct connections_data crec;
00173
00174 if (dbuf.dsize != sizeof(crec))
00175 return 0;
00176
00177 memcpy(&crec, dbuf.dptr, sizeof(crec));
00178
00179 if (crec.cnum == -1 && process_exists(crec.pid)) {
00180 char buf[30];
00181 slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec.pid));
00182 if (cgi_variable(buf)) {
00183 kill_pid(crec.pid);
00184 sleep(SLEEP_TIME);
00185 }
00186 }
00187 return 0;
00188 }
00189
00190
00191 static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
00192 {
00193 struct connections_data crec;
00194
00195 if (dbuf.dsize != sizeof(crec))
00196 return 0;
00197
00198 memcpy(&crec, dbuf.dptr, sizeof(crec));
00199
00200 if (crec.cnum == -1 || !process_exists(crec.pid) ||
00201 procid_equal(&crec.pid, &smbd_pid))
00202 return 0;
00203
00204 addPid2Machine (crec.pid, crec.machine);
00205
00206 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n",
00207 procid_str_static(&crec.pid),
00208 crec.machine,crec.addr,
00209 tstring(crec.start));
00210 if (geteuid() == 0) {
00211 printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n",
00212 procid_str_static(&crec.pid));
00213 }
00214 printf("</tr>\n");
00215
00216 return 0;
00217 }
00218
00219
00220 static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
00221 {
00222 struct connections_data crec;
00223
00224 if (dbuf.dsize != sizeof(crec))
00225 return 0;
00226
00227 memcpy(&crec, dbuf.dptr, sizeof(crec));
00228
00229 if (crec.cnum == -1 || !process_exists(crec.pid))
00230 return 0;
00231
00232 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
00233 crec.servicename,uidtoname(crec.uid),
00234 gidtoname(crec.gid),procid_str_static(&crec.pid),
00235 crec.machine,
00236 tstring(crec.start));
00237 return 0;
00238 }
00239
00240
00241
00242 void status_page(void)
00243 {
00244 const char *v;
00245 int autorefresh=0;
00246 int refresh_interval=30;
00247 TDB_CONTEXT *tdb;
00248 int nr_running=0;
00249 BOOL waitup = False;
00250
00251 smbd_pid = pid_to_procid(pidfile_pid("smbd"));
00252
00253 if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
00254 stop_smbd();
00255 start_smbd();
00256 waitup=True;
00257 }
00258
00259 if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
00260 start_smbd();
00261 waitup=True;
00262 }
00263
00264 if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
00265 stop_smbd();
00266 waitup=True;
00267 }
00268
00269 if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
00270 stop_nmbd();
00271 start_nmbd();
00272 waitup=True;
00273 }
00274 if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
00275 start_nmbd();
00276 waitup=True;
00277 }
00278
00279 if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
00280 stop_nmbd();
00281 waitup=True;
00282 }
00283
00284 #ifdef WITH_WINBIND
00285 if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
00286 stop_winbindd();
00287 start_winbindd();
00288 waitup=True;
00289 }
00290
00291 if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
00292 start_winbindd();
00293 waitup=True;
00294 }
00295
00296 if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
00297 stop_winbindd();
00298 waitup=True;
00299 }
00300 #endif
00301
00302 if (waitup)
00303 sleep(SLEEP_TIME);
00304
00305 if (cgi_variable("autorefresh")) {
00306 autorefresh = 1;
00307 } else if (cgi_variable("norefresh")) {
00308 autorefresh = 0;
00309 } else if (cgi_variable("refresh")) {
00310 autorefresh = 1;
00311 }
00312
00313 if ((v=cgi_variable("refresh_interval"))) {
00314 refresh_interval = atoi(v);
00315 }
00316
00317 if (cgi_variable("show_client_in_col_1")) {
00318 PID_or_Machine = 1;
00319 }
00320
00321 if (cgi_variable("show_pid_in_col_1")) {
00322 PID_or_Machine = 0;
00323 }
00324
00325 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
00326 if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
00327
00328 initPid2Machine ();
00329
00330 printf("<H2>%s</H2>\n", _("Server Status"));
00331
00332 printf("<FORM method=post>\n");
00333
00334 if (!autorefresh) {
00335 printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh"));
00336 printf("<br>%s", _("Refresh Interval: "));
00337 printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n",
00338 refresh_interval);
00339 } else {
00340 printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing"));
00341 printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval);
00342 printf("<input type=hidden name=\"refresh\" value=\"1\">\n");
00343 }
00344
00345 printf("<p>\n");
00346
00347 if (!tdb) {
00348
00349
00350 }
00351
00352
00353 printf("<table>\n");
00354
00355 printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING);
00356
00357 fflush(stdout);
00358 printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
00359 if (geteuid() == 0) {
00360 if (smbd_running()) {
00361 nr_running++;
00362 printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd"));
00363 } else {
00364 printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd"));
00365 }
00366 printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd"));
00367 }
00368 printf("</tr>\n");
00369
00370 fflush(stdout);
00371 printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running"));
00372 if (geteuid() == 0) {
00373 if (nmbd_running()) {
00374 nr_running++;
00375 printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd"));
00376 } else {
00377 printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd"));
00378 }
00379 printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd"));
00380 }
00381 printf("</tr>\n");
00382
00383 #ifdef WITH_WINBIND
00384 fflush(stdout);
00385 printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
00386 if (geteuid() == 0) {
00387 if (winbindd_running()) {
00388 nr_running++;
00389 printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
00390 } else {
00391 printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
00392 }
00393 printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
00394 }
00395 printf("</tr>\n");
00396 #endif
00397
00398 if (geteuid() == 0) {
00399 printf("<tr><td></td><td></td>\n");
00400 if (nr_running >= 1) {
00401
00402 printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All"));
00403 printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All"));
00404 }
00405 else if (nr_running == 0) {
00406
00407 printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All"));
00408 }
00409 printf("</tr>\n");
00410 }
00411 printf("</table>\n");
00412 fflush(stdout);
00413
00414 printf("<p><h3>%s</h3>\n", _("Active Connections"));
00415 printf("<table border=1>\n");
00416 printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date"));
00417 if (geteuid() == 0) {
00418 printf("<th>%s</th>\n", _("Kill"));
00419 }
00420 printf("</tr>\n");
00421
00422 if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);
00423
00424 printf("</table><p>\n");
00425
00426 printf("<p><h3>%s</h3>\n", _("Active Shares"));
00427 printf("<table border=1>\n");
00428 printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
00429 _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
00430
00431 if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);
00432
00433 printf("</table><p>\n");
00434
00435 printf("<h3>%s</h3>\n", _("Open Files"));
00436 printf("<table border=1>\n");
00437 printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));
00438
00439 locking_init(1);
00440 share_mode_forall(print_share_mode, NULL);
00441 locking_end();
00442 printf("</table>\n");
00443
00444 if (tdb) tdb_close(tdb);
00445
00446 printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1"));
00447 printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1"));
00448
00449 printf("</FORM>\n");
00450
00451 if (autorefresh) {
00452
00453
00454
00455 printf("<script language=\"JavaScript\">\n");
00456 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
00457 cgi_baseurl(),
00458 refresh_interval,
00459 refresh_interval*1000);
00460 printf("//-->\n</script>\n");
00461 }
00462 }