[Openvas-commits] r9438 - in trunk/gsd: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 18 11:15:43 CET 2010


Author: raimund
Date: 2010-11-18 11:15:42 +0100 (Thu, 18 Nov 2010)
New Revision: 9438

Modified:
   trunk/gsd/ChangeLog
   trunk/gsd/src/dock_reports.cpp
   trunk/gsd/src/dock_reports.h
   trunk/gsd/src/dock_reports.ui
   trunk/gsd/src/gsd_control.cpp
   trunk/gsd/src/gsd_control.h
   trunk/gsd/src/gsd_mw.cpp
Log:
Added download support for report formats.

* src/gsd_control.cpp(gsd_control): Added temporary model for report
download.
(report_download, getReportDownloadModel): New.

* src/gsd_mw.cpp (show_report): Signal/slot configuration for report download.

* src/dock_reports.cpp (update): Save to file if a filename is set.
(load): Add report formats to combobox. Signal/slot configuration for saving
the report.
(download_report, saveReport): New.

* src/dock_reports.h, src/gsd_control.h: Updated prototypes.

* src/dock_reports.ui: Added widgets to report dockwidget.



Modified: trunk/gsd/ChangeLog
===================================================================
--- trunk/gsd/ChangeLog	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/ChangeLog	2010-11-18 10:15:42 UTC (rev 9438)
@@ -1,3 +1,22 @@
+2010-11-18  Raimund Renkert <raimund.renkert at greenbone.net>
+
+	Added download support for report formats.
+
+	* src/gsd_control.cpp(gsd_control): Added temporary model for report
+	download.
+	(report_download, getReportDownloadModel): New.
+
+	* src/gsd_mw.cpp (show_report): Signal/slot configuration for report download.
+
+	* src/dock_reports.cpp (update): Save to file if a filename is set.
+	(load): Add report formats to combobox. Signal/slot configuration for saving
+	the report.
+	(download_report, saveReport): New.
+
+	* src/dock_reports.h, src/gsd_control.h: Updated prototypes.
+
+	* src/dock_reports.ui: Added widgets to report dockwidget.
+
 2010-11-17  Raimund Renkert <raimund.renkert at greenbone.net>
 
 	* src/delegate_text.cpp (paint): Fixed some code to display text delegates

Modified: trunk/gsd/src/dock_reports.cpp
===================================================================
--- trunk/gsd/src/dock_reports.cpp	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/dock_reports.cpp	2010-11-18 10:15:42 UTC (rev 9438)
@@ -31,6 +31,11 @@
 void
 dock_reports::update (QString report_id)
 {
+  if (fileName.compare ("") != 0)
+    {
+      saveReport ();
+      return;
+    }
   if (report_id.contains ("##xml"))
     {
       report_id.remove ("##xml");
@@ -157,11 +162,20 @@
   la_log_count->setText (tmp->getValue (tmp_rep, "result_count log"));
   la_false_pos_count->setText (tmp->getValue (tmp_rep,
                                               "result_count false_positive"));
+  pb_save->setEnabled (true);
 }
 
 void
 dock_reports::load ()
 {
+  pb_save->setEnabled (false);
+  cb_format->addItem ("HTML");
+  cb_format->addItem ("XML");
+  cb_format->addItem ("PDF");
+  cb_format->addItem ("ITG");
+  cb_format->addItem ("CPE");
+  cb_format->addItem ("NBE");
+
   webView->setUrl (QUrl (""));
   webView->page ()->setLinkDelegationPolicy (QWebPage::DelegateAllLinks);
   cb_overrides->setChecked (true);
@@ -240,6 +254,10 @@
            SIGNAL (valueChanged (int)),
            this,
            SLOT (cvss_changed (int)));
+  connect (pb_save,
+           SIGNAL (released ()),
+           this,
+           SLOT (download_report ()));
 }
 
 
@@ -385,3 +403,121 @@
 {
   la_cvss_v->setText (QString ("%1").arg ((double)value /10));
 }
