4 * Citadel/UX call log stats program
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
17 # include <sys/time.h>
32 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
34 #define GRANULARITY 100
44 void logoff(int code) {
51 if (batch_mode == 0) {
52 printf("Press return to continue...");
53 fgets(buf, 16, stdin);
59 int halfhour(time_t time)
60 { /* Returns half-hour time period of time */
63 tm = (struct tm *) localtime(&time);
64 a = (tm->tm_hour) * 3;
65 if ((tm->tm_min) > 19)
67 if ((tm->tm_min) > 39)
74 void progress(long int curr, long int max)
80 printf("--------------------------------------");
81 printf("--------------------------------------\r");
85 pos = (curr * 72) / max;
102 int main(int argc, char **argv)
104 char hostbuf[SIZ], portbuf[SIZ];
106 unsigned int LogType;
114 long cftime, cttime, aa;
115 int calls, logins, newusers;
116 int badpws, terms, drops, sleeps;
117 time_t from, to, tottime;
118 int days, hours, minutes;
121 struct caller *callers = NULL;
122 struct caller *callptr = NULL;
124 char thegraph[GRANULARITY][73];
130 for (a = 0; a < argc; ++a) {
131 if (!strcmp(argv[a], "-b"))
133 if (!strcmp(argv[a], "-p"))
138 for (a = 0; a < GRANULARITY; ++a)
140 "........................................................................");
150 for (a = 0; a < 72; ++a) {
166 logfp = fopen("citadel.log", "r");
168 perror("Could not open citadel.log");
172 printf("Scanning call log, please wait...\n");
174 while (fgets(buf, sizeof buf, logfp) != NULL) {
175 buf[strlen(buf) - 1] = 0;
178 LogTime = atol(strtok(buf, "|"));
179 LogType = atol(strtok(NULL, "|"));
180 strcpy(LogName, strtok(NULL, "|"));
182 if ( (LogType != 0) && (LogTime > 100L)
183 && (LogTime <= now) ) {
184 if ((LogTime < from) || (from == 0L))
186 if ((LogTime > to) || (to == 0L))
189 if (LogType & CL_CONNECT) {
194 strcpy(dname, LogName);
196 if (LogType & CL_LOGIN) {
199 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
200 if (!strcmp(callptr->Cname, LogName)) {
202 ++callptr->Ctimescalled;
206 callptr = (struct caller *) malloc(sizeof(struct caller));
207 callptr->next = callers;
209 strcpy(callers->Cname, LogName);
210 callers->Ctimescalled = 1;
213 if (LogType & CL_NEWUSER)
215 if (LogType & CL_BADPW)
217 if (LogType & CL_TERMINATE) {
222 for (aa = cftime; aa <= cttime; aa = aa + 300L)
223 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
228 if (LogType & CL_DROPCARR) {
233 for (aa = cftime; aa <= cttime; aa = aa + 300L)
234 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
239 if (LogType & CL_SLEEPING) {
244 for (aa = cftime; aa <= cttime; aa = aa + 300L)
245 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
257 days = (int) (tottime / 86400L);
258 hours = (int) ((tottime % 86400L) / 3600L);
259 minutes = (int) ((tottime % 3600L) / 60L);
261 printf(" Avg/Call Avg/Day Total\n");
262 disply("Calls:", calls);
263 disply("Logins:", logins);
264 disply("New users:", newusers);
265 disply("Bad pw attempts:", badpws);
266 disply("Proper logoffs:", terms);
267 disply("Carrier drops:", drops);
268 disply("Sleeping drops:", sleeps);
271 tm = (struct tm *) localtime(&from);
272 printf("From: %s", (char *) asctime(localtime(&from)));
273 printf("To: %s", (char *) asctime(localtime(&to)));
274 printf("Total report time: ");
275 printf("%d days, %d hours, %d minutes\n",
276 days, hours, minutes);
278 for (aa = from; aa <= to; aa = aa + 1200L)
279 timeup[halfhour(aa)] = timeup[halfhour(aa)] + 20L;
282 lowest = GRANULARITY - 1;
283 for (b = 0; b < 72; ++b) {
284 for (a = 0; a <= GRANULARITY; ++a) {
285 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
288 thegraph[(GRANULARITY - 1) - a][b] = '#';
289 if (lowest > (GRANULARITY - 1) - a)
290 lowest = (GRANULARITY - 1) - a;
295 printf("\n\n\n\n\n\n");
297 b = ((GRANULARITY - lowest) / 18);
300 for (a = lowest; a < GRANULARITY; a = a + b)
301 printf("%2d%% |%s\n",
304 printf(" +------------------------------------------------------------------------\n");
305 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");
312 printf("Top 20 Callers (sorted by total number of logins)\n");
313 printf("Calls Avg/Day Username\n");
314 printf("----- ------- ------------------------------\n");
316 sortpipe = (FILE *) popen("sort |tail -20 |sort -nr", "w");
317 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
318 fprintf(sortpipe, "%5d %7.2f %-30s\n",
319 callptr->Ctimescalled,
320 (((float) callptr->Ctimescalled) / ((float) days)),
324 while (callers != NULL) {
325 callptr = callers->next;
331 PC_ONLY_HERE:; /* yes this semicolon is necessary; the DEC C compiler
332 complains that a label must be followed by an actual
336 printf("Top 20 Contributing Users (post to call ratio)\n");
337 printf("P/C Ratio Username\n");
338 printf("--------- ------------------------------\n");
340 sortpipe = (FILE *) popen("sort |tail -20 |sort -nr", "w");
344 fakeargs[0] = "whobbs";
345 fakeargs[1] = "localhost";
346 fakeargs[2] = malloc(64);
347 snprintf(fakeargs[2], 64, "%d", config.c_port_number);
349 attach_to_server(3, fakeargs, hostbuf, portbuf);
352 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
353 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
358 if (buf[0]=='1') while (serv_gets(buf),
359 strcmp(buf, "000")) {
360 extract(LogName, buf, 0);
361 fprintf(sortpipe, "%9.2f %-30s\n",
362 ((float) extract_int(buf,5) / (float) extract_int(buf,4)),