4 * Citadel/UX call log stats program
21 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
23 #define GRANULARITY 100
33 void logoff(int code) {
40 if (batch_mode == 0) {
41 printf("Press return to continue...");
42 fgets(buf, 16, stdin);
48 int halfhour(time_t time)
49 { /* Returns half-hour time period of time */
52 tm = (struct tm *) localtime(&time);
53 a = (tm->tm_hour) * 3;
54 if ((tm->tm_min) > 19)
56 if ((tm->tm_min) > 39)
63 void progress(long int curr, long int max)
69 printf("--------------------------------------");
70 printf("--------------------------------------\r");
74 pos = (curr * 72) / max;
91 int main(int argc, char **argv)
93 char hostbuf[256], portbuf[256];
103 long cftime, cttime, aa;
104 int calls, logins, newusers;
105 int badpws, terms, drops, sleeps;
106 time_t from, to, tottime;
107 int days, hours, minutes;
110 struct caller *callers = NULL;
111 struct caller *callptr = NULL;
113 char thegraph[GRANULARITY][73];
119 for (a = 0; a < argc; ++a) {
120 if (!strcmp(argv[a], "-b"))
122 if (!strcmp(argv[a], "-p"))
127 for (a = 0; a < GRANULARITY; ++a)
129 "........................................................................");
139 for (a = 0; a < 72; ++a) {
155 logfp = fopen("citadel.log", "r");
157 perror("Could not open citadel.log");
161 printf("Scanning call log, please wait...\n");
163 while (fgets(buf, 256, logfp) != NULL) {
164 buf[strlen(buf) - 1] = 0;
167 LogTime = atol(strtok(buf, "|"));
168 LogType = atol(strtok(NULL, "|"));
169 strcpy(LogName, strtok(NULL, "|"));
171 if ( (LogType != 0) && (LogTime > 100L)
172 && (LogTime <= now) ) {
173 if ((LogTime < from) || (from == 0L))
175 if ((LogTime > to) || (to == 0L))
178 if (LogType & CL_CONNECT) {
183 strcpy(dname, LogName);
185 if (LogType & CL_LOGIN) {
188 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
189 if (!strcmp(callptr->Cname, LogName)) {
191 ++callptr->Ctimescalled;
195 callptr = (struct caller *) malloc(sizeof(struct caller));
196 callptr->next = callers;
198 strcpy(callers->Cname, LogName);
199 callers->Ctimescalled = 1;
202 if (LogType & CL_NEWUSER)
204 if (LogType & CL_BADPW)
206 if (LogType & CL_TERMINATE) {
211 for (aa = cftime; aa <= cttime; aa = aa + 300L)
212 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
217 if (LogType & CL_DROPCARR) {
222 for (aa = cftime; aa <= cttime; aa = aa + 300L)
223 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
228 if (LogType & CL_SLEEPING) {
233 for (aa = cftime; aa <= cttime; aa = aa + 300L)
234 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
246 days = (int) (tottime / 86400L);
247 hours = (int) ((tottime % 86400L) / 3600L);
248 minutes = (int) ((tottime % 3600L) / 60L);
250 printf(" Avg/Call Avg/Day Total\n");
251 disply("Calls:", calls);
252 disply("Logins:", logins);
253 disply("New users:", newusers);
254 disply("Bad pw attempts:", badpws);
255 disply("Proper logoffs:", terms);
256 disply("Carrier drops:", drops);
257 disply("Sleeping drops:", sleeps);
260 tm = (struct tm *) localtime(&from);
261 printf("From: %s", (char *) asctime(localtime(&from)));
262 printf("To: %s", (char *) asctime(localtime(&to)));
263 printf("Total report time: ");
264 printf("%d days, %d hours, %d minutes\n",
265 days, hours, minutes);
267 for (aa = from; aa <= to; aa = aa + 1200L)
268 timeup[halfhour(aa)] = timeup[halfhour(aa)] + 20L;
271 lowest = GRANULARITY - 1;
272 for (b = 0; b < 72; ++b) {
273 for (a = 0; a <= GRANULARITY; ++a) {
274 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
277 thegraph[(GRANULARITY - 1) - a][b] = '#';
278 if (lowest > (GRANULARITY - 1) - a)
279 lowest = (GRANULARITY - 1) - a;
284 printf("\n\n\n\n\n\n");
286 b = ((GRANULARITY - lowest) / 18);
289 for (a = lowest; a < GRANULARITY; a = a + b)
290 printf("%2d%% |%s\n",
293 printf(" +------------------------------------------------------------------------\n");
294 printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n");
301 printf("Top 20 Callers (sorted by total number of logins)\n");
302 printf("Calls Avg/Day Username\n");
303 printf("----- ------- ------------------------------\n");
305 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
306 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
307 fprintf(sortpipe, "%5d %7.2f %-30s\n",
308 callptr->Ctimescalled,
309 (((float) callptr->Ctimescalled) / ((float) days)),
313 while (callers != NULL) {
314 callptr = callers->next;
320 PC_ONLY_HERE:; /* yes this semicolon is necessary; the DEC C compiler
321 complains that a label must be followed by an actual
325 printf("Top 20 Contributing Users (post to call ratio)\n");
326 printf("P/C Ratio Username\n");
327 printf("--------- ------------------------------\n");
329 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
333 fakeargs[0] = "whobbs";
334 fakeargs[1] = "localhost";
335 fakeargs[2] = malloc(64);
336 sprintf(fakeargs[2], "%d", config.c_port_number);
338 attach_to_server(3, fakeargs, hostbuf, portbuf);
341 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
342 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
347 if (buf[0]=='1') while (serv_gets(buf),
348 strcmp(buf, "000")) {
349 extract(LogName, buf, 0);
350 fprintf(sortpipe, "%9.2f %-30s\n",
351 ((float) extract_int(buf,5) / (float) extract_int(buf,4)),