Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

export links function combined into one function

* combined into "print_export_link"
* some visual cleanup where the icons get displayed

refs: #1783
refs: #1789
  • Loading branch information...
bb-Ricardo committed Aug 8, 2011
1 parent d9f0294 commit b20b0b051a0c954a629c76697abd6986783ddcf0
Showing with 182 additions and 270 deletions.
  1. +5 −5 cgi/avail.c
  2. +39 −81 cgi/cgiutils.c
  3. +41 −98 cgi/config.c
  4. +43 −23 cgi/extinfo.c
  5. +1 −2 cgi/histogram.c
  6. +1 −2 cgi/history.c
  7. +3 −3 cgi/notifications.c
  8. +9 −5 cgi/outages.c
  9. +4 −4 cgi/showlog.c
  10. +17 −27 cgi/status.c
  11. +15 −13 cgi/summary.c
  12. +1 −1 cgi/trends.c
  13. +1 −1 html/stylesheets/outages.css
  14. +1 −1 html/stylesheets/status.css
  15. +1 −4 include/cgiutils.h
@@ -600,7 +600,7 @@ int main(int argc, char **argv) {
printf("</table>\n");
printf("</form>\n");

printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s'></a>\n", get_export_link(AVAIL_CGI), url_images_path, EXPORT_LINK_ICON, EXPORT_LINK_ICON_ALT);
print_export_link(HTML_CONTENT, AVAIL_CGI, NULL);

printf("</td>\n");

@@ -993,10 +993,10 @@ int main(int argc, char **argv) {

/* add export to csv, json, xml, link */
printf("<div class='csv_export_link' align=right>");
printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s'></a>\n", get_export_csv_link(AVAIL_CGI), url_images_path, EXPORT_CSV_ICON, EXPORT_CSV_ICON_ALT);
printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s'></a>\n", get_export_json_link(AVAIL_CGI), url_images_path, EXPORT_JSON_ICON, EXPORT_JSON_ICON_ALT);
printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s'></a>\n", get_export_xml_link(AVAIL_CGI), url_images_path, EXPORT_XML_ICON, EXPORT_XML_ICON_ALT);
printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s'></a>\n", get_export_link(AVAIL_CGI), url_images_path, EXPORT_LINK_ICON, EXPORT_LINK_ICON_ALT);
print_export_link(CSV_CONTENT, AVAIL_CGI, NULL);
print_export_link(JSON_CONTENT, AVAIL_CGI, NULL);
print_export_link(XML_CONTENT, AVAIL_CGI, NULL);
print_export_link(HTML_CONTENT, AVAIL_CGI, NULL);
printf("</div>\n");

printf("<BR><BR>\n");
@@ -2333,97 +2333,55 @@ void print_generic_error_message(char *title, char *text, int returnlevels) {
return;
}

/* function to make export csv link XSS save #1275 */
char *get_export_csv_link(char *cgi) {
char temp_buffer[MAX_INPUT_BUFFER] = "";
static char ret[MAX_INPUT_BUFFER] = "";

/* just do stuff if some options are requested */
if (getenv("QUERY_STRING") != NULL) {
if (strcmp(getenv("QUERY_STRING"), "")) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", getenv("QUERY_STRING"));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
strip_html_brackets(temp_buffer);
snprintf(ret, sizeof(ret) - 1, "%s?%s&csvoutput", cgi, temp_buffer);
ret[sizeof(ret)-1] = '\x0';
} else
snprintf(ret, sizeof(ret) - 1, "%s?csvoutput", cgi);
} else
snprintf(ret, sizeof(ret) - 1, "%s?csvoutput", cgi);

ret[sizeof(ret)-1] = '\x0';

return ret;
}

char *get_export_json_link(char *cgi) {
char temp_buffer[MAX_INPUT_BUFFER] = "";
static char ret[MAX_INPUT_BUFFER] = "";

/* just do stuff if some options are requested */
if (getenv("QUERY_STRING") != NULL) {
if (strcmp(getenv("QUERY_STRING"), "")) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", getenv("QUERY_STRING"));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
strip_html_brackets(temp_buffer);
snprintf(ret, sizeof(ret) - 1, "%s?%s&jsonoutput", cgi, temp_buffer);
ret[sizeof(ret)-1] = '\x0';
} else
snprintf(ret, sizeof(ret) - 1, "%s?jsonoutput", cgi);
} else
snprintf(ret, sizeof(ret) - 1, "%s?jsonoutput", cgi);

ret[sizeof(ret)-1] = '\x0';
/** @brief prints export link with little icons
* @param [in] can be \c CSV_CONTENT , \c JSON_CONTENT \c XML_CONTENT or \c HTML_CONTENT
* @param [in] name of cgi as defined in include/cgiutils.h
* @param [in] additional string to add to url (set to NULL if nothing should be added)
* @note takes care that each link is XSS save #1275
*
* This function prints a little icon, depending on @ref content_type, which points to
* a new page with the desired content.
**/
void print_export_link(int content_type, char *cgi, char *add_to_url) {
char stripped_query_string[MAX_INPUT_BUFFER] = "";
char link[MAX_INPUT_BUFFER] = "";

return ret;
}
if (cgi == NULL)
return;

char *get_export_xml_link(char *cgi) {
char temp_buffer[MAX_INPUT_BUFFER] = "";
static char ret[MAX_INPUT_BUFFER] = "";
strcat(link, cgi);

/* just do stuff if some options are requested */
if (getenv("QUERY_STRING") != NULL) {
if (strcmp(getenv("QUERY_STRING"), "")) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", getenv("QUERY_STRING"));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
strip_html_brackets(temp_buffer);
snprintf(ret, sizeof(ret) - 1, "%s?%s&xmloutput", cgi, temp_buffer);
ret[sizeof(ret)-1] = '\x0';
} else
snprintf(ret, sizeof(ret) - 1, "%s?xmloutput", cgi);
} else
snprintf(ret, sizeof(ret) - 1, "%s?xmloutput", cgi);

ret[sizeof(ret)-1] = '\x0';

return ret;
}

