~ubuntu-branches/ubuntu/precise/ettercap/precise

« back to all changes in this revision

Viewing changes to src/interface/gtk/ec_gtk.c

  • Committer: Bazaar Package Importer
  • Author(s): Murat Demirten
  • Date: 2003-06-21 19:57:18 UTC
  • Revision ID: james.westby@ubuntu.com-20030621195718-qqbbfk18e1djchd9
Tags: upstream-0.6.b
ImportĀ upstreamĀ versionĀ 0.6.b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ettercap -- gtk main interface
 
3
 
 
4
    Copyright (C) 2001  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
 
5
    GTK+ 2.0 interface by daten <daten@dnetc.org>
 
6
 
 
7
    This program is free software; you can redistribute it and/or modify
 
8
    it under the terms of the GNU General Public License as published by
 
9
    the Free Software Foundation; either version 2 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
*/
 
21
 
 
22
#include <ec_main.h>
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include <stdarg.h>
 
27
 
 
28
#include <ec_version.h>
 
29
#include <ec_gtk.h>
 
30
#include <ec_gtk_sniff.h>
 
31
#include <ec_gtk_passive.h>
 
32
#include <ec_gtk_factory.h>
 
33
#include <ec_gtk_splash.h>
 
34
#include <ec_gtk_sniff_data.h>
 
35
#include <ec_gtk_plugins.h>
 
36
#include <ec_gtk_icons.h>
 
37
#include <ec_inet.h>
 
38
#include <ec_buffer.h>
 
39
#include <ec_fingerprint.h>
 
40
#include <ec_doppleganger.h>
 
41
#include <ec_thread.h>
 
42
 
 
43
#ifdef PERMIT_PLUGINS
 
44
   #include <ec_gtk_plugins.h>
 
45
   #include <ec_plugins.h>
 
46
#endif
 
47
 
 
48
// prototyping...
 
49
void Ginterface_Testing(void);
 
50
void Ginterface_InitTitle(char *ip, char *mac, char *subnet);
 
51
void Ginterface_Screen_Init(void);
 
52
void Ginterface_Screen_Close(void);
 
53
void Ginterface_WExit(char *buffer);
 
54
void Ginterface_Run(void);
 
55
void Ginterface_InitList(void);
 
56
void Ginterface_Connect(void);
 
57
void Ginterface_PopUp(char *question, ...);  /* for messages, controlled by user */
 
58
void Ginterface_PopUpN(char *notice);        /* for notices, controlled by program */
 
59
void Ginterface_PopUpNP(char *notice);       /* notices with progress bars */
 
60
char Ginterface_PopUpQ(char *question, ...); /* for yes/no questions */
 
61
void Ginterface_RefreshList(void);
 
62
void Ginterface_Manual(void);
 
63
void Ginterface_About(void);
 
64
void Ginterface_HelpWindow(char *help[]);
 
65
void Ginterface_OldStyleSniff(short mode);
 
66
void Ginterface_CheckForPoisoner(void);
 
67
void Ginterface_FingerPrint(void);
 
68
void Ginterface_EntryRemoval(void);
 
69
void Ginterface_OnlyPoison(void);
 
70
 
 
71
void Ginterface_ToolBar(GtkItemFactory *host_menu);
 
72
void Ginterface_Callback(gpointer data, guint action, GtkWidget *widget);
 
73
void Ginterface_SwitchPage(GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, gpointer user_data);
 
74
void Ginterface_SelectItem(GtkTreeView *treeview, gpointer arg1, GtkTreeViewColumn *arg2, gpointer data);
 
75
void Ginterface_PointItem (GtkWidget *widget, gpointer data);
 
76
void Ginterface_EditTop(int which, char *message);
 
77
void Ginterface_ClearTop(void);
 
78
void Ginterface_AppendTop(int which, char *message);
 
79
void Ginterface_EditBottom(int which, char *message);
 
80
void Ginterface_ClearBottom(void);
 
81
void Ginterface_AppendBottom(int which, char *message);
 
82
void Ginterface_CheckImgPath(char *path);
 
83
 
 
84
#ifndef HAVE_FORM
 
85
void trim_buffer(char *buffer, char trim);
 
86
#endif
 
87
 
 
88
// global variables for Interface...
 
89
GtkWidget *window;       // the main window
 
90
GtkWidget *notebook;     // for tabs
 
91
GtkWidget *frame[3];     // frames for the 3 main areas, 0 top, 1 middle, 2 bottom
 
92
GtkWidget *mainbox[6];   // host list, arp sniff, ip sniff, mac sniff, passive mode
 
93
GtkWidget *tablabel[6];
 
94
GtkItemFactory *main_menu;
 
95
GtkAccelGroup *accel_group = NULL;
 
96
GtkWidget *tb_label[9];  // top left, top middle, top right, middle left, ... bottom right
 
97
GtkWidget *tb_table;     // top frame layout
 
98
GtkWidget *bb_label[2];  // tow text rows in bottom box
 
99
GtkWidget *ec_table;     // main layout
 
100
GtkWidget *arrows;       // arrows in top frame
 
101
 
 
102
// for the host lists
 
103
GtkWidget         *h_scrolled;
 
104
GtkListStore      *h_list[2];
 
105
GtkTreeIter        h_iter[2];
 
106
GtkCellRenderer   *h_renderer;
 
107
GtkTreeViewColumn *h_column;
 
108
GtkWidget         *h_treeview[2];
 
109
GtkTreeSelection  *h_selection[2];
 
110
 
 
111
extern GtkWidget *s_scrolled;  // for sniffer modes
 
112
extern GtkWidget *splash_pbar; // progress bar
 
113
extern GtkWidget *o_win;       // plugin output window
 
114
 
 
115
int gBase_Pointer = 0;
 
116
int gSource_Pointer = 0;
 
117
int gDest_Pointer = 0;
 
118
int *gPointer = &gSource_Pointer;
 
119
int Sel_Number;
 
120
 
 
121
char title_bottom_window[100];
 
122
char title_main_window[100];
 
123
char title_top_window[100];
 
124
char image_path[100];
 
125
 
 
126
// -------------------------------------------
 
127
 
 
128
 
 
129
void Ginterface_InitTitle(char *ip, char *mac, char *subnet)
 
130
{
 
131
   DEBUG_MSG("Ginterface_InitTitle [%s] [%s] [%s]", ip, mac, subnet);
 
132
 
 
133
   if (Options.silent)
 
134
   {
 
135
      snprintf(title_main_window, 100, " ??? hosts in this LAN (%s : %s) ", ip, subnet);
 
136
      snprintf(title_bottom_window, 100, " Your IP: %s MAC: %s Iface: %s Link: not tested", ip, mac, Options.netiface);
 
137
   }
 
138
   else
 
139
   {
 
140
      char link_type[10];
 
141
      short type;
 
142
 
 
143
      switch(type = Inet_CheckSwitch())
 
144
      {
 
145
         case 0: strcpy(link_type, "unknown");
 
146
                 break;
 
147
         case 1: strcpy(link_type, "HUB");
 
148
                 break;
 
149
         case 2: strcpy(link_type, "SWITCH");
 
150
                 break;
 
151
      }
 
152
      snprintf(title_main_window, 100, " %3d hosts in this LAN (%s : %s) ", number_of_hosts_in_lan, ip, subnet);
 
153
      snprintf(title_bottom_window, 100, " Your IP: %s MAC: %s Iface: %s Link: %s ", ip, mac, Options.netiface, link_type);
 
154
   }
 
155
   snprintf(title_top_window, 100, " %s %s ", PROGRAM, VERSION);
 
156
}
 
157
 
 
158
void Ginterface_Screen_Init(void)
 
159
{
 
160
   GtkWidget *seperator, *box, *menubar;
 
161
   GdkPixbuf *pixbuf;
 
162
 
 
163
   DEBUG_MSG("Ginterface_Screen_Init");
 
164
   
 
165
   /* formerly set image paths, now just used for About data */
 
166
   Ginterface_CheckImgPath(DATA_PATH);
 
167
 
 
168
   Ginterface_InitTitle(Host_In_LAN[0].ip, Host_In_LAN[0].mac, Inet_MySubnet());
 
169
 
 
170
   /* create the main window, set it up */
 
171
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
172
   gtk_window_set_title(GTK_WINDOW (window), title_top_window);
 
173
   g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (Ginterface_WExit), NULL);
 
174
   gtk_container_set_border_width( GTK_CONTAINER (window), 0);
 
175
   gtk_window_set_default_size(GTK_WINDOW (window), 640, 420);
 
176
   gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
 
177
 
 
178
   /* create the table */
 
179
   ec_table = gtk_table_new (4, 1, FALSE);   /* 4 rows, 1 column, not same height */
 
180
   gtk_container_add (GTK_CONTAINER (window), ec_table);
 
181
   gtk_widget_show(ec_table);
 
182
 
 
183
   /* toolbars setup after frames so certain widgets get initialized first */
 
184
 
 
185
   /* setup the top table frame */
 
186
   /* ------------------------- */ 
 
187
   frame[0] = gtk_frame_new(title_top_window);
 
188
   gtk_frame_set_label_align(GTK_FRAME (frame[0]), 0.5, 0.5);
 
189
   gtk_table_attach (GTK_TABLE (ec_table), frame[0], 0, 1, 1, 2,  GTK_FILL | GTK_EXPAND, 0, 10, 10);
 
190
   gtk_widget_show(frame[0]);
 
191
 
 
192
   tb_table = gtk_table_new (4, 3, FALSE);
 
193
   gtk_container_add (GTK_CONTAINER (frame[0]), tb_table);
 
194
  
 
195
   /* source label */ 
 
196
   tb_label[0] = gtk_label_new ("       ");
 
