aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/daemon')
-rw-r--r--src/plugins/daemon/Makefile.am24
-rw-r--r--src/plugins/daemon/daemon.c509
-rw-r--r--src/plugins/daemon/daemon.h34
-rw-r--r--src/plugins/daemon/setup.c270
4 files changed, 0 insertions, 837 deletions
diff --git a/src/plugins/daemon/Makefile.am b/src/plugins/daemon/Makefile.am
deleted file mode 100644
index 467c4f13..00000000
--- a/src/plugins/daemon/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
1INCLUDES = \
2 -I$(top_srcdir)/intl \
3 -I$(top_srcdir)/src/include \
4 @GTK_CFLAGS@ \
5 @GNUNETGTK_CFLAGS@ \
6 @LIBSN_CFLAGS@ \
7 @LIBGKSU2_CFLAGS@
8
9plugindir = $(libdir)/GNUnet
10
11plugin_LTLIBRARIES = \
12 libgnunetgtkmodule_daemon.la
13
14libgnunetgtkmodule_daemon_la_SOURCES = \
15 daemon.c daemon.h \
16 setup.c
17libgnunetgtkmodule_daemon_la_LIBADD = \
18 @GTK_LIBS@ @GNUNETGTK_LIBS@ @LIBSN_LIBS@ @LIBGKSU2_LIBS@ \
19 $(top_builddir)/src/common/libgnunetgtk_common.la \
20 -lgnunetstatsapi \
21 -lgnunetutil \
22 -lgnunetgetoptionapi
23libgnunetgtkmodule_daemon_la_LDFLAGS = \
24 -export-dynamic -avoid-version -module
diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c
deleted file mode 100644
index 2eb95efd..00000000
--- a/src/plugins/daemon/daemon.c
+++ /dev/null
@@ -1,509 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2007 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/plugins/daemon/daemon.c
23 * @brief code for gnunet-gtk gnunetd interaction
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include <GNUnet/gnunet_directories.h>
30#include <GNUnet/gnunet_getoption_lib.h>
31#include <GNUnet/gnunet_stats_lib.h>
32#include <GNUnet/gnunet_util.h>
33#include <glib/gerror.h>
34#include "daemon.h"
35
36#ifdef WITH_LIBGKSU2
37/* Not used because libgksu2 headers have broken depends in Debian
38And this is not really needed
39#include <libgksu/libgksu.h> */
40gboolean gksu_run (gchar * command_line, GError ** error);
41#endif
42
43static struct GNUNET_CronManager *cron;
44
45static struct GNUNET_GE_Context *ectx;
46
47static struct GNUNET_GC_Configuration *cfg;
48
49/**
50 * Do the actual update (in event thread).
51 */
52static void *
53updateAppModelSafe (void *arg)
54{
55 GtkWidget *w;
56 GtkListStore *model = arg;
57
58 w =
59 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
60 "applicationList");
61 gtk_tree_view_set_model (GTK_TREE_VIEW (w), GTK_TREE_MODEL (model));
62 gtk_tree_selection_set_mode (gtk_tree_view_get_selection
63 (GTK_TREE_VIEW (w)), GTK_SELECTION_NONE);
64 return NULL;
65}
66
67/**
68 * cron job that periodically updates the model for the
69 * application list.
70 */
71static void
72updateAppModel (void *dummy)
73{
74 struct GNUNET_ClientServerConnection *sock;
75 GtkTreeIter iter;
76 char *apps;
77 char *next;
78 char *pos;
79 char *desc;
80 GtkListStore *model;
81
82 model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
83 apps = NULL;
84 sock = GNUNET_client_connection_create (ectx, cfg);
85 if (sock != NULL)
86 apps =
87 GNUNET_get_daemon_configuration_value (sock, "GNUNETD", "APPLICATIONS");
88 if (apps != NULL)
89 {
90 next = apps;
91 do
92 {
93 while (*next == ' ')
94 next++;
95 pos = next;
96 while ((*next != '\0') && (*next != ' '))
97 next++;
98 if (*next == '\0')
99 {
100 next = NULL; /* terminate! */
101 }
102 else
103 {
104 *next = '\0'; /* add 0-termination for pos */
105 next++;
106 }
107 if (strlen (pos) > 0)
108 {
109 desc =
110 GNUNET_get_daemon_configuration_value (sock, "ABOUT", pos);
111
112 gtk_list_store_append (model, &iter);
113 gtk_list_store_set (model,
114 &iter,
115 0, pos, 1, dgettext ("GNUnet", desc), -1);
116 GNUNET_free_non_null (desc);
117 }
118 }
119 while (next != NULL);
120 GNUNET_free (apps);
121 }
122 GNUNET_client_connection_destroy (sock);
123 GNUNET_GTK_save_call (&updateAppModelSafe, model);
124 g_object_unref (model);
125}
126
127
128void *
129daemon_doUpdateMenus (void *arg)
130{
131 int ret = *(int *) arg;
132 static GtkWidget *killEntry = NULL;
133 static GtkWidget *launchEntry = NULL;
134 static GtkWidget *statsEntry = NULL;
135 static GtkWidget *chooser = NULL;
136 static int once = 1;
137 static int isLocal;
138 char *host;
139 int canStart;
140 struct GNUNET_GC_Configuration *dcfg;
141 const char *fn;
142 char * fnx;
143 char *user;
144
145 if (once)
146 {
147 once = 0;
148 killEntry =
149 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "stopDaemon");
150 launchEntry =
151 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
152 "startDaemon");
153 statsEntry =
154 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
155 "statusPixmap");
156 chooser =
157 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
158 "configfilenameEntry");
159 GNUNET_GC_get_configuration_value_string (cfg, "NETWORK", "HOST",
160 "localhost", &host);
161 if (strncmp (host, "localhost", 9) == 0)
162 isLocal = TRUE;
163 else
164 isLocal = FALSE;
165 GNUNET_free (host);
166 }
167 if (ret == 0)
168 {
169 canStart = 0;
170 fn = gtk_entry_get_text (GTK_ENTRY (chooser));
171 fnx = NULL;
172 if (NULL == fn)
173 GNUNET_GC_get_configuration_value_filename (cfg, "DAEMON",
174 "CONFIGFILE",
175 GNUNET_DEFAULT_DAEMON_CONFIG_FILE,
176 &fnx);
177 fn = fnx;
178 if (isLocal && fn)
179 {
180 if (GNUNET_disk_file_test (ectx, fn) == GNUNET_YES)
181 {
182 dcfg = GNUNET_GC_create ();
183 canStart = 1;
184 if (0 != GNUNET_GC_parse_configuration (dcfg, fn))
185 canStart = 0;
186 user = NULL;
187 GNUNET_GC_get_configuration_value_string (dcfg,
188 "GNUNETD",
189 "USER", "", &user);
190 if (strlen (user) > 0)
191 {
192#if defined(WINDOWS) || defined(WITH_LIBGKSU2)
193 canStart = 1;
194#else
195 struct passwd *pws;
196 if (NULL == (pws = getpwnam (user)))
197 {
198 canStart = 0;
199 }
200 else
201 {
202 if (pws->pw_uid != getuid ())
203 canStart = (geteuid () == 0);
204 else
205 canStart = 1;
206 }
207#endif
208 }
209 GNUNET_free (user);
210 GNUNET_GC_free (dcfg);
211 }
212 }
213 GNUNET_free_non_null(fnx);
214 gtk_image_set_from_stock (GTK_IMAGE (statsEntry), GTK_STOCK_YES,
215 GTK_ICON_SIZE_SMALL_TOOLBAR);
216 gtk_widget_set_sensitive (killEntry, FALSE);
217 if (canStart && isLocal)
218 {
219 gtk_widget_set_sensitive (launchEntry, TRUE);
220 gtk_image_set_from_stock (GTK_IMAGE (statsEntry), GTK_STOCK_NO,
221 GTK_ICON_SIZE_SMALL_TOOLBAR);
222 }
223 else
224 {
225 gtk_widget_set_sensitive (launchEntry, FALSE);
226 gtk_image_set_from_stock (GTK_IMAGE (statsEntry),
227 GTK_STOCK_DIALOG_ERROR,
228 GTK_ICON_SIZE_SMALL_TOOLBAR);
229
230 }
231 }
232 else
233 {
234 gtk_image_set_from_stock (GTK_IMAGE (statsEntry), GTK_STOCK_YES,
235 GTK_ICON_SIZE_SMALL_TOOLBAR);
236 gtk_widget_set_sensitive (killEntry, TRUE);
237 gtk_widget_set_sensitive (launchEntry, FALSE);
238 }
239 return NULL;
240}
241
242/**
243 * Cron job that checks if the daemon is running.
244 */
245static void
246cronCheckDaemon (void *dummy)
247{
248 static int last = -1;
249 int ret;
250
251 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg))
252 ret = 1;
253 else
254 ret = 0;
255 if (last != ret)
256 {
257 updateAppModel (NULL);
258 last = ret;
259 if (ret)
260 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_DAEMONUP, 0);
261 else
262 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_NODAEMON, 0);
263 }
264 GNUNET_GTK_save_call (&daemon_doUpdateMenus, &ret);
265}
266
267
268/* in setup.c */
269void
270on_gnunetdconfigfile_changed_daemon (GtkWidget * wid, gpointer data);
271
272
273/**
274 * Launch gnunetd w/ checks
275 */
276void
277on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
278{
279 GtkWidget *launchEntry;
280 GtkWidget *statsEntry;
281 GtkWidget *chooser;
282 char *fn;
283 char *user;
284 struct GNUNET_GC_Configuration *dcfg;
285 int code = 0;
286
287 launchEntry =
288 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "startDaemon");
289 gtk_widget_set_sensitive (launchEntry, FALSE);
290 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg))
291 {
292 GNUNET_cron_advance_job (GNUNET_GTK_get_cron_manager (),
293 &cronCheckDaemon,
294 15 * GNUNET_CRON_SECONDS, NULL);
295 return;
296 }
297 else
298 {
299 GNUNET_GTK_add_log_entry (_("Launching gnunetd...\n"));
300 statsEntry =
301 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
302 "statusPixmap");
303 gtk_image_set_from_stock (GTK_IMAGE (statsEntry), GTK_STOCK_EXECUTE,
304 GTK_ICON_SIZE_SMALL_TOOLBAR);
305
306 chooser
307 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
308 "gnunetdconfigFileChooserButton");
309 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
310 GNUNET_GE_BREAK (ectx, fn != NULL);
311
312 dcfg = GNUNET_GC_create ();
313 if (0 != GNUNET_GC_parse_configuration (dcfg, fn))
314 user = NULL;
315 GNUNET_GC_get_configuration_value_string (dcfg,
316 "GNUNETD", "USER", "", &user);
317#ifdef WITH_LIBGKSU2
318 char *command;
319 GError *gerror = NULL;
320 struct passwd *pws;
321 if (strlen (user) > 0)
322 {
323 pws = getpwnam (user);
324 if (pws->pw_uid != getuid ())
325 {
326 command = g_strconcat ("gnunetd -c ", fn, NULL);
327 code = gksu_run (command, &gerror);
328 GNUNET_free (command);
329 if (gerror)
330 {
331 GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n"));
332
333 g_error_free (gerror);
334 }
335 else
336 {
337 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
338 }
339 g_free (fn);
340 GNUNET_cron_advance_job (GNUNET_GTK_get_cron_manager (),
341 &cronCheckDaemon,
342 15 * GNUNET_CRON_SECONDS, NULL);
343 return;
344 }
345 else
346 code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES);
347 }
348#else
349 code = GNUNET_daemon_start (ectx, cfg, fn, GNUNET_YES);
350#endif
351
352 if (GNUNET_SYSERR != code)
353 {
354 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
355 }
356 else
357 {
358 GNUNET_GTK_add_log_entry (_("Launching gnunetd failed\n"));
359 }
360 if (fn != NULL)
361 g_free (fn);
362 GNUNET_cron_advance_job (GNUNET_GTK_get_cron_manager (),
363 &cronCheckDaemon,
364 15 * GNUNET_CRON_SECONDS, NULL);
365 }
366
367 on_gnunetdconfigfile_changed_daemon (NULL, NULL);
368}
369
370/**
371 * Kill gnunetd
372 */
373void
374on_stopDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
375{
376 GtkWidget *killEntry = NULL;
377 GtkWidget *statsEntry;
378 struct GNUNET_ClientServerConnection *sock;
379 int i;
380
381 GNUNET_cron_del_job (cron, &cronCheckDaemon, 15 * GNUNET_CRON_SECONDS,
382 NULL);
383 killEntry =
384 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "stopDaemon");
385 gtk_widget_set_sensitive (killEntry, FALSE);
386
387 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg))
388 {
389 sock = GNUNET_client_connection_create (ectx, cfg);
390 if (GNUNET_OK !=
391 GNUNET_client_connection_request_daemon_shutdown (sock))
392 {
393 GtkWidget *dialog;
394
395 dialog = gtk_message_dialog_new
396 (NULL,
397 GTK_DIALOG_MODAL,
398 GTK_MESSAGE_ERROR,
399 GTK_BUTTONS_CLOSE, _("Error requesting shutdown of gnunetd.\n"));
400 gtk_dialog_run (GTK_DIALOG (dialog));
401 gtk_widget_destroy (dialog);
402 }
403 else
404 {
405 statsEntry =
406 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
407 "statusPixmap");
408 gtk_image_set_from_stock (GTK_IMAGE (statsEntry), GTK_STOCK_EXECUTE,
409 GTK_ICON_SIZE_SMALL_TOOLBAR);
410 GNUNET_GTK_add_log_entry (_("Terminating gnunetd...\n"));
411 }
412 GNUNET_client_connection_destroy (sock);
413 }
414 for (i = 0; i < 10; i++)
415 GNUNET_cron_add_job (cron,
416 &cronCheckDaemon,
417 (i + 1) * 500 * GNUNET_CRON_MILLISECONDS, 0, NULL);
418}
419
420struct GNUNET_GC_Configuration *
421daemon_get_cfg_handle()
422{
423 return cfg;
424}
425
426void
427init_daemon (struct GNUNET_GE_Context *e, struct GNUNET_GC_Configuration *c)
428{
429 GtkWidget *tab;
430 GtkWidget *apps;
431 GtkListStore *model;
432 GtkCellRenderer *renderer;
433 int col;
434 char *daemon_config;
435
436 ectx = e;
437 cfg = c;
438 apps =
439 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
440 "applicationList");
441 model = gtk_list_store_new (1, G_TYPE_STRING);
442 gtk_tree_view_set_model (GTK_TREE_VIEW (apps), GTK_TREE_MODEL (model));
443 renderer = gtk_cell_renderer_text_new ();
444 col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (apps),
445 -1,
446 _("Application"),
447 renderer,
448 "text", 0, NULL);
449 gtk_tree_view_column_set_resizable (gtk_tree_view_get_column
450 (GTK_TREE_VIEW (apps), col - 1), TRUE);
451 renderer = gtk_cell_renderer_text_new ();
452 col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (apps),
453 -1,
454 _("Description"),
455 renderer,
456 "text", 1, NULL);
457 gtk_tree_view_column_set_resizable (gtk_tree_view_get_column
458 (GTK_TREE_VIEW (apps), col - 1), TRUE);
459
460 tab =
461 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
462 "daemonScrolledWindow");
463 gtk_widget_show (tab);
464 daemon_config = NULL;
465 GNUNET_GC_get_configuration_value_filename (cfg,
466 "DAEMON",
467 "CONFIGFILE",
468 GNUNET_DEFAULT_DAEMON_CONFIG_FILE,
469 &daemon_config);
470 gtk_entry_set_text (GTK_ENTRY
471 (glade_xml_get_widget
472 (GNUNET_GTK_get_main_glade_XML (),
473 "configfilenameEntry")),
474 daemon_config);
475 if (GNUNET_YES != GNUNET_disk_file_test (NULL, daemon_config))
476 {
477 GNUNET_GTK_add_log_entry (_
478 ("Configuration file for GNUnet daemon `%s' does not exist! Run `gnunet-setup -d'.\n"),
479 daemon_config);
480 }
481 GNUNET_free (daemon_config);
482 cron = GNUNET_GTK_get_cron_manager ();
483 GNUNET_cron_add_job (cron, &cronCheckDaemon, 2 * GNUNET_CRON_SECONDS,
484 15 * GNUNET_CRON_SECONDS, NULL);
485 GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES,
486 5 * GNUNET_CRON_MINUTES, NULL);
487}
488
489void
490done_daemon ()
491{
492 GtkWidget *w;
493
494 GNUNET_cron_del_job (cron, &cronCheckDaemon, 15 * GNUNET_CRON_SECONDS,
495 NULL);
496 GNUNET_cron_del_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES, NULL);
497 w =
498 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
499 "applicationList");
500 gtk_tree_view_set_model (GTK_TREE_VIEW (w), NULL);
501
502 w =
503 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
504 "applicationList");
505 gtk_tree_view_set_model (GTK_TREE_VIEW (w), NULL);
506
507}
508
509/* end of daemon.c */
diff --git a/src/plugins/daemon/daemon.h b/src/plugins/daemon/daemon.h
deleted file mode 100644
index 5d5888e6..00000000
--- a/src/plugins/daemon/daemon.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/plugins/daemon/daemon.h
23 * @brief code for gnunet-setup interaction
24 * @author Christian Grothoff
25 */
26#ifndef DAEMON_H
27#define DAEMON_H
28
29void * daemon_doUpdateMenus (void *arg);
30
31struct GNUNET_GC_Configuration *
32daemon_get_cfg_handle(void);
33
34#endif
diff --git a/src/plugins/daemon/setup.c b/src/plugins/daemon/setup.c
deleted file mode 100644
index 563678f8..00000000
--- a/src/plugins/daemon/setup.c
+++ /dev/null
@@ -1,270 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/plugins/daemon/setup.c
23 * @brief code for gnunet-setup interaction
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include <GNUnet/gnunet_directories.h>
30#include <GNUnet/gnunet_util.h>
31#include <glib/gerror.h>
32#ifdef WITH_LIBGKSU2
33#include <libgksu/libgksu.h>
34#endif
35#include "daemon.h"
36
37/**
38 * Can we write to the given file (with our current
39 * permissions)?
40 */
41static int
42can_write(const char * f)
43{
44 struct stat buf;
45 char * fn;
46 int ret;
47 int sret;
48
49 fn = GNUNET_expand_file_name(NULL, f);
50 sret = STAT (fn, &buf);
51 ret =
52 (0 < strlen(fn)) &&
53 ( ( (0 == ACCESS (fn, W_OK)) &&
54 (! S_ISDIR(buf.st_mode)) ) ||
55 ( (0 != sret) &&
56 (GNUNET_OK == GNUNET_disk_directory_create_for_file(NULL,
57 fn))) );
58 GNUNET_free(fn);
59 return ret;
60}
61
62static char *
63get_gnunetdconfigfile (void)
64{
65 GtkWidget * entry;
66
67 entry
68 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
69 "configfilenameEntry");
70 return
71 GNUNET_strdup(gtk_entry_get_text (GTK_ENTRY(entry)));
72}
73
74/**
75 * Change the configuration filename.
76 */
77void
78on_change_config_name_clicked_daemon (GtkWidget * editFNbutton,
79 GtkWidget * ent)
80{
81 GtkWidget *dialog;
82 char * fn;
83 GtkWidget * entry;
84
85 dialog = gtk_file_chooser_dialog_new ("Select Configuration File",
86 NULL,
87 GTK_FILE_CHOOSER_ACTION_SAVE,
88 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
89 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
90 NULL);
91 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), FALSE);
92 fn = get_gnunetdconfigfile ();
93 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), fn);
94 GNUNET_free(fn);
95 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
96 {
97 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
98 entry
99 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
100 "configfilenameEntry");
101 gtk_entry_set_text (GTK_ENTRY(entry), fn);
102 GNUNET_free(fn);
103 }
104 gtk_widget_destroy (dialog);
105}
106
107/**
108 * Update sensitivity of daemon buttons
109 */
110void
111on_gnunetdconfigfile_changed_daemon (GtkWidget * wid, gpointer data)
112{
113 char *conffile;
114 int ret;
115
116 conffile =
117 get_gnunetdconfigfile();
118 GNUNET_GC_set_configuration_value_string (daemon_get_cfg_handle(),
119 NULL,
120 "DAEMON",
121 "CONFIGFILE",
122 conffile);
123 GNUNET_GC_write_configuration(daemon_get_cfg_handle(),
124 GNUNET_GTK_get_client_config_filename());
125
126#ifndef WITH_LIBGKSU2
127 GtkWidget *startDaemonConfWizard;
128 GtkWidget *startDaemonConfTool;
129
130 startDaemonConfWizard
131 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
132 "startDaemonConfWizard");
133 startDaemonConfTool
134 = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
135 "startDaemonConfTool");
136 if (can_write(conffile))
137 {
138 gtk_widget_set_sensitive (startDaemonConfWizard, TRUE);
139 gtk_widget_set_sensitive (startDaemonConfTool, TRUE);
140 }
141 else
142 {
143 gtk_widget_set_sensitive (startDaemonConfWizard, FALSE);
144 gtk_widget_set_sensitive (startDaemonConfTool, FALSE);
145 }
146#endif
147 ret = 0;
148 daemon_doUpdateMenus(&ret);
149 GNUNET_free_non_null (conffile);
150 return;
151}
152/**
153 * Start gnunet-setup, asking for a password if needed
154 *
155 * @param conffile path to the gnunetd configuration file
156 * @param run_wizard TRUE to run the wizard, FALSE to run the complete tool
157 * @returns FALSE if gnunet-setup was run, TRUE else
158 */
159static gboolean
160GNUNET_GTK_run_gnunet_setup (gchar * conffile, gboolean run_wizard)
161{
162 GtkWidget *mainWindow;
163 GtkWidget *messageDialog;
164 GError *gerror = NULL;
165 char *error_message = NULL;
166
167 if (can_write(conffile))
168 {
169 if (run_wizard)
170 {
171 char *argv[]
172 = { "gnunet-setup", "-d", "wizard-gtk", "-c", conffile, NULL };
173 g_spawn_async (NULL, argv, NULL,
174 G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN,
175 NULL, NULL, NULL, &gerror);
176 }
177 else
178 {
179 char *argv[]
180 = { "gnunet-setup", "-d", "gconfig", "-c", conffile, NULL };
181 g_spawn_async (NULL, argv, NULL,
182 G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN,
183 NULL, NULL, NULL, &gerror);
184 }
185 if (gerror)
186 {
187 error_message = GNUNET_strdup (gerror->message);
188 g_error_free (gerror);
189 }
190 }
191 else
192#ifndef WITH_LIBGKSU2
193 {
194 error_message =
195 GNUNET_strdup (_
196 ("You don't have rights to write to the provided configuration file."));
197 }
198#else
199 {
200 char *commandline;
201
202 if (run_wizard)
203 {
204 commandline =
205 g_strconcat ("gnunet-setup -d wizard-gtk -c ", conffile, NULL);
206 gksu_run (commandline, &gerror);
207 }
208 else
209 {
210 commandline =
211 g_strconcat ("gnunet-setup -d gconfig -c ", conffile, NULL);
212 gksu_run (commandline, &gerror);
213 }
214 GNUNET_free (commandline);
215 if (gerror)
216 {
217 error_message = GNUNET_strdup (gerror->message);
218 g_error_free (gerror);
219 }
220 }
221#endif
222 if (error_message)
223 {
224 mainWindow =
225 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "mainWindow");
226 messageDialog =
227 gtk_message_dialog_new (GTK_WINDOW (mainWindow),
228 GTK_DIALOG_MODAL |
229 GTK_DIALOG_DESTROY_WITH_PARENT,
230 GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
231 _
232 ("Failed to run the configuration tool (gnunet-setup): %s"),
233 error_message);
234 gtk_dialog_run (GTK_DIALOG (messageDialog));
235 gtk_widget_destroy (messageDialog);
236 GNUNET_free (error_message);
237 return FALSE;
238 }
239 return TRUE;
240}
241
242/**
243 * Launch 'gnunet-setup -d wizard-gtk' with needed rights
244 */
245void
246on_startDaemonConfWizard_clicked_daemon (GtkWidget * widget, gpointer data)
247{
248 char *conffile;
249
250 conffile =
251 get_gnunetdconfigfile();
252 GNUNET_GTK_run_gnunet_setup (conffile, TRUE);
253 GNUNET_free (conffile);
254}
255
256/**
257 * Launch 'gnunet-setup -d gconfig' with needed rights
258 */
259void
260on_startDaemonConfTool_clicked_daemon (GtkWidget * widget, gpointer data)
261{
262 char *conffile;
263
264 conffile =
265 get_gnunetdconfigfile();
266 GNUNET_GTK_run_gnunet_setup (conffile, FALSE);
267 GNUNET_free (conffile);
268}
269
270/* end of setup.c */