+
+
+void
+dock_reports::download_report ()
+{
+  QString overrides = "0";
+  if (cb_overrides->isChecked ())
+    overrides = "1";
+
+  QString sort_type = "", sort_order = "";
+  if (cb_sort->currentIndex () == 0)
+    {
+      sort_type = "port";
+      sort_order = "ascending";
+    }
+  else if (cb_sort->currentIndex () == 1)
+    {
+      sort_type = "port";
+      sort_order = "descending";
+    }
+  else if (cb_sort->currentIndex () == 2)
+    {
+      sort_type = "threat";
+      sort_order = "ascending";
+    }
+  else if (cb_sort->currentIndex () == 3)
+    {
+      sort_type = "threat";
+      sort_order = "descending";
+    }
+
+
+  QString level ("");
+  if (cb_high->isChecked ())
+    level += "h";
+  if (cb_medium->isChecked ())
+    level += "m";
+  if (cb_low->isChecked ())
+    level += "l";
+  if (cb_log->isChecked ())
+    level += "g";
+  if (cb_false_pos->isChecked ())
+    level += "f";
+  QString search = le_search->text ();
+  double cvss = (double)hs_cvss->value () / 10;
+
+  QString format = cb_format->currentText ().toLower ();
+  fileName = QFileDialog::getSaveFileName (this,
+                                           tr ("Save File ..."),
+                                           QDir::homePath () +
+                                           "/report",
+                                           tr ("all files *.*"));
+
+  QMap<QString, QString> parameter;
+  parameter.insert ("report_id", id);
+  parameter.insert ("format", format);
+  parameter.insert ("notes", "1");
+  parameter.insert ("note_details", "1");
+  parameter.insert ("overrides", "1");
+  parameter.insert ("overrides_details", "1");
+  parameter.insert ("apply_overrides", overrides);
+  parameter.insert ("result_hosts_only", "1");
+  parameter.insert ("levels", level);
+  parameter.insert ("search_phrase", search);
+  parameter.insert ("min_cvss_base", QString ("%1").arg (cvss));
+  parameter.insert ("sort_field", sort_type);
+  parameter.insert ("sort_order", sort_order);
+
+  emit sig_report_download (parameter);
+}
+
+
+void
+dock_reports::saveReport ()
+{
+  model_omp_entity *tmp = this->control->getReportDownloadModel ();
+
+  QDomElement element = tmp->getEntity (0);
+  QString ext = tmp->getAttr (element, "report extension");
+  if (ext.compare ("") == 0)
+    ext = tmp->getAttr (element, "report format");
+  if (ext.compare ("") == 0 || ext.compare ("xml") == 0)
+    {
+      const int indent = 4;
+      if (!fileName.endsWith (".xml"))
+        fileName += ".xml";
+      QFile wfile (fileName);
+      if (!wfile.open (QFile::WriteOnly|QFile::Text))
+        {
+          QMessageBox::information (NULL, tr ("File Error"),
+                                    tr ("Could not open file!"));
+          return;
+        }
+      QTextStream out (&wfile);
+      element.save (out, indent);
+      wfile.close ();
+    }
+  else
+    {
+      if (!fileName.endsWith (ext))
+        {
+          fileName += ".";
+          fileName += ext;
+        }
+      QFile wfile (fileName);
+      if (!wfile.open (QFile::WriteOnly))
+        {
+          QMessageBox::information (NULL, tr ("File Error"),
+                                    tr ("Could not open file!"));
+          return;
+        }
+      QByteArray data = QByteArray::fromBase64 (element.text ().toLatin1 ());
+      QDataStream out (&wfile);
+      out.writeRawData (data.data (), data.length ());
+      wfile.close ();
+    }
+  fileName = "";
+}

Modified: trunk/gsd/src/dock_reports.h
===================================================================
--- trunk/gsd/src/dock_reports.h	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/dock_reports.h	2010-11-18 10:15:42 UTC (rev 9438)
@@ -46,6 +46,7 @@
   signals:
     void sig_request_report (QMap<QString, QString>);
     void sig_details_nvt (QString, QString);
+    void sig_report_download (QMap<QString, QString>);
 
   public slots:
     void update (QString id);
@@ -54,13 +55,17 @@
   private slots:
     void web_link (const QUrl&);
     void cvss_changed (int);
+    void download_report ();
 
   private:
     gsd_control *control;
     model_omp_entity *report;
     model_omp_entity *htmlReport;
     QString id, task_id;
+    QString fileName;
 
+    void saveReport ();
+
   public:
     dock_reports (gsd_control *ctl)
       {

Modified: trunk/gsd/src/dock_reports.ui
===================================================================
--- trunk/gsd/src/dock_reports.ui	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/dock_reports.ui	2010-11-18 10:15:42 UTC (rev 9438)
@@ -59,7 +59,7 @@
             <rect>
              <x>0</x>
              <y>0</y>
-             <width>221</width>
+             <width>231</width>
              <height>530</height>
             </rect>
            </property>
@@ -277,7 +277,7 @@
         <enum>QFrame::Raised</enum>
        </property>
        <layout class="QGridLayout" name="gridLayout_2" >
-        <item row="0" column="0" >
+        <item row="1" column="0" colspan="4" >
          <widget class="QWebView" name="webView" >
           <property name="contextMenuPolicy" >
            <enum>Qt::NoContextMenu</enum>
@@ -289,13 +289,41 @@
           </property>
          </widget>
         </item>
+        <item row="0" column="3" >
+         <widget class="QPushButton" name="pb_save" >
+          <property name="text" >
+           <string>Save</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="2" >
+         <widget class="QComboBox" name="cb_format" />
+        </item>
+        <item row="0" column="1" >
+         <widget class="QLabel" name="la_save" >
+          <property name="text" >
+           <string>Save this report as</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="0" >
+         <spacer name="horizontalSpacer" >
+          <property name="orientation" >
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0" >
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
        </layout>
       </widget>
      </widget>
     </item>
    </layout>
-   <zorder>splitter</zorder>
-   <zorder>splitter</zorder>
   </widget>
  </widget>
  <customwidgets>

Modified: trunk/gsd/src/gsd_control.cpp
===================================================================
--- trunk/gsd/src/gsd_control.cpp	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/gsd_control.cpp	2010-11-18 10:15:42 UTC (rev 9438)
@@ -117,6 +117,7 @@
   xmlReportModel = new model_omp_entity ();
   configDownloadModel = new model_omp_entity ();
   reportFormatModel = new model_omp_entity ();
+  tmpReportModel = new model_omp_entity ();
 }
 
 gsd_control::~gsd_control ()