197
   gtk_misc_set_alignment(GTK_MISC (tb_label[0]), 0, 0);
 
198
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[0], 0, 1, 0, 1, GTK_FILL, 0, 5, 0);
 
199
   gtk_widget_show (tb_label[0]);
 
200
 
 
201
   /* source ip */
 
202
   tb_label[1] = gtk_label_new ("               ");
 
203
   gtk_misc_set_alignment(GTK_MISC (tb_label[1]), 1, 0);
 
204
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[1], 1, 2, 0, 1, GTK_FILL, 0, 5, 0);
 
205
   gtk_widget_show (tb_label[1]);
 
206
 
 
207
   /* source mac */
 
208
   tb_label[2] = gtk_label_new ("                 ");
 
209
   gtk_misc_set_alignment(GTK_MISC (tb_label[2]), 0, 0);
 
210
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[2], 3, 4, 0, 1, GTK_FILL, 0, 5, 0);
 
211
   gtk_widget_show (tb_label[2]);
 
212
 
 
213
   /* arrows */
 
214
   pixbuf = gdk_pixbuf_new_from_inline (-1, arrows_icon, FALSE, NULL);
 
215
   arrows = gtk_image_new_from_pixbuf(pixbuf);
 
216
   gtk_table_attach (GTK_TABLE (tb_table), arrows, 2, 3, 0, 3, GTK_FILL, 0, 0, 0);
 
217
 
 
218
   /* middle row */
 
219
   tb_label[3] = gtk_label_new ("       ");
 
220
   gtk_misc_set_alignment(GTK_MISC (tb_label[3]), 0, 0);
 
221
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[3], 0, 1, 1, 2, GTK_FILL, 0, 5, 0);
 
222
   gtk_widget_show (tb_label[3]);
 
223
 
 
224
   tb_label[4] = gtk_label_new ("       ");
 
225
   gtk_misc_set_alignment(GTK_MISC (tb_label[4]), 1, 0);
 
226
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[4], 1, 2, 1, 2, GTK_FILL, 0, 5, 0);
 
227
   gtk_widget_show (tb_label[4]);
 
228
 
 
229
   tb_label[5] = gtk_label_new ("       ");
 
230
   gtk_misc_set_alignment(GTK_MISC (tb_label[5]), 0, 0);
 
231
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[5], 3, 4, 1, 2, GTK_FILL, 0, 5, 0);
 
232
   gtk_widget_show (tb_label[5]);
 
233
 
 
234
   /* dest label */
 
235
   tb_label[6] = gtk_label_new ("       ");
 
236
   gtk_misc_set_alignment(GTK_MISC (tb_label[6]), 0, 0);
 
237
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[6], 0, 1, 2, 3, GTK_FILL, 0, 5, 0);
 
238
   gtk_widget_show (tb_label[6]);
 
239
 
 
240
   /* dest ip */
 
241
   tb_label[7] = gtk_label_new ("               ");
 
242
   gtk_misc_set_alignment(GTK_MISC (tb_label[7]), 1, 0);
 
243
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[7], 1, 2, 2, 3, GTK_FILL, 0, 5, 0);
 
244
   gtk_widget_show (tb_label[7]);
 
245
 
 
246
   /* dest mac */
 
247
   tb_label[8] = gtk_label_new ("                 ");
 
248
   gtk_misc_set_alignment(GTK_MISC (tb_label[8]), 0, 0);
 
249
   gtk_table_attach (GTK_TABLE (tb_table), tb_label[8], 3, 4, 2, 3, GTK_FILL, 0, 5, 0);
 
250
   gtk_widget_show (tb_label[8]);
 
251
 
 
252
   gtk_widget_show(tb_table);
 
253
 
 
254
   /* setup the middle table row */
 
255
   /* -------------------------- */
 
256
 
 
257
   frame[1] = gtk_frame_new(title_main_window);
 
258
   gtk_frame_set_label_align(GTK_FRAME (frame[1]), 0.5, 0.5);
 
259
   gtk_table_attach (GTK_TABLE (ec_table), frame[1], 0, 1, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 10, 0);
 
260
 
 
261
   /* make the notebook to hold the pages */
 
262
   notebook = gtk_notebook_new();
 
263
   gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_BOTTOM);
 
264
   gtk_container_add (GTK_CONTAINER (frame[1]), notebook);
 
265
   g_signal_connect (G_OBJECT (notebook), "switch-page", G_CALLBACK (Ginterface_SwitchPage), (gpointer) ec_table);
 
266
 
 
267
   /* make the pages, with one (reused) label and box each */
 
268
   /* host list */
 
269
   tablabel[0] = gtk_label_new_with_mnemonic ("Host List");
 
270
   mainbox[0] = gtk_hbox_new(FALSE, 0);
 
271
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[0], tablabel[0]);
 
272
   gtk_widget_show (tablabel[0]);
 
273
   gtk_widget_show (mainbox[0]);
 
274
 
 
275
   /* arp sniff */
 
276
   tablabel[1] = gtk_label_new ("ARP Sniff");
 
277
   gtk_widget_set_sensitive (GTK_WIDGET (tablabel[1]), FALSE);
 
278
   mainbox[1] = gtk_hbox_new(FALSE, 0);
 
279
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[1], tablabel[1]);
 
280
   gtk_widget_show (tablabel[1]);
 
281
   gtk_widget_show (mainbox[1]);
 
282
 
 
283
   /* ip sniff */
 
284
   tablabel[2] = gtk_label_new ("IP Sniff");
 
285
   mainbox[2] = gtk_hbox_new(FALSE, 0);
 
286
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[2], tablabel[2]);
 
287
   gtk_widget_show (tablabel[2]);
 
288
   gtk_widget_show (mainbox[2]);
 
289
 
 
290
   /* mac sniff*/
 
291
   tablabel[3] = gtk_label_new ("MAC Sniff");
 
292
   mainbox[3] = gtk_hbox_new(FALSE, 0);
 
293
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[3], tablabel[3]);
 
294
   gtk_widget_show (tablabel[3]);
 
295
   gtk_widget_show (mainbox[3]);
 
296
   
 
297
   /* passive */
 
298
   tablabel[4] = gtk_label_new ("Passive");
 
299
   mainbox[4] = gtk_hbox_new(FALSE, 0);
 
300
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[4], tablabel[4]);
 
301
   gtk_widget_show (tablabel[4]);
 
302
   gtk_widget_show (mainbox[4]);
 
303
 
 
304
#ifdef PERMIT_PLUGINS
 
305
   /* plugins */
 
306
   tablabel[5] = gtk_label_new ("Plugins");
 
307
   mainbox[5] = gtk_hbox_new(FALSE, 0);
 
308
   gtk_notebook_append_page(GTK_NOTEBOOK (notebook), mainbox[5], tablabel[5]);
 
309
   gtk_widget_show (tablabel[5]);
 
310
   gtk_widget_show (mainbox[5]);
 
311
#endif
 
312
 
 
313
   /* make the scrolled window */
 
314
   h_scrolled = gtk_scrolled_window_new(NULL, NULL);
 
315
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (h_scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
316
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (h_scrolled), GTK_SHADOW_IN);
 
317
   gtk_box_pack_start (GTK_BOX (mainbox[0]),  h_scrolled, TRUE, TRUE, 0);
 
318
   gtk_widget_show (h_scrolled);
 
319
 
 
320
   /* make the first list */
 
321
   h_treeview[0] = gtk_tree_view_new ();
 
322
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (h_treeview[0]), FALSE);
 
323
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (h_treeview[0]), FALSE);
 
324
      /* add the number column */
 
325
   h_renderer = gtk_cell_renderer_text_new ();
 
326
   h_renderer->xalign = 0.0;
 
327
   h_column = gtk_tree_view_column_new_with_attributes ("#", h_renderer, "text", 0, NULL);
 
328
   gtk_tree_view_column_set_sort_column_id (h_column, 0);
 
329
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[0]), h_column);
 
330
      /* add the source column */
 
331
   h_renderer = gtk_cell_renderer_text_new ();
 
332
   h_renderer->xalign = 1.0;
 
333
   h_column = gtk_tree_view_column_new_with_attributes ("Source", h_renderer, "text", 1, NULL);
 
334
   gtk_tree_view_column_set_sort_column_id (h_column, 1);
 
335
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[0]), h_column);
 
336
      /* additional column for padding */
 
337
   h_renderer = gtk_cell_renderer_text_new ();
 
338
   h_column = gtk_tree_view_column_new_with_attributes ("", h_renderer, "text", 2, NULL);
 
339
   gtk_tree_view_column_set_sort_column_id (h_column, 2);
 
340
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[0]), h_column);
 
341
      /* connect signals */
 
342
   h_selection[0] = gtk_tree_view_get_selection (GTK_TREE_VIEW (h_treeview[0]));
 
343
   gtk_tree_selection_set_mode (h_selection[0], GTK_SELECTION_SINGLE);
 
344
   g_signal_connect (G_OBJECT (h_selection[0]), "changed", G_CALLBACK (Ginterface_PointItem), "Source");
 
345
   g_signal_connect (G_OBJECT (h_treeview[0]), "row_activated", G_CALLBACK (Ginterface_SelectItem), (gpointer) "Source");
 
346
      /* add it and display it */
 
347
   gtk_container_add (GTK_CONTAINER (h_scrolled), h_treeview[0]);
 
348
   gtk_widget_show(h_treeview[0]);
 
349
 
 
350
   /* make a seperator for between the lists */
 
351
   seperator = gtk_vseparator_new();
 
352
   gtk_box_pack_start (GTK_BOX (mainbox[0]), seperator, FALSE, TRUE, 5);
 
353
   gtk_widget_show(seperator);
 
354
 
 
355
   /* make the scrolled window */
 
