Author: jan
Date: 2007-07-05 11:47:00 +0200 (Thu, 05 Jul 2007)
New Revision: 253

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/nessus/monitor_dialog.c
Log:
Introducing an improved scan progress dialog for GTK >= 2.6.

* nessus/monitor_dialog.c (stop_toggled): New. Stop a scan if toggled off.

* nessus/monitor_dialog.c (monitor_dialog_setup): default window size
smaller for new style of dialog. Set up new style of dialog now with
a TreeView Widget and full MVC (Model-View-Controller) concept.

* nessus/monitor_dialog.c (monitor_list_update, monitor_remove_host,
monitor_add_host): Consider new style of dialog (TreeView and MVC).


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog      2007-07-05 09:35:42 UTC (rev 252)
+++ trunk/openvas-client/ChangeLog      2007-07-05 09:47:00 UTC (rev 253)
@@ -1,5 +1,18 @@
 2007-07-05  Jan-Oliver Wagner <[EMAIL PROTECTED]>
 
+       Introducing an improved scan progress dialog for GTK >= 2.6.
+
+       * nessus/monitor_dialog.c (stop_toggled): New. Stop a scan if toggled 
off.
+
+       * nessus/monitor_dialog.c (monitor_dialog_setup): default window size
+       smaller for new style of dialog. Set up new style of dialog now with
+       a TreeView Widget and full MVC (Model-View-Controller) concept.
+
+       * nessus/monitor_dialog.c (monitor_list_update, monitor_remove_host,
+       monitor_add_host): Consider new style of dialog (TreeView and MVC).
+
+2007-07-05  Jan-Oliver Wagner <[EMAIL PROTECTED]>
+
        First bunch of renaming.
 
        * ChangeLog: New. Starting to explicity log changes.

Modified: trunk/openvas-client/nessus/monitor_dialog.c
===================================================================
--- trunk/openvas-client/nessus/monitor_dialog.c        2007-07-05 09:35:42 UTC 
(rev 252)
+++ trunk/openvas-client/nessus/monitor_dialog.c        2007-07-05 09:47:00 UTC 
(rev 253)
@@ -27,6 +27,19 @@
  *
  */
 
+/*
+ * XXX: For GTK > 2.6.0 the monitor dialog uses a modern
+ * design based on TreeView. The reason it is not activated for
+ * GTK 2.4 is that the progress bar inside TreeViews is only
+ * available since 2.6 and progress bars are a essential
+ * feature of this dialog.
+ *
+ * The old style is kept until GTK >= 2.6 can be assumed for
+ * any relevant system where NessusClient might run. Once this
+ * is true and the minimum requirement for NessusClient is GTK
+ * >= 2.6, the old style can be removed from the code.
+ */
+
 #include <includes.h>
 
 #ifdef USE_GTK 
@@ -127,6 +140,35 @@
   return TRUE;
 }
 
+/* column IDs of scanner TreeView Model */
+enum {
+  COL_ICON,
+  COL_HOSTNAME,
+  COL_PORTSCAN,
+  COL_CHECKS,
+  NUM_COLS
+};
+
+static void
+stop_toggled(cell, path_str, data)
+  GtkCellRendererToggle *cell;
+  gchar                 *path_str;
+  gpointer               data;
+{
+  GtkListStore * store = arg_get_value(data, "MON_STORE");
+  struct context * context = arg_get_value(data, "CONTEXT");
+  GtkTreeIter iter;
+  char * hostname;
+
+  gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, path_str);
+
+  gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+    COL_HOSTNAME, &hostname, -1);
+
+  network_printf(context->socket,
+    "CLIENT <|> STOP_ATTACK <|> %s <|> CLIENT\n", hostname);
+}
+
 /*
  * monitor_dialog_setup
  *
@@ -156,7 +198,10 @@
   prefs_context_update(context);
 
   w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  gtk_window_set_default_size(GTK_WINDOW(w), 640,480);
+  if (GTK_CHECK_VERSION(2,6,0)) /* TreeView since GTK 2.6 */
+    gtk_window_set_default_size(GTK_WINDOW(w), 320,200);
+  else
+    gtk_window_set_default_size(GTK_WINDOW(w), 640,480);
 
   /* TODO make the window non-modal
    * This can be done when context is kept for all called functions */
