diff options
Diffstat (limited to 'source/web/statuspage.c')
-rw-r--r-- | source/web/statuspage.c | 230 |
1 files changed, 82 insertions, 148 deletions
diff --git a/source/web/statuspage.c b/source/web/statuspage.c index 3d70796830d..12bb307d34a 100644 --- a/source/web/statuspage.c +++ b/source/web/statuspage.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 2.2. web status page Copyright (C) Andrew Tridgell 1997-1998 @@ -19,13 +20,9 @@ */ #include "includes.h" -#include "../web/swat_proto.h" #define PIDMAP struct PidMap -/* how long to wait for start/stops to take effect */ -#define SLEEP_TIME 3 - PIDMAP { PIDMAP *next, *prev; pid_t pid; @@ -93,7 +90,7 @@ static char *mapPid2Machine (pid_t pid) } /* PID not in list or machine name NULL? return pid as string */ - snprintf (pidbuf, sizeof (pidbuf) - 1, "%lu", (unsigned long)pid); + snprintf (pidbuf, sizeof (pidbuf) - 1, "%d", pid); return pidbuf; } @@ -107,42 +104,42 @@ static char *tstring(time_t t) static void print_share_mode(share_mode_entry *e, char *fname) { - d_printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid))); - d_printf("<td>"); + printf("<tr><td>%s</td>", mapPid2Machine (e->pid)); + printf("<td>"); switch ((e->share_mode>>4)&0xF) { - case DENY_NONE: d_printf("DENY_NONE"); break; - case DENY_ALL: d_printf("DENY_ALL "); break; - case DENY_DOS: d_printf("DENY_DOS "); break; - case DENY_READ: d_printf("DENY_READ "); break; - case DENY_WRITE:d_printf("DENY_WRITE "); break; + 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; } - d_printf("</td>"); + printf("</td>"); - d_printf("<td>"); + printf("<td>"); switch (e->share_mode&0xF) { - case 0: d_printf("%s", _("RDONLY ")); break; - case 1: d_printf("%s", _("WRONLY ")); break; - case 2: d_printf("%s", _("RDWR ")); break; + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; } - d_printf("</td>"); + printf("</td>"); - d_printf("<td>"); + printf("<td>"); if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) - d_printf("EXCLUSIVE+BATCH "); + printf("EXCLUSIVE+BATCH "); else if (e->op_type & EXCLUSIVE_OPLOCK) - d_printf("EXCLUSIVE "); + printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) - d_printf("BATCH "); + printf("BATCH "); else if (e->op_type & LEVEL_II_OPLOCK) - d_printf("LEVEL_II "); + printf("LEVEL_II "); else - d_printf("NONE "); - d_printf("</td>"); + printf("NONE "); + printf("</td>"); - d_printf("<td>%s</td><td>%s</td></tr>\n", - fname,tstring(e->time.tv_sec)); + printf("<td>%s</td><td>%s</td></tr>\n", + dos_to_unix_static(fname),tstring(e->time.tv_sec)); } @@ -161,7 +158,6 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); if (cgi_variable(buf)) { kill_pid(crec.pid); - sleep(SLEEP_TIME); } } return 0; @@ -177,20 +173,20 @@ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st memcpy(&crec, dbuf.dptr, sizeof(crec)); - if (crec.cnum == -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid)) + if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid)) return 0; addPid2Machine (crec.pid, crec.machine); - d_printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n", + 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) { - d_printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n", + printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n", (int)crec.pid); } - d_printf("</tr>\n"); + printf("</tr>\n"); return 0; } @@ -208,7 +204,7 @@ static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st if (crec.cnum == -1 || !process_exists(crec.pid)) return 0; - d_printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n", + 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, @@ -224,63 +220,34 @@ void status_page(void) int autorefresh=0; int refresh_interval=30; TDB_CONTEXT *tdb; - int nr_running=0; - BOOL waitup = False; smbd_pid = pidfile_pid("smbd"); - if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) { + if (cgi_variable("smbd_restart")) { stop_smbd(); start_smbd(); - waitup=True; } - if (cgi_variable("smbd_start") || cgi_variable("all_start")) { + if (cgi_variable("smbd_start")) { start_smbd(); - waitup=True; } - if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) { + if (cgi_variable("smbd_stop")) { stop_smbd(); - waitup=True; } - if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) { + if (cgi_variable("nmbd_restart")) { stop_nmbd(); start_nmbd(); - waitup=True; } - if (cgi_variable("nmbd_start") || cgi_variable("all_start")) { + if (cgi_variable("nmbd_start")) { start_nmbd(); - waitup=True; } - if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) { + if (cgi_variable("nmbd_stop")) { stop_nmbd(); - waitup=True; - } - -#ifdef WITH_WINBIND - if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) { - stop_winbindd(); - start_winbindd(); - waitup=True; - } - - if (cgi_variable("winbindd_start") || cgi_variable("all_start")) { - start_winbindd(); - waitup=True; } - if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) { - stop_winbindd(); - waitup=True; - } -#endif - /* wait for daemons to start/stop */ - if (waitup) - sleep(SLEEP_TIME); - if (cgi_variable("autorefresh")) { autorefresh = 1; } else if (cgi_variable("norefresh")) { @@ -297,145 +264,112 @@ void status_page(void) PID_or_Machine = 1; } - if (cgi_variable("show_pid_in_col_1")) { - PID_or_Machine = 0; - } - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); - + initPid2Machine (); - d_printf("<H2>%s</H2>\n", _("Server Status")); + printf("<H2>Server Status</H2>\n"); - d_printf("<FORM method=post>\n"); + printf("<FORM method=post>\n"); if (!autorefresh) { - d_printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh")); - d_printf("<br>%s", _("Refresh Interval: ")); - d_printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n", + 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 { - d_printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing")); - d_printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval); - d_printf("<input type=hidden name=\"refresh\" value=\"1\">\n"); + 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"); } - d_printf("<p>\n"); + printf("<p>\n"); if (!tdb) { /* open failure either means no connections have been - made */ + made or status=no */ + if (!lp_status(-1)) + printf("You need to have status=yes in your smb config file\n"); } - d_printf("<table>\n"); + printf("<table>\n"); - d_printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING); + printf("<tr><td>version:</td><td>%s</td></tr>",VERSION); fflush(stdout); - d_printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running")); + printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not "); if (geteuid() == 0) { if (smbd_running()) { - nr_running++; - d_printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd")); + printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n"); } else { - d_printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd")); + printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n"); } - d_printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd")); + printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n"); } - d_printf("</tr>\n"); + printf("</tr>\n"); fflush(stdout); - d_printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running")); + printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not "); if (geteuid() == 0) { if (nmbd_running()) { - nr_running++; - d_printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd")); + printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n"); } else { - d_printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd")); + printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n"); } - d_printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd")); + printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n"); } - d_printf("</tr>\n"); + printf("</tr>\n"); -#ifdef WITH_WINBIND - fflush(stdout); - d_printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running")); - if (geteuid() == 0) { - if (winbindd_running()) { - nr_running++; - d_printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd")); - } else { - d_printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd")); - } - d_printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd")); - } - d_printf("</tr>\n"); -#endif - - if (geteuid() == 0) { - d_printf("<tr><td></td><td></td>\n"); - if (nr_running >= 1) { - /* stop, restart all */ - d_printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All")); - d_printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All")); - } - else if (nr_running == 0) { - /* start all */ - d_printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All")); - } - d_printf("</tr>\n"); - } - d_printf("</table>\n"); + printf("</table>\n"); fflush(stdout); - d_printf("<p><h3>%s</h3>\n", _("Active Connections")); - d_printf("<table border=1>\n"); - d_printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date")); + 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) { - d_printf("<th>%s</th>\n", _("Kill")); + printf("<th>Kill</th>\n"); } - d_printf("</tr>\n"); + printf("</tr>\n"); if (tdb) tdb_traverse(tdb, traverse_fn2, NULL); - d_printf("</table><p>\n"); + printf("</table><p>\n"); - d_printf("<p><h3>%s</h3>\n", _("Active Shares")); - d_printf("<table border=1>\n"); - d_printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n", - _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date")); + 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"); if (tdb) tdb_traverse(tdb, traverse_fn3, NULL); - d_printf("</table><p>\n"); + printf("</table><p>\n"); - d_printf("<h3>%s</h3>\n", _("Open Files")); - d_printf("<table border=1>\n"); - d_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")); + printf("<h3>Open Files</h3>\n"); + printf("<table border=1>\n"); + 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"); locking_init(1); share_mode_forall(print_share_mode); locking_end(); - d_printf("</table>\n"); + printf("</table>\n"); if (tdb) tdb_close(tdb); - d_printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1")); - d_printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1")); + printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"Show Client in col 1\">\n"); + printf("<input type=submit name=\"show_pid_in_col_1\" value=\"Show PID in col 1\">\n"); - d_printf("</FORM>\n"); + 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 */ - d_printf("<script language=\"JavaScript\">\n"); - d_printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n", + 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); - d_printf("//-->\n</script>\n"); + printf("//-->\n</script>\n"); } } |