1 /* Citadel/UX call log stats program
14 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
16 #define GRANULARITY 100
34 printf ("Press return to continue...");
35 fgets (buf, 16, stdin);
44 halfhour (long int time) /* Returns half-hour time period of time */
49 tm = (struct tm *) localtime (&time);
50 a = (tm->tm_hour) * 3;
51 if ((tm->tm_min) > 19)
53 if ((tm->tm_min) > 39)
61 progress (long int curr, long int max)
68 printf ("--------------------------------------");
69 printf ("--------------------------------------\r");
74 pos = (curr * 72) / max;
95 main (int argc, char **argv)
106 long cftime, cttime, aa;
107 int calls, logins, newusers;
108 int badpws, terms, drops, sleeps;
109 long from, to, tottime;
110 int days, hours, minutes;
113 struct caller *callers = NULL;
114 struct caller *callptr = NULL;
116 char thegraph[GRANULARITY][73];
121 for (a = 0; a < argc; ++a)
123 if (!strcmp (argv[a], "-b"))
125 if (!strcmp (argv[a], "-p"))
130 for (a = 0; a < GRANULARITY; ++a)
132 "........................................................................");
140 printf ("Scanning call log, please wait...\n\n\n\n");
144 for (a = 0; a < 72; ++a)
161 logfp = fopen ("citadel.log", "r");
164 perror ("Could not open citadel.log");
171 printf ("Scanning call log, please wait...\n");
173 while (fgets (buf, 256, logfp) != NULL)
175 buf[strlen (buf) - 1] = 0;
177 LogTime = atol (strtok (buf, "|"));
178 LogType = atol (strtok (NULL, "|"));
179 strcpy (LogName, strtok (NULL, "|"));
183 if ((LogTime < from) || (from == 0L))
185 if ((LogTime > to) || (to == 0L))
188 if (LogType & CL_CONNECT)
194 strcpy (dname, LogName);
196 if (LogType & CL_LOGIN)
200 for (callptr = callers; callptr != NULL; callptr = callptr->next)
202 if (!strcmp (callptr->Cname, LogName))
205 ++callptr->Ctimescalled;
210 callptr = (struct caller *) malloc (sizeof (struct caller));
211 callptr->next = callers;
213 strcpy (callers->Cname, LogName);
214 callers->Ctimescalled = 1;
217 if (LogType & CL_NEWUSER)
219 if (LogType & CL_BADPW)
221 if (LogType & CL_TERMINATE)
228 for (aa = cftime; aa <= cttime; aa = aa + 300L)
229 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
234 if (LogType & CL_DROPCARR)
241 for (aa = cftime; aa <= cttime; aa = aa + 300L)
242 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
247 if (LogType & CL_SLEEPING)
254 for (aa = cftime; aa <= cttime; aa = aa + 300L)
255 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
268 days = (int) (tottime / 86400L);
269 hours = (int) ((tottime % 86400L) / 3600L);
270 minutes = (int) ((tottime % 3600L) / 60L);
272 printf (" Avg/Call Avg/Day Total\n");
273 disply ("Calls:", calls);
274 disply ("Logins:", logins);
275 disply ("New users:", newusers);
276 disply ("Bad pw attempts:", badpws);
277 disply ("Proper logoffs:", terms);
278 disply ("Carrier drops:", drops);
279 disply ("Sleeping drops:", sleeps);
282 tm = (struct tm *) localtime (&from);
283 printf ("From: %s", (char *) asctime (localtime (&from)));
284 printf ("To: %s", (char *) asctime (localtime (&to)));
285 printf ("Total report time: ");
286 printf ("%d days, %d hours, %d minutes\n",
287 days, hours, minutes);
289 for (aa = from; aa <= to; aa = aa + 1200L)
290 timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
293 lowest = GRANULARITY - 1;
294 for (b = 0; b < 72; ++b)
296 for (a = 0; a <= GRANULARITY; ++a)
298 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
302 thegraph[(GRANULARITY - 1) - a][b] = '#';
303 if (lowest > (GRANULARITY - 1) - a)
304 lowest = (GRANULARITY - 1) - a;
309 printf ("\n\n\n\n\n\n");
311 b = ((GRANULARITY - lowest) / 18);
314 for (a = lowest; a < GRANULARITY; a = a + b)
315 printf ("%2d%% |%s\n",
318 printf (" +------------------------------------------------------------------------\n");
319 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");
326 printf ("Top 20 Callers (sorted by total number of logins)\n");
327 printf ("Calls Avg/Day Username\n");
328 printf ("----- ------- ------------------------------\n");
330 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
331 for (callptr = callers; callptr != NULL; callptr = callptr->next)
333 fprintf (sortpipe, "%5d %7.2f %-30s\n",
334 callptr->Ctimescalled,
335 (((float) callptr->Ctimescalled) / ((float) days)),
339 while (callers != NULL)
341 callptr = callers->next;
351 This report doesn't work anymore, because it requires reading the user
352 file directly, which can't happen.
353 printf ("Top 20 Contributing Users (post to call ratio)\n");
354 printf ("P/C Ratio Username\n");
355 printf ("--------- ------------------------------\n");
357 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
358 fp = fopen ("usersupp", "r");
360 && (fread ((char *) &usersupp, sizeof (struct usersupp), 1, fp) > 0))
362 fprintf (sortpipe, "%9.2f %-30s\n",
363 ((float) usersupp.posted / (float) usersupp.timescalled),