1 /* Citadel/UX call log stats program
17 #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y)
19 #define GRANULARITY 100
29 void logoff(int code) {
36 if (batch_mode == 0) {
37 printf("Press return to continue...");
38 fgets(buf, 16, stdin);
44 int halfhour(time_t time)
45 { /* Returns half-hour time period of time */
48 tm = (struct tm *) localtime(&time);
49 a = (tm->tm_hour) * 3;
50 if ((tm->tm_min) > 19)
52 if ((tm->tm_min) > 39)
59 void progress(long int curr, long int max)
65 printf("--------------------------------------");
66 printf("--------------------------------------\r");
70 pos = (curr * 72) / max;
87 int main(int argc, char **argv)
89 char hostbuf[256], portbuf[256];
99 long cftime, cttime, aa;
100 int calls, logins, newusers;
101 int badpws, terms, drops, sleeps;
102 time_t from, to, tottime;
103 int days, hours, minutes;
106 struct caller *callers = NULL;
107 struct caller *callptr = NULL;
109 char thegraph[GRANULARITY][73];
115 for (a = 0; a < argc; ++a) {
116 if (!strcmp(argv[a], "-b"))
118 if (!strcmp(argv[a], "-p"))
123 for (a = 0; a < GRANULARITY; ++a)
125 "........................................................................");
135 for (a = 0; a < 72; ++a) {
151 logfp = fopen("citadel.log", "r");
153 perror("Could not open citadel.log");
157 printf("Scanning call log, please wait...\n");
159 while (fgets(buf, 256, logfp) != NULL) {
160 buf[strlen(buf) - 1] = 0;
163 LogTime = atol(strtok(buf, "|"));
164 LogType = atol(strtok(NULL, "|"));
165 strcpy(LogName, strtok(NULL, "|"));
167 if ( (LogType != 0) && (LogTime > 100L)
168 && (LogTime <= now) ) {
169 if ((LogTime < from) || (from == 0L))
171 if ((LogTime > to) || (to == 0L))
174 if (LogType & CL_CONNECT) {
179 strcpy(dname, LogName);
181 if (LogType & CL_LOGIN) {
184 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
185 if (!strcmp(callptr->Cname, LogName)) {
187 ++callptr->Ctimescalled;
191 callptr = (struct caller *) malloc(sizeof(struct caller));
192 callptr->next = callers;
194 strcpy(callers->Cname, LogName);
195 callers->Ctimescalled = 1;
198 if (LogType & CL_NEWUSER)
200 if (LogType & CL_BADPW)
202 if (LogType & CL_TERMINATE) {
207 for (aa = cftime; aa <= cttime; aa = aa + 300L)
208 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
213 if (LogType & CL_DROPCARR) {
218 for (aa = cftime; aa <= cttime; aa = aa + 300L)
219 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
224 if (LogType & CL_SLEEPING) {
229 for (aa = cftime; aa <= cttime; aa = aa + 300L)
230 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
242 days = (int) (tottime / 86400L);
243 hours = (int) ((tottime % 86400L) / 3600L);
244 minutes = (int) ((tottime % 3600L) / 60L);
246 printf(" Avg/Call Avg/Day Total\n");
247 disply("Calls:", calls);
248 disply("Logins:", logins);
249 disply("New users:", newusers);
250 disply("Bad pw attempts:", badpws);
251 disply("Proper logoffs:", terms);
252 disply("Carrier drops:", drops);
253 disply("Sleeping drops:", sleeps);
256 tm = (struct tm *) localtime(&from);
257 printf("From: %s", (char *) asctime(localtime(&from)));
258 printf("To: %s", (char *) asctime(localtime(&to)));
259 printf("Total report time: ");
260 printf("%d days, %d hours, %d minutes\n",
261 days, hours, minutes);
263 for (aa = from; aa <= to; aa = aa + 1200L)
264 timeup[halfhour(aa)] = timeup[halfhour(aa)] + 20L;
267 lowest = GRANULARITY - 1;
268 for (b = 0; b < 72; ++b) {
269 for (a = 0; a <= GRANULARITY; ++a) {
270 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
273 thegraph[(GRANULARITY - 1) - a][b] = '#';
274 if (lowest > (GRANULARITY - 1) - a)
275 lowest = (GRANULARITY - 1) - a;
280 printf("\n\n\n\n\n\n");
282 b = ((GRANULARITY - lowest) / 18);
285 for (a = lowest; a < GRANULARITY; a = a + b)
286 printf("%2d%% |%s\n",
289 printf(" +------------------------------------------------------------------------\n");
290 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");
297 printf("Top 20 Callers (sorted by total number of logins)\n");
298 printf("Calls Avg/Day Username\n");
299 printf("----- ------- ------------------------------\n");
301 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
302 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
303 fprintf(sortpipe, "%5d %7.2f %-30s\n",
304 callptr->Ctimescalled,
305 (((float) callptr->Ctimescalled) / ((float) days)),
309 while (callers != NULL) {
310 callptr = callers->next;
316 PC_ONLY_HERE:; /* yes this semicolon is necessary; the DEC C compiler
317 complains that a label must be followed by an actual
321 printf("Top 20 Contributing Users (post to call ratio)\n");
322 printf("P/C Ratio Username\n");
323 printf("--------- ------------------------------\n");
325 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
329 fakeargs[0] = "whobbs";
330 fakeargs[1] = "localhost";
331 fakeargs[2] = malloc(64);
332 sprintf(fakeargs[2], "%d", config.c_port_number);
334 attach_to_server(3, fakeargs, hostbuf, portbuf);
337 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
338 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
343 if (buf[0]=='1') while (serv_gets(buf),
344 strcmp(buf, "000")) {
345 extract(LogName, buf, 0);
346 fprintf(sortpipe, "%9.2f %-30s\n",
347 ((float) extract_int(buf,5) / (float) extract_int(buf,4)),