356
   h_scrolled = gtk_scrolled_window_new(NULL, NULL);
 
357
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (h_scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
358
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (h_scrolled), GTK_SHADOW_IN);
 
359
   gtk_box_pack_start (GTK_BOX (mainbox[0]),  h_scrolled, TRUE, TRUE, 0);
 
360
   gtk_widget_show (h_scrolled);
 
361
 
 
362
   /* make the second list */
 
363
   h_treeview[1] = gtk_tree_view_new ();
 
364
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (h_treeview[1]), FALSE);
 
365
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (h_treeview[1]), FALSE);
 
366
      /* add the number column */
 
367
   h_renderer = gtk_cell_renderer_text_new ();
 
368
   h_renderer->xalign = 0.0;
 
369
   h_column = gtk_tree_view_column_new_with_attributes ("Destination", h_renderer, "text", 0, NULL);
 
370
   gtk_tree_view_column_set_sort_column_id (h_column, 0);
 
371
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[1]), h_column);
 
372
      /* add the dest column */
 
373
   h_renderer = gtk_cell_renderer_text_new ();
 
374
   h_renderer->xalign = 1.0;
 
375
   h_column = gtk_tree_view_column_new_with_attributes ("Destination", h_renderer, "text", 1, NULL);
 
376
   gtk_tree_view_column_set_sort_column_id (h_column, 1);
 
377
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[1]), h_column);
 
378
      /* additional column for padding */
 
379
   h_renderer = gtk_cell_renderer_text_new ();
 
380
   h_column = gtk_tree_view_column_new_with_attributes ("", h_renderer, "text", 2, NULL);
 
381
   gtk_tree_view_column_set_sort_column_id (h_column, 2);
 
382
   gtk_tree_view_append_column (GTK_TREE_VIEW(h_treeview[1]), h_column);
 
383
      /* connect signals */
 
384
   h_selection[1] = gtk_tree_view_get_selection (GTK_TREE_VIEW (h_treeview[1]));
 
385
   gtk_tree_selection_set_mode (h_selection[1], GTK_SELECTION_SINGLE);
 
386
   g_signal_connect (G_OBJECT (h_selection[1]), "changed", G_CALLBACK (Ginterface_PointItem), "Dest");
 
387
   g_signal_connect (G_OBJECT (h_treeview[1]), "row_activated", G_CALLBACK (Ginterface_SelectItem), (gpointer) "Dest");
 
388
      /* add it and display it */
 
389
   gtk_container_add (GTK_CONTAINER (h_scrolled), h_treeview[1]);
 
390
   gtk_widget_show(h_treeview[1]);
 
391
 
 
392
   /*** ettercap call, initialize the list ***/
 
393
   Ginterface_InitList();
 
394
 
 
395
   gtk_tree_view_set_model(GTK_TREE_VIEW (h_treeview[0]), GTK_TREE_MODEL (h_list[0]));
 
396
   gtk_tree_view_set_model(GTK_TREE_VIEW (h_treeview[1]), GTK_TREE_MODEL (h_list[1]));
 
397
 
 
398
   gtk_widget_show(frame[1]);
 
399
   gtk_widget_show(notebook);
 
400
 
 
401
   /* setup the bottom table row */
 
402
   /* -------------------------- */
 
403
   frame[2] = gtk_frame_new(title_bottom_window);
 
404
   gtk_frame_set_label_align(GTK_FRAME (frame[2]), 0.5, 0.5);
 
405
   gtk_table_attach (GTK_TABLE (ec_table), frame[2], 0, 1, 3, 4, GTK_FILL | GTK_EXPAND, 0, 10, 10);
 
406
   gtk_widget_show(frame[2]);
 
407
 
 
408
   box = gtk_vbox_new(FALSE, 0);
 
409
   gtk_container_add (GTK_CONTAINER (frame[2]), box);
 
410
 
 
411
   bb_label[0] = gtk_label_new("                                   ");
 
412
   bb_label[1] = gtk_label_new("                                   ");
 
413
 
 
414
   gtk_misc_set_alignment(GTK_MISC (bb_label[0]), 0, 0);
 
415
   gtk_misc_set_alignment(GTK_MISC (bb_label[1]), 0, 0);
 
416
 
 
417
   gtk_container_add(GTK_CONTAINER (box), bb_label[0]);
 
418
   gtk_container_add(GTK_CONTAINER (box), bb_label[1]);
 
419
 
 
420
   gtk_widget_show(bb_label[0]);
 
421
   gtk_widget_show(bb_label[1]);
 
422
   gtk_widget_show(box);
 
423
 
 
424
   accel_group = gtk_accel_group_new();
 
425
   main_menu = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
 
426
   gtk_window_add_accel_group(GTK_WINDOW (window), accel_group);
 
427
 
 
428
   Ginterface_ToolBar(main_menu);
 
429
 
 
430
   menubar = gtk_item_factory_get_widget (main_menu, "<main>");
 
431
   gtk_table_attach (GTK_TABLE (ec_table), menubar, 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 
432
   gtk_widget_show (menubar);
 
433
 
 
434
   gtk_widget_show(window);
 
435
 
 
436
   DEBUG_MSG("Ginterface_Screen_Init -- INIZIALIZED");
 
437
}
 
438
 
 
439
void Ginterface_ToolBar(GtkItemFactory *host_menu) {
 
440
   static GtkItemFactoryEntry action_menu[] = {
 
441
      MENU_COMMON
 
442
      { "/Action", NULL, NULL, 0, "<Branch>", NULL},
 
443
      { "/Action/Only Poison", "j", Ginterface_Callback, 'j', "<StockItem>", GTK_STOCK_YES },
 
444
      { "/Action/Delete Entry", "d", Ginterface_Callback, 'd', "<StockItem>", GTK_STOCK_DELETE },
 
445
      { "/Action/Packet Forge", "x", Ginterface_Callback, 'x', "<StockItem>", GTK_STOCK_PREFERENCES },
 
446
      { "/Action/Fingerprint", "f", Ginterface_Callback, 'f', "<ImageItem>", finger_icon },
 
447
      { "/Action/Check for Poisoner", "c", Ginterface_Callback, 'c', "<ImageItem>", search_icon },
 
448
      { "/Action/Refresh List", "r", Ginterface_Callback, 'r', "<StockItem>", GTK_STOCK_REFRESH},
 
449
      { "/Action/Clear Selections", "at", Ginterface_Callback, '@', "<StockItem>", GTK_STOCK_CLEAR},
 
450
      { "/Action/Save Host List", "k", Ginterface_Callback, 'k', "<StockItem>", GTK_STOCK_SAVE },
 
451
      { "/Help", NULL, NULL, 0, "<LastBranch>", NULL},
 
452
      { "/Help/_Manual", NULL, Ginterface_Manual, 0, "<StockItem>", GTK_STOCK_HELP},
 
453
      { "/Help/_About", NULL, Ginterface_About, 0, "<StockItem>", GTK_STOCK_DIALOG_INFO}
 
454
   };
 
455
   gint num_items = 0;
 
456
 
 
457
   DEBUG_MSG("Ginterface_ToolBar");
 
458
 
 
459
   gtk_item_factory_delete_item(host_menu, "/Quit");
 
460
   gtk_item_factory_delete_item(host_menu, "/Sniff");
 
461
   gtk_item_factory_delete_item(host_menu, "/View");
 
462
   gtk_item_factory_delete_item(host_menu, "/Action");
 
463
   gtk_item_factory_delete_item(host_menu, "/Help");
 
464
 
 
465
   num_items = sizeof (action_menu) / sizeof (action_menu[0]);
 
466
   gtk_item_factory_create_items (host_menu, num_items, action_menu, NULL);
 
467
}
 
468
 
 
469
 
 
470
void Ginterface_InitList(void)
 
471
{
 
472
   gint j = 0;
 
473
   char line[100];
 
474
 
 
475
   DEBUG_MSG("Ginterface_InitList");
 
476
 
 
477
   g_signal_handlers_block_by_func (G_OBJECT (h_selection[0]), G_CALLBACK (Ginterface_PointItem), "Source");
 
478
   g_signal_handlers_block_by_func (G_OBJECT (h_selection[1]), G_CALLBACK (Ginterface_PointItem), "Dest");
 
479
 
 
480
   /* if the lists exist, clear them, otherwise create them */
 
481
   /* ----------------------------------------------------- */
 
482
   if(h_list[0] != NULL)
 
483
      gtk_list_store_clear (GTK_LIST_STORE (h_list[0]));
 
484
   else
 
485
      h_list[0] = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 
486
 
 
487
   if(h_list[1] != NULL)
 
488
      gtk_list_store_clear (GTK_LIST_STORE (h_list[1]));
 
489
   else
 
490
      h_list[1] = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 
491
 
 
492
   if (number_of_hosts_in_lan == 0) return;
 
493
 
 
494
   /* populate the lists */
 
495
   /* ------------------ */
 
496
   for(j = 0; j < number_of_hosts_in_lan; j++) {
 
497
      sprintf(line, "%3d) ", j+1);
 
498
 
 
499
      gtk_list_store_append (h_list[0], &h_iter[0]);
 
500
      gtk_list_store_set (h_list[0], &h_iter[0], 
 
501
                      0, line,
 
502
                      1, Host_In_LAN[j].ip,
 
503
                      2, " ", -1);
 
504
 
 
505
      gtk_list_store_append (h_list[1], &h_iter[1]);
 
506
      gtk_list_store_set (h_list[1], &h_iter[1], 
 
507
                      0, line, 
 
508
                      1, Host_In_LAN[j].ip,
 
509
                      2, " ", -1);
 
510
   }
 
511
 
 
512
   g_signal_handlers_unblock_by_func (G_OBJECT (h_selection[0]), G_CALLBACK (Ginterface_PointItem), "Source");
 
513
   g_signal_handlers_unblock_by_func (G_OBJECT (h_selection[1]), G_CALLBACK (Ginterface_PointItem), "Dest");
 
514
}
 
