/** * @brief Display the statistics page to the requesting connection. * @param con a pointer to the connection object across which the server statistics will be transmitted. * @return This function returns no value. */ void statistics_process(connection_t *con) { time_t sm_time; chr_t buffer[256]; stringer_t *raw; struct tm tm_time; http_page_t *page; if (!(page = http_page_get("statistics/statistics"))) { http_print_500(con); return; } statistics_refresh(); if ((sm_time = time(NULL)) == ((time_t)-1) || !localtime_r(&sm_time, &tm_time) || strftime(buffer, 256, "These statistics were last updated %A, %B %e, %Y at %I:%M:%S %p %Z.", &tm_time) <= 0) { log_pedantic("Unable to build the time string."); } else { // Update the time. xml_set_xpath_ns(page->xpath_ctx, (xmlChar *)"//xhtml:p[@id='time']", (uchr_t *)buffer); } xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='total_users']", portal_stats[portal_stat_total_users].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='checked_email_today']", portal_stats[portal_stat_users_checked_email_today].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='checked_email_week']", portal_stats[portal_stat_users_checked_email_week].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='sent_email_today']", portal_stats[portal_stat_users_sent_email_today].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='sent_email_week']", portal_stats[portal_stat_users_sent_email_week].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='emails_received_today']", portal_stats[portal_stat_emails_received_today].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='emails_received_week']", portal_stats[portal_stat_emails_received_week].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='emails_sent_today']", portal_stats[portal_stat_emails_sent_today].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='emails_sent_week']", portal_stats[portal_stat_emails_sent_week].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='users_registered_today']", portal_stats[portal_stat_users_registered_today].val); xml_set_xpath_uint64(page->xpath_ctx, (xmlChar *)"//xhtml:td[@id='users_registered_week']", portal_stats[portal_stat_users_registered_week].val); if (!(raw = xml_dump_doc(page->doc_obj))) { http_print_500(con); http_page_free(page); return; } http_response_header(con, 200, page->content->type, st_length_get(raw)); con_write_st(con, raw); http_page_free(page); st_free(raw); return; }
/** * @brief Return the contact/abuse page with a marked error indicator for the user in the event of a user submission error. * @param branch a null-terminated string containing the source of the error: "Abuse" or "Contact" * @param xpath a null-terminated string containing the xpath of the element in the returned page that should be colored red. * @param id a null-terminated string containing the id of the error text <span> element to be added to the document. * @param message a null-terminated string containing the actual error message text to be displayed to the user. * @return NULL on failure, or a pointer to the processed contact page with error message on success. */ http_page_t * contact_business_add_error(chr_t *branch, uchr_t *xpath, uchr_t *id, uchr_t *message) { http_page_t *page = NULL; xmlNodePtr node, error; xmlXPathObjectPtr xpath_obj; // We are here either for the contact or abuse page. if (!st_cmp_cs_eq(NULLER(branch), PLACER("Abuse", 5)) && !((page = http_page_get("contact/abuse")))) { return NULL; } else if (!page && !(page = http_page_get("contact/contact"))) { return NULL; } if ((xpath_obj = xml_xpath_eval(xpath, page->xpath_ctx)) && xpath_obj->nodesetval && xpath_obj->nodesetval->nodeNr && xpath_obj->nodesetval->nodeTab[0]) { node = (xmlNodePtr)xpath_obj->nodesetval->nodeTab[0]; // Make the field red. xml_node_set_property(node, (uchr_t *)"class", (uchr_t *)"red"); // Add the error message. if ((error = xml_node_new((uchr_t *)"span"))) { xml_node_set_property(error, (uchr_t *)"id", id); xml_node_set_content(error, message); if (!(xml_node_add_sibling(node, error))) { xml_node_free(error); } } } return page; }