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
25 void get_config (void);
35 printf ("Press return to continue...");
36 fgets (buf, 16, stdin);
45 halfhour (long int 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)
62 progress (long int curr, long int max)
69 printf ("--------------------------------------");
70 printf ("--------------------------------------\r");
75 pos = (curr * 72) / max;
96 main (int argc, char **argv)
107 long cftime, cttime, aa;
108 int calls, logins, newusers;
109 int badpws, terms, drops, sleeps;
110 long from, to, tottime;
111 int days, hours, minutes;
114 struct caller *callers = NULL;
115 struct caller *callptr = NULL;
117 char thegraph[GRANULARITY][73];
122 for (a = 0; a < argc; ++a)
124 if (!strcmp (argv[a], "-b"))
126 if (!strcmp (argv[a], "-p"))
131 for (a = 0; a < GRANULARITY; ++a)
133 "........................................................................");
141 printf ("Scanning call log, please wait...\n\n\n\n");
145 for (a = 0; a < 72; ++a)
162 logfp = fopen ("citadel.log", "r");
165 perror ("Could not open citadel.log");
172 printf ("Scanning call log, please wait...\n");
174 while (fgets (buf, 256, logfp) != NULL)
176 buf[strlen (buf) - 1] = 0;
178 LogTime = atol (strtok (buf, "|"));
179 LogType = atol (strtok (NULL, "|"));
180 strcpy (LogName, strtok (NULL, "|"));
184 if ((LogTime < from) || (from == 0L))
186 if ((LogTime > to) || (to == 0L))
189 if (LogType & CL_CONNECT)
195 strcpy (dname, LogName);
197 if (LogType & CL_LOGIN)
201 for (callptr = callers; callptr != NULL; callptr = callptr->next)
203 if (!strcmp (callptr->Cname, LogName))
206 ++callptr->Ctimescalled;
211 callptr = (struct caller *) malloc (sizeof (struct caller));
212 callptr->next = callers;
214 strcpy (callers->Cname, LogName);
215 callers->Ctimescalled = 1;
218 if (LogType & CL_NEWUSER)
220 if (LogType & CL_BADPW)
222 if (LogType & CL_TERMINATE)
229 for (aa = cftime; aa <= cttime; aa = aa + 300L)
230 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
235 if (LogType & CL_DROPCARR)
242 for (aa = cftime; aa <= cttime; aa = aa + 300L)
243 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
248 if (LogType & CL_SLEEPING)
255 for (aa = cftime; aa <= cttime; aa = aa + 300L)
256 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
269 days = (int) (tottime / 86400L);
270 hours = (int) ((tottime % 86400L) / 3600L);
271 minutes = (int) ((tottime % 3600L) / 60L);
273 printf (" Avg/Call Avg/Day Total\n");
274 disply ("Calls:", calls);
275 disply ("Logins:", logins);
276 disply ("New users:", newusers);
277 disply ("Bad pw attempts:", badpws);
278 disply ("Proper logoffs:", terms);
279 disply ("Carrier drops:", drops);
280 disply ("Sleeping drops:", sleeps);
283 tm = (struct tm *) localtime (&from);
284 printf ("From: %s", (char *) asctime (localtime (&from)));
285 printf ("To: %s", (char *) asctime (localtime (&to)));
286 printf ("Total report time: ");
287 printf ("%d days, %d hours, %d minutes\n",
288 days, hours, minutes);
290 for (aa = from; aa <= to; aa = aa + 1200L)
291 timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
294 lowest = GRANULARITY - 1;
295 for (b = 0; b < 72; ++b)
297 for (a = 0; a <= GRANULARITY; ++a)
299 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
303 thegraph[(GRANULARITY - 1) - a][b] = '#';
304 if (lowest > (GRANULARITY - 1) - a)
305 lowest = (GRANULARITY - 1) - a;
310 printf ("\n\n\n\n\n\n");
312 b = ((GRANULARITY - lowest) / 18);
315 for (a = lowest; a < GRANULARITY; a = a + b)
316 printf ("%2d%% |%s\n",
319 printf (" +------------------------------------------------------------------------\n");
320 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");
327 printf ("Top 20 Callers (sorted by total number of logins)\n");
328 printf ("Calls Avg/Day Username\n");
329 printf ("----- ------- ------------------------------\n");
331 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
332 for (callptr = callers; callptr != NULL; callptr = callptr->next)
334 fprintf (sortpipe, "%5d %7.2f %-30s\n",
335 callptr->Ctimescalled,
336 (((float) callptr->Ctimescalled) / ((float) days)),
340 while (callers != NULL)
342 callptr = callers->next;
352 This report doesn't work anymore, because it requires reading the user
353 file directly, which can't happen.
354 printf ("Top 20 Contributing Users (post to call ratio)\n");
355 printf ("P/C Ratio Username\n");
356 printf ("--------- ------------------------------\n");
358 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
359 fp = fopen ("usersupp", "r");
361 && (fread ((char *) &usersupp, sizeof (struct usersupp), 1, fp) > 0))
363 fprintf (sortpipe, "%9.2f %-30s\n",
364 ((float) usersupp.posted / (float) usersupp.timescalled),