515
 
 
516
/* this is similar to SelectItem, but doesn't setup Host_Source/Host_Dest or affect the top box */
 
517
void Ginterface_PointItem (GtkWidget *widget, gpointer data)
 
518
{
 
519
   GtkTreeIter iter;
 
520
   GtkTreeModel *model;
 
521
   gchar temp[150], *lineptr;
 
522
   int line;
 
523
 
 
524
   DEBUG_MSG("Ginterface_PointItem");
 
525
 
 
526
   if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (widget), &model, &iter)) {
 
527
      gtk_tree_model_get (model, &iter, 0, &lineptr, -1);
 
528
      if(lineptr == NULL || strlen(lineptr) < 4)
 
529
         return;
 
530
      sscanf(lineptr, "%i) ", &line);
 
531
      g_free (lineptr);
 
532
   }
 
533
 
 
534
   if(strcmp(data, "Source") == 0) {
 
535
      gSource_Pointer = line - 1;
 
536
      snprintf(temp, 150, "Host: %s (%s) : %s", Host_In_LAN[gSource_Pointer].name, 
 
537
               Host_In_LAN[gSource_Pointer].ip, Host_In_LAN[gSource_Pointer].mac);      
 
538
      Ginterface_EditBottom(0, temp);
 
539
   } else {
 
540
      gDest_Pointer  = line - 1;
 
541
      snprintf(temp, 150, "Host: %s (%s) : %s", Host_In_LAN[gDest_Pointer].name, 
 
542
               Host_In_LAN[gDest_Pointer].ip, Host_In_LAN[gDest_Pointer].mac);
 
543
      Ginterface_EditBottom(1, temp);
 
544
   }
 
545
}
 
546
 
 
547
void Ginterface_SelectItem(GtkTreeView *treeview, gpointer arg1, GtkTreeViewColumn *arg2, gpointer data)
 
548
{
 
549
   GtkTreeIter iter;
 
550
   GtkTreeModel *model;
 
551
   gchar *lineptr;
 
552
   gint line = 0;
 
553
 
 
554
   DEBUG_MSG("Ginterface_SelectItem");
 
555
 
 
556
   if(strcmp((char *)data, "Source") == 0) {
 
557
      if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (h_selection[0]), &model, &iter)) {
 
558
         gtk_tree_model_get (model, &iter, 0, &lineptr, -1);
 
559
         line = atoi(strtok(lineptr, ")"));
 
560
      }
 
561
 
 
562
      if(line < 1)
 
563
         return;
 
564
 
 
565
      gSource_Pointer = line - 1;
 
566
      Ginterface_EditTop(0, "Source:");
 
567
      Ginterface_EditTop(1, Host_In_LAN[gSource_Pointer].ip);
 
568
      Ginterface_EditTop(2, Host_In_LAN[gSource_Pointer].mac);
 
569
      memcpy(&Host_Source, &Host_In_LAN[gSource_Pointer], sizeof(HOST) );
 
570
   } else if(strcmp((char *)data, "Dest") == 0) {
 
571
      if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (h_selection[1]), &model, &iter)) {
 
572
         gtk_tree_model_get (model, &iter, 0, &lineptr, -1);
 
573
         line = atoi(strtok(lineptr, ")"));
 
574
      }
 
575
 
 
576
      if(line < 1)
 
577
         return;
 
578
 
 
579
      gDest_Pointer = line - 1;
 
580
 
 
581
      Ginterface_EditTop(6, "Dest:");
 
582
      Ginterface_EditTop(7, Host_In_LAN[gDest_Pointer].ip);
 
583
      Ginterface_EditTop(8, Host_In_LAN[gDest_Pointer].mac);
 
584
      memcpy(&Host_Dest, &Host_In_LAN[gDest_Pointer], sizeof(HOST) );
 
585
   }
 
586
 
 
587
   /* if ARP mode is disabled, enable it now that a source or dest has been selected */
 
588
   if(!GTK_WIDGET_SENSITIVE (tablabel[1]))
 
589
      gtk_widget_set_sensitive (GTK_WIDGET (tablabel[1]), TRUE);
 
590
 
 
591
}
 
592
 
 
593
void Ginterface_PopUp(char *question, ...)
 
594
{
 
595
   GtkWidget *dialog, *label;
 
596
   char message[150];
 
597
   va_list ap;
 
598
 
 
599
   DEBUG_MSG("Ginterface_PopUp");
 
600
 
 
601
   va_start(ap, question);
 
602
   vsnprintf(message, 150, question, ap);
 
603
   va_end(ap);
 
604
 
 
605
   /* Create the widgets */
 
606
   dialog = gtk_dialog_new_with_buttons ("ettercap", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);
 
607
   label = gtk_label_new (message);
 
608
 
 
609
   /* Ensure that the dialog box is destroyed when the user responds. */
 
610
   g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog));
 
611
 
 
612
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
613
 
 
614
   /* Add the label, and show everything we've added to the dialog. */
 
615
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
 
616
   gtk_widget_show_all (dialog);
 
617
}
 
618
 
 
619
void Ginterface_PopUpN(char *notice)
 
620
{
 
621
   static GtkWidget *dialog, *label;
 
622
 
 
623
   DEBUG_MSG("Ginterface_PopUpN");
 
624
   
 
625
   if(notice) {
 
626
      dialog = gtk_dialog_new_with_buttons ("ettercap - notice", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
 
627
      label = gtk_label_new (notice);
 
628
      
 
629
      /* make it appear in the middle of the screen */
 
630
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
631
 
 
632
      /* remove the seperator since we wont need it */
 
633
      gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
 
634
 
 
635
      /* remove the borders and such as well.. */
 
636
      gtk_window_set_decorated (GTK_WINDOW (dialog), FALSE);
 
637
 
 
638
      gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
 
639
      gtk_widget_show(label); 
 
640
      gtk_widget_show_all (dialog);
 
641
   } else {
 
642
      if(!dialog) return;
 
643
      gtk_widget_destroy(dialog);
 
644
      dialog = NULL;
 
645
   }
 
646
 
 
647
   while (g_main_iteration(FALSE)); /* update gui */
 
648
}
 
649
 
 
650
/* same as previous but with a global progress bar that's manipulated by Parser_StatusBar */
 
651
void Ginterface_PopUpNP(char *notice)
 
652
{
 
653
   static GtkWidget *dialog, *label;
 
654
 
 
655
   DEBUG_MSG("Ginterface_PopUpNP");
 
656
  
 
657
   if(notice) {
 
658
      dialog = gtk_dialog_new_with_buttons ("ettercap - notice", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
 
659
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
660
      gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
 
661
      gtk_window_set_decorated (GTK_WINDOW (dialog), FALSE);
 
662
 
 
663
      label = gtk_label_new (notice);
 
664
      gtk_misc_set_alignment(GTK_MISC (label), 0, 0);
 
665
      gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
 
666
 
 
667
      splash_pbar = gtk_progress_bar_new ();
 
668
      gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), splash_pbar, FALSE, FALSE, 0);
 
669
 
 
670
      gtk_widget_show_all (dialog);
 
671
   } else {
 
672
      if(!dialog) return;
 
673
      gtk_widget_destroy(dialog);
 
674
      dialog = NULL;
 
675
   }
 
676
 
 
677
   while (g_main_iteration(FALSE)); /* update gui */
 
678
}
 
679
 
 
680
char Ginterface_PopUpQ(char *question, ...)
 
681
{
 
682
   GtkWidget *dialog, *label;
 
683
   char answer;
 
684
   int response;
 
685
   char message[150];
 
686
   va_list ap;
 
687
 
 
688
   DEBUG_MSG("Ginterface_PopUpQ");
 
689
   
 
690
   va_start(ap, question);
 
691
   vsnprintf(message, 150, question, ap);
 
692
   va_end(ap);
 
693
   
 
694
   dialog = gtk_dialog_new_with_buttons ("Question", GTK_WINDOW (window), 
 
695
                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 
 
696
                   GTK_STOCK_YES, GTK_RESPONSE_YES, GTK_STOCK_NO, GTK_RESPONSE_NO, NULL);
 
697
   label = gtk_label_new (message);
 
698
 
 
699
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
700
 
 
701
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
 
702
   gtk_widget_show(label);
 
703
 
 
704
   response = gtk_dialog_run (GTK_DIALOG (dialog));
 
705
 
 
706
   if(response == -8)   // yes
 
707
      answer = 'y';
 
708
   else
 
709
      answer = 'n';
 
710
 
 
711
   gtk_widget_destroy (dialog);
 
712
 
 
713
   DEBUG_MSG("Ginterface_PopUpQ returns -- %c", answer); 
 
714
   return(answer); 
 
715
}
 
716
 
 
717
void Ginterface_RefreshList(void)
 
718
{
 
719
   DEBUG_MSG("Ginterface_RefreshList");
 
720
 
 
721
   Ginterface_PopUpNP( "updating the list..." );
 
722
 
 
723
   /* refresh the list */
 
724
   number_of_hosts_in_lan = Inet_HostInLAN();
 
725
   gSource_Pointer = gDest_Pointer = 0;
 
726
   gBase_Pointer = 0;
 
727
   sprintf(title_main_window, " %3d", number_of_hosts_in_lan);
 
728
   title_main_window[4] = ' ';
 
729
   gtk_frame_set_label (GTK_FRAME (frame[1]), title_main_window);
 
730
 
 
731
   Ginterface_InitList();
 
732
   Ginterface_PopUpNP(NULL);
 
733
}
 
