4 * Command-line "who is online?" utility
14 #include "citadel_ipc.h"
23 static void escapize(char *buf, size_t n) {
30 for (i=0; i<strlen(hold); ++i) {
31 size_t tmp = strlen(buf);
34 snprintf(&buf[tmp], n - tmp, "<");
35 else if (hold[i]=='>')
36 snprintf(&buf[tmp], n - tmp, ">");
38 snprintf(&buf[tmp], n - tmp, """);
40 snprintf(&buf[tmp], n - tmp, "%c", hold[i]);
47 int main(int argc, char **argv)
60 int r; /* IPC response code */
63 struct CtdlServInfo *serv_info = NULL;
65 /* If this environment variable is set, we assume that the program
66 * is being called as a cgi-bin from a webserver and will output
69 if (getenv("REQUEST_METHOD") != NULL) www = 1;
71 attach_to_server(argc, argv, hostbuf, portbuf);
73 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
74 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
77 strcpy(nodetitle, "this BBS");
78 r = CtdlIPCServerInfo(serv_info, buf);
80 my_pid = serv_info->serv_pid;
81 strcpy(nodetitle, serv_info->serv_humannode);
85 printf( "Content-type: text/html\n"
88 "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">\n"
90 printf("%s: who is online", nodetitle);
91 printf( "</TITLE></HEAD><BODY><H1>");
97 printf("<CENTER><H1>");
100 printf("Users currently logged on to %s\n", nodetitle);
106 r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
108 fprintf(stderr,"%s: %s\n",argv[0], buf);
113 printf( "<TABLE BORDER=1 WIDTH=100%%>"
114 "<TR><TH>Session</TH><TH>User name</TH>"
115 "<TH>Room</TH><TH>From host</TH>"
116 "<TH>Client software</TH></TR>\n");
119 printf( "Session User name "
121 printf( "------- ------------------------- "
122 "------------------- ------------------------\n");
126 while (strlen(listing) > 0) {
127 extract_token(buf, listing, 0, '\n');
128 remove_token(listing, 0, '\n');
130 /* Escape some stuff if we're using www mode */
131 if (www) escapize(buf, sizeof buf);
133 s_pid = extract_int(buf,0);
134 extract(s_user,buf,1);
135 extract(s_room,buf,2);
136 extract(s_host,buf,3);
137 extract(s_client,buf,4);
138 if (s_pid != my_pid) {
140 if (www) printf("<TR><TD>");
141 printf("%-7d", s_pid);
143 ((s_pid == my_pid) ? '*' : ' '));
144 if (www) printf("</TD><TD>");
145 printf("%-25s", s_user);
146 if (www) printf("</TD><TD>");
147 printf("%-20s ", s_room);
148 if (www) printf("</TD><TD>");
149 printf("%-24s\n", s_host);
150 if (www) printf("</TD><TD>%s</TD></TR>\n", s_client);
155 if (www) printf("</TABLE></CENTER>\n"
157 "(This display will automatically refresh "
158 "once per minute)</FONT>\n"
162 return (r / 100 == 2) ? 0 : r;
166 #ifndef HAVE_STRERROR
168 * replacement strerror() for systems that don't have it
170 char *strerror(int e)
174 snprintf(buf, sizeof buf, "errno = %d",e);