/* entry point to generate a report writing it to the fp */ void output_html (GLog * logger, GHolder * holder) { FILE *fp = stdout; char now[DATE_TIME]; generate_time (); strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S", now_tm); print_html_header (fp, now); print_pure_menu (fp, now); print_html_summary (fp, logger); print_html_visitors_report (fp, holder + VISITORS); print_html_request_report (fp, holder + REQUESTS, logger->process); print_html_request_report (fp, holder + REQUESTS_STATIC, logger->process); print_html_request_report (fp, holder + NOT_FOUND, logger->process); print_html_hosts (fp, holder + HOSTS, logger->process); print_html_browser_os (fp, holder + OS); print_html_browser_os (fp, holder + BROWSERS); print_html_generic (fp, holder + REFERRERS, logger->process); print_html_generic (fp, holder + REFERRING_SITES, logger->process); print_html_generic (fp, holder + KEYPHRASES, logger->process); #ifdef HAVE_LIBGEOIP print_html_geolocation (fp, holder + GEO_LOCATION, logger->process); #endif print_html_status (fp, holder + STATUS_CODES, logger->process); print_html_footer (fp); }
int main(void) { char *path = getenv("PATH_INFO"); char *query= getenv("QUERY_STRING"); char **patharray = NULL; char **queryarray = NULL; char *filename; char *category = NULL; int number_of_entries = 0, i = 0, sizeofpath = 0, sizeofquery = 0, feed=0; char *token; int page = 0; int page_entries = 0; struct entry **entries = read_entries(&number_of_entries); struct sidebar *sb = make_sidebar(entries, number_of_entries); struct entry **entries_to_print = entries; struct entry *lonely_entry = NULL; /* GET information from path */ if (path) { token = strtok(path, "/"); if (token) { do { patharray = realloc( patharray, sizeof(char *) * (sizeofpath + 1)); patharray[sizeofpath] = strdup(token); sizeofpath++; } while ((token = strtok(NULL, "/"))); } } /* GET information from query */ if (query) { token = strtok(query, "="); if (token) { do { queryarray = realloc( queryarray, sizeof(char *) * (sizeofquery + 1)); queryarray[sizeofquery] = strdup(token); sizeofquery++; } while ((token = strtok(NULL, "="))); if (sizeofquery > 1 && strcasecmp(queryarray[0], "page") == 0) { if (strlen(queryarray[1]) < 3 && sscanf(queryarray[1], "%d", &page) == 1) { if (page > 0) { page_entries = NUMBEROFENTRIESPERPAGE * page; } } } } } /* Check if this is feed */ if (sizeofpath > 0 && strcasecmp(patharray[sizeofpath-1], "feed") == 0) { feed = 1; } /* Entry, category or month*/ if (sizeofpath > 0 && sizeofpath < 3) { /* Look for category */ for (i = 0; i < sb->number_of_categories; i++) { if (strcasecmp(patharray[0], sb->categories[i]->name) == 0) { category = sb->categories[i]->name; entries_to_print = sb->categories[i]->ent; number_of_entries = sb->categories[i]->number; goto out; } } /* No category found look for months */ for (i = 0; i < sb->number_of_months; i++) { if (strcasecmp(patharray[0], sb->months[i]->name) == 0) { entries_to_print = sb->months[i]->ent; number_of_entries = sb->months[i]->number; goto out; } } /* No months or categories found look one entry */ asprintf(&filename, "%s.txt", patharray[0]); if ((lonely_entry = read_entry(filename))) { number_of_entries = 1; entries_to_print[0] = lonely_entry; } /* Else just show the normal index*/ } out: /* Sort entries according to date */ qsort(entries_to_print, number_of_entries, sizeof(struct entry *), compare_entries); /* Print entries */ if (feed) { print_feed_header(entries_to_print[i]); for (i = page_entries; i < number_of_entries && i < (NUMBEROFENTRIESPERPAGE + page_entries); i++) { print_feed_entry(entries_to_print[i]); } print_feed_footer(); } else { print_html_header(sb); for (i = page_entries; i < number_of_entries && i < (NUMBEROFENTRIESPERPAGE + page_entries); i++) { print_html_entry(entries_to_print[i]); } /* Next and previous page links. Print links only if we have more than one entry to print */ if (i > (page_entries + 1) && number_of_entries > (page_entries + NUMBEROFENTRIESPERPAGE)) { printf("<div class=\"navi\">"); if (page > 0) { if (sizeofpath == 1) { printf("<a href=\"%s/%s?page=%d\">%s</a> ", BASEURL, patharray[0], page - 1, L_PREVIOUSPAGE); } else { printf("<a href=\"%s?page=%d\">%s</a> ", BASEURL, page - 1, L_PREVIOUSPAGE); } } if (sizeofpath == 1) { printf("<a href=\"%s/%s?page=%d\">%s</a>", BASEURL, patharray[0], page + 1, L_NEXTPAGE); } else { printf("<a href=\"%s?page=%d\">%s</a>", BASEURL, page + 1, L_NEXTPAGE); } printf("</div>"); } print_html_sidebar(sb); print_html_footer(); } return 0; }