734
 
 
735
void Ginterface_Manual (void)
 
736
{
 
737
   FILE *manpage;
 
738
   GtkWidget *dialog, *scrolled, *textview;
 
739
   GtkTextBuffer *buffer;
 
740
   gchar message[100];
 
741
 
 
742
   DEBUG_MSG("Ginterface_Manual");
 
743
 
 
744
   dialog = gtk_dialog_new_with_buttons ("Ettercap Manual", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, NULL);
 
745
   gtk_window_set_default_size(GTK_WINDOW (dialog), 520, 300);
 
746
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
747
   g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog));
 
748
 
 
749
   /* make the scrolled window */
 
750
   scrolled = gtk_scrolled_window_new(NULL, NULL);
 
751
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
752
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), scrolled);
 
753
   gtk_widget_show (scrolled);
 
754
 
 
755
   /* make the Text View window */
 
756
   textview = gtk_text_view_new();
 
757
   gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE);
 
758
   gtk_text_view_set_left_margin(GTK_TEXT_VIEW (textview), 10);
 
759
   gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview), 10);
 
760
   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), textview);
 
761
   gtk_widget_show(textview);
 
762
 
 
763
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
 
764
 
 
765
   DEBUG_MSG("Ginterface_Manual - running: man ettercap | col -b");
 
766
   manpage = popen("man ettercap | col -b", "r");
 
767
 
 
768
   if(manpage == NULL) {
 
769
      Ginterface_PopUp ("Failed to execute 'man ettercap | col -b'.\n");
 
770
      return;
 
771
   }
 
772
 
 
773
   while(fgets(message, sizeof(message), manpage))
 
774
      gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER (buffer), g_locale_to_utf8 (message, strlen(message), NULL, NULL, NULL), -1);
 
775
 
 
776
   fclose(manpage);
 
777
 
 
778
   gtk_widget_show (dialog);
 
779
}
 
780
 
 
781
void Ginterface_About (void)
 
782
{
 
783
   GtkWidget *dialog, *image, *label, *book, *box, *scrolled, *textview;
 
784
   GdkPixbuf *pixbuf;
 
785
   GtkTextBuffer *buffer;
 
786
   GtkTextIter iter;
 
787
   FILE *infile;
 
788
   gchar line[100];
 
789
   gchar *aboutstring = "A multipurpose sniffer/interceptor/logger for switched LAN.\n\n"
 
790
                        "http://ettercap.sourceforge.net/\n\n"
 
791
                        "Copyright (C) 2002\n"
 
792
                        "ALoR <alor@users.sourceforge.net>\n"
 
793
                        "NaGA <crwm@freemail.it>\n";
 
794
 
 
795
   DEBUG_MSG("Ginterface_About");
 
796
 
 
797
   dialog = gtk_dialog_new_with_buttons ("About Ettercap", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, NULL);
 
798
   gtk_window_set_default_size(GTK_WINDOW (dialog), 450, 400);
 
799
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
800
   g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog));
 
801
 
 
802
#if DEVEL_RELEASE == 1
 
803
   snprintf (line, sizeof(line), "%s %s beta %s", PROGRAM, VERSION, RELEASE_DATE);
 
804
#else
 
805
   snprintf (line, sizeof(line), "%s %s", PROGRAM, VERSION);
 
806
#endif
 
807
 
 
808
   label = gtk_label_new (line);
 
809
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
810
   gtk_misc_set_padding (GTK_MISC (label), 0, 5);
 
811
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
 
812
   gtk_widget_show(label);
 
813
 
 
814
   book = gtk_notebook_new();
 
815
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), book, TRUE, TRUE, 0);
 
816
   gtk_widget_show(book);
 
817
 
 
818
   label = gtk_label_new ("About");
 
819
   box = gtk_vbox_new(FALSE, 0);
 
820
   gtk_notebook_append_page(GTK_NOTEBOOK (book), box, label);
 
821
 
 
822
   pixbuf = gdk_pixbuf_new_from_inline (-1, ettercap_logo, FALSE, NULL);
 
823
   image = gtk_image_new_from_pixbuf(pixbuf);
 
824
   gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 0);
 
825
   gtk_widget_show(image);
 
826
 
 
827
   label = gtk_label_new (aboutstring);
 
828
   gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
 
829
   gtk_widget_show(label);
 
830
 
 
831
   snprintf(line, sizeof(line), "%s/AUTHORS", image_path);
 
832
   infile = fopen(line, "r");
 
833
   if(infile != NULL) {
 
834
      label = gtk_label_new ("Authors");
 
835
      box = gtk_vbox_new(FALSE, 0);
 
836
      gtk_notebook_append_page(GTK_NOTEBOOK (book), box, label);
 
837
 
 
838
      scrolled = gtk_scrolled_window_new(NULL, NULL);
 
839
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);  
 
840
      gtk_box_pack_start (GTK_BOX(box), scrolled, TRUE, TRUE, 0);
 
841
      gtk_widget_show(scrolled);
 
842
 
 
843
      textview = gtk_text_view_new();
 
844
      gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE);
 
845
      gtk_text_view_set_left_margin(GTK_TEXT_VIEW (textview), 10);
 
846
      gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview), 10);
 
847
      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), textview);
 
848
      gtk_widget_show(textview);
 
849
   
 
850
      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
 
851
 
 
852
      while(fgets(line, sizeof(line), infile)) {
 
853
         gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER (buffer), &iter);
 
854
         gtk_text_buffer_insert(GTK_TEXT_BUFFER (buffer), &iter,  g_locale_to_utf8 (line, strlen(line), NULL, NULL, NULL), -1);
 
855
      }
 
856
      fclose(infile);
 
857
   }
 
858
 
 
859
   /* just have to change the filename and tab-label, rest is same as last */
 
860
   snprintf(line, sizeof(line), "%s/THANKS", image_path);
 
861
   infile = fopen(line, "r");
 
862
   if(infile != NULL) {
 
863
      label = gtk_label_new ("Thanks");
 
864
      box = gtk_vbox_new(FALSE, 0);
 
865
      gtk_notebook_append_page(GTK_NOTEBOOK (book), box, label);
 
866
 
 
867
      scrolled = gtk_scrolled_window_new(NULL, NULL);
 
868
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
869
      gtk_box_pack_start (GTK_BOX(box), scrolled, TRUE, TRUE, 0);
 
870
      gtk_widget_show(scrolled);
 
871
 
 
872
      textview = gtk_text_view_new();
 
873
      gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE);
 
874
      gtk_text_view_set_left_margin(GTK_TEXT_VIEW (textview), 10);
 
875
      gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview), 10);
 
876
      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), textview);
 
877
      gtk_widget_show(textview);
 
878
 
 
879
      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
 
880
 
 
881
      while(fgets(line, sizeof(line), infile)) {
 
882
         gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER (buffer), &iter);
 
883
         gtk_text_buffer_insert(GTK_TEXT_BUFFER (buffer), &iter,  g_locale_to_utf8 (line, strlen(line), NULL, NULL, NULL), -1);
 
884
      }
 
885
      fclose(infile);
 
886
   }
 
887
      
 
888
   gtk_widget_show_all (dialog);
 
889
}
 
890
 
 
891
void Ginterface_HelpWindow(char *help[])
 
892
{
 
893
   char **counter, message[1024] = "";
 
894
   GtkWidget *dialog, *label;
 
895
 
 
896
   DEBUG_MSG("Ginterface_HelpWindow");
 
897
 
 
898
   /* Create the widgets */
 
899
   dialog = gtk_dialog_new_with_buttons ("Help Window", GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, NULL);
 
900
 
 
901
   /* build a single multiline string for the label */
 
902
   for (counter = help; *counter; counter++) {
 
903
      strcat(message, *counter);
 
904
      strcat(message, "\n");
 
905
   }
 
906
 
 
907
   label = gtk_label_new (g_locale_to_utf8 (message, strlen(message), NULL, NULL, NULL));
 
908
 
 
909
   /* Ensure that the dialog box is destroyed when the user responds. */
 
910
   g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog));
 
911
 
 
912
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
913
 
 
914
   /* Add the label, and show everything we've added to the dialog. */
 
915
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
 
916
   gtk_widget_show_all (dialog);
 
917
}
 
918
 
 
919
 
 
920
void Ginterface_Connect(void)
 
