* converted to autoconf and began port to Digital UNIX
[citadel.git] / webcit / who.c
1 /* $Id$ */
2
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <signal.h>
7 #include <sys/types.h>
8 #include <ctype.h>
9 #include <string.h>
10 #include "webcit.h"
11 #include "child.h"
12
13 struct whouser {
14         struct whouser *next;
15         int sessionnum;
16         char username[256];
17         char roomname[256];
18         char hostname[256];
19         char clientsoftware[256];
20         };
21         
22 /*
23  * who is on?
24  */
25 void whobbs(void) {
26         struct whouser *wlist = NULL;
27         struct whouser *wptr = NULL;
28         char buf[256],sess,user[256],room[256],host[256];
29         int foundit;
30
31         printf("HTTP/1.0 200 OK\n");
32         output_headers();
33         wprintf("<HTML><HEAD><TITLE>Who is online?</TITLE>\n");
34
35         /* Uncomment this line to cause the wholist to auto-refresh */
36         /* wprintf("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">\n"); */
37
38         wprintf("</HEAD><BODY>\n");
39
40         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
41         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
42         escputs(serv_info.serv_humannode);
43         wprintf("</B></FONT></TD></TR></TABLE>\n");
44
45         wprintf("<CENTER><TABLE border><TR>");
46         wprintf("<TH>Session ID</TH><TH>User Name</TH><TH>Room</TH>");
47         wprintf("<TH>From host</TH></TR>\n");
48         serv_puts("RWHO");
49         serv_gets(buf);
50         if (buf[0]=='1') {
51                 while(serv_gets(buf), strcmp(buf,"000")) {
52                         sess = extract_int(buf, 0);
53                         extract(user, buf, 1);
54                         extract(room, buf, 2);
55                         extract(host, buf, 3);
56
57                         foundit = 0;
58                         for (wptr = wlist; wptr != NULL; wptr = wptr -> next) {
59                                 if (wptr->sessionnum == sess) {
60                                         foundit = 1;
61                                         if (strcasecmp(user, wptr->username)) {
62                                                 sprintf(buf, "%cBR%c%s", 
63                                                         LB, RB, user);
64                                                 strcat(wptr->username, buf);
65                                                 }
66                                         if (strcasecmp(room, wptr->roomname)) {
67                                                 sprintf(buf, "%cBR%c%s", 
68                                                         LB, RB, room);
69                                                 strcat(wptr->roomname, buf);
70                                                 }
71                                         if (strcasecmp(host, wptr->hostname)) {
72                                                 sprintf(buf, "%cBR%c%s", 
73                                                         LB, RB, host);
74                                                 strcat(wptr->hostname, buf);
75                                                 }
76                                         }
77                                 }
78
79                         if (foundit == 0) {
80                                 wptr = (struct whouser *)
81                                         malloc(sizeof(struct whouser));
82                                 wptr->next = wlist;
83                                 wlist = wptr;
84                                 strcpy(wlist->username, user);
85                                 strcpy(wlist->roomname, room);
86                                 strcpy(wlist->hostname, host);
87                                 wlist->sessionnum = sess;
88                                 }
89                         }
90
91                 while (wlist != NULL) {
92                         wprintf("<TR><TD>%d</TD><TD>", wlist->sessionnum);
93                         escputs(wlist->username);
94                         wprintf("</TD><TD>");
95                         escputs(wlist->roomname);
96                         wprintf("</TD><TD>");
97                         escputs(wlist->hostname);
98                         wprintf("</TD></TR>\n");
99                         wptr = wlist->next;
100                         free(wlist);
101                         wlist = wptr;
102                         }
103                 }
104         wprintf("</TABLE></CENTER>\n");
105         wprintf("</BODY></HTML>\n");
106         wDumpContent();
107         }
108
109