char *get_export_link(char *cgi) {
char temp_buffer[MAX_INPUT_BUFFER] = "";
static char ret[MAX_INPUT_BUFFER] = "";
if (getenv("QUERY_STRING") != NULL && strcmp(getenv("QUERY_STRING"), "")) {
strcpy(stripped_query_string, getenv("QUERY_STRING"));
strip_html_brackets(stripped_query_string);
strcat(link, "?");
strcat(link, stripped_query_string);
}

/* just do stuff if some options are requested */
if (getenv("QUERY_STRING") != NULL) {
if (strcmp(getenv("QUERY_STRING"), "")) {
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s", getenv("QUERY_STRING"));
temp_buffer[sizeof(temp_buffer)-1] = '\x0';
strip_html_brackets(temp_buffer);
snprintf(ret, sizeof(ret) - 1, "%s?%s", cgi, temp_buffer);
ret[sizeof(ret)-1] = '\x0';
} else
snprintf(ret, sizeof(ret) - 1, "%s", cgi);
} else
snprintf(ret, sizeof(ret) - 1, "%s", cgi);
/* add string to url */
if (add_to_url != NULL && (strlen(add_to_url) != 0)) {
if (strlen(stripped_query_string) != 0)
strcat(link, "&");
else
strcat(link, "?");
strcat(link, add_to_url);
}

ret[sizeof(ret)-1] = '\x0';
/* print formatted link */
if (content_type == CSV_CONTENT)
printf("<a href='%s%scsvoutput' target='_blank'><img src='%s%s' border=0 alt='%s' title='%s'></a>\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_CSV_ICON, EXPORT_CSV_ICON_ALT, EXPORT_CSV_ICON_ALT);
else if (content_type == JSON_CONTENT)
printf("<a href='%s%sjsonoutput' target='_blank'><img src='%s%s' border=0 alt='%s' title='%s'></a>\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_JSON_ICON, EXPORT_JSON_ICON_ALT, EXPORT_JSON_ICON_ALT);
else if (content_type == XML_CONTENT)
printf("<a href='%s%sxmloutput' target='_blank'><img src='%s%s' border=0 alt='%s' title='%s'></a>\n", link, (strlen(stripped_query_string) != 0) ? "&" : "?", url_images_path, EXPORT_XML_ICON, EXPORT_XML_ICON_ALT, EXPORT_XML_ICON_ALT);
else
printf("<a href='%s' target='_blank'><img src='%s%s' border=0 alt='%s' title='%s'></a>\n", link, url_images_path, EXPORT_LINK_ICON, EXPORT_LINK_ICON_ALT, EXPORT_LINK_ICON_ALT);

return ret;
return;
}



/**
* Logging and file functions
**/

0 comments on commit b20b0b0

Please sign in to comment.
You can’t perform that action at this time.