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