aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/daemon/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/daemon/setup.c')
-rw-r--r--src/plugins/daemon/setup.c270
1 files changed, 0 insertions, 270 deletions
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 */