921
{
 
922
 
 
923
   DEBUG_MSG("Ginterface_Connect");
 
924
 
 
925
   if ( (!strcmp(Host_Source.ip, "")) && (!strcmp(Host_Dest.ip, "")) ) {
 
926
      Ginterface_PopUp("Before sniffing select AT LEAST source OR destination !!");
 
927
   } else if ( (!strcmp(Host_Source.ip, Inet_MyIPAddress())) || (!strcmp(Host_Dest.ip, Inet_MyIPAddress())) ) {
 
928
      Ginterface_PopUp("You CAN'T arpsniff yourself !!");
 
929
   } else if ( !strcmp(Host_Source.ip, Host_Dest.ip) ) {
 
930
      Ginterface_PopUp("SOURCE and DEST (ip) must be different !!");
 
931
   } else if (Options.dumpfile && !Options.writedump) {
 
932
      Ginterface_PopUp("You CAN'T arpsniff from a file !!");
 
933
   } else {
 
934
      char answer;
 
935
 
 
936
      if (Options.silent || Options.arpsniff)  answer = 'y';
 
937
      else answer = Ginterface_PopUpQ("Do you really want to poison the ARP cache of the targets ?");
 
938
 
 
939
      if ((answer == 'y') || (answer == 'Y'))
 
940
      {
 
941
         Ginterface_EditTop(0, "Source:");
 
942
 
 
943
         if (strcmp(Host_Source.ip,""))
 
944
            Ginterface_EditTop(1, Host_Source.ip);
 
945
         else
 
946
            Ginterface_EditTop(1, "ANY");
 
947
 
 
948
         Ginterface_EditTop(6, "Dest:");
 
949
 
 
950
         if (strcmp(Host_Dest.ip,""))
 
951
            Ginterface_EditTop(7, Host_Dest.ip);
 
952
         else
 
953
            Ginterface_EditTop(7, "ANY");
 
954
 
 
955
         Ginterface_EditTop(5, "doppleganger ");
 
956
 
 
957
         if ( number_of_hosts_in_lan == 1 && ((!strcmp(Host_Source.ip, "")) || (!strcmp(Host_Dest.ip, ""))) )
 
958
            Ginterface_AppendTop(5, "- illithid (Public ARP) - ");
 
959
         else
 
960
            Ginterface_AppendTop(5, "- illithid (ARP Based) - ");
 
961
 
 
962
         Ginterface_AppendTop(5, PROGRAM);
 
963
 
 
964
         if ( number_of_hosts_in_lan == 1 && ((!strcmp(Host_Source.ip, "")) || (!strcmp(Host_Dest.ip, ""))) )
 
965
            Ginterface_Sniff_Run(PUBLICARP);   // with HALF duplex ARP poisoning
 
966
         else
 
967
            Ginterface_Sniff_Run(ARPBASED);   // with FULL duplex ARP poisoning
 
968
      }
 
969
   }
 
970
}
 
971
 
 
972
 
 
973
 
 
974
void Ginterface_OldStyleSniff(short mode)
 
975
{
 
976
 
 
977
   DEBUG_MSG("Ginterface_OldStyleSniff -- mode = %d -- [%s] [%s]", mode, Host_Source.ip, Host_Dest.ip);
 
978
 
 
979
   if ( !strcmp(Host_Source.ip, Host_Dest.ip) && strcmp(Host_Source.ip, "") )
 
980
      Ginterface_PopUp("SOURCE and DEST (ip) must be different !!");
 
981
   else if ( !strcmp(Host_Source.mac, Host_Dest.mac) && strcmp(Host_Source.mac, ""))
 
982
      Ginterface_PopUp("SOURCE and DEST (mac) must be different !!");
 
983
   else
 
984
   {
 
985
      Ginterface_EditTop(0, "Source:");
 
986
 
 
987
      if (mode)
 
988
      {
 
989
         if (strcmp(Host_Source.mac,""))
 
990
            Ginterface_EditTop(1, Host_Source.mac);
 
991
         else
 
992
            Ginterface_EditTop(1, "ANY");
 
993
      } else {
 
994
         if (strcmp(Host_Source.ip,""))
 
995
            Ginterface_EditTop(1, Host_Source.ip);
 
996
         else
 
997
            Ginterface_EditTop(1, "ANY");
 
998
      }
 
999
 
 
1000
      Ginterface_EditTop(6, "Dest:");
 
1001
 
 
1002
      if (mode) 
 
1003
      {
 
1004
         if (strcmp(Host_Dest.mac,""))
 
1005
            Ginterface_EditTop(7, Host_Dest.mac);
 
1006
         else
 
1007
            Ginterface_EditTop(7, "ANY");
 
1008
      } else {
 
1009
         if (strcmp(Host_Dest.ip,""))
 
1010
            Ginterface_EditTop(7, Host_Dest.ip);
 
1011
         else
 
1012
            Ginterface_EditTop(7, "ANY");
 
1013
      }
 
1014
 
 
1015
      if (!Options.writedump && Options.dumpfile) {
 
1016
         Ginterface_EditTop(5, "OffLine sniffing [");
 
1017
         Ginterface_AppendTop(5, Options.dumpfile);
 
1018
         Ginterface_AppendTop(5, "]");
 
1019
      } else if (mode) {
 
1020
         Ginterface_EditTop(5, "illithid (MAC based) - ");
 
1021
         Ginterface_AppendTop(5, PROGRAM);
 
1022
      } else {
 
1023
         Ginterface_EditTop(5, "illithid (IP based) - ");
 
1024
         Ginterface_AppendTop(5, PROGRAM);
 
1025
      }
 
1026
 
 
1027
      if (mode)
 
1028
         Ginterface_Sniff_Run(MACBASED);   // no ARP poisoning
 
1029
      else
 
1030
         Ginterface_Sniff_Run(IPBASED);    // no ARP poisoning
 
1031
   }
 
1032
}
 
1033
 
 
1034
void Ginterface_OnlyPoison(void)
 
1035
{
 
1036
   GtkWidget *dialog, *label;
 
1037
   DEBUG_MSG("Ginterface_OnlyPoison");
 
1038
 
 
1039
   if ( (!strcmp(Host_Source.ip, "")) && (!strcmp(Host_Dest.ip, "")) )
 
1040
      Ginterface_PopUp("Before poison select AT LEAST source OR destination !!");
 
1041
   else if ( (!strcmp(Host_Source.ip, Inet_MyIPAddress())) || (!strcmp(Host_Dest.ip, Inet_MyIPAddress())) )
 
1042
      Ginterface_PopUp("You CAN'T poison yourself !!");
 
1043
   else if ( !strcmp(Host_Source.ip, Host_Dest.ip) )
 
1044
      Ginterface_PopUp("SOURCE and DEST (ip) must be different !!");
 
1045
   else
 
1046
   {
 
1047
      int i;
 
1048
      gchar message[512];
 
1049
      pthread_t Dopple_pid = 0;
 
1050
      
 
1051
      for(i=0; i<number_of_hosts_in_lan; i++)
 
1052
      {
 
1053
        if ( !strcmp(Host_Source.ip, Host_In_LAN[i].ip) )
 
1054
           strlcpy(Host_Source.mac, Host_In_LAN[i].mac, sizeof(Host_Source.mac));
 
1055
        if ( !strcmp(Host_Dest.ip, Host_In_LAN[i].ip) )
 
1056
           strlcpy(Host_Dest.mac, Host_In_LAN[i].mac, sizeof(Host_Dest.mac));
 
1057
      }
 
1058
 
 
1059
      if ( !strcmp(Host_Source.mac, "") && !strcmp(Host_Dest.mac, "") )
 
1060
        Error_msg("Doppelganger needs at least one valid mac address !!\n\n(the ip was not found in the list)");
 
1061
 
 
1062
      Dopple_pid = Doppleganger_Run(Options.netiface, Host_Source.ip, Host_Dest.ip, Host_Source.mac, Host_Dest.mac);
 
1063
 
 
1064
      // make modal window, STOP button   
 
1065
      dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
1066
                                 GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, NULL);
 
1067
      gtk_window_set_decorated ( GTK_WINDOW(dialog), FALSE );
 
1068
 
 
1069
      sprintf(message, "Poisoning - %s [%s] -- %s [%s]\nClick \"Close\" to stop...\n", Host_Source.ip, Host_Source.mac, Host_Dest.ip, Host_Dest.mac);
 
1070
      label = gtk_label_new (message);
 
1071
      gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
 
1072
      gtk_widget_show(label);
 
1073
 
 
1074
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
1075
 
 
1076
      gtk_dialog_run (GTK_DIALOG (dialog));
 
1077
     
 
1078
      Ginterface_PopUpN("Shutting down all threads...\n");
 
1079
      
 
1080
      ECThread_destroy(Dopple_pid);
 
1081
 
 
1082
      Ginterface_PopUpN(NULL);
 
1083
                                                                                                      
 
1084
      gtk_main_quit();
 
1085
   }
 
1086
   
 
1087
   DEBUG_MSG("Ginterface_OnlyPoison -- END");
 
1088
}
 
1089
 
 
1090
   
 
1091
void Ginterface_CheckForPoisoner(void)
 
1092
{
 
1093
   SniffingHost *SniffList;
 
1094
   int i;
 
1095
   short found = 0;
 
1096
 
 
1097
   DEBUG_MSG("Ginterface_CheckForPoisoner");
 
1098
 
 
1099
   if (number_of_hosts_in_lan == 1)
 
1100
   {
 
1101
      Ginterface_PopUp("You cannot check the lan in silent mode");
 
1102
      return;
 
1103
   }
 
1104
 
 
1105
   Ginterface_PopUpN("Checking for poisoners...");
 
1106
 
 
1107
   SniffList = Inet_NoSniff();
 
1108
 
 
1109
   for (i=0; ; i++)
 
1110
   {
 
1111
      if (SniffList[i].mode == 0) break;
 
1112
      if (SniffList[i].mode == 1)
 
1113
      {
 
1114
         found = 1;
 
1115
         Ginterface_PopUp("%s is replying for %s", Host_In_LAN[SniffList[i].Host_Index1].ip, Host_In_LAN[SniffList[i].Host_Index2].ip);
 
1116
      }
 
1117
 
 
1118
      if (SniffList[i].mode == 2)
 
1119
      {
 
1120
         found = 1;
 
1121
         Ginterface_PopUp("MAC of %s and %s are identical !",Host_In_LAN[SniffList[i].Host_Index1].ip,Host_In_LAN[SniffList[i].Host_Index2].ip);
 
1122
      }
 
1123
   }
 
1124
 
 
1125
   if (!found)
 
1126
      Ginterface_PopUp("No poisoners found in this lan (seems to be safe)");
 
1127
 
 
1128
   free(SniffList);
 
1129
   Ginterface_PopUpN(NULL);
 
1130
}
 
1131
 
 
1132
 
 
1133
 
 
1134
void Ginterface_FingerPrint(void)
 