@@ -167,7 +212,7 @@
 #endif
 
   gtk_widget_realize(w);
-  gtk_signal_connect(GTK_OBJECT(w), "delete_event",
+  g_signal_connect(GTK_OBJECT(w), "delete_event",
                     (GtkSignalFunc)monitor_stop_whole_test_destroy,ctrls);
                     
   host_name = prefs_get_string(context, "nessusd_host");
@@ -185,27 +230,83 @@
   gtk_container_add(GTK_CONTAINER(w), box);
   gtk_widget_show(box);
   
-  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-  gtk_container_border_width (GTK_CONTAINER (scrolled_window), 10);
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
-                                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+  if (GTK_CHECK_VERSION(2,6,0)) { /* TreeView since GTK 2.6 */
+    GtkListStore * store;
+    GtkCellRenderer   * renderer;
+    GtkTreeViewColumn * column;
+
+    scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+    gtk_container_border_width(GTK_CONTAINER (scrolled_window), 10);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window),
+                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
                                
-  gtk_container_border_width(GTK_CONTAINER(scrolled_window), 10);  
-  gtk_box_pack_start(GTK_BOX(box), scrolled_window, TRUE, TRUE, 0);
-  
-  w = gtk_list_new();
-  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), 
w);
-  gtk_widget_show(w);
-  gtk_widget_show (scrolled_window);
-  arg_add_value(ctrls, "LIST", ARG_PTR, -1, w);
-                    
+    gtk_container_border_width(GTK_CONTAINER(scrolled_window), 10);  
+    gtk_box_pack_start(GTK_BOX(box), scrolled_window, TRUE, TRUE, 0);
 
+    store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF,
+      G_TYPE_STRING, GTK_TYPE_INT, GTK_TYPE_INT);
+    arg_add_value(ctrls, "MON_STORE", ARG_PTR, -1, store);
+
+    w = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+
+    /* The Icon column */
+    renderer = gtk_cell_renderer_pixbuf_new();
+    column = gtk_tree_view_column_new_with_attributes (NULL,
+      renderer, "pixbuf", COL_ICON, NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
+
+    /* The hostname column */
+    renderer = gtk_cell_renderer_text_new();
+    column = gtk_tree_view_column_new_with_attributes (_("Hostname"),
+      renderer, "text", COL_HOSTNAME, NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
+
+    /* The port scan progress bar column */
+    renderer = gtk_cell_renderer_progress_new();
+    column = gtk_tree_view_column_new_with_attributes (_("Portscan"),
+      renderer, "value", COL_PORTSCAN, NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
+
+    /* The checks progress bar column */
+    renderer = gtk_cell_renderer_progress_new();
+    column = gtk_tree_view_column_new_with_attributes (_("Checks"),
+      renderer, "value", COL_CHECKS, NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
+
+    /* The stop action as toggle */
+    renderer = gtk_cell_renderer_toggle_new();
+    g_signal_connect(renderer, "toggled", G_CALLBACK(stop_toggled), ctrls);
+    column = gtk_tree_view_column_new_with_attributes(_("Stop"), renderer,
+        NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW (w), column);
+
+    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
+                                          w);
+    gtk_widget_show(w);
+    gtk_widget_show (scrolled_window);
+  } else { /* old style for GTK < 2.6 */
+    scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+    gtk_container_border_width(GTK_CONTAINER (scrolled_window), 10);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window),
+                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+    gtk_container_border_width(GTK_CONTAINER(scrolled_window), 10);  
+    gtk_box_pack_start(GTK_BOX(box), scrolled_window, TRUE, TRUE, 0);
+
+    w = gtk_list_new();
+    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
+                                          w);
+    gtk_widget_show(w);
+    gtk_widget_show (scrolled_window);
+    arg_add_value(ctrls, "LIST", ARG_PTR, -1, w);
+  }
+
   
   tag = gtk_idle_add((GtkFunction)idle_socket, ctrls);
   
   arg_add_value(ctrls, "TAG", ARG_INT, sizeof(int), (void*)tag);
   w = gtk_button_new_with_label(_("Stop the whole test"));