@@ -1513,6 +1514,57 @@
 }
 
 
+void
+gsd_control::report_download (QMap<QString, QString> parameter)
+{
+  if (protocol_version == 2)
+    {
+      if (parameter.contains ("format"))
+        {
+          if (tmpReportModel->rowCount () > 0)
+            tmpReportModel->removeEntities ();
+          QString f = parameter["format"];
+          QDomElement element;
+          for (int i = 0; i < reportFormatModel->rowCount (); i++)
+            {
+              if (reportFormatModel->getValue (reportFormatModel->getEntity (i),
+                                               "name").compare (f.toUpper ()) == 0)
+                {
+                  element = reportFormatModel->getEntity (i);
+                  break;
+                }
+            }
+          if (reportFormatModel->getValue (element, "active").compare ("0")
+              == 0)
+            {
+              QMessageBox::information (NULL, tr ("Report format"),
+                                        tr ("Report format not active!"));
+              return;
+            }
+
+          parameter.remove ("format");
+          QString format_id = reportFormatModel->getAttr (element,
+                                                          "report_format id");
+
+          parameter.insert ("format_id", format_id);
+          this->connector->getEntity (omp_utilities::REPORT,
+                                      0,
+                                      tmpReportModel,
+                                      parameter);
+
+        }
+    }
+  else if (protocol_version == 1)
+    {
+      if (tmpReportModel->rowCount () > 0)
+        tmpReportModel->removeEntities ();
+      this->connector->getEntity (omp_utilities::REPORT,
+                                  0,
+                                  tmpReportModel,
+                                  parameter);
+    }
+}
+
 /**
  * @brief Slot that requests nvt details.
  *
@@ -1919,6 +1971,18 @@
 }
 
 
+/**
+ * @brief Getter
+ *
+ * @return The model containing a report prepared to be saved on local
+ *         filesystem.
+ */
+model_omp_entity*
+gsd_control::getReportDownloadModel ()
+{
+  return tmpReportModel;
+}
+
 void
 gsd_control::note_modify(int)
 {}

Modified: trunk/gsd/src/gsd_control.h
===================================================================
--- trunk/gsd/src/gsd_control.h	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/gsd_control.h	2010-11-18 10:15:42 UTC (rev 9438)
@@ -101,6 +101,7 @@
     model_omp_entity *xmlReportModel;
     model_omp_entity *configDownloadModel;
     model_omp_entity *reportFormatModel;
+    model_omp_entity *tmpReportModel;
     GSList *log_config;
 
     void createConnections ();
@@ -165,6 +166,7 @@
     void config_download (int);
     void system_report_download ();
     void system_report_download (QString name, int duration);
+    void report_download (QMap<QString, QString> parameter);
     void create (int, QMap<QString, QString>);
     void modify (int, QString, model_omp_entity*, QMap<QString, QString>);
 
@@ -203,6 +205,7 @@
     model_omp_entity *getHtmlReportModel ();
     model_omp_entity *getXmlReportModel ();
     model_omp_entity *getConfigDownloadModel ();
+    model_omp_entity *getReportDownloadModel ();
     omp_credentials *getProfile (QString name);
     QString getProfile (int);
     int getProfileCount ();

Modified: trunk/gsd/src/gsd_mw.cpp
===================================================================
--- trunk/gsd/src/gsd_mw.cpp	2010-11-18 10:01:46 UTC (rev 9437)
+++ trunk/gsd/src/gsd_mw.cpp	2010-11-18 10:15:42 UTC (rev 9438)
@@ -3592,6 +3592,10 @@
                SIGNAL (sig_request_report (QMap<QString, QString>)),
                control,
                SLOT (request_report (QMap<QString, QString>)));
+      connect (reports,
+               SIGNAL (sig_report_download (QMap<QString, QString>)),
+               control,
+               SLOT (report_download (QMap<QString, QString>)));
       reports->setTask (task);
       reports->setId (id);
       reports->load ();



More information about the Openvas-commits mailing list