1135
{
 
1136
   GtkWidget *dialog, *label, *f_table;
 
1137
   char *mac_finger;
 
1138
   char *long_os_fingers;
 
1139
   char line[100];
 
1140
 
 
1141
   DEBUG_MSG("Ginterface_FingerPrint -- [%s] [%s]", Host_In_LAN[*gPointer].ip, Host_In_LAN[*gPointer].mac );
 
1142
 
 
1143
   Ginterface_PopUpN ("Fingerprinting ...");
 
1144
 
 
1145
   long_os_fingers = strdup(Fingerprint_OS(Host_In_LAN[*gPointer].ip) );
 
1146
   mac_finger = strdup(Fingerprint_MAC(Host_In_LAN[*gPointer].mac));
 
1147
 
 
1148
   Ginterface_PopUpN (NULL);
 
1149
 
 
1150
   sprintf(line, "FingerPrint %s", Host_In_LAN[*gPointer].ip);
 
1151
   dialog = gtk_dialog_new_with_buttons (line, GTK_WINDOW (window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 
 
1152
                                          GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);
 
1153
   // g_signal_connect_swapped (GTK_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog));
 
1154
   f_table = gtk_table_new (2, 2, FALSE); 
 
1155
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), f_table);
 
1156
   gtk_widget_show(f_table);
 
1157
 
 
1158
   label = gtk_label_new("Operating System:");
 
1159
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);   /* align to top left of cell */
 
1160
   gtk_table_attach (GTK_TABLE (f_table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 10, 5); 
 
1161
   gtk_widget_show(label);
 
1162
 
 
1163
   label = gtk_label_new("Network Adapter :");
 
1164
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);   /* align to top left of cell */
 
1165
   gtk_table_attach (GTK_TABLE (f_table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 10, 5);
 
1166
   gtk_widget_show(label);
 
1167
 
 
1168
   label = gtk_label_new(long_os_fingers);
 
1169
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);   /* align to top left of cell */
 
1170
   gtk_table_attach (GTK_TABLE (f_table), label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 10, 5);
 
1171
   gtk_widget_show(label);
 
1172
 
 
1173
   label = gtk_label_new(mac_finger);
 
1174
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);   /* align to top left of cell */
 
1175
   gtk_table_attach(GTK_TABLE (f_table), label, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 10, 5);
 
1176
   gtk_widget_show(label);
 
1177
 
 
1178
   DEBUG_MSG("Ginterface_FingerPrint");   
 
1179
 
 
1180
   gtk_dialog_run (GTK_DIALOG (dialog));
 
1181
 
 
1182
   gtk_widget_destroy (dialog);
 
1183
   free(long_os_fingers);
 
1184
   free(mac_finger);
 
1185
}
 
1186
 
 
1187
 
 
1188
 
 
1189
void Ginterface_EntryRemoval(void)
 
1190
{
 
1191
   DEBUG_MSG("Ginterface_EntryRemoval -- %d", *gPointer);
 
1192
 
 
1193
   if (*gPointer == 0 || number_of_hosts_in_lan == 1)
 
1194
   {
 
1195
      Ginterface_PopUp("You cannot remove yourself from the list !!");
 
1196
      return;
 
1197
   }
 
1198
 
 
1199
   if (*gPointer < number_of_hosts_in_lan-1)
 
1200
      memmove(&Host_In_LAN[*gPointer], &Host_In_LAN[*gPointer+1], (number_of_hosts_in_lan-1-*gPointer)*sizeof(HOST));
 
1201
   else
 
1202
      *gPointer = *gPointer - 1;
 
1203
 
 
1204
   number_of_hosts_in_lan--;
 
1205
 
 
1206
   Host_In_LAN = realloc(Host_In_LAN, number_of_hosts_in_lan*sizeof(HOST));
 
1207
   if (Host_In_LAN == NULL)
 
1208
      Error_msg("ec_gtk:%d realloc() | ERRNO : %d | %s", __LINE__, errno, strerror(errno));
 
1209
 
 
1210
}
 
1211
 
 
1212
void Ginterface_EditTop(int which, char *message)
 
1213
{
 
1214
   /* 'which' is the cell number:  */
 
1215
   /*--------------------------------
 
1216
   |   0   | <--\  |   1   |   2
 
1217
   ---------    |  ------------------
 
1218
   |   3   |    |--|   4   |   5
 
1219
   ---------    |  ------------------
 
1220
   |   6   | <--/  |   7   |   8
 
1221
   --------------------------------*/
 
1222
 
 
1223
   gtk_label_set_text (GTK_LABEL (tb_label[which]), message);
 
1224
}
 
1225
 
 
1226
void Ginterface_ClearTop(void)
 
1227
{
 
1228
   DEBUG_MSG("Ginterface_ClearTop");
 
1229
   gtk_label_set_text(GTK_LABEL (tb_label[0]), "       ");
 
1230
   gtk_label_set_text(GTK_LABEL (tb_label[1]), "       ");
 
1231
   gtk_label_set_text(GTK_LABEL (tb_label[2]), "       ");
 
1232
   gtk_label_set_text(GTK_LABEL (tb_label[3]), "       ");
 
1233
   gtk_label_set_text(GTK_LABEL (tb_label[4]), "       ");
 
1234
   gtk_label_set_text(GTK_LABEL (tb_label[5]), "       ");
 
1235
   gtk_label_set_text(GTK_LABEL (tb_label[6]), "       ");
 
1236
   gtk_label_set_text(GTK_LABEL (tb_label[7]), "       ");
 
1237
   gtk_label_set_text(GTK_LABEL (tb_label[8]), "       ");
 
1238
}
 
1239
 
 
1240
void Ginterface_AppendTop(int which, char *message)
 
1241
{
 
1242
   gchar *contents, *line;
 
1243
 
 
1244
   DEBUG_MSG("Ginterface_AppendTop");
 
1245
 
 
1246
   contents = strdup( gtk_label_get_text (GTK_LABEL (tb_label[which])) );
 
1247
   line = (gchar *)g_malloc(strlen(contents) + strlen(message) + 1);
 
1248
 
 
1249
   if(line == NULL)
 
1250
      return;
 
1251
   
 
1252
   strcpy(line, contents);
 
1253
   strcat(line, message);
 
1254
   
 
1255
   gtk_label_set_text (GTK_LABEL (tb_label[which]), line);
 
1256
 
 
1257
   g_free(line);
 
1258
}
 
1259
 
 
1260
void Ginterface_EditBottom(int which, char *message)
 
1261
{
 
1262
   DEBUG_MSG("Ginterface_EditBottom");
 
1263
   gtk_label_set_text (GTK_LABEL (bb_label[which]), message);
 
1264
}
 
1265
 
 
1266
void Ginterface_ClearBottom(void)
 
1267
{
 
1268
   DEBUG_MSG("Ginterface_ClearBottom");
 
1269
   gtk_label_set_text (GTK_LABEL (bb_label[0]), " ");
 
1270
   gtk_label_set_text (GTK_LABEL (bb_label[1]), " ");
 
1271
}
 
1272
 
 
1273
void Ginterface_AppendBottom(int which, char *message)
 
1274
{
 
1275
   gchar *contents, *line;
 
1276
 
 
1277
   DEBUG_MSG("Ginterface_AppendBottom");
 
1278
 
 
1279
   contents = strdup( gtk_label_get_text (GTK_LABEL (bb_label[which])) );
 
1280
   line = (gchar *)g_malloc(strlen(contents) + strlen(message) + 1);
 
1281
 
 
1282
   if(line == NULL)
 
1283
      return;
 
1284
 
 
1285
   strcpy(line, contents);
 
1286
   strcat(line, message);
 
1287
 
 
1288
   gtk_label_set_text (GTK_LABEL (bb_label[which]), line);
 
1289
 
 
1290
   g_free(line);
 
1291
}
 
1292
 
 
1293
void Ginterface_Run(void)
 
1294
{
 
1295
   DEBUG_MSG("Ginterface_Run");
 
1296
   Ginterface_Splash_Init();
 
1297
   Ginterface_Splash_Show();
 
1298
 
 
1299
   if (Options.arpsniff)
 
1300
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 1);
 
1301
   else if (Options.macsniff)
 
1302
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 3);
 
1303
   else if (Options.sniff)
 
1304
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 2);
 
1305
   else if (Options.passive)
 
1306
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 4);
 
1307
   #ifdef PERMIT_PLUGINS
 
1308
   else if (Options.plugin)
 
1309
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 5);
 
1310
   #endif
 
1311
 
 
1312
   if (Options.silent && !(Options.sniff || Options.macsniff || Options.arpsniff))
 
1313
      Options.silent = 0;
 
1314
 
 
1315
   if (Options.hoststofile)
 
1316
      Ginterface_PopUp("Host list dumped into file: %s", Inet_Save_Host_List());
 
1317
 
 
1318
   /* main interface loop, doesn't return until program is done */
 
1319
   gtk_main();
 
1320
}
 
1321
 
 
1322
void Ginterface_Callback(gpointer data, guint action, GtkWidget *widget) {
 
1323
      switch (action)
 
1324
      {
 
1325
         case 'A':
 
1326
         case 'a':
 
1327
            gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 1);
 
1328
            break;
 
1329
         case 'M':
 
1330
         case 'm':
 
1331
            gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 3);
 
1332
            break;
 
1333
         case 'S':
 
1334
         case 's':
 
1335
            gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 2);
 
1336
            break;
 
1337
         case 'O':
 
1338
         case 'o':
 
1339
            gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 4);
 
1340
            break;
 
1341
#ifdef PERMIT_PLUGINS
 
1342
         case 'P':
 
1343
         case 'p':
 
1344
            gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 5);
 
1345
            break;
 
1346
#endif
 
1347
 
 
1348
         case 'C':
 
1349
         case 'c':
 
1350
            Ginterface_CheckForPoisoner();
 
1351
            break;
 
1352
         case 'F':
 