-  gtk_signal_connect(GTK_OBJECT(w), "clicked",
+  g_signal_connect(GTK_OBJECT(w), "clicked",
                     (GtkSignalFunc)monitor_stop_whole_test,ctrls);
   gtk_box_pack_start(GTK_BOX(box), w, FALSE, TRUE, 0);
   gtk_widget_show(w);
@@ -272,39 +373,66 @@
   }
  }
  
- gtkw = arg_get_value(ctrls, "LIST");
- dlist = GTK_LIST(gtkw)->children;
- while(dlist && !flag)
- {
-  item = GTK_OBJECT(dlist->data);
-  list_hostname = gtk_object_get_data(item, "hostname");
-  if(!list_hostname){
-    fprintf(stderr, _("Error ! Null hostname in the list\n"));
-       /*exit(1);*/
-       return;
-       }
-  if(!strcmp(list_hostname, hostname))
-  {
-   GtkWidget * progress_bar;
-   gfloat f;
+  if (GTK_CHECK_VERSION(2,6,0)) { /* TreeView since GTK 2.6 */
+    GtkListStore * store = arg_get_value(ctrls, "MON_STORE");
+    GtkTreeIter iter;
+    int f = (atoi(current) * 100) / max;
+    if(f>=100)f=100;
+    if(f<=0)f=0;
+
+    if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
+      do {
+        gtk_tree_model_get (GTK_TREE_MODEL(store), &iter,
+          COL_HOSTNAME, &list_hostname, -1);
+        if(!list_hostname){
+          fprintf(stderr, _("Error ! Null hostname in the list\n"));
+          return;
+        }
+        if (!strcmp(list_hostname, hostname)) {
+          if( strcmp(action, "portscan") == 0 )
+            gtk_list_store_set(store, &iter, COL_PORTSCAN, f, -1);
+          else
+            gtk_list_store_set(store, &iter, COL_CHECKS, f, -1);
+          flag = 1;
+          break;
+        }
+      } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
+    }
+  } else { /* old style for GTK < 2.6 */
+    gtkw = arg_get_value(ctrls, "LIST");
+    dlist = GTK_LIST(gtkw)->children;
+    while(dlist && !flag)
+    {
+      item = GTK_OBJECT(dlist->data);
+      list_hostname = gtk_object_get_data(item, "hostname");
+      if(!list_hostname){
+        fprintf(stderr, _("Error ! Null hostname in the list\n"));
+        /*exit(1);*/
+        return;
+      }
+      if(!strcmp(list_hostname, hostname))
+      {
+        GtkWidget * progress_bar;
+        gfloat f;
    
-   if( strcmp(action, "portscan") == 0 )
-    progress_bar = gtk_object_get_data(item, "progress_bar_portscan");
-   else
-    progress_bar = gtk_object_get_data(item, "progress_bar_attack");
-    
-   gmax = max;
-   gcurrent = atoi(current);
-   f = (gcurrent/gmax);
-   if(f>=1.0)f=1.0;
-   if(f<=0.0)f=0.0;
-   gtk_progress_bar_update (GTK_PROGRESS_BAR(progress_bar), f);
+        if( strcmp(action, "portscan") == 0 )
+          progress_bar = gtk_object_get_data(item, "progress_bar_portscan");
+        else
+          progress_bar = gtk_object_get_data(item, "progress_bar_attack");
 
-   flag = 1;
+        gmax = max;
+        gcurrent = atoi(current);
+        f = (gcurrent/gmax);
+        if(f>=1.0)f=1.0;
+        if(f<=0.0)f=0.0;
+        gtk_progress_bar_update (GTK_PROGRESS_BAR(progress_bar), f);
+
+        flag = 1;
+      }
+    dlist = dlist->next;
+    }
   }
-  dlist = dlist->next;
- }
- 
+
  if(!flag)
  {
  /* the host was not found, we must add one... */
@@ -314,7 +442,6 @@
  efree(&hostname);
  efree(&action);
  if(current)efree(&current);
- 
 }
  
 /*
@@ -325,26 +452,43 @@
  struct arglist * ctrls;
  char * host;
 {
- GtkWidget * item;
- GList * list = NULL;
- item =  gtk_object_get_data(GTK_OBJECT(arg_get_value(ctrls, "LIST")),host);
+  if (GTK_CHECK_VERSION(2,6,0)) { /* TreeView since GTK 2.6 */
+    GtkListStore * store = arg_get_value(ctrls, "MON_STORE");
+    GtkTreeIter iter;
+    char * list_hostname;
+
+    if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
+      do {
+        gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+          COL_HOSTNAME, &list_hostname, -1);
+        if (!strcmp(list_hostname, host)) {
+          gtk_list_store_remove(store, &iter);
+          break;
+        }
+      } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
+    }
+  } else { /* old style for GTK < 2.6 */
+    GtkWidget * item;
+    GList * list = NULL;
+    item =  gtk_object_get_data(GTK_OBJECT(arg_get_value(ctrls, "LIST")),host);
  
- if(!item){
-       /*
-        * If this happens, then it's very likely that the server
-        * thinks the communication has been cut between the client
-        * and itself. Which is not a good thing.
-        */
-       return;
-       }
+    if(!item){
+      /*
+       * If this happens, then it's very likely that the server
+       * thinks the communication has been cut between the client
+       * and itself. Which is not a good thing.
+       */
+      return;
+    }
  
- if(item != (void*)-1)
- {
- list = g_list_append(list, item);
- gtk_list_remove_items(GTK_LIST(arg_get_value(ctrls, "LIST")), list);
- gtk_object_remove_data(GTK_OBJECT(arg_get_value(ctrls, "LIST")), host);
- g_list_free(list);
- }
+    if(item != (void*)-1)
+    {
+      list = g_list_append(list, item);
+      gtk_list_remove_items(GTK_LIST(arg_get_value(ctrls, "LIST")), list);
+      gtk_object_remove_data(GTK_OBJECT(arg_get_value(ctrls, "LIST")), host);
+      g_list_free(list);
+    }
+  }
 }
 
  
