4 * Command-line "who is online?" utility
15 #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 */
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 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
73 fprintf(stderr, "Server not available: %s\n", strerror(errno));
76 CtdlIPC_getline(ipc, buf);
77 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
78 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
81 strcpy(nodetitle, "this BBS");
82 r = CtdlIPCServerInfo(ipc, buf);
84 my_pid = ipc->ServInfo.pid;
85 strcpy(nodetitle, ipc->ServInfo.humannode);
89 printf( "Content-type: text/html\n"
92 "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"60\">\n"
94 printf("%s: who is online", nodetitle);
95 printf( "</TITLE></HEAD><BODY><H1>");
101 printf("<CENTER><H1>");
104 printf("Users currently logged on to %s\n", nodetitle);
110 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
112 fprintf(stderr,"%s: %s\n",argv[0], buf);
117 printf( "<TABLE BORDER=1 WIDTH=100%%>"
118 "<TR><TH>Session</TH><TH>User name</TH>"
119 "<TH>Room</TH><TH>From host</TH>"
120 "<TH>Client software</TH></TR>\n");
123 printf( "Session User name "
125 printf( "------- ------------------------- "
126 "------------------- ------------------------\n");
130 while (strlen(listing) > 0) {
131 extract_token(buf, listing, 0, '\n');
132 remove_token(listing, 0, '\n');
134 /* Escape some stuff if we're using www mode */
135 if (www) escapize(buf, sizeof buf);
137 s_pid = extract_int(buf,0);
138 extract(s_user,buf,1);
139 extract(s_room,buf,2);
140 extract(s_host,buf,3);
141 extract(s_client,buf,4);
142 if (s_pid != my_pid) {
144 if (www) printf("<TR><TD>");
145 printf("%-7d", s_pid);
147 ((s_pid == my_pid) ? '*' : ' '));
148 if (www) printf("</TD><TD>");
149 printf("%-26s", s_user);
150 if (www) printf("</TD><TD>");
151 printf("%-19s ", s_room);
152 if (www) printf("</TD><TD>");
153 printf("%-24s\n", s_host);
154 if (www) printf("</TD><TD>%s</TD></TR>\n", s_client);
159 if (www) printf("</TABLE></CENTER>\n"
161 "(This display will automatically refresh "
162 "once per minute)</FONT>\n"
165 r = CtdlIPCQuit(ipc);
166 return (r / 100 == 2) ? 0 : r;
170 #ifndef HAVE_STRERROR
172 * replacement strerror() for systems that don't have it
174 char *strerror(int e)
178 snprintf(buf, sizeof buf, "errno = %d",e);