1 /* gtk_interface.c
2 *
3 * GTK Interface setup
4 *
5 * Yersinia
6 * By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>
7 * Copyright 2005-2017 Alfredo Andres and David Barroso
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <stdio.h>
33
34 #include <gdk/gdkkeysyms.h>
35 #include <gtk/gtk.h>
36
37 #include "gtk-interface.h"
38
39 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
40 g_object_set_data_full (G_OBJECT (component), name, \
41 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
42
43 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
44 g_object_set_data (G_OBJECT (component), name, widget)
45
46 GtkWidget*
gtk_i_create_Main(struct gtk_s_helper * helper)47 gtk_i_create_Main (struct gtk_s_helper *helper)
48 {
49 u_int8_t i;
50 char title[64];
51 GtkWidget *Main;
52 GtkWidget *main_vbox;
53 GtkWidget *main_menubar;
54 GtkWidget *menu_file;
55 GtkWidget *menu_file_menu;
56 GtkWidget *menu_file_open;
57 GtkWidget *menu_file_save;
58 GtkWidget *separatormenuitem1;
59 GtkWidget *menu_file_quit;
60 GtkWidget *menu_protocols;
61 GtkWidget *menu_protocols_menu;
62 GtkWidget *menu_protocols_proto1;
63 GtkWidget *menu_actions;
64 GtkWidget *menu_actions_menu;
65 GtkWidget *menu_actions_execute;
66 GtkWidget *menu_actions_execute_img;
67 GtkWidget *menu_actions_interfaces;
68 GtkWidget *menu_actions_interfaces_img;
69 GtkWidget *menu_actions_load_default;
70 GtkWidget *menu_actions_load_default_img;
71 GtkWidget *menu_actions_list_attacks;
72 GtkWidget *menu_actions_list_attacks_img;
73 GtkWidget *menu_actions_clear;
74 GtkWidget *menu_actions_clear_img;
75 GtkWidget *menu_actions_clear_menu;
76 GtkWidget *menu_clear_proto1;
77 GtkWidget *menu_capture;
78 GtkWidget *menu_capture_img;
79 GtkWidget *menu_capture_menu;
80 GtkWidget *menu_capture_proto1;
81 GtkWidget *menu_options;
82 GtkWidget *menu_options_menu;
83 GtkWidget *menu_options_macspoofing;
84 GtkWidget *menu_help;
85 GtkWidget *menu_help_menu;
86 GtkWidget *menu_help_about;
87 GtkWidget *toolbar;
88 GtkIconSize tmp_toolbar_icon_size;
89 GtkWidget *toolbar_launch_img;
90 GtkWidget *toolbar_launch;
91 GtkWidget *toolbar_interfaces_img;
92 GtkWidget *toolbar_interfaces;
93 GtkWidget *toolbar_default_img;
94 GtkWidget *toolbar_default;
95 GtkWidget *toolbar_list_attacks_img;
96 GtkWidget *toolbar_list_attacks;
97 GtkWidget *toolbar_clear;
98 GtkWidget *toolbar_clear_img;
99 GtkWidget *toolbar_capture;
100 GtkWidget *toolbar_capture_img;
101 GtkWidget *toolbar_edit;
102 GtkWidget *toolbar_edit_img;
103 GtkWidget *toolbar_quit_img;
104 GtkWidget *toolbar_quit;
105 GtkWidget *main_vbox_hpaned;
106 GtkWidget *main_vh_vpaned;
107 GtkWidget *main_vhv_scroll;
108 GtkListStore *main_vhvs_tree_model;
109 GtkListStore *main_vhvvs_tree_model;
110 GtkTreeIter iter;
111 GtkCellRenderer *cell;
112 GtkCellRenderer *cell2;
113 GtkTreeViewColumn *column;
114 GtkWidget *main_vhvs_tree;
115 GtkWidget *main_vhvvs_tree;
116 GtkWidget *main_vhv_vbox;
117 GtkWidget *main_vhvv_scroll;
118 GtkWidget *main_vhvv_clock;
119 GtkWidget *main_vhvv_eventbox;
120 GtkWidget *main_vh2_vpaned;
121 GtkTextBuffer *buffer_hex;
122 GtkWidget *main_vhv2_scrollhex;
123 GtkWidget *main_vhv2_texthex;
124 GtkWidget *main_vhv2_notebook;
125 GtkWidget *protocols_vpaned[MAX_PROTOCOLS + 1];
126 GtkWidget *main_vhn_labels[MAX_PROTOCOLS + 1];
127 GtkWidget *main_log_scroll;
128 GtkWidget *main_log;
129 GtkTooltips *tooltips;
130 GtkAccelGroup *accel_group;
131 PangoFontDescription *font_desc;
132
133 accel_group = gtk_accel_group_new ();
134
135 /* Tooltips */
136 tooltips = gtk_tooltips_new();
137 helper->tooltips = tooltips;
138 gtk_tooltips_enable(tooltips);
139
140 /* Main window */
141 Main = gtk_window_new (GTK_WINDOW_TOPLEVEL);
142 snprintf(title, 64, "Yersinia %s", VERSION);
143 gtk_window_set_title (GTK_WINDOW (Main), title);
144 gtk_window_set_default_size (GTK_WINDOW (Main), 640, 480);
145
146 g_signal_connect( Main, "delete_event", G_CALLBACK( gtk_c_on_file_quit_activate ), helper );
147
148 main_vbox = gtk_vbox_new (FALSE, 0);
149 gtk_widget_show (main_vbox);
150 gtk_container_add (GTK_CONTAINER (Main), main_vbox);
151
152 /* Menu widgets */
153 main_menubar = gtk_menu_bar_new ();
154 gtk_widget_show (main_menubar);
155 gtk_box_pack_start (GTK_BOX (main_vbox), main_menubar, FALSE, FALSE, 0);
156
157 /* Menu File */
158 menu_file = gtk_menu_item_new_with_mnemonic (_("_File"));
159 gtk_widget_show (menu_file);
160 gtk_container_add (GTK_CONTAINER (main_menubar), menu_file);
161
162 menu_file_menu = gtk_menu_new ();
163 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
164
165 /* Menu File - Open */
166 menu_file_open = gtk_image_menu_item_new_from_stock ("gtk-open", accel_group);
167 gtk_widget_show (menu_file_open);
168 gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_file_open);
169
170 /* Menu File - Save */
171 menu_file_save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
172 gtk_widget_show (menu_file_save);
173 gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_file_save);
174
175 /* Menu File - Separator */
176 separatormenuitem1 = gtk_separator_menu_item_new ();
177 gtk_widget_show (separatormenuitem1);
178 gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
179 gtk_widget_set_sensitive (separatormenuitem1, FALSE);
180
181 /* Menu File - Quit */
182 menu_file_quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
183 gtk_widget_show (menu_file_quit);
184 gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_file_quit);
185
186 /* Menu Protocols */
187 menu_protocols = gtk_menu_item_new_with_mnemonic (_("_Protocols"));
188 gtk_widget_show (menu_protocols);
189 gtk_container_add (GTK_CONTAINER (main_menubar), menu_protocols);
190
191 menu_protocols_menu = gtk_menu_new ();
192 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_protocols), menu_protocols_menu);
193
194 /* Menu Protocols - PROTO_NAME */
195 for (i = 0; i < MAX_PROTOCOLS; i++)
196 {
197 menu_protocols_proto1 = gtk_check_menu_item_new_with_mnemonic (_(protocols[i].namep));
198 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_protocols_proto1), TRUE);
199
200 if (protocols[i].visible)
201 gtk_widget_show (menu_protocols_proto1);
202 gtk_container_add (GTK_CONTAINER (menu_protocols_menu), menu_protocols_proto1);
203 /* Disabled, wrong usage!! Variable 'i' on stack!!
204 g_signal_connect ((gpointer) menu_protocols_proto1, "toggled", G_CALLBACK (gtk_c_on_protocols_toggle), &i);
205 */
206 }
207
208 /* Menu Actions */
209 menu_actions = gtk_menu_item_new_with_mnemonic (_("_Actions"));
210 gtk_widget_show (menu_actions);
211 gtk_container_add (GTK_CONTAINER (main_menubar), menu_actions);
212
213 menu_actions_menu = gtk_menu_new ();
214 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_actions), menu_actions_menu);
215
216 /* Menu Actions - Execute Attack */
217 menu_actions_execute = gtk_image_menu_item_new_with_mnemonic (_("e_Xecute attack"));
218 menu_actions_execute_img = gtk_image_new_from_stock ("gtk-execute", GTK_ICON_SIZE_MENU);
219 gtk_widget_show(menu_actions_execute_img);
220 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_actions_execute), menu_actions_execute_img);
221 gtk_widget_show (menu_actions_execute);
222 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_actions_execute);
223 gtk_widget_add_accelerator (menu_actions_execute, "activate", accel_group,
224 GDK_x, (GdkModifierType) GDK_CONTROL_MASK,
225 GTK_ACCEL_VISIBLE);
226
227 /* Menu Actions - Edit interfaces */
228 menu_actions_interfaces = gtk_image_menu_item_new_with_mnemonic (_("edit _Interfaces"));
229 menu_actions_interfaces_img = gtk_image_new_from_stock ("gtk-preferences", GTK_ICON_SIZE_MENU);
230 gtk_widget_show(menu_actions_interfaces_img);
231 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_actions_interfaces), menu_actions_interfaces_img);
232 gtk_widget_show (menu_actions_interfaces);
233 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_actions_interfaces);
234 gtk_widget_add_accelerator (menu_actions_interfaces, "activate", accel_group,
235 GDK_i, (GdkModifierType) GDK_CONTROL_MASK,
236 GTK_ACCEL_VISIBLE);
237
238 /* Menu Actions - Load Default */
239 menu_actions_load_default = gtk_image_menu_item_new_with_mnemonic (_("Load protocol _Default values"));
240 menu_actions_load_default_img = gtk_image_new_from_stock ("gtk-network", GTK_ICON_SIZE_MENU);
241 gtk_widget_show(menu_actions_load_default_img);
242 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_actions_load_default), menu_actions_load_default_img);
243 gtk_widget_show (menu_actions_load_default);
244 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_actions_load_default);
245 gtk_widget_add_accelerator (menu_actions_load_default, "activate", accel_group,
246 GDK_d, (GdkModifierType) GDK_CONTROL_MASK,
247 GTK_ACCEL_VISIBLE);
248
249 /* Menu Actions - List Attacks */
250 menu_actions_list_attacks = gtk_image_menu_item_new_with_mnemonic (_("_list attacks"));
251 menu_actions_list_attacks_img = gtk_image_new_from_stock ("gtk-justify-center", GTK_ICON_SIZE_MENU);
252 gtk_widget_show(menu_actions_list_attacks_img);
253 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_actions_list_attacks), menu_actions_list_attacks_img);
254 gtk_widget_show (menu_actions_list_attacks);
255 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_actions_list_attacks);
256 gtk_widget_add_accelerator (menu_actions_list_attacks, "activate", accel_group,
257 GDK_T, (GdkModifierType) GDK_CONTROL_MASK,
258 GTK_ACCEL_VISIBLE);
259
260 /* Menu Actions - Clear stats */
261 menu_actions_clear = gtk_image_menu_item_new_with_mnemonic (_("_Clear packet stats"));
262 menu_actions_clear_img = gtk_image_new_from_stock ("gtk-clear", GTK_ICON_SIZE_MENU);
263 gtk_widget_show(menu_actions_clear_img);
264 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_actions_clear), menu_actions_clear_img);
265 gtk_widget_show (menu_actions_clear);
266 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_actions_clear);
267
268 menu_actions_clear_menu = gtk_menu_new();
269 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_actions_clear), menu_actions_clear_menu);
270
271 /* Menu Actions - Clear stats - PROTO_NAME */
272 for (i = 0; i < MAX_PROTOCOLS; i++)
273 {
274 menu_clear_proto1 = gtk_menu_item_new_with_mnemonic (_(protocols[i].namep));
275 gtk_widget_set_name(menu_clear_proto1, protocols[i].namep);
276 if (protocols[i].visible)
277 gtk_widget_show (menu_clear_proto1);
278 gtk_container_add (GTK_CONTAINER (menu_actions_clear_menu), menu_clear_proto1);
279 g_signal_connect ((gpointer) menu_clear_proto1, "activate",
280 G_CALLBACK (gtk_c_on_actions_clear_activate),
281 helper);
282 }
283
284 /* Menu Actions - Clear stats - ALL PROTOCOLS */
285 menu_clear_proto1 = gtk_menu_item_new_with_mnemonic (_("All protocols"));
286 gtk_widget_set_name(menu_clear_proto1, "ALL");
287 gtk_widget_show (menu_clear_proto1);
288 gtk_container_add (GTK_CONTAINER (menu_actions_clear_menu), menu_clear_proto1);
289 g_signal_connect ((gpointer) menu_clear_proto1, "activate",
290 G_CALLBACK (gtk_c_on_actions_clear_activate),
291 helper);
292
293 /* Menu Actions - Capture Traffic */
294 menu_capture = gtk_image_menu_item_new_with_mnemonic (_("Capture traffic"));
295 menu_capture_img = gtk_image_new_from_stock("gtk-save", GTK_ICON_SIZE_MENU);
296 gtk_widget_show(menu_capture_img);
297 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_capture), menu_capture_img);
298 gtk_widget_show (menu_capture);
299 gtk_container_add (GTK_CONTAINER (menu_actions_menu), menu_capture);
300
301 menu_capture_menu = gtk_menu_new ();
302 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_capture), menu_capture_menu);
303
304 /* Menu Actions - Capture Traffic - PROTO_NAME */
305 for (i = 0; i < MAX_PROTOCOLS; i++)
306 {
307 menu_capture_proto1 = gtk_menu_item_new_with_mnemonic (_(protocols[i].namep));
308 gtk_widget_set_name(menu_capture_proto1, protocols[i].namep);
309 if (protocols[i].visible)
310 gtk_widget_show (menu_capture_proto1);
311 gtk_container_add (GTK_CONTAINER (menu_capture_menu), menu_capture_proto1);
312 g_signal_connect ((gpointer) menu_capture_proto1, "activate",
313 G_CALLBACK (gtk_c_on_capture_activate),
314 helper);
315 }
316
317 /* Menu Actions - Capture Traffic - ALL PROTOCOLS */
318 menu_capture_proto1 = gtk_menu_item_new_with_mnemonic (_("All protocols"));
319 gtk_widget_set_name(menu_capture_proto1, "ALL");
320 gtk_widget_show (menu_capture_proto1);
321 gtk_container_add (GTK_CONTAINER (menu_capture_menu), menu_capture_proto1);
322 g_signal_connect ((gpointer) menu_capture_proto1, "activate",
323 G_CALLBACK (gtk_c_on_capture_activate),
324 helper);
325
326 /* Menu Options */
327 menu_options = gtk_menu_item_new_with_mnemonic (_("_Options"));
328 gtk_widget_show (menu_options);
329 gtk_container_add (GTK_CONTAINER (main_menubar), menu_options);
330
331 menu_options_menu = gtk_menu_new ();
332 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_options), menu_options_menu);
333
334 /* Menu Options - MAC Spoofing */
335 menu_options_macspoofing = gtk_check_menu_item_new_with_mnemonic (_("_MAC Spoofing"));
336 if (helper->node->mac_spoofing)
337 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_options_macspoofing), TRUE);
338 else
339 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_options_macspoofing), FALSE);
340
341 gtk_widget_show (menu_options_macspoofing);
342 gtk_container_add (GTK_CONTAINER (menu_options_menu), menu_options_macspoofing);
343 gtk_widget_add_accelerator (menu_options_macspoofing, "activate", accel_group,
344 GDK_M, (GdkModifierType) GDK_CONTROL_MASK,
345 GTK_ACCEL_VISIBLE);
346
347 /* Menu Help */
348 menu_help = gtk_menu_item_new_with_mnemonic (_("_Help"));
349 gtk_widget_show (menu_help);
350 gtk_container_add (GTK_CONTAINER (main_menubar), menu_help);
351
352 menu_help_menu = gtk_menu_new ();
353 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_help), menu_help_menu);
354
355 /* Menu Help - About */
356 menu_help_about = gtk_image_menu_item_new_from_stock ("gtk-about", accel_group);
357 gtk_widget_show (menu_help_about);
358 gtk_container_add (GTK_CONTAINER (menu_help_menu), menu_help_about);
359
360 /* Toolbar */
361 toolbar = gtk_toolbar_new();
362 gtk_widget_show(toolbar);
363 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH);
364 gtk_toolbar_set_tooltips(GTK_TOOLBAR(toolbar), TRUE);
365 gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, FALSE, 0);
366 tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
367
368 /* Toolbar: launch attack */
369 toolbar_launch_img = gtk_image_new_from_stock ("gtk-execute", tmp_toolbar_icon_size);
370 gtk_widget_show (toolbar_launch_img);
371 toolbar_launch = (GtkWidget*) gtk_tool_button_new (toolbar_launch_img, _("Launch attack"));
372 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_launch), tooltips, ("Launch a specific attack"), NULL);
373 gtk_widget_show (toolbar_launch);
374 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_launch);
375
376 /* Toolbar: edit interfaces */
377 toolbar_interfaces_img = gtk_image_new_from_stock ("gtk-preferences", tmp_toolbar_icon_size);
378 gtk_widget_show (toolbar_interfaces_img);
379 toolbar_interfaces = (GtkWidget*) gtk_tool_button_new (toolbar_interfaces_img, _("Edit interfaces"));
380 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_interfaces), tooltips, ("Edit interfaces to sniff and inject data"), NULL);
381 gtk_widget_show (toolbar_interfaces);
382 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_interfaces);
383
384 /* Toolbar: load default values */
385 toolbar_default_img = gtk_image_new_from_stock ("gtk-network", tmp_toolbar_icon_size);
386 gtk_widget_show (toolbar_default_img);
387 toolbar_default = (GtkWidget*) gtk_tool_button_new (toolbar_default_img, _("Load default"));
388 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_default), tooltips, ("Load protocol default (and random) values"), NULL);
389 gtk_widget_show (toolbar_default);
390 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_default);
391
392 /* Toolbar: list attacks */
393 toolbar_list_attacks_img = gtk_image_new_from_stock ("gtk-justify-center", tmp_toolbar_icon_size);
394 gtk_widget_show (toolbar_list_attacks_img);
395 toolbar_list_attacks = (GtkWidget*) gtk_tool_button_new (toolbar_list_attacks_img, _("List attacks"));
396 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_list_attacks), tooltips, ("List running attacks (and kill them!)"), NULL);
397 gtk_widget_show (toolbar_list_attacks);
398 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_list_attacks);
399
400 /* Toolbar: clear */
401 toolbar_clear_img = gtk_image_new_from_stock ("gtk-clear", tmp_toolbar_icon_size);
402 gtk_widget_show (toolbar_clear_img);
403 toolbar_clear = (GtkWidget*) gtk_menu_tool_button_new (toolbar_clear_img, _("Clear stats"));
404 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_clear), tooltips, ("Clear ALL packet statistics"), NULL);
405 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_clear), menu_actions_clear_menu);
406 gtk_widget_show (toolbar_clear);
407 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_clear);
408
409 /* Toolbar: capture */
410 toolbar_capture_img = gtk_image_new_from_stock ("gtk-save", tmp_toolbar_icon_size);
411 gtk_widget_show (toolbar_capture_img);
412 toolbar_capture = (GtkWidget*) gtk_menu_tool_button_new (toolbar_capture_img, _("Capture"));
413 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_capture), tooltips, ("Capture traffic in PCAP format"), NULL);
414 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_capture), menu_capture_menu);
415 gtk_widget_show (toolbar_capture);
416 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_capture);
417
418 /* Toolbar: edit mode */
419 toolbar_edit = (GtkWidget*) gtk_toggle_tool_button_new ();
420 gtk_widget_show (toolbar_edit);
421 gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolbar_edit), _("Edit mode"));
422 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_edit), tooltips, ("Enable/Disable edit mode"), NULL);
423 toolbar_edit_img = gtk_image_new_from_stock ("gtk-edit", tmp_toolbar_icon_size);
424 gtk_widget_show (toolbar_edit_img);
425 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolbar_edit), toolbar_edit_img);
426 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_edit);
427 //gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toggletoolbutton1), TRUE);
428
429 /* Toolbar: quit */
430 toolbar_quit_img = gtk_image_new_from_stock ("gtk-quit", tmp_toolbar_icon_size);
431 gtk_widget_show (toolbar_quit_img);
432 toolbar_quit = (GtkWidget*) gtk_tool_button_new (toolbar_quit_img, _("Exit"));
433 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar_quit), tooltips, ("Quit: Bring da noize!!"), NULL);
434 gtk_widget_show (toolbar_quit);
435 gtk_container_add (GTK_CONTAINER (toolbar), toolbar_quit);
436
437 main_vbox_hpaned = gtk_hpaned_new ();
438 gtk_widget_show (main_vbox_hpaned);
439 gtk_box_pack_start (GTK_BOX (main_vbox), main_vbox_hpaned, TRUE, TRUE, 0);
440
441 main_vh_vpaned = gtk_vpaned_new ();
442 gtk_widget_show (main_vh_vpaned);
443 gtk_paned_pack1 (GTK_PANED (main_vbox_hpaned), main_vh_vpaned, FALSE, TRUE);
444
445 main_vhv_scroll = gtk_scrolled_window_new (NULL, NULL);
446 gtk_widget_set_size_request (main_vhv_scroll, 200, 250);
447 gtk_widget_show (main_vhv_scroll);
448 gtk_paned_pack1 (GTK_PANED (main_vh_vpaned), main_vhv_scroll, FALSE, TRUE);
449 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_vhv_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
450 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (main_vhv_scroll), GTK_SHADOW_IN);
451
452 main_vhvs_tree = gtk_tree_view_new();
453 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(main_vhvs_tree), TRUE);
454 main_vhvs_tree_model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
455
456 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (main_vhv_scroll), main_vhvs_tree);
457 gtk_tree_view_set_model (GTK_TREE_VIEW (main_vhvs_tree), GTK_TREE_MODEL (main_vhvs_tree_model));
458 gtk_widget_show (main_vhvs_tree);
459
460 for (i=0; i < MAX_PROTOCOLS; i++)
461 {
462 if (protocols[i].visible) {
463 gtk_list_store_append (GTK_LIST_STORE (main_vhvs_tree_model), &iter);
464 gtk_list_store_set (GTK_LIST_STORE(main_vhvs_tree_model), &iter, 0, protocols[i].namep, -1);
465 gtk_list_store_set (GTK_LIST_STORE(main_vhvs_tree_model), &iter, 1, protocols[i].packets, -1);
466 }
467 }
468 gtk_list_store_append (GTK_LIST_STORE (main_vhvs_tree_model), &iter);
469 gtk_list_store_set (GTK_LIST_STORE(main_vhvs_tree_model), &iter, 0, "Total", -1);
470
471 g_timeout_add(1000, (GSourceFunc)>k_c_tree_update, main_vhvs_tree_model);
472
473 cell = gtk_cell_renderer_text_new ();
474 cell2 = gtk_cell_renderer_text_new();
475
476 column = gtk_tree_view_column_new_with_attributes ("Protocols", cell, "text", 0, NULL);
477 gtk_tree_view_append_column (GTK_TREE_VIEW (main_vhvs_tree), GTK_TREE_VIEW_COLUMN (column));
478 g_object_set(cell, "background", "Blue", "background-set", TRUE, NULL);
479 g_object_set(cell, "foreground", "White", "foreground-set", TRUE, NULL);
480 column = gtk_tree_view_column_new_with_attributes ("Packets", cell2, "text", 1, NULL);
481 gtk_tree_view_append_column (GTK_TREE_VIEW (main_vhvs_tree), GTK_TREE_VIEW_COLUMN (column));
482
483 main_vhv_vbox = gtk_vbox_new (FALSE, 5);
484 gtk_widget_show (main_vhv_vbox);
485 gtk_paned_pack2 (GTK_PANED (main_vh_vpaned), main_vhv_vbox, TRUE, TRUE);
486
487 main_vhvv_scroll = gtk_scrolled_window_new (NULL, NULL);
488 gtk_widget_show (main_vhvv_scroll);
489 gtk_box_pack_start (GTK_BOX (main_vhv_vbox), main_vhvv_scroll, TRUE, TRUE, 0);
490 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_vhvv_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
491 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (main_vhvv_scroll), GTK_SHADOW_IN);
492
493 main_vhvvs_tree = gtk_tree_view_new();
494 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(main_vhvvs_tree), TRUE);
495 main_vhvvs_tree_model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
496
497 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (main_vhvv_scroll), main_vhvvs_tree);
498 gtk_tree_view_set_model (GTK_TREE_VIEW (main_vhvvs_tree), GTK_TREE_MODEL (main_vhvvs_tree_model));
499 gtk_widget_show (main_vhvvs_tree);
500
501 cell = gtk_cell_renderer_text_new ();
502
503 column = gtk_tree_view_column_new_with_attributes ("Field", cell, "text", 0, NULL);
504 gtk_tree_view_append_column (GTK_TREE_VIEW (main_vhvvs_tree), GTK_TREE_VIEW_COLUMN (column));
505 column = gtk_tree_view_column_new_with_attributes ("Value", cell, "text", 1, NULL);
506 gtk_tree_view_append_column (GTK_TREE_VIEW (main_vhvvs_tree), GTK_TREE_VIEW_COLUMN (column));
507 column = gtk_tree_view_column_new_with_attributes ("Description", cell, "text", 2, NULL);
508 gtk_tree_view_append_column (GTK_TREE_VIEW (main_vhvvs_tree), GTK_TREE_VIEW_COLUMN (column));
509
510 main_vhvv_eventbox = gtk_event_box_new();
511 gtk_widget_set_size_request (main_vhvv_eventbox, 20, 20);
512 //color.red = 0;
513 //color.green = 0;
514 //color.blue = 0;
515 //gtk_widget_modify_bg (GTK_WIDGET(main_vhvv_eventbox), GTK_STATE_NORMAL, &color);
516 gtk_container_set_border_width(GTK_CONTAINER(main_vhvv_eventbox), 1);
517 gtk_widget_show(main_vhvv_eventbox);
518 main_vhvv_clock = gtk_label_new(_("00:00:00"));
519 //gdk_color_parse ("green", &color);
520 //gtk_widget_modify_fg (GTK_WIDGET(main_vhvv_clock), GTK_STATE_NORMAL, &color);
521 gtk_widget_show(main_vhvv_clock);
522 gtk_box_pack_start (GTK_BOX (main_vhv_vbox), main_vhvv_eventbox, FALSE, TRUE, 0);
523 gtk_container_add(GTK_CONTAINER(main_vhvv_eventbox), main_vhvv_clock);
524
525 main_vh2_vpaned = gtk_vpaned_new();
526 gtk_widget_show(main_vh2_vpaned);
527 gtk_paned_pack2 (GTK_PANED (main_vbox_hpaned), main_vh2_vpaned, TRUE, TRUE);
528
529 main_vhv2_notebook = gtk_notebook_new ();
530 gtk_widget_show (main_vhv2_notebook);
531 helper->notebook = main_vhv2_notebook;
532 gtk_paned_pack1 (GTK_PANED (main_vh2_vpaned), main_vhv2_notebook, TRUE, TRUE);
533
534 GLADE_HOOKUP_OBJECT (Main, main_vhv2_notebook, "main_vhv2_notebook");
535 for (i=0; i < MAX_PROTOCOLS; i++)
536 {
537 protocols_vpaned[i] = create_protocol_mwindow(Main, helper, i);
538 if (protocols[i].visible)
539 gtk_widget_show(protocols_vpaned[i]);
540 gtk_container_add (GTK_CONTAINER (main_vhv2_notebook), protocols_vpaned[i]);
541
542 main_vhn_labels[i] = gtk_label_new (_(protocols[i].namep));
543
544 if (protocols[i].visible)
545 gtk_widget_show (main_vhn_labels[i]);
546 gtk_notebook_set_tab_label (GTK_NOTEBOOK (main_vhv2_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (main_vhv2_notebook), i), main_vhn_labels[i]);
547 }
548
549 /* Yersinia log viewer */
550 tty_tmp->buffer_log = gtk_text_buffer_new(NULL);
551
552 main_log_scroll = gtk_scrolled_window_new(NULL, NULL);
553 gtk_widget_show(main_log_scroll);
554 gtk_container_add(GTK_CONTAINER(main_vhv2_notebook), main_log_scroll);
555 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_log_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
556 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (main_log_scroll), GTK_SHADOW_IN);
557
558 main_log = gtk_text_view_new_with_buffer(tty_tmp->buffer_log);
559 gtk_text_view_set_editable(GTK_TEXT_VIEW(main_log), FALSE);
560 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(main_log), FALSE);
561 gtk_widget_show(main_log);
562 gtk_container_add (GTK_CONTAINER (main_log_scroll), main_log);
563
564 main_vhn_labels[MAX_PROTOCOLS] = gtk_label_new (_("Yersinia log"));
565 gtk_widget_show(main_vhn_labels[MAX_PROTOCOLS]);
566 gtk_tooltips_set_tip(tooltips, main_vhn_labels[MAX_PROTOCOLS], "Yersinia log for debugging purposes", NULL);
567 gtk_notebook_set_tab_label (GTK_NOTEBOOK (main_vhv2_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (main_vhv2_notebook), MAX_PROTOCOLS), main_vhn_labels[MAX_PROTOCOLS]);
568
569 /* Hexadecimal View */
570 main_vhv2_scrollhex = gtk_scrolled_window_new (NULL, NULL);
571 gtk_widget_show (main_vhv2_scrollhex);
572 gtk_paned_pack2 (GTK_PANED (main_vh2_vpaned), main_vhv2_scrollhex, FALSE, TRUE);
573 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_vhv2_scrollhex), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
574 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (main_vhv2_scrollhex), GTK_SHADOW_IN);
575
576 buffer_hex = gtk_text_buffer_new(NULL);
577
578 main_vhv2_texthex = gtk_text_view_new_with_buffer(buffer_hex);
579 /* We need to set a monospaced font for the alignment */
580 font_desc = pango_font_description_from_string ("Monospace 10");
581 gtk_widget_modify_font(main_vhv2_texthex, font_desc);
582 // pango_font_description_free(font_desc);
583 gtk_widget_show (main_vhv2_texthex);
584 gtk_container_add (GTK_CONTAINER (main_vhv2_scrollhex), main_vhv2_texthex);
585
586 gtk_paned_pack2 (GTK_PANED (main_vh2_vpaned), main_vhv2_scrollhex, TRUE, TRUE);
587
588 /* Status bar - botton of the screen */
589 helper->statusbar = gtk_statusbar_new ();
590
591 g_signal_connect( (gpointer)helper->statusbar, "destroy", G_CALLBACK( gtk_c_statusbar_destroy ), (gpointer)helper );
592
593 gtk_widget_show (helper->statusbar);
594
595 gtk_box_pack_start (GTK_BOX (main_vbox), helper->statusbar, FALSE, FALSE, 0);
596
597 helper->mode = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_vhv2_notebook));
598
599 /* Timeouts */
600 g_timeout_add(500, (GSourceFunc)gtk_c_refresh_mwindow, (gpointer)helper);
601 g_timeout_add(1000, (GSourceFunc)>k_c_clock_update, main_vhvv_clock);
602
603 /* Menu signals */
604
605 g_signal_connect ((gpointer) menu_file_open, "activate",
606 G_CALLBACK (gtk_c_on_file_open_activate),
607 helper);
608 g_signal_connect ((gpointer) menu_file_save, "activate",
609 G_CALLBACK (gtk_c_on_file_save_activate),
610 helper);
611 g_signal_connect ((gpointer) menu_file_quit, "activate",
612 G_CALLBACK (gtk_c_on_file_quit_activate),
613 helper);
614 g_signal_connect ((gpointer) menu_protocols_proto1, "activate",
615 G_CALLBACK (on_protocols_proto1_activate),
616 NULL);
617 g_signal_connect ((gpointer) menu_actions_execute, "activate",
618 G_CALLBACK (gtk_c_on_actions_execute_activate),
619 helper);
620 g_signal_connect ((gpointer) menu_actions_interfaces, "activate",
621 G_CALLBACK (gtk_c_on_actions_interfaces_activate),
622 helper);
623 g_signal_connect ((gpointer) menu_actions_load_default, "activate",
624 G_CALLBACK (gtk_c_on_menu_actions_load_default_activate),
625 helper);
626 g_signal_connect ((gpointer) menu_actions_list_attacks, "activate",
627 G_CALLBACK (gtk_c_on_menu_actions_list_attacks_activate),
628 helper);
629 g_signal_connect ((gpointer) menu_actions_clear, "activate",
630 G_CALLBACK (on_menu_actions_clear_activate),
631 main_vhv2_notebook);
632
633 g_signal_connect( (gpointer) menu_options_macspoofing, "toggled",
634 G_CALLBACK( on_menu_options_macspoofing_toggle ),
635 helper );
636 g_signal_connect( (gpointer) menu_help_about, "activate",
637 G_CALLBACK( gtk_i_create_aboutdialog ),
638 NULL );
639
640 /* Toolbar signals */
641 g_signal_connect ((gpointer) toolbar_launch, "clicked",
642 G_CALLBACK (gtk_c_on_actions_execute_activate),
643 helper);
644 g_signal_connect ((gpointer) toolbar_interfaces, "clicked",
645 G_CALLBACK (gtk_c_on_actions_interfaces_activate),
646 helper);
647 g_signal_connect ((gpointer) toolbar_default, "clicked",
648 G_CALLBACK (gtk_c_on_menu_actions_load_default_activate),
649 helper);
650 g_signal_connect ((gpointer) toolbar_list_attacks, "clicked",
651 G_CALLBACK (gtk_c_on_menu_actions_list_attacks_activate),
652 helper);
653 g_signal_connect ((gpointer) toolbar_clear, "clicked",
654 G_CALLBACK (on_menu_actions_clear_activate),
655 main_vhv2_notebook);
656 g_signal_connect ((gpointer) toolbar_edit, "toggled",
657 G_CALLBACK (gtk_c_on_menu_options_edit_toggle),
658 helper);
659 g_signal_connect ((gpointer) toolbar_quit, "clicked",
660 G_CALLBACK (gtk_c_on_file_quit_activate),
661 helper);
662
663 /* Mwindow signals */
664 g_signal_connect_after(G_OBJECT(main_vhv2_notebook), "switch-page",
665 G_CALLBACK(gtk_c_refresh_mwindow_notebook), helper);
666
667 /* Store pointers to all widgets, for use by lookup_widget(). */
668 GLADE_HOOKUP_OBJECT_NO_REF (Main, Main, "Main");
669 GLADE_HOOKUP_OBJECT (Main, main_vbox, "main_vbox");
670 GLADE_HOOKUP_OBJECT (Main, main_menubar, "main_menubar");
671 GLADE_HOOKUP_OBJECT (Main, menu_file, "menu_file");
672 GLADE_HOOKUP_OBJECT (Main, menu_file_menu, "menu_file_menu");
673 GLADE_HOOKUP_OBJECT (Main, menu_file_open, "menu_file_open");
674 GLADE_HOOKUP_OBJECT (Main, menu_file_save, "menu_file_save");
675 GLADE_HOOKUP_OBJECT (Main, separatormenuitem1, "separatormenuitem1");
676 GLADE_HOOKUP_OBJECT (Main, menu_file_quit, "menu_file_quit");
677 GLADE_HOOKUP_OBJECT (Main, menu_protocols, "menu_protocols");
678 GLADE_HOOKUP_OBJECT (Main, menu_protocols_menu, "menu_protocols_menu");
679 GLADE_HOOKUP_OBJECT (Main, menu_protocols_proto1, "menu_protocols_proto1");
680 GLADE_HOOKUP_OBJECT (Main, menu_actions, "menu_actions");
681 GLADE_HOOKUP_OBJECT (Main, menu_actions_menu, "menu_actions_menu");
682 GLADE_HOOKUP_OBJECT (Main, menu_actions_execute, "menu_actions_execute");
683 GLADE_HOOKUP_OBJECT (Main, menu_actions_interfaces, "menu_actions_interfaces");
684 GLADE_HOOKUP_OBJECT (Main, menu_actions_load_default, "menu_actions_load_default");
685 GLADE_HOOKUP_OBJECT (Main, menu_actions_list_attacks, "menu_actions_list_attacks");
686 GLADE_HOOKUP_OBJECT (Main, menu_actions_clear, "menu_actions_clear");
687 GLADE_HOOKUP_OBJECT (Main, menu_actions_clear_menu, "menu_actions_clear_menu");
688 GLADE_HOOKUP_OBJECT (Main, menu_clear_proto1, "menu_clear_proto1");
689 GLADE_HOOKUP_OBJECT (Main, menu_capture, "menu_capture");
690 GLADE_HOOKUP_OBJECT (Main, menu_capture_menu, "menu_capture_menu");
691 GLADE_HOOKUP_OBJECT (Main, menu_options, "menu_options");
692 GLADE_HOOKUP_OBJECT (Main, menu_options_menu, "menu_options_menu");
693 GLADE_HOOKUP_OBJECT (Main, menu_options_macspoofing, "menu_options_macspoofing");
694 GLADE_HOOKUP_OBJECT (Main, menu_help, "menu_help");
695 GLADE_HOOKUP_OBJECT (Main, menu_help_menu, "menu_help_menu");
696 GLADE_HOOKUP_OBJECT (Main, menu_help_about, "menu_help_about");
697 GLADE_HOOKUP_OBJECT (Main, toolbar_launch, "toolbar_launch");
698 GLADE_HOOKUP_OBJECT (Main, toolbar_interfaces, "toolbar_interfaces");
699 GLADE_HOOKUP_OBJECT (Main, toolbar_default, "toolbar_default");
700 GLADE_HOOKUP_OBJECT (Main, toolbar_list_attacks, "toolbar_list_attacks");
701 GLADE_HOOKUP_OBJECT (Main, toolbar_clear, "toolbar_clear");
702 GLADE_HOOKUP_OBJECT (Main, toolbar_capture, "toolbar_capture");
703 GLADE_HOOKUP_OBJECT (Main, toolbar_edit, "toolbar_edit");
704 GLADE_HOOKUP_OBJECT (Main, toolbar_quit, "toolbar_quit");
705 GLADE_HOOKUP_OBJECT (Main, main_vbox_hpaned, "main_vbox_hpaned");
706 GLADE_HOOKUP_OBJECT (Main, main_vh_vpaned, "main_vh_vpaned");
707 GLADE_HOOKUP_OBJECT (Main, main_vhv_scroll, "main_vhv_scroll");
708 GLADE_HOOKUP_OBJECT (Main, main_vhvs_tree, "main_vhvs_tree");
709 GLADE_HOOKUP_OBJECT (Main, main_vhv_vbox, "main_vhv_vbox");
710 GLADE_HOOKUP_OBJECT (Main, main_vhvv_scroll, "main_vhvv_scroll");
711 GLADE_HOOKUP_OBJECT (Main, main_vhvvs_tree, "main_vhvvs_tree");
712 GLADE_HOOKUP_OBJECT (Main, main_vhv2_texthex, "main_vhv2_texthex");
713 GLADE_HOOKUP_OBJECT (Main, main_vhvv_clock, "main_vhvv_clock");
714 GLADE_HOOKUP_OBJECT (Main, helper->statusbar, "statusbar");
715
716 gtk_window_add_accel_group (GTK_WINDOW (Main), accel_group);
717
718 return Main;
719 }
720
721
722 GtkWidget*
gtk_i_create_opendialog(struct gtk_s_helper * helper)723 gtk_i_create_opendialog (struct gtk_s_helper *helper)
724 {
725 GtkWidget *opendialog;
726 GtkWidget *opendialog_vbox;
727 GtkWidget *opendialog_buttons;
728 GtkWidget *opendialog_cancel_button;
729 GtkWidget *opendialog_ok_button;
730
731 opendialog = gtk_file_chooser_dialog_new (_("Open configuration file"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
732 GTK_WINDOW (opendialog)->type = GTK_WINDOW_TOPLEVEL;
733 gtk_window_set_type_hint (GTK_WINDOW (opendialog), GDK_WINDOW_TYPE_HINT_DIALOG);
734
735 opendialog_vbox = GTK_DIALOG (opendialog)->vbox;
736 gtk_widget_show (opendialog_vbox);
737
738 opendialog_buttons = GTK_DIALOG (opendialog)->action_area;
739 gtk_widget_show (opendialog_buttons);
740 gtk_button_box_set_layout (GTK_BUTTON_BOX (opendialog_buttons), GTK_BUTTONBOX_END);
741
742 opendialog_cancel_button = gtk_button_new_from_stock ("gtk-cancel");
743 gtk_widget_show (opendialog_cancel_button);
744 gtk_dialog_add_action_widget (GTK_DIALOG (opendialog), opendialog_cancel_button, GTK_RESPONSE_CANCEL);
745 GTK_WIDGET_SET_FLAGS (opendialog_cancel_button, GTK_CAN_DEFAULT);
746
747 opendialog_ok_button = gtk_button_new_from_stock ("gtk-open");
748 gtk_widget_show (opendialog_ok_button);
749 gtk_dialog_add_action_widget (GTK_DIALOG (opendialog), opendialog_ok_button, GTK_RESPONSE_OK);
750 GTK_WIDGET_SET_FLAGS (opendialog_ok_button, GTK_CAN_DEFAULT);
751
752 g_signal_connect_swapped ((gpointer) opendialog_cancel_button, "clicked",
753 G_CALLBACK (gtk_widget_destroy),
754 GTK_OBJECT (opendialog));
755
756 g_signal_connect ((gpointer) opendialog_ok_button, "clicked",
757 G_CALLBACK (gtk_c_opendialog_open),
758 helper);
759
760 /* Store pointers to all widgets, for use by lookup_widget(). */
761 GLADE_HOOKUP_OBJECT_NO_REF (opendialog, opendialog, "opendialog");
762 GLADE_HOOKUP_OBJECT_NO_REF (opendialog, opendialog_vbox, "opendialog_vbox");
763 GLADE_HOOKUP_OBJECT_NO_REF (opendialog, opendialog_buttons, "opendialog_buttons");
764 GLADE_HOOKUP_OBJECT (opendialog, opendialog_cancel_button, "opendialog_cancel_button");
765 GLADE_HOOKUP_OBJECT (opendialog, opendialog_ok_button, "opendialog_ok_button");
766
767 gtk_widget_grab_default (opendialog_ok_button);
768 return opendialog;
769 }
770
771
772 GtkWidget*
gtk_i_create_savedialog(struct gtk_s_helper * helper)773 gtk_i_create_savedialog (struct gtk_s_helper *helper)
774 {
775 GtkWidget *savedialog;
776 GtkWidget *savedialog_vbox;
777 GtkWidget *savedialog_buttons;
778 GtkWidget *savedialog_cancel_button;
779 GtkWidget *savedialog_ok_button;
780
781 savedialog = gtk_file_chooser_dialog_new (_("Save config file"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
782 GTK_WINDOW (savedialog)->type = GTK_WINDOW_TOPLEVEL;
783 gtk_window_set_type_hint (GTK_WINDOW (savedialog), GDK_WINDOW_TYPE_HINT_DIALOG);
784
785 savedialog_vbox = GTK_DIALOG (savedialog)->vbox;
786 gtk_widget_show (savedialog_vbox);
787
788 savedialog_buttons = GTK_DIALOG (savedialog)->action_area;
789 gtk_widget_show (savedialog_buttons);
790 gtk_button_box_set_layout (GTK_BUTTON_BOX (savedialog_buttons), GTK_BUTTONBOX_END);
791
792 savedialog_cancel_button = gtk_button_new_from_stock ("gtk-cancel");
793 gtk_widget_show (savedialog_cancel_button);
794 gtk_dialog_add_action_widget (GTK_DIALOG (savedialog), savedialog_cancel_button, GTK_RESPONSE_CANCEL);
795 GTK_WIDGET_SET_FLAGS (savedialog_cancel_button, GTK_CAN_DEFAULT);
796
797 savedialog_ok_button = gtk_button_new_from_stock ("gtk-open");
798 gtk_widget_show (savedialog_ok_button);
799 gtk_dialog_add_action_widget (GTK_DIALOG (savedialog), savedialog_ok_button, GTK_RESPONSE_OK);
800 GTK_WIDGET_SET_FLAGS (savedialog_ok_button, GTK_CAN_DEFAULT);
801
802 g_signal_connect_swapped ((gpointer) savedialog_cancel_button, "clicked",
803 G_CALLBACK (gtk_widget_destroy),
804 GTK_OBJECT (savedialog));
805
806 g_signal_connect ((gpointer) savedialog_ok_button, "clicked",
807 G_CALLBACK (gtk_c_savedialog_save),
808 helper);
809
810 /* Store pointers to all widgets, for use by lookup_widget(). */
811 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog, "savedialog");
812 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog_vbox, "savedialog_vbox");
813 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog_buttons, "savedialog_buttons");
814 GLADE_HOOKUP_OBJECT (savedialog, savedialog_cancel_button, "savedialog_cancel_button");
815 GLADE_HOOKUP_OBJECT (savedialog, savedialog_ok_button, "savedialog_ok_button");
816
817 gtk_widget_grab_default (savedialog_ok_button);
818
819 return savedialog;
820 }
821
822
823 GtkWidget*
gtk_i_create_capturedialog(struct gtk_s_helper * helper)824 gtk_i_create_capturedialog (struct gtk_s_helper *helper)
825 {
826 GtkWidget *savedialog;
827 GtkWidget *savedialog_vbox;
828 GtkWidget *savedialog_buttons;
829 GtkWidget *savedialog_cancel_button;
830 GtkWidget *savedialog_ok_button;
831
832 savedialog = gtk_file_chooser_dialog_new (_("Save capture file"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
833 GTK_WINDOW (savedialog)->type = GTK_WINDOW_TOPLEVEL;
834 //gtk_window_set_type_hint (GTK_WINDOW (savedialog), GDK_WINDOW_TYPE_HINT_DIALOG);
835
836 savedialog_vbox = GTK_DIALOG (savedialog)->vbox;
837 gtk_widget_show (savedialog_vbox);
838
839 savedialog_buttons = GTK_DIALOG (savedialog)->action_area;
840 gtk_widget_show (savedialog_buttons);
841 gtk_button_box_set_layout (GTK_BUTTON_BOX (savedialog_buttons), GTK_BUTTONBOX_END);
842
843 savedialog_cancel_button = gtk_button_new_from_stock ("gtk-cancel");
844 gtk_widget_show (savedialog_cancel_button);
845 gtk_dialog_add_action_widget (GTK_DIALOG (savedialog), savedialog_cancel_button, GTK_RESPONSE_CANCEL);
846 GTK_WIDGET_SET_FLAGS (savedialog_cancel_button, GTK_CAN_DEFAULT);
847
848 savedialog_ok_button = gtk_button_new_from_stock ("gtk-open");
849 gtk_widget_show (savedialog_ok_button);
850 gtk_dialog_add_action_widget (GTK_DIALOG (savedialog), savedialog_ok_button, GTK_RESPONSE_OK);
851 GTK_WIDGET_SET_FLAGS (savedialog_ok_button, GTK_CAN_DEFAULT);
852
853 g_signal_connect_swapped ((gpointer) savedialog_cancel_button, "clicked",
854 G_CALLBACK (gtk_widget_destroy),
855 GTK_OBJECT (savedialog));
856
857 g_signal_connect ((gpointer) savedialog_ok_button, "clicked",
858 G_CALLBACK (gtk_c_capturedialog_save),
859 helper);
860
861 /* Store pointers to all widgets, for use by lookup_widget(). */
862 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog, "savedialog");
863 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog_vbox, "savedialog_vbox");
864 GLADE_HOOKUP_OBJECT_NO_REF (savedialog, savedialog_buttons, "savedialog_buttons");
865 GLADE_HOOKUP_OBJECT (savedialog, savedialog_cancel_button, "savedialog_cancel_button");
866 GLADE_HOOKUP_OBJECT (savedialog, savedialog_ok_button, "savedialog_ok_button");
867
868 gtk_widget_grab_default (savedialog_ok_button);
869
870 return savedialog;
871 }
872
873
gtk_i_create_aboutdialog(GtkMenuItem * menuitem,gpointer user_data)874 void gtk_i_create_aboutdialog( GtkMenuItem *menuitem, gpointer user_data )
875
876 {
877 GtkWidget *aboutdialog;
878 int j;
879 const gchar *authors[] = {
880 "David Barroso Berrueta <tomac@yersinia.net>",
881 "Alfredo Andr\303\251s Omella <aandreswork@hotmail.com>",
882 NULL
883 };
884 gchar *translators = _("translator-credits");
885 GdkPixbuf *aboutdialog_logo_pixbuf;
886
887 aboutdialog = gtk_about_dialog_new();
888
889 gtk_about_dialog_set_version( GTK_ABOUT_DIALOG( aboutdialog ), VERSION );
890 gtk_about_dialog_set_name( GTK_ABOUT_DIALOG( aboutdialog ), _( "Yersinia" ) );
891 gtk_about_dialog_set_copyright( GTK_ABOUT_DIALOG( aboutdialog ), _( " Yersinia\n By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>\nCopyright 2005-2017 Alfredo Andres and David Barroso" ) );
892
893 j = term_motd();
894
895 if (j >= 0)
896 gtk_about_dialog_set_comments( GTK_ABOUT_DIALOG( aboutdialog ), _( vty_motd[j] ) );
897
898 gtk_about_dialog_set_license( GTK_ABOUT_DIALOG( aboutdialog ), LICENSE );
899 gtk_about_dialog_set_website( GTK_ABOUT_DIALOG( aboutdialog ), "http://www.yersinia.net");
900 gtk_about_dialog_set_website_label( GTK_ABOUT_DIALOG( aboutdialog), _("http://www.yersinia.net"));
901 gtk_about_dialog_set_authors( GTK_ABOUT_DIALOG( aboutdialog ), authors );
902 gtk_about_dialog_set_translator_credits( GTK_ABOUT_DIALOG( aboutdialog ), translators );
903
904 aboutdialog_logo_pixbuf = create_pixbuf( "yersinia.png" );
905
906 gtk_about_dialog_set_logo( GTK_ABOUT_DIALOG( aboutdialog ), aboutdialog_logo_pixbuf );
907
908 gtk_dialog_run( GTK_DIALOG( aboutdialog ) );
909
910 gtk_widget_destroy( aboutdialog );
911 }
912
913
gtk_i_create_attacksdialog(GtkWidget * notebook,struct gtk_s_helper * helper,u_int8_t mode)914 GtkWidget *gtk_i_create_attacksdialog( GtkWidget *notebook, struct gtk_s_helper *helper, u_int8_t mode )
915 {
916 GtkWidget *main_dialog;
917 GtkWidget *attacks_frame;
918 GtkWidget *attacks_vbox;
919 GtkWidget *attacks_v_table = NULL ;
920 GtkWidget *attacks_notebook;
921 GtkWidget *attacks_n_labels[MAX_PROTOCOLS];
922 GtkWidget *attacks_vt_radio_attack[MAX_PROTOCOLS];
923 GtkWidget *attacks_vt_label_attack = NULL ;
924 GtkWidget *attacks_vt_label_dos = NULL ;
925 GtkWidget *attacks_vt_check_attack1 = NULL ;
926 GtkWidget *attacks_v_hbox;
927 GtkWidget *attacks_vh_cancel_button;
928 GtkWidget *attacks_vh_ok_button;
929 struct _attack_definition *attack_def ;
930 u_int8_t i, j, num_attacks;
931
932 helper->attack_def = NULL ;
933 helper->row = 0 ;
934
935 main_dialog = gtk_window_new( GTK_WINDOW_TOPLEVEL );
936 gtk_window_set_title( GTK_WINDOW( main_dialog ), _( "Choose protocol attack" ) );
937 gtk_window_set_position( GTK_WINDOW( main_dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
938 gtk_window_set_resizable( GTK_WINDOW( main_dialog ), FALSE );
939
940 attacks_vbox = gtk_vbox_new (FALSE, 0);
941 gtk_widget_show (attacks_vbox);
942 gtk_container_add( GTK_CONTAINER( main_dialog ), attacks_vbox );
943
944 attacks_notebook = gtk_notebook_new ();
945 gtk_widget_show(attacks_notebook);
946
947 g_signal_connect_after( G_OBJECT(attacks_notebook), "switch-page", G_CALLBACK( gtk_c_attacks_synchro ), (gpointer)notebook );
948
949 gtk_box_pack_start( GTK_BOX( attacks_vbox ), attacks_notebook, TRUE, TRUE, 0 );
950
951 for (i=0; i < MAX_PROTOCOLS; i++)
952 {
953 if ( protocols[i].attack_def_list )
954 {
955 attack_def = protocols[i].attack_def_list;
956
957 attacks_frame = gtk_frame_new( " Choose attack ");
958 gtk_container_add( GTK_CONTAINER( attacks_notebook ), attacks_frame );
959 if ( protocols[i].visible )
960 gtk_widget_show( attacks_frame );
961
962 attacks_n_labels[i] = gtk_label_new (_(protocols[i].namep));
963
964 if (protocols[i].visible)
965 gtk_widget_show (attacks_n_labels[i]);
966
967 gtk_notebook_set_tab_label (GTK_NOTEBOOK (attacks_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (attacks_notebook), i), attacks_n_labels[i]);
968
969 attacks_v_table = gtk_table_new( 1, 3, FALSE );
970
971 gtk_widget_show (attacks_v_table);
972 gtk_container_add(GTK_CONTAINER(attacks_frame), attacks_v_table);
973 gtk_container_set_border_width (GTK_CONTAINER (attacks_v_table), 10);
974
975 attacks_vt_label_attack = gtk_label_new (_("Description"));
976 gtk_widget_show (attacks_vt_label_attack);
977 gtk_table_attach (GTK_TABLE (attacks_v_table), attacks_vt_label_attack, 0, 1, 0, 1,
978 (GtkAttachOptions) (GTK_FILL),
979 (GtkAttachOptions) (0), 0, 0);
980 gtk_misc_set_alignment (GTK_MISC (attacks_vt_label_attack), 0, 0.5);
981
982 attacks_vt_label_dos = gtk_label_new (_("DoS"));
983 gtk_widget_show (attacks_vt_label_dos);
984 gtk_table_attach (GTK_TABLE (attacks_v_table), attacks_vt_label_dos, 1, 2, 0, 1,
985 (GtkAttachOptions) (GTK_FILL),
986 (GtkAttachOptions) (0), 0, 0);
987 gtk_misc_set_alignment (GTK_MISC (attacks_vt_label_dos), 0, 0.5);
988
989 num_attacks = 0;
990
991 while ( attack_def[num_attacks].desc )
992 num_attacks++;
993
994 for(j = 0; j < num_attacks; j++)
995 {
996 if (j == 0)
997 attacks_vt_radio_attack[i] = gtk_radio_button_new_with_label( NULL, attack_def[j].desc );
998 else
999 attacks_vt_radio_attack[i] = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( attacks_vt_radio_attack[i] ), ( attack_def[j].desc ) );
1000
1001 gtk_widget_show (attacks_vt_radio_attack[i]);
1002
1003 g_signal_connect(attacks_vt_radio_attack[i], "toggled", (GCallback) gtk_c_attacks_radio_changed, helper);
1004
1005 gtk_table_attach (GTK_TABLE (attacks_v_table), attacks_vt_radio_attack[i], 0, 1, j+1, j+2,
1006 (GtkAttachOptions) (GTK_FILL),
1007 (GtkAttachOptions) (0), 0, 0);
1008
1009 attacks_vt_check_attack1 = gtk_check_button_new();
1010 gtk_widget_set_sensitive(GTK_WIDGET(attacks_vt_check_attack1), FALSE);
1011
1012 if ( attack_def[j].type == DOS )
1013 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attacks_vt_check_attack1), TRUE);
1014 else
1015 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attacks_vt_check_attack1), FALSE);
1016
1017 gtk_widget_show (attacks_vt_check_attack1);
1018 gtk_table_attach (GTK_TABLE (attacks_v_table), attacks_vt_check_attack1, 1, 2, j+1, j+2,
1019 (GtkAttachOptions) (GTK_FILL),
1020 (GtkAttachOptions) (0), 0, 0);
1021 }
1022 }
1023 }
1024
1025 /* Start in the same label than the main window */
1026 gtk_notebook_set_current_page( GTK_NOTEBOOK( attacks_notebook ), mode );
1027
1028 attacks_v_hbox = gtk_hbox_new( TRUE, 0 );
1029 gtk_widget_show(attacks_v_hbox);
1030 gtk_container_add( GTK_CONTAINER( attacks_vbox ), attacks_v_hbox );
1031
1032 attacks_vh_cancel_button = gtk_button_new_with_mnemonic (_("Cancel"));
1033 gtk_widget_show (attacks_vh_cancel_button);
1034 gtk_box_pack_start (GTK_BOX (attacks_v_hbox), attacks_vh_cancel_button, FALSE, TRUE, 0);
1035
1036 g_signal_connect_swapped((gpointer) attacks_vh_cancel_button, "clicked", G_CALLBACK( gtk_widget_destroy ), GTK_OBJECT( main_dialog ) );
1037
1038 attacks_vh_ok_button = gtk_button_new_with_mnemonic (_("OK"));
1039 gtk_widget_show (attacks_vh_ok_button);
1040 gtk_box_pack_start( GTK_BOX( attacks_v_hbox ), attacks_vh_ok_button, FALSE, TRUE, 0 );
1041
1042 g_signal_connect((gpointer) attacks_vh_ok_button, "clicked", G_CALLBACK( gtk_c_attacks_launch ), helper );
1043
1044 /* Store pointers to all widgets, for use by lookup_widget(). */
1045 GLADE_HOOKUP_OBJECT_NO_REF( main_dialog, main_dialog, "attacksdialog");
1046 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vbox, "attacks_vbox");
1047 GLADE_HOOKUP_OBJECT( main_dialog, attacks_v_table, "attacks_v_table");
1048 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vt_label_attack, "attacks_vt_label_attack");
1049 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vt_label_dos, "attacks_vt_label_dos");
1050 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vt_check_attack1, "attacks_vt_check_attack1");
1051 GLADE_HOOKUP_OBJECT( main_dialog, attacks_v_hbox, "attacks_v_hbox");
1052 GLADE_HOOKUP_OBJECT( main_dialog, attacks_notebook, "attacks_notebook");
1053 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vh_cancel_button, "attacks_vh_cancel_button");
1054 GLADE_HOOKUP_OBJECT( main_dialog, attacks_vh_ok_button, "attacks_vh_ok_button");
1055
1056 return main_dialog;
1057 }
1058
1059
1060 GtkWidget*
create_interfacesdialog(struct term_node * node)1061 create_interfacesdialog (struct term_node *node)
1062 {
1063 GtkWidget *interfacesdialog;
1064 GtkWidget *interfaces_frame;
1065 GtkWidget *interfaces_vbox;
1066 GtkWidget *interfaces_v_table;
1067 GtkWidget *interfaces_v_button;
1068 GtkWidget **int_checkb;
1069 dlist_t *p;
1070 struct interface_data *iface_data;
1071 u_int32_t i;
1072 void *found;
1073
1074 interfacesdialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1075 gtk_widget_set_size_request (interfacesdialog, 200, 150);
1076 gtk_window_set_title (GTK_WINDOW (interfacesdialog), _("Choose interfaces"));
1077 gtk_window_set_position (GTK_WINDOW (interfacesdialog), GTK_WIN_POS_CENTER_ON_PARENT);
1078
1079 interfaces_frame = gtk_frame_new(_("Select interfaces"));
1080 gtk_widget_show(interfaces_frame);
1081 gtk_container_add(GTK_CONTAINER (interfacesdialog), interfaces_frame);
1082
1083 interfaces_vbox = gtk_vbox_new (FALSE, 0);
1084 gtk_widget_show (interfaces_vbox);
1085 gtk_container_add (GTK_CONTAINER (interfaces_frame), interfaces_vbox);
1086
1087 interfaces_v_table = gtk_table_new (dlist_length(interfaces->list), 1, FALSE);
1088 gtk_widget_show (interfaces_v_table);
1089 gtk_box_pack_start (GTK_BOX (interfaces_vbox), interfaces_v_table, TRUE, TRUE, 0);
1090 gtk_container_set_border_width (GTK_CONTAINER (interfaces_v_table), 5);
1091
1092 int_checkb = (GtkWidget **) calloc(dlist_length(interfaces->list), sizeof(GtkWidget *));
1093 for (p = interfaces->list, i = 0; p; p = dlist_next(interfaces->list, p), i++) {
1094 iface_data = (struct interface_data *) dlist_data(p);
1095 found = dlist_search(node->used_ints->list, node->used_ints->cmp, (void *) iface_data->ifname);
1096 int_checkb[i] = gtk_check_button_new_with_mnemonic(iface_data->ifname);
1097 gtk_widget_show(int_checkb[i]);
1098 if (found)
1099 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(int_checkb[i]), TRUE);
1100 else
1101 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(int_checkb[i]), FALSE);
1102 gtk_table_attach (GTK_TABLE (interfaces_v_table), int_checkb[i], 0, 1, i, i + 1,
1103 (GtkAttachOptions) (GTK_FILL),
1104 (GtkAttachOptions) (0), 0, 0);
1105
1106 g_signal_connect (int_checkb[i], "toggled", G_CALLBACK (gtk_c_toggle_interface), node);
1107 }
1108
1109 interfaces_v_button = gtk_button_new_with_mnemonic (_("OK"));
1110 gtk_widget_show (interfaces_v_button);
1111 gtk_box_pack_start (GTK_BOX (interfaces_vbox), interfaces_v_button, FALSE, FALSE, 0);
1112
1113 g_signal_connect_swapped ((gpointer) interfaces_v_button, "clicked",
1114 G_CALLBACK (gtk_widget_destroy),
1115 GTK_OBJECT (interfacesdialog));
1116
1117 /* Store pointers to all widgets, for use by lookup_widget(). */
1118 GLADE_HOOKUP_OBJECT_NO_REF (interfacesdialog, interfacesdialog, "interfacesdialog");
1119 GLADE_HOOKUP_OBJECT (interfacesdialog, interfaces_vbox, "interfaces_vbox");
1120 GLADE_HOOKUP_OBJECT (interfacesdialog, interfaces_v_table, "interfaces_v_table");
1121 GLADE_HOOKUP_OBJECT (interfacesdialog, interfaces_v_button, "interfaces_v_button");
1122
1123 return interfacesdialog;
1124 }
1125
1126
gtk_i_create_listattacksdialog(struct term_node * node)1127 GtkWidget *gtk_i_create_listattacksdialog( struct term_node *node )
1128 {
1129 GtkWidget *main_dialog ;
1130 GtkWidget *frame ;
1131 GtkWidget *frame_vbox ;
1132 GtkWidget *main_vbox ;
1133 GtkWidget *attack_hbox ;
1134 GtkWidget *stop_button ;
1135 GtkWidget *quit_hbox ;
1136 GtkWidget *stopall_button ;
1137 GtkWidget *quit_button ;
1138 GtkWidget *label ;
1139 struct _attack_definition *attack_def ;
1140 u_int8_t i, j;
1141 int attack_count = 0 ;
1142 GTK_DIALOG_ATTACK_CONTEXT *dialog_ctx;
1143 GTK_ATTACK_CONTEXT *attack_ctx ;
1144
1145 dialog_ctx = (GTK_DIALOG_ATTACK_CONTEXT *)calloc( 1, sizeof( GTK_DIALOG_ATTACK_CONTEXT ) );
1146 dialog_ctx->enabled_attacks_list = (GTK_ATTACK_CONTEXT *)malloc( sizeof( GTK_ATTACK_CONTEXT ) * MAX_PROTOCOLS * MAX_THREAD_ATTACK );
1147
1148 attack_ctx = dialog_ctx->enabled_attacks_list ;
1149
1150 main_dialog = gtk_window_new( GTK_WINDOW_TOPLEVEL );
1151
1152 gtk_window_set_title( GTK_WINDOW( main_dialog ), _( "Running Attacks" ) );
1153 gtk_window_set_position( GTK_WINDOW( main_dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
1154 gtk_window_set_resizable( GTK_WINDOW( main_dialog ), FALSE );
1155
1156 dialog_ctx->dialog = main_dialog ;
1157 dialog_ctx->node = node ;
1158
1159 g_signal_connect( main_dialog, "delete_event", G_CALLBACK( gtk_c_listattacks_delete_event ), (gpointer)dialog_ctx );
1160
1161 frame = gtk_frame_new( NULL );
1162 frame_vbox = gtk_vbox_new( FALSE, 0 );
1163 main_vbox = gtk_vbox_new( FALSE, 0 );
1164
1165 gtk_box_pack_start( GTK_BOX( main_vbox ), frame, FALSE, FALSE, 0 );
1166
1167 /* Attacks list... */
1168 for( i = 0; i < MAX_PROTOCOLS; i++ )
1169 {
1170 attack_def = protocols[i].attack_def_list;
1171
1172 for( j = 0; j < MAX_THREAD_ATTACK; j++ )
1173 {
1174 if ( node->protocol[i].attacks[j].up )
1175 {
1176 attack_hbox = gtk_hbox_new( FALSE, 5 );
1177
1178 /* Attack Proto */
1179 label = gtk_label_new( protocols[i].namep );
1180 gtk_widget_show( label );
1181 gtk_box_pack_start( GTK_BOX( attack_hbox ), label, FALSE, FALSE, 5 );
1182
1183 /* Attack Description... */
1184 label = gtk_label_new( attack_def[ node->protocol[ i ].attacks[ j ].attack ].desc );
1185 gtk_widget_show( label );
1186 gtk_box_pack_start( GTK_BOX( attack_hbox ), label, FALSE, FALSE, 0 );
1187
1188 /* Attack stop button... */
1189 stop_button = gtk_button_new_with_label( " Stop " );
1190 gtk_widget_show( stop_button );
1191 gtk_box_pack_end( GTK_BOX( attack_hbox ), stop_button, FALSE, FALSE, 5 );
1192
1193 attack_ctx->protocol = i ;
1194 attack_ctx->attack = j ;
1195 attack_ctx->dialog = main_dialog ;
1196 attack_ctx->node = node ;
1197 attack_ctx->h_box = attack_hbox ;
1198
1199 g_signal_connect( (gpointer)stop_button, "clicked", G_CALLBACK( gtk_c_listattacks_stop_click ), (gpointer)attack_ctx );
1200
1201 attack_ctx++;
1202
1203 gtk_box_pack_start( GTK_BOX( frame_vbox ), attack_hbox, FALSE, FALSE, 3 );
1204 gtk_widget_show( attack_hbox );
1205
1206 attack_count++;
1207 }
1208 }
1209 }
1210
1211 /* Bottom buttons... */
1212 quit_hbox = gtk_hbox_new( FALSE, 0 );
1213
1214 if ( attack_count )
1215 {
1216 stopall_button = gtk_button_new_with_label( " Stop ALL " );
1217 g_signal_connect( (gpointer)stopall_button, "clicked", G_CALLBACK( gtk_c_listattacks_stopall_click ), (gpointer)dialog_ctx );
1218 gtk_box_pack_start( GTK_BOX( quit_hbox ), stopall_button, TRUE, FALSE, 0 );
1219 gtk_widget_show( stopall_button );
1220 }
1221 else
1222 {
1223 label = gtk_label_new( " No attacks currently running " );
1224 gtk_widget_show( label );
1225 gtk_box_pack_start( GTK_BOX( frame_vbox ), label, FALSE, FALSE, 10 );
1226 }
1227
1228 quit_button = gtk_button_new_with_label( " Quit " );
1229 g_signal_connect( (gpointer)quit_button, "clicked", G_CALLBACK( gtk_c_listattacks_quit_click ), (gpointer)dialog_ctx );
1230 gtk_box_pack_start( GTK_BOX( quit_hbox ), quit_button, TRUE, FALSE, 0 );
1231
1232 gtk_box_pack_start( GTK_BOX( main_vbox ), quit_hbox, FALSE, FALSE, 5 );
1233
1234 gtk_widget_show( quit_button );
1235 gtk_widget_show( quit_hbox );
1236
1237 gtk_widget_show( frame_vbox );
1238 gtk_widget_show( frame );
1239 gtk_widget_show( main_vbox );
1240
1241 gtk_container_add( GTK_CONTAINER( frame ), frame_vbox );
1242 gtk_container_add( GTK_CONTAINER( main_dialog ), main_vbox );
1243
1244 return main_dialog ;
1245 }
1246
1247
gtk_i_modaldialog(int gtk_msg_type,char * header,char * msg,...)1248 void gtk_i_modaldialog( int gtk_msg_type, char *header, char *msg, ...)
1249 {
1250 GtkWidget *dialog ;
1251 va_list ap ;
1252 char *buffer = (char *)malloc( 2048 );
1253
1254 if ( buffer )
1255 {
1256 va_start( ap, msg );
1257 vsnprintf( buffer, 2048, msg, ap );
1258 va_end( ap );
1259
1260 if ( header )
1261 dialog = gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1262 gtk_msg_type, GTK_BUTTONS_OK,
1263 "%s", header );
1264 else
1265 dialog = gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1266 gtk_msg_type, GTK_BUTTONS_OK,
1267 NULL );
1268
1269 gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( dialog ), "%s", buffer );
1270
1271 gtk_dialog_run( GTK_DIALOG( dialog ) );
1272
1273 gtk_widget_destroy( dialog );
1274
1275 free( buffer );
1276 }
1277 }
1278
1279 GtkWidget*
gtk_i_create_warningdialog(char * msg,...)1280 gtk_i_create_warningdialog (char *msg, ...)
1281 {
1282 GtkWidget *warningdialog;
1283 GtkWidget *warning_vbox;
1284 GtkWidget *warning_v_scroll;
1285 GtkWidget *warning_vs_text;
1286 GtkWidget *warning_v_button;
1287 va_list ap;
1288 char buffer[4096];
1289
1290 va_start(ap, msg);
1291 vsnprintf(buffer, 4096, msg, ap);
1292 va_end(ap);
1293
1294 warningdialog = gtk_window_new (GTK_WINDOW_POPUP);
1295 gtk_widget_set_size_request (warningdialog, 200, 150);
1296 gtk_window_set_title (GTK_WINDOW (warningdialog), _("Warning"));
1297 gtk_window_set_position (GTK_WINDOW (warningdialog), GTK_WIN_POS_CENTER_ON_PARENT);
1298 gtk_window_set_type_hint (GTK_WINDOW (warningdialog), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
1299
1300 warning_vbox = gtk_vbox_new (FALSE, 0);
1301 gtk_widget_show (warning_vbox);
1302 gtk_container_add (GTK_CONTAINER (warningdialog), warning_vbox);
1303
1304 warning_v_scroll = gtk_scrolled_window_new (NULL, NULL);
1305 gtk_widget_show (warning_v_scroll);
1306 gtk_box_pack_start (GTK_BOX (warning_vbox), warning_v_scroll, TRUE, TRUE, 0);
1307 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (warning_v_scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
1308 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (warning_v_scroll), GTK_SHADOW_IN);
1309
1310 warning_vs_text = gtk_text_view_new ();
1311 gtk_widget_show (warning_vs_text);
1312 gtk_container_add (GTK_CONTAINER (warning_v_scroll), warning_vs_text);
1313 gtk_text_view_set_editable (GTK_TEXT_VIEW (warning_vs_text), FALSE);
1314 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (warning_vs_text), GTK_WRAP_WORD);
1315 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (warning_vs_text), FALSE);
1316 gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (warning_vs_text)), (buffer), -1);
1317
1318 warning_v_button = gtk_button_new_with_mnemonic (_("OK"));
1319 gtk_widget_show (warning_v_button);
1320 gtk_box_pack_start (GTK_BOX (warning_vbox), warning_v_button, FALSE, FALSE, 0);
1321
1322 g_signal_connect_swapped ((gpointer) warning_v_button, "clicked",
1323 G_CALLBACK (gtk_widget_destroy),
1324 GTK_OBJECT (warningdialog));
1325
1326 /* Store pointers to all widgets, for use by lookup_widget(). */
1327 GLADE_HOOKUP_OBJECT_NO_REF (warningdialog, warningdialog, "warningdialog");
1328 GLADE_HOOKUP_OBJECT (warningdialog, warning_vbox, "warning_vbox");
1329 GLADE_HOOKUP_OBJECT (warningdialog, warning_v_scroll, "warning_v_scroll");
1330 GLADE_HOOKUP_OBJECT (warningdialog, warning_vs_text, "warning_vs_text");
1331 GLADE_HOOKUP_OBJECT (warningdialog, warning_v_button, "warning_v_button");
1332
1333 return warningdialog;
1334 }
1335
1336
1337 GtkWidget*
gtk_i_create_extradialog(struct gtk_s_helper * helper)1338 gtk_i_create_extradialog (struct gtk_s_helper *helper)
1339 {
1340 GtkWidget *extradialog;
1341 GtkWidget *extra_vbox;
1342 GtkWidget *extra_v_scroll;
1343 GtkWidget *extra_vs_text;
1344 GtkWidget *extra_v_button_add, *extra_v_button_remove, *extra_v_button_ok;
1345
1346 extradialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1347 gtk_widget_set_size_request (extradialog, 200, 150);
1348 gtk_window_set_title (GTK_WINDOW (extradialog), _("Extra parameters"));
1349 gtk_window_set_position (GTK_WINDOW (extradialog), GTK_WIN_POS_CENTER_ON_PARENT);
1350 gtk_window_set_type_hint (GTK_WINDOW (extradialog), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
1351
1352 extra_vbox = gtk_vbox_new (FALSE, 0);
1353 gtk_widget_show (extra_vbox);
1354 gtk_container_add (GTK_CONTAINER (extradialog), extra_vbox);
1355
1356 extra_v_scroll = gtk_scrolled_window_new (NULL, NULL);
1357 gtk_widget_show (extra_v_scroll);
1358 gtk_box_pack_start (GTK_BOX (extra_vbox), extra_v_scroll, TRUE, TRUE, 0);
1359 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (extra_v_scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
1360 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (extra_v_scroll), GTK_SHADOW_IN);
1361
1362 extra_vs_text = gtk_text_view_new ();
1363 gtk_widget_show (extra_vs_text);
1364 gtk_container_add (GTK_CONTAINER (extra_v_scroll), extra_vs_text);
1365
1366 extra_v_button_add = gtk_button_new_with_mnemonic (_("Add"));
1367 gtk_widget_show (extra_v_button_add);
1368 gtk_box_pack_start (GTK_BOX (extra_vbox), extra_v_button_add, FALSE, FALSE, 0);
1369
1370 extra_v_button_remove = gtk_button_new_with_mnemonic (_("Remove"));
1371 gtk_widget_show (extra_v_button_remove);
1372 gtk_box_pack_start (GTK_BOX (extra_vbox), extra_v_button_remove, FALSE, FALSE, 0);
1373
1374 extra_v_button_ok = gtk_button_new_with_mnemonic (_("OK"));
1375 gtk_widget_show (extra_v_button_ok);
1376 gtk_box_pack_start (GTK_BOX (extra_vbox), extra_v_button_ok, FALSE, FALSE, 0);
1377
1378 g_signal_connect ((gpointer) extra_v_button_add, "clicked",
1379 G_CALLBACK (gtk_c_extra_button_add_clicked),
1380 (gpointer) helper);
1381
1382 g_signal_connect_swapped ((gpointer) extra_v_button_ok, "clicked",
1383 G_CALLBACK (gtk_widget_destroy),
1384 GTK_OBJECT (extradialog));
1385
1386 /* Store pointers to all widgets, for use by lookup_widget(). */
1387 GLADE_HOOKUP_OBJECT_NO_REF (extradialog, extradialog, "extradialog");
1388 GLADE_HOOKUP_OBJECT (extradialog, extra_vbox, "extra_vbox");
1389 GLADE_HOOKUP_OBJECT (extradialog, extra_v_scroll, "extra_v_scroll");
1390 GLADE_HOOKUP_OBJECT (extradialog, extra_vs_text, "extra_vs_text");
1391 GLADE_HOOKUP_OBJECT (extradialog, extra_v_button_ok, "extra_v_button_ok");
1392
1393 return extradialog;
1394 }
1395
1396
1397 GtkWidget*
gtk_i_create_add_extradialog(struct gtk_s_helper * helper,u_int8_t proto)1398 gtk_i_create_add_extradialog (struct gtk_s_helper *helper, u_int8_t proto)
1399 {
1400 GtkWidget *add_extradialog;
1401 GtkWidget *add_extra_vbox;
1402 GtkWidget *add_extra_v_table;
1403 GtkWidget *add_extra_v_lcombo, *add_extra_v_lentry;
1404 GtkWidget *add_extra_v_combo;
1405 GtkWidget *add_extra_v_entry;
1406 GtkWidget *add_extra_v_hbox;
1407 GtkWidget *add_extra_v_button_cancel, *add_extra_v_button_ok;
1408 struct commands_param_extra *params;
1409 u_int8_t i;
1410
1411 add_extradialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1412 gtk_window_set_title (GTK_WINDOW (add_extradialog), _("Add add_extra parameter"));
1413 gtk_window_set_position (GTK_WINDOW (add_extradialog), GTK_WIN_POS_CENTER_ON_PARENT);
1414 gtk_window_set_type_hint (GTK_WINDOW (add_extradialog), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
1415
1416 add_extra_vbox = gtk_vbox_new (FALSE, 0);
1417 gtk_widget_show (add_extra_vbox);
1418 gtk_container_add (GTK_CONTAINER (add_extradialog), add_extra_vbox);
1419
1420 add_extra_v_table = gtk_table_new(2, 2, TRUE);
1421 gtk_widget_show(add_extra_v_table);
1422 gtk_box_pack_start (GTK_BOX (add_extra_vbox), add_extra_v_table, FALSE, FALSE, 0);
1423
1424 add_extra_v_lcombo = gtk_label_new("Choose type");
1425 gtk_widget_show(add_extra_v_lcombo);
1426 gtk_table_attach(GTK_TABLE(add_extra_v_table), add_extra_v_lcombo, 0, 1, 0, 1,
1427 (GtkAttachOptions) (GTK_FILL),
1428 (GtkAttachOptions) (0), 0, 0);
1429
1430 add_extra_v_combo = gtk_combo_box_new_text();
1431 gtk_widget_show(add_extra_v_combo);
1432 gtk_table_attach(GTK_TABLE(add_extra_v_table), add_extra_v_combo, 1, 2, 0, 1,
1433 (GtkAttachOptions) (GTK_FILL),
1434 (GtkAttachOptions) (0), 0, 0);
1435
1436 add_extra_v_lentry = gtk_label_new("Set value");
1437 gtk_widget_show(add_extra_v_lentry);
1438 gtk_table_attach(GTK_TABLE(add_extra_v_table), add_extra_v_lentry, 0, 1, 1, 2,
1439 (GtkAttachOptions) (GTK_FILL),
1440 (GtkAttachOptions) (0), 0, 0);
1441
1442 add_extra_v_entry = gtk_entry_new();
1443 gtk_widget_show(add_extra_v_entry);
1444 gtk_table_attach(GTK_TABLE(add_extra_v_table), add_extra_v_entry, 1, 2, 1, 2,
1445 (GtkAttachOptions) (GTK_FILL),
1446 (GtkAttachOptions) (0), 0, 0);
1447
1448 if (protocols[proto].extra_nparams > 0) {
1449 params = protocols[proto].extra_parameters;
1450 for (i = 0; i < protocols[proto].extra_nparams; i++) {
1451 gtk_combo_box_append_text(GTK_COMBO_BOX(add_extra_v_combo), params[i].desc);
1452 }
1453 }
1454
1455 add_extra_v_hbox = gtk_hbox_new(FALSE, 0);
1456 gtk_widget_show(add_extra_v_hbox);
1457 gtk_container_add (GTK_CONTAINER (add_extra_vbox), add_extra_v_hbox);
1458
1459 add_extra_v_button_cancel = gtk_button_new_with_mnemonic (_("Cancel"));
1460 gtk_widget_show (add_extra_v_button_cancel);
1461 gtk_box_pack_start (GTK_BOX (add_extra_v_hbox), add_extra_v_button_cancel, FALSE, TRUE, 0);
1462
1463 add_extra_v_button_ok = gtk_button_new_with_mnemonic (_("OK"));
1464 gtk_widget_show (add_extra_v_button_ok);
1465 gtk_box_pack_start (GTK_BOX (add_extra_v_hbox), add_extra_v_button_ok, FALSE, TRUE, 0);
1466
1467 g_signal_connect_swapped ((gpointer) add_extra_v_button_cancel, "clicked",
1468 G_CALLBACK (gtk_widget_destroy),
1469 GTK_OBJECT (add_extradialog));
1470
1471 g_signal_connect ((gpointer) add_extra_v_button_ok, "clicked",
1472 G_CALLBACK (gtk_c_add_extra_button_add_ok_clicked),
1473 helper);
1474
1475 /* Store pointers to all widgets, for use by lookup_widget(). */
1476 GLADE_HOOKUP_OBJECT_NO_REF (add_extradialog, add_extradialog, "add_extradialog");
1477 GLADE_HOOKUP_OBJECT (add_extradialog, add_extra_vbox, "add_extra_vbox");
1478 GLADE_HOOKUP_OBJECT (add_extradialog, add_extra_v_button_ok, "add_extra_v_button_ok");
1479
1480 return add_extradialog;
1481 }
1482
1483
gtk_i_create_attackparamsdialog(GTK_ATTACK_PARAMS_CONTEXT * params_ctx)1484 GtkWidget *gtk_i_create_attackparamsdialog( GTK_ATTACK_PARAMS_CONTEXT *params_ctx )
1485 {
1486 GtkWidget *main_dialog ;
1487 GtkWidget *main_vbox ;
1488 GtkWidget *frame;
1489 GtkWidget *frame_vbox;
1490 GtkWidget *param_hbox;
1491 GtkWidget *label;
1492 GtkWidget *button_hbox ;
1493 GtkWidget *cancel_button;
1494 GtkWidget *ok_button;
1495 u_int8_t i;
1496 gchar *title_text = g_strconcat( protocols[ params_ctx->helper->mode ].namep, " attack parameters", NULL );
1497 gchar *frame_text = g_strconcat( " ", protocols[ params_ctx->helper->mode ].attack_def_list[ params_ctx->helper->row ].desc, " ", NULL );
1498
1499 main_dialog = gtk_window_new( GTK_WINDOW_TOPLEVEL );
1500
1501 gtk_window_set_title( GTK_WINDOW( main_dialog ), _( title_text ) );
1502 g_free( title_text );
1503
1504 gtk_window_set_position( GTK_WINDOW( main_dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
1505 gtk_window_set_resizable( GTK_WINDOW( main_dialog ), FALSE );
1506
1507 params_ctx->dialog = main_dialog ;
1508
1509 main_vbox = gtk_vbox_new( FALSE, 0 );
1510 gtk_container_add( GTK_CONTAINER( main_dialog ), main_vbox );
1511
1512 frame = gtk_frame_new( _( frame_text ) );
1513 g_free( frame_text );
1514 gtk_box_pack_start( GTK_BOX( main_vbox ), frame, FALSE, FALSE, 0 );
1515
1516 frame_vbox = gtk_vbox_new( FALSE, 0 );
1517 gtk_container_add( GTK_CONTAINER( frame ), frame_vbox );
1518
1519 for (i = 0; i < params_ctx->nparams; i++)
1520 {
1521 param_hbox = gtk_hbox_new( FALSE, 5 );
1522
1523 label = gtk_label_new( _( params_ctx->params_list[i].desc ) );
1524 gtk_widget_show( label );
1525 gtk_box_pack_start( GTK_BOX( param_hbox ), label, FALSE, FALSE, 5 );
1526
1527 params_ctx->vh_entry[i] = gtk_entry_new();
1528
1529 gtk_entry_set_editable( GTK_ENTRY( params_ctx->vh_entry[i]), TRUE );
1530 gtk_entry_set_width_chars( GTK_ENTRY( params_ctx->vh_entry[i] ), params_ctx->params_list[i].size_print );
1531 gtk_entry_set_max_length( GTK_ENTRY( params_ctx->vh_entry[i] ), params_ctx->params_list[i].size_print );
1532
1533 gtk_widget_show( params_ctx->vh_entry[i] );
1534 gtk_box_pack_end( GTK_BOX( param_hbox ), params_ctx->vh_entry[i], FALSE, FALSE, 5 );
1535
1536 gtk_box_pack_start( GTK_BOX( frame_vbox ), param_hbox, FALSE, FALSE, 3 );
1537 gtk_widget_show( param_hbox );
1538 }
1539
1540 button_hbox = gtk_hbox_new( FALSE, 0 );
1541 gtk_box_pack_start( GTK_BOX( main_vbox ), button_hbox, FALSE, FALSE, 5 );
1542
1543 cancel_button = gtk_button_new_with_mnemonic( _( "Cancel" ) );
1544 g_signal_connect( (gpointer) cancel_button, "clicked", G_CALLBACK( gtk_c_attackparams_cancel_click ), (gpointer)params_ctx );
1545 gtk_box_pack_start( GTK_BOX( button_hbox ), cancel_button, TRUE, FALSE, 0 );
1546
1547 ok_button = gtk_button_new_with_mnemonic( _( " OK " ) );
1548 g_signal_connect( (gpointer) ok_button, "clicked", G_CALLBACK( gtk_c_attackparams_ok_click ), (gpointer)params_ctx );
1549 gtk_box_pack_start( GTK_BOX( button_hbox ), ok_button, TRUE, FALSE, 0 );
1550
1551 gtk_widget_show( cancel_button );
1552 gtk_widget_show( ok_button );
1553 gtk_widget_show( button_hbox );
1554
1555 gtk_widget_show( frame_vbox );
1556 gtk_widget_show( frame );
1557 gtk_widget_show( main_vbox );
1558
1559 g_signal_connect( main_dialog, "delete_event", G_CALLBACK( gtk_c_attackparams_delete_event ), (gpointer)params_ctx );
1560
1561 return main_dialog;
1562 }
1563
1564
1565 GtkWidget*
create_protocol_mwindow(GtkWidget * Main,struct gtk_s_helper * helper,u_int8_t proto)1566 create_protocol_mwindow(GtkWidget *Main, struct gtk_s_helper *helper, u_int8_t proto)
1567 {
1568 u_int8_t i, total, row;
1569 struct commands_param *params;
1570 struct commands_param_extra *extra_params;
1571 GtkWidget *vpaned, *fields_vbox, *fields_hbox[5], *field_label;
1572 GtkWidget *scroll, *vbox, *frame, *fixed;
1573 GtkWidget *entry[20], *extra_button;
1574 GtkCellRenderer *cell;
1575 GtkTreeViewColumn *column;
1576 GType *types;
1577 PangoFontDescription *font_desc;
1578 char tmp_name[5], msg[1024];
1579
1580 params = protocols[proto].parameters;
1581 extra_params = protocols[proto].extra_parameters;
1582
1583 total = 0;
1584
1585 for (i = 0; i < protocols[proto].nparams; i++) {
1586 if (params[i].mwindow)
1587 total++;
1588 }
1589 for (i = 0; i < protocols[proto].extra_nparams; i++) {
1590 if (extra_params[i].mwindow)
1591 total++;
1592 }
1593
1594 vpaned = gtk_vpaned_new ();
1595
1596 scroll = gtk_scrolled_window_new (NULL, NULL);
1597 gtk_widget_show (scroll);
1598 // gtk_paned_pack1 (GTK_PANED (vpaned), scroll, TRUE, TRUE);
1599 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1600 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
1601
1602 protocols_tree[proto] = gtk_tree_view_new();
1603 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(protocols_tree[proto]), TRUE);
1604
1605 /* +4 for the index, interface, total count and the timestamp */
1606 types = g_new0 (GType, total + 4);
1607
1608 types[0] = G_TYPE_INT;
1609 for (i = 1; i < total + 4; i++) {
1610 if (i == total + 4 - 2)
1611 types[i] = G_TYPE_ULONG;
1612 else
1613 types[i] = G_TYPE_STRING;
1614 }
1615
1616 protocols_tree_model[proto] = gtk_list_store_newv(total + 4, types);
1617 g_free(types);
1618
1619 gtk_widget_set_size_request (scroll, 250, 250);
1620 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), protocols_tree[proto]);
1621 gtk_tree_view_set_model (GTK_TREE_VIEW(protocols_tree[proto]), GTK_TREE_MODEL(protocols_tree_model[proto]));
1622 g_object_unref(protocols_tree_model[proto]);
1623 gtk_widget_show (protocols_tree[proto]);
1624
1625 cell = gtk_cell_renderer_text_new ();
1626
1627 total = 1;
1628 for (i = 0; i < protocols[proto].nparams; i++) {
1629 if (params[i].mwindow) {
1630 column = gtk_tree_view_column_new_with_attributes (params[i].ldesc, cell, "text", total, NULL);
1631 gtk_tree_view_append_column (GTK_TREE_VIEW (protocols_tree[proto]), GTK_TREE_VIEW_COLUMN (column));
1632 total++;
1633 }
1634 }
1635
1636 for (i = 0; i < protocols[proto].extra_nparams; i++) {
1637 if (extra_params[i].mwindow) {
1638 column = gtk_tree_view_column_new_with_attributes (extra_params[i].ldesc, cell, "text", total, NULL);
1639 gtk_tree_view_append_column (GTK_TREE_VIEW (protocols_tree[proto]), GTK_TREE_VIEW_COLUMN (column));
1640 total++;
1641 }
1642 }
1643
1644 column = gtk_tree_view_column_new_with_attributes ("Interface", cell, "text", total, NULL);
1645 gtk_tree_view_append_column (GTK_TREE_VIEW (protocols_tree[proto]), GTK_TREE_VIEW_COLUMN (column));
1646 total++;
1647 column = gtk_tree_view_column_new_with_attributes ("Count", cell, "text", total, NULL);
1648 gtk_tree_view_append_column (GTK_TREE_VIEW (protocols_tree[proto]), GTK_TREE_VIEW_COLUMN (column));
1649 total++;
1650 column = gtk_tree_view_column_new_with_attributes ("Last seen", cell, "text", total, NULL);
1651 gtk_tree_view_append_column (GTK_TREE_VIEW (protocols_tree[proto]), GTK_TREE_VIEW_COLUMN (column));
1652
1653 /* Setup the click handler */
1654 g_signal_connect(protocols_tree[proto], "button-press-event", (GCallback) gtk_c_view_onButtonPressed, helper);
1655 // g_signal_connect(protocols_tree[proto], "popup-menu", (GCallback) gtk_c_view_onPopupMenu, NULL);
1656
1657 /* Setup the selection handler */
1658
1659 helper->select = gtk_tree_view_get_selection (GTK_TREE_VIEW (protocols_tree[proto]));
1660 gtk_tree_selection_set_mode (helper->select, GTK_SELECTION_SINGLE);
1661 /* Update the packet information in the left widget */
1662 g_signal_connect (G_OBJECT (helper->select), "changed",
1663 G_CALLBACK (gtk_c_tree_selection_changed_cb), helper);
1664
1665 /* Update the hexview */
1666 g_signal_connect (G_OBJECT (helper->select), "changed",
1667 G_CALLBACK (gtk_c_update_hexview), helper);
1668
1669 /* for (i = 0; i < MAX_PACKET_STATS; i++) {
1670 gtk_list_store_append (GTK_LIST_STORE (protocols_tree_model[proto]), &iter);
1671 gtk_list_store_set (GTK_LIST_STORE(protocols_tree_model[proto]), &iter, 0, i, -1);
1672 }*/
1673
1674 vbox = gtk_vbox_new (FALSE, 0);
1675 gtk_widget_show (vbox);
1676 gtk_paned_pack1 (GTK_PANED (vpaned), vbox, FALSE, TRUE);
1677
1678 /* A frame which name is the protocol name */
1679 frame = gtk_frame_new(protocols[proto].description);
1680 gtk_widget_show(frame);
1681
1682 /* Ncurses compability: we are going to have 5 rows and in each row, 2*number of fields */
1683 fixed = gtk_fixed_new ();
1684 gtk_widget_set_size_request (fixed, 200, 200);
1685 gtk_widget_show (fixed);
1686 gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
1687 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
1688
1689 fields_vbox = gtk_vbox_new(FALSE, 0);
1690 gtk_widget_show(fields_vbox);
1691 gtk_container_add(GTK_CONTAINER(frame), fields_vbox);
1692
1693 for (i = 0; i < 5; i++) {
1694 fields_hbox[i] = gtk_hbox_new(FALSE, 25);
1695 gtk_widget_show(fields_hbox[i]);
1696 gtk_box_pack_start(GTK_BOX(fields_vbox), fields_hbox[i], TRUE, TRUE, 0);
1697 }
1698
1699 for (i = 0; i < protocols[proto].nparams; i++) {
1700 if ((params[i].type != FIELD_DEFAULT) && (params[i].type != FIELD_IFACE) && (params[i].type != FIELD_EXTRA)) {
1701 field_label = gtk_label_new(params[i].ldesc);
1702 gtk_widget_show(field_label);
1703 entry[i] = gtk_entry_new();
1704 gtk_entry_set_width_chars(GTK_ENTRY(entry[i]), params[i].size_print);
1705 /* By default, entry widgets are not editable, you have to turn on
1706 * edit mode */
1707 gtk_entry_set_editable(GTK_ENTRY(entry[i]), FALSE);
1708
1709 /* Set up a monospaced font */
1710 font_desc = pango_font_description_from_string ("Monospace 10");
1711 gtk_widget_modify_font(entry[i], font_desc);
1712 gtk_widget_show(entry[i]);
1713
1714 /* Initialize the values */
1715 parser_binary2printable(proto, i, helper->node->protocol[proto].commands_param[i], msg);
1716 gtk_entry_set_text(GTK_ENTRY(entry[i]), msg);
1717
1718 row = params[i].row;
1719 gtk_box_pack_start(GTK_BOX(fields_hbox[row-1]), field_label, FALSE, TRUE, 0);
1720 gtk_box_pack_start(GTK_BOX(fields_hbox[row-1]), entry[i], FALSE, TRUE, 0);
1721
1722 /* We are going to refer to the entry boxes as XXYY where XX is the protocol number, and YY the field number */
1723 snprintf(tmp_name, 5, "%02d%02d", proto, i);
1724 GLADE_HOOKUP_OBJECT (Main, entry[i], tmp_name);
1725 }
1726 }
1727
1728 if (protocols[proto].extra_nparams > 0)
1729 {
1730 extra_button = gtk_button_new_with_label("Extra");
1731 gtk_widget_show(extra_button);
1732 gtk_box_pack_start(GTK_BOX(fields_hbox[0]), extra_button, FALSE, TRUE, 0);
1733 g_signal_connect ((gpointer) extra_button, "clicked",
1734 G_CALLBACK (gtk_c_on_extra_button_clicked),
1735 helper);
1736 }
1737
1738 /* Store pointers to all widgets, for use by lookup_widget(). */
1739 return vpaned;
1740 }
1741
1742
1743 void
gtk_i_view_menu(GtkWidget * treeview,GtkWidget * wmain,GdkEventButton * event,struct gtk_s_helper * helper)1744 gtk_i_view_menu(GtkWidget *treeview, GtkWidget *wmain, GdkEventButton *event, struct gtk_s_helper *helper)
1745 {
1746 GtkWidget *menu, *menuitem;
1747
1748 menu = gtk_menu_new();
1749
1750 menuitem = gtk_menu_item_new_with_label(_("Learn packet from network"));
1751
1752 g_signal_connect(menuitem, "activate",
1753 (GCallback) gtk_c_view_popup_menu, helper);
1754
1755 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1756
1757 gtk_widget_show_all(menu);
1758
1759 /* Note: event can be NULL here when called from view_onPopupMenu;
1760 * gdk_event_get_time() accepts a NULL argument */
1761 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
1762 (event != NULL) ? event->button : 0,
1763 gdk_event_get_time((GdkEvent*)event));
1764
1765 GLADE_HOOKUP_OBJECT (wmain, menuitem, "menuitem");
1766 }
1767
1768 /* vim:set tabstop=4:set expandtab:set shiftwidth=4:set textwidth=120: */
1769