summaryrefslogtreecommitdiff
path: root/source3/web
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1999-12-21 04:54:30 +0000
committerAndrew Tridgell <tridge@samba.org>1999-12-21 04:54:30 +0000
commit69d24d869bf97978b31a51fe8e8d08cac4874d67 (patch)
tree30ec2bcdc8491098dd9b3f0c4e3432092b73f23a /source3/web
parent0c4b1ea0140ed5418fcbde3077d424ffa08a2dcf (diff)
downloadsamba-69d24d869bf97978b31a51fe8e8d08cac4874d67.tar.gz
samba-69d24d869bf97978b31a51fe8e8d08cac4874d67.tar.bz2
samba-69d24d869bf97978b31a51fe8e8d08cac4874d67.zip
first cut at using the tdb code for the connections structure, the
SWAT status page and smbstatus. It made the code _much_ simpler, I wish we'd done a database module a long time ago! (This used to be commit 4951755413c11d4c5b9af4699a6e622056d52433)
Diffstat (limited to 'source3/web')
-rw-r--r--source3/web/statuspage.c117
1 files changed, 63 insertions, 54 deletions
diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c
index 304a122e23..8b7108c0b5 100644
--- a/source3/web/statuspage.c
+++ b/source3/web/statuspage.c
@@ -71,15 +71,68 @@ static void print_share_mode(share_mode_entry *e, char *fname)
}
+/* kill off any connections chosen by the user */
+static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf)
+{
+ struct connections_data crec;
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (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);
+ }
+ }
+ return 0;
+}
+
+/* traversal fn for showing machine connections */
+static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf)
+{
+ struct connections_data crec;
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (crec.cnum != -1 || !process_exists(crec.pid)) return 0;
+
+ 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");
+
+ return 0;
+}
+
+/* traversal fn for showing share connections */
+static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf)
+{
+ struct connections_data crec;
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (crec.cnum != -1 || !process_exists(crec.pid)) return 0;
+
+ 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));
+ return 0;
+}
+
+
/* 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;
+ TDB_CONTEXT *tdb;
if (cgi_variable("smbd_restart")) {
if (smbd_running())
@@ -123,24 +176,10 @@ void status_page(void)
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);
- }
+ pstrcat(fname,"/connections.tdb");
+
+ tdb = tdb_open(fname, 0, O_RDONLY, 0);
+ if (tdb) tdb_traverse(tdb, traverse_fn1);
printf("<H2>Server Status</H2>\n");
@@ -159,8 +198,7 @@ void status_page(void)
printf("<p>\n");
- f = sys_fopen(fname,"r");
- if (!f) {
+ if (!tdb) {
/* open failure either means no connections have been
made or status=no */
if (!lp_status(-1))
@@ -207,44 +245,15 @@ void status_page(void)
}
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");
- }
- }
+ if (tdb) tdb_traverse(tdb, traverse_fn2);
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));
- }
- }
+ if (tdb) tdb_traverse(tdb, traverse_fn3);
printf("</table><p>\n");
@@ -257,7 +266,7 @@ void status_page(void)
locking_end();
printf("</table>\n");
- if (f) fclose(f);
+ tdb_close(tdb);
printf("</FORM>\n");