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)
98 long cftime, cttime, aa;
99 int calls, logins, newusers;
100 int badpws, terms, drops, sleeps;
101 time_t from, to, tottime;
102 int days, hours, minutes;
105 struct caller *callers = NULL;
106 struct caller *callptr = NULL;
108 char thegraph[GRANULARITY][73];
114 for (a = 0; a < argc; ++a) {
115 if (!strcmp(argv[a], "-b"))
117 if (!strcmp(argv[a], "-p"))
122 for (a = 0; a < GRANULARITY; ++a)
124 "........................................................................");
134 for (a = 0; a < 72; ++a) {
150 logfp = fopen("citadel.log", "r");
152 perror("Could not open citadel.log");
156 printf("Scanning call log, please wait...\n");
158 while (fgets(buf, 256, logfp) != NULL) {
159 buf[strlen(buf) - 1] = 0;
162 LogTime = atol(strtok(buf, "|"));
163 LogType = atol(strtok(NULL, "|"));
164 strcpy(LogName, strtok(NULL, "|"));
166 if ( (LogType != 0) && (LogTime > 100L)
167 && (LogTime <= now) ) {
168 if ((LogTime < from) || (from == 0L))
170 if ((LogTime > to) || (to == 0L))
173 if (LogType & CL_CONNECT) {
178 strcpy(dname, LogName);
180 if (LogType & CL_LOGIN) {
183 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
184 if (!strcmp(callptr->Cname, LogName)) {
186 ++callptr->Ctimescalled;
190 callptr = (struct caller *) malloc(sizeof(struct caller));
191 callptr->next = callers;
193 strcpy(callers->Cname, LogName);
194 callers->Ctimescalled = 1;
197 if (LogType & CL_NEWUSER)
199 if (LogType & CL_BADPW)
201 if (LogType & CL_TERMINATE) {
206 for (aa = cftime; aa <= cttime; aa = aa + 300L)
207 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
212 if (LogType & CL_DROPCARR) {
217 for (aa = cftime; aa <= cttime; aa = aa + 300L)
218 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
223 if (LogType & CL_SLEEPING) {
228 for (aa = cftime; aa <= cttime; aa = aa + 300L)
229 timeon[halfhour(aa)] = timeon[halfhour(aa)] + 5L;
241 days = (int) (tottime / 86400L);
242 hours = (int) ((tottime % 86400L) / 3600L);
243 minutes = (int) ((tottime % 3600L) / 60L);
245 printf(" Avg/Call Avg/Day Total\n");
246 disply("Calls:", calls);
247 disply("Logins:", logins);
248 disply("New users:", newusers);
249 disply("Bad pw attempts:", badpws);
250 disply("Proper logoffs:", terms);
251 disply("Carrier drops:", drops);
252 disply("Sleeping drops:", sleeps);
255 tm = (struct tm *) localtime(&from);
256 printf("From: %s", (char *) asctime(localtime(&from)));
257 printf("To: %s", (char *) asctime(localtime(&to)));
258 printf("Total report time: ");
259 printf("%d days, %d hours, %d minutes\n",
260 days, hours, minutes);
262 for (aa = from; aa <= to; aa = aa + 1200L)
263 timeup[halfhour(aa)] = timeup[halfhour(aa)] + 20L;
266 lowest = GRANULARITY - 1;
267 for (b = 0; b < 72; ++b) {
268 for (a = 0; a <= GRANULARITY; ++a) {
269 p = ((float) timeon[b]) / ((float) timeup[b]) * GRANULARITY;
272 thegraph[(GRANULARITY - 1) - a][b] = '#';
273 if (lowest > (GRANULARITY - 1) - a)
274 lowest = (GRANULARITY - 1) - a;
279 printf("\n\n\n\n\n\n");
281 b = ((GRANULARITY - lowest) / 18);
284 for (a = lowest; a < GRANULARITY; a = a + b)
285 printf("%2d%% |%s\n",
288 printf(" +------------------------------------------------------------------------\n");
289 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");
296 printf("Top 20 Callers (sorted by total number of logins)\n");
297 printf("Calls Avg/Day Username\n");
298 printf("----- ------- ------------------------------\n");
300 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
301 for (callptr = callers; callptr != NULL; callptr = callptr->next) {
302 fprintf(sortpipe, "%5d %7.2f %-30s\n",
303 callptr->Ctimescalled,
304 (((float) callptr->Ctimescalled) / ((float) days)),
308 while (callers != NULL) {
309 callptr = callers->next;
315 PC_ONLY_HERE:; /* yes this semicolon is necessary; the DEC C compiler
316 complains that a label must be followed by an actual
320 printf("Top 20 Contributing Users (post to call ratio)\n");
321 printf("P/C Ratio Username\n");
322 printf("--------- ------------------------------\n");
324 sortpipe = (FILE *) popen("sort |tail -20 |sort -r", "w");
328 fakeargs[0] = "whobbs";
329 fakeargs[1] = "localhost";
330 fakeargs[2] = malloc(64);
331 sprintf(fakeargs[2], "%d", config.c_port_number);
333 attach_to_server(3, fakeargs);
336 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
337 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
342 if (buf[0]=='1') while (serv_gets(buf),
343 strcmp(buf, "000")) {
344 extract(LogName, buf, 0);
345 fprintf(sortpipe, "%9.2f %-30s\n",
346 ((float) extract_int(buf,5) / (float) extract_int(buf,4)),