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;
105 struct usersupp usersupp;
112 long cftime, cttime, aa;
113 int calls, logins, newusers;
114 int badpws, terms, drops, sleeps;
115 long from, to, tottime;
116 int days, hours, minutes;
119 struct caller *callers = NULL;
120 struct caller *callptr = NULL;
122 char thegraph[GRANULARITY][73];
127 for (a = 0; a < argc; ++a)
129 if (!strcmp (argv[a], "-b"))
131 if (!strcmp (argv[a], "-p"))
136 for (a = 0; a < GRANULARITY; ++a)
138 "........................................................................");
146 printf ("Scanning call log, please wait...\n\n\n\n");
150 for (a = 0; a < 72; ++a)
167 logfp = fopen ("citadel.log", "r");
170 perror ("Could not open citadel.log");
177 printf ("Scanning call log, please wait...\n");
179 while (fgets (buf, 256, logfp) != NULL)
181 buf[strlen (buf) - 1] = 0;
183 LogTime = atol (strtok (buf, "|"));
184 LogType = atol (strtok (NULL, "|"));
185 strcpy (LogName, strtok (NULL, "|"));
189 if ((LogTime < from) || (from == 0L))
191 if ((LogTime > to) || (to == 0L))
194 if (LogType & CL_CONNECT)
200 strcpy (dname, LogName);
202 if (LogType & CL_LOGIN)
206 for (callptr = callers; callptr != NULL; callptr = callptr->next)
208 if (!strcmp (callptr->Cname, LogName))
211 ++callptr->Ctimescalled;
216 callptr = (struct caller *) malloc (sizeof (struct caller));
217 callptr->next = callers;
219 strcpy (callers->Cname, LogName);
220 callers->Ctimescalled = 1;
223 if (LogType & CL_NEWUSER)
225 if (LogType & CL_BADPW)
227 if (LogType & CL_TERMINATE)
234 for (aa = cftime; aa <= cttime; aa = aa + 300L)
235 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
240 if (LogType & CL_DROPCARR)
247 for (aa = cftime; aa <= cttime; aa = aa + 300L)
248 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
253 if (LogType & CL_SLEEPING)
260 for (aa = cftime; aa <= cttime; aa = aa + 300L)
261 timeon[halfhour (aa)] = timeon[halfhour (aa)] + 5L;
274 days = (int) (tottime / 86400L);
275 hours = (int) ((tottime % 86400L) / 3600L);
276 minutes = (int) ((tottime % 3600L) / 60L);
278 printf (" Avg/Call Avg/Day Total\n");
279 disply ("Calls:", calls);
280 disply ("Logins:", logins);
281 disply ("New users:", newusers);
282 disply ("Bad pw attempts:", badpws);
283 disply ("Proper logoffs:", terms);
284 disply ("Carrier drops:", drops);
285 disply ("Sleeping drops:", sleeps);
288 tm = (struct tm *) localtime (&from);
289 printf ("From: %s", (char *) asctime (localtime (&from)));
290 printf ("To: %s", (char *) asctime (localtime (&to)));
291 printf ("Total report time: ");
292 printf ("%d days, %d hours, %d minutes\n",
293 days, hours, minutes);
295 for (aa = from; aa <= to; aa = aa + 1200L)
296 timeup[halfhour (aa)] = timeup[halfhour (aa)] + 20L;
299 lowest = GRANULARITY - 1;
300 for (b = 0; b < 72; ++b)
302 for (a = 0; a <= GRANULARITY; ++a)
304 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
308 thegraph[(GRANULARITY - 1) - a][b] = '#';
309 if (lowest > (GRANULARITY - 1) - a)
310 lowest = (GRANULARITY - 1) - a;
315 printf ("\n\n\n\n\n\n");
317 b = ((GRANULARITY - lowest) / 18);
320 for (a = lowest; a < GRANULARITY; a = a + b)
321 printf ("%2d%% |%s\n",
324 printf (" +------------------------------------------------------------------------\n");
325 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");
332 printf ("Top 20 Callers (sorted by total number of logins)\n");
333 printf ("Calls Avg/Day Username\n");
334 printf ("----- ------- ------------------------------\n");
336 sortpipe = (FILE *) popen ("sort |tail -20 |sort -r", "w");
337 for (callptr = callers; callptr != NULL; callptr = callptr->next)
339 fprintf (sortpipe, "%5d %7.2f %-30s\n",
340 callptr->Ctimescalled,
341 (((float) callptr->Ctimescalled) / ((float) days)),
345 while (callers != NULL)
347 callptr = callers->next;
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),