1 /* Citadel/UX call log stats program
12 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
14 #define GRANULARITY 100
35 printf ("Press return to continue...");
36 fgets (buf, 16, stdin);
45 halfhour (time) /* Returns half-hour time period of time */
50 tm = (struct tm *) localtime (&time);
51 a = (tm->tm_hour) * 3;
52 if ((tm->tm_min) > 19)
54 if ((tm->tm_min) > 39)
71 printf ("--------------------------------------");
72 printf ("--------------------------------------\r");
77 pos = (curr * 72) / max;
103 unsigned int LogType;
111 long cftime, cttime, aa;
112 int calls, logins, newusers;
113 int badpws, terms, drops, sleeps;
114 long from, to, tottime;
115 int days, hours, minutes;
118 struct caller *callers = NULL;
119 struct caller *callptr = NULL;
121 char thegraph[GRANULARITY][73];
126 for (a = 0; a < argc; ++a)
128 if (!strcmp (argv[a], "-b"))
130 if (!strcmp (argv[a], "-p"))
135 for (a = 0; a < GRANULARITY; ++a)
137 "........................................................................");
145 printf ("Scanning call log, please wait...\n\n\n\n");
149 for (a = 0; a < 72; ++a)
166 logfp = fopen ("citadel.log", "r");
169 perror ("Could not open citadel.log");
176 printf ("Scanning call log, please wait...\n");
178 while (fgets (buf, 256, logfp) != NULL)
180 buf[strlen (buf) - 1] = 0;
182 LogTime = atol (strtok (buf, "|"));
183 LogType = atol (strtok (NULL, "|"));
184 strcpy (LogName, strtok (NULL, "|"));
188 if ((LogTime < from) || (from == 0L))
190 if ((LogTime > to) || (to == 0L))
193 if (LogType & CL_CONNECT)
199 strcpy (dname, LogName);
201 if (LogType & CL_LOGIN)
205 for (callptr = callers; callptr != NULL; callptr = callptr->next)
207 if (!strcmp (callptr->Cname, LogName))
210 ++callptr->Ctimescalled;
215 callptr = (struct caller *) malloc (sizeof (struct caller));
216 callptr->next = callers;
218 strcpy (callers->Cname, LogName);
219 callers->Ctimescalled = 1;
222 if (LogType & CL_NEWUSER)
224 if (LogType & CL_BADPW)
226 if (LogType & CL_TERMINATE)
233 for (aa = cftime; aa <= cttime; aa = aa + 300L)
234 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
239 if (LogType & CL_DROPCARR)
246 for (aa = cftime; aa <= cttime; aa = aa + 300L)
247 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
252 if (LogType & CL_SLEEPING)
259 for (aa = cftime; aa <= cttime; aa = aa + 300L)
260 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
273 days = (int) (tottime / 86400L);
274 hours = (int) ((tottime % 86400L) / 3600L);
275 minutes = (int) ((tottime % 3600L) / 60L);
277 printf (" Avg/Call Avg/Day Total\n");
278 disply ("Calls:", calls);
279 disply ("Logins:", logins);
280 disply ("New users:", newusers);
281 disply ("Bad pw attempts:", badpws);
282 disply ("Proper logoffs:", terms);
283 disply ("Carrier drops:", drops);
284 disply ("Sleeping drops:", sleeps);
287 tm = (struct tm *) localtime (&from);
288 printf ("From: %s", (char *) asctime (localtime (&from)));
289 printf ("To: %s", (char *) asctime (localtime (&to)));
290 printf ("Total report time: ");
291 printf ("%d days, %d hours, %d minutes\n",
292 days, hours, minutes);
294 for (aa = from; aa <= to; aa = aa + 1200L)
295 timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
298 lowest = GRANULARITY - 1;
299 for (b = 0; b < 72; ++b)
301 for (a = 0; a <= GRANULARITY; ++a)
303 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
307 thegraph[(GRANULARITY - 1) - a][b] = '#';
308 if (lowest > (GRANULARITY - 1) - a)
309 lowest = (GRANULARITY - 1) - a;
314 printf ("\n\n\n\n\n\n");
316 b = ((GRANULARITY - lowest) / 18);
319 for (a = lowest; a < GRANULARITY; a = a + b)
320 printf ("%2d%% |%s\n",
323 printf (" +------------------------------------------------------------------------\n");
324 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");
331 printf ("Top 20 Callers (sorted by total number of logins)\n");
332 printf ("Calls Avg/Day Username\n");
333 printf ("----- ------- ------------------------------\n");
335 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
336 for (callptr = callers; callptr != NULL; callptr = callptr->next)
338 fprintf (sortpipe, "%5d %7.2f %-30s\n",
339 callptr->Ctimescalled,
340 (((float) callptr->Ctimescalled) / ((float) days)),
344 while (callers != NULL)
346 callptr = callers->next;
356 This report doesn't work anymore, because it requires reading the user
357 file directly, which can't happen.
358 printf ("Top 20 Contributing Users (post to call ratio)\n");
359 printf ("P/C Ratio Username\n");
360 printf ("--------- ------------------------------\n");
362 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
363 fp = fopen ("usersupp", "r");
365 && (fread ((char *) &usersupp, sizeof (struct usersupp), 1, fp) > 0))
367 fprintf (sortpipe, "%9.2f %-30s\n",
368 ((float) usersupp.posted / (float) usersupp.timescalled),