15
extern void gstm_quit(void);
16
extern void docklet_x11_create(void);
17
extern void docklet_x11_position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data);
21
on_maindialog_remove (GtkContainer *container,
30
extern GtkWidget *maindialog;
31
GtkWidget *confirm = gtk_message_dialog_new_with_markup (
32
GTK_WINDOW (maindialog),
36
"<b><big>Really quit?</big></b>\n\n"
37
"All active tunnels will be stopped.");
39
gtk_dialog_add_buttons (GTK_DIALOG (confirm),
40
GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
41
GTK_STOCK_QUIT, GTK_RESPONSE_YES,
44
if (activeCount==0 || gtk_dialog_run(GTK_DIALOG(confirm))==GTK_RESPONSE_YES)
47
gtk_widget_destroy(confirm);
48
gtk_window_set_focus(GTK_WINDOW(maindialog),lookup_widget(maindialog,"tunnellist"));
53
on_maindialog_delete_event (GtkWidget *widget,
61
on_btn_close_clicked (GtkButton *button,
67
/* show about dialog, disable main */
69
on_eventbox1_button_press_event (GtkWidget *widget,
70
GdkEventButton *event,
74
about = create_aboutdialog();
75
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(about),TRUE);
76
gstm_interface_enable_maindialog(FALSE);
77
gtk_widget_show(about);
81
/* re-enable main dialog */
83
on_aboutdialog_remove (GtkContainer *container,
87
gstm_interface_enable_maindialog(TRUE);
88
gtk_widget_destroy(widget);
91
on_aboutdialog_response (GtkDialog *dialog,
95
gstm_interface_enable_maindialog(TRUE);
96
gtk_widget_destroy(GTK_WIDGET(dialog));
100
on_btn_properties_clicked (GtkButton *button,
105
if (s=gstm_interface_get_selected_tunnel()) {
106
id = gstm_interface_selection2id(s,COL_ID);
107
gstm_interface_properties(id);
113
on_btn_add_clicked (GtkButton *button,
116
extern GtkWidget *maindialog;
119
if (gstm_interface_asknewname(&newname) == GTK_RESPONSE_OK) {
120
id = gstm_tunnel_add(newname);
121
if (id>-1) gstm_interface_properties(id);
124
gtk_window_set_focus(GTK_WINDOW(maindialog),lookup_widget(maindialog,"tunnellist"));
128
on_btn_delete_clicked (GtkButton *button,
131
extern GtkWidget *maindialog;
133
GtkWidget *del = gtk_message_dialog_new (
134
GTK_WINDOW (maindialog),
136
GTK_MESSAGE_QUESTION,
141
if (s=gstm_interface_get_selected_tunnel()) {
142
id = gstm_interface_selection2id(s,COL_ID);
143
gchar *messagemarkup = g_strdup_printf (
144
"<b><big>Delete tunnel?</big></b>\n\nAre you sure you want to delete "
145
"the tunnel '%s'?", gSTMtunnels[id]->name);
146
gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (del), messagemarkup);
147
if (gtk_dialog_run(GTK_DIALOG(del))==GTK_RESPONSE_YES) {
148
gstm_tunnel_del(gstm_interface_selection2id(s,COL_ID));
150
g_free (messagemarkup);
152
gstm_interface_error("oops, selected tunnel not found!");
155
gtk_widget_destroy(del);
156
gtk_window_set_focus(GTK_WINDOW(maindialog), lookup_widget(maindialog, "tunnellist"));
157
gstm_interface_rowactivity();
160
/* start or stop a tunnel */
162
on_btn_start_clicked (GtkButton *button,
165
gstm_interface_rowaction();
168
on_tunnellist_row_activated (GtkTreeView *treeview,
170
GtkTreeViewColumn *column,
173
gstm_interface_rowaction();
176
/* possible rowselection change */
178
on_tunnellist_button_release_event (GtkWidget *widget,
179
GdkEventButton *event,
182
gstm_interface_rowactivity();
186
on_tunnellist_key_release_event (GtkWidget *widget,
190
gstm_interface_rowactivity();
195
void redir_addedit(GtkButton *button, GtkWidget *tun, gint editid) {
196
GtkWidget *t,*p1,*h,*p2,*w;
202
if (gtk_dialog_run(GTK_DIALOG(tun))==GTK_RESPONSE_OK) {
203
if (t=lookup_widget(GTK_WIDGET(tun),"choice_type")) {
204
p.type = gtk_combo_box_get_active_text(GTK_COMBO_BOX(t));
206
if (t && p.type && strlen(p.type)>0) {
207
if (p1=lookup_widget(GTK_WIDGET(tun),"input_port1")) {
208
p.port1=(gchar *)gtk_entry_get_text(GTK_ENTRY(p1));
209
if (!p.port1 || strlen(p.port1)==0) {
210
gstm_interface_error("Port entry is empty");
215
if (strcmp(p.type,"dynamic")==0) {
217
strcpy(p.host,"n/a\0");
219
strcpy(p.port2,"n/a\0");
221
if (h=lookup_widget(GTK_WIDGET(tun),"input_host")) {
222
p.host=(gchar *)gtk_entry_get_text(GTK_ENTRY(h));
223
if (!p.host || strlen(p.host)==0) {
224
gstm_interface_error("Host entry is empty");
229
if (p2=lookup_widget(GTK_WIDGET(tun),"input_port2")) {
230
p.port2=(gchar *)gtk_entry_get_text(GTK_ENTRY(p2));
231
if (!p.port2 || strlen(p.port2)==0) {
232
gstm_interface_error("Port2 entry is empty");
239
if (w=lookup_widget(GTK_WIDGET(button),"redirlist")) {
242
gstm_interface_redirlist_edit(&p, editid, GTK_TREE_VIEW(w));
245
gstm_interface_redirlist_add(&p, (int)random(), GTK_TREE_VIEW(w));
252
gstm_interface_error("No tunnel type selected");
259
on_btn_redir_add_clicked (GtkButton *button,
262
extern GtkWidget *prop;
264
GtkWidget *tun = create_tundialog();
265
/* some dialog init */
266
gtk_window_set_transient_for(GTK_WINDOW(tun),GTK_WINDOW(prop));
267
if (t=lookup_widget(GTK_WIDGET(tun),"choice_type")) {
268
gtk_combo_box_set_active(GTK_COMBO_BOX(t),0);
271
redir_addedit(button,tun,-1);
272
gtk_widget_destroy(tun);
276
on_btn_redir_delete_clicked (GtkButton *button,
281
if (w = lookup_widget(GTK_WIDGET(button),"redirlist")) {
282
s = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
283
if (gtk_tree_selection_count_selected_rows(s)>0) {
284
gstm_interface_redirlist_del(GTK_TREE_VIEW(w),gstm_interface_selection2id(s,COL_RID));
292
on_check_auto_toggled (GtkToggleButton *togglebutton,
300
on_choice_type_changed (GtkComboBox *combobox,
303
GtkWidget *port1, *host, *port2;
305
port1 = lookup_widget(GTK_WIDGET(combobox),"input_port1");
306
host = lookup_widget(GTK_WIDGET(combobox),"input_host");
307
port2 = lookup_widget(GTK_WIDGET(combobox),"input_port2");
308
cbtext = gtk_combo_box_get_active_text(combobox);
309
if (port1 && host && port2 && cbtext!=NULL) {
310
if (strcmp(cbtext,"dynamic")==0) {
311
//gtk_entry_set_text(GTK_ENTRY(port1),"");
312
gtk_entry_set_text(GTK_ENTRY(host),"n/a");
313
gtk_entry_set_text(GTK_ENTRY(port2),"n/a");
314
gtk_editable_set_editable(GTK_EDITABLE(host),FALSE);
315
gtk_editable_set_editable(GTK_EDITABLE(port2),FALSE);
317
if (strcmp(gtk_entry_get_text(GTK_ENTRY(host)),"n/a")==0) {
318
//gtk_entry_set_text(GTK_ENTRY(port1),"");
319
gtk_entry_set_text(GTK_ENTRY(host),"");
320
gtk_entry_set_text(GTK_ENTRY(port2),"");
321
gtk_editable_set_editable(GTK_EDITABLE(host),TRUE);
322
gtk_editable_set_editable(GTK_EDITABLE(port2),TRUE);
328
void docklet_clicked(int buttontype) {
329
extern GtkWidget *maindialog;
330
static GtkWidget *menu = NULL;
333
gtk_widget_destroy(menu);
336
switch (buttontype) {
339
if (GTK_WIDGET_VISIBLE(maindialog)) {
340
//hide the main dialog
341
gtk_widget_hide(maindialog);
343
//show the dialog again
344
gtk_widget_show(maindialog);
352
menu = gstm_create_dockletmenu();
353
gtk_widget_show_all(menu);
354
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
355
docklet_x11_position_menu,
356
NULL, 0, gtk_get_current_event_time());
362
on_btn_redir_edit_clicked (GtkButton *button, gpointer user_data)
366
gint selid=-1,typeid=0;
367
extern GtkWidget *prop;
372
gchar *type,*port1,*host,*port2;
373
if (w = lookup_widget(GTK_WIDGET(button),"redirlist")) {
374
s = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
375
if (gtk_tree_selection_count_selected_rows(s)>0) {
376
selid=gstm_interface_selection2id(s,COL_RID);
379
if (selid>-1 && gtk_tree_selection_get_selected(s,&m,&i)) {
380
tun = create_tundialog();
381
/* some dialog init */
382
gtk_window_set_transient_for(GTK_WINDOW(tun),GTK_WINDOW(prop));
383
gtk_window_set_title(GTK_WINDOW(tun),"Edit redirection");
384
/* get values from the listselection */
385
gtk_tree_model_get (m, &i, COL_TYPE, &type, -1);
386
gtk_tree_model_get (m, &i, COL_PORT1, &port1, -1);
387
gtk_tree_model_get (m, &i, COL_HOST, &host, -1);
388
gtk_tree_model_get (m, &i, COL_PORT2, &port2, -1);
389
/* put type into the dialog */
390
if (strcmp(type,"remote")==0) {
392
} else if (strcmp(type,"dynamic")==0) {
395
if (t=lookup_widget(GTK_WIDGET(tun),"choice_type")) {
396
gtk_combo_box_set_active(GTK_COMBO_BOX(t),typeid);
398
/* put port1 into the dialog */
399
if (t=lookup_widget(GTK_WIDGET(tun),"input_port1")) {
400
gtk_entry_set_text(GTK_ENTRY(t),port1);
402
/* put host into the dialog */
403
if (t=lookup_widget(GTK_WIDGET(tun),"input_host")) {
404
gtk_entry_set_text(GTK_ENTRY(t),host);
406
/* put port2 into the dialog */
407
if (t=lookup_widget(GTK_WIDGET(tun),"input_port2")) {
408
gtk_entry_set_text(GTK_ENTRY(t),port2);
411
redir_addedit(button,tun,selid);
412
gtk_widget_destroy(tun);
417
on_dockletmenu_quit_activate (GtkMenuItem *menuitem,
418
gpointer user_data) {
422
on_dockletmenu_toggle_activate (GtkMenuItem *menuitem,
423
gpointer user_data) {
427
on_dockletmenu_tunnel_activate (GtkMenuItem *menuitem,
428
gpointer user_data) {
429
int id = (int)user_data;
431
gboolean active = gSTMtunnels[id]->active;
434
if (s=gstm_interface_get_selected_tunnel()) {
435
selid = gstm_interface_selection2id(s,COL_ID);
438
gstm_interface_paint_row_id(id, !active);
439
if (selid==id) gstm_interface_enablebuttons(!active);
440
gstm_ssht_starttunnel(id);
442
gstm_ssht_stoptunnel(id);
443
gstm_interface_paint_row_id(id, !active);
444
if (selid==id) gstm_interface_enablebuttons(!active);
449
on_btn_copy_clicked (GtkButton *button,
452
extern GtkWidget *maindialog;
457
struct sshtunnel *tun;
459
GdkPixbuf *pixbuf_red;
460
extern GtkListStore *tunnellist_store;
462
if (s=gstm_interface_get_selected_tunnel()) {
463
id = gstm_interface_selection2id(s,COL_ID);
464
if (gstm_interface_asknewname(&newname) == GTK_RESPONSE_OK) {
465
/* create new filename */
466
fname = (char *)gstm_name2filename(newname);
468
/* expand the list */
469
gSTMtunnels = realloc(gSTMtunnels, (tunnelCount+1)*sizeof(struct sshtunnel *));
470
gSTMtunnels[tunnelCount] = malloc(sizeof(struct sshtunnel));
471
/* copy the tunneldata */
472
gSTMtunnels[tunnelCount]->name = malloc(strlen(newname)+1);
473
strcpy(gSTMtunnels[tunnelCount]->name, newname);
474
gSTMtunnels[tunnelCount]->login = malloc(strlen(gSTMtunnels[id]->login)+1);
475
strcpy(gSTMtunnels[tunnelCount]->login, gSTMtunnels[id]->login);
476
gSTMtunnels[tunnelCount]->host = malloc(strlen(gSTMtunnels[id]->host)+1);
477
strcpy(gSTMtunnels[tunnelCount]->host, gSTMtunnels[id]->host);
478
gSTMtunnels[tunnelCount]->port = malloc(strlen(gSTMtunnels[id]->port)+1);
479
strcpy(gSTMtunnels[tunnelCount]->port, gSTMtunnels[id]->port);
480
gSTMtunnels[tunnelCount]->privkey = malloc(strlen(gSTMtunnels[id]->privkey)+1);
481
strcpy(gSTMtunnels[tunnelCount]->privkey, gSTMtunnels[id]->privkey);
482
gSTMtunnels[tunnelCount]->autostart = gSTMtunnels[id]->autostart;
483
gSTMtunnels[tunnelCount]->active = FALSE;
484
gSTMtunnels[tunnelCount]->sshpid = 0;
485
gSTMtunnels[tunnelCount]->defcount = gSTMtunnels[id]->defcount;
486
gSTMtunnels[tunnelCount]->portredirs = NULL;
487
gSTMtunnels[tunnelCount]->fn = malloc(strlen(fname)+1);
488
strcpy(gSTMtunnels[tunnelCount]->fn, fname);
489
for (i=0; i<gSTMtunnels[id]->defcount; i++) {
490
gSTMtunnels[tunnelCount]->portredirs = realloc(gSTMtunnels[tunnelCount]->portredirs, (i+1)*sizeof(struct portredir *));
491
gSTMtunnels[tunnelCount]->portredirs[i] = malloc(sizeof(struct portredir));
492
gSTMtunnels[tunnelCount]->portredirs[i]->type = malloc(strlen(gSTMtunnels[id]->portredirs[i]->type));
493
strcpy(gSTMtunnels[tunnelCount]->portredirs[i]->type,gSTMtunnels[id]->portredirs[i]->type);
494
gSTMtunnels[tunnelCount]->portredirs[i]->port1 = malloc(strlen(gSTMtunnels[id]->portredirs[i]->port1));
495
strcpy(gSTMtunnels[tunnelCount]->portredirs[i]->port1,gSTMtunnels[id]->portredirs[i]->port1);
496
gSTMtunnels[tunnelCount]->portredirs[i]->host = malloc(strlen(gSTMtunnels[id]->portredirs[i]->host));
497
strcpy(gSTMtunnels[tunnelCount]->portredirs[i]->host,gSTMtunnels[id]->portredirs[i]->host);
498
gSTMtunnels[tunnelCount]->portredirs[i]->port2 = malloc(strlen(gSTMtunnels[id]->portredirs[i]->port2));
499
strcpy(gSTMtunnels[tunnelCount]->portredirs[i]->port2,gSTMtunnels[id]->portredirs[i]->port2);
502
gstm_tunnel2file(gSTMtunnels[tunnelCount], gSTMtunnels[tunnelCount]->fn);
505
pixbuf_red = create_pixbuf("gstm/red.xpm");
506
gtk_list_store_append (tunnellist_store, &iter);
507
gtk_list_store_set (tunnellist_store, &iter,
508
COL_ACTIVE, pixbuf_red,
514
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(tunnellist_store),
518
gstm_interface_error("error making new filename");
522
gstm_interface_error("error getting selected tunnel");
525
gtk_window_set_focus(GTK_WINDOW(maindialog),lookup_widget(maindialog,"tunnellist"));