4 * Command-line "who is online?" utility
21 static void escapize(char *buf, size_t n) {
28 for (i=0; i<strlen(hold); ++i) {
29 size_t tmp = strlen(buf);
32 snprintf(&buf[tmp], n - tmp, "<");
33 else if (hold[i]=='>')
34 snprintf(&buf[tmp], n - tmp, ">");
36 snprintf(&buf[tmp], n - tmp, """);
38 snprintf(&buf[tmp], n - tmp, "%c", hold[i]);
45 int main(int argc, char **argv)
60 /* If this environment variable is set, we assume that the program
61 * is being called as a cgi-bin from a webserver and will output
64 if (getenv("REQUEST_METHOD") != NULL) www = 1;
66 attach_to_server(argc, argv, hostbuf, portbuf);
68 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
69 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
72 strcpy(nodetitle, "this BBS");
77 while (serv_gets(buf), strcmp(buf,"000")) {
78 if (a==0) my_pid = atoi(buf);
79 if (a==2) strcpy(nodetitle, buf);
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);
109 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
114 printf( "<TABLE BORDER=1 WIDTH=100%%>"
115 "<TR><TH>Session</TH><TH>User name</TH>"
116 "<TH>Room</TH><TH>From host</TH>"
117 "<TH>Client software</TH></TR>\n");
120 printf( "Session User name "
122 printf( "------- ------------------------- "
123 "-------------------- ------------------------\n");
127 while (serv_gets(buf), strcmp(buf,"000")) {
129 /* Escape some stuff if we're using www mode */
130 if (www) escapize(buf, sizeof buf);
132 s_pid = extract_int(buf,0);
133 extract(s_user,buf,1);
134 extract(s_room,buf,2);
135 extract(s_host,buf,3);
136 extract(s_client,buf,4);
137 if (s_pid != my_pid) {
139 if (www) printf("<TR><TD>");
140 printf("%-7d", s_pid);
142 ((s_pid == my_pid) ? '*' : ' '));
143 if (www) printf("</TD><TD>");
144 printf("%-25s", s_user);
145 if (www) printf("</TD><TD>");
146 printf("%-20s ", s_room);
147 if (www) printf("</TD><TD>");
148 printf("%-24s\n", s_host);
149 if (www) printf("</TD><TD>%s</TD></TR>\n", s_client);
153 if (www) printf("</TABLE></CENTER>\n"
155 "(This display will automatically refresh "
156 "once per minute)</FONT>\n"
165 #ifndef HAVE_STRERROR
167 * replacement strerror() for systems that don't have it
169 char *strerror(int e)
173 snprintf(buf, sizeof buf, "errno = %d",e);