
bh at nessus
May 4, 2006, 8:33 AM
Post #1 of 1
(594 views)
Permalink
|
|
NessusClient/nessus report_save.c, 1.3, 1.4 pdf_output.h, 1.2, 1.3 pdf_output.c, 1.5, 1.6
|
|
Update of /usr/local/cvs/NessusClient/nessus In directory raccoon.nessus.org:/tmp/cvs-serv70713/nessus Modified Files: report_save.c pdf_output.h pdf_output.c Log Message: When exporting a report as PDF, include basic information (description, etc) in an appendix in the PDF. Index: report_save.c =================================================================== RCS file: /usr/local/cvs/NessusClient/nessus/report_save.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- report_save.c 15 Mar 2006 15:50:03 -0000 1.3 +++ report_save.c 4 May 2006 15:33:18 -0000 1.4 @@ -94,6 +94,8 @@ #define MAX_SUFFIX_LEN 5 /* .html */ char *suffix = suffixes[type]; int be = (int)arg_get_value(arg_get_value(MainDialog, "REPORT"), "BE"); + struct context *report_context + = arg_get_value(arg_get_value(MainDialog, "REPORT"), "REPORT_CONTEXT"); gtk_widget_hide(filedialog); @@ -141,7 +143,7 @@ break; #endif case SAVE_PDF: - arglist_to_pdf(be, fname); + arglist_to_pdf(report_context, be, fname); break; case SAVE_NSR: backend_to_nsr(be, fname); @@ -357,10 +359,12 @@ gpointer ctrls; { int be = (int)arg_get_value(arg_get_value(ctrls, "REPORT"), "BE"); + struct context *report_context + = arg_get_value(arg_get_value(ctrls, "REPORT"), "REPORT_CONTEXT"); char *basename = g_path_get_basename(Context->dir); char *filename = g_build_filename(Context->dir, basename, NULL); - arglist_to_pdf(be, filename); + arglist_to_pdf(report_context, be, filename); show_pdf(filename); g_free(filename); Index: pdf_output.h =================================================================== RCS file: /usr/local/cvs/NessusClient/nessus/pdf_output.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pdf_output.h 11 Feb 2006 01:32:31 -0000 1.2 +++ pdf_output.h 4 May 2006 15:33:18 -0000 1.3 @@ -30,6 +30,8 @@ #ifndef _NESSUSC_PDF_OUTPUT_H #define _NESSUSC_PDF_OUTPUT_H -int arglist_to_pdf(int, char *); +#include "context.h" + +int arglist_to_pdf(struct context *, int, char *); #endif Index: pdf_output.c =================================================================== RCS file: /usr/local/cvs/NessusClient/nessus/pdf_output.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pdf_output.c 31 Oct 2005 15:56:06 -0000 1.5 +++ pdf_output.c 4 May 2006 15:33:18 -0000 1.6 @@ -38,13 +38,15 @@ #include "preferences.h" #include "backend.h" #include "data_mining.h" +#include "nessus_plugin.h" #include "nessus_i18n.h" static char * convert_cr_to_html(char *); static char * portname_to_ahref(char *, char *); -int arglist_to_plainhtml(int, char *); +int arglist_to_plainhtml(struct context *, int, char *); void pdf_summary_to_file(FILE *, int, struct arglist *); +static void print_appendix(FILE *, GHashTable*); /* @@ -216,9 +218,8 @@ } static void -print_data_with_links(file, str, plugin_id) - FILE * file; - char * str, * plugin_id; +print_data_with_links(FILE * file, char * str, char * plugin_id, + int internal_link) { while(str != NULL && str[0] != '\0') { @@ -261,7 +262,10 @@ } fprintf(file, "Nessus ID : "); - fprint_link(file, "url_nessus", plugin_id); + if (internal_link) + fprintf(file, "<a href=\"#plugin%s\">%s</a>", plugin_id, plugin_id); + else + fprint_link(file, "url_nessus", plugin_id); } @@ -385,10 +389,8 @@ -int -arglist_to_pdf(be, filename) - int be; - char * filename; +int +arglist_to_pdf(struct context * context, int be, char * filename) { char tmpfname[PATH_MAX]; char * cwd = emalloc(PATH_MAX * sizeof(char)); @@ -408,7 +410,7 @@ chdir(tmpfname); /* Write the arglist to plain HTML suitable to be processed by HTMLDoc */ - arglist_to_plainhtml(be, "report.html"); + arglist_to_plainhtml(context, be, "report.html"); argv = append_argv(argv, "htmldoc"); argv = append_argv(argv, "--firstpage"); @@ -444,12 +446,12 @@ int -arglist_to_plainhtml(be, filename) - int be; - char *filename; +arglist_to_plainhtml(struct context * context, int be, char *filename) { FILE *file; struct arglist *hosts; + GHashTable * appendix_plugins = NULL; + int has_plugins = context->plugins != NULL; if(!strcmp(filename, "-"))file = stdout; else file = fopen(filename, "w"); @@ -459,6 +461,9 @@ return(-1); } + if (has_plugins) + appendix_plugins = g_hash_table_new(g_str_hash, g_str_equal); + hosts = backend_convert(be); /* Print the Style Sheet Opts and Report Summary */ @@ -607,7 +612,9 @@ fprintf(file, "\t<tr>\n"); fprintf(file, "\t\t<td>\n"); - print_data_with_links(file, desc, report->name); + print_data_with_links(file, desc, report->name, has_plugins); + if (has_plugins) + g_hash_table_insert(appendix_plugins, report->name, context); fprintf(file, "\n\t\t</td>\t</tr>\n"); efree(&desc); } @@ -628,7 +635,9 @@ fprintf(file, ": "); fprintf(file, "\t<tr>\n"); fprintf(file, "\t\t<td>\n"); - print_data_with_links(file, desc, info->name); + print_data_with_links(file, desc, info->name, has_plugins); + if (has_plugins) + g_hash_table_insert(appendix_plugins, info->name, context); fprintf(file, "\n\t\t</td>\t</tr>\n"); efree(&desc); } @@ -653,7 +662,9 @@ fprintf(file, ": "); fprintf(file, "\t<tr>\n"); fprintf(file, "\t\t<td>\n"); - print_data_with_links(file, desc, note->name); + print_data_with_links(file, desc, note->name, has_plugins); + if (has_plugins) + g_hash_table_insert(appendix_plugins, note->name, context); fprintf(file, "\n\t\t</td>\t</tr>\n"); efree(&desc); } @@ -670,6 +681,13 @@ hosts = hosts->next; efree(&href); } + + if (has_plugins && g_hash_table_size(appendix_plugins) > 0) + { + fprintf(file, "<hr>\n\n"); + print_appendix(file, appendix_plugins); + } + fprintf(file, "<hr>\n<i>"); PRINT(file, _("This file was generated by <a href=\"http://www.nessus.org\">Nessus</a>, the free security scanner.")); @@ -677,6 +695,9 @@ fprintf(file, "</HTML>\n"); fclose(file); + if (appendix_plugins) + g_hash_table_destroy(appendix_plugins); + if(hosts) arg_free_all(hosts); return(0); @@ -791,3 +812,67 @@ fprintf(file, "\t</tr>\n"); fprintf(file, "</table>\n"); } + + +static void +print_plugin_table_row(FILE *file, char *fieldname, char *text) +{ + char *html = convert_cr_to_html(text); + fprintf(file, "\t<tr><th align=\"right\">%s</th>" + "<td>%s</td></tr>\n", fieldname, html); + efree(&html); +} + +static void +print_plugin_information(gpointer key, gpointer value, gpointer userdata) +{ + struct context *context = value; + FILE *file = userdata; + char *plugin_id_str = key; + int plugin_id = atoi(plugin_id_str); + struct nessus_plugin *plugin; + char *description; + char *html_description; + + plugin = nessus_plugin_get_by_id(context->plugins, plugin_id); + if (plugin == NULL) + plugin = nessus_plugin_get_by_id(context->scanners, plugin_id); + + if (plugin == NULL) + { + fprintf(stderr, "print_plugin_information: no plugin with id %d\n", + plugin_id); + return; + } + + fprintf(file, "<H3><a name=\"plugin%s\">Plugin %d: %s</a></H3>\n\n", + plugin_id_str, plugin_id, plugin->name); + + fprintf(file, "<table>\n"); + print_plugin_table_row(file, "Summary", plugin->summary); + print_plugin_table_row(file, "Category", plugin->category); + print_plugin_table_row(file, "Family", plugin->family); + print_plugin_table_row(file, "Version", plugin->version); + print_plugin_table_row(file, "CVE", plugin->cve); + print_plugin_table_row(file, "BID", plugin->bid); + print_plugin_table_row(file, "XRefs", plugin->xrefs); + fprintf(file, "</table>"); + + description = nessus_plugin_get_description(plugin); + html_description = convert_cr_to_html(description); + fputs("<p></p>\n<h4>Description</h4>\n", file); + fputs(html_description, file); + efree(&html_description); + efree(&description); + + fprintf(file, "\n<p>\n"); +} + +static void +print_appendix(FILE *file, GHashTable *hash) +{ + fprintf(file, "<H2>Appendix: Plugin Information</H2>\n\n"); + + g_hash_table_foreach(hash, print_plugin_information, file); +} + _______________________________________________ Nessus-cvs mailing list Nessus-cvs [at] list http://mail.nessus.org/mailman/listinfo/nessus-cvs
|