1353
         case 'f':
 
1354
            Ginterface_FingerPrint();
 
1355
            break;    
 
1356
         case '@':    
 
1357
            // clear selections
 
1358
            memset(&Host_Source, 0, sizeof(HOST));
 
1359
            memset(&Host_Dest, 0, sizeof(HOST));
 
1360
            gtk_widget_set_sensitive (GTK_WIDGET (tablabel[1]), FALSE);                           Ginterface_ClearTop();
 
1361
            break;                                                                             case 'X':
 
1362
         case 'x':
 
1363
            Ginterface_Factory_Run();
 
1364
            break;                                                                             case 'D':
 
1365
         case 'd':
 
1366
            Ginterface_EntryRemoval();
 
1367
            Ginterface_InitList();
 
1368
            break;
 
1369
         case 'J':
 
1370
         case 'j':
 
1371
            Ginterface_OnlyPoison(); /* never returns */
 
1372
            break;
 
1373
         case 'H':
 
1374
         case 'h':
 
1375
            {
 
1376
            static char *help[] = {
 
1377
               "[qQ][F10] - quit",
 
1378
               "[return]  - select the IP",
 
1379
               "[space]   - deselect the IPs",
 
1380
               "[tab]     - switch between source and dest",
 
1381
               "[aA]      - ARP poisoning based sniffing ",
 
1382
               "             . for sniffing on switched LAN",
 
1383
               "             . for man-in-the-middle technique",
 
1384
               "[sS]      - IP based sniffing",
 
1385
               "[mM]      - MAC based sniffing",
 
1386
               "[jJ]      - Only poisoning - no sniffing",
 
1387
               "[dD]      - delete an entry from the list",
 
1388
               "[xX]      - Packet Forge",
 
1389
               "[pP]      - run a plugin",
 
1390
               "[fF]      - OS fingerprint",
 
1391
               "[oO]      - passive host identification",
 
1392
               "[cC]      - check for other poisoner...",
 
1393
               "[rR]      - refresh the list",
 
1394
               "[kK]      - save host list to a file",
 
1395
               "[hH]      - this help screen",
 
1396
               NULL};
 
1397
            Ginterface_HelpWindow(help);
 
1398
            }
 
1399
            break;
 
1400
         case 'R':
 
1401
         case 'r':
 
1402
            Ginterface_RefreshList();
 
1403
            Ginterface_InitList();
 
1404
            break;
 
1405
         case 'K':
 
1406
         case 'k':
 
1407
            Ginterface_PopUp("Host list dumped to file: %s", Inet_Save_Host_List());
 
1408
            break;
 
1409
         case 'q':
 
1410
         case 'Q':
 
1411
            if(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)) != 0) {
 
1412
               gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);             
 
1413
            } else {
 
1414
               char answer;
 
1415
               DEBUG_MSG("Ginterface_Run_END");
 
1416
               answer = Ginterface_PopUpQ("Do you really want to exit?");
 
1417
               if ((answer == 'y') || (answer == 'Y'))
 
1418
                  Ginterface_WExit("They are safe!!  for now... ");
 
1419
            }
 
1420
            break;
 
1421
      }
 
1422
}
 
1423
 
 
1424
void Ginterface_SwitchPage(GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, gpointer user_data) {
 
1425
   static int notebook_page;
 
1426
 
 
1427
   DEBUG_MSG("Ginterface_SwitchPage - current page: %i, new page: %i", notebook_page, page_num);
 
1428
 
 
1429
   /* if newpage and oldpage are the same, don't do anything */
 
1430
   if(notebook_page == page_num)
 
1431
      return;
 
1432
   
 
1433
   /* see which mode we're leaving */
 
1434
   switch (notebook_page) {
 
1435
      case 0:
 
1436
         break;
 
1437
      case 1:
 
1438
      case 2:
 
1439
      case 3:
 
1440
         if(s_scrolled)
 
1441
            gtk_container_remove (GTK_CONTAINER (mainbox[notebook_page]), s_scrolled);
 
1442
         Ginterface_Sniff_Stop();
 
1443
         break;
 
1444
      case 4:
 
1445
         Ginterface_Passive_Stop();
 
1446
         Ginterface_InitList();
 
1447
         break;
 
1448
#ifdef PERMIT_PLUGINS
 
1449
      case 5:
 
1450
         Ginterface_Plugins_Stop();
 
1451
         break;
 
1452
#endif
 
1453
   }
 
1454
 
 
1455
   /* update current page */
 
1456
   notebook_page = page_num;
 
1457
 
 
1458
   /* and which mode to change too */
 
1459
   switch (page_num) {
 
1460
      case 0:
 
1461
         if(GTK_WIDGET_VISIBLE(arrows))
 
1462
            gtk_widget_hide(arrows);
 
1463
         Ginterface_ToolBar(main_menu);
 
1464
         memset(&Host_Source, 0, sizeof(HOST));
 
1465
         memset(&Host_Dest, 0, sizeof(HOST));
 
1466
         Ginterface_ClearTop();
 
1467
         Ginterface_ClearBottom();
 
1468
         break;
 
1469
 
 
1470
      case 1:
 
1471
         if(!GTK_WIDGET_VISIBLE(arrows))
 
1472
            gtk_widget_show (arrows);
 
1473
         Ginterface_Sniff_ToolBar(main_menu);
 
1474
         Options.arpsniff = 1;
 
1475
         Options.sniff = 0;
 
1476
         Options.macsniff = 0;
 
1477
         Ginterface_Connect();
 
1478
         break;
 
1479
 
 
1480
      case 2:
 
1481
         if(!GTK_WIDGET_VISIBLE(arrows))
 
1482
            gtk_widget_show (arrows);
 
1483
         Ginterface_Sniff_ToolBar(main_menu);
 
1484
         Options.arpsniff = 0;
 
1485
         Options.sniff = 1;
 
1486
         Options.macsniff = 0;
 
1487
         Ginterface_OldStyleSniff(0);
 
1488
         break;
 
1489
 
 
1490
      case 3:
 
1491
         if(!GTK_WIDGET_VISIBLE(arrows))
 
1492
            gtk_widget_show (arrows);
 
1493
         Ginterface_Sniff_ToolBar(main_menu);
 
1494
         Options.arpsniff = 0;
 
1495
         Options.sniff = 0;
 
1496
         Options.macsniff = 1;
 
1497
         Ginterface_OldStyleSniff(1);
 
1498
         break;
 
1499
      case 4:
 
1500
         Ginterface_ClearTop();
 
1501
         if(!GTK_WIDGET_VISIBLE(arrows))
 
1502
            gtk_widget_show (arrows);
 
1503
         Ginterface_Passive_ToolBar(main_menu);
 
1504
         Ginterface_Passive_Run();
 
1505
         break;
 
1506
#ifdef PERMIT_PLUGINS
 
1507
      case 5:
 
1508
         if(GTK_WIDGET_VISIBLE(arrows))
 
1509
            gtk_widget_hide(arrows);
 
1510
         Ginterface_Plugins_ToolBar(main_menu);
 
1511
         Ginterface_ClearTop();
 
1512
         Ginterface_ClearBottom();
 
1513
         Ginterface_Plugins_Run();
 
1514
         break;
 
1515
#endif
 
1516
   }
 
1517
}
 
1518
 
 
1519
/* figure out if ettercap was installed properly, if not, use images in local dir */
 
1520
void Ginterface_CheckImgPath(char *path)
 
1521
{
 
1522
   FILE *testimg;
 
1523
   char line[200];
 
1524
 
 
1525
   snprintf(line, sizeof(line), "%s/AUTHORS", path);
 
1526
   testimg = fopen(line, "r");
 
1527
 
 
1528
   if(testimg == NULL)
 
1529
      snprintf(image_path, sizeof(image_path), ".");
 
1530
   else {
 
1531
      snprintf(image_path, sizeof(image_path), "%s", path);
 
1532
      fclose(testimg);
 
1533
   }
 
1534
}
 
1535
 
 
1536
void Ginterface_Screen_Close(void)
 
1537
{
 
1538
   gint page = -1;
 
1539
   DEBUG_MSG("Ginterface_Screen_Close");
 
1540
 
 
1541
   page = gtk_notebook_get_current_page(GTK_NOTEBOOK (notebook));
 
1542
   
 
1543
   if(page > 0)
 
1544
      gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 0);
 
1545
 
 
1546
   while (g_main_iteration(FALSE)); /* update gui */
 
1547
 
 
1548
   gtk_main_quit();
 
1549
}
 
1550
 
 
1551
void Ginterface_WExit(char *buffer)
 
1552
{
 
1553
   DEBUG_MSG("Ginterface_WExit -- [%s]", buffer);
 
1554
 
 
1555
   if (Options.gtk) Ginterface_Screen_Close();
 
1556
 
 
1557
   fprintf(stdout, "\n\n");
 
1558
   fprintf(stdout, "\033[01m\033[1m%s %s brought from the dark side of the net by ALoR, NaGA and daten...\033[0m\n\n", PROGRAM, VERSION);
 
1559
   fprintf(stdout, "\033[01m\033[1mmay the packets be with you...\033[0m\n\n");
 
1560
   fprintf(stdout, "\n%s\n\n", buffer);
 
1561
}
 
1562
 
 
1563
#ifndef HAVE_FORM
 
1564
void trim_buffer(char *buffer, char trim)
 
1565
{
 
1566
   int i;
 
1567
 
 
1568
   for(i = strlen(buffer)-1; i >= 0; i--)
 
1569
      if (buffer[i] == trim) buffer[i] = 0;
 
1570
      else break;
 
1571
}
 
1572
#endif
 
1573
 
 
1574
/* EOF */
 
1575
 
 
1576
// vim:ts=3:expandtab
 
1577