@@ -364,6 +508,20 @@
        char * hostname;
        int port;
 {
+  if (GTK_CHECK_VERSION(2,6,0)) { /* TreeView since GTK 2.6 */
+    GtkListStore * store = arg_get_value(ctrls, "MON_STORE");
+    GtkTreeIter iter;
+    GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data(
+      (const char **)computer_xpm);
+
+    gtk_list_store_append(store, &iter);  /* Acquire an iterator */
+    gtk_list_store_set(store, &iter,
+      COL_ICON, pixbuf,
+      COL_HOSTNAME, hostname,
+      COL_PORTSCAN, 0,
+      COL_CHECKS, 0,
+      -1);
+  } else { /* old style for GTK < 2.6 */
  GtkWidget * progress_bar_portscan;
  GtkWidget * progress_bar_attack;
  GtkWidget * table;
@@ -460,7 +618,7 @@
  gtk_widget_show(box);
  
  button = gtk_button_new_with_label(_("Stop"));
- gtk_signal_connect(GTK_OBJECT(button), "clicked",
+ g_signal_connect(GTK_OBJECT(button), "clicked",
                     (GtkSignalFunc)monitor_stop_test, context);
  gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
  gtk_object_set_data(GTK_OBJECT(button), "hostname", hostname);
@@ -481,6 +639,8 @@
  dlist = g_list_append(dlist, item);
  gtk_object_set_data(GTK_OBJECT(arg_get_value(ctrls, "LIST")), hostname,item);
  gtk_list_append_items(GTK_LIST(arg_get_value(ctrls, "LIST")), dlist);
+
+  }
  }
  
  

_______________________________________________
Openvas-commits mailing list
[email protected]
http://lists.wald.intevation.org/mailman/listinfo/openvas-commits

Reply via email to